Compare commits

..

18 commits

Author SHA1 Message Date
Echo J
dc04c3ca39 SilentPatchVC: Add GCC-style inline assembly statements
This also includes a small wrapper to call a C++ function from GCC-style inline ASM

These statements almost work on llvm-mingw too (but there's some stubborn call instructions)
2024-11-20 23:42:38 +02:00
Echo J
8362b0a1d0 SilentPatchIII: Add GCC-style inline assembly statements
These almost work on llvm-mingw too (but there's some stubborn call instructions)
2024-11-20 23:41:41 +02:00
Echo J
184f3c60f9 SilentPatchIII: Add a missing functional header include
MinGW GCC doesn't implicitly include it either
2024-11-20 23:39:29 +02:00
Echo J
74e16c5f04 SilentPatch: Add missing cmath header include
It's required for the modf() function (and it isn't implicitly
included on MinGW GCC)
2024-11-20 23:39:29 +02:00
Echo J
44b9f507cf SilentPatch: Move a header include in SVF
This makes sure the fixed-width integer types are included in SVF.h
2024-11-20 23:39:29 +02:00
Echo J
de2536a984 SilentPatch: Define a replacement for _stricmp() on non-MSVC
MinGW GCC doesn't have this MSVC-specific function
2024-11-20 23:39:29 +02:00
Echo J
3120120ea4 SilentPatch: Move RwEngineInstance definition to headers
MinGW GCC can't locate it in some files otherwise
2024-11-20 23:39:29 +02:00
Echo J
83ac060e53 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-20 23:39:29 +02:00
Echo J
d5c3398606 SilentPatch: Don't define certain Rw* functions if not needed
Redefining them can cause strange compile errors with MinGW GCC
2024-11-20 23:39:29 +02:00
Echo J
8093c055e6 DDraw: Cast the memcpy() source argument
This works around the MinGW GCC type strictness
2024-11-20 23:39:29 +02:00
Echo J
b80ee9d8ca DDraw: Use a pragma for DirectDrawCreateEx export on MSVC
The .def file is either going to have issues on MSVC or MinGW GCC
(so replace it with a pragma on MSVC)
2024-11-20 23:39:29 +02:00
Echo J
3106c51455 SilentPatchIII/VC/SA: Mark some function pointers as inline
MinGW GCC's linker can't find them otherwise
2024-11-20 23:39:29 +02:00
Echo J
277515a56b SilentPatchIII/VC: Remove extern from ppUserFilesDir variable definitions
This fixes compile warnings with MinGW GCC
2024-11-20 23:39:29 +02:00
Echo J
9cbc846dbd SilentPatchIII/VC/SA: Add GCC/Clang-compatible safebuffers equivalent
And switch to a common define for this attribute (this fixes
compile warnings on MinGW GCC)
2024-11-20 23:39:29 +02:00
Echo J
2bd71990de 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-20 23:39:29 +02:00
Echo J
4cccda9da6 Set Windows defines earlier
This avoids compile warnings on MinGW GCC (because standard C++
headers eventually import the Windows stuff)
2024-11-20 23:39:29 +02:00
Echo J
a360f693d3 Use lowercase names for Windows headers
This fixes missing header issues on a case-sensitive filesystem
with MinGW GCC
2024-11-20 23:39:29 +02:00
Echo J
4c78e857f0 Remove unused dllmain.cpp file
It seems to be used in the early days of SilentPatch (but it's
no longer included since the III/VC/SA code split and serves no purpose)
2024-11-20 23:39:29 +02:00
2 changed files with 63 additions and 70 deletions

View file

@ -4652,6 +4652,7 @@ BOOL InjectDelayedPatches_10()
// Fix some big messages staying on screen longer at high resolutions due to a cut sliding text feature
// Also since we're touching it, optionally allow to re-enable this feature.
if (const int INIoption = GetPrivateProfileIntW(L"SilentPatch", L"SlidingMissionTitleText", -1, wcModulePath); INIoption != -1)
{
using namespace SlidingTextsScalingFixes;
@ -4747,31 +4748,6 @@ BOOL InjectDelayedPatches_10()
}
// Fix credits not scaling to resolution
// Moved here for compatibility with wshps.asi
if (MemEquals(0x5A8679, {0xD8, 0xC1, 0xD8, 0x05}) && MemEquals(0x5A8679+8, {0xD8, 0x64, 0x24, 0x18, 0xD9, 0x54, 0x24, 0x14})) // Verify wshps.asi isn't already patching the credits
{
using namespace CreditsScalingFixes;
std::array<uintptr_t, 2> creditPrintString = { 0x5A8707, 0x5A8785 };
HookEach_PrintString(creditPrintString, InterceptCall);
InterceptCall(0x5A86C0, orgSetScale, SetScale_ScaleToRes);
// Fix the credits cutting off on the bottom early, they don't do that in III
// but it regressed in VC and SA
static const float topMargin = 1.0f;
static const float bottomMargin = -(**(float**)(0x5A869A + 2));
Patch(0x5A8689 + 2, &topMargin);
Patch(0x5A869A + 2, &bottomMargin);
// As we now scale everything on PrintString time, the resolution height checks need to be unscaled.
Patch(0x5A8660 + 2, &FIXED_RES_HEIGHT_SCALE);
Patch(0x5AF8C9 + 2, &FIXED_RES_HEIGHT_SCALE);
}
#ifndef NDEBUG
if ( const int QPCDays = GetPrivateProfileIntW(L"Debug", L"AddDaysToQPC", 0, wcModulePath); QPCDays != 0 )
{
@ -5313,46 +5289,6 @@ BOOL InjectDelayedPatches_NewBinaries()
TXN_CATCH();
// Fix credits not scaling to resolution
// Moved here for compatibility with wshps.asi
try
{
using namespace CreditsScalingFixes;
// Verify wshps.asi isn't already patching the credits
(void)get_pattern("DE C2 D9 45 18 DE EA", 1);
std::array<void*, 2> creditPrintString = {
get_pattern("E8 ? ? ? ? 83 C4 0C 80 7D 1C 00"),
get_pattern("D9 1C 24 E8 ? ? ? ? DD 05 ? ? ? ? 83 C4 0C 5E", 3),
};
auto setScale = get_pattern("D9 1C 24 E8 ? ? ? ? 83 C4 08 68 FF 00 00 00 6A 00 6A 00 6A 00", 3);
// Fix the credits cutting off on the bottom early, they don't do that in III
// but it regressed in VC and SA
auto positionOffset = get_pattern("DE C2 D9 45 18 DE EA D9 C9 D9 5D 14 D9 05", 12 + 2);
// As we now scale everything on PrintString time, the resolution height checks need to be unscaled.
void* resHeightScales[] = {
get_pattern("DB 05 ? ? ? ? 57 8B 7D 14", 2),
get_pattern("A1 ? ? ? ? 03 45 FC 89 45 F4", 1)
};
static const float topMargin = 1.0f;
Patch(positionOffset, &topMargin);
HookEach_PrintString(creditPrintString, InterceptCall);
InterceptCall(setScale, orgSetScale, SetScale_ScaleToRes);
for (void* addr : resHeightScales)
{
Patch(addr, &FIXED_RES_HEIGHT_SCALE);
}
}
TXN_CATCH();
return FALSE;
}
return TRUE;
@ -6420,6 +6356,29 @@ void Patch_SA_10(HINSTANCE hInstance)
}
// Fix credits not scaling to resolution
{
using namespace CreditsScalingFixes;
std::array<uintptr_t, 2> creditPrintString = { 0x5A8707, 0x5A8785 };
HookEach_PrintString(creditPrintString, InterceptCall);
InterceptCall(0x5A86C0, orgSetScale, SetScale_ScaleToRes);
// Fix the credits cutting off on the bottom early, they don't do that in III
// but it regressed in VC and SA
static const float topMargin = 1.0f;
static const float bottomMargin = -(**(float**)(0x5A869A + 2));
Patch(0x5A8689 + 2, &topMargin);
Patch(0x5A869A + 2, &bottomMargin);
// As we now scale everything on PrintString time, the resolution height checks need to be unscaled.
Patch(0x5A8660 + 2, &FIXED_RES_HEIGHT_SCALE);
Patch(0x5AF8C9 + 2, &FIXED_RES_HEIGHT_SCALE);
}
// Fix some big messages staying on screen longer at high resolutions due to a cut sliding text feature
// Also since we're touching it, optionally allow to re-enable this feature.
{
@ -8550,6 +8509,40 @@ void Patch_SA_NewBinaries_Common(HINSTANCE hInstance)
TXN_CATCH();
// Fix credits not scaling to resolution
{
using namespace CreditsScalingFixes;
std::array<void*, 2> creditPrintString = {
get_pattern("E8 ? ? ? ? 83 C4 0C 80 7D 1C 00"),
get_pattern("D9 1C 24 E8 ? ? ? ? DD 05 ? ? ? ? 83 C4 0C 5E", 3),
};
auto setScale = get_pattern("D9 1C 24 E8 ? ? ? ? 83 C4 08 68 FF 00 00 00 6A 00 6A 00 6A 00", 3);
// Fix the credits cutting off on the bottom early, they don't do that in III
// but it regressed in VC and SA
auto positionOffset = get_pattern("DE C2 D9 45 18 DE EA D9 C9 D9 5D 14 D9 05", 12 + 2);
// As we now scale everything on PrintString time, the resolution height checks need to be unscaled.
void* resHeightScales[] = {
get_pattern("DB 05 ? ? ? ? 57 8B 7D 14", 2),
get_pattern("A1 ? ? ? ? 03 45 FC 89 45 F4", 1)
};
static const float topMargin = 1.0f;
Patch(positionOffset, &topMargin);
HookEach_PrintString(creditPrintString, InterceptCall);
InterceptCall(setScale, orgSetScale, SetScale_ScaleToRes);
for (void* addr : resHeightScales)
{
Patch(addr, &FIXED_RES_HEIGHT_SCALE);
}
}
// Fix some big messages staying on screen longer at high resolutions due to a cut sliding text feature
// Also since we're touching it, optionally allow to re-enable this feature.
try

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()
@ -477,4 +477,4 @@ static_assert(sizeof(CVehicle) == 0x5A0, "Wrong size: CVehicle");
static_assert(sizeof(CAutomobile) == 0x988, "Wrong size: CAutomobile");
static_assert(sizeof(CStoredCar) == 0x40, "Wrong size: CStoredCar");
#endif
#endif