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

View file

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

View file

@ -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<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);
Common::Patches::DDraw_III_10( desktop, aNoDesktopMode );
}
else if (*(DWORD*)0x5C2135 == 0xB85548EC)
{
// III 1.1
ppUserFilesDir = (char**)0x580F66;
InjectHook(0x580F00, GetMyDocumentsPath, PATCH_JUMP);
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);
Common::Patches::DDraw_III_11( desktop, aNoDesktopMode );
}
else if (*(DWORD*)0x5C6FD5 == 0xB85548EC)
{
// III Steam
ppUserFilesDir = (char**)0x580E66;
InjectHook(0x580E00, GetMyDocumentsPath, PATCH_JUMP);
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);
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<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);
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<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);
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<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);
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;
}
}
}
}

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
#include <windows.h>
#include <mmsystem.h>
#include <cassert>
#include <cstdio>
#include <ShlObj.h>
#include <Shlwapi.h>
#include "MemoryMgr.h"

View file

@ -3,6 +3,7 @@
#include "General.h"
#include "Timer.h"
#include "Patterns.h"
#include "Common.h"
#include <memory>
@ -285,20 +286,7 @@ void __declspec(naked) RadarBoundsCheckEntityBlip()
}
}
char** const 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;
}
extern char** ppUserFilesDir = AddressByVersion<char**>(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<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)
ReadCall( 0x48C4FB, orgCarCtrlReInit );
InjectHook(0x48C4FB, CarCtrlReInit_SilentPatch);
@ -518,6 +489,8 @@ void Patch_III_10(const RECT& desktop)
Patch<WORD>(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<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)
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<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)
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<ScopedUnprotect::Unprotect> Protect = ScopedUnprotect::UnprotectSectionOrFullModule( GetModuleHandle( nullptr ), ".text" );
// 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" );
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);

View file

@ -15,6 +15,11 @@
</ProjectConfiguration>
</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">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">NotUsing</PrecompiledHeader>

View file

@ -27,6 +27,9 @@
<ClCompile Include="..\SilentPatch\Patterns.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\SilentPatch\Common.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<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);
}
char* GetMyDocumentsPath()
char* GetMyDocumentsPathSA()
{
static char cUserFilesPath[MAX_PATH];
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);
// 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<DWORD>(AddressByRegion_11<DWORD>(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<DWORD>(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<DWORD>(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<DWORD>(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);

View file

@ -2,6 +2,7 @@
#include "Timer.h"
#include "Patterns.h"
#include "Common.h"
#include <memory>
@ -143,20 +144,7 @@ void __declspec(naked) SubtitlesShadowFix()
}
}
char** const 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;
}
extern char** ppUserFilesDir = AddressByVersion<char**>(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<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)
InjectHook(0x4A5E45, ResetMousePos);
@ -351,6 +321,8 @@ void Patch_VC_10(const RECT& desktop)
Patch<WORD>(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<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)
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<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)
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<ScopedUnprotect::Unprotect> Protect = ScopedUnprotect::UnprotectSectionOrFullModule( GetModuleHandle( nullptr ), ".text" );
// 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" );
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);

View file

@ -175,6 +175,11 @@
<ClInclude Include="..\SilentPatch\Timer.h" />
</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">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">NotUsing</PrecompiledHeader>

View file

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