using ET; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Reflection; #if UNITY using UnityEngine; #endif namespace ET { public sealed class Hotfix : Object { private static Hotfix _instance; public static Hotfix instance => _instance = _instance ?? new Hotfix(); #if ILRuntime private ILRuntime.Runtime.Enviorment.AppDomain appDomain; private MemoryStream dllStream; private MemoryStream pdbStream; #else private Assembly assembly; #endif private IStaticMethod start; private List hotfixTypes; public Assembly hotfix; public Assembly hotfixView; //public Action Update; //public Action LateUpdate; //public Action OnApplicationQuit; public void GotoHotfix() { Log.Info($"开始加载热更逻辑"); Log.Info($"{start}"); this.start.Run(); } public List GetHotfixTypes() { return this.hotfixTypes; } public async ETTask LoadHotfixAssembly() { try { #if UNITY byte[] assBytes = (await ResourceHelper.LoadAssetAsync(PathHelper.HotfixDll)).bytes; byte[] pdbBytes = (await ResourceHelper.LoadAssetAsync(PathHelper.HotfixPdb)).bytes; byte[] assViewBytes = (await ResourceHelper.LoadAssetAsync(PathHelper.HotfixViewDll)).bytes; byte[] pdbViewBytes = (await ResourceHelper.LoadAssetAsync(PathHelper.HotfixViewPdb)).bytes; if (!Define.IsEditorMode) { string key = GameKeyComponent.Instance.key; string keyIV = GameKeyComponent.Instance.keyIV; assBytes = Utility.Encryption.AesCBCDecrypt(assBytes,key ,keyIV); pdbBytes = Utility.Encryption.AesCBCDecrypt(pdbBytes, key,keyIV); assViewBytes = Utility.Encryption.AesCBCDecrypt(assViewBytes,key ,keyIV); pdbViewBytes = Utility.Encryption.AesCBCDecrypt(pdbViewBytes, key,keyIV); } #else byte[] assBytes = null; byte[] pdbBytes = null; byte[] assViewBytes = null; byte[] pdbViewBytes = null; #endif hotfix = Assembly.Load(assBytes, pdbBytes); Type hotfixInit = hotfix.GetType("ET.InitHotfix"); this.start = new MonoStaticMethod(hotfixInit, "Start"); //this.hotfixTypes = assembly.GetTypes().ToList(); hotfixView = Assembly.Load(assViewBytes, pdbViewBytes); //this.hotfixTypes.AddRange(viewAssembly.GetTypes()); } catch (Exception e) { Log.Error(e); } } } }