Plugin.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Reflection.Emit;
  6. using BepInEx;
  7. using BepInEx.Logging;
  8. using HarmonyLib;
  9. namespace JoystickTriggerFix
  10. {
  11. [BepInPlugin(PluginInfo.PLUGIN_ID, PluginInfo.PLUGIN_NAME, PluginInfo.PLUGIN_VERSION)]
  12. public class Plugin : BaseUnityPlugin
  13. {
  14. internal static ManualLogSource log;
  15. private void Awake()
  16. {
  17. log = Logger;
  18. Harmony.CreateAndPatchAll(typeof(Plugin));
  19. }
  20. [HarmonyPatch(typeof(ZInput), "AddButton", typeof(string), typeof(string), typeof(bool), typeof(float), typeof(float))]
  21. [HarmonyPrefix]
  22. static void OnAddButton(ref string axis, ref bool inverted)
  23. {
  24. if (axis == "JoyAxis 10")
  25. axis = "JoyAxis 3";
  26. if (axis != "JoyAxis 3")
  27. return;
  28. log.LogInfo($"Inverting {axis}");
  29. inverted = !inverted;
  30. }
  31. [HarmonyPatch(typeof(ZInput), "GetJoyRTrigger")]
  32. [HarmonyTranspiler]
  33. static IEnumerable<CodeInstruction> InvertGetJoyRTrigger(IEnumerable<CodeInstruction> instrs)
  34. {
  35. return new CodeMatcher(instrs)
  36. .MatchForward(false,
  37. new CodeMatch(OpCodes.Ldstr))
  38. .SetOperandAndAdvance("JoyAxis 3")
  39. .InstructionEnumeration();
  40. }
  41. [HarmonyPatch(typeof(ZInput), "GetJoyLTrigger")]
  42. [HarmonyTranspiler]
  43. static IEnumerable<CodeInstruction> InvertGetJoyLTrigger(IEnumerable<CodeInstruction> instrs)
  44. {
  45. return new CodeMatcher(instrs)
  46. .MatchForward(false,
  47. new CodeMatch(OpCodes.Ldstr))
  48. .SetOperandAndAdvance("JoyAxis 6")
  49. .InstructionEnumeration();
  50. }
  51. }
  52. }