From 628010e6c2241d10e05f285b0e08e3b495ddba29 Mon Sep 17 00:00:00 2001 From: mykola2312 <49044616+mykola2312@users.noreply.github.com> Date: Thu, 31 Aug 2023 00:17:20 +0300 Subject: [PATCH] implement ESH --- format.txt | 5 +++-- src/fot.rs | 1 + src/fot/esh.rs | 46 ++++++++++++++++++++++++++++++++++++++++++++++ src/fot/fstring.rs | 4 ++-- 4 files changed, 52 insertions(+), 4 deletions(-) create mode 100644 src/fot/esh.rs diff --git a/format.txt b/format.txt index 15203d8..2d19a58 100644 --- a/format.txt +++ b/format.txt @@ -49,11 +49,12 @@ next zar = + 0x1A + unk5 uint32_t unk1 uint16_t ? uint16_t ? (0xFFFF = no ) + uint32_t N N times FString name uint32_t type - uint32_t dataLen - uint8_t data[dataLen] \ No newline at end of file + uint32_t dataSize + uint8_t data[dataSize] \ No newline at end of file diff --git a/src/fot.rs b/src/fot.rs index 794edcd..026c8aa 100644 --- a/src/fot.rs +++ b/src/fot.rs @@ -4,6 +4,7 @@ mod raw; pub mod save; mod sgd; mod ssg; +mod esh; mod stream; mod tag; mod world; diff --git a/src/fot/esh.rs b/src/fot/esh.rs new file mode 100644 index 0000000..535fcc2 --- /dev/null +++ b/src/fot/esh.rs @@ -0,0 +1,46 @@ +use super::raw::Raw; +use super::tag::Tag; +use super::decoder::Decoder; +use super::fstring::FString; +use super::stream::{ReadStream, WriteStream}; +use anyhow::Result; +use indexmap::IndexMap; + +pub struct ESHValue { + pub data_type: u32, + pub data: Vec +} + +pub struct ESH { + pub tag: Tag, + pub props: IndexMap, + enc_size: usize +} + +impl Decoder for ESH { + fn decode(raw: &Raw, offset: usize, _: usize) -> Result { + let mut rd = ReadStream::new(raw, offset); + let tag: Tag = rd.read(0)?; + + let n = rd.read_u32()? as usize; + let mut props: IndexMap = IndexMap::with_capacity(n); + for _ in 0..n { + let name: FString = rd.read(0)?; + let data_type = rd.read_u32()?; + let data_size = rd.read_u32()? as usize; + let data = rd.read_bytes(data_size)?; + props.insert(name, ESHValue { data_type, data }); + } + + let enc_size = rd.offset() - offset; + Ok(ESH { tag, props, enc_size }) + } + + fn encode(&self) -> Result { + todo!(); + } + + fn get_enc_size(&self) -> usize { + self.enc_size + } +} \ No newline at end of file diff --git a/src/fot/fstring.rs b/src/fot/fstring.rs index 7bfb37d..9a73006 100644 --- a/src/fot/fstring.rs +++ b/src/fot/fstring.rs @@ -7,13 +7,13 @@ use std::io::Cursor; // FString - Fallout -#[derive(Debug, Hash, PartialEq, Eq)] +#[derive(Debug, Hash, PartialEq, Eq, Clone)] pub enum FStringEncoding { ANSI, WCS2, } -#[derive(Debug, Hash, PartialEq, Eq)] +#[derive(Debug, Hash, PartialEq, Eq, Clone)] pub struct FString { pub encoding: FStringEncoding, pub enc_len: usize,