Skip to content

Commit 4057e21

Browse files
committed
Add db2 flags to PhaseId reading
1 parent a217ca2 commit 4057e21

13 files changed

Lines changed: 75 additions & 118 deletions

File tree

WowPacketParser/DBC/DBC.cs

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,15 @@ await Task.WhenAll(Task.Run(() =>
196196
if (PhaseXPhaseGroup != null)
197197
foreach (var phase in PhaseXPhaseGroup)
198198
{
199-
if (!Phases.ContainsKey(phase.Value.PhaseGroupID))
200-
Phases.Add(phase.Value.PhaseGroupID, new List<ushort>() { phase.Value.PhaseID });
199+
if (!PhasesByGroup.TryGetValue(phase.Value.PhaseGroupID, out var phases))
200+
PhasesByGroup.Add(phase.Value.PhaseGroupID, [phase.Value.PhaseID]);
201201
else
202-
Phases[phase.Value.PhaseGroupID].Add(phase.Value.PhaseID);
202+
phases.Add(phase.Value.PhaseID);
203+
204+
if (!PhaseGroupsByPhase.TryGetValue(phase.Value.PhaseID, out var phaseGroups))
205+
PhaseGroupsByPhase.Add(phase.Value.PhaseID, [phase.Value.PhaseGroupID]);
206+
else
207+
phaseGroups.Add(phase.Value.PhaseGroupID);
203208
}
204209
}), Task.Run(() =>
205210
{
@@ -216,22 +221,14 @@ await Task.WhenAll(Task.Run(() =>
216221

217222
public static HashSet<int> GetPhaseGroups(ICollection<ushort> phases)
218223
{
219-
if (!phases.Any())
224+
if (phases.Count == 0)
220225
return new HashSet<int>();
221226

222-
HashSet<int> phaseGroups = new HashSet<int>();
227+
var phaseGroups = new HashSet<int>();
223228

224-
foreach (var phaseGroup in Phases)
225-
{
226-
foreach (var phase in phaseGroup.Value)
227-
{
228-
if (phases.Contains(phase))
229-
{
230-
phaseGroups.Add(phaseGroup.Key);
231-
break;
232-
}
233-
}
234-
}
229+
foreach (var phase in phases)
230+
if (PhaseGroupsByPhase.TryGetValue(phase, out var phaseGroupsIds))
231+
phaseGroups.UnionWith(phaseGroupsIds);
235232

236233
return phaseGroups;
237234
}
@@ -249,7 +246,8 @@ public static uint GetEmptyAnimStateID()
249246
public static readonly Dictionary<ushort, string> CriteriaStores = new Dictionary<ushort, string>();
250247
public static readonly Dictionary<uint, FactionEntry> FactionStores = new Dictionary<uint, FactionEntry>();
251248
public static readonly Dictionary<Tuple<uint, uint>, SpellEffectEntry> SpellEffectStores = new Dictionary<Tuple<uint, uint>, SpellEffectEntry>();
252-
public static readonly Dictionary<int, List<ushort>> Phases = new Dictionary<int, List<ushort>>();
249+
public static readonly Dictionary<int, List<ushort>> PhasesByGroup = new Dictionary<int, List<ushort>>();
250+
private static readonly Dictionary<ushort, List<int>> PhaseGroupsByPhase = new Dictionary<ushort, List<int>>();
253251
public static readonly Dictionary<int, HashSet<int>> BroadcastTextDurations = new Dictionary<int, HashSet<int>>();
254252
}
255253
}

WowPacketParser/Misc/StoreGetters.cs

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,53 +20,57 @@ public static string GetName(StoreNameType type, int entry, bool withEntry = tru
2020
switch (type)
2121
{
2222
case StoreNameType.Achievement:
23-
if (DBC.DBC.Achievement.ContainsKey(entry))
24-
name = DBC.DBC.Achievement[entry].Title;
23+
if (DBC.DBC.Achievement.TryGetValue(entry, out var achievement))
24+
name = achievement.Title;
2525
break;
2626
case StoreNameType.Area:
27-
if (DBC.DBC.AreaTable.ContainsKey(entry))
28-
name = DBC.DBC.AreaTable[entry].AreaName;
27+
if (DBC.DBC.AreaTable.TryGetValue(entry, out var area))
28+
name = area.AreaName;
2929
break;
3030
case StoreNameType.Unit:
31-
if (DBC.DBC.Creature.ContainsKey(entry))
32-
name = DBC.DBC.Creature[entry].Name;
31+
if (DBC.DBC.Creature.TryGetValue(entry, out var creature))
32+
name = creature.Name;
3333
break;
3434
case StoreNameType.CreatureFamily:
35-
if (DBC.DBC.CreatureFamily.ContainsKey(entry))
36-
name = DBC.DBC.CreatureFamily[entry].Name;
35+
if (DBC.DBC.CreatureFamily.TryGetValue(entry, out var creatureFamily))
36+
name = creatureFamily.Name;
3737
break;
3838
case StoreNameType.Criteria:
39-
if (DBC.DBC.CriteriaStores.ContainsKey((ushort)entry))
40-
name = DBC.DBC.CriteriaStores[(ushort)entry];
39+
if (DBC.DBC.CriteriaStores.TryGetValue((ushort)entry, out var criteriaName))
40+
name = criteriaName;
4141
break;
4242
case StoreNameType.Difficulty:
43-
if (DBC.DBC.Difficulty.ContainsKey(entry))
44-
name = DBC.DBC.Difficulty[entry].Name;
43+
if (DBC.DBC.Difficulty.TryGetValue(entry, out var difficulty))
44+
name = difficulty.Name;
4545
break;
4646
case StoreNameType.Faction:
47-
if (DBC.DBC.FactionStores.ContainsKey((uint)entry))
48-
name = DBC.DBC.FactionStores[(uint)entry].Name;
47+
if (DBC.DBC.FactionStores.TryGetValue((uint)entry, out var faction))
48+
name = faction.Name;
4949
break;
5050
case StoreNameType.Item:
51-
if (DBC.DBC.ItemSparse.ContainsKey(entry))
52-
name = DBC.DBC.ItemSparse[entry].Display;
51+
if (DBC.DBC.ItemSparse.TryGetValue(entry, out var item))
52+
name = item.Display;
5353
break;
5454
case StoreNameType.Map:
55-
if (DBC.DBC.Map.ContainsKey(entry))
56-
name = DBC.DBC.Map[entry].MapName;
55+
if (DBC.DBC.Map.TryGetValue(entry, out var map))
56+
name = map.MapName;
5757
break;
5858
case StoreNameType.Spell:
59-
if (DBC.DBC.SpellName.ContainsKey(entry))
60-
name = DBC.DBC.SpellName[entry].Name;
59+
if (DBC.DBC.SpellName.TryGetValue(entry, out var spell))
60+
name = spell.Name;
6161
break;
6262
case StoreNameType.Zone:
63-
if (DBC.DBC.Zones.ContainsKey((uint)entry))
64-
name = DBC.DBC.Zones[(uint)entry];
63+
if (DBC.DBC.Zones.TryGetValue((uint)entry, out var zone))
64+
name = zone;
65+
break;
66+
case StoreNameType.Phase:
67+
if (DBC.DBC.Phase.TryGetValue(entry, out var phase))
68+
name = ((DBCPhaseFlags)phase.Flags).ToString();
6569
break;
6670
}
6771
if (name != string.Empty)
6872
{
69-
if (withEntry)
73+
if (withEntry)
7074
return entry + " (" + name + ")";
7175
return name;
7276
}
@@ -78,10 +82,10 @@ public static string GetName(StoreNameType type, int entry, bool withEntry = tru
7882
if (type != StoreNameType.Map && entry == 0)
7983
return "0"; // map can be 0
8084

81-
if (!SQLDatabase.NameStores.ContainsKey(type))
85+
if (!SQLDatabase.NameStores.TryGetValue(type, out var store))
8286
return entryStr;
8387

84-
if (!SQLDatabase.NameStores[type].TryGetValue(entry, out name))
88+
if (!store.TryGetValue(entry, out name))
8589
if (!withEntry)
8690
return "-Unknown-";
8791

WowPacketParserModule.V3_4_0_45166/Parsers/MovementHandler.cs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -471,24 +471,16 @@ public static void HandlePhaseShift(Packet packet)
471471
{
472472
packet.ReadUInt32E<PhaseFlags>("PhaseFlags", i);
473473

474-
var id = packet.ReadUInt16();
474+
var id = packet.ReadUInt16<PhaseId>("ID", i);
475475
phaseShift.Phases.Add(id);
476476

477-
if (Settings.UseDBC && DBC.Phase.ContainsKey(id))
478-
{
479-
packet.WriteLine($"[{i}] ID: {id} ({StoreGetters.GetName(StoreNameType.PhaseId, id, false)}) Flags: {(DBCPhaseFlags)DBC.Phase[id].Flags}");
480-
}
481-
else
482-
packet.AddValue($"ID", id, i);
483-
484477
CoreParsers.MovementHandler.ActivePhases.Add(id, true);
485478
}
486479

487-
if (DBC.Phases.Any())
488-
{
480+
if (DBC.PhasesByGroup.Count != 0)
489481
foreach (var phaseGroup in DBC.GetPhaseGroups(CoreParsers.MovementHandler.ActivePhases.Keys))
490-
packet.WriteLine($"PhaseGroup: {phaseGroup} Phases: {string.Join(" - ", DBC.Phases[phaseGroup])}");
491-
}
482+
packet.WriteLine($"PhaseGroup: {phaseGroup} Phases: {string.Join(" - ", DBC.PhasesByGroup[phaseGroup])}");
483+
492484
var visibleMapIDsCount = packet.ReadInt32("VisibleMapIDsCount") / 2;
493485
for (var i = 0; i < visibleMapIDsCount; ++i)
494486
phaseShift.VisibleMaps.Add((uint)packet.ReadInt16<MapId>("VisibleMapID", i));

WowPacketParserModule.V4_3_4_15595/Parsers/MovementHandler.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2732,16 +2732,14 @@ public static void HandlePhaseShift434(Packet packet)
27322732
var count = packet.ReadUInt32("PhaseShiftCount") / 2;
27332733
for (var i = 0; i < count; ++i)
27342734
{
2735-
var id = packet.ReadUInt16("Id", i);
2735+
var id = packet.ReadUInt16<PhaseId>("Id", i);
27362736
phaseShift.Phases.Add(id);
27372737
CoreParsers.MovementHandler.ActivePhases.Add(id, true);
27382738
}
27392739

2740-
if (DBC.Phases.Any())
2741-
{
2740+
if (DBC.PhasesByGroup.Count != 0)
27422741
foreach (var phaseGroup in DBC.GetPhaseGroups(CoreParsers.MovementHandler.ActivePhases.Keys))
2743-
packet.WriteLine($"PhaseGroup: { phaseGroup } Phases: { string.Join(" - ", DBC.Phases[phaseGroup]) }");
2744-
}
2742+
packet.WriteLine($"PhaseGroup: {phaseGroup} Phases: {string.Join(" - ", DBC.PhasesByGroup[phaseGroup])}");
27452743

27462744
packet.ReadXORByte(guid, 3);
27472745
packet.ReadXORByte(guid, 0);

WowPacketParserModule.V4_4_0_54481/Parsers/MovementHandler.cs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -445,24 +445,16 @@ public static void HandlePhaseShift(Packet packet)
445445
{
446446
packet.ReadUInt32E<PhaseFlags>("PhaseFlags", i);
447447

448-
var id = packet.ReadUInt16();
448+
var id = packet.ReadUInt16<PhaseId>("ID", i);
449449
phaseShift.Phases.Add(id);
450450

451-
if (Settings.UseDBC && DBC.Phase.ContainsKey(id))
452-
{
453-
packet.WriteLine($"[{i}] ID: {id} ({StoreGetters.GetName(StoreNameType.PhaseId, id, false)}) Flags: {(DBCPhaseFlags)DBC.Phase[id].Flags}");
454-
}
455-
else
456-
packet.AddValue($"ID", id, i);
457-
458451
CoreParsers.MovementHandler.ActivePhases.Add(id, true);
459452
}
460453

461-
if (DBC.Phases.Any())
462-
{
454+
if (DBC.PhasesByGroup.Count != 0)
463455
foreach (var phaseGroup in DBC.GetPhaseGroups(CoreParsers.MovementHandler.ActivePhases.Keys))
464-
packet.WriteLine($"PhaseGroup: {phaseGroup} Phases: {string.Join(" - ", DBC.Phases[phaseGroup])}");
465-
}
456+
packet.WriteLine($"PhaseGroup: {phaseGroup} Phases: {string.Join(" - ", DBC.PhasesByGroup[phaseGroup])}");
457+
466458
var visibleMapIDsCount = packet.ReadInt32("VisibleMapIDsCount") / 2;
467459
for (var i = 0; i < visibleMapIDsCount; ++i)
468460
phaseShift.VisibleMaps.Add((uint)packet.ReadInt16<MapId>("VisibleMapID", i));

WowPacketParserModule.V5_3_0_16981/Parsers/MovementHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ public static void HandlePhaseShift(Packet packet)
471471
packet.AddValue("Phases count", count);
472472
for (var i = 0; i < count; ++i)
473473
{
474-
var phaseId = packet.ReadUInt16("Phase id", i);
474+
var phaseId = packet.ReadUInt16<PhaseId>("ID", i);
475475
phaseShift.Phases.Add(phaseId);
476476
CoreParsers.MovementHandler.ActivePhases.Add(phaseId, true); // Phase.dbc
477477
}

WowPacketParserModule.V5_4_0_17359/Parsers/MovementHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ public static void HandlePhaseShift(Packet packet)
248248
packet.AddValue("Phases count", count);
249249
for (var i = 0; i < count; ++i)
250250
{
251-
var phaseId = packet.ReadUInt16("Phase id", i);
251+
var phaseId = packet.ReadUInt16<PhaseId>("ID", i);
252252
phaseShift.Phases.Add(phaseId);
253253
CoreParsers.MovementHandler.ActivePhases.Add(phaseId, true); // Phase.dbc
254254
}

WowPacketParserModule.V5_4_2_17658/Parsers/MovementHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -917,7 +917,7 @@ public static void HandlePhaseShift(Packet packet)
917917
packet.AddValue("Phases count", count);
918918
for (var i = 0; i < count; ++i)
919919
{
920-
var phaseId = packet.ReadUInt16("Phase id", i);
920+
var phaseId = packet.ReadUInt16<PhaseId>("ID", i);
921921
phaseShift.Phases.Add(phaseId);
922922
CoreParsers.MovementHandler.ActivePhases.Add(phaseId, true); // Phase.dbc
923923
}

WowPacketParserModule.V5_4_7_17898/Parsers/MovementHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ public static void HandlePhaseShift(Packet packet)
447447
packet.AddValue("Phases count", count);
448448
for (var i = 0; i < count; ++i)
449449
{
450-
var phaseId = packet.ReadUInt16("Phase id", i);
450+
var phaseId = packet.ReadUInt16<PhaseId>("ID", i);
451451
phaseShift.Phases.Add(phaseId);
452452
CoreParsers.MovementHandler.ActivePhases.Add(phaseId, true); // Phase.dbc
453453
}

WowPacketParserModule.V5_5_0_61735/Parsers/MovementHandler.cs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -557,24 +557,16 @@ public static void HandlePhaseShift(Packet packet)
557557
{
558558
packet.ReadUInt32E<PhaseFlags>("PhaseFlags", i);
559559

560-
var id = packet.ReadUInt16();
560+
var id = packet.ReadUInt16<PhaseId>("ID", i);
561561
phaseShift.Phases.Add(id);
562562

563-
if (Settings.UseDBC && DBC.Phase.ContainsKey(id))
564-
{
565-
packet.WriteLine($"[{i}] ID: {id} ({StoreGetters.GetName(StoreNameType.PhaseId, id, false)}) Flags: {(DBCPhaseFlags)DBC.Phase[id].Flags}");
566-
}
567-
else
568-
packet.AddValue($"ID", id, i);
569-
570563
CoreParsers.MovementHandler.ActivePhases.Add(id, true);
571564
}
572565

573-
if (DBC.Phases.Any())
574-
{
566+
if (DBC.PhasesByGroup.Count != 0)
575567
foreach (var phaseGroup in DBC.GetPhaseGroups(CoreParsers.MovementHandler.ActivePhases.Keys))
576-
packet.WriteLine($"PhaseGroup: {phaseGroup} Phases: {string.Join(" - ", DBC.Phases[phaseGroup])}");
577-
}
568+
packet.WriteLine($"PhaseGroup: {phaseGroup} Phases: {string.Join(" - ", DBC.PhasesByGroup[phaseGroup])}");
569+
578570
var visibleMapIDsCount = packet.ReadInt32("VisibleMapIDsCount") / 2;
579571
for (var i = 0; i < visibleMapIDsCount; ++i)
580572
phaseShift.VisibleMaps.Add((uint)packet.ReadInt16<MapId>("VisibleMapID", i));

0 commit comments

Comments
 (0)