From b47a2dabbc142c25c7ae9cb0caab55d23a967a3c Mon Sep 17 00:00:00 2001 From: momo5502 Date: Sat, 19 Jan 2019 13:00:46 +0100 Subject: [PATCH] Add longjump hook --- src/game/game.cpp | 4 ++++ src/game/game.hpp | 2 ++ src/module/patches.cpp | 13 +++++++++++++ 3 files changed, 19 insertions(+) diff --git a/src/game/game.cpp b/src/game/game.cpp index e4ab61c..f46d0ff 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -27,6 +27,8 @@ namespace game VM_Notify_t VM_Notify; + decltype(longjmp)* _longjmp; + int* cmd_args; int* cmd_argc; const char*** cmd_argv; @@ -208,6 +210,8 @@ namespace game native::VM_Notify = native::VM_Notify_t(SELECT_VALUE(0x610200, 0x569720, 0x4EF450)); + native::_longjmp = reinterpret_cast(SELECT_VALUE(0x73AC20, 0x7363BC, 0x655558)); + native::cmd_args = reinterpret_cast(SELECT_VALUE(0x1750750, 0x1C978D0, 0x1B455F8)); native::cmd_argc = reinterpret_cast(SELECT_VALUE(0x1750794, 0x1C97914, 0x1B4563C)); native::cmd_argv = reinterpret_cast(SELECT_VALUE(0x17507B4, 0x1C97934, 0x1B4565C)); diff --git a/src/game/game.hpp b/src/game/game.hpp index cbb03f3..edf4645 100644 --- a/src/game/game.hpp +++ b/src/game/game.hpp @@ -42,6 +42,8 @@ namespace game typedef void (*VM_Notify_t)(unsigned int notifyListOwnerId, unsigned int stringValue, VariableValue* top); extern VM_Notify_t VM_Notify; + extern decltype(longjmp)* _longjmp; + extern int* cmd_args; extern int* cmd_argc; extern const char*** cmd_argv; diff --git a/src/module/patches.cpp b/src/module/patches.cpp index d3e893b..6285af9 100644 --- a/src/module/patches.cpp +++ b/src/module/patches.cpp @@ -13,6 +13,8 @@ public: if (game::is_sp()) this->patch_sp(); else if (game::is_mp()) this->patch_mp(); else if (game::is_dedi()) this->patch_dedi(); + + utils::hook(game::native::_longjmp, long_jump_stub, HOOK_JUMP).install()->quick(); } private: @@ -43,6 +45,17 @@ private: void patch_dedi() const { } + + static __declspec(noreturn) void long_jump_stub(jmp_buf buf, const int value) noexcept(false) + { +#ifdef DEBUG + { + printf("Unwinding the stack...\n"); + } +#endif + + longjmp(buf, value); + } }; REGISTER_MODULE(patches)