From 06187a79ac0ac786364b8ba9f0605577e5e60b35 Mon Sep 17 00:00:00 2001 From: Federico Cecchetto Date: Sun, 1 May 2022 17:49:10 +0200 Subject: [PATCH] Small fix --- src/client/component/ui_scripting.cpp | 11 ++++----- src/client/game/ui_scripting/execution.cpp | 26 ++++++++++++++++++---- src/client/game/ui_scripting/execution.hpp | 1 + 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/src/client/component/ui_scripting.cpp b/src/client/component/ui_scripting.cpp index 6b6056c8..a5594c0a 100644 --- a/src/client/component/ui_scripting.cpp +++ b/src/client/component/ui_scripting.cpp @@ -182,11 +182,6 @@ namespace ui_scripting auto game_type = game(); lua["game"] = game_type; - game_type["addlocalizedstring"] = [](const game&, const std::string& a, const std::string& b) - { - localized_strings::override(a, b); - }; - game_type["sharedset"] = [](const game&, const std::string& key, const std::string& value) { scripting::shared_table.access([key, value](scripting::shared_table_t& table) @@ -248,7 +243,7 @@ namespace ui_scripting const auto alternate = name.starts_with("alt_"); const auto weapon = ::game::G_GetWeaponForName(name.data()); - char buffer[0x400] = { 0 }; + char buffer[0x400] = {0}; ::game::CG_GetWeaponDisplayName(weapon, alternate, buffer, 0x400); return std::string(buffer); @@ -281,7 +276,9 @@ namespace ui_scripting std::vector args{}; for (const auto& value : va) { - args.push_back(to_string(value)[0].as()); + const auto value_str = to_string(value); + + args.push_back(value_str[0].as()); } ::scheduler::once([name, args]() diff --git a/src/client/game/ui_scripting/execution.cpp b/src/client/game/ui_scripting/execution.cpp index f1077fca..349ad960 100644 --- a/src/client/game/ui_scripting/execution.cpp +++ b/src/client/game/ui_scripting/execution.cpp @@ -78,6 +78,26 @@ namespace ui_scripting return values; } + arguments get_return_values(game::hks::HksObject* base) + { + const auto state = *game::hks::lua_state; + const auto count = static_cast(state->m_apistack.top - base); + arguments values; + + for (auto i = count - 1; i >= 0; i--) + { + const auto v = get_return_value(i); + values.push_back(v); + } + + if (values.size() == 0) + { + values.push_back({}); + } + + return values; + } + bool notify(const std::string& name, const event_arguments& arguments) { const auto state = *game::hks::lua_state; @@ -127,10 +147,8 @@ namespace ui_scripting push_value(*i); } - const auto num_args = static_cast(arguments.size()); - - game::hks::vm_call_internal(state, num_args, -1, 0); - const auto args = get_return_values(); + game::hks::vm_call_internal(state, static_cast(arguments.size()), -1, 0); + const auto args = get_return_values(top); state->m_apistack.top = top; return args; } diff --git a/src/client/game/ui_scripting/execution.hpp b/src/client/game/ui_scripting/execution.hpp index fa9dbd60..bc39e7a0 100644 --- a/src/client/game/ui_scripting/execution.hpp +++ b/src/client/game/ui_scripting/execution.hpp @@ -10,6 +10,7 @@ namespace ui_scripting script_value get_return_value(int offset); arguments get_return_values(); + arguments get_return_values(game::hks::HksObject* base); bool notify(const std::string& name, const event_arguments& arguments);