From bf8f58970dea395945f6b6f2e27bf7ab97342fca Mon Sep 17 00:00:00 2001 From: Silent Date: Mon, 18 Sep 2017 22:13:02 +0200 Subject: [PATCH] Unified code between ddraw and ASIs --- DDraw/DDraw.vcxproj | 2 + DDraw/DDraw.vcxproj.filters | 6 + DDraw/dllmain.cpp | 150 +++------------ SilentPatch/Common.cpp | 175 ++++++++++++++++++ SilentPatch/Common.h | 25 +++ SilentPatch/StdAfx.h | 3 - SilentPatchIII/SilentPatchIII.cpp | 89 ++------- SilentPatchIII/SilentPatchIII.vcxproj | 5 + SilentPatchIII/SilentPatchIII.vcxproj.filters | 3 + SilentPatchSA/SilentPatchSA.cpp | 12 +- SilentPatchVC/SilentPatchVC.cpp | 99 +++------- SilentPatchVC/SilentPatchVC.vcxproj | 5 + SilentPatchVC/SilentPatchVC.vcxproj.filters | 3 + 13 files changed, 295 insertions(+), 282 deletions(-) create mode 100644 SilentPatch/Common.cpp create mode 100644 SilentPatch/Common.h diff --git a/DDraw/DDraw.vcxproj b/DDraw/DDraw.vcxproj index 4687b24..288c7c9 100644 --- a/DDraw/DDraw.vcxproj +++ b/DDraw/DDraw.vcxproj @@ -150,6 +150,7 @@ copy /y "$(TargetPath)" "D:\Steam\steamapps\common\Grand Theft Auto Vice City\dd + @@ -157,6 +158,7 @@ copy /y "$(TargetPath)" "D:\Steam\steamapps\common\Grand Theft Auto Vice City\dd + diff --git a/DDraw/DDraw.vcxproj.filters b/DDraw/DDraw.vcxproj.filters index 6915b57..16560bd 100644 --- a/DDraw/DDraw.vcxproj.filters +++ b/DDraw/DDraw.vcxproj.filters @@ -21,6 +21,9 @@ Source Files + + Source Files + @@ -29,6 +32,9 @@ Header Files + + Header Files + diff --git a/DDraw/dllmain.cpp b/DDraw/dllmain.cpp index d3dce2c..2397e56 100644 --- a/DDraw/dllmain.cpp +++ b/DDraw/dllmain.cpp @@ -9,6 +9,8 @@ #include "MemoryMgr.h" #include "Patterns.h" +#include "Common.h" + #pragma comment(lib, "shlwapi.lib") extern "C" HRESULT WINAPI DirectDrawCreateEx(GUID FAR *lpGUID, LPVOID *lplpDD, REFIID iid, IUnknown FAR *pUnkOuter) @@ -57,124 +59,41 @@ void InjectHooks() { // III 1.0 ppUserFilesDir = (char**)0x580C16; - InjectHook(0x580BB0, GetMyDocumentsPath, PATCH_JUMP); - - Patch(0x581E5E, desktop.right); - Patch(0x581E68, desktop.bottom); - Patch(0x581E72, 32); - Patch(0x581EA8, aNoDesktopMode); - - // No 12mb vram check - Patch(0x581411, 0xEB); - - // No DirectPlay dependency - Patch(0x5812D6, 0xB8); - Patch(0x5812D7, 0x900); + Common::Patches::DDraw_III_10( desktop, aNoDesktopMode ); } else if (*(DWORD*)0x5C2135 == 0xB85548EC) { // III 1.1 ppUserFilesDir = (char**)0x580F66; - InjectHook(0x580F00, GetMyDocumentsPath, PATCH_JUMP); - - Patch(0x58219E, desktop.right); - Patch(0x5821A8, desktop.bottom); - Patch(0x5821B2, 32); - Patch(0x5821E8, aNoDesktopMode); - - // No 12mb vram check - Patch(0x581753, 0xEB); - - // No DirectPlay dependency - Patch(0x581620, 0xB8); - Patch(0x581621, 0x900); + Common::Patches::DDraw_III_11( desktop, aNoDesktopMode ); } else if (*(DWORD*)0x5C6FD5 == 0xB85548EC) { // III Steam ppUserFilesDir = (char**)0x580E66; - InjectHook(0x580E00, GetMyDocumentsPath, PATCH_JUMP); - - Patch(0x58208E, desktop.right); - Patch(0x582098, desktop.bottom); - Patch(0x5820A2, 32); - Patch(0x5820D8, aNoDesktopMode); - - // No 12mb vram check - Patch(0x581653, 0xEB); - - // No DirectPlay dependency - Patch(0x581520, 0xB8); - Patch(0x581521, 0x900); + Common::Patches::DDraw_III_Steam( desktop, aNoDesktopMode ); } else if (*(DWORD*)0x667BF5 == 0xB85548EC) { // VC 1.0 ppUserFilesDir = (char**)0x6022AA; - InjectHook(0x602240, GetMyDocumentsPath, PATCH_JUMP); - - InjectHook(0x601A40, GetMyDocumentsPath, PATCH_CALL); - InjectHook(0x601A45, 0x601B2F, PATCH_JUMP); - - Patch(0x600E7E, desktop.right); - Patch(0x600E88, desktop.bottom); - Patch(0x600E92, 32); - Patch(0x600EC8, aNoDesktopMode); - - // No 12mb vram check - Patch(0x601E26, 0xEB); - - // No DirectPlay dependency - Patch(0x601CA0, 0xB8); - Patch(0x601CA1, 0x900); + Common::Patches::DDraw_VC_10( desktop, aNoDesktopMode ); } else if (*(DWORD*)0x667C45 == 0xB85548EC) { // VC 1.1 ppUserFilesDir = (char**)0x60228A; - InjectHook(0x602220, GetMyDocumentsPath, PATCH_JUMP); - - InjectHook(0x601A70, GetMyDocumentsPath, PATCH_CALL); - InjectHook(0x601A75, 0x601B5F, PATCH_JUMP); - - Patch(0x600E9E, desktop.right); - Patch(0x600EA8, desktop.bottom); - Patch(0x600EB2, 32); - Patch(0x600EE8, aNoDesktopMode); - - // No 12mb vram check - Patch(0x601E56, 0xEB); - - // No DirectPlay dependency - Patch(0x601CD0, 0xB8); - Patch(0x601CD1, 0x900); + Common::Patches::DDraw_VC_11( desktop, aNoDesktopMode ); } else if (*(DWORD*)0x666BA5 == 0xB85548EC) { // VC Steam ppUserFilesDir = (char**)0x601ECA; - InjectHook(0x601E60, GetMyDocumentsPath, PATCH_JUMP); - - InjectHook(0x6016B0, GetMyDocumentsPath, PATCH_CALL); - InjectHook(0x6016B5, 0x60179F, PATCH_JUMP); - - Patch(0x600ADE, desktop.right); - Patch(0x600AE8, desktop.bottom); - Patch(0x600AF2, 32); - Patch(0x600B28, aNoDesktopMode); - - // No 12mb vram check - Patch(0x601A96, 0xEB); - - // No DirectPlay dependency - Patch(0x601910, 0xB8); - Patch(0x601911, 0x900); + Common::Patches::DDraw_VC_Steam( desktop, aNoDesktopMode ); } } - -static bool FixRwcseg_Patterns(); static bool rwcsegUnprotected = false; static void ProcHook() @@ -188,7 +107,7 @@ static void ProcHook() if ( !rwcsegUnprotected ) { - rwcsegUnprotected = FixRwcseg_Patterns(); + rwcsegUnprotected = Common::Patches::FixRwcseg_Patterns(); } } } @@ -247,26 +166,6 @@ static bool FixRwcseg_Header() return false; } -static bool FixRwcseg_Patterns() -{ - using namespace hook; - - auto begin = pattern( "55 8B EC 50 53 51 52 8B 5D 14 8B 4D 10 8B 45 0C 8B 55 08" ).count_hint(1000); - auto end = pattern( "9B D9 3D ? ? ? ? 81 25 ? ? ? ? FF FC FF FF 83 0D ? ? ? ? 3F" ).count_hint(1000); - - if ( begin.count_hint(1).size() == 1 && end.count_hint(1).size() == 1 ) - { - const ptrdiff_t size = (intptr_t)end.get_first( 24 ) - (intptr_t)begin.get_first(); - if ( size > 0 ) - { - DWORD dwProtect; - VirtualProtect( begin.get_first(), size, PAGE_EXECUTE_READ, &dwProtect ); - return true; - } - } - return false; -} - static bool PatchIAT() { HINSTANCE hInstance = GetModuleHandle(nullptr); @@ -280,25 +179,26 @@ static bool PatchIAT() { if ( !_stricmp((const char*)((DWORD_PTR)hInstance + pImports->Name), "KERNEL32.DLL") ) { - if ( pImports->OriginalFirstThunk == 0 ) return false; - - PIMAGE_IMPORT_BY_NAME* pFunctions = (PIMAGE_IMPORT_BY_NAME*)((DWORD_PTR)hInstance + pImports->OriginalFirstThunk); - - // kernel32.dll found, find GetStartupInfoA - for ( ptrdiff_t j = 0; pFunctions[j] != nullptr; j++ ) + if ( pImports->OriginalFirstThunk != 0 ) { - if ( !strcmp((const char*)((DWORD_PTR)hInstance + pFunctions[j]->Name), "GetStartupInfoA") ) + PIMAGE_IMPORT_BY_NAME* pFunctions = (PIMAGE_IMPORT_BY_NAME*)((DWORD_PTR)hInstance + pImports->OriginalFirstThunk); + + // kernel32.dll found, find GetStartupInfoA + for ( ptrdiff_t j = 0; pFunctions[j] != nullptr; j++ ) { - // Overwrite the address with the address to a custom GetStartupInfoA - DWORD dwProtect[2]; - DWORD_PTR* pAddress = &((DWORD_PTR*)((DWORD_PTR)hInstance + pImports->FirstThunk))[j]; + if ( !strcmp((const char*)((DWORD_PTR)hInstance + pFunctions[j]->Name), "GetStartupInfoA") ) + { + // Overwrite the address with the address to a custom GetStartupInfoA + DWORD dwProtect[2]; + DWORD_PTR* pAddress = &((DWORD_PTR*)((DWORD_PTR)hInstance + pImports->FirstThunk))[j]; - VirtualProtect(pAddress, sizeof(DWORD_PTR), PAGE_EXECUTE_READWRITE, &dwProtect[0]); - pOrgGetStartupInfoA = **(VOID(WINAPI**)(LPSTARTUPINFOA))pAddress; - *pAddress = (DWORD_PTR)GetStartupInfoA_Hook; - VirtualProtect(pAddress, sizeof(DWORD_PTR), dwProtect[0], &dwProtect[1]); + VirtualProtect(pAddress, sizeof(DWORD_PTR), PAGE_EXECUTE_READWRITE, &dwProtect[0]); + pOrgGetStartupInfoA = **(VOID(WINAPI**)(LPSTARTUPINFOA))pAddress; + *pAddress = (DWORD_PTR)GetStartupInfoA_Hook; + VirtualProtect(pAddress, sizeof(DWORD_PTR), dwProtect[0], &dwProtect[1]); - return true; + return true; + } } } } diff --git a/SilentPatch/Common.cpp b/SilentPatch/Common.cpp new file mode 100644 index 0000000..a875fec --- /dev/null +++ b/SilentPatch/Common.cpp @@ -0,0 +1,175 @@ +#include "Common.h" + +#include +#include +#include "MemoryMgr.h" +#include "Patterns.h" + +#pragma comment(lib, "shlwapi.lib") + +extern char** ppUserFilesDir; + +namespace Common { + char* GetMyDocumentsPath() + { + static char cUserFilesPath[MAX_PATH]; + + if ( cUserFilesPath[0] == '\0' ) + { + SHGetFolderPathA(nullptr, CSIDL_MYDOCUMENTS, nullptr, SHGFP_TYPE_CURRENT, cUserFilesPath); + PathAppendA(cUserFilesPath, *ppUserFilesDir); + CreateDirectoryA(cUserFilesPath, nullptr); + } + return cUserFilesPath; + } + + namespace Patches { + + bool FixRwcseg_Patterns() + { + using namespace hook; + + auto begin = pattern( "55 8B EC 50 53 51 52 8B 5D 14 8B 4D 10 8B 45 0C 8B 55 08" ); + auto end = pattern( "9B D9 3D ? ? ? ? 81 25 ? ? ? ? FF FC FF FF 83 0D ? ? ? ? 3F" ); + + if ( begin.count_hint(1).size() == 1 && end.count_hint(1).size() == 1 ) + { + const ptrdiff_t size = (intptr_t)end.get_first( 24 ) - (intptr_t)begin.get_first(); + if ( size > 0 ) + { + DWORD dwProtect; + VirtualProtect( begin.get_first(), size, PAGE_EXECUTE_READ, &dwProtect ); + return true; + } + } + return false; + } + + // ================= III ================= + void DDraw_III_10( const RECT& desktop, const char* desktopText ) + { + using namespace Memory; + + InjectHook(0x580BB0, GetMyDocumentsPath, PATCH_JUMP); + + Patch(0x581E5E, desktop.right); + Patch(0x581E68, desktop.bottom); + Patch(0x581E72, 32); + Patch(0x581EA8, desktopText); + + // No 12mb vram check + Patch(0x581411, 0xEB); + + // No DirectPlay dependency + Patch(0x5812D6, 0xB8); + Patch(0x5812D7, 0x900); + } + + void DDraw_III_11( const RECT& desktop, const char* desktopText ) + { + using namespace Memory; + + InjectHook(0x580F00, GetMyDocumentsPath, PATCH_JUMP); + + Patch(0x58219E, desktop.right); + Patch(0x5821A8, desktop.bottom); + Patch(0x5821B2, 32); + Patch(0x5821E8, desktopText); + + // No 12mb vram check + Patch(0x581753, 0xEB); + + // No DirectPlay dependency + Patch(0x581620, 0xB8); + Patch(0x581621, 0x900); + } + + void DDraw_III_Steam( const RECT& desktop, const char* desktopText ) + { + using namespace Memory; + + InjectHook(0x580E00, GetMyDocumentsPath, PATCH_JUMP); + + Patch(0x58208E, desktop.right); + Patch(0x582098, desktop.bottom); + Patch(0x5820A2, 32); + Patch(0x5820D8, desktopText); + + // No 12mb vram check + Patch(0x581653, 0xEB); + + // No DirectPlay dependency + Patch(0x581520, 0xB8); + Patch(0x581521, 0x900); + } + + // ================= VC ================= + + void DDraw_VC_10( const RECT& desktop, const char* desktopText ) + { + using namespace Memory; + + InjectHook(0x602240, GetMyDocumentsPath, PATCH_JUMP); + + InjectHook(0x601A40, GetMyDocumentsPath, PATCH_CALL); + InjectHook(0x601A45, 0x601B2F, PATCH_JUMP); + + Patch(0x600E7E, desktop.right); + Patch(0x600E88, desktop.bottom); + Patch(0x600E92, 32); + Patch(0x600EC8, desktopText); + + // No 12mb vram check + Patch(0x601E26, 0xEB); + + // No DirectPlay dependency + Patch(0x601CA0, 0xB8); + Patch(0x601CA1, 0x900); + } + + void DDraw_VC_11( const RECT& desktop, const char* desktopText ) + { + using namespace Memory; + + InjectHook(0x602220, GetMyDocumentsPath, PATCH_JUMP); + + InjectHook(0x601A70, GetMyDocumentsPath, PATCH_CALL); + InjectHook(0x601A75, 0x601B5F, PATCH_JUMP); + + Patch(0x600E9E, desktop.right); + Patch(0x600EA8, desktop.bottom); + Patch(0x600EB2, 32); + Patch(0x600EE8, desktopText); + + // No 12mb vram check + Patch(0x601E56, 0xEB); + + // No DirectPlay dependency + Patch(0x601CD0, 0xB8); + Patch(0x601CD1, 0x900); + } + + + void DDraw_VC_Steam( const RECT& desktop, const char* desktopText ) + { + using namespace Memory; + + InjectHook(0x601E60, GetMyDocumentsPath, PATCH_JUMP); + + InjectHook(0x6016B0, GetMyDocumentsPath, PATCH_CALL); + InjectHook(0x6016B5, 0x60179F, PATCH_JUMP); + + Patch(0x600ADE, desktop.right); + Patch(0x600AE8, desktop.bottom); + Patch(0x600AF2, 32); + Patch(0x600B28, desktopText); + + // No 12mb vram check + Patch(0x601A96, 0xEB); + + // No DirectPlay dependency + Patch(0x601910, 0xB8); + Patch(0x601911, 0x900); + } + } +} \ No newline at end of file diff --git a/SilentPatch/Common.h b/SilentPatch/Common.h new file mode 100644 index 0000000..7d04629 --- /dev/null +++ b/SilentPatch/Common.h @@ -0,0 +1,25 @@ +#pragma once + +#define WIN32_LEAN_AND_MEAN + +#define WINVER 0x0501 +#define _WIN32_WINNT 0x0501 +#define NOMINMAX + +#include + +namespace Common +{ + namespace Patches + { + bool FixRwcseg_Patterns(); + + void DDraw_III_10( const RECT& desktop, const char* desktopText ); + void DDraw_III_11( const RECT& desktop, const char* desktopText ); + void DDraw_III_Steam( const RECT& desktop, const char* desktopText ); + + void DDraw_VC_10( const RECT& desktop, const char* desktopText ); + void DDraw_VC_11( const RECT& desktop, const char* desktopText ); + void DDraw_VC_Steam( const RECT& desktop, const char* desktopText ); + } +}; \ No newline at end of file diff --git a/SilentPatch/StdAfx.h b/SilentPatch/StdAfx.h index fff2905..8ddc57a 100644 --- a/SilentPatch/StdAfx.h +++ b/SilentPatch/StdAfx.h @@ -5,11 +5,8 @@ #define NOMINMAX #include -#include #include #include -#include -#include #include "MemoryMgr.h" diff --git a/SilentPatchIII/SilentPatchIII.cpp b/SilentPatchIII/SilentPatchIII.cpp index 2db9c0e..ccad529 100644 --- a/SilentPatchIII/SilentPatchIII.cpp +++ b/SilentPatchIII/SilentPatchIII.cpp @@ -3,6 +3,7 @@ #include "General.h" #include "Timer.h" #include "Patterns.h" +#include "Common.h" #include @@ -285,20 +286,7 @@ void __declspec(naked) RadarBoundsCheckEntityBlip() } } -char** const ppUserFilesDir = AddressByVersion(0x580C16, 0x580F66, 0x580E66); - -char* GetMyDocumentsPath() -{ - static char cUserFilesPath[MAX_PATH]; - - if ( cUserFilesPath[0] == '\0' ) - { - SHGetFolderPathA(nullptr, CSIDL_MYDOCUMENTS, nullptr, SHGFP_TYPE_CURRENT, cUserFilesPath); - PathAppendA(cUserFilesPath, *ppUserFilesDir); - CreateDirectoryA(cUserFilesPath, nullptr); - } - return cUserFilesPath; -} +extern char** ppUserFilesDir = AddressByVersion(0x580C16, 0x580F66, 0x580E66); static LARGE_INTEGER FrameTime; int32_t GetTimeSinceLastFrame() @@ -461,23 +449,6 @@ void Patch_III_10(const RECT& desktop) InjectHook(0x582EFD, NewFrameRender); InjectHook(0x582EA4, GetTimeSinceLastFrame); - // Default to desktop res - Patch(0x581E5E, desktop.right); - Patch(0x581E68, desktop.bottom); - Patch(0x581E72, 32); - Patch(0x581EA8, aNoDesktopMode); - - // No 12mb vram check - Patch(0x581411, 0xEB); - - // No DirectPlay dependency - Patch(0x5812D6, 0xB8); - Patch(0x5812D7, 0x900); - - // SHGetFolderPath on User Files - InjectHook(0x580BB0, GetMyDocumentsPath, PATCH_JUMP); - - // Reinit CCarCtrl fields (firetruck and ambulance generation) ReadCall( 0x48C4FB, orgCarCtrlReInit ); InjectHook(0x48C4FB, CarCtrlReInit_SilentPatch); @@ -518,6 +489,8 @@ void Patch_III_10(const RECT& desktop) Patch(0x58274D, 0x006A); } #endif + + Common::Patches::DDraw_III_10( desktop, aNoDesktopMode ); } void Patch_III_11(const RECT& desktop) @@ -611,22 +584,6 @@ void Patch_III_11(const RECT& desktop) InjectHook(0x58323D, NewFrameRender); InjectHook(0x5831E4, GetTimeSinceLastFrame); - // Default to desktop res - Patch(0x58219E, desktop.right); - Patch(0x5821A8, desktop.bottom); - Patch(0x5821B2, 32); - Patch(0x5821E8, aNoDesktopMode); - - // No 12mb vram check - Patch(0x581753, 0xEB); - - // No DirectPlay dependency - Patch(0x581620, 0xB8); - Patch(0x581621, 0x900); - - // SHGetFolderPath on User Files - InjectHook(0x580F00, GetMyDocumentsPath, PATCH_JUMP); - // Reinit CCarCtrl fields (firetruck and ambulance generation) ReadCall( 0x48C5FB, orgCarCtrlReInit ); @@ -658,6 +615,8 @@ void Patch_III_11(const RECT& desktop) // Fixed crash related to autopilot timing calculations InjectHook(0x4139B2, AutoPilotTimerFix_III, PATCH_JUMP); + + Common::Patches::DDraw_III_11( desktop, aNoDesktopMode ); } void Patch_III_Steam(const RECT& desktop) @@ -747,23 +706,6 @@ void Patch_III_Steam(const RECT& desktop) InjectHook(0x58312D, NewFrameRender); InjectHook(0x5830D4, GetTimeSinceLastFrame); - // Default to desktop res - Patch(0x58208E, desktop.right); - Patch(0x582098, desktop.bottom); - Patch(0x5820A2, 32); - Patch(0x5820D8, aNoDesktopMode); - - // No 12mb vram check - Patch(0x581653, 0xEB); - - // No DirectPlay dependency - Patch(0x581520, 0xB8); - Patch(0x581521, 0x900); - - // SHGetFolderPath on User Files - InjectHook(0x580E00, GetMyDocumentsPath, PATCH_JUMP); - - // Reinit CCarCtrl fields (firetruck and ambulance generation) ReadCall( 0x48C58B, orgCarCtrlReInit ); InjectHook(0x48C58B, CarCtrlReInit_SilentPatch); @@ -786,6 +728,8 @@ void Patch_III_Steam(const RECT& desktop) // Fixed crash related to autopilot timing calculations InjectHook(0x4139B2, AutoPilotTimerFix_III, PATCH_JUMP); + + Common::Patches::DDraw_III_Steam( desktop, aNoDesktopMode ); } void Patch_III_Common() @@ -890,14 +834,19 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) GetWindowRect(GetDesktopWindow(), &desktop); sprintf_s(aNoDesktopMode, "Cannot find %dx%dx32 video mode", desktop.right, desktop.bottom); - std::unique_ptr Protect = ScopedUnprotect::UnprotectSectionOrFullModule( GetModuleHandle( nullptr ), ".text" ); + // This scope is mandatory so Protect goes out of scope before rwcseg gets fixed + { + std::unique_ptr Protect = ScopedUnprotect::UnprotectSectionOrFullModule( GetModuleHandle( nullptr ), ".text" ); - if (*(DWORD*)0x5C1E75 == 0xB85548EC) Patch_III_10(desktop); - else if (*(DWORD*)0x5C2135 == 0xB85548EC) Patch_III_11(desktop); - else if (*(DWORD*)0x5C6FD5 == 0xB85548EC) Patch_III_Steam(desktop); - else return TRUE; + if (*(DWORD*)0x5C1E75 == 0xB85548EC) Patch_III_10(desktop); + else if (*(DWORD*)0x5C2135 == 0xB85548EC) Patch_III_11(desktop); + else if (*(DWORD*)0x5C6FD5 == 0xB85548EC) Patch_III_Steam(desktop); + else return TRUE; - Patch_III_Common(); + Patch_III_Common(); + } + + Common::Patches::FixRwcseg_Patterns(); HMODULE hDummyHandle; GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, (LPCWSTR)&DllMain, &hDummyHandle); diff --git a/SilentPatchIII/SilentPatchIII.vcxproj b/SilentPatchIII/SilentPatchIII.vcxproj index 5f1afef..13eed4d 100644 --- a/SilentPatchIII/SilentPatchIII.vcxproj +++ b/SilentPatchIII/SilentPatchIII.vcxproj @@ -15,6 +15,11 @@ + + NotUsing + NotUsing + NotUsing + NotUsing NotUsing diff --git a/SilentPatchIII/SilentPatchIII.vcxproj.filters b/SilentPatchIII/SilentPatchIII.vcxproj.filters index 2f99a6a..f856ff4 100644 --- a/SilentPatchIII/SilentPatchIII.vcxproj.filters +++ b/SilentPatchIII/SilentPatchIII.vcxproj.filters @@ -27,6 +27,9 @@ Source Files + + Source Files + diff --git a/SilentPatchSA/SilentPatchSA.cpp b/SilentPatchSA/SilentPatchSA.cpp index 016a812..5730a79 100644 --- a/SilentPatchSA/SilentPatchSA.cpp +++ b/SilentPatchSA/SilentPatchSA.cpp @@ -813,7 +813,7 @@ void DrawRect_HalfPixel_Steam(CRect& rect, const CRGBA& rgba) ((void(*)(const CRect&, const CRGBA&))0x75CDA0)(rect, rgba); } -char* GetMyDocumentsPath() +char* GetMyDocumentsPathSA() { static char cUserFilesPath[MAX_PATH]; static char* const ppTempBufPtr = *GetVer() == 0 ? *AddressByRegion_10(0x744FE5) : cUserFilesPath; @@ -3258,7 +3258,7 @@ void Patch_SA_10() Patch(AddressByRegion_10(0x74754B), 0x900); // SHGetFolderPath on User Files - InjectHook(0x744FB0, GetMyDocumentsPath, PATCH_JUMP); + InjectHook(0x744FB0, GetMyDocumentsPathSA, PATCH_JUMP); // Fixed muzzleflash not showing from last bullet Nop(0x61ECE4, 2); @@ -3748,7 +3748,7 @@ void Patch_SA_11() Patch(AddressByRegion_11(0x747E1B), 0x900); // SHGetFolderPath on User Files - InjectHook(0x7457E0, GetMyDocumentsPath, PATCH_JUMP); + InjectHook(0x7457E0, GetMyDocumentsPathSA, PATCH_JUMP); // Fixed muzzleflash not showing from last bullet Nop(0x61F504, 2); @@ -4054,7 +4054,7 @@ void Patch_SA_Steam() Patch(0x781457, 0x900); // SHGetFolderPath on User Files - InjectHook(0x77EDC0, GetMyDocumentsPath, PATCH_JUMP); + InjectHook(0x77EDC0, GetMyDocumentsPathSA, PATCH_JUMP); // Fixed muzzleflash not showing from last bullet Nop(0x61F504, 2); @@ -4374,7 +4374,7 @@ void Patch_SA_NewSteam_r2() Patch(0x77B46F, 0x900); // SHGetFolderPath on User Files - InjectHook(0x778FA0, GetMyDocumentsPath, PATCH_JUMP); + InjectHook(0x778FA0, GetMyDocumentsPathSA, PATCH_JUMP); // Fixed muzzleflash not showing from last bullet Nop(0x63E8A9, 2); @@ -4561,7 +4561,7 @@ void Patch_SA_NewSteam_r2_lv() Patch(0x77B35F, 0x900); // SHGetFolderPath on User Files - InjectHook(0x778E90, GetMyDocumentsPath, PATCH_JUMP); + InjectHook(0x778E90, GetMyDocumentsPathSA, PATCH_JUMP); // Fixed muzzleflash not showing from last bullet Nop(0x63E789, 2); diff --git a/SilentPatchVC/SilentPatchVC.cpp b/SilentPatchVC/SilentPatchVC.cpp index c758188..54ecdec 100644 --- a/SilentPatchVC/SilentPatchVC.cpp +++ b/SilentPatchVC/SilentPatchVC.cpp @@ -2,6 +2,7 @@ #include "Timer.h" #include "Patterns.h" +#include "Common.h" #include @@ -143,20 +144,7 @@ void __declspec(naked) SubtitlesShadowFix() } } -char** const ppUserFilesDir = AddressByVersion(0x6022AA, 0x60228A, 0x601ECA); - -char* GetMyDocumentsPath() -{ - static char cUserFilesPath[MAX_PATH]; - - if ( cUserFilesPath[0] == '\0' ) - { - SHGetFolderPathA(nullptr, CSIDL_MYDOCUMENTS, nullptr, SHGFP_TYPE_CURRENT, cUserFilesPath); - PathAppendA(cUserFilesPath, *ppUserFilesDir); - CreateDirectoryA(cUserFilesPath, nullptr); - } - return cUserFilesPath; -} +extern char** ppUserFilesDir = AddressByVersion(0x6022AA, 0x60228A, 0x601ECA); static LARGE_INTEGER FrameTime; int32_t GetTimeSinceLastFrame() @@ -267,24 +255,6 @@ void Patch_VC_10(const RECT& desktop) InjectHook(0x6004A2, NewFrameRender); InjectHook(0x600449, GetTimeSinceLastFrame); - // Default to desktop res - Patch(0x600E7E, desktop.right); - Patch(0x600E88, desktop.bottom); - Patch(0x600E92, 32); - Patch(0x600EC8, aNoDesktopMode); - - // No 12mb vram check - Patch(0x601E26, 0xEB); - - // No DirectPlay dependency - Patch(0x601CA0, 0xB8); - Patch(0x601CA1, 0x900); - - // SHGetFolderPath on User Files - InjectHook(0x602240, GetMyDocumentsPath, PATCH_JUMP); - - InjectHook(0x601A40, GetMyDocumentsPath, PATCH_CALL); - InjectHook(0x601A45, 0x601B2F, PATCH_JUMP); // RsMouseSetPos call (SA style fix) InjectHook(0x4A5E45, ResetMousePos); @@ -351,6 +321,8 @@ void Patch_VC_10(const RECT& desktop) Patch(0x5FFAED, 0x006A); } #endif + + Common::Patches::DDraw_VC_10( desktop, aNoDesktopMode ); } void Patch_VC_11(const RECT& desktop) @@ -397,25 +369,6 @@ void Patch_VC_11(const RECT& desktop) InjectHook(0x6004C2, NewFrameRender); InjectHook(0x600469, GetTimeSinceLastFrame); - // Default to desktop res - Patch(0x600E9E, desktop.right); - Patch(0x600EA8, desktop.bottom); - Patch(0x600EB2, 32); - Patch(0x600EE8, aNoDesktopMode); - - // No 12mb vram check - Patch(0x601E56, 0xEB); - - // No DirectPlay dependency - Patch(0x601CD0, 0xB8); - Patch(0x601CD1, 0x900); - - // SHGetFolderPath on User Files - InjectHook(0x602220, GetMyDocumentsPath, PATCH_JUMP); - - InjectHook(0x601A70, GetMyDocumentsPath, PATCH_CALL); - InjectHook(0x601A75, 0x601B5F, PATCH_JUMP); - // RsMouseSetPos call (SA style fix) InjectHook(0x4A5E65, ResetMousePos); @@ -472,6 +425,8 @@ void Patch_VC_11(const RECT& desktop) // Fixed crash related to autopilot timing calculations InjectHook(0x418FAE, AutoPilotTimerFix_VC, PATCH_JUMP); + + Common::Patches::DDraw_VC_11( desktop, aNoDesktopMode ); } void Patch_VC_Steam(const RECT& desktop) @@ -518,25 +473,6 @@ void Patch_VC_Steam(const RECT& desktop) InjectHook(0x600102, NewFrameRender); InjectHook(0x6000A9, GetTimeSinceLastFrame); - // Default to desktop res - Patch(0x600ADE, desktop.right); - Patch(0x600AE8, desktop.bottom); - Patch(0x600AF2, 32); - Patch(0x600B28, aNoDesktopMode); - - // No 12mb vram check - Patch(0x601A96, 0xEB); - - // No DirectPlay dependency - Patch(0x601910, 0xB8); - Patch(0x601911, 0x900); - - // SHGetFolderPath on User Files - InjectHook(0x601E60, GetMyDocumentsPath, PATCH_JUMP); - - InjectHook(0x6016B0, GetMyDocumentsPath, PATCH_CALL); - InjectHook(0x6016B5, 0x60179F, PATCH_JUMP); - // RsMouseSetPos call (SA style fix) InjectHook(0x4A5D15, ResetMousePos); @@ -592,6 +528,8 @@ void Patch_VC_Steam(const RECT& desktop) // Fixed crash related to autopilot timing calculations InjectHook(0x418FAE, AutoPilotTimerFix_VC, PATCH_JUMP); + + Common::Patches::DDraw_VC_Steam( desktop, aNoDesktopMode ); } void Patch_VC_JP() @@ -708,17 +646,22 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) GetWindowRect(GetDesktopWindow(), &desktop); sprintf_s(aNoDesktopMode, "Cannot find %dx%dx32 video mode", desktop.right, desktop.bottom); - std::unique_ptr Protect = ScopedUnprotect::UnprotectSectionOrFullModule( GetModuleHandle( nullptr ), ".text" ); + // This scope is mandatory so Protect goes out of scope before rwcseg gets fixed + { + std::unique_ptr Protect = ScopedUnprotect::UnprotectSectionOrFullModule( GetModuleHandle( nullptr ), ".text" ); - if(*(DWORD*)0x667BF5 == 0xB85548EC) Patch_VC_10(desktop); - else if(*(DWORD*)0x667C45 == 0xB85548EC) Patch_VC_11(desktop); - else if (*(DWORD*)0x666BA5 == 0xB85548EC) Patch_VC_Steam(desktop); + if(*(DWORD*)0x667BF5 == 0xB85548EC) Patch_VC_10(desktop); + else if(*(DWORD*)0x667C45 == 0xB85548EC) Patch_VC_11(desktop); + else if (*(DWORD*)0x666BA5 == 0xB85548EC) Patch_VC_Steam(desktop); - // Y axis sensitivity only - else if (*(DWORD*)0x601048 == 0x5E5F5D60) Patch_VC_JP(); - else return TRUE; + // Y axis sensitivity only + else if (*(DWORD*)0x601048 == 0x5E5F5D60) Patch_VC_JP(); + else return TRUE; - Patch_VC_Common(); + Patch_VC_Common(); + } + + Common::Patches::FixRwcseg_Patterns(); HMODULE hDummyHandle; GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, (LPCWSTR)&DllMain, &hDummyHandle); diff --git a/SilentPatchVC/SilentPatchVC.vcxproj b/SilentPatchVC/SilentPatchVC.vcxproj index 3d84576..3564255 100644 --- a/SilentPatchVC/SilentPatchVC.vcxproj +++ b/SilentPatchVC/SilentPatchVC.vcxproj @@ -175,6 +175,11 @@ + + NotUsing + NotUsing + NotUsing + NotUsing NotUsing diff --git a/SilentPatchVC/SilentPatchVC.vcxproj.filters b/SilentPatchVC/SilentPatchVC.vcxproj.filters index 1447612..720a12e 100644 --- a/SilentPatchVC/SilentPatchVC.vcxproj.filters +++ b/SilentPatchVC/SilentPatchVC.vcxproj.filters @@ -44,6 +44,9 @@ Source Files + + Source Files +