2022-08-16 11:52:07 -04:00
|
|
|
use crate::common::Language;
|
2022-07-21 19:58:58 -04:00
|
|
|
use crate::gamedata::MemoryBuffer;
|
|
|
|
use binrw::binread;
|
|
|
|
use binrw::BinRead;
|
2022-08-16 11:52:07 -04:00
|
|
|
use std::io::Cursor;
|
2022-07-21 19:58:58 -04:00
|
|
|
|
|
|
|
#[binread]
|
|
|
|
#[br(magic = b"EXHF")]
|
|
|
|
#[br(big)]
|
|
|
|
pub struct EXHHeader {
|
2022-08-16 11:52:07 -04:00
|
|
|
version: u16,
|
2022-07-21 19:58:58 -04:00
|
|
|
|
2022-08-16 11:52:07 -04:00
|
|
|
pub(crate) data_offset: u16,
|
|
|
|
column_count: u16,
|
|
|
|
page_count: u16,
|
|
|
|
language_count: u16,
|
2022-07-21 19:58:58 -04:00
|
|
|
|
|
|
|
#[br(pad_before = 6)]
|
2022-08-16 11:52:07 -04:00
|
|
|
#[br(pad_after = 8)]
|
|
|
|
pub(crate) row_count: u32,
|
2022-07-21 19:58:58 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#[binread]
|
|
|
|
#[br(repr(u16))]
|
|
|
|
pub enum ColumnDataType {
|
|
|
|
String = 0x0,
|
|
|
|
Bool = 0x1,
|
|
|
|
Int8 = 0x2,
|
|
|
|
UInt8 = 0x3,
|
|
|
|
Int16 = 0x4,
|
|
|
|
UInt16 = 0x5,
|
|
|
|
Int32 = 0x6,
|
|
|
|
UInt32 = 0x7,
|
|
|
|
Float32 = 0x9,
|
|
|
|
Int64 = 0xA,
|
|
|
|
UInt64 = 0xB,
|
|
|
|
|
|
|
|
PackedBool0 = 0x19,
|
|
|
|
PackedBool1 = 0x1A,
|
|
|
|
PackedBool2 = 0x1B,
|
|
|
|
PackedBool3 = 0x1C,
|
|
|
|
PackedBool4 = 0x1D,
|
|
|
|
PackedBool5 = 0x1E,
|
|
|
|
PackedBool6 = 0x1F,
|
|
|
|
PackedBool7 = 0x20,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[binread]
|
|
|
|
#[br(big)]
|
|
|
|
pub struct ExcelColumnDefinition {
|
2022-08-16 11:52:07 -04:00
|
|
|
pub data_type: ColumnDataType,
|
|
|
|
pub offset: u16,
|
2022-07-21 19:58:58 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#[binread]
|
|
|
|
#[br(big)]
|
|
|
|
pub struct ExcelDataPagination {
|
2022-08-16 11:52:07 -04:00
|
|
|
pub start_id: u32,
|
|
|
|
row_count: u32,
|
2022-07-21 19:58:58 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#[binread]
|
|
|
|
#[br(big)]
|
|
|
|
pub struct EXH {
|
2022-08-16 11:52:07 -04:00
|
|
|
pub header: EXHHeader,
|
2022-07-21 19:58:58 -04:00
|
|
|
|
|
|
|
#[br(count = header.column_count)]
|
2022-08-16 11:52:07 -04:00
|
|
|
pub column_definitions: Vec<ExcelColumnDefinition>,
|
2022-07-21 19:58:58 -04:00
|
|
|
|
|
|
|
#[br(count = header.page_count)]
|
2022-08-16 11:52:07 -04:00
|
|
|
pub pages: Vec<ExcelDataPagination>,
|
2022-07-21 19:58:58 -04:00
|
|
|
|
|
|
|
#[br(count = header.language_count)]
|
2022-08-16 11:52:07 -04:00
|
|
|
languages: Vec<Language>,
|
2022-07-21 19:58:58 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
impl EXH {
|
2022-08-16 11:52:07 -04:00
|
|
|
pub fn from_existing(buffer: &MemoryBuffer) -> Option<EXH> {
|
2022-08-16 11:50:18 -04:00
|
|
|
EXH::read(&mut Cursor::new(&buffer)).ok()
|
2022-07-21 19:58:58 -04:00
|
|
|
}
|
2022-08-16 11:52:07 -04:00
|
|
|
}
|