Replaced Rosenberg Audio Fix that was placebo with PS2 randomness for this audio

Might bring it closer to PS2 odds,
but the feature was never broken in the first place.

Fixes #11
This commit is contained in:
Silent 2024-04-29 20:43:25 +02:00
parent e7a2a79de5
commit 836fbafd41
No known key found for this signature in database
GPG Key ID: AE53149BB0C45AF1

View File

@ -13,6 +13,7 @@
#include <array>
#include <memory>
#include <Shlwapi.h>
#include <time.h>
#include "Utils/ModuleList.hpp"
#include "Utils/Patterns.h"
@ -57,8 +58,6 @@ DebugMenuAPI gDebugMenuAPI;
static HMODULE hDLLModule;
static const void* RosieAudioFix_JumpBack;
static RsGlobalType* RsGlobal;
static const void* SubtitlesShadowFix_JumpBack;
@ -78,17 +77,6 @@ inline float GetHeightMult()
return ResolutionHeightMult;
}
void __declspec(naked) RosiesAudioFix()
{
_asm
{
mov byte ptr [ebx+0CCh], 0
mov byte ptr [ebx+148h], 0
jmp [RosieAudioFix_JumpBack]
}
}
static bool bGameInFocus = true;
static LRESULT (CALLBACK **OldWndProc)(HWND, UINT, WPARAM, LPARAM);
@ -296,6 +284,21 @@ void __declspec(naked) AutoPilotTimerFix_VC()
}
}
// PS2 implementation of rand()
static uint64_t seed_rand_ps2 = time(nullptr);
static int rand_ps2()
{
seed_rand_ps2 = 0x5851F42D4C957F2D * seed_rand_ps2 + 1;
return ((seed_rand_ps2 >> 32) & 0x7FFFFFFF);
}
// PS2 rand, but matching PC's RAND_MAX
static int rand15_ps2()
{
return rand_ps2() & 0x7FFF;
}
namespace ZeroAmmoFix
{
@ -875,13 +878,10 @@ void Patch_VC_10(uint32_t width, uint32_t height)
using namespace Memory::DynBase;
RsGlobal = *(RsGlobalType**)DynBaseAddress(0x602D32);
RosieAudioFix_JumpBack = (void*)DynBaseAddress(0x42BFFE);
SubtitlesShadowFix_JumpBack = (void*)DynBaseAddress(0x551701);
InjectHook(0x5433BD, FixedRefValue);
InjectHook(0x42BFF7, RosiesAudioFix, HookType::Jump);
InjectHook(0x5516FC, SubtitlesShadowFix, HookType::Jump);
Patch<BYTE>(0x5517C4, 0xD9);
Patch<BYTE>(0x5517DF, 0xD9);
@ -984,13 +984,10 @@ void Patch_VC_11(uint32_t width, uint32_t height)
using namespace Memory::DynBase;
RsGlobal = *(RsGlobalType**)DynBaseAddress(0x602D12);
RosieAudioFix_JumpBack = (void*)DynBaseAddress(0x42BFFE);
SubtitlesShadowFix_JumpBack = (void*)DynBaseAddress(0x551721);
InjectHook(0x5433DD, FixedRefValue);
InjectHook(0x42BFF7, RosiesAudioFix, HookType::Jump);
InjectHook(0x55171C, SubtitlesShadowFix, HookType::Jump);
Patch<BYTE>(0x5517E4, 0xD9);
Patch<BYTE>(0x5517FF, 0xD9);
@ -1083,13 +1080,10 @@ void Patch_VC_Steam(uint32_t width, uint32_t height)
using namespace Memory::DynBase;
RsGlobal = *(RsGlobalType**)DynBaseAddress(0x602952);
RosieAudioFix_JumpBack = (void*)DynBaseAddress(0x42BFCE);
SubtitlesShadowFix_JumpBack = (void*)DynBaseAddress(0x5515F1);
InjectHook(0x5432AD, FixedRefValue);
InjectHook(0x42BFC7, RosiesAudioFix, HookType::Jump);
InjectHook(0x5515EC, SubtitlesShadowFix, HookType::Jump);
Patch<BYTE>(0x5516B4, 0xD9);
Patch<BYTE>(0x5516CF, 0xD9);
@ -1537,6 +1531,14 @@ void Patch_VC_Common()
memmove(isPlayerTargettingChar.get<void>(), isPlayerTargettingChar.get<void>(5), 5);
InjectHook(isPlayerTargettingChar.get<void>(5), IsPlayerTargettingChar_ExtraChecks, HookType::Call);
}
// Use PS2 randomness for Rosenberg audio to hopefully bring the odds closer to PS2
// The functionality was never broken on PC - but the random distribution seemingly made it looks as if it was
{
auto busted_audio_rand = get_pattern("80 BB 48 01 00 00 00 0F 85 ? ? ? ? E8 ? ? ? ? 25 FF FF 00 00", 13);
InjectHook(busted_audio_rand, rand15_ps2);
}
}
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)