Fixed some encoding errors.

This commit is contained in:
Max 2021-05-04 19:45:00 -05:00
parent 32399a692c
commit 2e02c2e7ef
5 changed files with 25 additions and 7 deletions

View File

@ -463,6 +463,13 @@ namespace RobloxFiles.BinaryFormat.Chunks
readProperties(i =>
{
int instId = instIds[i];
if (instId >= File.NumInstances)
{
RobloxFile.LogError($"Got out of bounds referent index in {ClassName}.{Name}!");
return null;
}
return instId >= 0 ? File.Instances[instId] : null;
});
@ -1015,7 +1022,12 @@ namespace RobloxFiles.BinaryFormat.Chunks
if (prop.Value != null)
{
Instance value = prop.CastValue<Instance>();
referent = int.Parse(value.Referent);
if (value.IsDescendantOf(File))
{
string refValue = value.Referent;
int.TryParse(refValue, out referent);
}
}
InstanceIds.Add(referent);

Binary file not shown.

View File

@ -22,6 +22,9 @@ namespace RobloxFiles.Tokens
public void WriteProperty(Property prop, XmlDocument doc, XmlNode node)
{
if (!prop.HasRawBuffer)
return;
byte[] data = prop.RawBuffer;
string value = Convert.ToBase64String(data);

View File

@ -158,10 +158,8 @@ namespace RobloxFiles
internal void WriteString(string value)
{
int length = value.Length;
Writer.Write(length);
byte[] utf8 = Encoding.UTF8.GetBytes(value);
Writer.Write(utf8.Length);
Writer.Write(utf8);
}
@ -239,6 +237,10 @@ namespace RobloxFiles
}
}
public Attributes() : base()
{
}
internal Attributes(BinaryReader reader)
{
Initialize(reader);

View File

@ -64,7 +64,7 @@ namespace RobloxFiles
public HashSet<string> Tags { get; } = new HashSet<string>();
/// <summary>The attributes defined for this Instance.</summary>
private Attributes AttributesImpl;
private Attributes AttributesImpl = new Attributes();
/// <summary>The public readonly access point of the attributes on this Instance.</summary>
public IReadOnlyDictionary<string, Attribute> Attributes => AttributesImpl;
@ -161,7 +161,9 @@ namespace RobloxFiles
if (key.Length > 100)
return false;
if (!Attribute.SupportsType<T>())
Type type = value.GetType();
if (!Attribute.SupportsType(type))
return false;
var attr = new Attribute(value);
@ -170,7 +172,6 @@ namespace RobloxFiles
return true;
}
/// <summary>Returns true if this Instance is an ancestor to the provided Instance.</summary>
/// <param name="descendant">The instance whose descendance will be tested against this Instance.</param>
public bool IsAncestorOf(Instance descendant)