Add several comm MMF LUA functions
This commit is contained in:
parent
457ff87481
commit
e79d33bcfd
|
@ -21,10 +21,21 @@ namespace BizHawk.Client.Common
|
||||||
|
|
||||||
public string ReadFromFile(string filename, int expectedSize)
|
public string ReadFromFile(string filename, int expectedSize)
|
||||||
{
|
{
|
||||||
using var viewAccessor = MemoryMappedFile.OpenExisting(filename).CreateViewAccessor();
|
var bytes = ReadBytesFromFile(filename, expectedSize);
|
||||||
|
return Encoding.UTF8.GetString(bytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] ReadBytesFromFile(string filename, int expectedSize)
|
||||||
|
{
|
||||||
|
if (!_mmfFiles.TryGetValue(filename, out var mmfFile))
|
||||||
|
{
|
||||||
|
mmfFile = _mmfFiles[filename] = MemoryMappedFile.OpenExisting(filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
using var viewAccessor = mmfFile.CreateViewAccessor(0, expectedSize, MemoryMappedFileAccess.Read);
|
||||||
var bytes = new byte[expectedSize];
|
var bytes = new byte[expectedSize];
|
||||||
viewAccessor.ReadArray(0, bytes, 0, expectedSize);
|
viewAccessor.ReadArray(0, bytes, 0, expectedSize);
|
||||||
return Encoding.UTF8.GetString(bytes);
|
return bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int ScreenShotToFile()
|
public int ScreenShotToFile()
|
||||||
|
|
|
@ -153,11 +153,31 @@ namespace BizHawk.Client.Common
|
||||||
{
|
{
|
||||||
return APIs.Comm.MMF.WriteToFile(mmf_filename, outputString);
|
return APIs.Comm.MMF.WriteToFile(mmf_filename, outputString);
|
||||||
}
|
}
|
||||||
|
[LuaMethod("mmfWriteBytes", "Write bytes to a memory mapped file")]
|
||||||
|
public int MmfWriteBytes(string mmf_filename, LuaTable byteArray)
|
||||||
|
{
|
||||||
|
return APIs.Comm.MMF.WriteToFile(mmf_filename, _th.EnumerateValues<double>(byteArray).Select(d => (byte)d).ToArray());
|
||||||
|
}
|
||||||
|
[LuaMethod("mmfCopyFromMemory", "Copy a section of the memory to a memory mapped file")]
|
||||||
|
public int MmfCopyFromMemory(string mmf_filename, long addr, int length, string domain)
|
||||||
|
{
|
||||||
|
return APIs.Comm.MMF.WriteToFile(mmf_filename, APIs.Memory.ReadByteRange(addr, length, domain).ToArray());
|
||||||
|
}
|
||||||
|
[LuaMethod("mmfCopyToMemory", "Copy a memory mapped file to a section of the memory")]
|
||||||
|
public void MmfCopyToMemory(string mmf_filename, long addr, int length, string domain)
|
||||||
|
{
|
||||||
|
APIs.Memory.WriteByteRange(addr, new List<byte>(APIs.Comm.MMF.ReadBytesFromFile(mmf_filename, length)), domain);
|
||||||
|
}
|
||||||
[LuaMethod("mmfRead", "Reads a string from a memory mapped file")]
|
[LuaMethod("mmfRead", "Reads a string from a memory mapped file")]
|
||||||
public string MmfRead(string mmf_filename, int expectedSize)
|
public string MmfRead(string mmf_filename, int expectedSize)
|
||||||
{
|
{
|
||||||
return APIs.Comm.MMF.ReadFromFile(mmf_filename, expectedSize);
|
return APIs.Comm.MMF.ReadFromFile(mmf_filename, expectedSize);
|
||||||
}
|
}
|
||||||
|
[LuaMethod("mmfReadBytes", "Reads bytes from a memory mapped file")]
|
||||||
|
public LuaTable MmfReadBytes(string mmf_filename, int expectedSize)
|
||||||
|
{
|
||||||
|
return _th.ListToTable(APIs.Comm.MMF.ReadBytesFromFile(mmf_filename, expectedSize));
|
||||||
|
}
|
||||||
|
|
||||||
// All HTTP related methods
|
// All HTTP related methods
|
||||||
[LuaMethod("httpTest", "tests HTTP connections")]
|
[LuaMethod("httpTest", "tests HTTP connections")]
|
||||||
|
|
Loading…
Reference in New Issue