Exemple #1
0
        public void LoadHotfixAssembly()
        {
            Game.Scene.GetComponent <ResourcesComponent>().LoadBundle($"code.unity3d");
            GameObject code = (GameObject)Game.Scene.GetComponent <ResourcesComponent>().GetAsset("code.unity3d", "Code");

#if ILRuntime
            Log.Debug($"当前使用的是ILRuntime模式");
            this.appDomain = new ILRuntime.Runtime.Enviorment.AppDomain();

            byte[] assBytes = code.Get <TextAsset>("Hotfix.dll").bytes;
            byte[] pdbBytes = code.Get <TextAsset>("Hotfix.pdb").bytes;

            using (MemoryStream fs = new MemoryStream(assBytes))
                using (MemoryStream p = new MemoryStream(pdbBytes))
                {
                    this.appDomain.LoadAssembly(fs, p, new Mono.Cecil.Pdb.PdbReaderProvider());
                }

            this.start = new ILStaticMethod(this.appDomain, "ETHotfix.Init", "Start", 0);
#else
            Log.Debug($"当前使用的是Mono模式");
            byte[] assBytes = code.Get <TextAsset>("Hotfix.dll").bytes;
            byte[] pdbBytes = code.Get <TextAsset>("Hotfix.pdb").bytes;
            this.assembly = Assembly.Load(assBytes, pdbBytes);

            Type hotfixInit = this.assembly.GetType("ETHotfix.Init");
            this.start = new MonoStaticMethod(hotfixInit, "Start");
#endif
            Game.Scene.GetComponent <ResourcesComponent>().UnloadBundle($"code.unity3d");
        }
Exemple #2
0
        public void LoadHotfixAssembly()
        {
            TextAsset Hotfix_dll = (TextAsset)Game.Scene.GetComponent <ResourcesComponent>().GetAsset("Hotfix.dll.bytes");
            TextAsset Hotfix_pdb = (TextAsset)Game.Scene.GetComponent <ResourcesComponent>().GetAsset("Hotfix.pdb.bytes");

            byte[] assBytes = Hotfix_dll.bytes;
            byte[] pdbBytes = Hotfix_pdb.bytes;

#if ILRuntime
            Log.Debug($"当前使用的是ILRuntime模式");
            this.appDomain = new ILRuntime.Runtime.Enviorment.AppDomain();

            this.dllStream = new MemoryStream(assBytes);
            this.pdbStream = new MemoryStream(pdbBytes);
            this.appDomain.LoadAssembly(this.dllStream, this.pdbStream, new ILRuntime.Mono.Cecil.Pdb.PdbReaderProvider());

            this.start = new ILStaticMethod(this.appDomain, "ETHotfix.Init", "Start", 0);

            this.hotfixTypes = this.appDomain.LoadedTypes.Values.Select(x => x.ReflectionType).ToList();
#else
            Log.Debug($"当前使用的是Mono模式");

            this.assembly = Assembly.Load(assBytes, pdbBytes);

            Type hotfixInit = this.assembly.GetType("ETHotfix.Init");
            this.start = new MonoStaticMethod(hotfixInit, "Start");

            this.hotfixTypes = this.assembly.GetTypes().ToList();
#endif
        }
        public void LoadHotfixAssembly()
        {
            GameObject code = Game.Scene.GetComponent <ResourcesComponent>().LoadAsset <GameObject>(ABPathUtilities.GetNormalConfigPath("Code"));

            byte[] assBytes = code.GetTargetObjectFromRC <TextAsset>("Hotfix.dll").bytes;
            byte[] pdbBytes = code.GetTargetObjectFromRC <TextAsset>("Hotfix.pdb").bytes;

#if ILRuntime
            Log.Debug($"当前使用的是ILRuntime模式");
            this.appDomain = new ILRuntime.Runtime.Enviorment.AppDomain();

            this.dllStream = new MemoryStream(assBytes);
            this.pdbStream = new MemoryStream(pdbBytes);
            this.appDomain.LoadAssembly(this.dllStream, this.pdbStream, new Mono.Cecil.Pdb.PdbReaderProvider());

            this.start = new ILStaticMethod(this.appDomain, "ETHotfix.Init", "Start", 0);

            this.hotfixTypes = this.appDomain.LoadedTypes.Values.Select(x => x.ReflectionType).ToList();
#else
            Log.Debug($"当前使用的是Mono模式");

            this.assembly = Assembly.Load(assBytes, pdbBytes);

            Type hotfixInit = this.assembly.GetType("ETHotfix.Init");
            this.start = new MonoStaticMethod(hotfixInit, "Start");

            this.hotfixTypes = this.assembly.GetTypes().ToList();
#endif

            Game.Scene.GetComponent <ResourcesComponent>().UnLoadAsset(ABPathUtilities.GetNormalConfigPath("Code"));
        }
