Compare commits

...

18 commits

Author SHA1 Message Date
Echo J.
0f30079500
Merge dcde67d8e2 into 202101e4f7 2024-11-07 14:17:05 +02:00
Echo J
dcde67d8e2 SilentPatchVC: Explicitly define _USE_MATH_DEFINES
Not doing that makes M_PI disappear (possibly) due to rwcore.h
secretly including a math header (which breaks Maths.h on MinGW
GCC)
2024-11-07 14:16:06 +02:00
Echo J
00a48ec059 SilentPatchVC: Add GCC/Clang-specific inline assembly statements
This also includes a small wrapper to call a C++ function from inline ASM

(From III: This change also matches the MSVC statements more closely to
the GCC/Clang ones)
2024-11-07 14:16:06 +02:00
Echo J
135ceed86c SilentPatchIII: Add GCC/Clang-specific inline assembly statements
This also matches the MSVC statements more closely to the GCC/Clang
ones
2024-11-07 14:16:06 +02:00
Echo J
75004322ab SilentPatchIII: Add a missing functional header include
MinGW GCC doesn't implicitly include it either
2024-11-07 14:16:06 +02:00
Echo J
b386f216e4 SilentPatch: Add missing cmath header include
It's required for the modf() function (and it isn't implicitly
included on MinGW GCC)
2024-11-07 14:16:06 +02:00
Echo J
37a53c384a SilentPatch: Move a header include in SVF
This makes sure the fixed-width integer types are included in SVF.h
2024-11-07 14:16:06 +02:00
Echo J
52038fdd27 SilentPatch: Define a replacement for _stricmp() if needed
MinGW GCC doesn't have this MSVC-specific function
2024-11-07 14:16:06 +02:00
Echo J
8233e826ec SilentPatch: Simplify RwIm2DRenderLine function pointer declaration
MinGW GCC doesn't seem to unwind the layers of the macro define
properly (which causes it to not find the declaration type)
2024-11-07 14:15:54 +02:00
Echo J
9cf2881779 SilentPatch: Don't define certain Rw* functions if not needed
Redefining them can cause strange compile errors with MinGW GCC
2024-11-07 14:14:51 +02:00
Echo J
96e971e364 DDraw: Cast the memcpy() source argument
This works around the MinGW GCC type strictness
2024-11-07 14:14:51 +02:00
Echo J
f523ea372a DDraw: Change the forwarded name for DirectDrawCreateEx
MinGW GCC exports this function a bit differently (which doesn't
work here)
2024-11-07 14:14:51 +02:00
Echo J
b1a86e8a89 SilentPatchIII/VC/SA: Mark some function pointers as inline
MinGW GCC's linker can't find them otherwise
2024-11-07 14:14:33 +02:00
Echo J
9d988b3396 SilentPatchIII/VC: Remove extern from ppUserFilesDir variable definitions
This fixes compile warnings with MinGW GCC
2024-11-07 13:40:01 +02:00
Echo J
3eab9e4461 SilentPatchIII/VC/SA: Add GCC-compatible safebuffers equivalent
And switch to a common define for this attribute (this fixes
compile warnings on MinGW GCC)
2024-11-07 13:39:54 +02:00
Echo J
743fedfed2 Use reinterpret_cast for function pointer casts
MSVC (wrongly) allows those casts to succeed with static_cast:
https://stackoverflow.com/questions/74002657/why-cant-i-static-cast-a-void-to-a-pointer-to-function
(so adjust those casts for better compiler compatibility including MinGW GCC)
2024-11-07 13:38:07 +02:00
Echo J
a14472a16d Set Windows defines earlier
This avoids compile warnings on MinGW GCC (because standard C++
headers eventually import the Windows stuff)
2024-11-07 13:38:07 +02:00
Echo J
661336ecc9 Use lowercase names for Windows headers
This fixes missing header issues on a case-sensitive filesystem
with MinGW GCC
2024-11-07 13:37:56 +02:00
25 changed files with 568 additions and 135 deletions

View file

@ -1,3 +1,3 @@
LIBRARY DDRAW
EXPORTS
DirectDrawCreateEx=_DirectDrawCreateEx@16 @10
DirectDrawCreateEx=DirectDrawCreateEx@16 @10

View file

@ -4,8 +4,8 @@
#include <windows.h>
#include <stdio.h>
#include <Shlwapi.h>
#include <ShlObj.h>
#include <shlwapi.h>
#include <shlobj.h>
#include "Utils/MemoryMgr.h"
#include "Utils/Patterns.h"
#include "Utils/ScopedUnprotect.hpp"
@ -197,7 +197,7 @@ static bool PatchIAT()
static bool PatchIAT_ByPointers()
{
pOrgSystemParametersInfoA = SystemParametersInfoA;
memcpy( orgCode, pOrgSystemParametersInfoA, sizeof(orgCode) );
memcpy( orgCode, reinterpret_cast<void*>(pOrgSystemParametersInfoA), sizeof(orgCode) );
Memory::VP::InjectHook( pOrgSystemParametersInfoA, SystemParametersInfoA_OverwritingHook, Memory::HookType::Jump );
return true;
}

View file

