Decompiled source of MrGruschSlow v1.0.0

BepInEx/plugins/MrGruschSlow.dll

Decompiled 3 weeks ago
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using Mirror;
using UnityEngine;
using UnityEngine.AI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("MisterGruschSlow")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("MisterGruschSlow")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("c194d419-b590-4fa8-9f80-cf22b249993f")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
[BepInPlugin("MisterGruschSlow", "Mister Grusch Slow", "1.0.0")]
public class MisterGruschSlow : BaseUnityPlugin
{
	public const string PluginGuid = "MisterGruschSlow";

	public const string PluginName = "Mister Grusch Slow";

	public const string PluginVersion = "1.0.0";

	internal const float SpeedMultiplier = 0.1f;

	private void Awake()
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		new Harmony("MisterGruschSlow").PatchAll();
	}
}
[HarmonyPatch(typeof(MisterGrusch))]
internal static class MisterGruschPatches
{
	private sealed class State
	{
		public bool SlowEnabled;
	}

	private static readonly ConditionalWeakTable<MisterGrusch, State> States = new ConditionalWeakTable<MisterGrusch, State>();

	[HarmonyPostfix]
	[HarmonyPatch("OnStartServer")]
	private static void OnStartServer_Postfix(MisterGrusch __instance)
	{
		if (!NetworkServer.active)
		{
			return;
		}
		float num = 0.1f;
		if (num <= 0f || Mathf.Approximately(num, 1f) || !__instance.isAMiniGrusch)
		{
			return;
		}
		NavMeshAgent component = ((Component)__instance).GetComponent<NavMeshAgent>();
		if (!((Object)(object)component == (Object)null))
		{
			State orCreateValue = States.GetOrCreateValue(__instance);
			if (!orCreateValue.SlowEnabled)
			{
				orCreateValue.SlowEnabled = true;
				component.speed *= num;
			}
		}
	}

	[HarmonyPrefix]
	[HarmonyPatch("HitsCheck")]
	private static void HitsCheck_Prefix(MisterGrusch __instance, out bool __state)
	{
		__state = false;
		if (!NetworkServer.active)
		{
			return;
		}
		float num = 0.1f;
		if (!(num <= 0f) && !Mathf.Approximately(num, 1f) && States.GetOrCreateValue(__instance).SlowEnabled)
		{
			NavMeshAgent component = ((Component)__instance).GetComponent<NavMeshAgent>();
			if (!((Object)(object)component == (Object)null))
			{
				component.speed /= num;
				__state = true;
			}
		}
	}

	[HarmonyPostfix]
	[HarmonyPatch("HitsCheck")]
	private static void HitsCheck_Postfix(MisterGrusch __instance, bool __state)
	{
		if (!NetworkServer.active)
		{
			return;
		}
		float num = 0.1f;
		if (num <= 0f || Mathf.Approximately(num, 1f))
		{
			return;
		}
		NavMeshAgent component = ((Component)__instance).GetComponent<NavMeshAgent>();
		if (!((Object)(object)component == (Object)null))
		{
			State orCreateValue = States.GetOrCreateValue(__instance);
			if (!orCreateValue.SlowEnabled)
			{
				orCreateValue.SlowEnabled = true;
				component.speed *= num;
			}
			else if (__state)
			{
				component.speed *= num;
			}
		}
	}
}