Unified code between ddraw and ASIs

This commit is contained in:
Silent 2017-09-18 22:13:02 +02:00
parent 01dfbda6fd
commit bf8f58970d
13 changed files with 295 additions and 282 deletions

View file

@ -150,6 +150,7 @@ copy /y "$(TargetPath)" "D:\Steam\steamapps\common\Grand Theft Auto Vice City\dd
</PostBuildEvent> </PostBuildEvent>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="..\SilentPatch\Common.cpp" />
<ClCompile Include="..\SilentPatch\Patterns.cpp" /> <ClCompile Include="..\SilentPatch\Patterns.cpp" />
<ClCompile Include="dllmain.cpp" /> <ClCompile Include="dllmain.cpp" />
</ItemGroup> </ItemGroup>
@ -157,6 +158,7 @@ copy /y "$(TargetPath)" "D:\Steam\steamapps\common\Grand Theft Auto Vice City\dd
<ResourceCompile Include="..\SilentPatch\SilentPatch.rc" /> <ResourceCompile Include="..\SilentPatch\SilentPatch.rc" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="..\SilentPatch\Common.h" />
<ClInclude Include="..\SilentPatch\MemoryMgr.h" /> <ClInclude Include="..\SilentPatch\MemoryMgr.h" />
<ClInclude Include="..\SilentPatch\Patterns.h" /> <ClInclude Include="..\SilentPatch\Patterns.h" />
</ItemGroup> </ItemGroup>

View file

@ -21,6 +21,9 @@
<ClCompile Include="..\SilentPatch\Patterns.cpp"> <ClCompile Include="..\SilentPatch\Patterns.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\SilentPatch\Common.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="..\SilentPatch\MemoryMgr.h"> <ClInclude Include="..\SilentPatch\MemoryMgr.h">
@ -29,6 +32,9 @@
<ClInclude Include="..\SilentPatch\Patterns.h"> <ClInclude Include="..\SilentPatch\Patterns.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\SilentPatch\Common.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ResourceCompile Include="..\SilentPatch\SilentPatch.rc"> <ResourceCompile Include="..\SilentPatch\SilentPatch.rc">

View file

