Add handler for chunk loading

Will be used for the building mod
This commit is contained in:
ChrisMiuchiz 2018-10-23 16:53:04 -04:00 committed by GitHub
parent 04cc979bcd
commit 5e01054ac0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 43 additions and 0 deletions

View File

@ -1,5 +1,6 @@
#include "main.h"
#include <vector>
#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<ChunkLoadedCallback> 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;