diff options
| author | Wither OrNot | 2025-02-13 14:49:35 +0000 |
|---|---|---|
| committer | Wither OrNot | 2025-02-13 14:49:37 +0000 |
| commit | 0d59561bee4cf7db10d53a8aa58952ae65e856b5 (patch) | |
| tree | b2ddb66c883dd2ef75426de4c080f3121f0a8658 /LibTSforge/TokenStore/Common.cs | |
| download | TSforge-0d59561bee4cf7db10d53a8aa58952ae65e856b5.zip | |
Initial commit1.0.0
Co-authored-by: neko <[email protected]>
Co-authored-by: Lyssa <[email protected]>
Co-authored-by: abbodi1406 <[email protected]>
Diffstat (limited to 'LibTSforge/TokenStore/Common.cs')
| -rw-r--r-- | LibTSforge/TokenStore/Common.cs | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/LibTSforge/TokenStore/Common.cs b/LibTSforge/TokenStore/Common.cs new file mode 100644 index 0000000..1dda7e7 --- /dev/null +++ b/LibTSforge/TokenStore/Common.cs @@ -0,0 +1,67 @@ +namespace LibTSforge.TokenStore +{ + using System.Collections.Generic; + using System.IO; + + public class TokenEntry + { + public string Name; + public string Extension; + public byte[] Data; + public bool Populated; + } + + public class TokenMeta + { + public string Name; + public Dictionary<string, string> Data = new Dictionary<string, string>(); + + public byte[] Serialize() + { + BinaryWriter writer = new BinaryWriter(new MemoryStream()); + writer.Write(1); + byte[] nameBytes = Utils.EncodeString(Name); + writer.Write(nameBytes.Length); + writer.Write(nameBytes); + + foreach (KeyValuePair<string, string> kv in Data) + { + byte[] keyBytes = Utils.EncodeString(kv.Key); + byte[] valueBytes = Utils.EncodeString(kv.Value); + writer.Write(keyBytes.Length); + writer.Write(valueBytes.Length); + writer.Write(keyBytes); + writer.Write(valueBytes); + } + + return writer.GetBytes(); + } + + public void Deserialize(byte[] data) + { + BinaryReader reader = new BinaryReader(new MemoryStream(data)); + reader.ReadInt32(); + int nameLen = reader.ReadInt32(); + Name = reader.ReadNullTerminatedString(nameLen); + + while (reader.BaseStream.Position < data.Length - 0x8) + { + int keyLen = reader.ReadInt32(); + int valueLen = reader.ReadInt32(); + string key = reader.ReadNullTerminatedString(keyLen); + string value = reader.ReadNullTerminatedString(valueLen); + Data[key] = value; + } + } + + public TokenMeta(byte[] data) + { + Deserialize(data); + } + + public TokenMeta() + { + + } + } +} |
