Decompiled source of HeartAttack v1.0.1

HeartAttack.dll

Decompiled a month ago
using System.Collections;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using HeartAttack.Patches;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("HeartAttack")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("HeartAttack")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("f58e7f15-ddcf-41ab-a659-59dc598c291f")]
[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")]
namespace HeartAttack
{
	[BepInPlugin("Nono.HeartAttackMod", "Heart Attack", "1.0.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		private const string modGUID = "Nono.HeartAttackMod";

		private const string modName = "Heart Attack";

		private const string modVersion = "1.0.0.0";

		private readonly Harmony harmony = new Harmony("Nono.HeartAttackMod");

		private static Plugin Instance;

		internal static ManualLogSource Logger;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			Logger = ((BaseUnityPlugin)this).Logger;
			Logger.LogInfo((object)"OH MY LORD!");
			harmony.PatchAll(typeof(Plugin));
			harmony.PatchAll(typeof(PlayerControllerBPatch));
		}
	}
}
namespace HeartAttack.Patches
{
	[HarmonyPatch(typeof(PlayerControllerB))]
	internal class PlayerControllerBPatch
	{
		private static bool hasHeartAttackOccurred;

		private static bool hasFearAttackOccurred;

		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		private static void heartAttack(PlayerControllerB __instance)
		{
			if (!((Object)(object)__instance == (Object)(object)GameNetworkManager.Instance.localPlayerController))
			{
				return;
			}
			int num = StartOfRound.Instance.allPlayerScripts.Where((PlayerControllerB x) => x.isPlayerControlled).Count();
			if (num > 1)
			{
				if (StartOfRound.Instance.fearLevel > 0.5f)
				{
					if (!hasHeartAttackOccurred && !__instance.isPlayerAlone)
					{
						triggerHeartAttack(__instance);
					}
					else if (!hasFearAttackOccurred)
					{
						tremblingFear(__instance);
					}
				}
				else if (StartOfRound.Instance.fearLevel < 0.5f)
				{
					hasHeartAttackOccurred = false;
					hasFearAttackOccurred = false;
				}
			}
			else if (StartOfRound.Instance.fearLevel > 0.5f)
			{
				if (!hasHeartAttackOccurred)
				{
					triggerHeartAttack(__instance);
				}
				else if (!hasFearAttackOccurred)
				{
					tremblingFear(__instance);
				}
			}
			else if (StartOfRound.Instance.fearLevel < 0.5f)
			{
				hasHeartAttackOccurred = false;
				hasFearAttackOccurred = false;
			}
		}

		private static void triggerHeartAttack(PlayerControllerB player)
		{
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			float num = Random.Range(0f, 100f);
			float num2 = 10f;
			Plugin.Logger.LogDebug((object)$"Heart Attack Value: {num}");
			if (num <= num2)
			{
				player.KillPlayer(Vector3.zero, true, (CauseOfDeath)0, 0, Vector3.zero);
				Plugin.Logger.LogDebug((object)"HEART ATTACK");
			}
			hasHeartAttackOccurred = true;
		}

		private static void tremblingFear(PlayerControllerB player)
		{
			float num = Random.Range(0f, 100f);
			float num2 = 13f;
			Plugin.Logger.LogDebug((object)$"Fear Value: {num}");
			if (num <= num2)
			{
				((MonoBehaviour)player).StartCoroutine(applyTheFear(player));
				Plugin.Logger.LogDebug((object)"FEAR!");
			}
			hasFearAttackOccurred = true;
		}

		private static IEnumerator applyTheFear(PlayerControllerB player)
		{
			float originalMovementSpeed = player.movementSpeed;
			float originalClimbSpeed = player.climbSpeed;
			_ = player.lookSensitivity;
			player.movementSpeed = 0.35f;
			player.climbSpeed = 2f;
			HUDManager.Instance.ShakeCamera((ScreenShakeType)1);
			yield return (object)new WaitForSeconds(2.5f);
			player.movementSpeed = originalMovementSpeed;
			player.climbSpeed = originalClimbSpeed;
		}
	}
}