Decompiled source of SpawnPartyPlugin v1.0.0

SpawnPartyPlugin.dll

Decompiled 3 weeks ago
using System.Collections;
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 HarmonyLib;
using ModdingTales;
using Unity.Mathematics;
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("EnhancedAssetsPlugin")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Nth Dimension")]
[assembly: AssemblyProduct("EnhancedAssetsPlugin")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("EnhancedAssetsPlugin")]
[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.spawnparty", "Spawn Party Plugin", "1.0.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class SpawnPartyPlugin : BaseUnityPlugin
{
	[HarmonyPatch(typeof(CreaturePresenter), "OnCreatureAdded")]
	public static class PatcheCreaturePresenterOnCreatureAdded
	{
		public static void Postfix(in CreatureDataV3 creatureData)
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			if (creatureData.Alias == "Party")
			{
				LoggingPlugin.LogDebug("Spawned Party Pointer. Replacing with party minis.");
				((MonoBehaviour)_self).StartCoroutine(SpawnParty(creatureData.CreatureId));
			}
		}
	}

	[HarmonyPatch(typeof(CreatureBoardAsset), "OnCreatureDataChanged")]
	public static class PatcheCreatureBoardAssetOnCreatureDataChanged
	{
		public static void Postfix(CreatureBoardAsset __instance, in CreatureDataV3 newData)
		{
			//IL_0007: 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_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: 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)
			if (partyMembers.ContainsKey(__instance.CreatureId))
			{
				CreatureGuid creatureId = __instance.CreatureId;
				LoggingPlugin.LogTrace("Updating Stored CreatureData For Creature " + ((object)(CreatureGuid)(ref creatureId)).ToString());
				partyMembers[__instance.CreatureId] = newData;
			}
		}
	}

	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("Spawn Party Plugin"), text, false);
		}
	}

	public const string Name = "Spawn Party Plugin";

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

	public const string Version = "1.0.0.0";

	public const string Author = "Lord Ashes";

	public static KeyboardShortcut setTrigger;

	public static SpawnPartyPlugin _self = null;

	public static Dictionary<CreatureGuid, CreatureDataV3> partyMembers = new Dictionary<CreatureGuid, CreatureDataV3>();

	private static IEnumerator SpawnParty(CreatureGuid partyPointerCid)
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		LoggingPlugin.LogInfo("Spawning Party");
		CreatureBoardAsset asset = null;
		while (true)
		{
			CreaturePresenter.TryGetAsset(partyPointerCid, ref asset);
			if ((Object)(object)asset != (Object)null)
			{
				break;
			}
			yield return (object)new WaitForSeconds(1f);
		}
		LoggingPlugin.LogTrace("Party Pointer Reference Obtained");
		Vector3 pos = ((Component)asset).transform.position;
		foreach (CreatureDataV3 cdv3 in partyMembers.Values)
		{
			LoggingPlugin.LogDebug("Spawning Creature " + cdv3.Alias);
			CreatureManager.TryCreateAndAddNewCreature(cdv3, float3.op_Implicit(pos), quaternion.op_Implicit(Quaternion.identity), false, false, true);
			pos = new Vector3(pos.x + 1f, pos.y, pos.z);
		}
		CreatureGuid creatureId = asset.CreatureId;
		LoggingPlugin.LogDebug("Removing Pointer Creature " + ((object)(CreatureGuid)(ref creatureId)).ToString());
		CreatureManager.DeleteCreature(LocalClient.SelectedCreatureId, asset.UniqueId, false);
	}

	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_007f: Unknown result type (might be due to invalid IL or missing references)
		//IL_008a: Unknown result type (might be due to invalid IL or missing references)
		//IL_008f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0099: Unknown result type (might be due to invalid IL or missing references)
		//IL_009f: 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() + ")"));
		setTrigger = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Hotkeys", "Trigger To Save Selected Minis As Party Members", new KeyboardShortcut((KeyCode)277, (KeyCode[])(object)new KeyCode[1] { (KeyCode)305 }), (ConfigDescription)null).Value;
		Harmony val = new Harmony("org.lordashes.plugins.spawnparty");
		val.PatchAll();
		Utility.PostOnMainPage((BaseUnityPlugin)(object)this);
	}

	private void Update()
	{
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_0068: Unknown result type (might be due to invalid IL or missing references)
		//IL_006e: 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_007f: Unknown result type (might be due to invalid IL or missing references)
		if (((KeyboardShortcut)(ref setTrigger)).IsUp())
		{
			LoggingPlugin.LogDebug("Adding Selected Minis To Party");
			partyMembers.Clear();
			CreatureGuid[] array = null;
			LocalClient.TryGetLassoedCreatureIds(ref array);
			CreatureGuid[] array2 = array;
			for (int i = 0; i < array2.Length; i++)
			{
				CreatureGuid val = array2[i];
				LoggingPlugin.LogTrace("Adding Creature " + ((object)(CreatureGuid)(ref val)).ToString() + " To The Party");
				CreatureDataV3 value = default(CreatureDataV3);
				CreatureManager.TryGetCreatureData(val, ref value);
				partyMembers.Add(val, value);
			}
			((MonoBehaviour)_self).StartCoroutine(BaseIndicatorBlink(partyMembers.Keys.ToArray()));
		}
	}

	private IEnumerator BaseIndicatorBlink(CreatureGuid[] creatures)
	{
		foreach (CreatureGuid cid in creatures)
		{
			CreatureManager.SetCreatureExplicitHideState(cid, false);
		}
		yield return (object)new WaitForSeconds(0.25f);
		foreach (CreatureGuid cid2 in creatures)
		{
			CreatureManager.SetCreatureExplicitHideState(cid2, true);
		}
		yield return (object)new WaitForSeconds(0.25f);
		foreach (CreatureGuid cid3 in creatures)
		{
			CreatureManager.SetCreatureExplicitHideState(cid3, false);
		}
		yield return (object)new WaitForSeconds(0.25f);
		foreach (CreatureGuid cid4 in creatures)
		{
			CreatureManager.SetCreatureExplicitHideState(cid4, true);
		}
		yield return (object)new WaitForSeconds(0.25f);
		foreach (CreatureGuid cid5 in creatures)
		{
			CreatureManager.SetCreatureExplicitHideState(cid5, false);
		}
		yield return (object)new WaitForSeconds(0.25f);
		foreach (CreatureGuid cid6 in creatures)
		{
			CreatureManager.SetCreatureExplicitHideState(cid6, true);
		}
		yield return (object)new WaitForSeconds(0.25f);
		foreach (CreatureGuid cid7 in creatures)
		{
			CreatureManager.SetCreatureExplicitHideState(cid7, false);
		}
	}
}