Decompiled source of Queue Me Maybe v1.1.1

Queue_Me_Maybe.dll

Decompiled 7 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using JetBrains.Annotations;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("Queue_Me_Maybe")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Azumatt")]
[assembly: AssemblyProduct("Queue_Me_Maybe")]
[assembly: AssemblyCopyright("Copyright ©  2022")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("E0E2F92E-557C-4A05-9D89-AA92A0BD75C4")]
[assembly: AssemblyFileVersion("1.1.1")]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.1.0")]
[module: UnverifiableCode]
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;
		}
	}
}
namespace Queue_Me_Maybe
{
	public static class EquipPatchState
	{
		public static bool shouldEquipItemsAfterAttack;

		public static bool shouldHideItemsAfterAttack;

		public static List<ItemData> items;
	}
	[HarmonyPatch(typeof(Player), "FixedUpdate")]
	public static class PlayerFixedUpdatePatch
	{
		private static void Postfix(Player __instance)
		{
			if (Queue_Me_MaybePlugin.queueWeaponChanges.Value == Queue_Me_MaybePlugin.Toggle.Off)
			{
				return;
			}
			if (EquipPatchState.shouldEquipItemsAfterAttack && !((Character)__instance).InAttack() && ((Object)(object)((Character)__instance).m_nview == (Object)null || ((Object)(object)((Character)__instance).m_nview != (Object)null && ((Character)__instance).m_nview.IsOwner())))
			{
				foreach (ItemData item in EquipPatchState.items)
				{
					float equipDuration = item.m_shared.m_equipDuration;
					item.m_shared.m_equipDuration = 0f;
					((Humanoid)__instance).ToggleEquipped(item);
					item.m_shared.m_equipDuration = equipDuration;
				}
				EquipPatchState.shouldEquipItemsAfterAttack = false;
				EquipPatchState.items.Clear();
			}
			if (EquipPatchState.shouldHideItemsAfterAttack && !((Character)__instance).InAttack())
			{
				((Humanoid)__instance).HideHandItems();
				EquipPatchState.shouldHideItemsAfterAttack = false;
			}
		}
	}
	[HarmonyPatch(typeof(Player), "Update")]
	public static class PlayerUpdatePatch
	{
		private static void Postfix(ref Player __instance, ref Vector3 ___m_moveDir, ref Vector3 ___m_lookDir, ref GameObject ___m_placementGhost, Transform ___m_eye)
		{
			if (Queue_Me_MaybePlugin.queueWeaponChanges.Value == Queue_Me_MaybePlugin.Toggle.On && (ZInput.GetButtonDown("Hide") || ZInput.GetButtonDown("JoyHide")) && ((Character)__instance).InAttack() && (((Humanoid)__instance).GetRightItem() != null || ((Humanoid)__instance).GetLeftItem() != null))
			{
				EquipPatchState.shouldHideItemsAfterAttack = true;
			}
		}
	}
	[HarmonyPatch(typeof(Player), "ToggleEquipped")]
	public static class PlayerToggleEquipedPatch
	{
		private static void Postfix(Player __instance, bool __result, ItemData item)
		{
			if (Queue_Me_MaybePlugin.queueWeaponChanges.Value != 0 && __result && item.IsEquipable() && ((Character)__instance).InAttack())
			{
				if (EquipPatchState.items == null)
				{
					EquipPatchState.items = new List<ItemData>();
				}
				if (!EquipPatchState.items.Contains(item))
				{
					EquipPatchState.items.Add(item);
				}
				EquipPatchState.shouldEquipItemsAfterAttack = true;
			}
		}
	}
	[BepInPlugin("Azumatt.Queue_Me_Maybe", "Queue_Me_Maybe", "1.1.1")]
	public class Queue_Me_MaybePlugin : BaseUnityPlugin
	{
		public enum Toggle
		{
			On = 1,
			Off = 0
		}

		private class ConfigurationManagerAttributes
		{
			[UsedImplicitly]
			public int? Order;

			[UsedImplicitly]
			public bool? Browsable;

			[UsedImplicitly]
			public string? Category;

			[UsedImplicitly]
			public Action<ConfigEntryBase>? CustomDrawer;
		}

		internal const string ModName = "Queue_Me_Maybe";

		internal const string ModVersion = "1.1.1";

		internal const string Author = "Azumatt";

		private const string ModGUID = "Azumatt.Queue_Me_Maybe";

		private static string ConfigFileName = "Azumatt.Queue_Me_Maybe.cfg";

		private static string ConfigFileFullPath;

		private readonly Harmony _harmony = new Harmony("Azumatt.Queue_Me_Maybe");

		public static readonly ManualLogSource Queue_Me_MaybeLogger;

		internal static ConfigEntry<Toggle> queueWeaponChanges;

		public void Awake()
		{
			queueWeaponChanges = config("1 - General", "Queue Weapon Changes", Toggle.On, "If you turn on this option, any requests to switch weapons during an attack will be held off until the attack is done, instead of being ignored.");
			Assembly executingAssembly = Assembly.GetExecutingAssembly();
			_harmony.PatchAll(executingAssembly);
			SetupWatcher();
		}

		private void OnDestroy()
		{
			((BaseUnityPlugin)this).Config.Save();
		}

		private void SetupWatcher()
		{
			FileSystemWatcher fileSystemWatcher = new FileSystemWatcher(Paths.ConfigPath, ConfigFileName);
			fileSystemWatcher.Changed += ReadConfigValues;
			fileSystemWatcher.Created += ReadConfigValues;
			fileSystemWatcher.Renamed += ReadConfigValues;
			fileSystemWatcher.IncludeSubdirectories = true;
			fileSystemWatcher.SynchronizingObject = ThreadingHelper.SynchronizingObject;
			fileSystemWatcher.EnableRaisingEvents = true;
		}

		private void ReadConfigValues(object sender, FileSystemEventArgs e)
		{
			if (!File.Exists(ConfigFileFullPath))
			{
				return;
			}
			try
			{
				Queue_Me_MaybeLogger.LogDebug((object)"ReadConfigValues called");
				((BaseUnityPlugin)this).Config.Reload();
			}
			catch
			{
				Queue_Me_MaybeLogger.LogError((object)("There was an issue loading your " + ConfigFileName));
				Queue_Me_MaybeLogger.LogError((object)"Please check your config entries for spelling and format!");
			}
		}

		private ConfigEntry<T> config<T>(string group, string name, T value, ConfigDescription description)
		{
			return ((BaseUnityPlugin)this).Config.Bind<T>(group, name, value, description);
		}

		private ConfigEntry<T> config<T>(string group, string name, T value, string description)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			return config(group, name, value, new ConfigDescription(description, (AcceptableValueBase)null, Array.Empty<object>()));
		}

		static Queue_Me_MaybePlugin()
		{
			string configPath = Paths.ConfigPath;
			char directorySeparatorChar = Path.DirectorySeparatorChar;
			ConfigFileFullPath = configPath + directorySeparatorChar + ConfigFileName;
			Queue_Me_MaybeLogger = Logger.CreateLogSource("Queue_Me_Maybe");
			queueWeaponChanges = null;
		}
	}
}