Ejemplo n.º 1
0
        /// <summary>
        /// 加载Hotfix程序集
        /// </summary>
        /// <param name="dllPath"></param>
        /// <param name="isRegisterBindings"></param>
        public static void LoadHotfix(string dllPath, bool isRegisterBindings = true)
        {
            //
            IsRunning = true;
            string pdbPath = dllPath + ".pdb";

            BDebug.Log("DLL加载路径:" + dllPath, "red");
            //
            AppDomain = new AppDomain();
            if (File.Exists(pdbPath))
            {
                //这里的流不能释放,头铁的老哥别试了
                fsDll = new FileStream(dllPath, FileMode.Open, FileAccess.Read);
                fsPdb = new FileStream(pdbPath, FileMode.Open, FileAccess.Read);
                AppDomain.LoadAssembly(fsDll, fsPdb, new PdbReaderProvider());
            }
            else
            {
                //这里的流不能释放,头铁的老哥别试了
                fsDll = new FileStream(dllPath, FileMode.Open, FileAccess.Read);
                AppDomain.LoadAssembly(fsDll);
            }


#if UNITY_EDITOR
            AppDomain.UnityMainThreadID = System.Threading.Thread.CurrentThread.ManagedThreadId;
#endif

            //绑定的初始化
            //ada绑定
            AdapterRegister.RegisterCrossBindingAdaptor(AppDomain);
            //delegate绑定
            ILRuntimeDelegateHelper.Register(AppDomain);
            //值类型绑定
            AppDomain.RegisterValueTypeBinder(typeof(Vector2), new Vector2Binder());
            AppDomain.RegisterValueTypeBinder(typeof(Vector3), new Vector3Binder());
            AppDomain.RegisterValueTypeBinder(typeof(Vector4), new Vector4Binder());
            AppDomain.RegisterValueTypeBinder(typeof(Quaternion), new QuaternionBinder());


            //是否注册各种binding
            if (isRegisterBindings)
            {
                CLRBindings.Initialize(AppDomain);
                CLRManualBindings.Initialize(AppDomain);
                // ILRuntime.Runtime.Generated.PreCLRBuilding.Initialize(AppDomain);
            }

            JsonMapper.RegisterILRuntimeCLRRedirection(AppDomain);


            if (BDLauncher.Inst != null && Config.Inst.Data.IsDebuggerILRuntime)
            {
                AppDomain.DebugService.StartDebugService(56000);
                Debug.Log("热更调试器 准备待命~");
            }

            //
            AppDomain.Invoke("HotfixCheck", "Log", null, null);
        }
Ejemplo n.º 2
0
        public void Init()
        {
            IsHotFix = true;
            using (System.IO.MemoryStream fs = new MemoryStream(HotFixDll.bytes))
            {
                m_Assembly.LoadAssembly(fs);
            }
            m_Assembly.AllowUnboundCLRMethod = true;

            //根据实际情况手动添加几个注册
            m_Assembly.DelegateManager.RegisterMethodDelegate <UnityEngine.GameObject>();

            m_Assembly.DelegateManager.RegisterDelegateConvertor <UnityEngine.Events.UnityAction>((act) =>
            {
                return(new UnityEngine.Events.UnityAction(() =>
                {
                    ((Action)act)();
                }));
            });


            m_Assembly.DelegateManager.RegisterMethodDelegate <CSHotFix.Runtime.Intepreter.ILTypeInstance>();
#if CSHotFixSafe
#else
            LCLFunctionDelegate.Reg(m_Assembly);
            AdapterRegister.RegisterCrossBindingAdaptor(m_Assembly);

            CSHotFix.Runtime.Generated.CLRBindings.Initialize(m_Assembly);
#endif

            string HotFixLoop = "LCL.HotFixLoop";
            m_DllInstance = m_Assembly.Instantiate <IGameHotFixInterface>(HotFixLoop);
            m_DllInstance.Start();
        }
Ejemplo n.º 3
0
    public static void InitScript(object obj)
    {
        CSHotFix.Runtime.Enviorment.AppDomain appDomain = obj as CSHotFix.Runtime.Enviorment.AppDomain;
        //根据实际情况手动添加几个注册
        //appDomain.DelegateManager.RegisterMethodDelegate<UnityEngine.GameObject>();
        //appDomain.DelegateManager.RegisterMethodDelegate<WfPacket>();
        appDomain.DelegateManager.RegisterDelegateConvertor <UnityEngine.Events.UnityAction>((act) =>
        {
            return(new UnityEngine.Events.UnityAction(() =>
            {
                ((Action)act)();
            }));
        });
        appDomain.DelegateManager.RegisterMethodDelegate <CSHotFix.Runtime.Intepreter.ILTypeInstance>();

#if CSHotFixSafe
#else
#if CSHotFix
        LCLFunctionDelegate.Reg(appDomain);
#endif
#endif
        AdapterRegister.RegisterCrossBindingAdaptor(appDomain);
        //单独注册协程
        appDomain.RegisterCrossBindingAdaptor(new CoroutineAdapter());
        //注册值类型
        appDomain.RegisterValueTypeBinder(typeof(Vector3), new Vector3Binder());
        appDomain.RegisterValueTypeBinder(typeof(Quaternion), new QuaternionBinder());
        appDomain.RegisterValueTypeBinder(typeof(Vector2), new Vector2Binder());
    }
