using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Reflection.Emit; using BepInEx; using BepInEx.Logging; using HarmonyLib; namespace JoystickTriggerFix { [BepInPlugin(PluginInfo.PLUGIN_ID, PluginInfo.PLUGIN_NAME, PluginInfo.PLUGIN_VERSION)] public class Plugin : BaseUnityPlugin { internal static ManualLogSource log; private void Awake() { log = Logger; Harmony.CreateAndPatchAll(typeof(Plugin)); } [HarmonyPatch(typeof(ZInput), "AddButton", typeof(string), typeof(string), typeof(bool), typeof(float), typeof(float))] [HarmonyPrefix] static void OnAddButton(ref string axis, ref bool inverted) { if (axis == "JoyAxis 10") axis = "JoyAxis 3"; if (axis != "JoyAxis 3") return; log.LogInfo($"Inverting {axis}"); inverted = !inverted; } [HarmonyPatch(typeof(ZInput), "GetJoyRTrigger")] [HarmonyTranspiler] static IEnumerable InvertGetJoyRTrigger(IEnumerable instrs) { return new CodeMatcher(instrs) .MatchForward(false, new CodeMatch(OpCodes.Ldstr)) .SetOperandAndAdvance("JoyAxis 3") .InstructionEnumeration(); } [HarmonyPatch(typeof(ZInput), "GetJoyLTrigger")] [HarmonyTranspiler] static IEnumerable InvertGetJoyLTrigger(IEnumerable instrs) { return new CodeMatcher(instrs) .MatchForward(false, new CodeMatch(OpCodes.Ldstr)) .SetOperandAndAdvance("JoyAxis 6") .InstructionEnumeration(); } } }