2014-08-27 05:20:24 +06:00
|
|
|
#include "StdAfx.h"
|
|
|
|
|
|
|
|
#include "Timer.h"
|
2017-09-11 03:39:46 +05:00
|
|
|
#include "Patterns.h"
|
2014-08-27 05:20:24 +06:00
|
|
|
|
2017-09-17 02:32:17 +05:00
|
|
|
#include <memory>
|
|
|
|
|
2014-08-27 05:20:24 +06:00
|
|
|
struct RsGlobalType
|
|
|
|
{
|
|
|
|
const char* AppName;
|
|
|
|
unsigned int unkWidth, unkHeight;
|
2014-09-09 04:21:34 +06:00
|
|
|
signed int MaximumWidth;
|
|
|
|
signed int MaximumHeight;
|
2014-08-27 05:20:24 +06:00
|
|
|
unsigned int frameLimit;
|
|
|
|
BOOL quit;
|
|
|
|
void* ps;
|
|
|
|
void* keyboard;
|
|
|
|
void* mouse;
|
|
|
|
void* pad;
|
|
|
|
};
|
|
|
|
|
2015-09-21 01:25:10 +05:00
|
|
|
struct RwV2d
|
|
|
|
{
|
|
|
|
float x; /**< X value*/
|
|
|
|
float y; /**< Y value */
|
|
|
|
};
|
|
|
|
|
2014-08-27 05:20:24 +06:00
|
|
|
static const void* RosieAudioFix_JumpBack;
|
|
|
|
|
|
|
|
static void (*PrintString)(float,float,const wchar_t*);
|
|
|
|
|
|
|
|
static RsGlobalType* RsGlobal;
|
|
|
|
static const void* SubtitlesShadowFix_JumpBack;
|
|
|
|
|
2014-09-15 00:02:57 +06:00
|
|
|
inline float GetWidthMult()
|
|
|
|
{
|
|
|
|
static const float& ResolutionWidthMult = **AddressByVersion<float**>(0x5FA15E, 0x5FA17E, 0x5F9DBE);
|
|
|
|
return ResolutionWidthMult;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline float GetHeightMult()
|
|
|
|
{
|
|
|
|
static const float& ResolutionHeightMult = **AddressByVersion<float**>(0x5FA148, 0x5FA168, 0x5F9DA8);
|
|
|
|
return ResolutionHeightMult;
|
|
|
|
}
|
|
|
|
|
2014-08-27 05:20:24 +06:00
|
|
|
|
|
|
|
void __declspec(naked) RosiesAudioFix()
|
|
|
|
{
|
|
|
|
_asm
|
|
|
|
{
|
|
|
|
mov byte ptr [ebx+0CCh], 0
|
|
|
|
mov byte ptr [ebx+148h], 0
|
|
|
|
jmp [RosieAudioFix_JumpBack]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-21 01:25:10 +05:00
|
|
|
static bool bGameInFocus = true;
|
|
|
|
|
|
|
|
static LRESULT (CALLBACK **OldWndProc)(HWND, UINT, WPARAM, LPARAM);
|
|
|
|
LRESULT CALLBACK CustomWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
|
|
|
switch ( uMsg )
|
|
|
|
{
|
|
|
|
case WM_KILLFOCUS:
|
|
|
|
bGameInFocus = false;
|
|
|
|
break;
|
|
|
|
case WM_SETFOCUS:
|
|
|
|
bGameInFocus = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (*OldWndProc)(hwnd, uMsg, wParam, lParam);
|
|
|
|
}
|
2017-09-13 01:57:30 +05:00
|
|
|
static auto* const pCustomWndProc = CustomWndProc;
|
2015-09-21 01:25:10 +05:00
|
|
|
|
|
|
|
static void (* const ConstructRenderList)() = AddressByVersion<void(*)()>(0x4CA260, 0x4CA280, 0x4CA120);
|
|
|
|
static void (* const RsMouseSetPos)(RwV2d*) = AddressByVersion<void(*)(RwV2d*)>(0x6030C0, 0x6030A0, 0x602CE0);
|
|
|
|
void ResetMousePos()
|
|
|
|
{
|
|
|
|
if ( bGameInFocus )
|
|
|
|
{
|
|
|
|
RwV2d vecPos = { RsGlobal->MaximumWidth * 0.5f, RsGlobal->MaximumHeight * 0.5f };
|
|
|
|
RsMouseSetPos(&vecPos);
|
|
|
|
}
|
|
|
|
ConstructRenderList();
|
|
|
|
}
|
|
|
|
|
2014-08-27 05:20:24 +06:00
|
|
|
void __stdcall Recalculate(float& fX, float& fY, signed int nShadow)
|
|
|
|
{
|
2014-09-15 00:02:57 +06:00
|
|
|
fX = nShadow * GetWidthMult() * RsGlobal->MaximumWidth;
|
|
|
|
fY = nShadow * GetHeightMult() * RsGlobal->MaximumHeight;
|
2014-08-27 05:20:24 +06:00
|
|
|
}
|
|
|
|
|
|
|
|
template<int pFltX, int pFltY>
|
|
|
|
void AlteredPrintString(float fX, float fY, const wchar_t* pText)
|
|
|
|
{
|
|
|
|
float fMarginX = **reinterpret_cast<float**>(pFltX);
|
|
|
|
float fMarginY = **reinterpret_cast<float**>(pFltY);
|
2014-09-15 00:02:57 +06:00
|
|
|
PrintString(fX - fMarginX + (fMarginX * GetWidthMult() * RsGlobal->MaximumWidth), fY - fMarginY + (fMarginY * GetHeightMult() * RsGlobal->MaximumHeight), pText);
|
2014-08-27 05:20:24 +06:00
|
|
|
}
|
|
|
|
|
|
|
|
template<int pFltX, int pFltY>
|
|
|
|
void AlteredPrintStringMinus(float fX, float fY, const wchar_t* pText)
|
|
|
|
{
|
|
|
|
float fMarginX = **reinterpret_cast<float**>(pFltX);
|
|
|
|
float fMarginY = **reinterpret_cast<float**>(pFltY);
|
2014-09-15 00:02:57 +06:00
|
|
|
PrintString(fX + fMarginX - (fMarginX * GetWidthMult() * RsGlobal->MaximumWidth), fY + fMarginY - (fMarginY * GetHeightMult() * RsGlobal->MaximumHeight), pText);
|
2014-08-27 05:20:24 +06:00
|
|
|
}
|
|
|
|
|
|
|
|
template<int pFltX>
|
|
|
|
void AlteredPrintStringXOnly(float fX, float fY, const wchar_t* pText)
|
|
|
|
{
|
|
|
|
float fMarginX = **reinterpret_cast<float**>(pFltX);
|
2014-09-15 00:02:57 +06:00
|
|
|
PrintString(fX - fMarginX + (fMarginX * GetWidthMult() * RsGlobal->MaximumWidth), fY, pText);
|
2014-08-27 05:20:24 +06:00
|
|
|
}
|
|
|
|
|
|
|
|
template<int pFltY>
|
|
|
|
void AlteredPrintStringYOnly(float fX, float fY, const wchar_t* pText)
|
|
|
|
{
|
|
|
|
float fMarginY = **reinterpret_cast<float**>(pFltY);
|
2014-09-15 00:02:57 +06:00
|
|
|
PrintString(fX, fY - fMarginY + (fMarginY * GetHeightMult() * RsGlobal->MaximumHeight), pText);
|
2014-08-27 05:20:24 +06:00
|
|
|
}
|
|
|
|
|
|
|
|
float FixedRefValue()
|
|
|
|
{
|
|
|
|
return 1.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
void __declspec(naked) SubtitlesShadowFix()
|
|
|
|
{
|
|
|
|
_asm
|
|
|
|
{
|
|
|
|
mov [esp], eax
|
|
|
|
fild [esp]
|
|
|
|
push eax
|
|
|
|
lea eax, [esp+20h-18h]
|
|
|
|
push eax
|
|
|
|
lea eax, [esp+24h-14h]
|
|
|
|
push eax
|
|
|
|
call Recalculate
|
|
|
|
jmp SubtitlesShadowFix_JumpBack
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-22 18:47:56 +05:00
|
|
|
char** const ppUserFilesDir = AddressByVersion<char**>(0x6022AA, 0x60228A, 0x601ECA);
|
|
|
|
|
|
|
|
char* GetMyDocumentsPath()
|
|
|
|
{
|
|
|
|
static char cUserFilesPath[MAX_PATH];
|
|
|
|
|
|
|
|
if ( cUserFilesPath[0] == '\0' )
|
|
|
|
{
|
2017-04-09 21:21:07 +05:00
|
|
|
SHGetFolderPathA(nullptr, CSIDL_MYDOCUMENTS, nullptr, SHGFP_TYPE_CURRENT, cUserFilesPath);
|
|
|
|
PathAppendA(cUserFilesPath, *ppUserFilesDir);
|
|
|
|
CreateDirectoryA(cUserFilesPath, nullptr);
|
2015-04-22 18:47:56 +05:00
|
|
|
}
|
|
|
|
return cUserFilesPath;
|
|
|
|
}
|
|
|
|
|
2015-06-29 03:53:49 +05:00
|
|
|
static LARGE_INTEGER FrameTime;
|
2017-03-07 02:35:08 +05:00
|
|
|
int32_t GetTimeSinceLastFrame()
|
2015-06-29 03:53:49 +05:00
|
|
|
{
|
|
|
|
LARGE_INTEGER curTime;
|
|
|
|
QueryPerformanceCounter(&curTime);
|
2017-03-07 02:35:08 +05:00
|
|
|
return int32_t(curTime.QuadPart - FrameTime.QuadPart);
|
2015-06-29 03:53:49 +05:00
|
|
|
}
|
|
|
|
|
2017-03-07 02:35:08 +05:00
|
|
|
static int (*RsEventHandler)(int, void*);
|
|
|
|
int NewFrameRender(int nEvent, void* pParam)
|
2015-06-29 03:53:49 +05:00
|
|
|
{
|
|
|
|
QueryPerformanceCounter(&FrameTime);
|
2017-03-07 02:35:08 +05:00
|
|
|
return RsEventHandler(nEvent, pParam);
|
2015-06-29 03:53:49 +05:00
|
|
|
}
|
|
|
|
|
2016-05-29 22:17:44 +05:00
|
|
|
|
|
|
|
static signed int& LastTimeFireTruckCreated = **AddressByVersion<int**>(0x429435, 0x429435, 0x429405);
|
|
|
|
static signed int& LastTimeAmbulanceCreated = **AddressByVersion<int**>(0x429449, 0x429449, 0x429419);
|
|
|
|
static void (*orgCarCtrlReInit)();
|
|
|
|
void CarCtrlReInit_SilentPatch()
|
|
|
|
{
|
|
|
|
orgCarCtrlReInit();
|
|
|
|
LastTimeFireTruckCreated = 0;
|
|
|
|
LastTimeAmbulanceCreated = 0;
|
|
|
|
}
|
|
|
|
|
2016-05-30 01:59:15 +05:00
|
|
|
static bool& RespraysAreFree = **AddressByVersion<bool**>(0x430D17, 0x430D17, 0x430CE7);
|
|
|
|
void GaragesInit_SilentPatch()
|
|
|
|
{
|
|
|
|
RespraysAreFree = false;
|
|
|
|
}
|
|
|
|
|
2017-09-14 00:56:06 +05:00
|
|
|
static void (*orgPickNextNodeToChaseCar)(void*, float, float, void*);
|
|
|
|
static float PickNextNodeToChaseCarZ = 0.0f;
|
|
|
|
static void PickNextNodeToChaseCarXYZ( void* vehicle, const CVector& vec, void* chaseTarget )
|
|
|
|
{
|
|
|
|
PickNextNodeToChaseCarZ = vec.z;
|
|
|
|
orgPickNextNodeToChaseCar( vehicle, vec.x, vec.y, chaseTarget );
|
|
|
|
PickNextNodeToChaseCarZ = 0.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-03-05 19:51:52 +05:00
|
|
|
static char aNoDesktopMode[64];
|
2014-08-27 05:20:24 +06:00
|
|
|
|
2017-06-15 20:45:51 +05:00
|
|
|
unsigned int __cdecl AutoPilotTimerCalculation_VC(unsigned int nTimer, int nScaleFactor, float fScaleCoef)
|
|
|
|
{
|
|
|
|
return nTimer - static_cast<unsigned int>(nScaleFactor * fScaleCoef);
|
|
|
|
}
|
|
|
|
|
|
|
|
void __declspec(naked) AutoPilotTimerFix_VC()
|
|
|
|
{
|
|
|
|
_asm {
|
|
|
|
push dword ptr[esp + 0xC]
|
|
|
|
push dword ptr[ebx + 0x10]
|
|
|
|
push eax
|
|
|
|
call AutoPilotTimerCalculation_VC
|
|
|
|
add esp, 0xC
|
|
|
|
mov [ebx + 0xC], eax
|
|
|
|
add esp, 0x30
|
|
|
|
pop ebp
|
|
|
|
pop ebx
|
|
|
|
retn 4
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-05 19:51:52 +05:00
|
|
|
void Patch_VC_10(const RECT& desktop)
|
2014-08-27 05:20:24 +06:00
|
|
|
{
|
2016-08-11 01:27:58 +05:00
|
|
|
using namespace Memory;
|
2014-08-27 05:20:24 +06:00
|
|
|
|
|
|
|
PrintString = (void(*)(float,float,const wchar_t*))0x551040;
|
|
|
|
|
|
|
|
RsGlobal = *(RsGlobalType**)0x602D32;
|
|
|
|
RosieAudioFix_JumpBack = (void*)0x42BFFE;
|
|
|
|
SubtitlesShadowFix_JumpBack = (void*)0x551701;
|
|
|
|
|
|
|
|
Patch<BYTE>(0x43E983, 16);
|
|
|
|
Patch<BYTE>(0x43EC03, 16);
|
|
|
|
Patch<BYTE>(0x43EECB, 16);
|
|
|
|
Patch<BYTE>(0x43F52B, 16);
|
|
|
|
Patch<BYTE>(0x43F842, 16);
|
|
|
|
Patch<BYTE>(0x48EB27, 16);
|
|
|
|
Patch<BYTE>(0x541E7E, 16);
|
|
|
|
|
|
|
|
InjectHook(0x5433BD, FixedRefValue);
|
|
|
|
|
|
|
|
InjectHook(0x42BFF7, RosiesAudioFix, PATCH_JUMP);
|
|
|
|
|
|
|
|
InjectHook(0x5516FC, SubtitlesShadowFix, PATCH_JUMP);
|
|
|
|
Patch<BYTE>(0x5517C4, 0xD9);
|
|
|
|
Patch<BYTE>(0x5517DF, 0xD9);
|
|
|
|
Patch<BYTE>(0x551832, 0xD9);
|
|
|
|
Patch<BYTE>(0x551848, 0xD9);
|
|
|
|
Patch<BYTE>(0x5517E2, 0x34-0x14);
|
|
|
|
Patch<BYTE>(0x55184B, 0x34-0x14);
|
|
|
|
Patch<BYTE>(0x5517C7, 0x28-0x18);
|
|
|
|
Patch<BYTE>(0x551835, 0x24-0x18);
|
|
|
|
Patch<BYTE>(0x5516FB, 0x90);
|
|
|
|
|
|
|
|
InjectHook(0x5FA1FD, AlteredPrintString<0x5FA1F6,0x5FA1D5>);
|
|
|
|
InjectHook(0x54474D, AlteredPrintStringMinus<0x544727,0x544727>);
|
2015-03-05 19:51:52 +05:00
|
|
|
|
|
|
|
// Mouse fucking fix!
|
|
|
|
Patch<DWORD>(0x601740, 0xC3C030);
|
|
|
|
|
2015-06-29 03:53:49 +05:00
|
|
|
// (Hopefully) more precise frame limiter
|
2016-09-12 03:09:21 +05:00
|
|
|
ReadCall( 0x6004A2, RsEventHandler );
|
|
|
|
InjectHook(0x6004A2, NewFrameRender);
|
2015-06-29 03:53:49 +05:00
|
|
|
InjectHook(0x600449, GetTimeSinceLastFrame);
|
|
|
|
|
2015-03-05 19:51:52 +05:00
|
|
|
// 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);
|
2015-04-22 18:47:56 +05:00
|
|
|
|
|
|
|
// SHGetFolderPath on User Files
|
|
|
|
InjectHook(0x602240, GetMyDocumentsPath, PATCH_JUMP);
|
|
|
|
|
|
|
|
InjectHook(0x601A40, GetMyDocumentsPath, PATCH_CALL);
|
|
|
|
InjectHook(0x601A45, 0x601B2F, PATCH_JUMP);
|
2015-09-21 01:25:10 +05:00
|
|
|
|
|
|
|
// RsMouseSetPos call (SA style fix)
|
|
|
|
InjectHook(0x4A5E45, ResetMousePos);
|
|
|
|
|
|
|
|
// New wndproc
|
|
|
|
OldWndProc = *(LRESULT (CALLBACK***)(HWND, UINT, WPARAM, LPARAM))0x601727;
|
|
|
|
Patch(0x601727, &pCustomWndProc);
|
2016-03-11 03:14:25 +05:00
|
|
|
|
|
|
|
// Y axis sensitivity fix
|
|
|
|
// By ThirteenAG
|
|
|
|
float* sens = *(float**)0x4796E5;
|
|
|
|
Patch<const void*>(0x479410 + 0x2E0 + 0x2, sens);
|
|
|
|
Patch<const void*>(0x47A20E + 0x27D + 0x2, sens);
|
|
|
|
Patch<const void*>(0x47AE27 + 0x1CC + 0x2, sens);
|
|
|
|
Patch<const void*>(0x47BE8F + 0x22E + 0x2, sens);
|
|
|
|
Patch<const void*>(0x481AB3 + 0x4FE + 0x2, sens);
|
2016-04-01 01:29:31 +05:00
|
|
|
|
|
|
|
// Don't lock mouse Y axis during fadeins
|
|
|
|
Patch<BYTE>(0x47C11E, 0xEB);
|
|
|
|
Patch<BYTE>(0x47CD94, 0xEB);
|
|
|
|
Nop(0x47C15A, 2);
|
2016-04-01 01:51:52 +05:00
|
|
|
|
|
|
|
// Scan for A/B drives looking for audio files
|
|
|
|
Patch<DWORD>(0x5D7941, 'A');
|
|
|
|
Patch<DWORD>(0x5D7B04, 'A');
|
2016-05-21 19:14:34 +05:00
|
|
|
|
|
|
|
|
|
|
|
// ~x~ as cyan blip
|
|
|
|
// Shared with GInput
|
|
|
|
Patch<BYTE>(0x550481, 0);
|
|
|
|
Patch<BYTE>(0x550488, 255);
|
|
|
|
Patch<BYTE>(0x55048F, 255);
|
|
|
|
|
|
|
|
Patch<BYTE>(0x5505FF, 0);
|
|
|
|
Patch<BYTE>(0x550603, 255);
|
|
|
|
Patch<BYTE>(0x550607, 255);
|
2016-05-29 18:01:57 +05:00
|
|
|
|
2016-05-29 19:52:25 +05:00
|
|
|
|
|
|
|
// Corrected crime codes
|
|
|
|
Patch<DWORD>(0x5FDDDB, 0xC5);
|
|
|
|
|
2016-05-29 18:01:57 +05:00
|
|
|
|
2016-05-29 22:17:44 +05:00
|
|
|
// Reinit CCarCtrl fields (firetruck and ambulance generation)
|
2016-09-12 03:09:21 +05:00
|
|
|
ReadCall( 0x4A489B, orgCarCtrlReInit );
|
2016-05-29 22:17:44 +05:00
|
|
|
InjectHook(0x4A489B, CarCtrlReInit_SilentPatch);
|
|
|
|
|
|
|
|
|
2016-05-30 01:59:15 +05:00
|
|
|
// Reinit free resprays flag
|
|
|
|
InjectHook(0x4349BB, GaragesInit_SilentPatch, PATCH_JUMP);
|
|
|
|
|
2016-07-27 05:19:11 +05:00
|
|
|
// Fixed ammo for melee weapons in cheats
|
|
|
|
Patch<BYTE>(0x4AED14+1, 1); // katana
|
|
|
|
Patch<BYTE>(0x4AEB74+1, 1); // chainsaw
|
|
|
|
|
2017-06-15 20:45:51 +05:00
|
|
|
// Fixed crash related to autopilot timing calculations
|
|
|
|
InjectHook(0x418FAE, AutoPilotTimerFix_VC, PATCH_JUMP);
|
|
|
|
|
2016-07-27 05:19:11 +05:00
|
|
|
|
2016-05-29 18:01:57 +05:00
|
|
|
// Adblocker
|
|
|
|
#if DISABLE_FLA_DONATION_WINDOW
|
|
|
|
if ( *(DWORD*)0x5FFAE9 != 0x006A026A )
|
|
|
|
{
|
|
|
|
Patch<DWORD>(0x5FFAE9, 0x006A026A);
|
|
|
|
Patch<WORD>(0x5FFAED, 0x006A);
|
|
|
|
}
|
|
|
|
#endif
|
2014-08-27 05:20:24 +06:00
|
|
|
}
|
|
|
|
|
2015-03-05 19:51:52 +05:00
|
|
|
void Patch_VC_11(const RECT& desktop)
|
2014-08-27 05:20:24 +06:00
|
|
|
{
|
2016-08-11 01:27:58 +05:00
|
|
|
using namespace Memory;
|
2014-08-27 05:20:24 +06:00
|
|
|
|
|
|
|
PrintString = (void(*)(float,float,const wchar_t*))0x551060;
|
|
|
|
|
|
|
|
RsGlobal = *(RsGlobalType**)0x602D12;
|
|
|
|
RosieAudioFix_JumpBack = (void*)0x42BFFE;
|
|
|
|
SubtitlesShadowFix_JumpBack = (void*)0x551721;
|
|
|
|
|
|
|
|
Patch<BYTE>(0x43E983, 16);
|
|
|
|
Patch<BYTE>(0x43EC03, 16);
|
|
|
|
Patch<BYTE>(0x43EECB, 16);
|
|
|
|
Patch<BYTE>(0x43F52B, 16);
|
|
|
|
Patch<BYTE>(0x43F842, 16);
|
|
|
|
Patch<BYTE>(0x48EB37, 16);
|
|
|
|
Patch<BYTE>(0x541E9E, 16);
|
|
|
|
|
|
|
|
InjectHook(0x5433DD, FixedRefValue);
|
|
|
|
|
|
|
|
InjectHook(0x42BFF7, RosiesAudioFix, PATCH_JUMP);
|
|
|
|
|
|
|
|
InjectHook(0x55171C, SubtitlesShadowFix, PATCH_JUMP);
|
|
|
|
Patch<BYTE>(0x5517E4, 0xD9);
|
|
|
|
Patch<BYTE>(0x5517FF, 0xD9);
|
|
|
|
Patch<BYTE>(0x551852, 0xD9);
|
|
|
|
Patch<BYTE>(0x551868, 0xD9);
|
|
|
|
Patch<BYTE>(0x551802, 0x34-0x14);
|
|
|
|
Patch<BYTE>(0x55186B, 0x34-0x14);
|
|
|
|
Patch<BYTE>(0x5517E7, 0x28-0x18);
|
|
|
|
Patch<BYTE>(0x551855, 0x24-0x18);
|
|
|
|
Patch<BYTE>(0x55171B, 0x90);
|
|
|
|
|
|
|
|
InjectHook(0x5FA21D, AlteredPrintString<0x5FA216,0x5FA1F5>);
|
|
|
|
InjectHook(0x54476D, AlteredPrintStringMinus<0x544747,0x544747>);
|
2015-03-05 19:51:52 +05:00
|
|
|
|
|
|
|
// Mouse fucking fix!
|
|
|
|
Patch<DWORD>(0x601770, 0xC3C030);
|
|
|
|
|
2015-06-29 03:53:49 +05:00
|
|
|
// (Hopefully) more precise frame limiter
|
2016-09-12 03:09:21 +05:00
|
|
|
ReadCall( 0x6004C2, RsEventHandler );
|
|
|
|
InjectHook(0x6004C2, NewFrameRender);
|
2015-06-29 03:53:49 +05:00
|
|
|
InjectHook(0x600469, GetTimeSinceLastFrame);
|
|
|
|
|
2015-03-05 19:51:52 +05:00
|
|
|
// 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);
|
2015-04-22 18:47:56 +05:00
|
|
|
|
|
|
|
// SHGetFolderPath on User Files
|
|
|
|
InjectHook(0x602220, GetMyDocumentsPath, PATCH_JUMP);
|
|
|
|
|
|
|
|
InjectHook(0x601A70, GetMyDocumentsPath, PATCH_CALL);
|
|
|
|
InjectHook(0x601A75, 0x601B5F, PATCH_JUMP);
|
2015-09-21 01:25:10 +05:00
|
|
|
|
|
|
|
// RsMouseSetPos call (SA style fix)
|
|
|
|
InjectHook(0x4A5E65, ResetMousePos);
|
|
|
|
|
|
|
|
// New wndproc
|
|
|
|
OldWndProc = *(LRESULT (CALLBACK***)(HWND, UINT, WPARAM, LPARAM))0x601757;
|
|
|
|
Patch(0x601757, &pCustomWndProc);
|
2016-03-11 03:14:25 +05:00
|
|
|
|
|
|
|
// Y axis sensitivity fix
|
|
|
|
// By ThirteenAG
|
|
|
|
float* sens = *(float**)0x4796E5;
|
|
|
|
Patch<const void*>(0x479410 + 0x2E0 + 0x2, sens);
|
|
|
|
Patch<const void*>(0x47A20E + 0x27D + 0x2, sens);
|
|
|
|
Patch<const void*>(0x47AE27 + 0x1CC + 0x2, sens);
|
|
|
|
Patch<const void*>(0x47BE8F + 0x22E + 0x2, sens);
|
|
|
|
Patch<const void*>(0x481AB3 + 0x4FE + 0x2, sens);
|
2016-04-01 01:29:31 +05:00
|
|
|
|
|
|
|
// Don't lock mouse Y axis during fadeins
|
|
|
|
Patch<BYTE>(0x47C11E, 0xEB);
|
|
|
|
Patch<BYTE>(0x47CD94, 0xEB);
|
|
|
|
Nop(0x47C15A, 2);
|
2016-04-01 01:51:52 +05:00
|
|
|
|
|
|
|
// Scan for A/B drives looking for audio files
|
|
|
|
Patch<DWORD>(0x5D7961, 'A');
|
|
|
|
Patch<DWORD>(0x5D7B24, 'A');
|
2016-05-21 19:14:34 +05:00
|
|
|
|
|
|
|
|
|
|
|
// ~x~ as cyan blip
|
|
|
|
// Shared with GInput
|
|
|
|
Patch<BYTE>(0x5504A1, 0);
|
|
|
|
Patch<BYTE>(0x5504A8, 255);
|
|
|
|
Patch<BYTE>(0x5504AF, 255);
|
|
|
|
|
|
|
|
Patch<BYTE>(0x55061F, 0);
|
|
|
|
Patch<BYTE>(0x550623, 255);
|
|
|
|
Patch<BYTE>(0x550627, 255);
|
2016-05-29 19:52:25 +05:00
|
|
|
|
|
|
|
|
|
|
|
// Corrected crime codes
|
|
|
|
Patch<DWORD>(0x5FDDFB, 0xC5);
|
2016-05-29 22:17:44 +05:00
|
|
|
|
|
|
|
|
|
|
|
// Reinit CCarCtrl fields (firetruck and ambulance generation)
|
2016-09-12 03:09:21 +05:00
|
|
|
ReadCall( 0x4A48BB, orgCarCtrlReInit );
|
2016-05-29 22:17:44 +05:00
|
|
|
InjectHook(0x4A48BB, CarCtrlReInit_SilentPatch);
|
2016-05-30 01:59:15 +05:00
|
|
|
|
|
|
|
|
|
|
|
// Reinit free resprays flag
|
|
|
|
InjectHook(0x4349BB, GaragesInit_SilentPatch, PATCH_JUMP);
|
2016-07-27 05:19:11 +05:00
|
|
|
|
|
|
|
|
|
|
|
// Fixed ammo for melee weapons in cheats
|
|
|
|
Patch<BYTE>(0x4AED34+1, 1); // katana
|
|
|
|
Patch<BYTE>(0x4AEB94+1, 1); // chainsaw
|
2017-06-15 20:45:51 +05:00
|
|
|
|
|
|
|
// Fixed crash related to autopilot timing calculations
|
|
|
|
InjectHook(0x418FAE, AutoPilotTimerFix_VC, PATCH_JUMP);
|
2014-08-27 05:20:24 +06:00
|
|
|
}
|
|
|
|
|
2015-03-05 19:51:52 +05:00
|
|
|
void Patch_VC_Steam(const RECT& desktop)
|
2014-08-27 05:20:24 +06:00
|
|
|
{
|
2016-08-11 01:27:58 +05:00
|
|
|
using namespace Memory;
|
2014-08-27 05:20:24 +06:00
|
|
|
|
|
|
|
PrintString = (void(*)(float,float,const wchar_t*))0x550F30;
|
|
|
|
|
|
|
|
RsGlobal = *(RsGlobalType**)0x602952;
|
|
|
|
RosieAudioFix_JumpBack = (void*)0x42BFCE;
|
|
|
|
SubtitlesShadowFix_JumpBack = (void*)0x5515F1;
|
|
|
|
|
|
|
|
Patch<BYTE>(0x43E8F3, 16);
|
|
|
|
Patch<BYTE>(0x43EB73, 16);
|
|
|
|
Patch<BYTE>(0x43EE3B, 16);
|
|
|
|
Patch<BYTE>(0x43F49B, 16);
|
|
|
|
Patch<BYTE>(0x43F7B2, 16);
|
|
|
|
Patch<BYTE>(0x48EA37, 16);
|
|
|
|
Patch<BYTE>(0x541D6E, 16);
|
|
|
|
|
|
|
|
InjectHook(0x5432AD, FixedRefValue);
|
|
|
|
|
|
|
|
InjectHook(0x42BFC7, RosiesAudioFix, PATCH_JUMP);
|
|
|
|
|
|
|
|
InjectHook(0x5515EC, SubtitlesShadowFix, PATCH_JUMP);
|
|
|
|
Patch<BYTE>(0x5516B4, 0xD9);
|
|
|
|
Patch<BYTE>(0x5516CF, 0xD9);
|
|
|
|
Patch<BYTE>(0x551722, 0xD9);
|
|
|
|
Patch<BYTE>(0x551738, 0xD9);
|
|
|
|
Patch<BYTE>(0x5516D2, 0x34-0x14);
|
|
|
|
Patch<BYTE>(0x55173B, 0x34-0x14);
|
|
|
|
Patch<BYTE>(0x5516B7, 0x28-0x18);
|
|
|
|
Patch<BYTE>(0x551725, 0x24-0x18);
|
|
|
|
Patch<BYTE>(0x5515EB, 0x90);
|
|
|
|
|
|
|
|
InjectHook(0x5F9E5D, AlteredPrintString<0x5F9E56,0x5F9E35>);
|
|
|
|
InjectHook(0x54463D, AlteredPrintStringMinus<0x544617,0x544617>);
|
2015-03-05 19:51:52 +05:00
|
|
|
|
|
|
|
// Mouse fucking fix!
|
|
|
|
Patch<DWORD>(0x6013B0, 0xC3C030);
|
|
|
|
|
2015-06-29 03:53:49 +05:00
|
|
|
// (Hopefully) more precise frame limiter
|
2016-09-12 03:09:21 +05:00
|
|
|
ReadCall( 0x600102, RsEventHandler );
|
|
|
|
InjectHook(0x600102, NewFrameRender);
|
2015-06-29 03:53:49 +05:00
|
|
|
InjectHook(0x6000A9, GetTimeSinceLastFrame);
|
|
|
|
|
2015-03-05 19:51:52 +05:00
|
|
|
// 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);
|
2015-04-22 18:47:56 +05:00
|
|
|
|
|
|
|
// SHGetFolderPath on User Files
|
|
|
|
InjectHook(0x601E60, GetMyDocumentsPath, PATCH_JUMP);
|
|
|
|
|
|
|
|
InjectHook(0x6016B0, GetMyDocumentsPath, PATCH_CALL);
|
|
|
|
InjectHook(0x6016B5, 0x60179F, PATCH_JUMP);
|
2015-09-21 01:25:10 +05:00
|
|
|
|
|
|
|
// RsMouseSetPos call (SA style fix)
|
|
|
|
InjectHook(0x4A5D15, ResetMousePos);
|
|
|
|
|
|
|
|
// New wndproc
|
|
|
|
OldWndProc = *(LRESULT (CALLBACK***)(HWND, UINT, WPARAM, LPARAM))0x601397;
|
|
|
|
Patch(0x601397, &pCustomWndProc);
|
2016-03-11 03:14:25 +05:00
|
|
|
|
|
|
|
// Y axis sensitivity fix
|
|
|
|
// By ThirteenAG
|
|
|
|
float* sens = *(float**)0x4795C5;
|
|
|
|
Patch<const void*>(0x4792F0 + 0x2E0 + 0x2, sens);
|
|
|
|
Patch<const void*>(0x47A0EE + 0x27D + 0x2, sens);
|
|
|
|
Patch<const void*>(0x47AD07 + 0x1CC + 0x2, sens);
|
|
|
|
Patch<const void*>(0x47BD6F + 0x22E + 0x2, sens);
|
|
|
|
Patch<const void*>(0x481993 + 0x4FE + 0x2, sens);
|
2016-04-01 01:29:31 +05:00
|
|
|
|
|
|
|
// Don't lock mouse Y axis during fadeins
|
|
|
|
Patch<BYTE>(0x47BFFE, 0xEB);
|
|
|
|
Patch<BYTE>(0x47CC74, 0xEB);
|
|
|
|
Nop(0x47C03A, 2);
|
2016-04-01 01:51:52 +05:00
|
|
|
|
|
|
|
// Scan for A/B drives looking for audio files
|
|
|
|
Patch<DWORD>(0x5D7764, 'A');
|
2016-05-21 19:14:34 +05:00
|
|
|
|
|
|
|
|
|
|
|
// ~x~ as cyan blip
|
|
|
|
// Shared with GInput
|
|
|
|
Patch<BYTE>(0x550371, 0);
|
|
|
|
Patch<BYTE>(0x550378, 255);
|
|
|
|
Patch<BYTE>(0x55037F, 255);
|
|
|
|
|
|
|
|
Patch<BYTE>(0x5504EF, 0);
|
|
|
|
Patch<BYTE>(0x5504F3, 255);
|
|
|
|
Patch<BYTE>(0x5504F7, 255);
|
2016-05-29 19:52:25 +05:00
|
|
|
|
|
|
|
|
|
|
|
// Corrected crime codes
|
|
|
|
Patch<DWORD>(0x5FDA3B, 0xC5);
|
2016-05-29 22:17:44 +05:00
|
|
|
|
|
|
|
|
|
|
|
// Reinit CCarCtrl fields (firetruck and ambulance generation)
|
2016-09-12 03:09:21 +05:00
|
|
|
ReadCall( 0x4A475B, orgCarCtrlReInit );
|
2016-05-29 22:17:44 +05:00
|
|
|
InjectHook(0x4A475B, CarCtrlReInit_SilentPatch);
|
2016-05-30 01:59:15 +05:00
|
|
|
|
|
|
|
|
|
|
|
// Reinit free resprays flag
|
|
|
|
InjectHook(0x43497B, GaragesInit_SilentPatch, PATCH_JUMP);
|
2016-07-27 05:19:11 +05:00
|
|
|
|
|
|
|
|
|
|
|
// Fixed ammo for melee weapons in cheats
|
|
|
|
Patch<BYTE>(0x4AEA44+1, 1); // katana
|
|
|
|
Patch<BYTE>(0x4AEBE4+1, 1); // chainsaw
|
2017-06-15 20:45:51 +05:00
|
|
|
|
|
|
|
// Fixed crash related to autopilot timing calculations
|
|
|
|
InjectHook(0x418FAE, AutoPilotTimerFix_VC, PATCH_JUMP);
|
2014-08-27 05:20:24 +06:00
|
|
|
}
|
|
|
|
|
2016-03-12 00:48:14 +05:00
|
|
|
void Patch_VC_JP()
|
|
|
|
{
|
2016-08-11 01:27:58 +05:00
|
|
|
using namespace Memory;
|
2016-03-12 00:48:14 +05:00
|
|
|
|
|
|
|
// Y axis sensitivity fix
|
|
|
|
// By ThirteenAG
|
|
|
|
Patch<DWORD>(0x4797E7 + 0x2E0 + 0x2, 0x94ABD8);
|
|
|
|
Patch<DWORD>(0x47A5E5 + 0x27D + 0x2, 0x94ABD8);
|
|
|
|
Patch<DWORD>(0x47B1FE + 0x1CC + 0x2, 0x94ABD8);
|
|
|
|
Patch<DWORD>(0x47C266 + 0x22E + 0x2, 0x94ABD8);
|
|
|
|
Patch<DWORD>(0x481E8A + 0x4FE + 0x2, 0x94ABD8);
|
|
|
|
}
|
|
|
|
|
2017-09-11 03:39:46 +05:00
|
|
|
void Patch_VC_Common()
|
|
|
|
{
|
|
|
|
using namespace Memory;
|
|
|
|
using namespace hook;
|
|
|
|
|
|
|
|
// New timers fix
|
|
|
|
{
|
|
|
|
auto hookPoint = pattern( "83 E4 F8 89 44 24 08 C7 44 24 0C 00 00 00 00 DF 6C 24 08" ).get_one();
|
|
|
|
auto jmpPoint = get_pattern( "DD D8 E9 31 FF FF FF" );
|
|
|
|
|
2017-09-12 18:36:58 +05:00
|
|
|
InjectHook( hookPoint.get<void>( 0x21 ), CTimer::Update_SilentPatch, PATCH_CALL );
|
|
|
|
InjectHook( hookPoint.get<void>( 0x21 + 5 ), jmpPoint, PATCH_JUMP );
|
2017-09-11 03:39:46 +05:00
|
|
|
}
|
2017-09-12 16:31:57 +05:00
|
|
|
|
|
|
|
// Remove FILE_FLAG_NO_BUFFERING from CdStreams
|
|
|
|
{
|
|
|
|
auto addr = get_pattern( "81 7C 24 04 00 08 00 00", 0x12 );
|
|
|
|
Patch<uint8_t>( addr, 0xEB );
|
|
|
|
}
|
2017-09-12 18:36:58 +05:00
|
|
|
|
|
|
|
// Alt+F4
|
|
|
|
{
|
|
|
|
auto addr = pattern( "59 59 31 C0 83 C4 70 5D 5F 5E 5B C2 10 00" ).count(2);
|
|
|
|
auto dest = get_pattern( "53 55 56 FF B4 24 90 00 00 00 FF 15" );
|
|
|
|
|
|
|
|
addr.for_each_result( [&]( pattern_match match ) {
|
|
|
|
InjectHook( match.get<void>( 2 ), dest, PATCH_JUMP );
|
|
|
|
});
|
|
|
|
}
|
2017-09-12 21:01:02 +05:00
|
|
|
|
|
|
|
// Proper panels damage
|
|
|
|
{
|
|
|
|
auto addr = pattern( "C6 41 09 03 C6 41 0A 03 C6 41 0B 03" ).get_one();
|
|
|
|
|
|
|
|
// or dword ptr[ecx+14], 3300000h
|
|
|
|
// nop
|
|
|
|
Patch( addr.get<void>( 0x18 ), { 0x81, 0x49, 0x14, 0x00, 0x00, 0x30, 0x03 } );
|
|
|
|
Nop( addr.get<void>( 0x18 + 7 ), 13 );
|
|
|
|
|
|
|
|
Nop( addr.get<void>( 0x33 ), 7 );
|
2017-09-13 01:35:45 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Proper metric-imperial conversion constants
|
|
|
|
{
|
|
|
|
static const float METERS_TO_MILES = 0.0006213711922f;
|
|
|
|
auto addr = pattern( "75 ? D9 05 ? ? ? ? D8 0D ? ? ? ? 6A 00 6A 00 D9 9C 24" ).count(6);
|
|
|
|
addr.for_each_result( [&]( pattern_match match ) {
|
|
|
|
Patch<const void*>( match.get<void>( 0x8 + 2 ), &METERS_TO_MILES );
|
|
|
|
});
|
2017-09-12 21:01:02 +05:00
|
|
|
|
2017-09-13 01:35:45 +05:00
|
|
|
auto sum = get_pattern( "D9 9C 24 A8 00 00 00 8D 84 24 A8 00 00 00 50", -6 + 2 );
|
|
|
|
Patch<const void*>( sum, &METERS_TO_MILES );
|
2017-09-12 21:01:02 +05:00
|
|
|
}
|
2017-09-14 00:56:06 +05:00
|
|
|
|
|
|
|
// Improved pathfinding in PickNextNodeAccordingStrategy - PickNextNodeToChaseCar with XYZ coords
|
|
|
|
{
|
|
|
|
auto addr = pattern( "E8 ? ? ? ? 50 8D 44 24 10 50 E8" ).get_one();
|
|
|
|
ReadCall( addr.get<void>( 0x25 ), orgPickNextNodeToChaseCar );
|
|
|
|
|
|
|
|
const uintptr_t funcAddr = (uintptr_t)get_pattern( "8B 9C 24 BC 00 00 00 66 8B B3 A6 01 00 00 66 85 F6", -0xA );
|
|
|
|
InjectHook( funcAddr - 5, PickNextNodeToChaseCarXYZ, PATCH_JUMP ); // For plugin-sdk
|
|
|
|
|
|
|
|
// push PickNextNodeToChaseCarZ instead of 0.0f
|
|
|
|
// mov ecx, [PickNextNodeToChaseCarZ]
|
|
|
|
// mov [esp+0B8h+var_2C], ecx
|
|
|
|
Patch( funcAddr + 0x5D, { 0x8B, 0x0D } );
|
|
|
|
Patch<const void*>( funcAddr + 0x5D + 2, &PickNextNodeToChaseCarZ );
|
|
|
|
Patch( funcAddr + 0x5D + 6, { 0x89, 0x8C, 0x24, 0x8C, 0x00, 0x00, 0x00 } );
|
|
|
|
|
|
|
|
// lea eax, [ecx+edx*4] -> lea eax, [edx+edx*4]
|
|
|
|
Patch<uint8_t>( funcAddr + 0x6E + 2, 0x92 );
|
|
|
|
|
|
|
|
|
|
|
|
// lea eax, [esp+20h+var_10]
|
|
|
|
// push eax
|
|
|
|
// nop...
|
|
|
|
Patch( addr.get<void>( 0x10 ), { 0x83, 0xC4, 0x04, 0x8D, 0x44, 0x24, 0x10, 0x50, 0xEB, 0x0A } );
|
|
|
|
InjectHook( addr.get<void>( 0x25 ), PickNextNodeToChaseCarXYZ );
|
|
|
|
Patch<uint8_t>( addr.get<void>( 0x2A + 2 ), 0xC );
|
|
|
|
|
|
|
|
// push edx
|
|
|
|
// nop...
|
|
|
|
Patch<uint8_t>( addr.get<void>( 0x3E ), 0x52 );
|
|
|
|
Nop( addr.get<void>( 0x3E + 1 ), 6 );
|
|
|
|
InjectHook( addr.get<void>( 0x46 ), PickNextNodeToChaseCarXYZ );
|
|
|
|
Patch<uint8_t>( addr.get<void>( 0x4B + 2 ), 0xC );
|
|
|
|
}
|
|
|
|
|
2017-09-11 03:39:46 +05:00
|
|
|
}
|
|
|
|
|
2014-08-27 05:20:24 +06:00
|
|
|
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
|
|
|
|
{
|
|
|
|
UNREFERENCED_PARAMETER(hinstDLL);
|
|
|
|
UNREFERENCED_PARAMETER(lpvReserved);
|
|
|
|
|
|
|
|
if ( fdwReason == DLL_PROCESS_ATTACH )
|
|
|
|
{
|
2015-03-05 19:51:52 +05:00
|
|
|
RECT desktop;
|
|
|
|
GetWindowRect(GetDesktopWindow(), &desktop);
|
2016-03-31 22:51:14 +05:00
|
|
|
sprintf_s(aNoDesktopMode, "Cannot find %dx%dx32 video mode", desktop.right, desktop.bottom);
|
2015-03-05 19:51:52 +05:00
|
|
|
|
2017-09-18 15:52:35 +05:00
|
|
|
std::unique_ptr<ScopedUnprotect::Unprotect> Protect = ScopedUnprotect::UnprotectSectionOrFullModule( GetModuleHandle( nullptr ), ".text" );
|
2016-09-12 03:11:17 +05:00
|
|
|
|
2015-04-22 18:47:56 +05:00
|
|
|
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);
|
2016-03-12 00:48:14 +05:00
|
|
|
|
|
|
|
// Y axis sensitivity only
|
2017-09-11 03:39:46 +05:00
|
|
|
else if (*(DWORD*)0x601048 == 0x5E5F5D60) Patch_VC_JP();
|
2017-06-05 17:22:35 +05:00
|
|
|
else return TRUE;
|
2014-08-27 06:44:49 +06:00
|
|
|
|
2017-09-11 03:39:46 +05:00
|
|
|
Patch_VC_Common();
|
2015-03-05 19:51:52 +05:00
|
|
|
|
|
|
|
HMODULE hDummyHandle;
|
2017-04-09 21:21:07 +05:00
|
|
|
GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, (LPCWSTR)&DllMain, &hDummyHandle);
|
2014-08-27 05:20:24 +06:00
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|