Decompiled source of Silly Big Mod v1.0.3

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);
		}
	}
}

ElevatorSymphony.dll

Decompiled 2 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Threading.Tasks;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using ElevatorSymphony.Patches;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
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("Assembly-CSharp")]
[assembly: AssemblyCompany("ElevatorSymphony")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("My first plugin")]
[assembly: AssemblyFileVersion("1.1.2.0")]
[assembly: AssemblyInformationalVersion("1.1.2")]
[assembly: AssemblyProduct("ElevatorSymphony")]
[assembly: AssemblyTitle("ElevatorSymphony")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.2.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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 ElevatorSymphony
{
	[BepInPlugin("com.sk737.elevatorsymphony", "ElevatorSymphony", "1.1.2")]
	public class Plugin : BaseUnityPlugin
	{
		internal const string GUID = "com.sk737.elevatorsymphony";

		internal const string NAME = "ElevatorSymphony";

		internal const string VERSION = "1.1.2";

		private string[] mClipFiles;

		private Harmony mHarmony = new Harmony("com.sk737.elevatorsymphony");

		private int mTotalWeight;

		internal static ManualLogSource LoggerInstance { get; private set; }

		internal static Plugin Instance { get; private set; }

		internal string ExecutingPath => Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

		internal List<AudioClip> Clips { get; set; } = new List<AudioClip>();


		internal Random Random { get; set; }

		public static Config Config { get; private set; }

		private void Awake()
		{
			Instance = this;
			LoggerInstance = ((BaseUnityPlugin)this).Logger;
			if (Directory.Exists(ExecutingPath + "/Music"))
			{
				List<string> list = new List<string>();
				list.AddRange(from f in Directory.GetFiles(ExecutingPath + "/Music")
					orderby f
					select f);
				mClipFiles = list.ToArray();
			}
			Config = new Config(((BaseUnityPlugin)this).Config, mClipFiles);
			foreach (ConfigEntry<int> songWeight in Config.SongWeights)
			{
				mTotalWeight += songWeight.Value;
			}
			string[] array = mClipFiles;
			foreach (string path in array)
			{
				LoadClip(path, delegate(AudioClip c)
				{
					lock (Clips)
					{
						Clips.Add(c);
					}
				});
			}
			mHarmony.PatchAll(typeof(RoundManagerPatch));
			mHarmony.PatchAll(typeof(StartStartOfRoundPatch));
			mHarmony.PatchAll(typeof(Plugin));
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin ElevatorSymphony is loaded!");
		}

		public AudioType GetAudioType(string extension)
		{
			return (AudioType)(extension switch
			{
				".mp3" => 13, 
				".wav" => 20, 
				_ => 14, 
			});
		}

		public async Task LoadClip(string path, Action<AudioClip> callback)
		{
			AudioType audioType = GetAudioType(Path.GetExtension(path));
			UnityWebRequest request = UnityWebRequestMultimedia.GetAudioClip(path, audioType);
			try
			{
				request.SendWebRequest();
				while (!request.isDone)
				{
					await Task.Delay(50);
				}
				if ((int)request.result != 1)
				{
					((BaseUnityPlugin)this).Logger.LogError((object)("Failed to load file:" + path + ", + " + request.error));
					return;
				}
				AudioClip content = DownloadHandlerAudioClip.GetContent(request);
				((BaseUnityPlugin)this).Logger.LogMessage((object)("Loaded file: " + path));
				callback(content);
			}
			finally
			{
				if (request != null)
				{
					request.Dispose();
				}
			}
		}

		public void LoadNewAudioFile()
		{
			int num = Random.Next(0, mTotalWeight);
			int num2 = -1;
			int num3 = 0;
			for (int i = 0; i < Config.SongWeights.Count; i++)
			{
				int num4 = num3;
				num3 += Config.SongWeights[i].Value;
				if (num > num4 && num < num3)
				{
					num2 = i - 1;
					break;
				}
			}
			if (num2 >= 0 && mClipFiles.Length != 0)
			{
				LoadClip(mClipFiles[num2], SetElevator);
			}
		}

		public void SetElevator(AudioClip clip)
		{
			MineshaftElevatorController val = Object.FindObjectOfType<MineshaftElevatorController>();
			if ((Object)(object)val != (Object)null)
			{
				val.elevatorJingleMusic.clip = clip;
			}
		}
	}
	public class Config
	{
		public static List<ConfigEntry<int>> SongWeights = new List<ConfigEntry<int>>();

		public Config(ConfigFile config, string[] clipFiles)
		{
			SongWeights.Add(config.Bind<int>("General", "Default chance", 100, "Chance of the base games song being picked by the randomizer. The higher the value the greater the chance it is picked."));
			for (int i = 0; i < clipFiles.Length; i++)
			{
				string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(clipFiles[i]);
				SongWeights.Add(config.Bind<int>("General", fileNameWithoutExtension + " chance", 100, "Chance of " + fileNameWithoutExtension + " being picked by the randomizer. The higher the value the greater the chance it is picked."));
			}
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "ElevatorSymphony";

		public const string PLUGIN_NAME = "ElevatorSymphony";

		public const string PLUGIN_VERSION = "1.1.2";
	}
}
namespace ElevatorSymphony.Patches
{
	[HarmonyPatch(typeof(RoundManager))]
	internal class RoundManagerPatch
	{
		[HarmonyPatch("InitializeRandomNumberGenerators")]
		[HarmonyPrefix]
		public static void SeedPatch(ref RoundManager __instance)
		{
			Plugin.LoggerInstance.LogInfo((object)$"Initializing random with seed {__instance.playersManager.randomMapSeed}");
			Plugin.Instance.Random = new Random(__instance.playersManager.randomMapSeed);
		}
	}
	[HarmonyPatch(typeof(StartOfRound))]
	internal class StartStartOfRoundPatch
	{
		[HarmonyPatch("openingDoorsSequence")]
		[HarmonyPostfix]
		public static void openingDoorsSequencePatch()
		{
			Plugin.Instance.LoadNewAudioFile();
			MineshaftElevatorController val = Object.FindObjectOfType<MineshaftElevatorController>();
			if ((Object)(object)val != (Object)null)
			{
				List<AudioClip> list = new List<AudioClip>();
				list.AddRange(val.elevatorHalloweenClips.Concat(Plugin.Instance.Clips));
				val.elevatorHalloweenClips = list.ToArray();
				List<AudioClip> list2 = new List<AudioClip>();
				list2.AddRange(val.elevatorHalloweenClipsLoop.Concat(Plugin.Instance.Clips));
				val.elevatorHalloweenClipsLoop = list2.ToArray();
			}
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}