Fixed some binary file save problems.
This commit is contained in:
@ -32,7 +32,7 @@ namespace RobloxFiles.BinaryFormat
|
||||
public Dictionary<string, string> Metadata => META?.Data;
|
||||
|
||||
public bool HasSharedStrings => (SSTR != null);
|
||||
public Dictionary<uint, string> SharedStrings => SSTR?.Strings;
|
||||
public IReadOnlyDictionary<uint, string> SharedStrings => SSTR?.Strings;
|
||||
|
||||
internal BinaryRobloxFile()
|
||||
{
|
||||
@ -130,21 +130,8 @@ namespace RobloxFiles.BinaryFormat
|
||||
|
||||
NumInstances = 0;
|
||||
NumTypes = 0;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
SSTR = null;
|
||||
|
||||
// Record all instances and types.
|
||||
writer.RecordInstances(Children);
|
||||
|
||||
@ -185,6 +172,13 @@ namespace RobloxFiles.BinaryFormat
|
||||
Chunks.Insert(0, sharedStrings);
|
||||
}
|
||||
|
||||
// Write the META chunk.
|
||||
if (HasMetadata)
|
||||
{
|
||||
var metaChunk = META.SaveAsChunk(writer);
|
||||
Chunks.Insert(0, metaChunk);
|
||||
}
|
||||
|
||||
// Write the END_ chunk.
|
||||
writer.StartWritingChunk("END\0");
|
||||
writer.WriteString("</roblox>", true);
|
||||
|
@ -510,9 +510,16 @@ namespace RobloxFiles.BinaryFormat.Chunks
|
||||
case PropertyType.String:
|
||||
props.ForEach(prop =>
|
||||
{
|
||||
byte[] rawBuffer = prop.RawBuffer;
|
||||
writer.Write(rawBuffer.Length);
|
||||
writer.Write(rawBuffer);
|
||||
byte[] buffer = prop.HasRawBuffer ? prop.RawBuffer : null;
|
||||
|
||||
if (buffer == null)
|
||||
{
|
||||
string value = prop.CastValue<string>();
|
||||
buffer = Encoding.UTF8.GetBytes(value);
|
||||
}
|
||||
|
||||
writer.Write(buffer.Length);
|
||||
writer.Write(buffer);
|
||||
});
|
||||
|
||||
break;
|
||||
|
@ -45,13 +45,15 @@ namespace RobloxFiles.BinaryFormat.Chunks
|
||||
foreach (var pair in Lookup)
|
||||
{
|
||||
string key = pair.Key;
|
||||
|
||||
byte[] md5 = Convert.FromBase64String(key);
|
||||
|
||||
uint id = pair.Value;
|
||||
string value = Strings[id];
|
||||
|
||||
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();
|
||||
|
Reference in New Issue
Block a user