@ -9,6 +9,8 @@
#include "MemoryMgr.h" #include "MemoryMgr.h"
#include "Patterns.h" #include "Patterns.h"
#include "Common.h"
#pragma comment(lib, "shlwapi.lib") #pragma comment(lib, "shlwapi.lib")
extern "C" HRESULT WINAPI DirectDrawCreateEx(GUID FAR *lpGUID, LPVOID *lplpDD, REFIID iid, IUnknown FAR *pUnkOuter) extern "C" HRESULT WINAPI DirectDrawCreateEx(GUID FAR *lpGUID, LPVOID *lplpDD, REFIID iid, IUnknown FAR *pUnkOuter)
@ -57,124 +59,41 @@ void InjectHooks()
{ {
// III 1.0 // III 1.0
ppUserFilesDir = (char**)0x580C16; ppUserFilesDir = (char**)0x580C16;
InjectHook(0x580BB0, GetMyDocumentsPath, PATCH_JUMP); Common::Patches::DDraw_III_10( desktop, aNoDesktopMode );
Patch<DWORD>(0x581E5E, desktop.right);
Patch<DWORD>(0x581E68, desktop.bottom);
Patch<BYTE>(0x581E72, 32);
Patch<const char*>(0x581EA8, aNoDesktopMode);
// No 12mb vram check
Patch<BYTE>(0x581411, 0xEB);
// No DirectPlay dependency
Patch<BYTE>(0x5812D6, 0xB8);
Patch<DWORD>(0x5812D7, 0x900);
} }
else if (*(DWORD*)0x5C2135 == 0xB85548EC) else if (*(DWORD*)0x5C2135 == 0xB85548EC)
{ {
// III 1.1 // III 1.1
ppUserFilesDir = (char**)0x580F66; ppUserFilesDir = (char**)0x580F66;
InjectHook(0x580F00, GetMyDocumentsPath, PATCH_JUMP); Common::Patches::DDraw_III_11( desktop, aNoDesktopMode );
Patch<DWORD>(0x58219E, desktop.right);
Patch<DWORD>(0x5821A8, desktop.bottom);
Patch<BYTE>(0x5821B2, 32);
Patch<const char*>(0x5821E8, aNoDesktopMode);
// No 12mb vram check
Patch<BYTE>(0x581753, 0xEB);
// No DirectPlay dependency
Patch<BYTE>(0x581620, 0xB8);
Patch<DWORD>(0x581621, 0x900);
} }
else if (*(DWORD*)0x5C6FD5 == 0xB85548EC) else if (*(DWORD*)0x5C6FD5 == 0xB85548EC)
{ {
// III Steam // III Steam
ppUserFilesDir = (char**)0x580E66; ppUserFilesDir = (char**)0x580E66;
InjectHook(0x580E00, GetMyDocumentsPath, PATCH_JUMP); Common::Patches::DDraw_III_Steam( desktop, aNoDesktopMode );
Patch<DWORD>(0x58208E, desktop.right);
Patch<DWORD>(0x582098, desktop.bottom);
Patch<BYTE>(0x5820A2, 32);
Patch<const char*>(0x5820D8, aNoDesktopMode);
// No 12mb vram check
Patch<BYTE>(0x581653, 0xEB);
// No DirectPlay dependency
Patch<BYTE>(0x581520, 0xB8);
Patch<DWORD>(0x581521, 0x900);
} }
else if (*(DWORD*)0x667BF5 == 0xB85548EC) else if (*(DWORD*)0x667BF5 == 0xB85548EC)
{ {
// VC 1.0 // VC 1.0
ppUserFilesDir = (char**)0x6022AA; ppUserFilesDir = (char**)0x6022AA;
InjectHook(0x602240, GetMyDocumentsPath, PATCH_JUMP); Common::Patches::DDraw_VC_10( desktop, aNoDesktopMode );
InjectHook(0x601A40, GetMyDocumentsPath, PATCH_CALL);
InjectHook(0x601A45, 0x601B2F, PATCH_JUMP);
Patch<DWORD>(0x600E7E, desktop.right);
Patch<DWORD>(0x600E88, desktop.bottom);
Patch<BYTE>(0x600E92, 32);
Patch<const char*>(0x600EC8, aNoDesktopMode);
// No 12mb vram check
Patch<BYTE>(0x601E26, 0xEB);
// No DirectPlay dependency
Patch<BYTE>(0x601CA0, 0xB8);
Patch<DWORD>(0x601CA1, 0x900);
} }
else if (*(DWORD*)0x667C45 == 0xB85548EC) else if (*(DWORD*)0x667C45 == 0xB85548EC)
{ {
// VC 1.1 // VC 1.1
ppUserFilesDir = (char**)0x60228A; ppUserFilesDir = (char**)0x60228A;
InjectHook(0x602220, GetMyDocumentsPath, PATCH_JUMP); Common::Patches::DDraw_VC_11( desktop, aNoDesktopMode );
InjectHook(0x601A70, GetMyDocumentsPath, PATCH_CALL);
InjectHook(0x601A75, 0x601B5F, PATCH_JUMP);
Patch<DWORD>(0x600E9E, desktop.right);
Patch<DWORD>(0x600EA8, desktop.bottom);
Patch<BYTE>(0x600EB2, 32);
Patch<const char*>(0x600EE8, aNoDesktopMode);
// No 12mb vram check
Patch<BYTE>(0x601E56, 0xEB);
// No DirectPlay dependency
Patch<BYTE>(0x601CD0, 0xB8);
Patch<DWORD>(0x601CD1, 0x900);
} }
else if (*(DWORD*)0x666BA5 == 0xB85548EC) else if (*(DWORD*)0x666BA5 == 0xB85548EC)
{ {
// VC Steam // VC Steam
ppUserFilesDir = (char**)0x601ECA; ppUserFilesDir = (char**)0x601ECA;
InjectHook(0x601E60, GetMyDocumentsPath, PATCH_JUMP); Common::Patches::DDraw_VC_Steam( desktop, aNoDesktopMode );
InjectHook(0x6016B0, GetMyDocumentsPath, PATCH_CALL);
InjectHook(0x6016B5, 0x60179F, PATCH_JUMP);
Patch<DWORD>(0x600ADE, desktop.right);
Patch<DWORD>(0x600AE8, desktop.bottom);
Patch<BYTE>(0x600AF2, 32);
Patch<const char*>(0x600B28, aNoDesktopMode);
// No 12mb vram check
Patch<BYTE>(0x601A96, 0xEB);
// No DirectPlay dependency
Patch<BYTE>(0x601910, 0xB8);
Patch<DWORD>(0x601911, 0x900);
} }
} }
static bool FixRwcseg_Patterns();
static bool rwcsegUnprotected = false; static bool rwcsegUnprotected = false;
static void ProcHook() static void ProcHook()
@ -188,7 +107,7 @@ static void ProcHook()
if ( !rwcsegUnprotected ) if ( !rwcsegUnprotected )
{ {
rwcsegUnprotected = FixRwcseg_Patterns(); rwcsegUnprotected = Common::Patches::FixRwcseg_Patterns();
} }
} }
} }
@ -247,26 +166,6 @@ static bool FixRwcseg_Header()
return false; 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() static bool PatchIAT()
{ {
HINSTANCE hInstance = GetModuleHandle(nullptr); HINSTANCE hInstance = GetModuleHandle(nullptr);
@ -280,8 +179,8 @@ static bool PatchIAT()
{ {
if ( !_stricmp((const char*)((DWORD_PTR)hInstance + pImports->Name), "KERNEL32.DLL") ) if ( !_stricmp((const char*)((DWORD_PTR)hInstance + pImports->Name), "KERNEL32.DLL") )
{ {
if ( pImports->OriginalFirstThunk == 0 ) return false; if ( pImports->OriginalFirstThunk != 0 )
{
PIMAGE_IMPORT_BY_NAME* pFunctions = (PIMAGE_IMPORT_BY_NAME*)((DWORD_PTR)hInstance + pImports->OriginalFirstThunk); PIMAGE_IMPORT_BY_NAME* pFunctions = (PIMAGE_IMPORT_BY_NAME*)((DWORD_PTR)hInstance + pImports->OriginalFirstThunk);
// kernel32.dll found, find GetStartupInfoA // kernel32.dll found, find GetStartupInfoA
@ -303,6 +202,7 @@ static bool PatchIAT()
} }
} }
} }
}
return false; return false;
} }

