Decompiled source of Godspeed v1.0.0

Godspeed/Godspeed.dll

Decompiled 2 weeks ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using PluginConfig.API;
using PluginConfig.API.Fields;
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.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("Godspeed")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+e37cd77b1370d40a6ca3688b3188aebb5c9d7466")]
[assembly: AssemblyProduct("Godspeed")]
[assembly: AssemblyTitle("Godspeed")]
[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 Godspeed
{
	internal class CustomBossBar : MonoBehaviour, IEnemyHealthDetails
	{
		public string fullName = "speed up";

		private float health;

		public string FullName => fullName;

		public float Health
		{
			get
			{
				return health;
			}
			set
			{
				health = value;
			}
		}

		public bool Dead => false;

		public bool Blessed => false;

		public void ForceGetHealth()
		{
		}
	}
	internal class PluginInfo
	{
		public const string Name = "Godspeed";

		public const string GUID = "adohtq.ultrakill.godspeed";

		public const string Version = "1.0.0";
	}
	[BepInPlugin("adohtq.ultrakill.godspeed", "Godspeed", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	internal class Godspeed : BaseUnityPlugin
	{
		public enum Punishments
		{
			None,
			Death,
			Damage,
			Ramping
		}

		private PluginConfigurator config;

		public static FloatField speedThreshold;

		public static FloatField leniency;

		public static EnumField<Punishments> punishment;

		public static NewMovement player;

		public void Awake()
		{
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Expected O, but got Unknown
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Expected O, but got Unknown
			config = PluginConfigurator.Create("Godspeed", "godspeed.settings");
			string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
			string text = Path.Combine(Path.Combine(directoryName, "Data"), "icon.png");
			Debug.LogError((object)text);
			config.SetIconWithURL("file://" + text);
			speedThreshold = new FloatField(config.rootPanel, "Speed Threshold", "godspeed.settings.speedThreshold", 20f)
			{
				minimumValue = 0f,
				maximumValue = 100f
			};
			leniency = new FloatField(config.rootPanel, "Leniency Seconds", "godspeed.settings.leniency", 1f)
			{
				minimumValue = 0f,
				maximumValue = 60f
			};
			punishment = new EnumField<Punishments>(config.rootPanel, "Thy Punishment", "godspeed.settings.punishment", Punishments.Death);
		}

		public void Start()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			Harmony val = new Harmony("adohtq.ultrakill.godspeed");
			val.PatchAll(typeof(Movement_Patch));
			val.PatchAll(typeof(BossHealthBarTemplate_Patch));
		}
	}
	[HarmonyPatch(typeof(NewMovement))]
	public static class Movement_Patch
	{
		[HarmonyPostfix]
		[HarmonyPatch(typeof(NewMovement), "Start")]
		public static void patch_Update(NewMovement __instance)
		{
			Godspeed.player = __instance;
			((Component)__instance).gameObject.AddComponent<SpeedThreshold>();
		}
	}
	[HarmonyPatch(typeof(BossHealthBarTemplate))]
	public static class BossHealthBarTemplate_Patch
	{
		private static CustomBossBar? bossBarSource;

		private static bool onScreen;

		[HarmonyPostfix]
		[HarmonyPatch(typeof(BossHealthBarTemplate), "Initialize")]
		public static void patch_Initialize(BossHealthBarTemplate __instance, object[] __args)
		{
			object obj = __args[0];
			BossHealthBar val = (BossHealthBar)((obj is BossHealthBar) ? obj : null);
			if (!((Object)(object)val == (Object)null))
			{
				if (val.source is CustomBossBar)
				{
					bossBarSource = val.source as CustomBossBar;
				}
				ComponentExtensions.GetOrAddComponent<CanvasGroup>((Component)(object)__instance).alpha = 0f;
				onScreen = false;
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(BossHealthBarTemplate), "UpdateState")]
		public static void patch_UpdateState(BossHealthBarTemplate __instance)
		{
			if (!((Object)(object)bossBarSource == (Object)null))
			{
				if (MonoSingleton<PlayerTracker>.Instance.levelStarted && !onScreen)
				{
					((Component)__instance).GetComponent<CanvasGroup>().alpha = 1f;
					onScreen = true;
				}
				if (Godspeed.player.dead)
				{
					((Component)__instance).GetComponent<CanvasGroup>().alpha = 0f;
				}
			}
		}
	}
	internal class SpeedThreshold : MonoBehaviour
	{
		private CustomBossBar bossSource;

		private BossHealthBar bossBar;

		private float timeLeft = -1f;

		private int currentDamage = 5;

		public void Start()
		{
			bossSource = ((Component)this).gameObject.AddComponent<CustomBossBar>();
			CreateBar();
		}

		public void Update()
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			if (Godspeed.player.dead)
			{
				currentDamage = 5;
			}
			if (Godspeed.player.dead || !MonoSingleton<PlayerTracker>.Instance.levelStarted)
			{
				return;
			}
			Vector3 playerVelocity = MonoSingleton<PlayerTracker>.Instance.GetPlayerVelocity(true);
			float magnitude = ((Vector3)(ref playerVelocity)).magnitude;
			if (timeLeft < 0f && magnitude < Godspeed.speedThreshold.value)
			{
				timeLeft = Godspeed.leniency.value;
			}
			else
			{
				if (!(timeLeft >= 0f))
				{
					return;
				}
				if (magnitude > Godspeed.speedThreshold.value)
				{
					timeLeft = -1f;
					bossSource.Health = Godspeed.leniency.value;
					return;
				}
				timeLeft -= Time.deltaTime;
				bossSource.Health = timeLeft;
				if (timeLeft < 0f)
				{
					switch (Godspeed.punishment.value)
					{
					case Godspeed.Punishments.Death:
						Godspeed.player.GetHurt(5000000, false, 1f, false, false, 0.35f, false);
						break;
					case Godspeed.Punishments.Damage:
						Godspeed.player.GetHurt(20, false, 1f, false, false, 0.35f, false);
						break;
					case Godspeed.Punishments.Ramping:
						Godspeed.player.GetHurt(currentDamage, false, 1f, false, false, 0.35f, false);
						currentDamage += 5;
						break;
					}
					timeLeft = -1f;
				}
			}
		}

		private void CreateBar()
		{
			bossSource.Health = Godspeed.leniency.value + 0.001f;
			bossBar = ((Component)this).gameObject.AddComponent<BossHealthBar>();
			bossBar.bossName = "SPEED UP";
			bossBar.secondaryBar = false;
			bossBar.source = (IEnemyHealthDetails)(object)bossSource;
		}
	}
}