Decompiled source of HurryUp v0.180.3

HurryUp.dll

Decompiled 2 months ago
using System;
using System.Collections;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Mirror;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("HurryUp")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("HurryUp")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("320a9897-ee38-4a37-af54-db180f04f294")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace HurryUp
{
	[BepInPlugin("rei.stonewards.hurryup", "HurryUp", "0.180.3")]
	public class Plugin : BaseUnityPlugin
	{
		internal static Plugin Instance;

		internal static ManualLogSource Log;

		internal static ConfigEntry<bool> Enabled;

		internal static ConfigEntry<LaunchMode> Mode;

		internal static ConfigEntry<KeyboardShortcut> LaunchKey;

		private void Awake()
		{
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Expected O, but got Unknown
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			Instance = this;
			Log = ((BaseUnityPlugin)this).Logger;
			Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Enable or disable HurryUp.");
			Mode = ((BaseUnityPlugin)this).Config.Bind<LaunchMode>("General", "Mode", LaunchMode.Keypress, "How the next wave is launched.");
			LaunchKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("General", "Launch Key", new KeyboardShortcut((KeyCode)287, Array.Empty<KeyCode>()), "Key used to launch the next wave when using Keypress or Casual mode.");
			Harmony val = new Harmony("rei.stonewards.hurryup");
			val.PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"HurryUp loaded.");
			((BaseUnityPlugin)this).Logger.LogInfo((object)$"Enabled: {Enabled.Value}");
			((BaseUnityPlugin)this).Logger.LogInfo((object)$"Mode: {Mode.Value}");
			ManualLogSource logger = ((BaseUnityPlugin)this).Logger;
			KeyboardShortcut value = LaunchKey.Value;
			logger.LogInfo((object)$"Launch Key: {((KeyboardShortcut)(ref value)).MainKey}");
		}
	}
	internal enum LaunchMode
	{
		Instant,
		Keypress,
		Casual
	}
}
namespace HurryUp.Patches
{
	[HarmonyPatch(typeof(EnemyManager), "ServerCountdown")]
	public static class ServerCountdownPatch
	{
		private static bool Prefix(EnemyManager __instance, ref IEnumerator __result)
		{
			if (!Plugin.Enabled.Value)
			{
				return true;
			}
			if (!NetworkServer.active)
			{
				return true;
			}
			__result = HurryUpCountdown(__instance);
			return false;
		}

		private static IEnumerator HurryUpCountdown(EnemyManager enemyManager)
		{
			while ((Object)(object)DiggingManager.Instance == (Object)null)
			{
				yield return null;
			}
			yield return (object)new WaitUntil((Func<bool>)(() => DiggingManager.Instance.isLevelGenerated));
			if (Plugin.Mode.Value == LaunchMode.Instant)
			{
				Plugin.Log.LogInfo((object)"Instant mode: launching next wave.");
				LaunchWave(enemyManager);
				yield break;
			}
			KeyboardShortcut value;
			if (Plugin.Mode.Value == LaunchMode.Casual)
			{
				ManualLogSource log = Plugin.Log;
				value = Plugin.LaunchKey.Value;
				log.LogInfo((object)$"Casual mode: waiting for {((KeyboardShortcut)(ref value)).MainKey}.");
				while (true)
				{
					value = Plugin.LaunchKey.Value;
					if (((KeyboardShortcut)(ref value)).IsDown())
					{
						break;
					}
					yield return null;
				}
				Plugin.Log.LogInfo((object)"Casual mode: launch key pressed.");
				LaunchWave(enemyManager);
				yield break;
			}
			ManualLogSource log2 = Plugin.Log;
			value = Plugin.LaunchKey.Value;
			log2.LogInfo((object)$"Keypress mode: countdown started. Press {((KeyboardShortcut)(ref value)).MainKey} to skip.");
			float elapsed = 0f;
			while (true)
			{
				value = Plugin.LaunchKey.Value;
				if (((KeyboardShortcut)(ref value)).IsDown())
				{
					Plugin.Log.LogInfo((object)"Keypress mode: launch key pressed. Skipping countdown.");
					LaunchWave(enemyManager);
					yield break;
				}
				elapsed += Time.deltaTime;
				if (elapsed >= 1f)
				{
					elapsed -= 1f;
					int remaining = GetCurrentCountdown(enemyManager);
					remaining--;
					SetCurrentCountdown(enemyManager, remaining);
					NetworkHelper.Instance.ServerUpdateCountdown((float)remaining);
					if (remaining <= 0)
					{
						break;
					}
				}
				yield return null;
			}
			LaunchWave(enemyManager);
		}

		private static int GetCurrentCountdown(EnemyManager enemyManager)
		{
			return (int)AccessTools.Field(typeof(EnemyManager), "currentCountdown").GetValue(enemyManager);
		}

		private static void SetCurrentCountdown(EnemyManager enemyManager, int value)
		{
			AccessTools.Field(typeof(EnemyManager), "currentCountdown").SetValue(enemyManager, value);
		}

		private static void LaunchWave(EnemyManager enemyManager)
		{
			NetworkHelper.Instance.ServerUpdateCountdown(0f);
			Plugin.Log.LogInfo((object)"Launching next wave.");
			AccessTools.Method(typeof(EnemyManager), "LaunchWave", (Type[])null, (Type[])null).Invoke(enemyManager, null);
		}
	}
}