瀏覽代碼

同步HybridCLR

guodong 3 年之前
父節點
當前提交
564d52522d

+ 1 - 1
GameClient/Assets/Editor/HybridCLR.meta

@@ -1,5 +1,5 @@
 fileFormatVersion: 2
-guid: 009bc4a25347e4c4e9958470806ac819
+guid: 0cca09dc9d27f314da15fa746a01d51c
 folderAsset: yes
 DefaultImporter:
   externalObjects: {}

+ 2 - 4
GameClient/Assets/Editor/HybridCLR/BuildConfig_Custom.cs

@@ -23,7 +23,7 @@ namespace HybridCLR
         /// </summary>
         public static List<string> MonoHotUpdateDllNames { get; } = new List<string>()
         {
-            
+            "HotFix.dll",
         };
 
         /// <summary>
@@ -32,7 +32,7 @@ namespace HybridCLR
         public static List<string> AllHotUpdateDllNames { get; } = MonoHotUpdateDllNames.Concat(new List<string>
         {
             // 这里放除了s_monoHotUpdateDllNames以外的脚本不需要挂到资源上的dll列表
-            "Game.HotUpdate.dll",
+            "HotFix2.dll",
         }).ToList();
 
         public static List<string> AOTMetaDlls { get; } = new List<string>()
@@ -40,8 +40,6 @@ namespace HybridCLR
             "mscorlib.dll",
             "System.dll",
             "System.Core.dll", // 如果使用了Linq,需要这个
-            "ThirdParty.dll",
-            "Game.Launcher.dll",
         };
 
         public static List<string> AssetBundleFiles { get; } = new List<string>

+ 7 - 5
GameClient/Assets/Editor/HybridCLR/Generators/MethodBridge/IPlatformAdaptor.cs

@@ -13,14 +13,16 @@ namespace HybridCLR.Generators.MethodBridge
 
         TypeInfo CreateTypeInfo(Type type, bool returnValue);
 
-        IEnumerable<MethodBridgeSig> GetPreserveMethods();
+        void GenerateManaged2NativeMethod(MethodBridgeSig method, List<string> outputLines);
 
-        void GenerateCall(MethodBridgeSig method, List<string> outputLines);
+        void GenerateManaged2NativeStub(List<MethodBridgeSig> methods, List<string> lines);
 
-        void GenerateInvoke(MethodBridgeSig method, List<string> outputLines);
+        void GenerateNative2ManagedMethod(MethodBridgeSig method, List<string> outputLines);
 
-        void GenCallStub(List<MethodBridgeSig> methods, List<string> lines);
+        void GenerateNative2ManagedStub(List<MethodBridgeSig> methods, List<string> lines);
 
-        void GenInvokeStub(List<MethodBridgeSig> methods, List<string> lines);
+        void GenerateAdjustThunkMethod(MethodBridgeSig method, List<string> outputLines);
+
+        void GenerateAdjustThunkStub(List<MethodBridgeSig> methods, List<string> lines);
     }
 }

+ 125 - 105
GameClient/Assets/Editor/HybridCLR/Generators/MethodBridge/MethodBridgeGenerator.cs

