Skip to content

Commit 37cf50b

Browse files
committed
Add QAngle support to binary reader and writer
1 parent 4f08eb2 commit 37cf50b

2 files changed

Lines changed: 18 additions & 5 deletions

File tree

Codecs/Binary.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ static Binary()
3939
};
4040
SupportedAttributes[9] = new Type[] {
4141
typeof(Element), typeof(int), typeof(float), typeof(bool), typeof(string), typeof(byte[]),
42-
typeof(TimeSpan), typeof(Color), typeof(Vector2), typeof(Vector3), typeof(Vector4), typeof(Vector3) /* angle*/, typeof(Quaternion), typeof(Matrix4x4),
43-
typeof(ulong), typeof(byte)/*, typeof(QAngle) */
42+
typeof(TimeSpan), typeof(Color), typeof(Vector2), typeof(Vector3), typeof(Vector4), typeof(QAngle), typeof(Quaternion), typeof(Matrix4x4),
43+
typeof(ulong), typeof(byte)
4444
};
4545
}
4646

@@ -288,6 +288,12 @@ object ReadValue(Datamodel dm, Type type, bool raw_string)
288288
var ords = ReadVector(3);
289289
return new Vector3(ords[0], ords[1], ords[2]);
290290
}
291+
if (type == typeof(QAngle))
292+
{
293+
var ords = ReadVector(3);
294+
return new QAngle(ords[0], ords[1], ords[2]);
295+
}
296+
291297
if (type == typeof(Vector4))
292298
{
293299
var ords = ReadVector(4);
@@ -655,6 +661,13 @@ void WriteAttribute(object value, bool in_array)
655661
Writer.Write(vector3.Z);
656662
return;
657663
}
664+
if (value is QAngle qangle)
665+
{
666+
Writer.Write(qangle.Pitch);
667+
Writer.Write(qangle.Yaw);
668+
Writer.Write(qangle.Roll);
669+
return;
670+
}
658671
if (value is Vector4 vector4)
659672
{
660673
Writer.Write(vector4.X);

Types/QAngle.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ public QAngle(float pitch, float yaw, float roll)
2525
public static bool operator !=(QAngle a, QAngle b)
2626
=> !(a == b);
2727

28-
public override int GetHashCode()
28+
public readonly override int GetHashCode()
2929
=> HashCode.Combine(Pitch, Yaw, Roll);
3030

31-
public bool Equals(QAngle other)
31+
public readonly bool Equals(QAngle other)
3232
=> this == other;
3333

34-
public override bool Equals(object obj)
34+
public readonly override bool Equals(object obj)
3535
{
3636
if (obj is QAngle q)
3737
return this == q;

0 commit comments

Comments
 (0)