175
SilentPatch/Common.cpp Normal file
View file

@ -0,0 +1,175 @@
#include "Common.h"
#include <Shlwapi.h>
#include <ShlObj.h>
#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<DWORD>(0x581E5E, desktop.right);
Patch<DWORD>(0x581E68, desktop.bottom);
Patch<BYTE>(0x581E72, 32);
Patch<const char*>(0x581EA8, desktopText);
// No 12mb vram check
Patch<BYTE>(0x581411, 0xEB);
// No DirectPlay dependency
Patch<BYTE>(0x5812D6, 0xB8);
Patch<DWORD>(0x5812D7, 0x900);
}
void DDraw_III_11( const RECT& desktop, const char* desktopText )
{
using namespace Memory;
InjectHook(0x580F00, GetMyDocumentsPath, PATCH_JUMP);
Patch<DWORD>(0x58219E, desktop.right);
Patch<DWORD>(0x5821A8, desktop.bottom);
Patch<BYTE>(0x5821B2, 32);
Patch<const char*>(0x5821E8, desktopText);
// No 12mb vram check
Patch<BYTE>(0x581753, 0xEB);
// No DirectPlay dependency
Patch<BYTE>(0x581620, 0xB8);
Patch<DWORD>(0x581621, 0x900);
}
void DDraw_III_Steam( const RECT& desktop, const char* desktopText )
{
using namespace Memory;
InjectHook(0x580E00, GetMyDocumentsPath, PATCH_JUMP);
Patch<DWORD>(0x58208E, desktop.right);
Patch<DWORD>(0x582098, desktop.bottom);
Patch<BYTE>(0x5820A2, 32);
Patch<const char*>(0x5820D8, desktopText);
// No 12mb vram check
Patch<BYTE>(0x581653, 0xEB);
// No DirectPlay dependency
Patch<BYTE>(0x581520, 0xB8);
Patch<DWORD>(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<DWORD>(0x600E7E, desktop.right);
Patch<DWORD>(0x600E88, desktop.bottom);
Patch<BYTE>(0x600E92, 32);
Patch<const char*>(0x600EC8, desktopText);
// No 12mb vram check
Patch<BYTE>(0x601E26, 0xEB);
// No DirectPlay dependency
Patch<BYTE>(0x601CA0, 0xB8);
Patch<DWORD>(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<DWORD>(0x600E9E, desktop.right);
Patch<DWORD>(0x600EA8, desktop.bottom);
Patch<BYTE>(0x600EB2, 32);
Patch<const char*>(0x600EE8, desktopText);
// No 12mb vram check
Patch<BYTE>(0x601E56, 0xEB);
// No DirectPlay dependency
Patch<BYTE>(0x601CD0, 0xB8);
Patch<DWORD>(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<DWORD>(0x600ADE, desktop.right);
Patch<DWORD>(0x600AE8, desktop.bottom);
Patch<BYTE>(0x600AF2, 32);
Patch<const char*>(0x600B28, desktopText);
// No 12mb vram check
Patch<BYTE>(0x601A96, 0xEB);
// No DirectPlay dependency
Patch<BYTE>(0x601910, 0xB8);
Patch<DWORD>(0x601911, 0x900);
}
}
}

25
SilentPatch/Common.h Normal file
View file

@ -0,0 +1,25 @@
#pragma once
#define WIN32_LEAN_AND_MEAN
#define WINVER 0x0501
#define _WIN32_WINNT 0x0501
#define NOMINMAX
#include <windows.h>
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 );
}
};

