Decompiled source of Auto Initiative v1.1.0

AutoInitiative.dll

Decompiled 3 months ago
using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Bounce.ManagedCollections;
using HarmonyLib;
using ModdingTales;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("Auto Initiative")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("HolloFox")]
[assembly: AssemblyProduct("MFC")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("4e4deb5e-97f9-4901-bf67-6748a9c1229a")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.1.0.0")]
namespace AutoInitiative
{
	[BepInPlugin("org.hollofox.plugins.AutoInitiative", "Auto Initiative Plugin", "1.1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class AutoInitiativePlugin : BaseUnityPlugin
	{
		public const string Guid = "org.hollofox.plugins.AutoInitiative";

		internal const string Version = "1.1.0.0";

		internal static ConfigEntry<string> InitiativeText;

		internal static ManualLogSource logger;

		private void Awake()
		{
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			logger = ((BaseUnityPlugin)this).Logger;
			((BaseUnityPlugin)this).Logger.LogDebug((object)"Auto Initiative loaded");
			InitiativeText = ((BaseUnityPlugin)this).Config.Bind<string>("Initiative", "Required Text", "Initiative", (ConfigDescription)null);
			try
			{
				new Harmony("org.hollofox.plugins.AutoInitiative").PatchAll();
				ModdingUtils.AddPluginToMenuList((BaseUnityPlugin)(object)this, "HolloFoxes'");
			}
			catch (Exception ex)
			{
				logger.LogError((object)ex.Message);
			}
		}
	}
}
namespace AutoInitiative.Properties
{
	[GeneratedCode("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
	[DebuggerNonUserCode]
	[CompilerGenerated]
	internal class Resources
	{
		private static ResourceManager resourceMan;

		private static CultureInfo resourceCulture;

		[EditorBrowsable(EditorBrowsableState.Advanced)]
		internal static ResourceManager ResourceManager
		{
			get
			{
				if (resourceMan == null)
				{
					resourceMan = new ResourceManager("AutoInitiative.Properties.Resources", typeof(Resources).Assembly);
				}
				return resourceMan;
			}
		}

		[EditorBrowsable(EditorBrowsableState.Advanced)]
		internal static CultureInfo Culture
		{
			get
			{
				return resourceCulture;
			}
			set
			{
				resourceCulture = value;
			}
		}

		internal Resources()
		{
		}
	}
}
namespace AutoInitiative.Patches
{
	internal static class InitUtils
	{
		internal static bool EditIsOpen = false;

		internal static Dictionary<CreatureGuid, (int, int)> Initiatives = new Dictionary<CreatureGuid, (int, int)>();

		internal static void ClearInitiatives()
		{
			Initiatives.Clear();
			AutoInitiativePlugin.logger.LogInfo((object)"Cleared Tracked Initiatives");
		}

		internal static void SetInitiatives()
		{
			InitiativeManager.SetEditQueue((from entry in Initiatives
				orderby entry.Value.Item1 descending, entry.Value.Item2 descending
				select entry).Select(delegate(KeyValuePair<CreatureGuid, (int, int)> entry)
			{
				//IL_0018: Unknown result type (might be due to invalid IL or missing references)
				//IL_002e: Unknown result type (might be due to invalid IL or missing references)
				AutoInitiativePlugin.logger.LogInfo((object)$"{entry.Value}: {entry.Key}");
				return entry.Key;
			}).Select((Func<CreatureGuid, QueueElement>)((CreatureGuid e) => new QueueElement((ElementType)0, e))).ToArray());
		}
	}
	[HarmonyPatch(typeof(InitiativeManager), "RemoveElementFromEditQueue")]
	public class InitiativeManagerRemoveCreatureFromEditQueuePatch
	{
		private static void Postfix(QueueElement element)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: 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_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			if ((int)element.Type == 0 && InitUtils.Initiatives.ContainsKey(element.CreatureGuid))
			{
				InitUtils.Initiatives.Remove(element.CreatureGuid);
				AutoInitiativePlugin.logger.LogInfo((object)$"Removed {element.CreatureGuid} from Initiative");
			}
		}
	}
	[HarmonyPatch(typeof(InitiativeManager), "ReleaseElement", new Type[] { typeof(QueueElement) })]
	public class InitiativeManagerReleaseCreaturePatch
	{
		private static void Postfix(QueueElement queueElement)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			if ((int)queueElement.Type == 0 && InitUtils.Initiatives.ContainsKey(queueElement.CreatureGuid))
			{
				InitUtils.Initiatives.Remove(queueElement.CreatureGuid);
				AutoInitiativePlugin.logger.LogInfo((object)$"Removed {queueElement.CreatureGuid} from Initiative");
			}
		}
	}
	[HarmonyPatch(typeof(UI_InitativeManager), "ClearEdit")]
	public class InitiativeManagerClearPatch
	{
		private static void Prefix()
		{
			InitUtils.ClearInitiatives();
			AutoInitiativePlugin.logger.LogInfo((object)"Initiatives cleared");
		}
	}
	[HarmonyPatch(typeof(UI_InitativeManager), "OpenEdit")]
	public class InitiativeManagerApplyEditPatch
	{
		private static void Prefix(bool value)
		{
			InitUtils.EditIsOpen = value;
			AutoInitiativePlugin.logger.LogInfo((object)$"Initiative Manager is open: {value}");
		}
	}
	[HarmonyPatch(typeof(DiceManager), "RPC_DiceResult")]
	public class ReceiveDiceRolledPatch
	{
		private static void Postfix(bool isGmOnly, byte[] diceListData, PhotonMessageInfo msgInfo, Reader ____reader)
		{
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_021a: Unknown result type (might be due to invalid IL or missing references)
			//IL_021f: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_0261: Unknown result type (might be due to invalid IL or missing references)
			//IL_0266: Unknown result type (might be due to invalid IL or missing references)
			//IL_026b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Invalid comparison between Unknown and I4
			//IL_02c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fe: Unknown result type (might be due to invalid IL or missing references)
			if (!LocalClient.IsInGmMode || !InitUtils.EditIsOpen)
			{
				return;
			}
			RollResults val = default(RollResults);
			BrSerializeHelpers.DeserializeFromByteArray<RollResults>(____reader, diceListData, (BrDeserializer<RollResults>)RollResults.Deserialize, ref val);
			bool flag = false;
			int num = 0;
			int num2 = 0;
			num2 = 0;
			int num3 = 0;
			Enumerator<RollResultsGroup> enumerator = val.ResultsGroups.GetEnumerator();
			try
			{
				RollResultsOperation val2 = default(RollResultsOperation);
				RollResult val3 = default(RollResult);
				RollValue val4 = default(RollValue);
				while (enumerator.MoveNext())
				{
					RollResultsGroup current = enumerator.Current;
					num = 0;
					if (current.Name != null && Convert.ToString(current.Name).Trim() != "" && current.Name.Contains(AutoInitiativePlugin.InitiativeText.Value, StringComparison.OrdinalIgnoreCase))
					{
						flag = true;
					}
					if (!flag)
					{
						continue;
					}
					Which val5 = ((RollOperand)(ref current.Result)).Get(ref val2, ref val3, ref val4);
					if (!((Enum)val5).HasFlag((Enum)(object)(Which)0))
					{
						continue;
					}
					num = 1;
					try
					{
						num = (((int)val2.Operator != 1) ? 1 : (-1));
					}
					catch (Exception)
					{
					}
					if (val2.Operands != null)
					{
						Enumerator<RollOperand> enumerator2 = val2.Operands.GetEnumerator();
						try
						{
							while (enumerator2.MoveNext())
							{
								RollOperand current2 = enumerator2.Current;
								((RollOperand)(ref current2)).Get(ref val2, ref val3, ref val4);
								if (((DieKind)(ref val3.Kind)).RegisteredName == "<unknown>")
								{
									int num4 = val4.Value * num;
									num2 += num4;
									num3 += num4;
									AutoInitiativePlugin.logger.LogInfo((object)("Initiative Modifier: " + num3));
									continue;
								}
								Enumerator<short> enumerator3 = val3.Results.GetEnumerator();
								try
								{
									while (enumerator3.MoveNext())
									{
										short current3 = enumerator3.Current;
										num2 += current3;
									}
								}
								finally
								{
									((IDisposable)enumerator3).Dispose();
								}
							}
						}
						finally
						{
							((IDisposable)enumerator2).Dispose();
						}
					}
					else
					{
						if (val3.Results == null)
						{
							continue;
						}
						Enumerator<short> enumerator3 = val3.Results.GetEnumerator();
						try
						{
							while (enumerator3.MoveNext())
							{
								short current4 = enumerator3.Current;
								num2 += current4;
							}
						}
						finally
						{
							((IDisposable)enumerator3).Dispose();
						}
					}
				}
			}
			finally
			{
				((IDisposable)enumerator).Dispose();
			}
			if (!flag)
			{
				return;
			}
			CreatureGuid[] array = (CreatureGuid[])(object)new CreatureGuid[0];
			CreatureGuid[] array2 = default(CreatureGuid[]);
			if (val.ClientId == LocalClient.Id && LocalClient.HasLassoedCreatures && LocalClient.LassoedCount > 0 && LocalClient.TryGetLassoedCreatureIds(ref array2))
			{
				AutoInitiativePlugin.logger.LogInfo((object)"Using Initiative for Lassoed Creatures");
				array = array2;
			}
			else
			{
				array = (CreatureGuid[])(object)new CreatureGuid[1] { BoardSessionManager.GetLastSelectedCreatureGuid(val.ClientId) };
			}
			array = array.Where((CreatureGuid c) => c != default(CreatureGuid)).ToArray();
			if (array.Count() == 0)
			{
				AutoInitiativePlugin.logger.LogInfo((object)"No Creature Selected");
				return;
			}
			CreatureGuid[] array3 = array;
			for (int i = 0; i < array3.Length; i++)
			{
				CreatureGuid key = array3[i];
				AutoInitiativePlugin.logger.LogInfo((object)("Creature " + ((object)(CreatureGuid)(ref key)).ToString() + " rolled " + num2));
				InitUtils.Initiatives[key] = (num2, num3);
			}
			InitUtils.SetInitiatives();
		}
	}
}