Decompiled source of Foothold v1.2.0

Foothold.dll

Decompiled a week ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Microsoft.CodeAnalysis;
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(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Foothold")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.2.0.0")]
[assembly: AssemblyInformationalVersion("1.2.0+95be5713b4dcdc6c4405d0098c30469dcc081bd7")]
[assembly: AssemblyProduct("Foothold?")]
[assembly: AssemblyTitle("Foothold")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.2.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 Foothold
{
	[BepInPlugin("Foothold", "Foothold?", "1.2.0")]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Logger;

		internal static Scene currentScene;

		internal static MainCamera mainCamera;

		internal static bool activated = false;

		internal static Material baseMaterial;

		private static readonly List<GameObject> balls = new List<GameObject>();

		private static readonly List<GameObject> redBalls = new List<GameObject>();

		private static readonly List<GameObject> pool_balls = new List<GameObject>();

		private static readonly List<GameObject> pool_redBalls = new List<GameObject>();

		private static float lastScanTime = 0f;

		private ConfigEntry<KeyCode> configActivationKey;

		private ConfigEntry<bool> configFadeAway;

		private void Awake()
		{
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Expected O, but got Unknown
			Logger = ((BaseUnityPlugin)this).Logger;
			configActivationKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("General", "ActivationKey", (KeyCode)102, (ConfigDescription)null);
			configFadeAway = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "FadeAway", false, "Replaces the toggle behavior with fading away each scan after 3 seconds, credit to VicVoss on GitHub for the idea");
			Material val = new Material(Shader.Find("Universal Render Pipeline/Lit"));
			val.SetFloat("_Surface", 1f);
			val.SetFloat("_Blend", 0f);
			val.SetFloat("_ZWrite", 0f);
			val.SetFloat("_ReceiveShadows", 0f);
			val.SetInt("_SrcBlend", 5);
			val.SetInt("_DstBlend", 10);
			val.DisableKeyword("_ALPHATEST_ON");
			val.EnableKeyword("_ALPHABLEND_ON");
			val.DisableKeyword("_ALPHAPREMULTIPLY_ON");
			val.EnableKeyword("_SURFACE_TYPE_TRANSPARENT");
			val.renderQueue = 3000;
			baseMaterial = val;
			SceneManager.sceneLoaded += OnSceneLoaded;
			Logger.LogInfo((object)"Loaded Foothold? version 1.2.0");
		}

		private void OnSceneLoaded(Scene scene, LoadSceneMode _)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Expected O, but got Unknown
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Expected O, but got Unknown
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: 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)
			currentScene = scene;
			if (((Scene)(ref currentScene)).name.StartsWith("Level_"))
			{
				for (int i = 0; i < 2000; i++)
				{
					GameObject val = GameObject.CreatePrimitive((PrimitiveType)0);
					val.SetActive(false);
					val.GetComponent<Renderer>().material = new Material(baseMaterial);
					val.GetComponent<Collider>().enabled = false;
					val.transform.localScale = Vector3.one / 5f;
					pool_balls.Add(val);
				}
				for (int j = 0; j < 2000; j++)
				{
					GameObject val2 = GameObject.CreatePrimitive((PrimitiveType)0);
					val2.SetActive(false);
					Material val3 = new Material(baseMaterial);
					val3.color = Color.red;
					val2.GetComponent<Renderer>().material = val3;
					val2.GetComponent<Collider>().enabled = false;
					val2.transform.localScale = Vector3.one / 5f;
					pool_redBalls.Add(val2);
				}
			}
			else
			{
				pool_balls.Clear();
				pool_redBalls.Clear();
			}
		}

		private void Update()
		{
			if (!((Scene)(ref currentScene)).name.StartsWith("Level_"))
			{
				return;
			}
			if ((Object)(object)mainCamera == (Object)null)
			{
				mainCamera = Object.FindFirstObjectByType<MainCamera>();
				return;
			}
			CheckHotkeys();
			if (configFadeAway.Value)
			{
				SetBallAlphas();
			}
		}

		private void CheckHotkeys()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			if (Input.GetKeyDown(configActivationKey.Value))
			{
				if (!configFadeAway.Value)
				{
					activated = !activated;
				}
				if (activated || configFadeAway.Value)
				{
					RenderVisualization();
				}
				else
				{
					ReturnBallsToPool();
				}
			}
		}

		private void ReturnBallsToPool()
		{
			List<GameObject> list = balls.ToList();
			foreach (GameObject item in list)
			{
				item.SetActive(false);
				balls.Remove(item);
				pool_balls.Add(item);
			}
			List<GameObject> list2 = redBalls.ToList();
			foreach (GameObject item2 in list2)
			{
				item2.SetActive(false);
				redBalls.Remove(item2);
				pool_redBalls.Add(item2);
			}
		}

		private void RenderVisualization()
		{
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			ReturnBallsToPool();
			lastScanTime = Time.time;
			float num = 0.5f;
			float num2 = 1f;
			Vector3 position = default(Vector3);
			for (float num3 = -10f; num3 <= 10f; num3 += num)
			{
				for (float num4 = -10f; num4 <= 10f; num4 += num2)
				{
					for (float num5 = -10f; num5 <= 10f; num5 += num)
					{
						((Vector3)(ref position))..ctor(((Component)mainCamera).transform.position.x + num3, ((Component)mainCamera).transform.position.y + num4, ((Component)mainCamera).transform.position.z + num5);
						CheckAndPlaceBallAt(position);
					}
				}
			}
		}

		private void CheckAndPlaceBallAt(Vector3 position)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: 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)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: 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_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = position + Vector3.down * 1f;
			RaycastHit val2 = HelperFunctions.LineCheck(position, val, (LayerType)1, 0f, (QueryTriggerInteraction)1);
			if (!Object.op_Implicit((Object)(object)((RaycastHit)(ref val2)).transform))
			{
				return;
			}
			CollisionModifier component = ((Component)((RaycastHit)(ref val2)).collider).GetComponent<CollisionModifier>();
			if (Object.op_Implicit((Object)(object)component) && !component.standable)
			{
				return;
			}
			float num = Vector3.Angle(Vector3.up, ((RaycastHit)(ref val2)).normal);
			if (num > 30f)
			{
				if (num < 50f && pool_balls.Count > 0)
				{
					GameObject val3 = pool_balls.First();
					val3.transform.position = ((RaycastHit)(ref val2)).point;
					balls.Add(val3);
					pool_balls.Remove(val3);
					val3.SetActive(true);
				}
				else if (num >= 50f && pool_redBalls.Count > 0)
				{
					GameObject val4 = pool_redBalls.First();
					val4.transform.position = ((RaycastHit)(ref val2)).point;
					redBalls.Add(val4);
					pool_redBalls.Remove(val4);
					val4.SetActive(true);
				}
			}
		}

		private void SetBallAlphas()
		{
			//IL_0078: 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_008e: Unknown result type (might be due to invalid IL or missing references)
			if (!configFadeAway.Value)
			{
				return;
			}
			float a = Mathf.Lerp(1f, 0f, Mathf.Clamp01((Time.time - (lastScanTime + 3f)) / 3f));
			foreach (GameObject item in balls.Concat(redBalls))
			{
				Material material = item.GetComponent<Renderer>().material;
				Color color = material.GetColor("_BaseColor");
				color.a = a;
				material.SetColor("_BaseColor", color);
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "Foothold";

		public const string PLUGIN_NAME = "Foothold?";

		public const string PLUGIN_VERSION = "1.2.0";
	}
}