diff --git a/Il2CppInspector.Common/Model/AppModel.cs b/Il2CppInspector.Common/Model/AppModel.cs index 0fa6e8d..27ca4f0 100644 --- a/Il2CppInspector.Common/Model/AppModel.cs +++ b/Il2CppInspector.Common/Model/AppModel.cs @@ -223,17 +223,14 @@ namespace Il2CppInspector.Model } // Add custom attribute generators to the model - foreach (var method in ILModel.AttributesByIndices.Values.Where(m => m.VirtualAddress.HasValue)) { - var cppTypeName = declarationGenerator.TypeNamer.GetName(method.AttributeType); - var fnPtrType = CppFnPtrType.FromSignature(CppTypeCollection, $"void (*{cppTypeName}_CustomAttributesCacheGenerator)(CustomAttributesCache *)"); + foreach (var cppMethod in ILModel.AttributesByIndices.Values.Where(m => m.VirtualAddress.HasValue)) { + var cppMethodName = declarationGenerator.TypeNamer.GetName(cppMethod.AttributeType) + "_CustomAttributesCacheGenerator"; + var fnPtrType = CppFnPtrType.FromSignature(CppTypeCollection, $"void (*{cppMethodName})(CustomAttributesCache *)"); + fnPtrType.Name = cppMethodName; fnPtrType.Group = "custom_attribute_generators"; - // Get first constructor for attribute - // This is not strictly what the cache generator C++ function is but it'll do - var ctor = method.AttributeType.DeclaredConstructors.First(); - - var appMethod = new AppMethod(ctor, fnPtrType, method.VirtualAddress.Value.Start); - CustomAttributeGenerators.Add(method, appMethod); + var appMethod = new AppMethod(null, fnPtrType, cppMethod.VirtualAddress.Value.Start) {Group = fnPtrType.Group}; + CustomAttributeGenerators.Add(cppMethod, appMethod); } // This is to allow this method to be chained after a new expression diff --git a/Il2CppInspector.Common/Outputs/IDAPythonScript.cs b/Il2CppInspector.Common/Outputs/IDAPythonScript.cs index a33ba30..846cfce 100755 --- a/Il2CppInspector.Common/Outputs/IDAPythonScript.cs +++ b/Il2CppInspector.Common/Outputs/IDAPythonScript.cs @@ -104,11 +104,7 @@ typedef __int64 int64_t; writeMethods(model.GetMethodGroup("types_from_generic_methods")); writeSectionHeader("Custom attributes generators"); - foreach (var method in model.ILModel.AttributesByIndices.Values.Where(m => m.VirtualAddress.HasValue)) { - var address = method.VirtualAddress.Value.Start; - writeName(address, $"{method.AttributeType.Name}_CustomAttributesCacheGenerator"); - writeComment(address, $"{method.AttributeType.Name}_CustomAttributesCacheGenerator(CustomAttributesCache *)"); - } + writeMethods(model.CustomAttributeGenerators.Values, asRefs: true); writeSectionHeader("Method.Invoke thunks"); foreach (var method in model.ILModel.MethodInvokers.Where(m => m != null)) { @@ -123,11 +119,14 @@ typedef __int64 int64_t; writeDecls(type.ToString()); } - private void writeMethods(IEnumerable methods) { + private void writeMethods(IEnumerable methods, bool asRefs = false) { foreach (var method in methods) { - var address = method.MethodCodeAddress; + var address = asRefs? method.MethodInfoPtrAddress : method.MethodCodeAddress; writeTypedName(address, method.CppFnPtrType.ToSignatureString(), method.CppFnPtrType.Name); - writeComment(address, method.Method); + + // C++-only methods won't have an IL equivalent, eg. invokers and custom attribute generators + if (method.Method != null) + writeComment(address, method.Method); } }