From 7ac969aff40f8ee43efefe3cd573cc10e33728d2 Mon Sep 17 00:00:00 2001 From: mykola2312 <49044616+mykola2312@users.noreply.github.com> Date: Wed, 30 Aug 2023 23:57:03 +0300 Subject: [PATCH] implement SSG (though it's unknown) --- src/fot.rs | 1 + src/fot/sgd.rs | 4 +--- src/fot/ssg.rs | 31 +++++++++++++++++++++++++++++++ src/fot/world.rs | 6 +++++- 4 files changed, 38 insertions(+), 4 deletions(-) create mode 100644 src/fot/ssg.rs diff --git a/src/fot.rs b/src/fot.rs index ad61626..794edcd 100644 --- a/src/fot.rs +++ b/src/fot.rs @@ -3,6 +3,7 @@ mod fstring; mod raw; pub mod save; mod sgd; +mod ssg; mod stream; mod tag; mod world; diff --git a/src/fot/sgd.rs b/src/fot/sgd.rs index f125955..7f5526e 100644 --- a/src/fot/sgd.rs +++ b/src/fot/sgd.rs @@ -1,5 +1,3 @@ -use std::ops::Index; - use super::decoder::Decoder; use super::fstring::FString; use super::raw::Raw; @@ -17,7 +15,7 @@ pub struct SGD { } impl Decoder for SGD { - fn decode(raw: &Raw, offset: usize, size: usize) -> Result { + fn decode(raw: &Raw, offset: usize, _: usize) -> Result { let mut rd = ReadStream::new(raw, offset); let tag: Tag = rd.read(0)?; let unk1 = rd.read_bytes(0x48)?; diff --git a/src/fot/ssg.rs b/src/fot/ssg.rs new file mode 100644 index 0000000..86186fe --- /dev/null +++ b/src/fot/ssg.rs @@ -0,0 +1,31 @@ +use super::decoder::Decoder; +use super::raw::Raw; +use super::stream::{ReadStream, WriteStream}; +use super::tag::Tag; +use anyhow::Result; + +#[derive(Debug)] +pub struct SSG { + tag: Tag, + unk1: Vec, +} + +impl Decoder for SSG { + fn decode(raw: &Raw, offset: usize, _: usize) -> Result { + let mut rd = ReadStream::new(raw, offset); + let tag: Tag = rd.read(0)?; + let unk1 = rd.read_bytes(0x14)?; + Ok(SSG { tag, unk1 }) + } + + fn encode(&self) -> Result { + let mut wd = WriteStream::new(self.get_enc_size()); + wd.write(&self.tag)?; + wd.write_bytes(&self.unk1); + Ok(wd.into_raw(0, 0x14)) + } + + fn get_enc_size(&self) -> usize { + self.tag.get_enc_size() + 0x14 + } +} diff --git a/src/fot/world.rs b/src/fot/world.rs index 52beab0..18e5bfa 100644 --- a/src/fot/world.rs +++ b/src/fot/world.rs @@ -2,11 +2,12 @@ use super::decoder::Decoder; use super::fstring::FString; use super::raw::Raw; use super::sgd::SGD; +use super::ssg::SSG; use super::stream::ReadStream; use super::tag::Tag; use anyhow::anyhow; use anyhow::Result; -use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; +use byteorder::{LittleEndian, WriteBytesExt}; use deflate::deflate_bytes_zlib; use inflate::inflate_bytes_zlib; use std::io::Cursor; @@ -20,6 +21,7 @@ pub struct World { pub mission: FString, pub sgd: SGD, + pub ssg: SSG, } impl World { @@ -51,6 +53,7 @@ impl Decoder for World { let mission: FString = rd.read(0)?; let sgd: SGD = rd.read(0)?; + let ssg: SSG = rd.read(0)?; Ok(World { tag, @@ -58,6 +61,7 @@ impl Decoder for World { data, mission, sgd, + ssg, }) }