示例#1
0
        /// <summary>Unpatches patches of a given type and/or Harmony ID</summary>
        /// <param name="type">The <see cref="HarmonyPatchType"/> patch type</param>
        /// <param name="harmonyID">Harmony ID or <c>*</c> for any</param>
        /// <returns>A <see cref="PatchProcessor"/> for chaining calls</returns>
        ///
        public PatchProcessor Unpatch(HarmonyPatchType type, string harmonyID)
        {
            lock (locker)
            {
                var patchInfo = HarmonySharedState.GetPatchInfo(original);
                if (patchInfo == null)
                {
                    patchInfo = new PatchInfo();
                }

                if (type == HarmonyPatchType.All || type == HarmonyPatchType.Prefix)
                {
                    PatchFunctions.RemovePrefix(patchInfo, harmonyID);
                }
                if (type == HarmonyPatchType.All || type == HarmonyPatchType.Postfix)
                {
                    PatchFunctions.RemovePostfix(patchInfo, harmonyID);
                }
                if (type == HarmonyPatchType.All || type == HarmonyPatchType.Transpiler)
                {
                    PatchFunctions.RemoveTranspiler(patchInfo, harmonyID);
                }
                if (type == HarmonyPatchType.All || type == HarmonyPatchType.Finalizer)
                {
                    PatchFunctions.RemoveFinalizer(patchInfo, harmonyID);
                }
                _ = PatchFunctions.UpdateWrapper(original, patchInfo);

                HarmonySharedState.UpdatePatchInfo(original, patchInfo);
                return(this);
            }
        }
示例#2
0
        /// <summary>Unpatches patches of a given type and/or Harmony ID</summary>
        /// <param name="type">The patch type</param>
        /// <param name="harmonyID">Harmony ID or (*) for any</param>
        ///
        public void Unpatch(HarmonyPatchType type, string harmonyID)
        {
            lock (locker)
            {
                foreach (var original in originals)
                {
                    var patchInfo = HarmonySharedState.GetPatchInfo(original);
                    if (patchInfo == null)
                    {
                        patchInfo = new PatchInfo();
                    }

                    if (type == HarmonyPatchType.All || type == HarmonyPatchType.Prefix)
                    {
                        PatchFunctions.RemovePrefix(patchInfo, harmonyID);
                    }
                    if (type == HarmonyPatchType.All || type == HarmonyPatchType.Postfix)
                    {
                        PatchFunctions.RemovePostfix(patchInfo, harmonyID);
                    }
                    if (type == HarmonyPatchType.All || type == HarmonyPatchType.Transpiler)
                    {
                        PatchFunctions.RemoveTranspiler(patchInfo, harmonyID);
                    }
                    if (type == HarmonyPatchType.All || type == HarmonyPatchType.Finalizer)
                    {
                        PatchFunctions.RemoveFinalizer(patchInfo, harmonyID);
                    }
                    PatchFunctions.UpdateWrapper(original, patchInfo, instance.Id);

                    HarmonySharedState.UpdatePatchInfo(original, patchInfo);
                }
            }
        }