Skip to content

Commit f3bfd57

Browse files
committed
Prepare for versioned entity fragment enums
1 parent 0fd1275 commit f3bfd57

File tree

8 files changed

+163
-77
lines changed

8 files changed

+163
-77
lines changed

WowPacketParser/Enums/WowCSEntityFragments.cs

Lines changed: 91 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,42 @@
1-
using System.Collections.Generic;
1+
using System;
2+
using System.Collections.Generic;
23
using WowPacketParser.Misc;
34

45
namespace WowPacketParser.Enums
56
{
67
public enum WowCSEntityFragments : int
8+
{
9+
CGObject,
10+
Tag_Item,
11+
Tag_Container,
12+
Tag_AzeriteEmpoweredItem,
13+
Tag_AzeriteItem,
14+
Tag_Unit,
15+
Tag_Player,
16+
Tag_GameObject,
17+
Tag_DynamicObject,
18+
Tag_Corpse,
19+
Tag_AreaTrigger,
20+
Tag_SceneObject,
21+
Tag_Conversation,
22+
Tag_AIGroup,
23+
Tag_Scenario,
24+
Tag_LootObject,
25+
Tag_ActivePlayer,
26+
Tag_ActiveClient_S,
27+
Tag_ActiveObject_C,
28+
Tag_VisibleObject_C,
29+
Tag_UnitVehicle,
30+
FEntityPosition,
31+
FEntityLocalMatrix,
32+
FEntityWorldMatrix,
33+
CActor,
34+
FVendor_C,
35+
FMirroredObject_C,
36+
End
37+
}
38+
39+
public enum WowCSEntityFragments1100 : int
740
{
841
CGObject = 0,
942
Tag_Item = 1,
@@ -67,23 +100,76 @@ public static bool IsIndirect(WowCSEntityFragments fragment)
67100
}
68101
}
69102

