Skip to content

Commit

Permalink
Merge branch 'downsized' into 'master'
Browse files Browse the repository at this point in the history
Remove explicitly sized reads

See merge request OpenMW/openmw!3663
  • Loading branch information
jvoisin committed Dec 21, 2023
2 parents 51cb3b0 + 3e101ab commit 2873f97
Show file tree
Hide file tree
Showing 55 changed files with 394 additions and 436 deletions.
34 changes: 16 additions & 18 deletions apps/esmtool/record.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1084,14 +1084,8 @@ namespace EsmTool
std::cout << " Rank: " << (int)mData.mNpdt.mRank << std::endl;

std::cout << " Attributes:" << std::endl;
std::cout << " Strength: " << (int)mData.mNpdt.mStrength << std::endl;
std::cout << " Intelligence: " << (int)mData.mNpdt.mIntelligence << std::endl;
std::cout << " Willpower: " << (int)mData.mNpdt.mWillpower << std::endl;
std::cout << " Agility: " << (int)mData.mNpdt.mAgility << std::endl;
std::cout << " Speed: " << (int)mData.mNpdt.mSpeed << std::endl;
std::cout << " Endurance: " << (int)mData.mNpdt.mEndurance << std::endl;
std::cout << " Personality: " << (int)mData.mNpdt.mPersonality << std::endl;
std::cout << " Luck: " << (int)mData.mNpdt.mLuck << std::endl;
for (size_t i = 0; i != mData.mNpdt.mAttributes.size(); i++)
std::cout << " " << attributeLabel(i) << ": " << int(mData.mNpdt.mAttributes[i]) << std::endl;

std::cout << " Skills:" << std::endl;
for (size_t i = 0; i != mData.mNpdt.mSkills.size(); i++)
Expand Down Expand Up @@ -1169,19 +1163,23 @@ namespace EsmTool
std::cout << " Description: " << mData.mDescription << std::endl;
std::cout << " Flags: " << raceFlags(mData.mData.mFlags) << std::endl;

for (int i = 0; i < 2; ++i)
std::cout << " Male:" << std::endl;
for (int j = 0; j < ESM::Attribute::Length; ++j)
{
bool male = i == 0;

std::cout << (male ? " Male:" : " Female:") << std::endl;

for (int j = 0; j < ESM::Attribute::Length; ++j)
std::cout << " " << ESM::Attribute::indexToRefId(j) << ": "
<< mData.mData.mAttributeValues[j].getValue(male) << std::endl;
ESM::RefId id = ESM::Attribute::indexToRefId(j);
std::cout << " " << id << ": " << mData.mData.getAttribute(id, true) << std::endl;
}
std::cout << " Height: " << mData.mData.mMaleHeight << std::endl;
std::cout << " Weight: " << mData.mData.mMaleWeight << std::endl;

std::cout << " Height: " << mData.mData.mHeight.getValue(male) << std::endl;
std::cout << " Weight: " << mData.mData.mWeight.getValue(male) << std::endl;
std::cout << " Female:" << std::endl;
for (int j = 0; j < ESM::Attribute::Length; ++j)
{
ESM::RefId id = ESM::Attribute::indexToRefId(j);
std::cout << " " << id << ": " << mData.mData.getAttribute(id, false) << std::endl;
}
std::cout << " Height: " << mData.mData.mFemaleHeight << std::endl;
std::cout << " Weight: " << mData.mData.mFemaleWeight << std::endl;

for (const auto& bonus : mData.mData.mBonus)
// Not all races have 7 skills.
Expand Down
9 changes: 5 additions & 4 deletions apps/essimporter/converter.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "converter.hpp"

#include <algorithm>
#include <cstdint>
#include <stdexcept>

#include <osgDB/WriteFile>
Expand Down Expand Up @@ -90,14 +91,14 @@ namespace ESSImport

struct MAPH
{
unsigned int size;
unsigned int value;
uint32_t size;
uint32_t value;
};

