diff --git a/M2TWEOP Code/M2TWEOP library/Injects.cpp b/M2TWEOP Code/M2TWEOP library/Injects.cpp index 8cfe9502..640ffb87 100644 --- a/M2TWEOP Code/M2TWEOP library/Injects.cpp +++ b/M2TWEOP Code/M2TWEOP library/Injects.cpp @@ -5754,6 +5754,34 @@ void onCreateMarriageOption::SetNewCode() delete a; } +onEnemyClicked::onEnemyClicked(MemWork* mem, LPVOID addr, int ver) + :AATemplate(mem), funcAddress(addr) +{ + if (ver == 2)//steam + m_adress = 0x004DCDD4; + + else if (ver == 1)//kingdoms + m_adress = 0x4F0FD3; +} + +void onEnemyClicked::SetNewCode() +{ + const auto a = new Assembler(); + a->add(ecx, 0x88); + a->push(ecx); + a->push(edx); + a->push(eax); + a->mov(ecx, eax); + a->mov(eax, reinterpret_cast(funcAddress)); + a->call(eax); + a->pop(eax); + a->pop(edx); + a->pop(ecx); + a->ret(); + m_cheatBytes = static_cast(a->make()); + delete a; +} + onCreateMarriageOption2::onCreateMarriageOption2(MemWork* mem, LPVOID addr, int ver) :AATemplate(mem), funcAddress(addr) { diff --git a/M2TWEOP Code/M2TWEOP library/Injects.h b/M2TWEOP Code/M2TWEOP library/Injects.h index 0ba0adfb..28c29624 100644 --- a/M2TWEOP Code/M2TWEOP library/Injects.h +++ b/M2TWEOP Code/M2TWEOP library/Injects.h @@ -2105,6 +2105,18 @@ class onCreateMarriageOption LPVOID funcAddress; }; +class onEnemyClicked + :public AATemplate +{ +public: + onEnemyClicked(MemWork* mem, LPVOID addr, int ver); + ~onEnemyClicked() = default; + + void SetNewCode(); +private: + LPVOID funcAddress; +}; + class onCreateMarriageOption2 :public AATemplate { diff --git a/M2TWEOP Code/M2TWEOP library/luaPlugin.h b/M2TWEOP Code/M2TWEOP library/luaPlugin.h index 9e86a199..b023e88d 100644 --- a/M2TWEOP Code/M2TWEOP library/luaPlugin.h +++ b/M2TWEOP Code/M2TWEOP library/luaPlugin.h @@ -126,6 +126,7 @@ class luaPlugin sol::function* onCalculateUnitValue = nullptr; sol::function* onChangeTurnNumFunc = nullptr; sol::function* onClickAtTile = nullptr; + sol::function* onCharacterClicked = nullptr; sol::function* onNewGameStart = nullptr; sol::function* onPluginLoad = nullptr; sol::function* onCreateSaveFile = nullptr; diff --git a/M2TWEOP Code/M2TWEOP library/managerF.cpp b/M2TWEOP Code/M2TWEOP library/managerF.cpp index 6c9f32e6..1d994c3f 100644 --- a/M2TWEOP Code/M2TWEOP library/managerF.cpp +++ b/M2TWEOP Code/M2TWEOP library/managerF.cpp @@ -922,6 +922,12 @@ void managerF::execPatches() toCreateMarriageOption2->Enable(); f1 << "Done" << '\n'; + //f1 << "Start applying onEnemyClicked patch" << '\n'; + //onEnemyClicked* toEnemyClicked = new onEnemyClicked(mem, (LPVOID)patchesForGame::onEnemyClicked, globals::dataS.gameVersion); + //toEnemyClicked->SetNewCode(); + //toEnemyClicked->Enable(); + //f1 << "Done" << '\n'; + f1 << "Start applying onCreateBirthOption patch" << '\n'; onCreateBirthOption* toCreateBirthOption = new onCreateBirthOption(mem, (LPVOID)patchesForGame::onMarriageOption, globals::dataS.gameVersion); toCreateBirthOption->SetNewCode(); diff --git a/M2TWEOP Code/M2TWEOP library/patchesForGame.cpp b/M2TWEOP Code/M2TWEOP library/patchesForGame.cpp index 640d48db..c39769b8 100644 --- a/M2TWEOP Code/M2TWEOP library/patchesForGame.cpp +++ b/M2TWEOP Code/M2TWEOP library/patchesForGame.cpp @@ -1675,10 +1675,20 @@ character* __fastcall patchesForGame::mercenaryMovePointsGetGeneral(armyStruct* void __fastcall patchesForGame::clickAtTile(coordPair* xy) { + const auto tile = stratMapHelpers::getTile(xy->xCoord, xy->yCoord); + if (!tile) + return; + if (const auto character = tile->getCharacter(); character) + onCharacterClicked(character); gameEvents::onClickAtTile(xy->xCoord, xy->yCoord); plannedRetreatRoute::onClickAtTile(xy->xCoord, xy->yCoord); } +void __fastcall patchesForGame::onCharacterClicked(character* enemy) +{ + gameEvents::onCharacterClicked(enemy); +} + void __stdcall patchesForGame::afterCampaignMapLoaded() { discordManager::onCampaignMapLoaded(); diff --git a/M2TWEOP Code/M2TWEOP library/patchesForGame.h b/M2TWEOP Code/M2TWEOP library/patchesForGame.h index e083a780..53082b5d 100644 --- a/M2TWEOP Code/M2TWEOP library/patchesForGame.h +++ b/M2TWEOP Code/M2TWEOP library/patchesForGame.h @@ -122,6 +122,7 @@ class patchesForGame static unit** __fastcall onGetUnitByLabel(DWORD unitLabels, char* label); static unitGroup** __fastcall onGetGroupByLabel(DWORD groupLabels, char* label); static char* __fastcall onGetCultureEndTurnSound(int cultureID); + static void __fastcall onCharacterClicked(character* enemy); static character* __fastcall mercenaryMovePointsGetGeneral(armyStruct* army); diff --git a/M2TWEOP Code/M2TWEOP library/types/eopBuildings.h b/M2TWEOP Code/M2TWEOP library/types/eopBuildings.h index e5cf4589..d6e8f838 100644 --- a/M2TWEOP Code/M2TWEOP library/types/eopBuildings.h +++ b/M2TWEOP Code/M2TWEOP library/types/eopBuildings.h @@ -160,21 +160,21 @@ struct buildingLevel { /* (name, tga's, models, etc) */ std::string getLocalizedName(const int factionID); void setLocalizedName(const int factionID, const std::string& newName) { - const auto nameMem = new UNICODE_STRING**; + const auto nameMem = techFuncs::createGameClass(); buildingName[factionID] = nameMem; gameStringHelpers::createUniString(*buildingName[factionID], newName.c_str()); } std::string getLocalizedDescr(const int factionID); void setLocalizedDescr(const int factionID, const std::string& newName) { - const auto nameMem = new UNICODE_STRING**; + const auto nameMem = techFuncs::createGameClass(); buildingDescr[factionID] = nameMem; gameStringHelpers::createUniString(*buildingDescr[factionID], newName.c_str()); } std::string getLocalizedDescrShort(const int factionID); void setLocalizedDescrShort(const int factionID, const std::string& newName) { - const auto nameMem = new UNICODE_STRING**; + const auto nameMem = techFuncs::createGameClass(); buildingDescrShort[factionID] = nameMem; gameStringHelpers::createUniString(*buildingDescrShort[factionID], newName.c_str()); } diff --git a/M2TWEOP Code/M2TWEOP library/types/events.cpp b/M2TWEOP Code/M2TWEOP library/types/events.cpp index bb606754..f197ca9f 100644 --- a/M2TWEOP Code/M2TWEOP library/types/events.cpp +++ b/M2TWEOP Code/M2TWEOP library/types/events.cpp @@ -795,6 +795,14 @@ void onClickAtTile(int x, int y) } } +void onCharacterClicked(character* enemy) +{ + if (plugData::data.luaAll.onCharacterClicked != nullptr) + { + tryLua((*plugData::data.luaAll.onCharacterClicked)(enemy)); + } +} + std::string* onSelectWorldpkgdesc(const char* selectedRec, const char* selectedGroup) { std::string tmpS; @@ -1338,6 +1346,7 @@ void luaPlugin::onPluginLoadF() @tfield onUnloadCampaign onUnloadCampaign @tfield onAiTurn onAiTurn @tfield onClickAtTile onClickAtTile + @tfield onCharacterClicked onCharacterClicked @tfield onCampaignMapLoaded onCampaignMapLoaded @tfield onCreateSaveFile onCreateSaveFile @tfield onLoadSaveFile onLoadSaveFile @@ -4194,6 +4203,20 @@ void luaPlugin::onPluginLoadF() onClickAtTile = new sol::function(luaState["onClickAtTile"]); checkLuaFunc(&onClickAtTile); + /*** + Called when clicking on a character. + + @function onCharacterClicked + @tparam character clickedCharacter + @usage + + function onCharacterClicked(clickedCharacter) + --something here + end + */ + onCharacterClicked = new sol::function(luaState["onCharacterClicked"]); + checkLuaFunc(&onCharacterClicked); + /*** Called after loading the campaign map diff --git a/M2TWEOP Code/M2TWEOP library/types/events.h b/M2TWEOP Code/M2TWEOP library/types/events.h index b0f9f085..0bc53437 100644 --- a/M2TWEOP Code/M2TWEOP library/types/events.h +++ b/M2TWEOP Code/M2TWEOP library/types/events.h @@ -236,6 +236,7 @@ namespace gameEvents void onClickAtTile(int x, int y); + void onCharacterClicked(character* enemy); std::string * onSelectWorldpkgdesc(const char* selectedRec, const char* selectedGroup); int onFortificationLevelS(settlementStruct * settlement, bool* isCastle, bool* isChanged); float onCalculateUnitValue(eduEntry* entry, float value); diff --git a/M2TWEOP Code/M2TWEOP library/types/unit.cpp b/M2TWEOP Code/M2TWEOP library/types/unit.cpp index da8594d9..67a4d671 100644 --- a/M2TWEOP Code/M2TWEOP library/types/unit.cpp +++ b/M2TWEOP Code/M2TWEOP library/types/unit.cpp @@ -1298,22 +1298,22 @@ namespace unitHelpers void setUnitName(eduEntry* entry, const std::string& name) { - const auto nameMem = new UNICODE_STRING**; + const auto nameMem = techFuncs::createGameClass(); entry->localizedName = nameMem; gameStringHelpers::createUniString(*entry->localizedName, name.c_str()); } void setUnitDescr(eduEntry* entry, const std::string& descr) { - const auto descrMem = new UNICODE_STRING * *[4]; - entry->localizedDescr = descrMem; + const auto nameMem = techFuncs::createGameClass(); + entry->localizedDescr = nameMem; gameStringHelpers::createUniString(*entry->localizedDescr, descr.c_str()); } void setUnitDescrShort(eduEntry* entry, const std::string& descr) { - const auto shDescrMem = new UNICODE_STRING * *[4]; - entry->localizedDescrShort = shDescrMem; + const auto nameMem = techFuncs::createGameClass(); + entry->localizedDescrShort = nameMem; gameStringHelpers::createUniString(*entry->localizedDescrShort, descr.c_str()); }