From 86f3394be053a7fb1328dfcc433714f903892268 Mon Sep 17 00:00:00 2001 From: adelikat Date: Sun, 2 Sep 2012 22:45:06 +0000 Subject: [PATCH] Hex Editor - support archived roms for the Rom File domain --- BizHawk.MultiClient/tools/HexEditor.cs | 77 +++++++++++++++++++++++++- 1 file changed, 74 insertions(+), 3 deletions(-) diff --git a/BizHawk.MultiClient/tools/HexEditor.cs b/BizHawk.MultiClient/tools/HexEditor.cs index 7fb5a10abc..7247dd1404 100644 --- a/BizHawk.MultiClient/tools/HexEditor.cs +++ b/BizHawk.MultiClient/tools/HexEditor.cs @@ -174,12 +174,17 @@ namespace BizHawk.MultiClient for (int j = 0; j < 16; j += DataSize) { if (addr + j < Domain.Size) + { rowStr.AppendFormat(DigitFormatString, MakeValue(addr + j)); + } } rowStr.Append(" | "); for (int k = 0; k < 16; k++) { - rowStr.Append(Remap(Domain.PeekByte(addr + k))); + if (addr + k < Domain.Size) + { + rowStr.Append(Remap(Domain.PeekByte(addr + k))); + } } rowStr.AppendLine(); @@ -317,14 +322,80 @@ namespace BizHawk.MultiClient Refresh(); } + private bool CurrentROMIsArchive() + { + string path = Global.MainForm.CurrentlyOpenRom; + if (path == null) + { + return false; + } + + using (var file = new HawkFile()) + { + file.Open(path); + + if (!file.Exists) + { + return false; + } + + if (file.IsArchive) + { + return true; + } + else + { + return false; + } + } + } + + private byte[] GetRomBytes() + { + byte[] bytes; + string path = Global.MainForm.CurrentlyOpenRom; + if (path == null) + { + return null; + } + + using (var file = new HawkFile()) + { + file.Open(path); + + if (!file.Exists) + { + return null; + } + + if (file.IsArchive) + { + var stream = file.GetStream(); + return Util.ReadAllBytes(stream); + } + else + { + return File.ReadAllBytes(path); + } + } + + return new byte[0]; + } + private void SetMemoryDomain(int pos) { if (pos == 999) { - ROM = File.ReadAllBytes(Global.MainForm.CurrentlyOpenRom); - ROMDomain = new MemoryDomain("ROM File", ROM.Length, Endian.Little, + ROM = GetRomBytes(); + if (ROM == null) + { + ROM = new byte[1] { 0xFF }; + } + + ROMDomain = new MemoryDomain("ROM File", ROM.Length, Endian.Little, addr => ROM[addr], (addr, value) => ROM[addr] = value); + Domain = ROMDomain; } else if (pos < Global.Emulator.MemoryDomains.Count) //Sanity check