-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlua_hook.h
More file actions
79 lines (71 loc) · 4.58 KB
/
lua_hook.h
File metadata and controls
79 lines (71 loc) · 4.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#pragma once
#include "rvas.h"
#include <string>
struct lua_State;
typedef int (*lua_CFunction)(lua_State*);
// Function pointer types
typedef lua_State* (*fn_lua_open)();
typedef void (*fn_lua_pushstring)(lua_State*, const char*);
typedef void (*fn_lua_pushcclosure)(lua_State*, lua_CFunction, int);
typedef void (*fn_lua_settable)(lua_State*, int);
typedef const char* (*fn_lua_tostring)(lua_State*, int);
typedef double (*fn_lua_tonumber)(lua_State*, int);
typedef void (*fn_lua_newtable)(lua_State*);
typedef void (*fn_lua_rawseti)(lua_State*, int, int);
typedef void* (*fn_GetPlayerByIndex)(void*, int); // PlayerListClass::Get_Player_By_Index
typedef void* (*fn_PlayerWrapperCreate)(void*, void*); // PlayerWrapper::Create(PlayerClass*, LuaScriptClass*)
typedef void* (*fn_GetScriptFromState)(lua_State*); // LuaScriptClass::Get_Script_From_State
typedef void (*fn_MapVarToLua)(lua_State*, void*); // LuaScriptClass::Map_Var_To_Lua (static)
typedef void (*fn_AddTutorialText)(void*, void*, const char*, float, unsigned int, bool, void*); // CommandBarClass::Add_Tutorial_Text (inner)
typedef void (*fn_RemoveTutorialText)(void*, const char*); // CommandBarClass::Remove_Tutorial_Text
typedef void (*fn_DebugPrint)(const char*); // Debug_Print
// Scripting internals (LuaUserVar) -- usable by any wrapper module
typedef void (*fn_RegisterMember)(void* uservar, const char* name, void* fn_ptr); // LuaUserVar::Register_Member
typedef void* (*fn_ReturnVariable)(void* uservar, void* lua_var); // LuaUserVar::Return_Variable(LuaVar*) -> LuaTable*
// Game Object Type Wrapper internals
typedef void* (*fn_GotWrapperCtor)(void* this_wrapper); // GameObjectTypeWrapper::GameObjectTypeWrapper()
typedef void* (*fn_LuaUserVarCtor)(void* this_ptr, int param, bool flag); // LuaUserVar::LuaUserVar(int, bool)
// LuaValue<basic_string<>> constructor -- available in StarWarsI, inlined in StarWarsG
typedef void* (*fn_LuaValueStringCtor)(void* this_ptr, void* str_ptr); // LuaValue<basic_string<>>::LuaValue(basic_string*)
typedef void* (*fn_GameOperatorNew)(size_t size); // operator new(size_t) — game's CRT allocator
// GameObjectTypeClass::TextNameID is accessed via field offset (always inlined by compiler)
typedef void* (*fn_GameTextGet)(void* game_text, void* text_id_str, bool insert); // GameTextClass::Get(basic_string*, bool) -- returns wstring*
// Resolved function pointers (defined in lua_hook.cpp)
extern fn_lua_open real_lua_open;
extern fn_lua_pushstring pfn_pushstring;
extern fn_lua_pushcclosure pfn_pushcclosure;
extern fn_lua_settable pfn_settable;
extern fn_lua_tostring pfn_tostring;
extern fn_lua_tonumber pfn_tonumber;
extern fn_lua_newtable pfn_newtable;
extern fn_lua_rawseti pfn_rawseti;
extern fn_GetPlayerByIndex pfn_get_player_by_index;
extern void* g_player_list;
extern fn_PlayerWrapperCreate pfn_player_wrapper_create;
extern fn_GetScriptFromState pfn_get_script_from_state;
extern fn_MapVarToLua pfn_map_var_to_lua;
extern fn_AddTutorialText pfn_add_tutorial_text;
extern fn_RemoveTutorialText pfn_remove_tutorial_text;
extern void* g_command_bar;
extern fn_DebugPrint pfn_debug_print;
extern fn_RegisterMember pfn_register_member;
extern fn_ReturnVariable pfn_return_variable;
extern fn_GotWrapperCtor real_got_wrapper_ctor;
extern fn_LuaUserVarCtor pfn_lua_uservar_ctor;
extern size_t g_text_name_id_offset;
extern fn_LuaValueStringCtor pfn_lua_value_string_ctor;
extern fn_GameOperatorNew pfn_game_operator_new;
extern fn_GameTextGet pfn_game_text_get;
extern void* g_the_game_text;
extern const LuaRVAs* g_rvas;
extern uintptr_t g_base;
constexpr int LUA_GLOBALSINDEX = -10001;
// Equivalent of lua_setglobal — registers a C function in the Lua global table
void register_global(lua_State* L, const char* name, lua_CFunction fn);
// Creates a LuaValue<basic_string<>> from a std::string.
// Reproduces the inlined constructor pattern using per-executable layout constants.
void* CreateLuaValueString(const std::string& str);
// File-based debug logging (works on both executables; pfn_debug_print is unavailable on StarWarsG).
void debug_log(const char* fmt, ...);
bool LuaHook_Init();
void LuaHook_Shutdown();