From da43fb33ee48aa98ad2ae7b1bf9b486b8ae48ace Mon Sep 17 00:00:00 2001 From: Jari van der Kaap Date: Sun, 12 Feb 2023 19:32:33 +0100 Subject: [PATCH] Added luiReload command --- src/client/component/ui_scripting.cpp | 29 +++++++++++++++++++++++++-- src/client/game/symbols.hpp | 12 ++++++++++- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/src/client/component/ui_scripting.cpp b/src/client/component/ui_scripting.cpp index 2b02bc93..f283457e 100644 --- a/src/client/component/ui_scripting.cpp +++ b/src/client/component/ui_scripting.cpp @@ -4,6 +4,7 @@ #include "game/ui_scripting/execution.hpp" +#include "command.hpp" #include "ui_scripting.hpp" #include "scheduler.hpp" @@ -393,12 +394,36 @@ namespace ui_scripting game::Dvar_SetFromStringByName("ui_error_report_delay", "0", true); }, scheduler::pipeline::renderer); + command::add("luiReload", [](auto& params) + { + auto frontend = game::Com_IsRunningUILevel(); + + if (frontend) + { + converted_functions.clear(); + + globals.loaded_scripts.clear(); + globals.local_scripts.clear(); + + game::UI_CoD_Shutdown(); + game::UI_CoD_Init(true); + + // Com_LoadFrontEnd stripped + game::Lua_CoD_LoadLuaFile(*game::hks::lua_state, "ui_mp.T6.main"); + game::UI_AddMenu(game::UI_CoD_GetRootNameForController(0), "main", -1, *game::hks::lua_state); + + game::UI_CoD_LobbyUI_Init(); + } + else + { + // TODO: Find a way to do a full shutdown & restart like in frontend, that opens up the loading screen that can't be easily closed + game::CG_LUIHUDRestart(0); + } + }); scheduler::once([]() { - printf("dvar_cg_enable_unsafe_lua_functions scheduler %s", game::Dvar_DisplayableValue(dvar_cg_enable_unsafe_lua_functions)); if (!dvar_cg_enable_unsafe_lua_functions->current.enabled) { - printf("dvar_cg_enable_unsafe_lua_functions add jumps"); // Do not allow the HKS vm to open LUA's libraries // Disable unsafe functions utils::hook::jump(0x141D34190_g, luaopen_stub); // debug diff --git a/src/client/game/symbols.hpp b/src/client/game/symbols.hpp index 44505a57..0812052a 100644 --- a/src/client/game/symbols.hpp +++ b/src/client/game/symbols.hpp @@ -90,7 +90,17 @@ namespace game 0x1422C7F60 }; WEAK symbol s_dvarPool{ 0x157AC8220 }; - WEAK symbol g_dvarCount{ 0x157AC81CC }; + WEAK symbol g_dvarCount{ 0x157AC81CC }; + + // UI + WEAK symbol UI_CoD_Init{ 0x141F298B0, 0x0 }; + WEAK symbol UI_CoD_LobbyUI_Init{ 0x141F2C620, 0x0 }; + WEAK symbol UI_CoD_Shutdown{ 0x141F336B0, 0x0 }; + WEAK symbol UI_AddMenu{ 0x1427024B0, 0x0 }; + WEAK symbol UI_CoD_GetRootNameForController{ 0x141F291E0, 0x0 }; + WEAK symbol Lua_CoD_LoadLuaFile{ 0x141F122C0, 0x0 }; + WEAK symbol CG_LUIHUDRestart{ 0x140F7E970 }; + WEAK symbol CL_CheckKeepDrawingConnectScreen{ 0x1413CCAE0 }; // Scr WEAK symbol Scr_AddInt{0x0, 0x14016F160};