Decompiled source of Entity Spawn Stats v1.2.0

plugins/SpawnStats.dll

Decompiled a month ago
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using SpawnStats.UI;
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("SpawnStats")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SpawnStats")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("42bcfad8-6e0d-4c8e-889f-2cb81eba095e")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace SpawnStats
{
	[BepInPlugin("nachariah.whiteknuckle.spawnstats", "SpawnStats", "1.1.1")]
	[BepInProcess("White Knuckle.exe")]
	public class Plugin : BaseUnityPlugin
	{
		public const string GUID = "nachariah.whiteknuckle.spawnstats";

		public Plugin instance;

		private void Awake()
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			instance = this;
			((BaseUnityPlugin)this).Logger.LogInfo((object)"[SpawnStats] Patching...");
			Harmony val = new Harmony("nachariah.whiteknuckle.spawnstats");
			val.PatchAll();
			SceneManager.sceneLoaded += OnSceneLoaded;
			((BaseUnityPlugin)this).Logger.LogInfo((object)"[SpawnStats] Loaded");
		}

		private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
		{
			if (((Scene)(ref scene)).name == "Game-Main")
			{
				CommandConsole.hasCheated = true;
				CL_GameManager.gamemode.allowAchievements = false;
				CL_GameManager.gamemode.allowCheatedScores = false;
				Debug.Log((object)"[SpawnStats] Leaderboard Disabled");
			}
		}
	}
}
namespace SpawnStats.Patchers
{
	[HarmonyPatch(typeof(UT_SpawnChance), "Start")]
	public static class UT_SpawnChance_Start_Patcher
	{
		[HarmonyPrefix]
		public static bool Prefix(UT_SpawnChance __instance)
		{
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Expected O, but got Unknown
			SpawnSettings spawnSettings = __instance.spawnSettings;
			if (spawnSettings == null)
			{
				return true;
			}
			float effectiveSpawnChance = spawnSettings.GetEffectiveSpawnChance();
			((Component)__instance).gameObject.SetActive(true);
			string text = $"{((Object)((Component)__instance).gameObject).name}\nChance: {effectiveSpawnChance:P1}";
			List<string> list = new List<string>();
			if (spawnSettings.useAscent)
			{
				list.Add("Ascent");
			}
			if (spawnSettings.useDifficulty)
			{
				list.Add("Difficulty");
			}
			if (spawnSettings.useStats)
			{
				list.Add("useStats");
			}
			if (spawnSettings.useFlags && (spawnSettings.flagWhitelist.Count > 0 || spawnSettings.flagBlacklist.Count > 0))
			{
				list.Add("useFlags");
			}
			if (spawnSettings.useHardMode)
			{
				list.Add("useHardMode");
			}
			if (spawnSettings.useProgressionUnlock)
			{
				list.Add("useProgressionUnlock");
			}
			if (list.Count > 0)
			{
				text = text + "\nModifiers: " + string.Join(", ", list);
			}
			SpawnLabelTag spawnLabelTag = ((Component)__instance).gameObject.GetComponent<SpawnLabelTag>();
			if ((Object)(object)spawnLabelTag == (Object)null)
			{
				spawnLabelTag = ((Component)__instance).gameObject.AddComponent<SpawnLabelTag>();
			}
			if ((Object)(object)spawnLabelTag.label == (Object)null)
			{
				GameObject val = new GameObject("SpawnChanceLabel");
				ChanceLabel chanceLabel = val.AddComponent<ChanceLabel>();
				chanceLabel.Init(((Component)__instance).transform, text);
				spawnLabelTag.label = val;
			}
			else
			{
				ChanceLabel component = spawnLabelTag.label.GetComponent<ChanceLabel>();
				if ((Object)(object)component != (Object)null)
				{
					component.SetText(text);
				}
			}
			return false;
		}
	}
	[HarmonyPatch(typeof(DEN_Bloodbug), "FixedUpdate")]
	public static class DEN_Bloodbug_FixedUpdate_Patcher
	{
		[HarmonyPrefix]
		public static bool Prefix(DEN_Bloodbug __instance)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Expected O, but got Unknown
			FieldInfo field = typeof(DEN_Bloodbug).GetField("rigid", BindingFlags.Instance | BindingFlags.NonPublic);
			Rigidbody val = (Rigidbody)field.GetValue(__instance);
			val.useGravity = false;
			return false;
		}
	}
	[HarmonyPatch(typeof(DEN_Gasbag), "FixedUpdate")]
	public static class DEN_Gasbag_FixedUpdate_Patcher
	{
		[HarmonyPrefix]
		public static bool Prefix(DEN_Gasbag __instance)
		{
			return false;
		}
	}
	[HarmonyPatch(typeof(DebugMenu), "Start")]
	public static class DebugMenu_Start_Patcher
	{
		[HarmonyPostfix]
		public static void Postfix(DebugMenu __instance)
		{
			DebugMenu.CreateDebugText?.Invoke("LookAtTexture", "Texture: None");
		}
	}
	[HarmonyPatch(typeof(ENT_Player), "Update")]
	public static class ENT_Player_Update_Patcher
	{
		[HarmonyPostfix]
		public static void Postfix(ENT_Player __instance)
		{
			//IL_0024: 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_003d: Unknown result type (might be due to invalid IL or missing references)
			if (!DebugMenu.initialized)
			{
				return;
			}
			string arg = "Material: N/A | Texture: N/A";
			Ray val = default(Ray);
			((Ray)(ref val))..ctor(((Component)Camera.main).transform.position, ((Component)Camera.main).transform.forward);
			RaycastHit val2 = default(RaycastHit);
			if (Physics.Raycast(val, ref val2, 100f))
			{
				Renderer component = ((Component)((RaycastHit)(ref val2)).collider).GetComponent<Renderer>();
				if ((Object)(object)component != (Object)null && (Object)(object)component.material != (Object)null && (Object)(object)component.material.mainTexture != (Object)null)
				{
					string text = "None";
					if ((Object)(object)component.material == (Object)null)
					{
						text = "null";
					}
					else if (component.material.HasProperty("_MainTex") && ((Object)component.material).name != "Handhold-Debug (Instance) (Instance)")
					{
						Texture texture = component.material.GetTexture("_MainTex");
						if ((Object)(object)texture != (Object)null)
						{
							text = ((Object)texture).name;
						}
					}
					arg = "Material: " + ((Object)component.material).name + " | Texture: " + text;
				}
			}
			DebugMenu.UpdateDebugText?.Invoke("LookAtTexture", arg);
		}
	}
}
namespace SpawnStats.UI
{
	public class SpawnLabelTag : MonoBehaviour
	{
		public GameObject label;

		private void OnDestroy()
		{
			if ((Object)(object)label != (Object)null)
			{
				Object.Destroy((Object)(object)label);
			}
		}
	}
	public class ChanceLabel : MonoBehaviour
	{
		private Transform target;

		private TextMesh textMesh;

		private LineRenderer line;

		private float hoverOffset = 0.5f;

		private static Transform overlayRoot;

		private static Transform OverlayRoot
		{
			get
			{
				//IL_0016: Unknown result type (might be due to invalid IL or missing references)
				//IL_001c: Expected O, but got Unknown
				if ((Object)(object)overlayRoot == (Object)null)
				{
					GameObject val = new GameObject("SpawnChanceOverlayRoot");
					overlayRoot = val.transform;
					Object.DontDestroyOnLoad((Object)(object)val);
				}
				return overlayRoot;
			}
		}

		public void Init(Transform targetTransform, string labelText)
		{
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Expected O, but got Unknown
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
			target = targetTransform;
			((Component)this).transform.SetParent(OverlayRoot, false);
			textMesh = ((Component)this).gameObject.AddComponent<TextMesh>();
			textMesh.text = labelText;
			textMesh.fontSize = 64;
			textMesh.anchor = (TextAnchor)4;
			textMesh.alignment = (TextAlignment)1;
			textMesh.characterSize = 0.015f;
			textMesh.color = Color.yellow;
			line = ((Component)this).gameObject.AddComponent<LineRenderer>();
			line.positionCount = 2;
			line.useWorldSpace = true;
			line.widthCurve = AnimationCurve.Constant(0f, 1f, 0.01f);
			line.numCapVertices = 4;
			Material val = new Material(Shader.Find("Sprites/Default"));
			if ((Object)(object)val != (Object)null)
			{
				val.SetInt("_SrcBlend", 5);
				val.SetInt("_DstBlend", 10);
				val.SetInt("_ZWrite", 0);
				val.DisableKeyword("_ALPHATEST_ON");
				val.EnableKeyword("_ALPHABLEND_ON");
				val.DisableKeyword("_ALPHAPREMULTIPLY_ON");
				val.SetInt("_ZTest", 8);
				val.renderQueue = 3001;
			}
			((Renderer)line).material = val;
			line.startColor = new Color(1f, 0.9f, 0.2f, 1f);
			line.endColor = new Color(1f, 0.9f, 0.2f, 0.6f);
		}

		private void LateUpdate()
		{
			//IL_0081: 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)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: 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_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: 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_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: 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_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: 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_013c: 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_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: 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_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)target == (Object)null)
			{
				Object.Destroy((Object)(object)((Component)this).gameObject);
				return;
			}
			Collider component = ((Component)target).GetComponent<Collider>();
			Vector3 position = default(Vector3);
			if ((Object)(object)component != (Object)null)
			{
				Bounds bounds = component.bounds;
				((Vector3)(ref position))..ctor(((Bounds)(ref bounds)).center.x, ((Bounds)(ref bounds)).max.y + hoverOffset, ((Bounds)(ref bounds)).center.z);
			}
			else
			{
				position = target.position + Vector3.up * (1.5f + hoverOffset);
			}
			((Component)this).transform.position = position;
			if ((Object)(object)Camera.main != (Object)null)
			{
				Vector3 val = ((Component)Camera.main).transform.position - ((Component)this).transform.position;
				if (((Vector3)(ref val)).sqrMagnitude > 0.0001f)
				{
					((Component)this).transform.rotation = Quaternion.LookRotation(val, Vector3.up);
					((Component)this).transform.Rotate(0f, 180f, 0f);
				}
			}
			Vector3 position2 = default(Vector3);
			if ((Object)(object)component != (Object)null)
			{
				Bounds bounds2 = component.bounds;
				((Vector3)(ref position2))..ctor(((Bounds)(ref bounds2)).center.x, ((Bounds)(ref bounds2)).min.y + 0.05f, ((Bounds)(ref bounds2)).center.z);
			}
			else
			{
				position2 = target.position;
			}
			if ((Object)(object)line != (Object)null)
			{
				line.SetPosition(0, ((Component)this).transform.position);
				line.SetPosition(1, position2);
			}
		}

		public void SetText(string t)
		{
			if ((Object)(object)textMesh != (Object)null)
			{
				textMesh.text = t;
			}
		}
	}
	public class Billboard : MonoBehaviour
	{
		private void LateUpdate()
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)Camera.main == (Object)null))
			{
				((Component)this).transform.LookAt(((Component)Camera.main).transform, Vector3.up);
			}
		}
	}
}