@@ -526,7 +526,6 @@ private static bool IsFieldEligible(FieldInfo field)
526
526
private static bool IsMethodEligible ( MethodInfo method )
527
527
{
528
528
if ( method . Name == "Finalize" ) return false ;
529
- if ( method . IsStatic ) return false ;
530
529
if ( method . CustomAttributes . Any ( it => typeof ( HideFromIl2CppAttribute ) . IsAssignableFrom ( it . AttributeType ) ) )
531
530
return false ;
532
531
@@ -559,10 +558,12 @@ private static bool IsMethodEligible(MethodInfo method)
559
558
foreach ( var parameter in method . GetParameters ( ) )
560
559
{
561
560
var parameterType = parameter . ParameterType ;
562
- if ( ! IsTypeSupported ( parameterType ) )
561
+ if ( ! IsTypeSupported ( parameterType ) ||
562
+ method . IsStatic && parameterType . IsGenericType && parameterType . ContainsGenericParameters )
563
563
{
564
564
Logger . Instance . LogWarning (
565
- "Method {Method} on type {DeclaringType} has unsupported parameter {Parameter} of type {ParameterType}" , method . ToString ( ) , method . DeclaringType , parameter , parameterType ) ;
565
+ "Method {Method} on type {DeclaringType} has unsupported parameter {Parameter} of type {ParameterType}" , method . ToString ( ) ,
566
+ method . DeclaringType , parameter , parameterType ) ;
566
567
return false ;
567
568
}
568
569
}
@@ -702,6 +703,11 @@ private static bool IsMethodEligible(MethodInfo method)
702
703
converted . Flags = Il2CppMethodFlags . METHOD_ATTRIBUTE_PUBLIC |
703
704
Il2CppMethodFlags . METHOD_ATTRIBUTE_HIDE_BY_SIG ;
704
705
706
+ if ( monoMethod . IsStatic )
707
+ {
708
+ converted . Flags |= Il2CppMethodFlags . METHOD_ATTRIBUTE_STATIC ;
709
+ }
710
+
705
711
if ( monoMethod . IsAbstract )
706
712
{
707
713
converted . Flags |= Il2CppMethodFlags . METHOD_ATTRIBUTE_ABSTRACT ;
@@ -810,7 +816,8 @@ private static Delegate CreateInvoker(MethodInfo monoMethod)
810
816
811
817
var body = method . GetILGenerator ( ) ;
812
818
813
- body . Emit ( OpCodes . Ldarg_2 ) ;
819
+ if ( ! monoMethod . IsStatic )
820
+ body . Emit ( OpCodes . Ldarg_2 ) ;
814
821
for ( var i = 0 ; i < monoMethod . GetParameters ( ) . Length ; i ++ )
815
822
{
816
823
var parameterInfo = monoMethod . GetParameters ( ) [ i ] ;
@@ -892,33 +899,41 @@ private static void StaticVoidIntPtrInvoker_MetadataV29(IntPtr methodPointer, Il
892
899
893
900
private static Delegate CreateTrampoline ( MethodInfo monoMethod )
894
901
{
895
- var nativeParameterTypes = new [ ] { typeof ( IntPtr ) } . Concat ( monoMethod . GetParameters ( )
896
- . Select ( it => it . ParameterType . NativeType ( ) ) . Concat ( new [ ] { typeof ( Il2CppMethodInfo * ) } ) ) . ToArray ( ) ;
902
+ var nativeParameterTypes = new List < Type > ( ) ;
903
+ if ( ! monoMethod . IsStatic )
904
+ nativeParameterTypes . Add ( typeof ( IntPtr ) ) ;
905
+ nativeParameterTypes . AddRange ( monoMethod . GetParameters ( ) . Select ( it => it . ParameterType . NativeType ( ) ) ) ;
906
+ nativeParameterTypes . Add ( typeof ( Il2CppMethodInfo * ) ) ;
897
907
898
- var managedParameters = new [ ] { monoMethod . DeclaringType }
899
- . Concat ( monoMethod . GetParameters ( ) . Select ( it => it . ParameterType ) ) . ToArray ( ) ;
908
+ var managedParameters = new List < Type > ( ) ;
909
+ if ( ! monoMethod . IsStatic )
910
+ managedParameters . Add ( monoMethod . DeclaringType ) ;
911
+ managedParameters . AddRange ( monoMethod . GetParameters ( ) . Select ( it => it . ParameterType ) ) ;
900
912
901
913
var method = new DynamicMethod (
902
914
"Trampoline_" + ExtractSignature ( monoMethod ) + monoMethod . DeclaringType + monoMethod . Name ,
903
915
MethodAttributes . Static | MethodAttributes . Public , CallingConventions . Standard ,
904
- monoMethod . ReturnType . NativeType ( ) , nativeParameterTypes ,
916
+ monoMethod . ReturnType . NativeType ( ) , nativeParameterTypes . ToArray ( ) ,
905
917
monoMethod . DeclaringType , true ) ;
906
918
907
- var signature = new DelegateSupport . MethodSignature ( monoMethod , true ) ;
919
+ var signature = new DelegateSupport . MethodSignature ( monoMethod , ! monoMethod . IsStatic ) ;
908
920
var delegateType = DelegateSupport . GetOrCreateDelegateType ( signature , monoMethod ) ;
909
921
910
922
var body = method . GetILGenerator ( ) ;
911
923
912
924
body . BeginExceptionBlock ( ) ;
913
925
914
- body . Emit ( OpCodes . Ldarg_0 ) ;
915
- body . Emit ( OpCodes . Call ,
916
- typeof ( ClassInjectorBase ) . GetMethod ( nameof ( ClassInjectorBase . GetMonoObjectFromIl2CppPointer ) ) ! ) ;
917
- body . Emit ( OpCodes . Castclass , monoMethod . DeclaringType ) ;
926
+ if ( ! monoMethod . IsStatic )
927
+ {
928
+ body . Emit ( OpCodes . Ldarg_0 ) ;
929
+ body . Emit ( OpCodes . Call ,
930
+ typeof ( ClassInjectorBase ) . GetMethod ( nameof ( ClassInjectorBase . GetMonoObjectFromIl2CppPointer ) ) ! ) ;
931
+ body . Emit ( OpCodes . Castclass , monoMethod . DeclaringType ) ;
932
+ }
918
933
919
- var indirectVariables = new LocalBuilder [ managedParameters . Length ] ;
934
+ var indirectVariables = new LocalBuilder [ managedParameters . Count ] ;
920
935
921
- for ( var i = 1 ; i < managedParameters . Length ; i ++ )
936
+ for ( var i = 1 ; i < managedParameters . Count ; i ++ )
922
937
{
923
938
var parameter = managedParameters [ i ] ;
924
939
if ( parameter . IsSubclassOf ( typeof ( ValueType ) ) )
@@ -988,7 +1003,7 @@ void HandleTypeConversion(Type type)
988
1003
body . Emit ( OpCodes . Stloc , managedReturnVariable ) ;
989
1004
}
990
1005
991
- for ( var i = 1 ; i < managedParameters . Length ; i ++ )
1006
+ for ( var i = 1 ; i < managedParameters . Count ; i ++ )
992
1007
{
993
1008
var variable = indirectVariables [ i ] ;
994
1009
if ( variable == null )
0 commit comments