//methods private void onLogicDllLoaded(byte[] dllBytes, byte[] pdbBytes, bool isForEditor) { if (_app == null) { _app = new ILRuntime.Runtime.Enviorment.AppDomain(); } //发布 if (pdbBytes == null) { _app.LoadAssembly(new MemoryStream(dllBytes)); } //调试 else { _app.LoadAssembly(new MemoryStream(dllBytes), new MemoryStream(pdbBytes), new ILRuntime.Mono.Cecil.Pdb.PdbReaderProvider()); } //初始化 GameC.ILRuntime.initILRuntime(_app); string mName = isForEditor ? "mainForEditor" : "main"; //调用 _app.Invoke("HGameApp", mName, null, null); if (!isForEditor) { _stepTool.completeStep(LoadGame); } }
private async Task loadAssembly(AssemblyAndSymbolPath path) { if (m_LoadedAssemblies.TryGetValue(path.AssemblyPath, out var _assembly)) { _assembly.Dispose(); m_LoadedAssemblies.Remove(path.AssemblyPath); } if (m_LoadedSymbols.TryGetValue(path.SymbolPath, out var _symbol)) { _symbol.Dispose(); m_LoadedSymbols.Remove(path.SymbolPath); } var assembly_textasset = await m_Assets.LoadAsync <TextAsset>(path.AssemblyPath); var assembly_stream = new MemoryStream(assembly_textasset.bytes); m_Assets.Release(assembly_textasset); MemoryStream symbol_stream = null; if (this.LoadSymbol) { try { var symbol_textasset = await m_Assets.LoadAsync <TextAsset>(path.SymbolPath); symbol_stream = new MemoryStream(symbol_textasset.bytes); m_Assets.Release(symbol_textasset); } catch { } } m_LoadedAssemblies.Add(path.AssemblyPath, assembly_stream); if (this.LoadSymbol) { if (symbol_stream != null) { m_LoadedSymbols.Add(path.SymbolPath, symbol_stream); } else { Debug.LogWarning($"[{XILConst.ServiceName}] Load symbol file failed: {path.SymbolPath}"); } } if (this.LoadSymbol && symbol_stream != null) { m_AppDomain.LoadAssembly(assembly_stream, symbol_stream, new PdbReaderProvider()); } else { m_AppDomain.LoadAssembly(assembly_stream); } }
/// <summary> 加载HotfixDll</summary> public IEnumerator LoadHotfixDll() { appdomain = new ILRuntime.Runtime.Enviorment.AppDomain(); //PDB文件是调试数据库,如需要在日志中显示报错的行号,则必须提供PDB文件,不过由于会额外耗用内存,正式发布时请将PDB去掉,下面LoadAssembly的时候pdb传null即可 using (UnityWebRequest dllRequest = UnityWebRequest.Get(Path.Combine(local, hotfixdllName))) { yield return(dllRequest.SendWebRequest()); //如果不是完成状态 if (dllRequest.result != UnityWebRequest.Result.Success) { Debug.LogError("未加载到热更dll"); } else { fs = new MemoryStream(dllRequest.downloadHandler.data); if (isDebug) { using (UnityWebRequest pdbRequest = UnityWebRequest.Get(Path.Combine(local, hotfixpdbName))) { yield return(pdbRequest.SendWebRequest()); if (pdbRequest.result != UnityWebRequest.Result.Success) { Debug.LogError("未加载到pdb调试数据库"); } p = new MemoryStream(pdbRequest.downloadHandler.data); } } } try { if (isDebug) { appdomain.LoadAssembly(fs, p, new ILRuntime.Mono.Cecil.Pdb.PdbReaderProvider()); } else { appdomain.LoadAssembly(fs, null, null); } } catch (Exception e) { Debug.LogError($"appdomain LoadAssembly Error:{e.Message}"); } InitializeILRuntime(); OnHotFixLoaded(); } }
void LoadHotFixAssembly() { appdomain = new ILRuntime.Runtime.Enviorment.AppDomain(); if (LocalTest) { var dll = FileToByte("Assets/HotUpdateResources/Dll/HotUpdateScripts.dll"); fs = new MemoryStream(dll); try { appdomain.LoadAssembly(fs, null, new ILRuntime.Mono.Cecil.Pdb.PdbReaderProvider()); } catch (Exception e) { Log.PrintError("加载热更DLL失败,请确保HotUpdateResources/Dll里面有HotUpdateScripts.bytes文件,并且Build Bundle后将DLC传入服务器"); } InitializeILRuntime(); OnHotFixLoaded(); } else { var dllAsset = Assets.LoadAssetAsync("HotUpdateScripts.bytes", typeof(TextAsset)); dllAsset.completed += delegate { if (dllAsset.error != null) { Log.PrintError(dllAsset.error); return; } var dll = (TextAsset)dllAsset.asset; fs = new MemoryStream(dll.bytes); try { appdomain.LoadAssembly(fs, null, new ILRuntime.Mono.Cecil.Pdb.PdbReaderProvider()); } catch (Exception e) { Log.PrintError("加载热更DLL失败,请确保HotUpdateResources/Dll里面有HotUpdateScripts.bytes文件,并且Build Bundle后将DLC传入服务器"); } InitializeILRuntime(); OnHotFixLoaded(); }; } }
public IlRuntime(byte[] dat) { _app = new ILRuntime.Runtime.Enviorment.AppDomain(); RegDelegate(); MemoryStream m = new MemoryStream(dat); _app.LoadAssembly(m); RegAdaptor(); mainScript = _app.GetType("Main") as ILType; mStart = mainScript.GetMethod("Start"); mUpdate = mainScript.GetMethod("Update"); mShow = mainScript.GetMethod("Show"); mCmd = mainScript.GetMethod("Cmd"); mUpdateData = mainScript.GetMethod("UpdateData"); mResize = mainScript.GetMethod("Resize"); mChangeLanguage = mainScript.GetMethod("ChangeLanguage"); mDispose = mainScript.GetMethod("Dispose"); if (mStart != null) { try { _app.Invoke(mainScript.FullName, mStart.Name, mainScript); } catch (Exception ex) { Debug.Log(ex.StackTrace); } } }
IEnumerator LoadAssembly() { appDomain = new ILRuntime.Runtime.Enviorment.AppDomain(); WWW www = new WWW("file:///" + Application.streamingAssetsPath + "/ILRuntimeHotfixTest.dll"); while (!www.isDone) { yield return(null); } if (!string.IsNullOrEmpty(www.error)) { Debug.Log(www.error); } byte[] dll = www.bytes; www.Dispose(); using (System.IO.MemoryStream fs = new MemoryStream(dll)) { appDomain.LoadAssembly(fs, null, new Mono.Cecil.Pdb.PdbReaderProvider()); } InitializeILRuntime(); OnHotFixLoaded(); }
IEnumerator LoadHotFixAssembly() { //首先实例化ILRuntime的AppDomain,AppDomain是一个应用程序域,每个AppDomain都是一个独立的沙盒 appdomain = new AppDomain(); //正常项目中应该是自行从其他地方下载dll,或者打包在AssetBundle中读取,平时开发以及为了演示方便直接从StreammingAssets中读取, //正式发布的时候需要大家自行从其他地方读取dll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! //这个DLL文件是直接编译HotFix_Project.sln生成的,已经在项目中设置好输出目录为StreamingAssets,在VS里直接编译即可生成到对应目录,无需手动拷贝 #if UNITY_ANDROID WWW www = new WWW(Application.streamingAssetsPath + "/HotFix_Project.dll"); #else WWW www = new WWW("file:///" + Application.streamingAssetsPath + "/HotFix_Project.dll"); #endif yield return(www); if (!string.IsNullOrEmpty(www.error)) { UnityEngine.Debug.LogError(www.error); } byte[] dll = www.bytes; www.Dispose(); using (System.IO.MemoryStream fs = new MemoryStream(dll)) { appdomain.LoadAssembly(fs, null, null); } InitializeILRuntime(); OnHotFixLoaded(); }
private void btnGenerateBinding_Click(object sender, EventArgs e) { /*List<Type> types = new List<Type>(); * types.Add(typeof(int)); * types.Add(typeof(float)); * types.Add(typeof(long)); * types.Add(typeof(object)); * types.Add(typeof(string)); * types.Add(typeof(ValueType)); * types.Add(typeof(Console)); * types.Add(typeof(Array)); * types.Add(typeof(Dictionary<string, int>)); * types.Add(typeof(Dictionary<ILRuntime.Runtime.Intepreter.ILTypeInstance, int>)); * types.Add(typeof(TestFramework.TestStruct)); * ILRuntime.Runtime.CLRBinding.BindingCodeGenerator.GenerateBindingCode(types, "..\\..\\AutoGenerate");*/ ILRuntime.Runtime.Enviorment.AppDomain domain = new ILRuntime.Runtime.Enviorment.AppDomain(); using (FileStream fs = new FileStream(txtPath.Text, FileMode.Open, FileAccess.Read)) { domain.LoadAssembly(fs); //Crossbind Adapter is needed to generate the correct binding code ILRuntimeHelper.Init(domain); string outputPath = ".." + Path.DirectorySeparatorChar + ".." + Path.DirectorySeparatorChar + "AutoGenerate"; // "..\\..\\AutoGenerate" ILRuntime.Runtime.CLRBinding.BindingCodeGenerator.GenerateBindingCode(domain, outputPath); } }
private void load_game() { #if UNITY_EDITOR data_path = Application.streamingAssetsPath; #elif UNITY_ANDROID data_path = Application.temporaryCachePath; #elif UNITY_IOS data_path = Application.temporaryCachePath; #endif Debug.Log("开始加载游戏:" + data_path); //===加载热更新代码=== appdomain = new ILRuntime.Runtime.Enviorment.AppDomain(); //appdomain.UnityMainThreadID = Thread.CurrentThread.ManagedThreadId;//调试 string dll_path = string.Format("{0}/{1}", data_path, "HotFix_Project.dll"); byte[] dll = File.ReadAllBytes(dll_path); string dll_pdb_path = string.Format("{0}/{1}", data_path, "HotFix_Project.pdb"); byte[] pdb = File.ReadAllBytes(dll_pdb_path); using (System.IO.MemoryStream fs = new MemoryStream(dll)) { using (System.IO.MemoryStream p = new MemoryStream(pdb)) { appdomain.LoadAssembly(fs, p, new Mono.Cecil.Pdb.PdbReaderProvider()); } } //此处调用初始化 InitializeILRuntime(); //ILRuntime.Runtime.Generated.CLRBindings.Initialize(appdomain); Assets.CommGen.Initialize(appdomain); OnHotFixLoaded(); Debug.Log("启动完成"); }
public void Init() { using (System.IO.MemoryStream fs = new MemoryStream(HotFixDll.bytes)) { m_AssemblyILR.LoadAssembly(fs); } m_AssemblyILR.AllowUnboundCLRMethod = true; ILRuntime.Runtime.Enviorment.AppDomain.ShowDebugInfo = false; //注册跨域类 m_AssemblyILR.RegisterCrossBindingAdaptor(new IGameHotFixInterfaceAdapter()); m_AssemblyILR.DelegateManager.RegisterMethodDelegate <UnityEngine.GameObject>(); m_AssemblyILR.DelegateManager.RegisterMethodDelegate <System.Int32>(); m_AssemblyILR.DelegateManager.RegisterMethodDelegate <System.Boolean>(); m_AssemblyILR.DelegateManager.RegisterMethodDelegate <ILRuntime.Runtime.Intepreter.ILTypeInstance>(); m_AssemblyILR.DelegateManager.RegisterMethodDelegate <System.Int32, System.Int32>(); m_AssemblyILR.DelegateManager.RegisterMethodDelegate <System.Object>(); LCLFunctionDelegate.Reg(m_AssemblyILR); ILRuntime.Runtime.Generated.CLRBindings.Initialize(m_AssemblyILR); string HotFixLoop = "LCL.HotFixLoop"; m_HotFixDll = m_AssemblyILR.Instantiate <IGameHotFixInterface>(HotFixLoop); m_HotFixDll.Start(); }
public void Init() { //首先实例化ILRuntime的AppDomain,AppDomain是一个应用程序域,每个AppDomain都是一个独立的沙盒 appDomain = new AppDomain(); byte[] dll = null; using (WWW www = new WWW(PathTools.ILRuntimeDLL)) { while (!www.isDone || www.error != null) { } if (www.error != null) { Debug.LogError(www.error); } dll = www.bytes; } if (dll != null) { using (System.IO.MemoryStream ms = new System.IO.MemoryStream(dll)) { appDomain.LoadAssembly(ms, null, null); } } InitializeILRuntime(); OnHotFixLoaded(); }
private Coroutine LoadHotFix_Device() { #if USE_IL2CPP //热更代码合入主工程了 this.assembly = Assembly.GetExecutingAssembly(); onHotFixLoaded?.Invoke(); onHotFixLoaded = null; EB.Debug.Log("LoadHotFix_Device Finish!"); IsInit = true; return(null); #else return(EB.Assets.LoadAsyncAndInit <TextAsset>("Hotfix_LT", (assetName, ta, succ) => { if (ta != null) { EB.Debug.Log("LoadHotFix_Device Success!"); if (appdomain == null) { appdomain = new ILRuntime.Runtime.Enviorment.AppDomain(); } System.IO.MemoryStream fs = new MemoryStream(ta.bytes); appdomain.LoadAssembly(fs, null, null); #if ILRuntime InitializeILRuntime(appdomain); #else this.assembly = Assembly.Load(ta.bytes, null); #endif onHotFixLoaded?.Invoke(); onHotFixLoaded = null; EB.Debug.Log("LoadHotFix_Device Finish!"); IsInit = true; } }, GameEngine.Instance.gameObject, null, false)); #endif }
public static void GenerateCLRBindingByAnalysis() { //GenerateCLRBinding(); //用新的分析热更dll调用引用来生成绑定代码 ILRuntime.Runtime.Enviorment.AppDomain appdomain = new ILRuntime.Runtime.Enviorment.AppDomain(); string path = Application.dataPath.Replace("Assets", "/Library/ScriptAssemblies/hotfix.dll"); if (!File.Exists(path)) { Debug.LogError("需要先创建dll(描述文件) 然后编译完后再来生成!"); //需要先创建dll 然后编译完后再来生成 //DllTools.CreateDll(); } using (FileStream fs = new FileStream("Assets/../Library/ScriptAssemblies/hotfix.dll", FileMode.Open, FileAccess.Read)) { appdomain.LoadAssembly(fs); ILAdaptor.RegisterAdaptor(appdomain); //跨域继承适配器的注册 ILDelegate.RegisterDelegate(appdomain); //委托适配器 LitJson.JsonMapper.RegisterILRuntimeCLRRedirection(appdomain); //LitJson重定向 ILRuntime.Runtime.CLRBinding.BindingCodeGenerator.GenerateBindingCode(appdomain, "Assets/Script/Main/ILBinding"); AssetDatabase.Refresh(); } }
public void DoLoadDll(string dll, byte[] dllBytes, byte[] pdbBytes = null) { if (loadedDlls.Contains(dll)) { return; } loadedDlls.Add(dll); MemoryStream pdb = null; #if UNITY_EDITOR if (pdbBytes != null) { pdb = new MemoryStream(pdbBytes); } #endif System.IO.MemoryStream fs = new MemoryStream(dllBytes); { Debug.Log($"load dll {dllBytes != null}, load pdb {pdbBytes != null}"); #if ILRUNTIME appdomain.LoadAssembly(fs, pdb, new ILRuntime.Mono.Cecil.Pdb.PdbReaderProvider()); #else assembly = AppDomain.CurrentDomain.Load(dllBytes, pdbBytes); #endif } }
void LoadHotFixAssembly2(byte[] dll, byte[] pdb) { appdomain = new ILRuntime.Runtime.Enviorment.AppDomain(); fs = new MemoryStream(dll); p = new MemoryStream(pdb); try { appdomain.LoadAssembly(fs, p, new ILRuntime.Mono.Cecil.Pdb.PdbReaderProvider()); } catch { Debug.LogError("加载热更DLL失败,请确保已经通过VS打开Assets/Samples/ILRuntime/1.6/Demo/HotFix_Project/HotFix_Project.sln编译过热更DLL"); } InitializeILRuntime(); OnDllLoaded(); if (OnAssemblyLoadOver != null) { OnAssemblyLoadOver(); } MessageDispatcher.SendMessage("GeneralDllBehaviorAwake"); }
private void LoadAssemblyScript(string assemblyName) { Debuger.Log(assemblyName); string dllPath = FindAssemblyFullPath(assemblyName); if (string.IsNullOrEmpty(dllPath)) { Debuger.LogError("Assembly不存在:{0}", assemblyName); return; } byte[] dllBytes = FileUtils.ReadFile(dllPath); byte[] pdbBytes = null; if (UsePdb) { pdbBytes = FileUtils.ReadFile(GetPdbPath(dllPath)); } try { using (MemoryStream dll = new MemoryStream(dllBytes)) { if (pdbBytes != null) { using (MemoryStream pdb = new MemoryStream(pdbBytes)) { Debuger.Log("LoadAssembly"); m_appdomain.LoadAssembly(dll, pdb, new PdbReaderProvider()); } } else { Debuger.Log("LoadAssembly"); m_appdomain.LoadAssembly(dll, null, null); } } } catch (Exception e) { Debuger.LogError(e.Message); } }
public void Load(byte[] assBytes, byte[] pdbBytes) { appDomain = new ILRuntime.Runtime.Enviorment.AppDomain(); dllStream = new MemoryStream(assBytes); pdbStream = new MemoryStream(pdbBytes); appDomain.LoadAssembly(dllStream, pdbStream, new Mono.Cecil.Pdb.PdbReaderProvider()); Debug.Log($"当前使用的是ILRuntime模式"); }
IEnumerator LoadHotFixAssembly() { //首先实例化ILRuntime的AppDomain,AppDomain是一个应用程序域,每个AppDomain都是一个独立的沙盒 appdomain = new ILRuntime.Runtime.Enviorment.AppDomain(); //正常项目中应该是自行从其他地方下载dll,或者打包在AssetBundle中读取,平时开发以及为了演示方便直接从StreammingAssets中读取, //正式发布的时候需要大家自行从其他地方读取dll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! //这个DLL文件是直接编译HotFix_Project.sln生成的,已经在项目中设置好输出目录为StreamingAssets,在VS里直接编译即可生成到对应目录,无需手动拷贝 //工程目录在Assets\Samples\ILRuntime\1.6\Demo\HotFix_Project~ //以下加载写法只为演示,并没有处理在编辑器切换到Android平台的读取,需要自行修改 #if UNITY_ANDROID WWW www = new WWW(Application.streamingAssetsPath + "/HotFix_Project.dll"); #else //WWW www = new WWW("file:///" + Application.streamingAssetsPath + "/HotFix_Project.dll"); WWW www = new WWW(HOT_UPDATE_DLL_DIR + "HotUpdate.dll"); #endif while (!www.isDone) { yield return(null); } if (!string.IsNullOrEmpty(www.error)) { UnityEngine.Debug.LogError(www.error); } byte[] dll = www.bytes; www.Dispose(); //PDB文件是调试数据库,如需要在日志中显示报错的行号,则必须提供PDB文件,不过由于会额外耗用内存,正式发布时请将PDB去掉,下面LoadAssembly的时候pdb传null即可 #if UNITY_ANDROID www = new WWW(Application.streamingAssetsPath + "/HotFix_Project.pdb"); #else //www = new WWW("file:///" + Application.streamingAssetsPath + "/HotFix_Project.pdb"); www = new WWW(HOT_UPDATE_DLL_DIR + "HotUpdate.pdb"); #endif while (!www.isDone) { yield return(null); } if (!string.IsNullOrEmpty(www.error)) { UnityEngine.Debug.LogError(www.error); } byte[] pdb = www.bytes; fs = new MemoryStream(dll); p = new MemoryStream(pdb); try { appdomain.LoadAssembly(fs, p, new ILRuntime.Mono.Cecil.Pdb.PdbReaderProvider()); } catch { Debug.LogError("加载热更DLL失败,请确保已经通过VS打开Assets/Samples/ILRuntime/1.6/Demo/HotFix_Project/HotFix_Project.sln编译过热更DLL"); } InitializeILRuntime(); OnHotFixLoaded(); }
private void OnBtnLoad(object sender, EventArgs e) { if (txtPath.Text == "") { if (OD.ShowDialog() == DialogResult.OK) { Properties.Settings.Default["assembly_path"] = txtPath.Text = OD.FileName; Properties.Settings.Default.Save(); } else { return; } } try { using (FileStream fs = new FileStream(txtPath.Text, FileMode.Open, FileAccess.Read)) { var path = Path.GetDirectoryName(txtPath.Text); var name = Path.GetFileNameWithoutExtension(txtPath.Text); var pdbPath = Path.Combine(path, name) + ".pdb"; if (!File.Exists(pdbPath)) { name = Path.GetFileName(txtPath.Text); pdbPath = Path.Combine(path, name) + ".mdb"; } using (var fs2 = new System.IO.FileStream(pdbPath, FileMode.Open)) { Mono.Cecil.Cil.ISymbolReaderProvider symbolReaderProvider = null; if (pdbPath.EndsWith(".pdb")) { symbolReaderProvider = new Mono.Cecil.Pdb.PdbReaderProvider(); } else if (pdbPath.EndsWith(".mdb")) { symbolReaderProvider = new Mono.Cecil.Mdb.MdbReaderProvider(); } _app.LoadAssembly(fs, fs2, symbolReaderProvider); _isLoadAssembly = true; } ILRuntimeHelper.Init(_app); ILRuntime.Runtime.Generated.CLRBindings.Initialize(_app); LoadTest(); UpdateBtnState(); } } catch (Exception ex) { MessageBox.Show("[Error:]" + ex); } }
/// <summary> /// 加载热更工程,这里是技术尝试demo,所以特别简单,直接从嵌入资源里加载了 /// </summary> /// <returns></returns> private async Task LoadAssemblies() { var asm = IntrospectionExtensions.GetTypeInfo(typeof(HotUpdateService)).Assembly; var resources = asm.GetManifestResourceNames(); Stream stream_dll = asm.GetManifestResourceStream("XFApp.HotDlls.XFApp.HotUpdate.dll.bytes"); Stream stream_pdb = asm.GetManifestResourceStream("XFApp.HotDlls.XFApp.HotUpdate.pdb.bytes"); m_AppDomain.LoadAssembly(stream_dll, stream_pdb, new PdbReaderProvider()); await Task.CompletedTask; }
IEnumerator LoadHotFixAssembly(string dllName, Action action) { //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! //这个DLL文件是直接编译HotFix_Project.sln生成的,已经在项目中设置好输出目录为StreamingAssets,在VS里直接编译即可生成到对应目录,无需手动拷贝 #if UNITY_ANDROID WWW www = new WWW(Application.streamingAssetsPath + "/HotFix_Project.dll"); #else //string path = string.Format("file:///{0}/StreamingAssets/{1}.dll", Application.dataPath, dllName); string path = string.Format("file:///{0}/../../HotFix_Project/lib/{1}.dll", Application.dataPath, dllName); WWW www = new WWW(path); #endif while (!www.isDone) { yield return(null); } if (!string.IsNullOrEmpty(www.error)) { Debug.LogError(www.error); } byte[] dll = www.bytes; www.Dispose(); //PDB文件是调试数据库,如需要在日志中显示报错的行号,则必须提供PDB文件,不过由于会额外耗用内存,正式发布时请将PDB去掉,下面LoadAssembly的时候pdb传null即可 #if UNITY_ANDROID www = new WWW(Application.streamingAssetsPath + "/HotFix_Project.pdb"); #else //path = string.Format("file:///{0}/StreamingAssets/{1}.pdb", Application.dataPath, dllName); path = string.Format("file:///{0}/../../HotFix_Project/lib/{1}.pdb", Application.dataPath, dllName); www = new WWW(path); #endif while (!www.isDone) { yield return(null); } if (!string.IsNullOrEmpty(www.error)) { Debug.LogError(www.error); } byte[] pdb = www.bytes; www.Dispose(); using (MemoryStream fs = new MemoryStream(dll)) { using (MemoryStream p = new MemoryStream(pdb)) { appdomain.LoadAssembly(fs, null, new Mono.Cecil.Pdb.PdbReaderProvider()); } } if (null != action) { action.Invoke(); } }
void LoadHotFixAssembly() { appdomain = new AppDomain(); var dllAsset = Assets.LoadAssetAsync("HotUpdateScripts.bytes", typeof(TextAsset)); dllAsset.completed += delegate { 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); try { appdomain.LoadAssembly(fs, null, new PdbReaderProvider()); } catch (Exception e) { Log.PrintError("加载热更DLL失败,请确保HotUpdateResources/Dll里面有HotUpdateScripts.bytes文件,并且Build Bundle后将DLC传入服务器"); Log.PrintError("加载热更DLL错误:\n" + e.Message); return; } InitializeILRuntime(); OnHotFixLoaded(); }; }
public void BuildCLRBinding() { AppDomain appDomain = new AppDomain(); using (MemoryStream dll = new MemoryStream(RijndaelUtil.RijndaelDecrypt("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", FileUtil.GetAsset("Assets/Resources/DLL/Unity.Hotfix.dll.bytes")))) { appDomain.LoadAssembly(dll); ILRuntimeUtil.LccFrameworkRegisterCrossBindingAdaptor(appDomain); BindingCodeGenerator.GenerateBindingCode(appDomain, "Assets/Scripts/Runtime/Core/Manager/ILRuntime/Generated"); } AssetDatabase.Refresh(); }
static void GenerateCLRBindingByAnalysis() { //用新的分析热更dll调用引用来生成绑定代码 ILRuntime.Runtime.Enviorment.AppDomain domain = new ILRuntime.Runtime.Enviorment.AppDomain(); using (System.IO.FileStream fs = new System.IO.FileStream("Assets/StreamingAssets/HotFix_Project.dll", System.IO.FileMode.Open, System.IO.FileAccess.Read)) { domain.LoadAssembly(fs); } //Crossbind Adapter is needed to generate the correct binding code InitILRuntime(domain); ILRuntime.Runtime.CLRBinding.BindingCodeGenerator.GenerateBindingCode(domain, "Assets/ILRuntime/Generated"); }
void LoadHotFixDll() { //整个工程只有一个ILRuntime的AppDomain m_AppDomain = new ILRuntime.Runtime.Enviorment.AppDomain(); //读取热更资源的dll TextAsset dllText = ResourceManager.Instance.LoadResource <TextAsset>(DLLPATH); MemoryStream ms = new MemoryStream(dllText.bytes); m_AppDomain.LoadAssembly(ms, null, new ILRuntime.Mono.Cecil.Pdb.PdbReaderProvider()); InitializeIlRuntime(); OnHotFixLoaded(); }
static void GenerateCLRBindingByAnalysis() { //用新的分析热更dll调用引用来生成绑定代码 ILRuntime.Runtime.Enviorment.AppDomain domain = new ILRuntime.Runtime.Enviorment.AppDomain(); using (System.IO.FileStream fs = new System.IO.FileStream("Assets/Game/Knight/GameAsset/Hotfix/Libs/KnightHotfixModule.bytes", System.IO.FileMode.Open, System.IO.FileAccess.Read)) { domain.LoadAssembly(fs); } //Crossbind Adapter is needed to generate the correct binding code InitILRuntime(domain); ILRuntime.Runtime.CLRBinding.BindingCodeGenerator.GenerateBindingCode(domain, "Assets/Generate/ILRuntime"); }
public override IEnumerator Init(System.Action onDone) { //首先实例化ILRuntime的AppDomain,AppDomain是一个应用程序域,每个AppDomain都是一个独立的沙盒 appdomain = new ILRuntime.Runtime.Enviorment.AppDomain(); //正常项目中应该是自行从其他地方下载dll,或者打包在AssetBundle中读取,平时开发以及为了演示方便直接从StreammingAssets中读取, //正式发布的时候需要大家自行从其他地方读取dll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! //这个DLL文件是直接编译PTestDll.sln生成的,已经在项目中设置好输出目录为StreamingAssets,在VS里直接编译即可生成到对应目录,无需手动拷贝 #if UNITY_ANDROID WWW www = new WWW(Application.streamingAssetsPath + "/PTestDll.dll"); #else WWW www = new WWW("file:///" + Application.streamingAssetsPath + "/PTestDll.dll"); #endif while (!www.isDone) { yield return(null); } if (!string.IsNullOrEmpty(www.error)) { UnityEngine.Debug.LogError(www.error); } byte[] dll = www.bytes; www.Dispose(); //PDB文件是调试数据库,如需要在日志中显示报错的行号,则必须提供PDB文件,不过由于会额外耗用内存,正式发布时请将PDB去掉,下面LoadAssembly的时候pdb传null即可 #if UNITY_ANDROID www = new WWW(Application.streamingAssetsPath + "/PTestDll.pdb"); #else www = new WWW("file:///" + Application.streamingAssetsPath + "/PTestDll.pdb"); #endif while (!www.isDone) { yield return(null); } if (!string.IsNullOrEmpty(www.error)) { UnityEngine.Debug.LogError(www.error); } byte[] pdb = www.bytes; using (System.IO.MemoryStream fs = new MemoryStream(dll)) { using (System.IO.MemoryStream p = new MemoryStream(pdb)) { appdomain.LoadAssembly(fs, p, new Mono.Cecil.Pdb.PdbReaderProvider()); } } ILRuntime.Runtime.Generated.CLRBindings.Initialize(appdomain); onDone(); }
static void GenerateCLRBindingByAnalysis() { //用新的分析热更dll调用引用来生成绑定代码 ILRuntime.Runtime.Enviorment.AppDomain domain = new ILRuntime.Runtime.Enviorment.AppDomain(); using (System.IO.FileStream fs = new System.IO.FileStream("Assets/Res/hotfix/dll/Hotfix.dll.bytes", System.IO.FileMode.Open, System.IO.FileAccess.Read)) { domain.LoadAssembly(fs); } //Crossbind Adapter is needed to generate the correct binding code Hotfixer.InitILRuntime(domain); ILRuntime.Runtime.CLRBinding.BindingCodeGenerator.GenerateBindingCode(domain, "Assets/ThirdParty/ILRuntime/Generated"); AssetDatabase.Refresh(); }
public void RegisterAssembly() { GameObject code = (GameObject)Resources.Load("Code"); byte[] assBytes = code.GetComponent <ReferenceCollector>().Get <TextAsset>("Hotfix.dll").bytes; byte[] mdbBytes = code.GetComponent <ReferenceCollector>().Get <TextAsset>("Hotfix.pdb").bytes; using (MemoryStream fs = new MemoryStream(assBytes)) using (MemoryStream p = new MemoryStream(mdbBytes)) { AppDomain.LoadAssembly(fs, p, new Mono.Cecil.Pdb.PdbReaderProvider()); } }
static void GenerateCLRBindingByAnalysis() { //用新的分析热更dll调用引用来生成绑定代码 ILRuntime.Runtime.Enviorment.AppDomain domain = new ILRuntime.Runtime.Enviorment.AppDomain(); using (System.IO.FileStream fs = new System.IO.FileStream("Assets/RemoteResources/Dll/AHotGames.bytes", System.IO.FileMode.Open, System.IO.FileAccess.Read)) { domain.LoadAssembly(fs); //Crossbind Adapter is needed to generate the correct binding code InitILRuntime(domain); ILRuntime.Runtime.CLRBinding.BindingCodeGenerator.GenerateBindingCode(domain, "Assets/Plugins/ILRuntime/Generated"); } }