Ejemplo n.º 4
0
        /// <summary>
        /// 主工程的绑定
        /// </summary>
        /// <param name="isRegisterBindings"></param>
        static public void Bind(bool isRegisterBindings)
        {
            var AppDomain = BDFramework.ILRuntimeHelper.AppDomain;

            //绑定的初始化
            //ada绑定
            AdapterRegister.RegisterCrossBindingAdaptor(AppDomain);
            //delegate绑定
            ILRuntimeDelegateHelper.Register(AppDomain);
            //值类型绑定
            AppDomain.RegisterValueTypeBinder(typeof(Vector2), new Vector2Binder());
            AppDomain.RegisterValueTypeBinder(typeof(Vector3), new Vector3Binder());
            AppDomain.RegisterValueTypeBinder(typeof(Vector4), new Vector4Binder());
            AppDomain.RegisterValueTypeBinder(typeof(Quaternion), new QuaternionBinder());

            //是否注册各种binding
            if (isRegisterBindings)
            {
                //手动绑定放前
                ManualCLRBindings.Initialize(AppDomain);
                //自动绑定最后
                CLRBindings.Initialize(AppDomain);
                //PreCLRBinding.Initialize(AppDomain);
                BDebug.Log("[ILRuntime] CLR Binding Success!!!");
            }
        }
Ejemplo n.º 5
0
        public static void LoadHotfix(string dllPath, bool isRegisterBindings = true)
        {
            //
            IsRunning = true;
            string pdbPath = dllPath.Replace(".dll", ".pdb");

            BDebug.Log("DLL加载路径:" + dllPath, "red");
            //
            AppDomain = new AppDomain();
            if (File.Exists(pdbPath))
            {
                //这里的流不能释放,头铁的老哥别试了
                fsDll = new FileStream(dllPath, FileMode.Open, FileAccess.Read);
                fsPdb = new FileStream(pdbPath, FileMode.Open, FileAccess.Read);
                AppDomain.LoadAssembly(fsDll, fsPdb, new PdbReaderProvider());
            }
            else
            {
                //这里的流不能释放,头铁的老哥别试了
                fsDll = new FileStream(dllPath, FileMode.Open, FileAccess.Read);
                AppDomain.LoadAssembly(fsDll);
            }


            //绑定的初始化
            //ada绑定
            AdapterRegister.RegisterCrossBindingAdaptor(AppDomain);
            //delegate绑定
            ILRuntimeDelegateHelper.Register(AppDomain);
            //值类型绑定
            AppDomain.RegisterValueTypeBinder(typeof(Vector2), new Vector2Binder());
            AppDomain.RegisterValueTypeBinder(typeof(Vector3), new Vector3Binder());
            AppDomain.RegisterValueTypeBinder(typeof(Vector4), new Vector4Binder());
            AppDomain.RegisterValueTypeBinder(typeof(Quaternion), new QuaternionBinder());



            //是否注册各种binding
            if (isRegisterBindings)
            {
                ILRuntime.Runtime.Generated.CLRBindings.Initialize(AppDomain);
                ILRuntime.Runtime.Generated.CLRManualBindings.Initialize(AppDomain);
                // ILRuntime.Runtime.Generated.PreCLRBuilding.Initialize(AppDomain);
            }

            JsonMapper.RegisterILRuntimeCLRRedirection(AppDomain);


            if (Application.isEditor)
            {
                AppDomain.DebugService.StartDebugService(56000);
                Debug.Log("热更调试器 准备待命~");
            }

            //
            AppDomain.Invoke("HotfixCheck", "Log", null, null);
        }
Ejemplo n.º 6
0
        public static void LoadHotfix(string root)
        {
            if (AppDomain != null)
            {
                //AppDomain.FreeILIntepreter(AppDomain.);
            }

            //
            IsRunning = true;
            string dllPath = root + "/" + Utils.GetPlatformPath(Application.platform) + "/hotfix/hotfix.dll";
            string pdbPath = root + "/" + Utils.GetPlatformPath(Application.platform) + "/hotfix/hotfix.pdb";

            BDebug.Log("DLL加载路径:" + dllPath, "red");
            //
            AppDomain = new AppDomain();
            if (File.Exists(pdbPath))
            {
                var dllfs = File.ReadAllBytes(dllPath);
                var pdbfs = File.ReadAllBytes(pdbPath);
                using (MemoryStream dll = new MemoryStream(dllfs))
                {
                    using (MemoryStream pdb = new MemoryStream(pdbfs))
                    {
                        AppDomain.LoadAssembly(dll, pdb, new PdbReaderProvider());
                    }
                }
            }
            else
            {
                UnityWebRequest request;
                using (System.IO.FileStream fs = new System.IO.FileStream(dllPath, FileMode.Open, FileAccess.Read))
                {
                    AppDomain.LoadAssembly(fs);
                }
            }


            //绑定的初始化
            AdapterRegister.RegisterCrossBindingAdaptor(AppDomain);
            ILRuntime.Runtime.Generated.CLRBindings.Initialize(AppDomain);
            ILRuntime.Runtime.Generated.CLRManualBindings.Initialize(AppDomain);
//          ILRuntime.Runtime.Generated.PreCLRBuilding.Initialize(AppDomain);
            //
            ILRuntimeDelegateHelper.Register(AppDomain);
            JsonMapper.RegisterILRuntimeCLRRedirection(AppDomain);
            if (Application.isEditor)
            {
                AppDomain.DebugService.StartDebugService(56000);
                Debug.Log("热更调试器 准备待命~");
            }
            //
            AppDomain.Invoke("HotfixCheck", "Log", null, null);
        }
