using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Logging; using FuckOffKBM; using HarmonyLib; using Microsoft.CodeAnalysis; using TrinketAndBindingFramework; using UnityEngine; using UnityEngine.InputSystem; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("OnlyGamepad")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyFileVersion("0.3.0.0")] [assembly: AssemblyInformationalVersion("0.3.0")] [assembly: AssemblyProduct("OnlyGamepad")] [assembly: AssemblyTitle("OnlyGamepad")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("0.3.0.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } [Serializable] public class PerkModule_InputLock : PerkModule { public override void Initialize(Perk p) { ((PerkModule)this).Initialize(p); Patch_InputManager_TrafficControl.OnlyGamepad = true; Plugin.Logger.LogInfo((object)"Input locked to Gamepad by Perk Module"); } public override void AddModule(int amount = 1, bool firstTime = true) { ((PerkModule)this).AddModule(amount, firstTime); Patch_InputManager_TrafficControl.OnlyGamepad = true; } public override void OnDestroy(Perk p) { ((PerkModule)this).OnDestroy(p); Patch_InputManager_TrafficControl.OnlyGamepad = false; Plugin.Logger.LogInfo((object)"Input lock released"); } } namespace OnlyGamepad.lib { internal class Patch { [HarmonyPatch(typeof(CL_AssetManager), "GetPerkAsset")] public class Patch_CL_AssetManager_GetPerkAsset { private static void Postfix(string id, ref Perk __result) { if ((Object)(object)__result == (Object)null && Plugin.PerkDictionary.ContainsKey(id)) { __result = Plugin.PerkDictionary[id]; } } } } } namespace FuckOffKBM { [HarmonyPatch(typeof(InputManager), "UpdateInputs")] public class Patch_InputManager_TrafficControl { public static bool OnlyGamepad; private static bool Prefix(InputManager __instance) { //IL_01a8: Unknown result type (might be due to invalid IL or missing references) //IL_01ad: Unknown result type (might be due to invalid IL or missing references) //IL_0176: Unknown result type (might be due to invalid IL or missing references) //IL_017b: Unknown result type (might be due to invalid IL or missing references) List value = Traverse.Create((object)__instance).Field>("buttonInputs").Value; List value2 = Traverse.Create((object)__instance).Field>("vectorInputs").Value; if (value == null) { return true; } if (ShouldBlockKBM()) { foreach (ButtonInput item in value) { if (item.name == "Pause") { item.Pressed = item.action.IsPressed(); item.Down = item.action.WasPressedThisFrame(); item.Up = item.action.WasReleasedThisFrame(); } else if (IsFromKBM(item.action)) { item.Pressed = false; item.Down = false; item.Up = false; } else { item.Pressed = item.action.IsPressed(); item.Down = item.action.WasPressedThisFrame(); item.Up = item.action.WasReleasedThisFrame(); } } foreach (VectorInput item2 in value2) { if (IsFromKBM(item2.action)) { item2.vector = Vector2.zero; item2.Pressed = false; item2.Down = false; item2.Up = false; } else { item2.vector = item2.action.ReadValue(); item2.Pressed = item2.action.IsPressed(); item2.Down = item2.action.WasPressedThisFrame(); item2.Up = item2.action.WasReleasedThisFrame(); } } return false; } return true; } private static bool ShouldBlockKBM() { if (!OnlyGamepad) { return false; } if ((Object)(object)CL_GameManager.gMan == (Object)null) { return false; } if (CL_GameManager.isDead() || CL_GameManager.gMan.isPaused) { return false; } return true; } private static bool IsFromKBM(InputAction action) { if (action == null || action.activeControl == null) { return false; } InputDevice device = action.activeControl.device; return device is Keyboard || device is Mouse; } } [BepInPlugin("shenxl.OnlyGamepad", "OnlyGamepad", "0.3.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] public class Plugin : BaseUnityPlugin { public const string ModGUID = "shenxl.OnlyGamepad"; public const string ModName = "OnlyGamepad"; public const string ModVersion = "0.3.0"; public static Sprite BindingIcon; public static Dictionary PerkDictionary = new Dictionary(); private Harmony _harmony; internal static ManualLogSource Logger; private void Awake() { //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Expected O, but got Unknown //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_008f: Unknown result type (might be due to invalid IL or missing references) //IL_0092: Unknown result type (might be due to invalid IL or missing references) //IL_0097: Unknown result type (might be due to invalid IL or missing references) //IL_0099: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_00ad: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: Unknown result type (might be due to invalid IL or missing references) //IL_00bb: Unknown result type (might be due to invalid IL or missing references) //IL_00c2: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: Unknown result type (might be due to invalid IL or missing references) //IL_00e0: Unknown result type (might be due to invalid IL or missing references) //IL_00ec: Expected O, but got Unknown Logger = ((BaseUnityPlugin)this).Logger; _harmony = new Harmony("shenxl.OnlyGamepad"); _harmony.PatchAll(); BindingIcon = LoadSprite(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "icon.png", makePersistent: true); Perk val = new Perk { id = "Perk_Binding_OnlyGamepad", title = "Only Gamepad", tags = new List { "binding" }, description = "(-) Fuck Off Keyboard And Mouse", flavorText = "", perkType = (PerkType)9, spawnPool = (PerkPool)2, sortingCategory = -10, canStack = false, stackMax = 1, cost = 0, useBuff = false, useBaseBuff = false, modules = new List { (PerkModule)(object)new PerkModule_InputLock() }, icon = BindingIcon }; PerkDictionary[val.id] = val; TrinketRegistry.RegisterBinding("Perk_Binding_OnlyGamepad", "Only Gamepad", "(-) Fuck Off Keyboard And Mouse", "", 1, 2f, 0f, BindingIcon, (Func>)null, (Func>)PerksToGrantFactory, 0); Logger.LogInfo((object)"Plugin shenxl.OnlyGamepad is loaded!"); static List PerksToGrantFactory() { return PerkDictionary.Values.ToList(); } } public static Sprite LoadSprite(string dir, string filename, bool makePersistent = false) { //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Expected O, but got Unknown //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00b1: Unknown result type (might be due to invalid IL or missing references) string text = Path.Combine(dir, filename); if (!File.Exists(text)) { Logger.LogError((object)("icon not found: " + text)); return null; } try { byte[] array = File.ReadAllBytes(text); Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false); ((Object)val).name = filename + "_Texture"; if (!ImageConversion.LoadImage(val, array)) { return null; } ((Texture)val).filterMode = (FilterMode)0; ((Texture)val).wrapMode = (TextureWrapMode)1; Sprite val2 = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f), 100f); ((Object)val2).name = filename; if (makePersistent) { Object.DontDestroyOnLoad((Object)(object)val2); Object.DontDestroyOnLoad((Object)(object)val); } return val2; } catch (Exception ex) { Logger.LogError((object)("icon load failed for " + filename + ": " + ex.Message)); return null; } } } }