Skip to content

Commit

Permalink
fix(clcore): Adjust "==" and "!=" operators to fix null reference exc…
Browse files Browse the repository at this point in the history
…eptions
  • Loading branch information
Keyinator committed Jul 28, 2024
1 parent e8e1554 commit 470283e
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 19 deletions.
4 changes: 2 additions & 2 deletions code/client/clrcore/External/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1025,7 +1025,7 @@ public override int GetHashCode()

public static bool operator ==(WeaponHudStats left, WeaponHudStats right)
{
return left.Equals(right);
return ReferenceEquals(left, null) ? ReferenceEquals(right, null) : left.Equals(right);
}

public static bool operator !=(WeaponHudStats left, WeaponHudStats right)
Expand Down Expand Up @@ -1101,7 +1101,7 @@ public override int GetHashCode()

public static bool operator ==(WeaponComponentHudStats left, WeaponComponentHudStats right)
{
return left.Equals(right);
return ReferenceEquals(left, null) ? ReferenceEquals(right, null) : left.Equals(right);
}

public static bool operator !=(WeaponComponentHudStats left, WeaponComponentHudStats right)
Expand Down
4 changes: 2 additions & 2 deletions code/client/clrcore/External/Model.cs
Original file line number Diff line number Diff line change
Expand Up @@ -429,11 +429,11 @@ public static implicit operator WeaponHash(Model source)

public static bool operator ==(Model left, Model right)
{
return left.Equals(right);
return ReferenceEquals(left, null) ? ReferenceEquals(right, null) : left.Equals(right);
}
public static bool operator !=(Model left, Model right)
{
return !left.Equals(right);
return !(left==right);
}
}
}
2 changes: 1 addition & 1 deletion code/client/clrcore/External/RelationshipGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public static implicit operator RelationshipGroup(string source)

