-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bb1a2e8
commit bd4b4a2
Showing
4 changed files
with
177 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{31BD63CB-75D9-4AA1-B97D-31F9DE3DDAEE}</ProjectGuid> | ||
<OutputType>Library</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>BepInEx.InputHotkeyBlock</RootNamespace> | ||
<AssemblyName>BepInEx.InputHotkeyBlock</AssemblyName> | ||
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
<Deterministic>true</Deterministic> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<DebugSymbols>false</DebugSymbols> | ||
<DebugType>none</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>..\bin\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<DebugType>none</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>..\bin\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="0Harmony"> | ||
<HintPath>..\lib\0Harmony.dll</HintPath> | ||
<Private>False</Private> | ||
</Reference> | ||
<Reference Include="BepInEx"> | ||
<HintPath>..\lib\BepInEx.dll</HintPath> | ||
<Private>False</Private> | ||
</Reference> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.Xml.Linq" /> | ||
<Reference Include="System.Data.DataSetExtensions" /> | ||
<Reference Include="System.Data" /> | ||
<Reference Include="System.Xml" /> | ||
<Reference Include="UnityEngine"> | ||
<HintPath>..\lib\UnityEngine.dll</HintPath> | ||
<Private>False</Private> | ||
</Reference> | ||
<Reference Include="UnityEngine.UI"> | ||
<HintPath>..\lib\UnityEngine.UI.dll</HintPath> | ||
<Private>False</Private> | ||
</Reference> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="InputHotkeyBlock.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
using HarmonyLib; | ||
using System; | ||
using UnityEngine; | ||
using UnityEngine.EventSystems; | ||
using UnityEngine.UI; | ||
|
||
namespace BepInEx | ||
{ | ||
/// <summary> | ||
/// Intercepts GetKey to prevent plugin hotkeys from firing while typing in an input field | ||
/// </summary> | ||
[BepInPlugin(GUID, PluginName, Version)] | ||
public class InputHotkeyBlock : BaseUnityPlugin | ||
{ | ||
public const string GUID = "BepInEx.InputHotkeyBlock"; | ||
public const string PluginName = "Input Hotkey Block"; | ||
public const string Version = "1.3"; | ||
|
||
private static Type TMPInputFieldType; | ||
|
||
internal void Main() | ||
{ | ||
//Try to get the type of the TextMeshPro InputField, if present | ||
TMPInputFieldType = Type.GetType("TMPro.TMP_InputField, Unity.TextMeshPro"); | ||
if (TMPInputFieldType == null) | ||
TMPInputFieldType = Type.GetType("TMPro.TMP_InputField, TextMeshPro-1.0.55.56.0b12"); | ||
|
||
Harmony.CreateAndPatchAll(typeof(Hooks)); | ||
} | ||
|
||
/// <summary> | ||
/// Check if an input field is selected | ||
/// </summary> | ||
private static bool HotkeyBlock() | ||
{ | ||
//UI elements from some mods | ||
if (GUIUtility.keyboardControl > 0) | ||
return false; | ||
|
||
if (EventSystem.current?.currentSelectedGameObject != null) | ||
{ | ||
//TextMeshPro InputField | ||
if (TMPInputFieldType != null) | ||
if (EventSystem.current.currentSelectedGameObject.GetComponent(TMPInputFieldType) != null) | ||
return false; | ||
|
||
//Other InputFields | ||
if (EventSystem.current.currentSelectedGameObject.GetComponent<InputField>() != null) | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
/// <summary> | ||
/// GetKey hooks. When HotkeyBlock returns false the GetKey functions will be prevented from running. | ||
/// </summary> | ||
internal static partial class Hooks | ||
{ | ||
[HarmonyPrefix, HarmonyPatch(typeof(Input), nameof(Input.GetKey), typeof(KeyCode))] | ||
internal static bool GetKeyCode() => HotkeyBlock(); | ||
[HarmonyPrefix, HarmonyPatch(typeof(Input), nameof(Input.GetKey), typeof(string))] | ||
internal static bool GetKeyString() => HotkeyBlock(); | ||
[HarmonyPrefix, HarmonyPatch(typeof(Input), nameof(Input.GetKeyDown), typeof(KeyCode))] | ||
internal static bool GetKeyDownCode() => HotkeyBlock(); | ||
[HarmonyPrefix, HarmonyPatch(typeof(Input), nameof(Input.GetKeyDown), typeof(string))] | ||
internal static bool GetKeyDownString() => HotkeyBlock(); | ||
[HarmonyPrefix, HarmonyPatch(typeof(Input), nameof(Input.GetKeyUp), typeof(KeyCode))] | ||
internal static bool GetKeyUpCode() => HotkeyBlock(); | ||
[HarmonyPrefix, HarmonyPatch(typeof(Input), nameof(Input.GetKeyUp), typeof(string))] | ||
internal static bool GetKeyUpString() => HotkeyBlock(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System.Reflection; | ||
using System.Runtime.InteropServices; | ||
using static BepInEx.InputHotkeyBlock; | ||
|
||
// General Information about an assembly is controlled through the following | ||
// set of attributes. Change these attribute values to modify the information | ||
// associated with an assembly. | ||
[assembly: AssemblyTitle("BepInEx.InputHotkeyBlock")] | ||
[assembly: AssemblyDescription(PluginName)] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("")] | ||
[assembly: AssemblyProduct("BepInEx.InputHotkeyBlock")] | ||
[assembly: AssemblyCopyright("Copyright © 2020")] | ||
[assembly: AssemblyTrademark("")] | ||
[assembly: AssemblyCulture("")] | ||
|
||
// Setting ComVisible to false makes the types in this assembly not visible | ||
// to COM components. If you need to access a type in this assembly from | ||
// COM, set the ComVisible attribute to true on that type. | ||
[assembly: ComVisible(false)] | ||
|
||
// The following GUID is for the ID of the typelib if this project is exposed to COM | ||
[assembly: Guid("31bd63cb-75d9-4aa1-b97d-31f9de3ddaee")] | ||
|
||
// Version information for an assembly consists of the following four values: | ||
// | ||
// Major Version | ||
// Minor Version | ||
// Build Number | ||
// Revision | ||
// | ||
// You can specify all the values or you can default the Build and Revision Numbers | ||
// by using the '*' as shown below: | ||
// [assembly: AssemblyVersion("1.0.*")] | ||
[assembly: AssemblyVersion(Version)] | ||
[assembly: AssemblyFileVersion(Version)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters