From c7dd73c26bb7d20c40d1567dd1799c7a31f27fa9 Mon Sep 17 00:00:00 2001
From: nastys <@>
Date: Sun, 17 Nov 2019 06:57:41 +0100
Subject: [PATCH] Improve the AA patches and move them to Patches
---
.../source/plugins/Patches/Patches.vcxproj | 4 +-
.../source/plugins/Patches/dllmain.cpp | 57 +++++++++++++++++++
source-code/source/plugins/TLAC/dllmain.cpp | 8 +--
3 files changed, 63 insertions(+), 6 deletions(-)
diff --git a/source-code/source/plugins/Patches/Patches.vcxproj b/source-code/source/plugins/Patches/Patches.vcxproj
index 2e280a2..2d811ac 100644
--- a/source-code/source/plugins/Patches/Patches.vcxproj
+++ b/source-code/source/plugins/Patches/Patches.vcxproj
@@ -63,7 +63,7 @@
true
pch.h
stdcpp17
- ..\..\..\dependencies\PluginConfigApi;..\..\..\dependencies\freeglut\include;%(AdditionalIncludeDirectories)
+ ..\..\..\dependencies\PluginConfigApi;..\..\..\dependencies\freeglut\include;..\..\..\dependencies\freeglut\include;..\..\..\dependencies\detours\include;%(AdditionalIncludeDirectories)
MultiThreaded
-d2FH4- %(AdditionalOptions)
@@ -73,7 +73,7 @@
true
true
false
- ..\..\..\dependencies\freeglut\lib;%(AdditionalLibraryDirectories)
+ ..\..\..\dependencies\detours\lib;..\..\..\dependencies\freeglut\lib;%(AdditionalLibraryDirectories)
-d2:-FH4- %(AdditionalOptions)
diff --git a/source-code/source/plugins/Patches/dllmain.cpp b/source-code/source/plugins/Patches/dllmain.cpp
index adc49c1..ecb5c1b 100644
--- a/source-code/source/plugins/Patches/dllmain.cpp
+++ b/source-code/source/plugins/Patches/dllmain.cpp
@@ -8,11 +8,34 @@
#include
#include "PluginConfigApi.h"
+#include
+#pragma comment(lib, "detours.lib")
+
void InjectCode(void* address, const std::vector 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)
diff --git a/source-code/source/plugins/TLAC/dllmain.cpp b/source-code/source/plugins/TLAC/dllmain.cpp
index 45979ea..423bebe 100644
--- a/source-code/source/plugins/TLAC/dllmain.cpp
+++ b/source-code/source/plugins/TLAC/dllmain.cpp
@@ -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;