Decompiled source of AGGHHH Falling Scream v1.2.1

BepInEx/plugins/conchaSuMare.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 BepInEx.Logging;
using ConchaSuMare.Patches;
using GameNetcodeStuff;
using HarmonyLib;
using UnityEngine;
using UnityEngine.Networking;
using conchaSuMare.Objects;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("conchaSuMare")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("conchaSuMare")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("3572c49e-26d4-4444-9905-d2e2c4b5f38a")]
[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")]
public static class CoroutineHelper
{
	private class CoroutineRunner : MonoBehaviour
	{
	}

	private static GameObject coroutineObject;

	public static void StartCoroutine(IEnumerator coroutine)
	{
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Expected O, but got Unknown
		if ((Object)(object)coroutineObject == (Object)null)
		{
			coroutineObject = new GameObject("CoroutineHelper");
			Object.DontDestroyOnLoad((Object)(object)coroutineObject);
		}
		((MonoBehaviour)coroutineObject.AddComponent<CoroutineRunner>()).StartCoroutine(coroutine);
	}
}
namespace ConchaSuMare
{
	[BepInPlugin("Lecre.ConchaSuMareMod", "LC ConchaSuMareMod", "1.2.1")]
	public class ConchaSuMare : BaseUnityPlugin
	{
		private const string modGUID = "Lecre.ConchaSuMareMod";

		private const string modName = "LC ConchaSuMareMod";

		private const string modVersion = "1.2.1";

		private readonly Harmony harmony = new Harmony("Lecre.ConchaSuMareMod");

		public static ConchaSuMare instance;

		internal ManualLogSource mls;

		private void Awake()
		{
			mls = Logger.CreateLogSource("Lecre.ConchaSuMareMod");
			instance = this;
			Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject);
			if ((Object)(object)instance == (Object)null)
			{
				instance = this;
				Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject);
			}
			else
			{
				mls.LogInfo((object)"Happy kirbi :)");
			}
			mls.LogInfo((object)"Lecre.ConchaSuMareMod is loading");
			if ((Object)(object)instance == (Object)null)
			{
				mls.LogError((object)"INSTANCE IS NULL 2 TIMES IN A ROW, CONCHASUMARE WILL BE DISABLED");
			}
			harmony.PatchAll(typeof(ConchaSuMare));
			harmony.PatchAll(typeof(FallvoidPatch));
		}
	}
}
namespace ConchaSuMare.Patches
{
	[HarmonyPatch(typeof(PlayerControllerB))]
	internal class FallvoidPatch : HarmonyPatch
	{
		public static List<PlayerSoundStatus> playerSoundStatusList = new List<PlayerSoundStatus>();

		public static AudioClip newSFX;

		private static ManualLogSource mls;

		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		private static void startEventListener()
		{
			mls = Logger.CreateLogSource("Lecre.conchaSuMareMod");
			mls.LogInfo((object)"Starting to upload audio");
			if ((Object)(object)ConchaSuMare.instance != (Object)null)
			{
				string location = ((BaseUnityPlugin)ConchaSuMare.instance).Info.Location;
				string text = "conchaSuMare.dll";
				string text2 = location.TrimEnd(text.ToCharArray());
				string text3 = text2 + "CONCHA.wav";
				mls.LogInfo((object)("IS THE AUDIO FILE LOCATED HERE??: " + text3));
				((MonoBehaviour)ConchaSuMare.instance).StartCoroutine(LoadAudio("file:///" + text3, delegate(AudioClip sound)
				{
					newSFX = sound;
				}));
			}
			else
			{
				mls.LogWarning((object)"Instance was readed like <null> retriying to load audio files");
				string location2 = Assembly.GetExecutingAssembly().Location;
				string directoryName = Path.GetDirectoryName(location2);
				string text4 = Path.Combine(directoryName, "CONCHA.wav");
				mls.LogInfo((object)("(else)IS THE AUDIO FILE LOCATED HERE??: " + text4));
				CoroutineHelper.StartCoroutine(LoadAudio("file:///" + text4, delegate(AudioClip sound)
				{
					newSFX = sound;
				}));
			}
		}

		public static IEnumerator LoadAudio(string url, Action<AudioClip> callback)
		{
			UnityWebRequest www = UnityWebRequestMultimedia.GetAudioClip(url, (AudioType)20);
			try
			{
				yield return www.SendWebRequest();
				if ((int)www.result == 2)
				{
					mls.LogError((object)"Failed to load audio assets!");
					yield break;
				}
				AudioClip clip = DownloadHandlerAudioClip.GetContent(www);
				if ((Object)(object)clip == (Object)null)
				{
					mls.LogError((object)"The audio clip is null after loading!");
					yield break;
				}
				callback(clip);
				mls.LogInfo((object)"Audio inserted");
			}
			finally
			{
				((IDisposable)www)?.Dispose();
			}
		}

		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		private static void SoundVoidPatch(ref PlayerControllerB __instance)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Invalid comparison between Unknown and I4
			mls = Logger.CreateLogSource("Lecre.conchaSuMareMod");
			PlayerControllerB val = __instance;
			PlayerSoundStatus item = new PlayerSoundStatus(val);
			CauseOfDeath causeOfDeath = val.causeOfDeath;
			if ((Object)(object)__instance == (Object)null)
			{
				mls.LogInfo((object)"We have a problem... playerRef = null :(");
			}
			if (val.isPlayerDead && (int)causeOfDeath == 2)
			{
				if (!playerSoundStatusList.Contains(item))
				{
					playerSoundStatusList.Add(item);
					return;
				}
				item = playerSoundStatusList[playerSoundStatusList.IndexOf(item)];
				if (!item._status)
				{
					AudioSource val2 = ((Component)val).gameObject.AddComponent<AudioSource>();
					val2.clip = newSFX;
					val2.Play();
					item._status = true;
					mls.LogInfo((object)"CONCHA TU MAIIII, one memeber of the crew fell to the void, what a loser xD");
				}
			}
			else if (!val.isPlayerDead && playerSoundStatusList.IndexOf(item) != -1)
			{
				playerSoundStatusList.Remove(item);
			}
		}
	}
}
namespace conchaSuMare.Objects
{
	internal class PlayerSoundStatus
	{
		public bool _status;

		public PlayerControllerB _player;

		public bool Status
		{
			get
			{
				return _status;
			}
			set
			{
				_status = value;
			}
		}

		private PlayerControllerB Player
		{
			get
			{
				return _player;
			}
			set
			{
				_player = value;
			}
		}

		public PlayerSoundStatus(PlayerControllerB player)
		{
			Player = player;
			Status = false;
		}

		public override bool Equals(object obj)
		{
			if (obj == null || GetType() != obj.GetType())
			{
				return false;
			}
			PlayerSoundStatus playerSoundStatus = (PlayerSoundStatus)obj;
			return ((object)Player).Equals((object?)playerSoundStatus.Player);
		}
	}
}