From 3a0c0d59e85da36eb80f21be7590b15943e6432b Mon Sep 17 00:00:00 2001 From: Katy Coe Date: Sat, 9 Jan 2021 01:30:29 +0100 Subject: [PATCH] DLL: Output properties --- .../Outputs/AssemblyShims.cs | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/Il2CppInspector.Common/Outputs/AssemblyShims.cs b/Il2CppInspector.Common/Outputs/AssemblyShims.cs index 54eaf42..8f73878 100644 --- a/Il2CppInspector.Common/Outputs/AssemblyShims.cs +++ b/Il2CppInspector.Common/Outputs/AssemblyShims.cs @@ -164,8 +164,14 @@ namespace Il2CppInspector.Outputs foreach (var nestedType in type.DeclaredNestedTypes) mType.NestedTypes.Add(CreateType(module, nestedType)); - // Add methods - foreach (var method in type.DeclaredConstructors.AsEnumerable().Concat(type.DeclaredMethods)) + // Add properties + foreach (var prop in type.DeclaredProperties) + AddProperty(module, mType, prop); + + // Add methods that aren't properties + var props = type.DeclaredProperties.SelectMany(p => new[] { p.GetMethod, p.SetMethod }).Where(m => m != null); + + foreach (var method in type.DeclaredConstructors.AsEnumerable().Concat(type.DeclaredMethods).Except(props)) AddMethod(module, mType, method); // Add token attribute @@ -175,6 +181,24 @@ namespace Il2CppInspector.Outputs return mType; } + private PropertyDef AddProperty(ModuleDef module, TypeDef mType, PropertyInfo prop) { + var s = PropertySig.CreateInstance(GetTypeSig(module, prop.PropertyType)); + + var mProp = new PropertyDefUser(prop.Name, s, (PropertyAttributes) prop.Attributes); + + if (prop.CanRead) + mProp.GetMethod = AddMethod(module, mType, prop.GetMethod); + if (prop.CanWrite) + mProp.SetMethod = AddMethod(module, mType, prop.SetMethod); + + // Add token attribute + mProp.AddAttribute(module, tokenAttribute, ("Token", $"0x{prop.Definition.token:X8}")); + + // Add property to type + mType.Properties.Add(mProp); + return mProp; + } + private MethodDef AddMethod(ModuleDef module, TypeDef mType, MethodBase method) { // Return type and parameter signature var s = MethodSig.CreateInstance(