1
mirror of https://github.com/sampletext32/ParkanPlayground.git synced 2025-12-12 01:31:20 +04:00

improve binary varset parsing

This commit is contained in:
bird_egop
2025-11-22 09:02:35 +03:00
parent 2a78bbebda
commit f4442897a6
3 changed files with 99 additions and 21 deletions

View File

@@ -14,21 +14,21 @@ public class BinaryVarsetFileParser
public static BinaryVarsetFile Parse(Stream fs)
{
var count = fs.ReadInt32LittleEndian();
var items = new List<BinaryVarsetItem>(count);
Span<byte> buf4 = stackalloc byte[4];
for (int i = 0; i < count; i++)
{
var magic1 = fs.ReadInt32LittleEndian();
fs.ReadExactly(buf4);
var magic2 = new IntFloatValue(buf4);
var valueLength = fs.ReadInt32LittleEndian();
var valueType = (BinaryVarsetValueType)fs.ReadInt32LittleEndian();
fs.ReadExactly(buf4);
var magic3 = new IntFloatValue(buf4);
var name = fs.ReadLengthPrefixedString();
var string2 = fs.ReadLengthPrefixedString();
fs.ReadExactly(buf4);
var magic4 = new IntFloatValue(buf4);
fs.ReadExactly(buf4);
@@ -37,8 +37,55 @@ public class BinaryVarsetFileParser
var magic6 = new IntFloatValue(buf4);
fs.ReadExactly(buf4);
var magic7 = new IntFloatValue(buf4);
if(string2.Length != 0)
{
_ = 5;
}
items.Add(new BinaryVarsetItem(magic1, magic2, magic3, name, string2, magic4, magic5, magic6, magic7));
if (valueType is BinaryVarsetValueType.Bool)
{
items.Add(new BinaryVarsetItem<bool>(
valueLength,
valueType,
magic3.AsInt != 0,
name,
string2,
magic4.AsInt != 0,
magic5.AsInt != 0,
magic6.AsInt != 0,
magic7.AsInt != 0));
}
else if (valueType is BinaryVarsetValueType.Dword)
{
items.Add(new BinaryVarsetItem<uint>(
valueLength,
valueType,
(uint)magic3.AsInt,
name,
string2,
(uint)magic4.AsInt,
(uint)magic5.AsInt,
(uint)magic6.AsInt,
(uint)magic7.AsInt));
}
else if (valueType is BinaryVarsetValueType.Float)
{
items.Add(new BinaryVarsetItem<float>(
valueLength,
valueType,
magic3.AsFloat,
name,
string2,
magic4.AsFloat,
magic5.AsFloat,
magic6.AsFloat,
magic7.AsFloat));
}
else
{
throw new InvalidOperationException($"Unknown value type {valueType}");
}
}
return new BinaryVarsetFile(count, items);