Added Hori Taiko Drum support
This commit is contained in:
parent
0800f7bfc5
commit
051642c848
@ -16,6 +16,8 @@ namespace TakoTako
|
||||
public ConfigEntry<bool> ConfigDisableScreenChangeOnFocus;
|
||||
public ConfigEntry<bool> ConfigFixSignInScreen;
|
||||
public ConfigEntry<bool> ConfigEnableCustomSongs;
|
||||
public ConfigEntry<bool> ConfigEnableTaikoDrumSupport;
|
||||
public ConfigEntry<bool> ConfigTaikoDrumUseNintendoLayout;
|
||||
|
||||
public ConfigEntry<string> ConfigSongDirectory;
|
||||
public ConfigEntry<bool> ConfigSaveEnabled;
|
||||
@ -89,6 +91,16 @@ namespace TakoTako
|
||||
"DisableScreenChangeOnFocus",
|
||||
false,
|
||||
"When focusing this wont do anything jank, I thnk");
|
||||
|
||||
ConfigEnableTaikoDrumSupport = Config.Bind("Controller.TaikoDrum",
|
||||
"ConfigEnableTaikoDrumSupport",
|
||||
true,
|
||||
"This will enable support for Taiko drums, current tested with official Hori Drum");
|
||||
|
||||
ConfigTaikoDrumUseNintendoLayout = Config.Bind("Controller.TaikoDrum",
|
||||
"ConfigTaikoDrumUseNintendoLayout",
|
||||
false,
|
||||
"This will use the Nintendo layout YX/BA for the Hori Taiko Drum");
|
||||
}
|
||||
|
||||
private void SetupHarmony()
|
||||
@ -105,6 +117,9 @@ namespace TakoTako
|
||||
if (ConfigDisableScreenChangeOnFocus.Value)
|
||||
_harmony.PatchAll(typeof(DisableScreenChangeOnFocus));
|
||||
|
||||
if (ConfigEnableTaikoDrumSupport.Value)
|
||||
_harmony.PatchAll(typeof(TaikoDrumSupport));
|
||||
|
||||
if (ConfigEnableCustomSongs.Value)
|
||||
{
|
||||
_harmony.PatchAll(typeof(MusicPatch));
|
||||
@ -117,4 +132,4 @@ namespace TakoTako
|
||||
StartCoroutine(enumerator);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
153
TakoTako/TaikoDrumSupport.cs
Normal file
153
TakoTako/TaikoDrumSupport.cs
Normal file
@ -0,0 +1,153 @@
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using HarmonyLib;
|
||||
using UnityEngine;
|
||||
|
||||
namespace TakoTako;
|
||||
|
||||
[HarmonyPatch]
|
||||
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
||||
[SuppressMessage("Member Access", "Publicizer001:Accessing a member that was not originally public")]
|
||||
public class TaikoDrumSupport
|
||||
{
|
||||
private const float analogThreshold = 0.333f;
|
||||
|
||||
[HarmonyPatch(typeof(ControllerManager), "GetAxis")]
|
||||
[HarmonyPostfix]
|
||||
private static void GetAxis_Postfix(ControllerManager __instance, ref float __result, ControllerManager.ControllerPlayerNo controllerPlayerNo, ControllerManager.Axes axis)
|
||||
{
|
||||
int controllerIndex = __instance.GetContollersIndex(controllerPlayerNo);
|
||||
if (controllerIndex <= 0 || !__instance.Controllers[controllerIndex].joystickName.Contains("Taiko"))
|
||||
return;
|
||||
|
||||
var prefix = $"J{controllerIndex - 1}";
|
||||
switch (axis)
|
||||
{
|
||||
case ControllerManager.Axes.L_Horizontal:
|
||||
{
|
||||
__result = Input.GetAxis($"{prefix}H3");
|
||||
break;
|
||||
}
|
||||
case ControllerManager.Axes.L_Vertical:
|
||||
{
|
||||
__result = Input.GetAxis($"{prefix}V3");
|
||||
break;
|
||||
}
|
||||
case ControllerManager.Axes.D_Right:
|
||||
{
|
||||
var axisValue = Input.GetAxis($"{prefix}H3");
|
||||
if (axisValue > 0)
|
||||
__result = axisValue;
|
||||
break;
|
||||
}
|
||||
case ControllerManager.Axes.D_Left:
|
||||
{
|
||||
var axisValue = Input.GetAxis($"{prefix}H3");
|
||||
if (axisValue < 0)
|
||||
__result = -axisValue;
|
||||
break;
|
||||
}
|
||||
case ControllerManager.Axes.D_Up:
|
||||
{
|
||||
var axisValue = Input.GetAxis($"{prefix}V3");
|
||||
if (axisValue > 0)
|
||||
__result = axisValue;
|
||||
break;
|
||||
}
|
||||
case ControllerManager.Axes.D_Down:
|
||||
{
|
||||
var axisValue = Input.GetAxis($"{prefix}V3");
|
||||
if (axisValue < 0)
|
||||
__result = -axisValue;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(ControllerManager), "GetButtonDown")]
|
||||
[HarmonyPostfix]
|
||||
private static void GetButtonDown_Postfix(ControllerManager __instance, ref bool __result, ControllerManager.ControllerPlayerNo controllerPlayerNo, ControllerManager.Buttons btn)
|
||||
{
|
||||
int controllerIndex = __instance.GetContollersIndex(controllerPlayerNo);
|
||||
if (controllerIndex <= 0 || !__instance.Controllers[controllerIndex].joystickName.Contains("Taiko"))
|
||||
return;
|
||||
|
||||
var prefix = $"J{controllerIndex}";
|
||||
var previous = __instance.prevButtons[(int) (controllerPlayerNo - 1), (int) btn];
|
||||
|
||||
__result = btn switch
|
||||
{
|
||||
ControllerManager.Buttons.D_Right => Input.GetAxis($"{prefix}H3") > analogThreshold && !previous,
|
||||
ControllerManager.Buttons.D_Left => Input.GetAxis($"{prefix}H3") < -analogThreshold && !previous,
|
||||
ControllerManager.Buttons.D_Up => Input.GetAxis($"{prefix}V3") > analogThreshold && !previous,
|
||||
ControllerManager.Buttons.D_Down => Input.GetAxis($"{prefix}V3") < -analogThreshold && !previous || Input.GetButtonDown($"{prefix}B10"),
|
||||
_ => RunMethodWithButton(btn, controllerIndex, Input.GetButtonDown)
|
||||
};
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(ControllerManager), "GetButton")]
|
||||
[HarmonyPostfix]
|
||||
private static void GetButton_Postfix(ControllerManager __instance, ref bool __result, ControllerManager.ControllerPlayerNo controllerPlayerNo, ControllerManager.Buttons btn)
|
||||
{
|
||||
int controllerIndex = __instance.GetContollersIndex(controllerPlayerNo);
|
||||
if (controllerIndex <= 0 || !__instance.Controllers[controllerIndex].joystickName.Contains("Taiko"))
|
||||
return;
|
||||
|
||||
var prefix = $"J{controllerIndex}";
|
||||
|
||||
__result = btn switch
|
||||
{
|
||||
ControllerManager.Buttons.D_Right => Input.GetAxis($"{prefix}H3") > analogThreshold,
|
||||
ControllerManager.Buttons.D_Left => Input.GetAxis($"{prefix}H3") < -analogThreshold,
|
||||
ControllerManager.Buttons.D_Up => Input.GetAxis($"{prefix}V3") > analogThreshold,
|
||||
ControllerManager.Buttons.D_Down => Input.GetAxis($"{prefix}V3") < -analogThreshold || Input.GetButton($"{prefix}B10"),
|
||||
_ => RunMethodWithButton(btn, controllerIndex, Input.GetButton)
|
||||
};
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(ControllerManager), "GetButtonUp")]
|
||||
[HarmonyPostfix]
|
||||
private static void GetButtonUp_Postfix(ControllerManager __instance, ref bool __result, ControllerManager.ControllerPlayerNo controllerPlayerNo, ControllerManager.Buttons btn)
|
||||
{
|
||||
int controllerIndex = __instance.GetContollersIndex(controllerPlayerNo);
|
||||
if (controllerIndex <= 0 || !__instance.Controllers[controllerIndex].joystickName.Contains("Taiko"))
|
||||
return;
|
||||
|
||||
var prefix = $"J{controllerIndex}";
|
||||
var previous = __instance.prevButtons[(int) (controllerPlayerNo - 1), (int) btn];
|
||||
|
||||
__result = btn switch
|
||||
{
|
||||
ControllerManager.Buttons.D_Right => Input.GetAxis($"{prefix}H3") < analogThreshold && previous,
|
||||
ControllerManager.Buttons.D_Left => Input.GetAxis($"{prefix}H3") > -analogThreshold && previous,
|
||||
ControllerManager.Buttons.D_Up => Input.GetAxis($"{prefix}V3") < analogThreshold && previous,
|
||||
ControllerManager.Buttons.D_Down => (Input.GetAxis($"{prefix}V3") > -analogThreshold && previous) || Input.GetButtonUp($"{prefix}B10"),
|
||||
_ => RunMethodWithButton(btn, controllerIndex, Input.GetButtonUp)
|
||||
};
|
||||
}
|
||||
|
||||
private static bool RunMethodWithButton(ControllerManager.Buttons button, int controllerIndex, Func<string, bool> function)
|
||||
{
|
||||
var nintendoLayout = Plugin.Instance.ConfigTaikoDrumUseNintendoLayout.Value;
|
||||
var prefix = $"J{controllerIndex}";
|
||||
|
||||
return button switch
|
||||
{
|
||||
ControllerManager.Buttons.Menu1 => function($"{prefix}B13"),
|
||||
ControllerManager.Buttons.Menu2 => function($"{prefix}B12"),
|
||||
ControllerManager.Buttons.A => (nintendoLayout ? function($"{prefix}B2") : function($"{prefix}B1")) || function($"{prefix}B11"),
|
||||
ControllerManager.Buttons.B => (nintendoLayout ? function($"{prefix}B1") : function($"{prefix}B2")),
|
||||
ControllerManager.Buttons.X => nintendoLayout ? function($"{prefix}B3") : function($"{prefix}B0"),
|
||||
ControllerManager.Buttons.Y => nintendoLayout ? function($"{prefix}B0") : function($"{prefix}B3"),
|
||||
ControllerManager.Buttons.L1 => function($"{prefix}B4") || function($"{prefix}B6"),
|
||||
ControllerManager.Buttons.L2 => function($"{prefix}B6"),
|
||||
ControllerManager.Buttons.R1 => function($"{prefix}B5") || function($"{prefix}B7"),
|
||||
ControllerManager.Buttons.R2 => function($"{prefix}B7"),
|
||||
ControllerManager.Buttons.L3 => function($"{prefix}B10"),
|
||||
ControllerManager.Buttons.R3 => function($"{prefix}B11"),
|
||||
ControllerManager.Buttons.Start => function($"{prefix}B9"),
|
||||
ControllerManager.Buttons.Back => function($"{prefix}B8"),
|
||||
_ => false
|
||||
};
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user