Decompiled source of SillyDeltaTime v1.0.0

SillyDeltaTime.dll

Decompiled 4 months ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using IL.RoR2.CharacterAI;
using IL.RoR2.Skills;
using Microsoft.CodeAnalysis;
using Mono.Cecil.Cil;
using MonoMod.Cil;
using RiskOfOptions;
using RiskOfOptions.OptionConfigs;
using RiskOfOptions.Options;
using RoR2;
using RoR2.Skills;
using SillyDeltaTime;
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.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("SillyDeltaTime")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+aa8ef4b1ba8bc68b7f54a8cfede973c12ee1b1ea")]
[assembly: AssemblyProduct("SillyDeltaTime")]
[assembly: AssemblyTitle("SillyDeltaTime")]
[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;
		}
	}
}
internal static class Configuration
{
	private static bool loadedIcon;

	public static ConfigEntry<T> BindAndOptions<T>(string section, string name, T defaultValue, string description = "", bool restartRequired = false)
	{
		return BindAndOptions(section, name, defaultValue, 0f, 20f, description, restartRequired);
	}

	public static ConfigEntry<T> BindAndOptions<T>(string section, string name, T defaultValue, float min, float max, string description = "", bool restartRequired = false)
	{
		if (string.IsNullOrEmpty(description))
		{
			description = name;
		}
		description += $"\nDefault: {defaultValue}";
		if (restartRequired)
		{
			description += " (restart required)";
		}
		ConfigEntry<T> val = ((BaseUnityPlugin)SillyDeltaTimePlugin.instance).Config.Bind<T>(section, name, defaultValue, description);
		if (Chainloader.PluginInfos.ContainsKey("com.rune580.riskofoptions"))
		{
			TryRegisterOption<T>(val, min, max, restartRequired);
		}
		return val;
	}

	public static ConfigEntry<float> BindAndOptionsSlider(string section, string name, float defaultValue, string description, float min = 0f, float max = 20f, bool restartRequired = false)
	{
		return BindAndOptions(section, name, defaultValue, min, max, description, restartRequired);
	}

	[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
	private static void TryRegisterOption<T>(ConfigEntry<T> entry, float min, float max, bool restartRequired)
	{
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: 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_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Expected O, but got Unknown
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Expected O, but got Unknown
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0067: 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_0076: Unknown result type (might be due to invalid IL or missing references)
		//IL_0080: Expected O, but got Unknown
		//IL_0097: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a1: Expected O, but got Unknown
		//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c2: Expected O, but got Unknown
		if (entry is ConfigEntry<float>)
		{
			ModSettingsManager.AddOption((BaseOption)new SliderOption(entry as ConfigEntry<float>, new SliderConfig
			{
				min = min,
				max = max,
				formatString = "{0:0.00}",
				restartRequired = restartRequired
			}));
		}
		if (entry is ConfigEntry<int>)
		{
			ModSettingsManager.AddOption((BaseOption)new IntSliderOption(entry as ConfigEntry<int>, new IntSliderConfig
			{
				min = (int)min,
				max = (int)max,
				restartRequired = restartRequired
			}));
		}
		if (entry is ConfigEntry<bool>)
		{
			ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(entry as ConfigEntry<bool>, restartRequired));
		}
		if (entry is ConfigEntry<KeyboardShortcut>)
		{
			ModSettingsManager.AddOption((BaseOption)new KeyBindOption(entry as ConfigEntry<KeyboardShortcut>, restartRequired));
		}
		if (!loadedIcon)
		{
			loadedIcon = true;
			try
			{
				ModSettingsManager.SetModIcon(LoadSpriteFromModFolder("icon.png"));
			}
			catch (Exception ex)
			{
				Debug.LogError((object)("error adding ROO mod icon for aliem\n" + ex));
			}
		}
	}

	public static bool GetKeyPressed(ConfigEntry<KeyboardShortcut> entry)
	{
		//IL_0003: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: Unknown result type (might be due to invalid IL or missing references)
		//IL_004f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: Unknown result type (might be due to invalid IL or missing references)
		KeyboardShortcut value = entry.Value;
		foreach (KeyCode modifier in ((KeyboardShortcut)(ref value)).Modifiers)
		{
			if (!Input.GetKey(modifier))
			{
				return false;
			}
		}
		value = entry.Value;
		return Input.GetKeyDown(((KeyboardShortcut)(ref value)).MainKey);
	}

	public static void ConfigureBody(CharacterBody bodyComponent, string section, string bodyInfoTitle = "")
	{
		if (string.IsNullOrEmpty(bodyInfoTitle))
		{
			bodyInfoTitle = ((Object)bodyComponent).name;
		}
		bodyComponent.baseMaxHealth = BindAndOptions(section, bodyInfoTitle + " Base Max Health", bodyComponent.baseMaxHealth, 0f, 1000f, "levelMaxHealth will be adjusted accordingly (baseMaxHealth * 0.3)", restartRequired: true).Value;
		bodyComponent.levelMaxHealth = Mathf.Round(bodyComponent.baseMaxHealth * 0.3f);
		bodyComponent.baseRegen = BindAndOptions(section, bodyInfoTitle + " Base Regen", bodyComponent.baseRegen, "levelRegen will be adjusted accordingly (baseRegen * 0.2)", restartRequired: true).Value;
		bodyComponent.levelRegen = bodyComponent.baseRegen * 0.2f;
		bodyComponent.baseArmor = BindAndOptions(section, bodyInfoTitle + " Armor", bodyComponent.baseArmor, "", restartRequired: true).Value;
		bodyComponent.baseDamage = BindAndOptions(section, bodyInfoTitle + " Base Damage", bodyComponent.baseDamage, "pretty much all survivors are 12. If you want to change damage, change damage of the moves instead.\nlevelDamage will be adjusted accordingly (baseDamage * 0.2)", restartRequired: true).Value;
		bodyComponent.levelDamage = bodyComponent.baseDamage * 0.2f;
		bodyComponent.baseJumpCount = BindAndOptions(section, bodyInfoTitle + " Jump Count", bodyComponent.baseJumpCount, "", restartRequired: true).Value;
	}

