diff --git a/BlendFile/Reader.cs b/BlendFile/Reader.cs
index 30996ed..8b1ad3c 100644
--- a/BlendFile/Reader.cs
+++ b/BlendFile/Reader.cs
@@ -201,16 +201,19 @@ public class Reader {
field.SetValue(obj, value);
//Add the freshly handled object to the database
- objects.Add((block.MemAddr.ToPointer() + startOffset, obj!.GetType()), obj!);
+ objects.TryAdd((block.MemAddr.ToPointer() + startOffset, obj!.GetType()), obj!);
}
//Add the freshly handled object to the database
- objects.Add((block.MemAddr.ToPointer() + startOffset, obj!.GetType()), obj!);
- }
-
- private object? ConvertArrayField(FileBlock block, FieldInfo field, DNAArrayAttribute arrayAttribute, IntPtr startOffset) {
- throw new NotImplementedException();
+ objects.TryAdd((block.MemAddr.ToPointer() + startOffset, obj!.GetType()), obj!);
}
+ ///
+ /// Fills a given object from a block, using a pointer to the start of it's data
+ ///
+ /// pointer to the start of object
+ /// reference to the object to be filled
+ /// field metadata info for that object
+ /// Thrown when the block the pointer is pointing to is not found.
private void FillObject(IntPtr ptr, ref object? obj, FieldInfo[] fieldMetadata)
{
var block = GetBlock(ptr.ToInt64());
@@ -219,7 +222,7 @@ public class Reader {
var blockOffset = ptr.ToInt64() - block.MemAddr.ToPointer();
FillObject(block, ref obj, fieldMetadata, new IntPtr(blockOffset));
}
-
+
private object? ConvertNormalField(FileBlock block, DNAFieldAttribute attrib, IntPtr startOffset) {
//Calculate the offset from where the data of the field starts.
//Because the order of the fields is not guaranteed we need to compute it each time
@@ -229,20 +232,7 @@ public class Reader {
int size = attrib.Size;
var data = new byte[size];
Array.Copy((byte[])block.Body, offset, data, 0, size);
-
-
- //Check if it's an array
- if (Type.GetType(attrib.UnderlyingType) is { IsArray: true }) {
- int itemLenght = attrib.OriginalType.ParseFSize();
- var array = new object?[attrib.Size / itemLenght];
- for (int i = 0; i < attrib.Size; i += itemLenght) {
- var itemData = new byte[itemLenght];
- Array.Copy(data, i, itemData, 0, itemLenght);
- array[i / itemLenght] = ConvertFieldData(itemData, attrib.OriginalType);
- }
- return array;
- }
//Convert the data to the correct type if it's a base type
object? value = ConvertFieldData(data, attrib.OriginalType);
if (value != null) return value;
@@ -269,7 +259,12 @@ public class Reader {
if (memAddr == 0) return null; //nullPointer, no need to store the reference
pointers.TryAdd(block.MemAddr.ToPointer() + offset, data.ToPointer());
}
+ } else {
+ //TODO: handle void types. This gets spammed
+ //throw new NotSupportedException($"Unknown type \"{attrib.OriginalType}\"");
}
+ return null;
+ }
throw new NotSupportedException($"Unknown type \"{attrib.OriginalType}\"");
}
diff --git a/BlenderSharp.sln.DotSettings.user b/BlenderSharp.sln.DotSettings.user
index 7f84612..347eb6e 100644
--- a/BlenderSharp.sln.DotSettings.user
+++ b/BlenderSharp.sln.DotSettings.user
@@ -4,6 +4,7 @@
ForceIncluded
ForceIncluded
ForceIncluded
+ ForceIncluded
ForceIncluded
ForceIncluded
ForceIncluded