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
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
mod decode;
mod encode;

//
// Temporary comments from fabletlcmod.com.
//
// Compiled Defs (.Bin)
//
// Game.Bin, Script.Bin and Frontend.Bin use Names.Bin as a library.
//
// All Names.Bin offsets do not count 20 byte header

/// Compiled def format.
///
/// These are found at `Data/Defs`, `Data/Lang`, `Data/Misc`, and `Data/Shaders`.
///
/// The `Data/CompiledDefs/names.bin` is an important index of names used by other defs.
///
/// ## Format Description
///
/// WIP
pub struct DefBin {
    pub header: DefBinHeader,
    pub entries: Vec<DefBinNameLookup>,
}

// Header
//
// [1] Byte - 00 (Indicates to use Names.Bin as Library)
// [4] Bytes - File Indicator
// [4] Bytes - Platform Indicator (Xbox / PC)
// [4] Bytes - Number of Entries

pub struct DefBinHeader {
    pub use_names_bin: u8,
    pub file_indicator: u32,
    pub platform_indicator: u32,
    pub entries_count: u32,
}

// Names Lookup
//
// Each Row is 12 Bytes long. Loop until Number of Entries is met.
//
// [4] Bytes - Definition Name Offset in Names.Bin
// [4] Bytes - »PC File Name offset in Names.Bin »Xbox Enumerator for specific file.
// [4] Bytes - Counter Based on Definition Used
//
// *Exceptions For File Name or Enumerator Bytes:
// PC If the entry Equals (FF FF FF FF) Name is Defined outside of Names.Bin and does not require parsing.
// Xbox If the enumeration equals (00 00 00 00) Then Enumerator is Defined in Names.Bin
//

pub struct DefBinNameLookup {
    pub definition_offset: u32,
    pub file_name_offset: u32,
    pub counter: u32,
}

// Second Table Header
//
//
// [4] Bytes - Number of Compressed Chunks (Actual Compressed Chunks is always one less)
// [4] Bytes - Null
//

pub struct DefSecondTableHeader {
    pub compressed_chunks_count: u32,
    pub unknown1: u32,
}

// Second Table Lookup (Compressed)
//
//
// Each Row is 8 Bytes long, loop until number of compressed chunks is met.
//
// [4] Bytes - Offset to Compressed Chunk
// [4] Bytes - Last File Number Contained in Chunk (Running Counter)
//
// *Each Offset is based after the second table ends. (Equals (Number of Entries * 12 + 13 byte header) + (Number of Compressed Chunks * 8 + 8 byte header))
//
//
// Each Compressed Chunk is Zlib Compressed
//

pub struct DefSecondTableRow {
    pub compressed_chunk_offset: u32,
    pub last_file_number: u32,
}

// Decompressed
//
// [2] Bytes - Offset
//
// *If you divide initial Offset by 2 it equals number of files
// Each File uses indicator bytes that are defined in the NullDefs (Based on Definition From First Table)
//
// // *Additional Notes: PC .Bin Files require Names.Bin to be parsed into each file offset. Files are listed in order in the First Table.
// Bin Entries
//

pub struct DefSecondTableRowDecompressed {
    pub offset: u16,
}

// more as we get time…