-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathPackets.cs
More file actions
2060 lines (1754 loc) · 100 KB
/
Packets.cs
File metadata and controls
2060 lines (1754 loc) · 100 KB
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 System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace CreatureScriptsParser
{
public static class Packets
{
[Serializable]
public class Packet
{
public PacketTypes type;
public TimeSpan time;
public long number;
public string guid = "";
public long startIndex;
public long endIndex;
public Dictionary<long, long> indexes;
public Packet(PacketTypes type, TimeSpan time, long number)
{ this.type = type; this.time = time; this.number = number; }
public Packet(PacketTypes type, TimeSpan time, long number, long start, long end)
{ this.type = type; this.time = time; this.number = number; startIndex = start; endIndex = end; }
public Packet(PacketTypes type, TimeSpan time, long number, Dictionary<long, long> indexes)
{ this.type = type; this.time = time; this.number = number; this.indexes = indexes; }
public enum PacketTypes
{
Unknown_PACKET,
SMSG_UPDATE_OBJECT,
SMSG_SPELL_START,
SMSG_SPELL_GO,
SMSG_ON_MONSTER_MOVE,
SMSG_PLAY_ONE_SHOT_ANIM_KIT,
SMSG_CHAT,
SMSG_EMOTE,
SMSG_AURA_UPDATE,
SMSG_SET_AI_ANIM_KIT,
SMSG_PLAY_SPELL_VISUAL_KIT,
SMSG_PLAY_OBJECT_SOUND,
SMSG_PLAY_SPELL_VISUAL
}
}
[Serializable]
public class UpdateObjectPacket : Packet
{
public ObjectType objectType;
public UpdateType updateType;
public uint creatureEntry;
public uint conversationEntry;
public Position spawnPosition;
public uint? emoteStateId;
public uint? sheatheState;
public uint? standState;
public bool isSummonedByPlayer;
public bool hasReplacedObject;
public List<string> conversationActors;
public MonsterMovePacket moveData;
public long? unitFlags;
public long? unitFlags2;
public long? unitFlags3;
public uint factionTemplate;
public uint mountDisplayId;
public UpdateObjectPacket(PacketTypes packetType, TimeSpan time, long number, UpdateType updateType, ObjectType objectType) : base(packetType, time, number)
{ this.updateType = updateType; this.objectType = objectType; }
public enum UpdateType
{
CreateObject = 1,
Values = 2,
Destroy = 3
}
public enum ObjectType
{
Creature = 1,
Conversation = 2
}
public enum SheathState
{
SHEATH_STATE_UNARMED = 0,
SHEATH_STATE_MELEE = 1,
SHEATH_STATE_RANGED = 2
};
public enum UnitStandStateType
{
UNIT_STAND_STATE_STAND = 0,
UNIT_STAND_STATE_SIT = 1,
UNIT_STAND_STATE_SIT_CHAIR = 2,
UNIT_STAND_STATE_SLEEP = 3,
UNIT_STAND_STATE_SIT_LOW_CHAIR = 4,
UNIT_STAND_STATE_SIT_MEDIUM_CHAIR = 5,
UNIT_STAND_STATE_SIT_HIGH_CHAIR = 6,
UNIT_STAND_STATE_DEAD = 7,
UNIT_STAND_STATE_KNEEL = 8,
UNIT_STAND_STATE_SUBMERGED = 9
};
public enum UnitFlags : long
{
NotClientControlled = 0x00000001,
Spawning = 0x00000002,
RemoveClientControl = 0x00000004,
PlayerControlled = 0x00000008,
Rename = 0x00000010,
Preparation = 0x00000020,
Unk6 = 0x00000040,
NoAttack = 0x00000080,
ImmunePC = 0x00000100,
ImmuneNPC = 0x00000200,
Looting = 0x00000400,
PetIsAttackingTarget = 0x00000800,
PVP = 0x00001000,
Silenced = 0x00002000,
CannotSwim = 0x00004000,
CanSwim = 0x00008000,
NoAttack2 = 0x00010000,
Pacified = 0x00020000,
Stunned = 0x00040000,
AffectingCombat = 0x00080000,
OnTaxi = 0x00100000,
Disarmed = 0x00200000,
Confused = 0x00400000,
Feared = 0x00800000,
PossessedByPlayer = 0x01000000,
Uninteractible = 0x02000000,
Skinnable = 0x04000000,
Mount = 0x08000000,
PreventKneelingWhenLooting = 0x10000000,
PreventEmotes = 0x20000000,
Sheath = 0x40000000,
Immune = 0x80000000
};
public enum UnitFlags2 : long
{
UNIT_FLAG2_FEIGN_DEATH = 0x00000001,
UNIT_FLAG2_HIDE_BODY = 0x00000002,
UNIT_FLAG2_IGNORE_REPUTATION = 0x00000004,
UNIT_FLAG2_COMPREHEND_LANG = 0x00000008,
UNIT_FLAG2_MIRROR_IMAGE = 0x00000010,
UNIT_FLAG2_INSTANTLY_DONT_FADE_IN = 0x00000020,
UNIT_FLAG2_FORCE_MOVEMENT = 0x00000040,
UNIT_FLAG2_DISARM_OFFHAND = 0x00000080,
UNIT_FLAG2_DISABLE_PRED_STATS = 0x00000100,
UNIT_FLAG2_ALLOW_CHANGING_TALENTS = 0x00000200,
UNIT_FLAG2_DISARM_RANGED = 0x00000400,
UNIT_FLAG2_REGENERATE_POWER = 0x00000800,
UNIT_FLAG2_RESTRICT_PARTY_INTERACTION = 0x00001000,
UNIT_FLAG2_PREVENT_SPELL_CLICK = 0x00002000,
UNIT_FLAG2_INTERACT_WHILE_HOSTILE = 0x00004000,
UNIT_FLAG2_CANNOT_TURN = 0x00008000,
UNIT_FLAG2_UNK2 = 0x00010000,
UNIT_FLAG2_PLAY_DEATH_ANIM = 0x00020000,
UNIT_FLAG2_ALLOW_CHEAT_SPELLS = 0x00040000,
UNIT_FLAG2_SUPPRESS_HIGHLIGHT_WHEN_TARGETED_OR_MOUSED_OVER = 0x00080000,
UNIT_FLAG2_TREAT_AS_RAID_UNIT_FOR_HELPFUL_SPELLS = 0x00100000,
UNIT_FLAG2_LARGE_AOI = 0x00200000,
UNIT_FLAG2_GIGANTIC_AOI = 0x00400000,
UNIT_FLAG2_NO_ACTIONS = 0x00800000,
UNIT_FLAG2_AI_WILL_ONLY_SWIM_IF_TARGET_SWIMS = 0x01000000,
UNIT_FLAG2_DONT_GENERATE_COMBAT_LOG_WHEN_ENGAGED_WITH_NPCS = 0x02000000,
UNIT_FLAG2_UNTARGETABLE_BY_CLIENT = 0x04000000,
UNIT_FLAG2_ATTACKER_IGNORES_MINIMUM_RANGES = 0x08000000,
UNIT_FLAG2_UNINTERACTIBLE_IF_HOSTILE = 0x10000000,
UNIT_FLAG2_UNK13 = 0x20000000,
UNIT_FLAG2_INFINITE_AOI = 0x40000000,
UNIT_FLAG2_UNK15 = 0x80000000
};
public enum UnitFlags3 : long
{
UNIT_FLAG3_PASSIVE_AI = 0x00000001,
UNIT_FLAG3_UNCONSCIOUS_ON_DEATH = 0x00000002,
UNIT_FLAG3_ALLOW_MOUNTED_COMBAT = 0x00000004,
UNIT_FLAG3_GARRISON_PET = 0x00000008,
UNIT_FLAG3_UI_CAN_GET_POSITION = 0x00000010,
UNIT_FLAG3_AI_OBSTACLE = 0x00000020,
UNIT_FLAG3_ALTERNATIVE_DEFAULT_LANGUAGE = 0x00000040,
UNIT_FLAG3_SUPPRESS_ALL_NPC_FEEDBACK = 0x00000080,
UNIT_FLAG3_IGNORE_COMBAT = 0x00000100,
UNIT_FLAG3_SUPPRESS_NPC_FEEDBACK = 0x00000200,
UNIT_FLAG3_UNK11 = 0x00000400,
UNIT_FLAG3_UNK12 = 0x00000800,
UNIT_FLAG3_UNK13 = 0x00001000,
UNIT_FLAG3_FAKE_DEAD = 0x00002000,
UNIT_FLAG3_NO_FACING_ON_INTERACT_AND_FAST_FACING_CHASE = 0x00004000,
UNIT_FLAG3_UNTARGETABLE_FROM_UI = 0x00008000,
UNIT_FLAG3_NO_FACING_ON_INTERACT_WHILE_FAKE_DEAD = 0x00010000,
UNIT_FLAG3_ALREADY_SKINNED = 0x00020000,
UNIT_FLAG3_SUPPRESS_ALL_NPC_SOUNDS = 0x00040000,
UNIT_FLAG3_SUPPRESS_NPC_SOUNDS = 0x00080000,
UNIT_FLAG3_UNK21 = 0x00100000,
UNIT_FLAG3_UNK22 = 0x00200000,
UNIT_FLAG3_DONT_FADE_OUT = 0x00400000,
UNIT_FLAG3_UNK24 = 0x00800000,
UNIT_FLAG3_HIDE_NAMEPLATE = 0x01000000,
UNIT_FLAG3_UNK26 = 0x02000000,
UNIT_FLAG3_UNK27 = 0x04000000,
UNIT_FLAG3_UNK28 = 0x08000000,
UNIT_FLAG3_UNK29 = 0x10000000,
UNIT_FLAG3_UNK30 = 0x20000000,
UNIT_FLAG3_UNK31 = 0x40000000,
UNIT_FLAG3_UNK32 = 0x80000000
};
public static bool IsLineValidForObjectParse(string line)
{
if (line == null)
return false;
if (line == "")
return false;
if (line.Contains("UpdateType: 1 (CreateObject1)"))
return false;
if (line.Contains("UpdateType: 2 (CreateObject2)"))
return false;
if (line.Contains("UpdateType: 0 (Values)"))
return false;
if (line.Contains("DataSize"))
return false;
return true;
}
public static uint GetEntryFromLine(string line)
{
Regex entryRegexField = new Regex(@"EntryID:{1}\s*\d+");
if (entryRegexField.IsMatch(line))
return Convert.ToUInt32(entryRegexField.Match(line).ToString().Replace("EntryID: ", ""));
return 0;
}
public static Position GetSpawnPositionFromLine(string xyzLine, string oriLine)
{
Position spawnPosition = new Position();
if (xyzLine.Contains("TransportPosition"))
{
Regex xyzRegex = new Regex(@"TransportPosition:\s{1}X:{1}\s{1}");
if (xyzRegex.IsMatch(xyzLine))
{
string[] splittedLine = xyzLine.Split(' ');
spawnPosition.x = float.Parse(splittedLine[4], CultureInfo.InvariantCulture.NumberFormat);
spawnPosition.y = float.Parse(splittedLine[6], CultureInfo.InvariantCulture.NumberFormat);
spawnPosition.z = float.Parse(splittedLine[8], CultureInfo.InvariantCulture.NumberFormat);
spawnPosition.orientation = float.Parse(splittedLine[10], CultureInfo.InvariantCulture.NumberFormat);
}
}
else
{
Regex xyzRegex = new Regex(@"Position:\s{1}X:{1}\s{1}");
if (xyzRegex.IsMatch(xyzLine))
{
string[] splittedLine = xyzLine.Split(' ');
spawnPosition.x = float.Parse(splittedLine[3], CultureInfo.InvariantCulture.NumberFormat);
spawnPosition.y = float.Parse(splittedLine[5], CultureInfo.InvariantCulture.NumberFormat);
spawnPosition.z = float.Parse(splittedLine[7], CultureInfo.InvariantCulture.NumberFormat);
}
Regex oriRegex = new Regex(@"Orientation:\s{1}");
if (oriRegex.IsMatch(oriLine))
{
string[] splittedLine = oriLine.Split(' ');
spawnPosition.orientation = float.Parse(splittedLine[2], CultureInfo.InvariantCulture.NumberFormat);
}
}
return spawnPosition;
}
public static uint? GetEmoteStateFromLine(string line)
{
Regex emoteRegex = new Regex(@"EmoteState:{1}\s{1}\w+");
if (emoteRegex.IsMatch(line))
return Convert.ToUInt32(emoteRegex.Match(line).ToString().Replace("EmoteState: ", ""));
return null;
}
public static uint? GetSheatheStateFromLine(string line)
{
Regex sheatheStateRegex = new Regex(@"SheatheState:{1}\s{1}\w+");
if (sheatheStateRegex.IsMatch(line))
return Convert.ToUInt32(sheatheStateRegex.Match(line).ToString().Replace("SheatheState: ", ""));
return null;
}
public static uint? GetStandStateFromLine(string line)
{
Regex standstateRegex = new Regex(@"StandState:{1}\s{1}\w+");
if (standstateRegex.IsMatch(line))
return Convert.ToUInt32(standstateRegex.Match(line).ToString().Replace("StandState: ", ""));
return null;
}
public static bool IsSummonedByPlayer (string line)
{
return (line.Contains("SummonedBy: TypeName: Player") || line.Contains("CreatedBy: TypeName: Player") || line.Contains("DemonCreator: TypeName: Player"));
}
public static bool HasReplacedObject(string line)
{
return line.Contains("ReplaceObject: TypeName: Creature");
}
public static bool? GetFlyingFromLine(string line)
{
if (line.Contains("SplineFlags:"))
{
if (line.Contains("Flying"))
return true;
else
return false;
}
return null;
}
public static uint GetDurationFromLine(string line)
{
Regex durationRegex = new Regex(@"] Duration:{1}\s{1}\w+");
if (durationRegex.IsMatch(line))
return Convert.ToUInt32(durationRegex.Match(line).ToString().Replace("] Duration: ", ""));
return 0;
}
public static uint? GetUnitFlagsFromLine(string line)
{
Regex unitFlagsRegex = new Regex(@"\(UnitData\) Flags:{1}\s{1}\w+");
if (unitFlagsRegex.IsMatch(line))
return Convert.ToUInt32(unitFlagsRegex.Match(line).ToString().Replace("(UnitData) Flags: ", ""));
return null;
}
public static uint? GetUnitFlags2FromLine(string line)
{
Regex unitFlags2Regex = new Regex(@"\(UnitData\) Flags2:{1}\s{1}\w+");
if (unitFlags2Regex.IsMatch(line))
return Convert.ToUInt32(unitFlags2Regex.Match(line).ToString().Replace("(UnitData) Flags2: ", ""));
return null;
}
public static uint? GetUnitFlags3FromLine(string line)
{
Regex unitFlags3Regex = new Regex(@"\(UnitData\) Flags3:{1}\s{1}\w+");
if (unitFlags3Regex.IsMatch(line))
return Convert.ToUInt32(unitFlags3Regex.Match(line).ToString().Replace("(UnitData) Flags3: ", ""));
return null;
}
public static uint GetMountDisplayIdFromLine(string line)
{
Regex mountTemplateRegex = new Regex(@"\(UnitData\) MountDisplayID:{1}\s{1}\w+");
if (mountTemplateRegex.IsMatch(line))
return Convert.ToUInt32(mountTemplateRegex.Match(line).ToString().Replace("(UnitData) MountDisplayID: ", ""));
return 0;
}
public static uint GetFactionTemplateFromLine(string line)
{
Regex factionTemplateRegex = new Regex(@"\(UnitData\) FactionTemplate:{1}\s{1}\w+");
if (factionTemplateRegex.IsMatch(line))
return Convert.ToUInt32(factionTemplateRegex.Match(line).ToString().Replace("(UnitData) FactionTemplate: ", ""));
return 0;
}
public static IEnumerable<UpdateObjectPacket> ParseObjectUpdatePacket(string[] lines, Packet packet)
{
SynchronizedCollection<UpdateObjectPacket> updatePacketsList = new SynchronizedCollection<UpdateObjectPacket>();
foreach(var itr in packet.indexes)
{
if ((lines[itr.Key].Contains("UpdateType: CreateObject1") || lines[itr.Key].Contains("UpdateType: CreateObject2")) && lines[itr.Key + 1].IsCreatureLine())
{
UpdateObjectPacket updatePacket = new UpdateObjectPacket(packet.type, packet.time, packet.number, UpdateType.CreateObject, ObjectType.Creature);
updatePacket.moveData = new MonsterMovePacket(PacketTypes.SMSG_ON_MONSTER_MOVE, packet.time, packet.number);
for (long index = itr.Key; index < itr.Value; index++)
{
if (LineGetters.GetGuidFromLine(lines[index]) != "")
updatePacket.guid = LineGetters.GetGuidFromLine(lines[index]);
else if (IsSummonedByPlayer(lines[index]))
updatePacket.isSummonedByPlayer = true;
else if (HasReplacedObject(lines[index]))
updatePacket.hasReplacedObject = true;
else if (GetSpawnPositionFromLine(lines[index], lines[index + 1]).IsValid())
updatePacket.spawnPosition = GetSpawnPositionFromLine(lines[index], lines[index + 1]);
else if (GetEntryFromLine(lines[index]) != 0)
updatePacket.creatureEntry = GetEntryFromLine(lines[index]);
else if (GetFlyingFromLine(lines[index]) != null)
updatePacket.moveData.moveType = GetFlyingFromLine(lines[index]) == true ? MonsterMovePacket.MoveTypes.FLY : MonsterMovePacket.MoveTypes.UNKNOWN;
else if (GetDurationFromLine(lines[index]) != 0)
updatePacket.moveData.moveTime = GetDurationFromLine(lines[index]);
else if (MonsterMovePacket.GetPointPositionFromLine(lines[index]).IsValid())
{
do
{
if (MonsterMovePacket.GetPointPositionFromLine(lines[index]).IsValid())
{
updatePacket.moveData.waypoints.Add(MonsterMovePacket.GetPointPositionFromLine(lines[index]));
}
index++;
}
while (lines[index].Contains("Points"));
Dictionary<int, float> distancesDictionary = new Dictionary<int, float>();
for (int i = 0; i < updatePacket.moveData.waypoints.Count(); i++)
{
distancesDictionary.Add(i, updatePacket.spawnPosition.GetDistance(updatePacket.moveData.waypoints[i]));
}
for (int i = distancesDictionary.First(x => x.Value == distancesDictionary.Values.Min()).Key - 1; i >= 0; i--)
{
updatePacket.moveData.waypoints.RemoveAt(i);
}
}
}
updatePacket.moveData.startPosition = updatePacket.spawnPosition;
if (updatePacket.moveData.moveType == MonsterMovePacket.MoveTypes.UNKNOWN && updatePacket.moveData.GetWaypointsVelocity() != 0.0f)
{
if (updatePacket.moveData.GetWaypointsVelocity() >= 4.2)
{
updatePacket.moveData.moveType = MonsterMovePacket.MoveTypes.RUN;
}
else
{
updatePacket.moveData.moveType = MonsterMovePacket.MoveTypes.WALK;
}
}
if (updatePacket.creatureEntry != 0 && updatePacket.guid != "")
{
updatePacketsList.Add(updatePacket);
}
}
else if (lines[itr.Key].Contains("UpdateType: Values") && lines[itr.Key + 1].IsCreatureLine())
{
UpdateObjectPacket updatePacket = new UpdateObjectPacket(PacketTypes.SMSG_UPDATE_OBJECT, packet.time, packet.number, UpdateType.Values, ObjectType.Creature);
Parallel.For(itr.Key, itr.Value, index =>
{
if (LineGetters.GetGuidFromLine(lines[index]) != "")
updatePacket.guid = LineGetters.GetGuidFromLine(lines[index]);
else if (GetEmoteStateFromLine(lines[index]) != null)
updatePacket.emoteStateId = GetEmoteStateFromLine(lines[index]);
else if (GetSheatheStateFromLine(lines[index]) != null)
updatePacket.sheatheState = GetSheatheStateFromLine(lines[index]);
else if (GetStandStateFromLine(lines[index]) != null)
updatePacket.standState = GetStandStateFromLine(lines[index]);
else if (GetUnitFlagsFromLine(lines[index]) != null)
updatePacket.unitFlags = GetUnitFlagsFromLine(lines[index]);
else if (GetUnitFlags2FromLine(lines[index]) != null)
updatePacket.unitFlags2 = GetUnitFlags2FromLine(lines[index]);
else if (GetUnitFlags3FromLine(lines[index]) != null)
updatePacket.unitFlags3 = GetUnitFlags3FromLine(lines[index]);
else if (GetFactionTemplateFromLine(lines[index]) != 0)
updatePacket.factionTemplate = GetFactionTemplateFromLine(lines[index]);
else if (GetMountDisplayIdFromLine(lines[index]) != 0)
updatePacket.mountDisplayId = GetMountDisplayIdFromLine(lines[index]);
});
if (updatePacket.guid != "" && (updatePacket.emoteStateId != null || updatePacket.sheatheState != null ||
updatePacket.standState != null || updatePacket.unitFlags != null || updatePacket.unitFlags2 != null ||
updatePacket.unitFlags3 != null || updatePacket.factionTemplate != 0 || updatePacket.mountDisplayId != 0))
{
updatePacketsList.Add(updatePacket);
}
}
else if (lines[itr.Key].Contains("DestroyedObjCount"))
{
Parallel.For(itr.Key, itr.Value, index =>
{
UpdateObjectPacket updatePacket = new UpdateObjectPacket(PacketTypes.SMSG_UPDATE_OBJECT, packet.time, packet.number, UpdateType.Destroy, ObjectType.Creature);
if (LineGetters.GetGuidFromLine(lines[index]) != "")
updatePacket.guid = LineGetters.GetGuidFromLine(lines[index]);
if (updatePacket.guid != "")
{
updatePacketsList.Add(updatePacket);
}
});
}
else if ((lines[itr.Key].Contains("UpdateType: CreateObject1") || lines[itr.Key].Contains("UpdateType: CreateObject2")) && lines[itr.Key + 1].IsConversationLine())
{
UpdateObjectPacket updatePacket = new UpdateObjectPacket(PacketTypes.SMSG_UPDATE_OBJECT, packet.time, packet.number, UpdateType.CreateObject, ObjectType.Conversation);
updatePacket.conversationActors = new List<string>();
Parallel.For(itr.Key, itr.Value, index =>
{
if (LineGetters.GetGuidFromLine(lines[index]) != "")
updatePacket.guid = LineGetters.GetGuidFromLine(lines[index]);
else if (GetEntryFromLine(lines[index]) != 0)
updatePacket.conversationEntry = GetEntryFromLine(lines[index]);
else if (LineGetters.GetGuidFromLine(lines[index], conversationActorGuid: true) != "")
{
lock(updatePacket.conversationActors)
{
updatePacket.conversationActors.Add(LineGetters.GetGuidFromLine(lines[index], conversationActorGuid: true));
}
}
});
if (updatePacket.conversationEntry != 0 && updatePacket.guid != "" &&
updatePacket.conversationActors != null)
{
updatePacketsList.Add(updatePacket);
}
}
}
return updatePacketsList;
}
}
[Serializable]
public class SpellStartPacket : Packet
{
public string castGuid;
public uint spellId;
public Position destination;
public List<string> targetGuids = new List<string>();
public SpellStartPacket(PacketTypes packetType, TimeSpan time, long number) : base(packetType, time, number) { }
public static uint GetSpellIdFromLine(string line)
{
Regex spellIdRegex = new Regex(@"SpellID:{1}\s*\d+");
if (spellIdRegex.IsMatch(line))
return Convert.ToUInt32(spellIdRegex.Match(line).ToString().Replace("SpellID: ", ""));
return 0;
}
public static Position GetSpellDestinationFromLine(string line)
{
Position destPosition = new Position();
Regex xyzRegex = new Regex(@"Location:\s{1}X:{1}\s{1}");
if (xyzRegex.IsMatch(line))
{
string[] splittedLine = line.Split(' ');
destPosition.x = float.Parse(splittedLine[5], CultureInfo.InvariantCulture.NumberFormat);
destPosition.y = float.Parse(splittedLine[7], CultureInfo.InvariantCulture.NumberFormat);
destPosition.z = float.Parse(splittedLine[9], CultureInfo.InvariantCulture.NumberFormat);
}
return destPosition;
}
public static List<string> GetHitTargetGuidsFromLine(string[] lines, long index)
{
List<string> targetGuids = new List<string>();
Regex hitTargetRegex = new Regex(@"\(Go\){1}\s{1}\[{1}\d]{1}\s{1}HitTarget:{1}");
if (hitTargetRegex.IsMatch(lines[index]))
{
do
{
if (LineGetters.GetGuidFromLine(lines[index], hitTargetGuid: true) != "")
targetGuids.Add(LineGetters.GetGuidFromLine(lines[index], hitTargetGuid: true));
index++;
}
while (!lines[index].Contains("HitStatusReason"));
}
return targetGuids;
}
public static bool IsCreatureSpellCastLine(string line)
{
return line.Contains("CasterGUID: TypeName: Creature;") || line.Contains("CasterGUID: TypeName: Vehicle;");
}
public static void FilterSpellPackets(List<object> packetList)
{
List<object> copyofPacketsList = new List<object>(packetList);
Parallel.For(0, copyofPacketsList.Count(), i =>
{
if (copyofPacketsList[i].GetType() == typeof(SpellStartPacket))
{
SpellStartPacket startPacket = (SpellStartPacket)copyofPacketsList[i];
if (startPacket.type == PacketTypes.SMSG_SPELL_START)
{
object packet = copyofPacketsList.FirstOrDefault(x => x.GetType() == typeof(SpellStartPacket) && ((SpellStartPacket)x).type == PacketTypes.SMSG_SPELL_GO && ((SpellStartPacket)x).castGuid == startPacket.castGuid);
if (packet != null)
{
SpellStartPacket goPacket = (SpellStartPacket)packet;
startPacket.destination = goPacket.destination;
startPacket.targetGuids = goPacket.targetGuids;
lock (packetList)
{
packetList.Remove(goPacket);
}
}
}
}
});
Parallel.For(0, copyofPacketsList.Count(), i =>
{
if (copyofPacketsList[i].GetType() == typeof(SpellStartPacket))
{
SpellStartPacket goPacket = (SpellStartPacket)copyofPacketsList[i];
if (goPacket.type == PacketTypes.SMSG_SPELL_GO)
{
object startPacket = copyofPacketsList.FirstOrDefault(x => x.GetType() == typeof(SpellStartPacket) && ((SpellStartPacket)x).type == PacketTypes.SMSG_SPELL_START && ((SpellStartPacket)x).castGuid == goPacket.castGuid);
if (startPacket != null)
{
lock (packetList)
{
packetList.Remove(goPacket);
}
}
}
}
});
}
public static SpellStartPacket ParseSpellStartPacket(string[] lines, Packet packet)
{
SpellStartPacket spellPacket = new SpellStartPacket(packet.type, packet.time, packet.number);
if (packet.type == PacketTypes.SMSG_SPELL_START)
{
Parallel.For(packet.startIndex, packet.endIndex, x =>
{
if (LineGetters.GetGuidFromLine(lines[x], casterGuid: true) != "")
spellPacket.guid = LineGetters.GetGuidFromLine(lines[x], casterGuid: true);
else if(LineGetters.GetGuidFromLine(lines[x], castGuid: true) != "")
spellPacket.castGuid = LineGetters.GetGuidFromLine(lines[x], castGuid: true);
else if(GetSpellIdFromLine(lines[x]) != 0)
spellPacket.spellId = GetSpellIdFromLine(lines[x]);
});
}
else
{
Parallel.For(packet.startIndex, packet.endIndex, x =>
{
if (LineGetters.GetGuidFromLine(lines[x], casterGuid: true) != "")
spellPacket.guid = LineGetters.GetGuidFromLine(lines[x], casterGuid: true);
else if(LineGetters.GetGuidFromLine(lines[x], castGuid: true) != "")
spellPacket.castGuid = LineGetters.GetGuidFromLine(lines[x], castGuid: true);
else if(GetSpellIdFromLine(lines[x]) != 0)
spellPacket.spellId = GetSpellIdFromLine(lines[x]);
else if(GetSpellDestinationFromLine(lines[x]).IsValid())
spellPacket.destination = GetSpellDestinationFromLine(lines[x]);
else if(GetHitTargetGuidsFromLine(lines, x).Count != 0)
{
lock (spellPacket.targetGuids)
{
spellPacket.targetGuids = spellPacket.targetGuids.Union(GetHitTargetGuidsFromLine(lines, x)).ToList();
}
}
});
}
return spellPacket;
}
};
[Serializable]
public class MonsterMovePacket : Packet
{
public float creatureOrientation;
public JumpInfo jumpInfo;
public bool hasFacingToPlayer;
public uint moveTime;
public MoveTypes moveType = MoveTypes.UNKNOWN;
public List<Position> waypoints = new List<Position>();
public Position startPosition;
public uint tierTransitionId;
public MonsterSplineFilter splineFilter = new MonsterSplineFilter();
[Serializable]
public struct JumpInfo
{
public float jumpGravity;
public Position jumpPos;
public JumpInfo(float gravity, Position positon)
{ jumpGravity = gravity; jumpPos = positon; }
public bool IsValid()
{
return jumpGravity != 0.0f;
}
}
public enum MoveTypes
{
WALK = 1,
RUN = 2,
FLY = 3,
UNKNOWN = 4
}
[Serializable]
public struct MonsterSplineFilterKey
{
public uint idx;
public uint speed;
};
[Serializable]
public struct MonsterSplineFilter
{
public List<MonsterSplineFilterKey?> filterKeys;
public uint? filterFlags;
public float? baseSpeed;
public uint? startOffset;
public float? distToPrevFilterKey;
public uint? addedToStart;
public bool filled;
};
public MonsterMovePacket(PacketTypes type, TimeSpan time, long number) : base(type, time, number) { }
public static float GetFaceDirectionFromLine(string line)
{
Regex facingRegex = new Regex(@"FaceDirection:{1}\s+\d+\.+\d+");
if (facingRegex.IsMatch(line))
return float.Parse(facingRegex.Match(line).ToString().Replace("FaceDirection: ", ""), CultureInfo.InvariantCulture.NumberFormat);
return 0.0f;
}
public static Position GetPointPositionFromLine(string line)
{
Position pointPosition = new Position();
Regex xyzRegex = new Regex(@"Points:{1}\s{1}X:{1}.+");
if (xyzRegex.IsMatch(line))
{
string[] splittedLine = xyzRegex.Match(line).ToString().Replace("Points: X: ", "").Split(' ');
pointPosition.x = float.Parse(splittedLine[0], CultureInfo.InvariantCulture.NumberFormat);
pointPosition.y = float.Parse(splittedLine[2], CultureInfo.InvariantCulture.NumberFormat);
pointPosition.z = float.Parse(splittedLine[4], CultureInfo.InvariantCulture.NumberFormat);
}
return pointPosition;
}
public static Position GetWayPointPositionFromLine(string line)
{
Position wayPointPosition = new Position();
Regex xyzRegex = new Regex(@"WayPoints:{1}\s{1}X:{1}.+");
if (xyzRegex.IsMatch(line))
{
string[] splittedLine = xyzRegex.Match(line).ToString().Replace("WayPoints: X: ", "").Split(' ');
wayPointPosition.x = float.Parse(splittedLine[0], CultureInfo.InvariantCulture.NumberFormat);
wayPointPosition.y = float.Parse(splittedLine[2], CultureInfo.InvariantCulture.NumberFormat);
wayPointPosition.z = float.Parse(splittedLine[4], CultureInfo.InvariantCulture.NumberFormat);
}
return wayPointPosition;
}
public static float GetJumpGravityFromLine(string line)
{
Regex jumpGravityRegex = new Regex(@"JumpGravity:{1}\s+.+");
if (jumpGravityRegex.IsMatch(line))
return float.Parse((jumpGravityRegex.Match(line).ToString().Replace("JumpGravity: ", "")), CultureInfo.InvariantCulture.NumberFormat);
return 0.0f;
}
public static uint GetMoveTimeFromLine(string line)
{
Regex moveTimeRegex = new Regex(@"MoveTime:{1}\s+\d+");
if (moveTimeRegex.IsMatch(line))
return Convert.ToUInt32(moveTimeRegex.Match(line).ToString().Replace("MoveTime: ", ""));
return 0;
}
public static bool? GetFlyingFromLine(string line)
{
if (line.Contains("Flags:") && !line.Contains("FilterFlags"))
{
if (line.Contains("Flying"))
return true;
else
return false;
}
return null;
}
public static Position GetPositionFromLine(string line)
{
Position position = new Position();
Regex xyzRegex = new Regex(@"Position:{1}\s{1}X:{1}.+");
if (xyzRegex.IsMatch(line))
{
string[] splittedLine = xyzRegex.Match(line).ToString().Replace("Position: X: ", "").Split(' ');
position.x = float.Parse(splittedLine[0], CultureInfo.InvariantCulture.NumberFormat);
position.y = float.Parse(splittedLine[2], CultureInfo.InvariantCulture.NumberFormat);
position.z = float.Parse(splittedLine[4], CultureInfo.InvariantCulture.NumberFormat);
}
return position;
}
public static bool HasFacingToPlayer(string line)
{
return line.Contains("FacingGUID: TypeName: Player; Full:");
}
public bool HasOrientation()
{
return creatureOrientation != 0.0f;
}
public bool HasJump()
{
return jumpInfo.IsValid();
}
public string GetSetSpeedString()
{
switch (moveType)
{
case MoveTypes.WALK:
return "me->SetSpeed(MOVE_WALK, " + GetSpeedRateString() + ", true);";
case MoveTypes.RUN:
return "me->SetSpeed(MOVE_RUN, " + GetSpeedRateString() + ", true);";
case MoveTypes.FLY:
return tierTransitionId == 0 ? "me->SetSpeed(MOVE_FLIGHT, " + GetSpeedRateString() + ", true);" : "me->SetSpeed(MOVE_RUN, " + GetSpeedRateString() + ", true);";
default:
return "";
}
}
private string GetSpeedRateString()
{
string speedRate = "";
switch (moveType)
{
case MoveTypes.WALK:
{
speedRate += Convert.ToString(Math.Round((GetWaypointsVelocity() / 2.5f), 1)).Replace(",", ".");
break;
}
case MoveTypes.RUN:
{
speedRate += Convert.ToString(Math.Round((GetWaypointsVelocity() / 7.0f), 1)).Replace(",", ".");
break;
}
case MoveTypes.FLY:
{
speedRate += Convert.ToString(Math.Round((GetWaypointsVelocity() / 7.0f), 1)).Replace(",", ".");
break;
}
default:
break;
}
if (!speedRate.Contains("."))
return speedRate += ".0f";
else
return speedRate += "f";
}
public static bool ConsistsOfPoints(string pointLine, string nextLine)
{
if (pointLine.Contains("[0] Points: X:") && nextLine.Contains("[1] Points: X:"))
return true;
return false;
}
public float GetWaypointsDistance()
{
if (waypoints.Count() == 0)
return 0.0f;
float distance = startPosition.GetDistance(waypoints.First());
for (int i = 1; i < waypoints.Count(); i++)
{
distance += waypoints[i - 1].GetDistance(waypoints[i]);
}
return distance;
}
public float GetWaypointsVelocity()
{
return GetWaypointsDistance() / moveTime * 1000;
}
public static uint GetTierTransitionIdFromLine(string line)
{
Regex tierTransitionIdRegex = new Regex(@"TierTransitionID:{1}\s+\d+");
if (tierTransitionIdRegex.IsMatch(line))
return Convert.ToUInt32(tierTransitionIdRegex.Match(line).ToString().Replace("TierTransitionID: ", ""));
return 0;
}
public static float? GetBaseSpeedFromLine(string line)
{
Regex baseSpeedFloatRegex = new Regex(@"BaseSpeed:{1}\s+\d+\.+\d+");
if (baseSpeedFloatRegex.IsMatch(line))
return float.Parse(baseSpeedFloatRegex.Match(line).ToString().Replace("BaseSpeed: ", ""), CultureInfo.InvariantCulture.NumberFormat);
else
{
Regex baseSpeedIntRegex = new Regex(@"BaseSpeed:{1}\s+\d+");
if (baseSpeedIntRegex.IsMatch(line))
return float.Parse(baseSpeedIntRegex.Match(line).ToString().Replace("BaseSpeed: ", ""), CultureInfo.InvariantCulture.NumberFormat);
}
return null;
}
public static uint? GetStartOffsetFromLine(string line)
{
Regex startOffsetRegex = new Regex(@"StartOffset:{1}\s+\d+");
if (startOffsetRegex.IsMatch(line))
return Convert.ToUInt32(startOffsetRegex.Match(line).ToString().Replace("StartOffset: ", ""));
return null;
}
public static float? GetDistToPrevFilterKeyFromLine(string line)
{
Regex distToPrevFilterKeyFloatRegex = new Regex(@"DistToPrevFilterKey:{1}\s+\d+\.+\d+");
if (distToPrevFilterKeyFloatRegex.IsMatch(line))
return float.Parse(distToPrevFilterKeyFloatRegex.Match(line).ToString().Replace("DistToPrevFilterKey: ", ""), CultureInfo.InvariantCulture.NumberFormat);
else
{
Regex distToPrevFilterKeyIntRegex = new Regex(@"DistToPrevFilterKey:{1}\s+\d+");
if (distToPrevFilterKeyIntRegex.IsMatch(line))
return float.Parse(distToPrevFilterKeyIntRegex.Match(line).ToString().Replace("DistToPrevFilterKey: ", ""), CultureInfo.InvariantCulture.NumberFormat);
}