70-
public static int GetUpdateBitIndex(List<WowCSEntityFragments> entityFragments, WowCSEntityFragments fragment)
103+
public static int GetUpdateBitIndex(List<WowCSEntityFragment> entityFragments, WowCSEntityFragments fragment)
71104
{
72105
var index = 0;
73106
for (var i = 0; i < entityFragments.Count; ++i)
74107
{
75-
if (!IsUpdateable(entityFragments[i]))
108+
if (!IsUpdateable(entityFragments[i].UniversalValue))
76109
continue;
77110

78-
if (entityFragments[i] == fragment)
111+
if (entityFragments[i].UniversalValue == fragment)
79112
return index;
80113

81114
++index;
82-
if (IsIndirect(entityFragments[i]))
115+
if (IsIndirect(entityFragments[i].UniversalValue))
83116
++index;
84117
}
85118

86119
return -1;
87120
}
121+
122+
public static WowCSEntityFragments ToUniversal(WowCSEntityFragments1100 fragment)
123+
{
124+
return fragment switch
125+
{
126+
WowCSEntityFragments1100.CGObject => WowCSEntityFragments.CGObject,
127+
WowCSEntityFragments1100.Tag_Item => WowCSEntityFragments.Tag_Item,
128+
WowCSEntityFragments1100.Tag_Container => WowCSEntityFragments.Tag_Container,
129+
WowCSEntityFragments1100.Tag_AzeriteEmpoweredItem => WowCSEntityFragments.Tag_AzeriteEmpoweredItem,
130+
WowCSEntityFragments1100.Tag_AzeriteItem => WowCSEntityFragments.Tag_AzeriteItem,
131+
WowCSEntityFragments1100.Tag_Unit => WowCSEntityFragments.Tag_Unit,
132+
WowCSEntityFragments1100.Tag_Player => WowCSEntityFragments.Tag_Player,
133+
WowCSEntityFragments1100.Tag_GameObject => WowCSEntityFragments.Tag_GameObject,
134+
WowCSEntityFragments1100.Tag_DynamicObject => WowCSEntityFragments.Tag_DynamicObject,
135+
WowCSEntityFragments1100.Tag_Corpse => WowCSEntityFragments.Tag_Corpse,
136+
WowCSEntityFragments1100.Tag_AreaTrigger => WowCSEntityFragments.Tag_AreaTrigger,
137+
WowCSEntityFragments1100.Tag_SceneObject => WowCSEntityFragments.Tag_SceneObject,
138+
WowCSEntityFragments1100.Tag_Conversation => WowCSEntityFragments.Tag_Conversation,
139+
WowCSEntityFragments1100.Tag_AIGroup => WowCSEntityFragments.Tag_AIGroup,
140+
WowCSEntityFragments1100.Tag_Scenario => WowCSEntityFragments.Tag_Scenario,
141+
WowCSEntityFragments1100.Tag_LootObject => WowCSEntityFragments.Tag_LootObject,
142+
WowCSEntityFragments1100.Tag_ActivePlayer => WowCSEntityFragments.Tag_ActivePlayer,
143+
WowCSEntityFragments1100.Tag_ActiveClient_S => WowCSEntityFragments.Tag_ActiveClient_S,
144+
WowCSEntityFragments1100.Tag_ActiveObject_C => WowCSEntityFragments.Tag_ActiveObject_C,
145+
WowCSEntityFragments1100.Tag_VisibleObject_C => WowCSEntityFragments.Tag_VisibleObject_C,
146+
WowCSEntityFragments1100.Tag_UnitVehicle => WowCSEntityFragments.Tag_UnitVehicle,
147+
WowCSEntityFragments1100.FEntityPosition => WowCSEntityFragments.FEntityPosition,
148+
WowCSEntityFragments1100.FEntityLocalMatrix => WowCSEntityFragments.FEntityLocalMatrix,
149+
WowCSEntityFragments1100.FEntityWorldMatrix => WowCSEntityFragments.FEntityWorldMatrix,
150+
WowCSEntityFragments1100.CActor => WowCSEntityFragments.CActor,
151+
WowCSEntityFragments1100.FVendor_C => WowCSEntityFragments.FVendor_C,
152+
WowCSEntityFragments1100.FMirroredObject_C => WowCSEntityFragments.FMirroredObject_C,
153+
WowCSEntityFragments1100.End => WowCSEntityFragments.End,
154+
_ => throw new ArgumentOutOfRangeException(nameof(fragment), fragment, null)
155+
};
156+
}
157+
}
158+
159+
public readonly record struct WowCSEntityFragment : IComparable<WowCSEntityFragment>
160+
{
161+
public readonly WowCSEntityFragments UniversalValue;
162+
public readonly int VersionValue;
163+
164+
public WowCSEntityFragment(WowCSEntityFragments1100 versionValue)
165+
{
166+
UniversalValue = WowCSUtilities.ToUniversal(versionValue);
167+
VersionValue = (int)versionValue;
168+
}
169+
170+
public int CompareTo(WowCSEntityFragment other)
171+
{
172+
return VersionValue.CompareTo(other.VersionValue);
173+
}
88174
}
89175
}

WowPacketParser/Store/Objects/WoWObject.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public record WoWObject
2323
public IObjectData ObjectData;
2424
public Dictionary<int, UpdateField> UpdateFields;
2525
public Dictionary<int, List<UpdateField>> DynamicUpdateFields;
26-
public List<WowCSEntityFragments> EntityFragments;
26+
public List<WowCSEntityFragment> EntityFragments;
2727

2828
public uint PhaseMask;
2929

WowPacketParserModule.V11_0_0_55666/Parsers/UpdateHandler.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public static void HandleUpdateObject(Packet packet)
7272
WoWObject obj;
7373
Storage.Objects.TryGetValue(guid, out obj);
7474

75-
var fragments = obj != null ? obj.EntityFragments : [WowCSEntityFragments.CGObject];
75+
var fragments = obj != null ? obj.EntityFragments : [new WowCSEntityFragment(WowCSEntityFragments1100.CGObject)];
7676

7777
fieldsData.ReadBool("IsOwned", i);
7878
if (fieldsData.ReadBool("HasFragmentUpdates", i))
@@ -96,11 +96,11 @@ public static void HandleUpdateObject(Packet packet)
9696
var fragmentBitCount = 0;
9797
foreach (var existingFragment in fragments)
9898
{
99-
if (!WowCSUtilities.IsUpdateable(existingFragment))
99+
if (!WowCSUtilities.IsUpdateable(existingFragment.UniversalValue))
100100
continue;
101101

102102
++fragmentBitCount;
103-
if (WowCSUtilities.IsIndirect(existingFragment))
103+
if (WowCSUtilities.IsIndirect(existingFragment.UniversalValue))
104104
++fragmentBitCount;
105105
}
106106

