2022-02-10 21:22:44 +00:00
|
|
|
|
using System;
|
2022-10-13 02:19:43 +00:00
|
|
|
|
using System.Linq;
|
2022-02-10 21:22:44 +00:00
|
|
|
|
using System.Xml;
|
2022-04-25 03:28:42 +00:00
|
|
|
|
using RobloxFiles.DataTypes;
|
2022-02-10 21:22:44 +00:00
|
|
|
|
|
|
|
|
|
namespace RobloxFiles.Tokens
|
|
|
|
|
{
|
2022-04-25 03:28:42 +00:00
|
|
|
|
public class UniqueIdToken : IXmlPropertyToken
|
2022-02-10 21:22:44 +00:00
|
|
|
|
{
|
|
|
|
|
public string XmlPropertyToken => "UniqueId";
|
|
|
|
|
|
|
|
|
|
public bool ReadProperty(Property prop, XmlNode token)
|
|
|
|
|
{
|
|
|
|
|
string hex = token.InnerText;
|
|
|
|
|
|
|
|
|
|
if (Guid.TryParse(hex, out var guid))
|
|
|
|
|
{
|
2022-10-13 02:19:43 +00:00
|
|
|
|
var bytes = new byte[16];
|
2022-04-25 03:28:42 +00:00
|
|
|
|
|
2022-10-13 02:19:43 +00:00
|
|
|
|
for (int i = 0; i < 16; i++)
|
|
|
|
|
{
|
|
|
|
|
var hexChar = hex.Substring(i * 2, 2);
|
|
|
|
|
bytes[15 - i] = Convert.ToByte(hexChar, 16);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var rand = BitConverter.ToInt64(bytes, 8);
|
|
|
|
|
var time = BitConverter.ToUInt32(bytes, 4);
|
|
|
|
|
var index = BitConverter.ToUInt32(bytes, 0);
|
|
|
|
|
|
|
|
|
|
var uniqueId = new UniqueId(rand, time, index);
|
|
|
|
|
prop.Value = uniqueId;
|
2022-04-25 03:28:42 +00:00
|
|
|
|
|
2022-02-10 21:22:44 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void WriteProperty(Property prop, XmlDocument doc, XmlNode node)
|
|
|
|
|
{
|
2022-04-25 03:28:42 +00:00
|
|
|
|
var uniqueId = prop.CastValue<UniqueId>();
|
|
|
|
|
|
2022-10-13 02:19:43 +00:00
|
|
|
|
var random = BitConverter.GetBytes(uniqueId.Random);
|
2022-04-25 03:28:42 +00:00
|
|
|
|
var time = BitConverter.GetBytes(uniqueId.Time);
|
|
|
|
|
var index = BitConverter.GetBytes(uniqueId.Index);
|
|
|
|
|
|
|
|
|
|
var bytes = new byte[16];
|
|
|
|
|
random.CopyTo(bytes, 0);
|
|
|
|
|
time.CopyTo(bytes, 8);
|
|
|
|
|
index.CopyTo(bytes, 12);
|
|
|
|
|
|
|
|
|
|
var guid = new Guid(bytes);
|
2022-02-10 21:22:44 +00:00
|
|
|
|
node.InnerText = guid.ToString("N");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|