On last post DualShock 4 Unstable on Unity Eiyuden Chronicle: Rising, I fixed the issue with modifying one of binary/assembly files using dnSpy. Next step, lets create non-obstructive solution by using patches/mods and being scallable to other games.
There will be two method to achieve this:
- The patcher or mods to alter original behaviour.
- The injector to attach the mods.
For Unity with C#/Mono, The one of among populars to patch is using Harmony by Andreas Pardeike and to inject is using BepInEx.
TL;DR; Just grab this UnityInputManagerFilter.
Tutorial:
Based on previous post, I only need to avoid the noissy input being registered by AddDevice method. We can utilize the Prefix hoox to AddDevice, filter the device that being provided and return false to reject or true to accept. By returning false on Prefix hook, the original method won’t be called (skipped).

Since the AddDevice method is defined inside internal class UnityEngine.InputSystem.InputManager, it is impossible to use Harmony decorator. Alternatively using reflector via AccessTools is possible and patching with manual-patching.
Get the original method with: AccessTools.Method(AccessTools.TypeByName("UnityEngine.InputSystem.InputManager"), "AddDevice", new[] { typeof(UnityEngine.InputSystem.InputDevice) });
Notice here:
AccessTools.TypeByNamewill return internal class, since It cannot be hinted or referenced fromUnityEngine.InputSystem.- The
AddDeviceis overloaded function (it has more than one signature), the exact parameter list will be required.
Create the Prefix hook function/method with:
static bool PrefixAddDevice(object __instance, UnityEngine.InputSystem.InputDevice device)
Notice here:
- The prefix hook return type is
boolnot void, because we want to control wether the original AddDevice being called after. - The
object __instancemay be omitted, but here the type isobjectsince it is internal class (cannot be hinted). Later on we could access the instance’s methods usingdynamic. (See: Harmony patching-injections)
Then register the prefix hool with: harmony.Patch(original, new HarmonyMethod(prefixPatch));



