feat: added lua scripting to dedis

This commit is contained in:
Jari van der Kaap 2023-02-20 23:30:56 +01:00
parent 3706745bad
commit 11516da3af
2 changed files with 30 additions and 24 deletions

View File

@ -208,8 +208,11 @@ namespace ui_scripting
lua["luiglobals"] = lua;
utils::nt::library host{};
load_scripts((game::get_appdata_path() / "data/ui_scripts/").string());
load_scripts((host.get_folder() / "boiii/ui_scripts/").string());
std::string folder = "ui_scripts/";
if (game::is_server())
folder = "lobby_scripts/";
load_scripts((game::get_appdata_path() / "data" / folder).string());
load_scripts((host.get_folder() / "boiii" / folder).string());
}
void try_start()
@ -228,7 +231,7 @@ namespace ui_scripting
{
ui_cod_init_hook.invoke(frontend);
if (game::Com_IsRunningUILevel())
if (!game::is_server() && game::Com_IsRunningUILevel())
{
// Fetch the names of the local files so file overrides are already handled
globals = {};
@ -271,7 +274,7 @@ namespace ui_scripting
return load_buffer(globals.raw_script_name, utils::io::read_file(globals.raw_script_name));
}
return utils::hook::invoke<int>(0x141D3AFB0_g, state, compiler_options, reader, reader_data, debug_reader,
return utils::hook::invoke<int>(game::select(0x141D3AFB0, 0x1403E4090), state, compiler_options, reader, reader_data, debug_reader,
debug_reader_data, chunk_name);
}
@ -375,18 +378,21 @@ namespace ui_scripting
return closure;
}
class component final : public client_component
class component final : public generic_component
{
public:
void post_unpack() override
{
utils::hook::call(0x141D4979A_g, hks_load_stub);
utils::hook::call(game::select(0x141D4979A, 0x1403F233A), hks_load_stub);
hks_package_require_hook.create(0x141D28EF0_g, hks_package_require_stub);
ui_cod_init_hook.create(0x141F298B0_g, ui_cod_init_stub);
ui_cod_lobbyui_init_hook.create(0x141F2C620_g, ui_cod_lobbyui_init_stub);
ui_shutdown_hook.create(0x14270E9C0_g, ui_shutdown_stub);
lua_cod_getrawfile_hook.create(0x141F0F880_g, lua_cod_getrawfile_stub);
hks_package_require_hook.create(game::select(0x141D28EF0, 0x1403D7FC0), hks_package_require_stub);
ui_cod_init_hook.create(game::select(0x141F298B0, 0x1404A0A50), ui_cod_init_stub);
ui_cod_lobbyui_init_hook.create(game::select(0x141F2C620, 0x1404A1F50), ui_cod_lobbyui_init_stub);
ui_shutdown_hook.create(game::select(0x14270E9C0, 0x1404A1280), ui_shutdown_stub);
lua_cod_getrawfile_hook.create(game::select(0x141F0F880, 0x1404BCB70), lua_cod_getrawfile_stub);
if (game::is_server())
return;
dvar_cg_enable_unsafe_lua_functions = game::Dvar_RegisterBool(
game::Dvar_GenerateHash("cg_enable_unsafe_lua_functions"), "cg_enable_unsafe_lua_functions", false,

View File

@ -165,21 +165,21 @@ namespace game
namespace hks
{
WEAK symbol<lua_State*> lua_state {0x159C78D88};
WEAK symbol<void(lua_State* s, const char* str, unsigned int l)> hksi_lua_pushlstring{0x140A18430};
WEAK symbol<lua_State*> lua_state {0x159C78D88, 0x14858C408};
WEAK symbol<void(lua_State* s, const char* str, unsigned int l)> hksi_lua_pushlstring{0x140A18430, 0x1401DE6F0};
WEAK symbol<void(lua_State* s, const HksObject* tbl, const HksObject* key, const HksObject* val)> hks_obj_settable{0x141D4B660};
WEAK symbol<HksObject* (HksObject* result, lua_State* s, const HksObject* table, const HksObject* key)> hks_obj_gettable{0x141D4ABF0};
WEAK symbol<void(lua_State* s, int nargs, int nresults, const unsigned int* pc)> vm_call_internal{0x141D71070};
WEAK symbol<HashTable* (lua_State* s, unsigned int arraySize, unsigned int hashSize)> Hashtable_Create{0x141D3B5F0};
WEAK symbol<cclosure* (lua_State* s, lua_function function, int num_upvalues, int internal_, int profilerTreatClosureAsFunc)> cclosure_Create{0x141D3B7E0};
WEAK symbol<int(lua_State* s, int t)> hksi_luaL_ref{0x141D4D1A0};
WEAK symbol<void(lua_State* s, int t, int ref)> hksi_luaL_unref{0x141D4D320};
WEAK symbol<void(lua_State* s, const HksObject* tbl, const HksObject* key, const HksObject* val)> hks_obj_settable{0x141D4B660, 0x1403F41B0};
WEAK symbol<HksObject* (HksObject* result, lua_State* s, const HksObject* table, const HksObject* key)> hks_obj_gettable{0x141D4ABF0, 0x1403F3750};
WEAK symbol<void(lua_State* s, int nargs, int nresults, const unsigned int* pc)> vm_call_internal{0x141D71070, 0x140418E40};
WEAK symbol<HashTable* (lua_State* s, unsigned int arraySize, unsigned int hashSize)> Hashtable_Create{0x141D3B5F0, 0x1403E46D0};
WEAK symbol<cclosure* (lua_State* s, lua_function function, int num_upvalues, int internal_, int profilerTreatClosureAsFunc)> cclosure_Create{0x141D3B7E0, 0x1403E48C0};
WEAK symbol<int(lua_State* s, int t)> hksi_luaL_ref{0x141D4D1A0, 0x1403F5CF0};
WEAK symbol<void(lua_State* s, int t, int ref)> hksi_luaL_unref{0x141D4D320, 0x1403F5E70};
WEAK symbol<int(lua_State* s, const HksCompilerSettings* options, const char* buff, unsigned __int64 sz, const char* name)> hksi_hksL_loadbuffer{0x141D4BD80};
WEAK symbol<int(lua_State* s, const char* what, lua_Debug* ar)> hksi_lua_getinfo{0x141D4D960};
WEAK symbol<int(lua_State* s, int level, lua_Debug* ar)> hksi_lua_getstack{0x141D4DC20};
WEAK symbol<void(lua_State* s, const char* fmt, ...)> hksi_luaL_error{0x141D4D050};
WEAK symbol<int(lua_State* s, const HksCompilerSettings* options, const char* buff, unsigned __int64 sz, const char* name)> hksi_hksL_loadbuffer{0x141D4BD80, 0x1403F48D0};
WEAK symbol<int(lua_State* s, const char* what, lua_Debug* ar)> hksi_lua_getinfo{0x141D4D960, 0x1403F64B0};
WEAK symbol<int(lua_State* s, int level, lua_Debug* ar)> hksi_lua_getstack{0x141D4DC20, 0x1403F6770};
WEAK symbol<void(lua_State* s, const char* fmt, ...)> hksi_luaL_error{0x141D4D050, 0x1403F5BA0};
WEAK symbol<const char*> s_compilerTypeName{0x140A18430};
}
}