Exemple #4
0
        public void LoadHotfixAssembly()
        {
            Game.Scene.GetComponent <ResourcesComponent>().LoadBundle($"code.unity3d");
            GameObject code = (GameObject)Game.Scene.GetComponent <ResourcesComponent>().GetAsset("code.unity3d", "Code");

            byte[] assBytes = code.Get <TextAsset>("Hotfix.dll").bytes;
            byte[] pdbBytes = code.Get <TextAsset>("Hotfix.pdb").bytes;

#if ILRuntime
            Log.Debug($"当前使用的是ILRuntime模式");
            this.appDomain = new ILRuntime.Runtime.Enviorment.AppDomain();

            this.dllStream = new MemoryStream(assBytes);
            this.pdbStream = new MemoryStream(pdbBytes);
            this.appDomain.LoadAssembly(this.dllStream, this.pdbStream, new Mono.Cecil.Pdb.PdbReaderProvider());

            this.start = new ILStaticMethod(this.appDomain, "ETHotfix.Init", "Start", 0);

            this.hotfixTypes = this.appDomain.LoadedTypes.Values.Select(x => x.ReflectionType).ToList();
#else
            Log.Debug($"当前使用的是Mono模式");

            this.assembly = Assembly.Load(assBytes, pdbBytes);

            //Type hotfixInit = this.assembly.GetType("ETHotfix.Init");
            //this.start = new MonoStaticMethod(hotfixInit, "Start");
            // 改为demo的入口
            Type hotfixInit = this.assembly.GetType("ETHotfix.Main");
            this.start = new MonoStaticMethod(hotfixInit, "Start");

            this.hotfixTypes = this.assembly.GetTypes().ToList();
#endif

            Game.Scene.GetComponent <ResourcesComponent>().UnloadBundle($"code.unity3d");
        }
Exemple #5
0
        public void LoadHotfixAssembly()
        {
            AssetRequest assetRequest = Assets.LoadAsset("Assets/Bundles/Independent/Code.prefab", typeof(GameObject));
            GameObject   code         = assetRequest.asset as GameObject;

            byte[] assBytes = code.Get <TextAsset>("Hotfix.dll").bytes;
            byte[] pdbBytes = code.Get <TextAsset>("Hotfix.pdb").bytes;

#if ILRuntime
            Log.Debug($"当前使用的是ILRuntime模式");
            this.appDomain = new ILRuntime.Runtime.Enviorment.AppDomain();

            this.dllStream = new MemoryStream(assBytes);
            this.pdbStream = new MemoryStream(pdbBytes);

            this.appDomain.LoadAssembly(this.dllStream, this.pdbStream, new ILRuntime.Mono.Cecil.Pdb.PdbReaderProvider());

            this.start = new ILStaticMethod(this.appDomain, "ETHotfix.Init", "Start", 0);

            this.hotfixTypes = this.appDomain.LoadedTypes.Values.Select(x => x.ReflectionType).ToList();
#else
            Log.Debug($"当前使用的是Mono模式");

            this.assembly = Assembly.Load(assBytes, pdbBytes);

            Type hotfixInit = this.assembly.GetType("ETHotfix.Init");
            this.start = new MonoStaticMethod(hotfixInit, "Start");

            this.hotfixTypes = this.assembly.GetTypes().ToList();
#endif
            Assets.UnloadAsset(assetRequest);
        }
Exemple #6
0
        public void GotoHotfix()
        {
#if ILRuntime
            Log.Debug($"当前使用的是ILRuntime模式");
            this.start       = new ILStaticMethod(this.appDomain, "ETHotfix.Init", "Start", 0);
            this.hotfixTypes = this.appDomain.LoadedTypes.Values.Select(x => x.ReflectionType).ToList();
#else
            Type hotfixInit = this.assembly.GetType("ETHotfix.Init");
            this.start = new MonoStaticMethod(hotfixInit, "Start");
#endif

            this.start.Run();
        }
