diff --git a/CodeGenerator/BlendExt.cs b/CodeGenerator/BlendExt.cs index 1fdb7ca..05da10a 100644 --- a/CodeGenerator/BlendExt.cs +++ b/CodeGenerator/BlendExt.cs @@ -1,9 +1,22 @@ +using System; +using System.CodeDom; +using System.Linq; +using System.Runtime.InteropServices.ComTypes; +using Kaitai; + namespace CodeGenerator; -public class BlendExt { +public static class BlendExt { //TODO: Add an bool IsPrincipal extension method to kaitai structs lib //A principal (or root) block is defined by having a two digit code and by the fact that its dna_index is always valid. //If we have a pointer to a principal block, we can ignore the type of the pointer and use the block type. //Subsidiary blocks are defined by having the code "DATA", which is ommited here. Their dna_index is not // always correct and is only used when whichever field points to them has an "invalid" type (like void*). + public static bool IsPrincipal(this BlendFile.FileBlock block) { + string[] dataTypes = ["REND", "TEST", "GLOB", "DATA", "DNA1"]; + bool isPrincipal = !dataTypes.Contains(block.Code); + if (isPrincipal && block.Count > 1) + throw new("Corrupt File detected. Principal block has more than one data type"); + return isPrincipal; + } } \ No newline at end of file