Decompiled source of LethalGas v0.0.5

BepInEx/plugins/LethalGas.dll

Decompiled 7 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
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 LCSoundTool;
using LethalGas.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("LethalGas")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("LethalGas")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("4eca71fe-bd6f-4f0e-809f-3d43a114c5bb")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace LethalGas
{
	[BepInPlugin("Fizix.LethalGas", "Lethal Gas", "0.0.0.1")]
	public class Plugin : BaseUnityPlugin
	{
		private const string modGUID = "Fizix.LethalGas";

		private const string modName = "Lethal Gas";

		private const string modVersion = "0.0.0.1";

		private readonly Harmony harmony = new Harmony("Fizix.LethalGas");

		private static Plugin Instance;

		internal static ManualLogSource mls;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			mls = Logger.CreateLogSource("Fizix.LethalGas");
			mls.LogInfo((object)"The LethalGas mod has awaken :)");
			harmony.PatchAll(typeof(Plugin));
			harmony.PatchAll(typeof(PlayerControllerBPatch));
		}
	}
}
namespace LethalGas.Patches
{
	[HarmonyPatch(typeof(PlayerControllerB))]
	internal class PlayerControllerBPatch
	{
		private class Belch
		{
			public AudioClip Clip { get; }

			public float Volume { get; }

			public Belch(AudioClip clip, float volume = 1f)
			{
				Clip = clip;
				Volume = volume;
			}
		}

		private static Belch[] Belches = new Belch[5]
		{
			new Belch(SoundTool.GetAudioClip("fizixteam-LethalGas", "Belches", "rick-belching-rick-and-morty.mp3")),
			new Belch(SoundTool.GetAudioClip("fizixteam-LethalGas", "Belches", "rick-and-morty-burp-made-with-Voicemod.mp3")),
			new Belch(SoundTool.GetAudioClip("fizixteam-LethalGas", "Belches", "Burp-A1.mp3")),
			new Belch(SoundTool.GetAudioClip("fizixteam-LethalGas", "Belches", "Burp-A2.mp3")),
			new Belch(SoundTool.GetAudioClip("fizixteam-LethalGas", "Belches", "Burp-B1.mp3"))
		};

		private static Random Randomizer = new Random();

		private const int TimeInterval = 5;

		private static int NextBelchSecond = Randomizer.Next(5);

		private static DateTime LastPlayedBelch = DateTime.Now;

		private static string ChatPrefix = "<alpha=#FF>LG|";

		private static string ChatSuffix = "</alpha>";

		private static string ChatSeparator = "$|{¿|{|?!";

		[HarmonyPatch(typeof(HUDManager), "SubmitChat_performed")]
		[HarmonyPrefix]
		private static void ChatCommandsSubmitted(HUDManager __instance)
		{
			string text = __instance.chatTextField.text;
			string username = GameNetworkManager.Instance.username;
			Plugin.mls.LogInfo((object)("Received chat input: " + text));
			__instance.chatTextField.text = text;
		}

		[HarmonyPatch(typeof(HUDManager), "AddChatMessage")]
		[HarmonyPrefix]
		private static void ReadChatMessage(HUDManager __instance, ref string chatMessage, ref string nameOfUserWhoTyped)
		{
			Plugin.mls.LogInfo((object)("Chat Message: " + chatMessage + " sent by: " + nameOfUserWhoTyped));
			if (!chatMessage.StartsWith(ChatPrefix) || !chatMessage.EndsWith(ChatSuffix))
			{
				return;
			}
			string text = chatMessage.Substring(ChatPrefix.Length, chatMessage.Length - ChatPrefix.Length - ChatSuffix.Length);
			string[] array = text.Split(new string[1] { ChatSeparator }, StringSplitOptions.None);
			if (array.Length != 2 || !ulong.TryParse(array[0], out var result) || !int.TryParse(array[1], out var result2) || result2 < 0 || result2 >= Belches.Length)
			{
				return;
			}
			Belch belch = Belches[result2];
			Plugin.mls.LogInfo((object)("DO BELCH: " + result2));
			GameObject[] allPlayerObjects = RoundManager.Instance.playersManager.allPlayerObjects;
			PlayerControllerB val = null;
			GameObject[] array2 = allPlayerObjects;
			foreach (GameObject val2 in array2)
			{
				PlayerControllerB component = val2.GetComponent<PlayerControllerB>();
				Plugin.mls.LogInfo((object)("CONTROLLER NULL? " + ((Object)(object)component == (Object)null) + ", ID: " + (((Object)(object)component == (Object)null) ? "N/A" : component.playerClientId.ToString())));
				if (component.playerClientId == result)
				{
					val = component;
				}
				if (component.playerClientId != result)
				{
				}
			}
			Plugin.mls.LogInfo((object)("FOUND BELCHER: " + ((Object)(object)val == (Object)null)));
			if ((Object)(object)val != (Object)null)
			{
				Plugin.mls.LogInfo((object)("MAKING BELCH: " + result2));
				RoundManager.PlayRandomClip(val.movementAudio, (AudioClip[])(object)new AudioClip[1] { belch.Clip }, true, belch.Volume, 0);
			}
		}

		private static void PlayBelchForListener(Belch belch)
		{
		}

		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		private static void ExecuteBelch()
		{
			TimeSpan timeSpan = DateTime.Now - LastPlayedBelch;
			int num = (int)timeSpan.TotalSeconds;
			if (num >= 3 && timeSpan.Seconds % 5 == NextBelchSecond)
			{
				WalkieTalkie userWalkieTalkieBeingUsed = GetUserWalkieTalkieBeingUsed();
				if ((Object)(object)userWalkieTalkieBeingUsed != (Object)null)
				{
					Plugin.mls.LogInfo((object)("TIME CHECK: " + timeSpan.Seconds % 5 + " == " + NextBelchSecond));
					LastPlayedBelch = DateTime.Now;
					int randomBelchID = GetRandomBelchID();
					SendRandomBelchToServer(randomBelchID);
					NextBelchSecond = Randomizer.Next(5);
				}
			}
		}

		private static WalkieTalkie GetUserWalkieTalkieBeingUsed()
		{
			List<WalkieTalkie> allWalkieTalkies = WalkieTalkie.allWalkieTalkies;
			for (int i = 0; i < allWalkieTalkies.Count; i++)
			{
				WalkieTalkie val = allWalkieTalkies[i];
				if (!((Object)(object)((GrabbableObject)val).playerHeldBy == (Object)null) && val.clientIsHoldingAndSpeakingIntoThis && ((GrabbableObject)val).isBeingUsed && !((Object)(object)((GrabbableObject)val).playerHeldBy != (Object)(object)GameNetworkManager.Instance.localPlayerController) && ((GrabbableObject)val).isBeingUsed)
				{
					return val;
				}
			}
			return null;
		}

		private static float GetMaxVolume(WalkieTalkie walkieTalkie)
		{
			return (float)((object)walkieTalkie).GetType().GetField("maxVolume", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(walkieTalkie);
		}

		private static int GetRandomBelchID()
		{
			return Random.Range(0, Belches.Length);
		}

		public static void SendRandomBelchToServer(int belchID)
		{
			ulong playerClientId = GameNetworkManager.Instance.localPlayerController.playerClientId;
			string text = ChatPrefix + playerClientId + ChatSeparator + belchID + ChatSuffix;
			HUDManager.Instance.AddTextToChatOnServer(text, -1);
		}

		public static int PlayRandomClip(AudioSource audioSource, AudioClip[] clipsArray, bool randomize = true, float oneShotVolume = 1f, int audibleNoiseID = 0)
		{
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			if (randomize)
			{
				audioSource.pitch = Random.Range(0.94f, 1.06f);
			}
			Plugin.mls.LogInfo((object)"PLAY BELCH");
			int num = Random.Range(0, clipsArray.Length);
			audioSource.PlayOneShot(clipsArray[num], Random.Range(oneShotVolume - 0.18f, oneShotVolume));
			WalkieTalkie.TransmitOneShotAudio(audioSource, clipsArray[num], 0.85f);
			RoundManager.Instance.PlayAudibleNoise(((Component)audioSource).transform.position, 4f * oneShotVolume, oneShotVolume / 2f, 0, true, audibleNoiseID);
			return num;
		}
	}
}