Exemple #7
0
        public void LoadHotfixAssembly()
        {
            //         if (Game.Scene == null) return;
            //         if (Game.Scene.GetComponent<ResourcesComponent>() == null) return;
            //await Game.Scene.GetComponent<ResourcesComponent>().LoadBundleAsync($"code.unity3d");

            Game.Scene.GetComponent <ResourcesComponent>().LoadBundle($"code.unity3d");
            GameObject code = (GameObject)Game.Scene.GetComponent <ResourcesComponent>().GetAsset("code.unity3d", "Code");

            byte[] assBytes = code.Get <TextAsset>("Hotfix.dll").bytes;
            byte[] pdbBytes = code.Get <TextAsset>("Hotfix.pdb").bytes;

#if ILRuntime
            //            this.appDomain = new ILRuntime.Runtime.Enviorment.AppDomain();
            //#if ILRuntimeDebug
            //            this.appDomain.DebugService.StartDebugService(56000);
            //#endif
            //            GameObject code = (GameObject)Game.Scene.GetComponent<ResourcesComponent>().GetAsset("code.unity3d", "Code");
            //			byte[] assBytes = code.Get<TextAsset>("Hotfix.dll").bytes;
            //			byte[] mdbBytes = code.Get<TextAsset>("Hotfix.pdb").bytes;

            //			using (MemoryStream fs = new MemoryStream(assBytes))
            //			using (MemoryStream p = new MemoryStream(mdbBytes))
            //			{
            //				this.appDomain.LoadAssembly(fs, p, new Mono.Cecil.Pdb.PdbReaderProvider());
            //			}
            //            ILHelper.InitILRuntime(this.appDomain);
            //            this.start = new ILStaticMethod(this.appDomain, "ETHotfix.Init", "Start", 0);

            Log.Debug($"当前使用的是ILRuntime模式");
            this.appDomain = new ILRuntime.Runtime.Enviorment.AppDomain();

            this.dllStream = new MemoryStream(assBytes);
            this.pdbStream = new MemoryStream(pdbBytes);
            this.appDomain.LoadAssembly(this.dllStream, this.pdbStream, new Mono.Cecil.Pdb.PdbReaderProvider());

            this.start = new ILStaticMethod(this.appDomain, "ETHotfix.Init", "Start", 0);

            this.hotfixTypes = this.appDomain.LoadedTypes.Values.Select(x => x.ReflectionType).ToList();
#else
            this.assembly = Assembly.Load(assBytes, pdbBytes);

            Type hotfixInit = this.assembly.GetType("ETHotfix.Init");
            this.start       = new MonoStaticMethod(hotfixInit, "Start");
            this.hotfixTypes = this.assembly.GetTypes().ToList();
#endif
            Game.Scene.GetComponent <ResourcesComponent>().UnloadBundle($"code.unity3d");
        }
        public void LoadHotfixAssembly()
        {
            byte[] assBytes = ResMgr.LoadDll(@"Assets/Res/Code/Hotfix.dll.bytes");
#if UNITY_EDITOR || DEVELOPMENT_BUILD
            byte[] pdbBytes = ResMgr.LoadDll(@"Assets/Res/Code/Hotfix.pdb.bytes");
            Debug.Log("开发阶段:使用.pdb");
#endif

#if ILRuntime
            Debug.Log($"当前使用的是ILRuntime模式");
            this.appDomain = new ILRuntime.Runtime.Enviorment.AppDomain();

            this.dllStream = new MemoryStream(assBytes);
#if UNITY_EDITOR || DEVELOPMENT_BUILD
            this.pdbStream = new MemoryStream(pdbBytes);
            this.appDomain.LoadAssembly(this.dllStream, this.pdbStream, new ILRuntime.Mono.Cecil.Pdb.PdbReaderProvider());
#else
            this.appDomain.LoadAssembly(this.dllStream, null, new ILRuntime.Mono.Cecil.Pdb.PdbReaderProvider());
#endif
            this.start = new ILStaticMethod(this.appDomain, "ETHotfix.Init", "Start", 0);

            this.hotfixTypes = this.appDomain.LoadedTypes.Values.Select(x => x.ReflectionType).ToList();
#else
            Debug.Log($"当前使用的是Mono模式");
            try
            {
#if UNITY_EDITOR || DEVELOPMENT_BUILD
                this.assembly = Assembly.Load(assBytes, pdbBytes);
#else
                this.assembly = Assembly.Load(assBytes, null);
#endif
            }
            catch (Exception e)
            {
                Debug.LogError("这里报错可能是Mono模式开启了IL2CPP!" + e);
            }
            Type hotfixInit = this.assembly.GetType("ETHotfix.Init");
            this.start = new MonoStaticMethod(hotfixInit, "Start");

            this.hotfixTypes = this.assembly.GetTypes().ToList();
#endif
        }
Exemple #9
0
        public void LoadHotfixAssembly(TextAsset dll, TextAsset pdb)
        {
            Game.Scene.GetComponent <ResourcesComponent>().LoadBundle($"code.unity3d");
            GameObject code = (GameObject)Game.Scene.GetComponent <ResourcesComponent>().GetAsset("code.unity3d", "Code");

            byte[] assBytes = dll.bytes;
            byte[] pdbBytes = pdb.bytes;


            Log.Debug($"当前使用的是Mono模式");

            this.assembly = Assembly.Load(assBytes, pdbBytes);

            Type hotfixInit = this.assembly.GetType("ETHotfix.AdministratorInit");

            this.start = new MonoStaticMethod(hotfixInit, "Start");

            this.hotfixTypes = this.assembly.GetTypes().ToList();

            Game.Hotfix.SetHotfixTypes(this.hotfixTypes);
        }