From f7184eb8f8312728dff948f0736157b3ba5d8923 Mon Sep 17 00:00:00 2001 From: CloneTrooper1019 Date: Fri, 1 Feb 2019 12:40:39 -0600 Subject: [PATCH] Convert datatypes to classes instead of structs. --- BinaryFormat/ChunkTypes/PROP.cs | 2 +- Core/Enums.cs | 5 ++- DataTypes/BrickColor.cs | 6 +-- DataTypes/CFrame.cs | 28 ++++++++----- DataTypes/Color3.cs | 8 ++-- DataTypes/ColorSequence.cs | 4 +- DataTypes/ColorSequenceKeypoint.cs | 2 +- DataTypes/NumberRange.cs | 4 +- DataTypes/NumberSequence.cs | 4 +- DataTypes/NumberSequenceKeypoint.cs | 2 +- DataTypes/PhysicalProperties.cs | 32 ++++++--------- DataTypes/Ray.cs | 16 +++++--- DataTypes/Rect.cs | 4 +- DataTypes/Region3.cs | 2 +- DataTypes/Region3int16.cs | 2 +- DataTypes/UDim.cs | 2 +- DataTypes/UDim2.cs | 4 +- DataTypes/Vector2.cs | 2 +- DataTypes/Vector3.cs | 2 +- DataTypes/Vector3int16.cs | 9 ++++- Properties/AssemblyInfo.cs | 9 ++--- RobloxFileFormat.csproj | 12 ++---- UnitTest.cs | 19 --------- {DataTypes/Utility => Utility}/BrickColors.cs | 11 ++++-- .../Utility => Utility}/MaterialInfo.cs | 30 +++++++++++++- {DataTypes/Utility => Utility}/Quaternion.cs | 12 +++--- XmlFormat/PropertyTokens/Color3uint8.cs | 2 +- XmlFormat/PropertyTokens/Ray.cs | 39 +++++++++---------- XmlFormat/PropertyTokens/Rect.cs | 39 +++++++++---------- XmlFormat/PropertyTokens/UDim.cs | 8 ++-- XmlFormat/PropertyTokens/UDim2.cs | 8 ++-- XmlFormat/PropertyTokens/Vector2.cs | 8 ++-- XmlFormat/PropertyTokens/Vector3.cs | 8 ++-- XmlFormat/XmlRobloxFile.cs | 2 +- packages.config | 4 -- 35 files changed, 182 insertions(+), 169 deletions(-) delete mode 100644 UnitTest.cs rename {DataTypes/Utility => Utility}/BrickColors.cs (97%) rename {DataTypes/Utility => Utility}/MaterialInfo.cs (80%) rename {DataTypes/Utility => Utility}/Quaternion.cs (94%) delete mode 100644 packages.config diff --git a/BinaryFormat/ChunkTypes/PROP.cs b/BinaryFormat/ChunkTypes/PROP.cs index 1b5fb3d..99d13b7 100644 --- a/BinaryFormat/ChunkTypes/PROP.cs +++ b/BinaryFormat/ChunkTypes/PROP.cs @@ -415,7 +415,7 @@ namespace RobloxFiles.BinaryFormat.Chunks g = color3uint8_G[i], b = color3uint8_B[i]; - return Color3.fromRGB(r, g, b); + return Color3.FromRGB(r, g, b); }); break; diff --git a/Core/Enums.cs b/Core/Enums.cs index 3d1edd7..785326f 100644 --- a/Core/Enums.cs +++ b/Core/Enums.cs @@ -1,5 +1,5 @@ // This is an auto-generated list of all available enums on Roblox! -// Updated as of 0.369.1.273919 +// Updated as of 0.370.0.274702 namespace RobloxFiles.Enums { @@ -806,7 +806,8 @@ namespace RobloxFiles.Enums Players = 7, Chat = 15, Avatar, - Analytics = 22 + Analytics = 22, + Localization = 24 } public enum HumanoidDisplayDistanceType diff --git a/DataTypes/BrickColor.cs b/DataTypes/BrickColor.cs index ad668eb..8bd7e21 100644 --- a/DataTypes/BrickColor.cs +++ b/DataTypes/BrickColor.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Linq; -using RobloxFiles.DataTypes.Utility; +using RobloxFiles.Utility; namespace RobloxFiles.DataTypes { @@ -35,7 +35,7 @@ namespace RobloxFiles.DataTypes Name = name; Number = number; - Color = Color3.fromRGB(r, g, b); + Color = Color3.FromRGB(r, g, b); } static BrickColor() @@ -43,7 +43,7 @@ namespace RobloxFiles.DataTypes ByNumber = BrickColors.ColorMap.ToDictionary(brickColor => brickColor.Number); ByPalette = BrickColors.PaletteMap.Select(number => ByNumber[number]).ToList(); } - + public static BrickColor FromName(string name) { BrickColor result = null; diff --git a/DataTypes/CFrame.cs b/DataTypes/CFrame.cs index 1c6559b..16cdfca 100644 --- a/DataTypes/CFrame.cs +++ b/DataTypes/CFrame.cs @@ -20,6 +20,13 @@ namespace RobloxFiles.DataTypes public Vector3 RightVector => new Vector3( m11, m21, m31); public Vector3 UpVector => new Vector3( m12, m22, m32); + public CFrame() + { + m14 = 0; + m24 = 0; + m34 = 0; + } + public CFrame(Vector3 pos) { m14 = pos.X; @@ -27,6 +34,14 @@ namespace RobloxFiles.DataTypes m34 = pos.Z; } + public CFrame(float nx = 0, float ny = 0, float nz = 0) + { + m14 = nx; + m24 = ny; + m34 = nz; + } + + public CFrame(Vector3 eye, Vector3 look) { Vector3 zAxis = (eye - look).Unit; @@ -37,9 +52,9 @@ namespace RobloxFiles.DataTypes { if (zAxis.Y < 0) { - xAxis = new Vector3(0, 0, -1); - yAxis = new Vector3(1, 0, 0); - zAxis = new Vector3(0, -1, 0); + xAxis = new Vector3(0, 0, -1); + yAxis = new Vector3(1, 0, 0); + zAxis = new Vector3(0, -1, 0); } else { @@ -54,13 +69,6 @@ namespace RobloxFiles.DataTypes m31 = xAxis.Z; m32 = yAxis.Z; m33 = zAxis.Z; m34 = eye.Z; } - public CFrame(float nx = 0, float ny = 0, float nz = 0) - { - m14 = nx; - m24 = ny; - m34 = nz; - } - public CFrame(float nx, float ny, float nz, float i, float j, float k, float w) { float ii = i * i; diff --git a/DataTypes/Color3.cs b/DataTypes/Color3.cs index 9af1da7..381d50a 100644 --- a/DataTypes/Color3.cs +++ b/DataTypes/Color3.cs @@ -2,7 +2,7 @@ namespace RobloxFiles.DataTypes { - public struct Color3 + public class Color3 { public readonly float R, G, B; @@ -18,12 +18,12 @@ namespace RobloxFiles.DataTypes return string.Join(", ", R, G, B); } - public static Color3 fromRGB(uint r = 0, uint g = 0, uint b = 0) + public static Color3 FromRGB(uint r = 0, uint g = 0, uint b = 0) { return new Color3(r / 255f, g / 255f, b / 255f); } - public static Color3 fromHSV(float h = 0, float s = 0, float v = 0) + public static Color3 FromHSV(float h = 0, float s = 0, float v = 0) { int i = (int)Math.Min(5, Math.Floor(6.0 * h)); float f = 6.0f * h - i; @@ -51,7 +51,7 @@ namespace RobloxFiles.DataTypes } } - public static float[] toHSV(Color3 color) + public static float[] ToHSV(Color3 color) { float val = Math.Max(Math.Max(color.R, color.G), color.B); diff --git a/DataTypes/ColorSequence.cs b/DataTypes/ColorSequence.cs index 74eadf3..b2575ad 100644 --- a/DataTypes/ColorSequence.cs +++ b/DataTypes/ColorSequence.cs @@ -2,7 +2,7 @@ namespace RobloxFiles.DataTypes { - public struct ColorSequence + public class ColorSequence { public readonly ColorSequenceKeypoint[] Keypoints; @@ -46,7 +46,7 @@ namespace RobloxFiles.DataTypes public override string ToString() { - return string.Join(" ", Keypoints); + return string.Join(" ", Keypoints); } } } diff --git a/DataTypes/ColorSequenceKeypoint.cs b/DataTypes/ColorSequenceKeypoint.cs index 30e03fa..662fb42 100644 --- a/DataTypes/ColorSequenceKeypoint.cs +++ b/DataTypes/ColorSequenceKeypoint.cs @@ -1,6 +1,6 @@ namespace RobloxFiles.DataTypes { - public struct ColorSequenceKeypoint + public class ColorSequenceKeypoint { public readonly float Time; public readonly Color3 Value; diff --git a/DataTypes/NumberRange.cs b/DataTypes/NumberRange.cs index 468ea1f..0c9d359 100644 --- a/DataTypes/NumberRange.cs +++ b/DataTypes/NumberRange.cs @@ -2,12 +2,12 @@ namespace RobloxFiles.DataTypes { - public struct NumberRange + public class NumberRange { public readonly float Min; public readonly float Max; - public NumberRange(float min, float max) + public NumberRange(float min = 0, float max = 0) { if (max - min < 0) throw new Exception("NumberRange: invalid range"); diff --git a/DataTypes/NumberSequence.cs b/DataTypes/NumberSequence.cs index edbb6ed..846d178 100644 --- a/DataTypes/NumberSequence.cs +++ b/DataTypes/NumberSequence.cs @@ -2,7 +2,7 @@ namespace RobloxFiles.DataTypes { - public struct NumberSequence + public class NumberSequence { public readonly NumberSequenceKeypoint[] Keypoints; @@ -46,7 +46,7 @@ namespace RobloxFiles.DataTypes public override string ToString() { - return string.Join(" ", Keypoints); + return string.Join(" ", Keypoints); } } } diff --git a/DataTypes/NumberSequenceKeypoint.cs b/DataTypes/NumberSequenceKeypoint.cs index 78ed77f..381fdba 100644 --- a/DataTypes/NumberSequenceKeypoint.cs +++ b/DataTypes/NumberSequenceKeypoint.cs @@ -1,6 +1,6 @@ namespace RobloxFiles.DataTypes { - public struct NumberSequenceKeypoint + public class NumberSequenceKeypoint { public readonly float Time; public readonly float Value; diff --git a/DataTypes/PhysicalProperties.cs b/DataTypes/PhysicalProperties.cs index 7964332..764fe25 100644 --- a/DataTypes/PhysicalProperties.cs +++ b/DataTypes/PhysicalProperties.cs @@ -1,38 +1,28 @@ using RobloxFiles.Enums; -using RobloxFiles.DataTypes.Utility; +using RobloxFiles.Utility; namespace RobloxFiles.DataTypes { - public struct PhysicalProperties + public class PhysicalProperties { - public readonly float Density; - public readonly float Friction; - public readonly float Elasticity; + public readonly float Density = 1.0f; + public readonly float Friction = 1.0f; + public readonly float Elasticity = 0.5f; - public readonly float FrictionWeight; - public readonly float ElasticityWeight; + public readonly float FrictionWeight = 1.0f; + public readonly float ElasticityWeight = 1.0f; public PhysicalProperties(Material material) { + if (MaterialInfo.FrictionWeightMap.ContainsKey(material)) + FrictionWeight = MaterialInfo.FrictionWeightMap[material]; + Density = MaterialInfo.DensityMap[material]; Friction = MaterialInfo.FrictionMap[material]; Elasticity = MaterialInfo.ElasticityMap[material]; - - FrictionWeight = 1; - ElasticityWeight = 1; } - public PhysicalProperties(float density, float friction, float elasticity) - { - Density = density; - Friction = friction; - Elasticity = elasticity; - - FrictionWeight = 1; - ElasticityWeight = 1; - } - - public PhysicalProperties(float density, float friction, float elasticity, float frictionWeight, float elasticityWeight) + public PhysicalProperties(float density, float friction, float elasticity, float frictionWeight = 1f, float elasticityWeight = 1f) { Density = density; Friction = friction; diff --git a/DataTypes/Ray.cs b/DataTypes/Ray.cs index 0cbf237..8bc4647 100644 --- a/DataTypes/Ray.cs +++ b/DataTypes/Ray.cs @@ -1,6 +1,6 @@ namespace RobloxFiles.DataTypes { - public struct Ray + public class Ray { public readonly Vector3 Origin; public readonly Vector3 Direction; @@ -33,15 +33,19 @@ public Vector3 ClosestPoint(Vector3 point) { - Vector3 offset = point - Origin; - float diff = offset.Dot(Direction) / Direction.Dot(Direction); - return Origin + (diff * Direction); + Vector3 result = Origin; + float t = Direction.Dot(point - result); + + if (t >= 0) + result += (Direction * t); + + return result; } public float Distance(Vector3 point) { - Vector3 projected = ClosestPoint(point); - return (point - projected).Magnitude; + Vector3 closestPoint = ClosestPoint(point); + return (closestPoint - point).Magnitude; } } } diff --git a/DataTypes/Rect.cs b/DataTypes/Rect.cs index 426a4c2..3ab6ad1 100644 --- a/DataTypes/Rect.cs +++ b/DataTypes/Rect.cs @@ -1,6 +1,6 @@ namespace RobloxFiles.DataTypes { - public struct Rect + public class Rect { public readonly Vector2 Min; public readonly Vector2 Max; @@ -8,7 +8,7 @@ public float Width => (Max - Min).X; public float Height => (Max - Min).Y; - public Rect(Vector2? min, Vector2? max) + public Rect(Vector2 min = null, Vector2 max = null) { Min = min ?? Vector2.Zero; Max = max ?? Vector2.Zero; diff --git a/DataTypes/Region3.cs b/DataTypes/Region3.cs index 30e2779..fb8c766 100644 --- a/DataTypes/Region3.cs +++ b/DataTypes/Region3.cs @@ -2,7 +2,7 @@ namespace RobloxFiles.DataTypes { - public struct Region3 + public class Region3 { public readonly CFrame CFrame; public readonly Vector3 Size; diff --git a/DataTypes/Region3int16.cs b/DataTypes/Region3int16.cs index 7ab407a..a029831 100644 --- a/DataTypes/Region3int16.cs +++ b/DataTypes/Region3int16.cs @@ -10,7 +10,7 @@ namespace RobloxFiles.DataTypes { public readonly Vector3int16 Min, Max; - public Region3int16(Vector3int16? min, Vector3int16? max) + public Region3int16(Vector3int16 min = null, Vector3int16 max = null) { Min = min ?? new Vector3int16(); Max = max ?? new Vector3int16(); diff --git a/DataTypes/UDim.cs b/DataTypes/UDim.cs index 290a3c8..c3d6ba8 100644 --- a/DataTypes/UDim.cs +++ b/DataTypes/UDim.cs @@ -1,6 +1,6 @@ namespace RobloxFiles.DataTypes { - public struct UDim + public class UDim { public readonly float Scale; public readonly int Offset; diff --git a/DataTypes/UDim2.cs b/DataTypes/UDim2.cs index 16ccb5b..9c734ae 100644 --- a/DataTypes/UDim2.cs +++ b/DataTypes/UDim2.cs @@ -1,13 +1,13 @@ namespace RobloxFiles.DataTypes { - public struct UDim2 + public class UDim2 { public readonly UDim X, Y; public UDim Width => X; public UDim Height => Y; - public UDim2(float scaleX, int offsetX, float scaleY, int offsetY) + public UDim2(float scaleX = 0, int offsetX = 0, float scaleY = 0, int offsetY = 0) { X = new UDim(scaleX, offsetX); Y = new UDim(scaleY, offsetY); diff --git a/DataTypes/Vector2.cs b/DataTypes/Vector2.cs index ab9c928..c58b5df 100644 --- a/DataTypes/Vector2.cs +++ b/DataTypes/Vector2.cs @@ -2,7 +2,7 @@ namespace RobloxFiles.DataTypes { - public struct Vector2 + public class Vector2 { public readonly float X, Y; diff --git a/DataTypes/Vector3.cs b/DataTypes/Vector3.cs index a7250b4..b8f6a62 100644 --- a/DataTypes/Vector3.cs +++ b/DataTypes/Vector3.cs @@ -3,7 +3,7 @@ using RobloxFiles.Enums; namespace RobloxFiles.DataTypes { - public struct Vector3 + public class Vector3 { public readonly float X, Y, Z; diff --git a/DataTypes/Vector3int16.cs b/DataTypes/Vector3int16.cs index 011755c..6ac48cb 100644 --- a/DataTypes/Vector3int16.cs +++ b/DataTypes/Vector3int16.cs @@ -2,10 +2,17 @@ namespace RobloxFiles.DataTypes { - public struct Vector3int16 + public class Vector3int16 { public readonly short X, Y, Z; + public Vector3int16() + { + X = 0; + Y = 0; + Z = 0; + } + public Vector3int16(short x = 0, short y = 0, short z = 0) { X = x; diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index 225e9c8..876e7a8 100644 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -5,12 +5,11 @@ using System.Runtime.InteropServices; // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. -[assembly: AssemblyTitle("RobloxFiles")] -[assembly: AssemblyDescription("")] +[assembly: AssemblyTitle("Roblox File Format")] +[assembly: AssemblyDescription("Implementation of Roblox's File Format in C# for .NET 4.0")] [assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("RobloxFiles")] -[assembly: AssemblyCopyright("Copyright © 2019")] +[assembly: AssemblyCompany("Written by CloneTrooper1019")] +[assembly: AssemblyProduct("Roblox File Format")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] diff --git a/RobloxFileFormat.csproj b/RobloxFileFormat.csproj index 1c9054e..6466d66 100644 --- a/RobloxFileFormat.csproj +++ b/RobloxFileFormat.csproj @@ -42,7 +42,7 @@ bin\Release\ TRACE prompt - 4 + 1 @@ -86,7 +86,7 @@ - + @@ -94,9 +94,8 @@ - - - + + @@ -128,9 +127,6 @@ - - - False diff --git a/UnitTest.cs b/UnitTest.cs deleted file mode 100644 index 963be86..0000000 --- a/UnitTest.cs +++ /dev/null @@ -1,19 +0,0 @@ -#if DEBUG -using System.Diagnostics; - -namespace RobloxFiles -{ - // This is a placeholder. - internal class UnitTest - { - public static void Main(string[] args) - { - if (args.Length > 0) - { - RobloxFile file = new RobloxFile(args[0]); - Debugger.Break(); - } - } - } -} -#endif \ No newline at end of file diff --git a/DataTypes/Utility/BrickColors.cs b/Utility/BrickColors.cs similarity index 97% rename from DataTypes/Utility/BrickColors.cs rename to Utility/BrickColors.cs index 9e60f3d..fdc67e4 100644 --- a/DataTypes/Utility/BrickColors.cs +++ b/Utility/BrickColors.cs @@ -1,8 +1,13 @@ using System.Collections.Generic; + using RobloxFiles.DataTypes; -namespace RobloxFiles.DataTypes.Utility +namespace RobloxFiles.Utility { + /// + /// This static class defines all of Roblox's built-in BrickColor data. + /// It is used primarily by the BrickColor DataType. + /// public static class BrickColors { /// @@ -33,10 +38,10 @@ namespace RobloxFiles.DataTypes.Utility }; /// - /// This contains a list of all available BrickColors on Roblox. + /// This contains a list of all defined BrickColors on Roblox. /// - public static IReadOnlyCollection ColorMap = new List() + public static IReadOnlyList ColorMap = new List() { new BrickColor( 1, 0xF2F3F3, "White"), new BrickColor( 2, 0xA1A5A2, "Grey"), diff --git a/DataTypes/Utility/MaterialInfo.cs b/Utility/MaterialInfo.cs similarity index 80% rename from DataTypes/Utility/MaterialInfo.cs rename to Utility/MaterialInfo.cs index 5641fb3..58b4577 100644 --- a/DataTypes/Utility/MaterialInfo.cs +++ b/Utility/MaterialInfo.cs @@ -1,10 +1,17 @@ using System.Collections.Generic; using RobloxFiles.Enums; -namespace RobloxFiles.DataTypes.Utility +namespace RobloxFiles.Utility { + /// + /// This class defines several dictionaries of metadata for Roblox materials. + /// It is primarily used for the PhysicalProperties DataType. + /// public static class MaterialInfo { + /// + /// A dictionary mapping materials to their default Density. + /// public static IReadOnlyDictionary DensityMap = new Dictionary() { {Material.Air, 0.01f}, @@ -45,6 +52,9 @@ namespace RobloxFiles.DataTypes.Utility {Material.WoodPlanks, 0.35f}, }; + /// + /// A dictionary mapping materials to their default Elasticity. + /// public static IReadOnlyDictionary ElasticityMap = new Dictionary() { {Material.Air, 0.01f}, @@ -85,6 +95,9 @@ namespace RobloxFiles.DataTypes.Utility {Material.WoodPlanks, 0.20f}, }; + /// + /// A dictionary mapping materials to their default Friction. + /// public static IReadOnlyDictionary FrictionMap = new Dictionary() { {Material.Air, 0.01f}, @@ -124,5 +137,20 @@ namespace RobloxFiles.DataTypes.Utility {Material.Wood, 0.48f}, {Material.WoodPlanks, 0.48f}, }; + + /// + /// A dictionary mapping materials to their default Friction. + /// NOTE: This only maps materials that have different FrictionWeights. If it isn't in here, assume their FrictionWeight is 1. + /// + public static IReadOnlyDictionary FrictionWeightMap = new Dictionary() + { + {Material.Asphalt, 0.30f}, + {Material.Basalt, 0.30f}, + {Material.Brick, 0.30f}, + {Material.Concrete, 0.30f}, + {Material.Ice, 3.00f}, + {Material.Sand, 5.00f}, + {Material.Sandstone, 5.00f}, + }; } } \ No newline at end of file diff --git a/DataTypes/Utility/Quaternion.cs b/Utility/Quaternion.cs similarity index 94% rename from DataTypes/Utility/Quaternion.cs rename to Utility/Quaternion.cs index 0591661..aead226 100644 --- a/DataTypes/Utility/Quaternion.cs +++ b/Utility/Quaternion.cs @@ -2,12 +2,13 @@ namespace RobloxFiles.DataTypes.Utility { + /// + /// Quaternion is a utility used by the CFrame DataType to handle rotation interpolation. + /// It can be used as an independent Quaternion implementation if you so please! + /// public class Quaternion { - public readonly float X; - public readonly float Y; - public readonly float Z; - public readonly float W; + public readonly float X, Y, Z, W; public float Magnitude { @@ -41,8 +42,7 @@ namespace RobloxFiles.DataTypes.Utility CFrame matrix = (cf - cf.Position); float[] ac = cf.GetComponents(); - float m41 = ac[0], m42 = ac[1], m43 = ac[2], - m11 = ac[3], m12 = ac[4], m13 = ac[5], + float m11 = ac[3], m12 = ac[4], m13 = ac[5], m21 = ac[6], m22 = ac[7], m23 = ac[8], m31 = ac[9], m32 = ac[10], m33 = ac[11]; diff --git a/XmlFormat/PropertyTokens/Color3uint8.cs b/XmlFormat/PropertyTokens/Color3uint8.cs index e8287f0..74db424 100644 --- a/XmlFormat/PropertyTokens/Color3uint8.cs +++ b/XmlFormat/PropertyTokens/Color3uint8.cs @@ -20,7 +20,7 @@ namespace RobloxFiles.XmlFormat.PropertyTokens uint g = (value >> 8) & 0xFF; uint b = value & 0xFF; - prop.Value = Color3.fromRGB(r, g, b); + prop.Value = Color3.FromRGB(r, g, b); } return success; diff --git a/XmlFormat/PropertyTokens/Ray.cs b/XmlFormat/PropertyTokens/Ray.cs index e9cce47..70061cc 100644 --- a/XmlFormat/PropertyTokens/Ray.cs +++ b/XmlFormat/PropertyTokens/Ray.cs @@ -10,31 +10,30 @@ namespace RobloxFiles.XmlFormat.PropertyTokens public bool ReadToken(Property prop, XmlNode token) { - Vector3[] read = new Vector3[Fields.Length]; - - for (int i = 0; i < read.Length; i++) + try { - string field = Fields[i]; - try + Vector3[] read = new Vector3[Fields.Length]; + + for (int i = 0; i < read.Length; i++) { + string field = Fields[i]; var fieldToken = token[field]; - Vector3? vector3 = Vector3Token.ReadVector3(fieldToken); - read[i] = vector3.Value; - } - catch - { - return false; + read[i] = Vector3Token.ReadVector3(fieldToken); } + + Vector3 origin = read[0], + direction = read[1]; + + Ray ray = new Ray(origin, direction); + prop.Type = PropertyType.Ray; + prop.Value = ray; + + return true; + } + catch + { + return false; } - - Vector3 origin = read[0], - direction = read[1]; - - Ray ray = new Ray(origin, direction); - prop.Type = PropertyType.Ray; - prop.Value = ray; - - return true; } } } diff --git a/XmlFormat/PropertyTokens/Rect.cs b/XmlFormat/PropertyTokens/Rect.cs index 8c97a9e..a03ba7b 100644 --- a/XmlFormat/PropertyTokens/Rect.cs +++ b/XmlFormat/PropertyTokens/Rect.cs @@ -10,31 +10,30 @@ namespace RobloxFiles.XmlFormat.PropertyTokens public bool ReadToken(Property prop, XmlNode token) { - Vector2[] read = new Vector2[Fields.Length]; - - for (int i = 0; i < read.Length; i++) + try { - string field = Fields[i]; - try + Vector2[] read = new Vector2[Fields.Length]; + + for (int i = 0; i < read.Length; i++) { + string field = Fields[i]; var fieldToken = token[field]; - Vector2? vector2 = Vector2Token.ReadVector2(fieldToken); - read[i] = vector2.Value; - } - catch - { - return false; + read[i] = Vector2Token.ReadVector2(fieldToken); } + + Vector2 min = read[0], + max = read[1]; + + Rect rect = new Rect(min, max); + prop.Type = PropertyType.Rect; + prop.Value = rect; + + return true; + } + catch + { + return false; } - - Vector2 min = read[0], - max = read[1]; - - Rect rect = new Rect(min, max); - prop.Type = PropertyType.Rect; - prop.Value = rect; - - return true; } } } diff --git a/XmlFormat/PropertyTokens/UDim.cs b/XmlFormat/PropertyTokens/UDim.cs index dde22b8..b6dd52e 100644 --- a/XmlFormat/PropertyTokens/UDim.cs +++ b/XmlFormat/PropertyTokens/UDim.cs @@ -7,7 +7,7 @@ namespace RobloxFiles.XmlFormat.PropertyTokens { public string Token => "UDim"; - public static UDim? ReadUDim(XmlNode token, string prefix = "") + public static UDim ReadUDim(XmlNode token, string prefix = "") { try { @@ -27,13 +27,13 @@ namespace RobloxFiles.XmlFormat.PropertyTokens public bool ReadToken(Property property, XmlNode token) { - UDim? result = ReadUDim(token); - bool success = result.HasValue; + UDim result = ReadUDim(token); + bool success = (result != null); if (success) { property.Type = PropertyType.UDim; - property.Value = result.Value; + property.Value = result; } return success; diff --git a/XmlFormat/PropertyTokens/UDim2.cs b/XmlFormat/PropertyTokens/UDim2.cs index 35aa1cd..cc6be0c 100644 --- a/XmlFormat/PropertyTokens/UDim2.cs +++ b/XmlFormat/PropertyTokens/UDim2.cs @@ -9,13 +9,13 @@ namespace RobloxFiles.XmlFormat.PropertyTokens public bool ReadToken(Property property, XmlNode token) { - UDim? xDim = UDimToken.ReadUDim(token, "X"); - UDim? yDim = UDimToken.ReadUDim(token, "Y"); + UDim xUDim = UDimToken.ReadUDim(token, "X"); + UDim yUDim = UDimToken.ReadUDim(token, "Y"); - if (xDim != null && yDim != null) + if (xUDim != null && yUDim != null) { property.Type = PropertyType.UDim2; - property.Value = new UDim2(xDim.Value, yDim.Value); + property.Value = new UDim2(xUDim, yUDim); return true; } diff --git a/XmlFormat/PropertyTokens/Vector2.cs b/XmlFormat/PropertyTokens/Vector2.cs index 2fb0e18..86926ef 100644 --- a/XmlFormat/PropertyTokens/Vector2.cs +++ b/XmlFormat/PropertyTokens/Vector2.cs @@ -8,7 +8,7 @@ namespace RobloxFiles.XmlFormat.PropertyTokens public string Token => "Vector2"; private static string[] Coords = new string[2] { "X", "Y" }; - public static Vector2? ReadVector2(XmlNode token) + public static Vector2 ReadVector2(XmlNode token) { float[] xy = new float[2]; @@ -33,13 +33,13 @@ namespace RobloxFiles.XmlFormat.PropertyTokens public bool ReadToken(Property property, XmlNode token) { - Vector2? result = ReadVector2(token); - bool success = result.HasValue; + Vector2 result = ReadVector2(token); + bool success = (result != null); if (success) { property.Type = PropertyType.Vector2; - property.Value = result.Value; + property.Value = result; } return success; diff --git a/XmlFormat/PropertyTokens/Vector3.cs b/XmlFormat/PropertyTokens/Vector3.cs index 5081998..feda2b4 100644 --- a/XmlFormat/PropertyTokens/Vector3.cs +++ b/XmlFormat/PropertyTokens/Vector3.cs @@ -8,7 +8,7 @@ namespace RobloxFiles.XmlFormat.PropertyTokens public string Token => "Vector3"; private static string[] Coords = new string[3] { "X", "Y", "Z" }; - public static Vector3? ReadVector3(XmlNode token) + public static Vector3 ReadVector3(XmlNode token) { float[] xyz = new float[3]; @@ -32,13 +32,13 @@ namespace RobloxFiles.XmlFormat.PropertyTokens public bool ReadToken(Property property, XmlNode token) { - Vector3? result = ReadVector3(token); - bool success = result.HasValue; + Vector3 result = ReadVector3(token); + bool success = (result != null); if (success) { property.Type = PropertyType.Vector3; - property.Value = result.Value; + property.Value = result; } return success; diff --git a/XmlFormat/XmlRobloxFile.cs b/XmlFormat/XmlRobloxFile.cs index 2f41d3b..519506a 100644 --- a/XmlFormat/XmlRobloxFile.cs +++ b/XmlFormat/XmlRobloxFile.cs @@ -26,7 +26,7 @@ namespace RobloxFiles.XmlFormat } catch { - throw new Exception("XmlRobloxFile: Could not read XML!"); + throw new Exception("XmlRobloxFile: Could not read provided buffer as XML!"); } XmlNode roblox = Root.FirstChild; diff --git a/packages.config b/packages.config deleted file mode 100644 index 161ecfd..0000000 --- a/packages.config +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file