コード例 #1
0
ファイル: CodeTranspiler.cs プロジェクト: ROOT-LOGIN/harmony
 private static IEnumerable ConvertInstructions(TranspilerImpl transpiler, IEnumerable enumerable)
 {
     /*var type = transpiler.GetParameters()
      *        .Select(p => p.ParameterType)
      *        .FirstOrDefault(t => t.IsGenericType && t.GetGenericTypeDefinition().Name.StartsWith("IEnumerable"));*/
     return(ConvertInstructions(typeof(IEnumerable <CodeInstruction>), enumerable));
 }
コード例 #2
0
        public static HarmonyDelegate Clone(MethodInfo source, TranspilerImpl transpiler = null)
        {
            var types = new List <Type>(source.GetParameters().Select(p => p.ParameterType));

            if (source.IsStatic == false)
            {
                types.Insert(0, source.DeclaringType);
            }

            var dm     = new System.Reflection.Emit.DynamicMethod("", source.ReturnType, types.ToArray());
            var copier = new Harmony.ILCopying.MethodCopier(source, dm);

            copier.AddTranspiler(transpiler);
            copier.Emit(null);

            types.Add(source.ReturnType);
            // Use Expression to create Delegate type
            var delegateType = System.Linq.Expressions.Expression.GetDelegateType(types.ToArray());
            var __delegate   = dm.CreateDelegate(delegateType);

            return(new HarmonyDelegate(__delegate));
        }
コード例 #3
0
ファイル: PatchFunctions.cs プロジェクト: ROOT-LOGIN/harmony
        public static void UpdateWrapper(MethodBase original, PatchInfo patchInfo, PatchFlags flags)
        {
            var sortedPrefixes    = GetSortedPatchMethods(original, patchInfo.prefixes);
            var sortedPostfixes   = GetSortedPatchMethods(original, patchInfo.postfixes);
            var sortedTranspilers = GetSortedPatchMethods(original, patchInfo.transpilers).Select(m => TranspilerImpl.From(m)).ToList();

            var replacement = MethodPatcher.CreatePatchedMethod(original, sortedPrefixes, sortedPostfixes, sortedTranspilers, flags);

            if (replacement == null)
            {
                throw new MissingMethodException("Cannot create dynamic replacement for " + original);
            }

            patchInfo.patchdata.orgaddress = Memory.GetMethodStart(original);
            patchInfo.patchdata.jmpaddress = Memory.GetMethodStart(replacement);

            Memory.WriteJump(patchInfo.patchdata.orgaddress, patchInfo.patchdata.jmpaddress, out patchInfo.patchdata.orgbytes, out patchInfo.patchdata.jmpbytes);

            PatchTools.RememberObject(original, replacement);             // no gc for new value + release old value to gc
        }
コード例 #4
0
ファイル: CodeTranspiler.cs プロジェクト: ROOT-LOGIN/harmony
 public void Add(TranspilerImpl transpiler)
 {
     transpilers.Add(transpiler);
 }