Added Reader class to BlendFile library
This commit is contained in:
@@ -6,4 +6,14 @@
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="KaitaiStruct.Runtime.CSharp" Version="0.10.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="..\CodeGenerator\BlendFile.cs">
|
||||
<Link>BlendFile.cs</Link>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
42
BlendFile/Reader.cs
Normal file
42
BlendFile/Reader.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using System.Reflection;
|
||||
using Kaitai;
|
||||
|
||||
|
||||
namespace BlendFile;
|
||||
|
||||
public class Reader {
|
||||
readonly string _path;
|
||||
private readonly Dictionary<int, Type> dnaTypes = new();
|
||||
|
||||
private List<object> objects = new();
|
||||
public List<object> Objects => objects;
|
||||
|
||||
public Reader(string path) {
|
||||
_path = path;
|
||||
var types = Assembly.GetExecutingAssembly().DefinedTypes;
|
||||
foreach (var type in types) {
|
||||
var attrib = type.GetCustomAttribute<DNAClassAttribute>();
|
||||
if (attrib ==null) continue;
|
||||
dnaTypes.Add(attrib.OriginalIndex, type);
|
||||
}
|
||||
}
|
||||
|
||||
public void Read() {
|
||||
var file = new KaitaiStream(_path);
|
||||
var blend = new Kaitai.BlendFile(file);
|
||||
|
||||
foreach (var block in blend.Blocks) {
|
||||
Type t = dnaTypes[(int)block.SdnaIndex];
|
||||
var obj = Activator.CreateInstance(t);
|
||||
if(obj == null) continue;
|
||||
objects.Add(obj);
|
||||
|
||||
foreach (var field in t.GetFields()) {
|
||||
var attrib = field.GetCustomAttribute<DNAFieldAttribute>();
|
||||
if (attrib == null) continue;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user