Decompiled source of Foxy Jumpscare v1.1.0

plugins/FoxyJumpscare.dll

Decompiled 5 days ago
using System;
using System.CodeDom.Compiler;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using Agents;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using BepInEx.Unity.IL2CPP.Utils.Collections;
using FoxyJumpscare.Resources;
using HarmonyLib;
using Il2CppInterop.Runtime.Injection;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem;
using Il2CppSystem.Reflection;
using Microsoft.CodeAnalysis;
using Player;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyFileVersion("1.1.0")]
[assembly: AssemblyInformationalVersion("1.1.0")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyVersion("1.1.0.0")]
[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;
		}
	}
}
internal class ManifestInfo
{
	internal const string TSName = "Foxy_Jumpscare";

	internal const string TSDescription = "1 in 10000 chance ...";

	internal const string TSVersion = "1.1.0";

	internal const string TSAuthor = "AuriRex";

	internal const string TSWebsite = "https://github.com/AuriRex/GTFO_FoxyJumpscare";
}
namespace FoxyJumpscare
{
	public static class JumpscareConfig
	{
		public const string MAIN = "Jumpscare Settings";

		public static ConfigEntry<float> SoundVolume { get; private set; }

		public static ConfigEntry<float> EveryXSeconds { get; private set; }

		public static ConfigEntry<int> Chance { get; private set; }

		public static ConfigEntry<bool> KillLocalPlayerOnJumpscare { get; private set; }

		internal static void Initialize(ConfigFile cfg)
		{
			SoundVolume = cfg.Bind<float>("Jumpscare Settings", "SoundVolume", 0.33f, "How loud should the jumpscare be?");
			EveryXSeconds = cfg.Bind<float>("Jumpscare Settings", "EveryXSeconds", 1f, "How often to roll for a jumpscare? (Seconds)");
			Chance = cfg.Bind<int>("Jumpscare Settings", "Chance", 10000, "The one in Y chance every X seconds");
			KillLocalPlayerOnJumpscare = cfg.Bind<bool>("Jumpscare Settings", "KillLocalPlayerOnJumpscare", false, "Should you get downed anytime a jumpscare occurs?");
		}
	}
	public class LetsGoGambling : MonoBehaviour
	{
		private float _nextUpdate;

		public static int ChanceValue => JumpscareConfig.Chance.Value;

		public static float EveryXSeconds => JumpscareConfig.EveryXSeconds.Value;

		private void Update()
		{
			float realtimeSinceStartup = Time.realtimeSinceStartup;
			if (!(realtimeSinceStartup < _nextUpdate))
			{
				_nextUpdate = realtimeSinceStartup + EveryXSeconds;
				if (Random.Shared.Next(ChanceValue) == 0)
				{
					Plugin.L.LogInfo((object)"Scream now.");
					Plugin.PlayScare();
				}
			}
		}
	}
	[HarmonyPatch(typeof(StartMainGame), "Start")]
	public class Patches
	{
		public static void Postfix(StartMainGame __instance)
		{
			if (!((Object)(object)__instance == (Object)null))
			{
				Plugin.Init();
			}
		}
	}
	[BepInPlugin("dev.aurirex.gtfo.foxyjumpscare", "Foxy_Jumpscare", "1.1.0")]
	public class Plugin : BasePlugin
	{
		[CompilerGenerated]
		private sealed class <DoPlayScare>d__13 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			private Sprite[] <>7__wrap1;

			private int <>7__wrap2;

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

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

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

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

			private bool MoveNext()
			{
				//IL_004a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0054: Expected O, but got Unknown
				//IL_0111: Unknown result type (might be due to invalid IL or missing references)
				//IL_011b: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					((Component)renderer).gameObject.SetActive(true);
					audioSource.Play();
					<>2__current = (object)new WaitForSeconds(0.1f);
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					((Renderer)renderer).enabled = true;
					if (JumpscareConfig.KillLocalPlayerOnJumpscare.Value)
					{
						KillLocalPlayer();
					}
					<>7__wrap1 = sprites;
					<>7__wrap2 = 0;
					goto IL_00e9;
				case 2:
					<>1__state = -1;
					<>2__current = null;
					<>1__state = 3;
					return true;
				case 3:
					<>1__state = -1;
					<>7__wrap2++;
					goto IL_00e9;
				case 4:
					{
						<>1__state = -1;
						((Component)renderer).gameObject.SetActive(false);
						return false;
					}
					IL_00e9:
					if (<>7__wrap2 < <>7__wrap1.Length)
					{
						Sprite sprite = <>7__wrap1[<>7__wrap2];
						renderer.sprite = sprite;
						<>2__current = null;
						<>1__state = 2;
						return true;
					}
					<>7__wrap1 = null;
					((Renderer)renderer).enabled = false;
					<>2__current = (object)new WaitForSeconds(1f);
					<>1__state = 4;
					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();
			}
		}

