Decompiled source of WhoopieCushionModifier v0.0.2

baer1.WhoopieCushionFunny.dll

Decompiled 3 months ago
using System;
using System.Collections;
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 CSync.Extensions;
using CSync.Lib;
using GameNetcodeStuff;
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: AssemblyCompany("baer1.WhoopieCushionFunny")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("0.0.2.0")]
[assembly: AssemblyInformationalVersion("0.0.2+78facc186842fbb03541c64ab0e72ffd54528f24")]
[assembly: AssemblyProduct("WhoopieCushionFunny")]
[assembly: AssemblyTitle("baer1.WhoopieCushionFunny")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.2.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 WhoopieCushionFunny
{
	[BepInPlugin("baer1.WhoopieCushionFunny", "WhoopieCushionFunny", "0.0.2")]
	[BepInDependency("com.sigurd.csync", "5.0.0")]
	public class WhoopieCushionFunny : BaseUnityPlugin
	{
		public enum ModAction
		{
			None,
			PlaySound,
			Explode,
			Vanish,
			PlaySoundAndExplode,
			PlaySoundAndVanish,
			PlaySoundAndExplodeAndVanish,
			ExplodeAndVanish
		}

		public enum ModAction2
		{
			None = 0,
			PlaySound = 1,
			Explode = 2,
			PlaySoundAndExplode = 4
		}

		public enum ModPosition
		{
			FollowItem,
			FollowTrigger,
			TriggerPosition
		}

		[HarmonyPatch(typeof(WhoopieCushionItem), "ActivatePhysicsTrigger")]
		internal class TriggerPatch
		{
			private static bool Prefix(ref WhoopieCushionItem __instance, ref Collider other)
			{
				//IL_005d: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d1: 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)
				PlayerControllerB val = default(PlayerControllerB);
				if (!((Component)other).TryGetComponent<PlayerControllerB>(ref val))
				{
					return true;
				}
				if (!Instance.Enable || val.isPlayerDead)
				{
					return true;
				}
				if (!Instance.Delay.HasValue)
				{
					DoActionNow(__instance, ((Component)__instance).transform.position, other, Instance.Action, Instance.Position);
				}
				else
				{
					if (Instance.Action2 != 0)
					{
						DoActionNow(__instance, ((Component)__instance).transform.position, other, (ModAction)Instance.Action2, ModPosition.TriggerPosition);
					}
					DoActionAfter(Instance.Delay.Value, __instance, ((Component)__instance).transform.position, other, Instance.Action, Instance.Position);
				}
				return false;
			}
		}

		[HarmonyPatch(typeof(PlayerControllerB), "AllowPlayerDeath")]
		internal class AllowPlayerDeathPatch
		{
			private static bool Prefix(ref PlayerControllerB __instance, ref bool __result)
			{
				if (__instance.isPlayerDead || !__instance.isPlayerControlled)
				{
					return __result = false;
				}
				if (Instance.AllowDeathInOrbit && isExploding)
				{
					return !(__result = true) && false;
				}
				return true;
			}
		}

		private SyncedEntry<bool> enable = null;

		private SyncedEntry<bool> allowDeathInOrbit = null;

		private SyncedEntry<float> delay = null;

		private SyncedEntry<ModAction> action = null;

		private SyncedEntry<ModAction2> action2 = null;

		private SyncedEntry<ModPosition> position = null;

		internal static bool isExploding;

		public static WhoopieCushionFunny Instance { get; private set; }

		internal static ManualLogSource Logger { get; private set; }

		internal static Harmony? Harmony { get; set; }

		public bool Enable => enable.Value;

		public bool AllowDeathInOrbit => allowDeathInOrbit.Value;

		public float? Delay => (delay.Value > 0f) ? new float?(delay.Value) : null;

		public ModAction Action => action.Value;

		public ModAction2 Action2 => action2.Value;

		public ModPosition Position => position.Value;

		private void Awake()
		{
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Expected O, but got Unknown
			Logger = ((BaseUnityPlugin)this).Logger;
			Instance = this;
			enable = SyncedBindingExtensions.BindSyncedEntry<bool>(((BaseUnityPlugin)this).Config, "General", "Enable", false, "Enables or disables the mod");
			allowDeathInOrbit = SyncedBindingExtensions.BindSyncedEntry<bool>(((BaseUnityPlugin)this).Config, "Settings", "AllowDeathInOrbit", true, "If true, whoopie cushion explosions kill you even in space");
			delay = SyncedBindingExtensions.BindSyncedEntry<float>(((BaseUnityPlugin)this).Config, "Settings", "Delay", 0f, "Delay in seconds until the specified action happens");
			action = SyncedBindingExtensions.BindSyncedEntry<ModAction>(((BaseUnityPlugin)this).Config, "Settings", "Action", ModAction.PlaySound, "What action to perform after the specified delay");
			action2 = SyncedBindingExtensions.BindSyncedEntry<ModAction2>(((BaseUnityPlugin)this).Config, "Settings", "ActionNoDelay", ModAction2.None, "What action to perform immediately, ignoring the specified delay (This is ignored if there is no delay)");
			position = SyncedBindingExtensions.BindSyncedEntry<ModPosition>(((BaseUnityPlugin)this).Config, "Settings", "Position", ModPosition.TriggerPosition, "Where the action should be performed after the delay");
			if (Harmony == null)
			{
				Harmony = new Harmony("baer1.WhoopieCushionFunny");
			}
			Logger.LogDebug((object)"Patching...");
			Harmony.PatchAll();
			Logger.LogDebug((object)"Finished patching!");
			Logger.LogInfo((object)"baer1.WhoopieCushionFunny v0.0.2 has loaded!");
		}

		public static void DoActionNow(WhoopieCushionItem whoopieCushion, Vector3 origin, Collider other, ModAction action, ModPosition position)
		{
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: 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_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Expected O, but got Unknown
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			switch (action)
			{
			case ModAction.None:
				return;
			case ModAction.Vanish:
			case ModAction.PlaySoundAndVanish:
			case ModAction.PlaySoundAndExplodeAndVanish:
			case ModAction.ExplodeAndVanish:
				if (position == ModPosition.FollowItem)
				{
					position = ModPosition.TriggerPosition;
				}
				break;
			}
			if (1 == 0)
			{
			}
			Vector3 val = (Vector3)(position switch
			{
				ModPosition.FollowItem => ((Component)whoopieCushion).transform.position, 
				ModPosition.FollowTrigger => ((Component)other).transform.position, 
				_ => origin, 
			});
			if (1 == 0)
			{
			}
			Vector3 val2 = val;
			if ((action == ModAction.PlaySound || (uint)(action - 4) <= 2u) ? true : false)
			{
				if (Vector3.Distance(whoopieCushion.lastPositionAtFart, ((Component)whoopieCushion).transform.position) > 2f)
				{
					whoopieCushion.timesPlayingInOneSpot = 0;
				}
				whoopieCushion.timesPlayingInOneSpot++;
				whoopieCushion.lastPositionAtFart = ((Component)whoopieCushion).transform.position;
				GameObject val3 = new GameObject();
				AudioSource other2 = val3.AddComponent<AudioSource>();
				whoopieCushion.whoopieCushionAudio.CloneOnto(ref other2);
				val3.transform.position = val2;
				Transform transform = val3.transform;
				if (1 == 0)
				{
				}
				Transform parent = (Transform)(position switch
				{
					ModPosition.FollowItem => ((Component)whoopieCushion).transform, 
					ModPosition.FollowTrigger => ((Component)other).transform, 
					_ => val3.transform.parent, 
				});
				if (1 == 0)
				{
				}
				transform.parent = parent;
				RoundManager.PlayRandomClip(other2, whoopieCushion.fartAudios, true, 1f, -1, 1000);
				RoundManager.Instance.PlayAudibleNoise(val2, 8f, 0.8f, whoopieCushion.timesPlayingInOneSpot, ((GrabbableObject)whoopieCushion).isInShipRoom && StartOfRound.Instance.hangarDoorsClosed, 101158);
				((MonoBehaviour)val3.AddComponent<_MonoBehaviour>()).StartCoroutine(_CleanUpAfterPlayingAudio(other2, val3));
			}
			bool flag;
			switch (action)
			{
			case ModAction.Explode:
			case ModAction.PlaySoundAndExplode:
			case ModAction.PlaySoundAndExplodeAndVanish:
			case ModAction.ExplodeAndVanish:
				flag = true;
				break;
			default:
				flag = false;
				break;
			}
			if (flag)
			{
				Landmine.SpawnExplosion(val2, isExploding = true, 5.7f, 6f, 50, 0f, (GameObject)null, false);
			}
			isExploding = false;
			if (GameNetworkManager.Instance.isHostingGame)
			{
				StartOfRound.Instance.StartGameServerRpc();
			}
			if ((action == ModAction.Vanish || (uint)(action - 5) <= 2u) ? true : false)
			{
				Object.Destroy((Object)(object)((Component)whoopieCushion).gameObject);
			}
		}

		public static void DoActionAfter(float delay, WhoopieCushionItem whoopieCushion, Vector3 origin, Collider other, ModAction action, ModPosition position)
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Expected O, but got Unknown
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			if (action != 0)
			{
				switch (position)
				{
				case ModPosition.FollowItem:
					((MonoBehaviour)whoopieCushion).StartCoroutine(_DoActionAfter(delay, whoopieCushion, origin, other, action, position));
					return;
				}
				GameObject val = new GameObject();
				val.transform.parent = ((Component)other).transform;
				GameObject val2 = val;
				((MonoBehaviour)val2.AddComponent<_MonoBehaviour>()).StartCoroutine(_DoActionAfter(delay, whoopieCushion, origin, other, action, position, val2));
			}
		}

		internal static IEnumerator _DoActionAfter(float delay, WhoopieCushionItem whoopieCushion, Vector3 origin, Collider other, ModAction action, ModPosition position, GameObject? cleanUp = null)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			yield return (object)new WaitForSeconds(delay);
			try
			{
				DoActionNow(whoopieCushion, origin, other, action, position);
			}
			catch (Exception e)
			{
				Logger.LogError((object)e);
			}
			if (Object.op_Implicit((Object)(object)cleanUp))
			{
				Object.Destroy((Object)(object)cleanUp);
			}
		}

		internal static IEnumerator _CleanUpAfterPlayingAudio(AudioSource audioSource, GameObject cleanUp)
		{
			AudioSource audioSource2 = audioSource;
			yield return (object)new WaitUntil((Func<bool>)(() => !audioSource2.isPlaying));
			Object.Destroy((Object)(object)cleanUp);
		}
	}
	internal static class AudioSourceExtensions
	{
		internal static void CloneOnto(this AudioSource source, ref AudioSource other)
		{
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			other.bypassEffects = source.bypassEffects;
			other.bypassListenerEffects = source.bypassListenerEffects;
			other.bypassReverbZones = source.bypassReverbZones;
			other.clip = source.clip;
			other.dopplerLevel = source.dopplerLevel;
			other.ignoreListenerPause = source.ignoreListenerPause;
			other.ignoreListenerVolume = source.ignoreListenerVolume;
			other.loop = source.loop;
			other.maxDistance = source.maxDistance;
			other.minDistance = source.minDistance;
			other.mute = source.mute;
			other.outputAudioMixerGroup = source.outputAudioMixerGroup;
			other.panStereo = source.panStereo;
			other.pitch = source.pitch;
			other.playOnAwake = source.playOnAwake;
			other.priority = source.priority;
			other.reverbZoneMix = source.reverbZoneMix;
			other.rolloffMode = source.rolloffMode;
			other.spatialBlend = source.spatialBlend;
			other.spatialize = source.spatialize;
			other.spatializePostEffects = source.spatializePostEffects;
			other.spread = source.spread;
			other.time = source.time;
			other.timeSamples = source.timeSamples;
			other.velocityUpdateMode = source.velocityUpdateMode;
			other.volume = source.volume;
		}
	}
	internal class _MonoBehaviour : MonoBehaviour
	{
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "baer1.WhoopieCushionFunny";

		public const string PLUGIN_NAME = "WhoopieCushionFunny";

		public const string PLUGIN_VERSION = "0.0.2";
	}
}