Skip to content

Commit

Permalink
Support games with disabled Input class
Browse files Browse the repository at this point in the history
  • Loading branch information
ManlyMarco committed Jul 16, 2022
1 parent eb6dd0d commit 644f0dd
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
4 changes: 2 additions & 2 deletions ConfigurationManager/ConfigurationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -263,15 +263,15 @@ private void OnGUI()
SetUnlockCursor(0, true);

if (GUI.Button(_screenRect, string.Empty, GUI.skin.box) &&
!SettingWindowRect.Contains(Input.mousePosition))
!SettingWindowRect.Contains(UnityInput.Current.mousePosition))
DisplayingWindow = false;

GUI.Box(SettingWindowRect, GUIContent.none, new GUIStyle { normal = new GUIStyleState { background = WindowBackground } });

GUILayout.Window(WindowId, SettingWindowRect, SettingsWindow, "Plugin / mod settings");

if (!SettingFieldDrawer.SettingKeyboardShortcut)
Input.ResetInputAxes();
UnityInput.Current.ResetInputAxes();
}
}

Expand Down
8 changes: 6 additions & 2 deletions ConfigurationManager/ConfigurationManager.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,16 @@
<DocumentationFile>..\bin\BepInEx\plugins\ConfigurationManager.xml</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="BepInEx, Version=5.4.15.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\BepInEx.BaseLib.5.4.15\lib\net35\BepInEx.dll</HintPath>
<Reference Include="BepInEx, Version=5.4.20.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\BepInEx.BaseLib.5.4.20\lib\net35\BepInEx.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="Unity.InputSystem, Version=1.5.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Unity.InputSystem.1.5.0\lib\net35\Unity.InputSystem.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\UnityEngine.5.6.1\lib\net35\UnityEngine.dll</HintPath>
<Private>False</Private>
Expand Down
9 changes: 6 additions & 3 deletions ConfigurationManager/SettingFieldDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
using System.ComponentModel;
using System.Globalization;
using System.Linq;
using BepInEx;
using UnityEngine;

namespace ConfigurationManager
{
internal class SettingFieldDrawer
{
private static readonly IEnumerable<KeyCode> _keysToCheck = BepInEx.Configuration.KeyboardShortcut.AllKeyCodes.Except(new[] { KeyCode.Mouse0, KeyCode.None }).ToArray();
private static IEnumerable<KeyCode> _keysToCheck;

public static Dictionary<Type, Action<SettingEntryBase>> SettingDrawHandlers { get; }

Expand Down Expand Up @@ -337,11 +338,13 @@ private static void DrawKeyboardShortcut(SettingEntryBase setting)
GUILayout.Label("Press any key combination", GUILayout.ExpandWidth(true));
GUIUtility.keyboardControl = -1;

var input = UnityInput.Current;
if (_keysToCheck == null) _keysToCheck = input.SupportedKeyCodes.Except(new[] { KeyCode.Mouse0, KeyCode.None }).ToArray();
foreach (var key in _keysToCheck)
{
if (Input.GetKeyUp(key))
if (input.GetKeyUp(key))
{
setting.Set(new BepInEx.Configuration.KeyboardShortcut(key, _keysToCheck.Where(Input.GetKey).ToArray()));
setting.Set(new BepInEx.Configuration.KeyboardShortcut(key, _keysToCheck.Where(input.GetKey).ToArray()));
_currentKeyboardShortcutToSet = null;
break;
}
Expand Down
3 changes: 2 additions & 1 deletion ConfigurationManager/packages.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="BepInEx.Analyzers" version="1.0.8" targetFramework="net35" developmentDependency="true" />
<package id="BepInEx.BaseLib" version="5.4.15" targetFramework="net35" developmentDependency="true" />
<package id="BepInEx.BaseLib" version="5.4.20" targetFramework="net35" developmentDependency="true" />
<package id="Unity.InputSystem" version="1.5.0" targetFramework="net35" />
<package id="UnityEngine" version="5.6.1" targetFramework="net35" developmentDependency="true" />
</packages>

0 comments on commit 644f0dd

Please sign in to comment.
  翻译: