From 2af4ec8e06ca592391ba989edbacd4ae13ba8cd5 Mon Sep 17 00:00:00 2001 From: Silent Date: Mon, 26 Jul 2021 23:52:20 +0200 Subject: [PATCH] Obtain desktop resolution regardless of DPI scaling Fixes "Cannot find X video mode" when DPI scaling is in use --- DDraw/DDraw.vcxproj | 2 + DDraw/DDraw.vcxproj.filters | 6 ++ DDraw/dllmain.cpp | 18 ++--- SilentPatch/Common_ddraw.cpp | 74 +++++++++++++------ SilentPatch/Common_ddraw.h | 20 ++--- SilentPatch/Desktop.cpp | 24 ++++++ SilentPatch/Desktop.h | 6 ++ SilentPatchIII/SilentPatchIII.cpp | 24 +++--- SilentPatchIII/SilentPatchIII.vcxproj | 6 ++ SilentPatchIII/SilentPatchIII.vcxproj.filters | 6 ++ SilentPatchSA/SilentPatchSA.cpp | 44 ++++++----- SilentPatchSA/SilentPatchSA.vcxproj | 21 +++++- SilentPatchSA/SilentPatchSA.vcxproj.filters | 6 ++ SilentPatchVC/SilentPatchVC.cpp | 24 +++--- SilentPatchVC/SilentPatchVC.vcxproj | 6 ++ SilentPatchVC/SilentPatchVC.vcxproj.filters | 6 ++ 16 files changed, 202 insertions(+), 91 deletions(-) create mode 100644 SilentPatch/Desktop.cpp create mode 100644 SilentPatch/Desktop.h diff --git a/DDraw/DDraw.vcxproj b/DDraw/DDraw.vcxproj index 48fbe8e..e537367 100644 --- a/DDraw/DDraw.vcxproj +++ b/DDraw/DDraw.vcxproj @@ -168,6 +168,7 @@ copy /y "$(TargetPath)" "D:\Steam\steamapps\common\Grand Theft Auto Vice City\dd + @@ -176,6 +177,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 2e1bfcf..c6835eb 100644 --- a/DDraw/DDraw.vcxproj.filters +++ b/DDraw/DDraw.vcxproj.filters @@ -30,6 +30,9 @@ Source Files\Utils + + Source Files + @@ -41,6 +44,9 @@ Header Files\Utils + + Header Files + diff --git a/DDraw/dllmain.cpp b/DDraw/dllmain.cpp index 5aac924..f9f74f8 100644 --- a/DDraw/dllmain.cpp +++ b/DDraw/dllmain.cpp @@ -10,6 +10,7 @@ #include "Utils/Patterns.h" #include "Common_ddraw.h" +#include "Desktop.h" #pragma comment(lib, "shlwapi.lib") @@ -34,9 +35,8 @@ void InjectHooks() { static char aNoDesktopMode[64]; - RECT desktop; - GetWindowRect(GetDesktopWindow(), &desktop); - sprintf_s(aNoDesktopMode, "Cannot find %dx%dx32 video mode", desktop.right, desktop.bottom); + const auto [width, height] = GetDesktopResolution(); + sprintf_s(aNoDesktopMode, "Cannot find %ux%ux32 video mode", width, height); std::unique_ptr Protect = ScopedUnprotect::UnprotectSectionOrFullModule( GetModuleHandle( nullptr ), ".text" ); @@ -44,38 +44,38 @@ void InjectHooks() { // III 1.0 ppUserFilesDir = (char**)0x580C16; - Common::Patches::DDraw_III_10( desktop, aNoDesktopMode ); + Common::Patches::DDraw_III_10( width, height, aNoDesktopMode ); } else if (*(DWORD*)0x5C2135 == 0xB85548EC) { // III 1.1 ppUserFilesDir = (char**)0x580F66; - Common::Patches::DDraw_III_11( desktop, aNoDesktopMode ); + Common::Patches::DDraw_III_11( width, height, aNoDesktopMode ); } else if (*(DWORD*)0x5C6FD5 == 0xB85548EC) { // III Steam ppUserFilesDir = (char**)0x580E66; - Common::Patches::DDraw_III_Steam( desktop, aNoDesktopMode ); + Common::Patches::DDraw_III_Steam( width, height, aNoDesktopMode ); } else if (*(DWORD*)0x667BF5 == 0xB85548EC) { // VC 1.0 ppUserFilesDir = (char**)0x6022AA; - Common::Patches::DDraw_VC_10( desktop, aNoDesktopMode ); + Common::Patches::DDraw_VC_10( width, height, aNoDesktopMode ); } else if (*(DWORD*)0x667C45 == 0xB85548EC) { // VC 1.1 ppUserFilesDir = (char**)0x60228A; - Common::Patches::DDraw_VC_11( desktop, aNoDesktopMode ); + Common::Patches::DDraw_VC_11( width, height, aNoDesktopMode ); } else if (*(DWORD*)0x666BA5 == 0xB85548EC) { // VC Steam ppUserFilesDir = (char**)0x601ECA; - Common::Patches::DDraw_VC_Steam( desktop, aNoDesktopMode ); + Common::Patches::DDraw_VC_Steam( width, height, aNoDesktopMode ); } Common::Patches::DDraw_Common(); diff --git a/SilentPatch/Common_ddraw.cpp b/SilentPatch/Common_ddraw.cpp index 59c1e82..574edb6 100644 --- a/SilentPatch/Common_ddraw.cpp +++ b/SilentPatch/Common_ddraw.cpp @@ -1,5 +1,13 @@ #include "Common_ddraw.h" +#define WIN32_LEAN_AND_MEAN + +#define WINVER 0x0501 +#define _WIN32_WINNT 0x0501 +#define NOMINMAX + +#include + #include #include #include "Utils/MemoryMgr.h" @@ -52,16 +60,19 @@ namespace Common { } // ================= III ================= - void DDraw_III_10( const RECT& desktop, const char* desktopText ) + void DDraw_III_10( uint32_t width, uint32_t height, const char* desktopText ) { using namespace Memory; InjectHook(0x580BB0, GetMyDocumentsPath, PATCH_JUMP); - Patch(0x581E5E, desktop.right); - Patch(0x581E68, desktop.bottom); + if (width != 0 && height != 0) + { + Patch(0x581E5E, width); + Patch(0x581E68, height); + Patch(0x581EA8, desktopText); + } Patch(0x581E72, 32); - Patch(0x581EA8, desktopText); // No 12mb vram check Patch(0x581411, 0xEB); @@ -71,16 +82,19 @@ namespace Common { Patch(0x5812D7, 0x900); } - void DDraw_III_11( const RECT& desktop, const char* desktopText ) + void DDraw_III_11( uint32_t width, uint32_t height, const char* desktopText ) { using namespace Memory; InjectHook(0x580F00, GetMyDocumentsPath, PATCH_JUMP); - Patch(0x58219E, desktop.right); - Patch(0x5821A8, desktop.bottom); + if (width != 0 && height != 0) + { + Patch(0x58219E, width); + Patch(0x5821A8, height); + Patch(0x5821E8, desktopText); + } Patch(0x5821B2, 32); - Patch(0x5821E8, desktopText); // No 12mb vram check Patch(0x581753, 0xEB); @@ -90,16 +104,19 @@ namespace Common { Patch(0x581621, 0x900); } - void DDraw_III_Steam( const RECT& desktop, const char* desktopText ) + void DDraw_III_Steam( uint32_t width, uint32_t height, const char* desktopText ) { using namespace Memory; InjectHook(0x580E00, GetMyDocumentsPath, PATCH_JUMP); - Patch(0x58208E, desktop.right); - Patch(0x582098, desktop.bottom); + if (width != 0 && height != 0) + { + Patch(0x58208E, width); + Patch(0x582098, height); + Patch(0x5820D8, desktopText); + } Patch(0x5820A2, 32); - Patch(0x5820D8, desktopText); // No 12mb vram check Patch(0x581653, 0xEB); @@ -110,7 +127,7 @@ namespace Common { } // ================= VC ================= - void DDraw_VC_10( const RECT& desktop, const char* desktopText ) + void DDraw_VC_10( uint32_t width, uint32_t height, const char* desktopText ) { using namespace Memory; @@ -119,10 +136,13 @@ namespace Common { InjectHook(0x601A40, GetMyDocumentsPath, PATCH_CALL); InjectHook(0x601A45, 0x601B2F, PATCH_JUMP); - Patch(0x600E7E, desktop.right); - Patch(0x600E88, desktop.bottom); + if (width != 0 && height != 0) + { + Patch(0x600E7E, width); + Patch(0x600E88, height); + Patch(0x600EC8, desktopText); + } Patch(0x600E92, 32); - Patch(0x600EC8, desktopText); // No 12mb vram check Patch(0x601E26, 0xEB); @@ -132,7 +152,7 @@ namespace Common { Patch(0x601CA1, 0x900); } - void DDraw_VC_11( const RECT& desktop, const char* desktopText ) + void DDraw_VC_11( uint32_t width, uint32_t height, const char* desktopText ) { using namespace Memory; @@ -141,10 +161,13 @@ namespace Common { InjectHook(0x601A70, GetMyDocumentsPath, PATCH_CALL); InjectHook(0x601A75, 0x601B5F, PATCH_JUMP); - Patch(0x600E9E, desktop.right); - Patch(0x600EA8, desktop.bottom); + if (width != 0 && height != 0) + { + Patch(0x600E9E, width); + Patch(0x600EA8, height); + Patch(0x600EE8, desktopText); + } Patch(0x600EB2, 32); - Patch(0x600EE8, desktopText); // No 12mb vram check Patch(0x601E56, 0xEB); @@ -155,7 +178,7 @@ namespace Common { } - void DDraw_VC_Steam( const RECT& desktop, const char* desktopText ) + void DDraw_VC_Steam( uint32_t width, uint32_t height, const char* desktopText ) { using namespace Memory; @@ -164,10 +187,13 @@ namespace Common { InjectHook(0x6016B0, GetMyDocumentsPath, PATCH_CALL); InjectHook(0x6016B5, 0x60179F, PATCH_JUMP); - Patch(0x600ADE, desktop.right); - Patch(0x600AE8, desktop.bottom); + if (width != 0 && height != 0) + { + Patch(0x600ADE, width); + Patch(0x600AE8, height); + Patch(0x600B28, desktopText); + } Patch(0x600AF2, 32); - Patch(0x600B28, desktopText); // No 12mb vram check Patch(0x601A96, 0xEB); diff --git a/SilentPatch/Common_ddraw.h b/SilentPatch/Common_ddraw.h index f3964e3..577df68 100644 --- a/SilentPatch/Common_ddraw.h +++ b/SilentPatch/Common_ddraw.h @@ -1,12 +1,6 @@ #pragma once -#define WIN32_LEAN_AND_MEAN - -#define WINVER 0x0501 -#define _WIN32_WINNT 0x0501 -#define NOMINMAX - -#include +#include namespace Common { @@ -14,13 +8,13 @@ namespace Common { 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_III_10( uint32_t width, uint32_t height, const char* desktopText ); + void DDraw_III_11( uint32_t width, uint32_t height, const char* desktopText ); + void DDraw_III_Steam( uint32_t width, uint32_t height, 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 ); + void DDraw_VC_10( uint32_t width, uint32_t height, const char* desktopText ); + void DDraw_VC_11( uint32_t width, uint32_t height, const char* desktopText ); + void DDraw_VC_Steam( uint32_t width, uint32_t height, const char* desktopText ); void DDraw_Common(); } diff --git a/SilentPatch/Desktop.cpp b/SilentPatch/Desktop.cpp new file mode 100644 index 0000000..d4a69c0 --- /dev/null +++ b/SilentPatch/Desktop.cpp @@ -0,0 +1,24 @@ +#include "Desktop.h" + +#define WIN32_LEAN_AND_MEAN + +#define WINVER 0x0501 +#define _WIN32_WINNT 0x0501 +#define NOMINMAX + +#include + +std::pair GetDesktopResolution() +{ + std::pair result {}; + + DEVMODEW displaySettings; + displaySettings.dmSize = sizeof(displaySettings); + displaySettings.dmDriverExtra = 0; + if (EnumDisplaySettingsW(nullptr, ENUM_CURRENT_SETTINGS, &displaySettings) != FALSE) + { + result.first = displaySettings.dmPelsWidth; + result.second = displaySettings.dmPelsHeight; + } + return result; +} \ No newline at end of file diff --git a/SilentPatch/Desktop.h b/SilentPatch/Desktop.h new file mode 100644 index 0000000..c348612 --- /dev/null +++ b/SilentPatch/Desktop.h @@ -0,0 +1,6 @@ +#pragma once + +#include +#include + +std::pair GetDesktopResolution(); \ No newline at end of file diff --git a/SilentPatchIII/SilentPatchIII.cpp b/SilentPatchIII/SilentPatchIII.cpp index afa29cc..c11b97d 100644 --- a/SilentPatchIII/SilentPatchIII.cpp +++ b/SilentPatchIII/SilentPatchIII.cpp @@ -5,6 +5,7 @@ #include "Utils/Patterns.h" #include "Common.h" #include "Common_ddraw.h" +#include "Desktop.h" #include "VehicleIII.h" #include "ModelInfoIII.h" @@ -661,7 +662,7 @@ void InjectDelayedPatches_III_Common() } -void Patch_III_10(const RECT& desktop) +void Patch_III_10(uint32_t width, uint32_t height) { using namespace Memory; @@ -796,10 +797,10 @@ void Patch_III_10(const RECT& desktop) } #endif - Common::Patches::DDraw_III_10( desktop, aNoDesktopMode ); + Common::Patches::DDraw_III_10( width, height, aNoDesktopMode ); } -void Patch_III_11(const RECT& desktop) +void Patch_III_11(uint32_t width, uint32_t height) { using namespace Memory; @@ -914,10 +915,10 @@ 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 ); + Common::Patches::DDraw_III_11( width, height, aNoDesktopMode ); } -void Patch_III_Steam(const RECT& desktop) +void Patch_III_Steam(uint32_t width, uint32_t height) { using namespace Memory; @@ -1019,7 +1020,7 @@ 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 ); + Common::Patches::DDraw_III_Steam( width, height, aNoDesktopMode ); } void Patch_III_Common() @@ -1252,18 +1253,17 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) { hDLLModule = hinstDLL; - RECT desktop; - GetWindowRect(GetDesktopWindow(), &desktop); - sprintf_s(aNoDesktopMode, "Cannot find %dx%dx32 video mode", desktop.right, desktop.bottom); + const auto [width, height] = GetDesktopResolution(); + sprintf_s(aNoDesktopMode, "Cannot find %ux%ux32 video mode", width, height); // This scope is mandatory so Protect goes out of scope before rwcseg gets fixed { std::unique_ptr Protect = ScopedUnprotect::UnprotectSectionOrFullModule( GetModuleHandle( nullptr ), ".text" ); const int8_t version = Memory::GetVersion().version; - if ( version == 0 ) Patch_III_10(desktop); - else if ( version == 1 ) Patch_III_11(desktop); - else if ( version == 2 ) Patch_III_Steam(desktop); + if ( version == 0 ) Patch_III_10(width, height); + else if ( version == 1 ) Patch_III_11(width, height); + else if ( version == 2 ) Patch_III_Steam(width, height); Patch_III_Common(); Common::Patches::III_VC_Common(); diff --git a/SilentPatchIII/SilentPatchIII.vcxproj b/SilentPatchIII/SilentPatchIII.vcxproj index e7ac105..9afd957 100644 --- a/SilentPatchIII/SilentPatchIII.vcxproj +++ b/SilentPatchIII/SilentPatchIII.vcxproj @@ -25,6 +25,11 @@ NotUsing NotUsing + + NotUsing + NotUsing + NotUsing + NotUsing NotUsing @@ -54,6 +59,7 @@ + diff --git a/SilentPatchIII/SilentPatchIII.vcxproj.filters b/SilentPatchIII/SilentPatchIII.vcxproj.filters index 6170b0e..e1e24ef 100644 --- a/SilentPatchIII/SilentPatchIII.vcxproj.filters +++ b/SilentPatchIII/SilentPatchIII.vcxproj.filters @@ -51,6 +51,9 @@ Source Files + + Source Files + @@ -95,6 +98,9 @@ Header Files + + Header Files + diff --git a/SilentPatchSA/SilentPatchSA.cpp b/SilentPatchSA/SilentPatchSA.cpp index d234cf0..a715d74 100644 --- a/SilentPatchSA/SilentPatchSA.cpp +++ b/SilentPatchSA/SilentPatchSA.cpp @@ -25,6 +25,8 @@ #include "Utils/DelimStringReader.h" #include "Utils/ModuleList.hpp" +#include "Desktop.h" + #include "debugmenu_public.h" #include "resource.h" @@ -3759,13 +3761,15 @@ void Patch_SA_10() Nop( 0x735881 + 11, 3 ); // Default resolution to native resolution - RECT desktop; - GetWindowRect(GetDesktopWindow(), &desktop); - sprintf_s(aNoDesktopMode, "Cannot find %dx%dx32 video mode", desktop.right, desktop.bottom); + const auto [width, height] = GetDesktopResolution(); + sprintf_s(aNoDesktopMode, "Cannot find %ux%ux32 video mode", width, height); - Patch(0x746363, desktop.right); - Patch(0x746368, desktop.bottom); - Patch(0x7463C8, aNoDesktopMode); + if (width != 0 && height != 0) + { + Patch(0x746363, width); + Patch(0x746368, height); + Patch(0x7463C8, aNoDesktopMode); + } // Corrected Map screen 1px issue Patch(0x575DE7, -0.5f); @@ -4516,13 +4520,15 @@ void Patch_SA_11() Nop( 0x7360B1 + 11, 3 ); // Default resolution to native resolution - RECT desktop; - GetWindowRect(GetDesktopWindow(), &desktop); - sprintf_s(aNoDesktopMode, "Cannot find %dx%dx32 video mode", desktop.right, desktop.bottom); + const auto [width, height] = GetDesktopResolution(); + sprintf_s(aNoDesktopMode, "Cannot find %ux%ux32 video mode", width, height); - Patch(0x746BE3, desktop.right); - Patch(0x746BE8, desktop.bottom); - Patch(0x746C48, aNoDesktopMode); + if (width != 0 && height != 0) + { + Patch(0x746BE3, width); + Patch(0x746BE8, height); + Patch(0x746C48, aNoDesktopMode); + } // Corrected Map screen 1px issue Patch(0x576357, -0.5f); @@ -4825,13 +4831,15 @@ void Patch_SA_Steam() Nop( 0x768046 + 16, 1 ); // Default resolution to native resolution - RECT desktop; - GetWindowRect(GetDesktopWindow(), &desktop); - sprintf_s(aNoDesktopMode, "Cannot find %dx%dx32 video mode", desktop.right, desktop.bottom); + const auto [width, height] = GetDesktopResolution(); + sprintf_s(aNoDesktopMode, "Cannot find %ux%ux32 video mode", width, height); - Patch(0x780219, desktop.right); - Patch(0x78021E, desktop.bottom); - Patch(0x78027E, aNoDesktopMode); + if (width != 0 && height != 0) + { + Patch(0x780219, width); + Patch(0x78021E, height); + Patch(0x78027E, aNoDesktopMode); + } // Corrected Map screen 1px issue /*Patch(0x575DE7, -5.0f); diff --git a/SilentPatchSA/SilentPatchSA.vcxproj b/SilentPatchSA/SilentPatchSA.vcxproj index 75cb31b..ac4b608 100644 --- a/SilentPatchSA/SilentPatchSA.vcxproj +++ b/SilentPatchSA/SilentPatchSA.vcxproj @@ -95,8 +95,11 @@ copy /y "$(TargetPath)" "D:\gry\GTA San Andreas clean\SilentPatchSA.asi" +copy /y "$(TargetPath)" "D:\gry\GTA San Andreas clean\scripts\gta-sa_newsteam_r1\SilentPatchSA.asi" copy /y "$(TargetPath)" "D:\gry\GTA San Andreas clean\scripts\gta-sa_newsteam_r2\SilentPatchSA.asi" -copy /y "$(TargetPath)" "D:\gry\GTA San Andreas clean\scripts\newsteam_r2_lowviolence_gta-sa\SilentPatchSA.asi" +copy /y "$(TargetPath)" "D:\gry\GTA San Andreas clean\scripts\newsteam_r2_lowviolence_gta-sa\SilentPatchSA.asi" +copy /y "$(TargetPath)" "D:\gry\San Andreas Multiplayer\SilentPatchSA.asi" +copy /y "$(TargetPath)" "H:\Rockstar Games\Grand Theft Auto San Andreas\SilentPatchSA.asi" 2.0 @@ -135,8 +138,11 @@ copy /y "$(TargetPath)" "D:\gry\GTA San Andreas clean\scripts\newsteam_r2_lowvio copy /y "$(TargetPath)" "D:\gry\GTA San Andreas clean\SilentPatchSA.asi" +copy /y "$(TargetPath)" "D:\gry\GTA San Andreas clean\scripts\gta-sa_newsteam_r1\SilentPatchSA.asi" copy /y "$(TargetPath)" "D:\gry\GTA San Andreas clean\scripts\gta-sa_newsteam_r2\SilentPatchSA.asi" -copy /y "$(TargetPath)" "D:\gry\GTA San Andreas clean\scripts\newsteam_r2_lowviolence_gta-sa\SilentPatchSA.asi" +copy /y "$(TargetPath)" "D:\gry\GTA San Andreas clean\scripts\newsteam_r2_lowviolence_gta-sa\SilentPatchSA.asi" +copy /y "$(TargetPath)" "D:\gry\San Andreas Multiplayer\SilentPatchSA.asi" +copy /y "$(TargetPath)" "H:\Rockstar Games\Grand Theft Auto San Andreas\SilentPatchSA.asi" 2.0 @@ -175,8 +181,11 @@ copy /y "$(TargetPath)" "D:\gry\GTA San Andreas clean\scripts\newsteam_r2_lowvio copy /y "$(TargetPath)" "D:\gry\GTA San Andreas clean\SilentPatchSA.asi" +copy /y "$(TargetPath)" "D:\gry\GTA San Andreas clean\scripts\gta-sa_newsteam_r1\SilentPatchSA.asi" copy /y "$(TargetPath)" "D:\gry\GTA San Andreas clean\scripts\gta-sa_newsteam_r2\SilentPatchSA.asi" -copy /y "$(TargetPath)" "D:\gry\GTA San Andreas clean\scripts\newsteam_r2_lowviolence_gta-sa\SilentPatchSA.asi" +copy /y "$(TargetPath)" "D:\gry\GTA San Andreas clean\scripts\newsteam_r2_lowviolence_gta-sa\SilentPatchSA.asi" +copy /y "$(TargetPath)" "D:\gry\San Andreas Multiplayer\SilentPatchSA.asi" +copy /y "$(TargetPath)" "H:\Rockstar Games\Grand Theft Auto San Andreas\SilentPatchSA.asi" 2.0 @@ -186,6 +195,11 @@ copy /y "$(TargetPath)" "D:\gry\GTA San Andreas clean\scripts\newsteam_r2_lowvio + + NotUsing + NotUsing + NotUsing + NotUsing NotUsing @@ -223,6 +237,7 @@ copy /y "$(TargetPath)" "D:\gry\GTA San Andreas clean\scripts\newsteam_r2_lowvio + diff --git a/SilentPatchSA/SilentPatchSA.vcxproj.filters b/SilentPatchSA/SilentPatchSA.vcxproj.filters index 28d3f3f..33fcfce 100644 --- a/SilentPatchSA/SilentPatchSA.vcxproj.filters +++ b/SilentPatchSA/SilentPatchSA.vcxproj.filters @@ -81,6 +81,9 @@ Source Files + + Source Files + @@ -179,6 +182,9 @@ Header Files + + Header Files + diff --git a/SilentPatchVC/SilentPatchVC.cpp b/SilentPatchVC/SilentPatchVC.cpp index 86ff866..8b7860f 100644 --- a/SilentPatchVC/SilentPatchVC.cpp +++ b/SilentPatchVC/SilentPatchVC.cpp @@ -5,6 +5,7 @@ #include "Utils/Patterns.h" #include "Common.h" #include "Common_ddraw.h" +#include "Desktop.h" #include "ModelInfoVC.h" #include "VehicleVC.h" #include "SVF.h" @@ -610,7 +611,7 @@ void InjectDelayedPatches_VC_Common() Common::Patches::III_VC_DelayedCommon( hasDebugMenu, wcModulePath ); } -void Patch_VC_10(const RECT& desktop) +void Patch_VC_10(uint32_t width, uint32_t height) { using namespace Memory; @@ -714,10 +715,10 @@ void Patch_VC_10(const RECT& desktop) } #endif - Common::Patches::DDraw_VC_10( desktop, aNoDesktopMode ); + Common::Patches::DDraw_VC_10( width, height, aNoDesktopMode ); } -void Patch_VC_11(const RECT& desktop) +void Patch_VC_11(uint32_t width, uint32_t height) { using namespace Memory; @@ -811,10 +812,10 @@ 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 ); + Common::Patches::DDraw_VC_11( width, height, aNoDesktopMode ); } -void Patch_VC_Steam(const RECT& desktop) +void Patch_VC_Steam(uint32_t width, uint32_t height) { using namespace Memory; @@ -907,7 +908,7 @@ 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 ); + Common::Patches::DDraw_VC_Steam( width, height, aNoDesktopMode ); } void Patch_VC_JP() @@ -1154,18 +1155,17 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) { hDLLModule = hinstDLL; - RECT desktop; - GetWindowRect(GetDesktopWindow(), &desktop); - sprintf_s(aNoDesktopMode, "Cannot find %dx%dx32 video mode", desktop.right, desktop.bottom); + const auto [width, height] = GetDesktopResolution(); + sprintf_s(aNoDesktopMode, "Cannot find %ux%ux32 video mode", width, height); // This scope is mandatory so Protect goes out of scope before rwcseg gets fixed { std::unique_ptr Protect = ScopedUnprotect::UnprotectSectionOrFullModule( GetModuleHandle( nullptr ), ".text" ); const int8_t version = Memory::GetVersion().version; - if ( version == 0 ) Patch_VC_10(desktop); - else if ( version == 1 ) Patch_VC_11(desktop); - else if ( version == 2 ) Patch_VC_Steam(desktop); + if ( version == 0 ) Patch_VC_10(width, height); + else if ( version == 1 ) Patch_VC_11(width, height); + else if ( version == 2 ) Patch_VC_Steam(width, height); // Y axis sensitivity only else if (*(DWORD*)0x601048 == 0x5E5F5D60) Patch_VC_JP(); diff --git a/SilentPatchVC/SilentPatchVC.vcxproj b/SilentPatchVC/SilentPatchVC.vcxproj index f15d9c3..c2f0fc5 100644 --- a/SilentPatchVC/SilentPatchVC.vcxproj +++ b/SilentPatchVC/SilentPatchVC.vcxproj @@ -173,6 +173,7 @@ + @@ -196,6 +197,11 @@ NotUsing NotUsing + + NotUsing + NotUsing + NotUsing + NotUsing NotUsing diff --git a/SilentPatchVC/SilentPatchVC.vcxproj.filters b/SilentPatchVC/SilentPatchVC.vcxproj.filters index e61b197..20e683e 100644 --- a/SilentPatchVC/SilentPatchVC.vcxproj.filters +++ b/SilentPatchVC/SilentPatchVC.vcxproj.filters @@ -60,6 +60,9 @@ Header Files + + Header Files + @@ -95,6 +98,9 @@ Source Files + + Source Files +