using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using InstantItemSlotsFixed.Utils;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
[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("InstantItemSlotsFixed")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("InstantItemSlotsFixed")]
[assembly: AssemblyTitle("InstantItemSlotsFixed")]
[assembly: AssemblyVersion("1.0.0.0")]
[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 InstantItemSlotsFixed
{
[BepInPlugin("InstantItemSlotsFixed", "Instant Item Slots Fixed", "1.0.0")]
public class InstantItemSlotsFixed : BaseUnityPlugin
{
public const string PluginName = "Instant Item Slots Fixed";
public const string PluginVersion = "1.0.0";
public const string PluginGUID = "InstantItemSlotsFixed";
public static InstantItemSlotsFixed? Instance;
public ManualLogSource? Logger;
public Harmony? harmony;
private ConfigEntry<bool>? allowTwoHandedObjects;
public bool AllowTwoHandedObjects;
public InputAction? itemSlotOneInputAction;
public InputAction? itemSlotTwoInputAction;
public InputAction? itemSlotThreeInputAction;
public InputAction? itemSlotFourInputAction;
public void Awake()
{
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_0023: Expected O, but got Unknown
//IL_009e: Unknown result type (might be due to invalid IL or missing references)
//IL_00a8: Expected O, but got Unknown
//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
//IL_00d9: Expected O, but got Unknown
//IL_0100: Unknown result type (might be due to invalid IL or missing references)
//IL_010a: Expected O, but got Unknown
//IL_0131: Unknown result type (might be due to invalid IL or missing references)
//IL_013b: Expected O, but got Unknown
Instance = this;
Logger = ((BaseUnityPlugin)this).Logger;
harmony = new Harmony("InstantItemSlotsFixed");
harmony.PatchAll(Assembly.GetExecutingAssembly());
Logger.LogInfo((object)"Instant Item Slots Fixed 1.0.0 is loaded!");
allowTwoHandedObjects = ((BaseUnityPlugin)this).Config.Bind<bool>("Instant Item Slots Fixed", "Allow Two Handed Objects", false, "Allows Two Handed Objects to be swapped from");
AllowTwoHandedObjects = allowTwoHandedObjects.Value;
allowTwoHandedObjects.SettingChanged += delegate
{
AllowTwoHandedObjects = allowTwoHandedObjects.Value;
};
itemSlotOneInputAction = new InputAction("ItemSlot1", (InputActionType)1, "<Keyboard>/1", (string)null, (string)null, (string)null);
itemSlotOneInputAction.performed += delegate
{
SwitchToItemSlot(0);
};
itemSlotTwoInputAction = new InputAction("ItemSlot2", (InputActionType)1, "<Keyboard>/2", (string)null, (string)null, (string)null);
itemSlotTwoInputAction.performed += delegate
{
SwitchToItemSlot(1);
};
itemSlotThreeInputAction = new InputAction("ItemSlot3", (InputActionType)1, "<Keyboard>/3", (string)null, (string)null, (string)null);
itemSlotThreeInputAction.performed += delegate
{
SwitchToItemSlot(2);
};
itemSlotFourInputAction = new InputAction("ItemSlot4", (InputActionType)1, "<Keyboard>/4", (string)null, (string)null, (string)null);
itemSlotFourInputAction.performed += delegate
{
SwitchToItemSlot(3);
};
itemSlotOneInputAction.Enable();
itemSlotTwoInputAction.Enable();
itemSlotThreeInputAction.Enable();
itemSlotFourInputAction.Enable();
}
public void SwitchToItemSlot(int slot)
{
PlayerControllerB val = GameNetworkManager.Instance?.localPlayerController;
if ((Object)(object)val == (Object)null)
{
return;
}
GrabbableObject[] itemSlots = val.ItemSlots;
int num = ((itemSlots != null) ? itemSlots.Length : (-1));
if (slot < 0 || slot >= num)
{
return;
}
int currentItemSlot = val.currentItemSlot;
if (currentItemSlot != slot)
{
Item val2 = val.currentlyHeldObjectServer?.itemProperties;
if (!((Object)(object)val2 != (Object)null) || !val2.twoHanded || AllowTwoHandedObjects)
{
val.Reflect<PlayerControllerB>().Invoke("SwitchToItemSlot", slot, null);
}
}
}
}
}
namespace InstantItemSlotsFixed.Utils
{
public class ReflectionUtil<R>
{
private const BindingFlags privateInst = BindingFlags.Instance | BindingFlags.NonPublic;
private const BindingFlags privateStatic = BindingFlags.Static | BindingFlags.NonPublic;
private const BindingFlags privateField = BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.GetField;
private const BindingFlags privateProp = BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.GetProperty;
private const BindingFlags privateMethod = BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.InvokeMethod;
private const BindingFlags staticField = BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.GetField;
private const BindingFlags staticProp = BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.GetProperty;
private const BindingFlags staticMethod = BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.InvokeMethod;
private R @object { get; }
private Type type { get; }
internal ReflectionUtil(R obj)
{
@object = obj;
type = typeof(R);
}
private T? GetValue<T>(string variableName, BindingFlags flags)
{
try
{
return (T)type.GetField(variableName, flags).GetValue(@object);
}
catch (InvalidCastException)
{
return default(T);
}
}
private T? GetProperty<T>(string propertyName, BindingFlags flags)
{
try
{
return (T)type.GetProperty(propertyName, flags).GetValue(@object);
}
catch (InvalidCastException)
{
return default(T);
}
}
private ReflectionUtil<R>? SetValue(string variableName, object value, BindingFlags flags)
{
try
{
type.GetField(variableName, flags).SetValue(@object, value);
return this;
}
catch (Exception)
{
return null;
}
}
private ReflectionUtil<R>? SetProperty(string propertyName, object value, BindingFlags flags)
{
try
{
type.GetProperty(propertyName, flags).SetValue(@object, value);
return this;
}
catch (Exception)
{
return null;
}
}
private T? Invoke<T>(string methodName, BindingFlags flags, params object[] args)
{
try
{
return (T)type.GetMethod(methodName, flags).Invoke(@object, args);
}
catch (InvalidCastException)
{
return default(T);
}
}
public T? GetValue<T>(string fieldName, bool isStatic = false, bool isProperty = false)
{
BindingFlags flags = ((!isProperty) ? (isStatic ? (BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.GetField) : (BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.GetField)) : (isStatic ? (BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.GetProperty) : (BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.GetProperty)));
return isProperty ? GetProperty<T>(fieldName, flags) : GetValue<T>(fieldName, flags);
}
public ReflectionUtil<R>? SetValue(string fieldName, object value, bool isStatic = false, bool isProperty = false)
{
BindingFlags flags = ((!isProperty) ? (isStatic ? (BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.GetField) : (BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.GetField)) : (isStatic ? (BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.GetProperty) : (BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.GetProperty)));
return isProperty ? SetProperty(fieldName, value, flags) : SetValue(fieldName, value, flags);
}
private T? Invoke<T>(string methodName, bool isStatic = false, params object[] args)
{
return Invoke<T>(methodName, isStatic ? (BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.InvokeMethod) : (BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.InvokeMethod), args);
}
public object? GetValue(string fieldName, bool isStatic = false, bool isProperty = false)
{
return GetValue<R>(fieldName, isStatic, isProperty);
}
public ReflectionUtil<R>? Invoke(string methodName, bool isStatic = false, params object[] args)
{
R val = Invoke<R>(methodName, isStatic, args);
return (val != null) ? val.Reflect() : null;
}
public ReflectionUtil<R>? Invoke(string methodName, params object[] args)
{
R val = Invoke<R>(methodName, isStatic: false, args);
return (val != null) ? val.Reflect() : null;
}
}
public static class ReflectorExtensions
{
public static ReflectionUtil<R> Reflect<R>(this R obj)
{
return new ReflectionUtil<R>(obj);
}
}
}
namespace InstantItemSlotsFixed.Patches
{
[HarmonyPatch(typeof(PlayerControllerB))]
public class PlayerControllerBPatches
{
[HarmonyPatch("OnEnable")]
[HarmonyPostfix]
public static void OnEnable(PlayerControllerB __instance)
{
//IL_004b: Unknown result type (might be due to invalid IL or missing references)
//IL_0071: Unknown result type (might be due to invalid IL or missing references)
IngamePlayerSettings instance = IngamePlayerSettings.Instance;
object obj;
if (instance == null)
{
obj = null;
}
else
{
PlayerInput playerInput = instance.playerInput;
obj = ((playerInput != null) ? playerInput.actions : null);
}
InputActionAsset val = (InputActionAsset)obj;
if ((Object)(object)val != (Object)null)
{
InputAction val2 = val.FindAction("Emote1", false);
if (val2 != null)
{
InputActionSetupExtensions.AddBinding(val2, "<Keyboard>/upArrow", (string)null, (string)null, (string)null);
}
InputAction val3 = val.FindAction("Emote2", false);
if (val3 != null)
{
InputActionSetupExtensions.AddBinding(val3, "<Keyboard>/downArrow", (string)null, (string)null, (string)null);
}
}
}
[HarmonyPatch("PerformEmote")]
[HarmonyPrefix]
public static bool PerformEmote(PlayerControllerB __instance, CallbackContext context)
{
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
//IL_0022: Invalid comparison between Unknown and I4
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_0027: Invalid comparison between Unknown and I4
if (((CallbackContext)(ref context)).performed)
{
Key keyCode = ((KeyControl)((CallbackContext)(ref context)).control).keyCode;
if ((int)keyCode == 63 || (int)keyCode == 64)
{
return true;
}
}
return false;
}
}
}