1
 2
 3
 4
 5
 6
 7
 8
 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
use std::{
    fs::File,
    io::BufReader,
};

use binread::{
    BinResult,
    BinReaderExt
};

use crate::ArcFile;
use crate::SeekRead;
pub use crate::filesystem::*;

#[repr(C)]
#[derive(Debug)]
pub struct LoadedArc {
    pub magic: u64,
    pub stream_section_offset: u64,
    pub file_section_offset: u64,
    pub shared_section_offset: u64,
    pub file_system_offset: u64,
    /// Not too sure about that one
    pub file_system_search_offset: u64,
    pub padding: u64,
    pub uncompressed_fs: *const FileSystemHeader,
    pub fs_header: *const FileSystemHeader,
    /// Not too sure about that one
    pub region_entry: u64,
    pub file_info_buckets: *const FileInfoBucket,
    pub file_hash_to_path_index: *const HashToIndex,
    pub file_paths: *const FilePath,
    pub file_info_indices: *const FileInfoIndex,
    pub dir_hash_to_info_index: *const HashToIndex,
    pub dir_infos: *const DirInfo,
    pub folder_offsets: *const DirectoryOffset,
    pub folder_child_hashes: *const HashToIndex,
    pub file_infos: *mut FileInfo,
    pub file_info_to_datas: *const FileInfoToFileData,
    pub file_datas: *mut FileData,
    pub unk_section: u64,
    pub stream_header: *const StreamHeader,
    pub quick_dirs: *const QuickDir,
    pub stream_hash_to_entries: *const HashToIndex,
    pub stream_entries: *const StreamEntry,
    pub stream_file_indices: *const u32,
    pub stream_datas: *const StreamData,
    pub extra_buckets: *const FileInfoBucket,
    pub extra_entries: u64,
    pub extra_folder_offsets: *const DirectoryOffset,
    // CppVector
    pub extra_entry_vector: [u64;3],
    pub version: u32,
    pub extra_count: u32,
    pub loaded_file_system_search: *const LoadedSearchSection,
    // ...
}

impl LoadedArc {
    pub fn open() -> BinResult<ArcFile> {
        Self::from_reader(BufReader::new(File::open("rom:/data.arc")?))
    }

    pub fn from_reader<R: SeekRead + 'static>(mut reader: R) -> BinResult<ArcFile> {
        let arc: ArcFile = reader.read_le()?;

        *arc.reader.lock().unwrap() = Box::new(reader);

        Ok(arc)
    }
}

#[repr(C)]
pub struct SearchSectionHeader {
    pub section_size: u32,
    // ..
}

#[repr(C)]
pub struct SearchSectionBody {
    pub file_info_count: u32,
    pub file_info_indices_count: u32,
    pub path_group_count: u32,
}

#[repr(C)]
pub struct LoadedSearchSection {
    pub search_header: *const SearchSectionHeader,
    pub body: *const SearchSectionBody,
    // ...
}