Begun implementing Attributes, have added some string tables to work with

This commit is contained in:
mykola2312 2023-09-08 20:57:45 +03:00
parent 74f70c5171
commit 33e9cdaa75
3 changed files with 173 additions and 6 deletions

View file

@ -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<Self> {
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!()
}
}

View file

@ -6,13 +6,13 @@ use anyhow::Result;
use indexmap::IndexMap; use indexmap::IndexMap;
use std::fmt; use std::fmt;
#[derive(Debug)] #[derive(Debug, Eq, PartialEq)]
pub struct ESHUnknown { pub struct ESHUnknown {
pub data_type: u32, pub data_type: u32,
pub data: Vec<u8>, pub data: Vec<u8>,
} }
#[derive(Debug)] #[derive(Debug, Eq, PartialEq)]
pub struct ESHEntityFlags { pub struct ESHEntityFlags {
pub entity_id: u16, pub entity_id: u16,
pub flags: u16, pub flags: u16,
@ -22,7 +22,7 @@ impl ESHEntityFlags {
const SIZE: usize = 4; const SIZE: usize = 4;
} }
#[derive(Debug)] #[derive(Debug, PartialEq)]
pub struct ESHFrame { pub struct ESHFrame {
pub unk1: Vec<u8>, pub unk1: Vec<u8>,
pub a: f32, pub a: f32,
@ -34,7 +34,7 @@ impl ESHFrame {
const SIZE: usize = 48; const SIZE: usize = 48;
} }
#[derive(Debug)] #[derive(Debug, Eq, PartialEq)]
pub struct ESHRect { pub struct ESHRect {
pub top: i32, pub top: i32,
pub left: i32, pub left: i32,
@ -46,7 +46,7 @@ impl ESHRect {
const SIZE: usize = 16; const SIZE: usize = 16;
} }
#[derive(Debug)] #[derive(Debug, PartialEq)]
pub enum ESHValue { pub enum ESHValue {
Unknown(ESHUnknown), Unknown(ESHUnknown),
Bool(bool), Bool(bool),

View file

@ -98,12 +98,16 @@ impl WriteStream {
} }
} }
pub fn into_vec(self) -> Vec<u8> {
self.buf.into_inner()
}
pub fn into_raw(self, offset: usize, size: usize) -> Raw { pub fn into_raw(self, offset: usize, size: usize) -> Raw {
let buf_size = self.buf.get_ref().len(); let buf_size = self.buf.get_ref().len();
Raw { Raw {
offset: offset, offset: offset,
size: if size == 0 { buf_size } else { size }, size: if size == 0 { buf_size } else { size },
mem: self.buf.into_inner(), mem: self.into_vec(),
} }
} }