Decompiled source of VoidFiendTransformSpeed v1.6.1

VoidFiendTransformSpeed.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using EntityStates.VoidSurvivor.CorruptMode;
using HarmonyLib;
using RoR2;
using RoR2.ContentManagement;
using UnityEngine;
using UnityEngine.Networking;

[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace VoidFiendTransformSpeed;

[BepInPlugin("binma.voidfiend.transformspeed", "Void Fiend Transform Speed", "1.6.0")]
public class Plugin : BaseUnityPlugin
{
	public const string Guid = "binma.voidfiend.transformspeed";

	internal static ConfigEntry<float> Duration;

	internal static ConfigEntry<float> SpeedPercent;

	internal static ManualLogSource Log;

	internal static BuffDef SpeedBuff;

	private void Awake()
	{
		//IL_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_008a: Unknown result type (might be due to invalid IL or missing references)
		//IL_00be: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c8: Expected O, but got Unknown
		//IL_0108: Unknown result type (might be due to invalid IL or missing references)
		Log = ((BaseUnityPlugin)this).Logger;
		Duration = ((BaseUnityPlugin)this).Config.Bind<float>("General", "BoostDurationSeconds", 5f, "How long the speed boost lasts after Void Fiend enters corrupted form. Zero disables it.");
		SpeedPercent = ((BaseUnityPlugin)this).Config.Bind<float>("General", "BoostSpeedPercent", 160f, "Movement speed bonus during the boost, in percent.");
		SpeedBuff = ScriptableObject.CreateInstance<BuffDef>();
		((Object)SpeedBuff).name = "bdVoidFiendTransformSpeed";
		SpeedBuff.buffColor = new Color(0.95f, 0.12f, 0.12f, 1f);
		SpeedBuff.canStack = false;
		SpeedBuff.isDebuff = false;
		SpeedBuff.isHidden = false;
		ContentManager.collectContentPackProviders += (CollectContentPackProvidersDelegate)delegate(AddContentPackProviderDelegate add)
		{
			add.Invoke((IContentPackProvider)(object)new ContentProvider());
		};
		RoR2Application.onLoad = (Action)Delegate.Combine(RoR2Application.onLoad, (Action)delegate
		{
			if ((Object)(object)Buffs.CloakSpeed != (Object)null)
			{
				SpeedBuff.iconSprite = Buffs.CloakSpeed.iconSprite;
			}
		});
		new Harmony("binma.voidfiend.transformspeed").PatchAll(typeof(Plugin).Assembly);
	}
}
internal class ContentProvider : IContentPackProvider
{
	private readonly ContentPack pack = new ContentPack();

	public string identifier => "binma.voidfiend.transformspeed";

	public IEnumerator LoadStaticContentAsync(LoadStaticContentAsyncArgs args)
	{
		pack.buffDefs.Add((BuffDef[])(object)new BuffDef[1] { Plugin.SpeedBuff });
		args.ReportProgress(1f);
		yield break;
	}

	public IEnumerator GenerateContentPackAsync(GetContentPackAsyncArgs args)
	{
		ContentPack.Copy(pack, args.output);
		args.ReportProgress(1f);
		yield break;
	}

	public IEnumerator FinalizeAsync(FinalizeAsyncArgs args)
	{
		args.ReportProgress(1f);
		yield break;
	}
}
[HarmonyPatch(typeof(CorruptMode), "OnEnter")]
internal static class CorruptModeEnterPatch
{
	private static void Postfix(CorruptMode __instance)
	{
		try
		{
			if (!NetworkServer.active)
			{
				return;
			}
			float value = Plugin.Duration.Value;
			if (!(value <= 0f))
			{
				CharacterBody value2 = Traverse.Create((object)__instance).Property("characterBody", (object[])null).GetValue<CharacterBody>();
				if (!((Object)(object)value2 == (Object)null))
				{
					value2.AddTimedBuff(Plugin.SpeedBuff, value);
				}
			}
		}
		catch (Exception ex)
		{
			Plugin.Log.LogError((object)ex);
		}
	}
}
[HarmonyPatch(typeof(CharacterBody), "RecalculateStats")]
internal static class RecalculateStatsPatch
{
	private static readonly Action<CharacterBody, float> SetMoveSpeed = AccessTools.MethodDelegate<Action<CharacterBody, float>>(AccessTools.PropertySetter(typeof(CharacterBody), "moveSpeed"), (object)null, true);

	private static void Postfix(CharacterBody __instance)
	{
		try
		{
			if (__instance.HasBuff(Plugin.SpeedBuff))
			{
				float num = 1f + Plugin.SpeedPercent.Value / 100f;
				if (num > 0f)
				{
					SetMoveSpeed(__instance, __instance.moveSpeed * num);
				}
			}
		}
		catch (Exception ex)
		{
			Plugin.Log.LogError((object)ex);
		}
	}
}