@ -34,7 +34,7 @@ namespace HandlingNameLoadFix
// ============= Corona lines rendering fix =============
namespace CoronaLinesFix
{
static decltype(RwIm2DRenderLine)* orgRwIm2DRenderLine;
static RwIm2DRenderLineFunction orgRwIm2DRenderLine;
static RwBool RenderLine_SetRecipZ( RwIm2DVertex *vertices, RwInt32 numVertices, RwInt32 vert1, RwInt32 vert2 )
{
const RwReal nearScreenZ = RwIm2DGetNearScreenZ();

View file

@ -2,6 +2,17 @@
#include <cstdint>
// Workaround for old MSVC inline function bugs
#if defined(_MSC_VER) && _MSC_VER < 1930
#define STATIC_INLINE static
#else
#define STATIC_INLINE static inline
#endif
#define RwEngineInstance (*rwengine)
extern "C" void** rwengine;
namespace ExtraCompSpecularity
{
void ReadExtraCompSpecularityExceptions(const wchar_t* pPath);

View file

@ -1,22 +1,20 @@
#include "Common_ddraw.h"
#define WIN32_LEAN_AND_MEAN
#define WINVER 0x0501
#define _WIN32_WINNT 0x0501
#define NOMINMAX
#include "Common_ddraw.h"
#include <windows.h>
#include <Shlwapi.h>
#include <ShlObj.h>
#include <shlwapi.h>
#include <shlobj.h>
#include "Utils/MemoryMgr.h"
#include "Utils/Patterns.h"
#pragma comment(lib, "shlwapi.lib")
extern char** ppUserFilesDir;
namespace Common {
char* GetMyDocumentsPath()
{

View file

@ -2,6 +2,8 @@
#include <cstdint>
extern char** ppUserFilesDir;
namespace Common
{
namespace Patches

View file

@ -1,11 +1,11 @@
#include "Desktop.h"
#define WIN32_LEAN_AND_MEAN
#define WINVER 0x0501
#define _WIN32_WINNT 0x0501
#define NOMINMAX
#include "Desktop.h"
#include <windows.h>
std::pair<uint32_t, uint32_t> GetDesktopResolution()

View file

@ -1,5 +1,3 @@
#include "FriendlyMonitorNames.h"
// This API is Win7 only, so make sure we use dynamic imports
#define WIN32_LEAN_AND_MEAN
@ -7,6 +5,8 @@
#define WINVER 0x0602
#define _WIN32_WINNT 0x0602
#include "FriendlyMonitorNames.h"
#include <windows.h>
#include <memory>

View file

@ -6,6 +6,13 @@
#include <rwcore.h>
// FIXME: Common.h might be a better place for this (but SA doesn't include it)
#ifdef _MSC_VER
#define NOBUFFERCHECKS __declspec(safebuffers)
#else
#define NOBUFFERCHECKS __attribute__((optimize("-fno-stack-protector")))
#endif
constexpr double RAD_TO_DEG (180.0/M_PI);
constexpr double DEG_TO_RAD (M_PI/180.0);

View file

@ -1,8 +1,9 @@
#include "ParseUtils.hpp"
#define WIN32_LEAN_AND_MEAN
#define NOMINMAX
#include <Windows.h>
#include "ParseUtils.hpp"
#include <windows.h>
static std::string WcharToUTF8(std::wstring_view str)
{

View file

@ -1,8 +1,6 @@
#include "Utils/MemoryMgr.h"
#include "Utils/Patterns.h"
#define RwEngineInstance (*rwengine)
#include <rwcore.h>
#include "RWGTA.h"
@ -52,6 +50,7 @@ void RwD3D8GetRenderState(RwUInt32 state, void* value)
fnRwD3D8GetRenderState(state, value);
}
#ifndef RwIm2DGetNearScreenZ
RwReal RwIm2DGetNearScreenZ()
{
return RWSRCGLOBAL(dOpenDevice).zBufferNear;
@ -66,6 +65,7 @@ RwBool RwRenderStateSet(RwRenderState state, void *value)
{
return RWSRCGLOBAL(dOpenDevice).fpRenderStateSet(state, value);
}
#endif
// Unreachable stub
RwBool RwMatrixDestroy(RwMatrix* /*mpMat*/) { assert(!"Unreachable!"); return TRUE; }
@ -78,19 +78,19 @@ bool RWGTA::Patches::TryLocateRwD3D8() try
auto pfnRwD3D8SetRenderState = [] {
try {
// Everything except for III Steam
return static_cast<decltype(RwD3D8SetRenderState)*>(get_pattern("39 0C C5 ? ? ? ? 74 31", -8));
return reinterpret_cast<decltype(RwD3D8SetRenderState)*>(get_pattern("39 0C C5 ? ? ? ? 74 31", -8));
} catch (const hook::txn_exception&) {
// III Steam
return static_cast<decltype(RwD3D8SetRenderState)*>(get_pattern("8B 0C C5 ? ? ? ? 3B CA", -8));
return reinterpret_cast<decltype(RwD3D8SetRenderState)*>(get_pattern("8B 0C C5 ? ? ? ? 3B CA", -8));
}
}();
auto pfnRwD3D8GetRenderState = [] {
try {
// Everything except for III Steam
return static_cast<decltype(RwD3D8GetRenderState)*>(get_pattern("8B 0C C5 ? ? ? ? 89 0A C3", -8));
return reinterpret_cast<decltype(RwD3D8GetRenderState)*>(get_pattern("8B 0C C5 ? ? ? ? 89 0A C3", -8));
} catch (const hook::txn_exception&) {
// III Steam
return static_cast<decltype(RwD3D8GetRenderState)*>(get_pattern("8B 04 C5 ? ? ? ? 89 02 C3", -8));
return reinterpret_cast<decltype(RwD3D8GetRenderState)*>(get_pattern("8B 04 C5 ? ? ? ? 89 02 C3", -8));
}
}();

View file

@ -1,5 +1,9 @@
#pragma once
#define RwEngineInstance (*rwengine)
extern void** rwengine;
namespace RWGTA::Patches
{
bool TryLocateRwD3D8();

View file

@ -1,9 +1,13 @@
#include "SVF.h"
#include <cstdint>
#include <algorithm>
#include <map>
#ifndef _stricmp
#include <cstring>
#define _stricmp strcasecmp
#endif
namespace SVF
{
Feature GetFeatureFromName( const char* featureName )

View file

@ -1,5 +1,6 @@
#pragma once
#include <cstdint>
#include <functional>
#include <string>

View file

@ -1,7 +1,7 @@
#include "TheFLAUtils.h"
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include <windows.h>
#include "Utils/ModuleList.hpp"

View file

@ -1,6 +1,8 @@
#ifndef __TIMER
#define __TIMER
#include <cmath>
class CTimer
{
public:

View file

@ -1,6 +1,7 @@
#pragma once
#include <cstdint>
#include <functional>
#include "Maths.h"
#include <rwcore.h>

View file

@ -12,7 +12,7 @@
#include <array>
#include <memory>
#include <Shlwapi.h>
#include <shlwapi.h>
#include "Utils/ModuleList.hpp"
#include "Utils/Patterns.h"
@ -196,36 +196,70 @@ void ResetMousePos()
void __declspec(naked) M16StatsFix()
{
#ifdef _MSC_VER
_asm
{
add eax, 34h
add ebx, 34h
add eax, 0x34
add ebx, 0x34
mov ecx, [InstantHitsFiredByPlayer]
inc [ecx]
retn
inc dword ptr [ecx]
ret
}
#elif defined(__GNUC__) || defined(__clang__)
__asm__ volatile
(
"add eax, 0x34\n"
"add ebx, 0x34\n"
"mov ecx, [%[InstantHitsFiredByPlayer]]\n"
"inc dword ptr [ecx]\n"
"ret\n"
:: [InstantHitsFiredByPlayer] "m" (InstantHitsFiredByPlayer)
);
#endif
}
void __declspec(naked) HeadlightsFix()
{
static const float fMinusOne = -1.0f;
#ifdef _MSC_VER
_asm
{
fld [esp+708h-690h]
fld dword ptr [esp+0x708-0x690]
fcomp fMinusOne
fnstsw ax
and ah, 5
cmp ah, 1
jnz HeadlightsFix_DontLimit
fld fMinusOne
fstp [esp+708h-690h]
fstp dword ptr [esp+0x708-0x690]
HeadlightsFix_DontLimit:
fld [esp+708h-690h]
fld dword ptr [esp+0x708-0x690]
fabs
fld st
jmp [HeadlightsFix_JumpBack]
}
#elif defined(__GNUC__) || defined(__clang__)
__asm__ volatile
(
"fld dword ptr [esp+0x708-0x690]\n"
"fcomp %[fMinusOne]\n"
"fnstsw ax\n"
"and ah, 5\n"
"cmp ah, 1\n"
"jnz HeadlightsFix_DontLimit\n"
"fld %0\n"
"fstp dword ptr [esp+0x708-0x690]\n"
"HeadlightsFix_DontLimit:\n"
"fld dword ptr [esp+0x708-0x690]\n"
"fabs\n"
"fld st\n"
"jmp [%[HeadlightsFix_JumpBack]]\n"
:: [fMinusOne] "m" (fMinusOne),
[HeadlightsFix_JumpBack] "m" (HeadlightsFix_JumpBack)
);
#endif
}
static float fShadowXSize, fShadowYSize;
@ -314,35 +348,64 @@ float FixedRefValue()
void __declspec(naked) SubtitlesShadowFix()
{
#ifdef _MSC_VER
_asm
{
push eax
call Recalculate
fadd [esp+50h+8]
fadd dword ptr [esp+0x50+8]
fadd [fShadowYSize]
jmp SubtitlesShadowFix_JumpBack
}
#elif defined(__GNUC__) || defined(__clang__)
__asm__ volatile
(
"push eax\n"
"call %[Recalculate]\n"
"fadd dword ptr [esp+0x50+8]\n"
"fadd [%[fShadowYSize]]\n"
"jmp %[SubtitlesShadowFix_JumpBack]\n"
:: [Recalculate] "i" (Recalculate),
[fShadowYSize] "m" (fShadowYSize),
[SubtitlesShadowFix_JumpBack] "m" (SubtitlesShadowFix_JumpBack)
);
#endif
}
void __declspec(naked) III_SensResetFix()
{
#ifdef _MSC_VER
_asm
{
mov ecx, 3A76h
mov ecx, 0x3A76
mov edi, ebp
fld dword ptr [ebp+194h]
fld dword ptr [ebp+198h]
fld dword ptr [ebp+0x194]
fld dword ptr [ebp+0x198]
rep stosd
fstp dword ptr [ebp+198h]
fstp dword ptr [ebp+194h]
retn
fstp dword ptr [ebp+0x198]
fstp dword ptr [ebp+0x194]
ret
}
#elif defined(__GNUC__) || defined(__clang__)
__asm__ volatile
(
"mov ecx, 0x3A76\n"
"mov edi, ebp\n"
"fld dword ptr [ebp+0x194]\n"
"fld dword ptr [ebp+0x198]\n"
"rep stosd\n"
"fstp dword ptr [ebp+0x198]\n"
"fstp dword ptr [ebp+0x194]\n"
"ret\n"
);
#endif
}
static void* RadarBoundsCheckCoordBlip_JumpBack = AddressByVersion<void*>(0x4A55B8, 0x4A56A8, 0x4A5638);
static void* RadarBoundsCheckCoordBlip_Count = AddressByVersion<void*>(0x4A55AF, 0x4A569F, 0x4A562F);
void __declspec(naked) RadarBoundsCheckCoordBlip()
{
#ifdef _MSC_VER
_asm
{
mov edx, dword ptr [RadarBoundsCheckCoordBlip_Count]
@ -355,13 +418,32 @@ void __declspec(naked) RadarBoundsCheckCoordBlip()
OutOfBounds:
or eax, -1
fcompp
retn
ret
}
#elif defined(__GNUC__) || defined(__clang__)
__asm__ volatile
(
"mov edx, dword ptr [%[RadarBoundsCheckCoordBlip_Count]]\n"
"cmp cl, byte ptr [edx]\n"
"jnb OutOfBounds\n"
"mov edx, ecx\n"
"mov eax, [esp+4]\n"
"jmp %[RadarBoundsCheckCoordBlip_JumpBack]\n"
"OutOfBounds:\n"
"or eax, -1\n"
"fcompp\n"
"ret\n"
:: [RadarBoundsCheckCoordBlip_Count] "m" (RadarBoundsCheckCoordBlip_Count),
[RadarBoundsCheckCoordBlip_JumpBack] "m" (RadarBoundsCheckCoordBlip_JumpBack)
);
#endif
}
static void* RadarBoundsCheckEntityBlip_JumpBack = AddressByVersion<void*>(0x4A565E, 0x4A574E, 0x4A56DE);
void __declspec(naked) RadarBoundsCheckEntityBlip()
{
#ifdef _MSC_VER
_asm
{
mov edx, dword ptr [RadarBoundsCheckCoordBlip_Count]
@ -373,14 +455,31 @@ void __declspec(naked) RadarBoundsCheckEntityBlip()
OutOfBounds:
or eax, -1
retn
ret
}
#elif defined(__GNUC__) || defined(__clang__)
__asm__ volatile
(
"mov edx, dword ptr [%[RadarBoundsCheckCoordBlip_Count]]\n"
"cmp cl, byte ptr [edx]\n"
"jnb OutOfBounds2\n"
"mov edx, ecx\n"
"mov eax, [esp+4]\n"
"jmp %[RadarBoundsCheckEntityBlip_JumpBack]\n"
"OutOfBounds2:\n"
"or eax, -1\n"
"ret\n"
:: [RadarBoundsCheckCoordBlip_Count] "m" (RadarBoundsCheckCoordBlip_Count),
[RadarBoundsCheckEntityBlip_JumpBack] "m" (RadarBoundsCheckEntityBlip_JumpBack)
);
#endif
}
extern char** ppUserFilesDir = AddressByVersion<char**>(0x580C16, 0x580F66, 0x580E66);
char** ppUserFilesDir = AddressByVersion<char**>(0x580C16, 0x580F66, 0x580E66);
static LARGE_INTEGER FrameTime;
__declspec(safebuffers) int32_t GetTimeSinceLastFrame()
NOBUFFERCHECKS int32_t GetTimeSinceLastFrame()
{
LARGE_INTEGER curTime;
QueryPerformanceCounter(&curTime);
@ -413,9 +512,10 @@ unsigned int __cdecl AutoPilotTimerCalculation_III(unsigned int nTimer, int nSca
void __declspec(naked) AutoPilotTimerFix_III()
{
#ifdef _MSC_VER
_asm {
push dword ptr[esp + 0x4]
push dword ptr[ebx + 0x10]
push dword ptr [esp + 0x4]
push dword ptr [ebx + 0x10]
push eax
call AutoPilotTimerCalculation_III
add esp, 0xC
@ -424,8 +524,25 @@ void __declspec(naked) AutoPilotTimerFix_III()
pop ebp
pop esi
pop ebx
retn 4
ret 4
}
#elif defined(__GNUC__) || defined(__clang__)
__asm__ volatile
(
"push dword ptr [esp + 0x4]\n"
"push dword ptr [ebx + 0x10]\n"
"push eax\n"
"call %[AutoPilotTimerCalculation_III]\n"
"add esp, 0xC\n"
"mov [ebx + 0xC], eax\n"
"add esp, 0x28\n"
"pop ebp\n"
"pop esi\n"
"pop ebx\n"
"ret 4\n"
:: [AutoPilotTimerCalculation_III] "i" (AutoPilotTimerCalculation_III)
);
#endif
}
namespace ZeroAmmoFix
@ -542,7 +659,7 @@ namespace Localization
// ============= Call cDMAudio::IsAudioInitialised before adding one shot sounds, like in VC =============
namespace AudioInitializedFix
{
auto IsAudioInitialised = static_cast<bool(*)()>(Memory::ReadCallFrom( hook::get_pattern( "E8 ? ? ? ? 84 C0 74 ? 0F B7 47 10" ) ));
auto IsAudioInitialised = reinterpret_cast<bool(*)()>(Memory::ReadCallFrom( hook::get_pattern( "E8 ? ? ? ? 84 C0 74 ? 0F B7 47 10" ) ));
void* (*operatorNew)(size_t size);
void* operatorNew_InitializedCheck( size_t size )
@ -580,19 +697,35 @@ namespace RemoveDriverStatusFix
{
// if (m_nStatus != STATUS_WRECKED)
// m_nStatus = STATUS_ABANDONED;
#ifdef _MSC_VER
_asm
{
mov ah, [ecx+50h]
mov ah, [ecx+0x50]
mov al, ah
and ah, 0F8h
cmp ah, 28h
and ah, 0xF8
cmp ah, 0x28
je DontSetStatus
and al, 7
or al, 20h
or al, 0x20
DontSetStatus:
retn
ret
}
#elif defined(__GNUC__) || defined(__clang__)
__asm__ volatile
(
"mov ah, [ecx+0x50]\n"
"mov al, ah\n"
"and ah, 0xF8\n"
"cmp ah, 0x28\n"
"je DontSetStatus\n"
"and al, 7\n"
"or al, 0x20\n"
"DontSetStatus:\n"
"ret\n"
);
#endif
}
}
@ -625,16 +758,30 @@ namespace EvasiveDiveFix
__declspec(naked) void CalculateAngle_Hook()
{
#ifdef _MSC_VER
_asm
{
push dword ptr [esi+7Ch]
push dword ptr [esi+78h]
push dword ptr [esi+0x7C]
push dword ptr [esi+0x78]
call CalculateAngle
add esp, 8
mov ecx, ebp
retn
ret
}
#elif defined(__GNUC__) || defined(__clang__)
__asm__ volatile
(
"push dword ptr [esi+0x7C]\n"
"push dword ptr [esi+0x78]\n"
"call %[CalculateAngle]\n"
"add esp, 8\n"
"mov ecx, ebp\n"
"ret\n"
:: [CalculateAngle] "i" (CalculateAngle)
);
#endif
}
}
@ -647,36 +794,69 @@ namespace NullTerminatedLines
static void* orgSscanf_LoadPath;
__declspec(naked) static void sscanf1_LoadPath_Terminate()
{
#ifdef _MSC_VER
_asm
{
mov eax, [esp+4]
mov byte ptr [eax+ecx], 0
jmp [orgSscanf_LoadPath]
}
#elif defined(__GNUC__) || defined(__clang__)
__asm__ volatile
(
"mov eax, [esp+4]\n"
"mov byte ptr [eax+ecx], 0\n"
"jmp [%[orgSscanf_LoadPath]]\n"
:: [orgSscanf_LoadPath] "m" (orgSscanf_LoadPath)
);
#endif
}
static void* orgSscanf1;
__declspec(naked) static void sscanf1_Terminate()
{
#ifdef _MSC_VER
_asm
{
mov eax, [esp+4]
mov byte ptr [eax+ecx], 0
jmp [orgSscanf1]
}
#elif defined(__GNUC__) || defined(__clang__)
__asm__ volatile
(
"mov eax, [esp+4]\n"
"mov byte ptr [eax+ecx], 0\n"
"jmp [%[orgSscanf1]]\n"
:: [orgSscanf1] "m" (orgSscanf1)
);
#endif
}
__declspec(naked) static void ReadTrackFile_Terminate()
{
#ifdef _MSC_VER
_asm
{
mov ecx, [gString]
mov byte ptr [ecx+edx], 0
mov ecx, [esi]
inc ebp
add ecx, [esp+0ACh-98h]
retn
add ecx, [esp+0xAC-0x98]
ret
}
#elif defined(__GNUC__) || defined(__clang__)
__asm__ volatile
(
"mov ecx, [%[gString]]\n"
"mov byte ptr [ecx+edx], 0\n"
"mov ecx, [esi]\n"
"inc ebp\n"
"add ecx, [esp+0xAC-0x98]\n"
"ret\n"
:: [gString] "m" (gString)
);
#endif
}
}
@ -703,17 +883,33 @@ namespace DodoKeyboardControls
static void* (*orgFindPlayerVehicle)();
__declspec(naked) static void FindPlayerVehicle_DodoCheck()
{
#ifdef _MSC_VER
_asm
{
call [orgFindPlayerVehicle]
mov ecx, [bAllDodosCheat]
cmp byte ptr [ecx], 0
je CheatDisabled
mov byte ptr [esp+1Ch-14h], 1
mov byte ptr [esp+0x1C-0x14], 1
CheatDisabled:
retn
ret
}
#elif defined(__GNUC__) || defined(__clang__)
__asm__ volatile
(
"call [%[orgFindPlayerVehicle]]\n"
"mov ecx, [%[bAllDodosCheat]]\n"
"cmp byte ptr [ecx], 0\n"
"je CheatDisabled\n"
"mov byte ptr [esp+0x1C-0x14], 1\n"
"CheatDisabled:\n"
"ret\n"
:: [orgFindPlayerVehicle] "m" (orgFindPlayerVehicle),
[bAllDodosCheat] "m" (bAllDodosCheat)
);
#endif
}
}
@ -770,6 +966,7 @@ namespace GenerateNewPickup_ReuseObjectFix
__declspec(naked) void GiveUsAPickUpObject_CleanUpObject()
{
#ifdef _MSC_VER
_asm
{
mov eax, [pPickupObject]
@ -795,6 +992,36 @@ namespace GenerateNewPickup_ReuseObjectFix
NoPickup:
jmp [orgGiveUsAPickUpObject]
}
#elif defined(__GNUC__) || defined(__clang__)
__asm__ volatile
(
"mov eax, [%[pPickupObject]]\n"
"add eax, ebp\n"
"mov eax, [eax]\n"
"test eax, eax\n"
"jz NoPickup\n"
"push edi\n"
"mov edi, eax\n"
"push edi\n"
"call [%[WorldRemove]]\n"
"add esp, 4\n"
// Call dtor
"mov ecx, edi\n"
"mov eax, [edi]\n"
"push 1\n"
"call dword ptr [eax]\n"
"pop edi\n"
"NoPickup:\n"
"jmp [%[orgGiveUsAPickUpObject]]\n"
:: [pPickupObject] "m" (pPickupObject),
[WorldRemove] "m" (WorldRemove),
[orgGiveUsAPickUpObject] "m" (orgGiveUsAPickUpObject)
);
#endif
}
}
@ -1027,7 +1254,7 @@ namespace SlidingTextsScalingFixes
static inline float** pHorShadowValue;
template<std::size_t Index>
static void (*orgPrintString)(float,float,const wchar_t*);
STATIC_INLINE void (*orgPrintString)(float,float,const wchar_t*);
template<std::size_t Index>
static void PrintString_Slide(float fX, float fY, const wchar_t* pText)
@ -1054,7 +1281,7 @@ namespace SlidingTextsScalingFixes
static inline bool bSlidingEnabled = false;
template<std::size_t Index>
static void (*orgPrintString)(float,float,const wchar_t*);
STATIC_INLINE void (*orgPrintString)(float,float,const wchar_t*);
template<std::size_t Index>
static void PrintString_Slide(float fX, float fY, const wchar_t* pText)

View file

@ -2,7 +2,7 @@
#define __AUDIOHARDWARE
// IStream
#include <Objidl.h>
#include <objidl.h>
enum eDecoderType
{

View file

@ -3,8 +3,8 @@
#include "AudioHardwareSA.h"
// libflac
#include "FLAC\stream_decoder.h"
#include "FLAC\metadata.h"
#include "FLAC/stream_decoder.h"
#include "FLAC/metadata.h"
class CAEFLACDecoder final : public CAEStreamingDecoder
{

View file

@ -2,6 +2,7 @@
#define __GENERAL
#include <stdint.h>
#include "Common.h"
#include "TheFLAUtils.h"
class CSimpleTransform

View file

@ -3,9 +3,9 @@
#include <algorithm>
#include <array>
#include <d3d9.h>
#include <Shlwapi.h>
#include <ShlObj.h>
#include <ShellAPI.h>
#include <shlwapi.h>
#include <shlobj.h>
#include <shellapi.h>
#include <cinttypes>
#include "ScriptSA.h"
@ -950,7 +950,7 @@ char* GetMyDocumentsPathSA()
}
static LARGE_INTEGER FrameTime;
__declspec(safebuffers) int32_t GetTimeSinceLastFrame()
NOBUFFERCHECKS int32_t GetTimeSinceLastFrame()
{
LARGE_INTEGER curTime;
QueryPerformanceCounter(&curTime);
@ -2851,7 +2851,7 @@ namespace CreditsScalingFixes
static const unsigned int FIXED_RES_HEIGHT_SCALE = 448;
template<std::size_t Index>
static void (*orgPrintString)(float,float,const wchar_t*);
STATIC_INLINE void (*orgPrintString)(float,float,const wchar_t*);
template<std::size_t Index>
static void PrintString_ScaleY(float fX, float fY, const wchar_t* pText)
@ -2888,7 +2888,7 @@ namespace SlidingTextsScalingFixes
static inline bool bSlidingEnabled = false;
template<std::size_t Index>
static void (*orgPrintString)(float,float,const wchar_t*);
STATIC_INLINE void (*orgPrintString)(float,float,const wchar_t*);
template<std::size_t Index>
static void PrintString_Slide(float fX, float fY, const wchar_t* pText)
@ -2898,7 +2898,7 @@ namespace SlidingTextsScalingFixes
}
template<std::size_t Index>
static void (*orgSetRightJustifyWrap)(float wrap);
STATIC_INLINE void (*orgSetRightJustifyWrap)(float wrap);
template<std::size_t Index>
static void SetRightJustifyWrap_Slide(float wrap)
@ -2915,7 +2915,7 @@ namespace SlidingTextsScalingFixes
static inline bool bSlidingEnabled = false;
template<std::size_t Index>
static void (*orgPrintString)(float,float,const wchar_t*);
STATIC_INLINE void (*orgPrintString)(float,float,const wchar_t*);
template<std::size_t Index>
static void PrintString_Slide(float fX, float fY, const wchar_t* pText)
@ -3961,7 +3961,7 @@ DarkVehiclesFix4_MakeItDark:
}
// 1.0 ONLY ENDS HERE
__declspec(safebuffers) static int _Timers_ftol_internal( double timer, double& remainder )
NOBUFFERCHECKS static int _Timers_ftol_internal( double timer, double& remainder )
{
double integral;
remainder = modf( timer + remainder, &integral );
@ -7626,7 +7626,7 @@ void Patch_SA_NewBinaries_Common(HINSTANCE hInstance)
// Fixed escalators crash
try
{
orgEscalatorsUpdate = static_cast<decltype(orgEscalatorsUpdate)>(get_pattern( "80 3D ? ? ? ? ? 74 23 56" ));
orgEscalatorsUpdate = reinterpret_cast<decltype(orgEscalatorsUpdate)>(get_pattern( "80 3D ? ? ? ? ? 74 23 56" ));
auto updateEscalators = get_pattern("80 3D ? ? ? ? ? 74 22 56");
auto removeEscalatorsForEntity = pattern( "80 7E F5 00 74 56" ).get_one();
@ -8485,7 +8485,7 @@ void Patch_SA_NewBinaries_Common(HINSTANCE hInstance)
ppRWD3D9 = *get_pattern<IDirect3D9**>("33 ED A3 ? ? ? ? 3B C5", 2 + 1);
FrontEndMenuManager = *get_pattern<void**>("50 50 68 ? ? ? ? B9 ? ? ? ? E8", 7 + 1); // This has 2 identical matches, we just need one
orgGetDocumentsPath = static_cast<char*(*)()>(get_pattern( "8D 45 FC 50 68 19 00 02 00", -6 ));
orgGetDocumentsPath = reinterpret_cast<char*(*)()>(get_pattern( "8D 45 FC 50 68 19 00 02 00", -6 ));
Patch(dialogBoxParam, &pDialogBoxParamA_New);
Patch(setFocus, &pSetFocus_NOP);

View file

@ -302,7 +302,7 @@ public:
private:
template<std::size_t Index>
static void (CVehicle::*orgDoHeadLightBeam)(int type, CMatrix& m, bool right);
STATIC_INLINE void (CVehicle::*orgDoHeadLightBeam)(int type, CMatrix& m, bool right);
template<std::size_t Index>
void DoHeadLightBeam_LightBeamFixSaveObj(int type, CMatrix& m, bool right)
@ -337,7 +337,7 @@ public:
public:
template<std::size_t Index>
static void (CAutomobile::*orgAutomobilePreRender)();
STATIC_INLINE void (CAutomobile::*orgAutomobilePreRender)();
template<std::size_t Index>
void PreRender_SilentPatch()
@ -352,7 +352,7 @@ public:
void HideDestroyedWheels_SilentPatch(void (CAutomobile::*spawnFlyingComponentCB)(int, unsigned int), int nodeID, unsigned int modelID);
template<std::size_t Index>
static void (CAutomobile::*orgSpawnFlyingComponent)(int, unsigned int);
STATIC_INLINE void (CAutomobile::*orgSpawnFlyingComponent)(int, unsigned int);
template<std::size_t Index>
void SpawnFlyingComponent_HideWheels(int nodeID, unsigned int modelID)
@ -448,7 +448,7 @@ private:
private:
template<std::size_t Index>
static CVehicle* (CStoredCar::*orgRestoreCar)();
STATIC_INLINE CVehicle* (CStoredCar::*orgRestoreCar)();
template<std::size_t Index>
CVehicle* RestoreCar_SilentPatch()

View file

@ -1,5 +1,6 @@
#pragma once
#define _USE_MATH_DEFINES
#include <rwcore.h>
#include <rpworld.h>

View file

@ -16,7 +16,7 @@
#include <array>
#include <memory>
#include <Shlwapi.h>
#include <shlwapi.h>
#include <time.h>
#include "Utils/ModuleList.hpp"
@ -356,7 +356,7 @@ namespace RadarTraceOutlineFixes
}
template<std::size_t Index>
static void (*orgShowRadarTraceWithHeight)(float, float, unsigned int, unsigned char, unsigned char, unsigned char, unsigned char, unsigned char);
STATIC_INLINE void (*orgShowRadarTraceWithHeight)(float, float, unsigned int, unsigned char, unsigned char, unsigned char, unsigned char, unsigned char);
template<std::size_t Index>
static void ShowRadarTraceWithHeight_RecalculatePositions(float a1, float a2, unsigned int a3, unsigned char a4, unsigned char a5, unsigned char a6, unsigned char a7, unsigned char a8)
@ -456,7 +456,7 @@ namespace SlidingTextsScalingFixes
static inline bool bSlidingEnabled = false;
template<std::size_t Index>
static void (*orgPrintString)(float,float,const wchar_t*);
STATIC_INLINE void (*orgPrintString)(float,float,const wchar_t*);
template<std::size_t Index>
static void PrintString_Slide(float fX, float fY, const wchar_t* pText)
@ -466,7 +466,7 @@ namespace SlidingTextsScalingFixes
}
template<std::size_t Index>
static void (*orgSetRightJustifyWrap)(float wrap);
STATIC_INLINE void (*orgSetRightJustifyWrap)(float wrap);
template<std::size_t Index>
static void SetRightJustifyWrap_Slide(float wrap)
@ -483,7 +483,7 @@ namespace SlidingTextsScalingFixes
static inline bool bSlidingEnabled = false;
template<std::size_t Index>
static void (*orgPrintString)(float,float,const wchar_t*);
STATIC_INLINE void (*orgPrintString)(float,float,const wchar_t*);
template<std::size_t Index>
static void PrintString_Slide(float fX, float fY, const wchar_t* pText)
@ -671,10 +671,11 @@ float FixedRefValue()
void __declspec(naked) SubtitlesShadowFix()
{
#ifdef MSC_VER
_asm
{
mov [esp], eax
fild [esp]
fild dword ptr [esp]
push eax
lea eax, [esp+20h-18h]
push eax
@ -683,23 +684,56 @@ void __declspec(naked) SubtitlesShadowFix()
call Recalculate
jmp SubtitlesShadowFix_JumpBack
}
#elif defined(__GNUC__) || defined(__clang__)
__asm__ volatile
(
"mov [esp], eax\n"
"fild dword ptr [esp]\n"
"push eax\n"
"lea eax, [esp+0x20-0x18]\n"
"push eax\n"
"lea eax, [esp+0x24-0x14]\n"
"push eax\n"
"call %[Recalculate]\n"
"jmp %[SubtitlesShadowFix_JumpBack]\n"
:: [Recalculate] "i" (Recalculate),
[SubtitlesShadowFix_JumpBack] "m" (SubtitlesShadowFix_JumpBack)
);
#endif
}
// C-style wrapper for calling a C++ function in GCC-style inline assembly (the function signature is really important here)
RwFrame* __thiscall CVehicleModelInfo_GetExtrasFrame(CVehicleModelInfo* modelInfo, RpClump* clump)
{
return modelInfo->GetExtrasFrame(clump);
}
void __declspec(naked) CreateInstance_BikeFix()
{
#ifdef MSC_VER
_asm
{
push eax
mov ecx, ebp
call CVehicleModelInfo::GetExtrasFrame
retn
ret
}
#elif defined(__GNUC__) || defined(__clang__)
__asm__ volatile
(
"push eax\n"
"mov ecx, ebp\n"
"call %[CVehicleModelInfo_GetExtrasFrame]\n"
"ret\n"
:: [CVehicleModelInfo_GetExtrasFrame] "i" (CVehicleModelInfo_GetExtrasFrame)
);
#endif
}
extern char** ppUserFilesDir = AddressByVersion<char**>(0x6022AA, 0x60228A, 0x601ECA);
char** ppUserFilesDir = AddressByVersion<char**>(0x6022AA, 0x60228A, 0x601ECA);
static LARGE_INTEGER FrameTime;
__declspec(safebuffers) int32_t GetTimeSinceLastFrame()
NOBUFFERCHECKS int32_t GetTimeSinceLastFrame()
{
LARGE_INTEGER curTime;
QueryPerformanceCounter(&curTime);
@ -733,9 +767,11 @@ unsigned int __cdecl AutoPilotTimerCalculation_VC(unsigned int nTimer, int nScal
void __declspec(naked) AutoPilotTimerFix_VC()
{
_asm {
push dword ptr[esp + 0xC]
push dword ptr[ebx + 0x10]
#ifdef MSC_VER
_asm
{
push dword ptr [esp + 0xC]
push dword ptr [ebx + 0x10]
push eax
call AutoPilotTimerCalculation_VC
add esp, 0xC
@ -743,8 +779,24 @@ void __declspec(naked) AutoPilotTimerFix_VC()
add esp, 0x30
pop ebp
pop ebx
retn 4
ret 4
}
#elif defined(__GNUC__) || defined(__clang__)
__asm__ volatile
(
"push dword ptr [esp + 0xC]\n"
"push dword ptr [ebx + 0x10]\n"
"push eax\n"
"call %[AutoPilotTimerCalculation_VC]\n"
"add esp, 0xC\n"
"mov [ebx + 0xC], eax\n"
"add esp, 0x30\n"
"pop ebp\n"
"pop ebx\n"
"ret 4\n"
:: [AutoPilotTimerCalculation_VC] "i" (AutoPilotTimerCalculation_VC)
);
#endif
}
@ -865,22 +917,41 @@ namespace SirenSwitchingFix
{
void __declspec(naked) IsFBIRanchOrFBICar()
{
#ifdef MSC_VER
_asm
{
mov dword ptr [esi+1Ch], 1Ch
mov dword ptr [esi+0x1C], 0x1C
// al = 0 - high pitched siren
// al = 1 - normal siren
cmp dword ptr [ebp+14h], 90 // fbiranch
cmp dword ptr [ebp+0x14], 90 // fbiranch
je IsFBIRanchOrFBICar_HighPitchSiren
cmp dword ptr [ebp+14h], 17 // fbicar
cmp dword ptr [ebp+0x14], 17 // fbicar
setne al
retn
ret
IsFBIRanchOrFBICar_HighPitchSiren:
xor al, al
retn
ret
}
#elif defined(__GNUC__) || defined(__clang__)
__asm__ volatile
(
"mov dword ptr [esi+0x1C], 0x1C\n"
// al = 0 - high pitched siren
// al = 1 - normal siren
"cmp dword ptr [ebp+0x14], 90\n" // fbiranch
"je IsFBIRanchOrFBICar_HighPitchSiren\n"
"cmp dword ptr [ebp+0x14], 17\n" // fbicar
"setne al\n"
"ret\n"
"IsFBIRanchOrFBICar_HighPitchSiren:\n"
"xor al, al\n"
"ret\n"
);
#endif
}
}
@ -949,19 +1020,35 @@ namespace RemoveDriverStatusFix
{
// if (m_nStatus != STATUS_WRECKED)
// m_nStatus = STATUS_ABANDONED;
#ifdef MSC_VER
_asm
{
mov cl, [ebx+50h]
mov cl, [ebx+0x50]
mov al, cl
and cl, 0F8h
cmp cl, 28h
and cl, 0xF8
cmp cl, 0x28
je DontSetStatus
and al, 7
or al, 20h
or al, 0x20
DontSetStatus:
retn
ret
}
#elif defined(__GNUC__) || defined(__clang__)
__asm__ volatile
(
"mov cl, [ebx+0x50]\n"
"mov al, cl\n"
"and cl, 0xF8\n"
"cmp cl, 0x28\n"
"je DontSetStatus\n"
"and al, 7\n"
"or al, 0x20\n"
"DontSetStatus:\n"
"ret\n"
);
#endif
}
}
@ -1034,12 +1121,22 @@ namespace NullTerminatedLines
static void* orgSscanf_LoadPath;
__declspec(naked) static void sscanf1_LoadPath_Terminate()
{
#ifdef MSC_VER
_asm
{
mov eax, [esp+4]
mov byte ptr [eax+ecx], 0
jmp [orgSscanf_LoadPath]
}
#elif defined(__GNUC__) || defined(__clang__)
__asm__ volatile
(
"mov eax, [esp+4]\n"
"mov byte ptr [eax+ecx], 0\n"
"jmp [%[orgSscanf_LoadPath]]\n"
:: [orgSscanf_LoadPath] "m" (orgSscanf_LoadPath)
);
#endif
}
}
@ -1064,21 +1161,31 @@ namespace PickupEffectsFixes
{
__declspec(naked) static void PickUpEffects_BigDollarColor()
{
#ifdef MSC_VER
_asm
{
mov byte ptr [esp+184h-170h], 0
mov dword ptr [esp+184h-174h], 37
retn
mov byte ptr [esp+0x184-0x170], 0
mov dword ptr [esp+0x184-0x174], 37
ret
}
#elif defined(__GNUC__) || defined(__clang__)
__asm__ volatile
(
"mov byte ptr [esp+0x184-0x170], 0\n"
"mov dword ptr [esp+0x184-0x174], 37\n"
"ret\n"
);
#endif
}
__declspec(naked) static void PickUpEffects_Minigun2Glow()
{
#ifdef MSC_VER
_asm
{
cmp ecx, 294 // minigun2
jnz NotMinigun2
mov byte ptr [esp+184h-170h], 0
mov byte ptr [esp+0x184-0x170], 0
xor eax, eax
jmp Return
@ -1087,8 +1194,25 @@ namespace PickupEffectsFixes
Return:
mov ebx, ecx
retn
ret
}
#elif defined(__GNUC__) || defined(__clang__)
__asm__ volatile
(
"cmp ecx, 294\n" // minigun2
"jnz NotMinigun2\n"
"mov byte ptr [esp+0x184-0x170], 0\n"
"xor eax, eax\n"
"jmp Return\n"
"NotMinigun2:\n"
"lea eax, [ecx+1]\n"
"Return:\n"
"mov ebx, ecx\n"
"ret\n"
);
#endif
}
}
@ -1105,6 +1229,7 @@ namespace IsPlayerTargettingCharFix
__declspec(naked) static void IsPlayerTargettingChar_ExtraChecks()
{
// After this extra block of code, there is a jz Return, so set ZF to 0 here if this path is to be entered
#ifdef MSC_VER
_asm
{
test bl, bl
@ -1118,13 +1243,38 @@ namespace IsPlayerTargettingCharFix
jz ReturnToUpdateCompareFlag
CmpAndReturn:
cmp byte ptr [esp+11Ch-10Ch], 0
retn
cmp byte ptr [esp+0x11C-0x10C], 0
ret
ReturnToUpdateCompareFlag:
xor al, al
retn
ret
}
#elif defined(__GNUC__) || defined(__clang__)
__asm__ volatile
(
"test bl, bl\n"
"jnz ReturnToUpdateCompareFlag\n"
"mov eax, [%[bUseMouse3rdPerson]]\n"
"cmp byte ptr [eax], 0\n"
"jne CmpAndReturn\n"
"mov ecx, [%[TheCamera]]\n"
"call [%[Using1stPersonWeaponMode]]\n"
"test al, al\n"
"jz ReturnToUpdateCompareFlag\n"
"CmpAndReturn:\n"
"cmp byte ptr [esp+0x11C-0x10C], 0\n"
"ret\n"
"ReturnToUpdateCompareFlag:\n"
"xor al, al\n"
"ret\n"
:: [bUseMouse3rdPerson] "m" (bUseMouse3rdPerson),
[TheCamera] "m" (TheCamera),
[Using1stPersonWeaponMode] "m" (Using1stPersonWeaponMode)
);
#endif
}
}
@ -1210,13 +1360,24 @@ namespace SelectableBackfaceCulling
static void* EntityRender_Prologue_JumpBack;
__declspec(naked) static void __fastcall EntityRender_Original(CEntity*)
{
#ifdef MSC_VER
_asm
{
push ebx
mov ebx, ecx
cmp dword ptr [ebx+4Ch], 0
cmp dword ptr [ebx+0x4C], 0
jmp [EntityRender_Prologue_JumpBack]
}
#elif defined(__GNUC__) || defined(__clang__)
__asm__ volatile
(
"push ebx\n"
"mov ebx, ecx\n"
"cmp dword ptr [ebx+0x4C], 0\n"
"jmp [%[EntityRender_Prologue_JumpBack]]\n"
:: [EntityRender_Prologue_JumpBack] "m" (EntityRender_Prologue_JumpBack)
);
#endif
}
static bool ShouldDisableBackfaceCulling(const CEntity* entity)
@ -1392,14 +1553,26 @@ namespace TommyFistShakeWithWeapons
static __declspec(naked) void CheckWeaponGroupHook()
{
#ifdef MSC_VER
_asm
{
push dword ptr [eax]
call WeaponProhibitsFistShake
add esp, 4
test al, al
retn
ret
}
#elif defined(__GNUC__) || defined(__clang__)
__asm__ volatile
(
"push dword ptr [eax]\n"
"call %[WeaponProhibitsFistShake]\n"
"add esp, 4\n"
"test al, al\n"
"ret\n"
:: [WeaponProhibitsFistShake] "i" (WeaponProhibitsFistShake)
);
#endif
}
template<std::size_t Index>
@ -1875,7 +2048,7 @@ void InjectDelayedPatches_VC_Common( bool bHasDebugMenu, const wchar_t* wcModule
// Stuff to let us (re)initialize
static void (*HUDReInitialise)() = static_cast<decltype(HUDReInitialise)>(get_pattern("31 C0 53 0F EF C0 C6 05"));
static void (*HUDReInitialise)() = reinterpret_cast<decltype(HUDReInitialise)>(get_pattern("31 C0 53 0F EF C0 C6 05"));
// This pattern has 5 hits - first 2 are in Reinitialise, the rest is in Initialise
auto reinitialise1 = pattern("C7 05 ? ? ? ? 05 00 00 00 66 C7 05 ? ? ? ? 00 00 C7 05 ? ? ? ? 00 00 00 00").count(5);
@ -2758,7 +2931,7 @@ void Patch_VC_Common()
using namespace IsPlayerTargettingCharFix;
auto isPlayerTargettingChar = pattern("83 7C 24 ? ? A3 ? ? ? ? 0F 84").get_one();
auto using1stPersonWeaponMode = static_cast<decltype(Using1stPersonWeaponMode)>(get_pattern("66 83 F8 07 74 18", -7));
auto using1stPersonWeaponMode = reinterpret_cast<decltype(Using1stPersonWeaponMode)>(get_pattern("66 83 F8 07 74 18", -7));
bool* useMouse3rdPerson = *get_pattern<bool*>("80 3D ? ? ? ? ? 75 09 66 C7 05 ? ? ? ? ? ? 8B 35", 2);
void* theCamera = *get_pattern<void*>("B9 ? ? ? ? 31 DB E8", 1);