Exemplo n.º 1
0
        public List <DynamicMethod> Patch()
        {
            lock (locker)
            {
                var dynamicMethods = new List <DynamicMethod>();
                foreach (var original in originals)
                {
                    if (original == null)
                    {
                        throw new NullReferenceException("original");
                    }

                    var individualPrepareResult = RunMethod <HarmonyPrepare, bool>(true, original);
                    if (individualPrepareResult)
                    {
                        var patchInfo = HarmonySharedState.GetPatchInfo(original);
                        if (patchInfo == null)
                        {
                            patchInfo = new PatchInfo();
                        }

                        PatchFunctions.AddPrefix(patchInfo, instance.Id, prefix);
                        PatchFunctions.AddPostfix(patchInfo, instance.Id, postfix);
                        PatchFunctions.AddTranspiler(patchInfo, instance.Id, transpiler);
                        dynamicMethods.Add(PatchFunctions.UpdateWrapper(original, patchInfo, instance.Id));

                        HarmonySharedState.UpdatePatchInfo(original, patchInfo);

                        RunMethod <HarmonyCleanup>(original);
                    }
                }
                return(dynamicMethods);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 执行Patch
        /// </summary>
        /// <returns></returns>
        public PatchInfoData Patch(PatchFlags flags)
        {
            PatchInfo patchInfo = null;

            lock (locker)
            {
#if RECORD_PATCH_STATE
                patchInfo = HarmonySharedState.GetPatchInfo(original);
                if (patchInfo == null)
                {
                    patchInfo = new PatchInfo();
                }
#endif
                patchInfo = new PatchInfo();

                PatchFunctions.AddPrefix(patchInfo, instance.id, prefix);
                PatchFunctions.AddPostfix(patchInfo, instance.id, postfix);
                PatchFunctions.AddTranspiler(patchInfo, instance.id, transpiler);
                PatchFunctions.UpdateWrapper(original, patchInfo, flags);
#if RECORD_PATCH_STATE
                HarmonySharedState.UpdatePatchInfo(original, patchInfo);
#endif
            }

            return(patchInfo.patchdata);
        }
Exemplo n.º 3
0
        public void Patch()
        {
            var obj = locker;

            lock (obj)
            {
                foreach (var methodBase in originals)
                {
                    if (methodBase == null)
                    {
                        throw new NullReferenceException("original");
                    }
                    if (RunMethod <HarmonyPrepare, bool>(true, methodBase))
                    {
                        var patchInfo = HarmonySharedState.GetPatchInfo(methodBase) ?? new PatchInfo();
                        PatchFunctions.AddPrefix(patchInfo, instance.Id, prefix);
                        PatchFunctions.AddPostfix(patchInfo, instance.Id, postfix);
                        PatchFunctions.AddTranspiler(patchInfo, instance.Id, transpiler);
                        PatchFunctions.UpdateWrapper(methodBase, patchInfo, instance.Id);
                        HarmonySharedState.UpdatePatchInfo(methodBase, patchInfo);
                        RunMethod <HarmonyCleanup>(methodBase);
                    }
                }
            }
        }
Exemplo n.º 4
0
        public void Patch()
        {
            lock (locker)
            {
                var patchInfo = HarmonySharedState.GetPatchInfo(original);
                if (patchInfo == null)
                {
                    patchInfo = new PatchInfo();
                }

                PatchFunctions.AddPrefix(patchInfo, instance.Id, prefix);
                PatchFunctions.AddPostfix(patchInfo, instance.Id, postfix);
                PatchFunctions.AddTranspiler(patchInfo, instance.Id, transpiler);

                PatchHandler.Get(original).Apply();
            }
        }
Exemplo n.º 5
0
        public List <DynamicMethod> Patch()
        {
            lock (locker)
            {
                var dynamicMethods = new List <DynamicMethod>();
                foreach (var original in originals)
                {
                    if (original == null)
                    {
                        throw new NullReferenceException("original");
                    }

                    if ((original.DeclaringType.Assembly.GetCustomAttributes(typeof(HarmonyShield), false).Count() > 0) ||
                        (original.DeclaringType.GetCustomAttributes(typeof(HarmonyShield), false).Count() > 0) ||
                        (original.GetCustomAttributes(typeof(HarmonyShield), false).Count() > 0))
                    {
                        continue;
                    }

                    if (MelonDebug.IsEnabled() && UnhollowerSupport.IsGeneratedAssemblyType(original.DeclaringType))
                    {
                        WarnIfTargetMethodInlined(original);
                    }

                    var individualPrepareResult = RunMethod <HarmonyPrepare, bool>(true, original);
                    if (individualPrepareResult)
                    {
                        var patchInfo = HarmonySharedState.GetPatchInfo(original);
                        if (patchInfo == null)
                        {
                            patchInfo = new PatchInfo();
                        }

                        PatchFunctions.AddPrefix(patchInfo, instance.Id, prefix);
                        PatchFunctions.AddPostfix(patchInfo, instance.Id, postfix);
                        PatchFunctions.AddTranspiler(patchInfo, instance.Id, transpiler);
                        dynamicMethods.Add(PatchFunctions.UpdateWrapper(original, patchInfo, instance.Id));

                        HarmonySharedState.UpdatePatchInfo(original, patchInfo);

                        RunMethod <HarmonyCleanup>(original);
                    }
                }
                return(dynamicMethods);
            }
        }
Exemplo n.º 6
0
        public void Patch()
        {
            lock (locker)
            {
                var patchInfo = HarmonySharedState.GetPatchInfo(original);
                if (patchInfo == null)
                {
                    patchInfo = new PatchInfo();
                }

                PatchFunctions.AddPrefix(patchInfo, instance.Id, prefix);
                PatchFunctions.AddPostfix(patchInfo, instance.Id, postfix);
                PatchFunctions.AddTranspiler(patchInfo, instance.Id, transpiler);
                PatchFunctions.UpdateWrapper(original, patchInfo);

                HarmonySharedState.UpdatePatchInfo(original, patchInfo);
            }
        }