mirror of
https://github.com/MrUnknownDE/VRCX.git
synced 2026-04-18 22:33:50 +02:00
Optimize RPC event parsing
This commit is contained in:
36
IPCClient.cs
36
IPCClient.cs
@@ -5,18 +5,22 @@
|
||||
// For a copy, see <https://opensource.org/licenses/MIT>.
|
||||
|
||||
using CefSharp;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO.Pipes;
|
||||
using System.Text;
|
||||
|
||||
namespace VRCX
|
||||
{
|
||||
class IPCClient
|
||||
internal class IPCClient
|
||||
{
|
||||
private NamedPipeServerStream _ipcServer;
|
||||
private byte[] _recvBuffer = new byte[1024 * 8];
|
||||
|
||||
private string _currentPacket;
|
||||
private VRCEventDeserialization.EventEntry _eventEntry;
|
||||
private readonly VRCEventDeserialization eventDeserialization = new VRCEventDeserialization();
|
||||
|
||||
public IPCClient(NamedPipeServerStream ipcServer)
|
||||
{
|
||||
@@ -51,6 +55,34 @@ namespace VRCX
|
||||
if (string.IsNullOrEmpty(packet))
|
||||
continue;
|
||||
|
||||
var eventData = System.Text.Json.JsonSerializer.Deserialize<VRCEventDeserialization.EventData>(packet);
|
||||
if (eventData.type == "OnEvent" && eventData.OnEventData.Code == 6)
|
||||
{
|
||||
var byteArray = Convert.FromBase64String(eventData.OnEventData.Parameters[245].ToString());
|
||||
_eventEntry = eventDeserialization.DeserializeData(byteArray);
|
||||
if (VRCEventDeserialization.ignoreEvents.Contains(_eventEntry.EventType))
|
||||
continue;
|
||||
|
||||
_eventEntry.type = "VRCEvent";
|
||||
_eventEntry.dt = eventData.dt;
|
||||
_eventEntry.senderId = eventData.OnEventData.Sender;
|
||||
var jsonData = System.Text.Json.JsonSerializer.Serialize(_eventEntry);
|
||||
MainForm.Instance.Browser.ExecuteScriptAsync("$app.ipcEvent", jsonData);
|
||||
continue;
|
||||
}
|
||||
else if (eventData.type == "OnEvent" && eventData.OnEventData.Code == 7)
|
||||
{
|
||||
_eventEntry = new VRCEventDeserialization.EventEntry
|
||||
{
|
||||
type = "Event7",
|
||||
dt = eventData.dt,
|
||||
senderId = eventData.OnEventData.Sender
|
||||
};
|
||||
var jsonData = System.Text.Json.JsonSerializer.Serialize(_eventEntry);
|
||||
MainForm.Instance.Browser.ExecuteScriptAsync("$app.ipcEvent", jsonData);
|
||||
continue;
|
||||
}
|
||||
|
||||
MainForm.Instance.Browser.ExecuteScriptAsync("$app.ipcEvent", packet);
|
||||
}
|
||||
|
||||
@@ -71,4 +103,4 @@ namespace VRCX
|
||||
ipcClient.EndWrite(asyncResult);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user