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?
GameInfo
Gets the gameinfo.gi of the first game found, else the one of GameFileLoader.GameInfoFallback, else GameInfo.Empty.
public GameInfo GameInfo { get; }Property Value
GameInfoFallback
Gets a loader whose game gives the settings read from gameinfo.gi while this one has found no game of its own, such as the loader of the file this one's file was opened from.
protected virtual GameFileLoader? GameInfoFallback { get; }Property Value
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.
FindGameFromResource(Resource)
Mounts the installed Steam game named by the content search paths a resource was compiled with, such as csgo_addons/example, when no game was found otherwise.
public void FindGameFromResource(Resource resource)Parameters
resource Resource
The opened resource.
Remarks
Call it for each opened file before loading its dependencies. It is passed on to GameFileLoader.GameInfoFallback, so the package the file was opened from is still searched before the game.
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.

