From 33e9cdaa755f84306ac6ad71e4a458dc3613549d Mon Sep 17 00:00:00 2001 From: mykola2312 <49044616+mykola2312@users.noreply.github.com> Date: Fri, 8 Sep 2023 20:57:45 +0300 Subject: [PATCH] Begun implementing Attributes, have added some string tables to work with --- src/fot/attributes.rs | 163 ++++++++++++++++++++++++++++++++++++++++++ src/fot/esh.rs | 10 +-- src/fot/stream.rs | 6 +- 3 files changed, 173 insertions(+), 6 deletions(-) diff --git a/src/fot/attributes.rs b/src/fot/attributes.rs index 8b13789..574df2b 100644 --- a/src/fot/attributes.rs +++ b/src/fot/attributes.rs @@ -1 +1,164 @@ +use super::stream::{ReadStream, WriteStream}; +use super::esh::{ESH, ESHValue}; +use super::tag::Tag; +use indexmap::IndexMap; +use anyhow::{Result, anyhow}; +const STATS: [&str; 7] = [ + "strength", + "perception", + "endurance", + "charisma", + "intelligence", + "agility", + "luck" +]; + +const TRAITS: [&str; 11] = [ + "experience", + "skillPoints", + "tagsAvailable", + "statsAvailable", + "perksToTake", + "rank", + "reputation", + "age", + "bonusAC", + "sex", + "race" +]; + +const DERIVED: [&str; 26] = [ + "maxHitPoints", + "maxCarryWeight", + "maxActionPoints", + "radiationResist", + "poisonResist", + "armorClass", + "criticalChance", + "fallover", + "normalThresh", + "energyThresh", + "fireThresh", + "gasThresh", + "explodeThresh", + "electricalThresh", + "normalResist", + "energyResist", + "fireResist", + "gasResist", + "explodeResist", + "electricalResist", + "camoflage", + "healRate", + "meleeDamage", + "bonusDamage", + "skillPerLevel", + "levelsPerPerk" +]; + +const SKILLS: [&str; 18] = [ + "smallGuns", + "bigGuns", + "energyWeapons", + "unarmed", + "meleeWeapons", + "throwing", + "firstAid", + "doctor", + "sneak", + "lockpick", + "steal", + "traps", + "science", + "repair", + "pilot", + "barter", + "gambling", + "outdoorsman" +]; + +const OPT_TRAITS: [&str; 38] = [ + "fastMetabolism", + "bruiser", + "smallFrame", + "oneHander", + "finesse", + "kamikaze", + "heavyHanded", + "fastShot", + "bloodyMess", + "jinxed", + "goodNatured", + "chemReliant", + "chemResistant", + "nightPerson", + "skilled", + "gifted", + "glowingOne", + "techWizard", + "fearTheReaper", + "vatSkin", + "hamFisted", + "domesticated", + "rabid", + "tightNuts", + "targetingComputer", + "betaSoftware", + "empShielding", + "Human", + "Ghoul", + "Mutant", + "RobotHumanoid", + "Deathclaw", + "Dog", + "doAdrenalineRush", + "doDieHard", + "doHthEvade", + "doDrunkenMaster", + "doNightPerson" +]; + +pub struct Attributes { + esh: ESH, + pub stats: IndexMap<&'static str, u32>, + pub traits: IndexMap<&'static str, u32>, + pub derived: IndexMap<&'static str, u32>, + pub skills: IndexMap<&'static str, u32>, + pub skill_tags: IndexMap<&'static str, bool>, + pub opt_traits: IndexMap<&'static str, bool>, + pub perks: IndexMap<&'static str, u32>, + pub addictions: IndexMap<&'static str, u32> +} + +impl Attributes { + fn from_binary(bin: &[u8]) -> Result { + let mut rd = ReadStream::new(bin, 0); + + let _ = rd.read_u32()?; + let esh: ESH = rd.read()?; + if esh.props["Binary"] == ESHValue::Bool(false) { + return Err(anyhow!("Attributes Binary == false")); + } + + let mut stats: IndexMap<&'static str, u32>; + let mut traits: IndexMap<&'static str, u32>; + let mut derived: IndexMap<&'static str, u32>; + let mut skills: IndexMap<&'static str, u32>; + let mut skill_tags: IndexMap<&'static str, bool>; + let mut opt_traits: IndexMap<&'static str, bool>; + let mut perks: IndexMap<&'static str, u32>; + let mut addictions: IndexMap<&'static str, u32>; + + if let ESHValue::Binary(binary) = &esh.props["esbin"] { + let mut rd = ReadStream::new(&binary, 0); + + let _ = rd.read_u32()?; + let _: Tag = rd.read()?; + } else { + return Err(anyhow!("Attributes has no esbin")); + } + + todo!() + } +} diff --git a/src/fot/esh.rs b/src/fot/esh.rs index b1d62b6..c99d49c 100644 --- a/src/fot/esh.rs +++ b/src/fot/esh.rs @@ -6,13 +6,13 @@ use anyhow::Result; use indexmap::IndexMap; use std::fmt; -#[derive(Debug)] +#[derive(Debug, Eq, PartialEq)] pub struct ESHUnknown { pub data_type: u32, pub data: Vec, } -#[derive(Debug)] +#[derive(Debug, Eq, PartialEq)] pub struct ESHEntityFlags { pub entity_id: u16, pub flags: u16, @@ -22,7 +22,7 @@ impl ESHEntityFlags { const SIZE: usize = 4; } -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct ESHFrame { pub unk1: Vec, pub a: f32, @@ -34,7 +34,7 @@ impl ESHFrame { const SIZE: usize = 48; } -#[derive(Debug)] +#[derive(Debug, Eq, PartialEq)] pub struct ESHRect { pub top: i32, pub left: i32, @@ -46,7 +46,7 @@ impl ESHRect { const SIZE: usize = 16; } -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub enum ESHValue { Unknown(ESHUnknown), Bool(bool), diff --git a/src/fot/stream.rs b/src/fot/stream.rs index 640df70..4c3813d 100644 --- a/src/fot/stream.rs +++ b/src/fot/stream.rs @@ -98,12 +98,16 @@ impl WriteStream { } } + pub fn into_vec(self) -> Vec { + self.buf.into_inner() + } + pub fn into_raw(self, offset: usize, size: usize) -> Raw { let buf_size = self.buf.get_ref().len(); Raw { offset: offset, size: if size == 0 { buf_size } else { size }, - mem: self.buf.into_inner(), + mem: self.into_vec(), } }