Minor fixes and tweaks.

This commit is contained in:
CloneTrooper1019 2019-07-04 18:26:53 -05:00
parent 4e1fdc0a22
commit cf4cf829d7
9 changed files with 60 additions and 34 deletions

View File

@ -6,27 +6,26 @@
/// </summary>
public class Content
{
// TODO: Maybe introduce constraints to the value?
public readonly string Data;
public readonly string Url;
public override string ToString()
{
return Data;
return Url;
}
public Content(string data)
public Content(string url)
{
Data = data;
Url = url;
}
public static implicit operator string(Content content)
{
return content.Data;
return content.Url;
}
public static implicit operator Content(string data)
public static implicit operator Content(string url)
{
return new Content(data);
return new Content(url);
}
}
}

View File

@ -6,21 +6,21 @@
/// </summary>
public class ProtectedString
{
public readonly string Value;
public readonly string ProtectedValue;
public override string ToString()
{
return Value;
return ProtectedValue;
}
public ProtectedString(string value)
{
Value = value;
ProtectedValue = value;
}
public static implicit operator string(ProtectedString protectedString)
{
return protectedString.Value;
return protectedString.ProtectedValue;
}
public static implicit operator ProtectedString(string value)

View File

@ -21,6 +21,11 @@ namespace RobloxFiles.DataTypes
}
}
public override string ToString()
{
return string.Join(", ", X, Y, Z, W);
}
public Quaternion(float x, float y, float z, float w)
{
X = x;

View File

@ -1786,6 +1786,7 @@ namespace RobloxFiles
public abstract class LuaSourceContainer : Instance
{
public string ScriptGuid = "";
}
public abstract class BaseScript : LuaSourceContainer

Binary file not shown.

View File

@ -348,6 +348,12 @@ return
}
};
LuaSourceContainer =
{
Add = { ScriptGuid = "string" };
Defaults = { ScriptGuid = "" };
};
ManualSurfaceJointInstance =
{
Add =

View File

@ -459,7 +459,14 @@ namespace RobloxFiles
if (field.GetCustomAttribute<ObsoleteAttribute>() != null)
continue;
if (Property.Types.ContainsKey(fieldType))
PropertyType propType = PropertyType.Unknown;
if (fieldType.IsEnum)
propType = PropertyType.Enum;
else if (Property.Types.ContainsKey(fieldType))
propType = Property.Types[fieldType];
if (propType != PropertyType.Unknown)
{
if (fieldName.EndsWith("_"))
fieldName = instType.Name;
@ -468,9 +475,9 @@ namespace RobloxFiles
{
Property newProp = new Property()
{
Type = Property.Types[fieldType],
Value = field.GetValue(this),
Name = fieldName,
Type = propType,
Instance = this
};
@ -480,7 +487,7 @@ namespace RobloxFiles
{
Property prop = props[fieldName];
prop.Value = field.GetValue(this);
prop.Type = Property.Types[fieldType];
prop.Type = propType;
}
}
}

View File

@ -43,13 +43,13 @@ namespace RobloxFiles
public class Property
{
public string Name;
public string Name { get; internal set; }
public Instance Instance { get; internal set; }
public PropertyType Type;
public PropertyType Type { get; internal set; }
public string XmlToken = "";
public byte[] RawBuffer;
public string XmlToken { get; internal set; }
public byte[] RawBuffer { get; internal set; }
internal object RawValue;
internal BinaryRobloxFileWriter CurrentWriter;
@ -74,16 +74,20 @@ namespace RobloxFiles
{ typeof(UDim2), PropertyType.UDim2 },
{ typeof(CFrame), PropertyType.CFrame },
{ typeof(Color3), PropertyType.Color3 },
{ typeof(Content), PropertyType.String },
{ typeof(Vector2), PropertyType.Vector2 },
{ typeof(Vector3), PropertyType.Vector3 },
{ typeof(BrickColor), PropertyType.BrickColor },
{ typeof(Quaternion), PropertyType.Quaternion },
{ typeof(Color3uint8), PropertyType.Color3uint8 },
{ typeof(NumberRange), PropertyType.NumberRange },
{ typeof(SharedString), PropertyType.SharedString },
{ typeof(Vector3int16), PropertyType.Vector3int16 },
{ typeof(ColorSequence), PropertyType.ColorSequence },
{ typeof(NumberSequence), PropertyType.NumberSequence },
{ typeof(ProtectedString), PropertyType.String },
{ typeof(PhysicalProperties), PropertyType.PhysicalProperties },
};
@ -98,7 +102,7 @@ namespace RobloxFiles
else if (RawValue is SharedString)
{
var sharedString = CastValue<SharedString>();
RawBuffer = Convert.FromBase64String(sharedString.MD5_Key);
RawBuffer = sharedString.SharedValue;
return;
}
@ -134,17 +138,19 @@ namespace RobloxFiles
if (typeName == Name)
{
var implicitName = Name + '_';
return implicitName;
FieldInfo directField = instType.GetField(typeName, BindingFlags.DeclaredOnly);
if (directField != null)
{
var implicitName = Name + '_';
return implicitName;
}
}
}
if (Name.Contains(" "))
{
var implicitName = Name.Replace(' ', '_');
return implicitName;
}
return Name.Replace(' ', '_');
return Name;
}
}
@ -289,14 +295,16 @@ namespace RobloxFiles
public T CastValue<T>()
{
T result;
object result;
if (Value is T)
if (typeof(T) == typeof(string))
result = Value?.ToString() ?? "";
else if (Value is T)
result = (T)Value;
else
result = default(T);
return result;
return (T)result;
}
internal void WriteValue<T>() where T : struct

View File

@ -11,11 +11,11 @@ namespace RobloxFiles.XmlFormat.PropertyTokens
{
// BinaryStrings are encoded in base64
string base64 = token.InnerText.Replace("\n", "");
prop.Value = Convert.FromBase64String(base64);
prop.Type = PropertyType.String;
byte[] buffer = Convert.FromBase64String(base64);
prop.Value = buffer;
prop.RawBuffer = buffer;
prop.Type = PropertyType.String;
return true;
}