Decompiled source of TimescaleShenanigans v2.1.2

SpeedUpOnKill.dll

Decompiled 4 months ago
using System;
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.Bootstrap;
using BepInEx.Configuration;
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.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = ".NET Standard 2.0")]
[assembly: AssemblyCompany("SpeedUpOnKill")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("SpeedUpOnKill")]
[assembly: AssemblyTitle("SpeedUpOnKill")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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 SpeedUpOnKill
{
	[BepInPlugin("MarkTullius.TimescaleShenanigans", "TimescaleShenanigans", "2.1.2")]
	public class Main : BaseUnityPlugin
	{
		public enum Scaling
		{
			Linear,
			Random
		}

		public const string PluginGUID = "MarkTullius.TimescaleShenanigans";

		public const string PluginAuthor = "MarkTullius";

		public const string PluginName = "TimescaleShenanigans";

		public const string PluginVersion = "2.1.2";

		public float killCount = 0f;

		public static ConfigEntry<Scaling> ScalingStyle { get; set; }

		public static ConfigEntry<float> TimeFactor { get; set; }

		public static ConfigEntry<float> Ceiling { get; set; }

		public static ConfigEntry<float> UpperBound { get; set; }

		public static ConfigEntry<float> LowerBound { get; set; }

		public static ConfigEntry<float> KillFactor { get; set; }

		public static ConfigEntry<bool> ResetEachStage { get; set; }

		public void Awake()
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Expected O, but got Unknown
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Expected O, but got Unknown
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Expected O, but got Unknown
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Expected O, but got Unknown
			InitConfig();
			if (Chainloader.PluginInfos.ContainsKey("com.rune580.riskofoptions"))
			{
				BuildSettings();
			}
			GlobalEventManager.OnCharacterDeath += new hook_OnCharacterDeath(IncreaseTimeScale);
			Run.Start += new hook_Start(SetVoidCoins);
			Run.BeginStage += new hook_BeginStage(ResetPerStage);
			Run.OnDestroy += new hook_OnDestroy(ResetTimescale);
		}

		public void InitConfig()
		{
			ScalingStyle = ((BaseUnityPlugin)this).Config.Bind<Scaling>("General", "Scaling Style", Scaling.Linear, "The selected style of time scaling.\r\n            Linear scales the timescale of the engine upon killing an enemy (by default 1 kill will increase, config option to set this to be less frequent).\r\n            Random chooses the timescale to set the engine to between the upper and lower bounds (set in config values).");
			ResetEachStage = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Reset Each Stage", false, "Turn on to reset the timescale to 100% every time you load into a new stage.");
			KillFactor = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Kill Factor", 1f, "The kill interval at which the timescale will change. By default one kill will change the timescale, set higher to have the timescale change less frequently.");
			TimeFactor = ((BaseUnityPlugin)this).Config.Bind<float>("Linear", "Time Factor", 0.005f, "The factor by which to increase the timescale by upon a kill. Enter the % factor that you wish the game to increase by every time the Kill Factor is reached. i.e. 0.005 = 0.5%");
			Ceiling = ((BaseUnityPlugin)this).Config.Bind<float>("Linear", "Ceiling", 10f, "The hard cap that the timescale cannot go above with Linear scaling. WARNING changing this to a higher value may cause your game to crash (or even BSOD at ridiculous values) due to hardware limitations. Reduce this if you have concerns over the capabilities of your machine.");
			UpperBound = ((BaseUnityPlugin)this).Config.Bind<float>("Random", "Upper Bound", 3f, "Defines the maximum that the timescale can be set to.");
			LowerBound = ((BaseUnityPlugin)this).Config.Bind<float>("Random", "Lower Bound", 0.5f, "Defines the minimum that the timescale can be set to.");
		}

		public void ResetTimescale(orig_OnDestroy orig, Run self)
		{
			orig.Invoke(self);
			Time.timeScale = 1f;
		}

		public void ResetPerStage(orig_BeginStage orig, Run self)
		{
			orig.Invoke(self);
			if (ResetEachStage.Value)
			{
				Time.timeScale = 1f;
				PlayerCharacterMasterController._instances[0].master.voidCoins = 100u;
			}
		}

		public void SetVoidCoins(orig_Start orig, Run self)
		{
			orig.Invoke(self);
			PlayerCharacterMasterController._instances[0].master.voidCoins = 100u;
		}

		public void BuildSettings()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Expected O, but got Unknown
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: 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_0054: Expected O, but got Unknown
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Expected O, but got Unknown
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Expected O, but got Unknown
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: 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
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: 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
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Expected O, but got Unknown
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Expected O, but got Unknown
			StepSliderConfig val = new StepSliderConfig
			{
				min = 0.001f,
				max = Ceiling.Value,
				increment = 0.001f
			};
			StepSliderConfig val2 = new StepSliderConfig
			{
				min = 2f,
				max = 100f,
				increment = 1f
			};
			StepSliderConfig val3 = new StepSliderConfig
			{
				min = 1f,
				max = 100f,
				increment = 1f
			};
			ModSettingsManager.AddOption((BaseOption)new ChoiceOption((ConfigEntryBase)(object)ScalingStyle));
			ModSettingsManager.AddOption((BaseOption)new StepSliderOption(TimeFactor, val));
			ModSettingsManager.AddOption((BaseOption)new StepSliderOption(UpperBound, val));
			ModSettingsManager.AddOption((BaseOption)new StepSliderOption(LowerBound, val));
			ModSettingsManager.AddOption((BaseOption)new StepSliderOption(Ceiling, val2));
			ModSettingsManager.AddOption((BaseOption)new StepSliderOption(KillFactor, val3));
			ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(ResetEachStage));
		}

		public void IncreaseTimeScale(orig_OnCharacterDeath orig, GlobalEventManager self, DamageReport damageReport)
		{
			orig.Invoke(self, damageReport);
			killCount += 1f;
			if (killCount % KillFactor.Value != 0f)
			{
				return;
			}
			CharacterBody attackerBody = damageReport.attackerBody;
			if (Object.op_Implicit((Object)(object)attackerBody) && (attackerBody.isPlayerControlled || attackerBody.baseNameToken == "ENGITURRET_BODY_NAME"))
			{
				switch (ScalingStyle.Value)
				{
				case Scaling.Linear:
					Time.timeScale += TimeFactor.Value;
					break;
				case Scaling.Random:
					Time.timeScale = Random.Range(LowerBound.Value, UpperBound.Value);
					break;
				}
				PlayerCharacterMasterController._instances[0].master.voidCoins = (uint)(Time.timeScale * 100f);
			}
		}
	}
}