Skip to content

Commit 8301635

Browse files
SA: Fix post effects not scaling correctly
* Heat haze not rescaling after changing resolution * Water ripple effect having too high wave frequency at higher resolutions
1 parent 9de11ad commit 8301635

File tree

1 file changed

+91
-0
lines changed

1 file changed

+91
-0
lines changed

SilentPatchSA/SilentPatchSA.cpp

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2900,6 +2900,45 @@ namespace SlidingTextsScalingFixes
29002900
}
29012901

29022902

2903+
// ============= Fix post effects not scaling correctly =============
2904+
// Heat haze not rescaling after changing resolution
2905+
// Water ripple effect having too high wave frequency at higher resolutions
2906+
namespace PostEffectsScalingFixes
2907+
{
2908+
static int32_t* pHeatHazeFXTypeLast;
2909+
2910+
// Instead of NOPing the call to SetupBackBufferVertex, redirect it to an empty function,
2911+
// so other mods can chain with it fine
2912+
static void (*orgSetupBackBufferVertex)();
2913+
static void SetupBackBufferVertex_Nop()
2914+
{
2915+
}
2916+
2917+
template<std::size_t Index>
2918+
static void (*orgSetCurrentVideoMode)(int modeIndex);
2919+
2920+
template<std::size_t Index>
2921+
static void SetCurrentVideoMode_SetupPostFX(int modeIndex)
2922+
{
2923+
*pHeatHazeFXTypeLast = -1; // Force heat haze to reinit
2924+
2925+
orgSetCurrentVideoMode<Index>(modeIndex);
2926+
orgSetupBackBufferVertex();
2927+
}
2928+
2929+
HOOK_EACH_INIT(SetCurrentVideoMode, orgSetCurrentVideoMode, SetCurrentVideoMode_SetupPostFX);
2930+
2931+
static void (*orgUnderWaterRipple)(RwRGBA, float, float, int, float, float);
2932+
static void UnderWaterRipple_ScaleFrequency(RwRGBA a1, float xOffset, float yOffset, int a4, float a5, float frequency)
2933+
{
2934+
// Scale frequency counter-proportionally to the resolution height
2935+
// as the function already scales the sine wave frequency to that internally.
2936+
const float freqDivFactor = RsGlobal->MaximumHeight / 480.0f;
2937+
orgUnderWaterRipple(a1, xOffset, yOffset, a4, a5, frequency / freqDivFactor);
2938+
}
2939+
}
2940+
2941+
29032942
// ============= LS-RP Mode stuff =============
29042943
namespace LSRPMode
29052944
{
@@ -5899,6 +5938,31 @@ void Patch_SA_10(HINSTANCE hInstance)
58995938
}
59005939

59015940

5941+
// Fix post effects not scaling correctly
5942+
// Heat haze not rescaling after changing resolution
5943+
// Water ripple effect having too high wave frequency at higher resolutions
5944+
{
5945+
using namespace PostEffectsScalingFixes;
5946+
5947+
std::array<uintptr_t, 4> setCurrentVideoMode = { 0x574509, 0x57D096, 0x57D16E, 0x57D2B2 };
5948+
5949+
if (*(uint8_t*)0x701450 == 0xA1)
5950+
{
5951+
pHeatHazeFXTypeLast = *(int32_t**)(0x701450 + 1);
5952+
}
5953+
else
5954+
{
5955+
// Someone re-routed CPostEffects::HeatHazeFXInit and we can't read the variable, fall back to the 1.0 US address
5956+
pHeatHazeFXTypeLast = (int32_t*)0x8D50E4;
5957+
}
5958+
5959+
HookEach_SetCurrentVideoMode(setCurrentVideoMode, InterceptCall);
5960+
InterceptCall(0x745C7D, orgSetupBackBufferVertex, SetupBackBufferVertex_Nop);
5961+
5962+
InterceptCall(0x70529C, orgUnderWaterRipple, UnderWaterRipple_ScaleFrequency);
5963+
}
5964+
5965+
59025966
#if FULL_PRECISION_D3D
59035967
// Test - full precision D3D device
59045968
Patch<uint8_t>( 0x7F672B+1, *(uint8_t*)(0x7F672B+1) | D3DCREATE_FPU_PRESERVE );
@@ -7978,6 +8042,33 @@ void Patch_SA_NewBinaries_Common(HINSTANCE hInstance)
79788042
Patch(bigMessage0Threshold.get<void>(3 + 2), &f620);
79798043
}
79808044
TXN_CATCH();
8045+
8046+
8047+
// Fix post effects not scaling correctly
8048+
// Heat haze not rescaling after changing resolution
8049+
// Water ripple effect having too high wave frequency at higher resolutions
8050+
try
8051+
{
8052+
using namespace PostEffectsScalingFixes;
8053+
8054+
std::array<void*, 4> setCurrentVideoMode = {
8055+
get_pattern("E8 ? ? ? ? 83 C4 08 88 9E"),
8056+
get_pattern("89 86 D0 00 00 00 E8 ? ? ? ? 83 C4 04 8B CE", 6),
8057+
get_pattern("E8 ? ? ? ? 83 C4 08 8B CE E8 ? ? ? ? 8A 45 FF"),
8058+
get_pattern("8B 96 D0 00 00 00 52 E8 ? ? ? ? 83 C4 08", 7),
8059+
};
8060+
8061+
auto setupBackBufferVertex = get_pattern("E8 ? ? ? ? A1 ? ? ? ? 8B 48 60");
8062+
auto underWaterRipple = get_pattern("E8 ? ? ? ? 83 C4 18 80 3D ? ? ? ? ? 74 05");
8063+
8064+
pHeatHazeFXTypeLast = *get_pattern<int32_t*>("89 1D ? ? ? ? A1 ? ? ? ? 8B 48 0C", 2);
8065+
8066+
HookEach_SetCurrentVideoMode(setCurrentVideoMode, InterceptCall);
8067+
InterceptCall(setupBackBufferVertex, orgSetupBackBufferVertex, SetupBackBufferVertex_Nop);
8068+
8069+
InterceptCall(underWaterRipple, orgUnderWaterRipple, UnderWaterRipple_ScaleFrequency);
8070+
}
8071+
TXN_CATCH();
79818072
}
79828073

79838074

0 commit comments

Comments
 (0)