Decompiled source of CheekSqueak v1.0.3

CheekSqueak.dll

Decompiled 6 months ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using CheekSqueak.Patches;
using GameNetcodeStuff;
using HarmonyLib;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("CheekSqueak")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("CheekSqueak")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("1addc5bf-c7d8-4dce-af14-28a211ce85ab")]
[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")]
internal class <Module>
{
	static <Module>()
	{
	}
}
namespace CheekSqueak
{
	[BepInPlugin("CheekSqueak", "Cheek Squeak", "1.0.2")]
	public class CheekSqueakMod : BaseUnityPlugin
	{
		private const string modGUID = "CheekSqueak";

		private const string modName = "Cheek Squeak";

		private const string modVersion = "1.0.2";

		public static ConfigEntry<Key> fartKey;

		private readonly Harmony harmony = new Harmony("CheekSqueak");

		private static CheekSqueakMod Instance;

		public static ManualLogSource Log;

		public static Key defaultKey = (Key)20;

		private void Awake()
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			Log = Logger.CreateLogSource("CheekSqueak");
			fartKey = ((BaseUnityPlugin)this).Config.Bind<Key>("Bind", "fart", defaultKey, "");
			ManualLogSource log = Log;
			Key value = fartKey.Value;
			log.LogInfo((object)("Binded " + ((object)(Key)(ref value)).ToString() + " key to fart"));
			harmony.PatchAll(typeof(CheekSqueakMod));
			harmony.PatchAll(typeof(PlayerControllerBPatch));
			harmony.PatchAll(typeof(GameNetworkManagerPatch));
			harmony.PatchAll(typeof(StartOfRoundPatch));
			Log.LogInfo((object)"Cheek Squeak ready!");
			Type[] types = Assembly.GetExecutingAssembly().GetTypes();
			Type[] array = types;
			foreach (Type type in array)
			{
				MethodInfo[] methods = type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic);
				MethodInfo[] array2 = methods;
				foreach (MethodInfo methodInfo in array2)
				{
					object[] customAttributes = methodInfo.GetCustomAttributes(typeof(RuntimeInitializeOnLoadMethodAttribute), inherit: false);
					if (customAttributes.Length != 0)
					{
						methodInfo.Invoke(null, null);
					}
				}
			}
		}
	}
}
namespace CheekSqueak.Patches
{
	[HarmonyPatch(typeof(PlayerControllerB))]
	internal class PlayerControllerBPatch
	{
		public static ManualLogSource cheekSqueakLog = CheekSqueakMod.Log;

		public static PlayerControllerB player;

		public static bool isPlayerReady = false;

		public static float timer = 1f;

		[HarmonyPatch("ConnectClientToPlayerObject")]
		[HarmonyPostfix]
		public static void initializeClienttoPlayerObject()
		{
			cheekSqueakLog.LogInfo((object)"Connected Client to Player object");
			player = GameNetworkManager.Instance.localPlayerController;
			CheekSqueakNetworkHandler.Instance.audioSource = player.itemAudio;
			CheekSqueakNetworkHandler.Instance.audioClip = Resources.FindObjectsOfTypeAll<WhoopieCushionItem>()[0].fartAudios;
			isPlayerReady = true;
		}

		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		public static void PlayerControllerB_Update(PlayerControllerB __instance)
		{
			//IL_0034: 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)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			if (isPlayerReady && !player.isPlayerDead && (Object)(object)player == (Object)(object)__instance)
			{
				bool wasPressedThisFrame = ((ButtonControl)Keyboard.current[CheekSqueakMod.fartKey.Value]).wasPressedThisFrame;
				if (timer > 0f)
				{
					timer -= Time.deltaTime;
				}
				if (wasPressedThisFrame && timer < 0f)
				{
					float pitch = Random.Range(0.5f, 2f);
					int clipIndex = Random.Range(0, CheekSqueakNetworkHandler.Instance.audioClip.Length);
					CheekSqueakNetworkHandler.Instance.PlayerFartServerRpc(player.playerUsername, ((Component)player).transform.position, clipIndex, pitch);
					timer = 1f;
					bool flag = player.isInHangarShipRoom && player.playersManager.hangarDoorsClosed;
					RoundManager.Instance.PlayAudibleNoise(((Component)player).transform.position, 22f, 0.6f, 0, flag, 6);
				}
			}
		}
	}
	public class CheekSqueakNetworkHandler : NetworkBehaviour
	{
		public static CheekSqueakNetworkHandler Instance;

		public AudioSource audioSource;

		public AudioClip[] audioClip;

		public bool isPitchNormal = true;

		private void Awake()
		{
			Instance = this;
		}

		private void Update()
		{
			if ((Object)(object)audioSource != (Object)null && !audioSource.isPlaying && !isPitchNormal)
			{
				audioSource.pitch = 1f;
				isPitchNormal = true;
			}
		}

