Add support for Attributes!
This commit is contained in:
@ -1,32 +0,0 @@
|
||||
using System.Xml;
|
||||
using RobloxFiles.DataTypes;
|
||||
|
||||
namespace RobloxFiles.XmlFormat.PropertyTokens
|
||||
{
|
||||
public class AxesToken : IXmlPropertyToken
|
||||
{
|
||||
public string Token => "Axes";
|
||||
|
||||
public bool ReadProperty(Property prop, XmlNode token)
|
||||
{
|
||||
if (XmlPropertyTokens.ReadPropertyGeneric(token, out uint value))
|
||||
{
|
||||
Axes axes = (Axes)value;
|
||||
prop.Value = axes;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void WriteProperty(Property prop, XmlDocument doc, XmlNode node)
|
||||
{
|
||||
XmlElement axes = doc.CreateElement("axes");
|
||||
node.AppendChild(axes);
|
||||
|
||||
int value = prop.CastValue<int>();
|
||||
axes.InnerText = value.ToInvariantString();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
using System;
|
||||
using System.Xml;
|
||||
|
||||
namespace RobloxFiles.XmlFormat.PropertyTokens
|
||||
{
|
||||
public class BinaryStringToken : IXmlPropertyToken
|
||||
{
|
||||
public string Token => "BinaryString";
|
||||
|
||||
public bool ReadProperty(Property prop, XmlNode token)
|
||||
{
|
||||
// BinaryStrings are encoded in base64
|
||||
string base64 = token.InnerText.Replace("\n", "");
|
||||
byte[] buffer = Convert.FromBase64String(base64);
|
||||
|
||||
prop.Value = buffer;
|
||||
prop.RawBuffer = buffer;
|
||||
prop.Type = PropertyType.String;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void WriteProperty(Property prop, XmlDocument doc, XmlNode node)
|
||||
{
|
||||
byte[] data = prop.RawBuffer;
|
||||
string value = Convert.ToBase64String(data);
|
||||
|
||||
if (value.Length > 72)
|
||||
{
|
||||
string buffer = "";
|
||||
|
||||
while (value.Length > 72)
|
||||
{
|
||||
string chunk = value.Substring(0, 72);
|
||||
value = value.Substring(72);
|
||||
buffer += chunk + '\n';
|
||||
}
|
||||
|
||||
value = buffer + value;
|
||||
}
|
||||
|
||||
XmlCDataSection cdata = doc.CreateCDataSection(value);
|
||||
node.AppendChild(cdata);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
using System.Xml;
|
||||
|
||||
namespace RobloxFiles.XmlFormat.PropertyTokens
|
||||
{
|
||||
public class BoolToken : IXmlPropertyToken
|
||||
{
|
||||
public string Token => "bool";
|
||||
|
||||
public bool ReadProperty(Property prop, XmlNode token)
|
||||
{
|
||||
return XmlPropertyTokens.ReadPropertyGeneric<bool>(prop, PropertyType.Bool, token);
|
||||
}
|
||||
|
||||
public void WriteProperty(Property prop, XmlDocument doc, XmlNode node)
|
||||
{
|
||||
string boolString = prop.Value
|
||||
.ToString()
|
||||
.ToLower();
|
||||
|
||||
node.InnerText = boolString;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,39 +0,0 @@
|
||||
using System;
|
||||
using System.Xml;
|
||||
using RobloxFiles.DataTypes;
|
||||
|
||||
namespace RobloxFiles.XmlFormat.PropertyTokens
|
||||
{
|
||||
public class BrickColorToken : IXmlPropertyToken
|
||||
{
|
||||
public string Token => "BrickColor";
|
||||
// ^ This is a lie: The token is actually int, but that would cause a name collision.
|
||||
// Since BrickColors are written as ints, the IntToken class will try to redirect
|
||||
// to this handler if it believes that its representing a BrickColor.
|
||||
|
||||
public bool ReadProperty(Property prop, XmlNode token)
|
||||
{
|
||||
if (XmlPropertyTokens.ReadPropertyGeneric(token, out int value))
|
||||
{
|
||||
BrickColor brickColor = BrickColor.FromNumber(value);
|
||||
prop.XmlToken = "BrickColor";
|
||||
prop.Value = brickColor;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void WriteProperty(Property prop, XmlDocument doc, XmlNode node)
|
||||
{
|
||||
BrickColor value = prop.CastValue<BrickColor>();
|
||||
|
||||
XmlElement brickColor = doc.CreateElement("int");
|
||||
brickColor.InnerText = value.Number.ToInvariantString();
|
||||
|
||||
brickColor.SetAttribute("name", prop.Name);
|
||||
brickColor.AppendChild(node);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,64 +0,0 @@
|
||||
using System.Xml;
|
||||
using RobloxFiles.DataTypes;
|
||||
|
||||
namespace RobloxFiles.XmlFormat.PropertyTokens
|
||||
{
|
||||
public class CFrameToken : IXmlPropertyToken
|
||||
{
|
||||
public string Token => "CoordinateFrame; CFrame";
|
||||
private static string[] Coords = new string[12] { "X", "Y", "Z", "R00", "R01", "R02", "R10", "R11", "R12", "R20", "R21", "R22"};
|
||||
|
||||
public static CFrame ReadCFrame(XmlNode token)
|
||||
{
|
||||
float[] components = new float[12];
|
||||
|
||||
for (int i = 0; i < 12; i++)
|
||||
{
|
||||
string key = Coords[i];
|
||||
|
||||
try
|
||||
{
|
||||
var coord = token[key];
|
||||
components[i] = Formatting.ParseFloat(coord.InnerText);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return new CFrame(components);
|
||||
}
|
||||
|
||||
public bool ReadProperty(Property prop, XmlNode token)
|
||||
{
|
||||
CFrame result = ReadCFrame(token);
|
||||
bool success = (result != null);
|
||||
|
||||
if (success)
|
||||
{
|
||||
prop.Type = PropertyType.CFrame;
|
||||
prop.Value = result;
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
public void WriteProperty(Property prop, XmlDocument doc, XmlNode node)
|
||||
{
|
||||
CFrame cf = prop.CastValue<CFrame>();
|
||||
float[] components = cf.GetComponents();
|
||||
|
||||
for (int i = 0; i < 12; i++)
|
||||
{
|
||||
string coordName = Coords[i];
|
||||
float coordValue = components[i];
|
||||
|
||||
XmlElement coord = doc.CreateElement(coordName);
|
||||
coord.InnerText = coordValue.ToInvariantString();
|
||||
|
||||
node.AppendChild(coord);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,77 +0,0 @@
|
||||
using System;
|
||||
using System.Xml;
|
||||
using RobloxFiles.DataTypes;
|
||||
|
||||
namespace RobloxFiles.XmlFormat.PropertyTokens
|
||||
{
|
||||
public class Color3Token : IXmlPropertyToken
|
||||
{
|
||||
public string Token => "Color3";
|
||||
private readonly string[] Fields = new string[3] { "R", "G", "B" };
|
||||
|
||||
public bool ReadProperty(Property prop, XmlNode token)
|
||||
{
|
||||
bool success = true;
|
||||
float[] fields = new float[Fields.Length];
|
||||
|
||||
for (int i = 0; i < fields.Length; i++)
|
||||
{
|
||||
string key = Fields[i];
|
||||
|
||||
try
|
||||
{
|
||||
var coord = token[key];
|
||||
string text = coord?.InnerText;
|
||||
|
||||
if (text == null)
|
||||
{
|
||||
text = "0";
|
||||
success = false;
|
||||
}
|
||||
|
||||
fields[i] = Formatting.ParseFloat(text);
|
||||
}
|
||||
catch
|
||||
{
|
||||
success = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (success)
|
||||
{
|
||||
float r = fields[0],
|
||||
g = fields[1],
|
||||
b = fields[2];
|
||||
|
||||
prop.Type = PropertyType.Color3;
|
||||
prop.Value = new Color3(r, g, b);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Try falling back to the Color3uint8 technique...
|
||||
var color3uint8 = XmlPropertyTokens.GetHandler<Color3uint8Token>();
|
||||
success = color3uint8.ReadProperty(prop, token);
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
public void WriteProperty(Property prop, XmlDocument doc, XmlNode node)
|
||||
{
|
||||
Color3 color = prop.CastValue<Color3>();
|
||||
float[] rgb = new float[3] { color.R, color.G, color.B };
|
||||
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
string field = Fields[i];
|
||||
float value = rgb[i];
|
||||
|
||||
XmlElement channel = doc.CreateElement(field);
|
||||
channel.InnerText = value.ToInvariantString();
|
||||
|
||||
node.AppendChild(channel);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
using System.Xml;
|
||||
using RobloxFiles.DataTypes;
|
||||
using System.Diagnostics.Contracts;
|
||||
using System;
|
||||
|
||||
namespace RobloxFiles.XmlFormat.PropertyTokens
|
||||
{
|
||||
public class Color3uint8Token : IXmlPropertyToken
|
||||
{
|
||||
public string Token => "Color3uint8";
|
||||
|
||||
public bool ReadProperty(Property prop, XmlNode token)
|
||||
{
|
||||
if (XmlPropertyTokens.ReadPropertyGeneric(token, out uint value))
|
||||
{
|
||||
uint r = (value >> 16) & 0xFF;
|
||||
uint g = (value >> 8) & 0xFF;
|
||||
uint b = value & 0xFF;
|
||||
|
||||
Color3uint8 result = Color3.FromRGB(r, g, b);
|
||||
prop.Value = result;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void WriteProperty(Property prop, XmlDocument doc, XmlNode node)
|
||||
{
|
||||
Color3uint8 color = prop?.CastValue<Color3uint8>();
|
||||
Contract.Requires(node != null);
|
||||
|
||||
|
||||
uint r = color.R,
|
||||
g = color.G,
|
||||
b = color.B;
|
||||
|
||||
uint rgb = (255u << 24) | (r << 16) | (g << 8) | b;
|
||||
node.InnerText = rgb.ToInvariantString();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,54 +0,0 @@
|
||||
using System.Xml;
|
||||
using RobloxFiles.DataTypes;
|
||||
|
||||
namespace RobloxFiles.XmlFormat.PropertyTokens
|
||||
{
|
||||
public class ColorSequenceToken : IXmlPropertyToken
|
||||
{
|
||||
public string Token => "ColorSequence";
|
||||
|
||||
public bool ReadProperty(Property prop, XmlNode token)
|
||||
{
|
||||
string contents = token.InnerText.Trim();
|
||||
string[] buffer = contents.Split(' ');
|
||||
|
||||
int length = buffer.Length;
|
||||
bool valid = (length % 5 == 0);
|
||||
|
||||
if (valid)
|
||||
{
|
||||
try
|
||||
{
|
||||
ColorSequenceKeypoint[] keypoints = new ColorSequenceKeypoint[length / 5];
|
||||
|
||||
for (int i = 0; i < length; i += 5)
|
||||
{
|
||||
float Time = Formatting.ParseFloat(buffer[i]);
|
||||
|
||||
float R = Formatting.ParseFloat(buffer[i + 1]);
|
||||
float G = Formatting.ParseFloat(buffer[i + 2]);
|
||||
float B = Formatting.ParseFloat(buffer[i + 3]);
|
||||
|
||||
Color3 Value = new Color3(R, G, B);
|
||||
keypoints[i / 5] = new ColorSequenceKeypoint(Time, Value);
|
||||
}
|
||||
|
||||
prop.Type = PropertyType.ColorSequence;
|
||||
prop.Value = new ColorSequence(keypoints);
|
||||
}
|
||||
catch
|
||||
{
|
||||
valid = false;
|
||||
}
|
||||
}
|
||||
|
||||
return valid;
|
||||
}
|
||||
|
||||
public void WriteProperty(Property prop, XmlDocument doc, XmlNode node)
|
||||
{
|
||||
ColorSequence value = prop.CastValue<ColorSequence>();
|
||||
node.InnerText = value.ToString() + ' ';
|
||||
}
|
||||
}
|
||||
}
|
@ -1,66 +0,0 @@
|
||||
using System;
|
||||
using System.Xml;
|
||||
|
||||
using RobloxFiles.DataTypes;
|
||||
|
||||
namespace RobloxFiles.XmlFormat.PropertyTokens
|
||||
{
|
||||
public class ContentToken : IXmlPropertyToken
|
||||
{
|
||||
public string Token => "Content";
|
||||
|
||||
public bool ReadProperty(Property prop, XmlNode token)
|
||||
{
|
||||
string data = token.InnerText;
|
||||
prop.Value = new Content(data);
|
||||
prop.Type = PropertyType.String;
|
||||
|
||||
if (token.HasChildNodes)
|
||||
{
|
||||
XmlNode childNode = token.FirstChild;
|
||||
string contentType = childNode.Name;
|
||||
|
||||
if (contentType.StartsWith("binary") || contentType == "hash")
|
||||
{
|
||||
try
|
||||
{
|
||||
// Roblox technically doesn't support this anymore, but load it anyway :P
|
||||
byte[] buffer = Convert.FromBase64String(data);
|
||||
prop.RawBuffer = buffer;
|
||||
}
|
||||
catch
|
||||
{
|
||||
RobloxFile.LogError($"ContentToken: Got illegal base64 string: {data}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void WriteProperty(Property prop, XmlDocument doc, XmlNode node)
|
||||
{
|
||||
string content = prop.CastValue<Content>();
|
||||
string type = "null";
|
||||
|
||||
if (prop.HasRawBuffer)
|
||||
type = "binary";
|
||||
else if (content.Length > 0)
|
||||
type = "url";
|
||||
|
||||
XmlElement contentType = doc.CreateElement(type);
|
||||
|
||||
if (type == "binary")
|
||||
{
|
||||
XmlCDataSection cdata = doc.CreateCDataSection(content);
|
||||
contentType.AppendChild(cdata);
|
||||
}
|
||||
else
|
||||
{
|
||||
contentType.InnerText = content;
|
||||
}
|
||||
|
||||
node.AppendChild(contentType);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
using System.Xml;
|
||||
|
||||
namespace RobloxFiles.XmlFormat.PropertyTokens
|
||||
{
|
||||
public class DoubleToken : IXmlPropertyToken
|
||||
{
|
||||
public string Token => "double";
|
||||
|
||||
public bool ReadProperty(Property prop, XmlNode token)
|
||||
{
|
||||
return XmlPropertyTokens.ReadPropertyGeneric<double>(prop, PropertyType.Double, token);
|
||||
}
|
||||
|
||||
public void WriteProperty(Property prop, XmlDocument doc, XmlNode node)
|
||||
{
|
||||
double value = prop.CastValue<double>();
|
||||
node.InnerText = value.ToInvariantString();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,49 +0,0 @@
|
||||
using System;
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Reflection;
|
||||
using System.Xml;
|
||||
|
||||
namespace RobloxFiles.XmlFormat.PropertyTokens
|
||||
{
|
||||
public class EnumToken : IXmlPropertyToken
|
||||
{
|
||||
public string Token => "token";
|
||||
|
||||
public bool ReadProperty(Property prop, XmlNode token)
|
||||
{
|
||||
Contract.Requires(prop != null);
|
||||
|
||||
if (XmlPropertyTokens.ReadPropertyGeneric(token, out uint value))
|
||||
{
|
||||
Instance inst = prop.Instance;
|
||||
Type instType = inst?.GetType();
|
||||
|
||||
FieldInfo info = instType.GetField(prop.Name, Property.BindingFlags);
|
||||
|
||||
if (info != null)
|
||||
{
|
||||
Type enumType = info.FieldType;
|
||||
string item = value.ToInvariantString();
|
||||
|
||||
prop.Type = PropertyType.Enum;
|
||||
prop.Value = Enum.Parse(enumType, item);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void WriteProperty(Property prop, XmlDocument doc, XmlNode node)
|
||||
{
|
||||
Contract.Requires(prop != null && node != null);
|
||||
object rawValue = prop.Value;
|
||||
|
||||
int signed = (int)rawValue;
|
||||
uint value = (uint)signed;
|
||||
|
||||
node.InnerText = value.ToInvariantString();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Xml;
|
||||
using RobloxFiles.DataTypes;
|
||||
|
||||
namespace RobloxFiles.XmlFormat.PropertyTokens
|
||||
{
|
||||
public class FacesToken : IXmlPropertyToken
|
||||
{
|
||||
public string Token => "Faces";
|
||||
|
||||
public bool ReadProperty(Property prop, XmlNode token)
|
||||
{
|
||||
Contract.Requires(prop != null);
|
||||
|
||||
if (XmlPropertyTokens.ReadPropertyGeneric(token, out uint value))
|
||||
{
|
||||
Faces faces = (Faces)value;
|
||||
prop.Value = faces;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void WriteProperty(Property prop, XmlDocument doc, XmlNode node)
|
||||
{
|
||||
Contract.Requires(prop != null && doc != null && node != null);
|
||||
|
||||
XmlElement faces = doc.CreateElement("faces");
|
||||
node.AppendChild(faces);
|
||||
|
||||
int value = prop.CastValue<int>();
|
||||
faces.InnerText = value.ToInvariantString();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
using System.Xml;
|
||||
|
||||
namespace RobloxFiles.XmlFormat.PropertyTokens
|
||||
{
|
||||
public class FloatToken : IXmlPropertyToken
|
||||
{
|
||||
public string Token => "float";
|
||||
|
||||
public bool ReadProperty(Property prop, XmlNode token)
|
||||
{
|
||||
return XmlPropertyTokens.ReadPropertyGeneric<float>(prop, PropertyType.Float, token);
|
||||
}
|
||||
|
||||
public void WriteProperty(Property prop, XmlDocument doc, XmlNode node)
|
||||
{
|
||||
float value = prop.CastValue<float>();
|
||||
node.InnerText = value.ToInvariantString();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
using System.Xml;
|
||||
|
||||
namespace RobloxFiles.XmlFormat.PropertyTokens
|
||||
{
|
||||
public class IntToken : IXmlPropertyToken
|
||||
{
|
||||
public string Token => "int";
|
||||
|
||||
public bool ReadProperty(Property prop, XmlNode token)
|
||||
{
|
||||
// BrickColors are represented by ints, see if
|
||||
// we can infer when they should be a BrickColor.
|
||||
|
||||
if (prop.Name.Contains("Color") || prop.Instance.ClassName.Contains("Color"))
|
||||
{
|
||||
var brickColorToken = XmlPropertyTokens.GetHandler<BrickColorToken>();
|
||||
return brickColorToken.ReadProperty(prop, token);
|
||||
}
|
||||
else
|
||||
{
|
||||
return XmlPropertyTokens.ReadPropertyGeneric<int>(prop, PropertyType.Int, token);
|
||||
}
|
||||
}
|
||||
|
||||
public void WriteProperty(Property prop, XmlDocument doc, XmlNode node)
|
||||
{
|
||||
int value = prop.CastValue<int>();
|
||||
node.InnerText = value.ToInvariantString();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
using System.Xml;
|
||||
|
||||
namespace RobloxFiles.XmlFormat.PropertyTokens
|
||||
{
|
||||
public class Int64Token : IXmlPropertyToken
|
||||
{
|
||||
public string Token => "int64";
|
||||
|
||||
public bool ReadProperty(Property prop, XmlNode token)
|
||||
{
|
||||
return XmlPropertyTokens.ReadPropertyGeneric<long>(prop, PropertyType.Int64, token);
|
||||
}
|
||||
|
||||
public void WriteProperty(Property prop, XmlDocument doc, XmlNode node)
|
||||
{
|
||||
long value = prop.CastValue<long>();
|
||||
node.InnerText = value.ToString();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,42 +0,0 @@
|
||||
using System;
|
||||
using System.Xml;
|
||||
using RobloxFiles.DataTypes;
|
||||
|
||||
namespace RobloxFiles.XmlFormat.PropertyTokens
|
||||
{
|
||||
public class NumberRangeToken : IXmlPropertyToken
|
||||
{
|
||||
public string Token => "NumberRange";
|
||||
|
||||
public bool ReadProperty(Property prop, XmlNode token)
|
||||
{
|
||||
string contents = token.InnerText.Trim();
|
||||
string[] buffer = contents.Split(' ');
|
||||
bool valid = (buffer.Length == 2);
|
||||
|
||||
if (valid)
|
||||
{
|
||||
try
|
||||
{
|
||||
float min = Formatting.ParseFloat(buffer[0]);
|
||||
float max = Formatting.ParseFloat(buffer[1]);
|
||||
|
||||
prop.Type = PropertyType.NumberRange;
|
||||
prop.Value = new NumberRange(min, max);
|
||||
}
|
||||
catch
|
||||
{
|
||||
valid = false;
|
||||
}
|
||||
}
|
||||
|
||||
return valid;
|
||||
}
|
||||
|
||||
public void WriteProperty(Property prop, XmlDocument doc, XmlNode node)
|
||||
{
|
||||
NumberRange value = prop.CastValue<NumberRange>();
|
||||
node.InnerText = value.ToString() + ' ';
|
||||
}
|
||||
}
|
||||
}
|
@ -1,51 +0,0 @@
|
||||
using System.Xml;
|
||||
using RobloxFiles.DataTypes;
|
||||
|
||||
namespace RobloxFiles.XmlFormat.PropertyTokens
|
||||
{
|
||||
public class NumberSequenceToken : IXmlPropertyToken
|
||||
{
|
||||
public string Token => "NumberSequence";
|
||||
|
||||
public bool ReadProperty(Property prop, XmlNode token)
|
||||
{
|
||||
string contents = token.InnerText.Trim();
|
||||
string[] buffer = contents.Split(' ');
|
||||
|
||||
int length = buffer.Length;
|
||||
bool valid = (length % 3 == 0);
|
||||
|
||||
if (valid)
|
||||
{
|
||||
try
|
||||
{
|
||||
NumberSequenceKeypoint[] keypoints = new NumberSequenceKeypoint[length / 3];
|
||||
|
||||
for (int i = 0; i < length; i += 3)
|
||||
{
|
||||
float Time = Formatting.ParseFloat(buffer[ i ]);
|
||||
float Value = Formatting.ParseFloat(buffer[i + 1]);
|
||||
float Envelope = Formatting.ParseFloat(buffer[i + 2]);
|
||||
|
||||
keypoints[i / 3] = new NumberSequenceKeypoint(Time, Value, Envelope);
|
||||
}
|
||||
|
||||
prop.Type = PropertyType.NumberSequence;
|
||||
prop.Value = new NumberSequence(keypoints);
|
||||
}
|
||||
catch
|
||||
{
|
||||
valid = false;
|
||||
}
|
||||
}
|
||||
|
||||
return valid;
|
||||
}
|
||||
|
||||
public void WriteProperty(Property prop, XmlDocument doc, XmlNode node)
|
||||
{
|
||||
NumberSequence value = prop.CastValue<NumberSequence>();
|
||||
node.InnerText = value.ToString() + ' ';
|
||||
}
|
||||
}
|
||||
}
|
@ -1,87 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Xml;
|
||||
using RobloxFiles.DataTypes;
|
||||
|
||||
namespace RobloxFiles.XmlFormat.PropertyTokens
|
||||
{
|
||||
public class PhysicalPropertiesToken : IXmlPropertyToken
|
||||
{
|
||||
public string Token => "PhysicalProperties";
|
||||
|
||||
private Func<string, T> createReader<T>(Func<string, T> parse, XmlNode token) where T : struct
|
||||
{
|
||||
return new Func<string, T>(key =>
|
||||
{
|
||||
XmlElement node = token[key];
|
||||
return parse(node.InnerText);
|
||||
});
|
||||
}
|
||||
|
||||
public bool ReadProperty(Property prop, XmlNode token)
|
||||
{
|
||||
var readBool = createReader(bool.Parse, token);
|
||||
var readFloat = createReader(Formatting.ParseFloat, token);
|
||||
|
||||
try
|
||||
{
|
||||
bool custom = readBool("CustomPhysics");
|
||||
prop.Type = PropertyType.PhysicalProperties;
|
||||
|
||||
if (custom)
|
||||
{
|
||||
prop.Value = new PhysicalProperties
|
||||
(
|
||||
readFloat("Density"),
|
||||
readFloat("Friction"),
|
||||
readFloat("Elasticity"),
|
||||
readFloat("FrictionWeight"),
|
||||
readFloat("ElasticityWeight")
|
||||
);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void WriteProperty(Property prop, XmlDocument doc, XmlNode node)
|
||||
{
|
||||
bool hasCustomPhysics = (prop.Value != null);
|
||||
|
||||
XmlElement customPhysics = doc.CreateElement("CustomPhysics");
|
||||
customPhysics.InnerText = hasCustomPhysics
|
||||
.ToString()
|
||||
.ToLower();
|
||||
|
||||
node.AppendChild(customPhysics);
|
||||
|
||||
if (hasCustomPhysics)
|
||||
{
|
||||
var customProps = prop.CastValue<PhysicalProperties>();
|
||||
|
||||
var data = new Dictionary<string, float>()
|
||||
{
|
||||
{ "Density", customProps.Density },
|
||||
{ "Friction", customProps.Friction },
|
||||
{ "Elasticity", customProps.Elasticity },
|
||||
{ "FrictionWeight", customProps.FrictionWeight },
|
||||
{ "ElasticityWeight", customProps.ElasticityWeight }
|
||||
};
|
||||
|
||||
foreach (string elementType in data.Keys)
|
||||
{
|
||||
float value = data[elementType];
|
||||
|
||||
XmlElement element = doc.CreateElement(elementType);
|
||||
element.InnerText = value.ToInvariantString();
|
||||
|
||||
node.AppendChild(element);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,45 +0,0 @@
|
||||
using System.Text;
|
||||
using System.Xml;
|
||||
using RobloxFiles.DataTypes;
|
||||
|
||||
namespace RobloxFiles.XmlFormat.PropertyTokens
|
||||
{
|
||||
public class ProtectedStringToken : IXmlPropertyToken
|
||||
{
|
||||
public string Token => "ProtectedString";
|
||||
|
||||
public bool ReadProperty(Property prop, XmlNode token)
|
||||
{
|
||||
ProtectedString contents = token.InnerText;
|
||||
prop.Type = PropertyType.ProtectedString;
|
||||
prop.Value = contents;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void WriteProperty(Property prop, XmlDocument doc, XmlNode node)
|
||||
{
|
||||
ProtectedString value = prop.CastValue<ProtectedString>();
|
||||
|
||||
if (value.IsCompiled)
|
||||
{
|
||||
var binary = XmlPropertyTokens.GetHandler<BinaryStringToken>();
|
||||
binary.WriteProperty(prop, doc, node);
|
||||
}
|
||||
else
|
||||
{
|
||||
string contents = Encoding.UTF8.GetString(value.RawBuffer);
|
||||
|
||||
if (contents.Contains("\r") || contents.Contains("\n"))
|
||||
{
|
||||
XmlCDataSection cdata = doc.CreateCDataSection(contents);
|
||||
node.AppendChild(cdata);
|
||||
}
|
||||
else
|
||||
{
|
||||
node.InnerText = contents;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,54 +0,0 @@
|
||||
using System;
|
||||
using System.Xml;
|
||||
using RobloxFiles.DataTypes;
|
||||
|
||||
namespace RobloxFiles.XmlFormat.PropertyTokens
|
||||
{
|
||||
public class RayToken : IXmlPropertyToken
|
||||
{
|
||||
public string Token => "Ray";
|
||||
private static string[] Fields = new string[2] { "origin", "direction" };
|
||||
|
||||
public bool ReadProperty(Property prop, XmlNode token)
|
||||
{
|
||||
try
|
||||
{
|
||||
Vector3[] read = new Vector3[Fields.Length];
|
||||
|
||||
for (int i = 0; i < read.Length; i++)
|
||||
{
|
||||
string field = Fields[i];
|
||||
var fieldToken = token[field];
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
public void WriteProperty(Property prop, XmlDocument doc, XmlNode node)
|
||||
{
|
||||
Ray ray = prop.CastValue<Ray>();
|
||||
|
||||
XmlElement origin = doc.CreateElement("origin");
|
||||
XmlElement direction = doc.CreateElement("direction");
|
||||
|
||||
Vector3Token.WriteVector3(doc, origin, ray.Origin);
|
||||
Vector3Token.WriteVector3(doc, direction, ray.Direction);
|
||||
|
||||
node.AppendChild(origin);
|
||||
node.AppendChild(direction);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,53 +0,0 @@
|
||||
using System;
|
||||
using System.Xml;
|
||||
using RobloxFiles.DataTypes;
|
||||
|
||||
namespace RobloxFiles.XmlFormat.PropertyTokens
|
||||
{
|
||||
public class RectToken : IXmlPropertyToken
|
||||
{
|
||||
public string Token => "Rect2D";
|
||||
private static string[] Fields = new string[2] { "min", "max" };
|
||||
|
||||
public bool ReadProperty(Property prop, XmlNode token)
|
||||
{
|
||||
try
|
||||
{
|
||||
Vector2[] read = new Vector2[Fields.Length];
|
||||
|
||||
for (int i = 0; i < read.Length; i++)
|
||||
{
|
||||
string field = Fields[i];
|
||||
var fieldToken = token[field];
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
public void WriteProperty(Property prop, XmlDocument doc, XmlNode node)
|
||||
{
|
||||
Rect rect = prop.CastValue<Rect>();
|
||||
|
||||
XmlElement min = doc.CreateElement("min");
|
||||
Vector2Token.WriteVector2(doc, min, rect.Min);
|
||||
node.AppendChild(min);
|
||||
|
||||
XmlElement max = doc.CreateElement("max");
|
||||
Vector2Token.WriteVector2(doc, max, rect.Max);
|
||||
node.AppendChild(max);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
using System.Xml;
|
||||
|
||||
namespace RobloxFiles.XmlFormat.PropertyTokens
|
||||
{
|
||||
public class RefToken : IXmlPropertyToken
|
||||
{
|
||||
public string Token => "Ref";
|
||||
|
||||
public bool ReadProperty(Property prop, XmlNode token)
|
||||
{
|
||||
string refId = token.InnerText;
|
||||
prop.Type = PropertyType.Ref;
|
||||
prop.XmlToken = refId;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void WriteProperty(Property prop, XmlDocument doc, XmlNode node)
|
||||
{
|
||||
string result = "null";
|
||||
|
||||
if (prop.Value != null)
|
||||
{
|
||||
Instance inst = prop.CastValue<Instance>();
|
||||
result = inst.Referent;
|
||||
}
|
||||
|
||||
node.InnerText = result;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
using System.Xml;
|
||||
using RobloxFiles.DataTypes;
|
||||
|
||||
namespace RobloxFiles.XmlFormat.PropertyTokens
|
||||
{
|
||||
public class SharedStringToken : IXmlPropertyToken
|
||||
{
|
||||
public string Token => "SharedString";
|
||||
|
||||
public bool ReadProperty(Property prop, XmlNode token)
|
||||
{
|
||||
string key = token.InnerText;
|
||||
prop.Type = PropertyType.SharedString;
|
||||
prop.Value = new SharedString(key);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void WriteProperty(Property prop, XmlDocument doc, XmlNode node)
|
||||
{
|
||||
var value = prop.Value as SharedString;
|
||||
|
||||
if (value != null)
|
||||
{
|
||||
string key = value.Key;
|
||||
|
||||
if (value.ComputedKey == null)
|
||||
{
|
||||
var newShared = SharedString.FromBuffer(value.SharedValue);
|
||||
key = newShared.ComputedKey;
|
||||
}
|
||||
|
||||
node.InnerText = key;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
using System.Xml;
|
||||
|
||||
namespace RobloxFiles.XmlFormat.PropertyTokens
|
||||
{
|
||||
public class StringToken : IXmlPropertyToken
|
||||
{
|
||||
public string Token => "string";
|
||||
|
||||
public bool ReadProperty(Property prop, XmlNode token)
|
||||
{
|
||||
string contents = token.InnerText;
|
||||
prop.Type = PropertyType.String;
|
||||
prop.Value = contents;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void WriteProperty(Property prop, XmlDocument doc, XmlNode node)
|
||||
{
|
||||
string value = prop.Value.ToInvariantString();
|
||||
|
||||
if (value.Contains("\r") || value.Contains("\n"))
|
||||
{
|
||||
XmlCDataSection cdata = doc.CreateCDataSection(value);
|
||||
node.AppendChild(cdata);
|
||||
}
|
||||
else
|
||||
{
|
||||
node.InnerText = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,60 +0,0 @@
|
||||
using System;
|
||||
using System.Xml;
|
||||
using RobloxFiles.DataTypes;
|
||||
|
||||
namespace RobloxFiles.XmlFormat.PropertyTokens
|
||||
{
|
||||
public class UDimToken : IXmlPropertyToken
|
||||
{
|
||||
public string Token => "UDim";
|
||||
|
||||
public static UDim ReadUDim(XmlNode token, string prefix = "")
|
||||
{
|
||||
try
|
||||
{
|
||||
XmlElement scaleToken = token[prefix + 'S'];
|
||||
float scale = Formatting.ParseFloat(scaleToken.InnerText);
|
||||
|
||||
XmlElement offsetToken = token[prefix + 'O'];
|
||||
int offset = int.Parse(offsetToken.InnerText);
|
||||
|
||||
return new UDim(scale, offset);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static void WriteUDim(XmlDocument doc, XmlNode node, UDim value, string prefix = "")
|
||||
{
|
||||
XmlElement scale = doc.CreateElement(prefix + 'S');
|
||||
scale.InnerText = value.Scale.ToInvariantString();
|
||||
node.AppendChild(scale);
|
||||
|
||||
XmlElement offset = doc.CreateElement(prefix + 'O');
|
||||
offset.InnerText = value.Offset.ToInvariantString();
|
||||
node.AppendChild(offset);
|
||||
}
|
||||
|
||||
public bool ReadProperty(Property property, XmlNode token)
|
||||
{
|
||||
UDim result = ReadUDim(token);
|
||||
bool success = (result != null);
|
||||
|
||||
if (success)
|
||||
{
|
||||
property.Type = PropertyType.UDim;
|
||||
property.Value = result;
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
public void WriteProperty(Property prop, XmlDocument doc, XmlNode node)
|
||||
{
|
||||
UDim value = prop.CastValue<UDim>();
|
||||
WriteUDim(doc, node, value);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
using System;
|
||||
using System.Xml;
|
||||
using RobloxFiles.DataTypes;
|
||||
|
||||
namespace RobloxFiles.XmlFormat.PropertyTokens
|
||||
{
|
||||
public class UDim2Token : IXmlPropertyToken
|
||||
{
|
||||
public string Token => "UDim2";
|
||||
|
||||
public bool ReadProperty(Property property, XmlNode token)
|
||||
{
|
||||
UDim xUDim = UDimToken.ReadUDim(token, "X");
|
||||
UDim yUDim = UDimToken.ReadUDim(token, "Y");
|
||||
|
||||
if (xUDim != null && yUDim != null)
|
||||
{
|
||||
property.Type = PropertyType.UDim2;
|
||||
property.Value = new UDim2(xUDim, yUDim);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void WriteProperty(Property prop, XmlDocument doc, XmlNode node)
|
||||
{
|
||||
UDim2 value = prop.CastValue<UDim2>();
|
||||
|
||||
UDim xUDim = value.X;
|
||||
UDimToken.WriteUDim(doc, node, xUDim, "X");
|
||||
|
||||
UDim yUDim = value.Y;
|
||||
UDimToken.WriteUDim(doc, node, yUDim, "Y");
|
||||
}
|
||||
}
|
||||
}
|
@ -1,65 +0,0 @@
|
||||
using System.Xml;
|
||||
using RobloxFiles.DataTypes;
|
||||
|
||||
namespace RobloxFiles.XmlFormat.PropertyTokens
|
||||
{
|
||||
public class Vector2Token : IXmlPropertyToken
|
||||
{
|
||||
public string Token => "Vector2";
|
||||
private static string[] Coords = new string[2] { "X", "Y" };
|
||||
|
||||
public static Vector2 ReadVector2(XmlNode token)
|
||||
{
|
||||
float[] xy = new float[2];
|
||||
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
string key = Coords[i];
|
||||
|
||||
try
|
||||
{
|
||||
var coord = token[key];
|
||||
string text = coord.InnerText;
|
||||
xy[i] = Formatting.ParseFloat(text);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return new Vector2(xy);
|
||||
}
|
||||
|
||||
public static void WriteVector2(XmlDocument doc, XmlNode node, Vector2 value)
|
||||
{
|
||||
XmlElement x = doc.CreateElement("X");
|
||||
x.InnerText = value.X.ToInvariantString();
|
||||
node.AppendChild(x);
|
||||
|
||||
XmlElement y = doc.CreateElement("Y");
|
||||
y.InnerText = value.Y.ToInvariantString();
|
||||
node.AppendChild(y);
|
||||
}
|
||||
|
||||
public bool ReadProperty(Property property, XmlNode token)
|
||||
{
|
||||
Vector2 result = ReadVector2(token);
|
||||
bool success = (result != null);
|
||||
|
||||
if (success)
|
||||
{
|
||||
property.Type = PropertyType.Vector2;
|
||||
property.Value = result;
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
public void WriteProperty(Property prop, XmlDocument doc, XmlNode node)
|
||||
{
|
||||
Vector2 value = prop.CastValue<Vector2>();
|
||||
WriteVector2(doc, node, value);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,69 +0,0 @@
|
||||
using System;
|
||||
using System.Xml;
|
||||
using RobloxFiles.DataTypes;
|
||||
|
||||
namespace RobloxFiles.XmlFormat.PropertyTokens
|
||||
{
|
||||
public class Vector3Token : IXmlPropertyToken
|
||||
{
|
||||
public string Token => "Vector3";
|
||||
private static string[] Coords = new string[3] { "X", "Y", "Z" };
|
||||
|
||||
public static Vector3 ReadVector3(XmlNode token)
|
||||
{
|
||||
float[] xyz = new float[3];
|
||||
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
string key = Coords[i];
|
||||
|
||||
try
|
||||
{
|
||||
var coord = token[key];
|
||||
xyz[i] = Formatting.ParseFloat(coord.InnerText);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return new Vector3(xyz);
|
||||
}
|
||||
|
||||
public static void WriteVector3(XmlDocument doc, XmlNode node, Vector3 value)
|
||||
{
|
||||
XmlElement x = doc.CreateElement("X");
|
||||
x.InnerText = value.X.ToInvariantString();
|
||||
node.AppendChild(x);
|
||||
|
||||
XmlElement y = doc.CreateElement("Y");
|
||||
y.InnerText = value.Y.ToInvariantString();
|
||||
node.AppendChild(y);
|
||||
|
||||
XmlElement z = doc.CreateElement("Z");
|
||||
z.InnerText = value.Z.ToInvariantString();
|
||||
node.AppendChild(z);
|
||||
}
|
||||
|
||||
public bool ReadProperty(Property property, XmlNode token)
|
||||
{
|
||||
Vector3 result = ReadVector3(token);
|
||||
bool success = (result != null);
|
||||
|
||||
if (success)
|
||||
{
|
||||
property.Type = PropertyType.Vector3;
|
||||
property.Value = result;
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
public void WriteProperty(Property prop, XmlDocument doc, XmlNode node)
|
||||
{
|
||||
Vector3 value = prop.CastValue<Vector3>();
|
||||
WriteVector3(doc, node, value);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,57 +0,0 @@
|
||||
using System.Xml;
|
||||
using RobloxFiles.DataTypes;
|
||||
|
||||
namespace RobloxFiles.XmlFormat.PropertyTokens
|
||||
{
|
||||
public class Vector3int16Token : IXmlPropertyToken
|
||||
{
|
||||
public string Token => "Vector3int16";
|
||||
private static string[] Coords = new string[3] { "X", "Y", "Z" };
|
||||
|
||||
public bool ReadProperty(Property property, XmlNode token)
|
||||
{
|
||||
short[] xyz = new short[3];
|
||||
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
string key = Coords[i];
|
||||
|
||||
try
|
||||
{
|
||||
var coord = token[key];
|
||||
xyz[i] = short.Parse(coord.InnerText);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
short x = xyz[0],
|
||||
y = xyz[1],
|
||||
z = xyz[2];
|
||||
|
||||
property.Type = PropertyType.Vector3int16;
|
||||
property.Value = new Vector3int16(x, y, z);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void WriteProperty(Property prop, XmlDocument doc, XmlNode node)
|
||||
{
|
||||
Vector3int16 value = prop.CastValue<Vector3int16>();
|
||||
|
||||
XmlElement x = doc.CreateElement("X");
|
||||
x.InnerText = value.X.ToString();
|
||||
node.AppendChild(x);
|
||||
|
||||
XmlElement y = doc.CreateElement("Y");
|
||||
y.InnerText = value.Y.ToString();
|
||||
node.AppendChild(y);
|
||||
|
||||
XmlElement z = doc.CreateElement("Z");
|
||||
z.InnerText = value.Z.ToString();
|
||||
node.AppendChild(z);
|
||||
}
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@
|
||||
using System.Xml;
|
||||
|
||||
using RobloxFiles.DataTypes;
|
||||
using RobloxFiles.Tokens;
|
||||
|
||||
namespace RobloxFiles.XmlFormat
|
||||
{
|
@ -7,7 +7,7 @@ using System.Xml;
|
||||
|
||||
using RobloxFiles.DataTypes;
|
||||
using RobloxFiles.Utility;
|
||||
using RobloxFiles.XmlFormat.PropertyTokens;
|
||||
using RobloxFiles.Tokens;
|
||||
|
||||
namespace RobloxFiles.XmlFormat
|
||||
{
|
@ -5,6 +5,8 @@ using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Xml;
|
||||
|
||||
using RobloxFiles.Tokens;
|
||||
|
||||
namespace RobloxFiles.XmlFormat
|
||||
{
|
||||
public static class XmlPropertyTokens
|
||||
@ -27,7 +29,7 @@ namespace RobloxFiles.XmlFormat
|
||||
|
||||
foreach (IXmlPropertyToken propToken in propTokens)
|
||||
{
|
||||
var tokens = propToken.Token.Split(';')
|
||||
var tokens = propToken.XmlPropertyToken.Split(';')
|
||||
.Select(token => token.Trim())
|
||||
.ToList();
|
||||
|
||||
|
Reference in New Issue
Block a user