Decompiled source of HuntressBuffULTIMATE v1.2.0

SprintPerfected.dll

Decompiled 3 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using EntityStates;
using IL.RoR2;
using JetBrains.Annotations;
using Mono.Cecil.Cil;
using MonoMod.Cil;
using On.RoR2.Skills;
using R2API;
using R2API.Utils;
using RoR2;
using RoR2.Skills;
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 = "")]
[assembly: AssemblyCompany("SprintPerfected")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("SprintPerfected")]
[assembly: AssemblyTitle("SprintPerfected")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace SprintPerfected;

[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInPlugin("com.Borbo.HuntressBuffULTIMATE", "HuntressBuffULTIMATE", "1.2.0")]
[R2APISubmoduleDependency(new string[] { "LanguageAPI" })]
public class SprintPerfectedPlugin : BaseUnityPlugin
{
	public static float drinkSpeedBonusBase = 0.35f;

	public static float drinkSpeedBonusStack = 0.35f;

	public static ConfigFile CustomConfigFile { get; set; }

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

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

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

	public void Awake()
	{
		InitializeConfig();
		if (NerfSprint.Value)
		{
			SprintNerf();
		}
		else
		{
			SprintBuff();
		}
	}

	private void InitializeConfig()
	{
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Expected O, but got Unknown
		CustomConfigFile = new ConfigFile(Paths.ConfigPath + "\\HuntressBuffULTIMATE.cfg", true);
		NerfSprint = CustomConfigFile.Bind<bool>("HUNTRESS BUFF ULTIMATE", "Should Sprint Be Nerfed or Buffed", true, "This determines whether HUNTRESS BUFF ULTIMATE should BUFF sprint, or nerf it. IF TRUE: All characters are unable to sprint during states that are non-agile and are not canceled by sprinting. IF FALSE: All skills are now Agile and are no longer canceled by sprinting.");
		EnergyDrinkBase = CustomConfigFile.Bind<float>("Sprint Nerf", "Energy Drink BASE Speed Bonus", drinkSpeedBonusBase * 100f, "How much bonus speed Energy Drink should grant while sprinting, on the first stack. Vanilla is 25.");
		EnergyDrinkStack = CustomConfigFile.Bind<float>("Sprint Nerf", "Energy Drink STACK Speed Bonus", drinkSpeedBonusStack * 100f, "How much bonus speed Energy Drink should grant while sprinting, on every stack past the first. Vanilla is 25.");
	}

	private void SprintBuff()
	{
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Expected O, but got Unknown
		Debug.Log((object)"You chose Sprint Buff! Based and shoepilled!");
		SkillCatalog.SetSkillDefs += new hook_SetSkillDefs(MakeEverythingAgile);
	}

	private void MakeEverythingAgile(orig_SetSkillDefs orig, SkillDef[] newSkillDefs)
	{
		foreach (SkillDef val in newSkillDefs)
		{
			if (!((Object)(object)val != (Object)null) || val.canceledFromSprinting)
			{
				continue;
			}
			bool flag = false;
			if (val.keywordTokens == null || val.keywordTokens.Length == 0)
			{
				flag = true;
			}
			if (!flag)
			{
				string[] keywordTokens = val.keywordTokens;
				foreach (string text in keywordTokens)
				{
					if (text == "KEYWORD_AGILE")
					{
						flag = true;
						break;
					}
				}
			}
			if (flag)
			{
				string skillDescriptionToken = val.skillDescriptionToken;
				string @string = Language.GetString(skillDescriptionToken, "EN");
				if (skillDescriptionToken != @string && !@string.Contains("Agile"))
				{
					LanguageAPI.AddOverlay(skillDescriptionToken, "<style=cIsUtility>Agile</style>. " + @string);
				}
				string text2 = "KEYWORD_AGILE";
				if (val.keywordTokens == null || val.keywordTokens.Length == 0)
				{
					val.keywordTokens = new string[1] { text2 };
				}
				else
				{
					HGArrayUtilities.ArrayAppend<string>(ref val.keywordTokens, ref text2);
				}
				val.cancelSprintingOnActivation = false;
			}
		}
		orig.Invoke(newSkillDefs);
	}

	private void SprintNerf()
	{
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Expected O, but got Unknown
		//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c5: Expected O, but got Unknown
		Debug.Log((object)"You chose Sprint Nerf! Based and shoepilled!");
		SkillDef.OnFixedUpdate += new hook_OnFixedUpdate(SkillDefFixedUpdate);
		SkillDef val = Resources.Load<SkillDef>("skilldefs/crocobody/CrocoPassivePoison");
		SkillDef val2 = Resources.Load<SkillDef>("skilldefs/crocobody/CrocoPassiveBlight");
		val.cancelSprintingOnActivation = false;
		val2.cancelSprintingOnActivation = false;
		LanguageAPI.Add("ITEM_SPRINTBONUS_DESC", "<style=cIsUtility>Sprint speed</style> is improved by <style=cIsUtility>" + Tools.ConvertDecimal(drinkSpeedBonusBase) + "</style> <style=cStack>(+" + Tools.ConvertDecimal(drinkSpeedBonusStack) + " per stack)</style>.");
		drinkSpeedBonusBase = EnergyDrinkBase.Value / 100f;
		drinkSpeedBonusStack = EnergyDrinkStack.Value / 100f;
		CharacterBody.RecalculateStats += new Manipulator(DrinkBuff);
	}

	private void DrinkBuff(ILContext il)
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_000e: Expected O, but got Unknown
		ILCursor val = new ILCursor(il);
		int countLoc = -1;
		val.GotoNext((MoveType)2, new Func<Instruction, bool>[3]
		{
			(Instruction x) => ILPatternMatchingExt.MatchLdsfld(x, "RoR2.RoR2Content/Items", "SprintBonus"),
			(Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt<Inventory>(x, "GetItemCount"),
			(Instruction x) => ILPatternMatchingExt.MatchStloc(x, ref countLoc)
		});
		float num = default(float);
		val.GotoNext((MoveType)2, new Func<Instruction, bool>[3]
		{
			(Instruction x) => ILPatternMatchingExt.MatchLdcR4(x, ref num),
			(Instruction x) => ILPatternMatchingExt.MatchLdloc(x, countLoc),
			(Instruction x) => ILPatternMatchingExt.MatchConvR4(x)
		});
		val.EmitDelegate<Func<float, float, float>>((Func<float, float, float>)delegate(float speedBonus, float itemCount)
		{
			float result = 0f;
			if (itemCount > 0f)
			{
				result = drinkSpeedBonusBase + drinkSpeedBonusStack * (itemCount - 1f);
			}
			return result;
		});
		val.Remove();
	}

	private void SkillDefFixedUpdate(orig_OnFixedUpdate orig, SkillDef self, [NotNull] GenericSkill skillSlot, float deltaTime)
	{
		if ((Object)(object)skillSlot.stateMachine == (Object)null)
		{
			orig.Invoke(self, skillSlot, deltaTime);
			return;
		}
		skillSlot.RunRecharge(Time.deltaTime);
		if (((object)skillSlot.stateMachine.state)?.GetType() == ((SerializableEntityStateType)(ref self.activationState)).stateType)
		{
			if (self.canceledFromSprinting && skillSlot.characterBody.isSprinting)
			{
				skillSlot.stateMachine.SetNextStateToMain();
			}
			else if (self.forceSprintDuringState)
			{
				skillSlot.characterBody.isSprinting = true;
			}
			else if (self.cancelSprintingOnActivation)
			{
				skillSlot.characterBody.isSprinting = false;
			}
		}
	}
}
public static class Tools
{
	public static string modPrefix = string.Format("@{0}+{1}", "ArtificerExtended", "artiskillicons");

	public static AssetBundle LoadAssetBundle(byte[] resourceBytes)
	{
		if (resourceBytes == null)
		{
			throw new ArgumentNullException("resourceBytes");
		}
		return AssetBundle.LoadFromMemory(resourceBytes);
	}

	public static string GetModPrefix(this BaseUnityPlugin plugin, string bundleName)
	{
		return $"@{plugin.Info.Metadata.Name}+{bundleName}";
	}

	internal static bool isLoaded(string modguid)
	{
		foreach (KeyValuePair<string, PluginInfo> pluginInfo in Chainloader.PluginInfos)
		{
			string key = pluginInfo.Key;
			PluginInfo value = pluginInfo.Value;
			if (key == modguid)
			{
				return true;
			}
		}
		return false;
	}

	internal static string ConvertDecimal(float d)
	{
		return d * 100f + "%";
	}

	internal static void GetMaterial(GameObject model, string childObject, Color color, ref Material material, float scaleMultiplier = 1f, bool replaceAll = false)
	{
		//IL_0030: 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_00aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b1: 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_006a: Expected O, but got Unknown
		//IL_0092: Unknown result type (might be due to invalid IL or missing references)
		Renderer[] componentsInChildren = model.GetComponentsInChildren<Renderer>();
		Renderer[] array = componentsInChildren;
		foreach (Renderer val in array)
		{
			Renderer val2 = val;
			if (string.Equals(((Object)val).name, childObject))
			{
				if (color == Color.clear)
				{
					Object.Destroy((Object)(object)val);
					break;
				}
				if ((Object)(object)material == (Object)null)
				{
					material = new Material(val.material);
					material.mainTexture = val.material.mainTexture;
					material.shader = val.material.shader;
					material.color = color;
				}
				val.material = material;
				Transform transform = ((Component)val).transform;
				transform.localScale *= scaleMultiplier;
				if (!replaceAll)
				{
					break;
				}
			}
		}
	}

	internal static void DebugMaterial(GameObject model)
	{
		Renderer[] componentsInChildren = model.GetComponentsInChildren<Renderer>();
		Renderer[] array = componentsInChildren;
		foreach (Renderer val in array)
		{
			Renderer val2 = val;
			Debug.Log((object)("Material: " + ((Object)val2).name.ToString()));
		}
	}

	internal static void GetParticle(GameObject model, string childObject, Color color, float sizeMultiplier = 1f, bool replaceAll = false)
	{
		//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_0025: 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_002e: 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_004b: Unknown result type (might be due to invalid IL or missing references)
		//IL_004c: 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_006a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0077: Unknown result type (might be due to invalid IL or missing references)
		//IL_0078: Unknown result type (might be due to invalid IL or missing references)
		ParticleSystem[] componentsInChildren = model.GetComponentsInChildren<ParticleSystem>();
		ParticleSystem[] array = componentsInChildren;
		foreach (ParticleSystem val in array)
		{
			ParticleSystem val2 = val;
			MainModule main = val2.main;
			ColorOverLifetimeModule colorOverLifetime = val2.colorOverLifetime;
			ColorBySpeedModule colorBySpeed = val2.colorBySpeed;
			if (string.Equals(((Object)val2).name, childObject))
			{
				((MainModule)(ref main)).startColor = MinMaxGradient.op_Implicit(color);
				((MainModule)(ref main)).startSizeMultiplier = ((MainModule)(ref main)).startSizeMultiplier * sizeMultiplier;
				((ColorOverLifetimeModule)(ref colorOverLifetime)).color = MinMaxGradient.op_Implicit(color);
				((ColorBySpeedModule)(ref colorBySpeed)).color = MinMaxGradient.op_Implicit(color);
				if (!replaceAll)
				{
					break;
				}
			}
		}
	}

	internal static void DebugParticleSystem(GameObject model)
	{
		ParticleSystem[] components = model.GetComponents<ParticleSystem>();
		ParticleSystem[] array = components;
		foreach (ParticleSystem val in array)
		{
			ParticleSystem val2 = val;
			Debug.Log((object)("Particle: " + ((Object)val2).name.ToString()));
		}
	}

	internal static void GetLight(GameObject model, string childObject, Color color, bool replaceAll = false)
	{
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		Light[] componentsInChildren = model.GetComponentsInChildren<Light>();
		Light[] array = componentsInChildren;
		foreach (Light val in array)
		{
			Light val2 = val;
			if (string.Equals(((Object)val2).name, childObject))
			{
				val2.color = color;
				if (!replaceAll)
				{
					break;
				}
			}
		}
	}

	internal static void DebugLight(GameObject model)
	{
		Light[] componentsInChildren = model.GetComponentsInChildren<Light>();
		Light[] array = componentsInChildren;
		foreach (Light val in array)
		{
			Light val2 = val;
			Debug.Log((object)("Light: " + ((Object)val2).name.ToString()));
		}
	}
}