Decompiled source of RollNamePlugin v1.2.0

RollNamePlugin.dll

Decompiled 9 months ago
using System;
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 Bounce.Singletons;
using HarmonyLib;
using TMPro;
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("RollNamePlugin")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("RollNamePlugin")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("RollNamePlugin")]
[assembly: ComVisible(false)]
[assembly: Guid("c303405d-e66c-4316-9cdb-4e3ca15c6360")]
[assembly: AssemblyFileVersion("1.2.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.2.0.0")]
namespace LordAshes;

[BepInPlugin("org.lordashes.plugins.rollname", "Roll Name Plug-In", "1.2.0.0")]
public class RollNamePlugin : BaseUnityPlugin
{
	public static class Utility
	{
		private static GameInput gameInputInstance;

		private static MethodInfo gameInputDisable;

		private static MethodInfo gameInputEnable;

		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 string GetCreatureName(string nameBlock)
		{
			if (nameBlock == null)
			{
				return "(Unknown)";
			}
			if (!nameBlock.Contains("<size=0>"))
			{
				return nameBlock;
			}
			return nameBlock.Substring(0, nameBlock.IndexOf("<size=0>")).Trim();
		}

		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 + "\nPlugin Masters' " + val.Name + " - " + val.Version;
						}
					}
				}
				catch (Exception ex)
				{
					Debug.Log((object)ex);
				}
			};
		}

		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 void GameInputEnabled(bool setting)
		{
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Expected O, but got Unknown
			if (gameInputInstance == null || gameInputDisable == null || gameInputEnable == null)
			{
				try
				{
					Debug.Log((object)"Plane Image Plugin: Getting Game Input Reference");
					gameInputInstance = null;
					gameInputDisable = null;
					gameInputEnable = null;
					gameInputInstance = (GameInput)(from f in typeof(ControllerManager).GetRuntimeFields()
						where f.Name == "_gameInput"
						select f).ToArray()[0].GetValue(null);
					gameInputDisable = (from m in typeof(GameInput).GetMethods()
						where m.Name == "Disable"
						select m).ElementAt(0);
					gameInputEnable = (from m in typeof(GameInput).GetMethods()
						where m.Name == "Enable"
						select m).ElementAt(0);
				}
				catch
				{
					Debug.LogWarning((object)"Plane Image Plugin: Unable To Get Game Input Reference Or Reference To One Of Its Methods");
				}
			}
			if (setting)
			{
				Debug.Log((object)"Plane Image Plugin: Enabling Game Input");
				gameInputEnable.Invoke(gameInputInstance, new object[0]);
			}
			else
			{
				Debug.Log((object)"Plane Image Plugin: Disabling Game Input");
				gameInputDisable.Invoke(gameInputInstance, new object[0]);
			}
		}
	}

	[HarmonyPatch(typeof(UIDiceTray), "UpdateTrayDice")]
	public static class PatchUpdateTrayDice
	{
		public static bool Prefix(DieKind kind, int numberOfDice)
		{
			Debug.Log((object)"Roll Name Plugin: Game Input Disabled");
			rollName = "";
			Utility.GameInputEnabled(setting: false);
			isDiceTrayOpen = true;
			return true;
		}
	}

	[HarmonyPatch(typeof(DiceManager), "CreateLocalRoll")]
	public static class PatchCreateLocalRoll
	{
		public static bool Prefix(ref DiceRollDescriptor rollDescriptor, bool isGmRoll, bool showResult, RollId rollId)
		{
			//IL_0099: 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)
			if (rollDescriptor.DiceGroupDescriptors == null)
			{
				return true;
			}
			if (rollName != "" && (rollDescriptor.DiceGroupDescriptors[0].Name == null || rollDescriptor.DiceGroupDescriptors[0].Name.Trim() == ""))
			{
				Debug.Log((object)("Roll Name Plugin: Applying roll name '" + rollName + "'"));
				rollDescriptor = new DiceRollDescriptor((DiceGroupDescriptor[])(object)new DiceGroupDescriptor[1]
				{
					new DiceGroupDescriptor(rollName, rollDescriptor.DiceGroupDescriptors[0].OperandDescriptor)
				});
				Utility.GameInputEnabled(setting: true);
				Debug.Log((object)"Roll Name Plugin: Game Input Enabled");
				isDiceTrayOpen = false;
			}
			return true;
		}
	}

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

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

	public const string Version = "1.2.0.0";

	private static bool isDiceTrayOpen = false;

	private static string rollName = "";

	private static GUIStyle rollNameTextFieldStyle = null;

	private static ConfigEntry<int> detectPos;

	private void Awake()
	{
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_004c: Expected O, but got Unknown
		Debug.Log((object)("Roll Name Plugin: " + ((object)this).GetType().AssemblyQualifiedName + " Active."));
		detectPos = ((BaseUnityPlugin)this).Config.Bind<int>("Settings", "Y Position", 830, (ConfigDescription)null);
		Harmony val = new Harmony("org.lordashes.plugins.rollname");
		val.PatchAll();
		Utility.PostOnMainPage(((object)this).GetType());
	}

	private void OnGUI()
	{
		//IL_0093: 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_002f: Expected O, but got Unknown
		//IL_0039: 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)
		if (isDiceTrayOpen)
		{
			if (rollNameTextFieldStyle == null)
			{
				rollNameTextFieldStyle = new GUIStyle(GUI.skin.textField);
				rollNameTextFieldStyle.active.textColor = Color.white;
				rollNameTextFieldStyle.normal.textColor = Color.white;
				rollNameTextFieldStyle.fontSize = 24;
				rollNameTextFieldStyle.alignment = (TextAnchor)4;
			}
			rollName = GUI.TextField(new Rect((float)(Screen.width / 2 - 100), (float)detectPos.Value, 200f, 30f), rollName, rollNameTextFieldStyle);
		}
	}
}