Decompiled source of GiveUpYourMind v1.0.0

Give Up Your Mind.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.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using GameNetcodeStuff;
using UnityEngine;
using UnityEngine.Networking;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("Give Up Your Mind")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Give Up Your Mind")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("4ebd7b75-d85f-4ea0-9d2d-039ce038d6ca")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
[BepInPlugin("giveupyourmind", "Give Up Your Mind", "1.0.0")]
public class MyModName : BaseUnityPlugin
{
	private const string PLUGIN_GUID = "giveupyourmind";

	private const string PLUGIN_NAME = "Give Up Your Mind";

	private const string PLUGIN_VERSION = "1.0.0";

	private bool jumpScaring = false;

	private GameObject player;

	private AudioSource audioSource;

	private AudioClip audioClip1;

	private AudioClip audioClip2;

	private AudioClip audioClip3;

	private AudioClip audioClip4;

	private bool isInsane = false;

	private float insanityStartTime;

	private AudioSource audioSource1;

	private AudioSource GUYM;

	private AudioSource Music;

	private AudioSource CountDown;

	private AudioSource Transitions;

	private AudioSource Ambience;

	private AudioSource Ambience2;

	private List<AudioClip> insanityAmbienceSounds = new List<AudioClip>();

	private float nextSoundTime = 0f;

	private Dictionary<Light, Color> originalLightColors = new Dictionary<Light, Color>();

	private void Awake()
	{
		string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
		audioSource1 = ((Component)this).gameObject.AddComponent<AudioSource>();
		GUYM = ((Component)this).gameObject.AddComponent<AudioSource>();
		Transitions = ((Component)this).gameObject.AddComponent<AudioSource>();
		Music = ((Component)this).gameObject.AddComponent<AudioSource>();
		CountDown = ((Component)this).gameObject.AddComponent<AudioSource>();
		Ambience = ((Component)this).gameObject.AddComponent<AudioSource>();
		Ambience2 = ((Component)this).gameObject.AddComponent<AudioSource>();
		CountDown.volume = 0.2f;
		((MonoBehaviour)this).StartCoroutine(LoadAudioClip(Path.Combine(directoryName, "Sounds/AudioGlitch.wav"), delegate(AudioClip clip)
		{
			audioClip1 = clip;
		}));
		((MonoBehaviour)this).StartCoroutine(LoadAudioClip(Path.Combine(directoryName, "Sounds/GIVEUPYOURMIND.wav"), delegate(AudioClip clip)
		{
			audioClip2 = clip;
		}));
		((MonoBehaviour)this).StartCoroutine(LoadAudioClip(Path.Combine(directoryName, "Sounds/IncreasingHeartbeat.wav"), delegate(AudioClip clip)
		{
			audioClip3 = clip;
		}));
		((MonoBehaviour)this).StartCoroutine(LoadAudioClip(Path.Combine(directoryName, "Sounds/GiveUpYourMindAmbience.wav"), delegate(AudioClip clip)
		{
			audioClip4 = clip;
		}));
		((MonoBehaviour)this).StartCoroutine(LoadInsanityAmbienceSounds(Path.Combine(directoryName, "InsanityAmbienceSounds")));
		audioSource = ((Component)this).gameObject.AddComponent<AudioSource>();
		((MonoBehaviour)this).StartCoroutine(CheckPlayerAndEnvironment());
	}

	private IEnumerator LoadInsanityAmbienceSounds(string directoryPath)
	{
		DirectoryInfo dir = new DirectoryInfo(directoryPath);
		FileInfo[] files = dir.GetFiles("*.wav");
		FileInfo[] array = files;
		foreach (FileInfo file in array)
		{
			UnityWebRequest www = UnityWebRequestMultimedia.GetAudioClip("file://" + file.FullName, (AudioType)20);
			try
			{
				yield return www.SendWebRequest();
				if ((int)www.result == 1)
				{
					insanityAmbienceSounds.Add(DownloadHandlerAudioClip.GetContent(www));
				}
			}
			finally
			{
				((IDisposable)www)?.Dispose();
			}
		}
	}

