From 725e0605e81b66f5b11e7931939676f8c6ea655c Mon Sep 17 00:00:00 2001 From: Federico Cecchetto Date: Fri, 11 Mar 2022 22:06:05 +0100 Subject: [PATCH] More LUI error handling --- src/client/component/ui_scripting.cpp | 35 +++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/src/client/component/ui_scripting.cpp b/src/client/component/ui_scripting.cpp index f4122cf2..9c2214ac 100644 --- a/src/client/component/ui_scripting.cpp +++ b/src/client/component/ui_scripting.cpp @@ -28,6 +28,8 @@ namespace ui_scripting utils::hook::detour hks_start_hook; utils::hook::detour hks_shutdown_hook; utils::hook::detour hks_allocator_hook; + utils::hook::detour lui_error_hook; + utils::hook::detour hksi_hks_error_hook; bool error_hook_enabled = false; @@ -46,10 +48,37 @@ namespace ui_scripting { return hksi_lual_error_hook.invoke(s, formatted.data()); } - else + + throw std::runtime_error(formatted); + } + + void hksi_hks_error_stub(game::hks::lua_State* s, int a2) + { + if (!error_hook_enabled) { - throw std::runtime_error(formatted); + return hksi_hks_error_hook.invoke(s, a2); } + + throw std::runtime_error("unknown error"); + } + + void lui_error_stub(game::hks::lua_State* s) + { + if (!error_hook_enabled) + { + return lui_error_hook.invoke(s); + } + + const auto count = static_cast(s->m_apistack.top - s->m_apistack.base); + const auto arguments = get_return_values(count); + + std::string error_str = "LUI Error"; + if (count && arguments[0].is()) + { + error_str = arguments[0].as(); + } + + throw std::runtime_error(error_str); } void* hks_start_stub(char a1) @@ -154,6 +183,8 @@ namespace ui_scripting hksi_lual_error_hook.create(0x2E3E40_b, hksi_lual_error_stub); hksi_lual_error_hook2.create(0x2DCB40_b, hksi_lual_error_stub); hks_allocator_hook.create(0x2D92A0_b, hks_allocator_stub); + lui_error_hook.create(0x2B9D90_b, lui_error_stub); + hksi_hks_error_hook.create(0x2DBC00_b, hksi_hks_error_stub); } }; }