Decompiled source of FoxyJumpscare v1.0.0

BepInEx/plugins/lammas123.FoxyJumpscare.dll

Decompiled 3 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
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.Core.Logging.Interpolation;
using BepInEx.IL2CPP;
using BepInEx.IL2CPP.Utils;
using BepInEx.Logging;
using CrabDevKit.Intermediary;
using CrabDevKit.Utilities;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using SteamworksNative;
using UnhollowerBaseLib;
using UnhollowerRuntimeLib;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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 FoxyJumpscare
{
	internal static class JumpscareManager
	{
		private static class Patches
		{
			[HarmonyPatch(typeof(MonoBehaviourPublicObInVoAwVoVoVoVoVoVoUnique), "Awake")]
			[HarmonyPostfix]
			internal static void PostMainManagerAwake(MonoBehaviourPublicObInVoAwVoVoVoVoVoVoUnique __instance)
			{
				if (!((Object)(object)__instance != (Object)(object)MonoBehaviourPublicObInVoAwVoVoVoVoVoVoUnique.Instance))
				{
					TryLoadBundle();
					if (Bundle != null)
					{
						MonoBehaviourExtensions.StartCoroutine((MonoBehaviour)(object)PrefabStore, CoroJumpscareLoop());
					}
				}
			}
		}

		internal static AssetBundle Bundle;

		internal static GameObject Prefab;

		internal static AudioClip Clip;

		internal static MonoBehaviourPublicGaotUnique PrefabStore;

		internal static AudioSource ClipStore;

		internal static void Init()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			new Harmony("FoxyJumpscare.Manager").PatchAll(typeof(Patches));
		}

		internal static void Jumpscare()
		{
			MonoBehaviourExtensions.StartCoroutine((MonoBehaviour)(object)PrefabStore, CoroJumpscare());
		}

		private static IEnumerator CoroJumpscare()
		{
			float start = Time.time;
			GameObject go = Object.Instantiate<GameObject>(Prefab);
			Object.DontDestroyOnLoad((Object)(object)go);
			MonoBehaviourPublicAuhibuAusoObInAuUnique.Instance.source.PlayOneShot(Clip, 1f);
			RawImage img = go.GetComponentInChildren<RawImage>();
			float frameHeight = 1f / 14f;
			while (true)
			{
				int num = (int)((Time.time - start) * 24f);
				if (num >= 14)
				{
					break;
				}
				img.uvRect = new Rect(0f, 1f - frameHeight * (float)(num + 1), 1f, frameHeight);
				yield return null;
			}
			Object.Destroy((Object)(object)go);
		}

		private static void TryLoadBundle()
		{
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Expected O, but got Unknown
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Expected O, but got Unknown
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Expected O, but got Unknown
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			if (Bundle != null)
			{
				return;
			}
			using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("FoxyJumpscare.Assets.foxy");
			if (stream == null)
			{
				((BasePlugin)FoxyJumpscare.Instance).Log.LogWarning((object)"The foxy asset bundle is missing!");
				return;
			}
			using MemoryStream memoryStream = new MemoryStream();
			stream.CopyTo(memoryStream);
			Bundle = AssetBundle.LoadFromMemory(Il2CppStructArray<byte>.op_Implicit(memoryStream.ToArray()));
			if (Bundle == null)
			{
				((BasePlugin)FoxyJumpscare.Instance).Log.LogWarning((object)"Failed to load the foxy asset bundle!");
				return;
			}
			Prefab = new GameObject(((Il2CppObjectBase)Bundle.LoadAsset("Canvas", Il2CppType.Of<GameObject>())).Pointer);
			Clip = new AudioClip(((Il2CppObjectBase)Bundle.LoadAsset("scare", Il2CppType.Of<AudioClip>())).Pointer);
			GameObject val = new GameObject("JumpscareAssets");
			Object.DontDestroyOnLoad((Object)val);
			PrefabStore = val.AddComponent<MonoBehaviourPublicGaotUnique>();
			PrefabStore.other = Prefab;
			ClipStore = val.AddComponent<AudioSource>();
			ClipStore.clip = Clip;
			ClipStore.volume = 0f;
		}

		private static IEnumerator CoroJumpscareLoop()
		{
			while (true)
			{
				yield return (object)new WaitForSeconds(1f);
				if (FoxyJumpscare.Instance.Chance.Value <= 0 || Random.Range(0, FoxyJumpscare.Instance.Chance.Value) != 0)
				{
					continue;
				}
				if (MonoBehaviourPublicObInUIgaStCSBoStcuCSUnique.Instance.IsLobbyOwner())
				{
					Jumpscare();
					if (FoxyJumpscare.Instance.Networked.Value)
					{
						JumpscareNet.ServerSendJumpscare();
					}
				}
				else if (!FoxyJumpscare.Instance.Networked.Value || MonoBehaviourPublicObInUIgaStCSBoStcuCSUnique.Instance.currentLobby == CSteamID.Nil || SteamMatchmaking.GetLobbyData(MonoBehaviourPublicObInUIgaStCSBoStcuCSUnique.Instance.currentLobby, "lammas123.FoxyJumpscare.Networked") != "1")
				{
					Jumpscare();
				}
			}
		}
	}
	internal static class JumpscareNet
	{
		private static class Patches
		{
			private static bool _shouldSend;

			[HarmonyPatch(typeof(MonoBehaviourPublicObInUIgaStCSBoStcuCSUnique), "JoinLobby")]
			[HarmonyPrefix]
			internal static void PreSteamManagerJoinLobby()
			{
				if (!MonoBehaviourPublicObInUIgaStCSBoStcuCSUnique.Instance.IsLobbyOwner())
				{
					_shouldSend = true;
				}
			}

			[HarmonyPatch(typeof(MonoBehaviourPublicUIInUIByUIUnique), "LoadMap")]
			[HarmonyPrefix]
			internal static void PreClientHandleLoadMap()
			{
				if (!MonoBehaviourPublicObInUIgaStCSBoStcuCSUnique.Instance.IsLobbyOwner() && _shouldSend)
				{
					_shouldSend = false;
					if (FoxyJumpscare.Instance.Networked.Value)
					{
						ClientSendNetworked(networked: true);
					}
				}
			}

			[HarmonyPatch(typeof(MonoBehaviourPublicCSDi2UIInstObUIloDiUnique), "StartLobby")]
			[HarmonyPatch(typeof(MonoBehaviourPublicCSDi2UIInstObUIloDiUnique), "StartPracticeLobby")]
			[HarmonyPostfix]
			internal static void PostLobbyManagerStartLobby()
			{
				//IL_000f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0029: Unknown result type (might be due to invalid IL or missing references)
				NetworkedSteamIds.Clear();
				SteamMatchmaking.SetLobbyData(MonoBehaviourPublicObInUIgaStCSBoStcuCSUnique.Instance.currentLobby, "lammas123.FoxyJumpscare", "1.0.0");
				SteamMatchmaking.SetLobbyData(MonoBehaviourPublicObInUIgaStCSBoStcuCSUnique.Instance.currentLobby, "lammas123.FoxyJumpscare.Networked", FoxyJumpscare.Instance.Networked.Value ? "1" : "0");
			}

			[HarmonyPatch(typeof(MonoBehaviourPublicCSDi2UIInstObUIloDiUnique), "OnPlayerJoinLeaveUpdate")]
			[HarmonyPostfix]
			internal static void PostLobbyManagerOnPlayerJoinLeaveUpdate(CSteamID param_1, bool param_2)
			{
				//IL_0017: Unknown result type (might be due to invalid IL or missing references)
				if (!(!MonoBehaviourPublicObInUIgaStCSBoStcuCSUnique.Instance.IsLobbyOwner() || param_2))
				{
					NetworkedSteamIds.Remove(param_1);
				}
			}

			[HarmonyPatch(typeof(MonoBehaviourPublicCSDi2UIInstObUIloDiUnique), "CloseLobby")]
			[HarmonyPostfix]
			internal static void PostLobbyManagerCloseLobby()
			{
				NetworkedSteamIds.Clear();
			}
		}

		[CompilerGenerated]
		private static class <>O
		{
			public static MessageHandler <0>__ServerJumpscare;

			public static MessageHandler <1>__ClientNetworked;
		}

		private const string SERVER_JUMPSCARE = "lammas123.FoxyJumpscare:ServerJumpscare";

		private const string CLIENT_NETWORKED = "lammas123.FoxyJumpscare:ClientNetworked";

		private static readonly HashSet<CSteamID> NetworkedSteamIds = new HashSet<CSteamID>();

		internal static void Init()
		{
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Expected O, but got Unknown
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: 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: Expected O, but got Unknown
			FoxyJumpscare.Instance.Networked.SettingChanged += delegate
			{
				//IL_0005: Unknown result type (might be due to invalid IL or missing references)
				//IL_000a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0028: Unknown result type (might be due to invalid IL or missing references)
				if (!(MonoBehaviourPublicObInUIgaStCSBoStcuCSUnique.Instance.currentLobby == CSteamID.Nil))
				{
					if (MonoBehaviourPublicObInUIgaStCSBoStcuCSUnique.Instance.IsLobbyOwner())
					{
						SteamMatchmaking.SetLobbyData(MonoBehaviourPublicObInUIgaStCSBoStcuCSUnique.Instance.currentLobby, "lammas123.FoxyJumpscare.Networked", FoxyJumpscare.Instance.Networked.Value ? "1" : "0");
					}
					else
					{
						ClientSendNetworked(FoxyJumpscare.Instance.Networked.Value);
					}
				}
			};
			object obj = <>O.<0>__ServerJumpscare;
			if (obj == null)
			{
				MessageHandler val = ServerJumpscare;
				<>O.<0>__ServerJumpscare = val;
				obj = (object)val;
			}
			CrabNet.RegisterMessageHandler("lammas123.FoxyJumpscare:ServerJumpscare", (MessageHandler)obj);
			object obj2 = <>O.<1>__ClientNetworked;
			if (obj2 == null)
			{
				MessageHandler val2 = ClientNetworked;
				<>O.<1>__ClientNetworked = val2;
				obj2 = (object)val2;
			}
			CrabNet.RegisterMessageHandler("lammas123.FoxyJumpscare:ClientNetworked", (MessageHandler)obj2);
			new Harmony("FoxyJumpscare.Net").PatchAll(typeof(Patches));
		}

		private static IEnumerable<CSteamID> GetAllSteamIds()
		{
			int members = SteamMatchmaking.GetNumLobbyMembers(MonoBehaviourPublicObInUIgaStCSBoStcuCSUnique.Instance.currentLobby);
			for (int i = 0; i < members; i++)
			{
				CSteamID lobbyMemberByIndex = SteamMatchmaking.GetLobbyMemberByIndex(MonoBehaviourPublicObInUIgaStCSBoStcuCSUnique.Instance.currentLobby, i);
				if (NetworkedSteamIds.Contains(lobbyMemberByIndex))
				{
					yield return lobbyMemberByIndex;
				}
			}
		}

		internal static void ServerSendJumpscare()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Expected O, but got Unknown
			ObjectPublicIDisposableLi1ByInByBoUnique val = new ObjectPublicIDisposableLi1ByInByBoUnique();
			CrabNet.SendMessage("lammas123.FoxyJumpscare:ServerJumpscare", val, GetAllSteamIds());
			val.Dispose();
		}

		private static void ServerJumpscare(ulong clientId, ObjectPublicIDisposableLi1ByInByBoUnique packet)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			if (clientId == SteamManagerExtensions[MonoBehaviourPublicObInUIgaStCSBoStcuCSUnique.Instance].m_SteamID && FoxyJumpscare.Instance.Networked.Value && JumpscareManager.Bundle != null)
			{
				JumpscareManager.Jumpscare();
			}
		}

		internal static void ClientSendNetworked(bool networked)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Expected O, but got Unknown
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			ObjectPublicIDisposableLi1ByInByBoUnique val = new ObjectPublicIDisposableLi1ByInByBoUnique();
			PacketExtensions.Write(val, networked);
			CrabNet.SendMessage("lammas123.FoxyJumpscare:ClientNetworked", val, (IEnumerable<CSteamID>)new <>z__ReadOnlySingleElementList<CSteamID>(SteamManagerExtensions[MonoBehaviourPublicObInUIgaStCSBoStcuCSUnique.Instance]));
			val.Dispose();
		}

		private static void ClientNetworked(ulong clientId, ObjectPublicIDisposableLi1ByInByBoUnique packet)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			if (MonoBehaviourPublicObInUIgaStCSBoStcuCSUnique.Instance.IsLobbyOwner())
			{
				if (PacketExtensions.ReadBool(packet, true))
				{
					NetworkedSteamIds.Add(new CSteamID(clientId));
				}
				else
				{
					NetworkedSteamIds.Remove(new CSteamID(clientId));
				}
			}
		}
	}
	[BepInPlugin("lammas123.FoxyJumpscare", "FoxyJumpscare", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public sealed class FoxyJumpscare : BasePlugin
	{
		internal ConfigEntry<bool> Networked;

		internal ConfigEntry<int> Chance;

		internal static FoxyJumpscare Instance { get; private set; }

		public override void Load()
		{
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Expected O, but got Unknown
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Expected O, but got Unknown
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Expected O, but got Unknown
			CultureInfo.CurrentCulture = CultureInfo.InvariantCulture;
			CultureInfo.CurrentUICulture = CultureInfo.InvariantCulture;
			CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture;
			CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.InvariantCulture;
			Instance = this;
			Networked = ((BasePlugin)this).Config.Bind<bool>("FoxyJumpscare", "Networked", true, new ConfigDescription("If networking is enabled on the host, all clients that also have networking enabled will only be jumpscared when the host is jumpscared. This means everyone gets jumpscared together. If networking is disabled on you or the host's end, you'll be jumpscared individually.", (AcceptableValueBase)null, Array.Empty<object>()));
			Chance = ((BasePlugin)this).Config.Bind<int>("FoxyJumpscare", "Chance", 10000, new ConfigDescription("The 1 in X chance every second to be jumpscared by Foxy. A chance of 0 (or negative) disables this chance.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, int.MaxValue), Array.Empty<object>()));
			JumpscareManager.Init();
			JumpscareNet.Init();
			ManualLogSource log = ((BasePlugin)this).Log;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(16, 2, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Initialized [");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("FoxyJumpscare");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" v");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("1.0.0");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("]");
			}
			log.LogInfo(val);
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "lammas123.FoxyJumpscare";

		public const string PLUGIN_NAME = "FoxyJumpscare";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}
[CompilerGenerated]
internal sealed class <>z__ReadOnlySingleElementList<T> : IEnumerable, ICollection, IList, IEnumerable<T>, IReadOnlyCollection<T>, IReadOnlyList<T>, ICollection<T>, IList<T>
{
	private sealed class Enumerator : IDisposable, IEnumerator, IEnumerator<T>
	{
		object IEnumerator.Current => _item;

		T IEnumerator<T>.Current => _item;

		public Enumerator(T item)
		{
			_item = item;
		}

		bool IEnumerator.MoveNext()
		{
			if (!_moveNextCalled)
			{
				return _moveNextCalled = true;
			}
			return false;
		}

		void IEnumerator.Reset()
		{
			_moveNextCalled = false;
		}

		void IDisposable.Dispose()
		{
		}
	}

	int ICollection.Count => 1;

	bool ICollection.IsSynchronized => false;

	object ICollection.SyncRoot => this;

	object IList.this[int index]
	{
		get
		{
			if (index != 0)
			{
				throw new IndexOutOfRangeException();
			}
			return _item;
		}
		set
		{
			throw new NotSupportedException();
		}
	}

	bool IList.IsFixedSize => true;

	bool IList.IsReadOnly => true;

	int IReadOnlyCollection<T>.Count => 1;

	T IReadOnlyList<T>.this[int index]
	{
		get
		{
			if (index != 0)
			{
				throw new IndexOutOfRangeException();
			}
			return _item;
		}
	}

	int ICollection<T>.Count => 1;

	bool ICollection<T>.IsReadOnly => true;

	T IList<T>.this[int index]
	{
		get
		{
			if (index != 0)
			{
				throw new IndexOutOfRangeException();
			}
			return _item;
		}
		set
		{
			throw new NotSupportedException();
		}
	}

	public <>z__ReadOnlySingleElementList(T item)
	{
		_item = item;
	}

	IEnumerator IEnumerable.GetEnumerator()
	{
		return new Enumerator(_item);
	}

	void ICollection.CopyTo(Array array, int index)
	{
		array.SetValue(_item, index);
	}

	int IList.Add(object value)
	{
		throw new NotSupportedException();
	}

	void IList.Clear()
	{
		throw new NotSupportedException();
	}

	bool IList.Contains(object value)
	{
		return EqualityComparer<T>.Default.Equals(_item, (T)value);
	}

	int IList.IndexOf(object value)
	{
		if (!EqualityComparer<T>.Default.Equals(_item, (T)value))
		{
			return -1;
		}
		return 0;
	}

	void IList.Insert(int index, object value)
	{
		throw new NotSupportedException();
	}

	void IList.Remove(object value)
	{
		throw new NotSupportedException();
	}

	void IList.RemoveAt(int index)
	{
		throw new NotSupportedException();
	}

	IEnumerator<T> IEnumerable<T>.GetEnumerator()
	{
		return new Enumerator(_item);
	}

	void ICollection<T>.Add(T item)
	{
		throw new NotSupportedException();
	}

	void ICollection<T>.Clear()
	{
		throw new NotSupportedException();
	}

	bool ICollection<T>.Contains(T item)
	{
		return EqualityComparer<T>.Default.Equals(_item, item);
	}

	void ICollection<T>.CopyTo(T[] array, int arrayIndex)
	{
		array[arrayIndex] = _item;
	}

	bool ICollection<T>.Remove(T item)
	{
		throw new NotSupportedException();
	}

	int IList<T>.IndexOf(T item)
	{
		if (!EqualityComparer<T>.Default.Equals(_item, item))
		{
			return -1;
		}
		return 0;
	}

	void IList<T>.Insert(int index, T item)
	{
		throw new NotSupportedException();
	}

	void IList<T>.RemoveAt(int index)
	{
		throw new NotSupportedException();
	}
}