From c7d248f400a3ed6548a21072705c7fbeb2e88db0 Mon Sep 17 00:00:00 2001 From: RoadrunnerWMC Date: Wed, 11 Mar 2026 05:32:08 -0400 Subject: [PATCH] Improved logic for whether to apply commands at link time --- Source/Commands/BranchCommand.cs | 4 +--- Source/Commands/PatchExitCommand.cs | 4 +--- Source/Commands/RelocCommand.cs | 2 +- Source/KamekFile.cs | 2 ++ 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/Source/Commands/BranchCommand.cs b/Source/Commands/BranchCommand.cs index d904dc8..0ac6789 100644 --- a/Source/Commands/BranchCommand.cs +++ b/Source/Commands/BranchCommand.cs @@ -63,9 +63,7 @@ public override IEnumerable PackActionReplayCodes() public override bool Apply(KamekFile file) { - if (Address.Value.Type == file.BaseAddress.Type - && file.Contains(Address.Value) - && Address.Value.Type == Target.Type) + if (file.Contains(Address.Value) && Address.Value.Type == Target.Type) { file.WriteUInt32(Address.Value, GenerateInstruction()); return true; diff --git a/Source/Commands/PatchExitCommand.cs b/Source/Commands/PatchExitCommand.cs index 8c8b543..08ba952 100644 --- a/Source/Commands/PatchExitCommand.cs +++ b/Source/Commands/PatchExitCommand.cs @@ -80,9 +80,7 @@ public override void ApplyToCodeFile(CodeFiles.CodeFile file) public override bool Apply(KamekFile file) { - if (Address.Value.Type == file.BaseAddress.Type - && file.Contains(Address.Value) - && Address.Value.Type == Target.Type) + if (file.Contains(Address.Value) && Address.Value.Type == Target.Type) { file.WriteUInt32(Address.Value, GenerateInstruction()); return true; diff --git a/Source/Commands/RelocCommand.cs b/Source/Commands/RelocCommand.cs index 0a1a887..0ff49c3 100644 --- a/Source/Commands/RelocCommand.cs +++ b/Source/Commands/RelocCommand.cs @@ -83,7 +83,7 @@ public override void ApplyToCodeFile(CodeFiles.CodeFile file) public override bool Apply(KamekFile file) { - if (Address.Value.Type != file.BaseAddress.Type) + if (!file.Contains(Address.Value)) return false; switch (Id) diff --git a/Source/KamekFile.cs b/Source/KamekFile.cs index 79ed0a0..fd1daea 100644 --- a/Source/KamekFile.cs +++ b/Source/KamekFile.cs @@ -47,6 +47,8 @@ public void WriteUInt32(Word addr, uint value) public bool Contains(Word addr) { + if (addr.Type != _baseAddress.Type) + return false; return (addr >= _baseAddress && addr < (_baseAddress + _codeBlob.Length)); }