DLL: Fix TypeRefs, add constructor skeletons
This commit is contained in:
@@ -34,11 +34,9 @@ namespace Il2CppInspector.Outputs
|
|||||||
return ctor;
|
return ctor;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate custom attribute with named property arguments that calls default constructor
|
// Add custom attribute to type with named property arguments
|
||||||
// 'module' is the module that owns 'type'; type.Module may still be null when this is called
|
// 'module' is the module that owns 'type'; type.Module may still be null when this is called
|
||||||
public static CustomAttribute AddAttribute(this TypeDef type, ModuleDef module, TypeDef attrTypeDef, params (string prop, object value)[] args) {
|
public static CustomAttribute AddAttribute(this TypeDef type, ModuleDef module, TypeDef attrTypeDef, params (string prop, object value)[] args) {
|
||||||
|
|
||||||
// Resolution scope is the module that needs the reference
|
|
||||||
var attRef = module.Import(attrTypeDef);
|
var attRef = module.Import(attrTypeDef);
|
||||||
var attCtorRef = new MemberRefUser(attrTypeDef.Module, ".ctor", MethodSig.CreateInstance(module.CorLibTypes.Void), attRef);
|
var attCtorRef = new MemberRefUser(attrTypeDef.Module, ".ctor", MethodSig.CreateInstance(module.CorLibTypes.Void), attRef);
|
||||||
|
|
||||||
@@ -153,7 +151,8 @@ namespace Il2CppInspector.Outputs
|
|||||||
|
|
||||||
// Generate type recursively with all nested types
|
// Generate type recursively with all nested types
|
||||||
private TypeDefUser CreateType(ModuleDef module, TypeInfo type) {
|
private TypeDefUser CreateType(ModuleDef module, TypeInfo type) {
|
||||||
var mType = new TypeDefUser(type.Namespace, type.BaseName) { Attributes = (TypeAttributes) type.Attributes };
|
// Initialize with base class
|
||||||
|
var mType = new TypeDefUser(type.Namespace, type.BaseName, GetTypeRef(module, type.BaseType)) { Attributes = (TypeAttributes) type.Attributes };
|
||||||
|
|
||||||
// Generic parameters
|
// Generic parameters
|
||||||
foreach (var gp in type.GenericTypeParameters) {
|
foreach (var gp in type.GenericTypeParameters) {
|
||||||
@@ -166,10 +165,6 @@ namespace Il2CppInspector.Outputs
|
|||||||
mType.GenericParameters.Add(p);
|
mType.GenericParameters.Add(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Base class
|
|
||||||
if (type.BaseType != null)
|
|
||||||
mType.BaseType = GetTypeRef(module, type.BaseType);
|
|
||||||
|
|
||||||
// Interfaces
|
// Interfaces
|
||||||
foreach (var @interface in type.ImplementedInterfaces)
|
foreach (var @interface in type.ImplementedInterfaces)
|
||||||
mType.Interfaces.Add(new InterfaceImplUser(GetTypeRef(module, @interface)));
|
mType.Interfaces.Add(new InterfaceImplUser(GetTypeRef(module, @interface)));
|
||||||
@@ -178,16 +173,27 @@ namespace Il2CppInspector.Outputs
|
|||||||
foreach (var nestedType in type.DeclaredNestedTypes)
|
foreach (var nestedType in type.DeclaredNestedTypes)
|
||||||
mType.NestedTypes.Add(CreateType(module, nestedType));
|
mType.NestedTypes.Add(CreateType(module, nestedType));
|
||||||
|
|
||||||
// More processing if it's a TypeDef (rather than a TypeSpec)
|
// Add methods
|
||||||
if (type.Definition != null) {
|
foreach (var ctor in type.DeclaredConstructors) {
|
||||||
|
var s = MethodSig.CreateInstance(module.CorLibTypes.Void,
|
||||||
|
ctor.DeclaredParameters.Select(p => GetTypeRef(module, p.ParameterType).ToTypeSig()).ToArray());
|
||||||
|
|
||||||
// Add token attribute
|
var m = new MethodDefUser(ctor.Name, s, (MethodImplAttributes) ctor.MethodImplementationFlags, (MethodAttributes) ctor.Attributes);
|
||||||
mType.AddAttribute(module, tokenAttribute, ("Token", $"0x{type.Definition.token}"));
|
|
||||||
|
|
||||||
// Add type mapping
|
// TODO: Generic parameters
|
||||||
//typeMap.Add(type, mType);
|
|
||||||
|
// Method body
|
||||||
|
if (ctor.VirtualAddress.HasValue) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
mType.Methods.Add(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add token attribute
|
||||||
|
if (type.Definition != null)
|
||||||
|
mType.AddAttribute(module, tokenAttribute, ("Token", $"0x{type.Definition.token}"));
|
||||||
|
|
||||||
return mType;
|
return mType;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -202,8 +208,11 @@ namespace Il2CppInspector.Outputs
|
|||||||
|
|
||||||
// Convert Il2CppInspector TypeInfo into type reference imported to specified module
|
// Convert Il2CppInspector TypeInfo into type reference imported to specified module
|
||||||
private TypeRef GetTypeRef(ModuleDef module, TypeInfo type) {
|
private TypeRef GetTypeRef(ModuleDef module, TypeInfo type) {
|
||||||
var typeModuleName = modules.First(a => a.Name == type.Assembly.ShortName);
|
if (type == null)
|
||||||
return new TypeRefUser(typeModuleName, type.Namespace, type.Name, module);
|
return null;
|
||||||
|
|
||||||
|
var typeOwnerModule = modules.First(a => a.Name == type.Assembly.ShortName);
|
||||||
|
return module.Import(new TypeRefUser(typeOwnerModule, type.Namespace, type.BaseName, typeOwnerModule));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate and save all DLLs
|
// Generate and save all DLLs
|
||||||
|
|||||||
Reference in New Issue
Block a user