Decompiled source of Unstable Jetpacks v1.1.0

UnstableJetpacks.dll

Decompiled 3 months ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Threading;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;
using UnstableJetpacks.Patches;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("UnstableJetpacks")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("UnstableJetpacks")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("366344e9-8d68-4e7b-bce8-e89e7d4e6471")]
[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 UnstableJetpacks
{
	[BepInPlugin("minecart.UnstableJetpacks", "Unstable Jetpacks", "1.1.0")]
	public class UnstableJetpacksModBase : BaseUnityPlugin
	{
		private const string modGUID = "minecart.UnstableJetpacks";

		private const string modName = "Unstable Jetpacks";

		private const string modVersion = "1.1.0";

		private readonly Harmony harmony = new Harmony("minecart.UnstableJetpacks");

		private static UnstableJetpacksModBase Instance;

		internal ManualLogSource mls;

		private static ConfigEntry<bool> randomExploding;

		private static ConfigEntry<bool> randomSpeedIncrease;

		private static ConfigEntry<int> minimumSpeedIncrease;

		private static ConfigEntry<int> maximumSpeedIncrease;

		private static ConfigEntry<int> chanceToExplodeInt;

		private static ConfigEntry<int> chancetoIncreaseSpeedInt;

		public static bool GetRandomExploding => randomExploding.Value;

		public static bool GetRandomSpeedIncrease => randomSpeedIncrease.Value;

		public static int GetMinSpeedIncrease => minimumSpeedIncrease.Value;

		public static int GetMaxSpeedIncrease => maximumSpeedIncrease.Value;

		public static int GetCustomChanceToExplode => chanceToExplodeInt.Value;

		public static int GetCustomChanceToIncreaseSpeed => chancetoIncreaseSpeedInt.Value;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			randomExploding = ((BaseUnityPlugin)this).Config.Bind<bool>("Settings", "Random Chance to Explode", true, "Determines if theres a random chance you can explode by launching your jetpack.");
			randomSpeedIncrease = ((BaseUnityPlugin)this).Config.Bind<bool>("Settings", "Random Chance to Increase Speed", true, "Determines if there can be a random chance to increase your jetpack's speed every frame.");
			minimumSpeedIncrease = ((BaseUnityPlugin)this).Config.Bind<int>("Settings", "Minimum Random Speed Increase", 0, "The minimum value for a random speed increase. (Only applies if 'Random Chance to Increase Speed' is set to true.)");
			maximumSpeedIncrease = ((BaseUnityPlugin)this).Config.Bind<int>("Settings", "Maximum Random Speed Increase", 30, "The maximum value for a random speed increase. (Only applies if 'Random Chance to Increase Speed' is set to true.)");
			chanceToExplodeInt = ((BaseUnityPlugin)this).Config.Bind<int>("Settings", "Number Chance to Explode (1/num)", 20, "The number set here is what the chance will be to explode on jetpack launch. This is put in as 1/(Your Number Here).");
			chancetoIncreaseSpeedInt = ((BaseUnityPlugin)this).Config.Bind<int>("Settings", "Number Chance to Increase Speed (1/num)", 250, "The number set here is what the chance will be to increase your jetpack speed every frame. This is put in as 1/(Your Number Here).");
			mls = Logger.CreateLogSource("minecart.UnstableJetpacks");
			mls.LogInfo((object)"have fun exploding");
			harmony.PatchAll(typeof(UnstableJetpacksModBase));
			harmony.PatchAll(typeof(JetpackItemPatch));
		}
	}
}
namespace UnstableJetpacks.Patches
{
	[HarmonyPatch(typeof(JetpackItem))]
	internal class JetpackItemPatch
	{
		private static Random random = new Random();

		[HarmonyPatch("ActivateJetpack")]
		[HarmonyPostfix]
		private static void JetpackExplodePatch(ref float ___jetpackPower, ref AudioSource ___jetpackBeepsAudio, ref AudioClip ___jetpackWarningBeepSFX)
		{
			if (UnstableJetpacksModBase.GetRandomExploding && random.Next(0, UnstableJetpacksModBase.GetCustomChanceToExplode) == 0)
			{
				___jetpackPower = 1500f;
				___jetpackBeepsAudio.clip = ___jetpackWarningBeepSFX;
				___jetpackBeepsAudio.Play();
			}
		}

		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		private static void JetpackSpeedChancePatch(ref float ___jetpackPower, ref AudioSource ___jetpackBeepsAudio, ref AudioClip ___jetpackLowBatteriesSFX)
		{
			if (UnstableJetpacksModBase.GetRandomSpeedIncrease && random.Next(0, UnstableJetpacksModBase.GetCustomChanceToIncreaseSpeed) == 0)
			{
				int num = random.Next(UnstableJetpacksModBase.GetMinSpeedIncrease, UnstableJetpacksModBase.GetMaxSpeedIncrease);
				___jetpackPower += num;
				___jetpackBeepsAudio.clip = ___jetpackLowBatteriesSFX;
				___jetpackBeepsAudio.Play();
				Thread.Sleep(2);
				___jetpackBeepsAudio.Stop();
			}
		}
	}
}