Decompiled source of DentysLCModPack v1.4.5

DentysLCModPack.dll

Decompiled a year ago
using System;
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.Configuration;
using BepInEx.Logging;
using DentysLCModPack.Features.Utilities;
using DentysLCModPack.Patches;
using GameNetcodeStuff;
using HarmonyLib;
using LethalLib.Modules;
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("BepInExTestMod")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("BepInExTestMod")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("32c2d4c4-e4e6-40cc-b491-bbea2dc9cd1d")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace DentysLCModPack
{
	[BepInPlugin("Denty.DentysLCModPack", "DentysLCModPack", "1.4.4")]
	public class DentysLCModPack : BaseUnityPlugin
	{
		public static class ConfigSettings
		{
			public static ConfigEntry<bool> testBool;

			public static ConfigEntry<bool> customMenuMusic;

			public static ConfigEntry<bool> customMineDetonateAudio;

			public static ConfigEntry<bool> customMinePressAudio;

			public static ConfigEntry<bool> customFlowermanNecksnapAudio;

			public static void BindConfigSettings()
			{
				mls.LogInfo((object)"BindingConfigs");
				testBool = ((BaseUnityPlugin)Instance).Config.Bind<bool>("Main Settings", "Test Bool", true, "Testing bool bla bla bla, this does nothing.");
				customMenuMusic = ((BaseUnityPlugin)Instance).Config.Bind<bool>("Main Settings", "Custom Main Menu Music", true, "Should the main menu music be replaced? (Includes easter-egg audio)");
				customMineDetonateAudio = ((BaseUnityPlugin)Instance).Config.Bind<bool>("Main Settings", "Custom mine Detonate Audio", true, "Should the mine detonate audio be replaced?");
				customMinePressAudio = ((BaseUnityPlugin)Instance).Config.Bind<bool>("Main Settings", "Custom Mine Press Audio", true, "Should the mine press audio be replaced?");
				customFlowermanNecksnapAudio = ((BaseUnityPlugin)Instance).Config.Bind<bool>("Main Settings", "Custom Bracken Necksnap Audio", true, "Should the bracken necksnap audio be replaced? (Its tyler1 screaming for help)");
			}
		}

		private const string modGUILD = "Denty.DentysLCModPack";

		private const string modName = "DentysLCModPack";

		private const string modVersion = "1.4.4";

		private readonly Harmony harmony = new Harmony("Denty.DentysLCModPack");

		public static DentysLCModPack Instance;

		public static string filePath;

		internal static ManualLogSource mls;

		public static AssetBundle DentyBundle;

		public static string MenuMusicPath = "Assets/DentysLCPackBundles/MainMenuAudio.mp3";

		public static string SecretMenuMusicPath = "Assets/DentysLCPackBundles/SecretMainMenuAudio.mp3";

		public static string MenuCustomImage = "Assets/DentysLCPackBundles/CustomBackground.png";

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			DentyBundle = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "dentyslcpackbundles"));
			mls = Logger.CreateLogSource("Denty.DentysLCModPack");
			mls.LogInfo((object)"DentysLCModPack has been loaded smile");
			ConfigSettings.BindConfigSettings();
			harmony.PatchAll(typeof(DentysLCModPack));
			harmony.PatchAll(typeof(MinePatch));
			harmony.PatchAll(typeof(FlowermanAIPatch));
			harmony.PatchAll(typeof(MenuPatch));
			LoadCustomAssets();
		}

		private static void LoadCustomAssets()
		{
			LoadAndRegisterCustomItem("FryingPan", "Assets/DentysLCPackBundles/CustomItems/Scrap/FryingPanScrap/Pan.asset", 100, (LevelTypes)510, 0);
		}

		private static void LoadAndRegisterCustomItem(string itemName, string assetPath, int scrapValue, LevelTypes levelType, int shopItemPrice)
		{
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			mls.LogInfo((object)("Trying to load custom " + itemName));
			Item val = DentyBundle.LoadAsset<Item>(assetPath);
			if ((Object)(object)val != (Object)null)
			{
				mls.LogInfo((object)("Custom " + itemName + " loaded successfully."));
				NetworkPrefabs.RegisterNetworkPrefab(val.spawnPrefab);
				Items.RegisterScrap(val, scrapValue, levelType);
				if (shopItemPrice != 0)
				{
					Items.RegisterShopItem(val, shopItemPrice);
				}
			}
			else
			{
				mls.LogError((object)("Failed to load custom " + itemName + " from path: " + assetPath));
			}
		}
	}
}
namespace DentysLCModPack.Patches
{
	internal class FlowermanAIPatch
	{
		[HarmonyPatch(typeof(FlowermanAI), "Start")]
		[HarmonyPostfix]
		public static void FlowermanNeckSnapPatch(FlowermanAI __instance)
		{
			if (DentysLCModPack.ConfigSettings.customFlowermanNecksnapAudio.Value)
			{
				AudioClip crackNeckSFX = DentysLCModPack.DentyBundle.LoadAsset<AudioClip>("Assets/DentysLCPackBundles/FlowermanNecksnapAudio.mp3");
				__instance.crackNeckSFX = crackNeckSFX;
			}
		}
	}
	public class MenuPatch
	{
		[HarmonyPatch(typeof(MenuManager), "Start")]
		[HarmonyPostfix]
		public static void MenuManagerMusicOverridePatch(MenuManager __instance)
		{
			if (!DentysLCModPack.ConfigSettings.customMenuMusic.Value)
			{
				return;
			}
			DentysLCModPack.mls.LogInfo((object)("Attempting to load AudioClip from path: " + DentysLCModPack.MenuMusicPath));
			AudioClip val;
			if (EventProbabilityUtility.ShouldOccurWithProbability(10f))
			{
				val = DentysLCModPack.DentyBundle.LoadAsset<AudioClip>(DentysLCModPack.SecretMenuMusicPath);
				if ((Object)(object)val != (Object)null)
				{
					__instance.menuMusic = val;
					__instance.MenuAudio.clip = val;
					__instance.MenuAudio.volume = 0.1f;
					DentysLCModPack.mls.LogInfo((object)("Secret song patch applied. AudioClip replaced using path: " + DentysLCModPack.SecretMenuMusicPath));
					return;
				}
				DentysLCModPack.mls.LogInfo((object)("Failed to load secret song AudioClip from path: " + DentysLCModPack.SecretMenuMusicPath));
			}
			val = DentysLCModPack.DentyBundle.LoadAsset<AudioClip>(DentysLCModPack.MenuMusicPath);
			if ((Object)(object)val != (Object)null)
			{
				__instance.menuMusic = val;
				__instance.MenuAudio.clip = val;
				__instance.MenuAudio.volume = 0.1f;
				DentysLCModPack.mls.LogInfo((object)("Menu music patch applied. AudioClip replaced using path: " + DentysLCModPack.MenuMusicPath));
			}
			else
			{
				DentysLCModPack.mls.LogInfo((object)("Failed to load AudioClip from path: " + DentysLCModPack.MenuMusicPath));
			}
		}
	}
	[HarmonyPatch(typeof(PlayerControllerB))]
	internal class PlayerControllerBPatch
	{
		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		private static void InfSprintPatch(ref float ___sprintMeter)
		{
			___sprintMeter = 1f;
		}
	}
	internal class MinePatch
	{
		[HarmonyPatch(typeof(Landmine), "Start")]
		[HarmonyPostfix]
		public static void MineAudio(Landmine __instance)
		{
			if (DentysLCModPack.ConfigSettings.customMineDetonateAudio.Value)
			{
				AudioClip mineDetonate = DentysLCModPack.DentyBundle.LoadAsset<AudioClip>("Assets/DentysLCPackBundles/LandMineDetonate.mp3");
				__instance.mineDetonate = mineDetonate;
			}
			if (DentysLCModPack.ConfigSettings.customMinePressAudio.Value)
			{
				AudioClip minePress = DentysLCModPack.DentyBundle.LoadAsset<AudioClip>("Assets/DentysLCPackBundles/LandMinePress.mp3");
				__instance.minePress = minePress;
			}
		}
	}
}
namespace DentysLCModPack.Features.Utilities
{
	internal static class EventProbabilityUtility
	{
		public static bool ShouldOccurWithProbability(float percentage)
		{
			if (percentage < 0f || percentage > 100f)
			{
				throw new ArgumentException("Percentage must be between 0 and 100");
			}
			float num = Random.Range(0f, 100f);
			return num <= percentage;
		}
	}
	public class BundleUtilities
	{
		public static byte[] GetResourceBytes(string filename)
		{
			Assembly executingAssembly = Assembly.GetExecutingAssembly();
			string[] manifestResourceNames = executingAssembly.GetManifestResourceNames();
			string[] array = manifestResourceNames;
			foreach (string text in array)
			{
				if (text.Contains(filename))
				{
					Stream manifestResourceStream = executingAssembly.GetManifestResourceStream(text);
					if (manifestResourceStream == null)
					{
						return null;
					}
					byte[] array2 = new byte[manifestResourceStream.Length];
					manifestResourceStream.Read(array2, 0, array2.Length);
					return array2;
				}
			}
			return null;
		}

		public static AssetBundle LoadBundleFromInternalAssembly(string filename)
		{
			return AssetBundle.LoadFromMemory(GetResourceBytes(filename));
		}
	}
}