diff --git a/BizHawk.Client.Common/tools/Cheat.cs b/BizHawk.Client.Common/tools/Cheat.cs index e319a82849..cfe2d0ecc2 100644 --- a/BizHawk.Client.Common/tools/Cheat.cs +++ b/BizHawk.Client.Common/tools/Cheat.cs @@ -243,6 +243,44 @@ namespace BizHawk.Client.Common } } + public byte? GetByteVal(int addr) + { + if (!Contains(addr)) + { + return null; + } + + switch (_watch.Size) + { + default: + case Watch.WatchSize.Separator: + case Watch.WatchSize.Byte: + return (byte?)_val; + case Watch.WatchSize.Word: + if (addr == (_watch.Address ?? 0)) + { + return (byte)(_val >> 8); + } + + return (byte)(_val & 0xFF); + case Watch.WatchSize.DWord: + if (addr == (_watch.Address ?? 0)) + { + return (byte)((_val >> 24) & 0xFF); + } + else if (addr == (_watch.Address ?? 0) + 1) + { + return (byte)((_val >> 16) & 0xFF); + } + else if (addr == ((_watch.Address ?? 0)) + 2) + { + return (byte)((_val >> 8) & 0xFF); + } + + return (byte)(_val & 0xFF); + } + } + public void Increment() { if (!IsSeparator) diff --git a/BizHawk.Client.Common/tools/CheatList.cs b/BizHawk.Client.Common/tools/CheatList.cs index 5c9f7e315b..5a35393467 100644 --- a/BizHawk.Client.Common/tools/CheatList.cs +++ b/BizHawk.Client.Common/tools/CheatList.cs @@ -240,6 +240,22 @@ namespace BizHawk.Client.Common && cheat.Contains(address)); } + /// + /// Returns the value of a given byte in a cheat, If the cheat is a single byte this will be the same indexing the cheat, + /// But if the cheat is multi-byte, this will return just the cheat value for that specific byte + /// + /// Returns null if address is not a part of a cheat, else returns the value of that specific byte only + public byte? GetByteValue(MemoryDomain domain, int addr) + { + var activeCheat = _cheatList.FirstOrDefault(cheat => cheat.Contains(addr)); + if (activeCheat == (Cheat)null) + { + return null; + } + + return activeCheat.GetByteVal(addr); + } + public void SaveOnClose() { if (Global.Config.CheatsAutoSaveOnClose) diff --git a/BizHawk.Client.EmuHawk/tools/HexEditor/HexEditor.cs b/BizHawk.Client.EmuHawk/tools/HexEditor/HexEditor.cs index 74e9d59c44..9497f47403 100644 --- a/BizHawk.Client.EmuHawk/tools/HexEditor/HexEditor.cs +++ b/BizHawk.Client.EmuHawk/tools/HexEditor/HexEditor.cs @@ -560,7 +560,7 @@ namespace BizHawk.Client.EmuHawk private byte MakeByte(int address) { return Global.CheatList.IsActive(_domain, address) - ? (byte) Global.CheatList[_domain, address].Value.Value + ? Global.CheatList.GetByteValue(_domain, address).Value : _domain.PeekByte(address); }