Light maintenance

This commit is contained in:
Max 2021-02-18 13:15:08 -06:00
parent 17f131c9f6
commit b352e2568d
34 changed files with 144 additions and 145 deletions

View File

@ -805,16 +805,11 @@ namespace RobloxFiles.BinaryFormat.Chunks
{ {
CFrame value = null; CFrame value = null;
if (prop.Value is Quaternion) if (prop.Value is Quaternion q)
{
Quaternion q = prop.CastValue<Quaternion>();
value = q.ToCFrame(); value = q.ToCFrame();
}
else else
{
value = prop.CastValue<CFrame>(); value = prop.CastValue<CFrame>();
}
Vector3 pos = value.Position; Vector3 pos = value.Position;
CFrame_X.Add(pos.X); CFrame_X.Add(pos.X);
CFrame_Y.Add(pos.Y); CFrame_Y.Add(pos.Y);
@ -856,15 +851,15 @@ namespace RobloxFiles.BinaryFormat.Chunks
props.ForEach(prop => props.ForEach(prop =>
{ {
if (prop.Value is uint) if (prop.Value is uint raw)
{ {
uint raw = prop.CastValue<uint>();
Enums.Add(raw); Enums.Add(raw);
return; return;
} }
int signed = (int)prop.Value; int signed = (int)prop.Value;
uint value = (uint)signed; uint value = (uint)signed;
Enums.Add(value); Enums.Add(value);
}); });
@ -1103,8 +1098,8 @@ namespace RobloxFiles.BinaryFormat.Chunks
object value = prop?.Value; object value = prop?.Value;
string str = value?.ToInvariantString() ?? "null"; string str = value?.ToInvariantString() ?? "null";
if (value is byte[]) if (value is byte[] buffer)
str = Convert.ToBase64String(value as byte[]); str = Convert.ToBase64String(buffer);
if (str.Length > 25) if (str.Length > 25)
str = str.Substring(0, 22) + "..."; str = str.Substring(0, 22) + "...";

View File

@ -54,10 +54,9 @@ namespace RobloxFiles.DataTypes
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
if (!(obj is BrickColor)) if (!(obj is BrickColor bc))
return false; return false;
var bc = obj as BrickColor;
return Number == bc.Number; return Number == bc.Number;
} }

View File

@ -51,10 +51,9 @@ namespace RobloxFiles.DataTypes
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
if (!(obj is CFrame)) if (!(obj is CFrame other))
return false; return false;
var other = obj as CFrame;
var compA = GetComponents(); var compA = GetComponents();
var compB = other.GetComponents(); var compB = other.GetComponents();
@ -420,13 +419,24 @@ namespace RobloxFiles.DataTypes
return new float[] { m14, m24, m34, m11, m12, m13, m21, m22, m23, m31, m32, m33 }; return new float[] { m14, m24, m34, m11, m12, m13, m21, m22, m23, m31, m32, m33 };
} }
public EulerAngles ToEulerAngles() => new EulerAngles
{
Yaw = (float)Math.Asin(m13),
Pitch = (float)Math.Atan2(-m23, m33),
Roll = (float)Math.Atan2(-m12, m11),
};
[Obsolete]
public float[] ToEulerAnglesXYZ() public float[] ToEulerAnglesXYZ()
{ {
float x = (float)Math.Atan2(-m23, m33); var result = ToEulerAngles();
float y = (float)Math.Asin(m13);
float z = (float)Math.Atan2(-m12, m11);
return new float[] { x, y, z }; return new float[]
{
result.Pitch,
result.Yaw,
result.Roll
};
} }
public bool IsAxisAligned() public bool IsAxisAligned()

View File

@ -25,11 +25,9 @@ namespace RobloxFiles.DataTypes
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
if (!(obj is Color3)) if (!(obj is Color3 other))
return false; return false;
var other = obj as Color3;
if (!R.Equals(other.R)) if (!R.Equals(other.R))
return false; return false;

View File

@ -40,10 +40,9 @@ namespace RobloxFiles.DataTypes
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
if (!(obj is ColorSequence)) if (!(obj is ColorSequence colorSeq))
return false; return false;
var colorSeq = obj as ColorSequence;
var otherKeys = colorSeq.Keypoints; var otherKeys = colorSeq.Keypoints;
if (Keypoints.Length != otherKeys.Length) if (Keypoints.Length != otherKeys.Length)

