Decompiled source of TonyBonksMegarailBuilder v1.0.0

MegaRailsBuilder.dll

Decompiled a day 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 HarmonyLib;
using Il2Cpp;
using Il2CppAssets.Scripts.Actors.Player;
using Il2CppAssets.Scripts.Managers;
using Il2CppAssets.Scripts.Utility;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using MegaRailsBuilder;
using MelonLoader;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(RailsBuilder), "Tony Bonks Megarail Builder", "1.0.0", "svindler", null)]
[assembly: MelonGame("Ved", "Megabonk")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("MegaRailsBuilder")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("MegaRailsBuilder")]
[assembly: AssemblyTitle("MegaRailsBuilder")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
}
namespace MegaRailsBuilder
{
	public class RailsBuilder : MelonMod
	{
		private GameObject ghostRail;

		private int currentRailIndex;

		private bool buildMode;

		private float rotationY;

		private bool flipped;

		private SpawnInteractables spawner;

		private static Material ghostMaterial;

		private static Texture2D bgTex;

		public static bool freezeToggle;

		public static float cachedRunTimer;

		public static float cachedStageTimer;

		public override void OnUpdate()
		{
			//IL_0209: Unknown result type (might be due to invalid IL or missing references)
			//IL_020e: Unknown result type (might be due to invalid IL or missing references)
			//IL_020f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0214: Unknown result type (might be due to invalid IL or missing references)
			//IL_0228: Unknown result type (might be due to invalid IL or missing references)
			//IL_022d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0232: Unknown result type (might be due to invalid IL or missing references)
			//IL_0235: Unknown result type (might be due to invalid IL or missing references)
			//IL_023a: Unknown result type (might be due to invalid IL or missing references)
			//IL_023e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0243: Unknown result type (might be due to invalid IL or missing references)
			//IL_0340: Unknown result type (might be due to invalid IL or missing references)
			//IL_0341: Unknown result type (might be due to invalid IL or missing references)
			//IL_0352: Unknown result type (might be due to invalid IL or missing references)
			//IL_0357: Unknown result type (might be due to invalid IL or missing references)
			//IL_0251: Unknown result type (might be due to invalid IL or missing references)
			//IL_0253: Unknown result type (might be due to invalid IL or missing references)
			//IL_0371: Unknown result type (might be due to invalid IL or missing references)
			//IL_0363: Unknown result type (might be due to invalid IL or missing references)
			//IL_027d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0282: Unknown result type (might be due to invalid IL or missing references)
			//IL_0289: Unknown result type (might be due to invalid IL or missing references)
			//IL_028e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0293: Unknown result type (might be due to invalid IL or missing references)
			//IL_038e: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_03bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fd: Unknown result type (might be due to invalid IL or missing references)
			if (Input.GetKeyUp((KeyCode)282))
			{
				buildMode = !buildMode;
				if (!buildMode && (Object)(object)ghostRail != (Object)null)
				{
					Object.Destroy((Object)(object)ghostRail);
					ghostRail = null;
					rotationY = 0f;
					flipped = false;
				}
			}
			if (buildMode && Input.GetKeyDown((KeyCode)283))
			{
				freezeToggle = !freezeToggle;
			}
			if (!buildMode)
			{
				return;
			}
			if ((Object)(object)spawner == (Object)null)
			{
				spawner = Object.FindObjectOfType<SpawnInteractables>();
			}
			if ((Object)(object)spawner == (Object)null || spawner.rails == null || ((Il2CppArrayBase<GameObject>)(object)spawner.rails).Length == 0)
			{
				return;
			}
			if (Input.GetKeyDown((KeyCode)276))
			{
				currentRailIndex = (currentRailIndex - 1 + ((Il2CppArrayBase<GameObject>)(object)spawner.rails).Length) % ((Il2CppArrayBase<GameObject>)(object)spawner.rails).Length;
				RefreshGhost(((Il2CppArrayBase<GameObject>)(object)spawner.rails)[currentRailIndex]);
			}
			if (Input.GetKeyDown((KeyCode)275))
			{
				currentRailIndex = (currentRailIndex + 1) % ((Il2CppArrayBase<GameObject>)(object)spawner.rails).Length;
				RefreshGhost(((Il2CppArrayBase<GameObject>)(object)spawner.rails)[currentRailIndex]);
			}
			if (Input.GetKey((KeyCode)113))
			{
				rotationY -= 90f * Time.deltaTime;
			}
			if (Input.GetKey((KeyCode)101))
			{
				rotationY += 90f * Time.deltaTime;
			}
			if (Input.GetKeyUp((KeyCode)122))
			{
				rotationY += 90f;
			}
			if (Input.GetKeyUp((KeyCode)120))
			{
				rotationY -= 90f;
			}
			if (Input.GetKeyUp((KeyCode)99))
			{
				rotationY = 0f;
			}
			if (Input.GetKeyUp((KeyCode)102))
			{
				flipped = !flipped;
			}
			Vector3 val = Vector3.zero;
			Quaternion val2 = Quaternion.identity;
			Camera main = Camera.main;
			if ((Object)(object)main != (Object)null)
			{
				Ray val3 = main.ScreenPointToRay(Input.mousePosition);
				Vector3 val4 = ((Ray)(ref val3)).origin;
				Vector3 direction = ((Ray)(ref val3)).direction;
				float num = 0f;
				RaycastHit val5 = default(RaycastHit);
				while (num < 200f && Physics.Raycast(val4, direction, ref val5, 200f - num))
				{
					num += ((RaycastHit)(ref val5)).distance + 0.01f;
					val4 = ((RaycastHit)(ref val5)).point + direction * 0.01f;
					if (!((Object)(object)((RaycastHit)(ref val5)).collider != (Object)null) || !((Object)(object)((Component)((RaycastHit)(ref val5)).collider).GetComponentInParent<MyPlayer>() != (Object)null))
					{
						val = ((RaycastHit)(ref val5)).point;
						val2 = Quaternion.FromToRotation(Vector3.up, ((RaycastHit)(ref val5)).normal) * Quaternion.Euler(0f, rotationY, 0f);
						break;
					}
				}
			}
			if ((Object)(object)ghostRail == (Object)null)
			{
				RefreshGhost(((Il2CppArrayBase<GameObject>)(object)spawner.rails)[currentRailIndex]);
			}
			if ((Object)(object)ghostRail != (Object)null)
			{
				ghostRail.transform.SetPositionAndRotation(val, val2);
				Vector3 localScale = ghostRail.transform.localScale;
				localScale.x = (flipped ? (0f - Mathf.Abs(localScale.x)) : Mathf.Abs(localScale.x));
				ghostRail.transform.localScale = localScale;
				if (Input.GetMouseButtonDown(0) && !Cursor.visible)
				{
					GameObject obj = Object.Instantiate<GameObject>(((Il2CppArrayBase<GameObject>)(object)spawner.rails)[currentRailIndex], val, val2);
					Vector3 localScale2 = obj.transform.localScale;
					localScale2.x = (flipped ? (0f - Mathf.Abs(localScale2.x)) : Mathf.Abs(localScale2.x));
					obj.transform.localScale = localScale2;
				}
			}
		}

