Skip to content

Commit

Permalink
Adding KK_InputHotkeyBlock
Browse files Browse the repository at this point in the history
  • Loading branch information
DeathWeasel1337 authored Nov 3, 2018
1 parent 94772a6 commit 3365890
Show file tree
Hide file tree
Showing 4 changed files with 181 additions and 5 deletions.
78 changes: 78 additions & 0 deletions KK_InputHotkeyBlock/KK_InputHotkeyBlock.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using BepInEx;
using Harmony;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
/// <summary>
/// Intercepts GetKey to prevent hotkeys from mods from firing while typing in an input field
/// </summary>
namespace KK_InputHotkeyBlock
{
[BepInPlugin("com.deathweasel.bepinex.inputhotkeyblock", "Input Hotkey Block", "1.0")]
public class KK_InputHotkeyBlock : BaseUnityPlugin
{
void Main()
{
var harmony = HarmonyInstance.Create("com.deathweasel.bepinex.inputhotkeyblock");
harmony.PatchAll(typeof(KK_InputHotkeyBlock));
}
/// <summary>
/// Check if an input field is selected
/// </summary>
private static bool HotkeyBlock
{
get
{
if (GUIUtility.keyboardControl > 0)
return false; //UI elements from some mods
if (EventSystem.current.currentSelectedGameObject != null)
{
if (EventSystem.current.currentSelectedGameObject.name == "InputField")
return false; //Size fields in chara maker which don't have InputField component for some reason
if (EventSystem.current.currentSelectedGameObject.GetComponent<InputField>() != null)
return false; //All other InputFields
}
return true;
}
}
/// <summary>
/// GetKey hooks. When HotkeyBlock returns false the GetKey function will be prevented from running.
/// </summary>
[HarmonyPrefix]
[HarmonyPatch(typeof(Input), nameof(Input.GetKey), new[] { typeof(KeyCode) })]
public static bool GetKeyCode(KeyCode key)
{
return HotkeyBlock;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(Input), nameof(Input.GetKey), new[] { typeof(string) })]
public static bool GetKeyString(string name)
{
return HotkeyBlock;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(Input), nameof(Input.GetKeyDown), new[] { typeof(KeyCode) })]
public static bool GetKeyDownCode(KeyCode key)
{
return HotkeyBlock;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(Input), nameof(Input.GetKeyDown), new[] { typeof(string) })]
public static bool GetKeyDownString(string name)
{
return HotkeyBlock;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(Input), nameof(Input.GetKeyUp), new[] { typeof(KeyCode) })]
public static bool GetKeyUpCode(KeyCode key)
{
return HotkeyBlock;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(Input), nameof(Input.GetKeyUp), new[] { typeof(string) })]
public static bool GetKeyUpString(string name)
{
return HotkeyBlock;
}
}
}
62 changes: 62 additions & 0 deletions KK_InputHotkeyBlock/KK_InputHotkeyBlock.csproj
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>{3557D31C-F7F1-4FC6-BB2F-4360CD50152A}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>KK_InputHotkeyBlock</RootNamespace>
<AssemblyName>KK_InputHotkeyBlock</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>embedded</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\bin\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DebugSymbols>true</DebugSymbols>
</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="KK_InputHotkeyBlock.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
36 changes: 36 additions & 0 deletions KK_InputHotkeyBlock/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// 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("KK_InputHotkeyBlock")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("KK_InputHotkeyBlock")]
[assembly: AssemblyCopyright("Copyright © 2018")]
[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("3557d31c-f7f1-4fc6-bb2f-4360cd50152a")]

// 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("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
10 changes: 5 additions & 5 deletions KK_Plugins.sln
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KK_ReloadCharaListOnChange"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KK_InvisibleBody", "KK_InvisibleBody\KK_InvisibleBody.csproj", "{17B56A36-764F-4670-941A-B0CB76558F37}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KK_InputHotkeyLock", "KK_InputHotkeyLock\KK_InputHotkeyLock.csproj", "{7503D28F-2D8D-4F58-8312-48F18426B1F9}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KK_InputHotkeyBlock", "KK_InputHotkeyBlock\KK_InputHotkeyBlock.csproj", "{3557D31C-F7F1-4FC6-BB2F-4360CD50152A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -59,10 +59,10 @@ Global
{17B56A36-764F-4670-941A-B0CB76558F37}.Debug|Any CPU.Build.0 = Debug|Any CPU
{17B56A36-764F-4670-941A-B0CB76558F37}.Release|Any CPU.ActiveCfg = Release|Any CPU
{17B56A36-764F-4670-941A-B0CB76558F37}.Release|Any CPU.Build.0 = Release|Any CPU
{7503D28F-2D8D-4F58-8312-48F18426B1F9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7503D28F-2D8D-4F58-8312-48F18426B1F9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7503D28F-2D8D-4F58-8312-48F18426B1F9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7503D28F-2D8D-4F58-8312-48F18426B1F9}.Release|Any CPU.Build.0 = Release|Any CPU
{3557D31C-F7F1-4FC6-BB2F-4360CD50152A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3557D31C-F7F1-4FC6-BB2F-4360CD50152A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3557D31C-F7F1-4FC6-BB2F-4360CD50152A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3557D31C-F7F1-4FC6-BB2F-4360CD50152A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down

0 comments on commit 3365890

Please sign in to comment.