Skip to content

Instantly share code, notes, and snippets.

@shavitush
Last active December 22, 2018 22:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shavitush/d1659a015ce781522ad4c16f8b6cb139 to your computer and use it in GitHub Desktop.
Save shavitush/d1659a015ce781522ad4c16f8b6cb139 to your computer and use it in GitHub Desktop.
Universal fix for "Memory/DLL corruption" in MapleStory
#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