Decompiled source of Real Farts v1.1.4

plugins/Farts.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Farts.Utility;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Networking;

[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("Farts")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("My first plugin")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Farts")]
[assembly: AssemblyTitle("Farts")]
[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 Farts
{
	[BepInPlugin("OniHazza.CustomFarts", "CustomWhoopieFarts", "1.0.0")]
	[BepInProcess("Lethal Company.exe")]
	public class Plugin : BaseUnityPlugin
	{
		private const string modGUID = "OniHazza.CustomFarts";

		private const string modName = "CustomWhoopieFarts";

		private const string modVersion = "1.0.0";

		private readonly Harmony harmony = new Harmony("OniHazza.CustomFarts");

		private static Plugin Instance;

		private ConfigEntry<bool> Enabled;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General.Toggles", "Enabled or nah", true, (ConfigDescription)null);
			if (Enabled.Value)
			{
				harmony.PatchAll(typeof(StartOfRoundPatch));
				harmony.PatchAll(typeof(WhoopiePatch));
			}
			else
			{
				LogInfo("Plugin is disabled.");
			}
		}

		internal static void LogInfo(string message)
		{
			((BaseUnityPlugin)Instance).Logger.Log((LogLevel)16, (object)message);
		}

		internal static void LogWarning(string message)
		{
			((BaseUnityPlugin)Instance).Logger.Log((LogLevel)4, (object)message);
		}

		internal static void LogError(string message)
		{
			((BaseUnityPlugin)Instance).Logger.Log((LogLevel)2, (object)message);
		}

		internal static void LogError(Exception ex)
		{
			((BaseUnityPlugin)Instance).Logger.Log((LogLevel)2, (object)ex);
		}
	}
	[HarmonyPatch(typeof(StartOfRound))]
	internal class StartOfRoundPatch
	{
		[HarmonyPatch("Start")]
		private static void Prefix()
		{
			Audioloader.Load();
		}
	}
	[HarmonyPatch(typeof(WhoopieCushionItem))]
	public class WhoopiePatch
	{
		[HarmonyPatch("Fart")]
		[HarmonyPrefix]
		private static void Prefix(WhoopieCushionItem __instance)
		{
			try
			{
				if (((Object)__instance.fartAudios[0]).name != ((Object)Audioloader.FartSounds.ToArray()[0]).name)
				{
					__instance.fartAudios = Audioloader.FartSounds.ToArray();
					Plugin.LogInfo($"Farts replaced with {Audioloader.FartSounds}");
				}
			}
			catch (Exception ex)
			{
				Plugin.LogError(ex);
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "Farts";

		public const string PLUGIN_NAME = "Farts";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace Farts.Utility
{
	internal class Audioloader
	{
		public static List<AudioClip> FartSounds = new List<AudioClip>();

		private static string FartDir = Path.Combine(Paths.PluginPath, "CustomFarts");

		private static string FartDirMM = Path.Combine(Paths.PluginPath, "Oni_Hazza-Real_Farts", "CustomFarts");

		private static bool FirstRun = true;

		public static void Load()
		{
			if (!FirstRun)
			{
				return;
			}
			FirstRun = false;
			string path = FartDir;
			if (!Directory.Exists(FartDir))
			{
				path = FartDirMM;
				Plugin.LogInfo("Normal directory not found, using mod manager directory");
			}
			string[] files = Directory.GetFiles(path);
			if (files.Length == 0)
			{
				Plugin.LogError("No files have been found.");
				return;
			}
			try
			{
				int index = 0;
				string[] array = files;
				foreach (string filePath in array)
				{
					SharedCoroutineStarter.StartCoroutine(LoadAudioClip(filePath, index, close: true));
				}
			}
			catch (Exception ex)
			{
				Plugin.LogError(ex.Message);
				Plugin.LogError("error in load method");
			}
		}

		private static IEnumerator LoadAudioClip(string filePath, int index, bool close)
		{
			Plugin.LogInfo("Loading " + filePath);
			UnityWebRequest loader = UnityWebRequestMultimedia.GetAudioClip(filePath, (AudioType)20);
			loader.SendWebRequest();
			while (!loader.isDone)
			{
				yield return null;
			}
			if (loader.error != null)
			{
				Plugin.LogError("Error Loading " + filePath + "\n" + loader.error);
				yield break;
			}
			AudioClip clip = DownloadHandlerAudioClip.GetContent(loader);
			if (Object.op_Implicit((Object)(object)clip) && (int)clip.loadState == 2)
			{
				((Object)clip).name = Path.GetFileName(filePath);
				FartSounds.Add(clip);
			}
		}
	}
	internal class SharedCoroutineStarter : MonoBehaviour
	{
		private static SharedCoroutineStarter _instance;

		public static Coroutine StartCoroutine(IEnumerator routine)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_instance == (Object)null)
			{
				_instance = new GameObject("Shared Coroutine Starter").AddComponent<SharedCoroutineStarter>();
				Object.DontDestroyOnLoad((Object)(object)_instance);
			}
			return ((MonoBehaviour)_instance).StartCoroutine(routine);
		}
	}
}