Compare commits
3 Commits
9cbed0a8b8
...
0bf0aeab09
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0bf0aeab09 | ||
|
|
8678ee6c85 | ||
|
|
fbc0f9be49 |
@@ -222,9 +222,23 @@ public class Reader {
|
|||||||
var data = new byte[size];
|
var data = new byte[size];
|
||||||
Array.Copy((byte[])block.Body, offset, data, 0, size);
|
Array.Copy((byte[])block.Body, offset, data, 0, size);
|
||||||
|
|
||||||
//Convert the data to the correct type if it's a base type
|
|
||||||
object? value = ConvertFieldData(data, attrib.OriginalType);
|
|
||||||
if (value != null) return value;
|
//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;
|
||||||
|
} else {
|
||||||
|
//Convert the data to the correct type if it's a base type
|
||||||
|
object? value = ConvertFieldData(data, attrib.OriginalType);
|
||||||
|
if (value != null) return value;
|
||||||
|
}
|
||||||
|
|
||||||
//Check if the field is a pointer to another DNA structure
|
//Check if the field is a pointer to another DNA structure
|
||||||
if (dnaTypesDb.ContainsKey(attrib.OriginalType)) {
|
if (dnaTypesDb.ContainsKey(attrib.OriginalType)) {
|
||||||
|
|||||||
@@ -120,10 +120,10 @@ namespace CodeGenerator {
|
|||||||
CodeMemberField cmf;
|
CodeMemberField cmf;
|
||||||
string name = field.Name;
|
string name = field.Name;
|
||||||
if (name.Contains("()")) return 0;
|
if (name.Contains("()")) return 0;
|
||||||
if (name.Contains("[")) {
|
/*if (name.Contains("[")) {
|
||||||
Log($"Generating array field {field.Name}");
|
Log($"Generating array field {field.Name}");
|
||||||
cmf = CreateArrayMemberField(field);
|
cmf = CreateArrayMemberField(field);
|
||||||
}
|
}*/
|
||||||
else {
|
else {
|
||||||
Log($"Generating field {field.Name}");
|
Log($"Generating field {field.Name}");
|
||||||
cmf = CreateMemberField(field);
|
cmf = CreateMemberField(field);
|
||||||
@@ -135,9 +135,26 @@ namespace CodeGenerator {
|
|||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int AddListField(ref CodeTypeDeclaration ctd, int totalSize, int index,
|
private static int AddArrayField(ref CodeTypeDeclaration ctd, DnaField field, int index, int totalSize)
|
||||||
int listLenghtOffset, BlendFile.DnaField listPointer, BlendFile.DnaField listLength, int sizeIndex)
|
|
||||||
{
|
{
|
||||||
|
Log($"Generating Array field {field.Name}");
|
||||||
|
var cmf = CreateArrayMemberField(field);
|
||||||
|
var attribute = new CodeAttributeDeclaration("DNAArrayAttribute");
|
||||||
|
attribute.Arguments.AddRange(new CodeAttributeArgumentCollection() {
|
||||||
|
new(new CodePrimitiveExpression(totalSize)),
|
||||||
|
new(new CodePrimitiveExpression(field.Type)),
|
||||||
|
new(new CodePrimitiveExpression(index)),
|
||||||
|
new(new CodePrimitiveExpression(field.Name)),
|
||||||
|
new(new CodePrimitiveExpression(field.Type)),
|
||||||
|
new(new CodePrimitiveExpression(0))
|
||||||
|
});
|
||||||
|
cmf.CustomAttributes.Add(attribute);
|
||||||
|
ctd.Members.Add(cmf);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int AddListField(ref CodeTypeDeclaration ctd, int totalSize, int index, int listLenghtOffset,
|
||||||
|
DnaField listPointer, DnaField listLength, int sizeIndex) {
|
||||||
var cmf = CreateListMemberField(listPointer, listLength);
|
var cmf = CreateListMemberField(listPointer, listLength);
|
||||||
|
|
||||||
var attribute = GenerateDnaListAttribute(index, listPointer, sizeIndex, listLength, totalSize,
|
var attribute = GenerateDnaListAttribute(index, listPointer, sizeIndex, listLength, totalSize,
|
||||||
@@ -199,9 +216,13 @@ namespace CodeGenerator {
|
|||||||
Log($"Fields: {type.Fields.Count}");
|
Log($"Fields: {type.Fields.Count}");
|
||||||
for (var index = 0; index < type.Fields.Count; index++) {
|
for (var index = 0; index < type.Fields.Count; index++) {
|
||||||
var field = type.Fields[index];
|
var field = type.Fields[index];
|
||||||
if (normalFields.Contains(field) && !listFields.Select(f => f.Item2).Contains(field))
|
//Check if the field is a normal field or a list field
|
||||||
{
|
if (normalFields.Contains(field) && !listFields.Select(f => f.Item2).Contains(field)) {
|
||||||
totalSize += AddNormalField(field, ref ctd, index, totalSize);
|
//check if the field is an array
|
||||||
|
if (field.Name.Contains("["))
|
||||||
|
totalSize += AddArrayField(ref ctd, field, index, totalSize);
|
||||||
|
else
|
||||||
|
totalSize += AddNormalField(field, ref ctd, index, totalSize);
|
||||||
} else if (listFields.Select(f => f.Item1).Contains(field)) {
|
} else if (listFields.Select(f => f.Item1).Contains(field)) {
|
||||||
//Retrieve the list pointer and the list length fields
|
//Retrieve the list pointer and the list length fields
|
||||||
var (listPointer, listLength) = listFields.FirstOrDefault(x => x.Item1 == field);
|
var (listPointer, listLength) = listFields.FirstOrDefault(x => x.Item1 == field);
|
||||||
@@ -345,6 +366,19 @@ namespace CodeGenerator {
|
|||||||
.AddPropertiesConstructor()
|
.AddPropertiesConstructor()
|
||||||
.AddBaseConstructorParams(["OriginalIndex", "OriginalName"])
|
.AddBaseConstructorParams(["OriginalIndex", "OriginalName"])
|
||||||
.Build(),
|
.Build(),
|
||||||
|
attributeBuilder.New().SetName("DNAArrayAttribute")
|
||||||
|
.SetAttributeUsage(new (new CodeSnippetExpression("AttributeTargets.Field")))
|
||||||
|
.DeriveFromClass($"{Namespace}.DNAAttribute")
|
||||||
|
.AddAutoProperty(typeof(int), "Size")
|
||||||
|
.AddAutoProperty(typeof(string), "OriginalType")
|
||||||
|
.AddAutoProperty(typeof(int), "OriginalIndex")
|
||||||
|
.AddAutoProperty(typeof(string), "OriginalName")
|
||||||
|
.AddAutoProperty(typeof(string), "UnderlyingType")
|
||||||
|
.AddAutoProperty(typeof(int), "ArrayLenght")
|
||||||
|
.AddAutoProperty(typeof(int), "MemoryOffset")
|
||||||
|
.AddPropertiesConstructor()
|
||||||
|
.AddBaseConstructorParams(["OriginalIndex", "OriginalName"])
|
||||||
|
.Build(),
|
||||||
attributeBuilder.New().SetName("DNAClassAttribute")
|
attributeBuilder.New().SetName("DNAClassAttribute")
|
||||||
.SetAttributeUsage(new (new CodeSnippetExpression("AttributeTargets.Class | AttributeTargets.Struct")))
|
.SetAttributeUsage(new (new CodeSnippetExpression("AttributeTargets.Class | AttributeTargets.Struct")))
|
||||||
.DeriveFromClass($"{Namespace}.DNAAttribute")
|
.DeriveFromClass($"{Namespace}.DNAAttribute")
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ namespace CodeGenerator {
|
|||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static int ParseFSize(this string str) {
|
public static int ParseFSize(this string str) {
|
||||||
return str switch {
|
return str switch {
|
||||||
"char" => sizeof(char),
|
"char" => sizeof(sbyte),
|
||||||
"short" => sizeof(short),
|
"short" => sizeof(short),
|
||||||
"int" => sizeof(int),
|
"int" => sizeof(int),
|
||||||
"float" => sizeof(float),
|
"float" => sizeof(float),
|
||||||
|
|||||||
Reference in New Issue
Block a user