		public override void OnGUI()
		{
			//IL_006d: 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_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Expected O, but got Unknown
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: 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_00d1: 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_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Expected O, but got Unknown
			//IL_00f4: 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_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Expected O, but got Unknown
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Expected O, but got Unknown
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Expected O, but got Unknown
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0206: Unknown result type (might be due to invalid IL or missing references)
			//IL_0282: Unknown result type (might be due to invalid IL or missing references)
			if (buildMode)
			{
				float num = 350f;
				float num2 = 230f;
				float num3 = 350f;
				float num4 = 500f;
				if ((Object)(object)bgTex == (Object)null)
				{
					bgTex = new Texture2D(1, 1);
					bgTex.SetPixel(0, 0, new Color(0f, 0f, 0f, 0.6f));
					bgTex.Apply();
				}
				GUI.DrawTexture(new Rect(num3, num4, num, num2), (Texture)(object)bgTex);
				GUIStyle val = new GUIStyle(GUI.skin.label)
				{
					fontSize = 20,
					alignment = (TextAnchor)1
				};
				val.normal.textColor = Color.cyan;
				val.fontStyle = (FontStyle)1;
				GUIStyle val2 = val;
				GUIStyle val3 = new GUIStyle(GUI.skin.label)
				{
					fontSize = 16,
					alignment = (TextAnchor)1
				};
				val3.normal.textColor = Color.yellow;
				val3.fontStyle = (FontStyle)1;
				GUIStyle val4 = val3;
				GUIStyle val5 = new GUIStyle(GUI.skin.label)
				{
					fontSize = 14,
					alignment = (TextAnchor)7
				};
				val5.normal.textColor = Color.white;
				val5.fontStyle = (FontStyle)1;
				GUIStyle val6 = val5;
				GUIStyle val7 = new GUIStyle(GUI.skin.label)
				{
					fontSize = 16,
					alignment = (TextAnchor)1,
					fontStyle = (FontStyle)1,
					richText = true
				};
				GUI.Label(new Rect(num3, num4 + 5f, num, 25f), "BUILD MODE", val2);
				string text = (((Object)(object)spawner != (Object)null && ((Il2CppArrayBase<GameObject>)(object)spawner.rails).Length > 0) ? ((Object)((Il2CppArrayBase<GameObject>)(object)spawner.rails)[currentRailIndex]).name : "N/A");
				GUI.Label(new Rect(num3, num4 + 35f, num, 24f), "Selected Rail: " + text, val4);
				string text2 = "<color=white>Frozen:</color> " + (freezeToggle ? "<color=green>ON</color>" : "<color=red>OFF</color>");
				GUI.Label(new Rect(num3, num4 + 55f, num, 28f), text2, val7);
				string[] array = new string[8] { "← / → : Switch Rails", "Q / E : Rotate Rail", "Z / X : Rotate by 90*", "C : Reset rotation", "F : Flip", "LMB : Place Rail", "F1 : Toggle Build Mode", "F2 : Toggle Freeze" };
				for (int i = 0; i < array.Length; i++)
				{
					GUI.Label(new Rect(num3 + 10f, num4 + 80f + (float)(i * 18), num - 20f, 20f), array[i], val6);
				}
			}
		}

