Esempio n. 1
0
        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()}");
            }
        }
Esempio n. 2
0
        /// <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();
        }