Decompiled source of AutoRollPlugin v2.1.1

AutoRollPlugin.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
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 Bounce.Singletons;
using Dice;
using HarmonyLib;
using TMPro;
using Unity.Mathematics;
using UnityEngine;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("AutoRollPlugin")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("AutoRollPlugin")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("AutoRollPlugin")]
[assembly: ComVisible(false)]
[assembly: Guid("c303405d-e66c-4316-9cdb-4e3ca15c6360")]
[assembly: AssemblyFileVersion("2.1.1.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("2.1.1.0")]
namespace LordAshes;

[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInPlugin("org.lordashes.plugins.autoroll", "Auto Roll Plug-In", "2.1.1")]
public class AutoRollPlugin : BaseUnityPlugin
{
	[HarmonyPatch(typeof(UIDiceTray), "SetDiceUrl")]
	public static class UIDiceTraySetDiceUrl
	{
		public static bool Prefix(DiceRollDescriptor rollDescriptor, bool showResult)
		{
			return true;
		}

		public static void Postfix(DiceRollDescriptor rollDescriptor, bool showResult)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: 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)
			bool flag = false;
			DiceGroupDescriptor[] diceGroupDescriptors = rollDescriptor.DiceGroupDescriptors;
			foreach (DiceGroupDescriptor val in diceGroupDescriptors)
			{
				LoggingPlugin.LogTrace("Auto Roll Plug-In: Patch: Dice Resource Name = " + val.Name);
				if (val.Name != "")
				{
					flag = true;
				}
				else
				{
					LoggingPlugin.LogTrace("Auto Roll Plug-In: Patch: Ignoring Manually Added Dice");
				}
			}
			if (flag)
			{
				LoggingPlugin.LogTrace("Auto Roll Plug-In: Spawning Dice");
				if (callbackAutoSpawn != null)
				{
					callbackAutoSpawn();
				}
			}
		}
	}

	[HarmonyPatch(typeof(DiceRollManager), "SpawnNewRoll")]
	public static class PatchDiceRollManagerSpawnNewRoll
	{
		public static bool Prefix(RollId rollId, in DiceRollDescriptor diceRollDescriptor, float3 pos, bool isGmRoll, bool showResult)
		{
			return true;
		}

		public static void Postfix(RollId rollId, in DiceRollDescriptor diceRollDescriptor, float3 pos, bool isGmRoll, bool showResult)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			DiceGroupDescriptor[] diceGroupDescriptors = diceRollDescriptor.DiceGroupDescriptors;
			foreach (DiceGroupDescriptor val in diceGroupDescriptors)
			{
				LoggingPlugin.LogTrace("Auto Roll Plug-In: Patch: Dice '" + val.Name + "' Created");
			}
			if (callbackAutoRoll != null)
			{
				callbackAutoRoll(rollId);
			}
		}
	}

	[HarmonyPatch(typeof(Die), "Spawn")]
	public static class PatchDieSpawn
	{
		public static bool Prefix(ref Die __result)
		{
			return true;
		}

		public static void Postfix(ref Die __result)
		{
			//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_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			HeightHidePlane val = Object.FindObjectOfType<HeightHidePlane>();
			Quaternion rotation = Quaternion.Euler(new Vector3((float)random.Next(0, 180), (float)random.Next(0, 180), (float)random.Next(0, 180)));
			Vector3 position = default(Vector3);
			((Vector3)(ref position))..ctor(((Component)__result).transform.position.x, ((Component)__result).transform.position.y + val.Height / 25f, ((Component)__result).transform.position.z);
			((Component)__result).transform.position = position;
			((Component)__result).transform.rotation = rotation;
			LoggingPlugin.LogTrace("Auto Roll Plug-In: Adjusted Die: Pos: " + ((object)((Component)__result).transform.position/*cast due to .constrained prefix*/).ToString() + ", Rot: " + ((object)((Component)__result).transform.rotation/*cast due to .constrained prefix*/).ToString());
		}
	}

	public static class PatchAssistant
	{
		public static object GetProperty(object instance, string propertyName)
		{
			Type type = instance.GetType();
			foreach (PropertyInfo runtimeProperty in type.GetRuntimeProperties())
			{
				if (runtimeProperty.Name.Contains(propertyName))
				{
					return runtimeProperty.GetValue(instance);
				}
			}
			PropertyInfo[] properties = type.GetProperties();
			foreach (PropertyInfo propertyInfo in properties)
			{
				if (propertyInfo.Name.Contains(propertyName))
				{
					return propertyInfo.GetValue(instance);
				}
			}
			return null;
		}

		public static void SetProperty(object instance, string propertyName, object value)
		{
			Type type = instance.GetType();
			foreach (PropertyInfo runtimeProperty in type.GetRuntimeProperties())
			{
				if (runtimeProperty.Name.Contains(propertyName))
				{
					runtimeProperty.SetValue(instance, value);
					return;
				}
			}
			PropertyInfo[] properties = type.GetProperties();
			foreach (PropertyInfo propertyInfo in properties)
			{
				if (propertyInfo.Name.Contains(propertyName))
				{
					propertyInfo.SetValue(instance, value);
					break;
				}
			}
		}

		public static object GetField(object instance, string fieldName)
		{
			Type type = instance.GetType();
			foreach (FieldInfo runtimeField in type.GetRuntimeFields())
			{
				if (runtimeField.Name.Contains(fieldName))
				{
					return runtimeField.GetValue(instance);
				}
			}
			FieldInfo[] fields = type.GetFields();
			foreach (FieldInfo fieldInfo in fields)
			{
				if (fieldInfo.Name.Contains(fieldName))
				{
					return fieldInfo.GetValue(instance);
				}
			}
			return null;
		}

		public static void SetField(object instance, string fieldName, object value)
		{
			Type type = instance.GetType();
			foreach (FieldInfo runtimeField in type.GetRuntimeFields())
			{
				if (runtimeField.Name.Contains(fieldName))
				{
					runtimeField.SetValue(instance, value);
					return;
				}
			}
			FieldInfo[] fields = type.GetFields();
			foreach (FieldInfo fieldInfo in fields)
			{
				if (fieldInfo.Name.Contains(fieldName))
				{
					fieldInfo.SetValue(instance, value);
					break;
				}
			}
		}

		public static object UseMethod(object instance, string methodName, object[] parameters)
		{
			Type type = instance.GetType();
			foreach (MethodInfo runtimeMethod in type.GetRuntimeMethods())
			{
				if (runtimeMethod.Name.Contains(methodName))
				{
					return runtimeMethod.Invoke(instance, parameters);
				}
			}
			MethodInfo[] methods = type.GetMethods();
			foreach (MethodInfo methodInfo in methods)
			{
				if (methodInfo.Name.Contains(methodName))
				{
					return methodInfo.Invoke(instance, parameters);
				}
			}
			return null;
		}
	}

	public static class Utility
	{
		public static void PostOnMainPage(MemberInfo plugin)
		{
			SceneManager.sceneLoaded += delegate(Scene scene, LoadSceneMode mode)
			{
				//IL_0072: Unknown result type (might be due to invalid IL or missing references)
				//IL_0079: Expected O, but got Unknown
				try
				{
					if (((Scene)(ref scene)).name == "UI")
					{
						TextMeshProUGUI uITextByName = GetUITextByName("BETA");
						if (Object.op_Implicit((Object)(object)uITextByName))
						{
							((TMP_Text)uITextByName).text = "INJECTED BUILD - unstable mods";
						}
					}
					else
					{
						TextMeshProUGUI uITextByName2 = GetUITextByName("TextMeshPro Text");
						if (Object.op_Implicit((Object)(object)uITextByName2))
						{
							BepInPlugin val = (BepInPlugin)Attribute.GetCustomAttribute(plugin, typeof(BepInPlugin));
							if (((TMP_Text)uITextByName2).text.EndsWith("</size>"))
							{
								((TMP_Text)uITextByName2).text = ((TMP_Text)uITextByName2).text + "\n\nMods Currently Installed:\n";
							}
							TextMeshProUGUI val2 = uITextByName2;
							((TMP_Text)val2).text = ((TMP_Text)val2).text + "\nLord Ashes' " + val.Name + " - " + val.Version;
						}
					}
				}
				catch (Exception ex)
				{
					LoggingPlugin.LogError(ex.ToString());
				}
			};
		}

		public static bool isBoardLoaded()
		{
			return SimpleSingletonBehaviour<CameraController>.HasInstance && SingletonStateMBehaviour<BoardSessionManager, State<BoardSessionManager>>.HasInstance && !BoardSessionManager.IsLoading;
		}

		public static bool StrictKeyCheck(KeyboardShortcut check)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: 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)
			if (!((KeyboardShortcut)(ref check)).IsUp())
			{
				return false;
			}
			KeyCode[] array = new KeyCode[6];
			RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/);
			KeyCode[] array2 = (KeyCode[])(object)array;
			foreach (KeyCode val in array2)
			{
				if (Input.GetKey(val) != ((KeyboardShortcut)(ref check)).Modifiers.Contains(val))
				{
					return false;
				}
			}
			return true;
		}

		private static TextMeshProUGUI GetUITextByName(string name)
		{
			TextMeshProUGUI[] array = Object.FindObjectsOfType<TextMeshProUGUI>();
			for (int i = 0; i < array.Length; i++)
			{
				if (((Object)array[i]).name == name)
				{
					return array[i];
				}
			}
			return null;
		}
	}

	public static Action callbackAutoSpawn = null;

	public static Action<RollId> callbackAutoRoll = null;

	private static Random random = new Random();

	public const string Name = "Auto Roll Plug-In";

	public const string Guid = "org.lordashes.plugins.autoroll";

	public const string Version = "2.1.1";

	public const string Author = "Lord Ashes";

	private static AutoRollPlugin _self = null;

	private static float posRollX = 0f;

	private static float posRollY = 0f;

	private static float posRollZ = 0.5f;

	private static bool absolutePosition = false;

	private ConfigEntry<DiagnosticLevel> diagnostics { get; set; }

	private void Awake()
	{
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_013f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0145: Expected O, but got Unknown
		_self = this;
		LoggingPlugin.SetLogLevel(((BaseUnityPlugin)this).Config.Bind<DiagnosticLevel>("Settings", "Diagnostic Level", (DiagnosticLevel)3, (ConfigDescription)null).Value);
		LoggingPlugin.LogInfo(((object)this).GetType().AssemblyQualifiedName + ": Active. (Diagnostic Mode = " + ((object)LoggingPlugin.GetLogLevel()/*cast due to .constrained prefix*/).ToString() + ")");
		LoggingPlugin.LogInfo("Auto Roll Plug-In: Dice added via talespire://dice protocol will be auto added and rolled.");
		LoggingPlugin.LogInfo("Auto Roll Plug-In: For example:");
		LoggingPlugin.LogInfo("Auto Roll Plug-In: talespire://dice/Investigation:1D20+5");
		LoggingPlugin.LogInfo("Auto Roll Plug-In: talespire://dice/Attack:1D20+5/Damage:2D6+3");
		posRollZ = ((BaseUnityPlugin)this).Config.Bind<float>("Setting", "Extra Bounce Height", 0f, (ConfigDescription)null).Value;
		posRollX = ((BaseUnityPlugin)this).Config.Bind<float>("Setting", "Roll Position X", 0f, (ConfigDescription)null).Value;
		posRollY = ((BaseUnityPlugin)this).Config.Bind<float>("Setting", "Roll Position Y", 0f, (ConfigDescription)null).Value;
		absolutePosition = ((BaseUnityPlugin)this).Config.Bind<bool>("Setting", "Roll Position Is Sbaolute", false, (ConfigDescription)null).Value;
		callbackAutoSpawn = SpawnDice;
		callbackAutoRoll = RollDice;
		Harmony val = new Harmony("org.lordashes.plugins.autoroll");
		val.PatchAll();
		Utility.PostOnMainPage(((object)this).GetType());
	}

	private void Update()
	{
	}

	public void SpawnDice()
	{
		LoggingPlugin.LogDebug("Auto Roll Plug-In: Spawning Dice");
		LoggingPlugin.LogTrace("Auto Roll Plug-In: Getting Dice Tray");
		UIDiceTray val = Object.FindObjectOfType<UIDiceTray>();
		LoggingPlugin.LogTrace("Auto Roll Plug-In: Saving Left Mouse Button Held");
		bool flag = (bool)PatchAssistant.GetField(val, "_leftMouseButtonHeld");
		PatchAssistant.SetField(val, "_leftMouseButtonHeld", true);
		LoggingPlugin.LogTrace("Auto Roll Plug-In: Performing Spawn");
		val.SpawnDice();
		LoggingPlugin.LogTrace("Auto Roll Plug-In: Restoring Left Mouse Button Held");
		PatchAssistant.SetField(val, "_leftMouseButtonHeld", flag);
	}

	public void RollDice(RollId rollId)
	{
		//IL_000c: 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_002e: Unknown result type (might be due to invalid IL or missing references)
		LoggingPlugin.LogDebug("Auto Roll Plug-In: Getting Ready To Roll Dice");
		if (rollId.AsLong != -1)
		{
			((MonoBehaviour)this).StartCoroutine(DelayedRoll(rollId));
			((MonoBehaviour)this).StartCoroutine(DelayedHide(rollId, ((BaseUnityPlugin)this).Config.Bind<float>("Settings", "Seconds Before Dice Clear", 5f, (ConfigDescription)null).Value));
		}
	}

	private unsafe IEnumerator DelayedRoll(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)
		LoggingPlugin.LogDebug("Auto Roll Plug-In: Delayed Roll");
		if (rollId.AsLong != -1)
		{
			yield return (object)new WaitForSeconds(0.5f);
			LoggingPlugin.LogInfo("Auto Roll Plug-In: Rolling Dice");
			DiceRollManager dm = Object.FindObjectOfType<DiceRollManager>();
			LoggingPlugin.LogTrace("Auto Roll Plug-In: Rolling Dice (Roll Id: " + ((object)(*(RollId*)(&rollId))/*cast due to .constrained prefix*/).ToString() + ")");
			if (absolutePosition)
			{
				dm.GatherDice(new Vector3(posRollX, posRollY, posRollZ), rollId);
			}
			else if (posRollX != 0f || posRollY != 0f || posRollZ != 0f)
			{
				dm.GatherDice(((Component)SimpleSingletonBehaviour<CameraController>.Instance).transform.position + new Vector3(posRollX, posRollY, posRollZ), rollId);
			}
			dm.ThrowDice(rollId, new float3(0f, 1f, 0f));
		}
	}

	private unsafe IEnumerator DelayedHide(RollId rollId, float delayHide)
	{
		//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)
		LoggingPlugin.LogDebug("Auto Roll Plug-In: Dice Cleanup");
		if (delayHide >= 0f)
		{
			LoggingPlugin.LogTrace("Auto Roll Plug-In: Wait " + delayHide + " Seconds For Cleanup");
			yield return (object)new WaitForSeconds(delayHide);
			LoggingPlugin.LogTrace("Auto Roll Plug-In: Cleanup Of Roll " + ((object)(*(RollId*)(&rollId))/*cast due to .constrained prefix*/).ToString() + " Started");
			DiceRollManager drm = Object.FindObjectOfType<DiceRollManager>();
			if ((Object)(object)drm != (Object)null)
			{
				drm.RemoveRoll(rollId);
			}
		}
		else
		{
			LoggingPlugin.LogTrace("Auto Roll Plug-In: No Dice Cleanup Desired");
		}
	}
}