View File

@ -37,11 +37,9 @@
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
if (!(obj is ColorSequenceKeypoint)) if (!(obj is ColorSequenceKeypoint otherKey))
return false; return false;
var otherKey = obj as ColorSequenceKeypoint;
if (!Time.Equals(otherKey.Time)) if (!Time.Equals(otherKey.Time))
return false; return false;

View File

@ -31,10 +31,9 @@
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
if (!(obj is Content)) if (!(obj is Content content))
return false; return false;
var content = obj as Content;
return Url.Equals(content.Url); return Url.Equals(content.Url);
} }
} }

9
DataTypes/EulerAngles.cs Normal file
View File

@ -0,0 +1,9 @@
namespace RobloxFiles.DataTypes
{
public struct EulerAngles
{
public float Yaw;
public float Pitch;
public float Roll;
}
}

View File

@ -36,11 +36,9 @@ namespace RobloxFiles.DataTypes
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
if (!(obj is NumberRange)) if (!(obj is NumberRange other))
return false; return false;
var other = obj as NumberRange;
if (!Min.Equals(other.Min)) if (!Min.Equals(other.Min))
return false; return false;

View File

@ -75,11 +75,10 @@ namespace RobloxFiles.DataTypes
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
if (!(obj is NumberSequence)) if (!(obj is NumberSequence numberSeq))
return false; return false;
var colorSeq = obj as NumberSequence; var otherKeys = numberSeq.Keypoints;
var otherKeys = colorSeq.Keypoints;
if (Keypoints.Length != otherKeys.Length) if (Keypoints.Length != otherKeys.Length)
return false; return false;

View File

@ -36,11 +36,9 @@
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
if (!(obj is NumberSequenceKeypoint)) if (!(obj is NumberSequenceKeypoint otherKey))
return false; return false;
var otherKey = obj as NumberSequenceKeypoint;
if (!Time.Equals(otherKey.Time)) if (!Time.Equals(otherKey.Time))
return false; return false;

View File

@ -60,11 +60,9 @@ namespace RobloxFiles.DataTypes
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
if (!(obj is PhysicalProperties)) if (!(obj is PhysicalProperties other))
return false; return false;
var other = obj as PhysicalProperties;
if (!Density.Equals(other.Density)) if (!Density.Equals(other.Density))
return false; return false;

View File

@ -54,10 +54,9 @@ namespace RobloxFiles.DataTypes
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
if (!(obj is ProtectedString)) if (!(obj is ProtectedString other))
return false; return false;
var other = obj as ProtectedString;
var otherBuffer = other.RawBuffer; var otherBuffer = other.RawBuffer;
if (RawBuffer.Length != otherBuffer.Length) if (RawBuffer.Length != otherBuffer.Length)

View File

