Cube-World-Mod-Launcher/CubeModLoader/callbacks/ChatHandler.h

49 lines
1.1 KiB
C
Raw Normal View History

2019-10-25 06:07:08 +08:00
extern "C" int ChatHandler(wchar_t* msg) {
2019-09-23 07:17:15 +08:00
for (DLL* dll: modDLLs) {
if (dll->HandleChat) {
if ( ((int(*)(wchar_t*))dll->HandleChat)(msg) ){
return 1;
}
}
}
return 0;
}
2019-10-25 06:07:08 +08:00
GETTER_VAR(void*, ASMChatHandler_jmpback);
GETTER_VAR(void*, ASMChatHandler_bail);
void ASMChatHandler() {
asm(".intel_syntax \n"
PUSH_ALL
2019-09-23 07:17:15 +08:00
2019-09-25 07:03:07 +08:00
"mov rcx, rbx \n" // The message
2019-09-23 07:17:15 +08:00
PREPARE_STACK
2019-10-25 06:07:08 +08:00
"call ChatHandler \n"
2019-09-23 07:17:15 +08:00
RESTORE_STACK
// Did the handler return true?
"test al, al \n"
"jnz bail \n"
POP_ALL
// original code
2019-10-06 03:59:20 +08:00
"mov qword ptr [rbp+0x88], 7 \n"
"mov [rbp+0x80], r12 \n"
"mov [rbp+0x70], r12w \n"
2019-10-25 06:07:08 +08:00
DEREF_JMP(ASMChatHandler_jmpback)
2019-09-23 07:17:15 +08:00
"bail: \n"
POP_ALL
2019-10-25 06:07:08 +08:00
DEREF_JMP(ASMChatHandler_bail)
2019-09-23 07:17:15 +08:00
);
}
void SetupChatHandler() {
2019-10-25 06:07:08 +08:00
WriteFarJMP(Offset(base, 0x97198), (void*)&ASMChatHandler);
ASMChatHandler_jmpback = Offset(base, 0x971B0);
ASMChatHandler_bail = Offset(base, 0x9777A);
2019-09-23 07:17:15 +08:00
}