using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using Zorro.Settings;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: AssemblyCompany("com.visualerror.inputapi")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1")]
[assembly: AssemblyProduct("InputAPI")]
[assembly: AssemblyTitle("com.visualerror.inputapi")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.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.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
internal sealed class NullableAttribute : Attribute
{
public readonly byte[] NullableFlags;
public NullableAttribute(byte P_0)
{
NullableFlags = new byte[1] { P_0 };
}
public NullableAttribute(byte[] P_0)
{
NullableFlags = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
internal sealed class NullableContextAttribute : Attribute
{
public readonly byte Flag;
public NullableContextAttribute(byte P_0)
{
Flag = P_0;
}
}
[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;
}
}
}
namespace InputAPI
{
public abstract class BaseCWInput : KeyCodeSetting
{
internal InputKey inputKey;
protected bool _disabled;
public void HandleKeys(Player player)
{
if (!_disabled)
{
if (inputKey.GetKeyDown())
{
OnKeyDown(player);
}
else if (inputKey.GetKeyUp())
{
OnKeyUp(player);
}
else if (inputKey.GetKey())
{
OnHeld(player);
}
}
}
protected abstract void OnKeyDown(Player player);
protected abstract void OnKeyUp(Player player);
protected abstract void OnHeld(Player player);
public void Disable()
{
_disabled = true;
}
public void Enable()
{
_disabled = false;
}
public BaseCWInput()
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Expected O, but got Unknown
inputKey = new InputKey();
Plugin._inputs.Add(this);
_disabled = false;
}
}
[BepInPlugin("com.visualerror.inputapi", "InputAPI", "1.0.1")]
[ContentWarningPlugin("com.visualerror.inputapi", "InputAPI", true)]
public class Plugin : BaseUnityPlugin
{
internal static List<BaseCWInput> _inputs = new List<BaseCWInput>();
public static Plugin Instance { get; private set; } = null;
internal static ManualLogSource Logger { get; private set; } = null;
internal static Harmony? Harmony { get; set; }
private void Awake()
{
Logger = ((BaseUnityPlugin)this).Logger;
Instance = this;
Patch();
Logger.LogInfo((object)"com.visualerror.inputapi v1.0.1 has loaded!");
}
internal static void Patch()
{
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Expected O, but got Unknown
if (Harmony == null)
{
Harmony = new Harmony("com.visualerror.inputapi");
}
Logger.LogDebug((object)"Patching...");
Harmony.PatchAll();
Logger.LogDebug((object)"Finished patching!");
}
internal static void Unpatch()
{
Logger.LogDebug((object)"Unpatching...");
Harmony? harmony = Harmony;
if (harmony != null)
{
harmony.UnpatchSelf();
}
Logger.LogDebug((object)"Finished unpatching!");
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "com.visualerror.inputapi";
public const string PLUGIN_NAME = "InputAPI";
public const string PLUGIN_VERSION = "1.0.1";
}
}
namespace InputAPI.Patches
{
[HarmonyPatch(typeof(GlobalInputHandler))]
internal class GlobalInputHandlerPatch
{
[HarmonyPatch("OnCreated")]
[HarmonyPostfix]
private static void OnCreatedPatch(GlobalInputHandler __instance)
{
((MonoBehaviour)__instance).StartCoroutine(setModdedKeybinds());
}
private static IEnumerator setModdedKeybinds()
{
foreach (BaseCWInput keybind in Plugin._inputs)
{
yield return null;
keybind.inputKey.SetKeybind(GetSetting(keybind));
}
}
private static KeyCodeSetting GetSetting(BaseCWInput settingType)
{
foreach (Setting setting in GameHandler.Instance.SettingsHandler.settings)
{
KeyCodeSetting val = (KeyCodeSetting)(object)((setting is KeyCodeSetting) ? setting : null);
if (val != null && val == settingType)
{
return val;
}
}
return (KeyCodeSetting)(object)settingType;
}
}
[HarmonyPatch(typeof(PlayerInput))]
internal class PlayerInputPatch
{
[HarmonyPatch("SampeInput")]
[HarmonyPostfix]
private static void SampeInput(Player player)
{
foreach (BaseCWInput input in Plugin._inputs)
{
input.HandleKeys(player);
}
}
}
[HarmonyPatch(typeof(SettingsHandler))]
internal static class SettingsHandlerPatch
{
[HarmonyPatch(/*Could not decode attribute arguments.*/)]
[HarmonyTranspiler]
private static IEnumerable<CodeInstruction> ConstructorTranspiler(IEnumerable<CodeInstruction> instructions)
{
//IL_0039: Unknown result type (might be due to invalid IL or missing references)
//IL_003f: Expected O, but got Unknown
//IL_0055: Unknown result type (might be due to invalid IL or missing references)
//IL_005b: Expected O, but got Unknown
//IL_0082: Unknown result type (might be due to invalid IL or missing references)
//IL_0088: Expected O, but got Unknown
//IL_0096: Unknown result type (might be due to invalid IL or missing references)
//IL_009c: Expected O, but got Unknown
//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
//IL_00b0: Expected O, but got Unknown
//IL_00be: Unknown result type (might be due to invalid IL or missing references)
//IL_00c4: Expected O, but got Unknown
//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
//IL_00dd: Expected O, but got Unknown
//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
//IL_00eb: Expected O, but got Unknown
//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
//IL_00f9: Expected O, but got Unknown
FieldInfo fieldInfo = AccessTools.Field(typeof(SettingsHandler), "settings");
MethodInfo methodInfo = AccessTools.Method(typeof(SettingsHandlerPatch), "AddCustomBinds", (Type[])null, (Type[])null);
Plugin.Logger.LogInfo((object)methodInfo);
CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null);
val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
{
new CodeMatch((OpCode?)OpCodes.Ldc_I4_S, (object)null, (string)null)
}).SetOperandAndAdvance((object)0);
val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[4]
{
new CodeMatch((OpCode?)OpCodes.Ldarg_0, (object)null, (string)null),
new CodeMatch((OpCode?)OpCodes.Ldfld, (object)fieldInfo, (string)null),
new CodeMatch((OpCode?)OpCodes.Newobj, (object)null, (string)null),
new CodeMatch((OpCode?)OpCodes.Callvirt, (object)null, (string)null)
}).InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[3]
{
new CodeInstruction(OpCodes.Ldarg_0, (object)null),
new CodeInstruction(OpCodes.Ldfld, (object)fieldInfo),
new CodeInstruction(OpCodes.Call, (object)methodInfo)
});
return val.InstructionEnumeration();
}
private static void AddCustomBinds(List<Setting> settings)
{
foreach (BaseCWInput input in Plugin._inputs)
{
Plugin.Logger.LogInfo((object)$"Loading modded keybind: {input}");
settings.Add((Setting)(object)input);
}
}
}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
public IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}