Merge branch 'fixed' into 'master'

Replace more variable width integers in ESM code

See merge request OpenMW/openmw!3518
This commit is contained in:
jvoisin 2023-11-05 16:36:13 +00:00
commit e88f8e09c3
46 changed files with 190 additions and 191 deletions

View file

@ -9,15 +9,14 @@ namespace ESSImport
void convertInventory(const Inventory& inventory, ESM::InventoryState& state) void convertInventory(const Inventory& inventory, ESM::InventoryState& state)
{ {
int index = 0; uint32_t index = 0;
for (const auto& item : inventory.mItems) for (const auto& item : inventory.mItems)
{ {
ESM::ObjectState objstate; ESM::ObjectState objstate;
objstate.blank(); objstate.blank();
objstate.mRef = item; objstate.mRef = item;
objstate.mRef.mRefID = ESM::RefId::stringRefId(item.mId); objstate.mRef.mRefID = ESM::RefId::stringRefId(item.mId);
objstate.mCount = std::abs(item.mCount); // restocking items have negative count in the savefile objstate.mCount = item.mCount;
// openmw handles them differently, so no need to set any flags
state.mItems.push_back(objstate); state.mItems.push_back(objstate);
if (item.mRelativeEquipmentSlot != -1) if (item.mRelativeEquipmentSlot != -1)
// Note we should really write the absolute slot here, which we do not know about // Note we should really write the absolute slot here, which we do not know about

View file

@ -111,12 +111,12 @@ MWWorld::ContainerStoreIterator MWWorld::ContainerStore::getState(
} }
void MWWorld::ContainerStore::storeEquipmentState( void MWWorld::ContainerStore::storeEquipmentState(
const MWWorld::LiveCellRefBase& ref, int index, ESM::InventoryState& inventory) const const MWWorld::LiveCellRefBase& ref, size_t index, ESM::InventoryState& inventory) const
{ {
} }
void MWWorld::ContainerStore::readEquipmentState( void MWWorld::ContainerStore::readEquipmentState(
const MWWorld::ContainerStoreIterator& iter, int index, const ESM::InventoryState& inventory) const MWWorld::ContainerStoreIterator& iter, size_t index, const ESM::InventoryState& inventory)
{ {
} }
@ -128,7 +128,7 @@ void MWWorld::ContainerStore::storeState(const LiveCellRef<T>& ref, ESM::ObjectS
template <typename T> template <typename T>
void MWWorld::ContainerStore::storeStates( void MWWorld::ContainerStore::storeStates(
const CellRefList<T>& collection, ESM::InventoryState& inventory, int& index, bool equipable) const const CellRefList<T>& collection, ESM::InventoryState& inventory, size_t& index, bool equipable) const
{ {
for (const LiveCellRef<T>& liveCellRef : collection.mList) for (const LiveCellRef<T>& liveCellRef : collection.mList)
{ {
@ -926,7 +926,7 @@ void MWWorld::ContainerStore::writeState(ESM::InventoryState& state) const
{ {
state.mItems.clear(); state.mItems.clear();
int index = 0; size_t index = 0;
storeStates(potions, state, index); storeStates(potions, state, index);
storeStates(appas, state, index); storeStates(appas, state, index);
storeStates(armors, state, index, true); storeStates(armors, state, index, true);
@ -947,12 +947,12 @@ void MWWorld::ContainerStore::readState(const ESM::InventoryState& inventory)
mModified = true; mModified = true;
mResolved = true; mResolved = true;
int index = 0; size_t index = 0;
for (const ESM::ObjectState& state : inventory.mItems) for (const ESM::ObjectState& state : inventory.mItems)
{ {
int type = MWBase::Environment::get().getESMStore()->find(state.mRef.mRefID); int type = MWBase::Environment::get().getESMStore()->find(state.mRef.mRefID);
int thisIndex = index++; size_t thisIndex = index++;
switch (type) switch (type)
{ {

View file

@ -161,16 +161,16 @@ namespace MWWorld
void storeState(const LiveCellRef<T>& ref, ESM::ObjectState& state) const; void storeState(const LiveCellRef<T>& ref, ESM::ObjectState& state) const;
template <typename T> template <typename T>
void storeStates( void storeStates(const CellRefList<T>& collection, ESM::InventoryState& inventory, size_t& index,
const CellRefList<T>& collection, ESM::InventoryState& inventory, int& index, bool equipable = false) const; bool equipable = false) const;
void updateRechargingItems(); void updateRechargingItems();
virtual void storeEquipmentState( virtual void storeEquipmentState(
const MWWorld::LiveCellRefBase& ref, int index, ESM::InventoryState& inventory) const; const MWWorld::LiveCellRefBase& ref, size_t index, ESM::InventoryState& inventory) const;
virtual void readEquipmentState( virtual void readEquipmentState(
const MWWorld::ContainerStoreIterator& iter, int index, const ESM::InventoryState& inventory); const MWWorld::ContainerStoreIterator& iter, size_t index, const ESM::InventoryState& inventory);
public: public:
ContainerStore(); ContainerStore();

View file

@ -46,32 +46,32 @@ void MWWorld::InventoryStore::initSlots(TSlots& slots_)
} }
void MWWorld::InventoryStore::storeEquipmentState( void MWWorld::InventoryStore::storeEquipmentState(
const MWWorld::LiveCellRefBase& ref, int index, ESM::InventoryState& inventory) const const MWWorld::LiveCellRefBase& ref, size_t index, ESM::InventoryState& inventory) const
{ {
for (int i = 0; i < static_cast<int>(mSlots.size()); ++i) for (int32_t i = 0; i < MWWorld::InventoryStore::Slots; ++i)
{
if (mSlots[i].getType() != -1 && mSlots[i]->getBase() == &ref) if (mSlots[i].getType() != -1 && mSlots[i]->getBase() == &ref)
{ inventory.mEquipmentSlots[static_cast<uint32_t>(index)] = i;
inventory.mEquipmentSlots[index] = i; }
}
if (mSelectedEnchantItem.getType() != -1 && mSelectedEnchantItem->getBase() == &ref) if (mSelectedEnchantItem.getType() != -1 && mSelectedEnchantItem->getBase() == &ref)
inventory.mSelectedEnchantItem = index; inventory.mSelectedEnchantItem = index;
} }
void MWWorld::InventoryStore::readEquipmentState( void MWWorld::InventoryStore::readEquipmentState(
const MWWorld::ContainerStoreIterator& iter, int index, const ESM::InventoryState& inventory) const MWWorld::ContainerStoreIterator& iter, size_t index, const ESM::InventoryState& inventory)
{ {
if (index == inventory.mSelectedEnchantItem) if (index == inventory.mSelectedEnchantItem)
mSelectedEnchantItem = iter; mSelectedEnchantItem = iter;
std::map<int, int>::const_iterator found = inventory.mEquipmentSlots.find(index); auto found = inventory.mEquipmentSlots.find(index);
if (found != inventory.mEquipmentSlots.end()) if (found != inventory.mEquipmentSlots.end())
{ {
if (found->second < 0 || found->second >= MWWorld::InventoryStore::Slots) if (found->second < 0 || found->second >= MWWorld::InventoryStore::Slots)
throw std::runtime_error("Invalid slot index in inventory state"); throw std::runtime_error("Invalid slot index in inventory state");
// make sure the item can actually be equipped in this slot // make sure the item can actually be equipped in this slot
int slot = found->second; int32_t slot = found->second;
std::pair<std::vector<int>, bool> allowedSlots = iter->getClass().getEquipmentSlots(*iter); std::pair<std::vector<int>, bool> allowedSlots = iter->getClass().getEquipmentSlots(*iter);
if (!allowedSlots.first.size()) if (!allowedSlots.first.size())
return; return;

View file

@ -81,9 +81,9 @@ namespace MWWorld
void fireEquipmentChangedEvent(); void fireEquipmentChangedEvent();
void storeEquipmentState( void storeEquipmentState(
const MWWorld::LiveCellRefBase& ref, int index, ESM::InventoryState& inventory) const override; const MWWorld::LiveCellRefBase& ref, size_t index, ESM::InventoryState& inventory) const override;
void readEquipmentState( void readEquipmentState(
const MWWorld::ContainerStoreIterator& iter, int index, const ESM::InventoryState& inventory) override; const MWWorld::ContainerStoreIterator& iter, size_t index, const ESM::InventoryState& inventory) override;
ContainerStoreIterator findSlot(int slot) const; ContainerStoreIterator findSlot(int slot) const;

View file

@ -16,10 +16,10 @@ namespace ESM
struct AIData struct AIData
{ {
unsigned short mHello; // This is the base value for greeting distance [0, 65535] uint16_t mHello; // This is the base value for greeting distance [0, 65535]
unsigned char mFight, mFlee, mAlarm; // These are probabilities [0, 100] unsigned char mFight, mFlee, mAlarm; // These are probabilities [0, 100]
char mU1, mU2, mU3; // Unknown values char mU1, mU2, mU3; // Unknown values
int mServices; // See the Services enum int32_t mServices; // See the Services enum
void blank(); void blank();
///< Set record to default state (does not touch the ID). ///< Set record to default state (does not touch the ID).
@ -27,8 +27,8 @@ namespace ESM
struct AIWander struct AIWander
{ {
short mDistance; int16_t mDistance;
short mDuration; int16_t mDuration;
unsigned char mTimeOfDay; unsigned char mTimeOfDay;
unsigned char mIdle[8]; unsigned char mIdle[8];
unsigned char mShouldRepeat; unsigned char mShouldRepeat;
@ -44,7 +44,7 @@ namespace ESM
struct AITarget struct AITarget
{ {
float mX, mY, mZ; float mX, mY, mZ;
short mDuration; int16_t mDuration;
NAME32 mId; NAME32 mId;
unsigned char mShouldRepeat; unsigned char mShouldRepeat;
unsigned char mPadding; unsigned char mPadding;

View file

@ -196,7 +196,7 @@ namespace ESM
int count = 0; int count = 0;
while (esm.isNextSub("AIPK")) while (esm.isNextSub("AIPK"))
{ {
int type; int32_t type;
esm.getHT(type); esm.getHT(type);
mPackages.emplace_back(); mPackages.emplace_back();

View file

@ -9,7 +9,7 @@ namespace ESM
struct CreatureLevListState final : public ObjectState struct CreatureLevListState final : public ObjectState
{ {
int mSpawnActorId; int32_t mSpawnActorId;
bool mSpawn; bool mSpawn;
void load(ESMReader& esm) override; void load(ESMReader& esm) override;

View file

@ -47,9 +47,8 @@ namespace ESM
std::vector<int> mSummonGraveyard; std::vector<int> mSummonGraveyard;
TimeStamp mTradeTime; TimeStamp mTradeTime;
int mGoldPool; int32_t mGoldPool;
int mActorId; int32_t mActorId;
// int mHitAttemptActorId;
enum Flags enum Flags
{ {

View file

@ -24,14 +24,14 @@ namespace ESM
Flag_Global = 4 // make available from main menu (i.e. not location specific) Flag_Global = 4 // make available from main menu (i.e. not location specific)
}; };
unsigned int mRecordFlags; uint32_t mRecordFlags;
RefId mId; RefId mId;
std::string mDescription; std::string mDescription;
std::string mScriptText; std::string mScriptText;
unsigned int mFlags; uint32_t mFlags;
void load(ESMReader& esm, bool& isDeleted); void load(ESMReader& esm, bool& isDeleted);
void save(ESMWriter& esm, bool isDeleted = false) const; void save(ESMWriter& esm, bool isDeleted = false) const;

View file

@ -9,7 +9,7 @@ namespace ESM
struct DoorState final : public ObjectState struct DoorState final : public ObjectState
{ {
int mDoorState = 0; int32_t mDoorState = 0;
void load(ESMReader& esm) override; void load(ESMReader& esm) override;
void save(ESMWriter& esm, bool inInventory = false) const override; void save(ESMWriter& esm, bool inInventory = false) const override;

View file

@ -17,7 +17,7 @@ namespace ESM
static constexpr std::string_view getRecordType() { return "Filter"; } static constexpr std::string_view getRecordType() { return "Filter"; }
unsigned int mRecordFlags; uint32_t mRecordFlags;
RefId mId; RefId mId;
std::string mDescription; std::string mDescription;

View file

@ -7,22 +7,25 @@
namespace ESM namespace ESM
{ {
namespace
{
constexpr uint32_t sInvalidSlot = static_cast<uint32_t>(-1);
}
void InventoryState::load(ESMReader& esm) void InventoryState::load(ESMReader& esm)
{ {
// obsolete // obsolete
int index = 0; uint32_t index = 0;
while (esm.isNextSub("IOBJ")) while (esm.isNextSub("IOBJ"))
{ {
int unused; // no longer used esm.skipHT<int32_t>();
esm.getHT(unused);
ObjectState state; ObjectState state;
// obsolete // obsolete
if (esm.isNextSub("SLOT")) if (esm.isNextSub("SLOT"))
{ {
int slot; int32_t slot;
esm.getHT(slot); esm.getHT(slot);
mEquipmentSlots[index] = slot; mEquipmentSlots[index] = slot;
} }
@ -38,9 +41,9 @@ namespace ESM
++index; ++index;
} }
int itemsCount = 0; uint32_t itemsCount = 0;
esm.getHNOT(itemsCount, "ICNT"); esm.getHNOT(itemsCount, "ICNT");
for (int i = 0; i < itemsCount; i++) for (; itemsCount > 0; --itemsCount)
{ {
ObjectState state; ObjectState state;
@ -62,7 +65,7 @@ namespace ESM
{ {
// Get its name // Get its name
ESM::RefId id = esm.getRefId(); ESM::RefId id = esm.getRefId();
int count; int32_t count;
std::string parentGroup; std::string parentGroup;
// Then get its count // Then get its count
esm.getHNT(count, "COUN"); esm.getHNT(count, "COUN");
@ -91,9 +94,9 @@ namespace ESM
while (esm.isNextSub("EQUI")) while (esm.isNextSub("EQUI"))
{ {
esm.getSubHeader(); esm.getSubHeader();
int equipIndex; int32_t equipIndex;
esm.getT(equipIndex); esm.getT(equipIndex);
int slot; int32_t slot;
esm.getT(slot); esm.getT(slot);
mEquipmentSlots[equipIndex] = slot; mEquipmentSlots[equipIndex] = slot;
} }
@ -101,20 +104,24 @@ namespace ESM
if (esm.isNextSub("EQIP")) if (esm.isNextSub("EQIP"))
{ {
esm.getSubHeader(); esm.getSubHeader();
int slotsCount = 0; uint32_t slotsCount = 0;
esm.getT(slotsCount); esm.getT(slotsCount);
for (int i = 0; i < slotsCount; i++) for (; slotsCount > 0; --slotsCount)
{ {
int equipIndex; int32_t equipIndex;
esm.getT(equipIndex); esm.getT(equipIndex);
int slot; int32_t slot;
esm.getT(slot); esm.getT(slot);
mEquipmentSlots[equipIndex] = slot; mEquipmentSlots[equipIndex] = slot;
} }
} }
mSelectedEnchantItem = -1; uint32_t selectedEnchantItem = sInvalidSlot;
esm.getHNOT(mSelectedEnchantItem, "SELE"); esm.getHNOT(selectedEnchantItem, "SELE");
if (selectedEnchantItem == sInvalidSlot)
mSelectedEnchantItem.reset();
else
mSelectedEnchantItem = selectedEnchantItem;
// Old saves had restocking levelled items in a special map // Old saves had restocking levelled items in a special map
// This turns items from that map into negative quantities // This turns items from that map into negative quantities
@ -132,7 +139,7 @@ namespace ESM
void InventoryState::save(ESMWriter& esm) const void InventoryState::save(ESMWriter& esm) const
{ {
int itemsCount = static_cast<int>(mItems.size()); uint32_t itemsCount = static_cast<uint32_t>(mItems.size());
if (itemsCount > 0) if (itemsCount > 0)
{ {
esm.writeHNT("ICNT", itemsCount); esm.writeHNT("ICNT", itemsCount);
@ -149,34 +156,32 @@ namespace ESM
esm.writeHNString("LGRP", it->first.second); esm.writeHNString("LGRP", it->first.second);
} }
for (TEffectMagnitudes::const_iterator it = mPermanentMagicEffectMagnitudes.begin(); for (const auto& [id, params] : mPermanentMagicEffectMagnitudes)
it != mPermanentMagicEffectMagnitudes.end(); ++it)
{ {
esm.writeHNRefId("MAGI", it->first); esm.writeHNRefId("MAGI", id);
const std::vector<std::pair<float, float>>& params = it->second; for (const auto& [rand, mult] : params)
for (std::vector<std::pair<float, float>>::const_iterator pIt = params.begin(); pIt != params.end(); ++pIt)
{ {
esm.writeHNT("RAND", pIt->first); esm.writeHNT("RAND", rand);
esm.writeHNT("MULT", pIt->second); esm.writeHNT("MULT", mult);
} }
} }
int slotsCount = static_cast<int>(mEquipmentSlots.size()); uint32_t slotsCount = static_cast<uint32_t>(mEquipmentSlots.size());
if (slotsCount > 0) if (slotsCount > 0)
{ {
esm.startSubRecord("EQIP"); esm.startSubRecord("EQIP");
esm.writeT(slotsCount); esm.writeT(slotsCount);
for (std::map<int, int>::const_iterator it = mEquipmentSlots.begin(); it != mEquipmentSlots.end(); ++it) for (const auto& [index, slot] : mEquipmentSlots)
{ {
esm.writeT(it->first); esm.writeT(index);
esm.writeT(it->second); esm.writeT(slot);
} }
esm.endRecord("EQIP"); esm.endRecord("EQIP");
} }
if (mSelectedEnchantItem != -1) if (mSelectedEnchantItem)
esm.writeHNT("SELE", mSelectedEnchantItem); esm.writeHNT("SELE", *mSelectedEnchantItem);
} }
} }

View file

@ -2,6 +2,7 @@
#define OPENMW_ESM_INVENTORYSTATE_H #define OPENMW_ESM_INVENTORYSTATE_H
#include <map> #include <map>
#include <optional>
#include "objectstate.hpp" #include "objectstate.hpp"
#include <components/esm/refid.hpp> #include <components/esm/refid.hpp>
@ -19,20 +20,15 @@ namespace ESM
std::vector<ObjectState> mItems; std::vector<ObjectState> mItems;
// <Index in mItems, equipment slot> // <Index in mItems, equipment slot>
std::map<int, int> mEquipmentSlots; std::map<uint32_t, int32_t> mEquipmentSlots;
std::map<std::pair<ESM::RefId, std::string>, int> mLevelledItemMap; std::map<std::pair<ESM::RefId, std::string>, int32_t> mLevelledItemMap;
typedef std::map<ESM::RefId, std::vector<std::pair<float, float>>> TEffectMagnitudes; std::map<ESM::RefId, std::vector<std::pair<float, float>>> mPermanentMagicEffectMagnitudes;
TEffectMagnitudes mPermanentMagicEffectMagnitudes;
int mSelectedEnchantItem; // For inventories only std::optional<uint32_t> mSelectedEnchantItem; // For inventories only
InventoryState() virtual ~InventoryState() = default;
: mSelectedEnchantItem(-1)
{
}
virtual ~InventoryState() {}
virtual void load(ESMReader& esm); virtual void load(ESMReader& esm);
virtual void save(ESMWriter& esm) const; virtual void save(ESMWriter& esm) const;

View file

@ -17,7 +17,7 @@ namespace ESM
///< Translate 8bit/24bit code (stored in refNum.mIndex) into a proper refNum ///< Translate 8bit/24bit code (stored in refNum.mIndex) into a proper refNum
void adjustRefNum(RefNum& refNum, const ESMReader& reader) void adjustRefNum(RefNum& refNum, const ESMReader& reader)
{ {
unsigned int local = (refNum.mIndex & 0xff000000) >> 24; uint32_t local = (refNum.mIndex & 0xff000000) >> 24;
// If we have an index value that does not make sense, assume that it was an addition // If we have an index value that does not make sense, assume that it was an addition
// by the present plugin (but a faulty one) // by the present plugin (but a faulty one)
@ -124,7 +124,7 @@ namespace ESM
switch (esm.retSubName().toInt()) switch (esm.retSubName().toInt())
{ {
case fourCC("INTV"): case fourCC("INTV"):
int waterl; int32_t waterl;
esm.getHT(waterl); esm.getHT(waterl);
mWater = static_cast<float>(waterl); mWater = static_cast<float>(waterl);
mWaterInt = true; mWaterInt = true;
@ -192,7 +192,7 @@ namespace ESM
{ {
if (mWaterInt) if (mWaterInt)
{ {
int water = (mWater >= 0) ? (int)(mWater + 0.5) : (int)(mWater - 0.5); int32_t water = (mWater >= 0) ? static_cast<int32_t>(mWater + 0.5) : static_cast<int32_t>(mWater - 0.5);
esm.writeHNT("INTV", water); esm.writeHNT("INTV", water);
} }
else else
@ -218,13 +218,13 @@ namespace ESM
} }
} }
void Cell::saveTempMarker(ESMWriter& esm, int tempCount) const void Cell::saveTempMarker(ESMWriter& esm, int32_t tempCount) const
{ {
if (tempCount != 0) if (tempCount != 0)
esm.writeHNT("NAM0", tempCount); esm.writeHNT("NAM0", tempCount);
} }
void Cell::restore(ESMReader& esm, int iCtx) const void Cell::restore(ESMReader& esm, size_t iCtx) const
{ {
esm.restoreContext(mContextList.at(iCtx)); esm.restoreContext(mContextList.at(iCtx));
} }
@ -321,7 +321,7 @@ namespace ESM
void Cell::blank() void Cell::blank()
{ {
mName = ""; mName.clear();
mRegion = ESM::RefId(); mRegion = ESM::RefId();
mWater = 0; mWater = 0;
mWaterInt = false; mWaterInt = false;

View file

@ -34,7 +34,7 @@ namespace ESM
RefNum mRefNum; RefNum mRefNum;
// Coordinates of target exterior cell // Coordinates of target exterior cell
int mTarget[2]; int32_t mTarget[2];
// The content file format does not support moving objects to an interior cell. // The content file format does not support moving objects to an interior cell.
// The save game format does support moving to interior cells, but uses a different mechanism // The save game format does support moving to interior cells, but uses a different mechanism
@ -153,13 +153,13 @@ namespace ESM
ESMReader& esm, bool saveContext = true); // Load everything, except NAME, DATAstruct and references ESMReader& esm, bool saveContext = true); // Load everything, except NAME, DATAstruct and references
void save(ESMWriter& esm, bool isDeleted = false) const; void save(ESMWriter& esm, bool isDeleted = false) const;
void saveTempMarker(ESMWriter& esm, int tempCount) const; void saveTempMarker(ESMWriter& esm, int32_t tempCount) const;
bool isExterior() const { return !(mData.mFlags & Interior); } bool isExterior() const { return !(mData.mFlags & Interior); }
int getGridX() const { return mData.mX; } int32_t getGridX() const { return mData.mX; }
int getGridY() const { return mData.mY; } int32_t getGridY() const { return mData.mY; }
bool hasWater() const { return ((mData.mFlags & HasWater) != 0) || isExterior(); } bool hasWater() const { return ((mData.mFlags & HasWater) != 0) || isExterior(); }
@ -172,7 +172,7 @@ namespace ESM
// somewhere other than the file system, you need to pre-open the // somewhere other than the file system, you need to pre-open the
// ESMReader, and the filename must match the stored filename // ESMReader, and the filename must match the stored filename
// exactly. // exactly.
void restore(ESMReader& esm, int iCtx) const; void restore(ESMReader& esm, size_t iCtx) const;
std::string getDescription() const; std::string getDescription() const;
///< Return a short string describing the cell (mostly used for debugging/logging purpose) ///< Return a short string describing the cell (mostly used for debugging/logging purpose)

View file

@ -19,7 +19,7 @@ namespace ESM
struct ContItem struct ContItem
{ {
int mCount{ 0 }; int32_t mCount{ 0 };
ESM::RefId mItem; ESM::RefId mItem;
}; };
@ -48,12 +48,12 @@ namespace ESM
Unknown = 8 Unknown = 8
}; };
unsigned int mRecordFlags; uint32_t mRecordFlags;
RefId mId, mScript; RefId mId, mScript;
std::string mName, mModel; std::string mName, mModel;
float mWeight; // Not sure, might be max total weight allowed? float mWeight; // Not sure, might be max total weight allowed?
int mFlags; int32_t mFlags;
InventoryList mInventory; InventoryList mInventory;
void load(ESMReader& esm, bool& isDeleted); void load(ESMReader& esm, bool& isDeleted);

View file

@ -25,7 +25,7 @@ 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 "Global"; } static std::string_view getRecordType() { return "Global"; }
unsigned int mRecordFlags; uint32_t mRecordFlags;
ESM::RefId mId; ESM::RefId mId;
Variant mValue; Variant mValue;

View file

@ -26,7 +26,7 @@ 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 "GameSetting"; } static std::string_view getRecordType() { return "GameSetting"; }
unsigned int mRecordFlags; uint32_t mRecordFlags;
RefId mId; RefId mId;
Variant mValue; Variant mValue;

View file

@ -30,7 +30,7 @@ namespace ESM
break; break;
case fourCC("INDX"): case fourCC("INDX"):
{ {
int length = 0; uint32_t length = 0;
esm.getHT(length); esm.getHT(length);
mList.resize(length); mList.resize(length);
@ -87,12 +87,12 @@ namespace ESM
esm.writeHNT("DATA", mFlags); esm.writeHNT("DATA", mFlags);
esm.writeHNT("NNAM", mChanceNone); esm.writeHNT("NNAM", mChanceNone);
esm.writeHNT<int>("INDX", mList.size()); esm.writeHNT<uint32_t>("INDX", mList.size());
for (std::vector<LevelItem>::const_iterator it = mList.begin(); it != mList.end(); ++it) for (const auto& item : mList)
{ {
esm.writeHNCRefId(recName, it->mId); esm.writeHNCRefId(recName, item.mId);
esm.writeHNT("INTV", it->mLevel); esm.writeHNT("INTV", item.mLevel);
} }
} }

View file

@ -24,15 +24,15 @@ namespace ESM
struct LevelledListBase struct LevelledListBase
{ {
int mFlags; int32_t mFlags;
unsigned char mChanceNone; // Chance that none are selected (0-100) unsigned char mChanceNone; // Chance that none are selected (0-100)
unsigned int mRecordFlags; uint32_t mRecordFlags;
RefId mId; RefId mId;
struct LevelItem struct LevelItem
{ {
RefId mId; RefId mId;
short mLevel; uint16_t mLevel;
}; };
std::vector<LevelItem> mList; std::vector<LevelItem> mList;

View file

@ -29,7 +29,7 @@ namespace ESM
// mId is merely a user friendly name for the texture in the editor. // mId is merely a user friendly name for the texture in the editor.
std::string mTexture; std::string mTexture;
RefId mId; RefId mId;
int mIndex; int32_t mIndex;
void load(ESMReader& esm, bool& isDeleted); void load(ESMReader& esm, bool& isDeleted);
void save(ESMWriter& esm, bool isDeleted = false) const; void save(ESMWriter& esm, bool isDeleted = false) const;

View file

@ -36,7 +36,7 @@ namespace ESM
esm.getSubNameIs("MEDT"); esm.getSubNameIs("MEDT");
esm.getSubHeader(); esm.getSubHeader();
int school; int32_t school;
esm.getT(school); esm.getT(school);
mData.mSchool = MagicSchool::indexToSkillRefId(school); mData.mSchool = MagicSchool::indexToSkillRefId(school);
esm.getT(mData.mBaseCost); esm.getT(mData.mBaseCost);

View file

@ -25,7 +25,7 @@ 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 "MagicEffect"; } static std::string_view getRecordType() { return "MagicEffect"; }
unsigned int mRecordFlags; uint32_t mRecordFlags;
RefId mId; RefId mId;
enum Flags enum Flags
@ -74,9 +74,9 @@ namespace ESM
{ {
RefId mSchool; // Skill id RefId mSchool; // Skill id
float mBaseCost; float mBaseCost;
int mFlags; int32_t mFlags;
// Glow color for enchanted items with this effect // Glow color for enchanted items with this effect
int mRed, mGreen, mBlue; int32_t mRed, mGreen, mBlue;
float mUnknown1; // Called "Size X" in CS float mUnknown1; // Called "Size X" in CS
float mSpeed; // Speed of fired projectile float mSpeed; // Speed of fired projectile
@ -107,7 +107,7 @@ namespace ESM
// there. They can be redefined in mods by setting the name in GMST // there. They can be redefined in mods by setting the name in GMST
// sEffectSummonCreature04/05 creature id in // sEffectSummonCreature04/05 creature id in
// sMagicCreature04ID/05ID. // sMagicCreature04ID/05ID.
int mIndex; int32_t mIndex;
void load(ESMReader& esm, bool& isDeleted); void load(ESMReader& esm, bool& isDeleted);
void save(ESMWriter& esm, bool isDeleted = false) const; void save(ESMWriter& esm, bool isDeleted = false) const;

View file

@ -82,7 +82,7 @@ namespace ESM
break; break;
case fourCC("FLAG"): case fourCC("FLAG"):
hasFlags = true; hasFlags = true;
int flags; int32_t flags;
esm.getHT(flags); esm.getHT(flags);
mFlags = flags & 0xFF; mFlags = flags & 0xFF;
mBloodType = ((flags >> 8) & 0xFF) >> 2; mBloodType = ((flags >> 8) & 0xFF) >> 2;

View file

@ -79,28 +79,28 @@ namespace ESM
struct NPDTstruct52 struct NPDTstruct52
{ {
short mLevel; int16_t mLevel;
unsigned char mStrength, mIntelligence, mWillpower, mAgility, mSpeed, mEndurance, mPersonality, mLuck; unsigned char mStrength, mIntelligence, mWillpower, mAgility, mSpeed, mEndurance, mPersonality, mLuck;
// mSkill can grow up to 200, it must be unsigned // mSkill can grow up to 200, it must be unsigned
std::array<unsigned char, Skill::Length> mSkills; std::array<unsigned char, Skill::Length> mSkills;
char mUnknown1; char mUnknown1;
unsigned short mHealth, mMana, mFatigue; uint16_t mHealth, mMana, mFatigue;
unsigned char mDisposition, mReputation, mRank; unsigned char mDisposition, mReputation, mRank;
char mUnknown2; char mUnknown2;
int mGold; int32_t mGold;
}; // 52 bytes }; // 52 bytes
// Structure for autocalculated characters. // Structure for autocalculated characters.
// This is only used for load and save operations. // This is only used for load and save operations.
struct NPDTstruct12 struct NPDTstruct12
{ {
short mLevel; int16_t mLevel;
// see above // see above
unsigned char mDisposition, mReputation, mRank; unsigned char mDisposition, mReputation, mRank;
char mUnknown1, mUnknown2, mUnknown3; char mUnknown1, mUnknown2, mUnknown3;
int mGold; int32_t mGold;
}; // 12 bytes }; // 12 bytes
#pragma pack(pop) #pragma pack(pop)
@ -111,7 +111,7 @@ namespace ESM
int getFactionRank() const; /// wrapper for mNpdt*, -1 = no rank int getFactionRank() const; /// wrapper for mNpdt*, -1 = no rank
int mBloodType; int32_t mBloodType;
unsigned char mFlags; unsigned char mFlags;
InventoryList mInventory; InventoryList mInventory;
@ -125,7 +125,7 @@ namespace ESM
AIPackageList mAiPackage; AIPackageList mAiPackage;
unsigned int mRecordFlags; uint32_t mRecordFlags;
RefId mId, mRace, mClass, mFaction, mScript; RefId mId, mRace, mClass, mFaction, mScript;
std::string mModel, mName; std::string mModel, mName;

View file

@ -27,13 +27,13 @@ namespace ESM
struct SkillBonus struct SkillBonus
{ {
int mSkill; // SkillEnum int32_t mSkill; // SkillEnum
int mBonus; int32_t mBonus;
}; };
struct MaleFemale struct MaleFemale
{ {
int mMale, mFemale; int32_t mMale, mFemale;
int getValue(bool male) const; int getValue(bool male) const;
}; };
@ -63,13 +63,13 @@ namespace ESM
// as 'height' times 128. This has not been tested yet. // as 'height' times 128. This has not been tested yet.
MaleFemaleF mHeight, mWeight; MaleFemaleF mHeight, mWeight;
int mFlags; // 0x1 - playable, 0x2 - beast race int32_t mFlags; // 0x1 - playable, 0x2 - beast race
}; // Size = 140 bytes }; // Size = 140 bytes
RADTstruct mData; RADTstruct mData;
unsigned int mRecordFlags; uint32_t mRecordFlags;
std::string mName, mDescription; std::string mName, mDescription;
RefId mId; RefId mId;
SpellList mPowers; SpellList mPowers;

View file

@ -36,9 +36,9 @@ namespace ESM
}; };
// Type // Type
int mType; int32_t mType;
unsigned int mRecordFlags; uint32_t mRecordFlags;
RefId mId, mCreature, mSound; RefId mId, mCreature, mSound;
void load(ESMReader& esm, bool& isDeleted); void load(ESMReader& esm, bool& isDeleted);

View file

@ -28,7 +28,7 @@ namespace ESM
static std::string_view getRecordType() { return "StartScript"; } static std::string_view getRecordType() { return "StartScript"; }
std::string mData; std::string mData;
unsigned int mRecordFlags; uint32_t mRecordFlags;
RefId mId; RefId mId;
// Load a record and add it to the list // Load a record and add it to the list

View file

@ -31,7 +31,7 @@ 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 "Static"; } static std::string_view getRecordType() { return "Static"; }
unsigned int mRecordFlags; uint32_t mRecordFlags;
RefId mId; RefId mId;
std::string mModel; std::string mModel;

View file

@ -20,11 +20,11 @@ namespace ESM
versions are 1.2 and 1.3. These correspond to: versions are 1.2 and 1.3. These correspond to:
1.2 = 0x3f99999a and 1.3 = 0x3fa66666 1.2 = 0x3f99999a and 1.3 = 0x3fa66666
*/ */
unsigned int version; uint32_t version;
int type; // 0=esp, 1=esm, 32=ess (unused) int32_t type; // 0=esp, 1=esm, 32=ess (unused)
std::string author; // Author's name std::string author; // Author's name
std::string desc; // File description std::string desc; // File description
int records; // Number of records int32_t records; // Number of records
}; };
struct GMDT struct GMDT

View file

@ -20,8 +20,8 @@ namespace ESM
{ {
while (esm.isNextSub("EFID")) while (esm.isNextSub("EFID"))
{ {
int id; int32_t id;
std::pair<int, float> params; std::pair<int32_t, float> params;
esm.getHT(id); esm.getHT(id);
esm.getHNT(params.first, "BASE"); esm.getHNT(params.first, "BASE");
if (esm.getFormatVersion() <= MaxClearModifiersFormatVersion) if (esm.getFormatVersion() <= MaxClearModifiersFormatVersion)

View file

@ -16,7 +16,7 @@ namespace ESM
struct MagicEffects struct MagicEffects
{ {
// <Effect Id, Base value, Modifier> // <Effect Id, Base value, Modifier>
std::map<int, std::pair<int, float>> mEffects; std::map<int32_t, std::pair<int32_t, float>> mEffects;
void load(ESMReader& esm); void load(ESMReader& esm);
void save(ESMWriter& esm) const; void save(ESMWriter& esm) const;
@ -24,16 +24,16 @@ namespace ESM
struct SummonKey struct SummonKey
{ {
SummonKey(int effectId, const ESM::RefId& sourceId, int index) SummonKey(int32_t effectId, const ESM::RefId& sourceId, int32_t index)
: mEffectId(effectId) : mEffectId(effectId)
, mSourceId(sourceId) , mSourceId(sourceId)
, mEffectIndex(index) , mEffectIndex(index)
{ {
} }
int mEffectId; int32_t mEffectId;
ESM::RefId mSourceId; ESM::RefId mSourceId;
int mEffectIndex; int32_t mEffectIndex;
}; };
inline auto makeTupleRef(const SummonKey& value) noexcept inline auto makeTupleRef(const SummonKey& value) noexcept

View file

@ -21,7 +21,7 @@ namespace ESM
Faction faction; Faction faction;
int expelled = 0; int32_t expelled = 0;
esm.getHNOT(expelled, "FAEX"); esm.getHNOT(expelled, "FAEX");
if (expelled) if (expelled)
@ -75,7 +75,7 @@ namespace ESM
esm.getHNOT(hasWerewolfAttributes, "HWAT"); esm.getHNOT(hasWerewolfAttributes, "HWAT");
if (hasWerewolfAttributes) if (hasWerewolfAttributes)
{ {
StatState<int> dummy; StatState<int32_t> dummy;
for (int i = 0; i < ESM::Attribute::Length; ++i) for (int i = 0; i < ESM::Attribute::Length; ++i)
dummy.load(esm, intFallback); dummy.load(esm, intFallback);
mWerewolfDeprecatedData = true; mWerewolfDeprecatedData = true;
@ -130,21 +130,21 @@ namespace ESM
void NpcStats::save(ESMWriter& esm) const void NpcStats::save(ESMWriter& esm) const
{ {
for (auto iter(mFactions.begin()); iter != mFactions.end(); ++iter) for (const auto& [id, faction] : mFactions)
{ {
esm.writeHNRefId("FACT", iter->first); esm.writeHNRefId("FACT", id);
if (iter->second.mExpelled) if (faction.mExpelled)
{ {
int expelled = 1; int32_t expelled = 1;
esm.writeHNT("FAEX", expelled); esm.writeHNT("FAEX", expelled);
} }
if (iter->second.mRank >= 0) if (faction.mRank >= 0)
esm.writeHNT("FARA", iter->second.mRank); esm.writeHNT("FARA", faction.mRank);
if (iter->second.mReputation) if (faction.mReputation)
esm.writeHNT("FARE", iter->second.mReputation); esm.writeHNT("FARE", faction.mReputation);
} }
if (mDisposition) if (mDisposition)
@ -169,7 +169,7 @@ namespace ESM
esm.writeHNT("LPRO", mLevelProgress); esm.writeHNT("LPRO", mLevelProgress);
bool saveSkillIncreases = false; bool saveSkillIncreases = false;
for (int increase : mSkillIncrease) for (int32_t increase : mSkillIncrease)
{ {
if (increase != 0) if (increase != 0)
{ {
@ -183,8 +183,8 @@ namespace ESM
if (mSpecIncreases[0] != 0 || mSpecIncreases[1] != 0 || mSpecIncreases[2] != 0) if (mSpecIncreases[0] != 0 || mSpecIncreases[1] != 0 || mSpecIncreases[2] != 0)
esm.writeHNT("SPEC", mSpecIncreases); esm.writeHNT("SPEC", mSpecIncreases);
for (auto iter(mUsedIds.begin()); iter != mUsedIds.end(); ++iter) for (const RefId& id : mUsedIds)
esm.writeHNRefId("USED", *iter); esm.writeHNRefId("USED", id);
if (mTimeToStartDrowning) if (mTimeToStartDrowning)
esm.writeHNT("DRTI", mTimeToStartDrowning); esm.writeHNT("DRTI", mTimeToStartDrowning);

View file

@ -23,8 +23,8 @@ namespace ESM
struct Faction struct Faction
{ {
bool mExpelled; bool mExpelled;
int mRank; int32_t mRank;
int mReputation; int32_t mReputation;
Faction(); Faction();
}; };
@ -33,18 +33,18 @@ namespace ESM
bool mWerewolfDeprecatedData; bool mWerewolfDeprecatedData;
std::map<ESM::RefId, Faction> mFactions; // lower case IDs std::map<ESM::RefId, Faction> mFactions;
int mDisposition; int32_t mDisposition;
std::array<StatState<float>, ESM::Skill::Length> mSkills; std::array<StatState<float>, ESM::Skill::Length> mSkills;
int mBounty; int32_t mBounty;
int mReputation; int32_t mReputation;
int mWerewolfKills; int32_t mWerewolfKills;
int mLevelProgress; int32_t mLevelProgress;
std::array<int, ESM::Attribute::Length> mSkillIncrease; std::array<int32_t, ESM::Attribute::Length> mSkillIncrease;
std::array<int, 3> mSpecIncreases; std::array<int32_t, 3> mSpecIncreases;
std::vector<ESM::RefId> mUsedIds; // lower case IDs std::vector<ESM::RefId> mUsedIds;
float mTimeToStartDrowning; float mTimeToStartDrowning;
int mCrimeId; int32_t mCrimeId;
/// Initialize to default state /// Initialize to default state
void blank(); void blank();

View file

@ -49,7 +49,7 @@ namespace ESM
esm.getHNOT(mFlags, "FLAG"); esm.getHNOT(mFlags, "FLAG");
// obsolete // obsolete
int unused; int32_t unused;
esm.getHNOT(unused, "LTIM"); esm.getHNOT(unused, "LTIM");
mAnimationState.load(esm); mAnimationState.load(esm);
@ -179,6 +179,6 @@ namespace ESM
throw std::logic_error(error.str()); throw std::logic_error(error.str());
} }
ObjectState::~ObjectState() {} ObjectState::~ObjectState() = default;
} }

View file

@ -32,9 +32,9 @@ namespace ESM
Locals mLocals; Locals mLocals;
LuaScripts mLuaScripts; LuaScripts mLuaScripts;
unsigned char mEnabled; unsigned char mEnabled;
int mCount; int32_t mCount;
Position mPosition; Position mPosition;
unsigned int mFlags; uint32_t mFlags;
// Is there any class-specific state following the ObjectState // Is there any class-specific state following the ObjectState
bool mHasCustomState; bool mHasCustomState;

View file

@ -27,8 +27,8 @@ namespace ESM
RefId mMarkedCell; RefId mMarkedCell;
ESM::RefId mBirthsign; ESM::RefId mBirthsign;
int mCurrentCrimeId; int32_t mCurrentCrimeId;
int mPaidCrimeId; int32_t mPaidCrimeId;
float mSaveAttributes[Attribute::Length]; float mSaveAttributes[Attribute::Length];
float mSaveSkills[Skill::Length]; float mSaveSkills[Skill::Length];

View file

@ -23,7 +23,7 @@ namespace ESM
Vector3 mPosition; Vector3 mPosition;
Quaternion mOrientation; Quaternion mOrientation;
int mActorId; int32_t mActorId;
void load(ESMReader& esm); void load(ESMReader& esm);
void save(ESMWriter& esm) const; void save(ESMWriter& esm) const;

View file

@ -14,7 +14,7 @@ namespace ESM
struct QuestState struct QuestState
{ {
ESM::RefId mTopic; // lower case id ESM::RefId mTopic; // lower case id
int mState; int32_t mState;
unsigned char mFinished; unsigned char mFinished;
void load(ESMReader& esm); void load(ESMReader& esm);

View file

@ -20,7 +20,7 @@ namespace ESM
std::vector<std::string> mContentFiles; std::vector<std::string> mContentFiles;
std::string mPlayerName; std::string mPlayerName;
int mPlayerLevel; int32_t mPlayerLevel;
// ID of class // ID of class
ESM::RefId mPlayerClassId; ESM::RefId mPlayerClassId;
@ -34,7 +34,7 @@ namespace ESM
std::string mDescription; std::string mDescription;
std::vector<char> mScreenshot; // raw jpg-encoded data std::vector<char> mScreenshot; // raw jpg-encoded data
int mCurrentDay = 0; int32_t mCurrentDay = 0;
float mCurrentHealth = 0; float mCurrentHealth = 0;
float mMaximumHealth = 0; float mMaximumHealth = 0;

View file

@ -21,19 +21,19 @@ namespace ESM
// We changed stats values from integers to floats; ensure backwards compatibility // We changed stats values from integers to floats; ensure backwards compatibility
if (intFallback) if (intFallback)
{ {
int base = 0; int32_t base = 0;
esm.getHNT(base, "STBA"); esm.getHNT(base, "STBA");
mBase = static_cast<T>(base); mBase = static_cast<T>(base);
int mod = 0; int32_t mod = 0;
esm.getHNOT(mod, "STMO"); esm.getHNOT(mod, "STMO");
mMod = static_cast<T>(mod); mMod = static_cast<T>(mod);
int current = 0; int32_t current = 0;
esm.getHNOT(current, "STCU"); esm.getHNOT(current, "STCU");
mCurrent = static_cast<T>(current); mCurrent = static_cast<T>(current);
int oldDamage = 0; int32_t oldDamage = 0;
esm.getHNOT(oldDamage, "STDA"); esm.getHNOT(oldDamage, "STDA");
mDamage = static_cast<float>(oldDamage); mDamage = static_cast<float>(oldDamage);
} }

View file

@ -17,7 +17,7 @@ namespace ESM
template <typename T, bool orDefault = false> template <typename T, bool orDefault = false>
struct GetValue struct GetValue
{ {
constexpr T operator()(int value) const { return static_cast<T>(value); } constexpr T operator()(int32_t value) const { return static_cast<T>(value); }
constexpr T operator()(float value) const { return static_cast<T>(value); } constexpr T operator()(float value) const { return static_cast<T>(value); }
@ -41,7 +41,7 @@ namespace ESM
{ {
} }
void operator()(int& value) const { value = static_cast<int>(mValue); } void operator()(int32_t& value) const { value = static_cast<int32_t>(mValue); }
void operator()(float& value) const { value = static_cast<float>(mValue); } void operator()(float& value) const { value = static_cast<float>(mValue); }
@ -58,9 +58,9 @@ namespace ESM
return std::get<std::string>(mData); return std::get<std::string>(mData);
} }
int Variant::getInteger() const int32_t Variant::getInteger() const
{ {
return std::visit(GetValue<int>{}, mData); return std::visit(GetValue<int32_t>{}, mData);
} }
float Variant::getFloat() const float Variant::getFloat() const
@ -194,17 +194,17 @@ namespace ESM
case VT_Short: case VT_Short:
stream << "variant short: " << std::get<int>(mData); stream << "variant short: " << std::get<int32_t>(mData);
break; break;
case VT_Int: case VT_Int:
stream << "variant int: " << std::get<int>(mData); stream << "variant int: " << std::get<int32_t>(mData);
break; break;
case VT_Long: case VT_Long:
stream << "variant long: " << std::get<int>(mData); stream << "variant long: " << std::get<int32_t>(mData);
break; break;
case VT_Float: case VT_Float:
@ -259,7 +259,7 @@ namespace ESM
std::get<std::string>(mData) = std::move(value); std::get<std::string>(mData) = std::move(value);
} }
void Variant::setInteger(int value) void Variant::setInteger(int32_t value)
{ {
std::visit(SetValue(value), mData); std::visit(SetValue(value), mData);
} }

View file

@ -25,7 +25,7 @@ namespace ESM
class Variant class Variant
{ {
VarType mType; VarType mType;
std::variant<std::monostate, int, float, std::string> mData; std::variant<std::monostate, int32_t, float, std::string> mData;
public: public:
enum Format enum Format
@ -54,7 +54,7 @@ namespace ESM
{ {
} }
explicit Variant(int value) explicit Variant(int32_t value)
: mType(VT_Long) : mType(VT_Long)
, mData(value) , mData(value)
{ {
@ -71,7 +71,7 @@ namespace ESM
const std::string& getString() const; const std::string& getString() const;
///< Will throw an exception, if value can not be represented as a string. ///< Will throw an exception, if value can not be represented as a string.
int getInteger() const; int32_t getInteger() const;
///< Will throw an exception, if value can not be represented as an integer (implicit ///< Will throw an exception, if value can not be represented as an integer (implicit
/// casting of float values is permitted). /// casting of float values is permitted).
@ -93,7 +93,7 @@ namespace ESM
void setString(std::string&& value); void setString(std::string&& value);
///< Will throw an exception, if type is not compatible with string. ///< Will throw an exception, if type is not compatible with string.
void setInteger(int value); void setInteger(int32_t value);
///< Will throw an exception, if type is not compatible with integer. ///< Will throw an exception, if type is not compatible with integer.
void setFloat(float value); void setFloat(float value);

View file

@ -46,7 +46,7 @@ namespace ESM
esm.writeHNString("STRV", in); esm.writeHNString("STRV", in);
} }
void readESMVariantValue(ESMReader& esm, Variant::Format format, VarType type, int& out) void readESMVariantValue(ESMReader& esm, Variant::Format format, VarType type, int32_t& out)
{ {
if (type != VT_Short && type != VT_Long && type != VT_Int) if (type != VT_Short && type != VT_Long && type != VT_Int)
throw std::logic_error("not an integer type"); throw std::logic_error("not an integer type");
@ -60,9 +60,9 @@ namespace ESM
if (std::isnan(value)) if (std::isnan(value))
out = 0; out = 0;
else else
out = static_cast<short>(value); out = static_cast<int16_t>(value);
else if (type == VT_Long) else if (type == VT_Long)
out = static_cast<int>(value); out = static_cast<int32_t>(value);
else else
esm.fail("unsupported global variable integer type"); esm.fail("unsupported global variable integer type");
} }
@ -82,7 +82,7 @@ namespace ESM
{ {
if (type == VT_Short) if (type == VT_Short)
{ {
short value; int16_t value;
esm.getHT(value); esm.getHT(value);
out = value; out = value;
} }
@ -95,7 +95,7 @@ namespace ESM
} }
} }
void writeESMVariantValue(ESMWriter& esm, Variant::Format format, VarType type, int in) void writeESMVariantValue(ESMWriter& esm, Variant::Format format, VarType type, int32_t in)
{ {
if (type != VT_Short && type != VT_Long && type != VT_Int) if (type != VT_Short && type != VT_Long && type != VT_Int)
throw std::logic_error("not an integer type"); throw std::logic_error("not an integer type");
@ -126,7 +126,7 @@ namespace ESM
else if (format == Variant::Format_Local) else if (format == Variant::Format_Local)
{ {
if (type == VT_Short) if (type == VT_Short)
esm.writeHNT("STTV", static_cast<short>(in)); esm.writeHNT("STTV", static_cast<int16_t>(in));
else if (type == VT_Int) else if (type == VT_Int)
esm.writeHNT("INTV", in); esm.writeHNT("INTV", in);
else else

View file

@ -12,13 +12,13 @@ namespace ESM
void readESMVariantValue(ESMReader& reader, Variant::Format format, VarType type, float& value); void readESMVariantValue(ESMReader& reader, Variant::Format format, VarType type, float& value);
void readESMVariantValue(ESMReader& reader, Variant::Format format, VarType type, int& value); void readESMVariantValue(ESMReader& reader, Variant::Format format, VarType type, int32_t& value);
void writeESMVariantValue(ESMWriter& writer, Variant::Format format, VarType type, const std::string& value); void writeESMVariantValue(ESMWriter& writer, Variant::Format format, VarType type, const std::string& value);
void writeESMVariantValue(ESMWriter& writer, Variant::Format format, VarType type, float value); void writeESMVariantValue(ESMWriter& writer, Variant::Format format, VarType type, float value);
void writeESMVariantValue(ESMWriter& writer, Variant::Format format, VarType type, int value); void writeESMVariantValue(ESMWriter& writer, Variant::Format format, VarType type, int32_t value);
struct ReadESMVariantValue struct ReadESMVariantValue
{ {