Decompiled source of RoomViewPlugin v4.0.0

RoomViewPlugin.dll

Decompiled a week ago
using System;
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.ManagedCollections;
using Bounce.Singletons;
using Bounce.Unmanaged;
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("RoomViewPlugin")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Nth Dimension")]
[assembly: AssemblyProduct("TemplatePlugin")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("TemplatePlugin")]
[assembly: ComVisible(false)]
[assembly: Guid("c303405d-e66c-4316-9cdb-4e3ca15c6360")]
[assembly: AssemblyFileVersion("4.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("4.0.0.0")]
namespace LordAshes;

[BepInPlugin("org.lordashes.plugins.roomview", "Room View Plugin", "4.0.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class RoomViewPlugin : BaseUnityPlugin
{
	[HarmonyPatch(typeof(CreatureBoardAsset), "DropCommon")]
	public static class PatchMovableBoardAssetDropCommon
	{
		public static bool Prefix(CreatureBoardAsset __instance, Vector3 dropDestination, float height)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			string[] obj = new string[6] { "Patch: Asset ", null, null, null, null, null };
			CreatureGuid creatureId = __instance.CreatureId;
			obj[1] = ((object)(CreatureGuid)(ref creatureId)).ToString();
			obj[2] = " (";
			obj[3] = __instance.Name;
			obj[4] = ") Dropped To = ";
			obj[5] = ((object)(Vector3)(ref dropDestination)).ToString();
			LoggingPlugin.LogDebug(string.Concat(obj));
			ProcessHideVolumeStates();
			return true;
		}
	}

	[HarmonyPatch(typeof(MovableBoardAsset), "MoveTo")]
	public static class PatchMovableBoardAssetMoveTo
	{
		public static bool Prefix(MovableBoardAsset __instance, Vector3 pos, bool pickupLift = true)
		{
			LoggingPlugin.LogDebug("Patch: Asset " + ((Object)__instance).name + " Moved To = " + ((object)(Vector3)(ref pos)).ToString());
			if (preview)
			{
				ProcessHideVolumeStates();
			}
			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("Room View Plugin"), text, false);
		}
	}

	[CompilerGenerated]
	private sealed class <WarnAboutLogLevel>d__16 : IEnumerator<object>, IDisposable, IEnumerator
	{
		private int <>1__state;

		private object <>2__current;

		public RoomViewPlugin <>4__this;

		object IEnumerator<object>.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		object IEnumerator.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		[DebuggerHidden]
		public <WarnAboutLogLevel>d__16(int <>1__state)
		{
			this.<>1__state = <>1__state;
		}

		[DebuggerHidden]
		void IDisposable.Dispose()
		{
			<>1__state = -2;
		}

		private bool MoveNext()
		{
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Expected O, but got Unknown
			//IL_0029: 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)
			switch (<>1__state)
			{
			default:
				return false;
			case 0:
				<>1__state = -1;
				break;
			case 1:
				<>1__state = -1;
				break;
			}
			try
			{
				DiagnosticLevel logLevel = LoggingPlugin.GetLogLevel();
				SystemMessage.DisplayInfoText("Room View Plugin: Using '" + ((object)(DiagnosticLevel)(ref logLevel)).ToString() + "' diagnostics.\r\nUse 'Info' for better performance", 10f, 0f);
				SystemMessage.DisplayInfoText("Room View Plugin: Use 'Debug' or 'Trace' for\r\ntroubleshooting only.", 10f, 0f);
			}
			catch
			{
				goto IL_0072;
			}
			return false;
			IL_0072:
			<>2__current = (object)new WaitForSeconds(1f);
			<>1__state = 1;
			return true;
		}

		bool IEnumerator.MoveNext()
		{
			//ILSpy generated this explicit interface implementation from .override directive in MoveNext
			return this.MoveNext();
		}

		[DebuggerHidden]
		void IEnumerator.Reset()
		{
			throw new NotSupportedException();
		}
	}

	private static HideVolumeManager hvm = null;

	private static FieldInfo _hideVolumeItemsField = null;

	public const string Name = "Room View Plugin";

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

	public const string Version = "4.0.0.0";

	public const string Author = "Lord Ashes";

	public static RoomViewPlugin _self = null;

	public static bool rehide = true;

	public static bool preview = true;

	private static void ProcessHideVolumeStates()
	{
		//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)
		//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_011c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0121: Unknown result type (might be due to invalid IL or missing references)
		//IL_0126: Unknown result type (might be due to invalid IL or missing references)
		//IL_019a: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ee: 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)
		//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_026c: Unknown result type (might be due to invalid IL or missing references)
		List<HideVolumeItem> hideVolumes = GetHideVolumes();
		List<CreatureBoardAsset> revealingAssets = GetRevealingAssets();
		LoggingPlugin.LogDebug("Revealers: " + string.Join(", ", revealingAssets.Select(delegate(CreatureBoardAsset r)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			CreatureGuid creatureId = r.CreatureId;
			return ((object)(CreatureGuid)(ref creatureId)).ToString();
		})));
		foreach (HideVolumeItem hvi in hideVolumes)
		{
			bool flag = revealingAssets.Any((CreatureBoardAsset r) => IsInside(hvi.HideVolume.Bounds, ((Component)((MovableBoardAsset)r).Rotator).transform.position));
			string[] obj = new string[6]
			{
				"Patch: Checking Hide Volume ",
				((Object)hvi).name,
				" (",
				null,
				null,
				null
			};
			NGuid id = hvi.HideVolume.Id;
			obj[3] = ((object)(NGuid)(ref id)).ToString();
			obj[4] = "), Revealers Present = ";
			obj[5] = flag.ToString();
			LoggingPlugin.LogDebug(string.Concat(obj));
			if (flag)
			{
				string[] obj2 = new string[5]
				{
					"Patch: Switching Hide Volume ",
					((Object)hvi).name,
					" (",
					null,
					null
				};
				id = hvi.HideVolume.Id;
				obj2[3] = ((object)(NGuid)(ref id)).ToString();
				obj2[4] = ") To Visible";
				LoggingPlugin.LogDebug(string.Concat(obj2));
				hvi.ChangeIsActive(false);
				hvi.ChangeHideCreatures(true);
				hvi.ChangeHideLights(true);
				hvi.ChangeHidePlaceables(true);
				if ((Object)(object)hvm != (Object)null)
				{
					hvm.SetHideVolumeState(hvi.HideVolume);
				}
			}
			else if (!flag && rehide)
			{
				string[] obj3 = new string[5]
				{
					"Patch: Switching Hide Volume ",
					((Object)hvi).name,
					" (",
					null,
					null
				};
				id = hvi.HideVolume.Id;
				obj3[3] = ((object)(NGuid)(ref id)).ToString();
				obj3[4] = ") To Hidden";
				LoggingPlugin.LogDebug(string.Concat(obj3));
				hvi.ChangeIsActive(true);
				hvi.ChangeHideCreatures(true);
				hvi.ChangeHideLights(true);
				hvi.ChangeHidePlaceables(true);
				if ((Object)(object)hvm != (Object)null)
				{
					hvm.SetHideVolumeState(hvi.HideVolume);
				}
			}
		}
	}

	private static List<HideVolumeItem> GetHideVolumes()
	{
		if (_hideVolumeItemsField == null)
		{
			hvm = SimpleSingletonBehaviour<HideVolumeManager>.Instance;
			Type type = ((object)hvm).GetType();
			_hideVolumeItemsField = type.GetField("_hideVolumeItems", BindingFlags.Static | BindingFlags.NonPublic);
		}
		BList<HideVolumeItem> val = (BList<HideVolumeItem>)_hideVolumeItemsField.GetValue(null);
		return IReadOnlyListExtensions.ToList<HideVolumeItem>((IReadOnlyList<HideVolumeItem>)val);
	}

	private static bool IsInside(Bounds bounds, Vector3 test)
	{
		//IL_0003: Unknown result type (might be due to invalid IL or missing references)
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0015: 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_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0045: Unknown result type (might be due to invalid IL or missing references)
		if (((Bounds)(ref bounds)).min.x <= test.x && test.x <= ((Bounds)(ref bounds)).max.x && ((Bounds)(ref bounds)).min.z <= test.z && test.z <= ((Bounds)(ref bounds)).max.z)
		{
			return true;
		}
		return 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_009e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a4: Invalid comparison between Unknown and I4
		//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c7: 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() + ")"));
		rehide = ((BaseUnityPlugin)this).Config.Bind<bool>("Settings", "Rehide Rooms", true, (ConfigDescription)null).Value;
		preview = ((BaseUnityPlugin)this).Config.Bind<bool>("Settings", "Preview Rooms", false, (ConfigDescription)null).Value;
		if ((int)LoggingPlugin.GetLogLevel() >= 4)
		{
			((MonoBehaviour)this).StartCoroutine(WarnAboutLogLevel());
		}
		Harmony val = new Harmony("org.lordashes.plugins.roomview");
		val.PatchAll();
		Utility.PostOnMainPage((BaseUnityPlugin)(object)this);
	}

	[IteratorStateMachine(typeof(<WarnAboutLogLevel>d__16))]
	private IEnumerator WarnAboutLogLevel()
	{
		//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
		return new <WarnAboutLogLevel>d__16(0)
		{
			<>4__this = this
		};
	}

	public static List<CreatureBoardAsset> GetRevealingAssets()
	{
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_006b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_0125: Unknown result type (might be due to invalid IL or missing references)
		//IL_012a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0130: Unknown result type (might be due to invalid IL or missing references)
		List<CreatureGuid> list = new List<CreatureGuid>();
		foreach (PlayerGuid key in CampaignSessionManager.PlayersInfo.Keys)
		{
			PlayerGuid current = key;
			LoggingPlugin.LogDebug("Checking Owned Assets Of Player " + CampaignSessionManager.GetPlayerName(current) + " (" + ((object)(PlayerGuid)(ref current)).ToString() + ")");
			CreatureGuid[] array = null;
			CreatureManager.TryGetPlayerOwnedCreatureIds(current, ref array);
			LoggingPlugin.LogDebug("Player " + CampaignSessionManager.GetPlayerName(current) + " (" + ((object)(PlayerGuid)(ref current)).ToString() + ") Owns " + array.Length + " Assets (" + string.Join(",", array) + ")");
			list.AddRange(array);
		}
		List<CreatureBoardAsset> list2 = new List<CreatureBoardAsset>();
		foreach (CreatureGuid item in list.Distinct())
		{
			CreatureBoardAsset val = null;
			CreaturePresenter.TryGetAsset(item, ref val);
			if ((Object)(object)val != (Object)null)
			{
				list2.Add(val);
			}
		}
		return list2;
	}
}