public void GotoHotfix() { #if ILRuntime ILHelper.InitILRuntime(this.appDomain); #endif this.start.Run(); }
private CodeLoader() { Dictionary <string, UnityEngine.Object> dictionary = AssetsBundleHelper.LoadBundle("code.unity3d"); byte[] assBytes = ((TextAsset)dictionary["Code.dll"]).bytes; byte[] pdbBytes = ((TextAsset)dictionary["Code.pdb"]).bytes; #if ILRuntime ILRuntime.Runtime.Enviorment.AppDomain appDomain = new ILRuntime.Runtime.Enviorment.AppDomain(); using (System.IO.MemoryStream assStream = new System.IO.MemoryStream(assBytes)) using (System.IO.MemoryStream pdbStream = new System.IO.MemoryStream(pdbBytes)) { appDomain.LoadAssembly(assStream, pdbStream, new ILRuntime.Mono.Cecil.Pdb.PdbReaderProvider()); } ILHelper.InitILRuntime(appDomain); this.hotfixTypes = Type.EmptyTypes; this.hotfixTypes = appDomain.LoadedTypes.Values.Select(x => x.ReflectionType).ToArray(); this.start = new ILStaticMethod(appDomain, "ET.Entry", "Start", 0); #else System.Reflection.Assembly assembly = System.Reflection.Assembly.Load(assBytes, pdbBytes); hotfixTypes = assembly.GetTypes(); this.start = new MonoStaticMethod(assembly, "ET.Entry", "Start"); #endif }
public void Start() { switch (this.CodeMode) { case CodeMode.Mono: { Dictionary <string, UnityEngine.Object> dictionary = AssetsBundleHelper.LoadBundle("code.unity3d"); byte[] assBytes = ((TextAsset)dictionary["Code.dll"]).bytes; byte[] pdbBytes = ((TextAsset)dictionary["Code.pdb"]).bytes; assembly = Assembly.Load(assBytes, pdbBytes); this.allTypes = assembly.GetTypes(); IStaticMethod start = new MonoStaticMethod(assembly, "ET.Entry", "Start"); start.Run(); break; } case CodeMode.ILRuntime: { Dictionary <string, UnityEngine.Object> dictionary = AssetsBundleHelper.LoadBundle("code.unity3d"); byte[] assBytes = ((TextAsset)dictionary["Code.dll"]).bytes; byte[] pdbBytes = ((TextAsset)dictionary["Code.pdb"]).bytes; //byte[] assBytes = File.ReadAllBytes(Path.Combine("../Unity/", Define.BuildOutputDir, "Code.dll")); //byte[] pdbBytes = File.ReadAllBytes(Path.Combine("../Unity/", Define.BuildOutputDir, "Code.pdb")); appDomain = new ILRuntime.Runtime.Enviorment.AppDomain(); #if DEBUG && (UNITY_EDITOR || UNITY_ANDROID || UNITY_IPHONE) this.appDomain.UnityMainThreadID = System.Threading.Thread.CurrentThread.ManagedThreadId; #endif MemoryStream assStream = new MemoryStream(assBytes); MemoryStream pdbStream = new MemoryStream(pdbBytes); appDomain.LoadAssembly(assStream, pdbStream, new ILRuntime.Mono.Cecil.Pdb.PdbReaderProvider()); ILHelper.InitILRuntime(appDomain); this.allTypes = appDomain.LoadedTypes.Values.Select(x => x.ReflectionType).ToArray(); IStaticMethod start = new ILStaticMethod(appDomain, "ET.Entry", "Start", 0); start.Run(); break; } case CodeMode.Reload: { byte[] assBytes = File.ReadAllBytes(Path.Combine(Define.BuildOutputDir, "Data.dll")); byte[] pdbBytes = File.ReadAllBytes(Path.Combine(Define.BuildOutputDir, "Data.pdb")); assembly = Assembly.Load(assBytes, pdbBytes); this.LoadLogic(); IStaticMethod start = new MonoStaticMethod(assembly, "ET.Entry", "Start"); start.Run(); break; } } }
public void Start() { switch (Init.Instance.CodeMode) { case CodeMode.Mono: { Dictionary <string, UnityEngine.Object> dictionary = AssetsBundleHelper.LoadBundle("code.unity3d"); byte[] assBytes = ((TextAsset)dictionary["Code.dll"]).bytes; byte[] pdbBytes = ((TextAsset)dictionary["Code.pdb"]).bytes; assembly = Assembly.Load(assBytes, pdbBytes); this.allTypes = assembly.GetTypes(); IStaticMethod start = new MonoStaticMethod(assembly, "ET.Entry", "Start"); start.Run(); break; } case CodeMode.ILRuntime: { Dictionary <string, UnityEngine.Object> dictionary = AssetsBundleHelper.LoadBundle("code.unity3d"); byte[] assBytes = ((TextAsset)dictionary["Code.dll"]).bytes; byte[] pdbBytes = ((TextAsset)dictionary["Code.pdb"]).bytes; //byte[] assBytes = File.ReadAllBytes(Path.Combine("../Unity/", Define.BuildOutputDir, "Code.dll")); //byte[] pdbBytes = File.ReadAllBytes(Path.Combine("../Unity/", Define.BuildOutputDir, "Code.pdb")); ILRuntime.Runtime.Enviorment.AppDomain appDomain = new ILRuntime.Runtime.Enviorment.AppDomain(); MemoryStream assStream = new MemoryStream(assBytes); MemoryStream pdbStream = new MemoryStream(pdbBytes); appDomain.LoadAssembly(assStream, pdbStream, new ILRuntime.Mono.Cecil.Pdb.PdbReaderProvider()); ILHelper.InitILRuntime(appDomain); this.allTypes = appDomain.LoadedTypes.Values.Select(x => x.ReflectionType).ToArray(); IStaticMethod start = new ILStaticMethod(appDomain, "ET.Entry", "Start", 0); start.Run(); break; } case CodeMode.Reload: { byte[] assBytes = File.ReadAllBytes(Path.Combine(Define.BuildOutputDir, "Data.dll")); byte[] pdbBytes = File.ReadAllBytes(Path.Combine(Define.BuildOutputDir, "Data.pdb")); assembly = Assembly.Load(assBytes, pdbBytes); LoadHotfix(); IStaticMethod start = new MonoStaticMethod(assembly, "ET.Entry", "Start"); start.Run(); break; } } }
/// <summary> /// 这里开始正式进入游戏逻辑 /// </summary> public static void GoToHotfix(byte[] dllByte, byte[] pdbByte) { if (GlobalDefine.ILRuntimeMode) { _appDomain = new ILRuntime.Runtime.Enviorment.AppDomain(); s_hotfixDllStream = new MemoryStream(dllByte); s_hotfixPdbStream = new MemoryStream(pdbByte); _appDomain.LoadAssembly(s_hotfixDllStream, s_hotfixPdbStream, new ILRuntime.Mono.Cecil.Pdb.PdbReaderProvider()); ILHelper.InitILRuntime(_appDomain); _entryMethod = new ILStaticMethod(_appDomain, "ET.InitEntry", "RegFunction", 0); } else { _assembly = Assembly.Load(dllByte, pdbByte); _entryMethod = new MonoStaticMethod(_assembly, "ET.InitEntry", "RegFunction"); } _entryMethod.Run(); }
public void Start() { switch (this.CodeMode) { case CodeMode.Mono: { #if !UNITY_EDITOR var ab = AddressablesManager.Instance.SyncLoadAssetBundle("code_assets_all.bundle"); byte[] assBytes = ((TextAsset)ab.LoadAsset($"Assets/AssetsPackage/Code/Code{AssetBundleConfig.Instance.ResVer}.dll.bytes", typeof(TextAsset))).bytes; byte[] pdbBytes = ((TextAsset)ab.LoadAsset($"Assets/AssetsPackage/Code/Code{AssetBundleConfig.Instance.ResVer}.pdb.bytes", typeof(TextAsset))).bytes; #else byte[] assBytes = (AssetDatabase.LoadAssetAtPath($"Assets/AssetsPackage/Code/Code{AssetBundleConfig.Instance.ResVer}.dll.bytes", typeof(TextAsset)) as TextAsset).bytes; byte[] pdbBytes = (AssetDatabase.LoadAssetAtPath($"Assets/AssetsPackage/Code/Code{AssetBundleConfig.Instance.ResVer}.pdb.bytes", typeof(TextAsset)) as TextAsset).bytes; #endif assembly = Assembly.Load(assBytes, pdbBytes); foreach (Type type in this.assembly.GetTypes()) { this.monoTypes[type.FullName] = type; this.hotfixTypes[type.FullName] = type; } IStaticMethod start = new MonoStaticMethod(assembly, "ET.Entry", "Start"); start.Run(); #if !UNITY_EDITOR ab.Unload(true); #endif break; } case CodeMode.ILRuntimeJIT: case CodeMode.ILRuntime: { #if !UNITY_EDITOR var ab = AddressablesManager.Instance.SyncLoadAssetBundle("code_assets_all.bundle"); byte[] assBytes = ((TextAsset)ab.LoadAsset($"Assets/AssetsPackage/Code/Code{AssetBundleConfig.Instance.ResVer}.dll.bytes", typeof(TextAsset))).bytes; byte[] pdbBytes = ((TextAsset)ab.LoadAsset($"Assets/AssetsPackage/Code/Code{AssetBundleConfig.Instance.ResVer}.pdb.bytes", typeof(TextAsset))).bytes; #else byte[] assBytes = (AssetDatabase.LoadAssetAtPath($"Assets/AssetsPackage/Code/Code{AssetBundleConfig.Instance.ResVer}.dll.bytes", typeof(TextAsset)) as TextAsset).bytes; byte[] pdbBytes = (AssetDatabase.LoadAssetAtPath($"Assets/AssetsPackage/Code/Code{AssetBundleConfig.Instance.ResVer}.pdb.bytes", typeof(TextAsset)) as TextAsset).bytes; #endif if (this.CodeMode == CodeMode.ILRuntimeJIT) { appDomain = new ILRuntime.Runtime.Enviorment.AppDomain(ILRuntime.Runtime.ILRuntimeJITFlags.JITOnDemand); } else { appDomain = new ILRuntime.Runtime.Enviorment.AppDomain(); } #if DEBUG && (UNITY_EDITOR || UNITY_ANDROID || UNITY_IPHONE) this.appDomain.UnityMainThreadID = System.Threading.Thread.CurrentThread.ManagedThreadId; #endif if (assStream != null) { assStream.Dispose(); } if (pdbStream != null) { pdbStream.Dispose(); } assStream = new MemoryStream(assBytes); pdbStream = new MemoryStream(pdbBytes); appDomain.LoadAssembly(assStream, pdbStream, new ILRuntime.Mono.Cecil.Pdb.PdbReaderProvider()); Type[] types = appDomain.LoadedTypes.Values.Select(x => x.ReflectionType).ToArray(); foreach (Type type in types) { this.hotfixTypes[type.FullName] = type; } ILHelper.InitILRuntime(appDomain); IStaticMethod start = new ILStaticMethod(appDomain, "ET.Entry", "Start", 0); #if !UNITY_EDITOR ab.Unload(true); #endif start.Run(); break; } case CodeMode.Reload: { byte[] assBytes = File.ReadAllBytes(Path.Combine(Define.BuildOutputDir, "Data.dll")); byte[] pdbBytes = File.ReadAllBytes(Path.Combine(Define.BuildOutputDir, "Data.pdb")); assembly = Assembly.Load(assBytes, pdbBytes); this.LoadLogic(); IStaticMethod start = new MonoStaticMethod(assembly, "ET.Entry", "Start"); start.Run(); break; } } }