예제 #1
0
 public static void setEnabled(Type patchType, bool enabled)
 {
     if (patchType.getAttr <HarmonyPatch>() is HarmonyPatch patch)            // regular harmony patch
     {
         setEnabled(patchType, patch, enabled);
     }
     else if (patchType.checkAttr <PatchClassAttribute>())            // optional patch class
     {
         HarmonyHelper.patch(patchType, enabled);
     }
 }
예제 #2
0
        static void setEnabled(Type patchType, HarmonyPatch patch, bool enabled)
        {
            $"OptionalPatches: setEnabled {patchType} => {enabled}".logDbg();
            var method = patch.info.getTargetMethod();

            if (method == null)
            {
                "OptionalPatches: method is null!".logError();
                return;
            }

            var prefix     = patchType.method("Prefix");
            var postfix    = patchType.method("Postfix");
            var transpiler = patchType.method("Transpiler");

            var patches = HarmonyHelper.getPatchInfo(method);

            bool prefixActive     = patches.isPatchedBy(prefix);
            bool postfixActive    = patches.isPatchedBy(postfix);
            bool transpilerActive = patches.isPatchedBy(transpiler);

            if (enabled)
            {
                if (!prefixActive && !postfixActive && !transpilerActive)
                {
                    HarmonyHelper.patch(method, prefix, postfix, transpiler);
                }
            }
            else
            {
                // need to check if this is actual patches to avoid unnecessary updates in harmony (with transpilers especially)
                if (prefixActive)
                {
                    HarmonyHelper.unpatch(method, prefix);
                }
                if (postfixActive)
                {
                    HarmonyHelper.unpatch(method, postfix);
                }
                if (transpilerActive)
                {
                    HarmonyHelper.unpatch(method, transpiler);
                }
            }
        }
예제 #3
0
        public static void setEnabled(Type patchType, bool val)
        {
            $"OptionalPatches: setEnabled {patchType} => {val}".logDbg();
            if (!(patchType.getAttr <HarmonyPatch>() is HarmonyPatch patch))
            {
                return;
            }

            var method = patch.info.getTargetMethod();

            if (method == null && $"OptionalPatches: method is null!".logError())
            {
                return;
            }

            var prefix     = patchType.method("Prefix");
            var postfix    = patchType.method("Postfix");
            var transpiler = patchType.method("Transpiler");

            var patches = HarmonyHelper.getPatchInfo(method);