Replace more sized reads

macos_ci_fix
Evil Eye 1 year ago
parent 090da90302
commit b59739a529

@ -690,14 +690,8 @@ namespace EsmTool
std::cout << " Level: " << mData.mData.mLevel << std::endl; std::cout << " Level: " << mData.mData.mLevel << std::endl;
std::cout << " Attributes:" << std::endl; std::cout << " Attributes:" << std::endl;
std::cout << " Strength: " << mData.mData.mStrength << std::endl; for (size_t i = 0; i < mData.mData.mAttributes.size(); ++i)
std::cout << " Intelligence: " << mData.mData.mIntelligence << std::endl; std::cout << " " << ESM::Attribute::indexToRefId(i) << ": " << mData.mData.mAttributes[i] << std::endl;
std::cout << " Willpower: " << mData.mData.mWillpower << std::endl;
std::cout << " Agility: " << mData.mData.mAgility << std::endl;
std::cout << " Speed: " << mData.mData.mSpeed << std::endl;
std::cout << " Endurance: " << mData.mData.mEndurance << std::endl;
std::cout << " Personality: " << mData.mData.mPersonality << std::endl;
std::cout << " Luck: " << mData.mData.mLuck << std::endl;
std::cout << " Health: " << mData.mData.mHealth << std::endl; std::cout << " Health: " << mData.mData.mHealth << std::endl;
std::cout << " Magicka: " << mData.mData.mMana << std::endl; std::cout << " Magicka: " << mData.mData.mMana << std::endl;

