Added count field type argument to the list attribute

This commit is contained in:
Samuele Lorefice
2025-03-06 19:41:37 +01:00
parent e11cd54096
commit bfa185c8e4
12 changed files with 59 additions and 28 deletions

View File

@@ -13,15 +13,15 @@ using System;
namespace BlendFile.DNA { namespace BlendFile.DNA {
using BlendFile; using BlendFile;
[DNAClassAttribute(63, "ActionChannelBag", 24)] [DNAClassAttribute(63, "ActionChannelBag", 32)]
public class ActionChannelBag { public class ActionChannelBag {
[DNAFieldAttribute(4, "int", 0, "slot_handle", "int", false, 0)] [DNAFieldAttribute(4, "int", 0, "slot_handle", "int", false, 0)]
public int slot_handle; public int slot_handle;
[DNAFieldAttribute(4, "uchar", 3, "_pad[4]", "System.Byte[]", false, 4)] [DNAFieldAttribute(4, "uchar", 3, "_pad[4]", "System.Byte[]", false, 4)]
public byte[] _pad = new System.Byte[4]; public byte[] _pad = new System.Byte[4];
[DNAListAttribute(8, "bActionGroup", "**group_array", 2, "bActionGroup", "group_array_num", 1, 8, 8)] [DNAListAttribute(8, "bActionGroup", "**group_array", 2, "bActionGroup", "int", "group_array_num", 1, 12, 8)]
public System.Collections.Generic.List<bActionGroup> group_array; public System.Collections.Generic.List<bActionGroup> group_array;
[DNAListAttribute(8, "FCurve", "**fcurve_array", 5, "FCurve", "fcurve_array_num", 4, 16, 16)] [DNAListAttribute(8, "FCurve", "**fcurve_array", 5, "FCurve", "int", "fcurve_array_num", 4, 24, 20)]
public System.Collections.Generic.List<FCurve> fcurve_array; public System.Collections.Generic.List<FCurve> fcurve_array;
public ActionChannelBag() { public ActionChannelBag() {
this.slot_handle = default; this.slot_handle = default;

View File

@@ -13,7 +13,7 @@ using System;
namespace BlendFile.DNA { namespace BlendFile.DNA {
using BlendFile; using BlendFile;
[DNAClassAttribute(66, "ActionLayer", 84)] [DNAClassAttribute(66, "ActionLayer", 88)]
public class ActionLayer { public class ActionLayer {
[DNAFieldAttribute(64, "char", 0, "name[64]", "System.Char[]", false, 0)] [DNAFieldAttribute(64, "char", 0, "name[64]", "System.Char[]", false, 0)]
public char[] name = new System.Char[64]; public char[] name = new System.Char[64];
@@ -27,7 +27,7 @@ namespace BlendFile.DNA {
public byte[] _pad0 = new System.Byte[2]; public byte[] _pad0 = new System.Byte[2];
[DNAFieldAttribute(4, "uchar", 7, "_pad1[4]", "System.Byte[]", false, 72)] [DNAFieldAttribute(4, "uchar", 7, "_pad1[4]", "System.Byte[]", false, 72)]
public byte[] _pad1 = new System.Byte[4]; public byte[] _pad1 = new System.Byte[4];
[DNAListAttribute(8, "ActionStrip", "**strip_array", 5, "ActionStrip", "strip_array_num", 6, 76, 0)] [DNAListAttribute(8, "ActionStrip", "**strip_array", 5, "ActionStrip", "int", "strip_array_num", 6, 76, 0)]
public System.Collections.Generic.List<ActionStrip> strip_array; public System.Collections.Generic.List<ActionStrip> strip_array;
public ActionLayer() { public ActionLayer() {
this.name = default; this.name = default;

View File

@@ -13,11 +13,11 @@ using System;
namespace BlendFile.DNA { namespace BlendFile.DNA {
using BlendFile; using BlendFile;
[DNAClassAttribute(68, "ActionStripKeyframeData", 12)] [DNAClassAttribute(68, "ActionStripKeyframeData", 16)]
public class ActionStripKeyframeData { public class ActionStripKeyframeData {
[DNAFieldAttribute(4, "uchar", 2, "_pad[4]", "System.Byte[]", false, 0)] [DNAFieldAttribute(4, "uchar", 2, "_pad[4]", "System.Byte[]", false, 0)]
public byte[] _pad = new System.Byte[4]; public byte[] _pad = new System.Byte[4];
[DNAListAttribute(8, "ActionChannelBag", "**channelbag_array", 0, "ActionChannelBag", "channelbag_array_num", 1, 4, 0)] [DNAListAttribute(8, "ActionChannelBag", "**channelbag_array", 0, "ActionChannelBag", "int", "channelbag_array_num", 1, 4, 0)]
public System.Collections.Generic.List<ActionChannelBag> channelbag_array; public System.Collections.Generic.List<ActionChannelBag> channelbag_array;
public ActionStripKeyframeData() { public ActionStripKeyframeData() {
this._pad = default; this._pad = default;

View File

@@ -13,7 +13,7 @@ using System;
namespace BlendFile.DNA { namespace BlendFile.DNA {
using BlendFile; using BlendFile;
[DNAClassAttribute(311, "GreasePencil", 586)] [DNAClassAttribute(311, "GreasePencil", 592)]
public class GreasePencil { public class GreasePencil {
[DNAFieldAttribute(208, "ID", 0, "id", "ID", false, 0)] [DNAFieldAttribute(208, "ID", 0, "id", "ID", false, 0)]
public ID id; public ID id;
@@ -45,9 +45,9 @@ namespace BlendFile.DNA {
public GreasePencilOnionSkinningSettings onion_skinning_settings; public GreasePencilOnionSkinningSettings onion_skinning_settings;
[DNAFieldAttribute(8, "GreasePencilRuntimeHandle", 18, "*runtime", "GreasePencilRuntimeHandle", true, 562)] [DNAFieldAttribute(8, "GreasePencilRuntimeHandle", 18, "*runtime", "GreasePencilRuntimeHandle", true, 562)]
public GreasePencilRuntimeHandle runtime; public GreasePencilRuntimeHandle runtime;
[DNAListAttribute(8, "GreasePencilDrawingBase", "**drawing_array", 2, "GreasePencilDrawingBase", "drawing_array_size", 3, 570, 0)] [DNAListAttribute(8, "GreasePencilDrawingBase", "**drawing_array", 2, "GreasePencilDrawingBase", "int", "drawing_array_size", 3, 570, 0)]
public System.Collections.Generic.List<GreasePencilDrawingBase> drawing_array; public System.Collections.Generic.List<GreasePencilDrawingBase> drawing_array;
[DNAListAttribute(8, "Material", "**material_array", 10, "Material", "material_array_size", 11, 578, 0)] [DNAListAttribute(8, "Material", "**material_array", 10, "Material", "short", "material_array_size", 11, 582, 0)]
public System.Collections.Generic.List<Material> material_array; public System.Collections.Generic.List<Material> material_array;
public GreasePencil() { public GreasePencil() {
this.id = default; this.id = default;

View File

@@ -13,7 +13,7 @@ using System;
namespace BlendFile.DNA { namespace BlendFile.DNA {
using BlendFile; using BlendFile;
[DNAClassAttribute(19, "IDPropertyUIDataBool", 28)] [DNAClassAttribute(19, "IDPropertyUIDataBool", 32)]
public class IDPropertyUIDataBool { public class IDPropertyUIDataBool {
[DNAFieldAttribute(16, "IDPropertyUIData", 0, "base", "IDPropertyUIData", false, 0)] [DNAFieldAttribute(16, "IDPropertyUIData", 0, "base", "IDPropertyUIData", false, 0)]
public IDPropertyUIData @base; public IDPropertyUIData @base;
@@ -21,7 +21,7 @@ namespace BlendFile.DNA {
public char[] _pad = new System.Char[3]; public char[] _pad = new System.Char[3];
[DNAFieldAttribute(1, "int8_t", 4, "default_value", "int8_t", false, 19)] [DNAFieldAttribute(1, "int8_t", 4, "default_value", "int8_t", false, 19)]
public sbyte default_value; public sbyte default_value;
[DNAListAttribute(8, "int8_t", "*default_array", 1, "int8_t", "default_array_len", 2, 20, 0)] [DNAListAttribute(8, "int8_t", "*default_array", 1, "int8_t", "int", "default_array_len", 2, 20, 0)]
public System.Collections.Generic.List<sbyte> default_array; public System.Collections.Generic.List<sbyte> default_array;
public IDPropertyUIDataBool() { public IDPropertyUIDataBool() {
this.@base = default; this.@base = default;

View File

@@ -13,7 +13,7 @@ using System;
namespace BlendFile.DNA { namespace BlendFile.DNA {
using BlendFile; using BlendFile;
[DNAClassAttribute(20, "IDPropertyUIDataFloat", 76)] [DNAClassAttribute(20, "IDPropertyUIDataFloat", 80)]
public class IDPropertyUIDataFloat { public class IDPropertyUIDataFloat {
[DNAFieldAttribute(16, "IDPropertyUIData", 0, "base", "IDPropertyUIData", false, 0)] [DNAFieldAttribute(16, "IDPropertyUIData", 0, "base", "IDPropertyUIData", false, 0)]
public IDPropertyUIData @base; public IDPropertyUIData @base;
@@ -33,7 +33,7 @@ namespace BlendFile.DNA {
public double soft_max; public double soft_max;
[DNAFieldAttribute(8, "double", 10, "default_value", "double", false, 60)] [DNAFieldAttribute(8, "double", 10, "default_value", "double", false, 60)]
public double default_value; public double default_value;
[DNAListAttribute(8, "double", "*default_array", 1, "double", "default_array_len", 2, 68, 0)] [DNAListAttribute(8, "double", "*default_array", 1, "double", "int", "default_array_len", 2, 68, 0)]
public System.Collections.Generic.List<double> default_array; public System.Collections.Generic.List<double> default_array;
public IDPropertyUIDataFloat() { public IDPropertyUIDataFloat() {
this.@base = default; this.@base = default;

View File

@@ -13,7 +13,7 @@ using System;
namespace BlendFile.DNA { namespace BlendFile.DNA {
using BlendFile; using BlendFile;
[DNAClassAttribute(18, "IDPropertyUIDataInt", 60)] [DNAClassAttribute(18, "IDPropertyUIDataInt", 64)]
public class IDPropertyUIDataInt { public class IDPropertyUIDataInt {
[DNAFieldAttribute(16, "IDPropertyUIData", 0, "base", "IDPropertyUIData", false, 0)] [DNAFieldAttribute(16, "IDPropertyUIData", 0, "base", "IDPropertyUIData", false, 0)]
public IDPropertyUIData @base; public IDPropertyUIData @base;
@@ -33,7 +33,7 @@ namespace BlendFile.DNA {
public int enum_items_num; public int enum_items_num;
[DNAFieldAttribute(8, "IDPropertyUIDataEnumItem", 10, "*enum_items", "IDPropertyUIDataEnumItem", true, 44)] [DNAFieldAttribute(8, "IDPropertyUIDataEnumItem", 10, "*enum_items", "IDPropertyUIDataEnumItem", true, 44)]
public IDPropertyUIDataEnumItem enum_items; public IDPropertyUIDataEnumItem enum_items;
[DNAListAttribute(8, "int", "*default_array", 1, "int", "default_array_len", 2, 52, 0)] [DNAListAttribute(8, "int", "*default_array", 1, "int", "int", "default_array_len", 2, 52, 0)]
public System.Collections.Generic.List<int> default_array; public System.Collections.Generic.List<int> default_array;
public IDPropertyUIDataInt() { public IDPropertyUIDataInt() {
this.@base = default; this.@base = default;

View File

@@ -13,7 +13,7 @@ using System;
namespace BlendFile.DNA { namespace BlendFile.DNA {
using BlendFile; using BlendFile;
[DNAClassAttribute(65, "bAction", 340)] [DNAClassAttribute(65, "bAction", 352)]
public class bAction { public class bAction {
[DNAFieldAttribute(208, "ID", 0, "id", "ID", false, 0)] [DNAFieldAttribute(208, "ID", 0, "id", "ID", false, 0)]
public ID id; public ID id;
@@ -45,11 +45,11 @@ namespace BlendFile.DNA {
public float frame_end; public float frame_end;
[DNAFieldAttribute(8, "PreviewImage", 20, "*preview", "PreviewImage", true, 308)] [DNAFieldAttribute(8, "PreviewImage", 20, "*preview", "PreviewImage", true, 308)]
public PreviewImage preview; public PreviewImage preview;
[DNAListAttribute(8, "ActionLayer", "**layer_array", 1, "ActionLayer", "layer_array_num", 2, 316, 0)] [DNAListAttribute(8, "ActionLayer", "**layer_array", 1, "ActionLayer", "int", "layer_array_num", 2, 316, 0)]
public System.Collections.Generic.List<ActionLayer> layer_array; public System.Collections.Generic.List<ActionLayer> layer_array;
[DNAListAttribute(8, "ActionSlot", "**slot_array", 4, "ActionSlot", "slot_array_num", 5, 324, 0)] [DNAListAttribute(8, "ActionSlot", "**slot_array", 4, "ActionSlot", "int", "slot_array_num", 5, 328, 0)]
public System.Collections.Generic.List<ActionSlot> slot_array; public System.Collections.Generic.List<ActionSlot> slot_array;
[DNAListAttribute(8, "ActionStripKeyframeData", "**strip_keyframe_data_array", 7, "ActionStripKeyframeData", "strip_keyframe_data_array_num", 8, 332, 0)] [DNAListAttribute(8, "ActionStripKeyframeData", "**strip_keyframe_data_array", 7, "ActionStripKeyframeData", "int", "strip_keyframe_data_array_num", 8, 340, 0)]
public System.Collections.Generic.List<ActionStripKeyframeData> strip_keyframe_data_array; public System.Collections.Generic.List<ActionStripKeyframeData> strip_keyframe_data_array;
public bAction() { public bAction() {
this.id = default; this.id = default;

View File

@@ -13,7 +13,7 @@ using System;
namespace BlendFile.DNA { namespace BlendFile.DNA {
using BlendFile; using BlendFile;
[DNAClassAttribute(106, "bArmature", 412)] [DNAClassAttribute(106, "bArmature", 416)]
public class bArmature { public class bArmature {
[DNAFieldAttribute(208, "ID", 0, "id", "ID", false, 0)] [DNAFieldAttribute(208, "ID", 0, "id", "ID", false, 0)]
public ID id; public ID id;
@@ -59,7 +59,7 @@ namespace BlendFile.DNA {
public float axes_position; public float axes_position;
[DNAFieldAttribute(16, "bArmature_Runtime", 23, "runtime", "bArmature_Runtime", false, 388)] [DNAFieldAttribute(16, "bArmature_Runtime", 23, "runtime", "bArmature_Runtime", false, 388)]
public bArmature_Runtime runtime; public bArmature_Runtime runtime;
[DNAListAttribute(8, "BoneCollection", "**collection_array", 15, "BoneCollection", "collection_array_num", 16, 404, 0)] [DNAListAttribute(8, "BoneCollection", "**collection_array", 15, "BoneCollection", "int", "collection_array_num", 16, 404, 0)]
public System.Collections.Generic.List<BoneCollection> collection_array; public System.Collections.Generic.List<BoneCollection> collection_array;
public bArmature() { public bArmature() {
this.id = default; this.id = default;

View File

@@ -59,6 +59,15 @@ namespace BlendFile {
this._UnderlyingType = value; this._UnderlyingType = value;
} }
} }
private string _CountFieldType;
public virtual string CountFieldType {
get {
return this._CountFieldType;
}
set {
this._CountFieldType = value;
}
}
private string _CountFieldName; private string _CountFieldName;
public virtual string CountFieldName { public virtual string CountFieldName {
get { get {
@@ -95,13 +104,14 @@ namespace BlendFile {
this._CountMemoryOffset = value; this._CountMemoryOffset = value;
} }
} }
public DNAListAttribute(int Size, string OriginalType, string OriginalName, int OriginalIndex, string UnderlyingType, string CountFieldName, int CountFieldIndex, int PtrMemoryOffset, int CountMemoryOffset) : public DNAListAttribute(int Size, string OriginalType, string OriginalName, int OriginalIndex, string UnderlyingType, string CountFieldType, string CountFieldName, int CountFieldIndex, int PtrMemoryOffset, int CountMemoryOffset) :
base(OriginalIndex, OriginalName) { base(OriginalIndex, OriginalName) {
this._Size = Size; this._Size = Size;
this._OriginalType = OriginalType; this._OriginalType = OriginalType;
this._OriginalName = OriginalName; this._OriginalName = OriginalName;
this._OriginalIndex = OriginalIndex; this._OriginalIndex = OriginalIndex;
this._UnderlyingType = UnderlyingType; this._UnderlyingType = UnderlyingType;
this._CountFieldType = CountFieldType;
this._CountFieldName = CountFieldName; this._CountFieldName = CountFieldName;
this._CountFieldIndex = CountFieldIndex; this._CountFieldIndex = CountFieldIndex;
this._PtrMemoryOffset = PtrMemoryOffset; this._PtrMemoryOffset = PtrMemoryOffset;

View File

@@ -188,17 +188,17 @@ namespace CodeGenerator {
//Add the lists to the class //Add the lists to the class
for (var index = 0; index < type.Fields.Count; index++) { for (var index = 0; index < type.Fields.Count; index++) {
var field = type.Fields[index]; var field = type.Fields[index];
//Skip fields that are not part of a list if (listFields.Select(f => f.Item1).Contains(field)) { //Field is pointer of list
if (listFields.Select(f => f.Item1).Contains(field)) {
//Retrieve the list pointer and the list length fields //Retrieve the list pointer and the list length fields
var (listPointer, listLength) = listFields.FirstOrDefault(x => x.Item1 == field); var (listPointer, listLength) = listFields.FirstOrDefault(x => x.Item1 == field);
Log($"Generating list field {listPointer.Name}");
//retrieve the offset of the list length field if exists //retrieve the offset of the list length field if exists
listCountOffsets.TryGetValue(listLength.Name, out int listLenghtOffset); listCountOffsets.TryGetValue(listLength.Name, out int listLenghtOffset);
//Retrieve the index of the list length field //Retrieve the index of the list length field
int sizeIndex = type.Fields.IndexOf(listLength); int sizeIndex = type.Fields.IndexOf(listLength);
Log($"Generating list field {listPointer.Name}");
var cmf = CreateListMemberField(listPointer, listLength); var cmf = CreateListMemberField(listPointer, listLength);
var attribute = GenerateDnaListAttribute(index, listPointer, sizeIndex, listLength, totalSize, var attribute = GenerateDnaListAttribute(index, listPointer, sizeIndex, listLength, totalSize,
@@ -207,7 +207,7 @@ namespace CodeGenerator {
totalSize += size; totalSize += size;
cmf.CustomAttributes.Add(attribute); cmf.CustomAttributes.Add(attribute);
ctd.Members.Add(cmf); ctd.Members.Add(cmf);
} else if (listFields.Select(f => f.Item2).Contains(field)) { } else if (listFields.Select(f => f.Item2).Contains(field)) { // field is list length
//Retrieve the list length field //Retrieve the list length field
string fName = field.Name.ParseFName(); string fName = field.Name.ParseFName();
//Try seeing if the list attribute is already present //Try seeing if the list attribute is already present
@@ -217,7 +217,9 @@ namespace CodeGenerator {
x.CustomAttributes[0].Arguments[5] = new(new CodePrimitiveExpression(totalSize)); x.CustomAttributes[0].Arguments[5] = new(new CodePrimitiveExpression(totalSize));
else //Store the data for when the list attribute is made else //Store the data for when the list attribute is made
listCountOffsets.Add(fName, totalSize); listCountOffsets.Add(fName, totalSize);
} else {
totalSize += field.Type.ParseFSize();
} else { //Skip fields that are not part of a list
Log($"Field {field.Name} is not part of a list, skipping"); Log($"Field {field.Name} is not part of a list, skipping");
} }
} }
@@ -352,6 +354,7 @@ namespace CodeGenerator {
.AddAutoProperty(typeof(string), "OriginalName") .AddAutoProperty(typeof(string), "OriginalName")
.AddAutoProperty(typeof(int), "OriginalIndex") .AddAutoProperty(typeof(int), "OriginalIndex")
.AddAutoProperty(typeof(string), "UnderlyingType") .AddAutoProperty(typeof(string), "UnderlyingType")
.AddAutoProperty(typeof(string), "CountFieldType")
.AddAutoProperty(typeof(string), "CountFieldName") .AddAutoProperty(typeof(string), "CountFieldName")
.AddAutoProperty(typeof(int), "CountFieldIndex") .AddAutoProperty(typeof(int), "CountFieldIndex")
.AddAutoProperty(typeof(int), "PtrMemoryOffset") .AddAutoProperty(typeof(int), "PtrMemoryOffset")
@@ -421,6 +424,7 @@ namespace CodeGenerator {
new(new CodePrimitiveExpression(listField.Name)), new(new CodePrimitiveExpression(listField.Name)),
new(new CodePrimitiveExpression(listIndex)), new(new CodePrimitiveExpression(listIndex)),
new(new CodePrimitiveExpression(listField.Type)),//TODO: double check this new(new CodePrimitiveExpression(listField.Type)),//TODO: double check this
new(new CodePrimitiveExpression(lenghtField.Type)),
new(new CodePrimitiveExpression(lenghtField.Name)), new(new CodePrimitiveExpression(lenghtField.Name)),
new(new CodePrimitiveExpression(lenghtIndex)), new(new CodePrimitiveExpression(lenghtIndex)),
new(new CodePrimitiveExpression(ptrOffset)), new(new CodePrimitiveExpression(ptrOffset)),

View File

@@ -26,5 +26,22 @@ namespace CodeGenerator {
_ => str _ => str
}; };
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int ParseFSize(this string str) {
return str switch {
"char" => sizeof(char),
"short" => sizeof(short),
"int" => sizeof(int),
"float" => sizeof(float),
"double" => sizeof(double),
"ushort" => sizeof(ushort),
"uchar" => sizeof(byte),
"int64_t" => sizeof(long),
"int8_t" => sizeof(sbyte),
"uint64_t" => sizeof(ulong),
_ => throw new("Unknown type")
};
}
} }
} }