2019-05-17 06:14:04 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2019-06-30 22:01:19 +00:00
|
|
|
|
using RobloxFiles.DataTypes;
|
2019-05-17 06:14:04 +00:00
|
|
|
|
|
|
|
|
|
namespace RobloxFiles.BinaryFormat.Chunks
|
|
|
|
|
{
|
2019-06-08 03:43:28 +00:00
|
|
|
|
public class SSTR : IBinaryFileChunk
|
2019-05-17 06:14:04 +00:00
|
|
|
|
{
|
|
|
|
|
public int Version;
|
|
|
|
|
public int NumHashes;
|
|
|
|
|
|
|
|
|
|
public Dictionary<string, uint> Lookup = new Dictionary<string, uint>();
|
2019-06-30 22:01:19 +00:00
|
|
|
|
public Dictionary<uint, SharedString> Strings = new Dictionary<uint, SharedString>();
|
2019-05-17 06:14:04 +00:00
|
|
|
|
|
2019-06-08 03:43:28 +00:00
|
|
|
|
public void LoadFromReader(BinaryRobloxFileReader reader)
|
2019-05-17 06:14:04 +00:00
|
|
|
|
{
|
2019-06-08 03:43:28 +00:00
|
|
|
|
BinaryRobloxFile file = reader.File;
|
|
|
|
|
|
|
|
|
|
Version = reader.ReadInt32();
|
|
|
|
|
NumHashes = reader.ReadInt32();
|
|
|
|
|
|
|
|
|
|
for (uint id = 0; id < NumHashes; id++)
|
2019-05-17 06:14:04 +00:00
|
|
|
|
{
|
2019-06-08 03:43:28 +00:00
|
|
|
|
byte[] md5 = reader.ReadBytes(16);
|
|
|
|
|
|
|
|
|
|
int length = reader.ReadInt32();
|
|
|
|
|
byte[] data = reader.ReadBytes(length);
|
|
|
|
|
|
2019-06-30 22:01:19 +00:00
|
|
|
|
SharedString value = SharedString.FromBuffer(data);
|
|
|
|
|
Lookup.Add(value.MD5_Key, id);
|
2019-06-08 03:43:28 +00:00
|
|
|
|
Strings.Add(id, value);
|
|
|
|
|
}
|
2019-05-17 06:14:04 +00:00
|
|
|
|
|
2019-06-08 03:43:28 +00:00
|
|
|
|
file.SSTR = this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public BinaryRobloxFileChunk SaveAsChunk(BinaryRobloxFileWriter writer)
|
|
|
|
|
{
|
|
|
|
|
writer.StartWritingChunk(this);
|
2019-05-17 06:14:04 +00:00
|
|
|
|
|
2019-06-08 03:43:28 +00:00
|
|
|
|
writer.Write(Version);
|
|
|
|
|
writer.Write(NumHashes);
|
2019-05-17 06:14:04 +00:00
|
|
|
|
|
2019-06-08 03:43:28 +00:00
|
|
|
|
foreach (var pair in Lookup)
|
|
|
|
|
{
|
|
|
|
|
string key = pair.Key;
|
2019-06-11 01:27:57 +00:00
|
|
|
|
|
2019-06-08 03:43:28 +00:00
|
|
|
|
byte[] md5 = Convert.FromBase64String(key);
|
2019-06-11 01:27:57 +00:00
|
|
|
|
writer.Write(md5);
|
2019-06-08 03:43:28 +00:00
|
|
|
|
|
2019-06-30 22:01:19 +00:00
|
|
|
|
SharedString value = Strings[pair.Value];
|
|
|
|
|
byte[] buffer = SharedString.FindRecord(value.MD5_Key);
|
2019-05-17 06:14:04 +00:00
|
|
|
|
|
2019-06-11 01:27:57 +00:00
|
|
|
|
writer.Write(buffer.Length);
|
|
|
|
|
writer.Write(buffer);
|
2019-05-17 06:14:04 +00:00
|
|
|
|
}
|
2019-06-08 03:43:28 +00:00
|
|
|
|
|
|
|
|
|
return writer.FinishWritingChunk();
|
2019-05-17 06:14:04 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|