View file

@ -5,11 +5,8 @@
#define NOMINMAX #define NOMINMAX
#include <windows.h> #include <windows.h>
#include <mmsystem.h>
#include <cassert> #include <cassert>
#include <cstdio> #include <cstdio>
#include <ShlObj.h>
#include <Shlwapi.h>
#include "MemoryMgr.h" #include "MemoryMgr.h"

View file

@ -3,6 +3,7 @@
#include "General.h" #include "General.h"
#include "Timer.h" #include "Timer.h"
#include "Patterns.h" #include "Patterns.h"
#include "Common.h"
#include <memory> #include <memory>
@ -285,20 +286,7 @@ void __declspec(naked) RadarBoundsCheckEntityBlip()
} }
} }
char** const ppUserFilesDir = AddressByVersion<char**>(0x580C16, 0x580F66, 0x580E66); extern char** ppUserFilesDir = AddressByVersion<char**>(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;
}
static LARGE_INTEGER FrameTime; static LARGE_INTEGER FrameTime;
int32_t GetTimeSinceLastFrame() int32_t GetTimeSinceLastFrame()
@ -461,23 +449,6 @@ void Patch_III_10(const RECT& desktop)
InjectHook(0x582EFD, NewFrameRender); InjectHook(0x582EFD, NewFrameRender);
InjectHook(0x582EA4, GetTimeSinceLastFrame); InjectHook(0x582EA4, GetTimeSinceLastFrame);
// Default to desktop res
Patch<DWORD>(0x581E5E, desktop.right);
Patch<DWORD>(0x581E68, desktop.bottom);
Patch<BYTE>(0x581E72, 32);
Patch<const char*>(0x581EA8, aNoDesktopMode);
// No 12mb vram check
Patch<BYTE>(0x581411, 0xEB);
// No DirectPlay dependency
Patch<BYTE>(0x5812D6, 0xB8);
Patch<DWORD>(0x5812D7, 0x900);
// SHGetFolderPath on User Files
InjectHook(0x580BB0, GetMyDocumentsPath, PATCH_JUMP);
// Reinit CCarCtrl fields (firetruck and ambulance generation) // Reinit CCarCtrl fields (firetruck and ambulance generation)
ReadCall( 0x48C4FB, orgCarCtrlReInit ); ReadCall( 0x48C4FB, orgCarCtrlReInit );
InjectHook(0x48C4FB, CarCtrlReInit_SilentPatch); InjectHook(0x48C4FB, CarCtrlReInit_SilentPatch);
@ -518,6 +489,8 @@ void Patch_III_10(const RECT& desktop)
Patch<WORD>(0x58274D, 0x006A); Patch<WORD>(0x58274D, 0x006A);
} }
#endif #endif
Common::Patches::DDraw_III_10( desktop, aNoDesktopMode );
} }
void Patch_III_11(const RECT& desktop) void Patch_III_11(const RECT& desktop)
@ -611,22 +584,6 @@ void Patch_III_11(const RECT& desktop)
InjectHook(0x58323D, NewFrameRender); InjectHook(0x58323D, NewFrameRender);
InjectHook(0x5831E4, GetTimeSinceLastFrame); InjectHook(0x5831E4, GetTimeSinceLastFrame);
// Default to desktop res
Patch<DWORD>(0x58219E, desktop.right);
Patch<DWORD>(0x5821A8, desktop.bottom);
Patch<BYTE>(0x5821B2, 32);
Patch<const char*>(0x5821E8, aNoDesktopMode);
// No 12mb vram check
Patch<BYTE>(0x581753, 0xEB);
// No DirectPlay dependency
Patch<BYTE>(0x581620, 0xB8);
Patch<DWORD>(0x581621, 0x900);
// SHGetFolderPath on User Files
InjectHook(0x580F00, GetMyDocumentsPath, PATCH_JUMP);
// Reinit CCarCtrl fields (firetruck and ambulance generation) // Reinit CCarCtrl fields (firetruck and ambulance generation)
ReadCall( 0x48C5FB, orgCarCtrlReInit ); ReadCall( 0x48C5FB, orgCarCtrlReInit );
@ -658,6 +615,8 @@ void Patch_III_11(const RECT& desktop)
// Fixed crash related to autopilot timing calculations // Fixed crash related to autopilot timing calculations
InjectHook(0x4139B2, AutoPilotTimerFix_III, PATCH_JUMP); InjectHook(0x4139B2, AutoPilotTimerFix_III, PATCH_JUMP);
Common::Patches::DDraw_III_11( desktop, aNoDesktopMode );
} }
void Patch_III_Steam(const RECT& desktop) void Patch_III_Steam(const RECT& desktop)
@ -747,23 +706,6 @@ void Patch_III_Steam(const RECT& desktop)
InjectHook(0x58312D, NewFrameRender); InjectHook(0x58312D, NewFrameRender);
InjectHook(0x5830D4, GetTimeSinceLastFrame); InjectHook(0x5830D4, GetTimeSinceLastFrame);
// Default to desktop res
Patch<DWORD>(0x58208E, desktop.right);
Patch<DWORD>(0x582098, desktop.bottom);
Patch<BYTE>(0x5820A2, 32);
Patch<const char*>(0x5820D8, aNoDesktopMode);
// No 12mb vram check
Patch<BYTE>(0x581653, 0xEB);
// No DirectPlay dependency
Patch<BYTE>(0x581520, 0xB8);
Patch<DWORD>(0x581521, 0x900);
// SHGetFolderPath on User Files
InjectHook(0x580E00, GetMyDocumentsPath, PATCH_JUMP);
// Reinit CCarCtrl fields (firetruck and ambulance generation) // Reinit CCarCtrl fields (firetruck and ambulance generation)
ReadCall( 0x48C58B, orgCarCtrlReInit ); ReadCall( 0x48C58B, orgCarCtrlReInit );
InjectHook(0x48C58B, CarCtrlReInit_SilentPatch); InjectHook(0x48C58B, CarCtrlReInit_SilentPatch);
@ -786,6 +728,8 @@ void Patch_III_Steam(const RECT& desktop)
// Fixed crash related to autopilot timing calculations // Fixed crash related to autopilot timing calculations
InjectHook(0x4139B2, AutoPilotTimerFix_III, PATCH_JUMP); InjectHook(0x4139B2, AutoPilotTimerFix_III, PATCH_JUMP);
Common::Patches::DDraw_III_Steam( desktop, aNoDesktopMode );
} }
void Patch_III_Common() void Patch_III_Common()
@ -890,6 +834,8 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
GetWindowRect(GetDesktopWindow(), &desktop); GetWindowRect(GetDesktopWindow(), &desktop);
sprintf_s(aNoDesktopMode, "Cannot find %dx%dx32 video mode", desktop.right, desktop.bottom); sprintf_s(aNoDesktopMode, "Cannot find %dx%dx32 video mode", desktop.right, desktop.bottom);
// This scope is mandatory so Protect goes out of scope before rwcseg gets fixed
{
std::unique_ptr<ScopedUnprotect::Unprotect> Protect = ScopedUnprotect::UnprotectSectionOrFullModule( GetModuleHandle( nullptr ), ".text" ); std::unique_ptr<ScopedUnprotect::Unprotect> Protect = ScopedUnprotect::UnprotectSectionOrFullModule( GetModuleHandle( nullptr ), ".text" );
if (*(DWORD*)0x5C1E75 == 0xB85548EC) Patch_III_10(desktop); if (*(DWORD*)0x5C1E75 == 0xB85548EC) Patch_III_10(desktop);
@ -898,6 +844,9 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
else return TRUE; else return TRUE;
Patch_III_Common(); Patch_III_Common();
}
Common::Patches::FixRwcseg_Patterns();
HMODULE hDummyHandle; HMODULE hDummyHandle;
GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, (LPCWSTR)&DllMain, &hDummyHandle); GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, (LPCWSTR)&DllMain, &hDummyHandle);

