NoteCutHapticEffectPatch.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. using System;
  2. using HarmonyLib;
  3. using IPA.Utilities;
  4. using Libraries.HM.HMLib.VR;
  5. namespace BeatSaberTweakers.HapticFeedbackAdjust.HarmonyPatches
  6. {
  7. // void HitNote(SaberType saberType)
  8. [HarmonyPatch(typeof(NoteCutHapticEffect))]
  9. [HarmonyPatch("HitNote")]
  10. [HarmonyPatch(new Type[] { typeof(SaberType) })]
  11. internal static class NoteCutHapticEffectPatch
  12. {
  13. private static readonly HapticPresetSO RumblePreset = new HapticPresetSO
  14. {
  15. _continuous = false,
  16. _duration = 0.14f,
  17. _strength = 1f,
  18. _frequency = 1f,
  19. };
  20. private static readonly AccessTools.FieldRef<NoteCutHapticEffect, HapticFeedbackController> CtlFieldRef = AccessTools.FieldRefAccess<NoteCutHapticEffect, HapticFeedbackController>("_hapticFeedbackController");
  21. private static readonly AccessTools.FieldRef<NoteCutHapticEffect, HapticPresetSO> HapticPresetRef = AccessTools.FieldRefAccess<NoteCutHapticEffect, HapticPresetSO>("_rumblePreset");
  22. static bool Prefix(NoteCutHapticEffect __instance, SaberType saberType)
  23. {
  24. var ctl = CtlFieldRef(__instance);
  25. var hapticPreset = HapticPresetRef(__instance);
  26. Plugin.Logger.Debug("HitNote:" + saberType + ", s:" + hapticPreset._strength + ", d:" + hapticPreset._duration + ", f:" + hapticPreset._frequency);
  27. ctl.PlayHapticFeedback(saberType.Node(), RumblePreset);
  28. return false;
  29. }
  30. }
  31. }