From ee9660d81d84af39e39acfddf679e3b58d903c9f Mon Sep 17 00:00:00 2001 From: ParantezTech <12572227+par274@users.noreply.github.com> Date: Fri, 9 Oct 2026 01:27:52 +0300 Subject: [PATCH] [Loader] Patch red-zone sites from the previous instruction when every indirect branch is resolved --- src/SharpEmu.Core/Loader/GuestRedZonePatcher.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/SharpEmu.Core/Loader/GuestRedZonePatcher.cs b/src/SharpEmu.Core/Loader/GuestRedZonePatcher.cs index 236090a..e03e727 100644 --- a/src/SharpEmu.Core/Loader/GuestRedZonePatcher.cs +++ b/src/SharpEmu.Core/Loader/GuestRedZonePatcher.cs @@ -310,7 +310,10 @@ internal static class GuestRedZonePatcher canBorrowFollowingInstructions, out span, out refusal); - if (!forward) + var backward = !forward && + canBorrowFollowingInstructions && + TryBuildEnclosingPatchSpan(decoded, instructionIndex, branchTargets, out span); + if (!forward && !backward) { unrelocatableSites++; refusalCounts[(int)refusal]++; @@ -335,7 +338,10 @@ internal static class GuestRedZonePatcher shaInstructionCount += span.Instructions.Count(static instruction => ShaInstructionRewrite.CanRewrite(instruction)); } - instructionIndex += span.Instructions.Count - 1; + if (!backward) + { + instructionIndex += span.Instructions.Count - 1; + } } } }