From a931d7514346c8c6206ed2f4e457bca8faadda80 Mon Sep 17 00:00:00 2001 From: YoshiRulz Date: Sun, 26 Jul 2020 04:43:50 +1000 Subject: [PATCH] Add string overload for WriteToFile and also use UTF-8 instead of ASCII to match reads -_- --- src/BizHawk.Client.Common/Api/MemoryMappedFiles.cs | 2 ++ src/BizHawk.Client.EmuHawk/Api/Libraries/CommApi.cs | 4 +--- .../tools/Lua/Libraries/CommLuaLibrary.cs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/BizHawk.Client.Common/Api/MemoryMappedFiles.cs b/src/BizHawk.Client.Common/Api/MemoryMappedFiles.cs index eb528d9286..7bd779bb95 100644 --- a/src/BizHawk.Client.Common/Api/MemoryMappedFiles.cs +++ b/src/BizHawk.Client.Common/Api/MemoryMappedFiles.cs @@ -61,5 +61,7 @@ namespace BizHawk.Client.Common return TryWrite(_mmfFiles[filename] = MemoryMappedFile.CreateOrOpen(filename, outputBytes.Length)); } } + + public int WriteToFile(string filename, string outputString) => WriteToFile(filename, Encoding.UTF8.GetBytes(outputString)); } } diff --git a/src/BizHawk.Client.EmuHawk/Api/Libraries/CommApi.cs b/src/BizHawk.Client.EmuHawk/Api/Libraries/CommApi.cs index ef4b5cf0a1..773f398e29 100644 --- a/src/BizHawk.Client.EmuHawk/Api/Libraries/CommApi.cs +++ b/src/BizHawk.Client.EmuHawk/Api/Libraries/CommApi.cs @@ -1,5 +1,3 @@ -using System.Text; - using BizHawk.Client.Common; namespace BizHawk.Client.EmuHawk @@ -34,7 +32,7 @@ namespace BizHawk.Client.EmuHawk public int MmfScreenshot() => GlobalWin.memoryMappedFiles.ScreenShotToFile(); - public int MmfWrite(string mmf_filename, string outputString) => GlobalWin.memoryMappedFiles.WriteToFile(mmf_filename, Encoding.ASCII.GetBytes(outputString)); + public int MmfWrite(string mmf_filename, string outputString) => GlobalWin.memoryMappedFiles.WriteToFile(mmf_filename, outputString); public string MmfRead(string mmf_filename, int expectedSize) => GlobalWin.memoryMappedFiles.ReadFromFile(mmf_filename, expectedSize); diff --git a/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/CommLuaLibrary.cs b/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/CommLuaLibrary.cs index 352f72b376..de71ccaea6 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/CommLuaLibrary.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/CommLuaLibrary.cs @@ -149,7 +149,7 @@ namespace BizHawk.Client.EmuHawk public int MmfWrite(string mmf_filename, string outputString) { CheckMmf(); - return GlobalWin.memoryMappedFiles.WriteToFile(mmf_filename, Encoding.ASCII.GetBytes(outputString)); + return GlobalWin.memoryMappedFiles.WriteToFile(mmf_filename, outputString); } [LuaMethod("mmfRead", "Reads a string from a memory mapped file")] public string MmfRead(string mmf_filename, int expectedSize)