Decompiled source of Friends Dice Events v1.0.2

BepInEx\plugins\FriendsDiceEvents\FriendsDiceEvents.dll

Decompiled a day 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.Logging;
using FriendsDiceEvents.Effects;
using GameNetcodeStuff;
using Microsoft.CodeAnalysis;
using MysteryDice;
using MysteryDice.Effects;
using MysteryDice.Patches;
using Unity.Netcode;
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: AssemblyCompany("FriendsDiceEvents")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Custom dice events based on friends for Emergency Dice Updated")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("FriendsDiceEvents")]
[assembly: AssemblyTitle("FriendsDiceEvents")]
[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 FriendsDiceEvents
{
	[BepInPlugin("XtraModding.FriendsDiceEvents", "Friends Dice Events", "1.0.2")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		private const string modGUID = "XtraModding.FriendsDiceEvents";

		private const string modName = "Friends Dice Events";

		private const string modVersion = "1.0.2";

		public static ManualLogSource Log;

		private void Awake()
		{
			Log = ((BaseUnityPlugin)this).Logger;
			MysteryDice.RegisterNewEffect((IEffect)(object)new Paul(), false, false);
			MysteryDice.RegisterNewEffect((IEffect)(object)new Ghost(), false, false);
			MysteryDice.RegisterNewEffect((IEffect)(object)new Jane(), false, false);
			MysteryDice.RegisterNewEffect((IEffect)(object)new Xtra(), false, false);
			MysteryDice.RegisterNewEffect((IEffect)(object)new Saskia(), false, false);
			MysteryDice.RegisterNewEffect((IEffect)(object)new Daniel(), false, false);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Friends Dice Events loaded! 6 custom events registered.");
		}
	}
}
namespace FriendsDiceEvents.Effects
{
	internal class Daniel : IEffect
	{
		public string Name => "Daniel";

		public EffectType Outcome => (EffectType)1;

		public bool ShowDefaultTooltip => false;

		public string Tooltip => "Daniel silences you... completely!";

		public void Use()
		{
			PlayerControllerB localPlayerController = GameNetworkManager.Instance.localPlayerController;
			int num = Array.IndexOf(StartOfRound.Instance.allPlayerScripts, localPlayerController);
			localPlayerController.voiceMuffledByEnemy = true;
			if (num >= 0 && num < SoundManager.Instance.playerVoicePitchTargets.Length)
			{
				SoundManager.Instance.playerVoicePitchTargets[num] = 0f;
			}
			try
			{
				if ((Object)(object)localPlayerController.currentVoiceChatAudioSource != (Object)null)
				{
					localPlayerController.currentVoiceChatAudioSource.volume = 0f;
				}
			}
			catch
			{
			}
			AudioListener.volume = 0f;
			((Behaviour)HUDManager.Instance.audioListenerLowPass).enabled = true;
			Misc.SafeTipMessage("Silence is Golden", "Daniel teached you the art of his silence");
			SilentWatcher component = ((Component)localPlayerController).gameObject.GetComponent<SilentWatcher>();
			if ((Object)(object)component != (Object)null)
			{
				Object.Destroy((Object)(object)component);
			}
			SilentWatcher silentWatcher = ((Component)localPlayerController).gameObject.AddComponent<SilentWatcher>();
			silentWatcher.playerID = num;
		}
	}
	public class SilentWatcher : MonoBehaviour
	{
		public int playerID;

		public void Update()
		{
			if ((Object)(object)StartOfRound.Instance == (Object)null || StartOfRound.Instance.inShipPhase)
			{
				Restore();
				return;
			}
			PlayerControllerB localPlayerController = StartOfRound.Instance.localPlayerController;
			if ((Object)(object)localPlayerController == (Object)null || localPlayerController.isInHangarShipRoom || localPlayerController.isInElevator)
			{
				Restore();
			}
		}

		private void Restore()
		{
			try
			{
				PlayerControllerB localPlayerController = StartOfRound.Instance.localPlayerController;
				if ((Object)(object)localPlayerController != (Object)null)
				{
					localPlayerController.voiceMuffledByEnemy = false;
					if (playerID >= 0 && playerID < SoundManager.Instance.playerVoicePitchTargets.Length)
					{
						SoundManager.Instance.playerVoicePitchTargets[playerID] = 1f;
					}
					if ((Object)(object)localPlayerController.currentVoiceChatAudioSource != (Object)null)
					{
						localPlayerController.currentVoiceChatAudioSource.volume = 1f;
					}
					AudioListener.volume = 1f;
					((Behaviour)HUDManager.Instance.audioListenerLowPass).enabled = false;
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Restore error: " + ex.Message));
			}
			Object.Destroy((Object)(object)this);
		}

		public void OnDestroy()
		{
			try
			{
				AudioListener.volume = 1f;
				PlayerControllerB val = StartOfRound.Instance?.localPlayerController;
				if ((Object)(object)val != (Object)null)
				{
					val.voiceMuffledByEnemy = false;
					if (playerID >= 0 && playerID < SoundManager.Instance.playerVoicePitchTargets.Length)
					{
						SoundManager.Instance.playerVoicePitchTargets[playerID] = 1f;
					}
					if ((Object)(object)val.currentVoiceChatAudioSource != (Object)null)
					{
						val.currentVoiceChatAudioSource.volume = 1f;
					}
				}
			}
			catch
			{
			}
		}
	}
	internal class Ghost : IEffect
	{
		public string Name => "Ghost";

		public EffectType Outcome => (EffectType)1;

		public bool ShowDefaultTooltip => false;

		public string Tooltip => "Darkness shall come over you!";

		public void Use()
		{
			Networker.Instance.TurnOffAllLightsServerRPC();
			try
			{
				ShipLights val = Object.FindObjectOfType<ShipLights>();
				if ((Object)(object)val != (Object)null)
				{
					val.SetShipLightsServerRpc(false);
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Ship lights error: " + ex.Message));
			}
			try
			{
				int num = Misc.TotalAlive();
				for (int i = 0; i < num * 3; i++)
				{
					Networker.Instance.BatteryDrainServerRPC();
				}
			}
			catch (Exception ex2)
			{
				Plugin.Log.LogWarning((object)("Battery drain error: " + ex2.Message));
			}
			try
			{
				PlayerControllerB localPlayerController = StartOfRound.Instance.localPlayerController;
				if ((Object)(object)localPlayerController != (Object)null)
				{
					GrabbableObject[] itemSlots = localPlayerController.ItemSlots;
					foreach (GrabbableObject val2 in itemSlots)
					{
						if (!((Object)(object)val2 == (Object)null))
						{
							FlashlightItem val3 = (FlashlightItem)(object)((val2 is FlashlightItem) ? val2 : null);
							if ((Object)(object)val3 != (Object)null && ((GrabbableObject)val3).isBeingUsed)
							{
								((GrabbableObject)val3).isBeingUsed = false;
								((Behaviour)val3.flashlightBulb).enabled = false;
								((Behaviour)val3.flashlightBulbGlow).enabled = false;
								val3.usingPlayerHelmetLight = false;
								((Behaviour)localPlayerController.helmetLight).enabled = false;
								localPlayerController.pocketedFlashlight = null;
							}
						}
					}
				}
			}
			catch (Exception ex3)
			{
				Plugin.Log.LogWarning((object)("Flashlight error: " + ex3.Message));
			}
			Misc.SafeTipMessage("Ghoooooost", "Darkness shall come over you");
		}
	}
	internal class Jane : IEffect
	{
		public string Name => "Jane";

		public EffectType Outcome => (EffectType)1;

		public bool ShowDefaultTooltip => false;

		public string Tooltip => "Jane released the bugs!";

		public void Use()
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			Vector3 position = ((Component)GameNetworkManager.Instance.localPlayerController).transform.position;
			if (((NetworkBehaviour)Networker.Instance).IsHost || ((NetworkBehaviour)Networker.Instance).IsServer)
			{
				if (GetEnemies.HoardingBug != null)
				{
					Vector3 val = default(Vector3);
					for (int i = 0; i < 3; i++)
					{
						((Vector3)(ref val))..ctor(Random.Range(-3f, 3f), 0f, Random.Range(-3f, 3f));
						GameObject val2 = Object.Instantiate<GameObject>(GetEnemies.HoardingBug.enemyType.enemyPrefab, position + val, Quaternion.identity);
						val2.GetComponentInChildren<NetworkObject>().Spawn(true);
						RoundManager.Instance.SpawnedEnemies.Add(val2.GetComponent<EnemyAI>());
					}
				}
			}
			else
			{
				Vector3 val3 = default(Vector3);
				for (int j = 0; j < 3; j++)
				{
					((Vector3)(ref val3))..ctor(Random.Range(-3f, 3f), 0f, Random.Range(-3f, 3f));
					Networker.Instance.SpawnEnemyAtPosServerRPC("Hoarding bug", position + val3, false, default(Vector3));
				}
			}
			Misc.SafeTipMessage("JIPPPEEE", "Jane summoned her precious Yippee squad");
		}
	}
	internal class Paul : IEffect
	{
		public string Name => "Paul";

		public EffectType Outcome => (EffectType)1;

		public bool ShowDefaultTooltip => false;

		public string Tooltip => "Everyone goes to the reactor room!";

		public void Use()
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			LungProp val = Object.FindObjectOfType<LungProp>();
			if ((Object)(object)val == (Object)null)
			{
				Misc.SafeTipMessage("Reactor time", "Paul tried, but there's no reactor on this moon!");
				return;
			}
			Vector3 position = ((Component)val).transform.position;
			PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts;
			Vector3 val3 = default(Vector3);
			foreach (PlayerControllerB val2 in allPlayerScripts)
			{
				if (Misc.IsPlayerAliveAndControlled(val2))
				{
					int num = Array.IndexOf(StartOfRound.Instance.allPlayerScripts, val2);
					((Vector3)(ref val3))..ctor(Random.Range(-2f, 2f), 0f, Random.Range(-2f, 2f));
					Networker.Instance.TeleportInsideServerRPC(num, position + val3);
				}
			}
			Misc.SafeTipMessage("Reactor time", "Paul demands the reactor");
		}
	}
	internal class Saskia : IEffect
	{
		public string Name => "Saskia";

		public EffectType Outcome => (EffectType)2;

		public bool ShowDefaultTooltip => false;

		public string Tooltip => "Saskia demands VIP treatment!";

		public void Use()
		{
			PlayerControllerB localPlayerController = GameNetworkManager.Instance.localPlayerController;
			int num = Array.IndexOf(StartOfRound.Instance.allPlayerScripts, localPlayerController);
			if (Misc.TotalAlive() > 1)
			{
				Networker.Instance.SwapPlayersServerRPC(num);
			}
			Networker.Instance.TeleportToShipServerRPC(num);
			Misc.SafeTipMessage("You are special!", "Saskia gave you VIP treatment!");
		}
	}
	internal class Xtra : IEffect
	{
		public string Name => "Xtra";

		public EffectType Outcome => (EffectType)4;

		public bool ShowDefaultTooltip => false;

		public string Tooltip => "Xtra gives everyone a dice!";

		public void Use()
		{
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			if (!((NetworkBehaviour)Networker.Instance).IsHost && !((NetworkBehaviour)Networker.Instance).IsServer)
			{
				return;
			}
			List<Item> registeredDice = MysteryDice.RegisteredDice;
			if (registeredDice == null || registeredDice.Count == 0)
			{
				return;
			}
			PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts;
			foreach (PlayerControllerB val in allPlayerScripts)
			{
				if (Misc.IsPlayerAliveAndControlled(val))
				{
					try
					{
						Item val2 = registeredDice[Random.Range(0, registeredDice.Count)];
						Vector3 val3 = ((Component)val).transform.position + ((Component)val).transform.forward * 1.5f;
						GameObject val4 = Object.Instantiate<GameObject>(val2.spawnPrefab, val3, Quaternion.identity, RoundManager.Instance.playersManager.propsContainer);
						val4.GetComponent<GrabbableObject>().fallTime = 0f;
						val4.GetComponent<NetworkObject>().Spawn(true);
						val4.GetComponent<GrabbableObject>().EnablePhysics(true);
					}
					catch (Exception ex)
					{
						Plugin.Log.LogWarning((object)("Dice spawn failed: " + ex.Message));
					}
				}
			}
			Misc.SafeTipMessage("Roll the dice", "Xtra gifted you one of his dices");
		}
	}
}