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)
|
||||
{
|
||||
if (block.Code != "DATA") continue;
|
||||
//if (block.Code != "DATA") continue;
|
||||
if(!dnaTypes.ContainsKey((int)block.SdnaIndex)) continue;
|
||||
|
||||
Type t = dnaTypes[(int)block.SdnaIndex];
|
||||
var obj = Activator.CreateInstance(t);
|
||||
if(obj == null) continue;
|
||||
objects.Add(obj);
|
||||
Type t = dnaTypes.Values.First(x =>
|
||||
x.GetCustomAttribute<DNAClassAttribute>()!.OriginalName == block.SdnaStruct.Type);
|
||||
|
||||
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) {
|
||||
var attrib = field.GetCustomAttribute<DNAFieldAttribute>();
|
||||
if (attrib == null) continue;
|
||||
foreach (var field in fields) {
|
||||
var attrib = field.GetCustomAttribute<DNAFieldAttribute>();
|
||||
if (attrib == null) continue;
|
||||
|
||||
var offset = fields.Where(f => f.GetCustomAttribute<DNAFieldAttribute>()!.OriginalIndex < attrib.OriginalIndex)
|
||||
.Sum(f => f.GetCustomAttribute<DNAFieldAttribute>()!.Size);
|
||||
var size = attrib.Size;
|
||||
var offset = fields.Where(f => f.GetCustomAttribute<DNAFieldAttribute>()!.OriginalIndex < attrib.OriginalIndex)
|
||||
.Sum(f => f.GetCustomAttribute<DNAFieldAttribute>()!.Size) + blockOffset;
|
||||
var size = attrib.Size;
|
||||
|
||||
byte[] data = new byte[size];
|
||||
Array.Copy((byte[])block.Body, offset, data, 0, size);
|
||||
byte[] data = new byte[size];
|
||||
Array.Copy((byte[])block.Body, offset, data, 0, size);
|
||||
|
||||
var value = ConvertFieldData(data, attrib.OriginalType);
|
||||
if(value == null) continue;
|
||||
var value = ConvertFieldData(data, attrib.OriginalType);
|
||||
if(value == null) continue;
|
||||
|
||||
field.SetValue(obj, value);
|
||||
field.SetValue(obj, value);
|
||||
}
|
||||
|
||||
blockOffset += t.GetCustomAttribute<DNAClassAttribute>()!.Size;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user