Exemplo n.º 1
0
    void LoadHotFixAssembly()
    {
        appdomain = new AppDomain();

        pdb = null;

        //编译模式
        if (!Assets.runtimeMode)
        {
            if (File.Exists(dllPath))
            {
                fs = new MemoryStream(DLLMgr.FileToByte(dllPath));
            }
            else
            {
                Log.PrintError("DLL文件不存在");
                return;
            }

            //查看是否有PDB文件
            if (File.Exists(pdbPath) && UsePdb && (File.GetLastWriteTime(dllPath) - File.GetLastWriteTime(pdbPath)).Seconds < 30)
            {
                pdb = new MemoryStream(DLLMgr.FileToByte(pdbPath));
            }
        }
        else//解密加载
        {
            var dllAsset = Assets.LoadAsset("HotUpdateScripts.bytes", typeof(TextAsset));
            if (dllAsset.error != null)
            {
                Log.PrintError(dllAsset.error);
                return;
            }
            var dll = (TextAsset)dllAsset.asset;
            try
            {
                var original = CryptoHelper.AesDecrypt(dll.bytes, Key);
                fs = new MemoryStream(original);
            }
            catch (Exception ex)
            {
                Log.PrintError("加载热更DLL失败,可能是解密密码不正确");
                Log.PrintError("加载热更DLL错误:\n" + ex.Message);
                return;
            }
        }

        try
        {
            appdomain.LoadAssembly(fs, pdb, new PdbReaderProvider());
        }
        catch (Exception e)
        {
            if (!UsePdb)
            {
                Log.PrintError("加载热更DLL失败,请确保HotUpdateResources/Dll里面有HotUpdateScripts.bytes文件,并且Build Bundle后将DLC传入服务器");
                Log.PrintError("加载热更DLL错误:\n" + e.Message);
                return;
            }

            Log.PrintError("PDB不可用,可能是DLL和PDB版本不一致,可能DLL是Release,如果是Release出包,请取消UsePdb选项,本次已跳过使用PDB");
            UsePdb = false;
            LoadHotFixAssembly();
        }

        InitILrt.InitializeILRuntime(appdomain);
        OnHotFixLoaded();
    }
Exemplo n.º 2
0
    void LoadHotFixAssembly()
    {
        appdomain = new AppDomain();

        if (!Assets.runtimeMode)
        {
            DLLMgr.MakeBytes();
        }

        var dllAsset = Assets.LoadAsset("HotUpdateScripts.bytes", typeof(TextAsset));

        if (dllAsset.error != null)
        {
            Log.PrintError(dllAsset.error);
            return;
        }

        var dll = (TextAsset)dllAsset.asset;

        byte[] original = dll.bytes;
        try
        {
            if (!Assets.runtimeMode)
            {
                original = CryptoHelper.AesDecrypt(original, "DevelopmentMode.");
            }
            else
            {
                original = CryptoHelper.AesDecrypt(original, Key);
            }
        }
        catch (Exception ex)
        {
            Log.PrintError("加载热更DLL失败,可能是解密密码不正确");
            Log.PrintError("加载热更DLL错误:\n" + ex.Message);
            return;
        }

        fs = new MemoryStream(original);
        MemoryStream pdb = null;

#if UNITY_EDITOR
        if (File.Exists("Assets/HotUpdateResources/Dll/Hidden~/HotUpdateScripts.pdb"))
        {
            try
            {
                pdb = new MemoryStream(AssetDatabase.LoadAssetAtPath <TextAsset>("Assets/HotUpdateResources/Dll/Hidden~/HotUpdateScripts.pdb").bytes);
            }
            catch
            {
            }
        }
#endif

        try
        {
            appdomain.LoadAssembly(fs, pdb, new PdbReaderProvider());
        }
        catch (Exception e)
        {
            Log.PrintError("加载热更DLL失败,请确保HotUpdateResources/Dll里面有HotUpdateScripts.bytes文件,并且Build Bundle后将DLC传入服务器");
            Log.PrintError("加载热更DLL错误:\n" + e.Message);
            return;
        }


        InitILrt.InitializeILRuntime(appdomain);
        OnHotFixLoaded();
    }
