Change encoding for sockets to UTF-8, allow ext. tools to override it

This commit is contained in:
YoshiRulz 2021-03-22 08:10:59 +10:00
parent f08fdc3859
commit 45488f2667
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
1 changed files with 5 additions and 4 deletions

View File

@ -72,13 +72,14 @@ namespace BizHawk.Client.Common
public string GetInfo() => $"{_targetAddr.HostIP}:{_targetAddr.Port}";
public string ReceiveMessage()
public string ReceiveMessage(Encoding encoding = null)
{
if (!Connected)
{
Connect();
}
var encoding1 = encoding ?? Encoding.UTF8;
var resp = "";
var receivedBytes = new byte[256];
var receivedLength = 1;
@ -87,7 +88,7 @@ namespace BizHawk.Client.Common
try
{
receivedLength = _soc.Receive(receivedBytes, receivedBytes.Length, 0);
resp += Encoding.ASCII.GetString(receivedBytes);
resp += encoding1.GetString(receivedBytes);
}
catch
{
@ -141,9 +142,9 @@ namespace BizHawk.Client.Common
return resp == "" ? "Failed to get a response" : resp;
}
public int SendString(string sendString)
public int SendString(string sendString, Encoding encoding = null)
{
var sentBytes = SendBytes(Encoding.ASCII.GetBytes(sendString));
var sentBytes = SendBytes((encoding ?? Encoding.UTF8).GetBytes(sendString));
Successful = sentBytes > 0;
return sentBytes;
}