		[ServerRpc(RequireOwnership = false)]
		public void PlayerFartServerRpc(string username, Vector3 position, int clipIndex, float pitch)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: 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_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: 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)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: 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)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
			{
				ServerRpcParams val = default(ServerRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(1883520677u, val, (RpcDelivery)0);
				bool flag = username != null;
				((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref flag, default(ForPrimitives));
				if (flag)
				{
					((FastBufferWriter)(ref val2)).WriteValueSafe(username, false);
				}
				((FastBufferWriter)(ref val2)).WriteValueSafe(ref position);
				BytePacker.WriteValueBitPacked(val2, clipIndex);
				((FastBufferWriter)(ref val2)).WriteValueSafe<float>(ref pitch, default(ForPrimitives));
				((NetworkBehaviour)this).__endSendServerRpc(ref val2, 1883520677u, val, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost))
			{
				PlayerFartClientRpc(username, position, clipIndex, pitch);
			}
		}

		[ClientRpc]
		public void PlayerFartClientRpc(string username, Vector3 position, int clipIndex, float pitch)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: 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_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: 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)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: 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)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)base.__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val = default(ClientRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(2630412716u, val, (RpcDelivery)0);
				bool flag = username != null;
				((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref flag, default(ForPrimitives));
				if (flag)
				{
					((FastBufferWriter)(ref val2)).WriteValueSafe(username, false);
				}
				((FastBufferWriter)(ref val2)).WriteValueSafe(ref position);
				BytePacker.WriteValueBitPacked(val2, clipIndex);
				((FastBufferWriter)(ref val2)).WriteValueSafe<float>(ref pitch, default(ForPrimitives));
				((NetworkBehaviour)this).__endSendClientRpc(ref val2, 2630412716u, val, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
			{
				CheekSqueakMod.Log.LogInfo((object)(username + " farted!"));
				audioSource.pitch = pitch;
				((Component)audioSource).transform.position = position;
				audioSource.PlayOneShot(audioClip[clipIndex]);
				isPitchNormal = false;
			}
		}

		protected override void __initializeVariables()
		{
			((NetworkBehaviour)this).__initializeVariables();
		}

		[RuntimeInitializeOnLoadMethod]
		internal static void InitializeRPCS_CheekSqueakNetworkHandler()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			NetworkManager.__rpc_func_table.Add(1883520677u, new RpcReceiveHandler(__rpc_handler_1883520677));
			NetworkManager.__rpc_func_table.Add(2630412716u, new RpcReceiveHandler(__rpc_handler_2630412716));
		}

		private static void __rpc_handler_1883520677(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_002f: 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_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: 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)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				bool flag = default(bool);
				((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref flag, default(ForPrimitives));
				string username = null;
				if (flag)
				{
					((FastBufferReader)(ref reader)).ReadValueSafe(ref username, false);
				}
				Vector3 position = default(Vector3);
				((FastBufferReader)(ref reader)).ReadValueSafe(ref position);
				int clipIndex = default(int);
				ByteUnpacker.ReadValueBitPacked(reader, ref clipIndex);
				float pitch = default(float);
				((FastBufferReader)(ref reader)).ReadValueSafe<float>(ref pitch, default(ForPrimitives));
				target.__rpc_exec_stage = (__RpcExecStage)1;
				((CheekSqueakNetworkHandler)(object)target).PlayerFartServerRpc(username, position, clipIndex, pitch);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_2630412716(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_002f: 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_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: 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)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				bool flag = default(bool);
				((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref flag, default(ForPrimitives));
				string username = null;
				if (flag)
				{
					((FastBufferReader)(ref reader)).ReadValueSafe(ref username, false);
				}
				Vector3 position = default(Vector3);
				((FastBufferReader)(ref reader)).ReadValueSafe(ref position);
				int clipIndex = default(int);
				ByteUnpacker.ReadValueBitPacked(reader, ref clipIndex);
				float pitch = default(float);
				((FastBufferReader)(ref reader)).ReadValueSafe<float>(ref pitch, default(ForPrimitives));
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((CheekSqueakNetworkHandler)(object)target).PlayerFartClientRpc(username, position, clipIndex, pitch);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		protected internal override string __getTypeName()
		{
			return "CheekSqueakNetworkHandler";
		}
	}
	[HarmonyPatch(typeof(GameNetworkManager))]
	internal class GameNetworkManagerPatch
	{
		public static AssetBundle CheekSqueakAssetBundle;

		public static GameObject CheekSqueakNetworkPrefab;

		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		public static void Init()
		{
			CheekSqueakMod.Log.LogInfo((object)"GameNetworkManager Start");
			CheekSqueakAssetBundle = AssetBundle.LoadFromStream(Assembly.GetExecutingAssembly().GetManifestResourceStream("CheekSqueak.cheeksqueak"));
			CheekSqueakNetworkPrefab = CheekSqueakAssetBundle.LoadAsset<GameObject>("assets/networking/cheeksqueaknetwork.prefab");
			CheekSqueakNetworkPrefab.AddComponent<CheekSqueakNetworkHandler>();
			NetworkManager.Singleton.AddNetworkPrefab(CheekSqueakNetworkPrefab);
		}
	}
	[HarmonyPatch(typeof(StartOfRound))]
	internal class StartOfRoundPatch
	{
		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		public static void SpawnNetworkHandler()
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			CheekSqueakMod.Log.LogInfo((object)"StartOfRound Start");
			if (NetworkManager.Singleton.IsHost || NetworkManager.Singleton.IsServer)
			{
				GameObject val = Object.Instantiate<GameObject>(GameNetworkManagerPatch.CheekSqueakNetworkPrefab, Vector3.zero, Quaternion.identity);
				val.GetComponent<NetworkObject>().Spawn(false);
			}
		}
	}
}