Skip to content

Commit

Permalink
Fix parsing of flying catmullrom through parsing movement object content
Browse files Browse the repository at this point in the history
  • Loading branch information
killerwife committed Jun 29, 2024
1 parent 9372504 commit dcc70f0
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 7 deletions.
46 changes: 42 additions & 4 deletions WowPacketParserModule.V2_5_1_38707/Parsers/UpdateHandler.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
using WowPacketParser.Enums;
using System.Drawing;
using System.Linq;
using WowPacketParser.Enums;
using WowPacketParser.Misc;
using WowPacketParser.PacketStructures;
using WowPacketParser.Parsing;
using WowPacketParser.Proto;
using WowPacketParser.Store;
using WowPacketParser.Store.Objects;
using WowPacketParser.Store.Objects.Movement;
using WowPacketParser.Store.Objects.UpdateFields;
using CoreFields = WowPacketParser.Enums.Version;
using CoreParsers = WowPacketParser.Parsing.Parsers;
Expand Down Expand Up @@ -441,14 +444,35 @@ private static MovementInfo ReadMovementUpdateBlock(Packet packet, WowGuid guid,
{
packet.ResetBitReader();
packet.ReadInt32("ID", index);
packet.ReadVector3("Destination", index);

CreatureMovement movement = Storage.CreatureMovement.Where(p => p.Item1.GUID == guid).SingleOrDefault()?.Item1;
bool add = false;
if (movement == null)
{
movement = new CreatureMovement()
{
GUID = guid
};
add = true;
}

var destination = packet.ReadVector3("Destination", index);

var hasMovementSplineMove = packet.ReadBit("MovementSplineMove", index);
if (hasMovementSplineMove)
{
packet.ResetBitReader();

packet.ReadUInt32E<SplineFlag>("SplineFlags", index);
var splineFlag = packet.ReadUInt32E<SplineFlag>("SplineFlags", index);
CreatureMovementFlags moveType = CreatureMovementFlags.None;

if (splineFlag.HasFlag(SplineFlag.EnterCycle) || splineFlag.HasFlag(SplineFlag.Cyclic))
moveType = CreatureMovementFlags.ExactPathFlyingCyclic;
else if (splineFlag.HasFlag(SplineFlag.Flying))
moveType = CreatureMovementFlags.ExactPathFlying;
else if (splineFlag.HasFlag(SplineFlag.UncompressedPath))
moveType = CreatureMovementFlags.ExactPath;

packet.ReadInt32("Elapsed", index);
packet.ReadUInt32("Duration", index);
packet.ReadSingle("DurationModifier", index);
Expand Down Expand Up @@ -493,6 +517,7 @@ private static MovementInfo ReadMovementUpdateBlock(Packet packet, WowGuid guid,
break;
case 3:
orientation = packet.ReadSingle("FaceDirection", index);
moveType = CreatureMovementFlags.Invalid;
break;
default:
break;
Expand All @@ -504,13 +529,23 @@ private static MovementInfo ReadMovementUpdateBlock(Packet packet, WowGuid guid,
for (var i = 0; i < pointsCount; ++i)
{
var spot = packet.ReadVector3("Points", index, i);
if (moveType != CreatureMovementFlags.Invalid)
movement.Waypoints.Add(new CreatureMovementNode
{
Position = spot,
Point = splineFlag.HasFlag(SplineFlag.EnterCycle) || splineFlag.HasFlag(SplineFlag.Cyclic)
});
}

if (hasSpellEffectExtraData)
V8_0_1_27101.Parsers.MovementHandler.ReadMonsterSplineSpellEffectExtraData(packet, index);

if (hasJumpExtraData)
V8_0_1_27101.Parsers.MovementHandler.ReadMonsterSplineJumpExtraData(packet, index);
{
var jumpData = V8_0_1_27101.Parsers.MovementHandler.ReadMonsterSplineJumpExtraData(packet, index);
if (jumpData.StartTime > 0)
moveType = CreatureMovementFlags.ExactPathAndJump;
}

if (hasAnimationTierTransition)
{
Expand All @@ -531,6 +566,9 @@ private static MovementInfo ReadMovementUpdateBlock(Packet packet, WowGuid guid,
}
}
}

if (movement.Type != CreatureMovementFlags.Invalid && add)
Storage.CreatureMovement.Add(movement);
}
}

Expand Down
56 changes: 53 additions & 3 deletions WowPacketParserModule.V3_4_0_45166/Parsers/MovementHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
using WowPacketParser.PacketStructures;
using WowPacketParser.Parsing;
using WowPacketParser.Proto;
using WowPacketParser.SQL.Builders;
using WowPacketParser.Store;
using WowPacketParser.Store.Objects;
using WowPacketParser.Store.Objects.Movement;
using CoreParsers = WowPacketParser.Parsing.Parsers;
using MovementFlag = WowPacketParser.Enums.v4.MovementFlag;
using MovementFlag2 = WowPacketParser.Enums.v4.MovementFlag2;
Expand Down Expand Up @@ -55,10 +57,21 @@ public static SplineJump ReadMonsterSplineJumpExtraData(Packet packet, params ob
return jump;
}

public static void ReadMovementSpline(Packet packet, Vector3 pos, params object[] indexes)
public static void ReadMovementSpline(Packet packet, Vector3 pos, CreatureMovement movement, params object[] indexes)
{
PacketMonsterMove monsterMove = packet.Holder.MonsterMove;
monsterMove.Flags = packet.ReadUInt32E<SplineFlag>("Flags", indexes).ToUniversal();
var splineFlag = packet.ReadUInt32E<SplineFlag>("Flags", indexes);
monsterMove.Flags = splineFlag.ToUniversal();

CreatureMovementFlags moveType = CreatureMovementFlags.None;

if (splineFlag.HasFlag(SplineFlag.EnterCicle) || splineFlag.HasFlag(SplineFlag.Cyclic))
moveType = CreatureMovementFlags.ExactPathFlyingCyclic;
else if (splineFlag.HasFlag(SplineFlag.Flying))
moveType = CreatureMovementFlags.ExactPathFlying;
else if (splineFlag.HasFlag(SplineFlag.UncompressedPath))
moveType = CreatureMovementFlags.ExactPath;

if (ClientVersion.RemovedInVersion(ClientType.Shadowlands))
{
packet.ReadByte("AnimTier", indexes);
Expand Down Expand Up @@ -109,6 +122,7 @@ public static void ReadMovementSpline(Packet packet, Vector3 pos, params object[
SplineLookTarget lookTarget = monsterMove.LookTarget = new();
lookTarget.Orientation = packet.ReadSingle("FaceDirection", indexes);
lookTarget.Target = packet.ReadPackedGuid128("FacingGUID", indexes);
moveType = CreatureMovementFlags.Invalid;
break;
case SplineFacingType.Angle:
monsterMove.LookOrientation = packet.ReadSingle("FaceDirection", indexes);
Expand Down Expand Up @@ -148,7 +162,11 @@ public static void ReadMovementSpline(Packet packet, Vector3 pos, params object[
ReadMonsterSplineSpellEffectExtraData(packet, indexes, "MonsterSplineSpellEffectExtra");

if (hasJumpExtraData)
{
monsterMove.Jump = ReadMonsterSplineJumpExtraData(packet, indexes, "MonsterSplineJumpExtraData");
if (monsterMove.Jump.StartTime > 0)
moveType = CreatureMovementFlags.ExactPathAndJump;
}

if (hasAnimTier)
{
Expand Down Expand Up @@ -185,19 +203,48 @@ public static void ReadMovementSpline(Packet packet, Vector3 pos, params object[
Y = mid.Y - waypoints[i].Y,
Z = mid.Z - waypoints[i].Z
};
if (moveType != CreatureMovementFlags.Invalid)
movement.Waypoints.Add(new CreatureMovementNode
{
Position = vec,
Point = false
});
monsterMove.PackedPoints.Add(vec);
packet.AddValue("WayPoints", vec, indexes, i);
}

if (moveType != CreatureMovementFlags.Invalid)
foreach (var point in monsterMove.Points)
movement.Waypoints.Add(new CreatureMovementNode
{
Position = point,
Point = true
});

float moveTimeInSec = (float)monsterMove.MoveTime / 1000;
float speedXY = (float)overallDist / moveTimeInSec;
packet.AddValue("CalculatedSpeedXY", speedXY, indexes);
if (moveType != CreatureMovementFlags.Invalid)
movement.Type |= moveType;
}

public static void ReadMovementMonsterSpline(Packet packet, Vector3 pos, params object[] indexes)
{
PacketMonsterMove monsterMove = packet.Holder.MonsterMove;
monsterMove.Id = packet.ReadUInt32("Id", indexes);

var guid = new WowGuid128(monsterMove.Mover.Guid128.Low, monsterMove.Mover.Guid128.High);
CreatureMovement movement = Storage.CreatureMovement.Where(p => p.Item1.GUID == guid).SingleOrDefault()?.Item1;
bool add = false;
if (movement == null)
{
movement = new CreatureMovement()
{
GUID = guid
};
add = true;
}

if (ClientVersion.RemovedInVersion(ClientBranch.Classic, ClientVersionBuild.V1_15_0_52302) || ClientVersion.Branch != ClientBranch.Classic)
monsterMove.Destination = packet.ReadVector3("Destination", indexes);

Expand All @@ -206,7 +253,10 @@ public static void ReadMovementMonsterSpline(Packet packet, Vector3 pos, params
packet.ReadBit("CrzTeleport", indexes);
packet.ReadBits("StopDistanceTolerance", 3, indexes);

ReadMovementSpline(packet, pos, indexes, "MovementSpline");
ReadMovementSpline(packet, pos, movement, indexes, "MovementSpline");

if (movement.Type != CreatureMovementFlags.Invalid && add)
Storage.CreatureMovement.Add(movement);
}

[Parser(Opcode.SMSG_LOGIN_SET_TIME_SPEED)]
Expand Down

0 comments on commit dcc70f0

Please sign in to comment.