Add longjump hook

This commit is contained in:
momo5502 2019-01-19 13:00:46 +01:00
parent c14b6813d2
commit b47a2dabbc
3 changed files with 19 additions and 0 deletions

View File

@ -27,6 +27,8 @@ namespace game
VM_Notify_t VM_Notify; VM_Notify_t VM_Notify;
decltype(longjmp)* _longjmp;
int* cmd_args; int* cmd_args;
int* cmd_argc; int* cmd_argc;
const char*** cmd_argv; const char*** cmd_argv;
@ -208,6 +210,8 @@ namespace game
native::VM_Notify = native::VM_Notify_t(SELECT_VALUE(0x610200, 0x569720, 0x4EF450)); native::VM_Notify = native::VM_Notify_t(SELECT_VALUE(0x610200, 0x569720, 0x4EF450));
native::_longjmp = reinterpret_cast<decltype(longjmp)*>(SELECT_VALUE(0x73AC20, 0x7363BC, 0x655558));
native::cmd_args = reinterpret_cast<int*>(SELECT_VALUE(0x1750750, 0x1C978D0, 0x1B455F8)); native::cmd_args = reinterpret_cast<int*>(SELECT_VALUE(0x1750750, 0x1C978D0, 0x1B455F8));
native::cmd_argc = reinterpret_cast<int*>(SELECT_VALUE(0x1750794, 0x1C97914, 0x1B4563C)); native::cmd_argc = reinterpret_cast<int*>(SELECT_VALUE(0x1750794, 0x1C97914, 0x1B4563C));
native::cmd_argv = reinterpret_cast<const char***>(SELECT_VALUE(0x17507B4, 0x1C97934, 0x1B4565C)); native::cmd_argv = reinterpret_cast<const char***>(SELECT_VALUE(0x17507B4, 0x1C97934, 0x1B4565C));

View File

@ -42,6 +42,8 @@ namespace game
typedef void (*VM_Notify_t)(unsigned int notifyListOwnerId, unsigned int stringValue, VariableValue* top); typedef void (*VM_Notify_t)(unsigned int notifyListOwnerId, unsigned int stringValue, VariableValue* top);
extern VM_Notify_t VM_Notify; extern VM_Notify_t VM_Notify;
extern decltype(longjmp)* _longjmp;
extern int* cmd_args; extern int* cmd_args;
extern int* cmd_argc; extern int* cmd_argc;
extern const char*** cmd_argv; extern const char*** cmd_argv;

View File

@ -13,6 +13,8 @@ public:
if (game::is_sp()) this->patch_sp(); if (game::is_sp()) this->patch_sp();
else if (game::is_mp()) this->patch_mp(); else if (game::is_mp()) this->patch_mp();
else if (game::is_dedi()) this->patch_dedi(); else if (game::is_dedi()) this->patch_dedi();
utils::hook(game::native::_longjmp, long_jump_stub, HOOK_JUMP).install()->quick();
} }
private: private:
@ -43,6 +45,17 @@ private:
void patch_dedi() const 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) REGISTER_MODULE(patches)