From 1c4706208397fb5b856cbef7fc1c7545db24094e Mon Sep 17 00:00:00 2001 From: Evil Eye Date: Sat, 14 Oct 2023 16:22:28 +0200 Subject: [PATCH] Replace more explicitly sized reads --- components/esm3/loadrepa.cpp | 2 +- components/esm3/loadrepa.hpp | 6 +++--- components/esm3/loadscpt.cpp | 12 ++++++++---- components/esm3/loadscpt.hpp | 4 ++-- components/esm3/loadskil.cpp | 2 +- components/esm3/loadskil.hpp | 8 ++++---- components/esm3/loadweap.cpp | 3 ++- components/esm3/loadweap.hpp | 12 ++++++------ 8 files changed, 27 insertions(+), 22 deletions(-) diff --git a/components/esm3/loadrepa.cpp b/components/esm3/loadrepa.cpp index ea0fc29f19..c911cb1a23 100644 --- a/components/esm3/loadrepa.cpp +++ b/components/esm3/loadrepa.cpp @@ -28,7 +28,7 @@ namespace ESM mName = esm.getHString(); break; case fourCC("RIDT"): - esm.getHTSized<16>(mData); + esm.getHT(mData.mWeight, mData.mValue, mData.mUses, mData.mQuality); hasData = true; break; case fourCC("SCRI"): diff --git a/components/esm3/loadrepa.hpp b/components/esm3/loadrepa.hpp index 63f0a2959d..37fe94c349 100644 --- a/components/esm3/loadrepa.hpp +++ b/components/esm3/loadrepa.hpp @@ -22,14 +22,14 @@ namespace ESM struct Data { float mWeight; - int mValue; + int32_t mValue; - int mUses; + int32_t mUses; float mQuality; }; // Size = 16 Data mData; - unsigned int mRecordFlags; + uint32_t mRecordFlags; RefId mId, mScript; std::string mName, mModel, mIcon; diff --git a/components/esm3/loadscpt.cpp b/components/esm3/loadscpt.cpp index 51752deca3..c1dc759cdc 100644 --- a/components/esm3/loadscpt.cpp +++ b/components/esm3/loadscpt.cpp @@ -12,12 +12,12 @@ namespace ESM { void Script::loadSCVR(ESMReader& esm) { - int s = mData.mStringTableSize; + uint32_t s = mData.mStringTableSize; std::vector tmp(s); // not using getHExact, vanilla doesn't seem to mind unused bytes at the end esm.getSubHeader(); - int left = esm.getSubSize(); + uint32_t left = esm.getSubSize(); if (left < s) esm.fail("SCVR string list is smaller than specified"); esm.getExact(tmp.data(), s); @@ -99,7 +99,11 @@ namespace ESM { esm.getSubHeader(); mId = esm.getMaybeFixedRefIdSize(32); - esm.getTSized<20>(mData); + esm.getT(mData.mNumShorts); + esm.getT(mData.mNumLongs); + esm.getT(mData.mNumFloats); + esm.getT(mData.mScriptDataSize); + esm.getT(mData.mStringTableSize); hasHeader = true; break; @@ -114,7 +118,7 @@ namespace ESM esm.getSubHeader(); uint32_t subSize = esm.getSubSize(); - if (subSize != static_cast(mData.mScriptDataSize)) + if (subSize != mData.mScriptDataSize) { std::stringstream ss; ss << "Script data size defined in SCHD subrecord does not match size of SCDT subrecord"; diff --git a/components/esm3/loadscpt.hpp b/components/esm3/loadscpt.hpp index f0fab766cf..61b27f1423 100644 --- a/components/esm3/loadscpt.hpp +++ b/components/esm3/loadscpt.hpp @@ -29,7 +29,7 @@ namespace ESM { /// Data from script-precompling in the editor. /// \warning Do not use them. OpenCS currently does not precompile scripts. - int mNumShorts, mNumLongs, mNumFloats, mScriptDataSize, mStringTableSize; + uint32_t mNumShorts, mNumLongs, mNumFloats, mScriptDataSize, mStringTableSize; }; struct SCHD { @@ -37,7 +37,7 @@ namespace ESM Script::SCHDstruct mData; }; - unsigned int mRecordFlags; + uint32_t mRecordFlags; RefId mId; SCHDstruct mData; diff --git a/components/esm3/loadskil.cpp b/components/esm3/loadskil.cpp index 8661230e8c..fd53726f90 100644 --- a/components/esm3/loadskil.cpp +++ b/components/esm3/loadskil.cpp @@ -55,7 +55,7 @@ namespace ESM hasIndex = true; break; case fourCC("SKDT"): - esm.getHTSized<24>(mData); + esm.getHT(mData.mAttribute, mData.mSpecialization, mData.mUseValue); hasData = true; break; case fourCC("DESC"): diff --git a/components/esm3/loadskil.hpp b/components/esm3/loadskil.hpp index dac7745d3f..978e3d5dc4 100644 --- a/components/esm3/loadskil.hpp +++ b/components/esm3/loadskil.hpp @@ -24,7 +24,7 @@ namespace ESM ESM::RefId mFailureSound; ESM::RefId mHitSound; std::string mName; - int mAutoCalcMax; + int32_t mAutoCalcMax; static constexpr int Length = 6; @@ -44,13 +44,13 @@ namespace ESM /// Return a string descriptor for this record type. Currently used for debugging / error logs only. static std::string_view getRecordType() { return "Skill"; } - unsigned int mRecordFlags; + uint32_t mRecordFlags; SkillId mId; struct SKDTstruct { - int mAttribute; // see defs.hpp - int mSpecialization; // 0 - Combat, 1 - Magic, 2 - Stealth + int32_t mAttribute; // see defs.hpp + int32_t mSpecialization; // 0 - Combat, 1 - Magic, 2 - Stealth float mUseValue[4]; // How much skill improves through use. Meaning // of each field depends on what skill this // is. We should document this better later. diff --git a/components/esm3/loadweap.cpp b/components/esm3/loadweap.cpp index 501f0602e4..31c03b00fe 100644 --- a/components/esm3/loadweap.cpp +++ b/components/esm3/loadweap.cpp @@ -29,7 +29,8 @@ namespace ESM mName = esm.getHString(); break; case fourCC("WPDT"): - esm.getHTSized<32>(mData); + esm.getHT(mData.mWeight, mData.mValue, mData.mType, mData.mHealth, mData.mSpeed, mData.mReach, + mData.mEnchant, mData.mChop, mData.mSlash, mData.mThrust, mData.mFlags); hasData = true; break; case fourCC("SCRI"): diff --git a/components/esm3/loadweap.hpp b/components/esm3/loadweap.hpp index 6eec3a9ef4..e8355d0f55 100644 --- a/components/esm3/loadweap.hpp +++ b/components/esm3/loadweap.hpp @@ -62,19 +62,19 @@ namespace ESM struct WPDTstruct { float mWeight; - int mValue; - short mType; - unsigned short mHealth; + int32_t mValue; + int16_t mType; + uint16_t mHealth; float mSpeed, mReach; - unsigned short mEnchant; // Enchantment points. The real value is mEnchant/10.f + uint16_t mEnchant; // Enchantment points. The real value is mEnchant/10.f unsigned char mChop[2], mSlash[2], mThrust[2]; // Min and max - int mFlags; + int32_t mFlags; }; // 32 bytes #pragma pack(pop) WPDTstruct mData; - unsigned int mRecordFlags; + uint32_t mRecordFlags; RefId mId, mEnchant, mScript; std::string mName, mModel, mIcon;