From ef24d66f08abe452efe57c9bff7b7885855879ab Mon Sep 17 00:00:00 2001 From: shalzuth Date: Wed, 7 Jul 2021 20:30:15 -0700 Subject: [PATCH] netcore support --- AssemblyUnhollower/Extensions/EnumEx.cs | 2 +- AssemblyUnhollower/Passes/Pass10CreateTypedefs.cs | 1 + .../Passes/Pass20GenerateStaticConstructors.cs | 5 +++-- AssemblyUnhollower/Passes/Pass24GenerateTypeStaticGetters.cs | 1 + 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/AssemblyUnhollower/Extensions/EnumEx.cs b/AssemblyUnhollower/Extensions/EnumEx.cs index 26ab221..0a69119 100644 --- a/AssemblyUnhollower/Extensions/EnumEx.cs +++ b/AssemblyUnhollower/Extensions/EnumEx.cs @@ -11,7 +11,7 @@ public static FieldAttributes ForcePublic(this FieldAttributes fieldAttributes) public static GenericParameterAttributes StripValueTypeConstraint(this GenericParameterAttributes parameterAttributes) { - return parameterAttributes & ~GenericParameterAttributes.NotNullableValueTypeConstraint; + return parameterAttributes & ~(GenericParameterAttributes.NotNullableValueTypeConstraint | GenericParameterAttributes.VarianceMask); } } } \ No newline at end of file diff --git a/AssemblyUnhollower/Passes/Pass10CreateTypedefs.cs b/AssemblyUnhollower/Passes/Pass10CreateTypedefs.cs index 2d88f6a..fe9c3e1 100644 --- a/AssemblyUnhollower/Passes/Pass10CreateTypedefs.cs +++ b/AssemblyUnhollower/Passes/Pass10CreateTypedefs.cs @@ -19,6 +19,7 @@ private static void ProcessType(TypeDefinition type, AssemblyRewriteContext asse { var convertedTypeName = GetConvertedTypeName(assemblyContext.GlobalContext, type, parentType); var newType = new TypeDefinition(convertedTypeName.Namespace ?? type.Namespace.UnSystemify(), convertedTypeName.Name, AdjustAttributes(type.Attributes)); + newType.IsSequentialLayout = false; // needs more testing, does it matter if anything isn't sequential? if (type.IsSealed && type.IsAbstract) // is static { diff --git a/AssemblyUnhollower/Passes/Pass20GenerateStaticConstructors.cs b/AssemblyUnhollower/Passes/Pass20GenerateStaticConstructors.cs index 11998b5..30ae03d 100644 --- a/AssemblyUnhollower/Passes/Pass20GenerateStaticConstructors.cs +++ b/AssemblyUnhollower/Passes/Pass20GenerateStaticConstructors.cs @@ -24,6 +24,7 @@ private static void GenerateStaticProxy(AssemblyRewriteContext assemblyContext, { var oldType = typeContext.OriginalType; var newType = typeContext.NewType; + if (newType.IsEnum) return; var staticCtorMethod = new MethodDefinition(".cctor", MethodAttributes.Static | MethodAttributes.Private | MethodAttributes.SpecialName | @@ -149,8 +150,8 @@ private static void EmitLoadTypeNameString(this ILProcessor ctorBuilder, Assembl ctorBuilder.Emit(OpCodes.Ldstr, originalTypeReference.FullName); else { - ctorBuilder.Emit(newTypeReference.IsByReference ? OpCodes.Ldc_I4_1 : OpCodes.Ldc_I4_0); - ctorBuilder.Emit(OpCodes.Call, imports.Module.ImportReference(new GenericInstanceMethod(imports.Il2CppRenderTypeNameGeneric) {GenericArguments = {newTypeReference}})); + ctorBuilder.Emit(newTypeReference.IsByReference ? OpCodes.Ldc_I4_1 : OpCodes.Ldc_I4_0); + ctorBuilder.Emit(OpCodes.Call, imports.Module.ImportReference(new GenericInstanceMethod(imports.Il2CppRenderTypeNameGeneric) {GenericArguments = { newTypeReference.IsByReference ? newTypeReference.GetElementType() : newTypeReference } })); } } } diff --git a/AssemblyUnhollower/Passes/Pass24GenerateTypeStaticGetters.cs b/AssemblyUnhollower/Passes/Pass24GenerateTypeStaticGetters.cs index e298de0..44e40af 100644 --- a/AssemblyUnhollower/Passes/Pass24GenerateTypeStaticGetters.cs +++ b/AssemblyUnhollower/Passes/Pass24GenerateTypeStaticGetters.cs @@ -17,6 +17,7 @@ public static void DoPass(RewriteGlobalContext context) foreach (var typeContext in assemblyContext.Types) { + if (typeContext.NewType.IsEnum) continue; var typeGetMethod = new MethodDefinition("get_Il2CppType", MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.Static, il2CppSystemTypeRef); typeContext.NewType.Methods.Add(typeGetMethod); var typeProperty = new PropertyDefinition("Il2CppType", PropertyAttributes.None, il2CppSystemTypeRef);