Skip to content

Commit

Permalink
PromoteGovernor
Browse files Browse the repository at this point in the history
  • Loading branch information
Wild-W committed Jun 30, 2024
1 parent 7ab9260 commit f29efa6
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
37 changes: 36 additions & 1 deletion Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<short*> lockedAppeals;

void __cdecl Hook_SetAppeal(void* plot, int appeal) {
Expand Down Expand Up @@ -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;

Expand All @@ -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<ProxyTypes::CCallWithErrorHandling>(C_CALL_WITH_ERROR_HANDLING_OFFSET);
Expand All @@ -295,6 +322,9 @@ static void InitHooks() {
DiplomaticRelations_ChangeGrievanceScore = GetGameCoreGlobalAt
<ProxyTypes::DiplomaticRelations_ChangeGrievanceScore>(DIPLOMATIC_RELATIONS_CHANGE_GRIEVANCE_SCORE_OFFSET);

PromoteGovernor = GetGameCoreGlobalAt<ProxyTypes::PromoteGovernor>(PROMOTE_GOVERNOR_OFFSET);
Governors_GetInstance = GetGameCoreGlobalAt<ProxyTypes::Governors_GetInstance>(GOVERNORS_GET_INSTANCE_OFFSET);

FAutoVariable_edit = GetGameCoreGlobalAt<ProxyTypes::FAutoVariable_edit>(GAME_F_AUTO_VARIABLE_EDIT_OFFSET);

orig_RegisterScriptData = GetGameCoreGlobalAt<ProxyTypes::RegisterScriptData>(REGISTER_SCRIPT_DATA_OFFSET);
Expand All @@ -318,6 +348,11 @@ static void InitHooks() {

orig_GameDiplomacy_PushMethods = GetGameCoreGlobalAt<ProxyTypes::InstancedPushMethods>(IGAME_DIPLOMACY_PUSH_METHODS_OFFSET);
CreateHook(orig_GameDiplomacy_PushMethods, &Hook_GameDiplomacy_PushMethods, &base_GameDiplomacy_PushMethods);

orig_IPlayerGovernors_PushMethods = GetGameCoreGlobalAt<ProxyTypes::InstancedPushMethods>(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) {
Expand Down
3 changes: 3 additions & 0 deletions ProxyTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}

0 comments on commit f29efa6

Please # to comment.