diff --git a/ISLE/isleapp.cpp b/ISLE/isleapp.cpp index bc426e49..8c3f85b5 100644 --- a/ISLE/isleapp.cpp +++ b/ISLE/isleapp.cpp @@ -156,14 +156,20 @@ BOOL StartDirectSound(void); int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) { #ifdef ISLE_BUILD_PATCH - // Load LEGO1_PATCH.DLL { - HMODULE hModule = LoadLibraryA("LEGO1_PATCH.DLL"); - if (hModule) { + // Find the imported LEGO1.DLL module + HMODULE hLego1Module = GetModuleHandleA("LEGO1.DLL"); + if (!hLego1Module) { + return 1; + } + + // Load LEGO1_PATCH.DLL + HMODULE hPatchModule = LoadLibraryA("LEGO1_PATCH.DLL"); + if (hPatchModule) { typedef void (*PatchFunc)(void*); - PatchFunc patchFunc = (PatchFunc)GetProcAddress(hModule, "Patch"); + PatchFunc patchFunc = (PatchFunc)GetProcAddress(hPatchModule, "Patch"); if (patchFunc) { - void *root = (char*)VideoManager - 0x10015720; + void *root = (char*)hLego1Module - 0x10000000; patchFunc(root); } } diff --git a/LEGO1/decomp.cpp b/LEGO1/decomp.cpp index f8387f24..cc041fec 100644 --- a/LEGO1/decomp.cpp +++ b/LEGO1/decomp.cpp @@ -58,32 +58,11 @@ static class DecompPatchList BYTE *location = (BYTE*)((DWORD)root + (DWORD)node->origFunc); BYTE *newFunction = (BYTE*)node->newFunc; - /* DWORD dwOldProtection; VirtualProtect(location, 5, PAGE_EXECUTE_READWRITE, &dwOldProtection); location[0] = 0xE9; //jmp *((DWORD*)(location + 1)) = (DWORD)(((DWORD)newFunction - (DWORD)location) - 5); VirtualProtect(location, 5, dwOldProtection, &dwOldProtection); - */ - - BYTE code[5]; - code[0] = 0xE9; //jmp - *((DWORD*)(code + 1)) = (DWORD)(((DWORD)newFunction - (DWORD)location) - 5); - - char buffer[256]; - sprintf(buffer, "location %p, newFunction %p, origFunc %p, root %p", location, newFunction, node->origFunc, root); - MessageBoxA(NULL, buffer, "DecompPatchList", MB_ICONERROR); - - static HANDLE hProcess = GetCurrentProcess(); - DWORD written = 0; - if (WriteProcessMemory(hProcess, location, code, sizeof(code), &written) == FALSE || written != sizeof(code)) - { - // Print error reason - sprintf(buffer, "WriteProcessMemory failed: %d", GetLastError()); - MessageBoxA(NULL, buffer, "DecompPatchList", MB_ICONERROR); - - MessageBoxA(NULL, "Patch failed", "DecompPatchList", MB_ICONERROR); - } } } } decompPatchList; diff --git a/LEGO1/decomp.h b/LEGO1/decomp.h index 23a849e1..06c18b5f 100644 --- a/LEGO1/decomp.h +++ b/LEGO1/decomp.h @@ -14,26 +14,32 @@ typedef unsigned int undefined4; #ifdef ISLE_BUILD_PATCH +// Function called to add a patch to the list of patches void DecompPatchAdd(void *origFunc, void *newFunc); -#define DECOMP_METHOD_HOOK(origFunc, cls, method, retv, args) \ -namespace _DecompPatchHook_##__COUNTER__ \ -{ \ - class DecompPatchHook \ +// Class decomp hook macros +#define DECOMP_HOOK_DECL_CLS() \ + static void _ExportHooks() + +#define DECOMP_HOOK_START_CLS(cls) \ + void cls::_ExportHooks() { +#define DECOMP_HOOK_END_CLS(cls) \ + } static struct _ExportHooks_##cls { _ExportHooks_##cls () { cls::_ExportHooks(); } } _exportHooks_##cls + +#define DECOMP_HOOK_EXPORT_CLS(origFunc, cls, retv, method, args) \ { \ - public: \ - DecompPatchHook() \ - { \ - retv(cls :: *method) args = cls::method; \ - DecompPatchAdd((void*)origFunc, (void*)&_patchHook); \ - } \ - } _patchHook; \ -} + retv(cls :: * _ourFunc ) args = cls::method; \ + DecompPatchAdd((void*)origFunc, (void*)*((DWORD*)& _ourFunc )); \ + } #else #define DECOMP_METHOD_HOOK() +#define DECOMP_HOOK_DECL_EXPORT() +#define DECOMP_HOOK_DEFN_EXPORT() +#define DECOMP_HOOK_EXPORT() + #endif #endif // DECOMP_H diff --git a/LEGO1/mxtransitionmanager.cpp b/LEGO1/mxtransitionmanager.cpp index ce3cd215..290f1d80 100644 --- a/LEGO1/mxtransitionmanager.cpp +++ b/LEGO1/mxtransitionmanager.cpp @@ -4,6 +4,10 @@ DECOMP_SIZE_ASSERT(MxTransitionManager, 0x900); +DECOMP_HOOK_START_CLS(MxTransitionManager); +DECOMP_HOOK_EXPORT_CLS(0x1004bb70, MxTransitionManager, void, SubmitCopyRect, (DDSURFACEDESC&)); +DECOMP_HOOK_END_CLS(MxTransitionManager); + // 0x100f4378 RECT g_fullScreenRect = {0, 0, 640, 480}; @@ -153,7 +157,6 @@ MxResult MxTransitionManager::GetDDrawSurfaceFromVideoManager() // vtable+0x14 MxResult MxTransitionManager::StartTransition(TransitionType p_animationType, MxS32 p_speed, MxBool p_doCopy, MxBool p_playMusicInAnim) { - Beep(750, 300); if (this->m_transitionType == NOT_TRANSITIONING) { if (!p_playMusicInAnim) { MxBackgroundAudioManager *backgroundAudioManager = BackgroundAudioManager(); @@ -193,8 +196,6 @@ MxResult MxTransitionManager::StartTransition(TransitionType p_animationType, Mx return FAILURE; } -DECOMP_METHOD_HOOK(0x1004bb70, MxTransitionManager, StartTransition, MxResult, (MxTransitionManager::TransitionType, MxS32, MxBool, MxBool)); - // OFFSET: LEGO1 0x1004c170 void MxTransitionManager::Transition_Wipe() { @@ -253,7 +254,7 @@ void MxTransitionManager::SubmitCopyRect(DDSURFACEDESC &ddsc) DWORD bytesPerPixel = ddsc.ddpfPixelFormat.dwRGBBitCount / 8; - const char *src = (const char *)m_copyBuffer; + const char *src = (const char*)m_copyBuffer; LONG copyPitch; copyPitch = ((m_copyRect.right - m_copyRect.left) + 1) * bytesPerPixel; diff --git a/LEGO1/mxtransitionmanager.h b/LEGO1/mxtransitionmanager.h index cc5bd678..c0fdcc2c 100644 --- a/LEGO1/mxtransitionmanager.h +++ b/LEGO1/mxtransitionmanager.h @@ -9,6 +9,8 @@ class MxTransitionManager : public MxCore { public: + DECOMP_HOOK_DECL_CLS(); + MxTransitionManager(); virtual ~MxTransitionManager() override; // vtable+0x0