From 818129fa3ce4e726d86ca5e0af142771d057c301 Mon Sep 17 00:00:00 2001 From: "Drew C." Date: Sat, 28 Feb 2026 13:28:06 -0600 Subject: [PATCH] Include RVAs for both StarWarsI.exe and StarWarsG.exe --- lua_hook.cpp | 25 ++++++++++++++++++++----- lua_hook.h | 30 +++++++++++++++++++++++++----- 2 files changed, 45 insertions(+), 10 deletions(-) diff --git a/lua_hook.cpp b/lua_hook.cpp index 3e41295..eb5e124 100644 --- a/lua_hook.cpp +++ b/lua_hook.cpp @@ -86,14 +86,29 @@ static lua_State* Hook_lua_open() { } bool LuaHook_Init() { + char exePath[MAX_PATH]; + GetModuleFileNameA(nullptr, exePath, MAX_PATH); + + const LuaRVAs* rvas = nullptr; + if (strstr(exePath, "StarWarsI.exe")) + rvas = &RVAs_StarWarsI; + else if (strstr(exePath, "StarWarsG.exe")) + rvas = &RVAs_StarWarsG; + else + return false; + + if (!rvas->lua_open || !rvas->lua_pushstring || !rvas->lua_pushcclosure || + !rvas->lua_settable || !rvas->lua_tostring) + return false; + uintptr_t base = (uintptr_t)GetModuleHandleA(nullptr); - pfn_pushstring = (fn_lua_pushstring)(base + RVA_lua_pushstring); - pfn_pushcclosure = (fn_lua_pushcclosure)(base + RVA_lua_pushcclosure); - pfn_settable = (fn_lua_settable)(base + RVA_lua_settable); - pfn_tostring = (fn_lua_tostring)(base + RVA_lua_tostring); + pfn_pushstring = (fn_lua_pushstring)(base + rvas->lua_pushstring); + pfn_pushcclosure = (fn_lua_pushcclosure)(base + rvas->lua_pushcclosure); + pfn_settable = (fn_lua_settable)(base + rvas->lua_settable); + pfn_tostring = (fn_lua_tostring)(base + rvas->lua_tostring); - void* const target = (void*)(base + RVA_lua_open); + void* const target = (void*)(base + rvas->lua_open); if (MH_Initialize() != MH_OK) { return false; diff --git a/lua_hook.h b/lua_hook.h index 7628a6c..077848c 100644 --- a/lua_hook.h +++ b/lua_hook.h @@ -1,11 +1,31 @@ #pragma once #include -constexpr uintptr_t RVA_lua_open = 0x12AB790; -constexpr uintptr_t RVA_lua_pushstring = 0x12AC930; -constexpr uintptr_t RVA_lua_pushcclosure = 0x12AC6E0; -constexpr uintptr_t RVA_lua_settable = 0x12AD020; -constexpr uintptr_t RVA_lua_tostring = 0x12AD430; +struct LuaRVAs { + uintptr_t lua_open; + uintptr_t lua_pushstring; + uintptr_t lua_pushcclosure; + uintptr_t lua_settable; + uintptr_t lua_tostring; +}; + +// StarWarsI.exe -- debug kit, PDB available +constexpr LuaRVAs RVAs_StarWarsI = { + 0x12AB790, // lua_open + 0x12AC930, // lua_pushstring + 0x12AC6E0, // lua_pushcclosure + 0x12AD020, // lua_settable + 0x12AD430, // lua_tostring +}; + +// StarWarsG.exe -- client binary, no PDB +constexpr LuaRVAs RVAs_StarWarsG = { + 0x07b8930, // lua_open + 0x07b9540, // lua_pushstring + 0x07b9340, // lua_pushcclosure + 0x07b9a60, // lua_settable + 0x07b9cc0, // lua_tostring +}; constexpr int LUA_GLOBALSINDEX = -10001;