Decompiled source of AntroSpawnVisualizer v1.0.0

Antro.SpawnVisualizer.dll

Decompiled 3 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.IL2CPP;
using Il2CppSystem;
using Microsoft.CodeAnalysis;
using UnhollowerBaseLib;
using UnhollowerRuntimeLib;
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: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("Antro.SpawnVisualizer")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Antro.SpawnVisualizer")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0.0")]
[assembly: AssemblyProduct("Antro.SpawnVisualizer")]
[assembly: AssemblyTitle("Antro.SpawnVisualizer")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace SpawnVisualizerSimple
{
	[BepInPlugin("com.research.spawnsimple", "Simple Spawn Visualizer", "2.7.0")]
	public class SpawnSimplePlugin : BasePlugin
	{
		public override void Load()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			ClassInjector.RegisterTypeInIl2Cpp<SpawnSimpleController>();
			GameObject val = new GameObject("Spawn_Visualizer_Manager");
			Object.DontDestroyOnLoad((Object)(object)val);
			((Object)val).hideFlags = (HideFlags)61;
			val.AddComponent<SpawnSimpleController>();
		}
	}
	public static class ZoneUtils
	{
		public static List<GameObject> FindAllZones()
		{
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			List<GameObject> list = new List<GameObject>();
			Il2CppArrayBase<MonoBehaviourPublicObInGaspUnique> val = Object.FindObjectsOfType<MonoBehaviourPublicObInGaspUnique>();
			Scene scene;
			foreach (MonoBehaviourPublicObInGaspUnique item in val)
			{
				if ((Object)(object)item == (Object)null || (Object)(object)((Component)item).gameObject == (Object)null)
				{
					continue;
				}
				scene = ((Component)item).gameObject.scene;
				if (((Scene)(ref scene)).name == null)
				{
					continue;
				}
				for (int i = 0; i < ((Component)item).transform.childCount; i++)
				{
					Transform child = ((Component)item).transform.GetChild(i);
					if ((Object)(object)child != (Object)null)
					{
						list.Add(((Component)child).gameObject);
					}
				}
			}
			Il2CppArrayBase<MonoBehaviourPublicVesiUnique> val2 = Object.FindObjectsOfType<MonoBehaviourPublicVesiUnique>();
			foreach (MonoBehaviourPublicVesiUnique item2 in val2)
			{
				if (!((Object)(object)item2 == (Object)null) && !((Object)(object)((Component)item2).gameObject == (Object)null))
				{
					scene = ((Component)item2).gameObject.scene;
					if (((Scene)(ref scene)).name != null && !list.Contains(((Component)item2).gameObject))
					{
						list.Add(((Component)item2).gameObject);
					}
				}
			}
			return list;
		}

		public static void GetZoneParameters(GameObject obj, out Vector3 center, out Vector3 size, out Quaternion rot)
		{
			//IL_0008: 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_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_019b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			rot = obj.transform.rotation;
			center = obj.transform.position;
			size = new Vector3(5f, 5f, 5f);
			MonoBehaviourPublicVesiUnique component = obj.GetComponent<MonoBehaviourPublicVesiUnique>();
			if ((Object)(object)component != (Object)null)
			{
				Type type = ((object)component).GetType();
				PropertyInfo property = type.GetProperty("size");
				if (property != null && property.PropertyType == typeof(Vector3))
				{
					size = (Vector3)property.GetValue(component);
					return;
				}
				PropertyInfo[] properties = type.GetProperties(BindingFlags.Instance | BindingFlags.Public);
				PropertyInfo[] array = properties;
				foreach (PropertyInfo propertyInfo in array)
				{
					if (!(propertyInfo.PropertyType == typeof(Vector3)))
					{
						continue;
					}
					try
					{
						Vector3 val = (Vector3)propertyInfo.GetValue(component);
						if (((Vector3)(ref val)).magnitude > 1.5f)
						{
							size = val;
							return;
						}
					}
					catch
					{
					}
				}
			}
			BoxCollider component2 = obj.GetComponent<BoxCollider>();
			if ((Object)(object)component2 != (Object)null)
			{
				Vector3 lossyScale = obj.transform.lossyScale;
				size = new Vector3(component2.size.x * lossyScale.x, component2.size.y * lossyScale.y, component2.size.z * lossyScale.z);
				center = obj.transform.TransformPoint(component2.center);
			}
		}

		public static void DebugPrintZoneInfo()
		{
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			List<GameObject> list = FindAllZones();
			Debug.Log(Object.op_Implicit($"[SpawnVis DEBUG] Found {list.Count} zones."));
			foreach (GameObject item in list)
			{
				if ((Object)(object)item == (Object)null)
				{
					continue;
				}
				MonoBehaviourPublicVesiUnique component = item.GetComponent<MonoBehaviourPublicVesiUnique>();
				string text = "Zone '" + ((Object)item).name + "': ";
				if ((Object)(object)component != (Object)null)
				{
					text += "Has Script. ";
					PropertyInfo[] properties = ((object)component).GetType().GetProperties();
					PropertyInfo[] array = properties;
					foreach (PropertyInfo propertyInfo in array)
					{
						if (propertyInfo.PropertyType == typeof(Vector3))
						{
							try
							{
								text += $"[Prop: {propertyInfo.Name} = {(object)(Vector3)propertyInfo.GetValue(component)}] ";
							}
							catch
							{
							}
						}
					}
				}
				Debug.Log(Object.op_Implicit(text));
			}
		}
	}
	public class SpawnSimpleController : MonoBehaviour
	{
		private bool _isMenuOpen = false;

		private Rect _windowRect = new Rect(50f, 50f, 320f, 550f);

		private float _scanDensity = 1.5f;

		private float _pointsPerFrame = 200f;

		private float _tileSizeMultiplier = 0.8f;

		private List<GameObject> _debugBoxes = new List<GameObject>();

		private List<GameObject> _validSpawns = new List<GameObject>();

		private Queue<Vector3> _raycastQueue = new Queue<Vector3>();

		private bool _isScanning = false;

		private HashSet<string> _scannedPointsRegistry = new HashSet<string>();

		private GUIStyle centeredStyle => new GUIStyle(GUI.skin.label)
		{
			alignment = (TextAnchor)4,
			fontStyle = (FontStyle)1
		};

		public SpawnSimpleController(IntPtr ptr)
			: base(ptr)
		{
		}//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)


		private void Update()
		{
			if (Input.GetKeyDown((KeyCode)282))
			{
				_isMenuOpen = !_isMenuOpen;
				ToggleCursor(_isMenuOpen);
			}
			if (_isScanning)
			{
				ProcessScan();
				if (_raycastQueue.Count == 0)
				{
					_isScanning = false;
				}
			}
		}

		private void ProcessScan()
		{
			//IL_0041: 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_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: 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_0086: Unknown result type (might be due to invalid IL or missing references)
			int num = -1;
			int num2 = LayerMask.NameToLayer("Player");
			if (num2 != -1)
			{
				num &= ~(1 << num2);
			}
			num &= -5;
			int i = 0;
			RaycastHit val2 = default(RaycastHit);
			for (int num3 = Mathf.RoundToInt(_pointsPerFrame); i < num3; i++)
			{
				if (_raycastQueue.Count <= 0)
				{
					break;
				}
				Vector3 val = _raycastQueue.Dequeue();
				if (Physics.Raycast(val, Vector3.down, ref val2, 200f, num, (QueryTriggerInteraction)1) && Vector3.Angle(Vector3.up, ((RaycastHit)(ref val2)).normal) < 45f)
				{
					CreateGreenTile(((RaycastHit)(ref val2)).point);
				}
			}
		}

		private void StartTerrainScan()
		{
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: 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_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
			ClearGreenPoints();
			List<GameObject> list = ZoneUtils.FindAllZones();
			Vector3 val2 = default(Vector3);
			foreach (GameObject item2 in list)
			{
				if ((Object)(object)item2 == (Object)null)
				{
					continue;
				}
				ZoneUtils.GetZoneParameters(item2, out var center, out var size, out var rot);
				float num = Mathf.Max(size.x, Mathf.Max(size.y, size.z));
				float num2 = num * 0.8f;
				float num3 = Mathf.Floor((center.x - num2) / _scanDensity) * _scanDensity;
				float num4 = Mathf.Floor((center.z - num2) / _scanDensity) * _scanDensity;
				float num5 = center.x + num2;
				float num6 = center.z + num2;
				float num7 = center.y + size.y / 2f + 1f;
				Quaternion val = Quaternion.Inverse(rot);
				float num8 = size.x / 2f;
				float num9 = size.z / 2f;
				for (float num10 = num3; num10 <= num5; num10 += _scanDensity)
				{
					for (float num11 = num4; num11 <= num6; num11 += _scanDensity)
					{
						string item = $"{Mathf.Round(num10 * 10f)}_{Mathf.Round(num11 * 10f)}";
						if (!_scannedPointsRegistry.Contains(item))
						{
							((Vector3)(ref val2))..ctor(num10, center.y, num11);
							Vector3 val3 = val2 - center;
							Vector3 val4 = val * val3;
							if (Mathf.Abs(val4.x) <= num8 && Mathf.Abs(val4.z) <= num9)
							{
								_scannedPointsRegistry.Add(item);
								_raycastQueue.Enqueue(new Vector3(num10, num7, num11));
							}
						}
					}
				}
			}
			_isScanning = true;
		}

		private void DrawBoundaries()
		{
			foreach (GameObject debugBox in _debugBoxes)
			{
				if ((Object)(object)debugBox != (Object)null)
				{
					Object.Destroy((Object)(object)debugBox);
				}
			}
			_debugBoxes.Clear();
			List<GameObject> list = ZoneUtils.FindAllZones();
			foreach (GameObject item in list)
			{
				if (!((Object)(object)item == (Object)null))
				{
					CreateRedBoxPrecise(item);
				}
			}
		}

		private void CreateRedBoxPrecise(GameObject zone)
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: 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_0091: Unknown result type (might be due to invalid IL or missing references)
			ZoneUtils.GetZoneParameters(zone, out var center, out var size, out var rot);
			GameObject val = GameObject.CreatePrimitive((PrimitiveType)3);
			Object.Destroy((Object)(object)val.GetComponent<Collider>());
			val.transform.position = center;
			val.transform.rotation = rot;
			val.transform.localScale = size;
			Renderer component = val.GetComponent<Renderer>();
			if ((Object)(object)component != (Object)null)
			{
				component.material.shader = Shader.Find("Sprites/Default");
				component.material.color = new Color(1f, 0f, 0f, 0.2f);
			}
			_debugBoxes.Add(val);
		}

		private void CreateGreenTile(Vector3 pos)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: 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)
			GameObject val = GameObject.CreatePrimitive((PrimitiveType)3);
			val.transform.position = pos + Vector3.up * 0.1f;
			float num = _scanDensity * _tileSizeMultiplier;
			val.transform.localScale = new Vector3(num, 0.1f, num);
			Object.Destroy((Object)(object)val.GetComponent<Collider>());
			Renderer component = val.GetComponent<Renderer>();
			if ((Object)(object)component != (Object)null)
			{
				component.material.shader = Shader.Find("Sprites/Default");
				component.material.color = new Color(0f, 1f, 0f, 0.5f);
			}
			_validSpawns.Add(val);
		}

		private void ClearAll()
		{
			ClearGreenPoints();
			foreach (GameObject debugBox in _debugBoxes)
			{
				if ((Object)(object)debugBox != (Object)null)
				{
					Object.Destroy((Object)(object)debugBox);
				}
			}
			_debugBoxes.Clear();
		}

		private void ClearGreenPoints()
		{
			_isScanning = false;
			_raycastQueue.Clear();
			_scannedPointsRegistry.Clear();
			foreach (GameObject validSpawn in _validSpawns)
			{
				if ((Object)(object)validSpawn != (Object)null)
				{
					Object.Destroy((Object)(object)validSpawn);
				}
			}
			_validSpawns.Clear();
		}

		private void ToggleCursor(bool show)
		{
			Cursor.lockState = (CursorLockMode)((!show) ? 1 : 0);
			Cursor.visible = show;
		}

		private void OnGUI()
		{
			//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_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			if (_isMenuOpen)
			{
				GUI.backgroundColor = new Color(0.1f, 0.1f, 0.1f, 0.95f);
				_windowRect = GUI.Window(777, _windowRect, WindowFunction.op_Implicit((Action<int>)DrawWindow), "Spawn Tools 2.7");
			}
		}

		private void DrawWindow(int id)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_024f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0215: Unknown result type (might be due to invalid IL or missing references)
			GUI.contentColor = Color.white;
			GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
			GUILayout.Space(10f);
			if (GUILayout.Button("1. DRAW ZONES (RED)", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(30f) }))
			{
				DrawBoundaries();
			}
			GUILayout.Space(5f);
			if (GUILayout.Button("2. SCAN FLOOR (GREEN)", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(30f) }))
			{
				StartTerrainScan();
			}
			GUILayout.Space(5f);
			if (GUILayout.Button("CLEAR ALL", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(25f) }))
			{
				ClearAll();
			}
			GUILayout.Space(15f);
			GUI.backgroundColor = new Color(0.5f, 0.1f, 0.1f);
			if (GUILayout.Button("PRINT DEBUG INFO", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(25f) }))
			{
				ZoneUtils.DebugPrintZoneInfo();
			}
			GUI.backgroundColor = new Color(0.1f, 0.1f, 0.1f, 0.95f);
			GUILayout.Space(15f);
			GUILayout.Label("--- SETTINGS ---", centeredStyle, Array.Empty<GUILayoutOption>());
			GUILayout.Label($"Density: {_scanDensity:F1}m", Array.Empty<GUILayoutOption>());
			_scanDensity = GUILayout.HorizontalSlider(_scanDensity, 0.5f, 4f, Array.Empty<GUILayoutOption>());
			GUILayout.Label($"Speed (Ray/Frame): {(int)_pointsPerFrame}", Array.Empty<GUILayoutOption>());
			_pointsPerFrame = GUILayout.HorizontalSlider(_pointsPerFrame, 10f, 1000f, Array.Empty<GUILayoutOption>());
			GUILayout.Label($"Tile Scale: {_tileSizeMultiplier:F2}", Array.Empty<GUILayoutOption>());
			_tileSizeMultiplier = GUILayout.HorizontalSlider(_tileSizeMultiplier, 0.1f, 1f, Array.Empty<GUILayoutOption>());
			GUILayout.Space(15f);
			if (_isScanning)
			{
				GUI.contentColor = Color.yellow;
				GUILayout.Label($"Queue: {_raycastQueue.Count}", centeredStyle, Array.Empty<GUILayoutOption>());
			}
			else
			{
				GUI.contentColor = Color.green;
				GUILayout.Label($"Points: {_validSpawns.Count}", centeredStyle, Array.Empty<GUILayoutOption>());
			}
			GUILayout.EndVertical();
			GUI.DragWindow();
		}
	}
}