From 375f4499ec3ab480ddfd4343e551bfb3d98c2ac9 Mon Sep 17 00:00:00 2001 From: Diavolo Date: Sun, 28 Aug 2022 11:07:31 +0200 Subject: [PATCH] gsc: allow scripts with both handles to load, assert gsc funcs --- src/client/component/gsc.cpp | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/client/component/gsc.cpp b/src/client/component/gsc.cpp index 7827f41f..5226da19 100644 --- a/src/client/component/gsc.cpp +++ b/src/client/component/gsc.cpp @@ -146,7 +146,8 @@ namespace gsc console::info("Loaded '%s::main'\n", name.data()); main_handles[name] = main_handle; } - else if (init_handle) + + if (init_handle) { console::info("Loaded '%s::init'\n", name.data()); init_handles[name] = init_handle; @@ -388,6 +389,24 @@ namespace gsc gsc_error = error; game::Scr_ErrorInternal(); } + + void assert_cmd() + { + const auto expr = get_argument(0).as(); + if (!expr) + { + set_gsc_error("assert fail"); + } + } + + void assertex_cmd() + { + const auto expr = get_argument(0).as(); + if (!expr) + { + set_gsc_error(get_argument(1).as()); + } + } } game::ScriptFile* find_script(game::XAssetType /*type*/, const char* name, int /*allow_create_default*/) @@ -450,6 +469,10 @@ namespace gsc // replace builtin print function utils::hook::jump(0x1404EC640, gscr_print_stub); + // restore assert + utils::hook::jump(0x1404EC890, assert_cmd); + utils::hook::jump(0x1404EC920, assertex_cmd); + utils::hook::call(0x1405CB94F, vm_error_stub); utils::hook::call(0x1405BC583, unknown_function_stub); @@ -479,7 +502,7 @@ namespace gsc if (with.type != game::SCRIPT_FUNCTION) { - set_gsc_error("replaceFunc: parameter 0 must be a function"); + set_gsc_error("replaceFunc: parameter 1 must be a function"); return; }