infinite_rs

Struct ModuleFile

Source
pub struct ModuleFile {
    header: ModuleHeader,
    pub files: Vec<ModuleFileEntry>,
    resource_indices: Vec<u32>,
    blocks: Vec<ModuleBlockEntry>,
    file_data_offset: u64,
    module_file: Option<BufReader<File>>,
    hd1_file: Option<BufReader<File>>,
}
Expand description

Module structure which contains the layout of the entire module file.

Fields§

§header: ModuleHeader

Information relating to how the other fields should be read.

§files: Vec<ModuleFileEntry>

Metadata regarding compression and layout of files (tags).

§resource_indices: Vec<u32>

Indices of resource files present in the module.

§blocks: Vec<ModuleBlockEntry>

Uncompressed/compressed blocks making up a file.

§file_data_offset: u64

Offset in BufReader where file data starts.

§module_file: Option<BufReader<File>>

Reference to the module file buffer.

§hd1_file: Option<BufReader<File>>

Reference to HD1 buffer if it exists.

Implementations§

Source§

impl ModuleFile

Source

pub fn new() -> Self

Instantiates a default ModuleFile object.

Source

pub fn from_path<T: AsRef<Path>>(file_path: T) -> Result<Self>

Examples found in repository?
examples/load_all_modules.rs (line 18)
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
fn load_modules(deploy_path: String) -> infinite_rs::Result<Vec<ModuleFile>> {
    let mut modules = Vec::new();
    for entry in walkdir::WalkDir::new(deploy_path)
        .into_iter()
        .filter_map(|e| e.ok())
    {
        if entry.file_type().is_file() {
            let file_path = entry.path().to_str().unwrap();
            if file_path.ends_with(".module") {
                let module = ModuleFile::from_path(file_path);
                match module {
                    Ok(_) => {
                        modules.push(module?);
                        println!("Read module: {}", file_path);
                    }
                    Err(err) => {
                        println!("Failed on file: {}", file_path);
                        return Err(err);
                    }
                };
            }
        }
    }
    Ok(modules)
}
Source

pub fn read<T: AsRef<Path>>(&mut self, file_path: T) -> Result<()>

Reads the module file from the given file path. This function reads the entire structure of the module file. It also calculates and stores important offsets within the file.

§Arguments
  • file_path - A reference to a type that implements Path that holds the path to the module file.
§Returns

Returns Ok(()) if the read operation is successful, or an Error containing the I/O error if any reading operation fails.

Source

fn open_hd1<T: AsRef<Path>>(&mut self, file_path: T) -> Result<()>

Source

pub fn read_tag(&mut self, index: u32) -> Result<()>

Reads a specific tag from the module file.

This function reads a specific tag from the module file based on the provided index. It checks if the tag is not a resource tag (indicated by a tag_id of -1) and then reads the tag data from the module file. It also utilizes the HD1 stream if the file entry has the flag set for it and the stream is loaded.

§Arguments
  • index - The index of the file entry to read the tag from. This index corresponds to the position of the file entry in the files vector.
§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?
examples/load_all_modules.rs (line 167)
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
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)?;
                println!("{:#?}", mat.style_info);
            }
        }
    }
    Ok(())
}
Source

pub fn read_tag_from_id(&mut self, global_id: i32) -> Result<Option<usize>>

Searches for the index of the tag given the global_id.

This function searches for the index of a tag in the files vector using the provided global_id. If the tag is found, it reads the tag using the read_tag function and stores it in the index.

§Arguments
  • global_id - The global tag ID of the file to find. This ID is used to identify the specific tag within the module file.
§Returns

Returns the index of the file if successful, wrapped in Some(usize). If the tag is not found, it returns None. Any I/O error encountered during the operation is also returned if it occurs.

Source

pub fn read_resources(&mut self, index: u32) -> Result<Vec<&ModuleFileEntry>>

Reads the resources referenced by a module entry.

This function reads the resources referenced by a specific module entry. It retrieves the resources based on the provided index and returns them as a vector of references to ModuleFileEntry.

§Arguments
  • index - Index of the file to read the resources of. This index corresponds to the position of the file entry in the files vector.
§Returns

Returns Ok(Vec<&ModuleFileEntry>) if the read operation is successful, containing a vector of references to ModuleFileEntry. If the requested resource wasn’t found in the module, an Error is returned.

Trait Implementations§

Source§

impl Debug for ModuleFile

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ModuleFile

Source§

fn default() -> ModuleFile

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.