コード例 #1
0
ファイル: MethodCopier.cs プロジェクト: yakiu1/Harmony
        internal static List <CodeInstruction> GetInstructions(ILGenerator generator, MethodBase method, int maxTranspilers)
        {
            if (generator == null)
            {
                throw new ArgumentNullException(nameof(generator));
            }
            if (method == null)
            {
                throw new ArgumentNullException(nameof(method));
            }

            var originalVariables     = MethodPatcher.DeclareLocalVariables(generator, method);
            var useStructReturnBuffer = StructReturnBuffer.NeedsFix(method);
            var copier = new MethodCopier(method, generator, originalVariables);

            copier.SetArgumentShift(useStructReturnBuffer);

            var info = Harmony.GetPatchInfo(method);

            if (info != null)
            {
                var sortedTranspilers = PatchFunctions.GetSortedPatchMethods(method, info.Transpilers.ToArray(), false);
                for (var i = 0; i < maxTranspilers && i < sortedTranspilers.Count; i++)
                {
                    copier.AddTranspiler(sortedTranspilers[i]);
                }
            }

            return(copier.Finalize(null, null, out var _));
        }
コード例 #2
0
ファイル: MethodCopier.cs プロジェクト: sudokuhk/Harmony
        internal static List <CodeInstruction> GetInstructions(ILGenerator generator, MethodBase method, int maxTranspilers)
        {
            if (generator == null)
            {
                throw new ArgumentNullException(nameof(generator));
            }
            if (method == null)
            {
                throw new ArgumentNullException(nameof(method));
            }

            var originalVariables     = MethodPatcher.DeclareLocalVariables(generator, method);
            var useStructReturnBuffer = StructReturnBuffer.NeedsFix(method);
            var copier = new MethodCopier(method, generator, originalVariables);

            copier.SetArgumentShift(useStructReturnBuffer);

            var info = Harmony.GetPatchInfo(method);

            if (info != null)
            {
                var sortedTranspilers = PatchFunctions.GetSortedPatchMethods(method, info.Transpilers.ToArray(), false);
                for (var i = 0; i < maxTranspilers && i < sortedTranspilers.Count; i++)
                {
                    copier.AddTranspiler(sortedTranspilers[i]);
                }
            }

            var endLabels = new List <Label>();
            var emitter   = new Emitter(generator, false);

            copier.Finalize(emitter, endLabels, out var hasReturnCode);
            return(emitter.GetInstructions().OrderBy(pair => pair.Key).Select(pair => pair.Value).ToList());
        }
コード例 #3
0
 /// <summary>Sort patch methods by their priority rules</summary>
 /// <param name="original">The original method</param>
 /// <param name="patches">Patches to sort</param>
 /// <returns>The sorted patch methods</returns>
 ///
 public static List <MethodInfo> GetSortedPatchMethods(MethodBase original, Patch[] patches)
 {
     return(PatchFunctions.GetSortedPatchMethods(original, patches, false));
 }