Add handler for chunk loading
Will be used for the building mod
This commit is contained in:
parent
04cc979bcd
commit
5e01054ac0
|
@ -1,5 +1,6 @@
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#define no_shenanigans __attribute__((noinline)) __declspec(dllexport)
|
||||||
UINT_PTR base;
|
UINT_PTR base;
|
||||||
|
|
||||||
//Chat Events
|
//Chat Events
|
||||||
|
@ -53,6 +54,44 @@ _declspec(naked) void DLL_EXPORT ASMHandleMessage(){
|
||||||
asm("jmp eax");
|
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){
|
void WriteJMP(BYTE* location, BYTE* newFunction){
|
||||||
DWORD dwOldProtection;
|
DWORD dwOldProtection;
|
||||||
|
@ -69,6 +108,10 @@ extern "C" DLL_EXPORT BOOL APIENTRY DllMain(HINSTANCE hinstDLL, DWORD fdwReason,
|
||||||
{
|
{
|
||||||
case DLL_PROCESS_ATTACH:
|
case DLL_PROCESS_ATTACH:
|
||||||
WriteJMP((BYTE*)(base + 0x7E61A), (BYTE*)&ASMHandleMessage);
|
WriteJMP((BYTE*)(base + 0x7E61A), (BYTE*)&ASMHandleMessage);
|
||||||
|
|
||||||
|
ASMHandleChunkLoaded_JMP_back = base + 0x6ACDE;
|
||||||
|
WriteJMP((BYTE*)(base + 0x6ACD6), (BYTE*)&ASMHandleChunkLoaded);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Reference in New Issue