Skip to content

Commit

Permalink
force rewired to fallback to unity input system
Browse files Browse the repository at this point in the history
  • Loading branch information
Eddio0141 committed Sep 25, 2024
1 parent 07482f3 commit 7b5cee6
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
{
Expand All @@ -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}");
}
}
40 changes: 40 additions & 0 deletions UniTAS/Patcher/Implementations/RewiredFix/FallbackToUnityInput.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ public interface IInputSystemState
{
bool HasNewInputSystem { get; }
bool HasOldInputSystem { get; }
}
bool HasRewired { get; }
}

0 comments on commit 7b5cee6

Please sign in to comment.