mirror of
https://github.com/isledecomp/isle.git
synced 2026-01-24 00:31:16 +00:00
implement class hooks
This commit is contained in:
parent
e20e27fdc3
commit
1c195370fa
@ -156,14 +156,20 @@ BOOL StartDirectSound(void);
|
|||||||
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
|
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
|
||||||
{
|
{
|
||||||
#ifdef ISLE_BUILD_PATCH
|
#ifdef ISLE_BUILD_PATCH
|
||||||
// Load LEGO1_PATCH.DLL
|
|
||||||
{
|
{
|
||||||
HMODULE hModule = LoadLibraryA("LEGO1_PATCH.DLL");
|
// Find the imported LEGO1.DLL module
|
||||||
if (hModule) {
|
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*);
|
typedef void (*PatchFunc)(void*);
|
||||||
PatchFunc patchFunc = (PatchFunc)GetProcAddress(hModule, "Patch");
|
PatchFunc patchFunc = (PatchFunc)GetProcAddress(hPatchModule, "Patch");
|
||||||
if (patchFunc) {
|
if (patchFunc) {
|
||||||
void *root = (char*)VideoManager - 0x10015720;
|
void *root = (char*)hLego1Module - 0x10000000;
|
||||||
patchFunc(root);
|
patchFunc(root);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -58,32 +58,11 @@ static class DecompPatchList
|
|||||||
BYTE *location = (BYTE*)((DWORD)root + (DWORD)node->origFunc);
|
BYTE *location = (BYTE*)((DWORD)root + (DWORD)node->origFunc);
|
||||||
BYTE *newFunction = (BYTE*)node->newFunc;
|
BYTE *newFunction = (BYTE*)node->newFunc;
|
||||||
|
|
||||||
/*
|
|
||||||
DWORD dwOldProtection;
|
DWORD dwOldProtection;
|
||||||
VirtualProtect(location, 5, PAGE_EXECUTE_READWRITE, &dwOldProtection);
|
VirtualProtect(location, 5, PAGE_EXECUTE_READWRITE, &dwOldProtection);
|
||||||
location[0] = 0xE9; //jmp
|
location[0] = 0xE9; //jmp
|
||||||
*((DWORD*)(location + 1)) = (DWORD)(((DWORD)newFunction - (DWORD)location) - 5);
|
*((DWORD*)(location + 1)) = (DWORD)(((DWORD)newFunction - (DWORD)location) - 5);
|
||||||
VirtualProtect(location, 5, dwOldProtection, &dwOldProtection);
|
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;
|
} decompPatchList;
|
||||||
|
|||||||
@ -14,26 +14,32 @@ typedef unsigned int undefined4;
|
|||||||
|
|
||||||
#ifdef ISLE_BUILD_PATCH
|
#ifdef ISLE_BUILD_PATCH
|
||||||
|
|
||||||
|
// Function called to add a patch to the list of patches
|
||||||
void DecompPatchAdd(void *origFunc, void *newFunc);
|
void DecompPatchAdd(void *origFunc, void *newFunc);
|
||||||
|
|
||||||
#define DECOMP_METHOD_HOOK(origFunc, cls, method, retv, args) \
|
// Class decomp hook macros
|
||||||
namespace _DecompPatchHook_##__COUNTER__ \
|
#define DECOMP_HOOK_DECL_CLS() \
|
||||||
{ \
|
static void _ExportHooks()
|
||||||
class DecompPatchHook \
|
|
||||||
|
#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: \
|
retv(cls :: * _ourFunc ) args = cls::method; \
|
||||||
DecompPatchHook() \
|
DecompPatchAdd((void*)origFunc, (void*)*((DWORD*)& _ourFunc )); \
|
||||||
{ \
|
}
|
||||||
retv(cls :: *method) args = cls::method; \
|
|
||||||
DecompPatchAdd((void*)origFunc, (void*)&_patchHook); \
|
|
||||||
} \
|
|
||||||
} _patchHook; \
|
|
||||||
}
|
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
#define DECOMP_METHOD_HOOK()
|
#define DECOMP_METHOD_HOOK()
|
||||||
|
|
||||||
|
#define DECOMP_HOOK_DECL_EXPORT()
|
||||||
|
#define DECOMP_HOOK_DEFN_EXPORT()
|
||||||
|
#define DECOMP_HOOK_EXPORT()
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif // DECOMP_H
|
#endif // DECOMP_H
|
||||||
|
|||||||
@ -4,6 +4,10 @@
|
|||||||
|
|
||||||
DECOMP_SIZE_ASSERT(MxTransitionManager, 0x900);
|
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
|
// 0x100f4378
|
||||||
RECT g_fullScreenRect = {0, 0, 640, 480};
|
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,
|
MxResult MxTransitionManager::StartTransition(TransitionType p_animationType, MxS32 p_speed,
|
||||||
MxBool p_doCopy, MxBool p_playMusicInAnim)
|
MxBool p_doCopy, MxBool p_playMusicInAnim)
|
||||||
{
|
{
|
||||||
Beep(750, 300);
|
|
||||||
if (this->m_transitionType == NOT_TRANSITIONING) {
|
if (this->m_transitionType == NOT_TRANSITIONING) {
|
||||||
if (!p_playMusicInAnim) {
|
if (!p_playMusicInAnim) {
|
||||||
MxBackgroundAudioManager *backgroundAudioManager = BackgroundAudioManager();
|
MxBackgroundAudioManager *backgroundAudioManager = BackgroundAudioManager();
|
||||||
@ -193,8 +196,6 @@ MxResult MxTransitionManager::StartTransition(TransitionType p_animationType, Mx
|
|||||||
return FAILURE;
|
return FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
DECOMP_METHOD_HOOK(0x1004bb70, MxTransitionManager, StartTransition, MxResult, (MxTransitionManager::TransitionType, MxS32, MxBool, MxBool));
|
|
||||||
|
|
||||||
// OFFSET: LEGO1 0x1004c170
|
// OFFSET: LEGO1 0x1004c170
|
||||||
void MxTransitionManager::Transition_Wipe()
|
void MxTransitionManager::Transition_Wipe()
|
||||||
{
|
{
|
||||||
@ -253,7 +254,7 @@ void MxTransitionManager::SubmitCopyRect(DDSURFACEDESC &ddsc)
|
|||||||
|
|
||||||
DWORD bytesPerPixel = ddsc.ddpfPixelFormat.dwRGBBitCount / 8;
|
DWORD bytesPerPixel = ddsc.ddpfPixelFormat.dwRGBBitCount / 8;
|
||||||
|
|
||||||
const char *src = (const char *)m_copyBuffer;
|
const char *src = (const char*)m_copyBuffer;
|
||||||
|
|
||||||
LONG copyPitch;
|
LONG copyPitch;
|
||||||
copyPitch = ((m_copyRect.right - m_copyRect.left) + 1) * bytesPerPixel;
|
copyPitch = ((m_copyRect.right - m_copyRect.left) + 1) * bytesPerPixel;
|
||||||
|
|||||||
@ -9,6 +9,8 @@
|
|||||||
class MxTransitionManager : public MxCore
|
class MxTransitionManager : public MxCore
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
DECOMP_HOOK_DECL_CLS();
|
||||||
|
|
||||||
MxTransitionManager();
|
MxTransitionManager();
|
||||||
virtual ~MxTransitionManager() override; // vtable+0x0
|
virtual ~MxTransitionManager() override; // vtable+0x0
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user