mirror of
https://github.com/sampletext32/ParkanPlayground.git
synced 2025-12-11 04:51:21 +04:00
improve binary varset parsing
This commit is contained in:
@@ -18,8 +18,20 @@ using VarsetLib;
|
||||
// converter.Convert("E:\\ParkanUnpacked\\bases.rlb\\25_MESH_R_H_02.msh");
|
||||
|
||||
|
||||
var fs = new FileStream("E:\\ParkanUnpacked\\behpsp.res\\31_00 00 00 00_prof_generator.var", FileMode.Open, FileAccess.Read, FileShare.Read);
|
||||
foreach (var path in Directory.EnumerateFiles("E:\\ParkanUnpacked\\behpsp.res"))
|
||||
{
|
||||
using var fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read);
|
||||
|
||||
var file = BinaryVarsetFileParser.Parse(fs);
|
||||
var file = BinaryVarsetFileParser.Parse(fs);
|
||||
|
||||
_ = 5;
|
||||
_ = 5;
|
||||
}
|
||||
|
||||
{
|
||||
var fs = new FileStream("E:\\ParkanUnpacked\\behpsp.res\\31_00 00 00 00_prof_generator.var", FileMode.Open,
|
||||
FileAccess.Read, FileShare.Read);
|
||||
|
||||
var file = BinaryVarsetFileParser.Parse(fs);
|
||||
|
||||
_ = 5;
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
@@ -1,15 +1,34 @@
|
||||
using Common;
|
||||
using System.Diagnostics;
|
||||
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
|
||||
);
|
||||
[DebuggerDisplay("{DebugDisplay}")]
|
||||
public abstract record BinaryVarsetItem()
|
||||
{
|
||||
protected abstract string DebugDisplay { get; }
|
||||
}
|
||||
|
||||
public record BinaryVarsetItem<TValue>(
|
||||
int ValueLength, // длина значения
|
||||
BinaryVarsetValueType ValueType, // тип значения
|
||||
TValue Magic3, // кажется 0 всегда
|
||||
string Name, // имя переменной
|
||||
string String2, // кажется всегда пусто
|
||||
TValue Magic4,
|
||||
TValue Magic5,
|
||||
TValue Magic6, // минимум
|
||||
TValue Magic7 // максимум
|
||||
) : BinaryVarsetItem
|
||||
{
|
||||
protected override string DebugDisplay => $"{typeof(TValue).Name}, {ValueLength} bytes. magic3: {Magic3}. {Name,-30} {String2} - {Magic4} {Magic5} {Magic6} {Magic7}";
|
||||
};
|
||||
|
||||
public enum BinaryVarsetValueType
|
||||
{
|
||||
Int = 1,
|
||||
Bool = 2,
|
||||
Float = 3,
|
||||
CharPtr = 4,
|
||||
Dword = 5
|
||||
}
|
||||
Reference in New Issue
Block a user