Decompiled source of MistBingBong v0.1.2

MistBingBong.dll

Decompiled 2 months 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 BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.SceneManagement;
using Zorro.Core;

[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("MistBingBong")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+2f79d25e011e178fcb33eb84a030139f3c0c8e6c")]
[assembly: AssemblyProduct("MIST bingong")]
[assembly: AssemblyTitle("MistBingBong")]
[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 MistBingBong
{
	[BepInPlugin("hu.ebot.mistbingbong", "Bing Bong Swapper", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		[CompilerGenerated]
		private sealed class <GetFile>d__7 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public string fullPath;

			public Plugin <>4__this;

			private AudioType <type>5__1;

			private UnityWebRequest <request>5__2;

			private AudioClip <clip>5__3;

			private SFX_Instance <newSfx>5__4;

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

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

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

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				int num = <>1__state;
				if (num == -3 || num == 1)
				{
					try
					{
					}
					finally
					{
						<>m__Finally1();
					}
				}
				<request>5__2 = null;
				<clip>5__3 = null;
				<newSfx>5__4 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_002a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0047: Unknown result type (might be due to invalid IL or missing references)
				//IL_006e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0074: Invalid comparison between Unknown and I4
				//IL_0067: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
				//IL_00fc: Invalid comparison between Unknown and I4
				//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
				//IL_018e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0193: Unknown result type (might be due to invalid IL or missing references)
				//IL_019e: Unknown result type (might be due to invalid IL or missing references)
				//IL_01af: Expected O, but got Unknown
				bool result;
				try
				{
					switch (<>1__state)
					{
					default:
						result = false;
						break;
					case 0:
						<>1__state = -1;
						<type>5__1 = (AudioType)0;
						if (fullPath.EndsWith(".wav"))
						{
							<type>5__1 = (AudioType)20;
						}
						else if (fullPath.EndsWith(".mp3"))
						{
							<type>5__1 = (AudioType)13;
						}
						if ((int)<type>5__1 == 0)
						{
							Logger.LogWarning((object)(fullPath + " cannot be loaded since it's not an mp3 OR wav file!"));
							result = false;
							break;
						}
						<request>5__2 = UnityWebRequestMultimedia.GetAudioClip("file://" + fullPath, <type>5__1);
						<>1__state = -3;
						<>2__current = <request>5__2.SendWebRequest();
						<>1__state = 1;
						result = true;
						break;
					case 1:
						<>1__state = -3;
						if ((int)<request>5__2.result != 1)
						{
							Logger.LogError((object)"Failed to load mp3!");
							result = false;
							<>m__Finally1();
							break;
						}
						<clip>5__3 = DownloadHandlerAudioClip.GetContent(<request>5__2);
						((Object)<clip>5__3).name = fullPath.Split(Path.DirectorySeparatorChar)[^1];
						Logger.LogInfo((object)"Making instance...");
						<newSfx>5__4 = ScriptableObject.CreateInstance<SFX_Instance>();
						<newSfx>5__4.clips = (AudioClip[])(object)new AudioClip[1] { <clip>5__3 };
						MistResponseGenerator.responses.Add(new BingBongResponse
						{
							subtitleID = "haha",
							sfx = <newSfx>5__4
						});
						<clip>5__3 = null;
						<newSfx>5__4 = null;
						<>m__Finally1();
						<request>5__2 = null;
						result = false;
						break;
					}
				}
				catch
				{
					//try-fault
					((IDisposable)this).Dispose();
					throw;
				}
				return result;
			}

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

			private void <>m__Finally1()
			{
				<>1__state = -1;
				if (<request>5__2 != null)
				{
					((IDisposable)<request>5__2).Dispose();
				}
			}

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

		public const string MIST_NAME = "MIST :3";

		internal static ManualLogSource Logger;

		private AssetBundle bundle;

		public static GameObject mistBong;

		public static GameObject mistBongAlternate;

		private Texture2D iconTexture = null;

		private void Awake()
		{
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Expected O, but got Unknown
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Expected O, but got Unknown
			//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cd: Expected O, but got Unknown
			//IL_0243: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_04cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d3: Expected O, but got Unknown
			//IL_03be: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03db: Expected O, but got Unknown
			//IL_03e0: Expected O, but got Unknown
			Logger = ((BaseUnityPlugin)this).Logger;
			Logger.LogInfo((object)"Bing Bong Modell swapper loaded!");
			Logger.LogInfo((object)"Finding asset bundle in root...");
			SceneManager.activeSceneChanged += OnSceneLoaded;
			bundle = AssetBundle.LoadFromFile(Path.Combine(Paths.PluginPath, "EBot-MistBingBong", "mistpeak"));
			Object[] array = bundle.LoadAllAssets();
			Object[] array2 = array;
			foreach (Object val in array2)
			{
				if (val.name == "IconDone")
				{
					iconTexture = (Texture2D)val;
				}
				else
				{
					if (((object)val).GetType() != typeof(GameObject))
					{
						continue;
					}
					if (val.name == "MistBong")
					{
						Logger.LogInfo((object)"MistBong is safe and sound!");
						mistBong = (GameObject)val;
						FaceManager faceManager = mistBong.AddComponent<FaceManager>();
						faceManager.faceRegular = ((Component)((IEnumerable<Transform>)mistBong.GetComponentsInChildren<Transform>(true)).FirstOrDefault((Func<Transform, bool>)((Transform t) => ((Object)t).name == "FacePanel"))).gameObject;
						faceManager.faceTalk = ((Component)((IEnumerable<Transform>)mistBong.GetComponentsInChildren<Transform>(true)).FirstOrDefault((Func<Transform, bool>)((Transform t) => ((Object)t).name == "TalkFace"))).gameObject;
						Item component = mistBong.GetComponent<Item>();
						SingletonAsset<ItemDatabase>.Instance.itemLookup[component.itemID] = component;
					}
					else if (val.name == "MistModelReplacable")
					{
						mistBongAlternate = (GameObject)val;
					}
				}
			}
			Renderer[] componentsInChildren = mistBong.GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val2 in componentsInChildren)
			{
				Material[] materials = val2.materials;
				foreach (Material val3 in materials)
				{
					Shader shader = Shader.Find("W/Character");
					val3.shader = shader;
					val3.SetVector("_Tint", new Vector4(0.75f, 0.75f, 0.75f, 1f));
				}
			}
			Renderer[] componentsInChildren2 = mistBongAlternate.GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val4 in componentsInChildren2)
			{
				Material[] materials2 = val4.materials;
				foreach (Material val5 in materials2)
				{
					Shader shader2 = Shader.Find("W/Character");
					val5.shader = shader2;
					val5.SetVector("_Tint", new Vector4(0.75f, 0.75f, 0.75f, 1f));
				}
			}
			IPunPrefabPool prefabPool = PhotonNetwork.PrefabPool;
			DefaultPool val6 = (DefaultPool)(object)((prefabPool is DefaultPool) ? prefabPool : null);
			if (val6 != null)
			{
				val6.ResourceCache["0_Items/BingBong"] = mistBong;
				val6.ResourceCache.Add("0_Items/MistBong", mistBong);
				Logger.LogInfo((object)"Registered custom mist bong!");
			}
			if (!File.Exists(Path.Combine(Paths.PluginPath, "EBot-MistBingBong", "onlymine")) && !File.Exists(Path.Combine(Paths.PluginPath, "EBot-MistBingBong", "onlymine.txt")))
			{
				Object[] array3 = array;
				foreach (Object val7 in array3)
				{
					if (val7.name.Contains("MISTV_"))
					{
						MistResponseGenerator.responses.Add(new BingBongResponse
						{
							subtitleID = "haha",
							sfx = (SFX_Instance)val7
						});
					}
				}
			}
			else
			{
				Logger.LogInfo((object)"Only your own custom voice lines will be loaded!");
			}
			string text = Path.Combine(Paths.PluginPath, "EBot-MistBingBong", "CustomMistLines");
			Logger.LogInfo((object)("Custom lines path: " + text));
			if (Directory.Exists(text))
			{
				Logger.LogInfo((object)"Found custom lines directory...");
				string[] files = Directory.GetFiles(text);
				Logger.LogInfo((object)$"Discovered {files.Length} custom lines!");
				string[] array4 = files;
				foreach (string path in array4)
				{
					Logger.LogInfo((object)("Loading: " + Path.Combine(text, path)));
					((MonoBehaviour)this).StartCoroutine(GetFile(Path.Combine(text, path)));
				}
			}
			Harmony val8 = new Harmony("hu.ebot.mistbingbong");
			val8.PatchAll();
		}

		[IteratorStateMachine(typeof(<GetFile>d__7))]
		private IEnumerator GetFile(string fullPath)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <GetFile>d__7(0)
			{
				<>4__this = this,
				fullPath = fullPath
			};
		}

		private void OnSceneLoaded(Scene oldScene, Scene nextScene)
		{
			//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			if (((Scene)(ref nextScene)).name == "Title")
			{
				GameObject[] array = Resources.FindObjectsOfTypeAll<GameObject>();
				foreach (GameObject val in array)
				{
					if (((Object)val).name.Equals("BingBong", StringComparison.OrdinalIgnoreCase))
					{
						Item component = val.GetComponent<Item>();
						if (Object.op_Implicit((Object)(object)component))
						{
							component.UIData.icon = iconTexture;
						}
					}
					if (!((Object)val).name.Equals("BingBong_Prop Variant", StringComparison.OrdinalIgnoreCase))
					{
						continue;
					}
					Transform[] componentsInChildren = val.GetComponentsInChildren<Transform>(true);
					foreach (Transform val2 in componentsInChildren)
					{
						if (((Object)((Component)val2).gameObject).name == "Bing Bong Plush")
						{
							GameObject gameObject = ((Component)val2).gameObject;
							GameObject val3 = Object.Instantiate<GameObject>(mistBongAlternate);
							val3.transform.position = val2.position;
							val3.transform.parent = gameObject.transform.parent;
							FaceManager faceManager = val.AddComponent<FaceManager>();
							Item component2 = val.GetComponent<Item>();
							component2.UIData.itemName = "mist";
							component2.UIData.icon = iconTexture;
							SingletonAsset<ItemDatabase>.Instance.itemLookup[component2.itemID] = component2;
							faceManager.faceRegular = GameObject.Find("FacePanel");
							faceManager.faceTalk = GameObject.Find("FaceTalk");
							val3.transform.rotation = Quaternion.Euler(0f, 0f, 0f);
							Object.Destroy((Object)(object)gameObject);
						}
					}
				}
			}
			if (((Scene)(ref nextScene)).name == "Airport")
			{
				GameObject val4 = GameObject.Find("Bing Bong Plush");
				GameObject val5 = Object.Instantiate<GameObject>(mistBongAlternate);
				val5.transform.position = val4.transform.position;
				val5.transform.parent = val4.transform.parent;
				Object.Destroy((Object)(object)val4);
			}
		}
	}
	[HarmonyPatch(typeof(SingleItemSpawner), "TrySpawnItems")]
	public class SingleItemSpawnerPatch
	{
		public static bool Prefix(SingleItemSpawner __instance, ref List<PhotonView> __result)
		{
			if (((Object)__instance.prefab).name == "BingBong")
			{
				__instance.prefab = Plugin.mistBong;
			}
			return true;
		}
	}
	public static class MistResponseGenerator
	{
		public static List<BingBongResponse> responses = new List<BingBongResponse>();

		public static BingBongResponse GetResponse(int index)
		{
			return responses[index];
		}
	}
	[HarmonyPatch(typeof(Action_AskBingBong), "Ask")]
	public class BingBongAskPatch
	{
		[CompilerGenerated]
		private sealed class <AskRoutine>d__3 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public int index;

			public bool spamming;

			public Action_AskBingBong __instance;

			public Item item;

			private float <t>5__1;

			private FieldInfo <subtitleRoutine>5__2;

			private BingBongResponse <response>5__3;

			private AudioClip <clip>5__4;

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

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

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

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<subtitleRoutine>5__2 = null;
				<response>5__3 = null;
				<clip>5__4 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_011a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0124: Expected O, but got Unknown
				//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
				//IL_00da: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<t>5__1 = 0f;
					goto IL_0081;
				case 1:
					<>1__state = -1;
					goto IL_0081;
				case 2:
					{
						<>1__state = -1;
						if (<subtitleRoutine>5__2.GetValue(__instance) != null)
						{
							((MonoBehaviour)__instance).StopCoroutine((Coroutine)<subtitleRoutine>5__2.GetValue(__instance));
						}
						<response>5__3 = MistResponseGenerator.GetResponse(index);
						if ((Object)(object)<response>5__3.sfx != (Object)null)
						{
							<clip>5__4 = <response>5__3.sfx.clips[0];
							<subtitleRoutine>5__2.SetValue(__instance, ((MonoBehaviour)__instance).StartCoroutine(FaceAnimRoutine(<response>5__3.subtitleID, __instance, <clip>5__4.length)));
							__instance.source.PlayOneShot(<clip>5__4);
							<clip>5__4 = null;
						}
						return false;
					}
					IL_0081:
					if (<t>5__1 < 0.5f)
					{
						item.holderCharacter.refs.items.UpdateAttachedItem();
						<t>5__1 += Time.deltaTime;
						<>2__current = null;
						<>1__state = 1;
						return true;
					}
					if (spamming)
					{
						return false;
					}
					<subtitleRoutine>5__2 = AccessTools.Field(typeof(Action_AskBingBong), "subtitleRoutine");
					__instance.source.Stop();
					<>2__current = (object)new WaitForSeconds(0.5f);
					<>1__state = 2;
					return true;
				}
			}

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

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

		[CompilerGenerated]
		private sealed class <FaceAnimRoutine>d__2 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public string subtitleID;

			public Action_AskBingBong __instance;

			public float length;

			private FaceManager <faceManager>5__1;

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

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

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

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

			private bool MoveNext()
			{
				//IL_0031: Unknown result type (might be due to invalid IL or missing references)
				//IL_003b: Expected O, but got Unknown
				//IL_0074: Unknown result type (might be due to invalid IL or missing references)
				//IL_007e: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = (object)new WaitForSeconds(0.19f);
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					<faceManager>5__1 = ((Component)__instance).gameObject.GetComponent<FaceManager>();
					<faceManager>5__1.Swap();
					<>2__current = (object)new WaitForSeconds(length);
					<>1__state = 2;
					return true;
				case 2:
					<>1__state = -1;
					<faceManager>5__1.Swap();
					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 int lastNum;

		public static bool Prefix(Action_AskBingBong __instance, object[] __args)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected O, but got Unknown
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Expected O, but got Unknown
			FieldInfo fieldInfo = AccessTools.DeclaredField(typeof(ItemActionBase), "item");
			Item val = (Item)fieldInfo.GetValue(__instance);
			if ((Object)(object)val.holderCharacter == (Object)null)
			{
				return false;
			}
			FieldInfo fieldInfo2 = AccessTools.Field(typeof(Action_AskBingBong), "askRoutine");
			if (fieldInfo2.GetValue(__instance) != null)
			{
				((MonoBehaviour)__instance).StopCoroutine((Coroutine)fieldInfo2.GetValue(__instance));
			}
			int num = Random.RandomRangeInt(0, MistResponseGenerator.responses.Count);
			Console.WriteLine($"Available lines: {MistResponseGenerator.responses.Count}");
			Console.WriteLine($"Rolled line: {num} last: {lastNum}");
			while (lastNum == num)
			{
				num = Random.RandomRangeInt(0, MistResponseGenerator.responses.Count);
				Console.WriteLine($"Rolled again: {num} last: {lastNum}");
			}
			lastNum = num;
			Console.WriteLine(((Object)MistResponseGenerator.GetResponse(num).sfx.clips[0]).name);
			((MonoBehaviour)__instance).StartCoroutine(AskRoutine(num, (bool)__args[1], __instance, val));
			__instance.squishAnim.SetTrigger("Squish");
			return false;
		}

		[IteratorStateMachine(typeof(<FaceAnimRoutine>d__2))]
		private static IEnumerator FaceAnimRoutine(string subtitleID, Action_AskBingBong __instance, float length)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <FaceAnimRoutine>d__2(0)
			{
				subtitleID = subtitleID,
				__instance = __instance,
				length = length
			};
		}

		[IteratorStateMachine(typeof(<AskRoutine>d__3))]
		private static IEnumerator AskRoutine(int index, bool spamming, Action_AskBingBong __instance, Item item)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <AskRoutine>d__3(0)
			{
				index = index,
				spamming = spamming,
				__instance = __instance,
				item = item
			};
		}
	}
	[HarmonyPatch]
	public static class TextPatch
	{
		private static MethodBase TargetMethod()
		{
			return AccessTools.Method(typeof(LocalizedText), "GetText", new Type[2]
			{
				typeof(string),
				typeof(bool)
			}, (Type[])null);
		}

		public static bool Prefix(object[] __args, ref string __result)
		{
			if ((string)__args[0] == "NAME_mist")
			{
				__result = "MIST :3";
				return false;
			}
			if (((string)__args[0]).Contains("shake"))
			{
				__result = "Shake";
				return false;
			}
			return true;
		}
	}
	public class FaceManager : MonoBehaviour
	{
		public GameObject faceRegular;

		public GameObject faceTalk;

		public void Swap()
		{
			faceRegular.SetActive(!faceRegular.activeSelf);
			faceTalk.SetActive(!faceTalk.activeSelf);
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "MistBingBong";

		public const string PLUGIN_NAME = "MIST bingong";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}