using System;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using CSync.Extensions;
using CSync.Lib;
using GameNetcodeStuff;
using HarmonyLib;
using Unity.Netcode;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("OneHandNeeded")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("OneHandNeeded")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("bae26c84-1626-4982-b1ae-21a30ffed679")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace OneHandNeeded;
[BepInPlugin("Swaggies.OneHandNeeded", "OneHandNeeded", "1.1.1")]
public class Plugin : BaseUnityPlugin
{
public const string _guid = "Swaggies.OneHandNeeded";
private const string _name = "OneHandNeeded";
private const string _ver = "1.1.1";
private readonly Harmony harmony = new Harmony("Swaggies.OneHandNeeded");
private static Plugin Instance;
private static ManualLogSource loggimino;
private static Config config;
private static int twoHandedItemsHeld;
private void Awake()
{
if ((Object)(object)Instance == (Object)null)
{
Instance = this;
}
loggimino = Logger.CreateLogSource("Swaggies.OneHandNeeded");
harmony.PatchAll(typeof(Plugin));
loggimino.LogInfo((object)"OneHandNeeded up and running.");
config = new Config(((BaseUnityPlugin)this).Config);
}
[HarmonyPatch(typeof(PlayerControllerB), "BeginGrabObject")]
[HarmonyPostfix]
private static void SetPlayerTwoHandedCheck1(ref PlayerControllerB __instance)
{
CancelTwoHanded(__instance);
}
[HarmonyPatch(typeof(PlayerControllerB), "SwitchToItemSlot")]
[HarmonyPostfix]
private static void SetPlayerTwoHandedCheck2(ref PlayerControllerB __instance)
{
CancelTwoHanded(__instance);
}
[HarmonyPatch(typeof(PlayerControllerB), "GrabObjectClientRpc")]
[HarmonyPostfix]
private static void SetPlayerTwoHandedCheck3(ref PlayerControllerB __instance)
{
CancelTwoHanded(__instance);
}
private static void CancelTwoHanded(PlayerControllerB player)
{
if (config.MaxTwoHandeds.Value == 0)
{
player.twoHanded = false;
if (((NetworkBehaviour)player).IsOwner)
{
((Behaviour)HUDManager.Instance.holdingTwoHandedItem).enabled = false;
}
}
else
{
if (!player.twoHanded || ((Object)(object)player.currentlyHeldObjectServer != (Object)null && player.currentlyHeldObjectServer is CaveDwellerPhysicsProp))
{
return;
}
twoHandedItemsHeld = 0;
GrabbableObject[] itemSlots = player.ItemSlots;
foreach (GrabbableObject val in itemSlots)
{
if (!((Object)(object)val == (Object)null) && val.itemProperties.twoHanded)
{
twoHandedItemsHeld++;
if (twoHandedItemsHeld >= config.MaxTwoHandeds.Value)
{
return;
}
}
}
player.twoHanded = false;
if (((NetworkBehaviour)player).IsOwner)
{
((Behaviour)HUDManager.Instance.holdingTwoHandedItem).enabled = false;
}
}
}
[HarmonyPatch(typeof(NetworkManager), "SetSingleton")]
[HarmonyPostfix]
private static void SetSingletonP()
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Expected O, but got Unknown
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
GameObject val = new GameObject("Swaggies.OneHandNeeded-NetworkPatchObject");
((Object)val).hideFlags = (HideFlags)(((Object)val).hideFlags | 0x3D);
Object.DontDestroyOnLoad((Object)(object)val);
NetworkObject obj = val.AddComponent<NetworkObject>();
uint num = "Swaggies.OneHandNeeded".Aggregate(17u, (uint u, char c) => (u * 31) ^ c);
typeof(NetworkObject).GetField("GlobalObjectIdHash", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(obj, num);
NetworkManager.Singleton.PrefabHandler.AddNetworkPrefab(val);
}
}
public class Config : SyncedConfig2<Config>
{
[SyncedEntryField]
public SyncedEntry<int> MaxTwoHandeds;
public Config(ConfigFile cfg)
: base("Swaggies.OneHandNeeded")
{
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
//IL_0036: Expected O, but got Unknown
MaxTwoHandeds = SyncedBindingExtensions.BindSyncedEntry<int>(cfg, "General", "Max Two-Handed Items", 0, new ConfigDescription("Max number of two-handed items a player can hold before \"Hands Full\" is triggered. Set to 0 for no limit.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 10), Array.Empty<object>()));
ConfigManager.Register<Config>((SyncedConfig2<Config>)this);
}
}