Decompiled source of MoreDashes v1.1.0

MoreDashes.dll

Decompiled a day ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using BoplFixedMath;
using HarmonyLib;
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("MoreDashes")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("MoreDashes")]
[assembly: AssemblyTitle("MoreDashes")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace MoreDashes;

[HarmonyPatch(typeof(AbilityGrid), "Awake")]
internal static class AbilityGrid_Awake_Patch
{
	private static bool _addedSuperDash;

	private static bool _addedMegaDash;

	private static bool _addedUpDash;

	private static bool TryGetAbility(NamedSpriteList abilityIcons, string abilityName, out NamedSprite ability)
	{
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0071: Unknown result type (might be due to invalid IL or missing references)
		ability = default(NamedSprite);
		if ((Object)(object)abilityIcons == (Object)null || abilityIcons.sprites == null)
		{
			return false;
		}
		int num = abilityIcons.sprites.FindIndex((NamedSprite sprite) => sprite.name != null && sprite.name.ToLower() == abilityName.ToLower());
		if (num < 0)
		{
			Plugin.Log.LogError((object)("Couldn't find " + abilityName + " in the ability list"));
			return false;
		}
		ability = abilityIcons.sprites[num];
		return true;
	}

	private static bool TryAddClone(NamedSpriteList abilityIcons, string templateName, string newName, string iconResourceName, Action<GameObject> modifyClone)
	{
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		//IL_008d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)abilityIcons == (Object)null || abilityIcons.sprites == null)
		{
			return false;
		}
		if (abilityIcons.sprites.Exists((NamedSprite sprite) => sprite.name != null && sprite.name.ToLower() == newName.ToLower()))
		{
			Plugin.Log.LogInfo((object)(newName + " is already in the list, skipping"));
			return true;
		}
		if (!TryGetAbility(abilityIcons, templateName, out var ability))
		{
			return false;
		}
		GameObject val = Object.Instantiate<GameObject>(ability.associatedGameObject);
		Object.DontDestroyOnLoad((Object)(object)val);
		((Object)val).name = newName;
		modifyClone?.Invoke(val);
		Sprite val2 = IconLoader.Load(iconResourceName, ability.sprite);
		abilityIcons.sprites.Add(new NamedSprite(newName, val2, val, ability.isOffensiveAbility));
		Plugin.Log.LogInfo((object)("Added " + newName + " (copied from " + ability.name + ")"));
		return true;
	}

	private static void AddSuperDash(NamedSpriteList abilityIcons)
	{
		if (TryAddClone(abilityIcons, "dash", "SuperDash", "MoreDashes.SuperDashIcon.png", delegate(GameObject abilityClone)
		{
			//IL_0012: 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_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: 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)
			//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_0063: Unknown result type (might be due to invalid IL or missing references)
			Dash component = abilityClone.GetComponent<Dash>();
			if ((Object)(object)component != (Object)null)
			{
				component.dashLength *= (Fix)2L;
				component.leaveSpeed *= (Fix)2L;
			}
			Ability component2 = abilityClone.GetComponent<Ability>();
			if ((Object)(object)component2 != (Object)null)
			{
				component2.Cooldown *= (Fix)2L;
			}
		}))
		{
			_addedSuperDash = true;
		}
	}

	private static void AddMegaDash(NamedSpriteList abilityIcons)
	{
		if (TryAddClone(abilityIcons, "dash", "MegaDash", "MoreDashes.MegaDashIcon.png", delegate(GameObject abilityClone)
		{
			//IL_0012: 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_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: 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)
			//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_0063: Unknown result type (might be due to invalid IL or missing references)
			Dash component = abilityClone.GetComponent<Dash>();
			if ((Object)(object)component != (Object)null)
			{
				component.dashLength *= (Fix)3L;
				component.leaveSpeed *= (Fix)3L;
			}
			Ability component2 = abilityClone.GetComponent<Ability>();
			if ((Object)(object)component2 != (Object)null)
			{
				component2.Cooldown *= (Fix)3L;
			}
		}))
		{
			_addedMegaDash = true;
		}
	}

	private static void AddUpDash(NamedSpriteList abilityIcons)
	{
		if (TryAddClone(abilityIcons, "dash", "UpDash", "MoreDashes.UpDashIcon.png", delegate(GameObject abilityClone)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: 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_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: 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_006c: Unknown result type (might be due to invalid IL or missing references)
			Dash component = abilityClone.GetComponent<Dash>();
			if ((Object)(object)component != (Object)null)
			{
				component.dashLength *= (Fix)0.5f;
				component.leaveSpeed *= (Fix)0.5f;
			}
			Ability component2 = abilityClone.GetComponent<Ability>();
			if ((Object)(object)component2 != (Object)null)
			{
				component2.Cooldown *= (Fix)0.5f;
			}
		}))
		{
			_addedUpDash = true;
		}
	}

	public static void Prefix(AbilityGrid __instance)
	{
		if (!_addedSuperDash)
		{
			AddSuperDash(__instance.abilityIcons);
		}
		if (!_addedMegaDash)
		{
			AddMegaDash(__instance.abilityIcons);
		}
		if (!_addedUpDash)
		{
			AddUpDash(__instance.abilityIcons);
		}
	}
}
[HarmonyPatch(typeof(Dash), "performDash")]
internal static class Dash_performDash_UpDash_Patch
{
	public static void Prefix(Dash __instance, ref Vec2 ___inputVector)
	{
		//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)
		if (((Object)((Component)__instance).gameObject).name.Contains("UpDash"))
		{
			___inputVector = Vec2.up;
		}
	}
}
internal static class Constants
{
	public const string ModVersion = "1.1.0";

