Decompiled source of FoxyJumpscareMod v1.0.3

FoxyJumpscareMod.dll

Decompiled a month 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.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using LCSoundTool;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("FoxyJumpscare")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("FoxyJumpscare")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("e0685965-fe05-4ee7-9469-6ecec48ea921")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace FoxyJumpscareMod;

[BepInPlugin("rakuchansugoi.FoxyJumpscareMod", "Foxy Jumpscare Mod", "1.0.3")]
public class Plugin : BaseUnityPlugin
{
	public static ConfigEntry<int> jumpscareChance;

	public static ConfigEntry<float> jumpscareSpeed;

	private const string modGUID = "rakuchansugoi.FoxyJumpscareMod";

	private const string modName = "Foxy Jumpscare Mod";

	private const string modVersion = "1.0.3";

	public static ManualLogSource mls;

	public static Sprite[] jumpscareFrames;

	public static Image jumpscareImage;

	public static JumpscareController jumpscareController;

	public static AudioClip jumpscareSound;

	private const int frameCount = 25;

	private readonly Harmony harmony = new Harmony("rakuchansugoi.FoxyJumpscareMod");

	private void Awake()
	{
		//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ba: Expected O, but got Unknown
		//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
		jumpscareChance = ((BaseUnityPlugin)this).Config.Bind<int>("Settings", "JumpscareChance", 10000, "Chance of triggering a jumpscare (1 in X chance)");
		jumpscareSpeed = ((BaseUnityPlugin)this).Config.Bind<float>("Settings", "JumpscareSpeed", 1f, "Speed multiplier of the animation");
		mls = Logger.CreateLogSource("rakuchansugoi.FoxyJumpscareMod");
		string directoryName = Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath);
		jumpscareFrames = (Sprite[])(object)new Sprite[25];
		for (int i = 0; i < 25; i++)
		{
			string path = Path.Combine(directoryName, "assets", $"frame_{i:D6}.png");
			byte[] array = File.ReadAllBytes(path);
			Texture2D val = new Texture2D(1920, 1080);
			ImageConversion.LoadImage(val, array);
			((Texture)val).filterMode = (FilterMode)0;
			jumpscareFrames[i] = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), Vector2.one * 0.5f);
		}
		jumpscareSound = SoundTool.GetAudioClip("alucardia-FoxyJumpscareMod", "assets", "jumpscare.ogg");
		mls.LogInfo((object)"[Foxy Jumpscare Mod] version 1.0.3 loaded!");
		harmony.PatchAll();
	}
}
public class JumpscareController : MonoBehaviour
{
	[CompilerGenerated]
	private sealed class <Play>d__4 : IEnumerator<object>, IDisposable, IEnumerator
	{
		private int <>1__state;

		private object <>2__current;

		public JumpscareController <>4__this;

		private Image <img>5__1;

		private float <dt>5__2;

		private Sprite[] <>s__3;

		private int <>s__4;

		private Sprite <frame>5__5;

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

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

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

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

		private bool MoveNext()
		{
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Expected O, but got Unknown
			switch (<>1__state)
			{
			default:
				return false;
			case 0:
				<>1__state = -1;
				<>4__this.isPlaying = true;
				<img>5__1 = Plugin.jumpscareImage;
				((Behaviour)<img>5__1).enabled = true;
				if ((Object)(object)<>4__this.audioSource != (Object)null && (Object)(object)<>4__this.audioSource.clip != (Object)null)
				{
					<>4__this.audioSource.Play();
				}
				<dt>5__2 = 1f / (30f * Plugin.jumpscareSpeed.Value);
				<>s__3 = Plugin.jumpscareFrames;
				<>s__4 = 0;
				break;
			case 1:
				<>1__state = -1;
				<frame>5__5 = null;
				<>s__4++;
				break;
			}
			if (<>s__4 < <>s__3.Length)
			{
				<frame>5__5 = <>s__3[<>s__4];
				<img>5__1.sprite = <frame>5__5;
				<>2__current = (object)new WaitForSeconds(<dt>5__2);
				<>1__state = 1;
				return true;
			}
			<>s__3 = null;
			((Behaviour)<img>5__1).enabled = false;
			<>4__this.isPlaying = 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 bool isPlaying;

	private AudioSource audioSource;

	private void Awake()
	{
		JumpscareController[] array = Object.FindObjectsOfType<JumpscareController>();
		if (array.Length > 1)
		{
			Object.Destroy((Object)(object)((Component)this).gameObject);
			return;
		}
		Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject);
		audioSource = ((Component)this).gameObject.AddComponent<AudioSource>();
		audioSource.playOnAwake = false;
		audioSource.clip = Plugin.jumpscareSound;
	}

	public void TriggerJumpscare()
	{
		if (!isPlaying && (Object)(object)Plugin.jumpscareImage != (Object)null)
		{
			((MonoBehaviour)this).StartCoroutine(Play());
		}
	}

	[IteratorStateMachine(typeof(<Play>d__4))]
	private IEnumerator Play()
	{
		//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
		return new <Play>d__4(0)
		{
			<>4__this = this
		};
	}
}
[HarmonyPatch(typeof(HUDManager))]
internal static class HUDManagerPatches
{
	private static float timePassed;

	[HarmonyPostfix]
	[HarmonyPatch("Start")]
	private static void StartPostfix(HUDManager __instance)
	{
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Expected O, but got Unknown
		//IL_0067: Unknown result type (might be due to invalid IL or missing references)
		//IL_0073: 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_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_0086: Unknown result type (might be due to invalid IL or missing references)
		//IL_008e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Expected O, but got Unknown
		if ((Object)(object)Plugin.jumpscareController == (Object)null)
		{
			GameObject val = new GameObject("JumpscareController");
			Plugin.jumpscareController = val.AddComponent<JumpscareController>();
		}
		GameObject val2 = GameObject.Find("Canvas");
		GameObject val3 = new GameObject("JumpscareImage");
		val3.transform.SetParent(val2.transform, false);
		val3.transform.SetAsLastSibling();
		RectTransform val4 = val3.AddComponent<RectTransform>();
		val4.anchorMin = Vector2.zero;
		val4.anchorMax = Vector2.one;
		Vector2 offsetMin = (val4.offsetMax = Vector2.zero);
		val4.offsetMin = offsetMin;
		Plugin.jumpscareImage = val3.AddComponent<Image>();
		((Behaviour)Plugin.jumpscareImage).enabled = false;
	}

	[HarmonyPostfix]
	[HarmonyPatch("Update")]
	private static void UpdatePostfix()
	{
		if ((Object)(object)Plugin.jumpscareController == (Object)null)
		{
			Plugin.mls.LogWarning((object)"Jumpscare controller is null!");
			return;
		}
		timePassed += Time.deltaTime;
		if (timePassed >= 1f)
		{
			timePassed -= 1f;
			if (Random.Range(0, Plugin.jumpscareChance.Value) == 0)
			{
				Plugin.jumpscareController.TriggerJumpscare();
			}
		}
	}
}