From 526e67524cf8a641ff4f3f9d05e31343a5b5a8ec Mon Sep 17 00:00:00 2001 From: Federico Cecchetto Date: Fri, 2 Sep 2022 19:01:53 +0200 Subject: [PATCH] Print builtin function name in gsc errors --- src/client/component/gsc.cpp | 43 ++++++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/src/client/component/gsc.cpp b/src/client/component/gsc.cpp index 156f7af2..e6b36bf0 100644 --- a/src/client/component/gsc.cpp +++ b/src/client/component/gsc.cpp @@ -306,6 +306,24 @@ namespace gsc } } + void builtin_call_error() + { + const auto pos = game::scr_function_stack->pos; + const auto function_id = *reinterpret_cast( + reinterpret_cast(pos - 2)); + + if (function_id > 0x1000) + { + console::warn("in call to builtin method \"%s\"", + xsk::gsc::h2::resolver::method_name(function_id).data()); + } + else + { + console::warn("in call to builtin function \"%s\"", + xsk::gsc::h2::resolver::function_name(function_id).data()); + } + } + bool force_error_print = false; void* vm_error_stub(void* a1) { @@ -317,19 +335,26 @@ namespace gsc console::warn("*********** script runtime error *************\n"); const auto opcode_id = *reinterpret_cast(0x14BAA93E8); - const auto opcode = get_opcode_name(opcode_id); - const std::string error_str = gsc_error.has_value() - ? utils::string::va(": %s", gsc_error.value().data()) - : ""; - if (opcode.has_value()) + if ((opcode_id >= 0x1A && opcode_id <= 0x20) || (opcode_id >= 0xA8 && opcode_id <= 0xAE)) { - console::warn("while processing instruction %s%s\n", - opcode.value().data(), error_str.data()); + builtin_call_error(); } else { - console::warn("while processing instruction 0x%X%s\n", - opcode_id, error_str.data()); + const auto opcode = get_opcode_name(opcode_id); + const std::string error_str = gsc_error.has_value() + ? utils::string::va(": %s", gsc_error.value().data()) + : ""; + if (opcode.has_value()) + { + console::warn("while processing instruction %s%s\n", + opcode.value().data(), error_str.data()); + } + else + { + console::warn("while processing instruction 0x%X%s\n", + opcode_id, error_str.data()); + } } force_error_print = false;