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:
Samuele Lorefice
2025-03-12 01:54:56 +01:00
parent c0bc1f0a0f
commit 8202c2185b
2 changed files with 16 additions and 20 deletions

View File

@@ -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}\"");
}

View File

@@ -4,6 +4,7 @@
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AArgumentOutOfRangeException_002Ecs_002Fl_003AC_0021_003FUsers_003Fairon_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F72e5853ed6f2c1967eff9d6f0cf6ba12744c8978c516cbc5e74d992944ab_003FArgumentOutOfRangeException_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AArray_002ECoreCLR_002Ecs_002Fl_003AC_0021_003FUsers_003Fairon_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003Fee3c9d264411441f56a12bac52a58ad25b495ef52e59b4a86f8478158f7d_003FArray_002ECoreCLR_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AArray_002ECoreCLR_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F51b332f64116ca1bf68931ca13adc3cd38b6dd2da04af6aef46bd08d218e58b5_003FArray_002ECoreCLR_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AArray_002Ecs_002Fl_003AC_0021_003FUsers_003Fairon_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F96178db1709e872c391367fef1b31fca80f9f18119cdf4145a2650ac9f332ac_003FArray_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ACodeConstructor_002Ecs_002Fl_003AC_0021_003FUsers_003Fairon_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003Fbe433ced0c0d9b3aa171b7fbcd7df89ef13497cab9fb55640c7d49c891f_003FCodeConstructor_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ACodeDomProvider_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F4333c036d67eaa64623a27221cb821b663bc08410ac68797b1c10376d8379fe_003FCodeDomProvider_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ACodeExpression_002Ecs_002Fl_003AC_0021_003FUsers_003Fairon_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F3127868066451f65e848b2ed6b9f84913de3cfb771a33c5f1bf5f1ba22c12e_003FCodeExpression_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>