plugins/com.github.krils.Poop.dll

Decompiled 3 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using PEAKLib.Core;
using PEAKLib.Items.UnityEditor;
using Photon.Pun;
using Poop.Utilities;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("com.github.krils.poop")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.3.0.0")]
[assembly: AssemblyInformationalVersion("0.3.0+b7ec7033a4d2b3d9ee19f8070d9ecbbbfe4c2ebf")]
[assembly: AssemblyProduct("com.github.krils.poop")]
[assembly: AssemblyTitle("Poop")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.3.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.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 BepInEx
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class BepInAutoPluginAttribute : Attribute
	{
		public BepInAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace BepInEx.Preloader.Core.Patching
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class PatcherAutoPluginAttribute : Attribute
	{
		public PatcherAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace Poop
{
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("com.github.krils.poop", "Poop", "0.3.0")]
	public class Plugin : BaseUnityPlugin
	{
		public static List<AudioClip> FartClips = new List<AudioClip>();

		public const string Id = "com.github.krils.poop";

		internal static ManualLogSource? Log { get; private set; }

		public static string Name => "Poop";

		public static string Version => "0.3.0";

		private void Awake()
		{
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			LoadFartClip("Poop.Resources.dad fart.wav", "DadFart");
			LoadFartClip("Poop.Resources.ploop.wav", "Ploop");
			LoadFartClip("Poop.Resources.toot.wav", "Toot");
			Debug.Log((object)$"DID MUH SOUNDS LOAD {FartClips.Count}");
			BundleLoader.LoadBundleWithName((BaseUnityPlugin)(object)this, "poop.peakbundle", (Action<PeakBundle>)delegate(PeakBundle peakBundle)
			{
				UnityItemContent val2 = peakBundle.LoadAsset<UnityItemContent>("PooContent");
				GameObject itemPrefab = val2.ItemPrefab;
				itemPrefab.AddComponent<PlayTootSound>();
				peakBundle.Mod.RegisterContent();
			});
			LocalizedText.mainTable["NAME_POO POO"] = new List<string>(15)
			{
				"Poop", "Poop", "Poop", "Poop", "Poop", "Poop", "Poop", "Poop", "Poop", "Poop",
				"Poop", "Poop", "Poop", "Poop", "Poop"
			};
			Harmony val = new Harmony("com.github.krils.poop");
			val.PatchAll();
		}

		private void LoadFartClip(string resourceName, string name)
		{
			Assembly executingAssembly = Assembly.GetExecutingAssembly();
			using Stream stream = executingAssembly.GetManifestResourceStream(resourceName);
			if (stream == null)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("Resource not found: " + resourceName));
				return;
			}
			byte[] wavFileBytes;
			using (MemoryStream memoryStream = new MemoryStream())
			{
				stream.CopyTo(memoryStream);
				wavFileBytes = memoryStream.ToArray();
			}
			FartClips.Add(WavUtility.ToAudioClip(wavFileBytes, name));
		}
	}
}
namespace Poop.Utilities
{
	public class PlayTootSound : MonoBehaviour
	{
		public void PlayToot()
		{
			if (Plugin.FartClips == null || Plugin.FartClips.Count == 0)
			{
				Debug.LogWarning((object)"No fart clip was loaded :(");
				return;
			}
			int num = new Random().Next(0, Plugin.FartClips.Count);
			PhotonView component = ((Component)this).GetComponent<PhotonView>();
			if ((Object)(object)component == (Object)null)
			{
				Debug.LogWarning((object)"PhotonView not found on PlayTootSound GameObject.");
				return;
			}
			component.RPC("RPCA_PlayToot", (RpcTarget)0, new object[1] { num });
		}

