/// <summary> /// Raise the OnClientBeforeMessageSent event. /// </summary> /// <param name="cl">Client that raised the event.</param> /// <param name="msg">Message to be sent.</param> internal void RaiseBeforeMessageSentEvent(ClientS cl, TCPMessage msg) { if (OnClientBeforeMessageSent != null) { OnClientBeforeMessageSent(this, (BaseMessageClientS)cl, msg); } }
/// <summary> /// Send a message structure to the server. /// </summary> /// <param name="msg">Message structure to be send.</param> /// <exception cref="TCPLibrary.Core.NotConnectedException"></exception> public void Send(TCPMessage msg) { if (OnBeforeMessageSent != null) { OnBeforeMessageSent(this, msg); } base.Send(new Data(msg.ToByteArray())); }
/// <summary> /// Parse the raw data sent to the server and create Message structures. /// </summary> /// <param name="sender">Sender of the event.</param> /// <param name="Data">Line of data sent.</param> void BaseMessageClient_OnDataSent(Client sender, Data Data) { TCPMessage msg = TCPMessage.FromByteArray(Data.Message); if (OnAfterMessageSent != null) { OnAfterMessageSent(sender, msg); } }
/// <summary> /// Kick the client if the server reached the maximum allowed number of clients. /// </summary> /// <param name="server">Server raising the event.</param> /// <param name="client">Client connecting to the server.</param> /// <param name="args">Specify if the client should be accepted into the server.</param> void BaseMessageServer_OnClientBeforeConnect(Server server, ClientS client, CancelArgs args) { if ((Clients.Count >= UserLimit) && (UserLimit != 0)) { TCPMessage msg = new TCPMessage(); msg.MessageType = MessageType.MaxUsers; ((BaseMessageClientS)client).Send(msg); args.Cancel = true; } }
/// <summary> /// Parse a string and create a Message structure. /// </summary> /// <param name="data">Raw data.</param> /// <returns>Parsed message structure.</returns> static public TCPMessage FromByteArray(byte[] data) { MemoryStream ms = new MemoryStream(); BinaryWriter sw = new BinaryWriter(ms); sw.Write(data, 0, data.Length); sw.Flush(); ms.Position = 0; BinaryFormatter formatter = new BinaryFormatter(); TCPMessage msg = formatter.Deserialize(ms) as TCPMessage; return(msg); }
/// <summary> /// Trasform the line of data received into a Message structure and raise /// the event linked. /// </summary> /// <param name="server">Server raising the event.</param> /// <param name="sender">Client sending the data.</param> /// <param name="Data">Line of data received.</param> void BaseMessageServer_OnDataReceived(Server server, ClientS sender, Data Data) { TCPMessage msg = null; try { msg = TCPMessage.FromByteArray(Data.Message); } catch (Exception) { } if (msg != null) { if (OnClientMessageReceived != null) { OnClientMessageReceived(this, (BaseMessageClientS)sender, msg); } } }
/// <summary> /// Trasform the line of data sent into a Message structure and raise /// the event linked. /// </summary> /// <param name="server">Server raising the event.</param> /// <param name="receiver">Client that will receive the Message.</param> /// <param name="Data">Line of data sent.</param> void BaseMessageServer_OnDataSent(Server server, ClientS receiver, Data Data) { TCPMessage msg = null; try { msg = TCPMessage.FromByteArray(Data.Message); } catch (Exception) { } if (msg != null) { if (OnClientAfterMessageSent != null) { OnClientAfterMessageSent(this, (BaseMessageClientS)receiver, msg); } } }
/// <summary> /// Parse the raw data received from the server and create Message structures. /// </summary> /// <param name="sender">Sender of the event.</param> /// <param name="Data">Line of data received.</param> void BaseMessageClient_OnDataReceived(Client sender, Data Data) { TCPMessage msg = null; try { msg = TCPMessage.FromByteArray(Data.Message); } catch (Exception) { } if (msg != null) { if (OnMessageReceived != null) { OnMessageReceived(sender, msg); } } }
private void cmdGoToStart_Click(object sender, EventArgs e) { TCPMessage msg = new TCPMessage(); msg.MessageType = MessageType.RunToCursor; msg.Parameters.Add(0); Program.Clients.Find(a => a.IPAddress == lstProcesses.SelectedItem.ToString()).Send(msg); }
private void btnRunToSelection_Click(object sender, EventArgs e) { if (treTreeView.SelectedNode != null) { TCPMessage msg = new TCPMessage(); msg.MessageType = MessageType.RunToCursor; msg.Parameters.Add(Convert.ToInt32(treTreeView.SelectedNode.Text.Split(new string[]{" - "}, StringSplitOptions.None)[0])); Program.Clients.Find(a => a.IPAddress == lstProcesses.SelectedItem.ToString()).Send(msg); } else MessageBox.Show("You have not selected a node to jump to"); }
private void btnStep_Click(object sender, EventArgs e) { TCPMessage msg = new TCPMessage(); msg.MessageType = MessageType.Step; Program.Clients.Find(a => a.IPAddress == lstProcesses.SelectedItem.ToString()).Send(msg); }
private void chkDebugMode_CheckedChanged(object sender, EventArgs e) { if (lstProcesses.SelectedIndex != -1) { TCPMessage msg = new TCPMessage(); msg.MessageType = MessageType.SetDebugMode; msg.Parameters.Add(chkDebugMode.Checked); Program.Clients.Find(a => a.IPAddress == lstProcesses.SelectedItem.ToString()).Send(msg); } }
private void lstProcesses_SelectedIndexChanged(object sender, EventArgs e) { if (lstProcesses.SelectedIndex != -1) { chkDebugMode.Enabled = true; TCPMessage msg = new TCPMessage(); msg.MessageType = MessageType.GetDebugMode; msg.Parameters.Add(chkDebugMode.Checked); Program.Clients.Find(a => a.IPAddress == lstProcesses.SelectedItem.ToString()).Send(msg); msg = new TCPMessage(); msg.MessageType = MessageType.SizeDump; Program.Clients.Find(a => a.IPAddress == lstProcesses.SelectedItem.ToString()).Send(msg); msg = new TCPMessage(); msg.MessageType = MessageType.Statistics; Program.Clients.Find(a => a.IPAddress == lstProcesses.SelectedItem.ToString()).Send(msg); } else { chkDebugMode.Enabled = false; } }
/// <summary> /// Send a Message structure to the client. /// </summary> /// <param name="msg">Message to be sent.</param> /// <exception cref="TCPLibrary.Core.NotConnectedException" /> public void Send(TCPMessage msg) { ((BaseMessageServer)_server).RaiseBeforeMessageSentEvent(this, msg); base.Send(new Data(msg.ToByteArray())); }
/// <summary> /// Send a message to all clients in broadcast. /// </summary> /// <param name="Data">Message to be sent.</param> public void Broadcast(TCPMessage Data) { base.Broadcast(new Data(Data.ToByteArray())); }
public unsafe void Run(GSDump dump, int rendererOverride) { QueueMessage = new Queue<TCPMessage>(); Running = true; ExternalEvent = new AutoResetEvent(true); GSinit(); byte[] tempregisters = new byte[8192]; Array.Copy(dump.Registers, tempregisters, 8192); fixed (byte* pointer = tempregisters) { GSsetBaseMem(new IntPtr(pointer)); Int32 HWND = 0; GSopen(new IntPtr(&HWND), "", rendererOverride); GSsetGameCRC(dump.CRC, 0); fixed (byte* freeze = dump.StateData) { byte[] GSFreez = new byte[8]; Array.Copy(BitConverter.GetBytes(dump.StateData.Length), 0, GSFreez, 0, 4); Array.Copy(BitConverter.GetBytes(new IntPtr(freeze).ToInt32()), 0, GSFreez, 4, 4); fixed (byte* fr = GSFreez) { int ris = GSfreeze(0, new IntPtr(fr)); if (ris == -1) { DumpTooOld = true; return; } GSVSync(1); while (Running) { if (!NativeMethods.IsWindowVisible(new IntPtr(HWND))) { Running = false; break; } GSreset(); Marshal.Copy(dump.Registers, 0, new IntPtr(pointer), 8192); GSsetBaseMem(new IntPtr(pointer)); GSfreeze(0, new IntPtr(fr)); for (int i = 0; i < dump.Data.Count; i++) { GSData itm = dump.Data[i]; CurrentGIFPacket = itm; if (DebugMode) { if (RunTo != -1) { if (i == RunTo) { RunTo = -1; int idxnextReg = dump.Data.FindIndex(i, a => a.id == GSType.Registers); if (idxnextReg != -1) { Step(dump.Data[idxnextReg], pointer); } GSData g = new GSData(); g.id = GSType.VSync; Step(g, pointer); TCPMessage Msg = new TCPMessage(); Msg.MessageType = MessageType.RunToCursor; Msg.Parameters.Add(i); Program.Client.Send(Msg); ExternalEvent.Set(); } else { Step(itm, pointer); } } else { while (!ThereIsWork && Running) { NativeMessage message; while (NativeMethods.PeekMessage(out message, IntPtr.Zero, 0, 0, 1)) { if (!NativeMethods.IsWindowVisible(new IntPtr(HWND))) { Running = false; } NativeMethods.TranslateMessage(ref message); NativeMethods.DispatchMessage(ref message); } } ThereIsWork = false; if (QueueMessage.Count > 0) { TCPMessage Mess = QueueMessage.Dequeue(); switch (Mess.MessageType) { case MessageType.Step: RunTo = i; break; case MessageType.RunToCursor: RunTo = (int)Mess.Parameters[0]; break; case MessageType.RunToNextVSync: RunTo = dump.Data.FindIndex(i, a => a.id == GSType.VSync); break; default: break; } break; } } } else { Step(itm, pointer); } } } GSclose(); GSshutdown(); } } } }
static void Client_OnMessageReceived(TCPLibrary.Core.Client sender, TCPLibrary.MessageBased.Core.TCPMessage Mess) { TCPMessage msg; switch (Mess.MessageType) { case TCPLibrary.MessageBased.Core.MessageType.Connect: break; case TCPLibrary.MessageBased.Core.MessageType.MaxUsers: break; case TCPLibrary.MessageBased.Core.MessageType.SizeDump: SendDumpSize(); break; case MessageType.Statistics: SendStatistics(); break; case MessageType.SetDebugMode: wrap.DebugMode = (Boolean)Mess.Parameters[0]; msg = new TCPMessage(); msg.MessageType = MessageType.GetDebugMode; msg.Parameters.Add(wrap.DebugMode); Client.Send(msg); if (wrap.DebugMode) { msg = new TCPMessage(); msg.MessageType = MessageType.DebugState; msg.Parameters.AddRange(wrap.GetGifPackets(dump)); Client.Send(msg); msg = new TCPMessage(); msg.MessageType = MessageType.Step; msg.Parameters.Add(dump.Data.FindIndex(a => a == wrap.CurrentGIFPacket)); Client.Send(msg); } break; case MessageType.GetDebugMode: msg = new TCPMessage(); msg.MessageType = MessageType.GetDebugMode; msg.Parameters.Add(wrap.DebugMode); Client.Send(msg); if (wrap.DebugMode) { msg = new TCPMessage(); msg.MessageType = MessageType.DebugState; msg.Parameters.AddRange(wrap.GetGifPackets(dump)); Client.Send(msg); msg = new TCPMessage(); msg.MessageType = MessageType.Step; msg.Parameters.Add(dump.Data.FindIndex(a => a == wrap.CurrentGIFPacket)); Client.Send(msg); } break; case MessageType.PacketInfo: int id = (int)Mess.Parameters[0]; msg = new TCPMessage(); msg.MessageType = MessageType.PacketInfo; msg.Parameters.Add(wrap.GetGifPacketInfo(dump, id)); Client.Send(msg); break; case MessageType.Step: case MessageType.RunToCursor: case MessageType.RunToNextVSync: wrap.ExternalEvent.WaitOne(); wrap.ExternalEvent.Reset(); wrap.QueueMessage.Enqueue(Mess); wrap.ThereIsWork = true; break; default: break; } }
private static void SendDumpSize() { TCPMessage msg; msg = new TCPMessage(); msg.MessageType = MessageType.SizeDump; if (dump != null) msg.Parameters.Add(dump.Size); else msg.Parameters.Add(0); Client.Send(msg); }
private void cmdGoToNextVSync_Click(object sender, EventArgs e) { TCPMessage msg = new TCPMessage(); msg.MessageType = MessageType.RunToNextVSync; Program.Clients.Find(a => a.IPAddress == lstProcesses.SelectedItem.ToString()).Send(msg); }
static void Main(String[] args) { if (args.Length == 4) { // do this first, else racy mess ;) wrap = new GSDXWrapper(); try { Client = new TCPLibrary.MessageBased.Core.BaseMessageClient(); Client.OnMessageReceived += new TCPLibrary.MessageBased.Core.BaseMessageClient.MessageReceivedHandler(Client_OnMessageReceived); Client.Connect("localhost", 9999); } catch (Exception) { Client = null; } Thread thd = new Thread(new ThreadStart(delegate { while (true) { IntPtr pt = Process.GetCurrentProcess().MainWindowHandle; if (ChangeIcon) { if (pt.ToInt64() != 0) { NativeMethods.SetClassLong(pt, -14, Resources.AppIcon.Handle.ToInt64()); ChangeIcon = false; } } Int32 tmp = NativeMethods.GetAsyncKeyState(0x1b) & 0xf; if (tmp != 0) Process.GetCurrentProcess().Kill(); Thread.Sleep(16); } })); thd.IsBackground = true; thd.Start(); // Retrieve parameters String DLLPath = args[0]; String DumpPath = args[1]; String Operation = args[2]; Int32 Renderer = Convert.ToInt32(args[3]); wrap.Load(DLLPath); Directory.SetCurrentDirectory(Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory + "GSDumpGSDXConfigs\\" + Path.GetFileName(DLLPath) + "\\")); if (Operation == "GSReplay") { dump = GSDump.LoadDump(DumpPath); if (Client != null) { SendStatistics(); SendDumpSize(); } wrap.Run(dump, Renderer); ChangeIcon = true; } else wrap.GSConfig(); wrap.Unload(); if (GSDXWrapper.DumpTooOld) { if (Client != null) { TCPMessage msg = new TCPMessage(); msg.MessageType = MessageType.StateOld; Client.Send(msg); } } if (Client != null) Client.Disconnect(); } else { Clients = new List<TCPLibrary.MessageBased.Core.BaseMessageClientS>(); Server = new TCPLibrary.MessageBased.Core.BaseMessageServer(); Server.OnClientMessageReceived += new BaseMessageServer.MessageReceivedHandler(Server_OnClientMessageReceived); Server.OnClientAfterConnect += new TCPLibrary.Core.Server.ConnectedHandler(Server_OnClientAfterConnect); Server.OnClientAfterDisconnected += new TCPLibrary.Core.Server.DisconnectedHandler(Server_OnClientAfterDisconnected); Server.Port = 9999; Server.Enabled = true; Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); frmMain = new GSDumpGUI(); Application.Run(frmMain); Server.Enabled = false; } }
private void treTreeView_AfterSelect(object sender, TreeViewEventArgs e) { if (treTreeView.SelectedNode != null) { TCPMessage msg = new TCPMessage(); msg.MessageType = MessageType.PacketInfo; msg.Parameters.Add(Convert.ToInt32(treTreeView.SelectedNode.Text.Split(new string[] { " - " }, StringSplitOptions.None)[0])); Program.Clients.Find(a => a.IPAddress == lstProcesses.SelectedItem.ToString()).Send(msg); } treTreeView.SelectedNode = e.Node; }
private static void SendStatistics() { TCPMessage msg; msg = new TCPMessage(); msg.MessageType = MessageType.Statistics; if (dump != null) { msg.Parameters.Add(dump.Data.Count); msg.Parameters.Add(dump.Data.FindAll(a => (int)a.id == 0 && (a.data[0] == 3 || a.data[0] == 0)).Count); msg.Parameters.Add(dump.Data.FindAll(a => (int)a.id == 0 && a.data[0] == 1).Count); msg.Parameters.Add(dump.Data.FindAll(a => (int)a.id == 0 && a.data[0] == 2).Count); msg.Parameters.Add(dump.Data.FindAll(a => (int)a.id == 1).Count); msg.Parameters.Add(dump.Data.FindAll(a => (int)a.id == 2).Count); msg.Parameters.Add(dump.Data.FindAll(a => (int)a.id == 3).Count); } else { msg.Parameters.Add(0); msg.Parameters.Add(0); msg.Parameters.Add(0); msg.Parameters.Add(0); msg.Parameters.Add(0); msg.Parameters.Add(0); msg.Parameters.Add(0); } Client.Send(msg); }
/// <summary> /// Send a message structure to the server. /// </summary> /// <param name="msg">Message structure to be send.</param> /// <exception cref="TCPLibrary.Core.NotConnectedException"></exception> public void Send(TCPMessage msg) { if (OnBeforeMessageSent != null) OnBeforeMessageSent(this, msg); base.Send(new Data(msg.ToByteArray())); }
/// <summary> /// Raise the OnClientBeforeMessageSent event. /// </summary> /// <param name="cl">Client that raised the event.</param> /// <param name="msg">Message to be sent.</param> internal void RaiseBeforeMessageSentEvent(ClientS cl, TCPMessage msg) { if (OnClientBeforeMessageSent != null) OnClientBeforeMessageSent(this, (BaseMessageClientS)cl, msg); }
static void Server_OnClientMessageReceived(BaseMessageServer server, BaseMessageClientS sender, TCPMessage Mess) { switch (Mess.MessageType) { case MessageType.Connect: break; case MessageType.MaxUsers: break; case MessageType.SizeDump: frmMain.Invoke(new Action<object>(delegate(object e) { frmMain.txtDumpSize.Text = (((int)Mess.Parameters[0]) / 1024f / 1024f).ToString("F2") + " MB"; }), new object[] { null }); break; case MessageType.Statistics: frmMain.Invoke(new Action<object>(delegate(object e) { frmMain.txtGIFPackets.Text = ((int)Mess.Parameters[0]).ToString(); frmMain.txtPath1.Text = ((int)Mess.Parameters[1]).ToString(); frmMain.txtPath2.Text = ((int)Mess.Parameters[2]).ToString(); frmMain.txtPath3.Text = ((int)Mess.Parameters[3]).ToString(); frmMain.txtReadFifo.Text = ((int)Mess.Parameters[5]).ToString(); frmMain.txtVSync.Text = ((int)Mess.Parameters[4]).ToString(); frmMain.txtRegisters.Text = ((int)Mess.Parameters[6]).ToString(); }), new object[] { null }); break; case MessageType.StateOld: frmMain.Invoke(new Action<object>(delegate(object e) { MessageBox.Show("Savestate too old to be read. :(", "Warning"); frmMain.Focus(); }), new object[] { null }); break; case MessageType.GetDebugMode: frmMain.Invoke(new Action<object>(delegate(object e) { frmMain.chkDebugMode.Checked = (Boolean)Mess.Parameters[0]; frmMain.lblGif.Enabled = frmMain.chkDebugMode.Checked; frmMain.btnRunToSelection.Enabled = frmMain.chkDebugMode.Checked; frmMain.treTreeView.Enabled = frmMain.chkDebugMode.Checked; frmMain.btnStep.Enabled = frmMain.chkDebugMode.Checked; frmMain.cmdGoToStart.Enabled = frmMain.chkDebugMode.Checked; frmMain.cmdGoToNextVSync.Enabled = frmMain.chkDebugMode.Checked; frmMain.treeGifPacketContent.Enabled = frmMain.chkDebugMode.Checked; if (frmMain.chkDebugMode.Checked == false) frmMain.treTreeView.Nodes.Clear(); }), new object[] { null }); break; case MessageType.DebugState: frmMain.Invoke(new Action<object>(delegate(object e) { frmMain.treTreeView.Nodes.Clear(); List<TreeNode> parents = new List<TreeNode>(); List<TreeNode> nodes = new List<TreeNode>(); foreach (var itm in Mess.Parameters) { String[] parts = itm.ToString().Split(new char[] { '|' }); switch (parts[1]) { case "Transfer": TreeNode tn2 = new TreeNode(); tn2.Name = parts[0]; tn2.Text = parts[0] + " - " + parts[1] + " - " + parts[2] + " - " + parts[3] + " byte"; nodes.Add(tn2); break; case "ReadFIFO2": TreeNode tn3 = new TreeNode(); tn3.Name = parts[0]; tn3.Text = parts[0] + " - " + parts[1] + " - " + parts[2] + " byte"; nodes.Add(tn3); break; case "VSync": TreeNode tn = new TreeNode(); tn.Name = parts[0]; tn.Text = parts[0] + " - " + parts[1] + " - " + parts[2] + " byte"; tn.Nodes.AddRange(nodes.ToArray()); parents.Add(tn); nodes.Clear(); break; case "Registers": TreeNode tn4 = new TreeNode(); tn4.Name = parts[0]; tn4.Text = parts[0] + " - " + parts[1] + " - " + parts[2] + " byte"; nodes.Add(tn4); break; } } frmMain.treTreeView.Nodes.AddRange(parents.ToArray()); }), new object[] { null }); break; case MessageType.Step: case MessageType.RunToCursor: frmMain.Invoke(new Action<object>(delegate(object e) { int idtoselect = (int)Mess.Parameters[0]; TreeNode[] noes = frmMain.treTreeView.Nodes.Find(idtoselect.ToString(), true); if (noes.Length > 0) { if (CurrentNode != null) CurrentNode.BackColor = Color.White; noes[0].BackColor = Color.LightBlue; CurrentNode = noes[0]; frmMain.treTreeView.SelectedNode = noes[0]; } }), new object[] { null }); break; case MessageType.PacketInfo: frmMain.Invoke(new Action<object>(delegate(object e) { if (Mess.Parameters[0].GetType() == typeof(GIFTag)) { GIFTag tag = (GIFTag)Mess.Parameters[0]; frmMain.txtGifPacketSize.Text = tag.size + " bytes"; frmMain.treeGifPacketContent.Nodes.Clear(); frmMain.treeGifPacketContent.Nodes.Add("Transfer Path " + tag.path); frmMain.treeGifPacketContent.Nodes[0].Nodes.Add("nloop = " + tag.nloop); frmMain.treeGifPacketContent.Nodes[0].Nodes.Add("eop = " + tag.eop); frmMain.treeGifPacketContent.Nodes[0].Nodes.Add("flg = " + tag.flg.ToString()); frmMain.treeGifPacketContent.Nodes[0].Nodes.Add("pre = " + tag.pre); TreeNode nodePrim = new TreeNode("Prim"); string[] prim = tag.prim.ToString().Split(new char[] { '@' }); for (int j = 0; j < prim.Length; j++) nodePrim.Nodes.Add(prim[j]); frmMain.treeGifPacketContent.Nodes[0].Nodes.Add(nodePrim); frmMain.treeGifPacketContent.Nodes[0].Nodes.Add("nreg = " + (tag.nreg == 0 ? (16).ToString() : tag.nreg.ToString())); TreeNode nodeReg = new TreeNode("reg"); for (int j = 0; j < tag.regs.Count; j++) { string[] fvals = tag.regs[j].ToString().Split(new char[] { '@' }, StringSplitOptions.RemoveEmptyEntries); TreeNode nodeObj = new TreeNode(fvals[0]); for (int z = 1; z < fvals.Length; z++) { TreeNode item = new TreeNode(fvals[z]); nodeObj.Nodes.Add(item); } nodeReg.Nodes.Add(nodeObj); } frmMain.treeGifPacketContent.Nodes[0].Nodes.Add(nodeReg); frmMain.treeGifPacketContent.Nodes[0].ExpandAll(); } else { String[] vals = Mess.Parameters[0].ToString().Split('|'); frmMain.txtGifPacketSize.Text = vals[0] + " bytes"; frmMain.treeGifPacketContent.Nodes.Clear(); frmMain.treeGifPacketContent.Nodes.Add(vals[1]); frmMain.treeGifPacketContent.Nodes[0].ExpandAll(); } }), new object[] { null }); break; default: break; } }