/// <summary> /// 分析dll生成 /// </summary> /// <param name="platform"></param> /// <param name="dllpath"></param> static private void GenCLRBindingByAnalysis(RuntimePlatform platform = RuntimePlatform.Lumin, string dllpath = "") { if (platform == RuntimePlatform.Lumin) { platform = Application.platform; } //默认读StreammingAssets下面path if (dllpath == "") { dllpath = Application.streamingAssetsPath + "/" + BApplication.GetPlatformPath(platform) + DLLPATH; } //不参与自动绑定的 List <Type> excludeTypes = new List <Type>(); // excludeTypes.AddRange(manualBindingTypes); excludeTypes.AddRange(preBindingTypes); //用新的分析热更dll调用引用来生成绑定代码 var targetPath = "Assets/Code/Game/ILRuntime/Binding/Analysis"; ILRuntimeHelper.LoadHotfix(dllpath, false); BindingCodeGenerator.GenerateAnalysisBindingCode(ILRuntimeHelper.AppDomain, targetPath, blackTypes: excludeTypes); ILRuntimeHelper.Close(); AssetDatabase.Refresh(); //暂时先不处理 }
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); } }
//生成clr绑定 static public void GenCLRBindingByAnalysis(RuntimePlatform platform = RuntimePlatform.Lumin, string dllpath = "") { if (platform == RuntimePlatform.Lumin) { platform = Application.platform; } //默认读StreammingAssets下面path if (dllpath == "") { dllpath = Application.streamingAssetsPath + "/" + BDUtils.GetPlatformPath(platform) + "/hotfix/hotfix.dll"; } //不参与自动绑定的 List <Type> notGenerateTypes = new List <Type>() { typeof(MethodBase), typeof(MemberInfo), typeof(FieldInfo), typeof(MethodInfo), typeof(PropertyInfo) , typeof(Component), typeof(Type) }; //用新的分析热更dll调用引用来生成绑定代码 ILRuntimeHelper.LoadHotfix(dllpath, false); BindingCodeGenerator.GenerateBindingCode(ILRuntimeHelper.AppDomain, "Assets/Code/Game/ILRuntime/Binding/Analysis", notGenTypes: notGenerateTypes); ILRuntimeHelper.Close(); AssetDatabase.Refresh(); //暂时先不处理 }
public void Load(string assemblyPath, bool useRegister) { fs = new FileStream(assemblyPath, FileMode.Open, FileAccess.Read); { var path = Path.GetDirectoryName(assemblyPath); var name = Path.GetFileNameWithoutExtension(assemblyPath); var pdbPath = Path.Combine(path, name) + ".pdb"; if (!File.Exists(pdbPath)) { name = Path.GetFileName(assemblyPath); pdbPath = Path.Combine(path, name) + ".mdb"; } _app = new ILRuntime.Runtime.Enviorment.AppDomain(useRegister ? ILRuntime.Runtime.ILRuntimeJITFlags.JITImmediately : ILRuntime.Runtime.ILRuntimeJITFlags.None); _app.DebugService.StartDebugService(56000); fs2 = new System.IO.FileStream(pdbPath, FileMode.Open); { ILRuntime.Mono.Cecil.Cil.ISymbolReaderProvider symbolReaderProvider = null; if (pdbPath.EndsWith(".pdb")) { symbolReaderProvider = new ILRuntime.Mono.Cecil.Pdb.PdbReaderProvider(); }/* else if (pdbPath.EndsWith (".mdb")) { * symbolReaderProvider = new Mono.Cecil.Mdb.MdbReaderProvider (); * }*/ _app.LoadAssembly(fs, fs2, symbolReaderProvider); } ILRuntimeHelper.Init(_app); ILRuntime.Runtime.Generated.CLRBindings.Initialize(_app); _app.InitializeBindings(true); LoadTest(); } lastSession = this; }
//生成clr绑定 static void GenCLRBindingByAnalysis() { //用新的分析热更dll调用引用来生成绑定代码 ILRuntimeHelper.LoadHotfix(false); BindingCodeGenerator.GenerateBindingCode(ILRuntimeHelper.AppDomain, "Assets/Code/Game/ILRuntime/Binding"); AssetDatabase.Refresh(); }
//生成clr绑定 public static void GenCLRBindingByAnalysis(RuntimePlatform platform = RuntimePlatform.Lumin, string dllpath = "") { #if ILRUNTIME if (platform == RuntimePlatform.Lumin) { platform = Application.platform; } //默认读StreammingAssets下面path if (dllpath == "") { dllpath = Application.streamingAssetsPath + "/" + DLLPATH; } //不参与自动绑定的 List <Type> notGenerateTypes = new List <Type>() { typeof(MethodBase), typeof(MemberInfo), typeof(FieldInfo), typeof(MethodInfo), typeof(PropertyInfo) , typeof(Component), typeof(Type) }; //用新的分析热更dll调用引用来生成绑定代码 ILRuntimeHelper.LoadHotfix(dllpath, false); BindingCodeGenerator.GenerateBindingCode(ILRuntimeHelper.AppDomain, "Assets/LWFramework/ILRuntime/Binding/Analysis", notGenTypes: notGenerateTypes); ILRuntimeHelper.Close(); AssetDatabase.Refresh(); #else Debug.Log("当前不是IL模式"); #endif //暂时先不处理 }
void DownloadNewClient() { string url = _patchUrl + "_" + ILRuntimeHelper.GetDownladName() + ".apk"; string savepath = Application.persistentDataPath + "/" + _targetVersion + "_game.apk"; Downloader.DownloadFiles(new List <DownloadFile>() { new DownloadFile(url, savepath) }, (obj) => { if (!File.Exists(savepath)) { ChangeCurrentUpdateState(UpdateState.OpenNewClientUrl); } else { ChangeCurrentUpdateState(UpdateState.InstallNewClient); } }, (arg) => { object[] args = arg as object[]; _currentProgress.Progreess = (float)args[0]; _onShowUpdateProgress(_currentProgress); }); }
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); } }
//生成clr绑定 static public void GenCLRBindingByAnalysis(RuntimePlatform platform = RuntimePlatform.Lumin) { if (platform == RuntimePlatform.Lumin) { platform = Application.platform; } //用新的分析热更dll调用引用来生成绑定代码 var dllpath = Application.streamingAssetsPath + "/" + BDUtils.GetPlatformPath(platform) + "/hotfix/hotfix.dll"; ILRuntimeHelper.LoadHotfix(dllpath, false); BindingCodeGenerator.GenerateBindingCode(ILRuntimeHelper.AppDomain, "Assets/Code/Game/ILRuntime/Binding/Analysis"); AssetDatabase.Refresh(); return; //暂时先不处理 var assemblies = new List <Assembly>() { typeof(UnityEngine.UI.Button).Assembly, }; var types = new List <Type>(); types.Add(typeof(Vector4)); // // foreach (var assm in assemblies) // { // var _ts = assm.GetTypes(); // foreach (var t in _ts) // { // if (t.Namespace != null) // { // if (t.FullName.Contains("UnityEngine.Android") // || t.FullName.Contains("UnityEngine.iPhone") // || t.FullName.Contains("UnityEngine.WSA") // || t.FullName.Contains("UnityEngine.iOS") // || t.FullName.Contains("UnityEngine.Windows") // || t.FullName.Contains("JetBrains") // || t.FullName.Contains("Editor")) // { // continue; // } // } // // // types.Add(t); // } // } // // types = types.Distinct().ToList(); //PreBinding BindingCodeGenerator.GenerateBindingCode(types, "Assets/Code/Game/ILRuntime/Binding/PreBinding"); 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/Res/HotfixDLL/Hotfix.dll.bytes", System.IO.FileMode.Open, System.IO.FileAccess.Read)) { domain.LoadAssembly(fs); //Crossbind Adapter is needed to generate the correct binding code ILRuntimeHelper.InitILRuntime(domain); ILRuntime.Runtime.CLRBinding.BindingCodeGenerator.GenerateBindingCode(domain, "Assets/Scripts/GameMain/Customs/CustomComponents/ILRuntime/Generated"); AssetDatabase.Refresh(); } }
//生成clr绑定 private static void GenClrBindingByAnalysis(RuntimePlatform platform = RuntimePlatform.Lumin) { if (platform == RuntimePlatform.Lumin) { platform = Application.platform; } //用新的分析热更dll调用引用来生成绑定代码 var dllpath = Application.streamingAssetsPath + "/AssetBundles/" + AssetBundleSettings.GetPlatformForAssetBundles(platform) + "/hotfix.dll"; ILRuntimeHelper.LoadHotfix(dllpath, false); BindingCodeGenerator.GenerateBindingCode(ILRuntimeHelper.AppDomain, "Assets/" + ILRuntimeScriptSetting.Default.GenClrBindPath.CreateDirIfNotExists()); AssetDatabase.Refresh(); }
//生成clr绑定 static void GenCLRBindingByAnalysis() { //用新的分析热更dll调用引用来生成绑定代码 ILRuntimeHelper.LoadHotfix(Application.streamingAssetsPath, false); BindingCodeGenerator.GenerateBindingCode(ILRuntimeHelper.AppDomain, "Assets/Code/Game/ILRuntime/Binding/Analysis"); AssetDatabase.Refresh(); return; //暂时先不处理 //预先绑定所有的 var assemblies = new List <Assembly>() { typeof(UnityEngine.UI.Button).Assembly, }; var types = new List <Type>(); // foreach (var assm in assemblies) { var _ts = assm.GetTypes(); foreach (var t in _ts) { if (t.Namespace != null) { if (t.FullName.Contains("UnityEngine.Android") || t.FullName.Contains("UnityEngine.iPhone") || t.FullName.Contains("UnityEngine.WSA") || t.FullName.Contains("UnityEngine.iOS") || t.FullName.Contains("UnityEngine.Windows") || t.FullName.Contains("JetBrains") || t.FullName.Contains("Editor")) { continue; } } types.Add(t); } } types = types.Distinct().ToList(); //PreBinding BindingCodeGenerator.GenerateBindingCode(types, "Assets/Code/Game/ILRuntime/Binding/PreBinding"); AssetDatabase.Refresh(); }
/// <summary> /// 开始启动游戏 /// </summary> private void OnLaunch() { if (IsCodeHotfix) //热更代码模式 { ILRuntimeHelper.LoadHotfix(IsLoadPdb); ILRuntimeHelper.AppDomain.Invoke("BDLauncherBridge", "Start", null, new object[] { IsCodeHotfix, IsAssetBundleModel }); } else { //这里用反射是为了 不访问逻辑模块的具体类,防止编译失败 var assembly = Assembly.GetExecutingAssembly(); var type = assembly.GetType("BDLauncherBridge"); var method = type.GetMethod("Start", BindingFlags.Public | BindingFlags.Static); method.Invoke(null, new object[] { IsCodeHotfix, IsAssetBundleModel }); } }
void Awake() { string str = ILRuntimeHelper.GetLanguage(id); Text text = GetComponent <Text>(); if (text != null) { text.text = str; return; } InputField input = GetComponent <InputField>(); if (input != null) { input.text = str; return; } Image img = GetComponent <Image>(); if (img != null) { try { string[] strs = str.Split(':'); img.sprite = UIAtlas.GetSprite(strs[0], strs[1]); img.SetNativeSize(); return; } catch (Exception ex) { Debugger.LogException(ex); } } RawImage rawImg = GetComponent <RawImage>(); if (rawImg != null) { rawImg.texture = ResourceLoader.Load <Texture>(str); rawImg.SetNativeSize(); return; } }
// Use this for initialization private void Awake() { this.gameObject.AddComponent <IEnumeratorTool>(); this.gameObject.AddComponent <BResources>(); if (IsCodeHotfix) { ILRuntimeHelper.LoadHotfix(IsLoadPdb); ILRuntimeHelper.AppDomain.Invoke("BDLauncherBridge", "Start", null, new object[] { IsCodeHotfix, IsResourceHotfix }); } else { //这里用反射是为了 不访问逻辑模块的具体类,防止编译失败 var assembly = Assembly.GetExecutingAssembly(); var type = assembly.GetType("BDLauncherBridge"); var method = type.GetMethod("Start", BindingFlags.Public | BindingFlags.Static); method.Invoke(null, new object[] { IsCodeHotfix, IsResourceHotfix }); } }
static void InitILRuntime(ILRuntime.Runtime.Enviorment.AppDomain domain) { //这里需要注册所有热更DLL中用到的跨域继承Adapter,否则无法正确抓取引用 var gameDll = AssemblyManager.GetAssembly(ConfigBase.Load <FrameworkRuntimeConfig>().GameDllName); var para = new object[] { domain }; foreach (var type in gameDll.GetTypes()) { ILRuntimeAdapterHelper.AddAdaptor(type); if (type.GetCustomAttribute(typeof(HotfixInitAttribute), false) != null) { type.GetMethods().First(info => info.GetCustomAttribute(typeof(HotfixInitAttribute)) != null) .Invoke(null, para); } } foreach (var type in typeof(ILRuntimeHelper).Assembly.GetTypes()) { ILRuntimeAdapterHelper.AddAdaptor(type); } ILRuntimeHelper.InitializeILRuntime(domain); }
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); using (var fs2 = new System.IO.FileStream($"{path}\\{name}.pdb", FileMode.Open)) { _app.LoadAssembly(fs, fs2, new Mono.Cecil.Pdb.PdbReaderProvider()); _isLoadAssembly = true; } ILRuntimeHelper.Init(_app); _app.RegisterValueTypeBinder(typeof(TestVector3), new TestVector3Binder()); _app.RegisterValueTypeBinder(typeof(TestVectorStruct), new TestVectorStructBinder()); _app.RegisterValueTypeBinder(typeof(TestVectorStruct2), new TestVectorStruct2Binder()); LoadTest(); UpdateBtnState(); } } catch (Exception ex) { MessageBox.Show("[Error:]" + ex); } }
// 加載 dll // isregisterBindings 為 false 時,是生成 binding的時候 private void LoadDll(string dllPath, bool isRegisterBindings = true) { switch (ILRuntimeScriptSetting.Default.HotfixRunMode) { case HotfixCodeRunMode.ILRuntime: ILRuntimeHelper.LoadHotfix(dllPath, isRegisterBindings); break; case HotfixCodeRunMode.Reflection: { var bytes = File.ReadAllBytes(dllPath); var bytes2 = File.ReadAllBytes(dllPath + ".mdb"); Assembly = Assembly.Load(bytes, bytes2); break; } case HotfixCodeRunMode.Editor: // 等分了asmdef 则去获取asmdef生成的程序集 Assembly = Assembly.GetExecutingAssembly(); break; } }
void DownloadGateway() { GameClient.Instance.ips.Clear(); GameClient.Instance.ports.Clear(); #if UNITY_EDITOR if (File.Exists(Application.dataPath + "/../gateway.txt")) { string str = File.ReadAllText(Application.dataPath + "/../gateway.txt"); string[] strs = str.Split(' '); GameClient.Instance.ips.Add(strs[0]); GameClient.Instance.ports.Add(int.Parse(strs[1])); } ChangeCurrentUpdateState(UpdateState.UpdateFinish); #else #if ILRUNTIME_DEBUG && UNITY_STANDALONE_WIN if (ResourceManager.IsILRuntimeDebug) { if (File.Exists(Application.dataPath + "/gateway.txt")) { string str = File.ReadAllText(Application.dataPath + "/gateway.txt"); string[] strs = str.Split(' '); GameClient.Instance.ips.Add(strs[0]); GameClient.Instance.ports.Add(int.Parse(strs[1])); } ChangeCurrentUpdateState(UpdateState.UpdateFinish); } else { #endif string url = ILRuntimeHelper.GetGatewayUrl(); Debugger.Log("gateway url : " + url, true); string savepath = Application.persistentDataPath + "/gateway.txt"; Downloader.DownloadFiles(new List <DownloadFile>() { new DownloadFile(url, savepath) }, (obj) => { if (!File.Exists(savepath)) { Debugger.LogError("DownloadGateway 0"); _onShowUpdateStepFail(0); return; } string json = File.ReadAllText(savepath); GatewayConfig gatewayConfig = JsonMapper.ToObject <GatewayConfig>(json); _resourceUpdateTips = gatewayConfig.resourceTips; _versionUpdateTips = gatewayConfig.versionTips; _versionUrl = gatewayConfig.versionUrl; _patchUrl = gatewayConfig.patchUrl; Debugger.Log("vesion url : " + _versionUrl, true); Debugger.Log("patch url : " + _patchUrl, true); string version = ResourceManager.CodeVersion.ToString(); string channelName = ILRuntimeHelper.GetChannelName(); bool find = false; for (int i = 0; i < gatewayConfig.gameVersions.Count; ++i) { if (gatewayConfig.gameVersions[i].version == version) { for (int j = 0; j < gatewayConfig.gameVersions[i].channels.Count; ++j) { var channel = gatewayConfig.gameVersions[i].channels[j]; if (channel.channelName == channelName) { GameClient.Instance.isShenHe = channel.isShenHe; ResourceManager.ResourceUrl = channel.resourceUrl; Debugger.Log("resource url : " + ResourceManager.ResourceUrl, true); GameClient.Instance.ips.AddRange(channel.ips); GameClient.Instance.ports.AddRange(channel.ports); find = true; break; } } } } if (!find) { _onShowUpdateStepFail(1); return; } File.Delete(savepath); if (GameClient.Instance.isShenHe && !GameClient.Instance.BuildSettings.MiniBuild) { ChangeCurrentUpdateState(UpdateState.UpdateFinish); } else { ChangeCurrentUpdateState(UpdateState.ComparServerVersion); } }); #if ILRUNTIME_DEBUG && UNITY_STANDALONE_WIN } #endif #endif }
public void Dispose() { ILRuntimeHelper.Close(); }
private void button1_Click_1(object sender, EventArgs e) { if (OD.ShowDialog() == DialogResult.OK) { using (System.IO.FileStream fs = new System.IO.FileStream(OD.FileName, System.IO.FileMode.Open, System.IO.FileAccess.Read)) { var path = System.IO.Path.GetDirectoryName(OD.FileName); var name = System.IO.Path.GetFileNameWithoutExtension(OD.FileName); using (System.IO.FileStream fs2 = new System.IO.FileStream(string.Format("{0}\\{1}.pdb", path, name), System.IO.FileMode.Open)) app.LoadAssembly(fs, fs2, new Mono.Cecil.Pdb.PdbReaderProvider()); ILRuntimeHelper.Init(app); //app.RegisterCrossBindingAdaptor(new TestFramework.ClassInheritanceAdaptor()); //app.RegisterCrossBindingAdaptor(new TestFramework.InterfaceTestAdaptor()); //app.DelegateManager.RegisterMethodDelegate<int>(); ////app.DelegateManager.RegisterMethodDelegate<int, string>(); //app.DelegateManager.RegisterFunctionDelegate<int, int>(); ////app.DelegateManager.RegisterFunctionDelegate<int, int, int>(); ////app.DelegateManager.RegisterMethodDelegate<MyClass2>(); //app.DelegateManager.RegisterDelegateConvertor<TestFramework.IntDelegate>((action) => //{ // return new TestFramework.IntDelegate((a) => // { // ((Action<int>)action)(a); // }); //}); //app.DelegateManager.RegisterDelegateConvertor<TestFramework.IntDelegate2>((action) => //{ // return new TestFramework.IntDelegate2((a) => // { // return ((Func<int, int>)action)(a); // }); //}); /*app.RegisterCLRMethodRedirection(typeof(UnitTest.Logger).GetMethod("Log"), (ctx, instance, param, ga) => * { * Console.WriteLine(param[0]); * return null; * }); * app.DelegateManager.RegisterDelegateConvertor<TestDele.Action2<int, string>>((action) => * { * return new TestDele.Action2<int, string>((a, b) => * { * ((Action<int, string>)action)(a, b); * }); * }); * * app.DelegateManager.RegisterDelegateConvertor<UnitTest.Perform.Action>((action) => * { * return new UnitTest.Perform.Action(() => * { * ((Action)action)(); * }); * }); * app.DelegateManager.RegisterDelegateConvertor<TestDele.myup>((action) => * { * return new TestDele.myup(() => * { * ((Action)action)(); * }); * }); * * app.DelegateManager.RegisterDelegateConvertor<Comparison<int>>((action) => * { * return new Comparison<int>((a, b) => * { * return ((Func<int, int, int>)action)(a, b); * }); * }); */ assembly = Assembly.LoadFrom(OD.FileName); } } }
/// <summary> /// 分析dll生成 /// </summary> /// <param name="platform"></param> /// <param name="dllpath"></param> static private void GenCLRBindingByAnalysis(RuntimePlatform platform = RuntimePlatform.Lumin, string dllpath = "") { if (platform == RuntimePlatform.Lumin) { platform = Application.platform; } //默认读StreammingAssets下面path if (dllpath == "") { dllpath = Application.streamingAssetsPath + "/" + BApplication.GetPlatformPath(platform) + DLLPATH; } //不参与自动绑定的 List <Type> excludeTypes = new List <Type>(); // excludeTypes.AddRange(manualBindingTypes); excludeTypes.AddRange(preBindingTypes); //用新的分析热更dll调用引用来生成绑定代码 var outputPath = "Assets/Code/Game/ILRuntime/Binding/Analysis"; ILRuntimeHelper.LoadHotfix(dllpath, false); BindingCodeGenerator.GenerateBindingCode(ILRuntimeHelper.AppDomain, outputPath); ILRuntimeHelper.Close(); /******************移除已经被绑定的部分****************/ var analysisClrBinding = IPath.Combine(outputPath, "CLRBindings.cs"); var manualPath = "Assets/Code/Game/ILRuntime/Binding/Manual"; var prebindingPath = "Assets/Code/Game/ILRuntime/Binding/PreBinding"; //手动绑定的所有文件 var bindingFs = Directory.GetFiles(manualPath, "*.*").ToList(); if (Directory.Exists(prebindingPath)) { bindingFs.AddRange(Directory.GetFiles(prebindingPath, "*.*")); } for (int i = 0; i < bindingFs.Count; i++) { //删除被手动绑定的文件 var f = IPath.Combine(outputPath, Path.GetFileName(bindingFs[i])); if (f != analysisClrBinding && File.Exists(f)) { File.Delete(f); } bindingFs[i] = Path.GetFileNameWithoutExtension(bindingFs[i]); } var analysisContent = File.ReadAllLines(analysisClrBinding).ToList(); //修改CLRbingding内容 for (int i = analysisContent.Count - 1; i >= 0; i--) { var line = analysisContent[i]; //移除line foreach (var mf in bindingFs) { if (line.Contains(mf + ".Register(app);")) { analysisContent.RemoveAt(i); Debug.Log("移除[已经绑定]:" + line); break; } } } //写入 File.WriteAllLines(analysisClrBinding, analysisContent); //Manual AssetDatabase.Refresh(); }
private void OnBtnLoad(object sender, EventArgs e) { if (fs != null) { fs.Close(); } if (fs2 != null) { fs2.Close(); } if (txtPath.Text == "") { if (OD.ShowDialog() == DialogResult.OK) { Properties.Settings.Default["assembly_path"] = txtPath.Text = OD.FileName; Properties.Settings.Default.Save(); } else { return; } } try { 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"; } _app = new ILRuntime.Runtime.Enviorment.AppDomain(cbEnableRegVM.Checked ? ILRuntime.Runtime.ILRuntimeJITFlags.JITImmediately : ILRuntime.Runtime.ILRuntimeJITFlags.None); _app.DebugService.StartDebugService(56000); fs2 = new System.IO.FileStream(pdbPath, FileMode.Open); { ILRuntime.Mono.Cecil.Cil.ISymbolReaderProvider symbolReaderProvider = null; if (pdbPath.EndsWith(".pdb")) { symbolReaderProvider = new ILRuntime.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> /// 收集Test的数据 /// </summary> static public void CollectTestClassData(TestType testType) { testMethodDataMap = new Dictionary <Type, List <TestMethodData> >(); List <Type> types = new List <Type>(); //判断不同的模式 if (testType == TestType.MonoOrCLR) { var assembly = typeof(BDLauncher).Assembly; types = assembly.GetTypes().ToList(); } else if (testType == TestType.ILRuntime) { types = ILRuntimeHelper.GetHotfixTypes(); } var attribute = typeof(UnitTestBaseAttribute); //测试用例类 List <Type> testClassList = new List <Type>(); foreach (var type in types) { var attrs = type.GetCustomAttributes(attribute, false); if (attrs.Length > 0) { testClassList.Add(type); } } //搜集Test信息 foreach (var type in testClassList) { var methods = type.GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); // var attrs = type.GetCustomAttributes(attribute,false); // var attr = attrs[0] as HotfixTest; var testMethodDataList = new List <TestMethodData>(); testMethodDataMap[type] = testMethodDataList; //获取uit test并排序 foreach (var method in methods) { var mattrs = method.GetCustomAttributes(attribute, false); var mattr = mattrs[0] as UnitTestBaseAttribute; //数据 var newMethodData = new TestMethodData() { MethodInfo = method, TestData = mattr, }; //添加整合排序 bool isAdd = false; for (int i = 0; i < testMethodDataList.Count; i++) { var tdata = testMethodDataList[i]; if (newMethodData.TestData.Order < tdata.TestData.Order) { testMethodDataList.Insert(i, newMethodData); isAdd = true; break; } } if (!isAdd) { testMethodDataList.Add(newMethodData); } } } }
/// <summary> /// 这里注册整个游戏类型 /// </summary> /// <param name="isILRMode"></param> static public void Start(bool isILRMode = false, bool isRefMode = false) { BDebug.Log("解释执行:" + isILRMode, "yellow"); //组件加载 List <Type> allTypes = new List <Type>(); //编辑器环境下 寻找dll if (isILRMode) { allTypes = ILRuntimeHelper.GetHotfixTypes(); } else { //获取DLL ALLtype var assembly = Assembly.GetAssembly(typeof(BDLauncherBridge)); if (assembly == null) { Debug.Log("当前dll is null"); } allTypes = assembly.GetTypes().ToList(); } // var mgrs = new List <IMgr>(); var gsaType = typeof(GameStartAtrribute); //寻找所有的管理器 allTypes = allTypes.Distinct().ToList(); foreach (var t in allTypes) { if (t != null && t.BaseType != null && t.BaseType.FullName != null && t.BaseType.FullName.Contains(".ManagerBase`2")) { BDebug.Log("加载管理器-" + t, "green"); var i = t.BaseType.GetProperty("Inst").GetValue(null, null) as IMgr; mgrs.Add(i); continue; } //游戏启动器 //这里主要寻找 if (hotfixStart == null) { var attrs = t.GetCustomAttributes(gsaType, false); if (attrs.Length > 0 && attrs[0] is GameStartAtrribute && ((GameStartAtrribute)attrs[0]).Index == 1) { hotfixStart = Activator.CreateInstance(t) as IGameStart; } } } //类型注册 foreach (var t in allTypes) { foreach (var iMgr in mgrs) { iMgr.CheckType(t); } } //管理器初始化 foreach (var m in mgrs) { m.Init(); } //gamestart生命注册 if (hotfixStart != null) { hotfixStart.Start(); BDLauncher.OnUpdate = hotfixStart.Update; BDLauncher.OnLateUpdate = hotfixStart.LateUpdate; } //执行框架初始化完成的测试 BDLauncher.OnBDFrameInitialized?.Invoke(); BDLauncher.OnBDFrameInitializedForTest?.Invoke(); //所有管理器开始工作 foreach (var m in mgrs) { m.Start(); } IEnumeratorTool.WaitingForExec(5, () => { //执行单元测试 if (Config.Inst.Data.IsExcuteHotfixUnitTest && ILRuntimeHelper.IsRunning) { ILRuntimeTestRunner.RunHotfixUnitTest(); } }); }
void OpenNewClientUrl() { string url = _versionUrl + "?channlname=" + ILRuntimeHelper.GetChannelName(); Application.OpenURL(url); }
/// <summary> /// 分析dll生成 /// </summary> /// <param name="platform"></param> /// <param name="dllpath"></param> static private void GenCLRBindingByAnalysis(RuntimePlatform platform = RuntimePlatform.Lumin, string dllpath = "") { //默认参数 if (platform == RuntimePlatform.Lumin) { platform = Application.platform; } if (dllpath == "") { dllpath = Application.streamingAssetsPath; } //路径 dllpath = dllpath + "/" + BDApplication.GetPlatformPath(platform) + DLLPATH; //不参与自动绑定的 List <Type> excludeTypes = new List <Type>(); // excludeTypes.AddRange(manualBindingTypes); excludeTypes.AddRange(preBindingTypes); //用新的分析热更dll调用引用来生成绑定代码 var outputPath = "Assets/Code/BDFramework.Game/ILRuntime/Binding/Analysis"; //游戏工程的Bind Action <bool> mainProjectIlrBindAction = null; var type = BDFrameEditorLife.Types.FirstOrDefault((t) => t.FullName == "Game.ILRuntime.GameLogicCLRBinding"); if (type != null) { var method = type.GetMethod("Bind", BindingFlags.Public | BindingFlags.Static); Delegate bindDelegate = Delegate.CreateDelegate(typeof(Action <bool>), null, method); mainProjectIlrBindAction = bindDelegate as Action <bool>; } else { Debug.LogError("Not find CLRBinding logic!!!"); } //注册 ILRuntimeHelper.LoadHotfix(dllpath, mainProjectIlrBindAction, false); BindingCodeGenerator.GenerateBindingCode(ILRuntimeHelper.AppDomain, outputPath); ILRuntimeHelper.Close(); /******************移除已经被绑定的部分****************/ var analysisClrBinding = IPath.Combine(outputPath, "CLRBindings.cs"); var manualPath = "Assets/Code/BDFramework.Game/ILRuntime/Binding/Manual"; var prebindingPath = "Assets/Code/BDFramework.Game/ILRuntime/Binding/PreBinding"; //手动绑定的所有文件 var bindingFs = Directory.GetFiles(manualPath, "*.*").ToList(); if (Directory.Exists(prebindingPath)) { bindingFs.AddRange(Directory.GetFiles(prebindingPath, "*.*")); } for (int i = 0; i < bindingFs.Count; i++) { //删除被手动绑定的文件 var f = IPath.Combine(outputPath, Path.GetFileName(bindingFs[i])); if (f != analysisClrBinding && File.Exists(f)) { File.Delete(f); } bindingFs[i] = Path.GetFileNameWithoutExtension(bindingFs[i]); } var analysisContent = File.ReadAllLines(analysisClrBinding).ToList(); //修改CLRbindding内容 for (int i = analysisContent.Count - 1; i >= 0; i--) { var line = analysisContent[i]; //移除line foreach (var mf in bindingFs) { if (line.Contains(mf + ".Register(app);")) { analysisContent.RemoveAt(i); Debug.Log("移除[已经绑定]:" + line); break; } } } //写入 File.WriteAllLines(analysisClrBinding, analysisContent); //Manual AssetDatabase.Refresh(); }
public void AfterInit() { Debugger.Log(ILRuntimeHelper.GetResourceUrl(), true); }
void ComparServerVersion() { string url = ResourceManager.ResourceUrl + "version.txt"; string savepath = Application.persistentDataPath + "/version.txt"; Downloader.DownloadFiles(new List <DownloadFile>() { new DownloadFile(url, savepath) }, (obj) => { if (!File.Exists(savepath)) { _onShowUpdateStepFail(0); return; } string str = File.ReadAllText(savepath); string[] strs = str.Split(' '); if (strs.Length != 3) { _onShowUpdateStepFail(1); return; } float serverCodeVersion; if (!float.TryParse(strs[0], out serverCodeVersion)) { _onShowUpdateStepFail(2); return; } uint crc; if (!uint.TryParse(strs[1], out crc)) { _onShowUpdateStepFail(3); return; } GameClient.Instance.targetVersion = strs[2]; File.Delete(savepath); if ((int)serverCodeVersion > (int)ResourceManager.CodeVersion) { #if UNITY_ANDROID && !UNITY_EDITOR bool updateInGame = ILRuntimeHelper.GetUpdateInGame(); if (updateInGame) { _targetVersion = (int)serverCodeVersion; ChangeCurrentUpdateState(UpdateState.DownloadPatchConfig); } else { ChangeCurrentUpdateState(UpdateState.OpenNewClientUrl, false); } #else ChangeCurrentUpdateState(UpdateState.OpenNewClientUrl, false); #endif } else { uint localCrc = FileHelper.GetFileCrc(ResourceManager.DataPath + "ResourceList.ab"); if (crc != localCrc) { _resourceCrc = crc; ChangeCurrentUpdateState(UpdateState.DownloadResourceList); } else { ChangeCurrentUpdateState(UpdateState.CheckLoacalResource); } } }); }
void DownloadPatchConfig() { string url = _patchUrl + "patchs.txt"; string savepath = Application.persistentDataPath + "/patchs.txt"; Downloader.DownloadFiles(new List <DownloadFile>() { new DownloadFile(url, savepath) }, (arg) => { if (!File.Exists(savepath)) { object[] obj = new object[2]; obj[0] = 50000; obj[1] = _versionUpdateTips; _currentProgress.TotalSize = 50000; ChangeCurrentUpdateState(UpdateState.DownloadNewClient, false, obj); } else { string str = File.ReadAllText(savepath); bool find = false; int totalSize = 50000; PatchConfig config = JsonMapper.ToObject <PatchConfig>(str); if (_targetVersion == (int)GetVersionValue(config.newVersion)) { string channelName = ILRuntimeHelper.GetChannelName(); for (int i = 0; i < config.channels.Count; ++i) { var channel = config.channels[i]; if (channelName == channel.name) { totalSize = channel.size_mini; _targetMd5 = GameClient.Instance.BuildSettings.MiniBuild ? channel.md5_mini : channel.md5_all; for (int j = 0; j < channel.patchs.Count; ++j) { var patch = channel.patchs[j]; if (ResourceManager.CodeVersion == GetVersionValue(patch.oldVersion)) { string md5 = FileHelper.GetFileMd5(Application.dataPath); if ((GameClient.Instance.BuildSettings.MiniBuild && md5 == patch.oldmd5_mini) || (!GameClient.Instance.BuildSettings.MiniBuild && md5 == patch.oldmd5_all)) { _patchFileUrl = GameClient.Instance.BuildSettings.MiniBuild ? _patchUrl + patch.patch_mini : _patchUrl + patch.patch_all; totalSize = GameClient.Instance.BuildSettings.MiniBuild ? patch.size_mini : patch.size_all; find = true; } break; } } if (find) { break; } } } } File.Delete(savepath); _currentProgress.TotalSize = totalSize; if (find) { object[] obj = new object[2]; obj[0] = totalSize; obj[1] = _versionUpdateTips; ChangeCurrentUpdateState(UpdateState.DownloadNewClientPatch, false, obj); } else { object[] obj = new object[2]; obj[0] = totalSize; obj[1] = _versionUpdateTips; ChangeCurrentUpdateState(UpdateState.DownloadNewClient, false, obj); } } }); }