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
Implements
Remarks
This class is intended for loading compiled resources (such as models, textures, materials) that need to be parsed as objects. It handles resource lookup across VPK packages and loose files on disk, automatically discovering game search paths from gameinfo.gi files.
To read raw file bytes from a VPK package, use Package.ReadEntry instead.
Constructors
GameFileLoader(Package?, string?)
Initializes a new instance of the class.
public GameFileLoader(Package? currentPackage, string? currentFileName)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.
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
Properties
CurrentPackage
Gets or sets the current package being processed.
public Package? CurrentPackage { get; set; }Property Value
Package?
Methods
AddDiskPathToSearch(string)
Adds a disk path to the search paths.
public bool AddDiskPathToSearch(string searchPath)Parameters
searchPath string
Returns
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.
protected 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)
Gets a stream for reading a file.
public Stream? GetFileStream(string file)Parameters
file string
Returns
GetPackageEntryStream(Package, PackageEntry)
Gets a stream for reading a package entry.
public static Stream GetPackageEntryStream(Package package, PackageEntry entry)Parameters
package Package
entry PackageEntry
Returns
Remarks
Do not use this method, it will be removed in the future in favor of a method in the ValvePak library.
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 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
RemovePackageFromSearch(Package)
Removes a package from the search paths.
public bool RemovePackageFromSearch(Package package)Parameters
package Package

