From 5e01054ac0d56faaa3c6af1fb00f39b41c683749 Mon Sep 17 00:00:00 2001 From: ChrisMiuchiz Date: Tue, 23 Oct 2018 16:53:04 -0400 Subject: [PATCH] Add handler for chunk loading Will be used for the building mod --- CallbackManager/main.cpp | 43 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/CallbackManager/main.cpp b/CallbackManager/main.cpp index 78951e4..8d4881f 100644 --- a/CallbackManager/main.cpp +++ b/CallbackManager/main.cpp @@ -1,5 +1,6 @@ #include "main.h" #include +#define no_shenanigans __attribute__((noinline)) __declspec(dllexport) UINT_PTR base; //Chat Events @@ -53,6 +54,44 @@ _declspec(naked) void DLL_EXPORT ASMHandleMessage(){ asm("jmp eax"); } +//Chunk Loaded +typedef void (__stdcall *ChunkLoadedCallback)(unsigned int zone_ptr); +std::vector chunk_loaded_callbacks; +extern "C" void DLL_EXPORT RegisterChunkLoadedCallback(ChunkLoadedCallback func){ + chunk_loaded_callbacks.push_back(func); +} +void __stdcall no_shenanigans HandleChunkLoaded(unsigned int zone_ptr){ + for (ChunkLoadedCallback func : chunk_loaded_callbacks){ + func(zone_ptr); + } +} +DWORD HandleChunkLoaded_ptr = (DWORD)&HandleChunkLoaded; + +unsigned int ASMHandleChunkLoaded_JMP_back; +_declspec(naked) void DLL_EXPORT ASMHandleChunkLoaded(){ + asm("push eax"); + asm("push ebx"); + asm("push ecx"); + asm("push edx"); + asm("push edi"); + asm("push esi"); + + asm("push eax"); + asm("call [_HandleChunkLoaded_ptr]"); + + asm("pop esi"); + asm("pop edi"); + asm("pop edx"); + asm("pop ecx"); + asm("pop ebx"); + asm("pop eax"); + + asm("mov ecx, [ebx]"); //Original code + asm("add ecx, 0x800D44"); + + asm("jmp [_ASMHandleChunkLoaded_JMP_back]"); +} + void WriteJMP(BYTE* location, BYTE* newFunction){ DWORD dwOldProtection; @@ -69,6 +108,10 @@ extern "C" DLL_EXPORT BOOL APIENTRY DllMain(HINSTANCE hinstDLL, DWORD fdwReason, { case DLL_PROCESS_ATTACH: WriteJMP((BYTE*)(base + 0x7E61A), (BYTE*)&ASMHandleMessage); + + ASMHandleChunkLoaded_JMP_back = base + 0x6ACDE; + WriteJMP((BYTE*)(base + 0x6ACD6), (BYTE*)&ASMHandleChunkLoaded); + break; } return true;