@ -134,21 +134,21 @@ namespace RobloxFiles.DataTypes
public CFrame ToCFrame() public CFrame ToCFrame()
{ {
float xc = X * 2f; float xc = X * 2f,
float yc = Y * 2f; yc = Y * 2f,
float zc = Z * 2f; zc = Z * 2f;
float xx = X * xc; float xx = X * xc,
float xy = X * yc; xy = X * yc,
float xz = X * zc; xz = X * zc;
float wx = W * xc; float wx = W * xc,
float wy = W * yc; wy = W * yc,
float wz = W * zc; wz = W * zc;
float yy = Y * yc; float yy = Y * yc,
float yz = Y * zc; yz = Y * zc,
float zz = Z * zc; zz = Z * zc;
return new CFrame return new CFrame
( (
@ -195,15 +195,33 @@ namespace RobloxFiles.DataTypes
public static Quaternion operator *(Quaternion a, Quaternion b) public static Quaternion operator *(Quaternion a, Quaternion b)
{ {
Vector3 v1 = new Vector3(a.X, a.Y, a.Z); Vector3 v1 = new Vector3(a.X, a.Y, a.Z),
float s1 = a.W; v2 = new Vector3(b.X, b.Y, b.Z);
Vector3 v2 = new Vector3(b.X, b.Y, b.Z); float s1 = a.W,
float s2 = b.W; s2 = b.W;
return new Quaternion(s1 * v2 + s2 * v1 + v1.Cross(v2), s1 * s2 - v1.Dot(v2)); return new Quaternion(s1 * v2 + s2 * v1 + v1.Cross(v2), s1 * s2 - v1.Dot(v2));
} }
public EulerAngles ToEulerAngles()
{
var angles = new EulerAngles();
double sinr_cosp = 2 * (W * X + Y * Z);
double cosr_cosp = 1 - 2 * (X * X + Y * Y);
angles.Roll = (float)Math.Atan2(sinr_cosp, cosr_cosp);
double sinp = 2 * (W * Y - Z * X);
angles.Pitch = (float)Math.Asin(sinp);
double siny_cosp = 2 * (W * Z + X * Y);
double cosy_cosp = 1 - 2 * (Y * Y + Z * Z);
angles.Yaw = (float)Math.Atan2(siny_cosp, cosy_cosp);
return angles;
}
public override int GetHashCode() public override int GetHashCode()
{ {
int hash = X.GetHashCode() int hash = X.GetHashCode()
@ -216,11 +234,9 @@ namespace RobloxFiles.DataTypes
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
if (!(obj is Quaternion)) if (!(obj is Quaternion other))
return false; return false;
var other = obj as Quaternion;
if (!X.Equals(other.X)) if (!X.Equals(other.X))
return false; return false;

View File

@ -53,11 +53,9 @@
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
if (!(obj is Ray)) if (!(obj is Ray other))
return false; return false;
var other = obj as Ray;
if (!Origin.Equals(other.Origin)) if (!Origin.Equals(other.Origin))
return false; return false;

View File

@ -38,11 +38,9 @@
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
if (!(obj is Rect)) if (!(obj is Rect other))
return false; return false;
var other = obj as Rect;
if (!Min.Equals(other.Min)) if (!Min.Equals(other.Min))
return false; return false;

View File

@ -52,11 +52,9 @@ namespace RobloxFiles.DataTypes
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
if (!(obj is Region3)) if (!(obj is Region3 other))
return false; return false;
var other = obj as Region3;
if (!Min.Equals(other.Min)) if (!Min.Equals(other.Min))
return false; return false;

View File

@ -27,11 +27,9 @@
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
if (!(obj is Region3int16)) if (!(obj is Region3int16 other))
return false; return false;
var other = obj as Region3int16;
if (!Min.Equals(other.Min)) if (!Min.Equals(other.Min))
return false; return false;

View File

@ -30,10 +30,9 @@ namespace RobloxFiles.DataTypes
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
if (!(obj is SharedString)) if (!(obj is SharedString other))
return false; return false;
var other = (obj as SharedString);
return Key.Equals(other.Key); return Key.Equals(other.Key);
} }

View File

@ -39,11 +39,9 @@
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
if (!(obj is UDim)) if (!(obj is UDim other))
return false; return false;
var other = obj as UDim;
if (!Scale.Equals(other.Scale)) if (!Scale.Equals(other.Scale))
return false; return false;

View File

@ -47,11 +47,9 @@
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
if (!(obj is UDim2)) if (!(obj is UDim2 other))
return false; return false;
var other = obj as UDim2;
if (!X.Equals(other.X)) if (!X.Equals(other.X))
return false; return false;

View File

@ -114,11 +114,9 @@ namespace RobloxFiles.DataTypes
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
if (!(obj is Vector2)) if (!(obj is Vector2 other))
return false; return false;
var other = obj as Vector2;
if (!X.Equals(other.X)) if (!X.Equals(other.X))
return false; return false;

View File

@ -76,11 +76,9 @@ namespace RobloxFiles.DataTypes
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
if (!(obj is Vector2int16)) if (!(obj is Vector2int16 other))
return false; return false;
var other = obj as Vector2int16;
if (!X.Equals(other.X)) if (!X.Equals(other.X))
return false; return false;

View File

@ -171,11 +171,9 @@ namespace RobloxFiles.DataTypes
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
if (!(obj is Vector3)) if (!(obj is Vector3 other))
return false; return false;
var other = obj as Vector3;
if (!X.Equals(other.X)) if (!X.Equals(other.X))
return false; return false;

View File

@ -84,11 +84,9 @@ namespace RobloxFiles.DataTypes
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
if (!(obj is Vector3int16)) if (!(obj is Vector3int16 other))
return false; return false;
var other = obj as Vector3int16;
if (!X.Equals(other.X)) if (!X.Equals(other.X))
return false; return false;

Binary file not shown.

View File

@ -6,6 +6,32 @@ local function UseColor3(propName)
} }
end end
local function TryDefineEnum(enumName)
local gotEnum, enum = pcall(function ()
return Enum[enumName]
end)
if gotEnum then
return "Enum:" .. tostring(enum)
end
end
local function TryGetEnumItem(enumName, itemName)
local gotEnum, enum = pcall(function ()
return Enum[enumName]
end)
if gotEnum then
local gotEnumItem, item = pcall(function ()
return enum[itemName]
end)
if gotEnumItem then
return item
end
end
end
local GuiTextMixIn = local GuiTextMixIn =
{ {
Add = { Transparency = "float" }; Add = { Transparency = "float" };
@ -121,14 +147,14 @@ return
{ {
Add = Add =
{ {
LODX = "Enum:LevelOfDetailSetting"; LODX = TryDefineEnum("LevelOfDetailSetting");
LODY = "Enum:LevelOfDetailSetting"; LODY = TryDefineEnum("LevelOfDetailSetting");
}; };
Defaults = Defaults =
{ {
LODX = Enum.LevelOfDetailSetting.High; LODX = TryGetEnumItem("LevelOfDetailSetting", "High");
LODY = Enum.LevelOfDetailSetting.High; LODY = TryGetEnumItem("LevelOfDetailSetting", "High");
}; };
}; };
@ -282,12 +308,12 @@ return
{ {
Add = Add =
{ {
Technology = "Enum:Technology"; Technology = TryDefineEnum("Technology");
}; };
Defaults = Defaults =
{ {
Technology = Enum.Technology.Compatibility; Technology = TryGetEnumItem("Technology", "Compatibility");
}; };
}; };
@ -485,7 +511,7 @@ return
{ {
MaxDistance = "xmlRead_MaxDistance_3"; MaxDistance = "xmlRead_MaxDistance_3";
xmlRead_MinDistance_3 = "EmitterSize"; xmlRead_MinDistance_3 = "EmitterSize";
RollOffMinDistance = "EmitterSize";
MinDistance = "EmitterSize"; MinDistance = "EmitterSize";
Pitch = "PlaybackSpeed"; Pitch = "PlaybackSpeed";
}; };
@ -649,7 +675,7 @@ return
StreamingMinRadius = "int"; StreamingMinRadius = "int";
StreamingTargetRadius = "int"; StreamingTargetRadius = "int";
StreamingPauseMode = "Enum:StreamingPauseMode"; StreamingPauseMode = TryDefineEnum("StreamingPauseMode");
TerrainWeldsFixed = "bool"; TerrainWeldsFixed = "bool";
}; };
@ -661,10 +687,11 @@ return
StreamingMinRadius = 64; StreamingMinRadius = 64;
StreamingTargetRadius = 1024; StreamingTargetRadius = 1024;
StreamingPauseMode = Enum.StreamingPauseMode.Default; StreamingPauseMode = TryGetEnumItem("StreamingPauseMode", "Default");
TerrainWeldsFixed = true; TerrainWeldsFixed = true;
MeshPartHeads = Enum.MeshPartHeads.Default; MeshPartHeads = TryGetEnumItem("MeshPartHeads", "Default");
MeshPartHeadsAndAccessories = TryGetEnumItem("MeshPartHeadsAndAccessories", "Default");
} }
} }
} }

