Adds memory.hash_region to aid in detecting RAM changes
This commit is contained in:
parent
f94d3f58c6
commit
fef2c131f8
|
@ -4,6 +4,7 @@ using System.ComponentModel;
|
||||||
using NLua;
|
using NLua;
|
||||||
using BizHawk.Emulation.Common;
|
using BizHawk.Emulation.Common;
|
||||||
using BizHawk.Emulation.Common.IEmulatorExtensions;
|
using BizHawk.Emulation.Common.IEmulatorExtensions;
|
||||||
|
using BizHawk.Common.BufferExtensions;
|
||||||
|
|
||||||
namespace BizHawk.Client.Common
|
namespace BizHawk.Client.Common
|
||||||
{
|
{
|
||||||
|
@ -108,6 +109,37 @@ namespace BizHawk.Client.Common
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[LuaMethod("hash_region", "Returns a hash as a string of a region of memory, starting from addr, through count bytes. If the domain is unspecified, it uses the current region.")]
|
||||||
|
public string HashRegion(int addr, int count, string domain = null)
|
||||||
|
{
|
||||||
|
var d = string.IsNullOrEmpty(domain) ? Domain : DomainList[VerifyMemoryDomain(domain)];
|
||||||
|
|
||||||
|
// checks
|
||||||
|
if (addr < 0 || addr >= d.Size)
|
||||||
|
{
|
||||||
|
string error = $"Address {addr} is outside the bounds of domain {d.Name}";
|
||||||
|
Log(error);
|
||||||
|
throw new ArgumentOutOfRangeException(error);
|
||||||
|
}
|
||||||
|
if (addr + count > d.Size)
|
||||||
|
{
|
||||||
|
string error = $"Address {addr} + count {count} is outside the bounds of domain {d.Name}";
|
||||||
|
Log(error);
|
||||||
|
throw new ArgumentOutOfRangeException(error);
|
||||||
|
}
|
||||||
|
|
||||||
|
byte[] data = new byte[count];
|
||||||
|
for (int i = 0; i < count; i++)
|
||||||
|
{
|
||||||
|
data[i] = d.PeekByte(addr + i);
|
||||||
|
}
|
||||||
|
|
||||||
|
using (var hasher = System.Security.Cryptography.SHA256.Create())
|
||||||
|
{
|
||||||
|
return hasher.ComputeHash(data).BytesToHexString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Common Special and Legacy Methods
|
#region Common Special and Legacy Methods
|
||||||
|
|
Loading…
Reference in New Issue