	public const string ModAuthor = "Shayos";

	public const string ModName = "MoreDashes";

	public const string ModId = "com.Shayos.MoreDashes";

	public const string Banner = "+-----------------------------------------------------------------------------------------------------------+\n|                                                                                                           |\n|  ______________  _______________ __    __  _____________  __   ______  _________________________________  |\n|  ___  ____/_  / / /_  ____/__  //_/    _ \\/ /_  __ \\_  / / /   ___   |/  /__    |__  __ \\__  /___  ____/  |\n|  __  /_   _  / / /_  /    __  ,<       __  /_  / / /  / / /    __  /|_/ /__  /| |_  /_/ /_  / __  __/     |\n|  _  __/   / /_/ / / /___  _  /| |      _  / / /_/ // /_/ /     _  /  / / _  ___ |  ____/_  /___  /___     |\n|  /_/      \\____/  \\____/  /_/ |_|      /_/  \\____/ \\____/      /_/  /_/  /_/  |_/_/     /_____/_____/     |\n|                                                                                                           |\n+-----------------------------------------------------------------------------------------------------------+";
}
internal static class IconLoader
{
	public static Sprite Load(string resourceName, Sprite fallback)
	{
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		//IL_004d: Expected O, but got Unknown
		//IL_007f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0084: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
		using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName);
		if (stream == null)
		{
			Plugin.Log.LogError((object)("No embedded resource called " + resourceName));
			return fallback;
		}
		byte[] array = new byte[stream.Length];
		stream.Read(array, 0, array.Length);
		Texture2D val = new Texture2D(2, 2);
		if (!ImageConversion.LoadImage(val, array))
		{
			Plugin.Log.LogError((object)(resourceName + " isn't a valid PNG"));
			return fallback;
		}
		float num = fallback.pixelsPerUnit * (float)((Texture)val).width;
		Rect rect = fallback.rect;
		float num2 = num / ((Rect)(ref rect)).width;
		return Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f), num2);
	}
}
[BepInPlugin("com.Shayos.MoreDashes", "MoreDashes", "1.1.0")]
public class Plugin : BaseUnityPlugin
{
	internal static ManualLogSource Log;

	private void Awake()
	{
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		Log = ((BaseUnityPlugin)this).Logger;
		new Harmony("com.Shayos.MoreDashes").PatchAll();
		((BaseUnityPlugin)this).Logger.LogInfo((object)"\n+-----------------------------------------------------------------------------------------------------------+\n|                                                                                                           |\n|  ______________  _______________ __    __  _____________  __   ______  _________________________________  |\n|  ___  ____/_  / / /_  ____/__  //_/    _ \\/ /_  __ \\_  / / /   ___   |/  /__    |__  __ \\__  /___  ____/  |\n|  __  /_   _  / / /_  /    __  ,<       __  /_  / / /  / / /    __  /|_/ /__  /| |_  /_/ /_  / __  __/     |\n|  _  __/   / /_/ / / /___  _  /| |      _  / / /_/ // /_/ /     _  /  / / _  ___ |  ____/_  /___  /___     |\n|  /_/      \\____/  \\____/  /_/ |_|      /_/  \\____/ \\____/      /_/  /_/  /_/  |_/_/     /_____/_____/     |\n|                                                                                                           |\n+-----------------------------------------------------------------------------------------------------------+");
	}
}