General Misc Patches

This commit is contained in:
CloneTrooper1019
2020-08-17 20:12:24 -05:00
parent 297426bdb5
commit f4899b4ce6
18 changed files with 267 additions and 47 deletions

View File

@ -170,6 +170,25 @@ namespace RobloxFiles.DataTypes
}
}
public override bool Equals(object obj)
{
if (obj is CFrame)
{
CFrame other = obj as CFrame;
float[] a = GetComponents();
float[] b = other.GetComponents();
for (int i = 0; i < 12; i++)
if (!a[i].FuzzyEquals(b[i]))
return false;
return true;
}
return base.Equals(obj);
}
public static CFrame operator +(CFrame a, Vector3 b)
{
float[] ac = a.GetComponents();

View File

@ -14,6 +14,15 @@ namespace RobloxFiles.DataTypes
B = b;
}
public override int GetHashCode()
{
int r = R.GetHashCode(),
g = G.GetHashCode(),
b = B.GetHashCode();
return (r ^ g ^ b);
}
internal Color3(Attribute attr)
{
R = attr.readFloat();

View File

@ -16,6 +16,11 @@
B = b;
}
public override int GetHashCode()
{
return (R << 24) | (G << 8) | B;
}
public static implicit operator Color3(Color3uint8 color)
{
float r = color.R / 255f;

View File

@ -21,10 +21,11 @@ namespace RobloxFiles.DataTypes
public ColorSequence(Color3 c0, Color3 c1)
{
ColorSequenceKeypoint a = new ColorSequenceKeypoint(0, c0);
ColorSequenceKeypoint b = new ColorSequenceKeypoint(1, c1);
Keypoints = new ColorSequenceKeypoint[2] { a, b };
Keypoints = new ColorSequenceKeypoint[2]
{
new ColorSequenceKeypoint(0, c0),
new ColorSequenceKeypoint(1, c1)
};
}
public ColorSequence(ColorSequenceKeypoint[] keypoints)

View File

@ -3,12 +3,13 @@
public class ColorSequenceKeypoint
{
public readonly float Time;
public readonly Color3 Value;
public readonly Color3uint8 Value;
public readonly int Envelope;
public override string ToString()
{
return $"{Time} {Value.R} {Value.G} {Value.B} {Envelope}";
Color3 Color = Value;
return $"{Time} {Color.R} {Color.G} {Color.B} {Envelope}";
}
public ColorSequenceKeypoint(float time, Color3 value, int envelope = 0)

View File

@ -59,7 +59,7 @@ namespace RobloxFiles.DataTypes
public static SharedString FromBuffer(byte[] buffer)
{
return new SharedString(buffer);
return new SharedString(buffer ?? Array.Empty<byte>());
}
public static SharedString FromString(string value)

View File

@ -1,4 +1,5 @@
using System;
using System.Text;
using RobloxFiles.Enums;
namespace RobloxFiles.DataTypes
@ -65,6 +66,36 @@ namespace RobloxFiles.DataTypes
return new Vector3(coords);
}
public override bool Equals(object obj)
{
if (obj is Vector3)
{
Vector3 other = obj as Vector3;
if (!X.FuzzyEquals(other.X))
return false;
if (!Y.FuzzyEquals(other.Y))
return false;
if (!Z.FuzzyEquals(other.Z))
return false;
return true;
}
return base.Equals(obj);
}
public override int GetHashCode()
{
int x = X.GetHashCode(),
y = Y.GetHashCode(),
z = Z.GetHashCode();
return x ^ y ^ z;
}
private delegate Vector3 Operator(Vector3 a, Vector3 b);
private static Vector3 upcastFloatOp(Vector3 vec, float num, Operator upcast)