Decompiled source of ULTRASPEEDRUN v1.4.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.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("UltraSpeedRun")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+38a4513b5875d7126d82a0eaa9b382b244fe8c1c")]
[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;

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

	private Material theMaterial;

	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;
		if (objectsMadeVisible == null)
		{
			return;
		}
		foreach (MeshRenderer item in objectsMadeVisible)
		{
			if (Object.op_Implicit((Object)(object)item))
			{
				((Renderer)item).enabled = false;
			}
		}
	}

	public void Enable(CheatsManager manager)
	{
		//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b6: Expected O, but got Unknown
		_active = true;
		if ((Object)(object)theMaterial == (Object)null)
		{
			Shader val = Shader.Find("ULTRAKILL/Master");
			if ((Object)(object)val == (Object)null)
			{
				Debug.LogWarning((object)"Failed Shader.Find (for whatever reason)");
				MeshRenderer[] array = Resources.FindObjectsOfTypeAll<MeshRenderer>();
				foreach (MeshRenderer val2 in array)
				{
					if ((Object)(object)val2 != (Object)null && (Object)(object)((Renderer)val2).material != (Object)null && ((Object)((Renderer)val2).material.shader).name.Contains("Master"))
					{
						_ = ((Renderer)val2).material;
						val = ((Renderer)val2).material.shader;
						break;
					}
				}
			}
			if ((Object)(object)val == (Object)null)
			{
				throw new ArgumentException("Could not get shader");
			}
			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_0040: 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_009c: 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_00f8: 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_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: 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_0096: 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_00a6: 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 obj2 = GameObject.CreatePrimitive((PrimitiveType)3);
			Mesh sharedMesh = obj2.GetComponent<MeshFilter>().sharedMesh;
			Object.Destroy((Object)(object)obj2);
			Mesh val3 = Object.Instantiate<Mesh>(sharedMesh);
			Vector3[] vertices = val3.vertices;
			for (int i = 0; i < vertices.Length; i++)
			{
				vertices[i] = Vector3.Scale(vertices[i], val.size);
			}
			val3.vertices = vertices;
			val3.RecalculateBounds();
			val2.mesh = sharedMesh;
			MakeVisible<T>(renderer2);
		}
	}

	public void MakeVisible<T>(MeshRenderer renderer) where T : MonoBehaviour
	{
		//IL_0045: Unknown result type (might be due to invalid IL or missing references)
		//IL_0065: 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_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000f: 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");
	}
}