Пример #1
0
        private static void GenerateCLRBindingByAnalysis()
        {
            //用新的分析热更dll调用引用来生成绑定代码
            ILRuntime.Runtime.Enviorment.AppDomain domain = new ILRuntime.Runtime.Enviorment.AppDomain();
            using (System.IO.FileStream fs = new System.IO.FileStream(BuildAssemblieEditor.ScriptAssembliesDir + "Code.dll", System.IO.FileMode.Open,
                                                                      System.IO.FileAccess.Read))
            {
                domain.LoadAssembly(fs);

                ILHelper.RegisterAdaptor(domain);

                ILRuntime.Runtime.CLRBinding.BindingCodeGenerator.GenerateBindingCode(domain, "Assets/Mono/ILRuntime/Generate");
            }

            AssetDatabase.Refresh();

            Debug.Log("生成CLR绑定文件完成");
        }
Пример #2
0
        private static void GenerateCLRBindingByAnalysis()
        {
            string jstr         = File.ReadAllText("Assets/AssetsPackage/config.bytes");
            var    config       = LitJson.JsonMapper.ToObject <Dictionary <string, string> >(jstr);
            string assemblyName = "Code" + config["ResVer"];

            //用新的分析热更dll调用引用来生成绑定代码
            ILRuntime.Runtime.Enviorment.AppDomain domain = new ILRuntime.Runtime.Enviorment.AppDomain();
            using (System.IO.FileStream fs = new System.IO.FileStream(Path.Combine(Define.BuildOutputDir, $"{assemblyName}.dll"), System.IO.FileMode.Open,
                                                                      System.IO.FileAccess.Read))
            {
                domain.LoadAssembly(fs);

                ILHelper.RegisterAdaptor(domain);

                ILRuntime.Runtime.CLRBinding.BindingCodeGenerator.GenerateBindingCode(domain, "Assets/Mono/ILRuntime/Generate");
            }

            AssetDatabase.Refresh();

            Debug.Log("生成CLR绑定文件完成");
        }
Пример #3
0
        /// <summary>
        /// 这里开始正式进入游戏逻辑
        /// </summary>
        public static void GoToHotfix(byte[] dllByte, byte[] pdbByte)
        {
            if (GlobalDefine.ILRuntimeMode)
            {
                _appDomain        = new ILRuntime.Runtime.Enviorment.AppDomain();
                s_hotfixDllStream = new MemoryStream(dllByte);
                s_hotfixPdbStream = new MemoryStream(pdbByte);
                _appDomain.LoadAssembly(s_hotfixDllStream, s_hotfixPdbStream,
                                        new ILRuntime.Mono.Cecil.Pdb.PdbReaderProvider());

                ILHelper.InitILRuntime(_appDomain);

                _entryMethod = new ILStaticMethod(_appDomain, "ET.InitEntry", "RegFunction", 0);
            }
            else
            {
                _assembly    = Assembly.Load(dllByte, pdbByte);
                _entryMethod = new MonoStaticMethod(_assembly, "ET.InitEntry", "RegFunction");
            }

            _entryMethod.Run();
        }
Пример #4
0
        public void Start()
        {
            switch (this.CodeMode)
            {
            case CodeMode.Mono:
            {
#if !UNITY_EDITOR
                var    ab       = AddressablesManager.Instance.SyncLoadAssetBundle("code_assets_all.bundle");
                byte[] assBytes = ((TextAsset)ab.LoadAsset($"Assets/AssetsPackage/Code/Code{AssetBundleConfig.Instance.ResVer}.dll.bytes", typeof(TextAsset))).bytes;
                byte[] pdbBytes = ((TextAsset)ab.LoadAsset($"Assets/AssetsPackage/Code/Code{AssetBundleConfig.Instance.ResVer}.pdb.bytes", typeof(TextAsset))).bytes;
#else
                byte[] assBytes = (AssetDatabase.LoadAssetAtPath($"Assets/AssetsPackage/Code/Code{AssetBundleConfig.Instance.ResVer}.dll.bytes", typeof(TextAsset)) as TextAsset).bytes;
                byte[] pdbBytes = (AssetDatabase.LoadAssetAtPath($"Assets/AssetsPackage/Code/Code{AssetBundleConfig.Instance.ResVer}.pdb.bytes", typeof(TextAsset)) as TextAsset).bytes;
#endif

                assembly = Assembly.Load(assBytes, pdbBytes);
                foreach (Type type in this.assembly.GetTypes())
                {
                    this.monoTypes[type.FullName]   = type;
                    this.hotfixTypes[type.FullName] = type;
                }
                IStaticMethod start = new MonoStaticMethod(assembly, "ET.Entry", "Start");
                start.Run();
#if !UNITY_EDITOR
                ab.Unload(true);
#endif
                break;
            }

            case CodeMode.ILRuntimeJIT:
            case CodeMode.ILRuntime:
            {
#if !UNITY_EDITOR
                var    ab       = AddressablesManager.Instance.SyncLoadAssetBundle("code_assets_all.bundle");
                byte[] assBytes = ((TextAsset)ab.LoadAsset($"Assets/AssetsPackage/Code/Code{AssetBundleConfig.Instance.ResVer}.dll.bytes", typeof(TextAsset))).bytes;
                byte[] pdbBytes = ((TextAsset)ab.LoadAsset($"Assets/AssetsPackage/Code/Code{AssetBundleConfig.Instance.ResVer}.pdb.bytes", typeof(TextAsset))).bytes;
#else
                byte[] assBytes = (AssetDatabase.LoadAssetAtPath($"Assets/AssetsPackage/Code/Code{AssetBundleConfig.Instance.ResVer}.dll.bytes", typeof(TextAsset)) as TextAsset).bytes;
                byte[] pdbBytes = (AssetDatabase.LoadAssetAtPath($"Assets/AssetsPackage/Code/Code{AssetBundleConfig.Instance.ResVer}.pdb.bytes", typeof(TextAsset)) as TextAsset).bytes;
#endif
                if (this.CodeMode == CodeMode.ILRuntimeJIT)
                {
                    appDomain = new ILRuntime.Runtime.Enviorment.AppDomain(ILRuntime.Runtime.ILRuntimeJITFlags.JITOnDemand);
                }
                else
                {
                    appDomain = new ILRuntime.Runtime.Enviorment.AppDomain();
                }

#if DEBUG && (UNITY_EDITOR || UNITY_ANDROID || UNITY_IPHONE)
                this.appDomain.UnityMainThreadID = System.Threading.Thread.CurrentThread.ManagedThreadId;
#endif
                if (assStream != null)
                {
                    assStream.Dispose();
                }
                if (pdbStream != null)
                {
                    pdbStream.Dispose();
                }
                assStream = new MemoryStream(assBytes);
                pdbStream = new MemoryStream(pdbBytes);
                appDomain.LoadAssembly(assStream, pdbStream, new ILRuntime.Mono.Cecil.Pdb.PdbReaderProvider());

                Type[] types = appDomain.LoadedTypes.Values.Select(x => x.ReflectionType).ToArray();
                foreach (Type type in types)
                {
                    this.hotfixTypes[type.FullName] = type;
                }

                ILHelper.InitILRuntime(appDomain);

                IStaticMethod start = new ILStaticMethod(appDomain, "ET.Entry", "Start", 0);
#if !UNITY_EDITOR
                ab.Unload(true);
#endif
                start.Run();
                break;
            }

            case CodeMode.Reload:
            {
                byte[] assBytes = File.ReadAllBytes(Path.Combine(Define.BuildOutputDir, "Data.dll"));
                byte[] pdbBytes = File.ReadAllBytes(Path.Combine(Define.BuildOutputDir, "Data.pdb"));

                assembly = Assembly.Load(assBytes, pdbBytes);
                this.LoadLogic();
                IStaticMethod start = new MonoStaticMethod(assembly, "ET.Entry", "Start");
                start.Run();
                break;
            }
            }
        }
