1
mirror of https://github.com/sampletext32/ParkanPlayground.git synced 2025-12-12 05:41:21 +04:00

parse binary varset file

This commit is contained in:
bird_egop
2025-11-22 06:53:07 +03:00
parent a774db37a6
commit 2a78bbebda
5 changed files with 78 additions and 4 deletions

View File

@@ -0,0 +1,3 @@
namespace VarsetLib;
public record BinaryVarsetFile(int Count, List<BinaryVarsetItem> Items);

View File

@@ -0,0 +1,46 @@
using Common;
namespace VarsetLib;
public class BinaryVarsetFileParser
{
public static BinaryVarsetFile Parse(string path)
{
using FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read);
return Parse(fs);
}
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);
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);
var magic5 = new IntFloatValue(buf4);
fs.ReadExactly(buf4);
var magic6 = new IntFloatValue(buf4);
fs.ReadExactly(buf4);
var magic7 = new IntFloatValue(buf4);
items.Add(new BinaryVarsetItem(magic1, magic2, magic3, name, string2, magic4, magic5, magic6, magic7));
}
return new BinaryVarsetFile(count, items);
}
}

View File

@@ -0,0 +1,15 @@
using Common;
namespace VarsetLib;
public record BinaryVarsetItem(
int Magic1, // length of something
IntFloatValue Magic2,
IntFloatValue Magic3,
string Name,
string String2,
IntFloatValue Magic4,
IntFloatValue Magic5,
IntFloatValue Magic6,
IntFloatValue Magic7
);

View File

@@ -1,3 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<ProjectReference Include="..\Common\Common.csproj" />
</ItemGroup>
</Project>