	private IEnumerator LoadAudioClip(string path, Action<AudioClip> setResult)
	{
		UnityWebRequest www = UnityWebRequestMultimedia.GetAudioClip("file://" + path, (AudioType)20);
		try
		{
			yield return www.SendWebRequest();
			if ((int)www.result == 1)
			{
				setResult(DownloadHandlerAudioClip.GetContent(www));
			}
		}
		finally
		{
			((IDisposable)www)?.Dispose();
		}
	}

	private IEnumerator CheckPlayerAndEnvironment()
	{
		while (true)
		{
			if (isInsane && (Object)(object)player != (Object)null && player.transform.position.y >= -200f)
			{
				EndInsanity();
			}
			if ((Object)(object)GameNetworkManager.Instance != (Object)null && (Object)(object)GameNetworkManager.Instance.localPlayerController != (Object)null)
			{
				player = ((Component)GameNetworkManager.Instance.localPlayerController).gameObject;
				if (player.transform.position.y < -200f && !isInsane)
				{
					yield return (object)new WaitForSeconds(60f);
					if (Random.value < 1f)
					{
						yield return (object)new WaitForSeconds(1f);
						StartInsanity();
					}
				}
				else if (isInsane)
				{
					if (Time.time - insanityStartTime >= 60f)
					{
						OneMinuteOfInsanity();
					}
					if (Time.time >= nextSoundTime)
					{
						PlayRandomInsanityAmbienceSound();
						nextSoundTime = Time.time + 15f;
					}
				}
			}
			yield return null;
		}
	}

	private void PlayRandomInsanityAmbienceSound()
	{
		if (insanityAmbienceSounds.Count > 0 && (double)Random.value <= 0.45)
		{
			AudioClip val = insanityAmbienceSounds[Random.Range(0, insanityAmbienceSounds.Count)];
			Ambience.PlayOneShot(val);
		}
	}

	private void StartInsanity()
	{
		//IL_001e: 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_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_0055: Unknown result type (might be due to invalid IL or missing references)
		//IL_010c: Unknown result type (might be due to invalid IL or missing references)
		Light[] array = Object.FindObjectsOfType<Light>();
		Light[] array2 = array;
		foreach (Light val in array2)
		{
			originalLightColors[val] = val.color;
			val.color = Color32.op_Implicit(new Color32(byte.MaxValue, (byte)0, (byte)0, (byte)1));
		}
		RenderSettings.fog = true;
		RenderSettings.fogColor = Color.black;
		RenderSettings.fogDensity = 1f;
		AudioSource[] array3 = Object.FindObjectsOfType<AudioSource>();
		AudioSource[] array4 = array3;
		foreach (AudioSource val2 in array4)
		{
			if ((Object)(object)val2 != (Object)(object)audioSource)
			{
				val2.mute = true;
			}
		}
		if ((Object)(object)Ambience2 != (Object)null)
		{
			GUYM.PlayOneShot(audioClip2);
			Ambience2.PlayOneShot(audioClip4);
			Music.PlayOneShot(audioClip3);
		}
		Light[] array5 = array;
		foreach (Light val3 in array5)
		{
			val3.color = Color.red;
		}
		isInsane = true;
		insanityStartTime = Time.time;
	}

	private void EndInsanity()
	{
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		foreach (KeyValuePair<Light, Color> originalLightColor in originalLightColors)
		{
			if ((Object)(object)originalLightColor.Key != (Object)null)
			{
				originalLightColor.Key.color = originalLightColor.Value;
			}
		}
		AudioSource[] array = Object.FindObjectsOfType<AudioSource>();
		AudioSource[] array2 = array;
		foreach (AudioSource val in array2)
		{
			val.mute = false;
		}
		if ((Object)(object)audioClip2 != (Object)null)
		{
			Transitions.PlayOneShot(audioClip1);
		}
		isInsane = false;
		if ((Object)(object)Ambience2 != (Object)null)
		{
			Ambience2.Stop();
		}
		Music.Stop();
	}

	private void OneMinuteOfInsanity()
	{
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		PlayerControllerB component = player.GetComponent<PlayerControllerB>();
		if ((Object)(object)component != (Object)null)
		{
			component.KillPlayer(Vector3.zero, true, (CauseOfDeath)10, 0);
		}
		EndInsanity();
	}
}