Clean up Patches, initial support for version 6.00

This commit is contained in:
nastys
2020-03-14 01:15:13 +01:00
parent f8519e003c
commit 17e1b99900
3 changed files with 742 additions and 300 deletions
+115 -26
View File
@@ -15,9 +15,18 @@
using namespace std::chrono;
unsigned short game_version = 710;
void exitGameClean(int)
{
*(bool*)0x0000000140EDA6B0 = true;
switch (game_version)
{
case 600:
*(bool*)0x0000000140E8DF20 = true; // 6.00
break;
default:
*(bool*)0x0000000140EDA6B0 = true; // 7.10
}
}
int hookedCreateWindow(const char* title, void(__cdecl* exit_function)(int))
@@ -43,13 +52,27 @@ int hookedCreateWindow(const char* title, void(__cdecl* exit_function)(int))
printf("[Render Manager] Requested display mode not supported. Using non-exclusive fullscreen instead.\n");
printf(GameModeString);
printf("\n");
*fullScreenFlag = 1;
switch (game_version)
{
case 600:
*fullScreenFlag_600 = 1;
break;
default:
*fullScreenFlag_710 = 1;
}
__glutCreateWindowWithExit(title, exitGameClean);
}
}
else // windowed or borderless
{
*fullScreenFlag = 0;
switch (game_version)
{
case 600:
*fullScreenFlag_600 = 0;
break;
default:
*fullScreenFlag_710 = 0;
}
RECT xy;
SystemParametersInfo(SPI_GETWORKAREA, 0, &xy, 0);
@@ -107,9 +130,23 @@ __int64 hookedParseParameters(int a1, __int64* a2)
{
// Force -wqhd if Custom Internal Resolution is enabled
if (nIntRes)
*resolutionType = 15;
switch (game_version)
{
case 600:
*resolutionType_600 = 15;
break;
default:
*resolutionType_710 = 15;
}
// Return to the original function
return divaParseParameters(a1, a2);
switch (game_version)
{
case 600:
return divaParseParameters_600(a1, a2);
break;
default:
return divaParseParameters_710(a1, a2);
}
}
time_point<high_resolution_clock> sleepUntil = high_resolution_clock::now();
@@ -124,8 +161,6 @@ __int64 __fastcall limiterFuncNormal(__int64 a1)
if (timeNow < nextUpdate)
return 0;
const auto result = divaEngineUpdate(a1);
timeNow = high_resolution_clock::now();
// increment nextUpdate by fixed interval to unsure timing accuracy between frames
@@ -138,7 +173,13 @@ __int64 __fastcall limiterFuncNormal(__int64 a1)
if (nextUpdate < timeNow)
nextUpdate = timeNow;
return result;
switch (game_version)
{
case 600:
return divaEngineUpdate_600(a1);
default:
return divaEngineUpdate_710(a1);
}
}
__int64 __fastcall limiterFuncLight(__int64 a1)
@@ -167,8 +208,6 @@ __int64 __fastcall limiterFuncLight(__int64 a1)
if (timeNow < nextUpdate)
return 0;
const auto result = divaEngineUpdate(a1);
timeNow = high_resolution_clock::now();
// increment nextUpdate by fixed interval to unsure timing accuracy between frames
@@ -183,13 +222,25 @@ __int64 __fastcall limiterFuncLight(__int64 a1)
sleepUntil = nextUpdate - sleepWindow;
return result;
switch (game_version)
{
case 600:
return divaEngineUpdate_600(a1);
default:
return divaEngineUpdate_710(a1);
}
}
__int64 __fastcall hookedEngineUpdate(__int64 a1)
{
if (nFpsLimit < 1)
return divaEngineUpdate(a1);
switch (game_version)
{
case 600:
return divaEngineUpdate_600(a1);
default:
return divaEngineUpdate_710(a1);
}
else if (nUseLightLimiter)
return limiterFuncLight(a1);
else
@@ -218,15 +269,29 @@ BOOL APIENTRY DllMain(HMODULE hModule,
{
if (ul_reason_for_call == DLL_PROCESS_ATTACH)
{
if (*(char*)0x140A570F0 == '6') game_version = 600;
DisableThreadLibraryCalls(hModule);
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourAttach(&(PVOID&)divaCreateWindow, hookedCreateWindow);
switch (game_version)
{
case 600:
DetourAttach(&(PVOID&)divaCreateWindow_600, hookedCreateWindow);
default:
DetourAttach(&(PVOID&)divaCreateWindow_710, hookedCreateWindow);
}
DetourTransactionCommit();
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourAttach(&(PVOID&)divaParseParameters, hookedParseParameters);
switch (game_version)
{
case 600:
DetourAttach(&(PVOID&)divaParseParameters_600, hookedCreateWindow);
default:
DetourAttach(&(PVOID&)divaParseParameters_710, hookedCreateWindow);
}
DetourTransactionCommit();
@@ -242,7 +307,13 @@ BOOL APIENTRY DllMain(HMODULE hModule,
setFramerateLimit(nFpsLimit);
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourAttach(&(PVOID&)divaEngineUpdate, hookedEngineUpdate);
switch (game_version)
{
case 600:
DetourAttach(&(PVOID&)divaEngineUpdate_600, hookedCreateWindow);
default:
DetourAttach(&(PVOID&)divaEngineUpdate_710, hookedCreateWindow);
}
DetourTransactionCommit();
// if window is set to screen res, process that now so it can be used for auto internal res
@@ -263,25 +334,43 @@ BOOL APIENTRY DllMain(HMODULE hModule,
printf("[Render] Custom internal resolution enabled\n");
printf("[Render] X: %d Y: %d\n", nIntResWidth, nIntResHeight);
switch (game_version)
{
case 600:
{
DWORD oldProtect, bck;
VirtualProtect((BYTE*)0x00000001409B8B68, 4, PAGE_EXECUTE_READWRITE, &oldProtect);
*((int*)0x00000001409B8B68) = nIntResWidth;
VirtualProtect((BYTE*)0x00000001409B8B68, 6, oldProtect, &bck);
VirtualProtect((BYTE*)0x0000000140980954, 4, PAGE_EXECUTE_READWRITE, &oldProtect);
*((int*)0x0000000140980954) = nIntResWidth;
VirtualProtect((BYTE*)0x0000000140980954, 6, oldProtect, &bck);
}
{
DWORD oldProtect, bck;
VirtualProtect((BYTE*)0x00000001409B8B6C, 4, PAGE_EXECUTE_READWRITE, &oldProtect);
*((int*)0x00000001409B8B6C) = nIntResHeight;
VirtualProtect((BYTE*)0x00000001409B8B6C, 6, oldProtect, &bck);
VirtualProtect((BYTE*)0x0000000140980958, 4, PAGE_EXECUTE_READWRITE, &oldProtect);
*((int*)0x0000000140980958) = nIntResHeight;
VirtualProtect((BYTE*)0x0000000140980958, 6, oldProtect, &bck);
}
break;
default:
{
DWORD oldProtect, bck;
VirtualProtect((BYTE*)0x00000001409B8B68, 4, PAGE_EXECUTE_READWRITE, &oldProtect);
*((int*)0x00000001409B8B68) = nIntResWidth;
VirtualProtect((BYTE*)0x00000001409B8B68, 6, oldProtect, &bck);
}
{
DWORD oldProtect, bck;
VirtualProtect((BYTE*)0x00000001409B8B6C, 4, PAGE_EXECUTE_READWRITE, &oldProtect);
*((int*)0x00000001409B8B6C) = nIntResHeight;
VirtualProtect((BYTE*)0x00000001409B8B6C, 6, oldProtect, &bck);
}
//*((int*)0x00000001409B8B6C) = maxHeight;
//*((int*)0x00000001409B8B14) = maxWidth;
//*((int*)0x00000001409B8B18) = maxHeight;
//*((int*)0x00000001409B8B6C) = maxHeight;
//*((int*)0x00000001409B8B14) = maxWidth;
//*((int*)0x00000001409B8B18) = maxHeight;
//*((int*)0x00000001409B8B1C) = maxWidth; // No parameters width?
//*((int*)0x00000001409B8B20) = maxHeight; // No parameters height?
//*((int*)0x00000001409B8B1C) = maxWidth; // No parameters width?
//*((int*)0x00000001409B8B20) = maxHeight; // No parameters height?
}
}
}
return TRUE;