		public const string GUID = "dev.aurirex.gtfo.foxyjumpscare";

		public const string MOD_NAME = "Foxy_Jumpscare";

		public const string VERSION = "1.1.0";

		internal static ManualLogSource L;

		private static readonly Harmony _harmony = new Harmony("dev.aurirex.gtfo.foxyjumpscare");

		private AssetBundle _bundle;

		internal static AudioSource audioSource;

		internal static SpriteRenderer renderer;

		internal static Sprite[] sprites;

		internal static AudioClip audioClip;

		private static bool _hasInited;

		public override void Load()
		{
			L = ((BasePlugin)this).Log;
			JumpscareConfig.Initialize(((BasePlugin)this).Config);
			ClassInjector.RegisterTypeInIl2Cpp<LetsGoGambling>();
			_bundle = AssetBundle.LoadFromMemory(Il2CppStructArray<byte>.op_Implicit(Data.foxy));
			Il2CppReferenceArray<Object> source = _bundle.LoadAllAssets();
			sprites = (from asset in (IEnumerable<Object>)source
				where ((MemberInfo)((Object)asset).GetIl2CppType()).Name == "Sprite"
				select ((Il2CppObjectBase)asset).Cast<Sprite>()).ToArray();
			Sprite[] array = sprites;
			foreach (Sprite obj in array)
			{
				Object.DontDestroyOnLoad((Object)(object)obj);
				((Object)obj).hideFlags = (HideFlags)61;
			}
			audioClip = ((Il2CppObjectBase)((IEnumerable<Object>)source).First((Object asset) => ((MemberInfo)((Object)asset).GetIl2CppType()).Name == "AudioClip")).Cast<AudioClip>();
			Object.DontDestroyOnLoad((Object)(object)audioClip);
			((Object)audioClip).hideFlags = (HideFlags)61;
			_harmony.PatchAll(Assembly.GetExecutingAssembly());
			L.LogInfo((object)"Plugin loaded!");
		}

		public static void PlayScare()
		{
			CoroutineManager.StartCoroutine(CollectionExtensions.WrapToIl2Cpp(DoPlayScare()), (Action)null);
		}

		private static void KillLocalPlayer()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Invalid comparison between Unknown and I4
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			PlayerAgent val = default(PlayerAgent);
			if ((int)GameStateManager.Current.m_currentStateName == 10 && PlayerManager.TryGetLocalPlayerAgent(ref val))
			{
				((Dam_SyncedDamageBase)val.Damage).MeleeDamage(1000f, (Agent)(object)val, ((Agent)val).Position, Vector3.zero, 1f, 1f, 1f, 1f, 1f, false, (DamageNoiseLevel)0, 0u);
			}
		}

		[IteratorStateMachine(typeof(<DoPlayScare>d__13))]
		private static IEnumerator DoPlayScare()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <DoPlayScare>d__13(0);
		}

		public static void Init()
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: 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)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: 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_0078: Unknown result type (might be due to invalid IL or missing references)
			if (!_hasInited)
			{
				_hasInited = true;
				new GameObject("FoxyChance").AddComponent<LetsGoGambling>();
				GameObject val = new GameObject("FoxyRenderer")
				{
					layer = LayerManager.LAYER_UI
				};
				Transform transform = val.transform;
				((Component)transform).transform.localPosition = new Vector3(0f, 0f, 935.3074f);
				((Component)transform).transform.localRotation = Quaternion.identity;
				((Component)transform).transform.localScale = Vector3.one * 140f;
				renderer = ((Component)transform).gameObject.AddComponent<SpriteRenderer>();
				((Component)transform).gameObject.AddComponent<AudioListener>();
				audioSource = ((Component)transform).gameObject.AddComponent<AudioSource>();
				audioSource.playOnAwake = false;
				audioSource.clip = audioClip;
				audioSource.loop = false;
				audioSource.dopplerLevel = 0f;
				audioSource.volume = 0.33f;
				renderer.sprite = sprites[0];
				val.SetActive(false);
			}
		}
	}
}
namespace FoxyJumpscare.Resources
{
	[GeneratedCode("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
	[DebuggerNonUserCode]
	[CompilerGenerated]
	internal class Data
	{
		private static ResourceManager resourceMan;

		private static CultureInfo resourceCulture;

		[EditorBrowsable(EditorBrowsableState.Advanced)]
		internal static ResourceManager ResourceManager
		{
			get
			{
				if (resourceMan == null)
				{
					resourceMan = new ResourceManager("FoxyJumpscare.Resources.Data", typeof(Data).Assembly);
				}
				return resourceMan;
			}
		}

		[EditorBrowsable(EditorBrowsableState.Advanced)]
		internal static CultureInfo Culture
		{
			get
			{
				return resourceCulture;
			}
			set
			{
				resourceCulture = value;
			}
		}

		internal static byte[] foxy => (byte[])ResourceManager.GetObject("foxy", resourceCulture);

		internal Data()
		{
		}
	}
}