View File

@ -77,8 +77,6 @@ local function exportStream(label)
export.Source = results export.Source = results
export.Name = label export.Name = label
export.Parent = workspace export.Parent = workspace
plugin:OpenScript(export)
end end
if isCoreScript then if isCoreScript then

View File

@ -123,6 +123,7 @@
<Compile Include="DataTypes\Vector2.cs" /> <Compile Include="DataTypes\Vector2.cs" />
<Compile Include="DataTypes\Vector3.cs" /> <Compile Include="DataTypes\Vector3.cs" />
<Compile Include="Utility\DefaultProperty.cs" /> <Compile Include="Utility\DefaultProperty.cs" />
<Compile Include="DataTypes\EulerAngles.cs" />
<Compile Include="Utility\Formatting.cs" /> <Compile Include="Utility\Formatting.cs" />
<Compile Include="Utility\FontUtility.cs" /> <Compile Include="Utility\FontUtility.cs" />
<Compile Include="Utility\ImplicitMember.cs" /> <Compile Include="Utility\ImplicitMember.cs" />

Binary file not shown.

View File

@ -60,8 +60,8 @@ namespace RobloxFiles
/// <summary>Indicates whether this Instance has been destroyed.</summary> /// <summary>Indicates whether this Instance has been destroyed.</summary>
public bool Destroyed { get; internal set; } public bool Destroyed { get; internal set; }
/// <summary>A list of CollectionService tags assigned to this Instance.</summary> /// <summary>A hashset of CollectionService tags assigned to this Instance.</summary>
public List<string> Tags { get; } = new List<string>(); public HashSet<string> Tags { get; } = new HashSet<string>();
/// <summary>The attributes defined for this Instance.</summary> /// <summary>The attributes defined for this Instance.</summary>
public Attributes Attributes { get; private set; } public Attributes Attributes { get; private set; }
@ -100,7 +100,7 @@ namespace RobloxFiles
{ {
int length = value.Length; int length = value.Length;
List<byte> buffer = new List<byte>(); var buffer = new List<byte>();
Tags.Clear(); Tags.Clear();
for (int i = 0; i < length; i++) for (int i = 0; i < length; i++)

View File

@ -104,10 +104,8 @@ namespace RobloxFiles
return; return;
} }
if (RawValue is SharedString) if (RawValue is SharedString sharedString)
{ {
var sharedString = CastValue<SharedString>();
if (sharedString != null) if (sharedString != null)
{ {
RawBuffer = sharedString.SharedValue; RawBuffer = sharedString.SharedValue;
@ -115,10 +113,8 @@ namespace RobloxFiles
} }
} }
if (RawValue is ProtectedString) if (RawValue is ProtectedString protectedString)
{ {
var protectedString = CastValue<ProtectedString>();
if (protectedString != null) if (protectedString != null)
{ {
RawBuffer = protectedString.RawBuffer; RawBuffer = protectedString.RawBuffer;
@ -222,9 +218,8 @@ namespace RobloxFiles
{ {
if (Instance != null) if (Instance != null)
{ {
if (Name == "Tags" && value is byte[]) if (Name == "Tags" && value is byte[] data)
{ {
byte[] data = value as byte[];
Instance.SerializedTags = data; Instance.SerializedTags = data;
} }
else else

View File

@ -7,8 +7,8 @@ namespace RobloxFiles.Utility
{ {
static class DefaultProperty static class DefaultProperty
{ {
private static Dictionary<string, Instance> ClassMap; private static readonly Dictionary<string, Instance> ClassMap;
private static HashSet<Instance> Refreshed = new HashSet<Instance>(); private static readonly HashSet<Instance> Refreshed = new HashSet<Instance>();
static DefaultProperty() static DefaultProperty()
{ {

View File

@ -40,16 +40,10 @@ namespace RobloxFiles.Utility
{ {
Type result = null; Type result = null;
if (member is FieldInfo) if (member is FieldInfo field)
{
var field = member as FieldInfo;
result = field.FieldType; result = field.FieldType;
} else if (member is PropertyInfo prop)
else if (member is PropertyInfo)
{
var prop = member as PropertyInfo;
result = prop.PropertyType; result = prop.PropertyType;
}
return result; return result;
} }
@ -57,32 +51,22 @@ namespace RobloxFiles.Utility
public object GetValue(object obj) public object GetValue(object obj)
{ {
if (member is FieldInfo) if (member is FieldInfo field)
{
var field = member as FieldInfo;
return field.GetValue(obj); return field.GetValue(obj);
} else if (member is PropertyInfo prop)
else if (member is PropertyInfo)
{
var prop = member as PropertyInfo;
return prop.GetValue(obj); return prop.GetValue(obj);
}
return null; return null;
} }
public void SetValue(object obj, object value) public void SetValue(object obj, object value)
{ {
if (member is FieldInfo) if (member is FieldInfo field)
{
var field = member as FieldInfo;
field.SetValue(obj, value); field.SetValue(obj, value);
} else if (member is PropertyInfo prop)
else if (member is PropertyInfo)
{
var prop = member as PropertyInfo;
prop.SetValue(obj, value); prop.SetValue(obj, value);
}
RobloxFile.LogError("Unknown field in ImplicitMember.SetValue");
} }
} }
} }