Decompiled source of ULTRASPEEDRUN v1.3.1

plugins/UltraSpeedRun.dll

Decompiled a month ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using UnityEngine;

[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.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("UltraSpeedRun")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+32270e463834a691a6022740a4a6bed2a77ce825")]
[assembly: AssemblyProduct("UltraSpeedRun")]
[assembly: AssemblyTitle("UltraSpeedRun")]
[assembly: AssemblyVersion("1.0.0.0")]
[HarmonyPatch(typeof(CheatsManager), "Start")]
public class CheatsPatcher
{
	[HarmonyPrefix]
	public static void Prefix(CheatsManager __instance)
	{
		Debug.Log((object)"Yippe!");
		__instance.RegisterExternalCheat((ICheat)(object)new ShowZoneCheats());
	}
}
public class ShowZoneCheats : ICheat
{
	private bool _active = false;

	private List<MeshRenderer> objectsMadeVisible = new List<MeshRenderer>();

	private Material theMaterial = null;

	private Dictionary<Type, Color> _colors = new Dictionary<Type, Color>();

	private static readonly int EmissionColor = Shader.PropertyToID("_EmissionColor");

	private static readonly int Color1 = Shader.PropertyToID("_Color");

	private static readonly int BlendMode = Shader.PropertyToID("_BlendMode");

	private static readonly int VertexLighting = Shader.PropertyToID("_VertexLighting");

	private static readonly int Opacity = Shader.PropertyToID("_Opacity");

	private static readonly int SrcBlend = Shader.PropertyToID("_SrcBlend");

	private static readonly int DstBlend = Shader.PropertyToID("_DstBlend");

	private static readonly int ZWrite = Shader.PropertyToID("_ZWrite");

	public string LongName => "Show All Trigger Zones";

	public string Identifier => "ultraspeedrun.zones";

	public string ButtonEnabledOverride => "Hide Zones";

	public string ButtonDisabledOverride => "Show Zones";

	public string Icon => "noclip";

	public bool IsActive => _active;

	public bool DefaultState => false;

	public StatePersistenceMode PersistenceMode => (StatePersistenceMode)1;

	public IEnumerator Coroutine(CheatsManager manager)
	{
		yield return null;
	}

	public void Disable()
	{
		_active = false;
		foreach (MeshRenderer item in objectsMadeVisible)
		{
			((Renderer)item).enabled = false;
		}
	}

	public void Enable(CheatsManager manager)
	{
		//IL_009c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a6: Expected O, but got Unknown
		_active = true;
		if ((Object)(object)theMaterial == (Object)null)
		{
			Shader val = null;
			Material val2 = null;
			PlayerActivator[] array = Resources.FindObjectsOfTypeAll<PlayerActivator>();
			foreach (PlayerActivator val3 in array)
			{
				MeshRenderer component = ((Component)val3).GetComponent<MeshRenderer>();
				if ((Object)(object)component != (Object)null && (Object)(object)((Renderer)component).material != (Object)null && ((Object)((Renderer)component).material).name.Contains("Trigger"))
				{
					val2 = ((Renderer)component).material;
					val = ((Renderer)component).material.shader;
					break;
				}
			}
			theMaterial = new Material(val);
			theMaterial.SetFloat(BlendMode, 2f);
			theMaterial.SetFloat(VertexLighting, 0f);
			theMaterial.SetFloat(Opacity, 0.5f);
			theMaterial.SetOverrideTag("RenderType", "Transparent");
			theMaterial.SetFloat(SrcBlend, 5f);
			theMaterial.SetFloat(DstBlend, 10f);
			theMaterial.SetFloat(ZWrite, 0f);
			theMaterial.DisableKeyword("ALPHA_TEST");
			theMaterial.EnableKeyword("TRANSPARENCY");
			theMaterial.EnableKeyword("_FOG_ON");
			theMaterial.EnableKeyword("_ALPHAPREMULTIPLY_ON");
			theMaterial.EnableKeyword("_EMISSION");
			theMaterial.EnableKeyword("_GLITCHMODE_NONE");
			theMaterial.EnableKeyword("_USEALBEDOASEMISSIVE_ON");
			theMaterial.renderQueue = 3000;
		}
		this.SetObjectsVisible<ObjectActivator>(includeChildren: false, includeParent: true);
		this.SetObjectsVisible<ActivateArena>(includeChildren: false, includeParent: true);
		this.SetObjectsVisible<DoorController>(includeChildren: false, includeParent: true);
		this.SetObjectsVisible<OutOfBounds>(includeChildren: false, includeParent: true);
		this.SetObjectsVisible<DeathZone>(includeChildren: true, includeParent: true);
		this.SetObjectsVisible<CheckPoint>(includeChildren: true, includeParent: false);
	}

	public ShowZoneCheats()
	{
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		//IL_007f: 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_00dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_010c: Unknown result type (might be due to invalid IL or missing references)
		_colors.Add(typeof(ActivateArena), new Color(0.23f, 0.5f, 0.2f, 1f));
		_colors.Add(typeof(DoorController), new Color(0.2f, 0.2f, 0.5f, 15f));
		_colors.Add(typeof(DeathZone), new Color(0.7f, 0.2f, 0.2f, 1f));
		_colors.Add(typeof(ObjectActivator), new Color(0.4f, 0.7f, 0.7f, 1f));
		_colors.Add(typeof(CheckPoint), new Color(0.7f, 0.4f, 0.7f, 1f));
	}

	public void SetObjectsVisible<T>(bool includeChildren = false, bool includeParent = true) where T : MonoBehaviour
	{
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: Expected O, but got Unknown
		T[] array = Resources.FindObjectsOfTypeAll<T>();
		foreach (T val in array)
		{
			if (includeParent)
			{
				SetObjectsVisibleGameObject<T>(((Component)(object)val).gameObject);
			}
			if (!includeChildren)
			{
				continue;
			}
			foreach (Transform item in ((Component)(object)val).transform)
			{
				Transform val2 = item;
				SetObjectsVisibleGameObject<T>(((Component)val2).gameObject);
			}
		}
	}

	public void SetObjectsVisibleGameObject<T>(GameObject obj) where T : MonoBehaviour
	{
		//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
		obj.gameObject.layer = 0;
		if ((Object)(object)obj.GetComponent<Collider>() == (Object)null)
		{
			return;
		}
		MeshRenderer renderer = default(MeshRenderer);
		BoxCollider val = default(BoxCollider);
		if (obj.TryGetComponent<MeshRenderer>(ref renderer))
		{
			MakeVisible<T>(renderer);
		}
		else if (obj.TryGetComponent<BoxCollider>(ref val))
		{
			MeshRenderer renderer2 = obj.gameObject.AddComponent<MeshRenderer>();
			MeshFilter val2 = default(MeshFilter);
			if (!obj.gameObject.TryGetComponent<MeshFilter>(ref val2))
			{
				val2 = obj.gameObject.AddComponent<MeshFilter>();
			}
			GameObject val3 = GameObject.CreatePrimitive((PrimitiveType)3);
			Mesh sharedMesh = val3.GetComponent<MeshFilter>().sharedMesh;
			Object.Destroy((Object)(object)val3);
			Mesh val4 = Object.Instantiate<Mesh>(sharedMesh);
			Vector3[] vertices = val4.vertices;
			for (int i = 0; i < vertices.Length; i++)
			{
				vertices[i] = Vector3.Scale(vertices[i], val.size);
			}
			val4.vertices = vertices;
			val4.RecalculateBounds();
			val2.mesh = sharedMesh;
			MakeVisible<T>(renderer2);
		}
	}

	public void MakeVisible<T>(MeshRenderer renderer) where T : MonoBehaviour
	{
		//IL_004b: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		((Renderer)renderer).enabled = true;
		((Renderer)renderer).material = theMaterial;
		if (_colors.ContainsKey(typeof(T)))
		{
			((Renderer)renderer).material.SetColor(Color1, _colors[typeof(T)]);
			((Renderer)renderer).material.color = _colors[typeof(T)];
		}
		if (!objectsMadeVisible.Contains(renderer))
		{
			objectsMadeVisible.Add(renderer);
		}
	}
}
[BepInPlugin("robi.uk.speedrun", "Speedrun Thingy", "1.3.1")]
public class SpeedRunMod : BaseUnityPlugin
{
	public const string pluginGuid = "robi.uk.speedrun";

	public const string pluginName = "Speedrun Thingy";

	public const string pluginVersion = "1.3.1";

	private static Harmony _harmony;

	private void Awake()
	{
		Debug.Log((object)"Loaded mod.");
	}

	private void Start()
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Expected O, but got Unknown
		_harmony = new Harmony("robi.uk.speedrun");
		_harmony.PatchAll();
	}

	private void OnDestroy()
	{
		Harmony harmony = _harmony;
		if (harmony != null)
		{
			harmony.UnpatchSelf();
		}
		Debug.Log((object)"Bye");
	}
}