public static StreamHandler ReadHasByte(this StreamHandler reader, out byte value) { if (reader == null) { throw new ArgumentNullException("reader"); } value = reader.UnalignedReadBit() ? (byte)1 : (byte)0; return(reader); }
protected void ReadByteMask(StreamHandler reader, ref byte b) { b = reader.UnalignedReadBit() ? (byte)1 : (byte)0; }
protected virtual void ReadElement(StreamHandler reader, MovementStatusElements element, MovementStatus status, byte[] guid, byte[] tguid) { if (element >= MovementStatusElements.GuidByte0 && element <= MovementStatusElements.GuidByte7) { ReadByteMask(reader, ref guid[element - MovementStatusElements.GuidByte0]); return; } if (element >= MovementStatusElements.TransportGuidByte0 && element <= MovementStatusElements.TransportGuidByte7) { if (status.HaveTransportData) ReadByteMask(reader, ref tguid[element - MovementStatusElements.TransportGuidByte0]); return; } if (element >= MovementStatusElements.GuidByte0_2 && element <= MovementStatusElements.GuidByte7_2) { ReadByteSeq(reader, ref guid[element - MovementStatusElements.GuidByte0_2]); return; } if (element >= MovementStatusElements.TransportGuidByte0_2 && element <= MovementStatusElements.TransportGuidByte7_2) { if (status.HaveTransportData) ReadByteSeq(reader, ref tguid[element - MovementStatusElements.TransportGuidByte0_2]); return; } switch (element) { case MovementStatusElements.Flags: status.Flags = (MovementFlags)(!reader.UnalignedReadBit() ? 1 : 0); break; case MovementStatusElements.Flags_2: if (status.Flags != 0) status.Flags = (MovementFlags)reader.UnalignedReadInt(30); break; case MovementStatusElements.Flags2: status.Flags2 = (MovementFlags2)(!reader.UnalignedReadBit() ? 1 : 0); break; case MovementStatusElements.Flags2_2: if (status.Flags2 != 0) status.Flags2 = (MovementFlags2)reader.UnalignedReadSmallInt(12); break; case MovementStatusElements.Timestamp: status.TimeStamp = !reader.UnalignedReadBit() ? 1U : 0U; break; case MovementStatusElements.Timestamp_2: if (status.TimeStamp != 0) status.TimeStamp = reader.ReadUInt32(); break; case MovementStatusElements.HaveFallData: status.HaveFallData = reader.UnalignedReadBit(); break; case MovementStatusElements.HaveFallDirection: if (status.HaveFallData) status.HaveFallDirection = reader.UnalignedReadBit(); break; case MovementStatusElements.HaveTransportData: status.HaveTransportData = reader.UnalignedReadBit(); break; case MovementStatusElements.TransportHaveTime2: if (status.HaveTransportData) status.HaveTransportTime2 = reader.UnalignedReadBit(); break; case MovementStatusElements.TransportHaveTime3: if (status.HaveTransportData) status.HaveTransportTime3 = reader.UnalignedReadBit(); break; case MovementStatusElements.HaveSpline: status.HaveSpline = reader.UnalignedReadBit(); break; case MovementStatusElements.HaveSpline2: status.HaveSpline2 = reader.UnalignedReadBit(); break; case MovementStatusElements.PositionX: status.Position.X = reader.ReadSingle(); break; case MovementStatusElements.PositionY: status.Position.Y = reader.ReadSingle(); break; case MovementStatusElements.PositionZ: status.Position.Z = reader.ReadSingle(); break; case MovementStatusElements.PositionO: status.Orientation = !reader.UnalignedReadBit() ? 1.0f : 0.0f; break; case MovementStatusElements.PositionO_2: if (status.Orientation != 0.0f) status.Orientation = reader.ReadSingle(); break; case MovementStatusElements.Pitch: status.HavePitch = !reader.UnalignedReadBit(); break; case MovementStatusElements.Pitch_2: if (status.HavePitch) status.Pitch = reader.ReadSingle(); break; case MovementStatusElements.FallTime: if (status.HaveFallData) status.FallTime = reader.ReadUInt32(); break; case MovementStatusElements.SplineElev: status.HaveSplineElevation = !reader.UnalignedReadBit(); break; case MovementStatusElements.SplineElev_2: if (status.HaveSplineElevation) status.SplineElevation = reader.ReadSingle(); break; case MovementStatusElements.FallHorizontalSpeed: if (status.HaveFallDirection) status.FallHorizontalSpeed = reader.ReadSingle(); break; case MovementStatusElements.FallVerticalSpeed: if (status.HaveFallData) status.FallVerticalSpeed = reader.ReadSingle(); break; case MovementStatusElements.FallCosAngle: if (status.HaveFallDirection) status.FallCosAngle = reader.ReadSingle(); break; case MovementStatusElements.FallSinAngle: if (status.HaveFallDirection) status.FallSinAngle = reader.ReadSingle(); break; case MovementStatusElements.TransportSeat: if (status.HaveTransportData) status.TransportSeat = reader.ReadSByte(); break; case MovementStatusElements.TransportPositionO: if (status.HaveTransportData) status.TransportFacing = reader.ReadSingle(); break; case MovementStatusElements.TransportPositionX: if (status.HaveTransportData) status.TransportPosition.X = reader.ReadSingle(); break; case MovementStatusElements.TransportPositionY: if (status.HaveTransportData) status.TransportPosition.Y = reader.ReadSingle(); break; case MovementStatusElements.TransportPositionZ: if (status.HaveTransportData) status.TransportPosition.Z = reader.ReadSingle(); break; case MovementStatusElements.TransportTime: if (status.HaveTransportData) status.TransportTime = reader.ReadUInt32(); break; case MovementStatusElements.TransportTime2: if (status.HaveTransportTime2) status.TransportTime2 = reader.ReadUInt32(); break; case MovementStatusElements.TransportTime3: if (status.HaveTransportTime3) status.TransportTime3 = reader.ReadUInt32(); break; default: throw new InvalidOperationException("Unknown element: " + element); } }
public unsafe MovementInfo(StreamHandler Reader) { var guid = new WowGuid(); this.HaveAttackingTarget = Reader.UnalignedReadBit(); guid.Bytes[2] = Reader.UnalignedReadTinyInt(1); this.HaveVehicleData = Reader.UnalignedReadBit(); guid.Bytes[1] = Reader.UnalignedReadTinyInt(1); guid.Bytes[4] = Reader.UnalignedReadTinyInt(1); guid.Bytes[3] = Reader.UnalignedReadTinyInt(1); this.HaveTransportTime = Reader.UnalignedReadBit(); this.HaveGameObjectPosition = Reader.UnalignedReadBit(); bool field_1C8 = Reader.UnalignedReadBit(); bool field_1AC = Reader.UnalignedReadBit(); this.HaveGameObjectRotation = Reader.UnalignedReadBit(); this.Living = Reader.UnalignedReadBit(); this.HavePosition = Reader.UnalignedReadBit(); var arrCounter = Reader.UnalignedReadInt(24); guid.Bytes[0] = Reader.UnalignedReadTinyInt(1); bool havePFlags = false; WowGuid p_guid; uint splinePoints = 0; bool havePFlags2 = false; bool haveOrientation = false; if (this.Living) { this.HaveTransportData = Reader.UnalignedReadBit(); if (this.HaveTransportData) { fixed (byte* bytes = this.TransportGuid.Bytes) { bytes[2] = Reader.UnalignedReadTinyInt(1); bytes[7] = Reader.UnalignedReadTinyInt(1); bytes[5] = Reader.UnalignedReadTinyInt(1); this.HaveTransportTime3 = Reader.UnalignedReadBit(); bytes[3] = Reader.UnalignedReadTinyInt(1); bytes[0] = Reader.UnalignedReadTinyInt(1); bytes[4] = Reader.UnalignedReadTinyInt(1); bytes[1] = Reader.UnalignedReadTinyInt(1); this.HaveTransportTime2 = Reader.UnalignedReadBit(); bytes[6] = Reader.UnalignedReadTinyInt(1); } } this.HaveSpline2 = Reader.UnalignedReadBit(); p_guid.Bytes[7] = Reader.UnalignedReadTinyInt(1); p_guid.Bytes[6] = Reader.UnalignedReadTinyInt(1); p_guid.Bytes[5] = Reader.UnalignedReadTinyInt(1); p_guid.Bytes[2] = Reader.UnalignedReadTinyInt(1); p_guid.Bytes[4] = Reader.UnalignedReadTinyInt(1); havePFlags = !Reader.UnalignedReadBit(); p_guid.Bytes[1] = Reader.UnalignedReadTinyInt(1); this.SelfTarget = Reader.UnalignedReadBit(); this.TimeStamp = !Reader.UnalignedReadBit() ? 1U : 0U; havePFlags2 = !Reader.UnalignedReadBit(); if (this.HaveSpline2) { this.HaveSpline = Reader.UnalignedReadBit(); if (this.HaveSpline) { this.Spline.HaveDurationMultiplier = Reader.UnalignedReadBit(); this.Spline.Flags = (SplineFlags)Reader.UnalignedReadInt(25); this.Spline.SplineMode = (SplineMode)Reader.UnalignedReadTinyInt(2); this.Spline.HaveUnknown1 = Reader.UnalignedReadBit(); splinePoints = Reader.UnalignedReadInt(22); var type = Reader.UnalignedReadTinyInt(2); switch (type) { case 0: this.Spline.SplineType = SplineType.FacingSpot; break; case 1: this.Spline.SplineType = SplineType.Normal; break; case 2: this.Spline.SplineType = SplineType.FacingTarget; break; case 3: this.Spline.SplineType = SplineType.FacingAngle; break; } if (this.Spline.SplineType == SplineType.FacingTarget) { fixed (byte* bytes = this.Spline.FacingTarget.Bytes) { bytes[7] = Reader.UnalignedReadTinyInt(1); bytes[3] = Reader.UnalignedReadTinyInt(1); bytes[4] = Reader.UnalignedReadTinyInt(1); bytes[2] = Reader.UnalignedReadTinyInt(1); bytes[1] = Reader.UnalignedReadTinyInt(1); bytes[6] = Reader.UnalignedReadTinyInt(1); bytes[0] = Reader.UnalignedReadTinyInt(1); bytes[5] = Reader.UnalignedReadTinyInt(1); } } } } p_guid.Bytes[3] = Reader.UnalignedReadTinyInt(1); if (havePFlags) this.Flags = (MovementFlags)Reader.UnalignedReadInt(30); this.HavePitch = !Reader.UnalignedReadBit(); this.HaveFallData = Reader.UnalignedReadBit(); if (havePFlags2) this.Flags2 = (MovementFlags2)Reader.UnalignedReadSmallInt(12); p_guid.Bytes[0] = Reader.UnalignedReadTinyInt(1); haveOrientation = !Reader.UnalignedReadBit(); if (this.HaveFallData) this.HaveFallDirection = Reader.UnalignedReadBit(); this.HaveSplineElevation = !Reader.UnalignedReadBit(); } if (this.HaveGameObjectPosition) { fixed (byte* bytes = this.TransportGuid.Bytes) { bytes[1] = Reader.UnalignedReadTinyInt(1); this.HaveTransportTime3 = Reader.UnalignedReadBit(); bytes[3] = Reader.UnalignedReadTinyInt(1); bytes[2] = Reader.UnalignedReadTinyInt(1); bytes[6] = Reader.UnalignedReadTinyInt(1); bytes[5] = Reader.UnalignedReadTinyInt(1); bytes[0] = Reader.UnalignedReadTinyInt(1); bytes[4] = Reader.UnalignedReadTinyInt(1); this.HaveTransportTime2 = Reader.UnalignedReadBit(); bytes[7] = Reader.UnalignedReadTinyInt(1); } } ushort field_1B2 = 0; ushort field_1AE = 0; ushort field_1B0 = 0; if (field_1AC) { field_1B2 = (ushort)(!Reader.UnalignedReadBit() ? 1 : 0); field_1AE = (ushort)(!Reader.UnalignedReadBit() ? 1 : 0); field_1B0 = (ushort)(!Reader.UnalignedReadBit() ? 1 : 0); } if (this.HaveAttackingTarget) { fixed (byte* bytes = this.AttackingTarget.Bytes) { bytes[3] = Reader.UnalignedReadTinyInt(1); bytes[4] = Reader.UnalignedReadTinyInt(1); bytes[6] = Reader.UnalignedReadTinyInt(1); bytes[0] = Reader.UnalignedReadTinyInt(1); bytes[1] = Reader.UnalignedReadTinyInt(1); bytes[7] = Reader.UnalignedReadTinyInt(1); bytes[5] = Reader.UnalignedReadTinyInt(1); bytes[2] = Reader.UnalignedReadTinyInt(1); } } this.UnkUInt32 = new uint[arrCounter]; for (uint i = 0; i < arrCounter; ++i) { this.UnkUInt32[i] = Reader.ReadUInt32(); } if (this.HavePosition) { Reader .ReadSingle(out this.Position.Z) .ReadSingle(out this.Orientation) .ReadSingle(out this.Position.X) .ReadSingle(out this.Position.Y); } if (this.HaveVehicleData) { Reader .ReadUInt32(out this.VehicleId) .ReadSingle(out this.VehicleAimAdjustement); } if (this.HaveGameObjectPosition) { fixed (byte* bytes = this.TransportGuid.Bytes) { Reader .ReadXorByte(ref bytes[1]) .ReadXorByte(ref bytes[4]) .ReadSingle(out this.TransportPosition.Z); if (this.HaveTransportTime3) this.TransportTime3 = Reader.ReadUInt32(); this.TransportTime = Reader.ReadUInt32(); Reader .ReadXorByte(ref bytes[5]) .ReadXorByte(ref bytes[6]) .ReadSingle(out this.TransportPosition.X) .ReadXorByte(ref bytes[2]); if (this.HaveTransportTime2) this.TransportTime2 = Reader.ReadUInt32(); Reader .ReadSByte(out this.TransportSeat) .ReadXorByte(ref bytes[3]) .ReadSingle(out this.TransportPosition.Y) .ReadSingle(out this.TransportFacing) .ReadXorByte(ref bytes[7]) .ReadXorByte(ref bytes[0]); } } if (this.Living) { if (this.HaveSpline2) { if (this.HaveSpline) { var points = this.Spline.Points; points.Capacity = (int)splinePoints; for (int i = 0; i < splinePoints; i++) points.Add(new Vector3() { Y = Reader.ReadSingle(), X = Reader.ReadSingle(), Z = Reader.ReadSingle() }); if (this.Spline.HaveDurationMultiplier) { this.Spline.DurationMultiplier = Reader.ReadSingle(); } this.Spline.UnknownFloat2 = Reader.ReadSingle(); if (this.Spline.SplineType == SplineType.FacingTarget) { fixed (byte* bytes = this.Spline.FacingTarget.Bytes) { Reader .ReadXorByte(ref bytes[3]) .ReadXorByte(ref bytes[4]) .ReadXorByte(ref bytes[5]) .ReadXorByte(ref bytes[7]) .ReadXorByte(ref bytes[2]) .ReadXorByte(ref bytes[0]) .ReadXorByte(ref bytes[6]) .ReadXorByte(ref bytes[1]); } } if (this.Spline.HaveUnknown1) { this.Spline.Unknown1 = Reader.ReadUInt32(); } this.Spline.UnknownFloat3 = Reader.ReadSingle(); this.Spline.Unknown2 = Reader.ReadUInt32(); if (this.Spline.SplineType == SplineType.FacingSpot) { Reader .ReadSingle(out this.Spline.FacingSpot.Y) .ReadSingle(out this.Spline.FacingSpot.Z) .ReadSingle(out this.Spline.FacingSpot.X); } this.Spline.CurrentTime = Reader.ReadUInt32(); if (this.Spline.SplineType == SplineType.FacingAngle) this.Spline.FacingAngle = Reader.ReadSingle(); } Reader .ReadSingle(out this.Spline.EndPoint.Z) .ReadSingle(out this.Spline.EndPoint.Y) .ReadUInt32(out this.Spline.FullTime) .ReadSingle(out this.Spline.EndPoint.X); } this.Speeds[8] = Reader.ReadSingle(); // Transport Data if (this.HaveTransportData) { fixed (byte* bytes = this.TransportGuid.Bytes) { Reader .ReadXorByte(ref bytes[4]) .ReadSingle(out this.TransportPosition.Z) .ReadXorByte(ref bytes[7]) .ReadXorByte(ref bytes[5]) .ReadXorByte(ref bytes[1]) .ReadSingle(out this.TransportPosition.X) .ReadXorByte(ref bytes[3]) .ReadXorByte(ref bytes[6]); if (this.HaveTransportTime3) this.TransportTime3 = Reader.ReadUInt32(); Reader .ReadSingle(out this.TransportPosition.Y) .ReadSByte(out this.TransportSeat) .ReadSingle(out this.TransportFacing); if (this.HaveTransportTime2) this.TransportTime2 = Reader.ReadUInt32(); Reader .ReadXorByte(ref bytes[2]) .ReadUInt32(out this.TransportTime) .ReadXorByte(ref bytes[0]); } } Reader .ReadSingle(out this.Speeds[7]) .ReadSingle(out this.Position.X); if (this.HavePitch) Reader.ReadSingle(out this.Pitch); // Fall Data if (this.HaveFallData) { Reader.ReadUInt32(out this.FallTime); if (this.HaveFallDirection) { Reader .ReadSingle(out this.FallSinAngle) .ReadSingle(out this.FallHorizontalSpeed) .ReadSingle(out this.FallCosAngle); } Reader.ReadSingle(out this.FallVerticalSpeed); } Reader .ReadXorByte(ref p_guid.Bytes[7]) .ReadSingle(out this.Speeds[4]) .ReadXorByte(ref p_guid.Bytes[0]) .ReadXorByte(ref p_guid.Bytes[5]); if (this.TimeStamp != 0) this.TimeStamp = Reader.ReadUInt32(); Reader .ReadSingle(out this.Position.Z) .ReadSingle(out this.Speeds[6]) .ReadXorByte(ref p_guid.Bytes[1]) .ReadSingle(out this.Speeds[2]) .ReadSingle(out this.Speeds[5]) .ReadSingle(out this.Speeds[3]) .ReadSingle(out this.Speeds[0]) .ReadXorByte(ref p_guid.Bytes[3]) .ReadXorByte(ref p_guid.Bytes[4]) .ReadXorByte(ref p_guid.Bytes[2]) .ReadXorByte(ref p_guid.Bytes[6]); if (this.HaveSplineElevation) this.SplineElevation = Reader.ReadSingle(); this.Position.Y = Reader.ReadSingle(); if (haveOrientation) this.Orientation = Reader.ReadSingle(); this.Speeds[1] = Reader.ReadSingle(); } if (field_1C8) { Console.WriteLine("Error: 16 floats @ 1CC detected !!!"); Reader.ReadBytes(16 * 4); // 16 floats starting at 1CC var field_20C = Reader.ReadByte(); } // transport time if (this.HaveTransportTime) Reader.ReadUInt32(out this.TransportTime); // unk2 ? if (field_1AC) { Console.WriteLine("Error: 3 shorts @ 1AE detected !!!"); if (field_1B0 != 0) field_1B0 = Reader.ReadUInt16(); if (field_1B2 != 0) field_1B2 = Reader.ReadUInt16(); if (field_1AE != 0) field_1AE = Reader.ReadUInt16(); } // go rotation? if (this.HaveGameObjectRotation) this.GameObjectRotation = Reader.ReadUInt64().UnpackQuaternion(); // target guid? if (this.HaveAttackingTarget) { fixed (byte* bytes = this.AttackingTarget.Bytes) { Reader .ReadXorByte(ref bytes[3]) .ReadXorByte(ref bytes[5]) .ReadXorByte(ref bytes[0]) .ReadXorByte(ref bytes[7]) .ReadXorByte(ref bytes[2]) .ReadXorByte(ref bytes[4]) .ReadXorByte(ref bytes[6]) .ReadXorByte(ref bytes[1]); } } this.Guid = guid; }
public sealed override void Read(StreamHandler reader) { var seq_b = ByteSequence; var seq_m = MaskSequence; var b_xor = ByteXorValue; int size = seq_m.Count(x => x >= 0); if (size != seq_m.Length && this.IsMaskSequenceSwapped) { throw new InvalidOperationException("Cannot have elements in swapped MaskSequence."); } CheckSequences(seq_b, seq_m); if (this.IsMaskSequenceSwapped) { var seq_m_copy = new int[seq_m.Length]; for (int i = 0; i < seq_m.Length;) { var t = i; for (int j = t + 8 - 1; j >= t; --j, ++i) { seq_m_copy[j] = seq_m[i]; } } seq_m = seq_m_copy; } //byte[] data = new byte[size]; //var src = new BitArray(reader.ReadBytes(size / 8)); //var dst = new BitArray(size); //for (int i = 0; i < size; ++i) // dst[seq_m[i]] = src[i]; //for (int i = 0; i < seq_b.Length; ++i) //{ // var el = seq_b[i]; // if (el < 0) // ElementRead(reader, el); // else if (dst[el]) // data[el] = (byte)(reader.ReadByte() ^ b_xor); //} byte[] data = new byte[size]; var dst = new BitArray(size); for (int i = 0; i < seq_m.Length; ++i) { var el = seq_m[i]; if (el < 0) { ElementRead(reader, el); } else { dst[el] = reader.UnalignedReadBit(); } } for (int i = 0; i < seq_b.Length; ++i) { var el = seq_b[i]; if (el < 0) { ElementRead(reader, el); } else if (dst[el]) { data[el] = (byte)(reader.ReadByte() ^ b_xor); } } PackedRead(data); }
public sealed override void Read(StreamHandler reader) { var seq_b = ByteSequence; var seq_m = MaskSequence; var b_xor = ByteXorValue; int size = seq_m.Count(x => x >= 0); if (size != seq_m.Length && this.IsMaskSequenceSwapped) throw new InvalidOperationException("Cannot have elements in swapped MaskSequence."); CheckSequences(seq_b, seq_m); if (this.IsMaskSequenceSwapped) { var seq_m_copy = new int[seq_m.Length]; for (int i = 0; i < seq_m.Length; ) { var t = i; for (int j = t + 8 - 1; j >= t; --j, ++i) seq_m_copy[j] = seq_m[i]; } seq_m = seq_m_copy; } //byte[] data = new byte[size]; //var src = new BitArray(reader.ReadBytes(size / 8)); //var dst = new BitArray(size); //for (int i = 0; i < size; ++i) // dst[seq_m[i]] = src[i]; //for (int i = 0; i < seq_b.Length; ++i) //{ // var el = seq_b[i]; // if (el < 0) // ElementRead(reader, el); // else if (dst[el]) // data[el] = (byte)(reader.ReadByte() ^ b_xor); //} byte[] data = new byte[size]; var dst = new BitArray(size); for (int i = 0; i < seq_m.Length; ++i) { var el = seq_m[i]; if (el < 0) ElementRead(reader, el); else dst[el] = reader.UnalignedReadBit(); } for (int i = 0; i < seq_b.Length; ++i) { var el = seq_b[i]; if (el < 0) ElementRead(reader, el); else if (dst[el]) data[el] = (byte)(reader.ReadByte() ^ b_xor); } PackedRead(data); }
public unsafe MovementInfo(StreamHandler Reader) { var guid = new WowGuid(); this.HaveAttackingTarget = Reader.UnalignedReadBit(); guid.Bytes[2] = Reader.UnalignedReadTinyInt(1); this.HaveVehicleData = Reader.UnalignedReadBit(); guid.Bytes[1] = Reader.UnalignedReadTinyInt(1); guid.Bytes[4] = Reader.UnalignedReadTinyInt(1); guid.Bytes[3] = Reader.UnalignedReadTinyInt(1); this.HaveTransportTime = Reader.UnalignedReadBit(); this.HaveGameObjectPosition = Reader.UnalignedReadBit(); bool field_1C8 = Reader.UnalignedReadBit(); bool field_1AC = Reader.UnalignedReadBit(); this.HaveGameObjectRotation = Reader.UnalignedReadBit(); this.Living = Reader.UnalignedReadBit(); this.HavePosition = Reader.UnalignedReadBit(); var arrCounter = Reader.UnalignedReadInt(24); guid.Bytes[0] = Reader.UnalignedReadTinyInt(1); bool havePFlags = false; WowGuid p_guid; uint splinePoints = 0; bool havePFlags2 = false; bool haveOrientation = false; if (this.Living) { this.HaveTransportData = Reader.UnalignedReadBit(); if (this.HaveTransportData) { fixed(byte *bytes = this.TransportGuid.Bytes) { bytes[2] = Reader.UnalignedReadTinyInt(1); bytes[7] = Reader.UnalignedReadTinyInt(1); bytes[5] = Reader.UnalignedReadTinyInt(1); this.HaveTransportTime3 = Reader.UnalignedReadBit(); bytes[3] = Reader.UnalignedReadTinyInt(1); bytes[0] = Reader.UnalignedReadTinyInt(1); bytes[4] = Reader.UnalignedReadTinyInt(1); bytes[1] = Reader.UnalignedReadTinyInt(1); this.HaveTransportTime2 = Reader.UnalignedReadBit(); bytes[6] = Reader.UnalignedReadTinyInt(1); } } this.HaveSpline2 = Reader.UnalignedReadBit(); p_guid.Bytes[7] = Reader.UnalignedReadTinyInt(1); p_guid.Bytes[6] = Reader.UnalignedReadTinyInt(1); p_guid.Bytes[5] = Reader.UnalignedReadTinyInt(1); p_guid.Bytes[2] = Reader.UnalignedReadTinyInt(1); p_guid.Bytes[4] = Reader.UnalignedReadTinyInt(1); havePFlags = !Reader.UnalignedReadBit(); p_guid.Bytes[1] = Reader.UnalignedReadTinyInt(1); this.SelfTarget = Reader.UnalignedReadBit(); this.TimeStamp = !Reader.UnalignedReadBit() ? 1U : 0U; havePFlags2 = !Reader.UnalignedReadBit(); if (this.HaveSpline2) { this.HaveSpline = Reader.UnalignedReadBit(); if (this.HaveSpline) { this.Spline.HaveDurationMultiplier = Reader.UnalignedReadBit(); this.Spline.Flags = (SplineFlags)Reader.UnalignedReadInt(25); this.Spline.SplineMode = (SplineMode)Reader.UnalignedReadTinyInt(2); this.Spline.HaveUnknown1 = Reader.UnalignedReadBit(); splinePoints = Reader.UnalignedReadInt(22); var type = Reader.UnalignedReadTinyInt(2); switch (type) { case 0: this.Spline.SplineType = SplineType.FacingSpot; break; case 1: this.Spline.SplineType = SplineType.Normal; break; case 2: this.Spline.SplineType = SplineType.FacingTarget; break; case 3: this.Spline.SplineType = SplineType.FacingAngle; break; } if (this.Spline.SplineType == SplineType.FacingTarget) { fixed(byte *bytes = this.Spline.FacingTarget.Bytes) { bytes[7] = Reader.UnalignedReadTinyInt(1); bytes[3] = Reader.UnalignedReadTinyInt(1); bytes[4] = Reader.UnalignedReadTinyInt(1); bytes[2] = Reader.UnalignedReadTinyInt(1); bytes[1] = Reader.UnalignedReadTinyInt(1); bytes[6] = Reader.UnalignedReadTinyInt(1); bytes[0] = Reader.UnalignedReadTinyInt(1); bytes[5] = Reader.UnalignedReadTinyInt(1); } } } } p_guid.Bytes[3] = Reader.UnalignedReadTinyInt(1); if (havePFlags) { this.Flags = (MovementFlags)Reader.UnalignedReadInt(30); } this.HavePitch = !Reader.UnalignedReadBit(); this.HaveFallData = Reader.UnalignedReadBit(); if (havePFlags2) { this.Flags2 = (MovementFlags2)Reader.UnalignedReadSmallInt(12); } p_guid.Bytes[0] = Reader.UnalignedReadTinyInt(1); haveOrientation = !Reader.UnalignedReadBit(); if (this.HaveFallData) { this.HaveFallDirection = Reader.UnalignedReadBit(); } this.HaveSplineElevation = !Reader.UnalignedReadBit(); } if (this.HaveGameObjectPosition) { fixed(byte *bytes = this.TransportGuid.Bytes) { bytes[1] = Reader.UnalignedReadTinyInt(1); this.HaveTransportTime3 = Reader.UnalignedReadBit(); bytes[3] = Reader.UnalignedReadTinyInt(1); bytes[2] = Reader.UnalignedReadTinyInt(1); bytes[6] = Reader.UnalignedReadTinyInt(1); bytes[5] = Reader.UnalignedReadTinyInt(1); bytes[0] = Reader.UnalignedReadTinyInt(1); bytes[4] = Reader.UnalignedReadTinyInt(1); this.HaveTransportTime2 = Reader.UnalignedReadBit(); bytes[7] = Reader.UnalignedReadTinyInt(1); } } ushort field_1B2 = 0; ushort field_1AE = 0; ushort field_1B0 = 0; if (field_1AC) { field_1B2 = (ushort)(!Reader.UnalignedReadBit() ? 1 : 0); field_1AE = (ushort)(!Reader.UnalignedReadBit() ? 1 : 0); field_1B0 = (ushort)(!Reader.UnalignedReadBit() ? 1 : 0); } if (this.HaveAttackingTarget) { fixed(byte *bytes = this.AttackingTarget.Bytes) { bytes[3] = Reader.UnalignedReadTinyInt(1); bytes[4] = Reader.UnalignedReadTinyInt(1); bytes[6] = Reader.UnalignedReadTinyInt(1); bytes[0] = Reader.UnalignedReadTinyInt(1); bytes[1] = Reader.UnalignedReadTinyInt(1); bytes[7] = Reader.UnalignedReadTinyInt(1); bytes[5] = Reader.UnalignedReadTinyInt(1); bytes[2] = Reader.UnalignedReadTinyInt(1); } } this.UnkUInt32 = new uint[arrCounter]; for (uint i = 0; i < arrCounter; ++i) { this.UnkUInt32[i] = Reader.ReadUInt32(); } if (this.HavePosition) { Reader .ReadSingle(out this.Position.Z) .ReadSingle(out this.Orientation) .ReadSingle(out this.Position.X) .ReadSingle(out this.Position.Y); } if (this.HaveVehicleData) { Reader .ReadUInt32(out this.VehicleId) .ReadSingle(out this.VehicleAimAdjustement); } if (this.HaveGameObjectPosition) { fixed(byte *bytes = this.TransportGuid.Bytes) { Reader .ReadXorByte(ref bytes[1]) .ReadXorByte(ref bytes[4]) .ReadSingle(out this.TransportPosition.Z); if (this.HaveTransportTime3) { this.TransportTime3 = Reader.ReadUInt32(); } this.TransportTime = Reader.ReadUInt32(); Reader .ReadXorByte(ref bytes[5]) .ReadXorByte(ref bytes[6]) .ReadSingle(out this.TransportPosition.X) .ReadXorByte(ref bytes[2]); if (this.HaveTransportTime2) { this.TransportTime2 = Reader.ReadUInt32(); } Reader .ReadSByte(out this.TransportSeat) .ReadXorByte(ref bytes[3]) .ReadSingle(out this.TransportPosition.Y) .ReadSingle(out this.TransportFacing) .ReadXorByte(ref bytes[7]) .ReadXorByte(ref bytes[0]); } } if (this.Living) { if (this.HaveSpline2) { if (this.HaveSpline) { var points = this.Spline.Points; points.Capacity = (int)splinePoints; for (int i = 0; i < splinePoints; i++) { points.Add(new Vector3() { Y = Reader.ReadSingle(), X = Reader.ReadSingle(), Z = Reader.ReadSingle() }); } if (this.Spline.HaveDurationMultiplier) { this.Spline.DurationMultiplier = Reader.ReadSingle(); } this.Spline.UnknownFloat2 = Reader.ReadSingle(); if (this.Spline.SplineType == SplineType.FacingTarget) { fixed(byte *bytes = this.Spline.FacingTarget.Bytes) { Reader .ReadXorByte(ref bytes[3]) .ReadXorByte(ref bytes[4]) .ReadXorByte(ref bytes[5]) .ReadXorByte(ref bytes[7]) .ReadXorByte(ref bytes[2]) .ReadXorByte(ref bytes[0]) .ReadXorByte(ref bytes[6]) .ReadXorByte(ref bytes[1]); } } if (this.Spline.HaveUnknown1) { this.Spline.Unknown1 = Reader.ReadUInt32(); } this.Spline.UnknownFloat3 = Reader.ReadSingle(); this.Spline.Unknown2 = Reader.ReadUInt32(); if (this.Spline.SplineType == SplineType.FacingSpot) { Reader .ReadSingle(out this.Spline.FacingSpot.Y) .ReadSingle(out this.Spline.FacingSpot.Z) .ReadSingle(out this.Spline.FacingSpot.X); } this.Spline.CurrentTime = Reader.ReadUInt32(); if (this.Spline.SplineType == SplineType.FacingAngle) { this.Spline.FacingAngle = Reader.ReadSingle(); } } Reader .ReadSingle(out this.Spline.EndPoint.Z) .ReadSingle(out this.Spline.EndPoint.Y) .ReadUInt32(out this.Spline.FullTime) .ReadSingle(out this.Spline.EndPoint.X); } this.Speeds[8] = Reader.ReadSingle(); // Transport Data if (this.HaveTransportData) { fixed(byte *bytes = this.TransportGuid.Bytes) { Reader .ReadXorByte(ref bytes[4]) .ReadSingle(out this.TransportPosition.Z) .ReadXorByte(ref bytes[7]) .ReadXorByte(ref bytes[5]) .ReadXorByte(ref bytes[1]) .ReadSingle(out this.TransportPosition.X) .ReadXorByte(ref bytes[3]) .ReadXorByte(ref bytes[6]); if (this.HaveTransportTime3) { this.TransportTime3 = Reader.ReadUInt32(); } Reader .ReadSingle(out this.TransportPosition.Y) .ReadSByte(out this.TransportSeat) .ReadSingle(out this.TransportFacing); if (this.HaveTransportTime2) { this.TransportTime2 = Reader.ReadUInt32(); } Reader .ReadXorByte(ref bytes[2]) .ReadUInt32(out this.TransportTime) .ReadXorByte(ref bytes[0]); } } Reader .ReadSingle(out this.Speeds[7]) .ReadSingle(out this.Position.X); if (this.HavePitch) { Reader.ReadSingle(out this.Pitch); } // Fall Data if (this.HaveFallData) { Reader.ReadUInt32(out this.FallTime); if (this.HaveFallDirection) { Reader .ReadSingle(out this.FallSinAngle) .ReadSingle(out this.FallHorizontalSpeed) .ReadSingle(out this.FallCosAngle); } Reader.ReadSingle(out this.FallVerticalSpeed); } Reader .ReadXorByte(ref p_guid.Bytes[7]) .ReadSingle(out this.Speeds[4]) .ReadXorByte(ref p_guid.Bytes[0]) .ReadXorByte(ref p_guid.Bytes[5]); if (this.TimeStamp != 0) { this.TimeStamp = Reader.ReadUInt32(); } Reader .ReadSingle(out this.Position.Z) .ReadSingle(out this.Speeds[6]) .ReadXorByte(ref p_guid.Bytes[1]) .ReadSingle(out this.Speeds[2]) .ReadSingle(out this.Speeds[5]) .ReadSingle(out this.Speeds[3]) .ReadSingle(out this.Speeds[0]) .ReadXorByte(ref p_guid.Bytes[3]) .ReadXorByte(ref p_guid.Bytes[4]) .ReadXorByte(ref p_guid.Bytes[2]) .ReadXorByte(ref p_guid.Bytes[6]); if (this.HaveSplineElevation) { this.SplineElevation = Reader.ReadSingle(); } this.Position.Y = Reader.ReadSingle(); if (haveOrientation) { this.Orientation = Reader.ReadSingle(); } this.Speeds[1] = Reader.ReadSingle(); } if (field_1C8) { Console.WriteLine("Error: 16 floats @ 1CC detected !!!"); Reader.ReadBytes(16 * 4); // 16 floats starting at 1CC var field_20C = Reader.ReadByte(); } // transport time if (this.HaveTransportTime) { Reader.ReadUInt32(out this.TransportTime); } // unk2 ? if (field_1AC) { Console.WriteLine("Error: 3 shorts @ 1AE detected !!!"); if (field_1B0 != 0) { field_1B0 = Reader.ReadUInt16(); } if (field_1B2 != 0) { field_1B2 = Reader.ReadUInt16(); } if (field_1AE != 0) { field_1AE = Reader.ReadUInt16(); } } // go rotation? if (this.HaveGameObjectRotation) { this.GameObjectRotation = Reader.ReadUInt64().UnpackQuaternion(); } // target guid? if (this.HaveAttackingTarget) { fixed(byte *bytes = this.AttackingTarget.Bytes) { Reader .ReadXorByte(ref bytes[3]) .ReadXorByte(ref bytes[5]) .ReadXorByte(ref bytes[0]) .ReadXorByte(ref bytes[7]) .ReadXorByte(ref bytes[2]) .ReadXorByte(ref bytes[4]) .ReadXorByte(ref bytes[6]) .ReadXorByte(ref bytes[1]); } } this.Guid = guid; }
protected void ReadByteMask(StreamHandler reader, ref byte b) { b = reader.UnalignedReadBit() ? (byte)1 : (byte)0; }
protected virtual void ReadElement(StreamHandler reader, MovementStatusElements element, MovementStatus status, byte[] guid, byte[] tguid) { if (element >= MovementStatusElements.GuidByte0 && element <= MovementStatusElements.GuidByte7) { ReadByteMask(reader, ref guid[element - MovementStatusElements.GuidByte0]); return; } if (element >= MovementStatusElements.TransportGuidByte0 && element <= MovementStatusElements.TransportGuidByte7) { if (status.HaveTransportData) { ReadByteMask(reader, ref tguid[element - MovementStatusElements.TransportGuidByte0]); } return; } if (element >= MovementStatusElements.GuidByte0_2 && element <= MovementStatusElements.GuidByte7_2) { ReadByteSeq(reader, ref guid[element - MovementStatusElements.GuidByte0_2]); return; } if (element >= MovementStatusElements.TransportGuidByte0_2 && element <= MovementStatusElements.TransportGuidByte7_2) { if (status.HaveTransportData) { ReadByteSeq(reader, ref tguid[element - MovementStatusElements.TransportGuidByte0_2]); } return; } switch (element) { case MovementStatusElements.Flags: status.Flags = (MovementFlags)(!reader.UnalignedReadBit() ? 1 : 0); break; case MovementStatusElements.Flags_2: if (status.Flags != 0) { status.Flags = (MovementFlags)reader.UnalignedReadInt(30); } break; case MovementStatusElements.Flags2: status.Flags2 = (MovementFlags2)(!reader.UnalignedReadBit() ? 1 : 0); break; case MovementStatusElements.Flags2_2: if (status.Flags2 != 0) { status.Flags2 = (MovementFlags2)reader.UnalignedReadSmallInt(12); } break; case MovementStatusElements.Timestamp: status.TimeStamp = !reader.UnalignedReadBit() ? 1U : 0U; break; case MovementStatusElements.Timestamp_2: if (status.TimeStamp != 0) { status.TimeStamp = reader.ReadUInt32(); } break; case MovementStatusElements.HaveFallData: status.HaveFallData = reader.UnalignedReadBit(); break; case MovementStatusElements.HaveFallDirection: if (status.HaveFallData) { status.HaveFallDirection = reader.UnalignedReadBit(); } break; case MovementStatusElements.HaveTransportData: status.HaveTransportData = reader.UnalignedReadBit(); break; case MovementStatusElements.TransportHaveTime2: if (status.HaveTransportData) { status.HaveTransportTime2 = reader.UnalignedReadBit(); } break; case MovementStatusElements.TransportHaveTime3: if (status.HaveTransportData) { status.HaveTransportTime3 = reader.UnalignedReadBit(); } break; case MovementStatusElements.HaveSpline: status.HaveSpline = reader.UnalignedReadBit(); break; case MovementStatusElements.HaveSpline2: status.HaveSpline2 = reader.UnalignedReadBit(); break; case MovementStatusElements.PositionX: status.Position.X = reader.ReadSingle(); break; case MovementStatusElements.PositionY: status.Position.Y = reader.ReadSingle(); break; case MovementStatusElements.PositionZ: status.Position.Z = reader.ReadSingle(); break; case MovementStatusElements.PositionO: status.Orientation = !reader.UnalignedReadBit() ? 1.0f : 0.0f; break; case MovementStatusElements.PositionO_2: if (status.Orientation != 0.0f) { status.Orientation = reader.ReadSingle(); } break; case MovementStatusElements.Pitch: status.HavePitch = !reader.UnalignedReadBit(); break; case MovementStatusElements.Pitch_2: if (status.HavePitch) { status.Pitch = reader.ReadSingle(); } break; case MovementStatusElements.FallTime: if (status.HaveFallData) { status.FallTime = reader.ReadUInt32(); } break; case MovementStatusElements.SplineElev: status.HaveSplineElevation = !reader.UnalignedReadBit(); break; case MovementStatusElements.SplineElev_2: if (status.HaveSplineElevation) { status.SplineElevation = reader.ReadSingle(); } break; case MovementStatusElements.FallHorizontalSpeed: if (status.HaveFallDirection) { status.FallHorizontalSpeed = reader.ReadSingle(); } break; case MovementStatusElements.FallVerticalSpeed: if (status.HaveFallData) { status.FallVerticalSpeed = reader.ReadSingle(); } break; case MovementStatusElements.FallCosAngle: if (status.HaveFallDirection) { status.FallCosAngle = reader.ReadSingle(); } break; case MovementStatusElements.FallSinAngle: if (status.HaveFallDirection) { status.FallSinAngle = reader.ReadSingle(); } break; case MovementStatusElements.TransportSeat: if (status.HaveTransportData) { status.TransportSeat = reader.ReadSByte(); } break; case MovementStatusElements.TransportPositionO: if (status.HaveTransportData) { status.TransportFacing = reader.ReadSingle(); } break; case MovementStatusElements.TransportPositionX: if (status.HaveTransportData) { status.TransportPosition.X = reader.ReadSingle(); } break; case MovementStatusElements.TransportPositionY: if (status.HaveTransportData) { status.TransportPosition.Y = reader.ReadSingle(); } break; case MovementStatusElements.TransportPositionZ: if (status.HaveTransportData) { status.TransportPosition.Z = reader.ReadSingle(); } break; case MovementStatusElements.TransportTime: if (status.HaveTransportData) { status.TransportTime = reader.ReadUInt32(); } break; case MovementStatusElements.TransportTime2: if (status.HaveTransportTime2) { status.TransportTime2 = reader.ReadUInt32(); } break; case MovementStatusElements.TransportTime3: if (status.HaveTransportTime3) { status.TransportTime3 = reader.ReadUInt32(); } break; default: throw new InvalidOperationException("Unknown element: " + element); } }