-
-
Save shavitush/d1659a015ce781522ad4c16f8b6cb139 to your computer and use it in GitHub Desktop.
Universal fix for "Memory/DLL corruption" in MapleStory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdint> | |
#include <Windows.h> | |
#include <detours.h> | |
DWORD g_getTickCount = GetTickCount(); | |
DWORD (__stdcall *g_real_GetTickCount)(void) = GetTickCount; | |
DWORD g_timeGetTime = timeGetTime(); | |
DWORD (__stdcall *g_real_timeGetTime)(void) = timeGetTime; | |
DWORD corrected_GetTickCount() | |
{ | |
return (g_real_GetTickCount() - g_getTickCount) % INT32_MAX; | |
} | |
DWORD corrected_timeGetTime() | |
{ | |
return (g_real_timeGetTime() - g_timeGetTime) % INT32_MAX; | |
} | |
int __stdcall DllMain(HMODULE hModule, unsigned long ul_reason_for_call, void *lpReserved) | |
{ | |
if(DetourIsHelperProcess()) | |
{ | |
return 1; | |
} | |
switch(ul_reason_for_call) | |
{ | |
case DLL_PROCESS_ATTACH: | |
DetourRestoreAfterWith(); | |
case DLL_PROCESS_DETACH: | |
DetourTransactionBegin(); | |
DetourUpdateThread(GetCurrentThread()); | |
((ul_reason_for_call == DLL_PROCESS_ATTACH)? DetourAttach:DetourDetach)(reinterpret_cast<void**>(&g_real_GetTickCount), corrected_GetTickCount); | |
((ul_reason_for_call == DLL_PROCESS_ATTACH)? DetourAttach:DetourDetach)(reinterpret_cast<void**>(&g_real_timeGetTime), corrected_timeGetTime); | |
DetourTransactionCommit(); | |
break; | |
} | |
return 1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment