Decompiled source of HubDummies v0.1.0

HubDummies.dll

Decompiled 8 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using HubDummies;
using Il2Cpp;
using Il2CppActiveRagdoll;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using MelonLoader;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(Core), "HubDummies", "0.1.0", "coope", null)]
[assembly: MelonGame("Kubunautilus", "BrutalistickVR")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("HubDummies")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("HubDummies")]
[assembly: AssemblyTitle("HubDummies")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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 HubDummies
{
	public class Core : MelonMod
	{
		private const string LogPath = "D:\\BrutalistickVrWork\\Probe\\hubdummies.log";

		private const int Count = 3;

		private bool _inHub;

		private float _scanTimer;

		private int _spawnAttempts;

		private GameObject _prefab;

		private bool _prefabChecked;

		private readonly List<GameObject> _dummies = new List<GameObject>();

		private readonly List<float> _deathTimers = new List<float>();

		public override void OnSceneWasLoaded(int buildIndex, string sceneName)
		{
			_inHub = string.Equals(sceneName, "MainHub", StringComparison.OrdinalIgnoreCase);
			_scanTimer = 0f;
			_dummies.Clear();
			_deathTimers.Clear();
			_prefab = null;
			_prefabChecked = false;
			if (!_inHub)
			{
				Write("left hub");
			}
		}

		public override void OnUpdate()
		{
			if (!_inHub)
			{
				return;
			}
			_scanTimer -= Time.unscaledDeltaTime;
			if (_scanTimer > 0f)
			{
				return;
			}
			_scanTimer = 0.5f;
			if (!_prefabChecked)
			{
				FindPrefab();
			}
			for (int num = _dummies.Count - 1; num >= 0; num--)
			{
				GameObject val = _dummies[num];
				if ((Object)(object)val == (Object)null)
				{
					_dummies.RemoveAt(num);
				}
				else
				{
					StickHealth componentInChildren = val.GetComponentInChildren<StickHealth>();
					if (!((Object)(object)componentInChildren == (Object)null) && componentInChildren.isDead)
					{
						if (_deathTimers.Count <= num)
						{
							_deathTimers.Add(0f);
						}
						_deathTimers[num] += 0.5f;
						if (_deathTimers[num] >= 2f)
						{
							Object.Destroy((Object)(object)val);
							_dummies.RemoveAt(num);
							if (num < _deathTimers.Count)
							{
								_deathTimers.RemoveAt(num);
							}
						}
					}
				}
			}
			while (_dummies.Count < 3 && _spawnAttempts < 20 && !((Object)(object)_prefab == (Object)null))
			{
				SpawnOne(_dummies.Count);
			}
		}

		private void FindPrefab()
		{
			_prefabChecked = true;
			try
			{
				Il2CppArrayBase<EnemyWaveSpawner> val = Object.FindObjectsOfType<EnemyWaveSpawner>(true);
				if (val != null)
				{
					for (int i = 0; i < val.Length; i++)
					{
						EnemyWaveSpawner val2 = val[i];
						if (!((Object)(object)val2 == (Object)null))
						{
							if ((Object)(object)val2.dummyEnemyPrefab != (Object)null)
							{
								_prefab = val2.dummyEnemyPrefab;
								break;
							}
							if (val2.meleePrefabs != null && ((Il2CppArrayBase<GameObject>)(object)val2.meleePrefabs).Length > 0 && (Object)(object)((Il2CppArrayBase<GameObject>)(object)val2.meleePrefabs)[0] != (Object)null)
							{
								_prefab = ((Il2CppArrayBase<GameObject>)(object)val2.meleePrefabs)[0];
								break;
							}
							if (val2.rangedPrefabs != null && ((Il2CppArrayBase<GameObject>)(object)val2.rangedPrefabs).Length > 0 && (Object)(object)((Il2CppArrayBase<GameObject>)(object)val2.rangedPrefabs)[0] != (Object)null)
							{
								_prefab = ((Il2CppArrayBase<GameObject>)(object)val2.rangedPrefabs)[0];
								break;
							}
						}
					}
				}
			}
			catch (Exception ex)
			{
				Write("find prefab failed " + ex.Message);
			}
			if ((Object)(object)_prefab == (Object)null)
			{
				try
				{
					Il2CppArrayBase<GameObject> val3 = Object.FindObjectsOfType<GameObject>(true);
					if (val3 != null)
					{
						int num = 0;
						for (int j = 0; j < val3.Length; j++)
						{
							GameObject val4 = val3[j];
							if ((Object)(object)val4 == (Object)null)
							{
								continue;
							}
							string text = ((Object)val4).name.ToLowerInvariant();
							if (!text.Contains("enemy") && !text.Contains("dummy") && !text.Contains("physical") && !text.Contains("stick"))
							{
								continue;
							}
							if (num++ < 30)
							{
								Write("candidate=" + ((Object)val4).name + " health=" + ((Object)(object)val4.GetComponentInChildren<StickHealth>() != (Object)null));
							}
							SpawnableItemInfo component = val4.GetComponent<SpawnableItemInfo>();
							GameObject val5 = (((Object)(object)component != (Object)null && (Object)(object)component.itemPrefab != (Object)null) ? component.itemPrefab : val4);
							if (!((Object)(object)val5.GetComponentInChildren<StickHealth>() == (Object)null))
							{
								if (text.Contains("harmless") || text.Contains("dummy"))
								{
									_prefab = val5;
									break;
								}
								if ((Object)(object)_prefab == (Object)null && (text.Contains("physical") || text.Contains("zombie") || text.Contains("enemy")))
								{
									_prefab = val5;
								}
							}
						}
					}
				}
				catch (Exception ex2)
				{
					Write("scan failed " + ex2.Message);
				}
			}
			Write("prefab=" + (((Object)(object)_prefab != (Object)null) ? ((Object)_prefab).name : "none"));
		}

		private void SpawnOne(int index)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: 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_003b: 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_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: 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)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: 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_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: 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_0166: 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)
			//IL_009f: 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_00b2: Unknown result type (might be due to invalid IL or missing references)
			_spawnAttempts++;
			GameObject playerHeadStatic = PlayerStaticReferences.playerHeadStatic;
			Vector3 val;
			Vector3 val2;
			Vector3 val3;
			if ((Object)(object)playerHeadStatic != (Object)null)
			{
				val = playerHeadStatic.transform.position;
				val2 = playerHeadStatic.transform.forward;
				val3 = playerHeadStatic.transform.right;
			}
			else
			{
				Camera main = Camera.main;
				val = (Vector3)(((Object)(object)main != (Object)null) ? ((Component)main).transform.position : new Vector3(0f, 1.6f, 0f));
				val2 = (((Object)(object)main != (Object)null) ? ((Component)main).transform.forward : Vector3.forward);
				val3 = (((Object)(object)main != (Object)null) ? ((Component)main).transform.right : Vector3.right);
			}
			val2.y = 0f;
			val3.y = 0f;
			if (((Vector3)(ref val2)).sqrMagnitude < 0.01f)
			{
				val2 = Vector3.forward;
			}
			((Vector3)(ref val2)).Normalize();
			((Vector3)(ref val3)).Normalize();
			float num = (float)(index - 1) * 2.2f;
			Vector3 val4 = val + val2 * 4.5f + val3 * num;
			GameObject playerHexaPelvisStatic = PlayerStaticReferences.playerHexaPelvisStatic;
			val4.y = (((Object)(object)playerHexaPelvisStatic != (Object)null) ? (playerHexaPelvisStatic.transform.position.y - 0.15f) : (val.y - 1.95f));
			Quaternion val5 = Quaternion.LookRotation(-val2, Vector3.up);
			try
			{
				GameObject val6 = Object.Instantiate<GameObject>(_prefab, val4, val5);
				((Object)val6).name = "HubDummy";
				StickHealth componentInChildren = val6.GetComponentInChildren<StickHealth>();
				if ((Object)(object)componentInChildren != (Object)null)
				{
					componentInChildren.StickStartHealth = 1500f;
					componentInChildren.StickCurrentHealth = 1500f;
					componentInChildren.isDead = false;
				}
				Il2CppArrayBase<StickGunManager> componentsInChildren = val6.GetComponentsInChildren<StickGunManager>(true);
				if (componentsInChildren != null)
				{
					for (int i = 0; i < componentsInChildren.Length; i++)
					{
						if ((Object)(object)componentsInChildren[i] != (Object)null)
						{
							((Behaviour)componentsInChildren[i]).enabled = false;
						}
					}
				}
				_dummies.Add(val6);
				_deathTimers.Add(0f);
				Write("spawned " + index + " at " + ((Vector3)(ref val4)).ToString("F1"));
			}
			catch (Exception ex)
			{
				Write("spawn failed " + ex.Message);
			}
		}

		private static void Write(string s)
		{
			try
			{
				File.AppendAllText("D:\\BrutalistickVrWork\\Probe\\hubdummies.log", "[" + DateTime.Now.ToString("HH:mm:ss") + "] " + s + "\n");
			}
			catch
			{
			}
		}
	}
}