diff --git a/DDraw/dllmain.cpp b/DDraw/dllmain.cpp index 236b1fd..fd2d034 100644 --- a/DDraw/dllmain.cpp +++ b/DDraw/dllmain.cpp @@ -170,21 +170,23 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) using namespace MemoryVP; DisableThreadLibraryCalls(hinstDLL); - // TODO: Offset by a byte, or 5 - if (*(DWORD*)0x5C1E70 == 0x53E58955) + if (*(DWORD*)0x5C1E75 == 0xB85548EC) { // III 1.0 - + ppUserFilesDir = (char**)0x580C16; + InjectHook(0x580BB0, GetMyDocumentsPath, PATCH_JUMP); } - else if (*(DWORD*)0x5C2130 == 0x53E58955) + else if (*(DWORD*)0x5C2135 == 0xB85548EC) { // III 1.1 - + ppUserFilesDir = (char**)0x580F66; + InjectHook(0x580F00, GetMyDocumentsPath, PATCH_JUMP); } - else if (*(DWORD*)0x5C6FD0 == 0x53E58955) + else if (*(DWORD*)0x5C6FD5 == 0xB85548EC) { // III Steam - + ppUserFilesDir = (char**)0x580E66; + InjectHook(0x580E00, GetMyDocumentsPath, PATCH_JUMP); } else if (*(DWORD*)0x667BF5 == 0xB85548EC) diff --git a/SilentPatch/StdAfx.h b/SilentPatch/StdAfx.h index b5cd033..44e1f69 100644 --- a/SilentPatch/StdAfx.h +++ b/SilentPatch/StdAfx.h @@ -15,6 +15,8 @@ #include #include #include +#include +#include #include "MemoryMgr.h" diff --git a/SilentPatchIII/SilentPatchIII.cpp b/SilentPatchIII/SilentPatchIII.cpp index bd866cd..d2c8aa4 100644 --- a/SilentPatchIII/SilentPatchIII.cpp +++ b/SilentPatchIII/SilentPatchIII.cpp @@ -219,6 +219,21 @@ void __declspec(naked) SubtitlesShadowFix() } } +char** const ppUserFilesDir = AddressByVersion(0x580C16, 0x580F66, 0x580E66); + +char* GetMyDocumentsPath() +{ + static char cUserFilesPath[MAX_PATH]; + + if ( cUserFilesPath[0] == '\0' ) + { + SHGetFolderPath(nullptr, CSIDL_MYDOCUMENTS, nullptr, SHGFP_TYPE_CURRENT, cUserFilesPath); + PathAppend(cUserFilesPath, *ppUserFilesDir); + CreateDirectory(cUserFilesPath, nullptr); + } + return cUserFilesPath; +} + static char aNoDesktopMode[64]; void Patch_III_10(const RECT& desktop) @@ -347,6 +362,9 @@ void Patch_III_10(const RECT& desktop) // No DirectPlay dependency Patch(0x5812D6, 0xB8); Patch(0x5812D7, 0x900); + + // SHGetFolderPath on User Files + InjectHook(0x580BB0, GetMyDocumentsPath, PATCH_JUMP); } void Patch_III_11(const RECT& desktop) @@ -469,6 +487,9 @@ void Patch_III_11(const RECT& desktop) // No DirectPlay dependency Patch(0x581620, 0xB8); Patch(0x581621, 0x900); + + // SHGetFolderPath on User Files + InjectHook(0x580E00, GetMyDocumentsPath, PATCH_JUMP); } void Patch_III_Steam(const RECT& desktop) @@ -587,6 +608,9 @@ void Patch_III_Steam(const RECT& desktop) // No DirectPlay dependency Patch(0x581520, 0xB8); Patch(0x581521, 0x900); + + // SHGetFolderPath on User Files + InjectHook(0x580E00, GetMyDocumentsPath, PATCH_JUMP); } BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) @@ -600,9 +624,9 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) GetWindowRect(GetDesktopWindow(), &desktop); sprintf(aNoDesktopMode, "Cannot find %dx%dx32 video mode", desktop.right, desktop.bottom); - if (*(DWORD*)0x5C1E70 == 0x53E58955) Patch_III_10(desktop); - else if (*(DWORD*)0x5C2130 == 0x53E58955) Patch_III_11(desktop); - else if (*(DWORD*)0x5C6FD0 == 0x53E58955) Patch_III_Steam(desktop); + 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 FALSE; CTimer::Initialise(); diff --git a/SilentPatchIII/SilentPatchIII.vcxproj b/SilentPatchIII/SilentPatchIII.vcxproj index 1716fc9..f360b3b 100644 --- a/SilentPatchIII/SilentPatchIII.vcxproj +++ b/SilentPatchIII/SilentPatchIII.vcxproj @@ -75,12 +75,11 @@ true - false Windows 5.0 - Winmm.lib;%(AdditionalDependencies) + Winmm.lib;Shlwapi.lib;%(AdditionalDependencies) copy /y "$(TargetPath)" "D:\gry\Steam\steamapps\common\Grand Theft Auto 3\SilentPatchIII.asi" @@ -106,12 +105,11 @@ false true true - false Windows 5.0 - Winmm.lib;%(AdditionalDependencies) + Winmm.lib;Shlwapi.lib;%(AdditionalDependencies) copy /y "$(TargetPath)" "D:\gry\Steam\steamapps\common\Grand Theft Auto 3\SilentPatchIII.asi" diff --git a/SilentPatchVC/SilentPatchVC.cpp b/SilentPatchVC/SilentPatchVC.cpp index becdb79..8b60412 100644 --- a/SilentPatchVC/SilentPatchVC.cpp +++ b/SilentPatchVC/SilentPatchVC.cpp @@ -106,6 +106,21 @@ void __declspec(naked) SubtitlesShadowFix() } } +char** const ppUserFilesDir = AddressByVersion(0x6022AA, 0x60228A, 0x601ECA); + +char* GetMyDocumentsPath() +{ + static char cUserFilesPath[MAX_PATH]; + + if ( cUserFilesPath[0] == '\0' ) + { + SHGetFolderPath(nullptr, CSIDL_MYDOCUMENTS, nullptr, SHGFP_TYPE_CURRENT, cUserFilesPath); + PathAppend(cUserFilesPath, *ppUserFilesDir); + CreateDirectory(cUserFilesPath, nullptr); + } + return cUserFilesPath; +} + static char aNoDesktopMode[64]; void Patch_VC_10(const RECT& desktop) @@ -180,6 +195,12 @@ void Patch_VC_10(const RECT& desktop) // 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); } void Patch_VC_11(const RECT& desktop) @@ -254,6 +275,12 @@ void Patch_VC_11(const RECT& desktop) // 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); } void Patch_VC_Steam(const RECT& desktop) @@ -328,6 +355,12 @@ void Patch_VC_Steam(const RECT& desktop) // 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); } BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) @@ -341,9 +374,9 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) GetWindowRect(GetDesktopWindow(), &desktop); sprintf(aNoDesktopMode, "Cannot find %dx%dx32 video mode", desktop.right, desktop.bottom); - if(*(DWORD*)0x667BF0 == 0x53E58955) Patch_VC_10(desktop); - else if(*(DWORD*)0x667C40 == 0x53E58955) Patch_VC_11(desktop); - else if (*(DWORD*)0x666BA0 == 0x53E58955) 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); else return FALSE; CTimer::Initialise(); diff --git a/SilentPatchVC/SilentPatchVC.vcxproj b/SilentPatchVC/SilentPatchVC.vcxproj index 9c9a9b2..2b15048 100644 --- a/SilentPatchVC/SilentPatchVC.vcxproj +++ b/SilentPatchVC/SilentPatchVC.vcxproj @@ -60,7 +60,7 @@ true Windows 5.0 - Winmm.lib;%(AdditionalDependencies) + Winmm.lib;Shlwapi.lib;%(AdditionalDependencies) copy /y "$(TargetPath)" "D:\gry\Steam\steamapps\common\Grand Theft Auto Vice City\SilentPatchVC.asi" @@ -88,7 +88,7 @@ true Windows 5.0 - Winmm.lib;%(AdditionalDependencies) + Winmm.lib;Shlwapi.lib;%(AdditionalDependencies) copy /y "$(TargetPath)" "D:\gry\Steam\steamapps\common\Grand Theft Auto Vice City\SilentPatchVC.asi"