From 77abb1a7e106428fef1e8c42f96a38d92aabd652 Mon Sep 17 00:00:00 2001 From: Maurice Heumann Date: Tue, 21 Feb 2023 17:48:00 +0100 Subject: [PATCH] Cleanup --- src/client/component/ui_scripting.cpp | 40 +++++++++---------- src/client/game/ui_scripting/script_value.hpp | 23 ++++++----- 2 files changed, 30 insertions(+), 33 deletions(-) diff --git a/src/client/component/ui_scripting.cpp b/src/client/component/ui_scripting.cpp index c7ee155f..bc4f574c 100644 --- a/src/client/component/ui_scripting.cpp +++ b/src/client/component/ui_scripting.cpp @@ -26,7 +26,7 @@ namespace ui_scripting utils::hook::detour lua_cod_getrawfile_hook; game::dvar_t* dvar_cg_enable_unsafe_lua_functions; - static bool unsafe_function_called_message_shown = false; + bool unsafe_function_called_message_shown = false; struct globals_t { @@ -171,10 +171,7 @@ namespace ui_scripting void setup_functions() { const auto lua = get_globals(); - - using game = table; - auto game_type = game(); - lua["game"] = game_type; + lua["game"] = table(); } void enable_globals() @@ -207,10 +204,8 @@ namespace ui_scripting lua["table"]["unpack"] = lua["unpack"]; lua["luiglobals"] = lua; - utils::nt::library host{}; - std::string folder = "ui_scripts/"; - if (game::is_server()) - folder = "lobby_scripts/"; + const utils::nt::library host{}; + const auto folder = game::is_server() ? "lobby_scripts/" : "ui_scripts/"; load_scripts((game::get_appdata_path() / "data" / folder).string()); load_scripts((host.get_folder() / "boiii" / folder).string()); } @@ -227,7 +222,7 @@ namespace ui_scripting } } - void ui_cod_init_stub(bool frontend) + void ui_cod_init_stub(const bool frontend) { ui_cod_init_hook.invoke(frontend); @@ -235,7 +230,8 @@ namespace ui_scripting { // Fetch the names of the local files so file overrides are already handled globals = {}; - utils::nt::library host{}; + const utils::nt::library host{}; + load_local_script_files((game::get_appdata_path() / "data/ui_scripts/").string()); load_local_script_files((host.get_folder() / "boiii/ui_scripts/").string()); return; @@ -274,14 +270,13 @@ namespace ui_scripting return load_buffer(globals.raw_script_name, utils::io::read_file(globals.raw_script_name)); } - return utils::hook::invoke(game::select(0x141D3AFB0, 0x1403E4090), state, compiler_options, reader, reader_data, debug_reader, + return utils::hook::invoke(game::select(0x141D3AFB0, 0x1403E4090), state, compiler_options, reader, + reader_data, debug_reader, debug_reader_data, chunk_name); } game::XAssetHeader lua_cod_getrawfile_stub(char* filename) { - game::XAssetHeader header{.luaFile = nullptr}; - if (!is_loaded_script(globals.in_require_script) && !is_local_script(filename)) { return lua_cod_getrawfile_hook.invoke(filename); @@ -303,9 +298,10 @@ namespace ui_scripting { globals.load_raw_script = true; globals.raw_script_name = target_script; - header.luaFile = reinterpret_cast(1); - return header; + return game::XAssetHeader{ + .luaFile = reinterpret_cast(1) // + }; } return lua_cod_getrawfile_hook.invoke(filename); @@ -392,7 +388,9 @@ namespace ui_scripting 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, @@ -402,19 +400,17 @@ namespace ui_scripting scheduler::once([]() { game::dvar_t* dvar_callstack_ship = game::Dvar_FindVar("ui_error_callstack_ship"); - dvar_callstack_ship->flags = (game::dvarFlags_e)0; + dvar_callstack_ship->flags = static_cast(0); game::dvar_t* dvar_report_delay = game::Dvar_FindVar("ui_error_report_delay"); - dvar_report_delay->flags = (game::dvarFlags_e)0; + dvar_report_delay->flags = static_cast(0); game::Dvar_SetFromStringByName("ui_error_callstack_ship", "1", true); game::Dvar_SetFromStringByName("ui_error_report_delay", "0", true); }, scheduler::pipeline::renderer); - command::add("luiReload", [](auto& params) + command::add("luiReload", [] { - auto frontend = game::Com_IsRunningUILevel(); - - if (frontend) + if (game::Com_IsRunningUILevel()) { converted_functions.clear(); diff --git a/src/client/game/ui_scripting/script_value.hpp b/src/client/game/ui_scripting/script_value.hpp index 479e8a11..67d3c16e 100644 --- a/src/client/game/ui_scripting/script_value.hpp +++ b/src/client/game/ui_scripting/script_value.hpp @@ -78,7 +78,7 @@ namespace ui_scripting void assign(const game::hks::HksObject& value); void release(); - game::hks::HksObject value_{ game::hks::TNONE, {} }; + game::hks::HksObject value_{game::hks::TNONE, {}}; int ref_{}; }; @@ -133,25 +133,25 @@ namespace ui_scripting bool operator==(const script_value& other) const; - arguments operator()() const; - arguments operator()(const arguments& arguments) const; + [[maybe_unused]] arguments operator()() const; + [[maybe_unused]] arguments operator()(const arguments& arguments) const; - template - arguments operator()(T... arguments) const + template + [[maybe_unused]] arguments operator()(T ... arguments) const { - return this->as().call({ arguments... }); + return this->as().call({arguments...}); } template - table_value operator[](const char(&key)[Size]) const + table_value operator[](const char (&key)[Size]) const { - return { this->as(), key }; + return {this->as
(), key}; } template table_value operator[](const T& key) const { - return { this->as
(), key }; + return {this->as
(), key}; } template @@ -240,11 +240,12 @@ namespace ui_scripting { if (static_cast(index) >= values_.size()) { - return { values_, {}, index }; + return {values_, {}, index}; } - return { values_, values_[index], index }; + return {values_, values_[index], index}; } + private: arguments values_{}; };