diff --git a/src/client/game/symbols.hpp b/src/client/game/symbols.hpp index 9381150a..f42835dd 100644 --- a/src/client/game/symbols.hpp +++ b/src/client/game/symbols.hpp @@ -146,6 +146,8 @@ namespace game WEAK symbol LUI_OpenMenu{0x14039D5F0, 0x1404CD210}; + WEAK symbol LUI_BeginEvent{0x1400D27F0, 0x140161A00}; + WEAK symbol LUI_EndEvent{0x1400D3A80, 0x140162CD0}; WEAK symbol Menu_IsMenuOpenAndVisible{0x1404709C0, 0x1404C7320}; diff --git a/src/client/game/ui_scripting/execution.cpp b/src/client/game/ui_scripting/execution.cpp index fff6b88e..cc8df795 100644 --- a/src/client/game/ui_scripting/execution.cpp +++ b/src/client/game/ui_scripting/execution.cpp @@ -37,6 +37,45 @@ namespace ui_scripting return values; } + bool notify(const std::string& name, const event_arguments& arguments) + { + const auto state = *game::hks::lua_state; + if (!game::LUI_BeginEvent(0, name.data(), state)) + { + return false; + } + + const auto _1 = gsl::finally(&disable_error_hook); + enable_error_hook(); + + const auto top = state->m_apistack.top; + try + { + const auto event = get_return_value(0).as(); + + for (const auto& arg : arguments) + { + event.set(arg.first, arg.second); + } + } + catch (...) + { + } + + state->m_apistack.top = top; + + try + { + game::LUI_EndEvent(state); + } + catch (const std::exception& e) + { + throw std::runtime_error(std::string("Error while processing event: ") + e.what()); + } + + return true; + } + arguments call_script_function(const function& function, const arguments& arguments) { const auto state = *game::hks::lua_state; diff --git a/src/client/game/ui_scripting/execution.hpp b/src/client/game/ui_scripting/execution.hpp index 24f4dd72..4a3d3562 100644 --- a/src/client/game/ui_scripting/execution.hpp +++ b/src/client/game/ui_scripting/execution.hpp @@ -9,6 +9,8 @@ namespace ui_scripting script_value get_return_value(int offset); arguments get_return_values(int count); + bool notify(const std::string& name, const event_arguments& arguments); + arguments call_script_function(const function& function, const arguments& arguments); script_value get_field(const userdata& self, const script_value& key); diff --git a/src/client/game/ui_scripting/script_value.hpp b/src/client/game/ui_scripting/script_value.hpp index 3de52ddf..a16d2622 100644 --- a/src/client/game/ui_scripting/script_value.hpp +++ b/src/client/game/ui_scripting/script_value.hpp @@ -53,4 +53,5 @@ namespace ui_scripting }; using arguments = std::vector; + using event_arguments = std::unordered_map; }