Added IsPrincipal implementation

This commit is contained in:
Samuele Lorefice
2025-05-08 18:02:42 +02:00
parent e3c269af47
commit 679f15bce0

View File

@@ -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;
}
}