Class Resource
- Namespace
- ValveResourceFormat
- Assembly
- ValveResourceFormat.dll
Represents a Valve resource.
public class Resource : IDisposable
Inheritance
Implements
Inherited Members
Constructors
Resource()
Initializes a new instance of the ValveResourceFormat.Resource class.
public Resource()
Resource(ResourceType, ushort)
Initializes a new instance of the ValveResourceFormat.Resource class for creating new resources.
public Resource(ResourceType resourceType, ushort version = 0)
Parameters
resourceType
ResourceTypeversion
ushort
Fields
KnownHeaderVersion
The known and expected header version for resource files.
public const ushort KnownHeaderVersion = 12
Field Value
Properties
Blocks
Gets the list of blocks this resource contains.
public List<Block> Blocks { get; }
Property Value
DataBlock
Gets the generic DATA block.
public Block? DataBlock { get; }
Property Value
EditInfo
Gets the ResourceEditInfo block.
public ResourceEditInfo? EditInfo { get; }
Property Value
ExternalReferences
Gets the ResourceExtRefList block.
public ResourceExtRefList? ExternalReferences { get; }
Property Value
FileName
Gets or sets the file name this resource was parsed from.
public string? FileName { get; set; }
Property Value
FileSize
Gets the resource size.
public uint FileSize { get; }
Property Value
FullFileSize
Resource files have a FileSize in the metadata, however certain file types such as sounds have streaming audio data come after the resource file, and the size is specified within the DATA block. This property attempts to return the correct size.
public uint FullFileSize { get; }
Property Value
HeaderVersion
Gets the version of this resource, should be 12.
public ushort HeaderVersion { get; }
Property Value
Reader
Gets the binary reader. USE AT YOUR OWN RISK! It is exposed publicly to ease of reading the same file.
public BinaryReader? Reader { get; }
Property Value
ResourceType
Gets or sets the type of the resource.
public ResourceType ResourceType { get; }
Property Value
Version
Gets the file type version.
public ushort Version { get; }
Property Value
Methods
ContainsBlockType(BlockType)
Determines whether the resource contains a block of the specified type.
public bool ContainsBlockType(BlockType type)
Parameters
type
BlockType-
The type of block to check for.
Returns
- bool
-
True if a block of the specified type exists; otherwise, false.
Dispose()
Releases binary reader.
public void Dispose()
Dispose(bool)
Releases the resources used by the ValveResourceFormat.Resource.
protected virtual void Dispose(bool disposing)
Parameters
disposing
bool-
True to release both managed and unmanaged resources; false to release only unmanaged resources.
GetBlockByIndex(int)
Gets a block by its index in the blocks list.
public Block GetBlockByIndex(int index)
Parameters
index
int-
The zero-based index of the block.
Returns
- Block
-
The block at the specified index.
Exceptions
- ArgumentOutOfRangeException
-
Thrown when the index is out of range.
GetBlockByType(BlockType)
Gets the first block of the specified type.
public Block? GetBlockByType(BlockType type)
Parameters
type
BlockType-
The type of block to retrieve.
Returns
- Block?
-
The first block of the specified type, or null if not found.
Read(string)
Opens and reads the given filename. The file is held open until the object is disposed.
public void Read(string filename)
Parameters
filename
string-
The file to open and read.
Read(Stream, bool, bool)
Reads the given System.IO.Stream.
public void Read(Stream input, bool verifyFileSize = true, bool leaveOpen = false)
Parameters
input
Stream-
The input System.IO.Stream to read from.
verifyFileSize
bool-
Whether to verify that the stream was correctly consumed.
leaveOpen
bool-
Whether to leave the stream open after the object is disposed.
Remarks
The input stream must remain open while accessing data from this resource, as some operations may perform reads lazily from the stream at call time.
Serialize(Stream)
Serialize resource to binary.
public void Serialize(Stream stream)
Parameters
stream
Stream-
Stream to write to. The stream support seeking.
Remarks
NOT PRODUCTION READY! Not all blocks support serialization and will throw. The total file size must not exceed System.UInt32.