Half-Handled generation of the same object, added docs, removed array specific handling from ConvertNormalField. Disabled exception thrown due to caveats.
This commit is contained in:
@@ -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!);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fills a given object from a block, using a pointer to the start of it's data
|
||||
/// </summary>
|
||||
/// <param name="ptr">pointer to the start of object</param>
|
||||
/// <param name="obj">reference to the object to be filled</param>
|
||||
/// <param name="fieldMetadata">field metadata info for that object</param>
|
||||
/// <exception cref="Exception">Thrown when the block the pointer is pointing to is not found.</exception>
|
||||
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}\"");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user