pub struct ModuleFileEntry {Show 27 fields
unknown: u8,
pub flags: FileEntryFlags,
block_count: u16,
block_index: i32,
pub resource_index: i32,
pub tag_group: String,
data_offset: u64,
pub data_offset_flags: DataOffsetType,
pub total_compressed_size: u32,
pub total_uncompressed_size: u32,
pub tag_id: i32,
pub uncompressed_header_size: u32,
pub uncompressed_tag_data_size: u32,
pub uncompressed_resource_data_size: u32,
pub uncompressed_actual_resource_size: u32,
header_alignment: u8,
tag_data_alignment: u8,
resource_data_alignment: u8,
actual_resource_data_alignment: u8,
pub(crate) name_offset: u32,
pub parent_index: i32,
pub asset_hash: i128,
pub resource_count: i32,
pub data_stream: Option<BufReader<Cursor<Vec<u8>>>>,
pub tag_info: Option<TagFile>,
is_loaded: bool,
pub tag_name: String,
}
Expand description
Module file entry structure containing metadata relating to file and required buffer sizes and offsets for the decompressor, as well as global tag ID, resource references and class.
Fields§
§unknown: u8
Unknown, some sort of size?
flags: FileEntryFlags
Determine how the file should be read.
block_count: u16
Number of blocks that make up the file.
block_index: i32
Index of the first block in the module.
resource_index: i32
Index of the first resource in the module’s resource list.
tag_group: String
4 byte-long string for tag group, stored as big endian. This determines how the rest of the tag is read. Example:
bitm
: Bitmapmat
: Material
data_offset: u64
Offset of compressed/uncompressed data in from the start of compressed data in the module.
data_offset_flags: DataOffsetType
Where the offset is located.
total_compressed_size: u32
Size in bytes of compressed buffer in module.
total_uncompressed_size: u32
Size in bytes of buffer to decompress into.
tag_id: i32
MurmurHash3_x86_64
32 bit hash of tag path.
Referred to in-memory as “global tag id”
Is set to -1 if file is resource.
uncompressed_header_size: u32
Size in bytes of header in decompressed buffer.
uncompressed_tag_data_size: u32
Size in bytes of actual tag data in decompressed buffer.
uncompressed_resource_data_size: u32
Size in bytes of resource data in decompressed buffer.
uncompressed_actual_resource_size: u32
Size in bytes of “external” resource data in decompressed buffer. (for instance, havok data or bitmaps)
header_alignment: u8
Power of 2 to align the header buffer to (ex w. 4 = align to a multiple of 16 bytes).
tag_data_alignment: u8
Power of 2 to align the tag data buffer to.
resource_data_alignment: u8
Power of 2 to align the resource data buffer to.
actual_resource_data_alignment: u8
Power of 2 to align the actual resource data buffer to.
name_offset: u32
Offset where the name of the file is located in the string table.
This is not read after ModuleVersion::Season3
.
parent_index: i32
Used with resources to point back to the parent file. -1 = none
asset_hash: i128
Murmur3_x64_128
hash of (what appears to be) the original file that this file was built from.
This is not always the same thing as the file stored in the module.
Only verified if the HasBlocks
flag is not set.
resource_count: i32
Number of resources owned by the file.
data_stream: Option<BufReader<Cursor<Vec<u8>>>>
Data stream containing a buffer of bytes to read/seek.
tag_info: Option<TagFile>
The actual tag file read from the contents (including header), only valid if file is not a resource.
is_loaded: bool
Indicates if file is cached (has data stream) or not.
tag_name: String
Name of the tag as specified in the module string list. Set to tag id if module version does not support names.
Implementations§
Source§impl ModuleFileEntry
impl ModuleFileEntry
Sourcepub fn read<R: BufReaderExt>(
&mut self,
reader: &mut R,
module_version: &ModuleVersion,
) -> Result<()>
pub fn read<R: BufReaderExt>( &mut self, reader: &mut R, module_version: &ModuleVersion, ) -> Result<()>
Reads module file entry data from a reader based on the module version.
§Arguments
reader
- A mutable reference to a reader implementingBufReaderExt
module_version
- Version of the module being read
§Returns
Returns Ok(())
if read is successful, or an Error
if reading fails
Sourcefn read_flight1<R: BufReaderExt>(&mut self, reader: &mut R) -> Result<()>
fn read_flight1<R: BufReaderExt>(&mut self, reader: &mut R) -> Result<()>
Reads module file entry data specifically for modules of version Flight1
.
§Arguments
reader
- A mutable reference to a reader implementingBufReaderExt
§Returns
Returns Ok(())
if read is successful, or an Error
if reading fails
Sourcefn read_other<R: BufReaderExt>(&mut self, reader: &mut R) -> Result<()>
fn read_other<R: BufReaderExt>(&mut self, reader: &mut R) -> Result<()>
Reads module file entry data for non-Flight1
module versions.
§Arguments
reader
- A mutable reference to a reader implementingBufReaderExt
§Returns
Returns Ok(())
if read is successful, or an Error
if reading fails
Sourcepub(super) fn read_tag(
&mut self,
reader: &mut BufReader<File>,
data_offset: u64,
blocks: &[ModuleBlockEntry],
) -> Result<()>
pub(super) fn read_tag( &mut self, reader: &mut BufReader<File>, data_offset: u64, blocks: &[ModuleBlockEntry], ) -> Result<()>
Reads and loads tag data from a file.
§Arguments
reader
- A mutable reference to aBufReader<File>
from which to read the data.data_offset
- Starting offset in bytes of the data in the file.blocks
- Metadata for data blocks.
§Returns
Returns Ok(())
if the read operation is successful, or an Error
containing
the I/O error if any reading operation fails.
Sourcefn read_multiple_blocks(
&self,
reader: &mut BufReader<File>,
blocks: &[ModuleBlockEntry],
file_offset: u64,
data: &mut [u8],
) -> Result<()>
fn read_multiple_blocks( &self, reader: &mut BufReader<File>, blocks: &[ModuleBlockEntry], file_offset: u64, data: &mut [u8], ) -> Result<()>
Reads multiple blocks of data from the file.
This function reads multiple blocks of data, which can be either compressed or uncompressed, from the file and stores them in the provided data buffer.
§Arguments
reader
- A mutable reference to aBufReader<File>
from which to read the data.blocks
- A slice ofModuleBlockEntry
containing metadata about each block.file_offset
- The offset in the file where the data blocks start.data
- A mutable slice where the (decompressed) data will be stored.
§Returns
Returns Ok(())
if the read operation is successful, or an Error
containing
the I/O error if any reading operation fails.
Sourcepub fn read_metadata<T: Default + TagStructure>(
&mut self,
struct_type: &mut T,
) -> Result<T>
pub fn read_metadata<T: Default + TagStructure>( &mut self, struct_type: &mut T, ) -> Result<T>
Reads a specified structure implementing TagStructure
from the tag data.
This function exhausts the inner data_stream
buffer to read the contents of the specified
struct. It first looks for the main struct definition of the file, then gets the referenced
data block and creates a reader for it. The initial contents of the struct are read, and
field block definitions are loaded recursively.
§Arguments
struct_type
- A mutable reference to the struct implementingTagStructure
to read the data into.
§Returns
Returns Ok(())
if the read operation is successful, or an Error
containing
the I/O error if any reading operation fails.
Examples found in repository?
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
fn main() -> infinite_rs::Result<()> {
let mut pc_modules =
load_modules(String::from("C:/XboxGames/Halo Infinite/Content/deploy/pc"))?;
let mut any_modules = load_modules(String::from(
"C:/XboxGames/Halo Infinite/Content/deploy/any",
))?;
let mut modules = pc_modules.iter_mut().chain(any_modules.iter_mut());
for module in &mut modules {
for index in 0..module.files.len() {
module.read_tag(index as u32)?;
let tag = &mut module.files[index];
if tag.tag_group == "mat " {
let mut mat = MaterialTag::default();
tag.read_metadata(&mut mat)?;
}
// explicitly drop buffer to free up memory
// normally, can take 50+ GBs of RAM
module.files[index].data_stream = None
}
}
Ok(())
}
More examples
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
fn main() -> Result<()> {
let mut module = ModuleFile::from_path(DEPLOY_PATH)?;
for idx in 0..module.files.len() {
if module.files[idx].tag_group == SCRIPT_GROUP {
module.read_tag(idx as u32)?;
let mut source = HsSourceFileTag::default();
module.files[idx].read_metadata(&mut source)?;
let size = module.files[idx].uncompressed_header_size + 0x2D8;
let tag_id = module.files[idx].tag_id;
let mut server_buf = vec![0; source.server.size as usize];
let mut client_buf = vec![0; source.client.size as usize];
if let Some(stream) = module.files[idx].data_stream.as_mut() {
stream.seek(SeekFrom::Start(size as u64))?;
stream.read_exact(&mut server_buf)?;
stream.read_exact(&mut client_buf)?;
}
let server_file = File::create(format!("{SAVE_PATH}/{}_server.luac", tag_id))?;
let mut bw = BufWriter::new(server_file);
bw.write_all(&server_buf)?;
let client_file = File::create(format!("{SAVE_PATH}/{}_client.luac", tag_id))?;
let mut bw = BufWriter::new(client_file);
bw.write_all(&client_buf)?;
}
}
Ok(())
}