Fixed list length value returning always zero.

Added separated pointer and count memory offsets to list attributes.
Tried handling them
This commit is contained in:
Samuele Lorefice
2025-03-06 19:11:03 +01:00
parent 0bc7f73aee
commit fb50e3fa44
12 changed files with 75 additions and 48 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -77,16 +77,25 @@ namespace BlendFile {
this._CountFieldIndex = value;
}
}
private int _MemoryOffset;
public virtual int MemoryOffset {
private int _PtrMemoryOffset;
public virtual int PtrMemoryOffset {
get {
return this._MemoryOffset;
return this._PtrMemoryOffset;
}
set {
this._MemoryOffset = value;
this._PtrMemoryOffset = value;
}
}
public DNAListAttribute(int Size, string OriginalType, string OriginalName, int OriginalIndex, string UnderlyingType, string CountFieldName, int CountFieldIndex, int MemoryOffset) :
private int _CountMemoryOffset;
public virtual int CountMemoryOffset {
get {
return this._CountMemoryOffset;
}
set {
this._CountMemoryOffset = value;
}
}
public DNAListAttribute(int Size, string OriginalType, string OriginalName, int OriginalIndex, string UnderlyingType, string CountFieldName, int CountFieldIndex, int PtrMemoryOffset, int CountMemoryOffset) :
base(OriginalIndex, OriginalName) {
this._Size = Size;
this._OriginalType = OriginalType;
@@ -95,7 +104,8 @@ namespace BlendFile {
this._UnderlyingType = UnderlyingType;
this._CountFieldName = CountFieldName;
this._CountFieldIndex = CountFieldIndex;
this._MemoryOffset = MemoryOffset;
this._PtrMemoryOffset = PtrMemoryOffset;
this._CountMemoryOffset = CountMemoryOffset;
}
}
}

View File

@@ -15,6 +15,7 @@
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ASortedDictionary_002Ecs_002Fl_003AC_0021_003FUsers_003Fairon_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003Febdb3cec3b3875204585daa9fc42159a24cae33b2087ff4dc114d0e6a5a3e9_003FSortedDictionary_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AStringBuilder_002Ecs_002Fl_003AC_0021_003FUsers_003Fairon_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003Fc6a25ea096494870a1dd94f188bc2634db58c9faa8b319e415cadf49b913d1a_003FStringBuilder_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AThrowHelper_002Ecs_002Fl_003AC_0021_003FUsers_003Fairon_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F2c8e7ca976f350cba9836d5565dac56b11e0b56656fa786460eb1395857a6fa_003FThrowHelper_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AThrowHelper_002Ecs_002Fl_003AC_0021_003FUsers_003Fairon_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003Fc7da56581ee7b20208f09e80b735961e4d5d7b9e5562bfdec94a75c57b391_003FThrowHelper_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AThrowHelper_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F0beb96d31db641cf82014cb1a758a330b2dc00_003F3e_003F433607bb_003FThrowHelper_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AType_002Ecs_002Fl_003AC_0021_003FUsers_003Fairon_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003Fe7dbd6fe331ff9a3c4b24dd470ec1f19a71b7c5acf258b81ae7f761cd2b319b_003FType_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:Boolean x:Key="/Default/Dpa/IsEnabledInDebug/@EntryValue">True</s:Boolean>

View File

@@ -186,26 +186,40 @@ namespace CodeGenerator {
//Add the lists to the class
for (var index = 0; index < type.Fields.Count; index++) {
Dictionary<string, int> listCountOffsets = new();
var field = type.Fields[index];
//Skip fields that are not part of a list
if (!listFields.Select(f => f.Item1).Contains(field)) {
if (listFields.Select(f => f.Item1).Contains(field)) {
//Retrieve the list pointer and the list length fields
var (listPointer, listLength) = listFields.FirstOrDefault(x => x.Item1 == field);
//retrieve the offset of the list length field if exists
listCountOffsets.TryGetValue(listLength.Name, out int listLenghtOffset);
//Retrieve the index of the list length field
int sizeIndex = type.Fields.IndexOf(listLength);
Log($"Generating list field {listPointer.Name}");
var cmf = CreateListMemberField(listPointer, listLength);
var attribute = GenerateDnaListAttribute(index, listPointer, sizeIndex, listLength, totalSize,
listLenghtOffset, out int size);
totalSize += size;
cmf.CustomAttributes.Add(attribute);
ctd.Members.Add(cmf);
} else if (listFields.Select(f => f.Item2).Contains(field)) {
//Retrieve the list length field
string fName = field.Name.ParseFName();
//Try seeing if the list attribute is already present
var x = ctd.Members.OfType<CodeMemberField>().FirstOrDefault(member => member.Name == fName);
if (x != null) //Update the existing list attribute
x.CustomAttributes[0].Arguments[5] = new(new CodePrimitiveExpression(totalSize));
else //Store the data for when the list attribute is made
listCountOffsets.Add(fName, totalSize);
} else {
Log($"Field {field.Name} is not part of a list, skipping");
continue;
}
//Retrieve the list pointer and the list length fields
var (listPointer, listLength) = listFields.FirstOrDefault(x => x.Item1 == field);
//Retrieve the index of the list length field
int sizeIndex = type.Fields.IndexOf(listLength);
Log($"Generating list field {listPointer.Name}");
var cmf = CreateListMemberField(listPointer, listLength);
var attribute = GenerateDnaListAttribute(index, listPointer, listPointer.M_Parent.M_Parent, sizeIndex,
listLength, totalSize, out int size);
totalSize += size;
cmf.CustomAttributes.Add(attribute);
ctd.Members.Add(cmf);
}
ctd.CustomAttributes[0].Arguments.Add(new (new CodePrimitiveExpression(totalSize)));
@@ -340,7 +354,8 @@ namespace CodeGenerator {
.AddAutoProperty(typeof(string), "UnderlyingType")
.AddAutoProperty(typeof(string), "CountFieldName")
.AddAutoProperty(typeof(int), "CountFieldIndex")
.AddAutoProperty(typeof(int), "MemoryOffset")
.AddAutoProperty(typeof(int), "PtrMemoryOffset")
.AddAutoProperty(typeof(int), "CountMemoryOffset")
.AddPropertiesConstructor()
.AddBaseConstructorParams(["OriginalIndex", "OriginalName"])
.Build()
@@ -397,8 +412,8 @@ namespace CodeGenerator {
}
private static CodeAttributeDeclaration GenerateDnaListAttribute(int listIndex, BlendFile.DnaField listField,
BlendFile.Dna1Body body, int lenghtIndex, BlendFile.DnaField lenghtField, int offset, out int size) {
size = 0;
int lenghtIndex, BlendFile.DnaField lenghtField, int ptrOffset, int countOffset, out int size) {
size = 8;
var cad = new CodeAttributeDeclaration("DNAListAttribute");
cad.Arguments.AddRange(new CodeAttributeArgumentCollection() {
new(new CodeSnippetExpression("8")),//pointer size
@@ -408,7 +423,8 @@ namespace CodeGenerator {
new(new CodePrimitiveExpression(listField.Type)),//TODO: double check this
new(new CodePrimitiveExpression(lenghtField.Name)),
new(new CodePrimitiveExpression(lenghtIndex)),
new(new CodePrimitiveExpression(offset))
new(new CodePrimitiveExpression(ptrOffset)),
new(new CodePrimitiveExpression(countOffset))
});
return cad;
}