Decompiled source of ToiletRoulette v1.0.0

ToiletRoulette.dll

Decompiled a day ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Threading.Tasks;
using BepInEx;
using BepInEx.Logging;
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(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("")]
[assembly: AssemblyCompany("DarkSnakeX")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ToiletRoulette")]
[assembly: AssemblyTitle("ToiletRoulette")]
[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.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[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 ToiletRoulette
{
	[HarmonyPatch(typeof(ToiletFun))]
	internal static class ToiletFunPatch
	{
		private static PlayerAvatar? lastPlayerWhoFlushed;

		private static float lastFlushTime = 0f;

		private static float flushInterval = 5f;

		[HarmonyPostfix]
		[HarmonyPatch("FlushStartRPC")]
		private static void FlushStartRPC_Postfix(ToiletFun __instance)
		{
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: 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)
			if (!(Time.time - lastFlushTime > flushInterval))
			{
				return;
			}
			ToiletRoulette.Logger.LogInfo((object)"The toilet has been flushed. Good luck!");
			lastFlushTime = Time.time;
			foreach (PhysGrabObject physGrabObject in __instance.physGrabObjects)
			{
				if (!((Object)(object)physGrabObject != (Object)null))
				{
					continue;
				}
				PlayerDeathHead component = ((Component)physGrabObject).GetComponent<PlayerDeathHead>();
				if ((Object)(object)component != (Object)null)
				{
					ToiletRoulette.Logger.LogInfo((object)("The head has been detected: " + ((Object)component).name));
					if (Random.value < 0.5f)
					{
						DelayedRevive(component, ((Component)__instance).transform.position + Vector3.up * 2f);
					}
					else
					{
						DelayedKill();
					}
				}
			}
		}

		private static async void DelayedKill()
		{
			await Task.Delay(3000);
			KillPlayer();
		}

		private static async void DelayedRevive(PlayerDeathHead head, Vector3 revivePosition)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			await Task.Delay(3000);
			ReviveSpecificPlayer(head, revivePosition);
		}

		[HarmonyPrefix]
		[HarmonyPatch("Flush")]
		private static void Flush_Prefix(ToiletFun __instance)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			lastPlayerWhoFlushed = FindNearestPlayer(((Component)__instance).transform.position);
			if ((Object)(object)lastPlayerWhoFlushed != (Object)null)
			{
				lastPlayerWhoFlushed.ChatMessageSpeak("LET'S GO GAMBLING!", false);
				ToiletRoulette.Logger.LogInfo((object)("Player " + ((Object)lastPlayerWhoFlushed).name + " interacted with the toilet."));
			}
			else
			{
				ToiletRoulette.Logger.LogWarning((object)"Could not find the player who flushed the toilet.");
			}
		}

		private static void KillPlayer()
		{
			if ((Object)(object)lastPlayerWhoFlushed != (Object)null)
			{
				lastPlayerWhoFlushed.ChatMessageSpeak("AW DANG IT!", false);
				lastPlayerWhoFlushed.PlayerDeath(-1);
				ToiletRoulette.Logger.LogInfo((object)("Player " + ((Object)lastPlayerWhoFlushed).name + " killed for failing the revive."));
			}
			else
			{
				ToiletRoulette.Logger.LogWarning((object)"Could not find the player who flushed the toilet.");
			}
		}

		private static void ReviveSpecificPlayer(PlayerDeathHead head, Vector3 revivePosition)
		{
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)head.playerAvatar != (Object)null && (bool)AccessTools.Field(typeof(PlayerAvatar), "deadSet").GetValue(head.playerAvatar))
			{
				head.playerAvatar.Revive(false);
				((Component)head.playerAvatar).transform.position = revivePosition;
				if ((Object)(object)lastPlayerWhoFlushed != (Object)null)
				{
					lastPlayerWhoFlushed.ChatMessageSpeak("I CANT STOP WINNING!", false);
				}
				ToiletRoulette.Logger.LogInfo((object)("Player " + ((Object)head.playerAvatar).name + " revived."));
			}
			else
			{
				ToiletRoulette.Logger.LogWarning((object)"The player is not dead or null. Cannot revive.");
			}
		}

		private static PlayerAvatar? FindNearestPlayer(Vector3 position)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			PlayerAvatar[] array = Object.FindObjectsOfType<PlayerAvatar>();
			PlayerAvatar result = null;
			float num = float.MaxValue;
			PlayerAvatar[] array2 = array;
			foreach (PlayerAvatar val in array2)
			{
				float num2 = Vector3.Distance(position, ((Component)val).transform.position);
				if (num2 < num)
				{
					num = num2;
					result = val;
				}
			}
			return result;
		}
	}
	[BepInPlugin("DarkSnakeX.ToiletRoulette", "ToiletRoulette", "1.0.0")]
	public class ToiletRoulette : BaseUnityPlugin
	{
		internal static ToiletRoulette Instance { get; private set; }

		internal static ManualLogSource Logger => Instance._logger;

		private ManualLogSource _logger => ((BaseUnityPlugin)this).Logger;

		internal Harmony? Harmony { get; set; }

		private void Awake()
		{
			Instance = this;
			((Component)this).gameObject.transform.parent = null;
			((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
			Patch();
			Logger.LogInfo((object)$"{((BaseUnityPlugin)this).Info.Metadata.GUID} v{((BaseUnityPlugin)this).Info.Metadata.Version} has loaded!");
		}

		internal void Patch()
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			//IL_0026: Expected O, but got Unknown
			if (Harmony == null)
			{
				Harmony val = new Harmony(((BaseUnityPlugin)this).Info.Metadata.GUID);
				Harmony val2 = val;
				Harmony = val;
			}
			Harmony.PatchAll();
			Harmony.PatchAll(typeof(ToiletFunPatch));
		}

		internal void Unpatch()
		{
			Harmony? harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}
	}
}