From b65c9b5961b0901aed22f6fcf6f128ae72003280 Mon Sep 17 00:00:00 2001 From: FynnTW Date: Tue, 8 Oct 2024 16:34:48 +0300 Subject: [PATCH] fix anc struct size --- M2TWEOP Code/M2TWEOP library/luaPlugin.cpp | 19 +++++++++++++------ M2TWEOP Code/M2TWEOP library/luaPlugin.h | 2 ++ .../M2TWEOP library/patchesForGame.cpp | 2 ++ .../M2TWEOP library/types/characterRecord.cpp | 4 ++-- .../M2TWEOP library/types/characterRecord.h | 8 ++++---- 5 files changed, 23 insertions(+), 12 deletions(-) diff --git a/M2TWEOP Code/M2TWEOP library/luaPlugin.cpp b/M2TWEOP Code/M2TWEOP library/luaPlugin.cpp index de0d8c9b..8ef5d365 100644 --- a/M2TWEOP Code/M2TWEOP library/luaPlugin.cpp +++ b/M2TWEOP Code/M2TWEOP library/luaPlugin.cpp @@ -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; } diff --git a/M2TWEOP Code/M2TWEOP library/luaPlugin.h b/M2TWEOP Code/M2TWEOP library/luaPlugin.h index 5625ad41..9e86a199 100644 --- a/M2TWEOP Code/M2TWEOP library/luaPlugin.h +++ b/M2TWEOP Code/M2TWEOP library/luaPlugin.h @@ -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 factions = { }; diff --git a/M2TWEOP Code/M2TWEOP library/patchesForGame.cpp b/M2TWEOP Code/M2TWEOP library/patchesForGame.cpp index 087400c4..fab8b632 100644 --- a/M2TWEOP Code/M2TWEOP library/patchesForGame.cpp +++ b/M2TWEOP Code/M2TWEOP library/patchesForGame.cpp @@ -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(); diff --git a/M2TWEOP Code/M2TWEOP library/types/characterRecord.cpp b/M2TWEOP Code/M2TWEOP library/types/characterRecord.cpp index 26f9d653..016851f9 100644 --- a/M2TWEOP Code/M2TWEOP library/types/characterRecord.cpp +++ b/M2TWEOP Code/M2TWEOP library/types/characterRecord.cpp @@ -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]; @@ -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]; diff --git a/M2TWEOP Code/M2TWEOP library/types/characterRecord.h b/M2TWEOP Code/M2TWEOP library/types/characterRecord.h index 4c7bcb9d..e6a6a865 100644 --- a/M2TWEOP Code/M2TWEOP library/types/characterRecord.h +++ b/M2TWEOP Code/M2TWEOP library/types/characterRecord.h @@ -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)); } };