@@ -184,7 +184,7 @@ public static void HandleUpdateObject(Packet packet)
184184
}
185185
}
186186
else
187-
obj?.EntityFragments.Remove(WowCSEntityFragments.CGObject);
187+
obj?.EntityFragments.RemoveAll(f => f.UniversalValue == WowCSEntityFragments.CGObject);
188188

189189
var vendorFragment = WowCSUtilities.GetUpdateBitIndex(fragments, WowCSEntityFragments.FVendor_C);
190190
if (vendorFragment >= 0 && changedFragments[vendorFragment])
@@ -213,12 +213,12 @@ public static void HandleUpdateObject(Packet packet)
213213
}
214214
}
215215

216-
private static List<WowCSEntityFragments> ReadEntityFragments(Packet packet, string name, int idx)
216+
private static List<WowCSEntityFragment> ReadEntityFragments(Packet packet, string name, int idx)
217217
{
218-
var fragmentIds = new List<WowCSEntityFragments>();
219-
WowCSEntityFragments fragmentId;
220-
while ((fragmentId = packet.ReadByteE<WowCSEntityFragments>()) != WowCSEntityFragments.End)
221-
fragmentIds.Add(packet.AddValue(name, fragmentId, idx, fragmentIds.Count));
218+
var fragmentIds = new List<WowCSEntityFragment>();
219+
WowCSEntityFragments1100 fragmentId;
220+
while ((fragmentId = packet.ReadByteE<WowCSEntityFragments1100>()) != WowCSEntityFragments1100.End)
221+
fragmentIds.Add(new WowCSEntityFragment(packet.AddValue(name, fragmentId, idx, fragmentIds.Count)));
222222

223223
return fragmentIds;
224224
}
@@ -239,7 +239,7 @@ private static void ReadCreateObjectBlock(Packet packet, CreateObject createObje
239239
var flags = fieldsData.ReadByteE<UpdateFieldFlag>("FieldFlags", index);
240240
obj.EntityFragments = ReadEntityFragments(fieldsData, "EntityFragmentID", index);
241241
var handler = CoreFields.UpdateFields.GetHandler();
242-
if (obj.EntityFragments.Contains(WowCSEntityFragments.CGObject))
242+
if (obj.EntityFragments.Exists(f => f.UniversalValue == WowCSEntityFragments.CGObject))
243243
{
244244
if (fieldsData.ReadBool("IndirectFragmentActive [CGObject]", index))
245245
{
@@ -301,9 +301,9 @@ private static void ReadCreateObjectBlock(Packet packet, CreateObject createObje
301301
}
302302
}
303303
else
304-
obj.EntityFragments.Remove(WowCSEntityFragments.CGObject);
304+
obj.EntityFragments.RemoveAll(f => f.UniversalValue == WowCSEntityFragments.CGObject);
305305
}
306-
if (obj.EntityFragments.Contains(WowCSEntityFragments.FVendor_C))
306+
if (obj.EntityFragments.Exists(f => f.UniversalValue == WowCSEntityFragments.FVendor_C))
307307
if (!WowCSUtilities.IsIndirect(WowCSEntityFragments.FVendor_C) || fieldsData.ReadBool("IndirectFragmentActive [FVendor_C]", index))
308308
handler.ReadCreateVendorData(fieldsData, flags, index);
309309

WowPacketParserModule.V3_4_0_45166/Parsers/UpdateHandler.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public static void HandleUpdateObject(Packet packet)
120120
WoWObject obj;
121121
Storage.Objects.TryGetValue(guid, out obj);
122122

123-
var fragments = obj != null ? obj.EntityFragments : [WowCSEntityFragments.CGObject];
123+
var fragments = obj != null ? obj.EntityFragments : [new WowCSEntityFragment(WowCSEntityFragments1100.CGObject)];
124124

125125
fieldsData.ReadBool("IsOwned", i);
126126
if (fieldsData.ReadBool("HasFragmentUpdates", i))
@@ -144,11 +144,11 @@ public static void HandleUpdateObject(Packet packet)
144144
var fragmentBitCount = 0;
145145
foreach (var existingFragment in fragments)
146146
{
147-
if (!WowCSUtilities.IsUpdateable(existingFragment))
147+
if (!WowCSUtilities.IsUpdateable(existingFragment.UniversalValue))
148148
continue;
149149

150150
++fragmentBitCount;
151-
if (WowCSUtilities.IsIndirect(existingFragment))
151+
if (WowCSUtilities.IsIndirect(existingFragment.UniversalValue))
152152
++fragmentBitCount;
153153
}
154154

@@ -224,7 +224,7 @@ public static void HandleUpdateObject(Packet packet)
224224
}
225225
}
226226
else
227-
obj?.EntityFragments.Remove(WowCSEntityFragments.CGObject);
227+
obj?.EntityFragments.RemoveAll(f => f.UniversalValue == WowCSEntityFragments.CGObject);
228228

