Skip to content

Commit

Permalink
Always initialize MMF LUA functions
Browse files Browse the repository at this point in the history
  • Loading branch information
E-Sh4rk authored and YoshiRulz committed Jul 16, 2021
1 parent 308d348 commit 457ff87
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 20 deletions.
10 changes: 9 additions & 1 deletion src/BizHawk.Client.Common/Api/MemoryMappedFiles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,15 @@ public string ReadFromFile(string filename, int expectedSize)
return Encoding.UTF8.GetString(bytes);
}

public int ScreenShotToFile() => WriteToFile(Filename, _takeScreenshotCallback());
public int ScreenShotToFile()
{
if (Filename is null)
{
Console.WriteLine("MMF screenshot target not set; start EmuHawk with `--mmf=filename`");
return 0;
}
return WriteToFile(Filename, _takeScreenshotCallback());
}

public int WriteToFile(string filename, byte[] outputBytes)
{
Expand Down
19 changes: 3 additions & 16 deletions src/BizHawk.Client.Common/lua/CommonLibs/CommLuaLibrary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public int SocketServerSend(string SendString)
return APIs.Comm.Sockets.SendString(SendString);
}

[LuaMethod("socketServerSendBytes", "sends a string to the Socket server")]
[LuaMethod("socketServerSendBytes", "sends bytes to the Socket server")]
public int SocketServerSendBytes(LuaTable byteArray)
{
if (!CheckSocketServer()) return -1;
Expand Down Expand Up @@ -133,43 +133,30 @@ private bool CheckSocketServer()
[LuaMethod("mmfSetFilename", "Sets the filename for the screenshots")]
public void MmfSetFilename(string filename)
{
CheckMmf();
APIs.Comm.MMF.Filename = filename;
}

[LuaMethod("mmfGetFilename", "Gets the filename for the screenshots")]
public string MmfGetFilename()
{
CheckMmf();
return APIs.Comm.MMF?.Filename;
return APIs.Comm.MMF.Filename;
}

[LuaMethod("mmfScreenshot", "Saves screenshot to memory mapped file")]
public int MmfScreenshot()
{
CheckMmf();
return APIs.Comm.MMF.ScreenShotToFile();
}

[LuaMethod("mmfWrite", "Writes a string to a memory mapped file")]
public int MmfWrite(string mmf_filename, string outputString)
{
CheckMmf();
return APIs.Comm.MMF.WriteToFile(mmf_filename, outputString);
}
[LuaMethod("mmfRead", "Reads a string from a memory mapped file")]
public string MmfRead(string mmf_filename, int expectedSize)
{
CheckMmf();
return APIs.Comm.MMF?.ReadFromFile(mmf_filename, expectedSize);
}

private void CheckMmf()
{
if (APIs.Comm.MMF == null)
{
Log("Memory mapped file was not initialized, please initialize it via the command line");
}
return APIs.Comm.MMF.ReadFromFile(mmf_filename, expectedSize);
}

// All HTTP related methods
Expand Down
4 changes: 1 addition & 3 deletions src/BizHawk.Client.EmuHawk/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -605,9 +605,7 @@ void MainForm_MouseClick(object sender, MouseEventArgs e)
_argParser.HTTPAddresses == null
? null
: new HttpCommunication(NetworkingTakeScreenshot, _argParser.HTTPAddresses.Value.UrlGet, _argParser.HTTPAddresses.Value.UrlPost),
_argParser.MMFFilename == null
? null
: new MemoryMappedFiles(NetworkingTakeScreenshot, _argParser.MMFFilename),
new MemoryMappedFiles(NetworkingTakeScreenshot, _argParser.MMFFilename),
_argParser.SocketAddress == null
? null
: new SocketServer(NetworkingTakeScreenshot, _argParser.SocketAddress.Value.IP, _argParser.SocketAddress.Value.Port)
Expand Down

0 comments on commit 457ff87

Please sign in to comment.