Exemplo n.º 3
0
    void LoadHotFixAssembly()
    {
        Appdomain = new AppDomain();
        _pdb      = null;

        byte[] buffer;

        //开发模式
        #if XASSET_PRO
        if (Assets.development)
        #else
        if (!Assets.runtimeMode)
        #endif
        {
            if (File.Exists(DLLPath))//直接读DLL
            {
                buffer = DLLMgr.FileToByte(DLLPath);

                //模拟加密
                buffer = CryptoHelper.AesEncrypt(buffer, key);
            }
            else
            {
                Log.PrintError("DLL文件不存在");
                return;
            }

            //查看是否有PDB文件
            if (File.Exists(PdbPath) && usePdb && (File.GetLastWriteTime(DLLPath) - File.GetLastWriteTime(PdbPath)).Seconds < 30)
            {
                _pdb = new MemoryStream(DLLMgr.FileToByte(PdbPath));
            }
        }
        else//真机模式解密加载
        {
            var dllAsset = Assets.LoadAsset("HotUpdateScripts.bytes", typeof(TextAsset));
            if (dllAsset.error != null)
            {
                Log.PrintError(dllAsset.error);
                return;
            }
            var dll = (TextAsset)dllAsset.asset;
            buffer = new byte[dll.bytes.Length];
            Array.Copy(dll.bytes, buffer, dll.bytes.Length);
            dllAsset.Release();//释放掉不需要再用的dll
        }
        try
        {
            // var original = CryptoHelper.AesDecrypt(dll.bytes, Key);以前的用法,过时了

            _fs = new JStream(buffer, key);

            /*
             * 如果一定要先解密,可以这样:
             * var original = CryptoHelper.AesDecrypt(dll.bytes, Key);
             * fs = new JStream(original, Key);
             * fs.Encrypted = false;
             */

            Appdomain.LoadAssembly(_fs, _pdb, new PdbReaderProvider());
        }
        catch (Exception e)
        {
            Log.PrintError("加载热更DLL错误:\n" + e);
            if (!usePdb)
            {
                Log.PrintError("加载热更DLL失败,请确保HotUpdateResources/Dll里面有HotUpdateScripts.bytes文件,并且Build Bundle后将DLC传入服务器");
            }
            else
            {
                Log.PrintError("PDB不可用,可能是DLL和PDB版本不一致,可能DLL是Release,如果是Release出包,请取消UsePdb选项,本次已跳过使用PDB");
                usePdb = false;
                LoadHotFixAssembly();
            }
            return;
        }

        Success = true;
        InitILrt.InitializeILRuntime(Appdomain);
    }
Exemplo n.º 4
0
    void LoadHotFixAssembly()
    {
        appdomain = new AppDomain();

        pdb = null;

        //编译模式
        if (!Assets.runtimeMode)
        {
            if (File.Exists("Assets/HotUpdateResources/Dll/Hidden~/HotUpdateScripts.dll"))
            {
                fs = new MemoryStream(DLLMgr.FileToByte("Assets/HotUpdateResources/Dll/Hidden~/HotUpdateScripts.dll"));
            }
            else
            {
                Log.PrintWarning("DLL文件不存在");
                return;
            }

            //查看是否有PDB文件
            if (File.Exists("Assets/HotUpdateResources/Dll/Hidden~/HotUpdateScripts.pdb"))
            {
                pdb = new MemoryStream(DLLMgr.FileToByte("Assets/HotUpdateResources/Dll/Hidden~/HotUpdateScripts.pdb"));
            }
        }
        else//解密加载
        {
            var dllAsset = Assets.LoadAsset("HotUpdateScripts.bytes", typeof(TextAsset));
            if (dllAsset.error != null)
            {
                Log.PrintError(dllAsset.error);
                return;
            }
            var dll = (TextAsset)dllAsset.asset;
            try
            {
                var original = CryptoHelper.AesDecrypt(dll.bytes, Key);
                fs = new MemoryStream(original);
            }
            catch (Exception ex)
            {
                Log.PrintError("加载热更DLL失败,可能是解密密码不正确");
                Log.PrintError("加载热更DLL错误:\n" + ex.Message);
                return;
            }
        }
        try
        {
            appdomain.LoadAssembly(fs, pdb, new PdbReaderProvider());
        }
        catch (Exception e)
        {
            Log.PrintError("加载热更DLL失败,请确保HotUpdateResources/Dll里面有HotUpdateScripts.bytes文件,并且Build Bundle后将DLC传入服务器");
            Log.PrintError("加载热更DLL错误:\n" + e.Message);
            return;
        }


        InitILrt.InitializeILRuntime(appdomain);
        OnHotFixLoaded();
    }