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:
3
VarsetLib/BinaryVarsetFile.cs
Normal file
3
VarsetLib/BinaryVarsetFile.cs
Normal file
@@ -0,0 +1,3 @@
|
||||
namespace VarsetLib;
|
||||
|
||||
public record BinaryVarsetFile(int Count, List<BinaryVarsetItem> Items);
|
||||
46
VarsetLib/BinaryVarsetFileParser.cs
Normal file
46
VarsetLib/BinaryVarsetFileParser.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
15
VarsetLib/BinaryVarsetItem.cs
Normal file
15
VarsetLib/BinaryVarsetItem.cs
Normal 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
|
||||
);
|
||||
@@ -1,3 +1,5 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Common\Common.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
||||
Reference in New Issue
Block a user