Compare commits
2 Commits
b7cd60e4cf
...
ebcc629feb
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ebcc629feb | ||
|
|
2bd93ab3bb |
@@ -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;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -18,9 +18,9 @@ namespace Kaitai {
|
||||
/// block would be a structure with code `DNA1`, which is a essentially
|
||||
/// a machine-readable schema of all other structures used in this file.
|
||||
/// </summary>
|
||||
public partial class BlenderBlend : KaitaiStruct {
|
||||
public static BlenderBlend FromFile(string fileName) {
|
||||
return new BlenderBlend(new KaitaiStream(fileName));
|
||||
public partial class BlendFile : KaitaiStruct {
|
||||
public static BlendFile FromFile(string fileName) {
|
||||
return new BlendFile(new KaitaiStream(fileName));
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ namespace Kaitai {
|
||||
Le = 118,
|
||||
}
|
||||
|
||||
public BlenderBlend(KaitaiStream p__io, KaitaiStruct p__parent = null, BlenderBlend p__root = null) : base(p__io) {
|
||||
public BlendFile(KaitaiStream p__io, KaitaiStruct p__parent = null, BlendFile p__root = null) : base(p__io) {
|
||||
m_parent = p__parent;
|
||||
m_root = p__root ?? this;
|
||||
f_sdnaStructs = false;
|
||||
@@ -62,7 +62,7 @@ namespace Kaitai {
|
||||
return new DnaStruct(new KaitaiStream(fileName));
|
||||
}
|
||||
|
||||
public DnaStruct(KaitaiStream p__io, BlenderBlend.Dna1Body p__parent = null, BlenderBlend p__root = null) :
|
||||
public DnaStruct(KaitaiStream p__io, BlendFile.Dna1Body p__parent = null, BlendFile p__root = null) :
|
||||
base(p__io) {
|
||||
m_parent = p__parent;
|
||||
m_root = p__root;
|
||||
@@ -95,8 +95,8 @@ namespace Kaitai {
|
||||
private ushort _idxType;
|
||||
private ushort _numFields;
|
||||
private List<DnaField> _fields;
|
||||
private BlenderBlend m_root;
|
||||
private BlenderBlend.Dna1Body m_parent;
|
||||
private BlendFile m_root;
|
||||
private BlendFile.Dna1Body m_parent;
|
||||
|
||||
public ushort IdxType {
|
||||
get { return _idxType; }
|
||||
@@ -110,11 +110,11 @@ namespace Kaitai {
|
||||
get { return _fields; }
|
||||
}
|
||||
|
||||
public BlenderBlend M_Root {
|
||||
public BlendFile M_Root {
|
||||
get { return m_root; }
|
||||
}
|
||||
|
||||
public BlenderBlend.Dna1Body M_Parent {
|
||||
public BlendFile.Dna1Body M_Parent {
|
||||
get { return m_parent; }
|
||||
}
|
||||
}
|
||||
@@ -124,7 +124,7 @@ namespace Kaitai {
|
||||
return new FileBlock(new KaitaiStream(fileName));
|
||||
}
|
||||
|
||||
public FileBlock(KaitaiStream p__io, BlenderBlend p__parent = null, BlenderBlend p__root = null) : base(p__io) {
|
||||
public FileBlock(KaitaiStream p__io, BlendFile p__parent = null, BlendFile p__root = null) : base(p__io) {
|
||||
m_parent = p__parent;
|
||||
m_root = p__root;
|
||||
f_sdnaStruct = false;
|
||||
@@ -174,8 +174,8 @@ namespace Kaitai {
|
||||
private uint _sdnaIndex;
|
||||
private uint _count;
|
||||
private object _body;
|
||||
private BlenderBlend m_root;
|
||||
private BlenderBlend m_parent;
|
||||
private BlendFile m_root;
|
||||
private BlendFile m_parent;
|
||||
private byte[] __raw_body;
|
||||
|
||||
/// <summary>
|
||||
@@ -217,11 +217,11 @@ namespace Kaitai {
|
||||
get { return _body; }
|
||||
}
|
||||
|
||||
public BlenderBlend M_Root {
|
||||
public BlendFile M_Root {
|
||||
get { return m_root; }
|
||||
}
|
||||
|
||||
public BlenderBlend M_Parent {
|
||||
public BlendFile M_Parent {
|
||||
get { return m_parent; }
|
||||
}
|
||||
|
||||
@@ -251,7 +251,7 @@ namespace Kaitai {
|
||||
return new Dna1Body(new KaitaiStream(fileName));
|
||||
}
|
||||
|
||||
public Dna1Body(KaitaiStream p__io, BlenderBlend.FileBlock p__parent = null, BlenderBlend p__root = null) :
|
||||
public Dna1Body(KaitaiStream p__io, BlendFile.FileBlock p__parent = null, BlendFile p__root = null) :
|
||||
base(p__io) {
|
||||
m_parent = p__parent;
|
||||
m_root = p__root;
|
||||
@@ -319,8 +319,8 @@ namespace Kaitai {
|
||||
private byte[] _strcMagic;
|
||||
private uint _numStructs;
|
||||
private List<DnaStruct> _structs;
|
||||
private BlenderBlend m_root;
|
||||
private BlenderBlend.FileBlock m_parent;
|
||||
private BlendFile m_root;
|
||||
private BlendFile.FileBlock m_parent;
|
||||
|
||||
public byte[] Id {
|
||||
get { return _id; }
|
||||
@@ -382,11 +382,11 @@ namespace Kaitai {
|
||||
get { return _structs; }
|
||||
}
|
||||
|
||||
public BlenderBlend M_Root {
|
||||
public BlendFile M_Root {
|
||||
get { return m_root; }
|
||||
}
|
||||
|
||||
public BlenderBlend.FileBlock M_Parent {
|
||||
public BlendFile.FileBlock M_Parent {
|
||||
get { return m_parent; }
|
||||
}
|
||||
}
|
||||
@@ -396,7 +396,7 @@ namespace Kaitai {
|
||||
return new Header(new KaitaiStream(fileName));
|
||||
}
|
||||
|
||||
public Header(KaitaiStream p__io, BlenderBlend p__parent = null, BlenderBlend p__root = null) : base(p__io) {
|
||||
public Header(KaitaiStream p__io, BlendFile p__parent = null, BlendFile p__root = null) : base(p__io) {
|
||||
m_parent = p__parent;
|
||||
m_root = p__root;
|
||||
f_psize = false;
|
||||
@@ -409,8 +409,8 @@ namespace Kaitai {
|
||||
throw new ValidationNotEqualError(new byte[] { 66, 76, 69, 78, 68, 69, 82 }, Magic, M_Io,
|
||||
"/types/header/seq/0");
|
||||
}
|
||||
_ptrSizeId = ((BlenderBlend.PtrSize)m_io.ReadU1());
|
||||
_endian = ((BlenderBlend.Endian)m_io.ReadU1());
|
||||
_ptrSizeId = ((BlendFile.PtrSize)m_io.ReadU1());
|
||||
_endian = ((BlendFile.Endian)m_io.ReadU1());
|
||||
_version = System.Text.Encoding.GetEncoding("ASCII").GetString(m_io.ReadBytes(3));
|
||||
}
|
||||
|
||||
@@ -424,7 +424,7 @@ namespace Kaitai {
|
||||
get {
|
||||
if (f_psize)
|
||||
return _psize;
|
||||
_psize = (sbyte)((PtrSizeId == BlenderBlend.PtrSize.Bits64 ? 8 : 4));
|
||||
_psize = (sbyte)((PtrSizeId == BlendFile.PtrSize.Bits64 ? 8 : 4));
|
||||
f_psize = true;
|
||||
return _psize;
|
||||
}
|
||||
@@ -434,8 +434,8 @@ namespace Kaitai {
|
||||
private PtrSize _ptrSizeId;
|
||||
private Endian _endian;
|
||||
private string _version;
|
||||
private BlenderBlend m_root;
|
||||
private BlenderBlend m_parent;
|
||||
private BlendFile m_root;
|
||||
private BlendFile m_parent;
|
||||
|
||||
public byte[] Magic {
|
||||
get { return _magic; }
|
||||
@@ -462,11 +462,11 @@ namespace Kaitai {
|
||||
get { return _version; }
|
||||
}
|
||||
|
||||
public BlenderBlend M_Root {
|
||||
public BlendFile M_Root {
|
||||
get { return m_root; }
|
||||
}
|
||||
|
||||
public BlenderBlend M_Parent {
|
||||
public BlendFile M_Parent {
|
||||
get { return m_parent; }
|
||||
}
|
||||
}
|
||||
@@ -476,7 +476,7 @@ namespace Kaitai {
|
||||
return new DnaField(new KaitaiStream(fileName));
|
||||
}
|
||||
|
||||
public DnaField(KaitaiStream p__io, BlenderBlend.DnaStruct p__parent = null, BlenderBlend p__root = null) :
|
||||
public DnaField(KaitaiStream p__io, BlendFile.DnaStruct p__parent = null, BlendFile p__root = null) :
|
||||
base(p__io) {
|
||||
m_parent = p__parent;
|
||||
m_root = p__root;
|
||||
@@ -518,8 +518,8 @@ namespace Kaitai {
|
||||
|
||||
private ushort _idxType;
|
||||
private ushort _idxName;
|
||||
private BlenderBlend m_root;
|
||||
private BlenderBlend.DnaStruct m_parent;
|
||||
private BlendFile m_root;
|
||||
private BlendFile.DnaStruct m_parent;
|
||||
|
||||
public ushort IdxType {
|
||||
get { return _idxType; }
|
||||
@@ -529,11 +529,11 @@ namespace Kaitai {
|
||||
get { return _idxName; }
|
||||
}
|
||||
|
||||
public BlenderBlend M_Root {
|
||||
public BlendFile M_Root {
|
||||
get { return m_root; }
|
||||
}
|
||||
|
||||
public BlenderBlend.DnaStruct M_Parent {
|
||||
public BlendFile.DnaStruct M_Parent {
|
||||
get { return m_parent; }
|
||||
}
|
||||
}
|
||||
@@ -545,7 +545,7 @@ namespace Kaitai {
|
||||
get {
|
||||
if (f_sdnaStructs)
|
||||
return _sdnaStructs;
|
||||
_sdnaStructs = (List<DnaStruct>)(((BlenderBlend.Dna1Body)(Blocks[(Blocks.Count - 2)].Body)).Structs);
|
||||
_sdnaStructs = (List<DnaStruct>)(((BlendFile.Dna1Body)(Blocks[(Blocks.Count - 2)].Body)).Structs);
|
||||
f_sdnaStructs = true;
|
||||
return _sdnaStructs;
|
||||
}
|
||||
@@ -553,7 +553,7 @@ namespace Kaitai {
|
||||
|
||||
private Header _hdr;
|
||||
private List<FileBlock> _blocks;
|
||||
private BlenderBlend m_root;
|
||||
private BlendFile m_root;
|
||||
private KaitaiStruct m_parent;
|
||||
|
||||
public Header Hdr {
|
||||
@@ -564,7 +564,7 @@ namespace Kaitai {
|
||||
get { return _blocks; }
|
||||
}
|
||||
|
||||
public BlenderBlend M_Root {
|
||||
public BlendFile M_Root {
|
||||
get { return m_root; }
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using Kaitai;
|
||||
using Microsoft.CSharp;
|
||||
using BlendFile = Kaitai.BlenderBlend;
|
||||
|
||||
// ReSharper disable BitwiseOperatorOnEnumWithoutFlags
|
||||
namespace CodeGenerator {
|
||||
@@ -314,7 +313,7 @@ namespace CodeGenerator {
|
||||
return cad;
|
||||
}
|
||||
|
||||
private static CodeMemberField CreateMemberField(BlenderBlend.DnaField field) {
|
||||
private static CodeMemberField CreateMemberField(BlendFile.DnaField field) {
|
||||
Type t = Type.GetType(field.Type.ParseFType());
|
||||
CodeMemberField cmf;
|
||||
//Check if the type is a built-in type or a custom type
|
||||
@@ -327,7 +326,7 @@ namespace CodeGenerator {
|
||||
return cmf;
|
||||
}
|
||||
|
||||
private static CodeMemberField CreateArrayMemberField(BlenderBlend.DnaField field) {
|
||||
private static CodeMemberField CreateArrayMemberField(BlendFile.DnaField field) {
|
||||
Type t = Type.GetType(field.Type.ParseFType());
|
||||
CodeMemberField cmf;
|
||||
|
||||
@@ -395,7 +394,7 @@ namespace CodeGenerator {
|
||||
return ctc;
|
||||
}
|
||||
|
||||
private static CodeConstructor GenerateConstructor(BlenderBlend.DnaStruct type, CodeTypeDeclaration ctd) {
|
||||
private static CodeConstructor GenerateConstructor(BlendFile.DnaStruct type, CodeTypeDeclaration ctd) {
|
||||
//Create a normal constructor
|
||||
CodeConstructor cc = new CodeConstructor {
|
||||
Name = type.Type,
|
||||
|
||||
Reference in New Issue
Block a user