Decompiled source of ExtremeBangerMusic v1.0.14

ExtremeBangerMusic.dll

Decompiled 9 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.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using ExtremeBangerMusic.Patches;
using ExtremeBangerMusic.Utils;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("ExtremeBangerMusic")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ExtremeBangerMusic")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("C9A5DB82-0588-4445-82D2-9D559B22264C")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace ExtremeBangerMusic
{
	[BepInPlugin("Sparky.ExtremeBangerMusic", "ExtremeBangerMusic", "1.0.14")]
	public class ModBase : BaseUnityPlugin
	{
		private const string ModGuid = "Sparky.ExtremeBangerMusic";

		private const string ModName = "ExtremeBangerMusic";

		private const string ModVersion = "1.0.14";

		public static ManualLogSource logger;

		public static ModBase Instance;

		private readonly Harmony _harmony = new Harmony("ExtremeBangerMusic");

		private void Awake()
		{
			Instance = this;
			logger = Logger.CreateLogSource("ExtremeBangerMusic");
			Config.CreateConfig();
			Assets.LoadAssets();
			_harmony.PatchAll(typeof(ModBase));
			_harmony.PatchAll(typeof(HUDManagerPatch));
			_harmony.PatchAll(typeof(StartOfRoundPatch));
			_harmony.PatchAll(typeof(JesterAiPatch));
			logger.LogInfo((object)"Extreme Banger Music has been loaded!");
		}

		private void WaitForDependencyPatchCoroutine(string dependencyName, Type patchType)
		{
			try
			{
				((MonoBehaviour)this).StartCoroutine(DependencyManager.PatchWithDependency(_harmony, dependencyName, patchType));
			}
			catch (Exception ex)
			{
				logger.LogWarning((object)("Error while patching: " + ex));
				throw;
			}
		}
	}
}
namespace ExtremeBangerMusic.Utils
{
	public static class DependencyManager
	{
		private static readonly List<Type> RegisteredPatches = new List<Type>();

		private static bool ModLoaded(string modName)
		{
			return Chainloader.PluginInfos.ContainsKey(modName);
		}

		public static IEnumerator PatchWithDependency(Harmony harmony, string dependency, Type patch)
		{
			if (RegisteredPatches.Contains(patch))
			{
				ModBase.logger.LogInfo((object)("Patch " + patch?.ToString() + " already registered, skipping"));
				yield break;
			}
			ModBase.logger.LogInfo((object)("Wait for " + dependency + " to load"));
			int loadingAttempts = 0;
			while (!ModLoaded(dependency))
			{
				if (loadingAttempts >= Config.MaxDependencyWaitTime.Value)
				{
					throw new Exception("Maximum attempts reached while waiting for " + dependency + " to load");
				}
				yield return (object)new WaitForSeconds(1f);
				loadingAttempts++;
			}
			ModBase.logger.LogInfo((object)("Dependency " + dependency + " loaded, patching " + patch));
			harmony.PatchAll(patch);
			RegisteredPatches.Add(patch);
		}
	}
	public static class Config
	{
		public static ConfigEntry<int> MaxDependencyWaitTime;

		public static ConfigEntry<bool> EnableGamblerModPatch;

		public static ConfigEntry<int> GamblerModMaxMachines;

		public static void CreateConfig()
		{
			ModBase.logger.LogInfo((object)"Creating config");
			MaxDependencyWaitTime = ((BaseUnityPlugin)ModBase.Instance).Config.Bind<int>("Dependency", "MaxDependencyWaitTime", 300, "Maximum time to wait for a dependency to load");
			EnableGamblerModPatch = ((BaseUnityPlugin)ModBase.Instance).Config.Bind<bool>("Dependency", "EnableGamblerModPatch", true, "Enable patch for GamblerMod (more machines)");
			GamblerModMaxMachines = ((BaseUnityPlugin)ModBase.Instance).Config.Bind<int>("Dependency", "GamblerModMaxMachines", 8, "Maximum amount of machines that can be placed with GamblerMod");
			ModBase.logger.LogInfo((object)"Config loaded");
		}
	}
	public static class Assets
	{
		public static AssetBundle Bundle { get; private set; }

		public static AudioClip FinalCountdown { get; private set; }

		public static AudioClip Jester { get; private set; }

