From b8976ff333cb1fb67d2b8c5b2da0151e1dd0df97 Mon Sep 17 00:00:00 2001 From: FynnTW Date: Fri, 1 Nov 2024 22:42:07 +0200 Subject: [PATCH] fix bug with hidden resources, add getTrait and getAncillary --- M2TWEOP Code/M2TWEOP library/luaPlugin.cpp | 22 ++++++++++ .../M2TWEOP library/patchesForGame.cpp | 6 ++- .../M2TWEOP library/types/characterRecord.cpp | 44 ++++++++++++++++++- .../M2TWEOP library/types/characterRecord.h | 7 +++ .../M2TWEOP library/types/eopBuildings.cpp | 2 + .../M2TWEOP library/types/faction.cpp | 2 + 6 files changed, 80 insertions(+), 3 deletions(-) diff --git a/M2TWEOP Code/M2TWEOP library/luaPlugin.cpp b/M2TWEOP Code/M2TWEOP library/luaPlugin.cpp index 2125ba93..5c051d81 100644 --- a/M2TWEOP Code/M2TWEOP library/luaPlugin.cpp +++ b/M2TWEOP Code/M2TWEOP library/luaPlugin.cpp @@ -211,6 +211,8 @@ sol::state* luaPlugin::init(std::string& luaFilePath, std::string& modPath) @tfield toggleDeveloperMode toggleDeveloperMode @tfield saveGame saveGame @tfield copyFile copyFile + @tfield getAncillary getAncillary + @tfield getTrait getTrait @tfield setExpandedString setExpandedString @tfield getGameVersion getGameVersion @tfield setPerfectSpy setPerfectSpy @@ -338,6 +340,26 @@ sol::state* luaPlugin::init(std::string& luaFilePath, std::string& modPath) */ tables.M2TWEOP.set_function("saveGame", &gameHelpers::saveGame); + /*** + Get an ancillary by name. + @function M2TWEOP.getAncillary + @tparam string name + @treturn ancillary anc + @usage + M2TWEOP.getAncillary("ancillary_name"); + */ + tables.M2TWEOP.set_function("getAncillary", &characterRecordHelpers::findAncillary); + + /*** + Get a trait by name. + @function M2TWEOP.getTrait + @tparam string name + @tparam traitEntry trait + @usage + M2TWEOP.getTrait("trait_name"); + */ + tables.M2TWEOP.set_function("getTrait", &characterRecordHelpers::findTrait); + /*** Copy a file. @function M2TWEOP.copyFile diff --git a/M2TWEOP Code/M2TWEOP library/patchesForGame.cpp b/M2TWEOP Code/M2TWEOP library/patchesForGame.cpp index 9a718322..640d48db 100644 --- a/M2TWEOP Code/M2TWEOP library/patchesForGame.cpp +++ b/M2TWEOP Code/M2TWEOP library/patchesForGame.cpp @@ -1681,8 +1681,6 @@ void __fastcall patchesForGame::clickAtTile(coordPair* xy) void __stdcall patchesForGame::afterCampaignMapLoaded() { - if (!eopHiddenResources::isInitialized()) - eopHiddenResources::initialize(); discordManager::onCampaignMapLoaded(); globals::dataS.Modules.tacticalMapViewer.unView(); plugData::data.luaAll.fillHashMaps(); @@ -1732,6 +1730,8 @@ void __stdcall patchesForGame::onUnloadCampaign() } void __stdcall patchesForGame::onNewGameLoaded() { + if (!eopHiddenResources::isInitialized()) + eopHiddenResources::initialize(); eopCharacterDataDb::get()->clearData(); minorSettlementDb::load(); eopSettlementDataDb::get()->newGameLoaded(); @@ -1957,6 +1957,8 @@ void __fastcall patchesForGame::onEvent(DWORD** vTab, DWORD arg2) } else if (eventCode == gameReloaded) { + if (!eopHiddenResources::isInitialized()) + eopHiddenResources::initialize(); minorSettlementDb::load(); eopSettlementDataDb::get()->onGameLoaded(); eopFortDataDb::get()->onGameLoaded(); diff --git a/M2TWEOP Code/M2TWEOP library/types/characterRecord.cpp b/M2TWEOP Code/M2TWEOP library/types/characterRecord.cpp index 016851f9..5f9a7c75 100644 --- a/M2TWEOP Code/M2TWEOP library/types/characterRecord.cpp +++ b/M2TWEOP Code/M2TWEOP library/types/characterRecord.cpp @@ -831,10 +831,13 @@ namespace characterRecordHelpers Basic ancillary table @tfield int index + @tfield string localizedName + @tfield string description + @tfield string effectsDescription + @tfield string name (internal) @tfield int effectsNum @tfield bool isUnique @tfield bool transferable - @tfield string name @tfield string type @tfield string imagePath @tfield getEffect getEffect @@ -855,6 +858,15 @@ namespace characterRecordHelpers types.ancillary.set("imagePath", sol::property( &getStringPropertyAnc, &setStringPropertyAnc )); + types.ancillary.set("localizedName", sol::property( + &ancillary::getLocalizedName, &ancillary::setLocalizedName + )); + types.ancillary.set("description", sol::property( + &ancillary::getLocalizedDescr, &ancillary::setLocalizedDescr + )); + types.ancillary.set("effectsDescription", sol::property( + &ancillary::getLocalizedEffectsDescr, &ancillary::setLocalizedEffectsDescr + )); /*** Get an ancillary effect. @function ancillary:getEffect @@ -1041,6 +1053,36 @@ namespace characterRecordHelpers } } +std::string ancillary::getLocalizedName() +{ + return gameStringHelpers::uniStringToStr(*localizedAncName); +} + +void ancillary::setLocalizedName(const std::string& newName) +{ + gameStringHelpers::createUniString(*localizedAncName, newName.c_str()); +} + +std::string ancillary::getLocalizedDescr() +{ + return gameStringHelpers::uniStringToStr(*localizedAncDesc); +} + +void ancillary::setLocalizedDescr(const std::string& newDescr) +{ + gameStringHelpers::createUniString(*localizedAncDesc, newDescr.c_str()); +} + +std::string ancillary::getLocalizedEffectsDescr() +{ + return gameStringHelpers::uniStringToStr(*effectsDescr); +} + +void ancillary::setLocalizedEffectsDescr(const std::string& newDescr) +{ + gameStringHelpers::createUniString(*effectsDescr, newDescr.c_str()); +} + std::string characterRecord::giveValidLabel() { if (labelCrypt != 0 && label) diff --git a/M2TWEOP Code/M2TWEOP library/types/characterRecord.h b/M2TWEOP Code/M2TWEOP library/types/characterRecord.h index e6a6a865..32114d62 100644 --- a/M2TWEOP Code/M2TWEOP library/types/characterRecord.h +++ b/M2TWEOP Code/M2TWEOP library/types/characterRecord.h @@ -132,6 +132,12 @@ struct ancillary { /* structure of ancillary */ int typeHash; //004C bool transferable;//00050 char pad_0051[31]; + std::string getLocalizedName(); + void setLocalizedName(const std::string& newName); + std::string getLocalizedDescr(); + void setLocalizedDescr(const std::string& newDescr); + std::string getLocalizedEffectsDescr(); + void setLocalizedEffectsDescr(const std::string& newDescr); traitEffect* getEffect(const int i) { @@ -550,6 +556,7 @@ namespace characterRecordHelpers int addAncillary(characterRecord* character, ancillary* anc); void removeAncillary(characterRecord* character, ancillary* anc); ancillary* findAncillary(const std::string& ancName); + traitEntry* findTrait(const std::string& name); void removeTrait(characterRecord* character, const char* traitName); void addTrait(characterRecord* character, const char* traitName, int traitLevel); diff --git a/M2TWEOP Code/M2TWEOP library/types/eopBuildings.cpp b/M2TWEOP Code/M2TWEOP library/types/eopBuildings.cpp index 6f6acae0..2b060614 100644 --- a/M2TWEOP Code/M2TWEOP library/types/eopBuildings.cpp +++ b/M2TWEOP Code/M2TWEOP library/types/eopBuildings.cpp @@ -150,6 +150,8 @@ void eopHiddenResources::addHiddenResourceToRegionIndex(const std::string& name, bool eopHiddenResources::hasHiddenResource(const int regionId, const int id) { + if (!isInitialized()) + initialize(); if (regionId >= static_cast(m_HiddenResources.size())) return false; const auto& res = m_HiddenResources[regionId]; diff --git a/M2TWEOP Code/M2TWEOP library/types/faction.cpp b/M2TWEOP Code/M2TWEOP library/types/faction.cpp index 0a1c50bc..d8ce5a5f 100644 --- a/M2TWEOP Code/M2TWEOP library/types/faction.cpp +++ b/M2TWEOP Code/M2TWEOP library/types/faction.cpp @@ -1794,6 +1794,7 @@ namespace factionHelpers @tfield int secondaryColorBlue Warning: resets on reload. @tfield int triumphValue Usage unknown. @tfield int religionID + @tfield string name @tfield int standardIndex Warning: resets on reload. @tfield int logoIndex Warning: resets on reload. @tfield int smallLogoIndex Warning: resets on reload. @@ -1831,6 +1832,7 @@ namespace factionHelpers */ types.factionRecord = luaState.new_usertype("factionRecord"); types.factionRecord.set("primaryColorRed", &factionRecord::primary_colour_red); + types.factionRecord.set("name", &factionRecord::facName); types.factionRecord.set("primaryColorGreen", &factionRecord::primary_colour_green); types.factionRecord.set("primaryColorBlue", &factionRecord::primary_colour_blue); types.factionRecord.set("canHorde", &factionRecord::canHorde);