Decompiled source of Verity v0.1.0

BepInEx\plugins\Verity\Verity.dll

Decompiled 2 months 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.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using Microsoft.CodeAnalysis;
using Unity.Collections;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.Networking;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("AmazingAssets.TerrainToMesh")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp-firstpass")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: IgnoresAccessChecksTo("ClientNetworkTransform")]
[assembly: IgnoresAccessChecksTo("com.olegknyazev.softmask")]
[assembly: IgnoresAccessChecksTo("DissonanceVoip")]
[assembly: IgnoresAccessChecksTo("DunGen")]
[assembly: IgnoresAccessChecksTo("DunGen.Integration.ASPP")]
[assembly: IgnoresAccessChecksTo("DunGen.Integration.UnityNav")]
[assembly: IgnoresAccessChecksTo("EasyTextEffects")]
[assembly: IgnoresAccessChecksTo("Facepunch Transport for Netcode for GameObjects")]
[assembly: IgnoresAccessChecksTo("Facepunch.Steamworks.Win64")]
[assembly: IgnoresAccessChecksTo("Unity.AI.Navigation")]
[assembly: IgnoresAccessChecksTo("Unity.Animation.Rigging")]
[assembly: IgnoresAccessChecksTo("Unity.Animation.Rigging.DocCodeExamples")]
[assembly: IgnoresAccessChecksTo("Unity.Burst")]
[assembly: IgnoresAccessChecksTo("Unity.Burst.Unsafe")]
[assembly: IgnoresAccessChecksTo("Unity.Collections")]
[assembly: IgnoresAccessChecksTo("Unity.Collections.LowLevel.ILSupport")]
[assembly: IgnoresAccessChecksTo("Unity.InputSystem")]
[assembly: IgnoresAccessChecksTo("Unity.InputSystem.ForUI")]
[assembly: IgnoresAccessChecksTo("Unity.Jobs")]
[assembly: IgnoresAccessChecksTo("Unity.Mathematics")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.Common")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.MetricTypes")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStats")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsMonitor.Component")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsMonitor.Configuration")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsMonitor.Implementation")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsReporting")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetworkProfiler.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetworkSolutionInterface")]
[assembly: IgnoresAccessChecksTo("Unity.Netcode.Components")]
[assembly: IgnoresAccessChecksTo("Unity.Netcode.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.Networking.Transport")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.Csg")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.KdTree")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.Poly2Tri")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.Stl")]
[assembly: IgnoresAccessChecksTo("Unity.Profiling.Core")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.Core.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.Core.ShaderLibrary")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.HighDefinition.Config.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.HighDefinition.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.ShaderGraph.ShaderGraphLibrary")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Authentication")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Analytics")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Components")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Configuration")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Device")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Environments")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Environments.Internal")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Internal")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Networking")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Registration")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Scheduler")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Telemetry")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Threading")]
[assembly: IgnoresAccessChecksTo("Unity.Services.QoS")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Relay")]
[assembly: IgnoresAccessChecksTo("Unity.TextMeshPro")]
[assembly: IgnoresAccessChecksTo("Unity.Timeline")]
[assembly: IgnoresAccessChecksTo("Unity.VisualEffectGraph.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.XR.CoreUtils")]
[assembly: IgnoresAccessChecksTo("Unity.XR.Management")]
[assembly: IgnoresAccessChecksTo("Unity.XR.OpenXR")]
[assembly: IgnoresAccessChecksTo("Unity.XR.OpenXR.Features.ConformanceAutomation")]
[assembly: IgnoresAccessChecksTo("Unity.XR.OpenXR.Features.MetaQuestSupport")]
[assembly: IgnoresAccessChecksTo("Unity.XR.OpenXR.Features.MockRuntime")]
[assembly: IgnoresAccessChecksTo("Unity.XR.OpenXR.Features.OculusQuestSupport")]
[assembly: IgnoresAccessChecksTo("Unity.XR.OpenXR.Features.RuntimeDebugger")]
[assembly: IgnoresAccessChecksTo("UnityEngine.ARModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.NVIDIAModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.SpatialTracking")]
[assembly: IgnoresAccessChecksTo("UnityEngine.UI")]
[assembly: IgnoresAccessChecksTo("UnityEngine.XR.LegacyInputHelpers")]
[assembly: AssemblyCompany("Verity")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0")]
[assembly: AssemblyProduct("Verity")]
[assembly: AssemblyTitle("Verity")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.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 VerityMod
{
	public static class VerityAssets
	{
		public static List<AudioClip> Distant = new List<AudioClip>();

		public static List<AudioClip> Music = new List<AudioClip>();

		public static List<AudioClip> Stingers = new List<AudioClip>();

		public static List<Texture2D> Jumpscare = new List<Texture2D>();

		public static List<Texture2D> Flash = new List<Texture2D>();

		public static bool Ready;

		public static IEnumerator LoadAll()
		{
			string root = VerityPlugin.AssetRoot;
			yield return LoadSounds(Path.Combine(root, "sounds/distant"), Distant);
			yield return LoadSounds(Path.Combine(root, "sounds/music"), Music);
			yield return LoadSounds(Path.Combine(root, "sounds/stingers"), Stingers);
			LoadImages(Path.Combine(root, "images/jumpscare"), Jumpscare);
			LoadImages(Path.Combine(root, "images/flash"), Flash);
			Ready = true;
			VerityPlugin.Log.LogInfo((object)$"Assets: distant={Distant.Count} music={Music.Count} stingers={Stingers.Count} jumpscare={Jumpscare.Count} flash={Flash.Count}");
		}

		private static IEnumerator LoadSounds(string dir, List<AudioClip> target)
		{
			if (!Directory.Exists(dir))
			{
				Directory.CreateDirectory(dir);
				yield break;
			}
			string[] files = Directory.GetFiles(dir);
			foreach (string path in files)
			{
				AudioType val = TypeOf(path);
				if ((int)val == 0)
				{
					continue;
				}
				UnityWebRequest req = UnityWebRequestMultimedia.GetAudioClip("file://" + path, val);
				try
				{
					yield return req.SendWebRequest();
					if ((int)req.result != 1)
					{
						VerityPlugin.Log.LogWarning((object)("Failed to load audio: " + path + " -> " + req.error));
						continue;
					}
					AudioClip content = DownloadHandlerAudioClip.GetContent(req);
					if (!((Object)(object)content == (Object)null))
					{
						((Object)content).name = Path.GetFileNameWithoutExtension(path);
						target.Add(content);
					}
				}
				finally
				{
					((IDisposable)req)?.Dispose();
				}
			}
		}

		private static void LoadImages(string dir, List<Texture2D> target)
		{
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Expected O, but got Unknown
			if (!Directory.Exists(dir))
			{
				Directory.CreateDirectory(dir);
				return;
			}
			string[] files = Directory.GetFiles(dir);
			foreach (string path in files)
			{
				string text = Path.GetExtension(path).ToLowerInvariant();
				if (!(text != ".png") || !(text != ".jpg") || !(text != ".jpeg"))
				{
					Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false);
					if (ImageConversion.LoadImage(val, File.ReadAllBytes(path)))
					{
						((Object)val).name = Path.GetFileNameWithoutExtension(path);
						((Object)val).hideFlags = (HideFlags)61;
						target.Add(val);
					}
				}
			}
		}

		private static AudioType TypeOf(string path)
		{
			return (AudioType)(Path.GetExtension(path).ToLowerInvariant() switch
			{
				".ogg" => 14, 
				".wav" => 20, 
				".mp3" => 13, 
				_ => 0, 
			});
		}

		public static T Pick<T>(List<T> list, Random rng)
		{
			if (list == null || list.Count == 0)
			{
				return default(T);
			}
			return list[rng.Next(list.Count)];
		}
	}
	public static class VerityNet
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static HandleNamedMessageDelegate <0>__OnEvent1;

			public static HandleNamedMessageDelegate <1>__OnEvent2;

			public static HandleNamedMessageDelegate <2>__OnImage;

			public static HandleNamedMessageDelegate <3>__OnFlash;
		}

		public const string MsgEvent1 = "Verity_Event1";

		public const string MsgEvent2 = "Verity_Event2";

		public const string MsgImage = "Verity_Image";

		public const string MsgFlash = "Verity_Flash";

		private static bool registered;

		public static bool Online
		{
			get
			{
				NetworkManager singleton = NetworkManager.Singleton;
				if ((Object)(object)singleton != (Object)null && singleton.IsListening)
				{
					return singleton.CustomMessagingManager != null;
				}
				return false;
			}
		}

		public static bool IsHost
		{
			get
			{
				NetworkManager singleton = NetworkManager.Singleton;
				if (!((Object)(object)singleton == (Object)null) && singleton.IsListening)
				{
					return singleton.IsServer;
				}
				return true;
			}
		}

		public static void TryRegister()
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Expected O, but got Unknown
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Expected O, but got Unknown
			//IL_007b: 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_0086: Expected O, but got Unknown
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Expected O, but got Unknown
			if (!registered && Online)
			{
				CustomMessagingManager customMessagingManager = NetworkManager.Singleton.CustomMessagingManager;
				object obj = <>O.<0>__OnEvent1;
				if (obj == null)
				{
					HandleNamedMessageDelegate val = OnEvent1;
					<>O.<0>__OnEvent1 = val;
					obj = (object)val;
				}
				customMessagingManager.RegisterNamedMessageHandler("Verity_Event1", (HandleNamedMessageDelegate)obj);
				object obj2 = <>O.<1>__OnEvent2;
				if (obj2 == null)
				{
					HandleNamedMessageDelegate val2 = OnEvent2;
					<>O.<1>__OnEvent2 = val2;
					obj2 = (object)val2;
				}
				customMessagingManager.RegisterNamedMessageHandler("Verity_Event2", (HandleNamedMessageDelegate)obj2);
				object obj3 = <>O.<2>__OnImage;
				if (obj3 == null)
				{
					HandleNamedMessageDelegate val3 = OnImage;
					<>O.<2>__OnImage = val3;
					obj3 = (object)val3;
				}
				customMessagingManager.RegisterNamedMessageHandler("Verity_Image", (HandleNamedMessageDelegate)obj3);
				object obj4 = <>O.<3>__OnFlash;
				if (obj4 == null)
				{
					HandleNamedMessageDelegate val4 = OnFlash;
					<>O.<3>__OnFlash = val4;
					obj4 = (object)val4;
				}
				customMessagingManager.RegisterNamedMessageHandler("Verity_Flash", (HandleNamedMessageDelegate)obj4);
				registered = true;
				VerityPlugin.Log.LogInfo((object)"Verity network channels registered.");
			}
		}

		public static void Reset()
		{
			registered = false;
		}

		public unsafe static void Broadcast(string message, int seed)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			if (!Online)
			{
				Handle(message, seed);
				return;
			}
			FastBufferWriter val = default(FastBufferWriter);
			((FastBufferWriter)(ref val))..ctor(8, (Allocator)2, -1);
			FastBufferWriter val2 = val;
			try
			{
				((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref seed, default(ForPrimitives));
				NetworkManager.Singleton.CustomMessagingManager.SendNamedMessageToAll(message, val, (NetworkDelivery)2);
			}
			finally
			{
				((IDisposable)(*(FastBufferWriter*)(&val2))/*cast due to .constrained prefix*/).Dispose();
			}
			Handle(message, seed);
		}

		private static void OnEvent1(ulong sender, FastBufferReader reader)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			Read("Verity_Event1", reader);
		}

		private static void OnEvent2(ulong sender, FastBufferReader reader)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			Read("Verity_Event2", reader);
		}

		private static void OnImage(ulong sender, FastBufferReader reader)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			Read("Verity_Image", reader);
		}

		private static void OnFlash(ulong sender, FastBufferReader reader)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			Read("Verity_Flash", reader);
		}

		private static void Read(string message, FastBufferReader reader)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			int seed = 0;
			if (((FastBufferReader)(ref reader)).TryBeginRead(4))
			{
				((FastBufferReader)(ref reader)).ReadValue<int>(ref seed, default(ForPrimitives));
			}
			Handle(message, seed);
		}

		private static void Handle(string message, int seed)
		{
			VerityRuntime instance = VerityRuntime.Instance;
			if (!((Object)(object)instance == (Object)null))
			{
				switch (message)
				{
				case "Verity_Event1":
					instance.PlayDistantSound(seed);
					break;
				case "Verity_Event2":
					instance.StartVigil(seed);
					break;
				case "Verity_Image":
					instance.ShowJumpscare(seed, VerityPlugin.E2KillPlayer.Value);
					break;
				case "Verity_Flash":
					instance.ShowFlash(seed);
					break;
				}
			}
		}
	}
	[BepInPlugin("experimenter.verity", "Verity", "0.1.0")]
	public class VerityPlugin : BaseUnityPlugin
	{
		public const string Guid = "experimenter.verity";

		public const string Name = "Verity";

		public const string Version = "0.1.0";

		public static VerityPlugin Instance;

		public static ManualLogSource Log;

		public static string AssetRoot;

		public static ConfigEntry<float> E1Chance;

		public static ConfigEntry<float> E1MinDistance;

		public static ConfigEntry<float> E1MaxDistance;

		public static ConfigEntry<float> E1Volume;

		public static ConfigEntry<float> E1MaxAudibleDistance;

		public static ConfigEntry<float> E2Chance;

		public static ConfigEntry<float> E2TriggerAfterSeconds;

		public static ConfigEntry<float> E2BuildupSeconds;

		public static ConfigEntry<float> E2StartVolume;

		public static ConfigEntry<float> E2EndVolume;

		public static ConfigEntry<float> E2ImageSeconds;

		public static ConfigEntry<bool> E2KillPlayer;

		public static ConfigEntry<bool> FlashEnabled;

		public static ConfigEntry<float> FlashChancePerMinute;

		public static ConfigEntry<float> FlashSeconds;

		public static ConfigEntry<bool> HotkeysEnabled;

		private void Awake()
		{
			//IL_0269: Unknown result type (might be due to invalid IL or missing references)
			//IL_026e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0276: Unknown result type (might be due to invalid IL or missing references)
			//IL_027c: Expected O, but got Unknown
			Instance = this;
			Log = ((BaseUnityPlugin)this).Logger;
			AssetRoot = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "Assets");
			E1Chance = ((BaseUnityPlugin)this).Config.Bind<float>("Event1 - Distant Sound", "Chance", 85f, "Chance in percent that the distant sound fires once per round when someone enters the facility.");
			E1MinDistance = ((BaseUnityPlugin)this).Config.Bind<float>("Event1 - Distant Sound", "MinDistance", 22f, "Minimum spawn distance from the player, in meters.");
			E1MaxDistance = ((BaseUnityPlugin)this).Config.Bind<float>("Event1 - Distant Sound", "MaxDistance", 40f, "Maximum spawn distance from the player, in meters.");
			E1Volume = ((BaseUnityPlugin)this).Config.Bind<float>("Event1 - Distant Sound", "Volume", 1f, "Source volume (0-1). Distance already makes it quiet.");
			E1MaxAudibleDistance = ((BaseUnityPlugin)this).Config.Bind<float>("Event1 - Distant Sound", "MaxAudibleDistance", 90f, "Audio rolloff max distance.");
			E2Chance = ((BaseUnityPlugin)this).Config.Bind<float>("Event2 - Vigil", "Chance", 67f, "Chance in percent that the music event can happen during a round.");
			E2TriggerAfterSeconds = ((BaseUnityPlugin)this).Config.Bind<float>("Event2 - Vigil", "TriggerAfterSeconds", 60f, "How long a player must stay inside the facility before the music starts.");
			E2BuildupSeconds = ((BaseUnityPlugin)this).Config.Bind<float>("Event2 - Vigil", "BuildupSeconds", 90f, "Music buildup length. At the end the image appears and the player dies. 90 = 1:30.");
			E2StartVolume = ((BaseUnityPlugin)this).Config.Bind<float>("Event2 - Vigil", "StartVolume", 0.05f, "Music volume at the start of the buildup.");
			E2EndVolume = ((BaseUnityPlugin)this).Config.Bind<float>("Event2 - Vigil", "EndVolume", 1f, "Music volume at the end of the buildup.");
			E2ImageSeconds = ((BaseUnityPlugin)this).Config.Bind<float>("Event2 - Vigil", "ImageSeconds", 1.2f, "How long the lethal image stays on screen.");
			E2KillPlayer = ((BaseUnityPlugin)this).Config.Bind<bool>("Event2 - Vigil", "KillPlayer", true, "Kill the player when the image appears.");
			FlashEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Random Flash", "Enabled", true, "Rare single-frame PNG flashes while inside the facility.");
			FlashChancePerMinute = ((BaseUnityPlugin)this).Config.Bind<float>("Random Flash", "ChancePerMinute", 4f, "Chance in percent per minute spent inside the facility.");
			FlashSeconds = ((BaseUnityPlugin)this).Config.Bind<float>("Random Flash", "Seconds", 0.12f, "How long the flash stays on screen.");
			HotkeysEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "HotkeysEnabled", true, "F7 = event 1, F8 = event 2, F9 = image only, F10 = random flash, F11 = reset round state. Turn OFF before release.");
			GameObject val = new GameObject("VerityRuntime")
			{
				hideFlags = (HideFlags)61
			};
			Object.DontDestroyOnLoad((Object)val);
			val.AddComponent<VerityRuntime>();
			Log.LogInfo((object)"Verity 0.1.0 loaded. It knows everything.");
		}
	}
	public class VerityRuntime : MonoBehaviour
	{
		public static VerityRuntime Instance;

		private Random rng = new Random();

		private bool roundActive;

		private bool event1Fired;

		private bool event2Fired;

		private bool event2RolledOk;

		private float insideTimer;

		private AudioSource musicSource;

		private Coroutine vigilRoutine;

		private Texture2D currentImage;

		private float imageUntil;

		private float imageAlpha = 1f;

		private void Awake()
		{
			Instance = this;
			((MonoBehaviour)this).StartCoroutine(VerityAssets.LoadAll());
		}

		private void Update()
		{
			VerityNet.TryRegister();
			if (VerityPlugin.HotkeysEnabled.Value)
			{
				Hotkeys();
			}
			StartOfRound instance = StartOfRound.Instance;
			if ((Object)(object)instance == (Object)null)
			{
				return;
			}
			bool inShipPhase = instance.inShipPhase;
			if (inShipPhase && roundActive)
			{
				EndRound();
			}
			if (!inShipPhase && !roundActive)
			{
				BeginRound();
			}
			if (!roundActive)
			{
				return;
			}
			if (VerityNet.IsHost && !event1Fired && AnyoneInsideFacility())
			{
				event1Fired = true;
				if (Roll(VerityPlugin.E1Chance.Value))
				{
					VerityNet.Broadcast("Verity_Event1", rng.Next(int.MaxValue));
				}
			}
			if (VerityNet.IsHost && !event2Fired)
			{
				if (AnyoneInsideFacility())
				{
					insideTimer += Time.deltaTime;
				}
				if (event2RolledOk && insideTimer >= VerityPlugin.E2TriggerAfterSeconds.Value)
				{
					event2Fired = true;
					VerityNet.Broadcast("Verity_Event2", rng.Next(int.MaxValue));
				}
			}
			if (VerityNet.IsHost && VerityPlugin.FlashEnabled.Value && AnyoneInsideFacility())
			{
				float num = VerityPlugin.FlashChancePerMinute.Value / 100f / 60f;
				if (Random.value < num * Time.deltaTime)
				{
					VerityNet.Broadcast("Verity_Flash", rng.Next(int.MaxValue));
				}
			}
		}

		private void BeginRound()
		{
			roundActive = true;
			event1Fired = false;
			event2Fired = false;
			insideTimer = 0f;
			event2RolledOk = Roll(VerityPlugin.E2Chance.Value);
			VerityPlugin.Log.LogInfo((object)("Verity: new round. Vigil armed = " + event2RolledOk));
		}

		private void EndRound()
		{
			roundActive = false;
			StopVigil();
		}

		public void ResetState()
		{
			EndRound();
			BeginRound();
		}

		private bool Roll(float percent)
		{
			return Random.Range(0f, 100f) < percent;
		}

		private static PlayerControllerB LocalPlayer()
		{
			GameNetworkManager instance = GameNetworkManager.Instance;
			if (!((Object)(object)instance == (Object)null))
			{
				return instance.localPlayerController;
			}
			return null;
		}

		private static bool AnyoneInsideFacility()
		{
			StartOfRound instance = StartOfRound.Instance;
			if ((Object)(object)instance == (Object)null || instance.allPlayerScripts == null)
			{
				return false;
			}
			for (int i = 0; i < instance.allPlayerScripts.Length; i++)
			{
				PlayerControllerB val = instance.allPlayerScripts[i];
				if ((Object)(object)val != (Object)null && val.isPlayerControlled && !val.isPlayerDead && val.isInsideFactory)
				{
					return true;
				}
			}
			return false;
		}

		public void PlayDistantSound(int seed)
		{
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Expected O, but got Unknown
			AudioClip val = VerityAssets.Pick(VerityAssets.Distant, new Random(seed));
			if ((Object)(object)val == (Object)null)
			{
				VerityPlugin.Log.LogWarning((object)"Event 1 fired but Assets/sounds/distant is empty.");
				return;
			}
			PlayerControllerB val2 = LocalPlayer();
			Vector3 val3 = (((Object)(object)val2 != (Object)null) ? ((Component)val2).transform.position : Vector3.zero);
			Random random = new Random(seed);
			float num = (float)(random.NextDouble() * Math.PI * 2.0);
			float num2 = Mathf.Lerp(VerityPlugin.E1MinDistance.Value, VerityPlugin.E1MaxDistance.Value, (float)random.NextDouble());
			Vector3 position = val3 + new Vector3(Mathf.Cos(num) * num2, Random.Range(-2f, 2f), Mathf.Sin(num) * num2);
			GameObject val4 = new GameObject("VerityDistantSound");
			val4.transform.position = position;
			AudioSource obj = val4.AddComponent<AudioSource>();
			obj.clip = val;
			obj.volume = VerityPlugin.E1Volume.Value;
			obj.spatialBlend = 1f;
			obj.rolloffMode = (AudioRolloffMode)1;
			obj.minDistance = 6f;
			obj.maxDistance = VerityPlugin.E1MaxAudibleDistance.Value;
			obj.dopplerLevel = 0f;
			obj.priority = 0;
			obj.Play();
			Object.Destroy((Object)val4, val.length + 1f);
			VerityPlugin.Log.LogInfo((object)("Verity event 1: " + ((Object)val).name + " at " + num2.ToString("F1") + "m"));
		}

		public void StartVigil(int seed)
		{
			StopVigil();
			vigilRoutine = ((MonoBehaviour)this).StartCoroutine(VigilRoutine(seed));
		}

		private void StopVigil()
		{
			if (vigilRoutine != null)
			{
				((MonoBehaviour)this).StopCoroutine(vigilRoutine);
				vigilRoutine = null;
			}
			if ((Object)(object)musicSource != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)musicSource).gameObject);
				musicSource = null;
			}
		}

		private IEnumerator VigilRoutine(int seed)
		{
			AudioClip val = VerityAssets.Pick(VerityAssets.Music, new Random(seed));
			float build = Mathf.Max(1f, VerityPlugin.E2BuildupSeconds.Value);
			if ((Object)(object)val != (Object)null)
			{
				GameObject val2 = new GameObject("VerityMusic");
				Object.DontDestroyOnLoad((Object)(object)val2);
				musicSource = val2.AddComponent<AudioSource>();
				musicSource.clip = val;
				musicSource.loop = true;
				musicSource.spatialBlend = 0f;
				musicSource.volume = VerityPlugin.E2StartVolume.Value;
				musicSource.priority = 0;
				musicSource.Play();
			}
			else
			{
				VerityPlugin.Log.LogWarning((object)"Event 2 fired but Assets/sounds/music is empty.");
			}
			VerityPlugin.Log.LogInfo((object)("Verity event 2: buildup " + build + "s"));
			float t = 0f;
			while (t < build)
			{
				t += Time.deltaTime;
				float num = Mathf.Clamp01(t / build);
				if ((Object)(object)musicSource != (Object)null)
				{
					musicSource.volume = Mathf.Lerp(VerityPlugin.E2StartVolume.Value, VerityPlugin.E2EndVolume.Value, num * num);
				}
				yield return null;
			}
			ShowJumpscare(seed, VerityPlugin.E2KillPlayer.Value);
			if ((Object)(object)musicSource != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)musicSource).gameObject);
				musicSource = null;
			}
			vigilRoutine = null;
		}

		public void ShowJumpscare(int seed, bool kill)
		{
			Texture2D val = VerityAssets.Pick(VerityAssets.Jumpscare, new Random(seed));
			AudioClip val2 = VerityAssets.Pick(VerityAssets.Stingers, new Random(seed));
			if ((Object)(object)val2 != (Object)null)
			{
				PlayOneShot2D(val2, 1f);
			}
			if ((Object)(object)val != (Object)null)
			{
				ShowTexture(val, VerityPlugin.E2ImageSeconds.Value, 1f);
			}
			else
			{
				VerityPlugin.Log.LogWarning((object)"No images in Assets/images/jumpscare.");
			}
			if (kill)
			{
				KillLocalPlayer();
			}
		}

		public void ShowFlash(int seed)
		{
			Texture2D val = VerityAssets.Pick(VerityAssets.Flash, new Random(seed));
			if (!((Object)(object)val == (Object)null))
			{
				ShowTexture(val, VerityPlugin.FlashSeconds.Value, 1f);
			}
		}

		private void ShowTexture(Texture2D tex, float seconds, float alpha)
		{
			currentImage = tex;
			imageAlpha = alpha;
			imageUntil = Time.realtimeSinceStartup + Mathf.Max(0.02f, seconds);
		}

		private void OnGUI()
		{
			//IL_002e: 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_00b2: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)currentImage == (Object)null))
			{
				if (Time.realtimeSinceStartup > imageUntil)
				{
					currentImage = null;
					return;
				}
				GUI.depth = -1000;
				Color color = GUI.color;
				GUI.color = new Color(1f, 1f, 1f, imageAlpha);
				float num = Screen.width;
				float num2 = Screen.height;
				float num3 = Mathf.Max(num / (float)((Texture)currentImage).width, num2 / (float)((Texture)currentImage).height);
				float num4 = (float)((Texture)currentImage).width * num3;
				float num5 = (float)((Texture)currentImage).height * num3;
				GUI.DrawTexture(new Rect((num - num4) * 0.5f, (num2 - num5) * 0.5f, num4, num5), (Texture)(object)currentImage, (ScaleMode)0);
				GUI.color = color;
			}
		}

		private void PlayOneShot2D(AudioClip clip, float volume)
		{
			//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_0046: Expected O, but got Unknown
			GameObject val = new GameObject("VerityStinger");
			AudioSource obj = val.AddComponent<AudioSource>();
			obj.clip = clip;
			obj.spatialBlend = 0f;
			obj.volume = volume;
			obj.priority = 0;
			obj.Play();
			Object.Destroy((Object)val, clip.length + 0.5f);
		}

		private void KillLocalPlayer()
		{
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			PlayerControllerB val = LocalPlayer();
			if ((Object)(object)val == (Object)null || val.isPlayerDead)
			{
				return;
			}
			try
			{
				val.KillPlayer(Vector3.zero, true, (CauseOfDeath)0, 0, default(Vector3), false);
			}
			catch (Exception ex)
			{
				VerityPlugin.Log.LogWarning((object)("KillPlayer failed, falling back to damage: " + ex.Message));
				try
				{
					val.DamagePlayer(200, true, true, (CauseOfDeath)0, 0, false, default(Vector3));
				}
				catch
				{
				}
			}
		}

		private void Hotkeys()
		{
			Keyboard current = Keyboard.current;
			if (current != null)
			{
				if (((ButtonControl)current.f7Key).wasPressedThisFrame)
				{
					VerityNet.Broadcast("Verity_Event1", rng.Next(int.MaxValue));
				}
				if (((ButtonControl)current.f8Key).wasPressedThisFrame)
				{
					VerityNet.Broadcast("Verity_Event2", rng.Next(int.MaxValue));
				}
				if (((ButtonControl)current.f9Key).wasPressedThisFrame)
				{
					VerityNet.Broadcast("Verity_Image", rng.Next(int.MaxValue));
				}
				if (((ButtonControl)current.f10Key).wasPressedThisFrame)
				{
					VerityNet.Broadcast("Verity_Flash", rng.Next(int.MaxValue));
				}
				if (((ButtonControl)current.f11Key).wasPressedThisFrame)
				{
					ResetState();
					VerityPlugin.Log.LogInfo((object)"Verity: round state reset.");
				}
			}
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "Verity";

		public const string PLUGIN_NAME = "Verity";

		public const string PLUGIN_VERSION = "0.1.0";
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}