Decompiled source of PrivateRollPlugin v1.0.1

PrivateRollPlugin.dll

Decompiled 2 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Bounce.Singletons;
using GameChat.UI;
using HarmonyLib;
using ModdingTales;
using UnityEngine;

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

[BepInPlugin("org.lordashes.plugins.privateroll", "Private Roll Plugin", "1.0.1.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class PrivateRollPlugin : BaseUnityPlugin
{
	[HarmonyPatch(typeof(DiceManager), "GetNewDiceRollId")]
	public static class PatchGetNewDiceRollId
	{
		public static void Postfix(ref RollId __result)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			if (isPrivateRoll)
			{
				__result = new RollId(__result.AsLong * -1);
			}
			string[] obj = new string[5] { "New Roll Is ", null, null, null, null };
			long asLong = __result.AsLong;
			obj[1] = asLong.ToString();
			obj[2] = " (Private = ";
			obj[3] = isPrivateRoll.ToString();
			obj[4] = ")";
			LoggingPlugin.LogTrace(string.Concat(obj));
		}
	}

	[HarmonyPatch(typeof(DiceManager), "CreateLocalRoll")]
	public static class PatchCreateLocalRoll
	{
		public static bool Prefix(ref DiceRollDescriptor rollDescriptor, bool isGmRoll, bool showResult, RollId rollId)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			if (rollDescriptor.DiceGroupDescriptors == null)
			{
				return true;
			}
			if (rollId.AsLong < 0 && (rollDescriptor.DiceGroupDescriptors[0].Name == null || rollDescriptor.DiceGroupDescriptors[0].Name.Trim() == ""))
			{
				LoggingPlugin.LogDebug("Signing Private Roll");
				rollDescriptor = new DiceRollDescriptor((DiceGroupDescriptor[])(object)new DiceGroupDescriptor[1]
				{
					new DiceGroupDescriptor("(Private) " + rollDescriptor.DiceGroupDescriptors[0].Name, rollDescriptor.DiceGroupDescriptors[0].OperandDescriptor)
				});
			}
			isDiceTrayOpen = false;
			return true;
		}
	}

	[HarmonyPatch(typeof(DiceManager), "RegisterDie")]
	public static class PatchAddDie
	{
		public static void Postfix(Die die, ClientGuid clientId, RollId rollId, bool gmOnly, bool showResult)
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			LoggingPlugin.LogTrace("Client " + ((object)(ClientGuid)(ref clientId)).ToString() + " Registered Dice RollId " + ((object)(RollId)(ref rollId)).ToString());
			if (rollId.AsLong < 0 && !LocalClient.IsInGmMode && clientId != LocalClient.Id)
			{
				LoggingPlugin.LogDebug("Private Roll By Client " + ((object)(ClientGuid)(ref clientId)).ToString() + ". Hiding Dice.");
				((Component)die).gameObject.SetActive(false);
			}
		}
	}

	[HarmonyPatch(typeof(UIDiceRollResult), "DisplayResult")]
	public static class PatchDisplayResult
	{
		public static bool Prefix(RollResults rollResultData, ClientGuid sender)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: 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)
			if (rollResultData.RollId.AsLong < 0 && !LocalClient.IsInGmMode && sender != LocalClient.Id)
			{
				LoggingPlugin.LogDebug("Private Roll Results - Supressing Result Popup");
				return false;
			}
			return true;
		}
	}

	[HarmonyPatch(typeof(UIChatMessageManager), "AddDiceResultMessage")]
	public static class PatchAddDiceResultMessage
	{
		public static bool Prefix(RollResults diceResult, ResultsOrigin origin, ClientGuid sender, bool hidden)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: 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)
			if (diceResult.RollId.AsLong < 0 && !LocalClient.IsInGmMode && sender != LocalClient.Id)
			{
				LoggingPlugin.LogDebug("Private Roll Results - Supressing Chat Message");
				return false;
			}
			return true;
		}
	}

	[HarmonyPatch(typeof(UIDiceTray), "UpdateTrayDice")]
	public static class PatchUpdateTrayDice
	{
		public static bool Prefix(DieKind kind, int numberOfDice)
		{
			LoggingPlugin.LogTrace("Die Loaded Into Dice Tray");
			isDiceTrayOpen = true;
			return true;
		}
	}

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

		public static float ParseFloat(string value)
		{
			return float.Parse(value, CultureInfo.InvariantCulture);
		}

		public static GameObject FindInHierarchy(GameObject start, string seekName)
		{
			List<GameObject> results = new List<GameObject>();
			bool done = false;
			Traverse(start.transform, seekName, null, single: true, ref results, ref done);
			return (results.Count > 0) ? results.ElementAt(0) : null;
		}

		public static GameObject FindInHierarchyViaPartialName(GameObject start, string seekName)
		{
			List<GameObject> results = new List<GameObject>();
			bool done = false;
			Traverse(start.transform, seekName, null, single: true, ref results, ref done, partial: true);
			return (results.Count > 0) ? results.ElementAt(0) : null;
		}

		public static GameObject[] FindAllInHierarchy(GameObject start, string seekName)
		{
			List<GameObject> results = new List<GameObject>();
			bool done = false;
			Traverse(start.transform, seekName, null, single: false, ref results, ref done);
			return results.ToArray();
		}

		public static GameObject[] FindAllInHierarchyViaPartialName(GameObject start, string seekName)
		{
			List<GameObject> results = new List<GameObject>();
			bool done = false;
			Traverse(start.transform, seekName, null, single: false, ref results, ref done, partial: true);
			return results.ToArray();
		}

		public static GameObject FindWithComponentInHierarchy(GameObject start, string seekType)
		{
			List<GameObject> results = new List<GameObject>();
			bool done = false;
			Traverse(start.transform, null, seekType, single: true, ref results, ref done);
			return (results.Count > 0) ? results.ElementAt(0) : null;
		}

		public static GameObject[] FindAllWithComponentInHierarchy<T>(GameObject start, string seekType)
		{
			List<GameObject> results = new List<GameObject>();
			bool done = false;
			Traverse(start.transform, null, seekType, single: false, ref results, ref done);
			return results.ToArray();
		}

		public static void Traverse(Transform root, string seekName, string seekType, bool single, ref List<GameObject> results, ref bool done, bool partial = false)
		{
			try
			{
				if ((seekName == null || seekName == ((Object)((Component)root).gameObject).name || (partial && ((Object)((Component)root).gameObject).name.Contains(seekName))) && (seekType == null || (Object)(object)((Component)root).GetComponent(seekType) != (Object)null))
				{
					LoggingPlugin.LogTrace("Matched '" + ((Object)((Component)root).gameObject).name + "'");
					results.Add(((Component)root).gameObject);
					if (single)
					{
						done = true;
						return;
					}
				}
				foreach (Transform item in ExtensionMethods.Children(root))
				{
					if (!done)
					{
						Traverse(item, seekName, seekType, single, ref results, ref done, partial);
					}
				}
			}
			catch
			{
			}
		}

		public static object LookUp(in Dictionary<string, object> dictionary, string key)
		{
			foreach (KeyValuePair<string, object> item in dictionary)
			{
				if (item.Key.ToUpper() == key.ToUpper())
				{
					return item.Value;
				}
			}
			return null;
		}

		public static void PostOnMainPage(BaseUnityPlugin plugin)
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Expected O, but got Unknown
			string text = "Lord Ashes" + ("Lord Ashes".ToUpper().EndsWith("S") ? "'" : "'s");
			ModdingUtils.Initialize(plugin, new ManualLogSource("Private Roll Plugin"), text, false);
		}
	}

	private static bool isPrivateRoll = false;

	private static bool isDiceTrayOpen = false;

	public const string Name = "Private Roll Plugin";

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

	public const string Version = "1.0.1.0";

	public const string Author = "Lord Ashes";

	public static PrivateRollPlugin _self = null;

	public static Texture2D[] icons = (Texture2D[])(object)new Texture2D[2];

	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_008d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0093: Expected O, but got Unknown
		_self = this;
		LoggingPlugin.SetLogLevel(((BaseUnityPlugin)this).Config.Bind<DiagnosticLevel>("Settings", "Diagnostic Level", (DiagnosticLevel)3, (ConfigDescription)null).Value);
		string? assemblyQualifiedName = ((object)this).GetType().AssemblyQualifiedName;
		DiagnosticLevel logLevel = LoggingPlugin.GetLogLevel();
		Debug.Log((object)(assemblyQualifiedName + ": Active. (Diagnostic Mode = " + ((object)(DiagnosticLevel)(ref logLevel)).ToString() + ")"));
		icons[0] = Image.LoadTexture("org.lordashes.plugins.privateroll.public.png", (CacheType)999);
		icons[1] = Image.LoadTexture("org.lordashes.plugins.privateroll.private.png", (CacheType)999);
		Harmony val = new Harmony("org.lordashes.plugins.privateroll");
		val.PatchAll();
		Utility.PostOnMainPage((BaseUnityPlugin)(object)this);
	}

	private void Update()
	{
		//IL_000b: 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)
		KeyboardShortcut val = new KeyboardShortcut((KeyCode)281, Array.Empty<KeyCode>());
		if (((KeyboardShortcut)(ref val)).IsUp())
		{
			isPrivateRoll = !isPrivateRoll;
			LoggingPlugin.LogInfo("Private Rolls Are " + isPrivateRoll);
		}
	}

	private void OnGUI()
	{
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		if (isDiceTrayOpen && GUI.Button(new Rect((float)Screen.width * 0.55f, (float)Screen.height * 0.605f, 48f, 48f), (Texture)(object)(isPrivateRoll ? icons[1] : icons[0])))
		{
			isPrivateRoll = !isPrivateRoll;
		}
	}
}