Formatting (again)

This commit is contained in:
Samuele Lorefice
2025-05-02 16:25:03 +02:00
parent a7337dd1d6
commit f03d907441

View File

@@ -49,9 +49,7 @@ public class Reader {
/// </summary> /// </summary>
/// <param name="memAddr">memory address in current system endianness</param> /// <param name="memAddr">memory address in current system endianness</param>
/// <returns>A <see cref="Kaitai.BlendFile.FileBlock"/> object</returns> /// <returns>A <see cref="Kaitai.BlendFile.FileBlock"/> object</returns>
public FileBlock? GetBlock(long memAddr) public FileBlock? GetBlock(long memAddr) {
{
var blocks = OrderedBlocks.Where(x => var blocks = OrderedBlocks.Where(x =>
memAddr >= x.MemAddr.ToPointer() && memAddr < x.MemAddr.ToPointer() + x.LenBody); memAddr >= x.MemAddr.ToPointer() && memAddr < x.MemAddr.ToPointer() + x.LenBody);
@@ -299,26 +297,24 @@ public class Reader {
return null; return null;
} }
private static int[] CalculateArrayIndices(List<int> sizes, int index) private static int[] CalculateArrayIndices(List<int> sizes, int index) {
{
int[] indexArray = new int[sizes.Count]; int[] indexArray = new int[sizes.Count];
for (int k = 0; k < sizes.Count; k++) { for (int k = 0; k < sizes.Count; k++) {
indexArray[k] = index/sizes[(k+1) ..].Aggregate(1, (a, b) => a * b) % sizes[k]; indexArray[k] = index / sizes[(k + 1) ..].Aggregate(1, (a, b) => a * b) % sizes[k];
} }
return indexArray; return indexArray;
} }
private Array FillPointersArray(DNAArrayAttribute arrayAttribute, byte[] data, private Array FillPointersArray(DNAArrayAttribute arrayAttribute, byte[] data,
Type type, List<int> sizes) Type type, List<int> sizes) {
{
//Create the array //Create the array
var array = Array.CreateInstance(type, sizes.ToArray()); var array = Array.CreateInstance(type, sizes.ToArray());
for (int i = 0; i < arrayAttribute.Size; i += 8) { for (int i = 0; i < arrayAttribute.Size; i += 8) {
var itemData = new byte[8]; var itemData = new byte[8];
Array.Copy(data, i, itemData, 0, 8); Array.Copy(data, i, itemData, 0, 8);
if(itemData.ToPointer() == IntPtr.Zero) continue; if (itemData.ToPointer() == IntPtr.Zero) continue;
object? cellData = ActivateInstance(type); object? cellData = ActivateInstance(type);
FillObject(itemData.ToPointer(), ref cellData, type.GetFields()); FillObject(itemData.ToPointer(), ref cellData, type.GetFields());
@@ -330,8 +326,8 @@ public class Reader {
return array; return array;
} }
private Array FillNormalTypeArray(DNAArrayAttribute arrayAttribute, byte[] data, FileBlock block, Type type, List<int> sizes, int itemLenght, int offset) private Array FillNormalTypeArray(DNAArrayAttribute arrayAttribute, byte[] data, FileBlock block, Type type,
{ List<int> sizes, int itemLenght, int offset) {
var array = Array.CreateInstance(type, sizes.ToArray()); var array = Array.CreateInstance(type, sizes.ToArray());
for (int i = 0; i < arrayAttribute.Size; i += itemLenght) { for (int i = 0; i < arrayAttribute.Size; i += itemLenght) {
@@ -347,8 +343,8 @@ public class Reader {
return array; return array;
} }
private Array FillCustomTypeArray(DNAArrayAttribute arrayAttribute, byte[] data, FileBlock block, Type type, List<int> sizes, int itemLenght, int offset) private Array FillCustomTypeArray(DNAArrayAttribute arrayAttribute, byte[] data, FileBlock block, Type type,
{ List<int> sizes, int itemLenght, int offset) {
var array = Array.CreateInstance(type, sizes.ToArray()); var array = Array.CreateInstance(type, sizes.ToArray());
for (int i = 0; i < arrayAttribute.Size; i += itemLenght) { for (int i = 0; i < arrayAttribute.Size; i += itemLenght) {
@@ -380,19 +376,18 @@ public class Reader {
var type = Type.GetType(arrayAttribute.OriginalType.ParseFType()) ?? dnaTypesDb[arrayAttribute.OriginalType]; var type = Type.GetType(arrayAttribute.OriginalType.ParseFType()) ?? dnaTypesDb[arrayAttribute.OriginalType];
if (type == null) throw new NotSupportedException($"Unknown type \"{arrayAttribute.OriginalType}\""); if (type == null) throw new NotSupportedException($"Unknown type \"{arrayAttribute.OriginalType}\"");
if(arrayAttribute.IsPointer){ if (arrayAttribute.IsPointer) {
return FillPointersArray(arrayAttribute, data, type, sizes); return FillPointersArray(arrayAttribute, data, type, sizes);
} }
if (!dnaTypesDb.ContainsKey(arrayAttribute.OriginalType)) { if (!dnaTypesDb.ContainsKey(arrayAttribute.OriginalType)) {
return FillNormalTypeArray(arrayAttribute, data, block, type, sizes,
return FillNormalTypeArray(arrayAttribute, data, block, type, sizes, arrayAttribute.OriginalType.ParseFSize()!.Value, offset.ToInt32()); arrayAttribute.OriginalType.ParseFSize()!.Value, offset.ToInt32());
} }
int itemLenght = type.GetCustomAttribute<DNAFieldAttribute>()?.Size ?? int itemLenght = type.GetCustomAttribute<DNAFieldAttribute>()?.Size ??
type.GetCustomAttribute<DNAClassAttribute>()!.Size; type.GetCustomAttribute<DNAClassAttribute>()!.Size;
return FillCustomTypeArray(arrayAttribute, data, block, type, sizes, itemLenght, offset.ToInt32()); return FillCustomTypeArray(arrayAttribute, data, block, type, sizes, itemLenght, offset.ToInt32());
} }
private object? ConvertListField(FileBlock block, FieldInfo field, DNAListAttribute attrib, IntPtr startOffset) { private object? ConvertListField(FileBlock block, FieldInfo field, DNAListAttribute attrib, IntPtr startOffset) {