void ConvertFMAP::read(ESM::ESMReader& esm)
{
MAPH maph;
esm.getHNTSized<8>(maph, "MAPH");
esm.getHNT("MAPH", maph.size, maph.value);
std::vector<char> data;
esm.getSubNameIs("MAPD");
esm.getSubHeader();
Expand Down Expand Up @@ -278,7 +279,7 @@ namespace ESSImport
while (esm.isNextSub("MPCD"))
{
float notepos[3];
esm.getHTSized<3 * sizeof(float)>(notepos);
esm.getHT(notepos);

// Markers seem to be arranged in a 32*32 grid, notepos has grid-indices.
// This seems to be the reason markers can't be placed everywhere in interior cells,
Expand Down
8 changes: 3 additions & 5 deletions apps/essimporter/importacdt.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef OPENMW_ESSIMPORT_ACDT_H
#define OPENMW_ESSIMPORT_ACDT_H

#include <cstdint>
#include <string>

#include "importscri.hpp"
Expand All @@ -25,14 +26,12 @@ namespace ESSImport
};

/// Actor data, shared by (at least) REFR and CellRef
#pragma pack(push)
#pragma pack(1)
struct ACDT
{
// Note, not stored at *all*:
// - Level changes are lost on reload, except for the player (there it's in the NPC record).
unsigned char mUnknown[12];
unsigned int mFlags;
uint32_t mFlags;
float mBreathMeter; // Seconds left before drowning
unsigned char mUnknown2[20];
float mDynamic[3][2];
Expand All @@ -41,7 +40,7 @@ namespace ESSImport
float mMagicEffects[27]; // Effect attributes:
// https://wiki.openmw.org/index.php?title=Research:Magic#Effect_attributes
unsigned char mUnknown4[4];
unsigned int mGoldPool;
uint32_t mGoldPool;
unsigned char mCountDown; // seen the same value as in ACSC.mCorpseClearCountdown, maybe
// this one is for respawning?
unsigned char mUnknown5[3];
Expand All @@ -60,7 +59,6 @@ namespace ESSImport
unsigned char mUnknown[3];
float mTime;
};
#pragma pack(pop)

struct ActorData
{
Expand Down
40 changes: 15 additions & 25 deletions apps/essimporter/importcellref.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "importcellref.hpp"

#include <components/esm3/esmreader.hpp>
#include <cstdint>

namespace ESSImport
{
Expand Down Expand Up @@ -44,19 +45,14 @@ namespace ESSImport
bool isDeleted = false;
ESM::CellRef::loadData(esm, isDeleted);

mActorData.mHasACDT = false;
if (esm.isNextSub("ACDT"))
{
mActorData.mHasACDT = true;
esm.getHTSized<264>(mActorData.mACDT);
}
mActorData.mHasACDT
= esm.getHNOT("ACDT", mActorData.mACDT.mUnknown, mActorData.mACDT.mFlags, mActorData.mACDT.mBreathMeter,
mActorData.mACDT.mUnknown2, mActorData.mACDT.mDynamic, mActorData.mACDT.mUnknown3,
mActorData.mACDT.mAttributes, mActorData.mACDT.mMagicEffects, mActorData.mACDT.mUnknown4,
mActorData.mACDT.mGoldPool, mActorData.mACDT.mCountDown, mActorData.mACDT.mUnknown5);

mActorData.mHasACSC = false;
if (esm.isNextSub("ACSC"))
{
mActorData.mHasACSC = true;
esm.getHTSized<112>(mActorData.mACSC);
}
mActorData.mHasACSC = esm.getHNOT("ACSC", mActorData.mACSC.mUnknown1, mActorData.mACSC.mFlags,
mActorData.mACSC.mUnknown2, mActorData.mACSC.mCorpseClearCountdown, mActorData.mACSC.mUnknown3);

if (esm.isNextSub("ACSL"))
esm.skipHSubSize(112);
Expand Down Expand Up @@ -122,23 +118,17 @@ namespace ESSImport
}

// FIXME: not all actors have this, add flag
if (esm.isNextSub("CHRD")) // npc only
esm.getHExact(mActorData.mSkills, 27 * 2 * sizeof(int));
esm.getHNOT("CHRD", mActorData.mSkills); // npc only

if (esm.isNextSub("CRED")) // creature only
esm.getHExact(mActorData.mCombatStats, 3 * 2 * sizeof(int));
esm.getHNOT("CRED", mActorData.mCombatStats); // creature only

mActorData.mSCRI.load(esm);

if (esm.isNextSub("ND3D"))
esm.skipHSub();

mActorData.mHasANIS = false;
if (esm.isNextSub("ANIS"))
{
mActorData.mHasANIS = true;
esm.getHTSized<8>(mActorData.mANIS);
}
mActorData.mHasANIS
= esm.getHNOT("ANIS", mActorData.mANIS.mGroupIndex, mActorData.mANIS.mUnknown, mActorData.mANIS.mTime);

if (esm.isNextSub("LVCR"))
{
Expand All @@ -155,13 +145,13 @@ namespace ESSImport
// DATA should occur for all references, except levelled creature spawners
// I've seen DATA *twice* on a creature record, and with the exact same content too! weird
// alarmvoi0000.ess
esm.getHNOTSized<24>(mPos, "DATA");
esm.getHNOTSized<24>(mPos, "DATA");
for (int i = 0; i < 2; ++i)
esm.getHNOT("DATA", mPos.pos, mPos.rot);

mDeleted = 0;
if (esm.isNextSub("DELE"))
{
unsigned int deleted;
uint32_t deleted;
esm.getHT(deleted);
mDeleted = ((deleted >> 24) & 0x2) != 0; // the other 3 bytes seem to be uninitialized garbage
}
Expand Down
1 change: 1 addition & 0 deletions apps/essimporter/importcntc.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "importcntc.hpp"

#include <components/esm3/esmreader.hpp>
#include <cstdint>

namespace ESSImport
{
Expand Down
2 changes: 1 addition & 1 deletion apps/essimporter/importcntc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace ESSImport
/// Changed container contents
struct CNTC
{
int mIndex;
int32_t mIndex;

Inventory mInventory;

Expand Down
3 changes: 2 additions & 1 deletion apps/essimporter/importcrec.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "importinventory.hpp"
#include <components/esm3/aipackage.hpp>
#include <cstdint>

namespace ESM
{
Expand All @@ -15,7 +16,7 @@ namespace ESSImport
/// Creature changes
struct CREC
{
int mIndex;
int32_t mIndex;

Inventory mInventory;
ESM::AIPackageList mAiPackages;
Expand Down
4 changes: 2 additions & 2 deletions apps/essimporter/importdial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ namespace ESSImport
void DIAL::load(ESM::ESMReader& esm)
{
// See ESM::Dialogue::Type enum, not sure why we would need this here though
int type = 0;
int32_t type = 0;
esm.getHNOT(type, "DATA");

// Deleted dialogue in a savefile. No clue what this means...
int deleted = 0;
int32_t deleted = 0;
esm.getHNOT(deleted, "DELE");

mIndex = 0;
Expand Down
5 changes: 4 additions & 1 deletion apps/essimporter/importdial.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#ifndef OPENMW_ESSIMPORT_IMPORTDIAL_H
#define OPENMW_ESSIMPORT_IMPORTDIAL_H

#include <cstdint>

namespace ESM
{
class ESMReader;
Expand All @@ -10,7 +13,7 @@ namespace ESSImport

struct DIAL
{
int mIndex; // Journal index
int32_t mIndex; // Journal index

void load(ESM::ESMReader& esm);
};
Expand Down
22 changes: 11 additions & 11 deletions apps/essimporter/importgame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ namespace ESSImport
{
esm.getSubNameIs("GMDT");
esm.getSubHeader();
if (esm.getSubSize() == 92)
{
esm.getExact(&mGMDT, 92);
mGMDT.mSecundaPhase = 0;
}
else if (esm.getSubSize() == 96)
{
esm.getTSized<96>(mGMDT);
}
else
esm.fail("unexpected subrecord size for GAME.GMDT");
bool hasSecundaPhase = esm.getSubSize() == 96;
esm.getT(mGMDT.mCellName);
esm.getT(mGMDT.mFogColour);
esm.getT(mGMDT.mFogDensity);
esm.getT(mGMDT.mCurrentWeather);
esm.getT(mGMDT.mNextWeather);
esm.getT(mGMDT.mWeatherTransition);
esm.getT(mGMDT.mTimeOfNextTransition);
esm.getT(mGMDT.mMasserPhase);
if (hasSecundaPhase)
esm.getT(mGMDT.mSecundaPhase);

mGMDT.mWeatherTransition &= (0x000000ff);
mGMDT.mSecundaPhase &= (0x000000ff);
Expand Down
10 changes: 6 additions & 4 deletions apps/essimporter/importgame.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef OPENMW_ESSIMPORT_GAME_H
#define OPENMW_ESSIMPORT_GAME_H

#include <cstdint>

namespace ESM
{
class ESMReader;
Expand All @@ -15,12 +17,12 @@ namespace ESSImport
struct GMDT
{
char mCellName[64]{};
int mFogColour{ 0 };
int32_t mFogColour{ 0 };
float mFogDensity{ 0.f };
int mCurrentWeather{ 0 }, mNextWeather{ 0 };
int mWeatherTransition{ 0 }; // 0-100 transition between weathers, top 3 bytes may be garbage
int32_t mCurrentWeather{ 0 }, mNextWeather{ 0 };
int32_t mWeatherTransition{ 0 }; // 0-100 transition between weathers, top 3 bytes may be garbage
float mTimeOfNextTransition{ 0.f }; // weather changes when gamehour == timeOfNextTransition
int mMasserPhase{ 0 }, mSecundaPhase{ 0 }; // top 3 bytes may be garbage
int32_t mMasserPhase{ 0 }, mSecundaPhase{ 0 }; // top 3 bytes may be garbage
};

GMDT mGMDT;
Expand Down
10 changes: 5 additions & 5 deletions apps/essimporter/importinventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace ESSImport
while (esm.isNextSub("NPCO"))
{
ContItem contItem;
esm.getHTSized<36>(contItem);
esm.getHT(contItem.mCount, contItem.mItem.mData);

InventoryItem item;
item.mId = contItem.mItem.toString();
Expand All @@ -28,7 +28,7 @@ namespace ESSImport
bool newStack = esm.isNextSub("XIDX");
if (newStack)
{
unsigned int idx;
uint32_t idx;
esm.getHT(idx);
separateStacks = true;
item.mCount = 1;
Expand All @@ -40,7 +40,7 @@ namespace ESSImport
bool isDeleted = false;
item.ESM::CellRef::loadData(esm, isDeleted);

int charge = -1;
int32_t charge = -1;
esm.getHNOT(charge, "XHLT");
item.mChargeInt = charge;

Expand All @@ -60,15 +60,15 @@ namespace ESSImport
// this is currently not handled properly.

esm.getSubHeader();
int itemIndex; // index of the item in the NPCO list
int32_t itemIndex; // index of the item in the NPCO list
esm.getT(itemIndex);

if (itemIndex < 0 || itemIndex >= int(mItems.size()))
esm.fail("equipment item index out of range");

// appears to be a relative index for only the *possible* slots this item can be equipped in,
// i.e. 0 most of the time
int slotIndex;
int32_t slotIndex;
esm.getT(slotIndex);

mItems[itemIndex].mRelativeEquipmentSlot = slotIndex;
Expand Down
Loading

0 comments on commit 2873f97

Please sign in to comment.