		public static AudioClip JesterRave { get; private set; }

		public static void LoadAssets()
		{
			try
			{
				ModBase.logger.LogInfo((object)"Importing AssetBundle");
				string text = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "extremebangermusic");
				ModBase.logger.LogInfo((object)("Loading AssetBundle " + text));
				Bundle = AssetBundle.LoadFromFile(text);
				ModBase.logger.LogInfo((object)"Loading FinalCountdown");
				FinalCountdown = Bundle.LoadAsset<AudioClip>("Assets/FinalCountdown.wav");
				ModBase.logger.LogInfo((object)"Loading Jester");
				Jester = Bundle.LoadAsset<AudioClip>("Assets/Jester.wav");
				ModBase.logger.LogInfo((object)"Loading JesterRave");
				JesterRave = Bundle.LoadAsset<AudioClip>("Assets/JesterRave.wav");
			}
			catch (Exception ex)
			{
				ModBase.logger.LogError((object)("Error while loading assets: " + ex));
				throw;
			}
		}
	}
}
namespace ExtremeBangerMusic.Patches
{
	[HarmonyPatch(typeof(HUDManager))]
	internal class HUDManagerPatch
	{
		[HarmonyPatch(typeof(HUDManager), "ReadDialogue")]
		[HarmonyPostfix]
		private static void PlayFinalCountdown(HUDManager __instance, DialogueSegment[] dialogueArray)
		{
			try
			{
				string text = dialogueArray[0].bodyText.Substring(0, 22);
				if (!(text != "WARNING! Please return") || !(text != "WARNING!!! The autopil"))
				{
					ModBase.logger.LogInfo((object)"Final countdown");
					__instance.LevellingAudio.PlayOneShot(Assets.FinalCountdown);
					ModBase.logger.LogInfo((object)"Final countdown played");
				}
			}
			catch (Exception ex)
			{
				ModBase.logger.LogError((object)ex);
			}
		}
	}
	[HarmonyPatch(typeof(JesterAI))]
	internal class JesterAiPatch
	{
		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		public static void JesterPatch(ref AudioClip ___popGoesTheWeaselTheme, ref AudioClip ___screamingSFX, ref AudioSource ___farAudio, ref AudioSource ___creatureVoice)
		{
			try
			{
				___popGoesTheWeaselTheme = Assets.Jester;
				___farAudio.volume = 0.5f;
				___screamingSFX = Assets.JesterRave;
				___creatureVoice.volume = 1f;
			}
			catch (Exception ex)
			{
				ModBase.logger.LogError((object)ex);
			}
		}
	}
	[HarmonyPatch(typeof(StartOfRound))]
	internal class StartOfRoundPatch
	{
		[HarmonyPatch(typeof(StartOfRound), "ShipLeave")]
		[HarmonyPostfix]
		public static void DisableFinalCountdown(StartOfRound __instance)
		{
			try
			{
				ModBase.logger.LogInfo((object)"Attempting to stop levellingAudio");
				HUDManager.Instance.LevellingAudio.Stop();
				ModBase.logger.LogInfo((object)"Success stop levellingAudio");
			}
			catch (Exception ex)
			{
				ModBase.logger.LogError((object)ex);
			}
		}
	}
}
namespace ExtremeBangerMusic.Patches.GamblingMachine
{
	[HarmonyPatch]
	public static class RoundManagerCustomPatch
	{
		[HarmonyPatch("GamblersMod.RoundManagerCustomSpace.RoundManagerCustom, GamblersMod", "Awake")]
		[HarmonyPostfix]
		public static void AwakePostfix(object __instance)
		{
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			ModBase.logger.LogInfo((object)"RoundManagerCustomPatch.Awake: Add new spawn points");
			Type type = AccessTools.TypeByName("GamblersMod.RoundManagerCustomSpace.RoundManagerCustom");
			FieldInfo fieldInfo = AccessTools.Field(type, "spawnPoints");
			if (!(fieldInfo == null))
			{
				List<Vector3> list = (List<Vector3>)fieldInfo.GetValue(__instance);
				list.RemoveRange(0, 4);
				for (int i = 0; i < Config.GamblerModMaxMachines.Value; i++)
				{
					list.Add(new Vector3(-27.808f, -2.6256f, -9.7409f + (float)(i * 5)));
				}
			}
		}
	}
}