Skip to content

Commit

Permalink
Unify phase storage for all versions
Browse files Browse the repository at this point in the history
  • Loading branch information
Shauren committed Dec 30, 2019
1 parent 63c936b commit b223e9f
Show file tree
Hide file tree
Showing 21 changed files with 41 additions and 53 deletions.
8 changes: 5 additions & 3 deletions WowPacketParser/Parsing/Parsers/MovementHandler.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using WowPacketParser.Enums;
using WowPacketParser.Enums.Version;
Expand All @@ -17,7 +18,8 @@ public static class MovementHandler
public static uint CurrentDifficultyID = 1;
public static int CurrentPhaseMask = 1;

public static readonly ConcurrentBag<ushort> ActivePhases = new ConcurrentBag<ushort>();
// this is a dictionary because ConcurrentSet does not exist
public static readonly IDictionary<ushort, bool> ActivePhases = new ConcurrentDictionary<ushort, bool>();

public static MovementInfo ReadMovementInfo(Packet packet, WowGuid guid, object index = null)
{
Expand Down Expand Up @@ -1586,7 +1588,7 @@ public static void HandlePhaseShift505(Packet packet)
count = packet.ReadUInt32() / 2;
packet.AddValue("Phases count", count);
for (var i = 0; i < count; ++i)
ActivePhases.Add(packet.ReadUInt16("Phase id", i)); // Phase.dbc
ActivePhases.Add(packet.ReadUInt16("Phase id", i), true); // Phase.dbc

count = packet.ReadUInt32() / 2;
packet.AddValue("WorldMapArea swap count", count);
Expand Down Expand Up @@ -1618,7 +1620,7 @@ public static void HandlePhaseShift510(Packet packet)
count = packet.ReadUInt32() / 2;
packet.AddValue("Phases count", count);
for (var i = 0; i < count; ++i)
ActivePhases.Add(packet.ReadUInt16("Phase id", i)); // Phase.dbc
ActivePhases.Add(packet.ReadUInt16("Phase id", i), true); // Phase.dbc

packet.ReadXORByte(guid, 1);
packet.ReadXORByte(guid, 6);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System.Collections.Concurrent;
using System.Collections.Generic;
using WowPacketParser.Enums;
using WowPacketParser.Misc;
using WowPacketParser.Parsing;
Expand All @@ -8,8 +6,6 @@ namespace WowPacketParserModule.V1_13_2_31446.Parsers
{
public static class MovementHandler
{
public static readonly IDictionary<ushort, bool> ActivePhases = new ConcurrentDictionary<ushort, bool>();

[Parser(Opcode.SMSG_LOGIN_SET_TIME_SPEED)]
public static void HandleLoginSetTimeSpeed(Packet packet)
{
Expand Down
7 changes: 2 additions & 5 deletions WowPacketParserModule.V1_13_2_31446/Parsers/UpdateHandler.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Generic;
using WowPacketParser.Enums;
using WowPacketParser.Enums.Version;
using WowPacketParser.Misc;
using WowPacketParser.Parsing;
using WowPacketParser.Store;
Expand Down Expand Up @@ -96,7 +93,7 @@ private static void ReadCreateObjectBlock(Packet packet, WowGuid guid, uint map,
obj.Area = CoreParsers.WorldStateHandler.CurrentAreaId;
obj.Zone = CoreParsers.WorldStateHandler.CurrentZoneId;
obj.PhaseMask = (uint)CoreParsers.MovementHandler.CurrentPhaseMask;
obj.Phases = new HashSet<ushort>(MovementHandler.ActivePhases.Keys);
obj.Phases = new HashSet<ushort>(CoreParsers.MovementHandler.ActivePhases.Keys);
obj.DifficultyID = CoreParsers.MovementHandler.CurrentDifficultyID;

// If this is the second time we see the same object (same guid,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2732,7 +2732,7 @@ public static void HandlePhaseShift434(Packet packet)
count = packet.ReadUInt32() / 2;
packet.AddValue("Phases count", count);
for (var i = 0; i < count; ++i)
CoreParsers.MovementHandler.ActivePhases.Add(packet.ReadUInt16("Phase id", i)); // Phase.dbc
CoreParsers.MovementHandler.ActivePhases.Add(packet.ReadUInt16("Phase id", i), true); // Phase.dbc

packet.ReadXORByte(guid, 3);
packet.ReadXORByte(guid, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private static void ReadCreateObjectBlock(Packet packet, WowGuid guid, uint map,
obj.Area = CoreParsers.WorldStateHandler.CurrentAreaId;
obj.Zone = CoreParsers.WorldStateHandler.CurrentZoneId;
obj.PhaseMask = (uint)CoreParsers.MovementHandler.CurrentPhaseMask;
obj.Phases = new HashSet<ushort>(CoreParsers.MovementHandler.ActivePhases);
obj.Phases = new HashSet<ushort>(CoreParsers.MovementHandler.ActivePhases.Keys);

// If this is the second time we see the same object (same guid,
// same position) update its phasemask
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ public static void HandlePhaseShift(Packet packet)
count = packet.ReadUInt32() / 2;
packet.AddValue("Phases count", count);
for (var i = 0; i < count; ++i)
CoreParsers.MovementHandler.ActivePhases.Add(packet.ReadUInt16("Phase id", i)); // Phase.dbc
CoreParsers.MovementHandler.ActivePhases.Add(packet.ReadUInt16("Phase id", i), true); // Phase.dbc

packet.ReadXORByte(guid, 7);
count = packet.ReadUInt32() / 2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ private static void ReadCreateObjectBlock(Packet packet, WowGuid guid, uint map,
obj.Area = CoreParsers.WorldStateHandler.CurrentAreaId;
obj.Zone = CoreParsers.WorldStateHandler.CurrentZoneId;
obj.PhaseMask = (uint)CoreParsers.MovementHandler.CurrentPhaseMask;
obj.Phases = new HashSet<ushort>(CoreParsers.MovementHandler.ActivePhases);
obj.Phases = new HashSet<ushort>(CoreParsers.MovementHandler.ActivePhases.Keys);

// If this is the second time we see the same object (same guid,
// same position) update its phasemask
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ public static void HandlePhaseShift(Packet packet)
count = packet.ReadUInt32() / 2;
packet.AddValue("Phases count", count);
for (var i = 0; i < count; ++i)
CoreParsers.MovementHandler.ActivePhases.Add(packet.ReadUInt16("Phase id", i)); // Phase.dbc
CoreParsers.MovementHandler.ActivePhases.Add(packet.ReadUInt16("Phase id", i), true); // Phase.dbc

count = packet.ReadUInt32() / 2;
packet.AddValue("Inactive Terrain swap count", count);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ private static void ReadCreateObjectBlock(Packet packet, WowGuid guid, uint map,
obj.Area = CoreParsers.WorldStateHandler.CurrentAreaId;
obj.Zone = CoreParsers.WorldStateHandler.CurrentZoneId;
obj.PhaseMask = (uint)CoreParsers.MovementHandler.CurrentPhaseMask;
obj.Phases = new HashSet<ushort>(CoreParsers.MovementHandler.ActivePhases);
obj.Phases = new HashSet<ushort>(CoreParsers.MovementHandler.ActivePhases.Keys);

// If this is the second time we see the same object (same guid,
// same position) update its phasemask
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ private static void ReadCreateObjectBlock(Packet packet, WowGuid guid, uint map,
obj.Area = CoreParsers.WorldStateHandler.CurrentAreaId;
obj.Zone = CoreParsers.WorldStateHandler.CurrentZoneId;
obj.PhaseMask = (uint)CoreParsers.MovementHandler.CurrentPhaseMask;
obj.Phases = new HashSet<ushort>(CoreParsers.MovementHandler.ActivePhases);
obj.Phases = new HashSet<ushort>(CoreParsers.MovementHandler.ActivePhases.Keys);

// If this is the second time we see the same object (same guid,
// same position) update its phasemask
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -906,7 +906,7 @@ public static void HandlePhaseShift(Packet packet)
count = packet.ReadUInt32() / 2;
packet.AddValue("Phases count", count);
for (var i = 0; i < count; ++i)
CoreParsers.MovementHandler.ActivePhases.Add(packet.ReadUInt16("Phase id", i)); // Phase.dbc
CoreParsers.MovementHandler.ActivePhases.Add(packet.ReadUInt16("Phase id", i), true); // Phase.dbc

packet.ParseBitStream(guid, 7, 0);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ private static void ReadCreateObjectBlock(Packet packet, WowGuid guid, uint map,
obj.Area = CoreParsers.WorldStateHandler.CurrentAreaId;
obj.Zone = CoreParsers.WorldStateHandler.CurrentZoneId;
obj.PhaseMask = (uint)CoreParsers.MovementHandler.CurrentPhaseMask;
obj.Phases = new HashSet<ushort>(CoreParsers.MovementHandler.ActivePhases);
obj.Phases = new HashSet<ushort>(CoreParsers.MovementHandler.ActivePhases.Keys);

// If this is the second time we see the same object (same guid,
// same position) update its phasemask
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ public static void HandlePhaseShift(Packet packet)
count = packet.ReadUInt32() / 2;
packet.AddValue("Phases count", count);
for (var i = 0; i < count; ++i)
CoreParsers.MovementHandler.ActivePhases.Add(packet.ReadUInt16("Phase id", i)); // Phase.dbc
CoreParsers.MovementHandler.ActivePhases.Add(packet.ReadUInt16("Phase id", i), true); // Phase.dbc

count = packet.ReadUInt32() / 2;
packet.AddValue("Active Terrain swap count", count);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ private static void ReadCreateObjectBlock(Packet packet, WowGuid guid, uint map,
obj.Area = CoreParsers.WorldStateHandler.CurrentAreaId;
obj.Zone = CoreParsers.WorldStateHandler.CurrentZoneId;
obj.PhaseMask = (uint)CoreParsers.MovementHandler.CurrentPhaseMask;
obj.Phases = new HashSet<ushort>(CoreParsers.MovementHandler.ActivePhases);
obj.Phases = new HashSet<ushort>(CoreParsers.MovementHandler.ActivePhases.Keys);

// If this is the second time we see the same object (same guid,
// same position) update its phasemask
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ private static void ReadCreateObjectBlock(Packet packet, WowGuid guid, uint map,
obj.Area = CoreParsers.WorldStateHandler.CurrentAreaId;
obj.Zone = CoreParsers.WorldStateHandler.CurrentZoneId;
obj.PhaseMask = (uint)CoreParsers.MovementHandler.CurrentPhaseMask;
obj.Phases = new HashSet<ushort>(CoreParsers.MovementHandler.ActivePhases);
obj.Phases = new HashSet<ushort>(CoreParsers.MovementHandler.ActivePhases.Keys);

// If this is the second time we see the same object (same guid,
// same position) update its phasemask
Expand Down
19 changes: 9 additions & 10 deletions WowPacketParserModule.V6_0_2_19033/Parsers/MovementHandler.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using WowPacketParser.DBC;
using WowPacketParser.Enums;
Expand All @@ -9,14 +7,13 @@
using WowPacketParser.Parsing;
using WowPacketParser.Store;
using WowPacketParser.Store.Objects;
using CoreParsers = WowPacketParser.Parsing.Parsers;
using MovementFlag = WowPacketParserModule.V6_0_2_19033.Enums.MovementFlag;

namespace WowPacketParserModule.V6_0_2_19033.Parsers
{
public static class MovementHandler
{
public static readonly IDictionary<ushort, bool> ActivePhases = new ConcurrentDictionary<ushort, bool>();

public static void ReadMovementStats(Packet packet, params object[] idx)
{
packet.ReadPackedGuid128("MoverGUID", idx);
Expand Down Expand Up @@ -157,7 +154,7 @@ public static void HandleZeroLengthPackets(Packet packet)
[Parser(Opcode.SMSG_LOGIN_VERIFY_WORLD)]
public static void HandleLoginVerifyWorld(Packet packet)
{
WowPacketParser.Parsing.Parsers.MovementHandler.CurrentMapId = (uint)packet.ReadInt32<MapId>("Map");
CoreParsers.MovementHandler.CurrentMapId = (uint)packet.ReadInt32<MapId>("Map");
packet.ReadVector4("Position");
packet.ReadUInt32("Reason");
}
Expand All @@ -166,11 +163,11 @@ public static void HandleLoginVerifyWorld(Packet packet)
[Parser(Opcode.SMSG_NEW_WORLD)]
public static void HandleNewWorld(Packet packet)
{
WowPacketParser.Parsing.Parsers.MovementHandler.CurrentMapId = (uint)packet.ReadInt32<MapId>("Map");
CoreParsers.MovementHandler.CurrentMapId = (uint)packet.ReadInt32<MapId>("Map");
packet.ReadVector4("Position");
packet.ReadUInt32("Reason");

packet.AddSniffData(StoreNameType.Map, (int)WowPacketParser.Parsing.Parsers.MovementHandler.CurrentMapId, "NEW_WORLD");
packet.AddSniffData(StoreNameType.Map, (int)CoreParsers.MovementHandler.CurrentMapId, "NEW_WORLD");
}

[Parser(Opcode.SMSG_LOGIN_SET_TIME_SPEED)]
Expand Down Expand Up @@ -360,7 +357,7 @@ public static void HandleOnMonsterMove(Packet packet)
[Parser(Opcode.SMSG_PHASE_SHIFT_CHANGE)]
public static void HandlePhaseShift(Packet packet)
{
ActivePhases.Clear();
CoreParsers.MovementHandler.ActivePhases.Clear();

packet.ReadPackedGuid128("Client");

Expand All @@ -372,12 +369,12 @@ public static void HandlePhaseShift(Packet packet)
{
var flags = packet.ReadUInt16("PhaseFlags", i);
var id = packet.ReadUInt16("Id", i);
ActivePhases.Add(id, true);
CoreParsers.MovementHandler.ActivePhases.Add(id, true);
}

if (Settings.UseDBC && DBC.Phases.Any())
{
foreach (var phaseGroup in DBC.GetPhaseGroups(ActivePhases.Keys))
foreach (var phaseGroup in DBC.GetPhaseGroups(CoreParsers.MovementHandler.ActivePhases.Keys))
packet.WriteLine($"PhaseGroup: { phaseGroup } Phases: { string.Join(" - ", DBC.Phases[phaseGroup]) }");
}

Expand Down Expand Up @@ -562,6 +559,7 @@ public static void HandleMovementIndex(Packet packet)
[Parser(Opcode.SMSG_MOVE_SET_FLIGHT_SPEED)]
[Parser(Opcode.SMSG_MOVE_SET_WALK_SPEED)]
[Parser(Opcode.SMSG_MOVE_SET_RUN_BACK_SPEED)]
[Parser(Opcode.SMSG_MOVE_SET_MOD_MOVEMENT_FORCE_MAGNITUDE)]
public static void HandleMovementIndexSpeed(Packet packet)
{
packet.ReadPackedGuid128("MoverGUID");
Expand Down Expand Up @@ -637,6 +635,7 @@ public static void HandleMovementAck(Packet packet)
[Parser(Opcode.CMSG_MOVE_FORCE_RUN_BACK_SPEED_CHANGE_ACK)]
[Parser(Opcode.CMSG_MOVE_FORCE_SWIM_SPEED_CHANGE_ACK)]
[Parser(Opcode.CMSG_MOVE_FORCE_WALK_SPEED_CHANGE_ACK)]
[Parser(Opcode.CMSG_MOVE_SET_MOD_MOVEMENT_FORCE_MAGNITUDE_ACK)]
public static void HandleMovementSpeedAck(Packet packet)
{
ReadMovementAck(packet);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ private static void ReadCreateObjectBlock(Packet packet, WowGuid guid, uint map,
obj.Area = CoreParsers.WorldStateHandler.CurrentAreaId;
obj.Zone = CoreParsers.WorldStateHandler.CurrentZoneId;
obj.PhaseMask = (uint)CoreParsers.MovementHandler.CurrentPhaseMask;
obj.Phases = new HashSet<ushort>(V6_0_2_19033.Parsers.MovementHandler.ActivePhases.Keys);
obj.Phases = new HashSet<ushort>(CoreParsers.MovementHandler.ActivePhases.Keys);
obj.DifficultyID = CoreParsers.MovementHandler.CurrentDifficultyID;

// If this is the second time we see the same object (same guid,
Expand Down
13 changes: 5 additions & 8 deletions WowPacketParserModule.V7_0_3_22248/Parsers/MovementHandler.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Linq;
using WowPacketParser.DBC;
using WowPacketParser.Enums;
using WowPacketParser.Misc;
using WowPacketParser.Parsing;
using WowPacketParserModule.V7_0_3_22248.Enums;
using CoreParsers = WowPacketParser.Parsing.Parsers;
using MovementFlag = WowPacketParserModule.V6_0_2_19033.Enums.MovementFlag;
using SplineFlag = WowPacketParserModule.V7_0_3_22248.Enums.SplineFlag;

namespace WowPacketParserModule.V7_0_3_22248.Parsers
{
public static class MovementHandler
{
public static readonly IDictionary<ushort, bool> ActivePhases = new ConcurrentDictionary<ushort, bool>();

public static void ReadMovementStats(Packet packet, params object[] idx)
{
packet.ReadPackedGuid128("MoverGUID", idx);
Expand Down Expand Up @@ -514,7 +511,7 @@ public static void HandleMoveSetVehicleRecIdAck(Packet packet)
[Parser(Opcode.SMSG_PHASE_SHIFT_CHANGE)]
public static void HandlePhaseShift(Packet packet)
{
ActivePhases.Clear();
CoreParsers.MovementHandler.ActivePhases.Clear();

packet.ReadPackedGuid128("Client");

Expand All @@ -526,12 +523,12 @@ public static void HandlePhaseShift(Packet packet)
{
var flags = packet.ReadUInt16("PhaseFlags", i);
var id = packet.ReadUInt16("Id", i);
ActivePhases.Add(id, true);
CoreParsers.MovementHandler.ActivePhases.Add(id, true);
}

if (DBC.Phases.Any())
{
foreach (var phaseGroup in DBC.GetPhaseGroups(ActivePhases.Keys))
foreach (var phaseGroup in DBC.GetPhaseGroups(CoreParsers.MovementHandler.ActivePhases.Keys))
packet.WriteLine($"PhaseGroup: { phaseGroup } Phases: { string.Join(" - ", DBC.Phases[phaseGroup]) }");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ private static void ReadCreateObjectBlock(Packet packet, WowGuid guid, uint map,
obj.Area = CoreParsers.WorldStateHandler.CurrentAreaId;
obj.Zone = CoreParsers.WorldStateHandler.CurrentZoneId;
obj.PhaseMask = (uint)CoreParsers.MovementHandler.CurrentPhaseMask;
obj.Phases = new HashSet<ushort>(MovementHandler.ActivePhases.Keys);
obj.Phases = new HashSet<ushort>(CoreParsers.MovementHandler.ActivePhases.Keys);
obj.DifficultyID = CoreParsers.MovementHandler.CurrentDifficultyID;

// If this is the second time we see the same object (same guid,
Expand Down
13 changes: 5 additions & 8 deletions WowPacketParserModule.V8_0_1_27101/Parsers/MovementHandler.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Linq;
using WowPacketParser.DBC;
using WowPacketParser.Enums;
using WowPacketParser.Misc;
using WowPacketParser.Parsing;
using CoreParsers = WowPacketParser.Parsing.Parsers;
using SplineFlag = WowPacketParserModule.V7_0_3_22248.Enums.SplineFlag;

namespace WowPacketParserModule.V8_0_1_27101.Parsers
{
public static class MovementHandler
{
public static readonly IDictionary<ushort, bool> ActivePhases = new ConcurrentDictionary<ushort, bool>();

public static void ReadMonsterSplineFilter(Packet packet, params object[] indexes)
{
var count = packet.ReadUInt32("MonsterSplineFilterKey", indexes);
Expand Down Expand Up @@ -162,7 +159,7 @@ public static void HandleOnMonsterMove(Packet packet)
[Parser(Opcode.SMSG_PHASE_SHIFT_CHANGE)]
public static void HandlePhaseShift(Packet packet)
{
ActivePhases.Clear();
CoreParsers.MovementHandler.ActivePhases.Clear();
packet.ReadPackedGuid128("Client");
// PhaseShiftData
packet.ReadInt32("PhaseShiftFlags");
Expand All @@ -172,11 +169,11 @@ public static void HandlePhaseShift(Packet packet)
{
var flags = packet.ReadUInt16("PhaseFlags", i);
var id = packet.ReadUInt16("Id", i);
ActivePhases.Add(id, true);
CoreParsers.MovementHandler.ActivePhases.Add(id, true);
}
if (DBC.Phases.Any())
{
foreach (var phaseGroup in DBC.GetPhaseGroups(ActivePhases.Keys))
foreach (var phaseGroup in DBC.GetPhaseGroups(CoreParsers.MovementHandler.ActivePhases.Keys))
packet.WriteLine($"PhaseGroup: { phaseGroup } Phases: { string.Join(" - ", DBC.Phases[phaseGroup]) }");
}
var visibleMapIDsCount = packet.ReadInt32("VisibleMapIDsCount") / 2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ private static void ReadCreateObjectBlock(Packet packet, WowGuid guid, uint map,
obj.Area = CoreParsers.WorldStateHandler.CurrentAreaId;
obj.Zone = CoreParsers.WorldStateHandler.CurrentZoneId;
obj.PhaseMask = (uint)CoreParsers.MovementHandler.CurrentPhaseMask;
obj.Phases = new HashSet<ushort>(MovementHandler.ActivePhases.Keys);
obj.Phases = new HashSet<ushort>(CoreParsers.MovementHandler.ActivePhases.Keys);
obj.DifficultyID = CoreParsers.MovementHandler.CurrentDifficultyID;

// If this is the second time we see the same object (same guid,
Expand Down

0 comments on commit b223e9f

Please sign in to comment.