Decompiled source of WaterRoll v2.0.0

WaterRoll.dll

Decompiled 4 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BoplFixedMath;
using HarmonyLib;
using Microsoft.CodeAnalysis;
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(".NETFramework,Version=v4.6", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("WaterRoll")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("My first plugin")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("WaterRoll")]
[assembly: AssemblyTitle("WaterRoll")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace WaterRoll
{
	[BepInPlugin("com.maxgamertyper1.waterroll", "Water Roll", "2.0.0")]
	public class WaterRoll : BaseUnityPlugin
	{
		internal static ConfigFile config;

		internal static ConfigEntry<bool> WaterBoost;

		internal static ConfigEntry<bool> AntiStalemate;

		internal static ConfigEntry<float> StalemateTime;

		private void Log(string message)
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)message);
		}

		private void Awake()
		{
			Log("Plugin WaterRoll is loaded!");
			DoPatching();
		}

		private void DoPatching()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			Harmony harmony = new Harmony("com.maxgamertyper1.waterroll");
			config = ((BaseUnityPlugin)this).Config;
			WaterBoost = config.Bind<bool>("General", "Water Boost", true, "if the roll ends in the water, it will boost you out");
			AntiStalemate = config.Bind<bool>("Stalemate", "AntiStalemate", true, "if the player is stuck in the water for x (Stalemate Time) amount of time, they will die");
			StalemateTime = config.Bind<float>("Stalemate", "Stalemate Time", 20f, "The amount of time before the player is killed from AntiStalemate");
			Patches.AntiStalemate = AntiStalemate.Value;
			Patches.StalemateTime = StalemateTime.Value;
			Patch(harmony, typeof(Roll), "ReleaseDash", "RollStarted", prefix: false);
			Patch(harmony, typeof(Roll), "OnDisable", "RollEnded", prefix: false);
			if (WaterBoost.Value)
			{
				Patch(harmony, typeof(Roll), "ExitAbility", "RollExit", prefix: true);
			}
		}

		private void OnDestroy()
		{
			Log("Bye Bye From WaterRoll");
		}

		private void Patch(Harmony harmony, Type OriginalClass, string OriginalMethod, string PatchMethod, bool prefix)
		{
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Expected O, but got Unknown
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Expected O, but got Unknown
			MethodInfo methodInfo = AccessTools.Method(OriginalClass, OriginalMethod, (Type[])null, (Type[])null);
			MethodInfo methodInfo2 = AccessTools.Method(typeof(Patches), PatchMethod, (Type[])null, (Type[])null);
			if (prefix)
			{
				harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(methodInfo2), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			}
			else
			{
				harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(methodInfo2), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			}
			Log("Patched " + OriginalMethod + " in " + OriginalClass.ToString());
		}

		private void Update()
		{
			Patches.Update();
		}
	}
	public class Patches
	{
		private static Dictionary<int, float> PlayerData = new Dictionary<int, float>();

		public static bool AntiStalemate;

		public static float StalemateTime;

		public static void RollStarted(ref Roll __instance)
		{
			DestroyIfOutsideSceneBounds component = ((Component)__instance).GetComponent<DestroyIfOutsideSceneBounds>();
			((Behaviour)component).enabled = false;
			if (AntiStalemate)
			{
				try
				{
					PlayerData[__instance.player.Id] = 0f;
				}
				catch
				{
				}
			}
		}

		public static void RollEnded(ref Roll __instance)
		{
			DestroyIfOutsideSceneBounds component = ((Component)__instance).GetComponent<DestroyIfOutsideSceneBounds>();
			((Behaviour)component).enabled = true;
			if (AntiStalemate)
			{
				try
				{
					PlayerData.Remove(__instance.player.Id);
				}
				catch
				{
				}
			}
		}

		public static void Update()
		{
			List<int> list = new List<int>(PlayerData.Keys);
			foreach (int item in list)
			{
				try
				{
					int key = item;
					float num = PlayerData[item];
					num += Time.deltaTime;
					PlayerData[key] = num;
				}
				catch
				{
				}
			}
		}

		public static bool RollExit(ref Roll __instance)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			Fix y = __instance.player.Position.y;
			if (y < SceneBounds.WaterHeight && __instance.dashTime < __instance.timeSinceRelease)
			{
				foreach (KeyValuePair<int, float> playerDatum in PlayerData)
				{
					int key = playerDatum.Key;
					float value = playerDatum.Value;
					if (value >= StalemateTime && key == __instance.player.Id)
					{
						return true;
					}
				}
				__instance.timeSinceRelease -= (Fix)0.25f;
				return false;
			}
			return true;
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "WaterRoll";

		public const string PLUGIN_NAME = "WaterRoll";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}