diff --git a/UniTAS/Patcher/Implementations/NewInputSystem/InputSystemOverride.cs b/UniTAS/Patcher/Implementations/NewInputSystem/InputSystemOverride.cs index 124ed564..4508437c 100644 --- a/UniTAS/Patcher/Implementations/NewInputSystem/InputSystemOverride.cs +++ b/UniTAS/Patcher/Implementations/NewInputSystem/InputSystemOverride.cs @@ -27,8 +27,6 @@ public class InputSystemOverride public InputSystemOverride(ILogger logger, InputOverrideDevice[] devices, IInputSystemState newInputSystemExists, IUpdateEvents updateEvents, IVirtualEnvController virtualEnv, IMovieRunner movieRunner) { - logger.LogMessage($"Has unity new input system: {newInputSystemExists.HasNewInputSystem}"); - if (!newInputSystemExists.HasNewInputSystem) return; _logger = logger; diff --git a/UniTAS/Patcher/Implementations/NewInputSystem/InputSystemState.cs b/UniTAS/Patcher/Implementations/NewInputSystem/InputSystemState.cs index a0a59367..08d55e0d 100644 --- a/UniTAS/Patcher/Implementations/NewInputSystem/InputSystemState.cs +++ b/UniTAS/Patcher/Implementations/NewInputSystem/InputSystemState.cs @@ -3,6 +3,7 @@ using UniTAS.Patcher.Interfaces.DependencyInjection; using UniTAS.Patcher.Services; using UniTAS.Patcher.Services.InputSystemOverride; +using UniTAS.Patcher.Services.Logging; using UnityEngine; namespace UniTAS.Patcher.Implementations.NewInputSystem; @@ -12,8 +13,9 @@ public class InputSystemState : IInputSystemState { public bool HasNewInputSystem { get; } public bool HasOldInputSystem { get; } + public bool HasRewired { get; } - public InputSystemState(IPatchReverseInvoker patchReverseInvoker) + public InputSystemState(IPatchReverseInvoker patchReverseInvoker, ILogger logger) { try { @@ -37,5 +39,11 @@ public InputSystemState(IPatchReverseInvoker patchReverseInvoker) { // ignored } + + HasRewired = AccessTools.TypeByName("Rewired.ReInput") != null; + + logger.LogMessage($"Has unity new input system: {HasNewInputSystem}"); + logger.LogMessage($"Has unity old input system: {HasOldInputSystem}"); + logger.LogMessage($"Has rewired input system: {HasRewired}"); } } diff --git a/UniTAS/Patcher/Implementations/RewiredFix/FallbackToUnityInput.cs b/UniTAS/Patcher/Implementations/RewiredFix/FallbackToUnityInput.cs new file mode 100644 index 00000000..39ac2e23 --- /dev/null +++ b/UniTAS/Patcher/Implementations/RewiredFix/FallbackToUnityInput.cs @@ -0,0 +1,40 @@ +using System; +using HarmonyLib; +using UniTAS.Patcher.Interfaces.DependencyInjection; +using UniTAS.Patcher.Services.InputSystemOverride; + +namespace UniTAS.Patcher.Implementations.RewiredFix; + +[Singleton] +[ForceInstantiate] +public class FallbackToUnityInput +{ + public FallbackToUnityInput(IInputSystemState inputSystemState) + { + if (!inputSystemState.HasRewired) return; + + var reInput = AccessTools.TypeByName("Rewired.ReInput"); + + if (reInput == null) + { + throw new Exception("failed to find Rewired.ReInput type, cannot apply fix"); + } + + var configuration = AccessTools.Property(reInput, "configuration")?.GetValue(null, null); + + if (configuration == null) + { + throw new Exception("failed to find Rewired.ReInput.configuration property, cannot apply fix"); + } + + var alwaysUseUnityInput = AccessTools.Property(configuration.GetType(), "alwaysUseUnityInput"); + + if (alwaysUseUnityInput == null) + { + throw new Exception( + "failed to find Rewired.ReInput.configuration.alwaysUseUnityInput property, cannot apply fix"); + } + + alwaysUseUnityInput.SetValue(configuration, true, null); + } +} \ No newline at end of file diff --git a/UniTAS/Patcher/Services/InputSystemOverride/IInputSystemState.cs b/UniTAS/Patcher/Services/InputSystemOverride/IInputSystemState.cs index a20490c9..f45c9b0c 100644 --- a/UniTAS/Patcher/Services/InputSystemOverride/IInputSystemState.cs +++ b/UniTAS/Patcher/Services/InputSystemOverride/IInputSystemState.cs @@ -4,4 +4,5 @@ public interface IInputSystemState { bool HasNewInputSystem { get; } bool HasOldInputSystem { get; } -} + bool HasRewired { get; } +} \ No newline at end of file