Skip to content

Commit

Permalink
fix anc struct size
Browse files Browse the repository at this point in the history
  • Loading branch information
FynnTW committed Oct 8, 2024
1 parent 75cdd9a commit b65c9b5
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 12 deletions.
19 changes: 13 additions & 6 deletions M2TWEOP Code/M2TWEOP library/luaPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1017,22 +1017,29 @@ void luaPlugin::fillHashMapsNonCampaign()
buildingLevelLines.insert_or_assign(std::string(level->name), building->buildingID);
}
}

hashNonCampaignLoaded = true;
}

void luaPlugin::fillHashMapsVnv()
{
const auto traitsDb = characterRecordHelpers::getTraitDb();
const auto ancDb = characterRecordHelpers::getAncillaryDb();
if (!traitsDb || !ancDb)
return;
const int traitNum = traitsDb->traitsNum;
const int ancNum = ancDb->ancillariesNum;
if (traitNum == 0 || ancNum == 0)
return;
for (int i = 0; i < traitNum; i++)
{
const auto trait = &traitsDb->traits[i];
traits.insert_or_assign(std::string(trait->name), i);
}

const auto ancDb = characterRecordHelpers::getAncillaryDb();
const int ancNum = ancDb->ancillariesNum;
for (int i = 0; i < ancNum; i++)
{
const auto anc = &ancDb->ancillaries[i];
gameHelpers::logStringGame(std::to_string(i));
ancillaries.insert_or_assign(std::string(anc->ancName), i);
}

hashNonCampaignLoaded = true;
hashVnvLoaded = true;
}
2 changes: 2 additions & 0 deletions M2TWEOP Code/M2TWEOP library/luaPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,11 @@ class luaPlugin
sol::state luaState;
void fillHashMaps();
void fillHashMapsNonCampaign();
void fillHashMapsVnv();

bool hashLoaded = false;
bool hashNonCampaignLoaded = false;
bool hashVnvLoaded = false;

std::unordered_map<std::string, int> factions = {
};
Expand Down
2 changes: 2 additions & 0 deletions M2TWEOP Code/M2TWEOP library/patchesForGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1698,7 +1698,9 @@ void __stdcall patchesForGame::onEduParsed()

void __stdcall patchesForGame::onGameInit()
{
gameHelpers::logStringGame("onGameInit");
plugData::data.luaAll.fillHashMapsNonCampaign();
plugData::data.luaAll.fillHashMapsVnv();
cultures::eopPortraitDb::createEopPortraitDb();
discordManager::menuLoaded();
gameEvents::onGameInit();
Expand Down
4 changes: 2 additions & 2 deletions M2TWEOP Code/M2TWEOP library/types/characterRecord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ namespace characterRecordHelpers
if (ancName.empty())
return nullptr;
if (plugData::data.luaAll.ancillaries.empty())
plugData::data.luaAll.fillHashMapsNonCampaign();
plugData::data.luaAll.fillHashMapsVnv();
const auto ancDb = getAncillaryDb();
if (const auto ancIndex = plugData::data.luaAll.ancillaries.find(ancName); ancIndex != plugData::data.luaAll.ancillaries.end())
return &ancDb->ancillaries[ancIndex->second];
Expand Down Expand Up @@ -350,7 +350,7 @@ namespace characterRecordHelpers
traitEntry* findTrait(const std::string& name)
{
if (plugData::data.luaAll.traits.empty())
plugData::data.luaAll.fillHashMapsNonCampaign();
plugData::data.luaAll.fillHashMapsVnv();
const auto traitsDb = getTraitDb();
if (const auto traitIndex = plugData::data.luaAll.traits.find(name); traitIndex != plugData::data.luaAll.traits.end())
return &traitsDb->traits[traitIndex->second];
Expand Down
8 changes: 4 additions & 4 deletions M2TWEOP Code/M2TWEOP library/types/characterRecord.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,15 @@ struct ancillary { /* structure of ancillary */
char* type; //0048
int typeHash; //004C
bool transferable;//00050
char pad_0051[3];
char pad_0051[31];

traitEffect* getEffect(int i)
traitEffect* getEffect(const int i)
{
return &effects[i];
}
bool isExcluded(const int cultureID)
bool isExcluded(const int cultureId)
{
return (1 << (cultureID & 0x1F)) & *(&excludedCultures + (cultureID >> 5));
return (1 << (cultureId & 0x1F)) & *(&excludedCultures + (cultureId >> 5));
}
};

Expand Down

0 comments on commit b65c9b5

Please sign in to comment.