123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- 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<CodeInstruction> InvertGetJoyRTrigger(IEnumerable<CodeInstruction> instrs)
- {
- return new CodeMatcher(instrs)
- .MatchForward(false,
- new CodeMatch(OpCodes.Ldstr))
- .SetOperandAndAdvance("JoyAxis 3")
- .InstructionEnumeration();
- }
-
- [HarmonyPatch(typeof(ZInput), "GetJoyLTrigger")]
- [HarmonyTranspiler]
- static IEnumerable<CodeInstruction> InvertGetJoyLTrigger(IEnumerable<CodeInstruction> instrs)
- {
- return new CodeMatcher(instrs)
- .MatchForward(false,
- new CodeMatch(OpCodes.Ldstr))
- .SetOperandAndAdvance("JoyAxis 6")
- .InstructionEnumeration();
- }
- }
- }
|