Improve the AA patches and move them to Patches

This commit is contained in:
nastys
2019-11-17 06:57:41 +01:00
parent c7af59c442
commit 831d8841fe
3 changed files with 63 additions and 6 deletions
@@ -63,7 +63,7 @@
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<LanguageStandard>stdcpp17</LanguageStandard>
<AdditionalIncludeDirectories>..\..\..\dependencies\PluginConfigApi;..\..\..\dependencies\freeglut\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>..\..\..\dependencies\PluginConfigApi;..\..\..\dependencies\freeglut\include;..\..\..\dependencies\freeglut\include;..\..\..\dependencies\detours\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<AdditionalOptions>-d2FH4- %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
@@ -73,7 +73,7 @@
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableUAC>false</EnableUAC>
<AdditionalLibraryDirectories>..\..\..\dependencies\freeglut\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalLibraryDirectories>..\..\..\dependencies\detours\lib;..\..\..\dependencies\freeglut\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalOptions>-d2:-FH4- %(AdditionalOptions)</AdditionalOptions>
</Link>
</ItemDefinitionGroup>
@@ -8,11 +8,34 @@
#include <iomanip>
#include "PluginConfigApi.h"
#include <detours.h>
#pragma comment(lib, "detours.lib")
void InjectCode(void* address, const std::vector<uint8_t> data);
void ApplyPatches();
void(__cdecl* originalTAA)(DWORD *a1, int a2) = (void(__cdecl*)(DWORD *a1, int a2))0x1404B23A0;
void(__cdecl* originalMLAA)(__int64 a1, int a2) = (void(__cdecl*)(__int64 a1, int a2))0x1404B2210;
void hookedTAA(DWORD *a1, int a2)
{
a1[3] = 0; //a1[3] = a2;
a1[348] = -1082130432;
a1[950] = 1;
std::cout << "[Patches] TAA disabled!" << std::endl;
}
void hookedMLAA(__int64 a1, int a2)
{
*(DWORD*)(a1 + 16) = 0; //*(DWORD*)(a1 + 16) = a2;
*(DWORD*)(a1 + 3800) = 1;
std::cout << "[Patches] MLAA disabled!" << std::endl;
}
const LPCWSTR CONFIG_FILE = L".\\config.ini";
HMODULE *hModulePtr;
BOOL APIENTRY DllMain(HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
@@ -21,6 +44,7 @@ BOOL APIENTRY DllMain(HMODULE hModule,
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
hModulePtr = &hModule;
ApplyPatches();
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
@@ -144,6 +168,39 @@ void ApplyPatches() {
auto nHardwareSlider = GetPrivateProfileIntW(L"patches", L"hardware_slider", FALSE, CONFIG_FILE);
auto nOGLPatchA = GetPrivateProfileIntW(L"patches", L"opengl_patch_a", FALSE, CONFIG_FILE);
auto nOGLPatchB = GetPrivateProfileIntW(L"patches", L"opengl_patch_b", FALSE, CONFIG_FILE);
auto nTAA = GetPrivateProfileIntW(L"graphics", L"taa", TRUE, CONFIG_FILE);
auto nMLAA = GetPrivateProfileIntW(L"graphics", L"mlaa", TRUE, CONFIG_FILE);
// Disable AA
if (!(nTAA && nMLAA))
{
DisableThreadLibraryCalls(*hModulePtr);
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
if (!nTAA)
{
std::cout << "[Patches] Hooking TAA..." << std::endl;
DetourAttach(&(PVOID&)originalTAA, (PVOID)hookedTAA);
std::cout << "[Patches] TAA hooked!" << std::endl;
hookedTAA((DWORD*)0x1411AB670, 0);
}
if (!nMLAA)
{
std::cout << "[Patches] Hooking MLAA..." << std::endl;
DetourAttach(&(PVOID&)originalMLAA, (PVOID)hookedMLAA);
std::cout << "[Patches] MLAA hooked!" << std::endl;
hookedMLAA(5387236976, 0);
// make constructor/init not set MLAA
DWORD oldProtect, bck;
VirtualProtect((BYTE*)0x00000001404AB11A, 3, PAGE_EXECUTE_READWRITE, &oldProtect);
*((byte*)0x00000001404AB11A + 0) = 0x90;
*((byte*)0x00000001404AB11A + 1) = 0x90;
*((byte*)0x00000001404AB11A + 2) = 0x90;
VirtualProtect((BYTE*)0x00000001404AB11A, 3, oldProtect, &bck);
}
DetourTransactionCommit();
}
// Replace the hardcoded videos with MP4s, if they exist
if (nMP4Movies)
+4 -4
View File
@@ -132,7 +132,7 @@ namespace TLAC
ComponentsManager.UpdateDraw2D();
}
void InitializeExtraSettings()
/*void InitializeExtraSettings()
{
const LPCTSTR RESOLUTION_CONFIG_FILE_NAME = _T(".\\config.ini");
auto nTAA = GetPrivateProfileIntW(L"graphics", L"taa", TRUE, RESOLUTION_CONFIG_FILE_NAME);
@@ -225,8 +225,8 @@ namespace TLAC
}
printf("[TLAC] MAG Filter set to %d\n", nMagFilter);
}*/
}
}*
}*/
void Dispose()
{
@@ -380,7 +380,7 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReser
DetourAttach(&(PVOID&)divaEngineDraw2D, hookedEngineDraw2D);
DetourTransactionCommit();
TLAC::InitializeExtraSettings();
//TLAC::InitializeExtraSettings();
TLAC::framework::Module = hModule;
break;