Decompiled source of CyberGrindUnlagNow v1.2.5

CyberGrindUnlagNow.dll

Decompiled an hour ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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 CyberGrindUnlagNow
{
	[BepInPlugin("com.corruptsoul.unlagnow", "CYBER GRIND UNLAG NOW!", "1.2.5")]
	public class Plugin : BaseUnityPlugin
	{
		public const string PluginGuid = "com.corruptsoul.unlagnow";

		public const string PluginName = "CYBER GRIND UNLAG NOW!";

		public const string PluginVersion = "1.2.5";

		internal static readonly Dictionary<EndlessCube, CubeGhost> CubeGhosts = new Dictionary<EndlessCube, CubeGhost>();

		internal static readonly Dictionary<EndlessPrefabAnimator, PrefabGhost> PrefabGhosts = new Dictionary<EndlessPrefabAnimator, PrefabGhost>();

		internal static readonly Dictionary<EndlessStairs, float> StairReleases = new Dictionary<EndlessStairs, float>();

		internal static readonly HashSet<EnemyIdentifier> GridEnemies = new HashSet<EnemyIdentifier>();

		private static readonly Predicate<EnemyIdentifier> destroyedEnemy = IsDestroyed;

		private static readonly List<Object> staleKeys = new List<Object>();

		private static Plugin instance;

		private static Material previewMaterial;

		private ConfigEntry<float> previewSeconds;

		private ConfigEntry<bool> disableJumpPads;

		private ConfigEntry<bool> disableSpawnEffects;

		private Harmony harmony;

		internal static float Delay
		{
			get
			{
				if ((Object)(object)instance == (Object)null || (Object)(object)previewMaterial == (Object)null)
				{
					return 0f;
				}
				return Mathf.Max(0f, instance.previewSeconds.Value);
			}
		}

		internal static bool JumpPadsDisabled
		{
			get
			{
				if ((Object)(object)instance != (Object)null)
				{
					return instance.disableJumpPads.Value;
				}
				return false;
			}
		}

		internal static bool SpawnEffectsDisabled
		{
			get
			{
				if ((Object)(object)instance != (Object)null)
				{
					return instance.disableSpawnEffects.Value;
				}
				return false;
			}
		}

		private void Awake()
		{
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Expected O, but got Unknown
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Expected O, but got Unknown
			instance = this;
			previewSeconds = ((BaseUnityPlugin)this).Config.Bind<float>("Preview", "PreviewSeconds", 1f, new ConfigDescription("Seconds the new layout is previewed before it snaps into place. 0 snaps instantly.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 5f), Array.Empty<object>()));
			disableJumpPads = ((BaseUnityPlugin)this).Config.Bind<bool>("Jump Pads", "DisableJumpPads", false, "Removes jump pads from Cyber Grind patterns (They lag alot when spawning.");
			disableSpawnEffects = ((BaseUnityPlugin)this).Config.Bind<bool>("Spawn Effects", "DisableSpawnEffects", false, "Removes the enemy spawn visuals in the Cyber Grind (They also lag alot when spawning.");
			previewMaterial = CreatePreviewMaterial();
			if ((Object)(object)previewMaterial == (Object)null)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)"No usable shader found for the preview. Pillars will snap instantly.");
			}
			harmony = new Harmony("com.corruptsoul.unlagnow");
			harmony.PatchAll(typeof(Plugin).Assembly);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"CYBER GRIND UNLAG NOW! loaded.");
		}

		private static Material CreatePreviewMaterial()
		{
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Expected O, but got Unknown
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			string[] array = new string[3] { "Sprites/Default", "UI/Default", "Hidden/Internal-Colored" };
			for (int i = 0; i < array.Length; i++)
			{
				Shader val = Shader.Find(array[i]);
				if (!((Object)(object)val == (Object)null))
				{
					Material val2 = new Material(val);
					if (val2.HasProperty("_Color"))
					{
						val2.color = new Color(0.2f, 0.9f, 1f, 0.35f);
					}
					val2.renderQueue = 3000;
					return val2;
				}
			}
			return null;
		}

		private void Update()
		{
			if (CubeGhosts.Count > 0)
			{
				Prune<EndlessCube, CubeGhost>(CubeGhosts);
				DrawCubeGhosts();
			}
			if (PrefabGhosts.Count > 0)
			{
				Prune<EndlessPrefabAnimator, PrefabGhost>(PrefabGhosts);
				DrawPrefabGhosts();
			}
			if (StairReleases.Count > 0)
			{
				Prune<EndlessStairs, float>(StairReleases);
			}
			if (GridEnemies.Count > 0)
			{
				GridEnemies.RemoveWhere(destroyedEnemy);
			}
		}

		private static bool IsDestroyed(EnemyIdentifier enemy)
		{
			return (Object)(object)enemy == (Object)null;
		}

		private static void DrawCubeGhosts()
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			foreach (KeyValuePair<EndlessCube, CubeGhost> cubeGhost in CubeGhosts)
			{
				if (!((Object)(object)cubeGhost.Value.Mesh == (Object)null))
				{
					DrawMesh(cubeGhost.Value.Mesh, cubeGhost.Value.Matrix);
				}
			}
		}

		private static void DrawPrefabGhosts()
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: 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_007f: Unknown result type (might be due to invalid IL or missing references)
			foreach (KeyValuePair<EndlessPrefabAnimator, PrefabGhost> prefabGhost in PrefabGhosts)
			{
				PrefabGhost value = prefabGhost.Value;
				Matrix4x4 val = Matrix4x4.Translate(value.Target - ((Component)prefabGhost.Key).transform.position);
				MeshFilter[] filters = value.Filters;
				foreach (MeshFilter val2 in filters)
				{
					if (!((Object)(object)val2 == (Object)null) && !((Object)(object)val2.sharedMesh == (Object)null))
					{
						DrawMesh(val2.sharedMesh, val * ((Component)val2).transform.localToWorldMatrix);
					}
				}
			}
		}

		private static void DrawMesh(Mesh mesh, Matrix4x4 matrix)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < mesh.subMeshCount; i++)
			{
				Graphics.DrawMesh(mesh, matrix, previewMaterial, 0, (Camera)null, i);
			}
		}

		private static void Prune<TKey, TValue>(Dictionary<TKey, TValue> dictionary) where TKey : Object
		{
			staleKeys.Clear();
			foreach (TKey key in dictionary.Keys)
			{
				if ((Object)(object)key == (Object)null)
				{
					staleKeys.Add((Object)(object)key);
				}
			}
			for (int i = 0; i < staleKeys.Count; i++)
			{
				dictionary.Remove((TKey)(object)staleKeys[i]);
			}
		}

		private void OnDestroy()
		{
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			CubeGhosts.Clear();
			PrefabGhosts.Clear();
			StairReleases.Clear();
			GridEnemies.Clear();
			if ((Object)(object)previewMaterial != (Object)null)
			{
				Object.Destroy((Object)(object)previewMaterial);
			}
		}
	}
	internal struct CubeGhost
	{
		public Mesh Mesh;

		public Matrix4x4 Matrix;
	}
	internal sealed class PrefabGhost
	{
		public float Release;

		public Vector3 Target;

		public MeshFilter[] Filters;
	}
	[HarmonyPatch(typeof(EndlessGrid), "SpawnOnGrid")]
	internal static class EndlessGrid_SpawnOnGrid_Patch
	{
		private const int JumpPadPoolType = 1;

		private static bool Prefix(object[] __args, ref GameObject __result)
		{
			if (!Plugin.JumpPadsDisabled)
			{
				return true;
			}
			if (Convert.ToInt32(__args[4]) != 1)
			{
				return true;
			}
			__result = null;
			return false;
		}

		private static void Postfix(GameObject __result)
		{
			if (!((Object)(object)__result == (Object)null) && Plugin.SpawnEffectsDisabled)
			{
				EnemyIdentifier[] componentsInChildren = __result.GetComponentsInChildren<EnemyIdentifier>(true);
				foreach (EnemyIdentifier item in componentsInChildren)
				{
					Plugin.GridEnemies.Add(item);
				}
			}
		}
	}
	[HarmonyPatch(typeof(SpawnEffect), "Start")]
	internal static class SpawnEffect_Start_Patch
	{
		private static void Postfix(SpawnEffect __instance)
		{
			if (!Plugin.SpawnEffectsDisabled)
			{
				return;
			}
			EnemyIdentifier componentInParent = ((Component)__instance).GetComponentInParent<EnemyIdentifier>();
			if (!((Object)(object)componentInParent == (Object)null) && Plugin.GridEnemies.Contains(componentInParent))
			{
				Light[] componentsInChildren = ((Component)__instance).GetComponentsInChildren<Light>(true);
				for (int i = 0; i < componentsInChildren.Length; i++)
				{
					((Behaviour)componentsInChildren[i]).enabled = false;
				}
				Renderer[] componentsInChildren2 = ((Component)__instance).GetComponentsInChildren<Renderer>(true);
				for (int i = 0; i < componentsInChildren2.Length; i++)
				{
					componentsInChildren2[i].enabled = false;
				}
			}
		}
	}
	[HarmonyPatch(typeof(EndlessCube), "SetTarget")]
	internal static class EndlessCube_SetTarget_Patch
	{
		private static void Postfix(EndlessCube __instance, Transform ___tf, Vector3 ___targetPos, MeshFilter ___meshFilter, ref bool ___active)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: 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_0093: 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_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			((MonoBehaviour)__instance).CancelInvoke("StartMoving");
			float delay = Plugin.Delay;
			bool flag = Mathf.Abs(___tf.position.y - ___targetPos.y) > 0.01f;
			if (delay <= 0f || !flag)
			{
				Plugin.CubeGhosts.Remove(__instance);
				___tf.position = ___targetPos;
				___active = true;
				return;
			}
			MeshFilter val = (((Object)(object)___meshFilter != (Object)null) ? ___meshFilter : ((Component)__instance).GetComponent<MeshFilter>());
			if ((Object)(object)val != (Object)null && (Object)(object)val.sharedMesh != (Object)null)
			{
				Matrix4x4 localToWorldMatrix = ___tf.localToWorldMatrix;
				localToWorldMatrix.m03 = ___targetPos.x;
				localToWorldMatrix.m13 = ___targetPos.y;
				localToWorldMatrix.m23 = ___targetPos.z;
				Plugin.CubeGhosts[__instance] = new CubeGhost
				{
					Mesh = val.sharedMesh,
					Matrix = localToWorldMatrix
				};
			}
			((MonoBehaviour)__instance).Invoke("StartMoving", delay);
		}
	}
	[HarmonyPatch(typeof(EndlessCube), "Update")]
	internal static class EndlessCube_Update_Patch
	{
		private static void Prefix(EndlessCube __instance, bool ___active, Transform ___tf, Vector3 ___targetPos)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			if (___active)
			{
				___tf.position = ___targetPos;
				Plugin.CubeGhosts.Remove(__instance);
			}
		}
	}
	[HarmonyPatch(typeof(EndlessPrefabAnimator), "Update")]
	internal static class EndlessPrefabAnimator_Update_Patch
	{
		private static bool Prefix(EndlessPrefabAnimator __instance, bool ___moving, Vector3 ___origPos)
		{
			//IL_008a: 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_0095: 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_0074: 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_0034: Unknown result type (might be due to invalid IL or missing references)
			if (___moving)
			{
				float delay = Plugin.Delay;
				if (delay > 0f)
				{
					if (!Plugin.PrefabGhosts.TryGetValue(__instance, out var value))
					{
						value = new PrefabGhost
						{
							Release = Time.time + delay,
							Target = ___origPos,
							Filters = ((Component)__instance).GetComponentsInChildren<MeshFilter>(true)
						};
						Plugin.PrefabGhosts[__instance] = value;
					}
					if (Time.time < value.Release)
					{
						return false;
					}
					Plugin.PrefabGhosts.Remove(__instance);
				}
				((Component)__instance).transform.position = ___origPos;
			}
			else if (__instance.reverse)
			{
				((Component)__instance).transform.position = ___origPos - Vector3.up * 20f;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(EndlessStairs), "Update")]
	internal static class EndlessStairs_Update_Patch
	{
		private static bool Prefix(EndlessStairs __instance, bool ___moving, bool ___activateFirst, bool ___activateSecond, Transform ___primaryStairs, Transform ___secondaryStairs)
		{
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			if (!___moving)
			{
				return true;
			}
			float delay = Plugin.Delay;
			if (delay > 0f)
			{
				if (!Plugin.StairReleases.TryGetValue(__instance, out var value))
				{
					value = Time.time + delay;
					Plugin.StairReleases[__instance] = value;
				}
				if (Time.time < value)
				{
					return false;
				}
				Plugin.StairReleases.Remove(__instance);
			}
			Vector3 position = ((Component)__instance).transform.position;
			if (___activateFirst && (Object)(object)___primaryStairs != (Object)null)
			{
				___primaryStairs.position = position;
			}
			if (___activateSecond && (Object)(object)___secondaryStairs != (Object)null)
			{
				___secondaryStairs.position = position;
			}
			return true;
		}
	}
}