/[pcsx2_0.9.7]/trunk/tools/GSDumpGUI/Core/Program.cs
ViewVC logotype

Contents of /trunk/tools/GSDumpGUI/Core/Program.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 290 - (show annotations) (download)
Sat Dec 25 02:51:30 2010 UTC (9 years, 1 month ago) by william
File size: 20416 byte(s)
Auto Commited Import of: pcsx2-0.9.7-DEBUG (upstream: v0.9.7.4139 local: v0.9.7.283-latest) in ./trunk
1 using System;
2 using System.Collections.Generic;
3 using System.Windows.Forms;
4 using Specialized = System.Collections.Specialized;
5 using Reflection = System.Reflection;
6 using System.Runtime.InteropServices;
7 using System.Threading;
8 using System.Diagnostics;
9 using GSDumpGUI.Properties;
10 using System.IO;
11 using TCPLibrary.MessageBased.Core;
12 using System.Drawing;
13
14 namespace GSDumpGUI
15 {
16 static class Program
17 {
18 static public GSDumpGUI frmMain;
19 static public TCPLibrary.MessageBased.Core.BaseMessageServer Server;
20 static public List<TCPLibrary.MessageBased.Core.BaseMessageClientS> Clients;
21
22 static public TCPLibrary.MessageBased.Core.BaseMessageClient Client;
23 static private Boolean ChangeIcon;
24 static private GSDump dump;
25 static private GSDXWrapper wrap;
26
27 static private TreeNode CurrentNode;
28
29 [STAThread]
30 static void Main(String[] args)
31 {
32 if (args.Length == 4)
33 {
34 // do this first, else racy mess ;)
35 wrap = new GSDXWrapper();
36
37 try
38 {
39 Client = new TCPLibrary.MessageBased.Core.BaseMessageClient();
40 Client.OnMessageReceived += new TCPLibrary.MessageBased.Core.BaseMessageClient.MessageReceivedHandler(Client_OnMessageReceived);
41 Client.Connect("localhost", 9999);
42 }
43 catch (Exception)
44 {
45 Client = null;
46 }
47
48 Thread thd = new Thread(new ThreadStart(delegate
49 {
50 while (true)
51 {
52 IntPtr pt = Process.GetCurrentProcess().MainWindowHandle;
53 if (ChangeIcon)
54 {
55 if (pt.ToInt64() != 0)
56 {
57 NativeMethods.SetClassLong(pt, -14, Resources.AppIcon.Handle.ToInt64());
58 ChangeIcon = false;
59 }
60 }
61
62 Int32 tmp = NativeMethods.GetAsyncKeyState(0x1b) & 0xf;
63 if (tmp != 0)
64 Process.GetCurrentProcess().Kill();
65 Thread.Sleep(16);
66 }
67 }));
68 thd.IsBackground = true;
69 thd.Start();
70
71 // Retrieve parameters
72 String DLLPath = args[0];
73 String DumpPath = args[1];
74 String Operation = args[2];
75 Int32 Renderer = Convert.ToInt32(args[3]);
76
77 wrap.Load(DLLPath);
78 Directory.SetCurrentDirectory(Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory + "GSDumpGSDXConfigs\\" + Path.GetFileName(DLLPath) + "\\"));
79 if (Operation == "GSReplay")
80 {
81 dump = GSDump.LoadDump(DumpPath);
82
83 if (Client != null)
84 {
85 SendStatistics();
86 SendDumpSize();
87 }
88
89 wrap.Run(dump, Renderer);
90 ChangeIcon = true;
91 }
92 else
93 wrap.GSConfig();
94 wrap.Unload();
95
96 if (GSDXWrapper.DumpTooOld)
97 {
98 if (Client != null)
99 {
100 TCPMessage msg = new TCPMessage();
101 msg.MessageType = MessageType.StateOld;
102 Client.Send(msg);
103 }
104 }
105
106 if (Client != null)
107 Client.Disconnect();
108 }
109 else
110 {
111 Clients = new List<TCPLibrary.MessageBased.Core.BaseMessageClientS>();
112
113 Server = new TCPLibrary.MessageBased.Core.BaseMessageServer();
114 Server.OnClientMessageReceived += new BaseMessageServer.MessageReceivedHandler(Server_OnClientMessageReceived);
115 Server.OnClientAfterConnect += new TCPLibrary.Core.Server.ConnectedHandler(Server_OnClientAfterConnect);
116 Server.OnClientAfterDisconnected += new TCPLibrary.Core.Server.DisconnectedHandler(Server_OnClientAfterDisconnected);
117 Server.Port = 9999;
118 Server.Enabled = true;
119
120 Application.EnableVisualStyles();
121 Application.SetCompatibleTextRenderingDefault(false);
122 frmMain = new GSDumpGUI();
123 Application.Run(frmMain);
124
125 Server.Enabled = false;
126 }
127 }
128
129 static void Server_OnClientAfterDisconnected(TCPLibrary.Core.Server server, TCPLibrary.Core.ClientS sender)
130 {
131 Clients.Remove((TCPLibrary.MessageBased.Core.BaseMessageClientS)sender);
132 RefreshList(false);
133 }
134
135 static void Server_OnClientMessageReceived(BaseMessageServer server, BaseMessageClientS sender, TCPMessage Mess)
136 {
137 switch (Mess.MessageType)
138 {
139 case MessageType.Connect:
140 break;
141 case MessageType.MaxUsers:
142 break;
143 case MessageType.SizeDump:
144 frmMain.Invoke(new Action<object>(delegate(object e)
145 {
146 frmMain.txtDumpSize.Text = (((int)Mess.Parameters[0]) / 1024f / 1024f).ToString("F2") + " MB";
147 }), new object[] { null });
148 break;
149 case MessageType.Statistics:
150 frmMain.Invoke(new Action<object>(delegate(object e)
151 {
152 frmMain.txtGIFPackets.Text = ((int)Mess.Parameters[0]).ToString();
153 frmMain.txtPath1.Text = ((int)Mess.Parameters[1]).ToString();
154 frmMain.txtPath2.Text = ((int)Mess.Parameters[2]).ToString();
155 frmMain.txtPath3.Text = ((int)Mess.Parameters[3]).ToString();
156 frmMain.txtReadFifo.Text = ((int)Mess.Parameters[5]).ToString();
157 frmMain.txtVSync.Text = ((int)Mess.Parameters[4]).ToString();
158 frmMain.txtRegisters.Text = ((int)Mess.Parameters[6]).ToString();
159 }), new object[] { null });
160 break;
161 case MessageType.StateOld:
162 frmMain.Invoke(new Action<object>(delegate(object e)
163 {
164 MessageBox.Show("Savestate too old to be read. :(", "Warning");
165 frmMain.Focus();
166 }), new object[] { null });
167 break;
168 case MessageType.GetDebugMode:
169 frmMain.Invoke(new Action<object>(delegate(object e)
170 {
171 frmMain.chkDebugMode.Checked = (Boolean)Mess.Parameters[0];
172
173 frmMain.lblGif.Enabled = frmMain.chkDebugMode.Checked;
174 frmMain.btnRunToSelection.Enabled = frmMain.chkDebugMode.Checked;
175 frmMain.treTreeView.Enabled = frmMain.chkDebugMode.Checked;
176 frmMain.btnStep.Enabled = frmMain.chkDebugMode.Checked;
177 frmMain.cmdGoToStart.Enabled = frmMain.chkDebugMode.Checked;
178 frmMain.cmdGoToNextVSync.Enabled = frmMain.chkDebugMode.Checked;
179 frmMain.treeGifPacketContent.Enabled = frmMain.chkDebugMode.Checked;
180 if (frmMain.chkDebugMode.Checked == false)
181 frmMain.treTreeView.Nodes.Clear();
182
183 }), new object[] { null });
184 break;
185 case MessageType.DebugState:
186 frmMain.Invoke(new Action<object>(delegate(object e)
187 {
188 frmMain.treTreeView.Nodes.Clear();
189 List<TreeNode> parents = new List<TreeNode>();
190 List<TreeNode> nodes = new List<TreeNode>();
191 foreach (var itm in Mess.Parameters)
192 {
193 String[] parts = itm.ToString().Split(new char[] { '|' });
194 switch (parts[1])
195 {
196 case "Transfer":
197 TreeNode tn2 = new TreeNode();
198 tn2.Name = parts[0];
199 tn2.Text = parts[0] + " - " + parts[1] + " - " + parts[2] + " - " + parts[3] + " byte";
200 nodes.Add(tn2);
201 break;
202 case "ReadFIFO2":
203 TreeNode tn3 = new TreeNode();
204 tn3.Name = parts[0];
205 tn3.Text = parts[0] + " - " + parts[1] + " - " + parts[2] + " byte";
206 nodes.Add(tn3);
207 break;
208 case "VSync":
209 TreeNode tn = new TreeNode();
210 tn.Name = parts[0];
211 tn.Text = parts[0] + " - " + parts[1] + " - " + parts[2] + " byte";
212 tn.Nodes.AddRange(nodes.ToArray());
213 parents.Add(tn);
214
215 nodes.Clear();
216 break;
217 case "Registers":
218 TreeNode tn4 = new TreeNode();
219 tn4.Name = parts[0];
220 tn4.Text = parts[0] + " - " + parts[1] + " - " + parts[2] + " byte";
221 nodes.Add(tn4);
222 break;
223 }
224 }
225 frmMain.treTreeView.Nodes.AddRange(parents.ToArray());
226 }), new object[] { null });
227 break;
228 case MessageType.Step:
229 case MessageType.RunToCursor:
230 frmMain.Invoke(new Action<object>(delegate(object e)
231 {
232 int idtoselect = (int)Mess.Parameters[0];
233 TreeNode[] noes = frmMain.treTreeView.Nodes.Find(idtoselect.ToString(), true);
234 if (noes.Length > 0)
235 {
236 if (CurrentNode != null)
237 CurrentNode.BackColor = Color.White;
238 noes[0].BackColor = Color.LightBlue;
239 CurrentNode = noes[0];
240 frmMain.treTreeView.SelectedNode = noes[0];
241 }
242 }), new object[] { null });
243 break;
244 case MessageType.PacketInfo:
245 frmMain.Invoke(new Action<object>(delegate(object e)
246 {
247 if (Mess.Parameters[0].ToString() != "No Data Available")
248 {
249 string[] vals = Mess.Parameters[0].ToString().Split('|');
250 frmMain.txtGifPacketSize.Text = vals[0] + " bytes";
251
252 frmMain.treeGifPacketContent.Nodes.Clear();
253
254 frmMain.treeGifPacketContent.Nodes.Add(vals[1]);
255
256 if (vals.Length > 2)
257 {
258 frmMain.treeGifPacketContent.Nodes[0].Nodes.Add(vals[2]);
259 frmMain.treeGifPacketContent.Nodes[0].Nodes.Add(vals[3]);
260 frmMain.treeGifPacketContent.Nodes[0].Nodes.Add(vals[4]);
261 frmMain.treeGifPacketContent.Nodes[0].Nodes.Add(vals[5]);
262
263 TreeNode nodePrim = new TreeNode("Prim");
264 string[] prim = vals[6].Split('~');
265 for (int j = 1; j < prim.Length; j++)
266 {
267 nodePrim.Nodes.Add(prim[j]);
268 }
269 frmMain.treeGifPacketContent.Nodes[0].Nodes.Add(nodePrim);
270
271 frmMain.treeGifPacketContent.Nodes[0].Nodes.Add(vals[7]);
272
273 TreeNode nodeReg = new TreeNode("reg");
274 string[] reg = vals[8].Split(new char[]{'~'}, StringSplitOptions.RemoveEmptyEntries);
275 for (int j = 1; j < reg.Length; j++)
276 {
277 nodeReg.Nodes.Add(reg[j]);
278 }
279 frmMain.treeGifPacketContent.Nodes[0].Nodes.Add(nodeReg);
280 }
281 frmMain.treeGifPacketContent.Nodes[0].ExpandAll();
282 }
283 else
284 {
285 frmMain.treeGifPacketContent.Nodes.Clear();
286
287 frmMain.treeGifPacketContent.Nodes.Add(Mess.Parameters[0].ToString());
288 }
289 }), new object[] { null });
290 break;
291 default:
292 break;
293 }
294 }
295
296 static void Client_OnMessageReceived(TCPLibrary.Core.Client sender, TCPLibrary.MessageBased.Core.TCPMessage Mess)
297 {
298 TCPMessage msg;
299 switch (Mess.MessageType)
300 {
301 case TCPLibrary.MessageBased.Core.MessageType.Connect:
302 break;
303 case TCPLibrary.MessageBased.Core.MessageType.MaxUsers:
304 break;
305 case TCPLibrary.MessageBased.Core.MessageType.SizeDump:
306 SendDumpSize();
307 break;
308 case MessageType.Statistics:
309 SendStatistics();
310 break;
311 case MessageType.SetDebugMode:
312 wrap.DebugMode = (Boolean)Mess.Parameters[0];
313
314 msg = new TCPMessage();
315 msg.MessageType = MessageType.GetDebugMode;
316 msg.Parameters.Add(wrap.DebugMode);
317 Client.Send(msg);
318
319 if (wrap.DebugMode)
320 {
321 msg = new TCPMessage();
322 msg.MessageType = MessageType.DebugState;
323 msg.Parameters.AddRange(wrap.GetGifPackets(dump));
324 Client.Send(msg);
325
326 msg = new TCPMessage();
327 msg.MessageType = MessageType.Step;
328 msg.Parameters.Add(dump.Data.FindIndex(a => a == wrap.CurrentGIFPacket));
329 Client.Send(msg);
330 }
331 break;
332 case MessageType.GetDebugMode:
333 msg = new TCPMessage();
334 msg.MessageType = MessageType.GetDebugMode;
335 msg.Parameters.Add(wrap.DebugMode);
336 Client.Send(msg);
337
338 if (wrap.DebugMode)
339 {
340 msg = new TCPMessage();
341 msg.MessageType = MessageType.DebugState;
342 msg.Parameters.AddRange(wrap.GetGifPackets(dump));
343 Client.Send(msg);
344
345 msg = new TCPMessage();
346 msg.MessageType = MessageType.Step;
347 msg.Parameters.Add(dump.Data.FindIndex(a => a == wrap.CurrentGIFPacket));
348 Client.Send(msg);
349 }
350 break;
351
352 case MessageType.PacketInfo:
353 int id = (int)Mess.Parameters[0];
354 msg = new TCPMessage();
355 msg.MessageType = MessageType.PacketInfo;
356 msg.Parameters.Add(wrap.GetGifPacketInfo(dump, id));
357 Client.Send(msg);
358 break;
359 case MessageType.Step:
360 case MessageType.RunToCursor:
361 case MessageType.RunToNextVSync:
362 wrap.ExternalEvent.WaitOne();
363 wrap.ExternalEvent.Reset();
364 wrap.QueueMessage.Enqueue(Mess);
365 wrap.ThereIsWork = true;
366 break;
367 default:
368 break;
369 }
370 }
371
372 private static void SendDumpSize()
373 {
374 TCPMessage msg;
375 msg = new TCPMessage();
376 msg.MessageType = MessageType.SizeDump;
377 if (dump != null)
378 msg.Parameters.Add(dump.Size);
379 else
380 msg.Parameters.Add(0);
381 Client.Send(msg);
382 }
383
384 private static void SendStatistics()
385 {
386 TCPMessage msg;
387 msg = new TCPMessage();
388 msg.MessageType = MessageType.Statistics;
389 if (dump != null)
390 {
391 msg.Parameters.Add(dump.Data.Count);
392 msg.Parameters.Add(dump.Data.FindAll(a => (int)a.id == 0 && (a.data[0] == 3 || a.data[0] == 0)).Count);
393 msg.Parameters.Add(dump.Data.FindAll(a => (int)a.id == 0 && a.data[0] == 1).Count);
394 msg.Parameters.Add(dump.Data.FindAll(a => (int)a.id == 0 && a.data[0] == 2).Count);
395 msg.Parameters.Add(dump.Data.FindAll(a => (int)a.id == 1).Count);
396 msg.Parameters.Add(dump.Data.FindAll(a => (int)a.id == 2).Count);
397 msg.Parameters.Add(dump.Data.FindAll(a => (int)a.id == 3).Count);
398 }
399 else
400 {
401 msg.Parameters.Add(0);
402 msg.Parameters.Add(0);
403 msg.Parameters.Add(0);
404 msg.Parameters.Add(0);
405 msg.Parameters.Add(0);
406 msg.Parameters.Add(0);
407 msg.Parameters.Add(0);
408 }
409 Client.Send(msg);
410 }
411
412 static void Server_OnClientAfterConnect(TCPLibrary.Core.Server server, TCPLibrary.Core.ClientS sender)
413 {
414 Clients.Add((TCPLibrary.MessageBased.Core.BaseMessageClientS)sender);
415 RefreshList(true);
416 }
417
418 private static void RefreshList(bool SelectLast)
419 {
420 frmMain.Invoke(new Action<object>( delegate(object e)
421 {
422 frmMain.lstProcesses.Items.Clear();
423
424 foreach (var itm in Clients)
425 {
426 frmMain.lstProcesses.Items.Add(itm.IPAddress);
427 }
428 if (SelectLast)
429 frmMain.lstProcesses.SelectedIndex = frmMain.lstProcesses.Items.Count - 1;
430 if (frmMain.lstProcesses.SelectedIndex == -1)
431 {
432 frmMain.chkDebugMode.Checked = false;
433 frmMain.lblGif.Enabled = frmMain.chkDebugMode.Checked;
434 frmMain.btnRunToSelection.Enabled = frmMain.chkDebugMode.Checked;
435 frmMain.treTreeView.Enabled = frmMain.chkDebugMode.Checked;
436 frmMain.btnStep.Enabled = frmMain.chkDebugMode.Checked;
437 frmMain.cmdGoToStart.Enabled = frmMain.chkDebugMode.Checked;
438 frmMain.cmdGoToNextVSync.Enabled = frmMain.chkDebugMode.Checked;
439 frmMain.treTreeView.Nodes.Clear();
440 frmMain.treeGifPacketContent.Nodes.Clear();
441 }
442 }), new object[] { null});
443 }
444 }
445 }

  ViewVC Help
Powered by ViewVC 1.1.22