Skip to content
This repository has been archived by the owner on Jul 1, 2024. It is now read-only.

netcore support #67

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion AssemblyUnhollower/Extensions/EnumEx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
1 change: 1 addition & 0 deletions AssemblyUnhollower/Passes/Pass10CreateTypedefs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
5 changes: 3 additions & 2 deletions AssemblyUnhollower/Passes/Pass20GenerateStaticConstructors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ private static void GenerateStaticProxy(AssemblyRewriteContext assemblyContext,
{
var oldType = typeContext.OriginalType;
var newType = typeContext.NewType;
if (newType.IsEnum) return;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing static constructors from enum types will likely break practically everything that uses them, including boxed enums and generics with enum type parameters.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm trying to find an example that uses a static constructor for an enum type. Do you happen to have one? I tried a generic method (i.e. from https://stackoverflow.com/questions/79126/create-generic-method-constraining-t-to-an-enum), but can't get mono working with it yet.


var staticCtorMethod = new MethodDefinition(".cctor",
MethodAttributes.Static | MethodAttributes.Private | MethodAttributes.SpecialName |
Expand Down Expand Up @@ -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);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be only used for methods that somehow don't get a token (in fact, this should have been removed a long time ago as in practice everything has tokens). It would be better to actually investigate those cases when there are tokenless methods and fix those.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the case of:
IL2CPP.RenderTypeName<someType*>(true) - .net doesn’t like class pointers as a generic type input.

ctorBuilder.Emit(OpCodes.Call, imports.Module.ImportReference(new GenericInstanceMethod(imports.Il2CppRenderTypeNameGeneric) {GenericArguments = { newTypeReference.IsByReference ? newTypeReference.GetElementType() : newTypeReference } }));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down