229229
var vendorFragment = WowCSUtilities.GetUpdateBitIndex(fragments, WowCSEntityFragments.FVendor_C);
230230
if (vendorFragment >= 0 && changedFragments[vendorFragment])
@@ -258,12 +258,12 @@ public static void HandleUpdateObject(Packet packet)
258258
}
259259
}
260260

261-
private static List<WowCSEntityFragments> ReadEntityFragments(Packet packet, string name, int idx)
261+
private static List<WowCSEntityFragment> ReadEntityFragments(Packet packet, string name, int idx)
262262
{
263-
var fragmentIds = new List<WowCSEntityFragments>();
264-
WowCSEntityFragments fragmentId;
265-
while ((fragmentId = packet.ReadByteE<WowCSEntityFragments>()) != WowCSEntityFragments.End)
266-
fragmentIds.Add(packet.AddValue(name, fragmentId, idx, fragmentIds.Count));
263+
var fragmentIds = new List<WowCSEntityFragment>();
264+
WowCSEntityFragments1100 fragmentId;
265+
while ((fragmentId = packet.ReadByteE<WowCSEntityFragments1100>()) != WowCSEntityFragments1100.End)
266+
fragmentIds.Add(new WowCSEntityFragment(packet.AddValue(name, fragmentId, idx, fragmentIds.Count)));
267267

268268
return fragmentIds;
269269
}
@@ -284,7 +284,7 @@ private static void ReadCreateObjectBlock(Packet packet, CreateObject createObje
284284
var flags = fieldsData.ReadByteE<UpdateFieldFlag>("FieldFlags", index);
285285
obj.EntityFragments = ReadEntityFragments(fieldsData, "EntityFragmentID", index);
286286
var handler = CoreFields.UpdateFields.GetHandler();
287-
if (obj.EntityFragments.Contains(WowCSEntityFragments.CGObject))
287+
if (obj.EntityFragments.Exists(f => f.UniversalValue == WowCSEntityFragments.CGObject))
288288
{
289289
if (fieldsData.ReadBool("IndirectFragmentActive [CGObject]", index))
290290
{
@@ -346,9 +346,9 @@ private static void ReadCreateObjectBlock(Packet packet, CreateObject createObje
346346
}
347347
}
348348
else
349-
obj.EntityFragments.Remove(WowCSEntityFragments.CGObject);
349+
obj.EntityFragments.RemoveAll(f => f.UniversalValue == WowCSEntityFragments.CGObject);
350350
}
351-
if (obj.EntityFragments.Contains(WowCSEntityFragments.FVendor_C))
351+
if (obj.EntityFragments.Exists(f => f.UniversalValue == WowCSEntityFragments.FVendor_C))
352352
if (!WowCSUtilities.IsIndirect(WowCSEntityFragments.FVendor_C) || fieldsData.ReadBool("IndirectFragmentActive [FVendor_C]", index))
353353
handler.ReadCreateVendorData(fieldsData, flags, index);
354354
}

WowPacketParserModule.V4_4_0_54481/Parsers/UpdateHandler.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -953,7 +953,7 @@ public static void HandleUpdateObject442(Packet packet)
953953
WoWObject obj;
954954
Storage.Objects.TryGetValue(guid, out obj);
955955

956-
var fragments = obj != null ? obj.EntityFragments : [WowCSEntityFragments.CGObject];
956+
var fragments = obj != null ? obj.EntityFragments : [new WowCSEntityFragment(WowCSEntityFragments1100.CGObject)];
957957

