Decompiled source of DrifterSprintFix v1.3.0

DrifterSprintFix.dll

Decompiled 3 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using EntityStates;
using RoR2.Skills;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace DrifterSprintFix;

[BepInPlugin("com.dsh.driftersprintfix", "Drifter Sprint Fix", "1.3.0")]
public class DrifterSprintFixPlugin : BaseUnityPlugin
{
	private static readonly string[] Targets = new string[5] { "Repossess", "TornadoSlam", "EmptyBag", "AimMagicBag", "MagicBag" };

	private readonly HashSet<int> seen = new HashSet<int>();

	private void Awake()
	{
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Drifter Sprint Fix v1.3.0 loaded");
		((MonoBehaviour)this).StartCoroutine(ScanLoop());
	}

	private static string GetStateTypeName(SkillDef d)
	{
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		string text = "";
		try
		{
			Type stateType = ((SerializableEntityStateType)(ref d.activationState)).stateType;
			if (stateType != null)
			{
				text = stateType.Name;
			}
		}
		catch
		{
		}
		if (string.IsNullOrEmpty(text))
		{
			try
			{
				object obj2 = d.activationState;
				FieldInfo field = obj2.GetType().GetField("_typeName", BindingFlags.Instance | BindingFlags.NonPublic);
				if (field != null)
				{
					text = ((string)field.GetValue(obj2)) ?? "";
				}
			}
			catch
			{
			}
		}
		return text;
	}

	private static bool IsTarget(string typeName, string skillName)
	{
		for (int i = 0; i < Targets.Length; i++)
		{
			string value = Targets[i];
			if (!string.IsNullOrEmpty(typeName) && typeName.IndexOf(value, StringComparison.OrdinalIgnoreCase) >= 0)
			{
				return true;
			}
			if (!string.IsNullOrEmpty(skillName) && skillName.IndexOf(value, StringComparison.OrdinalIgnoreCase) >= 0)
			{
				return true;
			}
		}
		return false;
	}

	private IEnumerator ScanLoop()
	{
		int total = 0;
		for (float waited = 0f; waited < 40f; waited += 1f)
		{
			SkillDef[] defs = Resources.FindObjectsOfTypeAll<SkillDef>();
			if (defs != null)
			{
				foreach (SkillDef val in defs)
				{
					if ((Object)(object)val == (Object)null)
					{
						continue;
					}
					string stateTypeName = GetStateTypeName(val);
					if (IsTarget(stateTypeName, val.skillName))
					{
						int instanceID = ((Object)val).GetInstanceID();
						bool flag = !seen.Contains(instanceID);
						bool flag2 = false;
						if (val.canceledFromSprinting)
						{
							val.canceledFromSprinting = false;
							flag2 = true;
						}
						if (val.cancelSprintingOnActivation)
						{
							val.cancelSprintingOnActivation = false;
							flag2 = true;
						}
						if (flag)
						{
							seen.Add(instanceID);
							total++;
							((BaseUnityPlugin)this).Logger.LogInfo((object)("match: skillName=" + val.skillName + " state=" + stateTypeName + " changed=" + flag2));
						}
					}
				}
			}
			yield return (object)new WaitForSeconds(1f);
		}
		((BaseUnityPlugin)this).Logger.LogInfo((object)("Drifter Sprint Fix scan finished: " + total + " skill def(s) handled"));
	}
}