using System;
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.Logging;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.SceneManagement;
using UnityEngine.Video;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("FoxyJumpscare2")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("FoxyJumpscare2")]
[assembly: AssemblyCopyright("Copyright © 2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("f4cd69dc-245d-4352-b9d6-a50043322e9d")]
[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 FoxyJumpscare;
[BepInPlugin("com.tetriz.foxyjumpscare", "Foxy Jumpscare", "1.0.2")]
public class FoxyJumpscarePlugin : BaseUnityPlugin
{
private static string savedVideoPath;
private static ManualLogSource savedLogger;
private static FoxyJumpscareController controller;
private static bool callbacksRegistered;
private static bool applicationClosing;
private void Awake()
{
savedLogger = ((BaseUnityPlugin)this).Logger;
((BaseUnityPlugin)this).Logger.LogInfo((object)"Foxy Jumpscare 1.0.2 starting.");
string directoryName = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location);
if (string.IsNullOrEmpty(directoryName))
{
((BaseUnityPlugin)this).Logger.LogError((object)"Could not determine the plugin folder.");
return;
}
savedVideoPath = Path.Combine(directoryName, "foxy.mp4");
((BaseUnityPlugin)this).Logger.LogInfo((object)("Video path: " + savedVideoPath));
if (!File.Exists(savedVideoPath))
{
((BaseUnityPlugin)this).Logger.LogError((object)"foxy.mp4 was not found.");
return;
}
RegisterStaticCallbacks();
EnsureControllerExists();
((BaseUnityPlugin)this).Logger.LogInfo((object)"Press F8 to test the jumpscare.");
}
private static void RegisterStaticCallbacks()
{
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_0030: Expected O, but got Unknown
if (!callbacksRegistered)
{
callbacksRegistered = true;
SceneManager.sceneLoaded += OnSceneLoaded;
Application.onBeforeRender += new UnityAction(EnsureControllerExists);
Application.quitting += OnApplicationQuitting;
savedLogger.LogInfo((object)"Static survival callbacks registered.");
}
}
private static void OnSceneLoaded(Scene scene, LoadSceneMode mode)
{
if (savedLogger != null)
{
savedLogger.LogInfo((object)("Scene loaded: " + ((Scene)(ref scene)).name));
}
EnsureControllerExists();
}
private static void OnApplicationQuitting()
{
applicationClosing = true;
}
private static void EnsureControllerExists()
{
//IL_003c: Unknown result type (might be due to invalid IL or missing references)
//IL_0041: Unknown result type (might be due to invalid IL or missing references)
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
//IL_004f: Expected O, but got Unknown
if (!applicationClosing && !((Object)(object)controller != (Object)null) && savedLogger != null && !string.IsNullOrEmpty(savedVideoPath) && File.Exists(savedVideoPath))
{
GameObject val = new GameObject("__FoxyJumpscareController")
{
hideFlags = (HideFlags)61
};
Object.DontDestroyOnLoad((Object)val);
controller = val.AddComponent<FoxyJumpscareController>();
controller.Initialize(savedVideoPath, savedLogger);
savedLogger.LogInfo((object)"Foxy controller created or recreated.");
}
}
public static void ReportControllerDestroyed(FoxyJumpscareController destroyedController)
{
if ((Object)(object)controller == (Object)(object)destroyedController)
{
controller = null;
}
if (!applicationClosing && savedLogger != null)
{
savedLogger.LogWarning((object)"Foxy controller was destroyed. It will be recreated automatically.");
}
}
}
public class FoxyJumpscareController : MonoBehaviour
{
private const int VK_F8 = 119;
private const int ChanceDenominator = 10000;
private const float VideoVolume = 1f;
private ManualLogSource logger;
private string videoPath;
private VideoPlayer videoPlayer;
private RenderTexture renderTexture;
private bool initialized;
private bool videoPrepared;
private bool jumpscareActive;
private bool f8WasDown;
private float randomTimer;
private float heartbeatTimer;
[DllImport("user32.dll")]
private static extern short GetAsyncKeyState(int virtualKey);
public void Initialize(string suppliedVideoPath, ManualLogSource suppliedLogger)
{
if (!initialized)
{
initialized = true;
logger = suppliedLogger;
videoPath = suppliedVideoPath;
((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
((Object)((Component)this).transform).hideFlags = (HideFlags)61;
logger.LogInfo((object)"Controller initialized.");
CreateVideoPlayer();
}
}
private void CreateVideoPlayer()
{
//IL_002b: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: Expected O, but got Unknown
//IL_0146: Unknown result type (might be due to invalid IL or missing references)
//IL_0150: Expected O, but got Unknown
//IL_015d: Unknown result type (might be due to invalid IL or missing references)
//IL_0167: Expected O, but got Unknown
//IL_0174: Unknown result type (might be due to invalid IL or missing references)
//IL_017e: Expected O, but got Unknown
//IL_018b: Unknown result type (might be due to invalid IL or missing references)
//IL_0195: Expected O, but got Unknown
if (!File.Exists(videoPath))
{
logger.LogError((object)"Cannot create VideoPlayer because foxy.mp4 is missing.");
return;
}
renderTexture = new RenderTexture(1920, 1080, 0, (RenderTextureFormat)0);
((Object)renderTexture).name = "FoxyJumpscareRenderTexture";
((Object)renderTexture).hideFlags = (HideFlags)61;
renderTexture.Create();
ClearRenderTexture();
videoPlayer = ((Component)this).gameObject.AddComponent<VideoPlayer>();
((Object)videoPlayer).hideFlags = (HideFlags)61;
videoPlayer.playOnAwake = false;
videoPlayer.waitForFirstFrame = true;
videoPlayer.skipOnDrop = true;
videoPlayer.isLooping = false;
videoPlayer.source = (VideoSource)1;
videoPlayer.url = new Uri(videoPath).AbsoluteUri;
videoPlayer.renderMode = (VideoRenderMode)2;
videoPlayer.targetTexture = renderTexture;
videoPlayer.audioOutputMode = (VideoAudioOutputMode)2;
videoPlayer.controlledAudioTrackCount = 1;
videoPlayer.EnableAudioTrack((ushort)0, true);
videoPlayer.SetDirectAudioMute((ushort)0, false);
videoPlayer.SetDirectAudioVolume((ushort)0, 1f);
videoPlayer.prepareCompleted += new EventHandler(OnVideoPrepared);
videoPlayer.started += new EventHandler(OnVideoStarted);
videoPlayer.loopPointReached += new EventHandler(OnVideoFinished);
videoPlayer.errorReceived += new ErrorEventHandler(OnVideoError);
logger.LogInfo((object)"Preparing foxy.mp4...");
videoPlayer.Prepare();
}
private void Update()
{
if (initialized)
{
CheckF8();
CheckRandomChance();
LogHeartbeat();
}
}
private void CheckF8()
{
bool flag = (GetAsyncKeyState(119) & 0x8000) != 0;
bool num = flag && !f8WasDown;
f8WasDown = flag;
if (num)
{
logger.LogInfo((object)"F8 was detected.");
PlayJumpscare();
}
}
private void CheckRandomChance()
{
randomTimer += Time.unscaledDeltaTime;
if (!(randomTimer < 1f))
{
randomTimer -= 1f;
if (!jumpscareActive && Random.Range(0, 10000) == 0)
{
logger.LogInfo((object)"Random 1-in-10000 roll succeeded.");
PlayJumpscare();
}
}
}
private void LogHeartbeat()
{
heartbeatTimer += Time.unscaledDeltaTime;
if (!(heartbeatTimer < 10f))
{
heartbeatTimer = 0f;
logger.LogInfo((object)"Foxy controller is still running.");
}
}
private void PlayJumpscare()
{
logger.LogInfo((object)"PlayJumpscare was called.");
if (jumpscareActive)
{
logger.LogWarning((object)"Jumpscare is already active.");
return;
}
if ((Object)(object)videoPlayer == (Object)null)
{
logger.LogError((object)"VideoPlayer does not exist.");
return;
}
if (!videoPrepared)
{
logger.LogWarning((object)"Video is not prepared yet.");
videoPlayer.Prepare();
return;
}
jumpscareActive = true;
videoPlayer.Stop();
ClearRenderTexture();
videoPlayer.time = 0.0;
videoPlayer.frame = 0L;
videoPlayer.SetDirectAudioVolume((ushort)0, 1f);
logger.LogInfo((object)"Starting Foxy jumpscare.");
videoPlayer.Play();
}
private void OnVideoPrepared(VideoPlayer player)
{
videoPrepared = true;
logger.LogInfo((object)"foxy.mp4 prepared successfully.");
logger.LogInfo((object)("Video resolution: " + player.width + "x" + player.height));
logger.LogInfo((object)("Video length: " + player.length + " seconds."));
}
private void OnVideoStarted(VideoPlayer player)
{
logger.LogInfo((object)"foxy.mp4 playback started.");
}
private void OnVideoFinished(VideoPlayer player)
{
logger.LogInfo((object)"foxy.mp4 playback finished.");
StopJumpscare();
}
private void OnVideoError(VideoPlayer player, string errorMessage)
{
logger.LogError((object)("VideoPlayer error: " + errorMessage));
StopJumpscare();
}
private void StopJumpscare()
{
jumpscareActive = false;
if ((Object)(object)videoPlayer != (Object)null)
{
videoPlayer.Stop();
}
ClearRenderTexture();
logger.LogInfo((object)"Foxy jumpscare stopped.");
}
private void ClearRenderTexture()
{
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
if (!((Object)(object)renderTexture == (Object)null))
{
RenderTexture active = RenderTexture.active;
RenderTexture.active = renderTexture;
GL.Clear(true, true, Color.black);
RenderTexture.active = active;
}
}
private void OnGUI()
{
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
if (jumpscareActive && !((Object)(object)renderTexture == (Object)null))
{
GUI.depth = -10000;
GUI.DrawTexture(new Rect(0f, 0f, (float)Screen.width, (float)Screen.height), (Texture)(object)renderTexture, (ScaleMode)0, false);
}
}
private void OnDestroy()
{
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_002b: Expected O, but got Unknown
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
//IL_0042: Expected O, but got Unknown
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
//IL_0059: Expected O, but got Unknown
//IL_0066: Unknown result type (might be due to invalid IL or missing references)
//IL_0070: Expected O, but got Unknown
FoxyJumpscarePlugin.ReportControllerDestroyed(this);
if ((Object)(object)videoPlayer != (Object)null)
{
videoPlayer.prepareCompleted -= new EventHandler(OnVideoPrepared);
videoPlayer.started -= new EventHandler(OnVideoStarted);
videoPlayer.loopPointReached -= new EventHandler(OnVideoFinished);
videoPlayer.errorReceived -= new ErrorEventHandler(OnVideoError);
}
if ((Object)(object)renderTexture != (Object)null)
{
renderTexture.Release();
Object.Destroy((Object)(object)renderTexture);
renderTexture = null;
}
}
}