public static bool operator ==(RelationshipGroup left, RelationshipGroup right)
{
return left.Equals(right);
return ReferenceEquals(left, null) ? ReferenceEquals(right, null) : left.Equals(right);
}
public static bool operator !=(RelationshipGroup left, RelationshipGroup right)
{
Expand Down
4 changes: 2 additions & 2 deletions code/client/clrcore/External/WeaponAsset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,11 @@ public static implicit operator WeaponAsset(WeaponHash hash)

public static bool operator ==(WeaponAsset left, WeaponAsset right)
{
return left.Equals(right);
return ReferenceEquals(left, null) ? ReferenceEquals(right, null) : left.Equals(right);
}
public static bool operator !=(WeaponAsset left, WeaponAsset right)
{
return !left.Equals(right);
return !(left==right);
}
}
}
4 changes: 2 additions & 2 deletions code/client/clrcore/Math/Matrix.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3091,7 +3091,7 @@ public static Matrix Transformation2D(Vector2 scalingCenter, float scalingRotati
/// <returns><c>true</c> if <paramref name="left"/> has the same value as <paramref name="right"/>; otherwise, <c>false</c>.</returns>
public static bool operator ==(Matrix left, Matrix right)
{
return left.Equals(ref right);
return ReferenceEquals(left, null) ? ReferenceEquals(right, null) : left.Equals(ref right);
}

/// <summary>
Expand All @@ -3102,7 +3102,7 @@ public static Matrix Transformation2D(Vector2 scalingCenter, float scalingRotati
/// <returns><c>true</c> if <paramref name="left"/> has a different value than <paramref name="right"/>; otherwise, <c>false</c>.</returns>
public static bool operator !=(Matrix left, Matrix right)
{
return !left.Equals(ref right);
return !(left==right);
}

/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions code/client/clrcore/Math/Matrix3x3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1951,7 +1951,7 @@ public static Matrix3x3 RotationYawPitchRoll(float yaw, float pitch, float roll)
/// <returns><c>true</c> if <paramref name="left"/> has the same value as <paramref name="right"/>; otherwise, <c>false</c>.</returns>
public static bool operator ==(Matrix3x3 left, Matrix3x3 right)
{
return left.Equals(ref right);
return ReferenceEquals(left, null) ? ReferenceEquals(right, null) : left.Equals(ref right);
}

/// <summary>
Expand All @@ -1962,7 +1962,7 @@ public static Matrix3x3 RotationYawPitchRoll(float yaw, float pitch, float roll)
/// <returns><c>true</c> if <paramref name="left"/> has a different value than <paramref name="right"/>; otherwise, <c>false</c>.</returns>
public static bool operator !=(Matrix3x3 left, Matrix3x3 right)
{
return !left.Equals(ref right);
return !(left==right);
}

/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions code/client/clrcore/Math/Quaternion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1294,7 +1294,7 @@ public static Quaternion[] SquadSetup(Quaternion value1, Quaternion value2, Quat
/// <returns><c>true</c> if <paramref name="left"/> has the same value as <paramref name="right"/>; otherwise, <c>false</c>.</returns>
public static bool operator ==(Quaternion left, Quaternion right)
{
return left.Equals(ref right);
return ReferenceEquals(left, null) ? ReferenceEquals(right, null) : left.Equals(ref right);
}

/// <summary>
Expand All @@ -1305,7 +1305,7 @@ public static Quaternion[] SquadSetup(Quaternion value1, Quaternion value2, Quat
/// <returns><c>true</c> if <paramref name="left"/> has a different value than <paramref name="right"/>; otherwise, <c>false</c>.</returns>
public static bool operator !=(Quaternion left, Quaternion right)
{
return !left.Equals(ref right);
return !(left==right);
}

/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions code/client/clrcore/Math/Vector2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1384,7 +1384,7 @@ public static void TransformNormal(Vector2[] source, ref Matrix transform, Vecto
/// <returns><c>true</c> if <paramref name="left"/> has the same value as <paramref name="right"/>; otherwise, <c>false</c>.</returns>
public static bool operator ==(Vector2 left, Vector2 right)
{
return left.Equals(ref right);
return ReferenceEquals(left, null) ? ReferenceEquals(right, null) : left.Equals(ref right);
}

/// <summary>
Expand All @@ -1395,7 +1395,7 @@ public static void TransformNormal(Vector2[] source, ref Matrix transform, Vecto
/// <returns><c>true</c> if <paramref name="left"/> has a different value than <paramref name="right"/>; otherwise, <c>false</c>.</returns>
public static bool operator !=(Vector2 left, Vector2 right)
{
return !left.Equals(ref right);
return !(left==right);
}

/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions code/client/clrcore/Math/Vector3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1652,7 +1652,7 @@ public static void TransformNormal(Vector3[] source, ref Matrix transform, Vecto
/// <returns><c>true</c> if <paramref name="left"/> has the same value as <paramref name="right"/>; otherwise, <c>false</c>.</returns>
public static bool operator ==(Vector3 left, Vector3 right)
{
return left.Equals(ref right);
return ReferenceEquals(left, null) ? ReferenceEquals(right, null) : left.Equals(ref right);
}

/// <summary>
Expand All @@ -1663,7 +1663,7 @@ public static void TransformNormal(Vector3[] source, ref Matrix transform, Vecto
/// <returns><c>true</c> if <paramref name="left"/> has a different value than <paramref name="right"/>; otherwise, <c>false</c>.</returns>
public static bool operator !=(Vector3 left, Vector3 right)
{
return !left.Equals(ref right);
return !(left==right);
}

/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions code/client/clrcore/Math/Vector4.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1292,7 +1292,7 @@ public static void Transform(Vector4[] source, ref Matrix transform, Vector4[] d
/// <returns><c>true</c> if <paramref name="left"/> has the same value as <paramref name="right"/>; otherwise, <c>false</c>.</returns>
public static bool operator ==(Vector4 left, Vector4 right)
{
return left.Equals(ref right);
return ReferenceEquals(left, null) ? ReferenceEquals(right, null) : left.Equals(ref right);
}

/// <summary>
Expand All @@ -1303,7 +1303,7 @@ public static void Transform(Vector4[] source, ref Matrix transform, Vector4[] d
/// <returns><c>true</c> if <paramref name="left"/> has a different value than <paramref name="right"/>; otherwise, <c>false</c>.</returns>
public static bool operator !=(Vector4 left, Vector4 right)
{
return !left.Equals(ref right);
return !(left==right);
}

/// <summary>
Expand Down

0 comments on commit 470283e

Please sign in to comment.