@@ -20,7 +20,9 @@ namespace HybridCLR.Generators.MethodBridge
 
     public class MethodBridgeGeneratorOptions
     {
-        public List<Assembly> Assemblies { get; set; }
+        public List<Assembly> HotfixAssemblies { get; set; }
+
+        public List<Assembly> AllAssemblies { get; set; }
 
         public PlatformABI CallConvention { get; set; }
 
@@ -29,6 +31,8 @@ namespace HybridCLR.Generators.MethodBridge
 
     public class MethodBridgeGenerator
     {
+        private readonly HashSet<Assembly> _hotfixAssemblies;
+
         private readonly List<Assembly> _assemblies;
 
         private readonly PlatformABI _callConvention;
@@ -37,17 +41,27 @@ namespace HybridCLR.Generators.MethodBridge
 
         private readonly IPlatformAdaptor _platformAdaptor;
 
-        private readonly HashSet<MethodBridgeSig> _callMethodSet = new HashSet<MethodBridgeSig>();
+        private readonly HashSet<MethodBridgeSig> _managed2nativeMethodSet = new HashSet<MethodBridgeSig>();
+
+        private List<MethodBridgeSig> _managed2nativeMethodList;
 
-        private List<MethodBridgeSig> _callMethodList;
+        private readonly HashSet<MethodBridgeSig> _native2managedMethodSet = new HashSet<MethodBridgeSig>();
 
-        private readonly HashSet<MethodBridgeSig> _invokeMethodSet = new HashSet<MethodBridgeSig>();
+        private List<MethodBridgeSig> _native2managedMethodList;
 
-        private List<MethodBridgeSig> _invokeMethodList;
+        private readonly HashSet<MethodBridgeSig> _adjustThunkMethodSet = new HashSet<MethodBridgeSig>();
+
+        private List<MethodBridgeSig> _adjustThunkMethodList;
+
+        public bool IsHotFixType(Type type)
+        {
+            return _hotfixAssemblies.Contains(type.Assembly);
+        }
 
         public MethodBridgeGenerator(MethodBridgeGeneratorOptions options)
         {
-            _assemblies = options.Assemblies;
+            _hotfixAssemblies = new HashSet<Assembly>(options.HotfixAssemblies);
+            _assemblies = options.AllAssemblies;
             _callConvention = options.CallConvention;
             _outputFile = options.OutputFile;
             _platformAdaptor = CreatePlatformAdaptor(options.CallConvention);
@@ -101,17 +115,25 @@ namespace HybridCLR.Generators.MethodBridge
             return mbs;
         }
 
-        private void AddCallMethod(MethodBridgeSig method)
+        private void AddManaged2NativeMethod(MethodBridgeSig method)
         {
-            if (_callMethodSet.Add(method))
+            if (_managed2nativeMethodSet.Add(method))
             {
                 method.Init();
             }
         }
 
-        private void AddInvokeMethod(MethodBridgeSig method)
+        private void AddNative2ManagedMethod(MethodBridgeSig method)
         {
-            if (_invokeMethodSet.Add(method))
+            if (_native2managedMethodSet.Add(method))
+            {
+                method.Init();
+            }
+        }
+
+        private void AddAdjustThunkMethod(MethodBridgeSig method)
+        {
+            if (_adjustThunkMethodSet.Add(method))
             {
                 method.Init();
             }
@@ -123,6 +145,20 @@ namespace HybridCLR.Generators.MethodBridge
             {
                 return;
             }
+            if (!type.IsNested)
+            {
+                if (!type.IsPublic)
+                {
+                    return;
+                }
+            }
+            else
+            {
+                if (type.IsNestedPrivate)
+                {
+                    return;
+                }
+            }
             var typeDel = typeof(MulticastDelegate);
             if (typeDel.IsAssignableFrom(type))
             {
@@ -132,13 +168,14 @@ namespace HybridCLR.Generators.MethodBridge
                     //Debug.LogError($"delegate:{typeDel.FullName} Invoke not exists");
                     return;
                 }
+                // Debug.Log($"== delegate:{type}");
                 var instanceCallMethod = CreateMethodBridgeSig(false, method.ReturnParameter, method.GetParameters());
-                AddCallMethod(instanceCallMethod);
-                var staticCallMethod = CreateMethodBridgeSig(true, method.ReturnParameter, method.GetParameters());
-                AddCallMethod(staticCallMethod);
+                AddManaged2NativeMethod(instanceCallMethod);
+                AddNative2ManagedMethod(instanceCallMethod);
 
-                var invokeMethod = CreateMethodBridgeSig(true, method.ReturnParameter, method.GetParameters());
-                AddInvokeMethod(invokeMethod);
+                var staticCallMethod = CreateMethodBridgeSig(true, method.ReturnParameter, method.GetParameters());
+                AddManaged2NativeMethod(staticCallMethod);
+                AddNative2ManagedMethod(staticCallMethod);
                 return;
             }
             foreach (var method in type.GetMethods(BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public
@@ -148,21 +185,49 @@ namespace HybridCLR.Generators.MethodBridge
                 {
                     continue;
                 }
-                var callMethod = CreateMethodBridgeSig(method.IsStatic, method.ReturnParameter, method.GetParameters());
-                AddCallMethod(callMethod);
 
-                var invokeMethod = CreateMethodBridgeSig(true, method.ReturnParameter, method.GetParameters());
-                AddInvokeMethod(invokeMethod);
+                if (method.IsPrivate || (method.IsAssembly && !method.IsPublic && !method.IsFamily))
+                {
+                    continue;
+                }
+
+                if (method.IsFamily || method.IsPublic)
+                {
+                    var m2nMethod = CreateMethodBridgeSig(method.IsStatic, method.ReturnParameter, method.GetParameters());
+                    AddManaged2NativeMethod(m2nMethod);
+
+                    if (type.IsValueType && !method.IsStatic)
+                    {
+                        var adjustThunkMethod = CreateMethodBridgeSig(true, method.ReturnParameter, method.GetParameters());
+                        AddAdjustThunkMethod(adjustThunkMethod);
+                    }
+
+                    if (method.IsVirtual)
+                    {
+                        AddNative2ManagedMethod(m2nMethod);
+                    }
+                }
             }
 
             foreach (var method in type.GetConstructors(BindingFlags.Instance | BindingFlags.Public
 | BindingFlags.NonPublic | BindingFlags.CreateInstance | BindingFlags.InvokeMethod | BindingFlags.FlattenHierarchy))
             {
-                var callMethod = CreateMethodBridgeSig(false, null, method.GetParameters());
-                AddCallMethod(callMethod);
+                if (method.IsPrivate || (method.IsAssembly && !method.IsPublic && !method.IsFamily))
+                {
+                    continue;
+                }
+
+                if (method.IsFamily || method.IsPublic)
+                {
+                    var callMethod = CreateMethodBridgeSig(false, null, method.GetParameters());
+                    AddManaged2NativeMethod(callMethod);
 
-                var invokeMethod = CreateMethodBridgeSig(true, null, method.GetParameters());
-                AddInvokeMethod(invokeMethod);
+                    if (type.IsValueType && !method.IsStatic)
+                    {
+                        var invokeMethod = CreateMethodBridgeSig(true, null, method.GetParameters());
+                        AddAdjustThunkMethod(invokeMethod);
+                    }
+                }
             }
 
             foreach (var subType in type.GetNestedTypes(BindingFlags.Public | BindingFlags.NonPublic))
@@ -175,6 +240,10 @@ namespace HybridCLR.Generators.MethodBridge
         {
             foreach (var ass in _assemblies)
             {
+                if (_hotfixAssemblies.Contains(ass))
+                {
+                    continue;
+                }
                 //Debug.Log("prepare assembly:" + ass.FullName);
                 foreach (var type in ass.GetTypes())
                 {
@@ -183,67 +252,6 @@ namespace HybridCLR.Generators.MethodBridge
             }
         }
 
-        public void PrepareCommon1()
-        {
-            // (void + int64 + float) * (int64 + float) * (0 - 20) = 120
-            TypeInfo typeVoid = new TypeInfo(typeof(void), ParamOrReturnType.VOID);
-            TypeInfo typeLong = new TypeInfo(typeof(long), ParamOrReturnType.I8_U8);
-            TypeInfo typeDouble = new TypeInfo(typeof(double), ParamOrReturnType.R8);
-            int maxParamCount = 20;
-                
-            foreach (var returnType in new TypeInfo[] { typeVoid, typeLong, typeDouble })
-            {
-                var rt = new ReturnInfo() { Type = returnType };
-                foreach (var argType in new TypeInfo[] { typeLong, typeDouble })
-                {
-                    for (int paramCount = 0; paramCount <= maxParamCount; paramCount++)
-                    {
-                        var paramInfos = new List<ParamInfo>();
-                        for (int i = 0; i < paramCount; i++)
-                        {
-                            paramInfos.Add(new ParamInfo() { Type = argType });
-                        }
-                        var mbs = new MethodBridgeSig() { ReturnInfo = rt, ParamInfos =  paramInfos};
-                        AddCallMethod(mbs);
-                    }
-                }
-            }
-        }
-
-        public void PrepareCommon2()
-        {
-            // (void + int64 + float) * (int64 + float + sr) ^ (0 - 4) = 363
-            TypeInfo typeVoid = new TypeInfo(typeof(void), ParamOrReturnType.VOID);
-            TypeInfo typeLong = new TypeInfo(typeof(long), ParamOrReturnType.I8_U8);
-            TypeInfo typeDouble = new TypeInfo(typeof(double), ParamOrReturnType.R8);
-
-            int maxParamCount = 4;
-
-            var argTypes = new TypeInfo[] { typeLong, typeDouble };
-            int paramTypeNum = argTypes.Length;
-            foreach (var returnType in new TypeInfo[] { typeVoid, typeLong, typeDouble })
-            {
-                var rt = new ReturnInfo() { Type = returnType };
-                for(int paramCount = 1; paramCount <= maxParamCount; paramCount++)
-                {
-                    int totalCombinationNum = (int)Math.Pow(paramTypeNum, paramCount);
-
-                    for (int k = 0; k < totalCombinationNum; k++)
-                    {
-                        var paramInfos = new List<ParamInfo>();
-                        int c = k;
-                        for(int i = 0; i < paramCount; i++)
-                        {
-                            paramInfos.Add(new ParamInfo { Type = argTypes[c % paramTypeNum] });
-                            c /= paramTypeNum;
-                        }
-                        var mbs = new MethodBridgeSig() { ReturnInfo = rt, ParamInfos = paramInfos };
-                        AddCallMethod(mbs);
-                    }
-                }
-            }
-        }
-
         private void PrepareMethodsFromCustomeGenericTypes()
         {
             foreach (var type in GeneratorConfig.PrepareCustomGenericTypes())
@@ -254,39 +262,40 @@ namespace HybridCLR.Generators.MethodBridge
 
         public void PrepareMethods()
         {
-            PrepareCommon1();
-            PrepareCommon2();
             PrepareMethodsFromCustomeGenericTypes();
 
 
             foreach(var methodSig in _platformAdaptor.IsArch32 ? GeneratorConfig.PrepareCustomMethodSignatures32() : GeneratorConfig.PrepareCustomMethodSignatures64())
             {
                 var method = MethodBridgeSig.CreateBySignatuer(methodSig);
-                AddCallMethod(method);
-                AddInvokeMethod(method);
-            }
-            foreach(var method in _platformAdaptor.GetPreserveMethods())
-            {
-                AddCallMethod(method);
-                AddInvokeMethod(method);
+                AddManaged2NativeMethod(method);
+                AddAdjustThunkMethod(method);
             }
             PrepareFromAssemblies();
 
             {
                 var sortedMethods = new SortedDictionary<string, MethodBridgeSig>();
-                foreach (var method in _callMethodSet)
+                foreach (var method in _managed2nativeMethodSet)
                 {
                     sortedMethods.Add(method.CreateCallSigName(), method);
                 }
-                _callMethodList = sortedMethods.Values.ToList();
+                _managed2nativeMethodList = sortedMethods.Values.ToList();
             }
             {
                 var sortedMethods = new SortedDictionary<string, MethodBridgeSig>();
-                foreach (var method in _invokeMethodSet)
+                foreach (var method in _native2managedMethodSet)
                 {
                     sortedMethods.Add(method.CreateCallSigName(), method);
                 }
-                _invokeMethodList = sortedMethods.Values.ToList();
+                _native2managedMethodList = sortedMethods.Values.ToList();
+            }
+            {
+                var sortedMethods = new SortedDictionary<string, MethodBridgeSig>();
+                foreach (var method in _adjustThunkMethodSet)
+                {
+                    sortedMethods.Add(method.CreateCallSigName(), method);
+                }
+                _adjustThunkMethodList = sortedMethods.Values.ToList();
             }
         }
 
@@ -296,21 +305,32 @@ namespace HybridCLR.Generators.MethodBridge
 
             List<string> lines = new List<string>(20_0000);
 
-            Debug.LogFormat("== call method count:{0}", _callMethodList.Count);
+            Debug.LogFormat("== managed2native method count:{0}", _managed2nativeMethodList.Count);
+
+            foreach(var method in _managed2nativeMethodList)
+            {
+                _platformAdaptor.GenerateManaged2NativeMethod(method, lines);
+            }
+
+            _platformAdaptor.GenerateManaged2NativeStub(_managed2nativeMethodList, lines);
+
+            Debug.LogFormat("== native2managed method count:{0}", _native2managedMethodList.Count);
 
-            foreach(var method in _callMethodList)
+            foreach (var method in _native2managedMethodList)
             {
-                _platformAdaptor.GenerateCall(method, lines);
+                _platformAdaptor.GenerateNative2ManagedMethod(method, lines);
             }
 
-            Debug.LogFormat("== invoke method count:{0}", _invokeMethodList.Count);
-            foreach (var method in _invokeMethodList)
+            _platformAdaptor.GenerateNative2ManagedStub(_native2managedMethodList, lines);
+
+            Debug.LogFormat("== adjustThunk method count:{0}", _adjustThunkMethodList.Count);
+
+            foreach (var method in _adjustThunkMethodList)
             {
-                _platformAdaptor.GenerateInvoke(method, lines);
+                _platformAdaptor.GenerateAdjustThunkMethod(method, lines);
             }
 
-            _platformAdaptor.GenCallStub(_callMethodList, lines);
-            _platformAdaptor.GenInvokeStub(_invokeMethodList, lines);
+            _platformAdaptor.GenerateAdjustThunkStub(_adjustThunkMethodList, lines);
 
             frr.Replace("INVOKE_STUB", string.Join("\n", lines));
 

+ 26 - 10
GameClient/Assets/Editor/HybridCLR/Generators/MethodBridge/PlatformAdaptorBase.cs

@@ -19,11 +19,11 @@ namespace HybridCLR.Generators.MethodBridge
 
         protected abstract TypeInfo CreateValueType(Type type, bool returnValue);
 
-        public abstract void GenerateCall(MethodBridgeSig method, List<string> lines);
+        public abstract void GenerateManaged2NativeMethod(MethodBridgeSig method, List<string> lines);
 
-        public abstract void GenerateInvoke(MethodBridgeSig method, List<string> lines);
+        public abstract void GenerateNative2ManagedMethod(MethodBridgeSig method, List<string> lines);
 
-        public abstract IEnumerable<MethodBridgeSig> GetPreserveMethods();
+        public abstract void GenerateAdjustThunkMethod(MethodBridgeSig method, List<string> outputLines);
 
         private static Dictionary<Type, (int, int)> _typeSizeCache64 = new Dictionary<Type, (int, int)>();
 
@@ -109,35 +109,51 @@ namespace HybridCLR.Generators.MethodBridge
             }
         }
 
-        public void GenCallStub(List<MethodBridgeSig> methods, List<string> lines)
+        public void GenerateManaged2NativeStub(List<MethodBridgeSig> methods, List<string> lines)
         {
             lines.Add($@"
-NativeCallMethod hybridclr::interpreter::g_callStub[] = 
+Managed2NativeMethodInfo hybridclr::interpreter::g_managed2nativeStub[] = 
 {{
 ");
 
             foreach (var method in methods)
             {
-                lines.Add($"\t{{\"{method.CreateInvokeSigName()}\", (Il2CppMethodPointer)__Native2ManagedCall_{method.CreateInvokeSigName()}, (Il2CppMethodPointer)__Native2ManagedCall_AdjustorThunk_{method.CreateCallSigName()}, __Managed2NativeCall_{method.CreateInvokeSigName()}}},");
+                lines.Add($"\t{{\"{method.CreateInvokeSigName()}\", __M2N_{method.CreateInvokeSigName()}}},");
             }
 
             lines.Add($"\t{{nullptr, nullptr}},");
             lines.Add("};");
         }
 
-        public void GenInvokeStub(List<MethodBridgeSig> methods, List<string> lines)
+        public void GenerateNative2ManagedStub(List<MethodBridgeSig> methods, List<string> lines)
         {
             lines.Add($@"
-NativeInvokeMethod hybridclr::interpreter::g_invokeStub[] = 
+Native2ManagedMethodInfo hybridclr::interpreter::g_native2managedStub[] = 
 {{
 ");
 
             foreach (var method in methods)
             {
-                lines.Add($"\t{{\"{method.CreateInvokeSigName()}\", __Invoke_instance_{method.CreateInvokeSigName()}, __Invoke_static_{method.CreateInvokeSigName()}}},");
+                lines.Add($"\t{{\"{method.CreateInvokeSigName()}\", (Il2CppMethodPointer)__N2M_{method.CreateInvokeSigName()}}},");
             }
 
-            lines.Add($"\t{{nullptr, nullptr, nullptr}},");
+            lines.Add($"\t{{nullptr, nullptr}},");
+            lines.Add("};");
+        }
+
+        public void GenerateAdjustThunkStub(List<MethodBridgeSig> methods, List<string> lines)
+        {
+            lines.Add($@"
+NativeAdjustThunkMethodInfo hybridclr::interpreter::g_adjustThunkStub[] = 
+{{
+");
+
+            foreach (var method in methods)
+            {
+                lines.Add($"\t{{\"{method.CreateInvokeSigName()}\", (Il2CppMethodPointer)__N2M_AdjustorThunk_{method.CreateCallSigName()}}},");
+            }
+
+            lines.Add($"\t{{nullptr, nullptr}},");
             lines.Add("};");
         }
     }

+ 20 - 166
GameClient/Assets/Editor/HybridCLR/Generators/MethodBridge/PlatformAdaptor_Arm64.cs

@@ -157,197 +157,51 @@ namespace HybridCLR.Generators.MethodBridge
             return TypeInfo.s_ref;
         }
 
-        public IEnumerable<MethodBridgeSig> PrepareCommon1()
+        public override void GenerateManaged2NativeMethod(MethodBridgeSig method, List<string> lines)
         {
-            // (void + int32 + int64 + float + double) * (int32 + int64 + float + double) * (0 - 20) = 420
-            TypeInfo typeVoid = new TypeInfo(typeof(void), ParamOrReturnType.VOID);
-            TypeInfo typeInt = new TypeInfo(typeof(int), ParamOrReturnType.I4_U4);
-            TypeInfo typeLong = new TypeInfo(typeof(long), ParamOrReturnType.I8_U8);
-            TypeInfo typeFloat = new TypeInfo(typeof(float), ParamOrReturnType.R4);
-            TypeInfo typeDouble = new TypeInfo(typeof(double), ParamOrReturnType.R8);
-            int maxParamCount = 20;
-
-            foreach (var returnType in new TypeInfo[] { typeVoid, typeInt, typeLong, typeFloat, typeDouble })
-            {
-                var rt = new ReturnInfo() { Type = returnType };
-                foreach (var argType in new TypeInfo[] { typeInt, typeLong, typeFloat, typeDouble })
-                {
-                    for (int paramCount = 0; paramCount <= maxParamCount; paramCount++)
-                    {
-                        var paramInfos = new List<ParamInfo>();
-                        for (int i = 0; i < paramCount; i++)
-                        {
-                            paramInfos.Add(new ParamInfo() { Type = argType });
-                        }
-                        var mbs = new MethodBridgeSig() { ReturnInfo = rt, ParamInfos = paramInfos };
-                        yield return mbs;
-                    }
-                }
-            }
-        }
-
-        public IEnumerable<MethodBridgeSig> PrepareCommon2()
-        {
-            // (void + int32 + int64 + float + double + v2f + v3f + v4f + s2) * (int32 + int64 + float + double + v2f + v3f + v4f + s2 + sr) ^ (0 - 2) = 399
-            TypeInfo typeVoid = new TypeInfo(typeof(void), ParamOrReturnType.VOID);
-            TypeInfo typeInt = new TypeInfo(typeof(int), ParamOrReturnType.I4_U4);
-            TypeInfo typeLong = new TypeInfo(typeof(long), ParamOrReturnType.I8_U8);
-            TypeInfo typeFloat = new TypeInfo(typeof(float), ParamOrReturnType.R4);
-            TypeInfo typeDouble = new TypeInfo(typeof(double), ParamOrReturnType.R8);
-            TypeInfo typeV2f = new TypeInfo(typeof(Vector2), ParamOrReturnType.ARM64_HFA_FLOAT_2);
-            TypeInfo typeV3f = new TypeInfo(typeof(Vector3), ParamOrReturnType.ARM64_HFA_FLOAT_3);
-            TypeInfo typeV4f = new TypeInfo(typeof(Vector4), ParamOrReturnType.ARM64_HFA_FLOAT_4);
-
-            int maxParamCount = 2;
-
-            var argTypes = new TypeInfo[] { typeInt, typeLong, typeFloat, typeDouble, typeV2f, typeV3f, typeV4f };
-            int paramTypeNum = argTypes.Length;
-            foreach (var returnType in new TypeInfo[] { typeVoid, typeInt, typeLong, typeFloat, typeDouble, typeV2f, typeV3f, typeV4f })
-            {
-                var rt = new ReturnInfo() { Type = returnType };
-                for (int paramCount = 0; paramCount <= maxParamCount; paramCount++)
-                {
-                    int totalCombinationNum = (int)Math.Pow(paramTypeNum, paramCount);
-
-                    for (int k = 0; k < totalCombinationNum; k++)
-                    {
-                        var paramInfos = new List<ParamInfo>();
-                        int c = k;
-                        for (int i = 0; i < paramCount; i++)
-                        {
-                            paramInfos.Add(new ParamInfo { Type = argTypes[c % paramTypeNum] });
-                            c /= paramTypeNum;
-                        }
-                        var mbs = new MethodBridgeSig() { ReturnInfo = rt, ParamInfos = paramInfos };
-                        yield return mbs;
-                    }
-                }
-            }
-        }
-
-        public override IEnumerable<MethodBridgeSig> GetPreserveMethods()
-        {
-            foreach (var method in PrepareCommon1())
-            {
-                yield return method;
-            }
-            foreach (var method in PrepareCommon2())
-            {
-                yield return method;
-            }
-        }
-
-        public override void GenerateCall(MethodBridgeSig method, List<string> lines)
-        {
-            //int totalQuadWordNum = method.ParamInfos.Sum(p => p.GetParamSlotNum(this.CallConventionType)) + method.ReturnInfo.GetParamSlotNum(this.CallConventionType);
             int totalQuadWordNum = method.ParamInfos.Count + method.ReturnInfo.GetParamSlotNum(this.CallConventionType);
-
-
-
             string paramListStr = string.Join(", ", method.ParamInfos.Select(p => $"{p.Type.GetTypeName()} __arg{p.Index}").Concat(new string[] { "const MethodInfo* method" }));
-            string paramTypeListStr = string.Join(", ", method.ParamInfos.Select(p => $"{p.Type.GetTypeName()}").Concat(new string[] { "const MethodInfo*" })); ;
             string paramNameListStr = string.Join(", ", method.ParamInfos.Select(p => p.Managed2NativeParamValue(this.CallConventionType)).Concat(new string[] { "method" }));
 
-            string invokeAssignArgs = @$"
-	if (hybridclr::IsInstanceMethod(method))
-	{{
-        args[0].ptr = __this;
-{string.Join("\n", method.ParamInfos.Skip(1).Select(p => $"\t\targs[{p.Index}].u64 = *(uint64_t*)__args[{p.Index - 1}];"))}
-    }}
-	else
-	{{
-{string.Join("\n", method.ParamInfos.Select(p => $"\t\targs[{p.Index}].u64 = *(uint64_t*)__args[{p.Index}];"))}
-    }}
-";
-
             lines.Add($@"
-static {method.ReturnInfo.Type.GetTypeName()} __Native2ManagedCall_{method.CreateCallSigName()}({paramListStr})
+static void __M2N_{method.CreateCallSigName()}(const MethodInfo* method, uint16_t* argVarIndexs, StackObject* localVarBase, void* ret)
 {{
-    StackObject args[{Math.Max(totalQuadWordNum, 1)}] = {{{string.Join(", ", method.ParamInfos.Select(p => p.Native2ManagedParamValue(this.CallConventionType)))} }};
-    StackObject* ret = {(method.ReturnInfo.IsVoid ? "nullptr" : "args + " + method.ParamInfos.Count)};
-    Interpreter::Execute(method, args, ret);
-    {(!method.ReturnInfo.IsVoid ? $"return *({method.ReturnInfo.Type.GetTypeName()}*)ret;" : "")}
+    typedef {method.ReturnInfo.Type.GetTypeName()} (*NativeMethod)({paramListStr});
+    {(!method.ReturnInfo.IsVoid ? $"*({method.ReturnInfo.Type.GetTypeName()}*)ret = " : "")}((NativeMethod)(GetInterpreterDirectlyCallMethodPointer(method)))({paramNameListStr});
 }}
+");
+        }
 
-static {method.ReturnInfo.Type.GetTypeName()} __Native2ManagedCall_AdjustorThunk_{method.CreateCallSigName()}({paramListStr})
+        public override void GenerateNative2ManagedMethod(MethodBridgeSig method, List<string> lines)
+        {
+            int totalQuadWordNum = method.ParamInfos.Count + method.ReturnInfo.GetParamSlotNum(this.CallConventionType);
+            string paramListStr = string.Join(", ", method.ParamInfos.Select(p => $"{p.Type.GetTypeName()} __arg{p.Index}").Concat(new string[] { "const MethodInfo* method" }));
+            
+            lines.Add($@"
+static {method.ReturnInfo.Type.GetTypeName()} __N2M_{method.CreateCallSigName()}({paramListStr})
 {{
-    StackObject args[{Math.Max(totalQuadWordNum, 1)}] = {{{string.Join(", ", method.ParamInfos.Select(p => (p.Index == 0 ? $"(uint64_t)(*(uint8_t**)&__arg{p.Index} + sizeof(Il2CppObject))" : p.Native2ManagedParamValue(this.CallConventionType))))} }};
+    StackObject args[{Math.Max(totalQuadWordNum, 1)}] = {{{string.Join(", ", method.ParamInfos.Select(p => p.Native2ManagedParamValue(this.CallConventionType)))} }};
     StackObject* ret = {(method.ReturnInfo.IsVoid ? "nullptr" : "args + " + method.ParamInfos.Count)};
     Interpreter::Execute(method, args, ret);
     {(!method.ReturnInfo.IsVoid ? $"return *({method.ReturnInfo.Type.GetTypeName()}*)ret;" : "")}
 }}
-
-static void __Managed2NativeCall_{method.CreateCallSigName()}(const MethodInfo* method, uint16_t* argVarIndexs, StackObject* localVarBase, void* ret)
-{{
-    if (hybridclr::metadata::IsInstanceMethod(method) && !localVarBase[argVarIndexs[0]].obj)
-    {{
-        il2cpp::vm::Exception::RaiseNullReferenceException();
-    }}
-    Interpreter::RuntimeClassCCtorInit(method);
-    typedef {method.ReturnInfo.Type.GetTypeName()} (*NativeMethod)({paramListStr});
-    {(!method.ReturnInfo.IsVoid ? $"*({method.ReturnInfo.Type.GetTypeName()}*)ret = " : "")}((NativeMethod)(GetInterpreterDirectlyCallMethodPointer(method)))({paramNameListStr});
-}}
 ");
         }
 
-        public override void GenerateInvoke(MethodBridgeSig method, List<string> lines)
+        public override void GenerateAdjustThunkMethod(MethodBridgeSig method, List<string> lines)
         {
-            //int totalQuadWordNum = method.ParamInfos.Sum(p => p.GetParamSlotNum(this.CallConventionType)) + method.ReturnInfo.GetParamSlotNum(this.CallConventionType);
             int totalQuadWordNum = method.ParamInfos.Count + method.ReturnInfo.GetParamSlotNum(this.CallConventionType);
 
-
-
             string paramListStr = string.Join(", ", method.ParamInfos.Select(p => $"{p.Type.GetTypeName()} __arg{p.Index}").Concat(new string[] { "const MethodInfo* method" }));
-            string paramTypeListStr = string.Join(", ", method.ParamInfos.Select(p => $"{p.Type.GetTypeName()}").Concat(new string[] { "const MethodInfo*" })); ;
-            string paramNameListStr = string.Join(", ", method.ParamInfos.Select(p => p.Managed2NativeParamValue(this.CallConventionType)).Concat(new string[] { "method" }));
-
-            string invokeAssignArgs = @$"
-	if (hybridclr::IsInstanceMethod(method))
-	{{
-        args[0].ptr = __this;
-{string.Join("\n", method.ParamInfos.Skip(1).Select(p => $"\t\targs[{p.Index}].u64 = *(uint64_t*)__args[{p.Index - 1}];"))}
-    }}
-	else
-	{{
-{string.Join("\n", method.ParamInfos.Select(p => $"\t\targs[{p.Index}].u64 = *(uint64_t*)__args[{p.Index}];"))}
-    }}
-";
-
 
             lines.Add($@"
-#ifdef HYBRIDCLR_UNITY_2021_OR_NEW
-static void __Invoke_instance_{method.CreateCallSigName()}(Il2CppMethodPointer __methodPtr, const MethodInfo* __method, void* __this, void** __args, void* __ret)
-{{
-    StackObject args[{totalQuadWordNum + 1}] = {{ (uint64_t)__this }};
-    ConvertInvokeArgs(args+1, __method, __args);
-    Interpreter::Execute(__method, args, __ret);
-}}
-
-static void __Invoke_static_{method.CreateCallSigName()}(Il2CppMethodPointer __methodPtr, const MethodInfo* __method, void* __this, void** __args, void* __ret)
+static {method.ReturnInfo.Type.GetTypeName()} __N2M_AdjustorThunk_{method.CreateCallSigName()}({paramListStr})
 {{
-    StackObject args[{Math.Max(totalQuadWordNum, 1)}] = {{ }};
-    ConvertInvokeArgs(args, __method, __args);
-    Interpreter::Execute(__method, args, __ret);
-}}
-#else
-static void* __Invoke_instance_{method.CreateCallSigName()}(Il2CppMethodPointer __methodPtr, const MethodInfo* __method, void* __this, void** __args)
-{{
-    StackObject args[{totalQuadWordNum + 1}] = {{ (uint64_t)AdjustValueTypeSelfPointer(({ConstStrings.typeObjectPtr})__this, __method)}};
-    ConvertInvokeArgs(args+1, __method, __args);
-    StackObject* ret = {(!method.ReturnInfo.IsVoid ? "args + " + (method.ParamInfos.Count + 1) : "nullptr")};
-    Interpreter::Execute(__method, args, ret);
-    return {(!method.ReturnInfo.IsVoid ? $"TranslateNativeValueToBoxValue(__method->return_type, ret)" : "nullptr")};
-}}
-
-static void* __Invoke_static_{method.CreateCallSigName()}(Il2CppMethodPointer __methodPtr, const MethodInfo* __method, void* __this, void** __args)
-{{
-    StackObject args[{Math.Max(totalQuadWordNum, 1)}] = {{ }};
-    ConvertInvokeArgs(args, __method, __args);
-    StackObject* ret = {(!method.ReturnInfo.IsVoid ? "args + " + method.ParamInfos.Count : "nullptr")};
-    Interpreter::Execute(__method, args, ret);
-    return {(!method.ReturnInfo.IsVoid ? $"TranslateNativeValueToBoxValue(__method->return_type, ret)" : "nullptr")};
+    StackObject args[{Math.Max(totalQuadWordNum, 1)}] = {{{string.Join(", ", method.ParamInfos.Select(p => (p.Index == 0 ? $"(uint64_t)(*(uint8_t**)&__arg{p.Index} + sizeof(Il2CppObject))" : p.Native2ManagedParamValue(this.CallConventionType))))} }};
+    StackObject* ret = {(method.ReturnInfo.IsVoid ? "nullptr" : "args + " + method.ParamInfos.Count)};
+    Interpreter::Execute(method, args, ret);
+    {(!method.ReturnInfo.IsVoid ? $"return *({method.ReturnInfo.Type.GetTypeName()}*)ret;" : "")}
 }}
-#endif
 ");
         }
     }

+ 20 - 164
GameClient/Assets/Editor/HybridCLR/Generators/MethodBridge/PlatformAdaptor_Universal32.cs

@@ -46,194 +46,50 @@ namespace HybridCLR.Generators.MethodBridge
             return CreateGeneralValueType(type, typeSize, actualAliment);
         }
 
-        public IEnumerable<MethodBridgeSig> PrepareCommon1()
+        public override void GenerateManaged2NativeMethod(MethodBridgeSig method, List<string> lines)
         {
-            // (void + int32 + int64 + float + double) * (int32 + int64 + float + double) * (0 - 20) = 420
-            TypeInfo typeVoid = new TypeInfo(typeof(void), ParamOrReturnType.VOID);
-            TypeInfo typeInt = new TypeInfo(typeof(int), ParamOrReturnType.I4_U4);
-            TypeInfo typeLong = new TypeInfo(typeof(long), ParamOrReturnType.I8_U8);
-            TypeInfo typeFloat = new TypeInfo(typeof(float), ParamOrReturnType.R4);
-            TypeInfo typeDouble = new TypeInfo(typeof(double), ParamOrReturnType.R8);
-            int maxParamCount = 20;
-
-            foreach (var returnType in new TypeInfo[] { typeVoid, typeInt, typeLong, typeFloat, typeDouble })
-            {
-                var rt = new ReturnInfo() { Type = returnType };
-                foreach (var argType in new TypeInfo[] { typeInt, typeLong, typeFloat, typeDouble })
-                {
-                    for (int paramCount = 0; paramCount <= maxParamCount; paramCount++)
-                    {
-                        var paramInfos = new List<ParamInfo>();
-                        for (int i = 0; i < paramCount; i++)
-                        {
-                            paramInfos.Add(new ParamInfo() { Type = argType });
-                        }
-                        var mbs = new MethodBridgeSig() { ReturnInfo = rt, ParamInfos = paramInfos };
-                        yield return mbs;
-                    }
-                }
-            }
-        }
-
-        public IEnumerable<MethodBridgeSig> PrepareCommon2()
-        {
-            // (void + int32 + int64 + float + double + v2f + v3f + v4f + s2) * (int32 + int64 + float + double + v2f + v3f + v4f + s2 + sr) ^ (0 - 2) = 399
-            TypeInfo typeVoid = new TypeInfo(typeof(void), ParamOrReturnType.VOID);
-            TypeInfo typeInt = new TypeInfo(typeof(int), ParamOrReturnType.I4_U4);
-            TypeInfo typeLong = new TypeInfo(typeof(long), ParamOrReturnType.I8_U8);
-            TypeInfo typeFloat = new TypeInfo(typeof(float), ParamOrReturnType.R4);
-            TypeInfo typeDouble = new TypeInfo(typeof(double), ParamOrReturnType.R8);
-            //TypeInfo typeStructRef = new TypeInfo(null, ParamOrReturnType.STRUCTURE_AS_REF_PARAM);
-
-            int maxParamCount = 2;
-
-            var argTypes = new TypeInfo[] { typeInt, typeLong, typeFloat, typeDouble };
-            int paramTypeNum = argTypes.Length;
-            foreach (var returnType in new TypeInfo[] { typeVoid, typeInt, typeLong, typeFloat, typeDouble })
-            {
-                var rt = new ReturnInfo() { Type = returnType };
-                for (int paramCount = 0; paramCount <= maxParamCount; paramCount++)
-                {
-                    int totalCombinationNum = (int)Math.Pow(paramTypeNum, paramCount);
-
-                    for (int k = 0; k < totalCombinationNum; k++)
-                    {
-                        var paramInfos = new List<ParamInfo>();
-                        int c = k;
-                        for (int i = 0; i < paramCount; i++)
-                        {
-                            paramInfos.Add(new ParamInfo { Type = argTypes[c % paramTypeNum] });
-                            c /= paramTypeNum;
-                        }
-                        var mbs = new MethodBridgeSig() { ReturnInfo = rt, ParamInfos = paramInfos };
-                        yield return mbs;
-                    }
-                }
-            }
-        }
+            string paramListStr = string.Join(", ", method.ParamInfos.Select(p => $"{p.Type.GetTypeName()} __arg{p.Index}").Concat(new string[] { "const MethodInfo* method" }));
+            string paramNameListStr = string.Join(", ", method.ParamInfos.Select(p => p.Managed2NativeParamValue(this.CallConventionType)).Concat(new string[] { "method" }));
 
-        public override IEnumerable<MethodBridgeSig> GetPreserveMethods()
-        {
-            foreach (var method in PrepareCommon1())
-            {
-                yield return method;
-            }
-            foreach (var method in PrepareCommon2())
-            {
-                yield return method;
-            }
+            lines.Add($@"
+static void __M2N_{method.CreateCallSigName()}(const MethodInfo* method, uint16_t* argVarIndexs, StackObject* localVarBase, void* ret)
+{{
+    typedef {method.ReturnInfo.Type.GetTypeName()} (*NativeMethod)({paramListStr});
+    {(!method.ReturnInfo.IsVoid ? $"*({method.ReturnInfo.Type.GetTypeName()}*)ret = " : "")}((NativeMethod)(GetInterpreterDirectlyCallMethodPointer(method)))({paramNameListStr});
+}}
+");
         }
-
-        public override void GenerateCall(MethodBridgeSig method, List<string> lines)
+        public override void GenerateNative2ManagedMethod(MethodBridgeSig method, List<string> lines)
         {
-            //int totalQuadWordNum = method.ParamInfos.Sum(p => p.GetParamSlotNum(this.CallConventionType)) + method.ReturnInfo.GetParamSlotNum(this.CallConventionType);
             int totalQuadWordNum = method.ParamInfos.Count + method.ReturnInfo.GetParamSlotNum(this.CallConventionType);
-
             string paramListStr = string.Join(", ", method.ParamInfos.Select(p => $"{p.Type.GetTypeName()} __arg{p.Index}").Concat(new string[] { "const MethodInfo* method" }));
-            string paramTypeListStr = string.Join(", ", method.ParamInfos.Select(p => $"{p.Type.GetTypeName()}").Concat(new string[] { "const MethodInfo*" })); ;
-            string paramNameListStr = string.Join(", ", method.ParamInfos.Select(p => p.Managed2NativeParamValue(this.CallConventionType)).Concat(new string[] { "method" }));
-
-            string invokeAssignArgs = @$"
-	if (hybridclr::IsInstanceMethod(method))
-	{{
-        args[0].ptr = __this;
-{string.Join("\n", method.ParamInfos.Skip(1).Select(p => $"\t\targs[{p.Index}].u64 = *(uint64_t*)__args[{p.Index - 1}];"))}
-    }}
-	else
-	{{
-{string.Join("\n", method.ParamInfos.Select(p => $"\t\targs[{p.Index}].u64 = *(uint64_t*)__args[{p.Index}];"))}
-    }}
-";
-
+            
             lines.Add($@"
-static {method.ReturnInfo.Type.GetTypeName()} __Native2ManagedCall_{method.CreateCallSigName()}({paramListStr})
+static {method.ReturnInfo.Type.GetTypeName()} __N2M_{method.CreateCallSigName()}({paramListStr})
 {{
     StackObject args[{Math.Max(totalQuadWordNum, 1)}] = {{{string.Join(", ", method.ParamInfos.Select(p => p.Native2ManagedParamValue(this.CallConventionType)))} }};
     StackObject* ret = {(method.ReturnInfo.IsVoid ? "nullptr" : "args + " + method.ParamInfos.Count)};
     Interpreter::Execute(method, args, ret);
     {(!method.ReturnInfo.IsVoid ? $"return *({method.ReturnInfo.Type.GetTypeName()}*)ret;" : "")}
 }}
-
-static {method.ReturnInfo.Type.GetTypeName()} __Native2ManagedCall_AdjustorThunk_{method.CreateCallSigName()}({paramListStr})
-{{
-    StackObject args[{Math.Max(totalQuadWordNum, 1)}] = {{{string.Join(", ", method.ParamInfos.Select(p => (p.Index == 0 ? $"(uint64_t)(*(uint8_t**)&__arg{p.Index} + sizeof(Il2CppObject))" : p.Native2ManagedParamValue(this.CallConventionType))))} }};
-    StackObject* ret = {(method.ReturnInfo.IsVoid ? "nullptr" : "args + " + method.ParamInfos.Count)};
-    Interpreter::Execute(method, args, ret);
-    {(!method.ReturnInfo.IsVoid ? $"return *({method.ReturnInfo.Type.GetTypeName()}*)ret;" : "")}
-}}
-
-static void __Managed2NativeCall_{method.CreateCallSigName()}(const MethodInfo* method, uint16_t* argVarIndexs, StackObject* localVarBase, void* ret)
-{{
-    if (hybridclr::metadata::IsInstanceMethod(method) && !localVarBase[argVarIndexs[0]].obj)
-    {{
-        il2cpp::vm::Exception::RaiseNullReferenceException();
-    }}
-    Interpreter::RuntimeClassCCtorInit(method);
-    typedef {method.ReturnInfo.Type.GetTypeName()} (*NativeMethod)({paramListStr});
-    {(!method.ReturnInfo.IsVoid ? $"*({method.ReturnInfo.Type.GetTypeName()}*)ret = " : "")}((NativeMethod)(GetInterpreterDirectlyCallMethodPointer(method)))({paramNameListStr});
-}}
 ");
-
         }
-
-
-        public override void GenerateInvoke(MethodBridgeSig method, List<string> lines)
+        public override void GenerateAdjustThunkMethod(MethodBridgeSig method, List<string> lines)
         {
-            //int totalQuadWordNum = method.ParamInfos.Sum(p => p.GetParamSlotNum(this.CallConventionType)) + method.ReturnInfo.GetParamSlotNum(this.CallConventionType);
             int totalQuadWordNum = method.ParamInfos.Count + method.ReturnInfo.GetParamSlotNum(this.CallConventionType);
 
             string paramListStr = string.Join(", ", method.ParamInfos.Select(p => $"{p.Type.GetTypeName()} __arg{p.Index}").Concat(new string[] { "const MethodInfo* method" }));
-            string paramTypeListStr = string.Join(", ", method.ParamInfos.Select(p => $"{p.Type.GetTypeName()}").Concat(new string[] { "const MethodInfo*" })); ;
-            string paramNameListStr = string.Join(", ", method.ParamInfos.Select(p => p.Managed2NativeParamValue(this.CallConventionType)).Concat(new string[] { "method" }));
-
-            string invokeAssignArgs = @$"
-	if (hybridclr::IsInstanceMethod(method))
-	{{
-        args[0].ptr = __this;
-{string.Join("\n", method.ParamInfos.Skip(1).Select(p => $"\t\targs[{p.Index}].u64 = *(uint64_t*)__args[{p.Index - 1}];"))}
-    }}
-	else
-	{{
-{string.Join("\n", method.ParamInfos.Select(p => $"\t\targs[{p.Index}].u64 = *(uint64_t*)__args[{p.Index}];"))}
-    }}
-";
-
 
             lines.Add($@"
-#ifdef HYBRIDCLR_UNITY_2021_OR_NEW
-static void __Invoke_instance_{method.CreateCallSigName()}(Il2CppMethodPointer __methodPtr, const MethodInfo* __method, void* __this, void** __args, void* __ret)
+static {method.ReturnInfo.Type.GetTypeName()} __N2M_AdjustorThunk_{method.CreateCallSigName()}({paramListStr})
 {{
-    StackObject args[{totalQuadWordNum + 1}] = {{ (uint64_t)__this }};
-    ConvertInvokeArgs(args+1, __method, __args);
-    Interpreter::Execute(__method, args, __ret);
-}}
-
-static void __Invoke_static_{method.CreateCallSigName()}(Il2CppMethodPointer __methodPtr, const MethodInfo* __method, void* __this, void** __args, void* __ret)
-{{
-    StackObject args[{Math.Max(totalQuadWordNum, 1)}] = {{ }};
-    ConvertInvokeArgs(args, __method, __args);
-    Interpreter::Execute(__method, args, __ret);
-}}
-#else
-static void* __Invoke_instance_{method.CreateCallSigName()}(Il2CppMethodPointer __methodPtr, const MethodInfo* __method, void* __this, void** __args)
-{{
-    StackObject args[{totalQuadWordNum + 1}] = {{ (uint64_t)AdjustValueTypeSelfPointer(({ConstStrings.typeObjectPtr})__this, __method)}};
-    ConvertInvokeArgs(args+1, __method, __args);
-    StackObject* ret = {(!method.ReturnInfo.IsVoid ? "args + " + (method.ParamInfos.Count + 1) : "nullptr")};
-    Interpreter::Execute(__method, args, ret);
-    return {(!method.ReturnInfo.IsVoid ? $"TranslateNativeValueToBoxValue(__method->return_type, ret)" : "nullptr")};
-}}
-
-static void* __Invoke_static_{method.CreateCallSigName()}(Il2CppMethodPointer __methodPtr, const MethodInfo* __method, void* __this, void** __args)
-{{
-    StackObject args[{Math.Max(totalQuadWordNum, 1)}] = {{ }};
-    ConvertInvokeArgs(args, __method, __args);
-    StackObject* ret = {(!method.ReturnInfo.IsVoid ? "args + " + method.ParamInfos.Count : "nullptr")};
-    Interpreter::Execute(__method, args, ret);
-    return {(!method.ReturnInfo.IsVoid ? $"TranslateNativeValueToBoxValue(__method->return_type, ret)" : "nullptr")};
+    StackObject args[{Math.Max(totalQuadWordNum, 1)}] = {{{string.Join(", ", method.ParamInfos.Select(p => (p.Index == 0 ? $"(uint64_t)(*(uint8_t**)&__arg{p.Index} + sizeof(Il2CppObject))" : p.Native2ManagedParamValue(this.CallConventionType))))} }};
+    StackObject* ret = {(method.ReturnInfo.IsVoid ? "nullptr" : "args + " + method.ParamInfos.Count)};
+    Interpreter::Execute(method, args, ret);
+    {(!method.ReturnInfo.IsVoid ? $"return *({method.ReturnInfo.Type.GetTypeName()}*)ret;" : "")}
 }}
-#endif
 ");
+
         }
     }
 

+ 19 - 167
GameClient/Assets/Editor/HybridCLR/Generators/MethodBridge/PlatformAdaptor_Universal64.cs

@@ -140,197 +140,49 @@ namespace HybridCLR.Generators.MethodBridge
 
         }
 
-        public IEnumerable<MethodBridgeSig> PrepareCommon1()
+        public override void GenerateManaged2NativeMethod(MethodBridgeSig method, List<string> lines)
         {
-            // (void + int32 + int64 + float + double) * (int32 + int64 + float + double) * (0 - 20) = 420
-            TypeInfo typeVoid = new TypeInfo(typeof(void), ParamOrReturnType.VOID);
-            TypeInfo typeInt = new TypeInfo(typeof(int), ParamOrReturnType.I4_U4);
-            TypeInfo typeLong = new TypeInfo(typeof(long), ParamOrReturnType.I8_U8);
-            TypeInfo typeFloat = new TypeInfo(typeof(float), ParamOrReturnType.R4);
-            TypeInfo typeDouble = new TypeInfo(typeof(double), ParamOrReturnType.R8);
-            int maxParamCount = 20;
-
-            foreach (var returnType in new TypeInfo[] { typeVoid, typeInt, typeLong, typeFloat, typeDouble })
-            {
-                var rt = new ReturnInfo() { Type = returnType };
-                foreach (var argType in new TypeInfo[] { typeInt, typeLong, typeFloat, typeDouble })
-                {
-                    for (int paramCount = 0; paramCount <= maxParamCount; paramCount++)
-                    {
-                        var paramInfos = new List<ParamInfo>();
-                        for (int i = 0; i < paramCount; i++)
-                        {
-                            paramInfos.Add(new ParamInfo() { Type = argType });
-                        }
-                        var mbs = new MethodBridgeSig() { ReturnInfo = rt, ParamInfos = paramInfos };
-                        yield return mbs;
-                    }
-                }
-            }
-        }
-
-        public IEnumerable<MethodBridgeSig> PrepareCommon2()
-        {
-            // (void + int32 + int64 + float + double + v2f + v3f + v4f + s2) * (int32 + int64 + float + double + v2f + v3f + v4f + s2 + sr) ^ (0 - 2) = 399
-            TypeInfo typeVoid = new TypeInfo(typeof(void), ParamOrReturnType.VOID);
-            TypeInfo typeInt = new TypeInfo(typeof(int), ParamOrReturnType.I4_U4);
-            TypeInfo typeLong = new TypeInfo(typeof(long), ParamOrReturnType.I8_U8);
-            TypeInfo typeFloat = new TypeInfo(typeof(float), ParamOrReturnType.R4);
-            TypeInfo typeDouble = new TypeInfo(typeof(double), ParamOrReturnType.R8);
-            TypeInfo typeV2f = new TypeInfo(typeof(Vector2), ParamOrReturnType.ARM64_HFA_FLOAT_2);
-            TypeInfo typeV3f = new TypeInfo(typeof(Vector3), ParamOrReturnType.ARM64_HFA_FLOAT_3);
-            TypeInfo typeV4f = new TypeInfo(typeof(Vector4), ParamOrReturnType.ARM64_HFA_FLOAT_4);
-
-            int maxParamCount = 2;
-
-            var argTypes = new TypeInfo[] { typeInt, typeLong, typeFloat, typeDouble, typeV2f, typeV3f, typeV4f };
-            int paramTypeNum = argTypes.Length;
-            foreach (var returnType in new TypeInfo[] { typeVoid, typeInt, typeLong, typeFloat, typeDouble, typeV2f, typeV3f, typeV4f })
-            {
-                var rt = new ReturnInfo() { Type = returnType };
-                for (int paramCount = 0; paramCount <= maxParamCount; paramCount++)
-                {
-                    int totalCombinationNum = (int)Math.Pow(paramTypeNum, paramCount);
-
-                    for (int k = 0; k < totalCombinationNum; k++)
-                    {
-                        var paramInfos = new List<ParamInfo>();
-                        int c = k;
-                        for (int i = 0; i < paramCount; i++)
-                        {
-                            paramInfos.Add(new ParamInfo { Type = argTypes[c % paramTypeNum] });
-                            c /= paramTypeNum;
-                        }
-                        var mbs = new MethodBridgeSig() { ReturnInfo = rt, ParamInfos = paramInfos };
-                        yield return mbs;
-                    }
-                }
-            }
-        }
-
-        public override IEnumerable<MethodBridgeSig> GetPreserveMethods()
-        {
-            foreach (var method in PrepareCommon1())
-            {
-                yield return method;
-            }
-            foreach (var method in PrepareCommon2())
-            {
-                yield return method;
-            }
-        }
-
-        public override void GenerateCall(MethodBridgeSig method, List<string> lines)
-        {
-            //int totalQuadWordNum = method.ParamInfos.Sum(p => p.GetParamSlotNum(this.CallConventionType)) + method.ReturnInfo.GetParamSlotNum(this.CallConventionType);
             int totalQuadWordNum = method.ParamInfos.Count + method.ReturnInfo.GetParamSlotNum(this.CallConventionType);
 
-
-
             string paramListStr = string.Join(", ", method.ParamInfos.Select(p => $"{p.Type.GetTypeName()} __arg{p.Index}").Concat(new string[] { "const MethodInfo* method" }));
             string paramTypeListStr = string.Join(", ", method.ParamInfos.Select(p => $"{p.Type.GetTypeName()}").Concat(new string[] { "const MethodInfo*" })); ;
             string paramNameListStr = string.Join(", ", method.ParamInfos.Select(p => p.Managed2NativeParamValue(this.CallConventionType)).Concat(new string[] { "method" }));
 
-            string invokeAssignArgs = @$"
-	if (hybridclr::IsInstanceMethod(method))
-	{{
-        args[0].ptr = __this;
-{string.Join("\n", method.ParamInfos.Skip(1).Select(p => $"\t\targs[{p.Index}].u64 = *(uint64_t*)__args[{p.Index - 1}];"))}
-    }}
-	else
-	{{
-{string.Join("\n", method.ParamInfos.Select(p => $"\t\targs[{p.Index}].u64 = *(uint64_t*)__args[{p.Index}];"))}
-    }}
-";
-
             lines.Add($@"
-static {method.ReturnInfo.Type.GetTypeName()} __Native2ManagedCall_{method.CreateCallSigName()}({paramListStr})
+static void __M2N_{method.CreateCallSigName()}(const MethodInfo* method, uint16_t* argVarIndexs, StackObject* localVarBase, void* ret)
 {{
-    StackObject args[{Math.Max(totalQuadWordNum, 1)}] = {{{string.Join(", ", method.ParamInfos.Select(p => p.Native2ManagedParamValue(this.CallConventionType)))} }};
-    StackObject* ret = {(method.ReturnInfo.IsVoid ? "nullptr" : "args + " + method.ParamInfos.Count)};
-    Interpreter::Execute(method, args, ret);
-    {(!method.ReturnInfo.IsVoid ? $"return *({method.ReturnInfo.Type.GetTypeName()}*)ret;" : "")}
+    typedef {method.ReturnInfo.Type.GetTypeName()} (*NativeMethod)({paramListStr});
+    {(!method.ReturnInfo.IsVoid ? $"*({method.ReturnInfo.Type.GetTypeName()}*)ret = " : "")}((NativeMethod)(GetInterpreterDirectlyCallMethodPointer(method)))({paramNameListStr});
 }}
-
-static {method.ReturnInfo.Type.GetTypeName()} __Native2ManagedCall_AdjustorThunk_{method.CreateCallSigName()}({paramListStr})
+");
+        }
+        public override void GenerateNative2ManagedMethod(MethodBridgeSig method, List<string> lines)
+        {
+            int totalQuadWordNum = method.ParamInfos.Count + method.ReturnInfo.GetParamSlotNum(this.CallConventionType);
+            string paramListStr = string.Join(", ", method.ParamInfos.Select(p => $"{p.Type.GetTypeName()} __arg{p.Index}").Concat(new string[] { "const MethodInfo* method" }));
+            lines.Add($@"
+static {method.ReturnInfo.Type.GetTypeName()} __N2M_{method.CreateCallSigName()}({paramListStr})
 {{
-    StackObject args[{Math.Max(totalQuadWordNum, 1)}] = {{{string.Join(", ", method.ParamInfos.Select(p => (p.Index == 0 ? $"(uint64_t)(*(uint8_t**)&__arg{p.Index} + sizeof(Il2CppObject))" : p.Native2ManagedParamValue(this.CallConventionType))))} }};
+    StackObject args[{Math.Max(totalQuadWordNum, 1)}] = {{{string.Join(", ", method.ParamInfos.Select(p => p.Native2ManagedParamValue(this.CallConventionType)))} }};
     StackObject* ret = {(method.ReturnInfo.IsVoid ? "nullptr" : "args + " + method.ParamInfos.Count)};
     Interpreter::Execute(method, args, ret);
     {(!method.ReturnInfo.IsVoid ? $"return *({method.ReturnInfo.Type.GetTypeName()}*)ret;" : "")}
 }}
-
-static void __Managed2NativeCall_{method.CreateCallSigName()}(const MethodInfo* method, uint16_t* argVarIndexs, StackObject* localVarBase, void* ret)
-{{
-    if (hybridclr::metadata::IsInstanceMethod(method) && !localVarBase[argVarIndexs[0]].obj)
-    {{
-        il2cpp::vm::Exception::RaiseNullReferenceException();
-    }}
-    Interpreter::RuntimeClassCCtorInit(method);
-    typedef {method.ReturnInfo.Type.GetTypeName()} (*NativeMethod)({paramListStr});
-    {(!method.ReturnInfo.IsVoid ? $"*({method.ReturnInfo.Type.GetTypeName()}*)ret = " : "")}((NativeMethod)(GetInterpreterDirectlyCallMethodPointer(method)))({paramNameListStr});
-}}
 ");
         }
 
-        public override void GenerateInvoke(MethodBridgeSig method, List<string> lines)
+        public override void GenerateAdjustThunkMethod(MethodBridgeSig method, List<string> lines)
         {
-            //int totalQuadWordNum = method.ParamInfos.Sum(p => p.GetParamSlotNum(this.CallConventionType)) + method.ReturnInfo.GetParamSlotNum(this.CallConventionType);
             int totalQuadWordNum = method.ParamInfos.Count + method.ReturnInfo.GetParamSlotNum(this.CallConventionType);
-
-
-
             string paramListStr = string.Join(", ", method.ParamInfos.Select(p => $"{p.Type.GetTypeName()} __arg{p.Index}").Concat(new string[] { "const MethodInfo* method" }));
-            string paramTypeListStr = string.Join(", ", method.ParamInfos.Select(p => $"{p.Type.GetTypeName()}").Concat(new string[] { "const MethodInfo*" })); ;
-            string paramNameListStr = string.Join(", ", method.ParamInfos.Select(p => p.Managed2NativeParamValue(this.CallConventionType)).Concat(new string[] { "method" }));
-
-            string invokeAssignArgs = @$"
-	if (hybridclr::IsInstanceMethod(method))
-	{{
-        args[0].ptr = __this;
-{string.Join("\n", method.ParamInfos.Skip(1).Select(p => $"\t\targs[{p.Index}].u64 = *(uint64_t*)__args[{p.Index - 1}];"))}
-    }}
-	else
-	{{
-{string.Join("\n", method.ParamInfos.Select(p => $"\t\targs[{p.Index}].u64 = *(uint64_t*)__args[{p.Index}];"))}
-    }}
-";
-
-
             lines.Add($@"
-#ifdef HYBRIDCLR_UNITY_2021_OR_NEW
-static void __Invoke_instance_{method.CreateCallSigName()}(Il2CppMethodPointer __methodPtr, const MethodInfo* __method, void* __this, void** __args, void* __ret)
-{{
-    StackObject args[{totalQuadWordNum + 1}] = {{ (uint64_t)__this }};
-    ConvertInvokeArgs(args+1, __method, __args);
-    Interpreter::Execute(__method, args, __ret);
-}}
-
-static void __Invoke_static_{method.CreateCallSigName()}(Il2CppMethodPointer __methodPtr, const MethodInfo* __method, void* __this, void** __args, void* __ret)
+static {method.ReturnInfo.Type.GetTypeName()} __N2M_AdjustorThunk_{method.CreateCallSigName()}({paramListStr})
 {{
-    StackObject args[{Math.Max(totalQuadWordNum, 1)}] = {{ }};
-    ConvertInvokeArgs(args, __method, __args);
-    Interpreter::Execute(__method, args, __ret);
-}}
-#else
-static void* __Invoke_instance_{method.CreateCallSigName()}(Il2CppMethodPointer __methodPtr, const MethodInfo* __method, void* __this, void** __args)
-{{
-    StackObject args[{totalQuadWordNum + 1}] = {{ (uint64_t)AdjustValueTypeSelfPointer(({ConstStrings.typeObjectPtr})__this, __method)}};
-    ConvertInvokeArgs(args+1, __method, __args);
-    StackObject* ret = {(!method.ReturnInfo.IsVoid ? "args + " + (method.ParamInfos.Count + 1) : "nullptr")};
-    Interpreter::Execute(__method, args, ret);
-    return {(!method.ReturnInfo.IsVoid ? $"TranslateNativeValueToBoxValue(__method->return_type, ret)" : "nullptr")};
-}}
-
-static void* __Invoke_static_{method.CreateCallSigName()}(Il2CppMethodPointer __methodPtr, const MethodInfo* __method, void* __this, void** __args)
-{{
-    StackObject args[{Math.Max(totalQuadWordNum, 1)}] = {{ }};
-    ConvertInvokeArgs(args, __method, __args);
-    StackObject* ret = {(!method.ReturnInfo.IsVoid ? "args + " + method.ParamInfos.Count : "nullptr")};
-    Interpreter::Execute(__method, args, ret);
-    return {(!method.ReturnInfo.IsVoid ? $"TranslateNativeValueToBoxValue(__method->return_type, ret)" : "nullptr")};
+    StackObject args[{Math.Max(totalQuadWordNum, 1)}] = {{{string.Join(", ", method.ParamInfos.Select(p => (p.Index == 0 ? $"(uint64_t)(*(uint8_t**)&__arg{p.Index} + sizeof(Il2CppObject))" : p.Native2ManagedParamValue(this.CallConventionType))))} }};
+    StackObject* ret = {(method.ReturnInfo.IsVoid ? "nullptr" : "args + " + method.ParamInfos.Count)};
+    Interpreter::Execute(method, args, ret);
+    {(!method.ReturnInfo.IsVoid ? $"return *({method.ReturnInfo.Type.GetTypeName()}*)ret;" : "")}
 }}
-#endif
 ");
         }
     }

+ 3 - 1
GameClient/Assets/Editor/HybridCLR/MethodBridgeHelper.cs

@@ -78,7 +78,9 @@ namespace HybridCLR
             var g = new MethodBridgeGenerator(new MethodBridgeGeneratorOptions()
             {
                 CallConvention = platform,
-                Assemblies = GetScanAssembiles(),
+                HotfixAssemblies = BuildConfig.AllHotUpdateDllNames.Select(name =>
+                    AppDomain.CurrentDomain.GetAssemblies().First(ass => ass.GetName().Name + ".dll" == name)).ToList(),
+                AllAssemblies = GetScanAssembiles(),
                 OutputFile = outputFile,
             });
 

+ 2 - 2
GameClient/HybridCLRData/iOSBuild/gen_lump.sh

@@ -45,11 +45,11 @@ OBJECTIVE_FILE_NAME=${GEN_SOURCE_DIR}/lump_mm/lump_libil2cpp_ojective.mm
 echo "#include \"${BASE_DIR}/il2cpp-config.h\"" > ${OBJECTIVE_FILE_NAME}
 echo gen file: ${OBJECTIVE_FILE_NAME}
 
-for FOLDER in huatuo vm pch utils vm-utils codegen metadata os debugger mono gc icalls
+for FOLDER in hybridclr vm pch utils vm-utils codegen metadata os debugger mono gc icalls
 do
     OUTPUT_FILE_NAME=${GEN_SOURCE_DIR}/lump_cpp/lump_libil2cpp_${FOLDER}.cpp
     echo "#include \"${BASE_DIR}/il2cpp-config.h\"" > ${OUTPUT_FILE_NAME}
-    if  [ $FOLDER = huatuo ] || [ $FOLDER = vm ]
+    if  [ $FOLDER = hybridclr ] || [ $FOLDER = vm ]
     then
         echo "#include \"${BASE_DIR}/codegen/il2cpp-codegen.h\"" >> ${OUTPUT_FILE_NAME}
     fi