	public static void ConfigureSkillDef(SkillDef skillDef, string section, string skillTitle, bool cooldown = true, bool maxStock = true, bool rechargeStock = false)
	{
		if (cooldown)
		{
			skillDef.baseRechargeInterval = BindAndOptions(section, skillTitle + " cooldown", skillDef.baseRechargeInterval, 0f, 20f, "", restartRequired: true).Value;
		}
		if (maxStock)
		{
			skillDef.baseMaxStock = BindAndOptions(section, skillTitle + " stocks", skillDef.baseMaxStock, 0f, 100f, "", restartRequired: true).Value;
		}
		if (rechargeStock)
		{
			skillDef.rechargeStock = BindAndOptions(section, skillTitle + " recharge stocks", skillDef.baseMaxStock, 0f, 100f, "", restartRequired: true).Value;
		}
	}

	internal static Sprite LoadSpriteFromModFolder(string fileName, bool pointFilter = false)
	{
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Expected O, but got Unknown
		//IL_0097: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
		string path = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)SillyDeltaTimePlugin.instance).Info.Location), fileName);
		Texture2D val = new Texture2D(2, 2);
		byte[] array = File.ReadAllBytes(path);
		ImageConversion.LoadImage(val, array);
		((Texture)val).filterMode = (FilterMode)((!pointFilter) ? 1 : 0);
		val.Apply();
		if (pointFilter)
		{
			((Texture)val).filterMode = (FilterMode)0;
			val.Apply();
		}
		((Object)val).name = fileName;
		((Texture)val).filterMode = (FilterMode)0;
		val.Apply();
		Rect val2 = default(Rect);
		((Rect)(ref val2))..ctor(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height);
		Sprite val3 = Sprite.Create(val, val2, new Vector2(0.5f, 0.5f), 16f);
		((Object)val3).name = fileName;
		return val3;
	}
}
namespace SillyDeltaTime
{
	[BepInPlugin("com.TheTimeSweeper.SillyDeltaTime", "Silly deltaTime", "1.0.0")]
	public class SillyDeltaTimePlugin : BaseUnityPlugin
	{
		public static SillyDeltaTimePlugin instance;

		private void Awake()
		{
			instance = this;
			ConfigureHook("SteppedSkillDef StepGrace", "affects how fast combos reset if not held. very minor", bydefault: true, delegate
			{
				//IL_0008: Unknown result type (might be due to invalid IL or missing references)
				//IL_0012: Expected O, but got Unknown
				SteppedSkillDef.OnFixedUpdate += new Manipulator(SwapTime);
			});
			ConfigureHook("MercDash Reset Timer", "fixes merc dash time until re-dashing dependent on frames", bydefault: true, delegate
			{
				//IL_0008: Unknown result type (might be due to invalid IL or missing references)
				//IL_0012: Expected O, but got Unknown
				MercDashSkillDef.OnFixedUpdate += new Manipulator(SwapTime);
			});
			ConfigureHook("ReloadSkillDef graceTime", "affects time it takes for reload skills (bandit) to happen", bydefault: true, delegate
			{
				//IL_0008: Unknown result type (might be due to invalid IL or missing references)
				//IL_0012: Expected O, but got Unknown
				ReloadSkillDef.OnFixedUpdate += new Manipulator(SwapTime);
			});
			ConfigureHook("Character AI", "not sure what this effects but it has the same code issue as the others. untested so disable by default. if someone can verify this is good let me know", bydefault: false, delegate
			{
				//IL_0008: Unknown result type (might be due to invalid IL or missing references)
				//IL_0012: Expected O, but got Unknown
				//IL_001a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0024: Expected O, but got Unknown
				BaseAI.ManagedFixedUpdate += new Manipulator(SwapTime);
				BaseAI.UpdateBodyAim += new Manipulator(SwapTime);
			});
		}

		private static void SwapTime(ILContext il)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Expected O, but got Unknown
			ILCursor val = new ILCursor(il);
			val.GotoNext((MoveType)2, new Func<Instruction, bool>[1]
			{
				(Instruction instruction) => ILPatternMatchingExt.MatchCall<Time>(instruction, "get_fixedDeltaTime")
			});
			val.EmitDelegate<Func<float, float>>((Func<float, float>)((float toime) => Time.deltaTime));
		}

		public void ConfigureHook(string hookName, string description, bool bydefault, Action performHook)
		{
			ConfigEntry<bool> val = Configuration.BindAndOptions("NEVA GIV UP", hookName, bydefault, description, restartRequired: true);
			if (val.Value)
			{
				performHook();
			}
		}
	}
}