Fixed some binary file save problems.
This commit is contained in:
parent
5b85043194
commit
41c84dc49c
@ -32,7 +32,7 @@ namespace RobloxFiles.BinaryFormat
|
|||||||
public Dictionary<string, string> Metadata => META?.Data;
|
public Dictionary<string, string> Metadata => META?.Data;
|
||||||
|
|
||||||
public bool HasSharedStrings => (SSTR != null);
|
public bool HasSharedStrings => (SSTR != null);
|
||||||
public Dictionary<uint, string> SharedStrings => SSTR?.Strings;
|
public IReadOnlyDictionary<uint, string> SharedStrings => SSTR?.Strings;
|
||||||
|
|
||||||
internal BinaryRobloxFile()
|
internal BinaryRobloxFile()
|
||||||
{
|
{
|
||||||
@ -130,21 +130,8 @@ namespace RobloxFiles.BinaryFormat
|
|||||||
|
|
||||||
NumInstances = 0;
|
NumInstances = 0;
|
||||||
NumTypes = 0;
|
NumTypes = 0;
|
||||||
|
SSTR = null;
|
||||||
if (HasSharedStrings)
|
|
||||||
{
|
|
||||||
SSTR.NumHashes = 0;
|
|
||||||
SSTR.Lookup.Clear();
|
|
||||||
SSTR.Strings.Clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Write the META chunk.
|
|
||||||
if (HasMetadata)
|
|
||||||
{
|
|
||||||
var metaChunk = META.SaveAsChunk(writer);
|
|
||||||
Chunks.Add(metaChunk);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Record all instances and types.
|
// Record all instances and types.
|
||||||
writer.RecordInstances(Children);
|
writer.RecordInstances(Children);
|
||||||
|
|
||||||
@ -185,6 +172,13 @@ namespace RobloxFiles.BinaryFormat
|
|||||||
Chunks.Insert(0, sharedStrings);
|
Chunks.Insert(0, sharedStrings);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Write the META chunk.
|
||||||
|
if (HasMetadata)
|
||||||
|
{
|
||||||
|
var metaChunk = META.SaveAsChunk(writer);
|
||||||
|
Chunks.Insert(0, metaChunk);
|
||||||
|
}
|
||||||
|
|
||||||
// Write the END_ chunk.
|
// Write the END_ chunk.
|
||||||
writer.StartWritingChunk("END\0");
|
writer.StartWritingChunk("END\0");
|
||||||
writer.WriteString("</roblox>", true);
|
writer.WriteString("</roblox>", true);
|
||||||
|
@ -510,9 +510,16 @@ namespace RobloxFiles.BinaryFormat.Chunks
|
|||||||
case PropertyType.String:
|
case PropertyType.String:
|
||||||
props.ForEach(prop =>
|
props.ForEach(prop =>
|
||||||
{
|
{
|
||||||
byte[] rawBuffer = prop.RawBuffer;
|
byte[] buffer = prop.HasRawBuffer ? prop.RawBuffer : null;
|
||||||
writer.Write(rawBuffer.Length);
|
|
||||||
writer.Write(rawBuffer);
|
if (buffer == null)
|
||||||
|
{
|
||||||
|
string value = prop.CastValue<string>();
|
||||||
|
buffer = Encoding.UTF8.GetBytes(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
writer.Write(buffer.Length);
|
||||||
|
writer.Write(buffer);
|
||||||
});
|
});
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
@ -45,13 +45,15 @@ namespace RobloxFiles.BinaryFormat.Chunks
|
|||||||
foreach (var pair in Lookup)
|
foreach (var pair in Lookup)
|
||||||
{
|
{
|
||||||
string key = pair.Key;
|
string key = pair.Key;
|
||||||
|
|
||||||
byte[] md5 = Convert.FromBase64String(key);
|
byte[] md5 = Convert.FromBase64String(key);
|
||||||
|
|
||||||
uint id = pair.Value;
|
|
||||||
string value = Strings[id];
|
|
||||||
|
|
||||||
writer.Write(md5);
|
writer.Write(md5);
|
||||||
writer.WriteString(value);
|
|
||||||
|
string value = Strings[pair.Value];
|
||||||
|
byte[] buffer = Convert.FromBase64String(value);
|
||||||
|
|
||||||
|
writer.Write(buffer.Length);
|
||||||
|
writer.Write(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
return writer.FinishWritingChunk();
|
return writer.FinishWritingChunk();
|
||||||
|
@ -44,12 +44,53 @@ namespace RobloxFiles
|
|||||||
public Instance Instance { get; internal set; }
|
public Instance Instance { get; internal set; }
|
||||||
|
|
||||||
public PropertyType Type;
|
public PropertyType Type;
|
||||||
public object Value;
|
|
||||||
|
|
||||||
public string XmlToken = "";
|
public string XmlToken = "";
|
||||||
public byte[] RawBuffer { get; internal set; }
|
public byte[] RawBuffer;
|
||||||
|
|
||||||
internal BinaryRobloxFileWriter CurrentWriter;
|
internal BinaryRobloxFileWriter CurrentWriter;
|
||||||
|
internal object RawValue;
|
||||||
|
|
||||||
|
private void ImproviseRawBuffer()
|
||||||
|
{
|
||||||
|
switch (Type)
|
||||||
|
{
|
||||||
|
case PropertyType.Int:
|
||||||
|
RawBuffer = BitConverter.GetBytes((int)Value);
|
||||||
|
break;
|
||||||
|
case PropertyType.Int64:
|
||||||
|
RawBuffer = BitConverter.GetBytes((long)Value);
|
||||||
|
break;
|
||||||
|
case PropertyType.Bool:
|
||||||
|
RawBuffer = BitConverter.GetBytes((bool)Value);
|
||||||
|
break;
|
||||||
|
case PropertyType.Float:
|
||||||
|
RawBuffer = BitConverter.GetBytes((float)Value);
|
||||||
|
break;
|
||||||
|
case PropertyType.Double:
|
||||||
|
RawBuffer = BitConverter.GetBytes((double)Value);
|
||||||
|
break;
|
||||||
|
case PropertyType.SharedString:
|
||||||
|
RawBuffer = Convert.FromBase64String((string)Value);
|
||||||
|
break;
|
||||||
|
//
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public object Value
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return RawValue;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
RawValue = value;
|
||||||
|
RawBuffer = null;
|
||||||
|
|
||||||
|
ImproviseRawBuffer();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public bool HasRawBuffer
|
public bool HasRawBuffer
|
||||||
{
|
{
|
||||||
@ -58,27 +99,7 @@ namespace RobloxFiles
|
|||||||
if (RawBuffer == null && Value != null)
|
if (RawBuffer == null && Value != null)
|
||||||
{
|
{
|
||||||
// Improvise what the buffer should be if this is a primitive.
|
// Improvise what the buffer should be if this is a primitive.
|
||||||
switch (Type)
|
ImproviseRawBuffer();
|
||||||
{
|
|
||||||
case PropertyType.Int:
|
|
||||||
RawBuffer = BitConverter.GetBytes((int)Value);
|
|
||||||
break;
|
|
||||||
case PropertyType.Int64:
|
|
||||||
RawBuffer = BitConverter.GetBytes((long)Value);
|
|
||||||
break;
|
|
||||||
case PropertyType.Bool:
|
|
||||||
RawBuffer = BitConverter.GetBytes((bool)Value);
|
|
||||||
break;
|
|
||||||
case PropertyType.Float:
|
|
||||||
RawBuffer = BitConverter.GetBytes((float)Value);
|
|
||||||
break;
|
|
||||||
case PropertyType.Double:
|
|
||||||
RawBuffer = BitConverter.GetBytes((double)Value);
|
|
||||||
break;
|
|
||||||
case PropertyType.SharedString:
|
|
||||||
RawBuffer = Convert.FromBase64String((string)Value);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (RawBuffer != null);
|
return (RawBuffer != null);
|
||||||
@ -138,8 +159,8 @@ namespace RobloxFiles
|
|||||||
throw new Exception("Property.CurrentWriter must be set to use WriteValue<T>");
|
throw new Exception("Property.CurrentWriter must be set to use WriteValue<T>");
|
||||||
|
|
||||||
T value = CastValue<T>();
|
T value = CastValue<T>();
|
||||||
|
|
||||||
byte[] bytes = BinaryRobloxFileWriter.GetBytes(value);
|
byte[] bytes = BinaryRobloxFileWriter.GetBytes(value);
|
||||||
|
|
||||||
CurrentWriter.Write(bytes);
|
CurrentWriter.Write(bytes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user