@ -456,22 +456,12 @@ void CSMTools::ReferenceableCheckStage::creatureCheck(
if (creature.mData.mLevel <= 0) if (creature.mData.mLevel <= 0)
messages.add(id, "Level is non-positive", "", CSMDoc::Message::Severity_Warning); messages.add(id, "Level is non-positive", "", CSMDoc::Message::Severity_Warning);
if (creature.mData.mStrength < 0) for (size_t i = 0; i < creature.mData.mAttributes.size(); ++i)
messages.add(id, "Strength is negative", "", CSMDoc::Message::Severity_Warning); {
if (creature.mData.mIntelligence < 0) if (creature.mData.mAttributes[i] < 0)
messages.add(id, "Intelligence is negative", "", CSMDoc::Message::Severity_Warning); messages.add(id, ESM::Attribute::indexToRefId(i).toDebugString() + " is negative", {},
if (creature.mData.mWillpower < 0) CSMDoc::Message::Severity_Warning);
messages.add(id, "Willpower is negative", "", CSMDoc::Message::Severity_Warning); }
if (creature.mData.mAgility < 0)
messages.add(id, "Agility is negative", "", CSMDoc::Message::Severity_Warning);
if (creature.mData.mSpeed < 0)
messages.add(id, "Speed is negative", "", CSMDoc::Message::Severity_Warning);
if (creature.mData.mEndurance < 0)
messages.add(id, "Endurance is negative", "", CSMDoc::Message::Severity_Warning);
if (creature.mData.mPersonality < 0)
messages.add(id, "Personality is negative", "", CSMDoc::Message::Severity_Warning);
if (creature.mData.mLuck < 0)
messages.add(id, "Luck is negative", "", CSMDoc::Message::Severity_Warning);
if (creature.mData.mCombat < 0) if (creature.mData.mCombat < 0)
messages.add(id, "Combat is negative", "", CSMDoc::Message::Severity_Warning); messages.add(id, "Combat is negative", "", CSMDoc::Message::Severity_Warning);

@ -1315,30 +1315,9 @@ QVariant CSMWorld::CreatureAttributesRefIdAdapter::getNestedData(
if (subColIndex == 0) if (subColIndex == 0)
return subRowIndex; return subRowIndex;
else if (subColIndex == 1) else if (subColIndex == 1 && subRowIndex > 0 && subRowIndex < ESM::Attribute::Length)
switch (subRowIndex) return creature.mData.mAttributes[subRowIndex];
{ return QVariant(); // throw an exception here?
case 0:
return creature.mData.mStrength;
case 1:
return creature.mData.mIntelligence;
case 2:
return creature.mData.mWillpower;
case 3:
return creature.mData.mAgility;
case 4:
return creature.mData.mSpeed;
case 5:
return creature.mData.mEndurance;
case 6:
return creature.mData.mPersonality;
case 7:
return creature.mData.mLuck;
default:
return QVariant(); // throw an exception here?
}
else
return QVariant(); // throw an exception here?
} }
void CSMWorld::CreatureAttributesRefIdAdapter::setNestedData( void CSMWorld::CreatureAttributesRefIdAdapter::setNestedData(
@ -1346,42 +1325,14 @@ void CSMWorld::CreatureAttributesRefIdAdapter::setNestedData(
{ {
Record<ESM::Creature>& record Record<ESM::Creature>& record
= static_cast<Record<ESM::Creature>&>(data.getRecord(RefIdData::LocalIndex(row, UniversalId::Type_Creature))); = static_cast<Record<ESM::Creature>&>(data.getRecord(RefIdData::LocalIndex(row, UniversalId::Type_Creature)));
ESM::Creature creature = record.get();
if (subColIndex == 1) if (subColIndex == 1 && subRowIndex > 0 && subRowIndex < ESM::Attribute::Length)
switch (subRowIndex) {
{ ESM::Creature creature = record.get();
case 0: creature.mData.mAttributes[subRowIndex] = value.toInt();
creature.mData.mStrength = value.toInt(); record.setModified(creature);
break; }
case 1: // throw an exception here?
creature.mData.mIntelligence = value.toInt();
break;
case 2:
creature.mData.mWillpower = value.toInt();
break;
case 3:
creature.mData.mAgility = value.toInt();
break;
case 4:
creature.mData.mSpeed = value.toInt();
break;
case 5:
creature.mData.mEndurance = value.toInt();
break;
case 6:
creature.mData.mPersonality = value.toInt();
break;
case 7:
creature.mData.mLuck = value.toInt();
break;
default:
return; // throw an exception here?
}
else
return; // throw an exception here?
record.setModified(creature);
} }
int CSMWorld::CreatureAttributesRefIdAdapter::getNestedColumnsCount( int CSMWorld::CreatureAttributesRefIdAdapter::getNestedColumnsCount(

@ -127,14 +127,8 @@ namespace MWClass
MWWorld::LiveCellRef<ESM::Creature>* ref = ptr.get<ESM::Creature>(); MWWorld::LiveCellRef<ESM::Creature>* ref = ptr.get<ESM::Creature>();
// creature stats // creature stats
data->mCreatureStats.setAttribute(ESM::Attribute::Strength, ref->mBase->mData.mStrength); for (size_t i = 0; i < ref->mBase->mData.mAttributes.size(); ++i)
data->mCreatureStats.setAttribute(ESM::Attribute::Intelligence, ref->mBase->mData.mIntelligence); data->mCreatureStats.setAttribute(ESM::Attribute::indexToRefId(i), ref->mBase->mData.mAttributes[i]);
data->mCreatureStats.setAttribute(ESM::Attribute::Willpower, ref->mBase->mData.mWillpower);
data->mCreatureStats.setAttribute(ESM::Attribute::Agility, ref->mBase->mData.mAgility);
data->mCreatureStats.setAttribute(ESM::Attribute::Speed, ref->mBase->mData.mSpeed);
data->mCreatureStats.setAttribute(ESM::Attribute::Endurance, ref->mBase->mData.mEndurance);
data->mCreatureStats.setAttribute(ESM::Attribute::Personality, ref->mBase->mData.mPersonality);
data->mCreatureStats.setAttribute(ESM::Attribute::Luck, ref->mBase->mData.mLuck);
data->mCreatureStats.setHealth(static_cast<float>(ref->mBase->mData.mHealth)); data->mCreatureStats.setHealth(static_cast<float>(ref->mBase->mData.mHealth));
data->mCreatureStats.setMagicka(static_cast<float>(ref->mBase->mData.mMana)); data->mCreatureStats.setMagicka(static_cast<float>(ref->mBase->mData.mMana));
data->mCreatureStats.setFatigue(static_cast<float>(ref->mBase->mData.mFatigue)); data->mCreatureStats.setFatigue(static_cast<float>(ref->mBase->mData.mFatigue));

@ -93,7 +93,7 @@ namespace ESM
mName = esm.getHString(); mName = esm.getHString();
break; break;
case fourCC("DATA"): case fourCC("DATA"):
esm.getHTSized<12>(mData); esm.getHT(mData.mFlags, mData.mX, mData.mY);
hasData = true; hasData = true;
break; break;
case SREC_DELE: case SREC_DELE:
@ -144,7 +144,7 @@ namespace ESM
mWater = waterLevel; mWater = waterLevel;
break; break;
case fourCC("AMBI"): case fourCC("AMBI"):
esm.getHTSized<16>(mAmbi); esm.getHT(mAmbi.mAmbient, mAmbi.mSunlight, mAmbi.mFog, mAmbi.mFogDensity);
mHasAmbi = true; mHasAmbi = true;
break; break;
case fourCC("RGNN"): case fourCC("RGNN"):

@ -96,8 +96,8 @@ namespace ESM
struct DATAstruct struct DATAstruct
{ {
int mFlags{ 0 }; int32_t mFlags{ 0 };
int mX{ 0 }, mY{ 0 }; int32_t mX{ 0 }, mY{ 0 };
}; };
struct AMBIstruct struct AMBIstruct
@ -132,11 +132,11 @@ namespace ESM
float mWater; // Water level float mWater; // Water level
bool mWaterInt; bool mWaterInt;
int mMapColor; int32_t mMapColor;
// Counter for RefNums. This is only used during content file editing and has no impact on gameplay. // Counter for RefNums. This is only used during content file editing and has no impact on gameplay.
// It prevents overwriting previous refNums, even if they were deleted. // It prevents overwriting previous refNums, even if they were deleted.
// as that would collide with refs when a content file is upgraded. // as that would collide with refs when a content file is upgraded.
int mRefNumCounter; int32_t mRefNumCounter;
// References "leased" from another cell (i.e. a different cell // References "leased" from another cell (i.e. a different cell
// introduced this ref, and it has been moved here by a plugin) // introduced this ref, and it has been moved here by a plugin)

@ -48,7 +48,8 @@ namespace ESM
mScript = esm.getRefId(); mScript = esm.getRefId();
break; break;
case fourCC("NPDT"): case fourCC("NPDT"):
esm.getHTSized<96>(mData); esm.getHT(mData.mType, mData.mLevel, mData.mAttributes, mData.mHealth, mData.mMana, mData.mFatigue,
mData.mSoul, mData.mCombat, mData.mMagic, mData.mStealth, mData.mAttack, mData.mGold);
hasNpdt = true; hasNpdt = true;
break; break;
case fourCC("FLAG"): case fourCC("FLAG"):
@ -139,8 +140,7 @@ namespace ESM
mRecordFlags = 0; mRecordFlags = 0;
mData.mType = 0; mData.mType = 0;
mData.mLevel = 0; mData.mLevel = 0;
mData.mStrength = mData.mIntelligence = mData.mWillpower = mData.mAgility = mData.mSpeed = mData.mEndurance mData.mAttributes.fill(0);
= mData.mPersonality = mData.mLuck = 0;
mData.mHealth = mData.mMana = mData.mFatigue = 0; mData.mHealth = mData.mMana = mData.mFatigue = 0;
mData.mSoul = 0; mData.mSoul = 0;
mData.mCombat = mData.mMagic = mData.mStealth = 0; mData.mCombat = mData.mMagic = mData.mStealth = 0;

@ -1,6 +1,7 @@
#ifndef OPENMW_ESM_CREA_H #ifndef OPENMW_ESM_CREA_H
#define OPENMW_ESM_CREA_H #define OPENMW_ESM_CREA_H
#include <array>
#include <string> #include <string>
#include "aipackage.hpp" #include "aipackage.hpp"
@ -8,6 +9,7 @@
#include "spelllist.hpp" #include "spelllist.hpp"
#include "transport.hpp" #include "transport.hpp"
#include "components/esm/attr.hpp"
#include "components/esm/defs.hpp" #include "components/esm/defs.hpp"
#include "components/esm/refid.hpp" #include "components/esm/refid.hpp"
@ -52,30 +54,30 @@ namespace ESM
struct NPDTstruct struct NPDTstruct
{ {
int mType; int32_t mType;
// For creatures we obviously have to use ints, not shorts and // For creatures we obviously have to use ints, not shorts and
// bytes like we use for NPCs.... this file format just makes so // bytes like we use for NPCs.... this file format just makes so
// much sense! (Still, _much_ easier to decode than the NIFs.) // much sense! (Still, _much_ easier to decode than the NIFs.)
int mLevel; int32_t mLevel;
int mStrength, mIntelligence, mWillpower, mAgility, mSpeed, mEndurance, mPersonality, mLuck; std::array<int32_t, Attribute::Length> mAttributes;
int mHealth, mMana, mFatigue; // Stats int32_t mHealth, mMana, mFatigue; // Stats
int mSoul; // The creatures soul value (used with soul gems.) int32_t mSoul; // The creatures soul value (used with soul gems.)
// Creatures have generalized combat, magic and stealth stats which substitute for // Creatures have generalized combat, magic and stealth stats which substitute for
// the specific skills (in the same way as specializations). // the specific skills (in the same way as specializations).
int mCombat, mMagic, mStealth; int32_t mCombat, mMagic, mStealth;
int mAttack[6]; // AttackMin1, AttackMax1, ditto2, ditto3 int32_t mAttack[6]; // AttackMin1, AttackMax1, ditto2, ditto3
int mGold; int32_t mGold;
}; // 96 byte }; // 96 byte
NPDTstruct mData; NPDTstruct mData;
int mBloodType; int32_t mBloodType;
unsigned char mFlags; unsigned char mFlags;
float mScale; float mScale;
unsigned int mRecordFlags; uint32_t mRecordFlags;
RefId mId, mScript; RefId mId, mScript;
std::string mModel; std::string mModel;
std::string mName; std::string mName;

@ -7,12 +7,12 @@
namespace ESM namespace ESM
{ {
int& Faction::FADTstruct::getSkill(int index, bool) int32_t& Faction::FADTstruct::getSkill(size_t index, bool)
{ {
return mSkills.at(index); return mSkills.at(index);
} }
int Faction::FADTstruct::getSkill(int index, bool) const int32_t Faction::FADTstruct::getSkill(size_t index, bool) const
{ {
return mSkills.at(index); return mSkills.at(index);
} }
@ -23,10 +23,10 @@ namespace ESM
mRecordFlags = esm.getRecordFlags(); mRecordFlags = esm.getRecordFlags();
mReactions.clear(); mReactions.clear();
for (int i = 0; i < 10; ++i) for (auto& rank : mRanks)
mRanks[i].clear(); rank.clear();
int rankCounter = 0; size_t rankCounter = 0;
bool hasName = false; bool hasName = false;
bool hasData = false; bool hasData = false;
while (esm.hasMoreSubs()) while (esm.hasMoreSubs())
@ -42,7 +42,7 @@ namespace ESM
mName = esm.getHString(); mName = esm.getHString();
break; break;
case fourCC("RNAM"): case fourCC("RNAM"):
if (rankCounter >= 10) if (rankCounter >= mRanks.size())
esm.fail("Rank out of range"); esm.fail("Rank out of range");
mRanks[rankCounter++] = esm.getHString(); mRanks[rankCounter++] = esm.getHString();
break; break;
@ -55,7 +55,7 @@ namespace ESM
case fourCC("ANAM"): case fourCC("ANAM"):
{ {
ESM::RefId faction = esm.getRefId(); ESM::RefId faction = esm.getRefId();
int reaction; int32_t reaction;
esm.getHNT(reaction, "INTV"); esm.getHNT(reaction, "INTV");
// Prefer the lowest reaction in case a faction is listed multiple times // Prefer the lowest reaction in case a faction is listed multiple times
auto it = mReactions.find(faction); auto it = mReactions.find(faction);
@ -93,12 +93,12 @@ namespace ESM
esm.writeHNOCString("FNAM", mName); esm.writeHNOCString("FNAM", mName);
for (int i = 0; i < 10; i++) for (const auto& rank : mRanks)
{ {
if (mRanks[i].empty()) if (rank.empty())
break; break;
esm.writeHNString("RNAM", mRanks[i], 32); esm.writeHNString("RNAM", rank, 32);
} }
esm.writeHNT("FADT", mData, 240); esm.writeHNT("FADT", mData, 240);

@ -21,15 +21,15 @@ namespace ESM
// Requirements for each rank // Requirements for each rank
struct RankData struct RankData
{ {
int mAttribute1, mAttribute2; // Attribute level int32_t mAttribute1, mAttribute2; // Attribute level
// Skill level (faction skills given in // Skill level (faction skills given in
// skillID below.) You need one skill at // skillID below.) You need one skill at
// level 'mPrimarySkill' and two skills at level // level 'mPrimarySkill' and two skills at level
// 'mFavouredSkill' to advance to this rank. // 'mFavouredSkill' to advance to this rank.
int mPrimarySkill, mFavouredSkill; int32_t mPrimarySkill, mFavouredSkill;
int mFactReaction; // Reaction from faction members int32_t mFactReaction; // Reaction from faction members
}; };
struct Faction struct Faction
@ -39,33 +39,33 @@ namespace ESM
/// Return a string descriptor for this record type. Currently used for debugging / error logs only. /// Return a string descriptor for this record type. Currently used for debugging / error logs only.
static std::string_view getRecordType() { return "Faction"; } static std::string_view getRecordType() { return "Faction"; }
unsigned int mRecordFlags; uint32_t mRecordFlags;
std::string mName; std::string mName;
RefId mId; RefId mId;
struct FADTstruct struct FADTstruct
{ {
// Which attributes we like // Which attributes we like
std::array<int, 2> mAttribute; std::array<int32_t, 2> mAttribute;
std::array<RankData, 10> mRankData; std::array<RankData, 10> mRankData;
std::array<int, 7> mSkills; // IDs of skills this faction require std::array<int32_t, 7> mSkills; // IDs of skills this faction require
// Each element will either contain an Skill index, or -1. // Each element will either contain an Skill index, or -1.
int mIsHidden; // 1 - hidden from player int32_t mIsHidden; // 1 - hidden from player
int& getSkill(int index, bool ignored = false); int32_t& getSkill(size_t index, bool ignored = false);
///< Throws an exception for invalid values of \a index. ///< Throws an exception for invalid values of \a index.
int getSkill(int index, bool ignored = false) const; int32_t getSkill(size_t index, bool ignored = false) const;
///< Throws an exception for invalid values of \a index. ///< Throws an exception for invalid values of \a index.
}; // 240 bytes }; // 240 bytes
FADTstruct mData; FADTstruct mData;
// <Faction ID, Reaction> // <Faction ID, Reaction>
std::map<ESM::RefId, int> mReactions; std::map<ESM::RefId, int32_t> mReactions;
// Name of faction ranks (may be empty for NPC factions) // Name of faction ranks (may be empty for NPC factions)
std::array<std::string, 10> mRanks; std::array<std::string, 10> mRanks;

@ -23,7 +23,8 @@ namespace ESM
switch (esm.retSubName().toInt()) switch (esm.retSubName().toInt())
{ {
case fourCC("DATA"): case fourCC("DATA"):
esm.getHTSized<12>(mData); esm.getHT(mData.mUnknown1, mData.mDisposition, mData.mRank, mData.mGender, mData.mPCrank,
mData.mUnknown2);
break; break;
case fourCC("ONAM"): case fourCC("ONAM"):
mActor = esm.getRefId(); mActor = esm.getRefId();

@ -35,11 +35,11 @@ namespace ESM
struct DATAstruct struct DATAstruct
{ {
int mUnknown1 = 0; int32_t mUnknown1 = 0;
union union
{ {
int mDisposition = 0; // Used for dialogue responses int32_t mDisposition = 0; // Used for dialogue responses
int mJournalIndex; // Used for journal entries int32_t mJournalIndex; // Used for journal entries
}; };
signed char mRank = -1; // Rank of NPC signed char mRank = -1; // Rank of NPC
signed char mGender = Gender::NA; // See Gender enum signed char mGender = Gender::NA; // See Gender enum

@ -28,7 +28,7 @@ namespace ESM
mName = esm.getHString(); mName = esm.getHString();
break; break;
case fourCC("IRDT"): case fourCC("IRDT"):
esm.getHTSized<56>(mData); esm.getHT(mData.mWeight, mData.mValue, mData.mEffectID, mData.mSkills, mData.mAttributes);
hasData = true; hasData = true;
break; break;
case fourCC("SCRI"): case fourCC("SCRI"):

@ -26,14 +26,14 @@ namespace ESM
struct IRDTstruct struct IRDTstruct
{ {
float mWeight; float mWeight;
int mValue; int32_t mValue;
int mEffectID[4]; // Effect, -1 means none int32_t mEffectID[4]; // Effect, -1 means none
int mSkills[4]; // SkillEnum related to effect int32_t mSkills[4]; // SkillEnum related to effect
int mAttributes[4]; // Attribute related to effect int32_t mAttributes[4]; // Attribute related to effect
}; };
IRDTstruct mData; IRDTstruct mData;
unsigned int mRecordFlags; uint32_t mRecordFlags;
RefId mId, mScript; RefId mId, mScript;
std::string mName, mModel, mIcon; std::string mName, mModel, mIcon;

@ -31,7 +31,7 @@ namespace ESM
mIcon = esm.getHString(); mIcon = esm.getHString();
break; break;
case fourCC("LHDT"): case fourCC("LHDT"):
esm.getHTSized<24>(mData); esm.getHT(mData.mWeight, mData.mValue, mData.mTime, mData.mRadius, mData.mColor, mData.mFlags);
hasData = true; hasData = true;
break; break;
case fourCC("SCRI"): case fourCC("SCRI"):

@ -41,16 +41,16 @@ namespace ESM
struct LHDTstruct struct LHDTstruct
{ {
float mWeight; float mWeight;
int mValue; int32_t mValue;
int mTime; // Duration int32_t mTime; // Duration
int mRadius; int32_t mRadius;
unsigned int mColor; // 4-byte rgba value uint32_t mColor; // 4-byte rgba value
int mFlags; int32_t mFlags;
}; // Size = 24 bytes }; // Size = 24 bytes
LHDTstruct mData; LHDTstruct mData;
unsigned int mRecordFlags; uint32_t mRecordFlags;
std::string mModel, mIcon, mName; std::string mModel, mIcon, mName;
ESM::RefId mId, mSound, mScript; ESM::RefId mId, mSound, mScript;

@ -28,7 +28,7 @@ namespace ESM
mName = esm.getHString(); mName = esm.getHString();
break; break;
case fourCC("LKDT"): case fourCC("LKDT"):
esm.getHTSized<16>(mData); esm.getHT(mData.mWeight, mData.mValue, mData.mQuality, mData.mUses);
hasData = true; hasData = true;
break; break;
case fourCC("SCRI"): case fourCC("SCRI"):

@ -22,14 +22,14 @@ namespace ESM
struct Data struct Data
{ {
float mWeight; float mWeight;
int mValue; int32_t mValue;
float mQuality; float mQuality;
int mUses; int32_t mUses;
}; // Size = 16 }; // Size = 16
Data mData; Data mData;
unsigned int mRecordFlags; uint32_t mRecordFlags;
RefId mId, mScript; RefId mId, mScript;
std::string mName, mModel, mIcon; std::string mName, mModel, mIcon;

Loading…
Cancel
Save