		private void RefreshGhost(GameObject prefab)
		{
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Expected O, but got Unknown
			if ((Object)(object)ghostRail != (Object)null)
			{
				Object.Destroy((Object)(object)ghostRail);
			}
			if (!((Object)(object)prefab == (Object)null))
			{
				ghostRail = Object.Instantiate<GameObject>(prefab);
				((Object)ghostRail).name = "GhostRail";
				if ((Object)(object)ghostMaterial == (Object)null)
				{
					ghostMaterial = new Material(Shader.Find("Standard"))
					{
						color = new Color(1f, 1f, 1f, 0.3f),
						renderQueue = 3000
					};
					ghostMaterial.SetInt("_SrcBlend", 5);
					ghostMaterial.SetInt("_DstBlend", 10);
					ghostMaterial.SetInt("_ZWrite", 0);
					ghostMaterial.EnableKeyword("_ALPHABLEND_ON");
				}
				ApplyGhost(ghostRail.transform);
			}
		}

		private void ApplyGhost(Transform t)
		{
			Collider component = ((Component)t).GetComponent<Collider>();
			if ((Object)(object)component != (Object)null)
			{
				component.enabled = false;
			}
			Renderer component2 = ((Component)t).GetComponent<Renderer>();
			if ((Object)(object)component2 != (Object)null)
			{
				component2.sharedMaterial = ghostMaterial;
			}
			for (int i = 0; i < t.childCount; i++)
			{
				ApplyGhost(t.GetChild(i));
			}
		}
	}
	[HarmonyPatch]
	internal static class EnemySpawnBlockPatch
	{
		private static IEnumerable<MethodBase> TargetMethods()
		{
			return from m in AccessTools.GetDeclaredMethods(typeof(EnemyManager))
				where m.Name == "SpawnEnemy"
				select m;
		}

		private static bool Prefix()
		{
			if (RailsBuilder.freezeToggle)
			{
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(MyTime), "Update")]
	public static class FreezeTimerPatch
	{
		private static bool Prefix()
		{
			if (RailsBuilder.freezeToggle)
			{
				MyTime.runTimer = RailsBuilder.cachedRunTimer;
				MyTime.stageTimer = RailsBuilder.cachedStageTimer;
				return false;
			}
			RailsBuilder.cachedRunTimer = MyTime.runTimer;
			RailsBuilder.cachedStageTimer = MyTime.stageTimer;
			return true;
		}
	}
}