From 6db18446560b141918e572981be266244d56b295 Mon Sep 17 00:00:00 2001 From: "Avi Halachmi (:avih)" Date: Sun, 31 Jul 2016 19:09:10 +0300 Subject: [PATCH] patches: load correctly for the bios on full boot We already had loading of the patches (and applying patch=0) before the game elf recompiles, now do the same when the bios starts too. --- pcsx2/x86/ix86-32/iR5900-32.cpp | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/pcsx2/x86/ix86-32/iR5900-32.cpp b/pcsx2/x86/ix86-32/iR5900-32.cpp index ffefcccaa6..3aa7a09892 100644 --- a/pcsx2/x86/ix86-32/iR5900-32.cpp +++ b/pcsx2/x86/ix86-32/iR5900-32.cpp @@ -570,6 +570,7 @@ static std::atomic eeRecIsReset(false); static std::atomic eeRecNeedsReset(false); static bool eeCpuExecuting = false; static int g_resetEeScalingStats = 0; +static int g_patchesNeedRedo = 0; //////////////////////////////////////////////////// static void recResetRaw() @@ -606,6 +607,8 @@ static void recResetRaw() g_branch = 0; g_resetEeScalingStats = 1; + + g_patchesNeedRedo = 1; } static void recShutdown() @@ -1595,6 +1598,11 @@ bool skipMPEG_By_Pattern(u32 sPC) { // defined at AppCoreThread.cpp but unclean and should not be public. We're the only // consumers of it, so it's declared only here. void LoadAllPatchesAndStuff(const Pcsx2Config&); +void doPlace0Patches() +{ + LoadAllPatchesAndStuff(EmuConfig); + ApplyLoadedPatches(PPT_ONCE_ON_LOAD); +} static void __fastcall recRecompile( const u32 startpc ) { @@ -1644,21 +1652,26 @@ static void __fastcall recRecompile( const u32 startpc ) eeloadMain = ((EELOAD_START + 0xa0) & 0xf0000000U) | (mainjump << 2 & 0x0fffffffU); } - if (eeloadMain && HWADDR(startpc) == HWADDR(eeloadMain)) + if (eeloadMain && HWADDR(startpc) == HWADDR(eeloadMain)) { xFastCall(eeloadHook); + // On fast/full boot this will have a crc of 0x0. But when the game/elf itself is + // recompiled (below - ElfEntry && g_GameLoading), then the crc would be from the elf. + // g_patchesNeedRedo is set on rec reset, and this is the only consumer. + // Also makes sure that patches from the previous elf/game are not applied on boot. + if (g_patchesNeedRedo) + doPlace0Patches(); + g_patchesNeedRedo = 0; + } + // this is the only way patches get applied, doesn't depend on a hack if (g_GameLoading && HWADDR(startpc) == ElfEntry) { Console.WriteLn(L"Elf entry point @ 0x%08x about to get recompiled. Load patches first.", startpc); xFastCall(eeGameStarting); + // Apply patch as soon as possible. Normally it is done in // eeGameStarting but first block is already compiled. - // - // First tentative was to call eeGameStarting directly (not through the - // recompiler) but it crashes some games (GT4, DMC3). It is either a - // thread issue or linked to the various components reset. - LoadAllPatchesAndStuff(EmuConfig); - ApplyLoadedPatches(PPT_ONCE_ON_LOAD); + doPlace0Patches(); } g_branch = 0;