Decompiled source of Uncap monster level v1.0.0

plugins/UncapMonsterLevel/UncapMonsterLevel.dll

Decompiled 14 hours ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using Microsoft.CodeAnalysis;
using On.RoR2;
using RiskOfOptions;
using RiskOfOptions.OptionConfigs;
using RiskOfOptions.Options;
using RoR2;
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: AssemblyCompany("UncapMonsterLevel")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+7e6f2311f0a7348b69474ff1980a93033ebd9d34")]
[assembly: AssemblyProduct("UncapMonsterLevel")]
[assembly: AssemblyTitle("UncapMonsterLevel")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.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 UncapMonsterLevel
{
	internal static class Log
	{
		private static ManualLogSource _logSource;

		internal static void Init(ManualLogSource logSource)
		{
			_logSource = logSource;
		}

		internal static void Debug(object data)
		{
			_logSource.LogDebug(data);
		}

		internal static void Error(object data)
		{
			_logSource.LogError(data);
		}

		internal static void Fatal(object data)
		{
			_logSource.LogFatal(data);
		}

		internal static void Info(object data)
		{
			_logSource.LogInfo(data);
		}

		internal static void Message(object data)
		{
			_logSource.LogMessage(data);
		}

		internal static void Warning(object data)
		{
			_logSource.LogWarning(data);
		}
	}
	internal static class MonsterLevelHooks
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static hook_RecalculateDifficultyCoefficentInternal <0>__RecalculateDifficultyCoefficentInternal;

			public static hook_OnRunAmbientLevelUp <1>__OnRunAmbientLevelUp;
		}

		public const int VANILLA_MAX_LEVEL = 99;

		public const int MAX_LEVEL = int.MaxValue;

		private const float PERCENT = 100f;

		private static int capBefore;

		private static bool capMoved;

		private static float lastLevelUpSound = float.NegativeInfinity;

		public static void Init()
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Expected O, but got Unknown
			object obj = <>O.<0>__RecalculateDifficultyCoefficentInternal;
			if (obj == null)
			{
				hook_RecalculateDifficultyCoefficentInternal val = RecalculateDifficultyCoefficentInternal;
				<>O.<0>__RecalculateDifficultyCoefficentInternal = val;
				obj = (object)val;
			}
			Run.RecalculateDifficultyCoefficentInternal += (hook_RecalculateDifficultyCoefficentInternal)obj;
			object obj2 = <>O.<1>__OnRunAmbientLevelUp;
			if (obj2 == null)
			{
				hook_OnRunAmbientLevelUp val2 = OnRunAmbientLevelUp;
				<>O.<1>__OnRunAmbientLevelUp = val2;
				obj2 = (object)val2;
			}
			LevelUpEffectManager.OnRunAmbientLevelUp += (hook_OnRunAmbientLevelUp)obj2;
		}

		private static void RecalculateDifficultyCoefficentInternal(orig_RecalculateDifficultyCoefficentInternal orig, Run self)
		{
			if (!UncapMonsterLevel.uncapLevel.Value)
			{
				RestoreCap();
				orig.Invoke(self);
				return;
			}
			if (!capMoved)
			{
				capBefore = Run.ambientLevelCap;
				capMoved = true;
			}
			int ambientLevelFloor = self.ambientLevelFloor;
			Run.ambientLevelCap = int.MaxValue;
			self.ambientLevelFloor = 0;
			orig.Invoke(self);
			int value = UncapMonsterLevel.maxLevel.Value;
			self.ambientLevel = Mathf.Min(SlowDown(self.ambientLevel), (float)value);
			self.ambientLevelFloor = ((self.ambientLevel >= (float)value) ? value : Mathf.FloorToInt(self.ambientLevel));
			if (ambientLevelFloor != 0 && self.ambientLevelFloor > ambientLevelFloor)
			{
				self.OnAmbientLevelUp();
			}
		}

		private static float SlowDown(float level)
		{
			if (level <= 99f)
			{
				return level;
			}
			return 99f + (level - 99f) * (UncapMonsterLevel.levelSpeed.Value / 100f);
		}

		private static void RestoreCap()
		{
			if (capMoved)
			{
				Run.ambientLevelCap = capBefore;
				capMoved = false;
			}
		}

		private static void OnRunAmbientLevelUp(orig_OnRunAmbientLevelUp orig, Run run)
		{
			int value = UncapMonsterLevel.levelUpSoundInterval.Value;
			if (value <= 0 || !(Time.unscaledTime - lastLevelUpSound < (float)value))
			{
				lastLevelUpSound = Time.unscaledTime;
				orig.Invoke(run);
			}
		}
	}
	internal static class RiskOfOptionsCompat
	{
		public const string GUID = "com.rune580.riskofoptions";

		private const string ICON_FILE = "icon.png";

		public static bool Enabled => Chainloader.PluginInfos.ContainsKey("com.rune580.riskofoptions");

		[MethodImpl(MethodImplOptions.NoInlining)]
		public static void Init(string pluginLocation)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Expected O, but got Unknown
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Expected O, but got Unknown
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Expected O, but got Unknown
			//IL_004f: Expected O, but got Unknown
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Expected O, but got Unknown
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: 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_0084: Expected O, but got Unknown
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Expected O, but got Unknown
			//IL_008e: 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_00a7: Expected O, but got Unknown
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Expected O, but got Unknown
			ModSettingsManager.SetModDescription("Lets the monsters level past 99 and lets you change how fast they do so.");
			Sprite val = LoadIcon(pluginLocation);
			if (Object.op_Implicit((Object)(object)val))
			{
				ModSettingsManager.SetModIcon(val);
			}
			ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(UncapMonsterLevel.uncapLevel));
			ConfigEntry<int> maxLevel = UncapMonsterLevel.maxLevel;
			IntFieldConfig val2 = new IntFieldConfig();
			((NumericFieldConfig<int>)val2).Min = 1;
			((NumericFieldConfig<int>)val2).Max = int.MaxValue;
			ModSettingsManager.AddOption((BaseOption)new IntFieldOption(maxLevel, val2));
			ModSettingsManager.AddOption((BaseOption)new SliderOption(UncapMonsterLevel.levelSpeed, new SliderConfig
			{
				min = 1f,
				max = 1000f,
				FormatString = "{0:0.#}%"
			}));
			ModSettingsManager.AddOption((BaseOption)new IntSliderOption(UncapMonsterLevel.levelUpSoundInterval, new IntSliderConfig
			{
				min = 0,
				max = 60
			}));
		}

		private static Sprite LoadIcon(string pluginLocation)
		{
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Expected O, but got Unknown
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			string directoryName = Path.GetDirectoryName(pluginLocation);
			string path = Path.Combine(directoryName, "icon.png");
			if (!File.Exists(path))
			{
				path = Path.Combine(Path.GetDirectoryName(directoryName), "icon.png");
			}
			if (!File.Exists(path))
			{
				return null;
			}
			Texture2D val = new Texture2D(2, 2);
			if (!ImageConversion.LoadImage(val, File.ReadAllBytes(path)))
			{
				return null;
			}
			return Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f));
		}
	}
	[BepInPlugin("360gaggi.UncapMonsterLevel", "UncapMonsterLevel", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class UncapMonsterLevel : BaseUnityPlugin
	{
		public const string PLUGIN_GUID = "360gaggi.UncapMonsterLevel";

		public const string PLUGIN_AUTHOR = "360gaggi";

		public const string PLUGIN_NAME = "UncapMonsterLevel";

		public const string PLUGIN_VERSION = "1.0.0";

		public const float MIN_LEVEL_SPEED = 1f;

		public const float MAX_LEVEL_SPEED = 1000f;

		public const int MAX_LEVEL_UP_SOUND_INTERVAL = 60;

		public static ConfigEntry<bool> uncapLevel;

		public static ConfigEntry<int> maxLevel;

		public static ConfigEntry<float> levelSpeed;

		public static ConfigEntry<int> levelUpSoundInterval;

		public void Awake()
		{
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Expected O, but got Unknown
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Expected O, but got Unknown
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Expected O, but got Unknown
			Log.Init(((BaseUnityPlugin)this).Logger);
			uncapLevel = ((BaseUnityPlugin)this).Config.Bind<bool>("Monsters", "Uncap level", true, "Lets the monsters level past 99. Turn it off to get vanilla back without removing the mod");
			maxLevel = ((BaseUnityPlugin)this).Config.Bind<int>("Monsters", "Max level", int.MaxValue, new ConfigDescription("The highest level the monsters can reach (vanilla stops at 99). The default is as high as the game can count", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, int.MaxValue), Array.Empty<object>()));
			levelSpeed = ((BaseUnityPlugin)this).Config.Bind<float>("Monsters", "Level speed past 99", 100f, new ConfigDescription("How fast the monsters keep levelling once they are past 99, in percent. 100% is what the difficulty of the run asks for, which gets out of hand in a long run: the levels come faster with every stage. With 50% they come half as fast. Up to 99 nothing changes", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 1000f), Array.Empty<object>()));
			levelUpSoundInterval = ((BaseUnityPlugin)this).Config.Bind<int>("Monsters", "Level up sound interval", 1, new ConfigDescription("The least time between two of the sounds that play when the monsters level up, in seconds. Late in a run they level many times a second. 0 plays every single one like vanilla", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 60), Array.Empty<object>()));
			MonsterLevelHooks.Init();
			if (RiskOfOptionsCompat.Enabled)
			{
				RiskOfOptionsCompat.Init(((BaseUnityPlugin)this).Info.Location);
			}
		}
	}
}