Decompiled source of Auto Dice Cleanup v1.1.0

AutoDiceCleanup.dll

Decompiled 12 hours ago
using System;
using System.CodeDom.Compiler;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
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.Singletons;
using Bounce.Unmanaged;
using Dice;
using GameChat.UI;
using HarmonyLib;
using ModdingTales;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("Auto Dice Cleanup")]
[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 AutoDiceCleanup
{
	[BepInPlugin("org.hollofox.plugins.AutoDiceCleanup", "Auto Dice Cleanup Plugin", "1.1.0.0")]
	public class AutoDiceCleanupPlugin : BaseUnityPlugin
	{
		[CompilerGenerated]
		private sealed class <ClearDiceRollIEnum>d__33 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			public float delayInSeconds;

			public RollId rollId;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <ClearDiceRollIEnum>d__33(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_0028: Unknown result type (might be due to invalid IL or missing references)
				//IL_0032: Expected O, but got Unknown
				//IL_004d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0067: Unknown result type (might be due to invalid IL or missing references)
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = (object)new WaitForSeconds(Mathf.Max(1f, delayInSeconds));
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					try
					{
						logger.LogDebug((object)$"Clearing dice roll {rollId}");
						SimpleSingletonBehaviour<DiceRollManager>.Instance.RemoveRoll(rollId);
					}
					catch (Exception ex)
					{
						logger.LogDebug((object)ex.Message);
					}
					return false;
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		public const string Guid = "org.hollofox.plugins.AutoDiceCleanup";

		internal const string Version = "1.1.0.0";

		public static AutoDiceCleanupPlugin Instance;

		internal static ManualLogSource logger;

		private static ConfigEntry<bool> _cleanupAfterSelf { get; set; }

		internal static bool CleanUpAfterSelf
		{
			get
			{
				return _cleanupAfterSelf.Value;
			}
			set
			{
				_cleanupAfterSelf.Value = value;
			}
		}

		private static ConfigEntry<bool> _cleanupAsGm { get; set; }

		internal static bool CleanupAsGm
		{
			get
			{
				return _cleanupAsGm.Value;
			}
			set
			{
				_cleanupAsGm.Value = value;
			}
		}

		private static ConfigEntry<float> _cleanupAfterSelfInSeconds { get; set; }

		internal static float CleanupAfterSelfInSeconds
		{
			get
			{
				return _cleanupAfterSelfInSeconds.Value;
			}
			set
			{
				_cleanupAfterSelfInSeconds.Value = value;
			}
		}

		private static ConfigEntry<float> _cleanupAsGmInSeconds { get; set; }

		internal static float CleanupAsGmInSeconds
		{
			get
			{
				return _cleanupAsGmInSeconds.Value;
			}
			set
			{
				_cleanupAsGmInSeconds.Value = value;
			}
		}

		internal void ClearDiceRoll(float delayInSeconds, RollId rollId)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			((MonoBehaviour)this).StartCoroutine(ClearDiceRollIEnum(delayInSeconds, rollId));
		}

		[IteratorStateMachine(typeof(<ClearDiceRollIEnum>d__33))]
		internal IEnumerator ClearDiceRollIEnum(float delayInSeconds, RollId rollId)
		{
			//IL_000e: 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)
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <ClearDiceRollIEnum>d__33(0)
			{
				delayInSeconds = delayInSeconds,
				rollId = rollId
			};
		}

		private void Awake()
		{
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			Instance = this;
			logger = ((BaseUnityPlugin)this).Logger;
			((BaseUnityPlugin)this).Logger.LogDebug((object)"Auto Dice Cleanup loaded");
			_cleanupAfterSelf = ((BaseUnityPlugin)this).Config.Bind<bool>("Cleanup", "Self", true, (ConfigDescription)null);
			_cleanupAsGm = ((BaseUnityPlugin)this).Config.Bind<bool>("Cleanup", "All as GM", true, (ConfigDescription)null);
			_cleanupAfterSelfInSeconds = ((BaseUnityPlugin)this).Config.Bind<float>("Cleanup", "Self Delay in Seconds", 5f, (ConfigDescription)null);
			_cleanupAsGmInSeconds = ((BaseUnityPlugin)this).Config.Bind<float>("Cleanup", "GM Delay in Seconds", 5f, (ConfigDescription)null);
			try
			{
				new Harmony("org.hollofox.plugins.AutoDiceCleanup").PatchAll();
				ModdingUtils.AddPluginToMenuList((BaseUnityPlugin)(object)this, "HolloFoxes'");
			}
			catch (Exception ex)
			{
				logger.LogError((object)ex.Message);
			}
		}
	}
}
namespace AutoDiceCleanup.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("AutoDiceCleanup.Properties.Resources", typeof(Resources).Assembly);
				}
				return resourceMan;
			}
		}

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

		internal Resources()
		{
		}
	}
}
namespace AutoDiceCleanup.Patches
{
	[HarmonyPatch(typeof(DiceRollManager), "OnResults")]
	public class OnDiceRolledPatch
	{
		private static void Postfix(DiceRollManager __instance, ClientGuid clientId, RollResults rollResults, bool isGmRoll, bool showResult, ResultsOrigin resultsOrigin, NGuid optionalSymbioteInteropId)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: 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_0043: Unknown result type (might be due to invalid IL or missing references)
			if (LocalClient.IsInGmMode && AutoDiceCleanupPlugin.CleanupAsGm)
			{
				AutoDiceCleanupPlugin.Instance.ClearDiceRoll(AutoDiceCleanupPlugin.CleanupAsGmInSeconds, rollResults.RollId);
			}
			else if (clientId == LocalClient.Id && AutoDiceCleanupPlugin.CleanUpAfterSelf)
			{
				AutoDiceCleanupPlugin.Instance.ClearDiceRoll(AutoDiceCleanupPlugin.CleanupAfterSelfInSeconds, rollResults.RollId);
			}
		}
	}
}