Bug fixes.

This commit is contained in:
Max
2022-12-27 06:36:50 -06:00
parent 7710cfba59
commit 4a360e4033
15 changed files with 126 additions and 64 deletions

View File

@ -1,12 +1,23 @@
using System.Xml;
using System;
using System.Runtime.Remoting.Messaging;
using System.Xml;
using RobloxFiles.DataTypes;
using RobloxFiles.Enums;
namespace RobloxFiles.Tokens
{
public class CFrameToken : IXmlPropertyToken
public class CFrameToken : IXmlPropertyToken, IAttributeToken<CFrame>
{
public string XmlPropertyToken => "CoordinateFrame; CFrame";
private static readonly string[] Coords = new string[12] { "X", "Y", "Z", "R00", "R01", "R02", "R10", "R11", "R12", "R20", "R21", "R22"};
public AttributeType AttributeType => AttributeType.CFrame;
private static readonly string[] Coords = new string[12]
{
"X", "Y", "Z",
"R00", "R01", "R02",
"R10", "R11", "R12",
"R20", "R21", "R22"
};
public static CFrame ReadCFrame(XmlNode token)
{
@ -65,5 +76,52 @@ namespace RobloxFiles.Tokens
CFrame value = prop.Value as CFrame;
WriteCFrame(value, doc, node);
}
public CFrame ReadAttribute(RbxAttribute attribute)
{
float x = attribute.ReadFloat(),
y = attribute.ReadFloat(),
z = attribute.ReadFloat();
var rawOrientId = attribute.ReadByte();
var pos = new Vector3(x, y, z);
if (rawOrientId > 0)
{
int orientId = (rawOrientId - 1) % 36;
return CFrame.FromOrientId(orientId) + pos;
}
else
{
float[] matrix = new float[12];
for (int i = 3; i < 12; i++)
matrix[i] = attribute.ReadFloat();
return new CFrame(matrix) + pos;
}
}
public void WriteAttribute(RbxAttribute attribute, CFrame value)
{
Vector3 pos = value.Position;
attribute.WriteFloat(pos.X);
attribute.WriteFloat(pos.Y);
attribute.WriteFloat(pos.Z);
int orientId = value.GetOrientId();
attribute.WriteByte((byte)(orientId + 1));
if (orientId == -1)
{
float[] components = value.GetComponents();
for (int i = 3; i < 12; i++)
{
float component = components[i];
attribute.WriteFloat(component);
}
}
}
}
}

View File

@ -1,8 +1,8 @@
using System;
using System.Diagnostics.Contracts;
using System.Reflection;
using System.Xml;
using RobloxFiles.Utility;
using RobloxFiles.XmlFormat;
namespace RobloxFiles.Tokens
@ -19,12 +19,11 @@ namespace RobloxFiles.Tokens
{
Instance inst = prop.Instance;
Type instType = inst?.GetType();
FieldInfo info = instType.GetField(prop.Name, Property.BindingFlags);
var info = ImplicitMember.Get(instType, prop.Name);
if (info != null)
{
Type enumType = info.FieldType;
Type enumType = info.MemberType;
string item = value.ToInvariantString();
prop.Type = PropertyType.Enum;

View File

@ -42,16 +42,19 @@ namespace RobloxFiles.Tokens
var weight = (uint)font.Weight;
string family = font.Family;
string contentType = "null";
string familyType = "null";
string cachedType = "null";
string cachedId = font.CachedFaceId;
if (family.Length > 0)
contentType = "url";
familyType = "url";
var contentNode = doc.CreateElement(contentType);
contentNode.InnerText = family;
if (cachedId.Length > 0)
cachedType = "url";
var familyNode = doc.CreateElement("Family");
familyNode.AppendChild(contentNode);
familyNode.InnerText = $"<{familyType}>{family}</{familyType}>";
node.AppendChild(familyNode);
var weightNode = doc.CreateElement("Weight");
@ -61,6 +64,10 @@ namespace RobloxFiles.Tokens
var styleNode = doc.CreateElement("Style");
styleNode.InnerText = $"{font.Style}";
node.AppendChild(styleNode);
var cacheNode = doc.CreateElement("CachedFaceId");
cacheNode.InnerText = $"<{cachedType}>{cachedId}</{cachedType}>";
node.AppendChild(cacheNode);
}
public FontFace ReadAttribute(RbxAttribute attribute)