diff --git a/TarnishedTool/Memory/AobScanner.cs b/TarnishedTool/Memory/AobScanner.cs index 657573e..bcf6f53 100644 --- a/TarnishedTool/Memory/AobScanner.cs +++ b/TarnishedTool/Memory/AobScanner.cs @@ -144,6 +144,7 @@ public void QueueFallbackPatterns() Queue(nameof(Pattern.NoRuneLossOnDeath), Pattern.NoRuneLossOnDeath, addr => Patches.NoRuneLossOnDeath = addr); Queue(nameof(Pattern.IsWorldPaused), Pattern.IsWorldPaused, addr => Patches.IsWorldPaused = addr); + Queue(nameof(Pattern.ShouldPauseWorld), Pattern.ShouldPauseWorld, addr => Patches.ShouldPauseWorld = addr); Queue(nameof(Pattern.GetItemChance), Pattern.GetItemChance, addr => Patches.GetItemChance = addr); Queue(nameof(Pattern.OpenMap), Pattern.OpenMap, addr => Patches.OpenMap = addr); Queue(nameof(Pattern.CloseMap), Pattern.CloseMap, addr => Patches.CloseMap = addr); diff --git a/TarnishedTool/Memory/Offsets.cs b/TarnishedTool/Memory/Offsets.cs index ad1d81c..40d47e5 100644 --- a/TarnishedTool/Memory/Offsets.cs +++ b/TarnishedTool/Memory/Offsets.cs @@ -959,6 +959,7 @@ public static class Patches public static nint IsTorrentDisabledInUnderworld; public static nint IsWhistleDisabled; public static nint IsWorldPaused; + public static nint ShouldPauseWorld; public static nint GetItemChance; public static nint FpsCap; public static nint MenuDelay; @@ -3229,6 +3230,12 @@ Version2_2_0 or Version2_2_3 or Version2_3_0 or Version2_4_0 or Version2_5_0 _ => 0 }; + Patches.ShouldPauseWorld = moduleBase + Version switch + { + Version2_7_2 => 0xAF9F45, + _ => 0 + }; + Patches.GetItemChance = moduleBase + Version switch { Version1_2_0 => 0xCC9E0E, @@ -3505,6 +3512,7 @@ public static void Print(nint moduleBase) PrintOffset("IsTorrentDisabledInUnderworld",Patches.IsTorrentDisabledInUnderworld); PrintOffset("IsWhistleDisabled", Patches.IsWhistleDisabled); PrintOffset("IsWorldPaused", Patches.IsWorldPaused); + PrintOffset("ShouldPauseWorld", Patches.ShouldPauseWorld); PrintOffset("GetItemChance", Patches.GetItemChance); PrintOffset("GetShopEvent", Patches.GetShopEvent); PrintOffset("FpsCap", Patches.FpsCap); diff --git a/TarnishedTool/Memory/Pattern.cs b/TarnishedTool/Memory/Pattern.cs index e6e2c0b..5955d4d 100644 --- a/TarnishedTool/Memory/Pattern.cs +++ b/TarnishedTool/Memory/Pattern.cs @@ -829,6 +829,13 @@ public class Pattern( anchorOffset: 1 ); + public static readonly Pattern ShouldPauseWorld = new Pattern( + [0x84, 0xC0, 0x74, 0x09, 0x66, 0xC7, 0x83, 0xB8, 0x04, 0x00, 0x00, 0x00, 0x01], + "xxxxxxxxxxxxx", + 2, + AddressingMode.Absolute + ); + public static readonly Pattern IsTorrentDisabledInUnderworld = new Pattern( [0x80, 0x78, 0x36, 0x00, 0x0F], "xxxxx", diff --git a/TarnishedTool/Services/UtilityService.cs b/TarnishedTool/Services/UtilityService.cs index 5d630f3..54ca0ed 100644 --- a/TarnishedTool/Services/UtilityService.cs +++ b/TarnishedTool/Services/UtilityService.cs @@ -1,5 +1,6 @@ using System; using System.Numerics; +using System.Threading; using TarnishedTool.Enums; using TarnishedTool.Interfaces; using TarnishedTool.Memory; @@ -12,6 +13,9 @@ public class UtilityService(IMemoryService memoryService, HookManager hookManage : IUtilityService { public const float DefaultNoClipSpeedScale = 0.2f; + + private const float FreezeWorldSettleSpeed = 0.0001f; + private const int FreezeWorldSettleFrames = 3; public void Quitout() => memoryService.Write(memoryService.Read(GameMan.Base) + GameMan.ShouldQuitout, (byte)1); @@ -239,8 +243,42 @@ public void MovePlayerToCam() } } - public void ToggleFreezeWorld(bool isEnabled) => - memoryService.WriteBytes(Patches.IsWorldPaused, isEnabled ? [0x0F, 0x85] : [0x0F, 0x84]); + public void ToggleFreezeWorld(bool isEnabled) + { + if (isEnabled) + { + // Zero out bone motion first so TAA doesn't smear frozen characters + var speed = GetSpeed(); + SetSpeed(FreezeWorldSettleSpeed); + WaitFrames(FreezeWorldSettleFrames); + WriteFreezeWorldPatch(true); + WaitFrames(FreezeWorldSettleFrames); + SetSpeed(speed); + } + else + { + WriteFreezeWorldPatch(false); + WaitFrames(FreezeWorldSettleFrames); + } + } + + private void WriteFreezeWorldPatch(bool isEnabled) + { + if (Patches.ShouldPauseWorld <= memoryService.BaseAddress) + { + memoryService.WriteBytes(Patches.IsWorldPaused, isEnabled ? [0x0F, 0x85] : [0x0F, 0x84]); + return; + } + + memoryService.WriteBytes(Patches.ShouldPauseWorld, isEnabled ? [0x90, 0x90] : [0x74, 0x09]); + } + + private void WaitFrames(int frames) + { + var frameTime = memoryService.Read(Patches.FpsCap + 0x3); + frameTime = Math.Min(Math.Max(frameTime, 1f / 60), 1f / 15); + Thread.Sleep((int)(frameTime * 1000 * frames)); + } public void ToggleDrawHitbox(bool isDrawHitboxEnabled) => memoryService.Write(memoryService.Read(DamageManager.Base) + DamageManager.HitboxView, diff --git a/TarnishedTool/ViewModels/UtilityViewModel.cs b/TarnishedTool/ViewModels/UtilityViewModel.cs index a7a74ec..0106288 100644 --- a/TarnishedTool/ViewModels/UtilityViewModel.cs +++ b/TarnishedTool/ViewModels/UtilityViewModel.cs @@ -880,6 +880,7 @@ private void OnGameNotLoaded() { AreOptionsEnabled = false; IsFreeCamEnabled = false; + IsFreezeWorldEnabled = false; if (IsDrawLowHitEnabled) { _utilityService.ToggleDrawLowHit(false);