Decompiled source of GroupViewPlugin v1.1.0

GroupViewPlugin.dll

Decompiled a month ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security.Cryptography;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using Bounce.Singletons;
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("GroupViewPlugin")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("GroupViewPlugin")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("GroupViewPlugin")]
[assembly: ComVisible(false)]
[assembly: Guid("c303405d-e66c-4316-9cdb-4e3ca15c6360")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace LordAshes;

[BepInPlugin("org.lordashes.plugins.groupview", "Group View Plugin", "1.0.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class GroupViewPlugin : BaseUnityPlugin
{
	public static class Utility
	{
		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;
		}

		public static Guid GuidFromString(string input)
		{
			using MD5 mD = MD5.Create();
			byte[] b = mD.ComputeHash(Encoding.Default.GetBytes(input));
			return new Guid(b);
		}

		public static GameObject GetBaseLoader(CreatureGuid cid)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				CreatureBoardAsset val = null;
				CreaturePresenter.TryGetAsset(cid, ref val);
				if ((Object)(object)val != (Object)null)
				{
					Transform match = null;
					Traverse(((Component)val).transform, "BaseLoader", 0, 10, ref match);
					if ((Object)(object)match != (Object)null)
					{
						Debug.Log((object)("Group View Plugin: Base Loader '" + ((Object)match.GetChild(0)).name + "' Found"));
						return ((Component)match.GetChild(0)).gameObject;
					}
					Debug.LogWarning((object)"Group View Plugin: Could Not Find Base Loader");
					return null;
				}
				return null;
			}
			catch
			{
				return null;
			}
		}

		public static GameObject GetAssetLoader(CreatureGuid cid)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				CreatureBoardAsset val = null;
				CreaturePresenter.TryGetAsset(cid, ref val);
				if ((Object)(object)val != (Object)null)
				{
					Transform match = null;
					Traverse(((Component)val).transform, "AssetLoader", 0, 10, ref match);
					if ((Object)(object)match != (Object)null)
					{
						Debug.Log((object)("Group View Plugin: Asset Loader '" + ((Object)match.GetChild(0)).name + "' Found"));
						return ((Component)match.GetChild(0)).gameObject;
					}
					Debug.LogWarning((object)"Group View Plugin: Could Not Find Asset Loader");
					return null;
				}
				return null;
			}
			catch
			{
				return null;
			}
		}

		public static void Traverse(Transform root, string seek, int depth, int depthMax, ref Transform match)
		{
			try
			{
				if ((Object)(object)match != (Object)null)
				{
					return;
				}
				if (((Object)root).name == seek)
				{
					match = root;
					return;
				}
				foreach (Transform item in ExtensionMethods.Children(root))
				{
					if (depth < depthMax)
					{
						Traverse(item, seek, depth + 1, depthMax, ref match);
					}
				}
			}
			catch
			{
			}
		}

		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 + "\nLord Ashes' " + 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 enum DiagnosticLevel
	{
		none,
		error,
		warning,
		info,
		debug,
		ultra
	}

	public const string Name = "Group View Plugin";

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

	public const string Version = "1.0.0.0";

	public const string Author = "Lord Ashes";

	private bool showMenu = false;

	private static string coreFolder = "C:\\\\Users\\\\" + Environment.GetEnvironmentVariable("USERNAME") + "\\AppData\\LocalLow\\BouncyRock Entertainment\\TaleSpire\\LocalContentPacks";

	private static string baseFolder = "C:\\\\Users\\\\" + Environment.GetEnvironmentVariable("USERNAME") + "\\AppData\\LocalLow\\BouncyRock Entertainment\\TaleSpire\\LocalContentPacksByGroups";

	private static string pluginFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

	private string currentFolder = "";

	private List<string> folders = new List<string>();

	private GUIStyle buttons = new GUIStyle();

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

	private ConfigEntry<KeyboardShortcut> trigger { get; set; }

	private void Awake()
	{
		//IL_0068: Unknown result type (might be due to invalid IL or missing references)
		//IL_0264: Unknown result type (might be due to invalid IL or missing references)
		diagnostics = ((BaseUnityPlugin)this).Config.Bind<DiagnosticLevel>("Settings", "Diagnostic Level", DiagnosticLevel.info, (ConfigDescription)null);
		Debug.Log((object)("Group View Plugin: Active. (Diagnostic Mode = " + diagnostics.Value.ToString() + ")"));
		trigger = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Hotkeys", "Activate", new KeyboardShortcut((KeyCode)278, Array.Empty<KeyCode>()), (ConfigDescription)null);
		coreFolder = ((BaseUnityPlugin)this).Config.Bind<string>("Settings", "Core Talespire Mods Folder", coreFolder, (ConfigDescription)null).Value;
		if (!coreFolder.EndsWith("/"))
		{
			coreFolder += "/";
		}
		baseFolder = ((BaseUnityPlugin)this).Config.Bind<string>("Settings", "Actual Mods Content Root Folder", baseFolder, (ConfigDescription)null).Value;
		if (!baseFolder.EndsWith("/"))
		{
			baseFolder += "/";
		}
		pluginFolder = pluginFolder.Replace("\\", "/");
		coreFolder = coreFolder.Replace("\\", "/");
		baseFolder = baseFolder.Replace("\\", "/");
		Debug.Log((object)("Group View Plugin: Plugin Folder: " + pluginFolder));
		Debug.Log((object)("Group View Plugin: Core Folder: " + coreFolder));
		Debug.Log((object)("Group View Plugin: Content Folder: " + baseFolder));
		if (Directory.EnumerateFiles(coreFolder, "_*.tsmod").Count() == 0)
		{
			Debug.Log((object)("Group View Plugin: Copying Core Asset From " + pluginFolder + " To " + coreFolder));
			File.Copy(pluginFolder + "/_GroupViewPluginAsset.tsMod", coreFolder + "_GroupViewPluginAsset.tsMod");
		}
		currentFolder = baseFolder;
		if (File.Exists(baseFolder + "active_folder.txt"))
		{
			currentFolder = File.ReadAllText(baseFolder + "active_folder.txt");
		}
		((MonoBehaviour)this).StartCoroutine(ActivateFolder(currentFolder));
		buttons.normal.textColor = Color.white;
		buttons.fontStyle = (FontStyle)1;
		buttons.normal.background = Image.LoadTexture("org.lordashes.plugins.groupview.buttons.background.png", (CacheType)999);
		Utility.PostOnMainPage(((object)this).GetType());
	}

	private void Update()
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		KeyboardShortcut value = trigger.Value;
		if (((KeyboardShortcut)(ref value)).IsUp())
		{
			showMenu = !showMenu;
			if (showMenu)
			{
				GetFolder(ref folders, currentFolder);
				((MonoBehaviour)this).StartCoroutine(ActivateFolder(currentFolder));
			}
		}
	}

	private void OnGUI()
	{
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
		if (!showMenu)
		{
			return;
		}
		int num = Screen.height - 460;
		foreach (string folder in folders)
		{
			if (GUI.Button(new Rect((float)(Screen.width / 2 - 250), (float)num, 500f, 20f), "   " + ((folder == "◄") ? folder : folder.Substring(baseFolder.Length - 1)), buttons))
			{
				if (folder == "◄")
				{
					currentFolder = currentFolder.Substring(0, currentFolder.Replace("\\", "/").LastIndexOf("/"));
					currentFolder = currentFolder.Substring(0, currentFolder.Replace("\\", "/").LastIndexOf("/"));
					Debug.Log((object)("Group View Plugin: Backing To " + currentFolder));
				}
				else
				{
					currentFolder = folder;
					Debug.Log((object)("Group View Plugin: Moving Into " + currentFolder));
				}
				currentFolder = currentFolder.Replace("\\", "/");
				if (!currentFolder.EndsWith("/"))
				{
					currentFolder += "/";
				}
				GetFolder(ref folders, currentFolder);
				((MonoBehaviour)this).StartCoroutine(ActivateFolder(currentFolder));
			}
			num -= 25;
		}
		GUI.Button(new Rect(1200f, (float)(Screen.height - 330), 500f, 20f), "   Current Folder: " + currentFolder.Substring(baseFolder.Length - 1), buttons);
	}

	private void GetFolder(ref List<string> folders, string currentFolder)
	{
		folders = Directory.EnumerateDirectories(currentFolder).ToList();
		if (currentFolder.Length > baseFolder.Length)
		{
			folders.Insert(0, "◄");
		}
	}

	private IEnumerator ActivateFolder(string folder)
	{
		string returnFolder = baseFolder;
		if (File.Exists(baseFolder + "active_folder.txt"))
		{
			returnFolder = File.ReadAllText(baseFolder + "active_folder.txt");
		}
		Debug.Log((object)"Group View Plugin: Returning Items");
		foreach (string item2 in Directory.EnumerateFiles(coreFolder, "*.tsMod"))
		{
			if (!Path.GetFileName(item2).StartsWith("_"))
			{
				Debug.Log((object)("Group View Plugin: Returning " + item2 + " To " + returnFolder + Path.GetFileName(item2)));
				File.Move(item2, returnFolder + Path.GetFileName(item2));
				yield return (object)new WaitForSeconds(0.1f);
			}
		}
		File.WriteAllText(baseFolder + "active_folder.txt", folder);
		Debug.Log((object)"Group View Plugin: Getting Items");
		foreach (string item in Directory.EnumerateFiles(folder, "*.tsMod"))
		{
			if (!Path.GetFileName(item).StartsWith("_"))
			{
				Debug.Log((object)("Group View Plugin: Getting " + item + " To " + coreFolder + Path.GetFileName(item)));
				File.Move(item, coreFolder + Path.GetFileName(item));
				yield return (object)new WaitForSeconds(0.1f);
			}
		}
	}
}