From 9bd419a7cb9c432e40b7ad3bad6ee2f941273747 Mon Sep 17 00:00:00 2001 From: m Date: Mon, 24 Oct 2022 16:00:40 -0500 Subject: [PATCH] throw error on getfunction + cleanup --- src/client/component/gsc/script_extension.cpp | 14 ++++++-------- src/client/component/logfile.cpp | 5 ++--- src/client/game/scripting/script_value.hpp | 2 +- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/client/component/gsc/script_extension.cpp b/src/client/component/gsc/script_extension.cpp index cb164a72..009613d8 100644 --- a/src/client/component/gsc/script_extension.cpp +++ b/src/client/component/gsc/script_extension.cpp @@ -134,9 +134,8 @@ namespace gsc void vm_call_builtin_function_stub(builtin_function function) { const auto function_id = get_function_id(); - const auto is_custom_function = functions.find(function_id) != functions.end(); - if (!is_custom_function) + if (!functions.contains(function_id)) { function(); } @@ -156,9 +155,8 @@ namespace gsc void vm_call_builtin_method_stub(builtin_method method) { const auto function_id = get_function_id(); - const auto is_custom_function = methods.find(function_id) != methods.end(); - if (!is_custom_function) + if (!methods.contains(function_id)) { method(saved_ent_ref); } @@ -402,17 +400,17 @@ namespace gsc return scripting::script_value{}; }); - function::add("getfunction", [](const function_args& args) -> scripting::script_value + function::add("getfunction", [](const function_args& args) { const auto filename = args[0].as(); const auto function = args[1].as(); - if (scripting::script_function_table[filename].find(function) != scripting::script_function_table[filename].end()) + if (!scripting::script_function_table[filename].contains(function)) { - return scripting::function{scripting::script_function_table[filename][function]}; + throw std::runtime_error("function not found"); } - return {}; + return scripting::function{scripting::script_function_table[filename][function]}; }); function::add("replacefunc", [](const function_args& args) diff --git a/src/client/component/logfile.cpp b/src/client/component/logfile.cpp index abce3289..ddf5b5b5 100644 --- a/src/client/component/logfile.cpp +++ b/src/client/component/logfile.cpp @@ -29,7 +29,6 @@ namespace logfile utils::hook::detour scr_player_damage_hook; utils::hook::detour client_command_hook; - utils::hook::detour g_shutdown_game_hook; utils::hook::detour g_log_printf_hook; @@ -328,8 +327,8 @@ namespace logfile const scripting::entity level{*game::levelEntityId}; const scripting::entity player{game::Scr_GetEntityId(self->s.number, 0)}; - scripting::notify(level, cmd, {player, message, hidden}); - scripting::notify(player, cmd, {message, hidden}); + notify(level, cmd, {player, message, hidden}); + notify(player, cmd, {message, hidden}); game::G_LogPrintf("%s;%s;%i;%s;%s\n", cmd, diff --git a/src/client/game/scripting/script_value.hpp b/src/client/game/scripting/script_value.hpp index 7c519828..3adbb9ef 100644 --- a/src/client/game/scripting/script_value.hpp +++ b/src/client/game/scripting/script_value.hpp @@ -30,7 +30,7 @@ namespace scripting {11, "builtin method"}, {12, "stack"}, {13, "animation"}, - {14, "developer codepos"}, // this exists on H1 but not IW6 + {14, "developer codepos"}, // this exists on H1 but not IW6 (also not sure if past here may be correct) {15, "pre animation"}, {16, "thread"}, {17, "notify thread"},