/
FrontendConnect.cs
executable file
·306 lines (281 loc) · 11.2 KB
/
FrontendConnect.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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
using Devcat.Core.Net.Message;
using Devcat.Core.Threading;
using MarketScraper;
using Nexon.CafeAuth;
using PacketCap;
using ServiceCore.CharacterServiceOperations;
using ServiceCore.EndPointNetwork;
using System;
using System.Collections.Generic;
using System.Net;
using System.Reflection;
namespace MarketQuery
{
class FrontendConnect : Connect
{
private static string serverIP = "192.168.0.200";
private static ushort serverPort = 27015;
public GameState gameState = new GameState();
//public MMOChannelConnect mmo;
private FrontendHandler mh = new FrontendHandler();
private LoginState _state = LoginState.WaitSyncFeatureMatrix;
public LoginState State {
get {
return _state;
}
set {
_state = value;
NextState();
}
}
private string username;
private string secondPassword;
private int charNum = 1;
private long checksum = 3053724526L;
private long CID;
public TradeSearchState searchState = new TradeSearchState();
public FrontendConnect(string username,string secondPassword, int charNum = 0) : base() {
this.username = username;
this.secondPassword = secondPassword;
this.charNum = charNum;
encrypt = EncryptionType.Normal;
}
public void Login() {
ConnectServer(serverIP, serverPort);
}
public enum LoginState
{
ProcessedTypeConverter,
WaitSyncFeatureMatrix,
SendUserLoginMessage,
WaitAskSecondPassword,
WaitHasSecondPassword,
QueryCashShopBalance,
WaitSecondPasswordResult,
SelectCharacter,
WaitLoginOk,
EnterRegion,
WaitMailList,
EnterChannel,
WaitRankAlarmInfo,
QueryInnTalk,
WaitNpcInnTalk,
QueryNpcTalkTrade,
WaitNpcTalkTrade,
ContinueSearch,
WaitSearch,
}
private LoginState NextState() {
Console.WriteLine("State={0}",_state);
LoginState s = _state;
LoginState nextState = s;
if (s == LoginState.SendUserLoginMessage)
{
nextState = LoginState.WaitAskSecondPassword;
//passport
UserLoginMessage msg = new UserLoginMessage(username);
//LocalAddress
IPAddress ip = IPAddress.Parse("10.0.0.0");
byte[] ipBytes = { 10, 0, 0, (byte)rand.Next(2, 254) };
uint localAddress = BitConverter.ToUInt32(ipBytes, 0);
SetReadOnlyProperty<UserLoginMessage>(msg, "LocalAddress", localAddress);
SetReadOnlyProperty<UserLoginMessage>(msg, "CheckSum", checksum);
rand.NextBytes(msg.MachineID);
Scheduler.Schedule(jp, Job.Create((Action)(() => SendMsg<UserLoginMessage>(msg))), 460);
}
else if (s == LoginState.QueryCashShopBalance)
{
nextState = LoginState.WaitSecondPasswordResult;
QueryCashShopBalanceMessage msg = new QueryCashShopBalanceMessage();
SendMsg<QueryCashShopBalanceMessage>(msg);
SecondPasswordMessage passwordMsg = new SecondPasswordMessage(secondPassword);
Scheduler.Schedule(jp, Job.Create((Action)(() => SendMsg<SecondPasswordMessage>(passwordMsg))), 10000);
}
else if (s == LoginState.SelectCharacter)
{
nextState = LoginState.WaitLoginOk;
SelectCharacterMessage charMsg = new SelectCharacterMessage(charNum);
SleepRand(4765);
SendMsg<SelectCharacterMessage>(charMsg);
SleepRand(11);
ClientLogMessage msg = new ClientLogMessage
{
LogType = (int)ClientLogMessage.LogTypes.Character
};
//TODO: update these values
Dictionary<string, string> clientInfo = new Dictionary<string, string>
{
["CPUVendor"] = "GenuineIntel",
["CPUCores"] = "4",
["TotalRAM"] = "4095",
["GPUDevice"] = "Microsoft",
["TotalVRAM"] = "0",
["DXVersion"] = "95",
["PixelShader"] = "1_x",
["OSDescription"] = "Win8",
["PrimaryDisplay"] = "1440x900x32",
["LocaleLanguage"] = "English",
["MultiCoreBoost"] = "1",
["Controller"] = "M"
};
int t = 1;
foreach (KeyValuePair<string, string> entry in clientInfo)
{
msg.Key = entry.Key;
msg.Value = entry.Value;
Scheduler.Schedule(jp, Job.Create((Action)(() => SendMsg<ClientLogMessage>(msg))), t++);
;
}
msg.Key = "VirtualMachine";
msg.Value = "VMWare";
Scheduler.Schedule(jp, Job.Create((Action)(() => SendMsg<ClientLogMessage>(msg))), t+43);
}
else if (s == LoginState.EnterRegion)
{
nextState = LoginState.WaitMailList;
EnterRegion msg = new EnterRegion
{
RegionCode = 0
};
Scheduler.Schedule(jp, Job.Create((Action)(() => SendMsg<EnterRegion>(msg))), 55);
QueryCharacterCommonInfoMessage query = new QueryCharacterCommonInfoMessage
{
CID = CID,
QueryID = RandLong()
};
Scheduler.Schedule(jp, Job.Create((Action)(() => SendMsg<QueryCharacterCommonInfoMessage>(query))), 67);
RequestJoinPartyMessage request = new RequestJoinPartyMessage
{
RequestType = 0
};
Scheduler.Schedule(jp, Job.Create((Action)(() => SendMsg<RequestJoinPartyMessage>(request))), 184);
}
else if (s == LoginState.EnterChannel)
{
nextState = LoginState.WaitRankAlarmInfo;
EnterChannel msg = new EnterChannel
{
ChannelID = -1,
PartitionID = 0
};
ActionSync action = new ActionSync
{
Position = new Vector3D
{
X = 7520,
Y = -352,
Z = 24
},
Velocity = new Vector3D
{
X = 0,
Y = 0,
Z = 0
},
Yaw = 90,
Sequence = 0,
ActionStateIndex = 2,
StartTime = 0,
State = 1
};
msg.Action = action;
Scheduler.Schedule(jp, Job.Create((Action)(() => SendMsg<EnterChannel>(msg))), 6);
QueryRankAlarmInfoMessage query = new QueryRankAlarmInfoMessage
{
CID = CID
};
Scheduler.Schedule(jp, Job.Create((Action)(() => SendMsg<QueryRankAlarmInfoMessage>(query))), 10);
}
else if (s == LoginState.QueryInnTalk)
{
nextState = LoginState.WaitNpcInnTalk;
QueryNpcTalkMessage msg = new QueryNpcTalkMessage("t01_inn", "TI", "", "greeting");
Scheduler.Schedule(jp, Job.Create((Action)(() => SendMsg<QueryNpcTalkMessage>(msg))), 61);
}
else if (s == LoginState.QueryNpcTalkTrade)
{
nextState = LoginState.WaitNpcTalkTrade;
QueryNpcTalkMessage msg = new QueryNpcTalkMessage("t01_trade", "TRADE", "", "greeting");
Scheduler.Schedule(jp, Job.Create((Action)(() => SendMsg<QueryNpcTalkMessage>(msg))), 10000);
}
else if (s == LoginState.ContinueSearch)
{
nextState = LoginState.WaitSearch;
if (searchState.IsDone())
{
Console.WriteLine("Finished searching");
Logout();
}
Console.WriteLine("Searching for {0}", searchState.GetTradeCategory());
TradeCategorySearchMessage msg = new TradeCategorySearchMessage
{
tradeCategory = searchState.GetTradeCategory(),
tradeCategorySub = "",
minLevel = 1,
maxLevel = 90,
uniqueNumber = searchState.uniqueNumber,
ChunkPageNumber = searchState.ChunkPageNumber,
Order = SortOrder.Level,
isDescending = true,
DetailOptions = new List<DetailOption>()
};
Scheduler.Schedule(jp, Job.Create((Action)(() => SendMsg<TradeCategorySearchMessage>(msg))), 1000);
}
else {
Console.WriteLine("Nothing to do in state {0}",s);
}
_state = nextState;
Console.WriteLine("Next State={0}", nextState);
return nextState;
}
public override void ProcessTypeConverter(Packet p) {
SetupDicts(p);
mh.RegisterPrinters(mf, getGuid);
}
private long RandLong() {
byte[] longBuf = new byte[8];
long result = BitConverter.ToInt64(longBuf, 0);
if (result < 0) {
result = -result;
}
return result;
}
private static void SetReadOnlyProperty<T>(T msg, string propName, object val)
{
FieldInfo[] fields = typeof(T).GetFields(BindingFlags.NonPublic | BindingFlags.Instance);
foreach (FieldInfo field in fields)
{
if (field.Name.Contains(propName))
{
field.SetValue(msg, val);
}
}
}
public static void SetPrivateProperty<T>(T msg, string propName, Object val)
{
FieldInfo field = typeof(T).GetField("propName",BindingFlags.NonPublic | BindingFlags.Instance);
Console.WriteLine("going to set property");
field.SetValue(msg, val);
Console.WriteLine("set property");
}
public void SetCID() {
int i = 0;
foreach (CharacterSummary charSum in gameState.characterList) {
if (i++ == charNum) {
CID = charSum.CID;
return;
}
}
}
private void Logout() {
LogOutMessage msg = new LogOutMessage();
SendMsg<LogOutMessage>(msg);
SleepRand(1000);
client.Disconnect();
if (SQLiteConnect.conn != null) {
SQLiteConnect.conn.Close();
}
System.Environment.Exit(1);
}
}
}