958958
fieldsData.ReadBool("IsOwned", i);
959959
if (fieldsData.ReadBool("HasFragmentUpdates", i))
@@ -977,11 +977,11 @@ public static void HandleUpdateObject442(Packet packet)
977977
var fragmentBitCount = 0;
978978
foreach (var existingFragment in fragments)
979979
{
980-
if (!WowCSUtilities.IsUpdateable(existingFragment))
980+
if (!WowCSUtilities.IsUpdateable(existingFragment.UniversalValue))
981981
continue;
982982

983983
++fragmentBitCount;
984-
if (WowCSUtilities.IsIndirect(existingFragment))
984+
if (WowCSUtilities.IsIndirect(existingFragment.UniversalValue))
985985
++fragmentBitCount;
986986
}
987987

@@ -1057,7 +1057,7 @@ public static void HandleUpdateObject442(Packet packet)
10571057
}
10581058
}
10591059
else
1060-
obj?.EntityFragments.Remove(WowCSEntityFragments.CGObject);
1060+
obj?.EntityFragments.RemoveAll(f => f.UniversalValue == WowCSEntityFragments.CGObject);
10611061

10621062
var vendorFragment = WowCSUtilities.GetUpdateBitIndex(fragments, WowCSEntityFragments.FVendor_C);
10631063
if (vendorFragment >= 0 && changedFragments[vendorFragment])
@@ -1083,12 +1083,12 @@ public static void HandleUpdateObject442(Packet packet)
10831083
}
10841084
}
10851085

1086-
private static List<WowCSEntityFragments> ReadEntityFragments(Packet packet, string name, int idx)
1086+
private static List<WowCSEntityFragment> ReadEntityFragments(Packet packet, string name, int idx)
10871087
{
1088-
var fragmentIds = new List<WowCSEntityFragments>();
1089-
WowCSEntityFragments fragmentId;
1090-
while ((fragmentId = packet.ReadByteE<WowCSEntityFragments>()) != WowCSEntityFragments.End)
1091-
fragmentIds.Add(packet.AddValue(name, fragmentId, idx, fragmentIds.Count));
1088+
var fragmentIds = new List<WowCSEntityFragment>();
1089+
WowCSEntityFragments1100 fragmentId;
1090+
while ((fragmentId = packet.ReadByteE<WowCSEntityFragments1100>()) != WowCSEntityFragments1100.End)
1091+
fragmentIds.Add(new WowCSEntityFragment(packet.AddValue(name, fragmentId, idx, fragmentIds.Count)));
10921092

10931093
return fragmentIds;
10941094
}
@@ -1109,7 +1109,7 @@ private static void ReadCreateObjectBlock442(Packet packet, CreateObject createO
11091109
var flags = fieldsData.ReadByteE<UpdateFieldFlag>("FieldFlags", index);
11101110
obj.EntityFragments = ReadEntityFragments(fieldsData, "EntityFragmentID", index);
11111111
var handler = CoreFields.UpdateFields.GetHandler();
1112-
if (obj.EntityFragments.Contains(WowCSEntityFragments.CGObject))
1112+
if (obj.EntityFragments.Exists(f => f.UniversalValue == WowCSEntityFragments.CGObject))
11131113
{
11141114
if (fieldsData.ReadBool("IndirectFragmentActive [CGObject]", index))
11151115
{
@@ -1171,9 +1171,9 @@ private static void ReadCreateObjectBlock442(Packet packet, CreateObject createO
11711171
}
11721172
}
11731173
else
1174-
obj.EntityFragments.Remove(WowCSEntityFragments.CGObject);
1174+
obj.EntityFragments.RemoveAll(f => f.UniversalValue == WowCSEntityFragments.CGObject);
11751175
}
1176-
if (obj.EntityFragments.Contains(WowCSEntityFragments.FVendor_C))
1176+
if (obj.EntityFragments.Exists(f => f.UniversalValue == WowCSEntityFragments.FVendor_C))
11771177
if (!WowCSUtilities.IsIndirect(WowCSEntityFragments.FVendor_C) || fieldsData.ReadBool("IndirectFragmentActive [FVendor_C]", index))
11781178
handler.ReadCreateVendorData(fieldsData, flags, index);
11791179
}

0 commit comments

Comments
 (0)