		[PunRPC]
		public void RPCA_PlayToot(int fartIndex)
		{
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: 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)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: 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_00a1: 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_00b8: Expected O, but got Unknown
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			if (Plugin.FartClips == null || fartIndex < 0 || fartIndex >= Plugin.FartClips.Count)
			{
				Debug.LogWarning((object)$"Invalid fart index: {fartIndex}");
				return;
			}
			SFX_Instance val = ScriptableObject.CreateInstance<SFX_Instance>();
			val.clips = (AudioClip[])(object)new AudioClip[1] { Plugin.FartClips[fartIndex] };
			val.settings = new SFX_Settings
			{
				volume = 0.8f,
				volume_Variation = 0.2f,
				pitch = 1f,
				pitch_Variation = 0.1f,
				spatialBlend = 1f,
				dopplerLevel = 1f,
				range = 150f,
				cooldown = 0.02f,
				maxInstances_NOT_IMPLEMENTED = 5
			};
			val.Play(((Component)this).transform.position);
		}
	}
	internal static class WavUtility
	{
		public static AudioClip ToAudioClip(byte[] wavFileBytes, string name)
		{
			if (wavFileBytes == null)
			{
				throw new ArgumentNullException("wavFileBytes");
			}
			if (wavFileBytes.Length < 44)
			{
				throw new ArgumentException("WAV data too short");
			}
			int num = BitConverter.ToInt16(wavFileBytes, 22);
			int num2 = BitConverter.ToInt32(wavFileBytes, 24);
			int num3 = BitConverter.ToInt16(wavFileBytes, 34);
			int i = 12;
			int num4 = -1;
			int num5 = 0;
			int num6;
			for (; i + 8 <= wavFileBytes.Length; i += 8 + num6)
			{
				string @string = Encoding.ASCII.GetString(wavFileBytes, i, 4);
				num6 = BitConverter.ToInt32(wavFileBytes, i + 4);
				if (@string == "data")
				{
					num4 = i + 8;
					num5 = num6;
					break;
				}
			}
			if (num4 < 0 || num4 + num5 > wavFileBytes.Length)
			{
				throw new Exception("Invalid WAV file: data chunk not found or out of range");
			}
			int num7 = num3 / 8;
			int num8 = num5 / num7;
			float[] array = new float[num8];
			switch (num3)
			{
			case 16:
			{
				int num10 = 0;
				for (int k = num4; k < num4 + num5; k += 2)
				{
					short num11 = BitConverter.ToInt16(wavFileBytes, k);
					array[num10++] = (float)num11 / 32768f;
				}
				break;
			}
			case 8:
			{
				int num9 = 0;
				for (int j = num4; j < num4 + num5; j++)
				{
					array[num9++] = (float)(wavFileBytes[j] - 128) / 128f;
				}
				break;
			}
			default:
				throw new NotSupportedException("Only 8-bit and 16-bit PCM WAV files are supported");
			}
			int num12 = num8 / num;
			AudioClip val = AudioClip.Create(name, num12, num, num2, false);
			val.SetData(array, 0);
			return val;
		}
	}
}
namespace Poop.Patches
{
	[HarmonyPatch(typeof(Action_RestoreHunger))]
	public class PoopPatch
	{
		[CompilerGenerated]
		private sealed class <SpawnRoutine>d__5 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public float timeout;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <SpawnRoutine>d__5(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_001e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0028: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = (object)new WaitForSeconds(timeout);
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					PooQueued = true;
					SpawnPoo();
					PooQueued = false;
					return false;
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		private static bool attached;

		public static bool PooQueued { get; set; }

		[IteratorStateMachine(typeof(<SpawnRoutine>d__5))]
		public static IEnumerator SpawnRoutine(float timeout)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <SpawnRoutine>d__5(0)
			{
				timeout = timeout
			};
		}

		public static void SpawnPoo()
		{
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: 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_007c: 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_0088: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = ((IEnumerable<GameObject>)Resources.FindObjectsOfTypeAll<GameObject>()).FirstOrDefault((Func<GameObject, bool>)((GameObject g) => ((Object)g).name == "com.github.krils.poop:PooPoo"));
			if (!((Object)(object)val == (Object)null))
			{
				GameObject val2 = GameObject.Find("MainCamera");
				Vector3 val3 = default(Vector3);
				((Vector3)(ref val3))..ctor(val2.transform.position.x, val2.transform.position.y - 1f, val2.transform.position.z);
				Quaternion identity = Quaternion.identity;
				GameObject val4 = PhotonNetwork.InstantiateItem("com.github.krils.poop:PooPoo", val3, identity);
				val4.gameObject.GetComponentInChildren<PlayTootSound>().PlayToot();
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch("RunAction")]
		public static void StartPooTimer(Action_RestoreHunger __instance)
		{
			if (!PooQueued)
			{
				float num = 180f;
				float num2 = 300f;
				float timeout = Random.Range(num, num2);
				GameObject val = GameObject.Find("MainCamera");
				if (!attached)
				{
					val.AddComponent<DummyScript>();
					attached = true;
				}
				((MonoBehaviour)val.GetComponentInChildren<DummyScript>()).StartCoroutine(SpawnRoutine(timeout));
			}
		}
	}
	public class DummyScript : MonoBehaviour
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}