コード例 #1
0
ファイル: ILFixEditor.cs プロジェクト: MF-JIN/test
        //生成特定平台的patch
        public static void GenPlatformPatch(BuildTargetGroup group, BuildTarget buildTarget,
                                            string corePath = IFixCoreDllPath)
        {
#if UNITY_2018_3_OR_NEWER
            RuntimePlatform           rplatform;
            ScriptCompilationSettings scriptCompilationSettings = new ScriptCompilationSettings()
            {
                group  = group,
                target = buildTarget,
            };

            var patchOutputDir = $"Assets/AppRes/ifix/{IFixCfg.TargetName(buildTarget)}/";
            Directory.CreateDirectory(patchOutputDir);

            var assemblyOutputDir = $"obj/{IFixCfg.TargetName(buildTarget)}/";
            Directory.CreateDirectory(assemblyOutputDir);
            ScriptCompilationResult scriptCompilationResult = PlayerBuildInterface.CompilePlayerScripts(scriptCompilationSettings, assemblyOutputDir);

            foreach (var assembly in injectAssemblys)
            {
                GenPatch(assembly, string.Format("{0}/{1}.dll", assemblyOutputDir, assembly),
                         IFixCoreDllPath, string.Format("{0}{1}.patch.ifix", patchOutputDir, assembly));
            }
#else
            throw new NotImplementedException();
            //var compileArgFile = "Temp/ifix/unity_" + platform + "_compile_argument";
            //var tmpDllPath = "Temp/ifix/Assembly-CSharp.dll";
            //File.WriteAllText(compileArgFile, getCompileArguments(platform, tmpDllPath));
            //先编译dll到Temp目录下
            //Compile(compileArgFile);
            //对编译后的dll生成补丁
            //GenPatch("Assembly-CSharp", tmpDllPath, corePath, patchPath);

            //File.Delete(compileArgFile);
            //File.Delete(tmpDllPath);
            //File.Delete(tmpDllPath + ".mdb");
#endif
        }
コード例 #2
0
ファイル: ILFixEditor.cs プロジェクト: MF-JIN/test
        public static void Patch()
        {
            if (Application.isPlaying)
            {
                return;
            }

            var patchDir = PatchOutputPath;

            if (!Directory.Exists(patchDir))
            {
                Directory.CreateDirectory(patchDir);
            }
            var ts = IFixCfg.IFixTypes;

            foreach (var assembly in injectAssemblys)
            {
                var patchPath = patchDir + $"{assembly}.patch.ifix";
                GenPatch(assembly, string.Format("./Library/ScriptAssemblies/{0}.dll", assembly),
                         IFixCoreDllPath, patchPath);
                UnityEngine.Debug.Log($"Fix:{assembly}-{IFixCfg.PlatformName()}");
            }
        }
コード例 #3
0
ファイル: ILFixEditor.cs プロジェクト: MF-JIN/test
        /// <summary>
        /// 生成patch
        /// </summary>
        /// <param name="assembly">程序集名,用来过滤配置</param>
        /// <param name="assemblyCSharpPath">程序集路径</param>
        /// <param name="corePath">IFix.Core.dll所在路径</param>
        /// <param name="patchPath">生成的patch的保存路径</param>
        public static void GenPatch(string assembly,
                                    string assemblyCSharpPath = "./Library/ScriptAssemblies/Assembly-CSharp.dll",
                                    string corePath           = IFixCoreDllPath,
                                    string patchPath          = "Assembly-CSharp.patch.ifix")
        {
            var patchMethods = Configure.GetTagMethods(typeof(PatchAttribute), assembly).ToList();

            if (patchMethods.Count == 0)
            {
                UnityEngine.Debug.Log($"not patchMethods assembly: {assembly}");
            }

            var genericMethod = patchMethods.FirstOrDefault(m => hasGenericParameter(m));

            if (genericMethod != null)
            {
                throw new InvalidDataException("not support generic method: " + genericMethod);
            }

            var newMethods    = Configure.GetTagMethods(typeof(InterpretAttribute), assembly).ToList();
            var newFields     = Configure.GetTagFields(typeof(InterpretAttribute), assembly).ToList();
            var newProperties = Configure.GetTagProperties(typeof(InterpretAttribute), assembly).ToList();
            var newClasses    = Configure.GetTagClasses(typeof(InterpretAttribute), assembly).ToList();

            genericMethod = newMethods.FirstOrDefault(m => hasGenericParameter(m));
            if (genericMethod != null)
            {
                throw new InvalidDataException("not support generic method: " + genericMethod);
            }

            var processCfgPath = $"./Assets/IFix/Editor/{assembly}-{IFixCfg.PlatformName()}.icfg";

            using (BinaryWriter writer = new BinaryWriter(new FileStream(processCfgPath, FileMode.Create,
                                                                         FileAccess.Write)))
            {
                writeMethods(writer, patchMethods);
                writeMethods(writer, newMethods);
                writeFields(writer, newFields);
                writeProperties(writer, newProperties);
                writeClasses(writer, newClasses);
            }

            List <string> args = new List <string>()
            {
                "-patch", corePath, assemblyCSharpPath, "null",
                processCfgPath, patchPath
            };

            foreach (var path in
                     (from asm in AppDomain.CurrentDomain.GetAssemblies()
                      select Path.GetDirectoryName(asm.ManifestModule.FullyQualifiedName)).Distinct())
            {
                try
                {
                    //UnityEngine.Debug.Log("searchPath:" + path);
                    args.Add(path);
                }
                catch { }
            }

            CallIFix(args);

            // File.Delete(processCfgPath);

            AssetDatabase.Refresh();
        }