Class GameFileLoader
Namespace: ValveResourceFormat.IO
Assembly: ValveResourceFormat.dll
Loads compiled game resources from VPK packages and disk with automatic path resolution.
public class GameFileLoader : IFileLoader, IDisposableInheritance
object ← GameFileLoader
Implements
Remarks
Loads compiled resources (models, textures, materials) as Resource objects. Lookup spans VPK packages and loose files on disk, with game search paths discovered from gameinfo.gi files.
To read raw file bytes from a VPK package, use Package.ReadEntry instead.
Constructors
GameFileLoader(Package?, string?, ILogger?)
Initializes a new instance of the GameFileLoader class.
public GameFileLoader(Package? currentPackage, string? currentFileName, ILogger? logger = null)Parameters
currentPackage Package?
The current package to search for files in.
currentFileName string?
The path on disk to the current file that is being opened.
logger ILogger?
Logger for the search paths that get mounted and the files that fail to load.
Remarks
fileName is needed when used by GUI when package has not yet been resolved.
Fields
CompiledFileSuffix
The suffix added to compiled file names.
public const string CompiledFileSuffix = "_c"Field Value
string
Properties
CurrentPackage
Gets or sets the current package being processed.
public Package? CurrentPackage { get; set; }Property Value
Package?
IsCounterStrike2
Gets whether the game found is Counter-Strike 2.
public bool IsCounterStrike2 { get; }Property Value
bool
ParticleShaderFeatureBranching
Gets whether the first game found switches particle shader features at run time rather than through static combos, which its gameinfo.gi gives as Particles/EnableParticleShaderFeatureBranching.
public bool ParticleShaderFeatureBranching { get; }Property Value
bool
ParticlesFoggedByDefault
Gets whether the first game found fogs particles whose renderer leaves fog to the game, which its gameinfo.gi gives as Particles/ParticlesFoggedByDefault.
public bool ParticlesFoggedByDefault { get; }Property Value
bool
SteamAppId
Gets the Steam app id the first game found mounts its content as, which its gameinfo.gi gives as FileSystem/SteamAppId, or zero when no game gives one.
public int SteamAppId { get; }Property Value
int
Methods
AddDiskPathToSearch(string)
Adds a disk path to the search paths.
public bool AddDiskPathToSearch(string searchPath)Parameters
searchPath string
Returns
bool
AddPackageToSearch(string)
Loads and adds a VPK package to the search paths.
public Package AddPackageToSearch(string searchPath)Parameters
searchPath string
Returns
Package
AddPackageToSearch(Package)
Adds an already loaded package to the search paths.
public void AddPackageToSearch(Package package)Parameters
package Package
Dispose(bool)
Releases resources used by this instance.
protected virtual void Dispose(bool disposing)Parameters
disposing bool
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()EnsureStringTokenGameKeys()
Ensures surface property string tokens are loaded and stored.
public void EnsureStringTokenGameKeys()FindAndLoadSearchPaths(string?)
Finds and loads search paths from gameinfo.gi files.
public void FindAndLoadSearchPaths(string? modIdentifierPath = null)Parameters
modIdentifierPath string?
FindFile(string, bool)
Finds a file in packages or on disk.
public virtual (string? PathOnDisk, Package? Package, PackageEntry? PackageEntry) FindFile(string file, bool logNotFound = true)Parameters
file string
The file path to find.
logNotFound bool
Whether to log if file is not found.
Returns
(string? PathOnDisk, Package? Package, PackageEntry? PackageEntry)
A tuple containing the path on disk, package, and package entry if found.
GetFileStream(string)
Opens a stream for reading a raw (uncompiled) file, such as a loose script text file.
public Stream? GetFileStream(string file)Parameters
file string
Path to the file to read.
Returns
A readable stream, or null if not found.
IsPackageMounted(string)
Returns whether a package with the given VPK path is mounted, including GameFileLoader.CurrentPackage.
public bool IsPackageMounted(string searchPath)Parameters
searchPath string
Path to the VPK, with or without the _dir.vpk suffix.
Returns
bool
LoadFile(string)
Loads a compiled resource file.
public virtual Resource? LoadFile(string file)Parameters
file string
Path to the resource file to load.
Returns
Loaded resource, or null if not found.
Remarks
To read raw file bytes from a VPK package, use Package.ReadEntry instead.
LoadFileCompiled(string)
Same as IFileLoader.LoadFile(string) but appends "_c" to the end of the string.
public virtual Resource? LoadFileCompiled(string file)Parameters
file string
Path to the file to load (without _c suffix).
Returns
Loaded compiled resource, or null if not found.
LoadShader(string)
Loads a shader collection by name.
public ShaderCollection LoadShader(string shaderName)Parameters
shaderName string
Name of the shader to load.
Returns
Loaded shader collection, or null if not found.
LoadShaderFromDisk(string)
Loads a shader from disk by finding all its program files.
protected virtual ShaderCollection LoadShaderFromDisk(string shaderName)Parameters
shaderName string
Returns
RemoveDiskPathFromSearch(string)
Removes a disk path from the search paths.
public bool RemoveDiskPathFromSearch(string searchPath)Parameters
searchPath string
Returns
bool
RemovePackageFromSearch(Package)
Removes a package from the search paths.
public bool RemovePackageFromSearch(Package package)Parameters
package Package
Returns
bool
TryMountMapPackage(string)
Mounts a map package found through the search paths in front of every search path except GameFileLoader.CurrentPackage, the way the engine mounts a map: the map mounted last is searched first. Mounting a map package again moves it to the front. Every mount is released with GameFileLoader.UnmountMapPackage(string).
public bool TryMountMapPackage(string mapPackagePath)Parameters
mapPackagePath string
Path of the map package in the search paths, such as maps/de_dust2.vpk.
Returns
bool
Whether the map package was found.
UnmountMapPackage(string)
Releases a mount of GameFileLoader.TryMountMapPackage(string). The package is removed from the search paths once every mount of it is released, but stays open until this loader is disposed, because resources loaded from it keep reading from its entry streams. Mounting it again reuses it.
public void UnmountMapPackage(string mapPackagePath)Parameters
mapPackagePath string
The path the map package was mounted with.