Ejemplo n.º 7
0
        public static void LoadHotfix(bool isLoadPdb)
        {
            string dllPath = "hotfix/hotfix.dll";
            string pdbPath = "hotfix/hotfix.pdb";

            IsRunning = true;
          #if UNITY_EDITOR
            dllPath = Path.Combine(Application.streamingAssetsPath, dllPath);
            pdbPath = Path.Combine(Application.streamingAssetsPath, pdbPath);
          #elif UNITY_IPHONE || UNITY_ANDROID
            dllPath = Path.Combine(Application.persistentDataPath, dllPath);
            pdbPath = Path.Combine(Application.persistentDataPath, pdbPath);
          #endif



            AppDomain = new AppDomain();
            if (isLoadPdb)
            {
                var dllfs = File.ReadAllBytes(dllPath);
                var pdbfs = File.ReadAllBytes(pdbPath);
                using (MemoryStream dll = new MemoryStream(dllfs))
                {
                    using (MemoryStream pdb = new MemoryStream(pdbfs))
                    {
                        AppDomain.LoadAssembly(dll, pdb, new PdbReaderProvider());
                    }
                }
            }
            else
            {
                using (System.IO.FileStream fs = new System.IO.FileStream(dllPath, FileMode.Open, FileAccess.Read))
                {
                    AppDomain.LoadAssembly(fs);
                }
            }


            //绑定的初始化
            AdapterRegister.RegisterCrossBindingAdaptor(AppDomain);
            ILRuntime.Runtime.Generated.CLRBindings.Initialize(AppDomain);
            ILRuntime.Runtime.Generated.CLRManualBindings.Initialize(AppDomain);
            //
            ILRuntimeDelegateHelper.Register(AppDomain);
            JsonMapper.RegisterILRuntimeCLRRedirection(AppDomain);
            if (Application.isEditor)
            {
                AppDomain.DebugService.StartDebugService(56000);
                Debug.Log("热更调试器 准备待命~");
            }
            //
            AppDomain.Invoke("HotfixCheck", "Log", null, null);
        }
Ejemplo n.º 8
0
        public static void LoadHotfix(string root, bool isRegisterBindings = true)
        {
            //
            IsRunning = true;
            string dllPath = root + "/" + Utils.GetPlatformPath(Application.platform) + "/hotfix/hotfix.dll";
            string pdbPath = root + "/" + Utils.GetPlatformPath(Application.platform) + "/hotfix/hotfix.pdb";

            BDebug.Log("DLL加载路径:" + dllPath, "red");
            //
            AppDomain = new AppDomain();
            if (File.Exists(pdbPath))
            {
                //这里的流不能释放,头铁的老哥别试了
                fsDll = new FileStream(dllPath, FileMode.Open, FileAccess.Read);
                fsPdb = new FileStream(pdbPath, FileMode.Open, FileAccess.Read);
                AppDomain.LoadAssembly(fsDll, fsPdb, new PdbReaderProvider());
            }
            else
            {
                //这里的流不能释放,头铁的老哥别试了
                fsDll = new FileStream(dllPath, FileMode.Open, FileAccess.Read);
                AppDomain.LoadAssembly(fsDll);
            }



            //绑定的初始化
            AdapterRegister.RegisterCrossBindingAdaptor(AppDomain);
            ILRuntimeDelegateHelper.Register(AppDomain);
            //是否注册各种binding
            if (isRegisterBindings)
            {
                ILRuntime.Runtime.Generated.CLRBindings.Initialize(AppDomain);
                ILRuntime.Runtime.Generated.CLRManualBindings.Initialize(AppDomain);
                //          ILRuntime.Runtime.Generated.PreCLRBuilding.Initialize(AppDomain);
            }
            JsonMapper.RegisterILRuntimeCLRRedirection(AppDomain);


            if (Application.isEditor)
            {
                AppDomain.DebugService.StartDebugService(56000);
                Debug.Log("热更调试器 准备待命~");
            }

            //
            AppDomain.Invoke("HotfixCheck", "Log", null, null);
        }