View file

@ -15,6 +15,11 @@
</ProjectConfiguration> </ProjectConfiguration>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="..\SilentPatch\Common.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Master|Win32'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">NotUsing</PrecompiledHeader>
</ClCompile>
<ClCompile Include="..\SilentPatch\Patterns.cpp"> <ClCompile Include="..\SilentPatch\Patterns.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">NotUsing</PrecompiledHeader> <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">NotUsing</PrecompiledHeader> <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">NotUsing</PrecompiledHeader>

View file

@ -27,6 +27,9 @@
<ClCompile Include="..\SilentPatch\Patterns.cpp"> <ClCompile Include="..\SilentPatch\Patterns.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\SilentPatch\Common.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="..\SilentPatch\MemoryMgr.h"> <ClInclude Include="..\SilentPatch\MemoryMgr.h">

View file

@ -813,7 +813,7 @@ void DrawRect_HalfPixel_Steam(CRect& rect, const CRGBA& rgba)
((void(*)(const CRect&, const CRGBA&))0x75CDA0)(rect, rgba); ((void(*)(const CRect&, const CRGBA&))0x75CDA0)(rect, rgba);
} }
char* GetMyDocumentsPath() char* GetMyDocumentsPathSA()
{ {
static char cUserFilesPath[MAX_PATH]; static char cUserFilesPath[MAX_PATH];
static char* const ppTempBufPtr = *GetVer() == 0 ? *AddressByRegion_10<char**>(0x744FE5) : cUserFilesPath; static char* const ppTempBufPtr = *GetVer() == 0 ? *AddressByRegion_10<char**>(0x744FE5) : cUserFilesPath;
@ -3258,7 +3258,7 @@ void Patch_SA_10()
Patch<DWORD>(AddressByRegion_10<DWORD>(0x74754B), 0x900); Patch<DWORD>(AddressByRegion_10<DWORD>(0x74754B), 0x900);
// SHGetFolderPath on User Files // SHGetFolderPath on User Files
InjectHook(0x744FB0, GetMyDocumentsPath, PATCH_JUMP); InjectHook(0x744FB0, GetMyDocumentsPathSA, PATCH_JUMP);
// Fixed muzzleflash not showing from last bullet // Fixed muzzleflash not showing from last bullet
Nop(0x61ECE4, 2); Nop(0x61ECE4, 2);
@ -3748,7 +3748,7 @@ void Patch_SA_11()
Patch<DWORD>(AddressByRegion_11<DWORD>(0x747E1B), 0x900); Patch<DWORD>(AddressByRegion_11<DWORD>(0x747E1B), 0x900);
// SHGetFolderPath on User Files // SHGetFolderPath on User Files
InjectHook(0x7457E0, GetMyDocumentsPath, PATCH_JUMP); InjectHook(0x7457E0, GetMyDocumentsPathSA, PATCH_JUMP);
// Fixed muzzleflash not showing from last bullet // Fixed muzzleflash not showing from last bullet
Nop(0x61F504, 2); Nop(0x61F504, 2);
@ -4054,7 +4054,7 @@ void Patch_SA_Steam()
Patch<DWORD>(0x781457, 0x900); Patch<DWORD>(0x781457, 0x900);
// SHGetFolderPath on User Files // SHGetFolderPath on User Files
InjectHook(0x77EDC0, GetMyDocumentsPath, PATCH_JUMP); InjectHook(0x77EDC0, GetMyDocumentsPathSA, PATCH_JUMP);
// Fixed muzzleflash not showing from last bullet // Fixed muzzleflash not showing from last bullet
Nop(0x61F504, 2); Nop(0x61F504, 2);
@ -4374,7 +4374,7 @@ void Patch_SA_NewSteam_r2()
Patch<DWORD>(0x77B46F, 0x900); Patch<DWORD>(0x77B46F, 0x900);
// SHGetFolderPath on User Files // SHGetFolderPath on User Files
InjectHook(0x778FA0, GetMyDocumentsPath, PATCH_JUMP); InjectHook(0x778FA0, GetMyDocumentsPathSA, PATCH_JUMP);
// Fixed muzzleflash not showing from last bullet // Fixed muzzleflash not showing from last bullet
Nop(0x63E8A9, 2); Nop(0x63E8A9, 2);
@ -4561,7 +4561,7 @@ void Patch_SA_NewSteam_r2_lv()
Patch<DWORD>(0x77B35F, 0x900); Patch<DWORD>(0x77B35F, 0x900);
// SHGetFolderPath on User Files // SHGetFolderPath on User Files
InjectHook(0x778E90, GetMyDocumentsPath, PATCH_JUMP); InjectHook(0x778E90, GetMyDocumentsPathSA, PATCH_JUMP);
// Fixed muzzleflash not showing from last bullet // Fixed muzzleflash not showing from last bullet
Nop(0x63E789, 2); Nop(0x63E789, 2);

View file

@ -2,6 +2,7 @@
#include "Timer.h" #include "Timer.h"
#include "Patterns.h" #include "Patterns.h"
#include "Common.h"
#include <memory> #include <memory>
@ -143,20 +144,7 @@ void __declspec(naked) SubtitlesShadowFix()
} }
} }
char** const ppUserFilesDir = AddressByVersion<char**>(0x6022AA, 0x60228A, 0x601ECA); extern char** ppUserFilesDir = AddressByVersion<char**>(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;
}
static LARGE_INTEGER FrameTime; static LARGE_INTEGER FrameTime;
int32_t GetTimeSinceLastFrame() int32_t GetTimeSinceLastFrame()
@ -267,24 +255,6 @@ void Patch_VC_10(const RECT& desktop)
InjectHook(0x6004A2, NewFrameRender); InjectHook(0x6004A2, NewFrameRender);
InjectHook(0x600449, GetTimeSinceLastFrame); InjectHook(0x600449, GetTimeSinceLastFrame);
// Default to desktop res
Patch<DWORD>(0x600E7E, desktop.right);
Patch<DWORD>(0x600E88, desktop.bottom);
Patch<BYTE>(0x600E92, 32);
Patch<const char*>(0x600EC8, aNoDesktopMode);
// No 12mb vram check
Patch<BYTE>(0x601E26, 0xEB);
// No DirectPlay dependency
Patch<BYTE>(0x601CA0, 0xB8);
Patch<DWORD>(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) // RsMouseSetPos call (SA style fix)
InjectHook(0x4A5E45, ResetMousePos); InjectHook(0x4A5E45, ResetMousePos);
@ -351,6 +321,8 @@ void Patch_VC_10(const RECT& desktop)
Patch<WORD>(0x5FFAED, 0x006A); Patch<WORD>(0x5FFAED, 0x006A);
} }
#endif #endif
Common::Patches::DDraw_VC_10( desktop, aNoDesktopMode );
} }
void Patch_VC_11(const RECT& desktop) void Patch_VC_11(const RECT& desktop)
@ -397,25 +369,6 @@ void Patch_VC_11(const RECT& desktop)
InjectHook(0x6004C2, NewFrameRender); InjectHook(0x6004C2, NewFrameRender);
InjectHook(0x600469, GetTimeSinceLastFrame); InjectHook(0x600469, GetTimeSinceLastFrame);
// Default to desktop res
Patch<DWORD>(0x600E9E, desktop.right);
Patch<DWORD>(0x600EA8, desktop.bottom);
Patch<BYTE>(0x600EB2, 32);
Patch<const char*>(0x600EE8, aNoDesktopMode);
// No 12mb vram check
Patch<BYTE>(0x601E56, 0xEB);
// No DirectPlay dependency
Patch<BYTE>(0x601CD0, 0xB8);
Patch<DWORD>(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) // RsMouseSetPos call (SA style fix)
InjectHook(0x4A5E65, ResetMousePos); InjectHook(0x4A5E65, ResetMousePos);
@ -472,6 +425,8 @@ void Patch_VC_11(const RECT& desktop)
// Fixed crash related to autopilot timing calculations // Fixed crash related to autopilot timing calculations
InjectHook(0x418FAE, AutoPilotTimerFix_VC, PATCH_JUMP); InjectHook(0x418FAE, AutoPilotTimerFix_VC, PATCH_JUMP);
Common::Patches::DDraw_VC_11( desktop, aNoDesktopMode );
} }
void Patch_VC_Steam(const RECT& desktop) void Patch_VC_Steam(const RECT& desktop)
@ -518,25 +473,6 @@ void Patch_VC_Steam(const RECT& desktop)
InjectHook(0x600102, NewFrameRender); InjectHook(0x600102, NewFrameRender);
InjectHook(0x6000A9, GetTimeSinceLastFrame); InjectHook(0x6000A9, GetTimeSinceLastFrame);
// Default to desktop res
Patch<DWORD>(0x600ADE, desktop.right);
Patch<DWORD>(0x600AE8, desktop.bottom);
Patch<BYTE>(0x600AF2, 32);
Patch<const char*>(0x600B28, aNoDesktopMode);
// No 12mb vram check
Patch<BYTE>(0x601A96, 0xEB);
// No DirectPlay dependency
Patch<BYTE>(0x601910, 0xB8);
Patch<DWORD>(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) // RsMouseSetPos call (SA style fix)
InjectHook(0x4A5D15, ResetMousePos); InjectHook(0x4A5D15, ResetMousePos);
@ -592,6 +528,8 @@ void Patch_VC_Steam(const RECT& desktop)
// Fixed crash related to autopilot timing calculations // Fixed crash related to autopilot timing calculations
InjectHook(0x418FAE, AutoPilotTimerFix_VC, PATCH_JUMP); InjectHook(0x418FAE, AutoPilotTimerFix_VC, PATCH_JUMP);
Common::Patches::DDraw_VC_Steam( desktop, aNoDesktopMode );
} }
void Patch_VC_JP() void Patch_VC_JP()
@ -708,6 +646,8 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
GetWindowRect(GetDesktopWindow(), &desktop); GetWindowRect(GetDesktopWindow(), &desktop);
sprintf_s(aNoDesktopMode, "Cannot find %dx%dx32 video mode", desktop.right, desktop.bottom); sprintf_s(aNoDesktopMode, "Cannot find %dx%dx32 video mode", desktop.right, desktop.bottom);
// This scope is mandatory so Protect goes out of scope before rwcseg gets fixed
{
std::unique_ptr<ScopedUnprotect::Unprotect> Protect = ScopedUnprotect::UnprotectSectionOrFullModule( GetModuleHandle( nullptr ), ".text" ); std::unique_ptr<ScopedUnprotect::Unprotect> Protect = ScopedUnprotect::UnprotectSectionOrFullModule( GetModuleHandle( nullptr ), ".text" );
if(*(DWORD*)0x667BF5 == 0xB85548EC) Patch_VC_10(desktop); if(*(DWORD*)0x667BF5 == 0xB85548EC) Patch_VC_10(desktop);
@ -719,6 +659,9 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
else return TRUE; else return TRUE;
Patch_VC_Common(); Patch_VC_Common();
}
Common::Patches::FixRwcseg_Patterns();
HMODULE hDummyHandle; HMODULE hDummyHandle;
GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, (LPCWSTR)&DllMain, &hDummyHandle); GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, (LPCWSTR)&DllMain, &hDummyHandle);

View file

@ -175,6 +175,11 @@
<ClInclude Include="..\SilentPatch\Timer.h" /> <ClInclude Include="..\SilentPatch\Timer.h" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="..\SilentPatch\Common.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Master|Win32'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">NotUsing</PrecompiledHeader>
</ClCompile>
<ClCompile Include="..\SilentPatch\Patterns.cpp"> <ClCompile Include="..\SilentPatch\Patterns.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">NotUsing</PrecompiledHeader> <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">NotUsing</PrecompiledHeader> <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">NotUsing</PrecompiledHeader>

View file

@ -44,6 +44,9 @@
<ClCompile Include="..\SilentPatch\Patterns.cpp"> <ClCompile Include="..\SilentPatch\Patterns.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\SilentPatch\Common.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ResourceCompile Include="..\SilentPatch\SilentPatch.rc"> <ResourceCompile Include="..\SilentPatch\SilentPatch.rc">