diff --git a/Main.cpp b/Main.cpp index 30f8d31..296a869 100644 --- a/Main.cpp +++ b/Main.cpp @@ -21,6 +21,9 @@ ProxyTypes::PushMethods orig_Cities_PushMethods; ProxyTypes::PushMethods base_Influence_PushMethods; ProxyTypes::PushMethods orig_Influence_PushMethods; +ProxyTypes::InstancedPushMethods base_IPlayerGovernors_PushMethods; +ProxyTypes::InstancedPushMethods orig_IPlayerGovernors_PushMethods; + ProxyTypes::InstancedPushMethods base_GameDiplomacy_PushMethods; ProxyTypes::InstancedPushMethods orig_GameDiplomacy_PushMethods; @@ -52,6 +55,9 @@ ProxyTypes::RegisterScriptData orig_RegisterScriptData; ProxyTypes::RegisterScriptDataForUI base_RegisterScriptDataForUI; ProxyTypes::RegisterScriptDataForUI orig_RegisterScriptDataForUI; +ProxyTypes::PromoteGovernor PromoteGovernor; +ProxyTypes::Governors_GetInstance Governors_GetInstance; + std::set lockedAppeals; void __cdecl Hook_SetAppeal(void* plot, int appeal) { @@ -245,6 +251,23 @@ static void __cdecl Hook_GameDiplomacy_PushMethods(void* _, hks::lua_State* L, i base_GameDiplomacy_PushMethods(_, L, stackOffset); } +static int lPromoteGovernor(hks::lua_State* L) { + void* governors = Governors_GetInstance(L, 1, true); + int governorId = hks::checkinteger(L, 2); + int governorPromotionIndex = hks::checkinteger(L, 3); + + hks::pushinteger(L, PromoteGovernor(governors, governorId, governorPromotionIndex)); + return 1; +} + +static void __cdecl Hook_IPlayerGovernors_PushMethods(void* _, hks::lua_State* L, int stackOffset) { + std::cout << "Hooked PlayerGovernors::PushMethods!\n"; + + PushLuaMethod(L, lPromoteGovernor, "lPromoteGovernor", stackOffset, "PromoteGovernor"); + + base_IPlayerGovernors_PushMethods(_, L, stackOffset); +} + #pragma region Offsets constexpr uintptr_t CURRENT_GAME_OFFSET = 0xb8aa60; @@ -270,10 +293,14 @@ constexpr uintptr_t CULTURE_FIND_OR_ADD_GREAT_WORK_OFFSET = 0x1c80e0; constexpr uintptr_t CULTURE_SET_GREAT_WORK_PLAYER_OFFSET = 0x1c8c80; constexpr uintptr_t DIPLOMATIC_RELATIONS_GET_INSTANCE_OFFSET = 0x6d86e0; constexpr uintptr_t IGAME_DIPLOMACY_PUSH_METHODS_OFFSET = 0x745660; +constexpr uintptr_t PROMOTE_GOVERNOR_OFFSET = 0x2df340; +constexpr uintptr_t IPLAYER_GOVERNORS_PUSH_METHODS_OFFSET = 0x713b20; +constexpr uintptr_t GOVERNORS_GET_INSTANCE_OFFSET = 0x7139c0; +constexpr uintptr_t NEUTRALIAZE_GOVERNOR_OFFSET = 0x2df270; #pragma endregion static void InitHooks() { - std::cout << "Initializing hooks!\n"; + std::cout << "Initializing hooks ...\n"; using namespace Runtime; CCallWithErrorHandling = GetGameCoreGlobalAt(C_CALL_WITH_ERROR_HANDLING_OFFSET); @@ -295,6 +322,9 @@ static void InitHooks() { DiplomaticRelations_ChangeGrievanceScore = GetGameCoreGlobalAt (DIPLOMATIC_RELATIONS_CHANGE_GRIEVANCE_SCORE_OFFSET); + PromoteGovernor = GetGameCoreGlobalAt(PROMOTE_GOVERNOR_OFFSET); + Governors_GetInstance = GetGameCoreGlobalAt(GOVERNORS_GET_INSTANCE_OFFSET); + FAutoVariable_edit = GetGameCoreGlobalAt(GAME_F_AUTO_VARIABLE_EDIT_OFFSET); orig_RegisterScriptData = GetGameCoreGlobalAt(REGISTER_SCRIPT_DATA_OFFSET); @@ -318,6 +348,11 @@ static void InitHooks() { orig_GameDiplomacy_PushMethods = GetGameCoreGlobalAt(IGAME_DIPLOMACY_PUSH_METHODS_OFFSET); CreateHook(orig_GameDiplomacy_PushMethods, &Hook_GameDiplomacy_PushMethods, &base_GameDiplomacy_PushMethods); + + orig_IPlayerGovernors_PushMethods = GetGameCoreGlobalAt(IPLAYER_GOVERNORS_PUSH_METHODS_OFFSET); + CreateHook(orig_IPlayerGovernors_PushMethods, &Hook_IPlayerGovernors_PushMethods, &base_IPlayerGovernors_PushMethods); + + std::cout << "Hooks initialized!\n"; } DWORD WINAPI MainThread(LPVOID lpParam) { diff --git a/ProxyTypes.h b/ProxyTypes.h index 1722606..d78d82f 100644 --- a/ProxyTypes.h +++ b/ProxyTypes.h @@ -9,6 +9,7 @@ namespace ProxyTypes { typedef void* (__cdecl* IPlayerCities_GetInstance)(hks::lua_State*, int, bool); typedef void* (__cdecl* IPlayerInfluence_GetInstance)(hks::lua_State*, int, bool); typedef void* (__cdecl* ICityTrade_GetInstance)(hks::lua_State*, int, bool); + typedef void* (__cdecl* Governors_GetInstance)(hks::lua_State*, int, bool); typedef void(__cdecl* RegisterScriptDataForUI)(hks::lua_State* _, hks::lua_State* L); typedef void(__cdecl* DiplomaticRelations_ChangeGrievanceScore)(void* diplomaticRelations, int player1Id, int player2Id, int amount); typedef void(__thiscall* SetAppeal)(void* plot, int appeal); @@ -27,4 +28,6 @@ namespace ProxyTypes { typedef int (__thiscall* FindOrAddGreatWork)(void* culture, unsigned int greatWorkIndex); typedef void(__thiscall* SetGreatWorkPlayer)(void* culture, unsigned int, int playerId); typedef void* (__cdecl* DiplomaticRelations_GetInstance)(hks::lua_State*, int, bool); + typedef bool(__thiscall* PromoteGovernor)(void* governors, int governorId, int governorPromotionIndex); + typedef void(__thiscall* NeutralizeGovernor)(void* governors, void* governor, int neutralizedTurns); }