From 7ce3d81583db93d52a73b814e4c7fb99762e43c5 Mon Sep 17 00:00:00 2001 From: quaK <38787176+Joelrau@users.noreply.github.com> Date: Wed, 14 Jun 2023 20:17:56 +0300 Subject: [PATCH] Small gsc changes --- src/client/component/gsc/script_error.cpp | 9 ++++++--- src/client/component/gsc/script_extension.cpp | 8 ++++---- src/client/component/gsc/script_extension.hpp | 2 +- src/client/component/scripting.cpp | 8 ++++---- src/client/component/scripting.hpp | 1 + 5 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/client/component/gsc/script_error.cpp b/src/client/component/gsc/script_error.cpp index 4062f845..6a1a90d6 100644 --- a/src/client/component/gsc/script_error.cpp +++ b/src/client/component/gsc/script_error.cpp @@ -78,12 +78,14 @@ namespace gsc { const auto& pos = function.value(); unknown_function_error = std::format( - "while processing function '{}' in script '{}':\nunknown script '{}'", pos.first, pos.second, scripting::current_file + "while processing function '{}' in script '{}':\nunknown script '{}' ({})", + pos.first, pos.second, scripting::current_file, scripting::current_file_id ); } else { - unknown_function_error = std::format("unknown script '{}'", scripting::current_file); + unknown_function_error = std::format("unknown script '{}' ({})", + scripting::current_file, scripting::current_file_id); } } @@ -93,7 +95,8 @@ namespace gsc const auto name = scripting::get_token(thread_name); unknown_function_error = std::format( - "while processing script '{}':\nunknown function '{}::{}'", scripting::current_file, filename, name + "while processing script '{}':\nunknown function '{}::{}'", + scripting::current_file, filename, name ); } diff --git a/src/client/component/gsc/script_extension.cpp b/src/client/component/gsc/script_extension.cpp index e5230cb6..5e174beb 100644 --- a/src/client/component/gsc/script_extension.cpp +++ b/src/client/component/gsc/script_extension.cpp @@ -102,7 +102,7 @@ namespace gsc if (func == nullptr) { - scr_error("function doesn't exist"); + scr_error(utils::string::va("builtin function \"%s\" doesn't exist", gsc_ctx->func_name(function_id).data()), true); return; } @@ -140,7 +140,7 @@ namespace gsc if (meth == nullptr) { - scr_error("function doesn't exist"); + scr_error(utils::string::va("builtin method \"%s\" doesn't exist", gsc_ctx->meth_name(method_id).data()), true); return; } @@ -252,9 +252,9 @@ namespace gsc } } - void scr_error(const char* error) + void scr_error(const char* error, const bool force_print) { - force_error_print = true; + force_error_print = force_print; gsc_error_msg = error; game::Scr_ErrorInternal(); diff --git a/src/client/component/gsc/script_extension.hpp b/src/client/component/gsc/script_extension.hpp index 93c1b3e7..ad57e2b5 100644 --- a/src/client/component/gsc/script_extension.hpp +++ b/src/client/component/gsc/script_extension.hpp @@ -34,7 +34,7 @@ namespace gsc extern const game::dvar_t* developer_script; - void scr_error(const char* error); + void scr_error(const char* error, const bool force_print = false); namespace function { diff --git a/src/client/component/scripting.cpp b/src/client/component/scripting.cpp index 79cd5701..6b9e1b35 100644 --- a/src/client/component/scripting.cpp +++ b/src/client/component/scripting.cpp @@ -28,6 +28,7 @@ namespace scripting utils::concurrency::container shared_table; std::string current_file; + unsigned int current_file_id{}; namespace { @@ -46,8 +47,7 @@ namespace scripting utils::hook::detour db_find_xasset_header_hook; - std::string current_script_file; - unsigned int current_file_id{}; + const char* current_script_file_name; game::dvar_t* g_dump_scripts; @@ -153,7 +153,7 @@ namespace scripting void process_script_stub(const char* filename) { - current_script_file = filename; + current_script_file_name = filename; const auto file_id = atoi(filename); if (file_id) @@ -176,7 +176,7 @@ namespace scripting if (!script_function_table_sort.contains(filename)) { - const auto script = gsc::find_script(game::ASSET_TYPE_SCRIPTFILE, current_script_file.data(), false); + const auto script = gsc::find_script(game::ASSET_TYPE_SCRIPTFILE, current_script_file_name, false); if (script) { const auto end = &script->bytecode[script->bytecodeLen]; diff --git a/src/client/component/scripting.hpp b/src/client/component/scripting.hpp index 12598b9c..14f2bd49 100644 --- a/src/client/component/scripting.hpp +++ b/src/client/component/scripting.hpp @@ -13,6 +13,7 @@ namespace scripting extern utils::concurrency::container shared_table; extern std::string current_file; + extern unsigned int current_file_id; void on_shutdown(const std::function& callback); std::optional get_canonical_string(const unsigned int id);