This repository has been archived by the owner on Oct 3, 2022. It is now read-only.
/
PacketParser.cs
2849 lines (2735 loc) · 88.6 KB
/
PacketParser.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
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using SecurityAPI;
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using xBot.App;
using xBot.Game.Objects;
using xBot.Game.Objects.Common;
using xBot.Game.Objects.Entity;
using xBot.Game.Objects.Guild;
using xBot.Game.Objects.Item;
using xBot.Game.Objects.Party;
using xBot.Network;
namespace xBot.Game
{
// Class to handle almost everything about parsing packets
// and filling the GUI with the necessary
public static class PacketParser
{
public static void ShardListResponse(Packet packet)
{
Window w = Window.Get;
WinAPI.InvokeIfRequired(w.Login_lstvServers, () => {
w.Login_lstvServers.Items.Clear();
//Window.get.Login_lstvServers.Groups.Clear();
});
WinAPI.InvokeIfRequired(w.Login_cmbxServer, () => {
w.Login_cmbxServer.Items.Clear();
});
while (packet.ReadByte() == 1)
{
byte farmID = packet.ReadByte();
string farmName = packet.ReadAscii();
//WinAPI.InvokeIfRequired(w.Login_lstvServers, () =>{
// Window.get.Login_lstvServers.Groups.Add(farmID.ToString(), farmName);
//});
}
InfoManager.ServerID = "";
while (packet.ReadByte() == 1)
{
ushort serverID = packet.ReadUShort();
string serverName = packet.ReadAscii();
ushort players = packet.ReadUShort();
ushort maxPlayers = packet.ReadUShort();
bool isAvailable = packet.ReadByte() == 1;
byte farm_ID = packet.ReadByte();
// Generate server list
ListViewItem server = new ListViewItem(serverName);
server.Name = serverID.ToString();
server.SubItems.Add(players + " / " + maxPlayers + " ("+Math.Round(players*100d/maxPlayers,2)+"%)");
server.SubItems.Add((isAvailable ? "Online" : "Offline"));
w.Login_lstvServers.InvokeIfRequired(() => {
//i.Group = w.Login_lstvServers.Groups[serverID_farmID.ToString()];
w.Login_lstvServers.Items.Add(server);
});
if (isAvailable)
{
w.Login_cmbxServer.InvokeIfRequired(() => {
w.Login_cmbxServer.Items.Add(serverName);
// Select Server if is AutoLogin
if (Bot.Get.hasAutoLoginMode
&& w.Login_cmbxServer.Tag != null
&& serverName.Equals((string)w.Login_cmbxServer.Tag, StringComparison.OrdinalIgnoreCase))
{
w.Login_cmbxServer.SelectedItem = serverName;
}
});
}
}
// Unlock button
if (w.Login_btnStart.Text == "STOP" && Bot.Get.Proxy.ClientlessMode
|| Bot.Get.hasAutoLoginMode)
{
WinAPI.InvokeIfRequired(w.Login_btnStart, () => {
w.Login_btnStart.Text = "LOGIN";
});
}
w.LogProcess("Server selection");
// AutoLogin
if (Bot.Get.hasAutoLoginMode) {
// Server found
if (InfoManager.ServerID != "") {
WinAPI.InvokeIfRequired(w, () => {
w.Control_Click(w.Login_btnStart, null);
});
}
}
else
{
// Select first one (Just for UX)
if (w.Login_cmbxServer.Items.Count > 0)
{
WinAPI.InvokeIfRequired(w.Login_cmbxServer, () => {
w.Login_cmbxServer.SelectedIndex = 0;
});
}
}
}
public static void CaptchaData(Packet packet)
{
}
public static void CharacterSelectionActionResponse(Packet packet)
{
byte action = packet.ReadByte();
byte result = packet.ReadByte();
switch ((SRTypes.CharacterSelectionAction)action)
{
case SRTypes.CharacterSelectionAction.Create:
if (result == 1)
Window.Get.Log("Character created successfully");
else
Window.Get.Log("Character creation failed!");
if (Bot.Get.Proxy.ClientlessMode)
PacketBuilder.RequestCharacterList();
break;
case SRTypes.CharacterSelectionAction.CheckName:
Bot.Get.OnNicknameChecked(result == 1);
break;
case SRTypes.CharacterSelectionAction.Delete:
// Not necessary at the moment..
break;
case SRTypes.CharacterSelectionAction.List:
if (result == 1)
{
Window w = Window.Get;
// Reset values
w.Login_lstvCharacters.InvokeIfRequired(() =>{
w.Login_lstvCharacters.Items.Clear();
});
w.Login_cmbxCharacter.InvokeIfRequired(() =>{
w.Login_cmbxCharacter.Items.Clear();
});
// Get character selection
List<SRCharSelection> CharacterList = new List<SRCharSelection>(packet.ReadByte());
for (byte n = 0; n < CharacterList.Capacity; n++)
{
SRCharSelection character = new SRCharSelection();
character.ModelID = packet.ReadUInt();
character.Name = packet.ReadAscii();
character.Scale = packet.ReadByte();
character.Level = packet.ReadByte();
character.Exp = packet.ReadULong();
character.STR = packet.ReadUShort();
character.INT = packet.ReadUShort();
character.StatPoints = packet.ReadUShort();
character.HP = packet.ReadUInt();
character.MP = packet.ReadUInt();
bool isDeleting = packet.ReadBool();
if (isDeleting)
character.DeletingDate = DateTime.Now.AddMinutes(packet.ReadUInt());
character.GuildMemberType = (SRCharSelection.GuildMember)packet.ReadByte();
bool isGuildRenameRequired = packet.ReadBool();
if (isGuildRenameRequired)
character.GuildName = packet.ReadAscii();
character.AcademyMemberType = (SRCharSelection.AcademyMember)packet.ReadByte();
// inventory
xList<SRItem> inventory = new xList<SRItem>(packet.ReadByte());
for (byte j = 0; j < inventory.Capacity; j++)
{
inventory[j] = SRItem.Create(packet.ReadUInt(),null);
byte plus = packet.ReadByte();
if (inventory[j].isEquipable())
((SREquipable)inventory[j]).Plus = plus;
}
character.Inventory = inventory;
// inventory avatar
xList<SREquipable> inventoryAvatar = new xList<SREquipable>(packet.ReadByte());
for (byte j = 0; j < inventoryAvatar.Capacity; j++)
{
inventoryAvatar[j] = (SREquipable)SRItem.Create(packet.ReadUInt(), null);
inventoryAvatar[j].Plus = packet.ReadByte();
}
character.InventoryAvatar = inventoryAvatar;
// Adding character
CharacterList.Add(character);
}
// End of Packet
InfoManager.OnCharacterListing(CharacterList);
}
else if (result == 2)
{
ushort errCode = packet.ReadUShort();
Window.Get.Log("Error [" + errCode + "]");
Bot.Get.Proxy.Stop();
}
break;
}
}
public static void CharacterSelectionJoinResponse(Packet packet)
{
byte success = packet.ReadByte();
Window w = Window.Get;
if (success == 1)
{
w.Log("Character selected [" + InfoManager.CharName + "]");
}
else
{
ushort errCode = packet.ReadUShort();
w.Log("Error: " + errCode);
}
}
private static Packet characterDataPacket;
public static void CharacterDataBegin(Packet packet)
{
characterDataPacket = new Packet(Agent.Opcode.SERVER_CHARACTER_DATA);
//InfoManager.OnTeleporting();
}
public static void CharacterData(Packet packet)
{
characterDataPacket.WriteByteArray(packet.GetBytes());
}
public static void CharacterDataEnd()
{
Packet p = characterDataPacket;
p.Lock();
InfoManager.SetServerTime(new SRTimeStamp(p.ReadUInt()));
SRCharacter character = new SRCharacter(p.ReadUInt());
character.Scale = p.ReadByte();
character.Level = p.ReadByte();
character.LevelMax = p.ReadByte();
character.Exp = p.ReadULong();
character.SPExp = p.ReadUInt();
character.Gold = p.ReadULong();
character.SP = p.ReadUInt();
character.StatPoints = p.ReadUShort();
character.BerserkPoints = p.ReadByte();
character.GatheredExpPoint = p.ReadUInt();
character.HPMax = p.ReadUInt();
character.MPMax = p.ReadUInt();
character.ExpIconType = (SRPlayer.ExpIcon)p.ReadByte();
character.PKDaily = p.ReadByte();
character.PKTotal = p.ReadUShort();
character.PKPenalty = p.ReadUInt();
character.BerserkLevel = p.ReadByte();
character.PVPCapeType = (SRPlayer.PVPCape)p.ReadByte();
// Inventory
xList<SRItem> inventory = new xList<SRItem>(p.ReadByte());
byte itemCount = p.ReadByte();
for (byte j = 0; j < itemCount; j++)
{
byte slot = p.ReadByte();
inventory[slot] = ItemParsing(p);
}
character.Inventory = inventory;
// Inventory Avatar
inventory = new xList<SRItem>(p.ReadByte());
itemCount = p.ReadByte();
for (byte j = 0; j < itemCount; j++)
{
byte slot = p.ReadByte();
inventory[slot] = ItemParsing(p);
}
character.InventoryAvatar = inventory;
// Masteries
character.unkByte01 = p.ReadByte();
xDictionary<uint,SRMastery> masteries = new xDictionary<uint,SRMastery>();
while (p.ReadBool())
{
SRMastery mastery = new SRMastery(p.ReadUInt());
mastery.Level = p.ReadByte();
masteries[mastery.ID] = mastery;
}
character.Masteries = masteries;
// Skills
character.unkByte02 = p.ReadByte();
xDictionary<uint, SRSkill> skills = new xDictionary<uint, SRSkill>();
while (p.ReadBool())
{
SRSkill skill = new SRSkill(p.ReadUInt());
skill.Enabled = p.ReadBool();
skills[skill.ID] = skill;
}
character.Skills = skills;
// Quests
xDictionary<uint, SRQuest> quests = new xDictionary<uint, SRQuest>();
ushort questsCompletedCount = p.ReadUShort();
for (ushort j = 0; j < questsCompletedCount; j++)
{
SRQuest quest = new SRQuest(p.ReadUInt());
quests[quest.ID] = quest;
}
character.QuestsCompleted = quests;
quests = new xDictionary<uint, SRQuest>();
byte questCount = p.ReadByte();
for (byte j = 0; j < questCount; j++)
{
SRQuest quest = new SRQuest(p.ReadUInt());
quest.Achievements = p.ReadByte();
quest.isAutoShareRequired = p.ReadBool();
quest.QuestType = p.ReadByte();
if (quest.QuestType == 28)
quest.TimeRemain = p.ReadUInt();
quest.State = p.ReadByte();
if (quest.QuestType != 8)
{
xList<SRQuestObjective> objectives = new xList<SRQuestObjective>(p.ReadByte());
for (byte k = 0; k < objectives.Capacity; k++)
{
SRQuestObjective objective = new SRQuestObjective(p.ReadByte());
objective.isEnabled = p.ReadBool();
objective.Name = p.ReadAscii();
objective.TasksID = p.ReadUIntArray(p.ReadByte());
objectives[k] = objective;
}
quest.Objectives = objectives;
}
if (quest.QuestType == 88)
quest.NpcsID = p.ReadUIntArray(p.ReadByte());
quests[quest.ID] = quest;
}
character.Quests = quests;
// Collection Books
character.unkByte03 = p.ReadByte();
xDictionary<uint, SRCollectionBook> collectionBooks = new xDictionary<uint, SRCollectionBook>();
uint bookCount = p.ReadUInt();
for (uint j = 0; j < bookCount; j++)
{
SRCollectionBook book = new SRCollectionBook(p.ReadUInt());
book.StartedDatetime = new SRTimeStamp(p.ReadUInt());
book.Pages = p.ReadUInt();
collectionBooks[book.ID] = book;
}
character.CollectionBooks = collectionBooks;
// Position
character.UniqueID = p.ReadUInt();
character.Position = new SRCoord(p.ReadUShort(), (int)p.ReadFloat(), (int)p.ReadFloat(), (int)p.ReadFloat());
character.Angle = p.ReadUShort();
bool hasMovement = p.ReadBool();
character.MovementSpeedType = (SRModel.MovementSpeed)p.ReadByte();
if (hasMovement)
{
if (character.Position.inDungeon())
character.MovementPosition = new SRCoord(p.ReadUShort(), p.ReadInt(), p.ReadInt(), p.ReadInt());
else
character.MovementPosition = new SRCoord(p.ReadUShort(),(int)p.ReadUShort(), (int)p.ReadUShort(), (int)p.ReadUShort());
}
else
{
character.MovementActionType = (SRModel.MovementAction)p.ReadByte();
character.Angle = p.ReadUShort();
}
character.GetRealtimePosition();
// States
character.LifeStateType = (SRModel.LifeState)p.ReadByte();
character.unkByte04 = p.ReadByte();
character.MotionStateType = (SRModel.MotionState)p.ReadByte();
character.GameStateType = (SRModel.GameState)p.ReadByte();
character.SpeedWalking = p.ReadFloat();
character.SpeedRunning = p.ReadFloat();
character.SpeedBerserk = p.ReadFloat();
// Buffs
xDictionary<uint, SRBuff> buffs = new xDictionary<uint, SRBuff>();
byte buffCount = p.ReadByte();
for (byte j = 0; j < buffCount; j++)
{
SRBuff buff = new SRBuff(p.ReadUInt());
buff.UniqueID = p.ReadUInt();
if (buff.hasAutoTransferEffect())
{
bool isCaster = p.ReadBool();
if (isCaster)
buff.CasterUniqueID = character.UniqueID;
}
buff.TargetUniqueID = character.UniqueID;
// Easy track using GroupID to avoid overlap issues
buffs[buff.GroupID] = buff;
}
character.Buffs = buffs;
// Identification
character.Name = p.ReadAscii();
character.JobName = p.ReadAscii();
character.JobType = (SRPlayer.Job)p.ReadByte();
character.JobLevel = p.ReadByte();
character.JobExp = p.ReadUInt();
character.JobContribution = p.ReadUInt();
character.JobReward = p.ReadUInt();
character.PVPStateType = (SRPlayer.PVPState)p.ReadByte();
bool isRiding = p.ReadBool();
character.inCombat = p.ReadBool();
if (isRiding)
character.RidingUniqueID = p.ReadUInt();
character.CaptureTheFlagType = (SRPlayer.CaptureTheFlag)p.ReadByte();
character.GuideFlag = p.ReadULong();
character.JoinID = p.ReadUInt();
character.isGameMaster = p.ReadBool();
#region (Game Settings from GUI)
//byte activationFlag = packet.ReadByte(); // ConfigType:0 --> (0 = Not activated, 7 = activated)
//byte hotkeysCount = packet.ReadByte(); // ConfigType:1
//for (int i = 0; i < hotkeysCount; i++)
//{
// byte HotkeySlotSeq = packet.ReadByte();
// byte HotkeySlotContentType = packet.ReadByte();
// uint HotkeySlotData = packet.ReadUInt();
//}
//ushort AutoHPConfig = packet.ReadUShort(); // ConfigType:11
//ushort AutoMPConfig = packet.ReadUShort(); // ConfigType:12
//ushort AutoUniversalConfig = packet.ReadUShort(); // ConfigType:13
//ushort AutoPotionDelay = packet.ReadByte(); // ConfigType:14
//byte BlockedWhisperCount = packet.ReadByte();
//for (int i = 0; i < BlockedWhisperCount; i++)
//{
// string Target = packet.ReadAscii();
//}
//uint unkUShort0 = packet.ReadUInt(); // Structure changes!!!
//byte unkByte4 = packet.ReadByte(); // Structure changes!!!
#endregion
// End of Packet
InfoManager.OnCharacterInfo(character);
}
private static SRItem ItemParsing(Packet p)
{
SRRentable rentable = new SRRentable(p.ReadUInt());
if(rentable.RentableType != SRRentable.Type.None)
{
if (rentable.RentableType == SRRentable.Type.LimitedTime)
{
rentable.CanDelete = p.ReadUShort();
rentable.PeriodBeginTime = p.ReadUInt();
rentable.PeriodEndTime = p.ReadUInt();
}
else if (rentable.RentableType == SRRentable.Type.LimitedDistance)
{
rentable.CanDelete = p.ReadUShort();
rentable.CanRecharge = p.ReadUShort();
rentable.MeterRateTime = p.ReadUInt();
}
else if (rentable.RentableType == SRRentable.Type.Package)
{
rentable.CanDelete = p.ReadUShort();
rentable.CanRecharge = p.ReadUShort();
rentable.PeriodBeginTime = p.ReadUInt();
rentable.PeriodEndTime = p.ReadUInt();
rentable.PackingTime = p.ReadUInt();
}
}
SRItem item = SRItem.Create(p.ReadUInt(), rentable);
if (item.isEquipable())
{
SREquipable equipable = (SREquipable)item;
equipable.Plus = p.ReadByte();
equipable.Variance = p.ReadULong();
equipable.Durability = p.ReadUInt();
// Magic options
xList<SRMagicOption> magicOptions = new xList<SRMagicOption>(p.ReadByte());
for (byte j = 0; j < magicOptions.Capacity; j++)
{
magicOptions[j] = new SRMagicOption(p.ReadUInt());
magicOptions[j].Value = p.ReadUInt();
}
equipable.MagicOptions = magicOptions;
// 1 = Socket
p.ReadByte();
xList<SRSocket> sockets = new xList<SRSocket>(p.ReadByte());
for (byte j = 0; j < sockets.Capacity; j++)
{
sockets[j] = new SRSocket(p.ReadByte(),p.ReadUInt());
sockets[j].Value = p.ReadUInt();
}
equipable.Sockets = sockets;
// 2 = Advanced elixir
p.ReadByte();
xList<SRAdvancedElixir> advancedElixirs = new xList<SRAdvancedElixir>(p.ReadByte());
for (byte j = 0; j < advancedElixirs.Capacity; j++)
{
advancedElixirs[j] = new SRAdvancedElixir(p.ReadByte(), p.ReadUInt());
advancedElixirs[j].Value = p.ReadUInt();
}
equipable.AdvancedElixirs = advancedElixirs;
}
else if (item.isCoS())
{
SRCoS cos = (SRCoS)item;
if (cos.isPet())
{
cos.StateType = (SRCoS.State)p.ReadByte();
if (cos.StateType != SRCoS.State.NeverSummoned)
{
cos.ModelID = p.ReadUInt();
cos.ModelName = p.ReadAscii();
if (cos.ID4 == 2)
cos.Rentable.PeriodEndTime = p.ReadUInt();
cos.unkByte01 = p.ReadByte();
}
}
else if (cos.isTransform())
{
cos.ModelID = p.ReadUInt();
}
else if (cos.isCube())
{
cos.Quantity = (ushort)p.ReadUInt();
}
}
else if (item.isEtc())
{
SREtc etc = (SREtc)item;
etc.Quantity = p.ReadUShort();
if (etc.isAlchemy())
{
if (item.ID4 == 1 || item.ID4 == 2)
{
// MAGIC/ATRIBUTTE STONE
etc.AssimilationProbability = p.ReadByte();
}
}
else if (item.ID3 == 14 && item.ID4 == 2)
{
// ITEM_MALL_GACHA_CARD_WIN
// ITEM_MALL_GACHA_CARD_LOSE
byte paramCount = p.ReadByte();
for (byte j = 0; j < paramCount; j++)
{
uint magicParamID = p.ReadUInt();
uint value = p.ReadUInt();
}
}
}
return item;
}
public static void CharacterStatsUpdate(Packet packet)
{
SRCharacter character = InfoManager.Character;
character.PhyAtkMin = packet.ReadUInt();
character.PhyAtkMax = packet.ReadUInt();
character.MagAtkMin = packet.ReadUInt();
character.MagAtkMax = packet.ReadUInt();
character.PhyDefense = packet.ReadUShort();
character.MagDefense = packet.ReadUShort();
character.HitRate = packet.ReadUShort();
character.ParryRatio = packet.ReadUShort();
character.HPMax = packet.ReadUInt();
character.MPMax = packet.ReadUInt();
character.STR = packet.ReadUShort();
character.INT = packet.ReadUShort();
// End of Packet
InfoManager.OnCharacterStatsUpdated();
}
public static void CharacterExperienceUpdate(Packet packet)
{
Window w = Window.Get;
uint sourceUniqueID = packet.ReadUInt(); // used to display exp. graphics
long ExpReceived = packet.ReadLong();
long SPExpReceived = packet.ReadLong(); // Long SP EXP? hmmm..
// byte unkByte01 = packet.ReadByte();
// End of Packet
if (w.Character_cbxMessageExp.Checked)
{
if (ExpReceived > 0)
w.LogMessageFilter(DataManager.GetUIFormat("UIIT_MSG_STATE_GAIN_EXP", ExpReceived));
else if (ExpReceived < 0)
w.LogMessageFilter(DataManager.GetUIFormat("UIIT_MSG_STATE_LOSE_EXP", ExpReceived));
if (SPExpReceived > 0)
w.LogMessageFilter(DataManager.GetUIFormat("UIIT_MSG_STATE_GET_SKILL_EXP", SPExpReceived));
}
InfoManager.OnExpReceived(ExpReceived,(long)InfoManager.Character.Exp, (long)InfoManager.Character.ExpMax, InfoManager.Character.Level);
}
public static void CharacterInfoUpdate(Packet packet)
{
Window w = Window.Get;
byte updateType = packet.ReadByte();
switch (updateType)
{
case 1: // Gold
InfoManager.Character.Gold = packet.ReadULong();
w.Character_SetGold(InfoManager.Character.Gold);
break;
case 2: // SP
InfoManager.Character.SP = packet.ReadUInt();
w.Character_lblSP.InvokeIfRequired(() => {
w.Character_lblSP.Text = InfoManager.Character.SP.ToString();
});
break;
case 4: // Berserk
InfoManager.Character.BerserkPoints = packet.ReadByte();
break;
}
}
public static void CharacterDied(Packet packet)
{
// Probably dead cause? 4 = Dead by mob?
byte unkByte01 = packet.ReadByte();
InfoManager.OnCharacterDead(unkByte01);
}
private static byte GroupSpawnType;
private static ushort GroupSpawnCount;
private static Packet GroupSpawnPacket;
public static void EntityGroupSpawnBegin(Packet packet)
{
GroupSpawnType = packet.ReadByte();
GroupSpawnCount = packet.ReadUShort();
GroupSpawnPacket = new Packet(Agent.Opcode.SERVER_ENTITY_GROUPSPAWN_DATA);
}
public static void EntityGroupSpawnData(Packet packet)
{
GroupSpawnPacket.WriteByteArray(packet.GetBytes());
}
public static void EntityGroupSpawnEnd(Packet packet)
{
GroupSpawnPacket.Lock();
for (int i = 0; i < GroupSpawnCount; i++)
{
if (GroupSpawnType == 1)
{
EntitySpawn(GroupSpawnPacket);
}
else
{
EntityDespawn(GroupSpawnPacket);
}
}
}
public static void EntitySpawn(Packet packet)
{
try
{
SREntity entity = SREntity.Create(packet.ReadUInt());
if (!entity.isSkillZone())
{
if (entity.isModel())
{
SRModel model = (SRModel)entity;
if (model.isPlayer())
{
SRPlayer player = (SRPlayer)entity;
player.Scale = packet.ReadByte();
player.BerserkLevel = packet.ReadByte();
player.PVPCapeType = (SRPlayer.PVPCape)packet.ReadByte();
player.ExpIconType = (SRPlayer.ExpIcon)packet.ReadByte();
// Inventory
packet.ReadByte(); // max capacity. seems useless at the moment..
xList<SRItem> inventory = new xList<SRItem>(packet.ReadByte());
for (byte j = 0; j < inventory.Capacity; j++)
{
inventory[j] = SRItem.Create(packet.ReadUInt(),null);
if (inventory[j].isEquipable())
((SREquipable)inventory[j]).Plus = packet.ReadByte();
}
player.Inventory = inventory;
// AvatarInventory
packet.ReadByte(); // max capacity. seems useless at the moment..
inventory = new xList<SRItem>(packet.ReadByte());
for (byte j = 0; j < inventory.Capacity; j++)
{
inventory[j] = SRItem.Create(packet.ReadUInt(), null);
if (inventory[j].isEquipable())
((SREquipable)inventory[j]).Plus = packet.ReadByte();
}
player.InventoryAvatar = inventory;
// Mask
bool hasMask = packet.ReadBool();
if (hasMask)
{
SRMask mask = new SRMask(packet.ReadUInt());
if (mask.ID1 == player.ID1 && mask.ID2 == player.ID2)
{
// Clone
mask.Scale = packet.ReadByte();
mask.Inventory = packet.ReadUIntArray(packet.ReadByte());
//inventory = new xList<SRItem>(packet.ReadByte());
//for (byte i = 0; i < inventory.Capacity; i++)
// inventory[i] = new SRItem(packet.ReadUInt());
//mask.Inventory = inventory;
}
player.Mask = mask;
}
}
else if (model.isNPC() && ((SRNpc)model).isFortressStruct())
{
SRFortressStruct fStruct = (SRFortressStruct)entity;
fStruct.HP = packet.ReadUInt();
fStruct.refEventStructID = packet.ReadUInt();
fStruct.State = packet.ReadUShort();
}
// Position
model.UniqueID = packet.ReadUInt();
model.Position = new SRCoord(packet.ReadUShort(), (int)packet.ReadFloat(), (int)packet.ReadFloat(), (int)packet.ReadFloat());
model.Angle = packet.ReadUShort();
// Movement
bool hasMovement = packet.ReadBool();
model.MovementSpeedType = (SRModel.MovementSpeed)packet.ReadByte();
if (hasMovement)
{
if (model.Position.inDungeon())
model.MovementPosition = new SRCoord(packet.ReadUShort(), packet.ReadInt(), packet.ReadInt(), packet.ReadInt());
else
model.MovementPosition = new SRCoord(packet.ReadUShort(), (int)packet.ReadUShort(), (int)packet.ReadUShort(), (int)packet.ReadUShort());
}
else
{
model.MovementActionType = (SRModel.MovementAction)packet.ReadByte();
model.Angle = packet.ReadUShort();
}
// States
model.LifeStateType = (SRModel.LifeState)packet.ReadByte();
model.unkByte01 = packet.ReadByte();
model.MotionStateType = (SRModel.MotionState)packet.ReadByte();
model.GameStateType = (SRModel.GameState)packet.ReadByte();
// Speed
model.SpeedWalking = packet.ReadFloat();
model.SpeedRunning = packet.ReadFloat();
model.SpeedBerserk = packet.ReadFloat();
// Buffs
xDictionary<uint, SRBuff> buffs = new xDictionary<uint, SRBuff>();
byte buffCount = packet.ReadByte();
for (byte j = 0; j < buffCount; j++)
{
SRBuff buff = new SRBuff(packet.ReadUInt());
buff.UniqueID = packet.ReadUInt();
if (buff.hasAutoTransferEffect())
{
bool isCaster = packet.ReadBool();
if (isCaster)
buff.CasterUniqueID = model.UniqueID;
}
buff.TargetUniqueID = model.UniqueID;
// Easy track using GroupID to avoid overlap issues
buffs[buff.GroupID] = buff;
}
model.Buffs = buffs;
if (model.isPlayer())
{
SRPlayer player = (SRPlayer)model;
// Actions
player.Name = packet.ReadAscii();
player.JobType = (SRPlayer.Job)packet.ReadByte();
player.JobLevel = packet.ReadByte();
player.PVPStateType = (SRPlayer.PVPState)packet.ReadByte();
bool isRiding = packet.ReadBool();
player.inCombat = packet.ReadBool();
if (isRiding)
player.RidingUniqueID = packet.ReadUInt();
player.ScrollingType = (SRPlayer.Scrolling)packet.ReadByte();
player.InteractionType = (SRPlayer.Interaction)packet.ReadByte();
player.unkByte03 = packet.ReadByte();
// Guild
player.GuildName = packet.ReadAscii();
if (player.hasJobMode())
{
player.Name = "*" + player.Name;
}
else
{
SRPlayer.SRPlayerGuildInfo gInfo = new SRPlayer.SRPlayerGuildInfo();
gInfo.GuildID = packet.ReadUInt();
gInfo.GuildMemberName = packet.ReadAscii();
gInfo.GuildLastCrestRev = packet.ReadUInt();
gInfo.UnionID = packet.ReadUInt();
gInfo.UnionLastCrestRev = packet.ReadUInt();
gInfo.isFriendly = packet.ReadBool();
gInfo.GuildMemberAuthorityType = (SRPlayer.SRPlayerGuildInfo.GuildMemberAuthority)packet.ReadByte();
player.GuildInfo = gInfo;
}
if (player.InteractionType == SRPlayer.Interaction.OnStall)
{
SRStall stall = new SRStall();
stall.Title = packet.ReadAscii();
stall.DecorationID = packet.ReadUInt();
player.Stall = stall;
}
player.EquipmentCooldown = packet.ReadByte();
player.CaptureTheFlagType = (SRPlayer.CaptureTheFlag)packet.ReadByte();
}
else if (model.isNPC())
{
SRNpc npc = (SRNpc)model;
bool hasTalk = packet.ReadByte() != 0;
if (hasTalk)
npc.TalkOptions = packet.ReadByteArray(packet.ReadByte());
if (npc.isMob())
{
SRMob mob = (SRMob)npc;
mob.MobType = (SRMob.Mob)packet.ReadByte();
if (mob.ID4 == 2 || mob.ID4 == 3)
mob.Appearence = packet.ReadByte();
}
else if (npc.isCOS())
{
SRCoService cos = (SRCoService)npc;
if (!cos.isHorse())
{
if (cos.isAttackPet() || cos.isPickPet())
cos.Name = packet.ReadAscii();
cos.OwnerName = packet.ReadAscii();
cos.JobType = (SRPlayer.Job)packet.ReadByte();
if (!cos.isPickPet())
{
cos.PVPStateType = (SRPlayer.PVPState)packet.ReadByte();
}
if (cos.isGuildGuard())
cos.OwnerObjectID = packet.ReadUInt();
cos.OwnerUniqueID = packet.ReadUInt();
}
}
else if (npc.isFortressCos())
{
SRFortressCos fCos = (SRFortressCos)npc;
fCos.GuildID = packet.ReadUInt();
fCos.GuildName = packet.ReadAscii();
}
}
if (packet.Opcode == Agent.Opcode.SERVER_ENTITY_SPAWN)
model.unkByte02 = packet.ReadByte();
}
else if (entity.isDrop())
{
SRDrop drop = (SRDrop)entity;
if (drop.isEquipable())
{
drop.Plus = packet.ReadByte();
}
else if (drop.isEtc())
{
if (drop.isGold())
drop.Gold = packet.ReadUInt();
else if (drop.isQuest() || drop.isTradeGoods())
drop.OwnerName = packet.ReadAscii();
}
// Position
drop.UniqueID = packet.ReadUInt();
drop.Position = new SRCoord(packet.ReadUShort(), (int)packet.ReadFloat(), (int)packet.ReadFloat(), (int)packet.ReadFloat());
drop.Angle = packet.ReadUShort();
// States
bool hasOwner = packet.ReadBool();
if (hasOwner)
drop.OwnerJoinID = packet.ReadUInt();
drop.Rarity = packet.ReadByte();
if (packet.Opcode == Agent.Opcode.SERVER_ENTITY_SPAWN)
{
drop.DropSourceType = packet.ReadByte();
drop.DropUniqueID = packet.ReadUInt();
}
}
else if (entity.isTeleport())
{
SRTeleport portal = (SRTeleport)entity;
// Position
portal.UniqueID = packet.ReadUInt();
portal.Position = new SRCoord(packet.ReadUShort(), (int)packet.ReadFloat(), (int)packet.ReadFloat(), (int)packet.ReadFloat());
portal.Angle = packet.ReadUShort();
// Types
portal.unkByte01 = packet.ReadByte();
portal.unkByte02 = packet.ReadByte();
portal.unkByte03 = packet.ReadByte();
portal.PortalType = (SRTeleport.Portal)packet.ReadByte();
if (portal.PortalType == SRTeleport.Portal.Regular)
{
portal.unkUInt01 = packet.ReadUInt();
portal.unkUInt02 = packet.ReadUInt();
}
else if (portal.PortalType == SRTeleport.Portal.Dimensional)
{
portal.OwnerName = packet.ReadAscii();
portal.OwnerUniqueID = packet.ReadUInt();
}
if (portal.unkByte02 == 1)
{
// STORE_OnONE_DEFAULT
portal.unkUInt03 = packet.ReadUInt();
portal.unkByte04 = packet.ReadByte();
}
}
}
else
{
SRSkillZone skillZone = (SRSkillZone)entity;
skillZone.unkUShort01 = packet.ReadUShort();
skillZone.SkillID = packet.ReadUInt();
// Position
skillZone.UniqueID = packet.ReadUInt();
skillZone.Position = new SRCoord(packet.ReadUShort(), (int)packet.ReadFloat(), (int)packet.ReadFloat(), (int)packet.ReadFloat());
skillZone.Angle = packet.ReadUShort();
}
// Tracking spawns
InfoManager.OnSpawn(entity);
}
catch (Exception ex)
{
Bot.Get.LogError("Parsing Spawn Error", ex, packet);
throw ex;
}
}
public static void EntityDespawn(Packet packet)
{
uint uniqueID = packet.ReadUInt();
// End of Packet
InfoManager.OnDespawn(uniqueID);
}
public static void EntitySelection(Packet packet)
{
// Success
if (packet.ReadBool())
InfoManager.OnEntitySelected(packet.ReadUInt());
else
InfoManager.OnEntitySelected(0);
}
public static void EntityMovement(Packet packet)
{
SRModel entity = (SRModel)InfoManager.GetEntity(packet.ReadUInt());
SRCoord currentPosition = entity.GetRealtimePosition();
bool hasMovement = packet.ReadBool();
if (hasMovement)
{
SRCoord newPosition;
if (currentPosition.inDungeon())
newPosition = new SRCoord(packet.ReadUShort(), packet.ReadInt(), packet.ReadInt(), packet.ReadInt());
else
newPosition = new SRCoord(packet.ReadUShort(), (int)packet.ReadUShort(), (int)packet.ReadUShort(), (int)packet.ReadUShort());
entity.MovementPosition = newPosition;
// Create an angle pointing to the movement position
if (entity == InfoManager.Character)
{
double xTranslate = newPosition.PosX - currentPosition.PosX;
double yTranslate = newPosition.PosY - currentPosition.PosY;
if (xTranslate == 0)
{
// 90° or 270° to SRO Angle
entity.Angle = (ushort)(ushort.MaxValue / 4 * (yTranslate > 0?1:3));
}
else
{
if (yTranslate == 0)
{
// 0° or 180° to SRO Angle
entity.Angle = (ushort)(xTranslate > 0 ? 0 : ushort.MaxValue / 2);
}
else
{
double angleRadians = Math.Atan(yTranslate / xTranslate);
// Fix direction manually
if(yTranslate < 0 || xTranslate < 0)
{
angleRadians += Math.PI;
if(xTranslate > 0)
angleRadians += Math.PI;
}
// Radians to SRO Angle
entity.Angle = (ushort)Math.Round(angleRadians * ushort.MaxValue / (Math.PI * 2.0));
}
}
}
}
if (packet.ReadBool())
{
if (hasMovement)
{
// ushort oldRegion = packet.ReadUShort();
// ushort unkUShort01
// ushort unkUShort02
// ushort unkUShort03
// ushort unkUShort04
}
else
{
// SKY WALKING
entity.Angle = packet.ReadUShort();
// short unkShort01 = packet.ReadShort();
// short unkShort02 = packet.ReadShort();
// short unkShort03 = packet.ReadShort();
// short unkShort04 = packet.ReadShort();
// Create a long sky walking movement to calculate realtime coords
double angle = entity.GetRadianAngle();
double MovementPosX = Math.Cos(angle) * ushort.MaxValue + currentPosition.PosX;
double MovementPosY = Math.Sin(angle) * ushort.MaxValue + currentPosition.PosY;
if (currentPosition.inDungeon())
entity.MovementPosition = new SRCoord(MovementPosX, MovementPosY, currentPosition.Region, currentPosition.Z);
else
entity.MovementPosition = new SRCoord(MovementPosX, MovementPosY);
}
}
// End of Packet
InfoManager.OnEntityMovement(ref entity);
}
public static void EntityMovementStuck(Packet packet)
{
SREntity entity = InfoManager.GetEntity(packet.ReadUInt());
entity.Position = new SRCoord(packet.ReadUShort(), (int)packet.ReadFloat(), (int)packet.ReadFloat(), (int)packet.ReadFloat());
entity.Angle = packet.ReadUShort();
// End of Packet
if (entity.isModel())
{
SRModel model = ((SRModel)entity);
model.MovementPosition = entity.Position;