From 439e505f0afc708016e4a627b0102e2cd349ca64 Mon Sep 17 00:00:00 2001 From: Federico Cecchetto Date: Sun, 26 Jun 2022 02:27:57 +0200 Subject: [PATCH] Some changes --- src/client/component/scripting.cpp | 25 ++++++++++++++++--- src/client/game/scripting/function_tables.cpp | 1 + 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/client/component/scripting.cpp b/src/client/component/scripting.cpp index 8ffcd5c8..bcb273cf 100644 --- a/src/client/component/scripting.cpp +++ b/src/client/component/scripting.cpp @@ -43,6 +43,8 @@ namespace scripting std::string current_file; unsigned int current_file_id{}; + std::unordered_map canonical_string_table; + void vm_notify_stub(const unsigned int notify_list_owner_id, const game::scr_string_t string_value, game::VariableValue* top) { @@ -73,6 +75,11 @@ namespace scripting void g_shutdown_game_stub(const int free_scripts) { + if (free_scripts) + { + canonical_string_table.clear(); + } + lua::engine::stop(); g_shutdown_game_hook.invoke(free_scripts); } @@ -105,9 +112,21 @@ namespace scripting process_script_hook.invoke(filename); } + std::vector get_token_names(unsigned int id) + { + auto result = scripting::find_token(id); + + if (canonical_string_table.find(id) != canonical_string_table.end()) + { + result.push_back(canonical_string_table[id]); + } + + return result; + } + void add_function(const std::string& file, unsigned int id, const char* pos) { - const auto function_names = scripting::find_token(id); + const auto function_names = scripting::get_token_names(id); for (const auto& name : function_names) { script_function_table[file][name] = pos; @@ -118,7 +137,7 @@ namespace scripting { if (current_file_id) { - const auto names = scripting::find_token(current_file_id); + const auto names = scripting::get_token_names(current_file_id); for (const auto& name : names) { add_function(name, thread_name, code_pos); @@ -147,7 +166,7 @@ namespace scripting unsigned int sl_get_canonical_string_stub(const char* str) { const auto result = sl_get_canonical_string_hook.invoke(str); - scripting::token_map[str] = result; + canonical_string_table[result] = str; return result; } diff --git a/src/client/game/scripting/function_tables.cpp b/src/client/game/scripting/function_tables.cpp index dd1764b2..72a8f7ab 100644 --- a/src/client/game/scripting/function_tables.cpp +++ b/src/client/game/scripting/function_tables.cpp @@ -1782,5 +1782,6 @@ namespace scripting {"main", 616}, {"player", 794}, {"default_start", 10126}, + {"maps/_utility", 42407}, }; }