Decompiled source of SkyLevelCooldown Skydorm v0.1.1

plugins/SkyLevelCooldown.dll

Decompiled a month ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
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 UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("SkyLevelCooldown")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SkyLevelCooldown")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("74eb5aae-2b80-4e14-b616-24649964c125")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
[BepInPlugin("com.skylevelcooldown", "Sky Level Cooldown", "0.1.0")]
public class SkyLevelCooldown : BaseUnityPlugin
{
	[HarmonyPatch(typeof(RunManager), "SetRunLevel")]
	public class Patch_RunManager_SetRunLevel
	{
		private static void Prefix(RunManager __instance)
		{
			if (!firstTimeInitialized)
			{
				levelCooldowns = new List<int>(new int[__instance.levels.Count]);
				log.LogInfo((object)$"Cooldownlist initialized with {__instance.levels.Count} Entries.");
				firstTimeInitialized = true;
			}
		}

		private static void Postfix(RunManager __instance)
		{
			if (__instance.levels == null || __instance.levels.Count == 0)
			{
				return;
			}
			int num = __instance.levels.IndexOf(__instance.levelCurrent);
			if (num < 0)
			{
				return;
			}
			if (levelCooldowns[num] == 0)
			{
				log.LogInfo((object)$"Level {((Object)__instance.levelCurrent).name} permitted, cooldown is was ({levelCooldowns[num]})");
				levelCooldowns[num] = levelRepeatDelay.Value + 1;
				DecreaseCooldownsExcept(num);
				return;
			}
			log.LogInfo((object)$"Level {((Object)__instance.levelCurrent).name} was cooldown ({levelCooldowns[num]}), new level will be chosen...");
			Level val = null;
			int num2 = -1;
			int num3 = 0;
			while ((Object)(object)val == (Object)null && num3 < maxRerollsConfig.Value)
			{
				int num4 = Random.Range(0, __instance.levels.Count);
				if (levelCooldowns[num4] == 0)
				{
					val = __instance.levels[num4];
					num2 = num4;
				}
				num3++;
			}
			if ((Object)(object)val == (Object)null)
			{
				num2 = Random.Range(0, __instance.levels.Count);
				val = __instance.levels[num2];
			}
			__instance.levelCurrent = val;
			levelCooldowns[num2] = levelRepeatDelay.Value + 1;
			DecreaseCooldownsExcept(num2);
			string text = string.Join(", ", __instance.levels.Select((Level lvl, int idx) => $"{((Object)lvl).name}:{levelCooldowns[idx]}"));
			log.LogInfo((object)("New level selected: " + ((Object)val).name + " | Cooldowns: " + text));
		}

		private static void DecreaseCooldownsExcept(int exceptIndex)
		{
			for (int i = 0; i < levelCooldowns.Count; i++)
			{
				if (i != exceptIndex && levelCooldowns[i] > 0)
				{
					levelCooldowns[i]--;
				}
			}
		}
	}

	internal static ManualLogSource log;

	public static ConfigEntry<int> levelRepeatDelay;

	public static ConfigEntry<int> maxRerollsConfig;

	public static List<int> levelCooldowns = new List<int>();

	private static bool firstTimeInitialized = false;

	private void Awake()
	{
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Expected O, but got Unknown
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		//IL_006f: Expected O, but got Unknown
		//IL_0079: Unknown result type (might be due to invalid IL or missing references)
		//IL_007f: Expected O, but got Unknown
		log = ((BaseUnityPlugin)this).Logger;
		levelRepeatDelay = ((BaseUnityPlugin)this).Config.Bind<int>("General", "Repeat Level After X Levels:", 3, new ConfigDescription("Cooldown delay, X levels before it can appear again. Please do not go higher than the amount of levels you installed + Vanilla levels.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 40), Array.Empty<object>()));
		maxRerollsConfig = ((BaseUnityPlugin)this).Config.Bind<int>("General", "Max Rerolls", 20, new ConfigDescription("Max attempts to reroll a level when the cooldown is active.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 200), Array.Empty<object>()));
		Harmony val = new Harmony("com.skylevelcooldown");
		val.PatchAll();
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Sky Level Cooldown loaded.");
	}
}