Ejemplo n.º 1
0
        List <MethodInfo> BulkPatch(List <MethodBase> originals, ref MethodBase lastOriginal)
        {
            var jobs = new PatchJobs <MethodInfo>();

            for (var i = 0; i < originals.Count; i++)
            {
                lastOriginal = originals[i];
                var job = jobs.GetJob(lastOriginal);
                foreach (var patchMethod in patchMethods)
                {
                    var note = "You cannot combine TargetMethod, TargetMethods or [HarmonyPatchAll] with individual annotations";
                    var info = patchMethod.info;
                    if (info.methodName is object)
                    {
                        throw new ArgumentException($"{note} [{info.methodName}]");
                    }
                    if (info.methodType.HasValue && info.methodType.Value != MethodType.Normal)
                    {
                        throw new ArgumentException($"{note} [{info.methodType}]");
                    }
                    if (info.argumentTypes is object)
                    {
                        throw new ArgumentException($"{note} [{info.argumentTypes.Description()}]");
                    }

                    job.AddPatch(patchMethod);
                }
            }
            foreach (var job in jobs.GetJobs())
            {
                lastOriginal = job.original;
                ProcessPatchJob(job);
            }
            return(jobs.GetReplacements());
        }
Ejemplo n.º 2
0
        List <MethodInfo> PatchWithAttributes()
        {
            var jobs = new PatchJobs <MethodInfo>();

            foreach (var patchMethod in patchMethods)
            {
                var original = patchMethod.info.GetOriginalMethod();
                if (original == null)
                {
                    throw new ArgumentException($"Undefined target method for patch method {patchMethod.info.method.FullDescription()}");
                }

                var job = jobs.GetJob(original);
                job.AddPatch(patchMethod);
            }
            foreach (var job in jobs.GetJobs())
            {
                ProcessPatchJob(job);
            }
            return(jobs.GetReplacements());
        }
Ejemplo n.º 3
0
        List <MethodInfo> BulkPatch()
        {
            var jobs = new PatchJobs <MethodInfo>();

            foreach (var original in bulkOriginals)
            {
                var job = jobs.GetJob(original);
                foreach (var patchMethod in patchMethods)
                {
                    var note = "You cannot combine TargetMethod, TargetMethods or PatchAll with individual annotations";
                    var info = patchMethod.info;
                    if (info.declaringType != null)
                    {
                        throw new ArgumentException($"{note} [{info.declaringType.FullDescription()}]");
                    }
                    if (info.methodName != null)
                    {
                        throw new ArgumentException($"{note} [{info.methodName}]");
                    }
                    if (info.methodType.HasValue && info.methodType.Value != MethodType.Normal)
                    {
                        throw new ArgumentException($"{note} [{info.methodType}]");
                    }
                    if (info.argumentTypes != null)
                    {
                        throw new ArgumentException($"{note} [{info.argumentTypes.Description()}]");
                    }

                    job.AddPatch(patchMethod);
                }
            }
            foreach (var job in jobs.GetJobs())
            {
                ProcessPatchJob(job);
            }
            return(jobs.GetReplacements());
        }