-
Notifications
You must be signed in to change notification settings - Fork 1
/
VanguardImplementation.cs
219 lines (195 loc) · 8.94 KB
/
VanguardImplementation.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace NetStub
{
using System;
using System.Threading;
using System.Windows.Forms;
using libdebug;
using NetStub.UI.HexEditor;
using RTCV.CorruptCore;
using RTCV.NetCore;
using RTCV.NetCore.Commands;
using RTCV.Vanguard;
using NetStub.StubEndpoints;
public static class VanguardImplementation
{
public static VanguardConnector connector;
public static HexEditor hexEditor;
public static StubMode stubMode = StubMode.PS4;
// PS4
public static PS4DBG ps4;
public static ProcessList pl;
// MAC
public static StubEndpoints.MacOSX_PPC.RPC.PowerMacRPC mac;
// Linux (amd64)
public static StubEndpoints.X86_64_Linux.LinuxRPC linux;
// Windows XP (x86)
public static StubEndpoints.WindowsXP.RPC winxp;
public static string ProcessName = "";
public static void StartClient()
{
try
{
hexEditor = new HexEditor();
ConsoleEx.WriteLine("Starting Vanguard Client");
Thread.Sleep(500); //When starting in Multiple Startup Project, the first try will be uncessful since
//the server takes a bit more time to start then the client.
var spec = new NetCoreReceiver();
spec.Attached = VanguardCore.attached;
spec.MessageReceived += OnMessageReceived;
connector = new VanguardConnector(spec);
}
catch (Exception ex)
{
if (VanguardCore.ShowErrorDialog(ex, true) == DialogResult.Abort)
throw new AbortEverythingException();
}
}
public static void RestartClient()
{
connector?.Kill();
connector = null;
StartClient();
}
private static void OnMessageReceived(object sender, NetCoreEventArgs e)
{
try
{
// This is where you implement interaction.
// Warning: Any error thrown in here will be caught by NetCore and handled by being displayed in the console.
var message = e.message;
var simpleMessage = message as NetCoreSimpleMessage;
var advancedMessage = message as NetCoreAdvancedMessage;
ConsoleEx.WriteLine(message.Type);
switch (message.Type) //Handle received messages here
{
case RTCV.NetCore.Commands.Remote.AllSpecSent:
{
//We still need to set the emulator's path
AllSpec.VanguardSpec.Update(VSPEC.EMUDIR, VanguardCore.emuDir);
SyncObjectSingleton.FormExecute(() =>
{
switch (stubMode)
{
case StubMode.PS4:
StubEndpoints.PS4.ProcessWatch.UpdateDomains();
break;
case StubMode.MacOSX_PPC:
StubEndpoints.MacOSX_PPC.ProcessWatch.UpdateDomains();
break;
case StubMode.Linux_AMD64:
StubEndpoints.X86_64_Linux.ProcessWatch.UpdateDomains();
break;
case StubMode.WindowsXP:
StubEndpoints.WindowsXP.ProcessWatch.UpdateDomains();
break;
default:
break;
}
});
}
break;
case RTCV.NetCore.Commands.Basic.SaveSavestate:
e.setReturnValue("");
break;
case RTCV.NetCore.Commands.Basic.LoadSavestate:
e.setReturnValue(true);
break;
case RTCV.NetCore.Commands.Remote.PreCorruptAction:
break;
case RTCV.NetCore.Commands.Remote.PostCorruptAction:
break;
case RTCV.NetCore.Commands.Remote.CloseGame:
break;
case RTCV.NetCore.Commands.Remote.DomainGetDomains:
SyncObjectSingleton.FormExecute(() =>
{
switch (stubMode)
{
case StubMode.PS4:
e.setReturnValue(StubEndpoints.PS4.ProcessWatch.GetInterfaces());
break;
case StubMode.MacOSX_PPC:
e.setReturnValue(StubEndpoints.MacOSX_PPC.ProcessWatch.GetInterfaces());
break;
case StubMode.Linux_AMD64:
e.setReturnValue(StubEndpoints.X86_64_Linux.ProcessWatch.GetInterfaces());
break;
case StubMode.WindowsXP:
e.setReturnValue(StubEndpoints.WindowsXP.ProcessWatch.GetInterfaces());
break;
default:
break;
}
});
break;
case RTCV.NetCore.Commands.Remote.DomainRefreshDomains:
SyncObjectSingleton.FormExecute(() => {
switch (stubMode)
{
case StubMode.PS4:
StubEndpoints.PS4.ProcessWatch.UpdateDomains();
break;
case StubMode.MacOSX_PPC:
StubEndpoints.MacOSX_PPC.ProcessWatch.UpdateDomains();
break;
case StubMode.Linux_AMD64:
StubEndpoints.X86_64_Linux.ProcessWatch.UpdateDomains();
break;
case StubMode.WindowsXP:
StubEndpoints.WindowsXP.ProcessWatch.UpdateDomains();
break;
default:
break;
}
});
break;
case RTCV.NetCore.Commands.Remote.EventEmuMainFormClose:
SyncObjectSingleton.FormExecute(() =>
{
Environment.Exit(0);
});
break;
case RTCV.NetCore.Commands.Remote.IsNormalAdvance:
e.setReturnValue(true);
break;
case RTCV.NetCore.Commands.Remote.OpenHexEditor:
SyncObjectSingleton.FormExecute( () =>
{
hexEditor.Show();
});
break;
case RTCV.NetCore.Commands.Emulator.OpenHexEditorAddress:
{
var temp = advancedMessage.objectValue as object[];
string domain = (string)temp[0];
long address = (long)temp[1];
MemoryDomainProxy mdp = MemoryDomains.GetProxy(domain, address);
long realAddress = MemoryDomains.GetRealAddress(domain, address);
SyncObjectSingleton.FormExecute(() =>
{
if (mdp?.MD == null)
return;
hexEditor.Show();
hexEditor.SetMemoryDomain(mdp.MD.ToString());
hexEditor.GoToAddress(realAddress);
});
break;
}
case RTCV.NetCore.Commands.Remote.EventCloseEmulator:
Environment.Exit(-1);
break;
}
}
catch (Exception ex)
{
if (VanguardCore.ShowErrorDialog(ex, true) == DialogResult.Abort)
throw new AbortEverythingException();
}
}
}
}