Decompiled source of QuickBelt v1.0.1

QuickBelt.dll

Decompiled 2 days ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using Il2CppInterop.Runtime.Injection;
using Il2CppSystem.Collections.Generic;
using Microsoft.CodeAnalysis;
using Mirror;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("QuickBelt")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("QuickBelt")]
[assembly: AssemblyTitle("QuickBelt")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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 QuickBelt
{
	internal static class BeltConfig
	{
		internal static ConfigEntry<KeyCode> BeltKey;

		internal static ConfigEntry<bool> DebugLog;

		internal static void Init(ConfigFile config)
		{
			BeltKey = config.Bind<KeyCode>("Belt", "BeltKey", (KeyCode)98, "press to take the item off your belt, press again with an item in hand to stow it");
			DebugLog = config.Bind<bool>("Debug", "DebugLog", false, "log why a belt action was refused");
		}
	}
	public sealed class BeltController : MonoBehaviour
	{
		public BeltController(IntPtr ptr)
			: base(ptr)
		{
		}

		private void Update()
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			if ((!NetworkClient.active && !NetworkServer.active) || !Input.GetKeyDown(BeltConfig.BeltKey.Value))
			{
				return;
			}
			PlayerCharacter val = FindLocalPlayer();
			if (!IsAlive((Object)(object)val) || val.texter.isPlayerTextChatting || (Object)(object)val.poser.playerHoldingMe != (Object)null)
			{
				return;
			}
			Prop equippedBelt = GetEquippedBelt(val);
			if (!IsAlive((Object)(object)equippedBelt))
			{
				Refused("no belt equipped");
				return;
			}
			PropHome beltStorage = GetBeltStorage(equippedBelt);
			if (!IsAlive((Object)(object)beltStorage))
			{
				Refused("belt has no storage home");
				return;
			}
			Prop heldProp = val.hands.heldProp;
			if (IsAlive((Object)(object)heldProp))
			{
				TryStow(val, heldProp, beltStorage);
			}
			else if (!IsAlive((Object)(object)val.hands.heldCharacter))
			{
				TryDraw(val, beltStorage);
			}
		}

		private static void TryStow(PlayerCharacter pc, Prop held, PropHome storage)
		{
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Expected O, but got Unknown
			if (IsAlive((Object)(object)storage.pinnedProp))
			{
				Refused("belt already has an item");
				return;
			}
			if (!storage.IsSafeToPlace(held))
			{
				Refused("'" + ((Object)held).name + "' cannot go on the belt");
				return;
			}
			pc.actions.ActionPlaceInHome(held, storage);
			if (BeltConfig.DebugLog.Value)
			{
				ManualLogSource logger = Plugin.Logger;
				bool flag = default(bool);
				BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(21, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("stowed '");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(((Object)held).name);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("' on the belt");
				}
				logger.LogInfo(val);
			}
		}

		private static void TryDraw(PlayerCharacter pc, PropHome storage)
		{
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Expected O, but got Unknown
			Prop pinnedProp = storage.pinnedProp;
			if (!IsAlive((Object)(object)pinnedProp))
			{
				Refused("belt is empty");
				return;
			}
			if (!pc.hands.IsSafeToPickUp(pinnedProp))
			{
				Refused("'" + ((Object)pinnedProp).name + "' cannot be taken right now");
				return;
			}
			pc.actions.ActionPickUpProp(pinnedProp, ((Component)pinnedProp).transform.position);
			if (BeltConfig.DebugLog.Value)
			{
				ManualLogSource logger = Plugin.Logger;
				bool flag = default(bool);
				BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(20, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("drew '");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(((Object)pinnedProp).name);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("' off the belt");
				}
				logger.LogInfo(val);
			}
		}

		private static Prop GetEquippedBelt(PlayerCharacter pc)
		{
			PlayerRegistry registry = pc.registry;
			if (registry == null)
			{
				return null;
			}
			PropHome holsterPocket = registry.holsterPocket;
			if (!IsAlive((Object)(object)holsterPocket))
			{
				return null;
			}
			return holsterPocket.pinnedProp;
		}

		private static PropHome GetBeltStorage(Prop belt)
		{
			List<PropHome> childPropHomes = belt.childPropHomes;
			if (childPropHomes == null || childPropHomes.Count == 0)
			{
				return null;
			}
			return childPropHomes[0];
		}

		private static void Refused(string reason)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			if (BeltConfig.DebugLog.Value)
			{
				ManualLogSource logger = Plugin.Logger;
				bool flag = default(bool);
				BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(21, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("belt action refused: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(reason);
				}
				logger.LogInfo(val);
			}
		}

		private static PlayerCharacter FindLocalPlayer()
		{
			List<PlayerCharacter> allPlayerCharacters = PlayerCharacter.allPlayerCharacters;
			if (allPlayerCharacters == null)
			{
				return null;
			}
			for (int i = 0; i < allPlayerCharacters.Count; i++)
			{
				PlayerCharacter val = allPlayerCharacters[i];
				if (IsAlive((Object)(object)val) && ((NetworkBehaviour)val).isLocalPlayer)
				{
					return val;
				}
			}
			return null;
		}

		private static bool IsAlive(Object obj)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			return obj != (Object)null;
		}
	}
	[BepInPlugin("com.zaddish.quickbelt", "QuickBelt", "1.0.1")]
	public sealed class Plugin : BasePlugin
	{
		public const string Guid = "com.zaddish.quickbelt";

		public const string Name = "QuickBelt";

		public const string Version = "1.0.1";

		internal static ManualLogSource Logger;

		public override void Load()
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Expected O, but got Unknown
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Expected O, but got Unknown
			Logger = ((BasePlugin)this).Log;
			BeltConfig.Init(new ConfigFile(Path.Combine(Paths.ConfigPath, "QuickBelt.cfg"), true));
			ClassInjector.RegisterTypeInIl2Cpp<BeltController>();
			((BasePlugin)this).AddComponent<BeltController>();
			ManualLogSource logger = Logger;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(9, 2, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("QuickBelt");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("1.0.1");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" loaded.");
			}
			logger.LogInfo(val);
		}
	}
}