Пример #5
0
        public void Start()
        {
            switch (this.CodeMode)
            {
            case CodeMode.Mono:
            {
                (AssetBundle assetsBundle, Dictionary <string, UnityEngine.Object> dictionary) = AssetsBundleHelper.LoadBundle("code.unity3d");
                byte[] assBytes = ((TextAsset)dictionary["Code.dll"]).bytes;
                byte[] pdbBytes = ((TextAsset)dictionary["Code.pdb"]).bytes;

                if (assetsBundle != null)
                {
                    assetsBundle.Unload(true);
                }

                assembly = Assembly.Load(assBytes, pdbBytes);
                foreach (Type type in this.assembly.GetTypes())
                {
                    this.monoTypes[type.FullName]   = type;
                    this.hotfixTypes[type.FullName] = type;
                }
                IStaticMethod start = new MonoStaticMethod(assembly, "ET.Entry", "Start");
                start.Run();
                break;
            }

            case CodeMode.ILRuntime:
            {
                (AssetBundle assetsBundle, Dictionary <string, UnityEngine.Object> dictionary) = AssetsBundleHelper.LoadBundle("code.unity3d");
                byte[] assBytes = ((TextAsset)dictionary["Code.dll"]).bytes;
                byte[] pdbBytes = ((TextAsset)dictionary["Code.pdb"]).bytes;

                if (assetsBundle != null)
                {
                    assetsBundle.Unload(true);
                }

                //byte[] assBytes = File.ReadAllBytes(Path.Combine("../Unity/", Define.BuildOutputDir, "Code.dll"));
                //byte[] pdbBytes = File.ReadAllBytes(Path.Combine("../Unity/", Define.BuildOutputDir, "Code.pdb"));

                appDomain = new ILRuntime.Runtime.Enviorment.AppDomain(ILRuntime.Runtime.ILRuntimeJITFlags.JITOnDemand);
#if DEBUG && (UNITY_EDITOR || UNITY_ANDROID || UNITY_IPHONE)
                this.appDomain.UnityMainThreadID = System.Threading.Thread.CurrentThread.ManagedThreadId;
#endif
                MemoryStream assStream = new MemoryStream(assBytes);
                MemoryStream pdbStream = new MemoryStream(pdbBytes);
                appDomain.LoadAssembly(assStream, pdbStream, new ILRuntime.Mono.Cecil.Pdb.PdbReaderProvider());

                Type[] types = appDomain.LoadedTypes.Values.Select(x => x.ReflectionType).ToArray();
                foreach (Type type in types)
                {
                    this.hotfixTypes[type.FullName] = type;
                }

                ILHelper.InitILRuntime(appDomain);

                IStaticMethod start = new ILStaticMethod(appDomain, "ET.Entry", "Start", 0);
                start.Run();
                break;
            }

            case CodeMode.Reload:
            {
                byte[] assBytes = File.ReadAllBytes(Path.Combine(Define.BuildOutputDir, "Data.dll"));
                byte[] pdbBytes = File.ReadAllBytes(Path.Combine(Define.BuildOutputDir, "Data.pdb"));

                assembly = Assembly.Load(assBytes, pdbBytes);
                this.LoadLogic();
                IStaticMethod start = new MonoStaticMethod(assembly, "ET.Entry", "Start");
                start.Run();
                break;
            }
            }
        }