Fixed SDNA type determination and fixed multiple count per block
This commit is contained in:
@@ -28,31 +28,39 @@ public class Reader {
|
|||||||
|
|
||||||
foreach (var block in blend.Blocks)
|
foreach (var block in blend.Blocks)
|
||||||
{
|
{
|
||||||
if (block.Code != "DATA") continue;
|
//if (block.Code != "DATA") continue;
|
||||||
if(!dnaTypes.ContainsKey((int)block.SdnaIndex)) continue;
|
if(!dnaTypes.ContainsKey((int)block.SdnaIndex)) continue;
|
||||||
|
|
||||||
Type t = dnaTypes[(int)block.SdnaIndex];
|
Type t = dnaTypes.Values.First(x =>
|
||||||
var obj = Activator.CreateInstance(t);
|
x.GetCustomAttribute<DNAClassAttribute>()!.OriginalName == block.SdnaStruct.Type);
|
||||||
if(obj == null) continue;
|
|
||||||
objects.Add(obj);
|
var count = block.Count;
|
||||||
|
var blockOffset = 0;
|
||||||
|
for(var i=0; i<count; i++) {
|
||||||
|
var obj = Activator.CreateInstance(t);
|
||||||
|
if(obj == null) continue;
|
||||||
|
objects.Add(obj);
|
||||||
|
|
||||||
var fields = t.GetFields();
|
var fields = t.GetFields();
|
||||||
|
|
||||||
foreach (var field in fields) {
|
foreach (var field in fields) {
|
||||||
var attrib = field.GetCustomAttribute<DNAFieldAttribute>();
|
var attrib = field.GetCustomAttribute<DNAFieldAttribute>();
|
||||||
if (attrib == null) continue;
|
if (attrib == null) continue;
|
||||||
|
|
||||||
var offset = fields.Where(f => f.GetCustomAttribute<DNAFieldAttribute>()!.OriginalIndex < attrib.OriginalIndex)
|
var offset = fields.Where(f => f.GetCustomAttribute<DNAFieldAttribute>()!.OriginalIndex < attrib.OriginalIndex)
|
||||||
.Sum(f => f.GetCustomAttribute<DNAFieldAttribute>()!.Size);
|
.Sum(f => f.GetCustomAttribute<DNAFieldAttribute>()!.Size) + blockOffset;
|
||||||
var size = attrib.Size;
|
var size = attrib.Size;
|
||||||
|
|
||||||
byte[] data = new byte[size];
|
byte[] data = new byte[size];
|
||||||
Array.Copy((byte[])block.Body, offset, data, 0, size);
|
Array.Copy((byte[])block.Body, offset, data, 0, size);
|
||||||
|
|
||||||
var value = ConvertFieldData(data, attrib.OriginalType);
|
var value = ConvertFieldData(data, attrib.OriginalType);
|
||||||
if(value == null) continue;
|
if(value == null) continue;
|
||||||
|
|
||||||
field.SetValue(obj, value);
|
field.SetValue(obj, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
blockOffset += t.GetCustomAttribute<DNAClassAttribute>()!.Size;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user