Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of FunMines v1.2.0
FunMines.dll
Decompiled 2 years agousing System; using System.Collections; 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 FunMines.Patches; using FunMines.Utils; using GameNetcodeStuff; using HarmonyLib; using UnityEngine; using UnityEngine.Networking; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: AssemblyTitle("FunMines")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("FunMines")] [assembly: AssemblyCopyright("Copyright © 2023")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("de7fb2a9-241f-4b66-a433-bda93bc6545a")] [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")] namespace FunMines { [BepInPlugin("FunMinesProximity", "Fun Mines :)", "1.2")] public class PluginBase : BaseUnityPlugin { public const string modGUID = "FunMinesProximity"; private readonly Harmony harmony = new Harmony("FunMinesProximity"); public static PluginBase Instance; internal ManualLogSource log; private void Awake() { if ((Object)(object)Instance == (Object)null) { Instance = this; } log = Logger.CreateLogSource("FunMinesProximity"); log.LogInfo((object)"Mod loaded"); harmony.PatchAll(typeof(PluginBase)); harmony.PatchAll(typeof(LandminePatch)); harmony.PatchAll(typeof(StartOfRoundPatch)); } public static void LogInfo(string message) { ((BaseUnityPlugin)Instance).Logger.Log((LogLevel)16, (object)message); } public static void LogWarning(string message) { ((BaseUnityPlugin)Instance).Logger.Log((LogLevel)4, (object)message); } public static void LogError(string message) { ((BaseUnityPlugin)Instance).Logger.Log((LogLevel)2, (object)message); } public static void LogError(Exception ex) { ((BaseUnityPlugin)Instance).Logger.Log((LogLevel)2, (object)ex); } } } namespace FunMines.Utils { internal static class MineDangerProximityAudio { private static bool hasRan; public static string audioPath = Path.Combine(Paths.PluginPath, "FunMinesProximity", "mine_proximity.wav"); public static readonly string audioPath2 = Path.Combine(Paths.PluginPath, "RedaOps-FunMines", "FunMinesProximity", "mine_proximity.wav"); public static AudioClip Clip = null; public static bool ready = false; public static void LoadClip() { if (hasRan) { return; } hasRan = true; if (!File.Exists(audioPath)) { PluginBase.LogError("Couldn't load " + audioPath); if (!File.Exists(audioPath2)) { PluginBase.LogError("Couldn't load " + audioPath2); return; } PluginBase.LogInfo("But " + audioPath2 + " exists"); audioPath = audioPath2; } SharedCoroutineStarter.StartCoroutine(LoadAudioCLip()); } private static IEnumerator LoadAudioCLip() { UnityWebRequest fileLoder = UnityWebRequestMultimedia.GetAudioClip(audioPath, (AudioType)20); fileLoder.SendWebRequest(); while (!fileLoder.isDone) { yield return null; } if (fileLoder.error != null) { PluginBase.LogError("Error loading audio clip: " + fileLoder.error); yield break; } AudioClip content = DownloadHandlerAudioClip.GetContent(fileLoder); if (Object.op_Implicit((Object)(object)content) && (int)content.loadState == 2) { PluginBase.LogInfo("Sucesfully loaded audio clip"); ((Object)content).name = Path.GetFileName(audioPath); Clip = content; ready = true; } } } public class SharedCoroutineStarter : MonoBehaviour { private static SharedCoroutineStarter _instance; public static Coroutine StartCoroutine(IEnumerator routine) { //IL_0012: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)_instance == (Object)null) { _instance = new GameObject("Shared Coroutine Starter").AddComponent<SharedCoroutineStarter>(); Object.DontDestroyOnLoad((Object)(object)_instance); } return ((MonoBehaviour)_instance).StartCoroutine(routine); } } } namespace FunMines.Patches { [HarmonyPatch(typeof(StartOfRound))] internal class StartOfRoundPatch { [HarmonyPatch("Start")] private static void Prefix() { MineDangerProximityAudio.LoadClip(); } } [HarmonyPatch(typeof(Landmine))] internal class LandminePatch { private const float checkRadius = 6f; private const int explodeChance = 50; private static float landmineTimer; private static bool CheckForPlayersNearby(Vector3 mineLocation) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) Collider[] array = Physics.OverlapSphere(mineLocation, 6f); foreach (Collider val in array) { if (((Component)val).CompareTag("Player")) { PlayerControllerB component = ((Component)val).gameObject.GetComponent<PlayerControllerB>(); if (!((Object)(object)component != (Object)(object)GameNetworkManager.Instance.localPlayerController) && (Object)(object)component != (Object)null && !component.isPlayerDead) { return true; } return false; } } return false; } private static bool doWeExplode(Random rnd) { return rnd.Next(0, 1000) <= 50; } [HarmonyPatch("Update")] [HarmonyPostfix] private static void patchUpdateSearchPlayer(Component __instance, ref bool ___hasExploded, ref bool ___mineActivated, ref RoundManager ___roundManager, ref AudioSource ___mineAudio) { //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result type (might be due to invalid IL or missing references) if (___hasExploded || !___mineActivated) { return; } landmineTimer += Time.deltaTime; if (!(landmineTimer > 1f)) { return; } if (CheckForPlayersNearby(((Transform)AccessTools.Property(typeof(Transform), "transform").GetValue(__instance)).position)) { if (doWeExplode(___roundManager.BreakerBoxRandom)) { AccessTools.Method(typeof(Landmine), "TriggerMineOnLocalClientByExiting", (Type[])null, (Type[])null).Invoke(__instance, null); } else if (MineDangerProximityAudio.ready) { ___mineAudio.PlayOneShot(MineDangerProximityAudio.Clip, 1f); } } landmineTimer = 0f; } } }