Decompiled source of JetpackSafety v1.2.0

BepInEx/plugins/JetpackSafety.dll

Decompiled an hour ago
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using JetpackSafety.Patches;
using Unity.Netcode;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("JetpackSafety")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("JetpackSafety")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("09921379-6b32-4bc0-ad08-d65d6be0946e")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace JetpackSafety
{
	internal static class ModInfo
	{
		internal const string modGUID = "PixelIndieDev_JetpackSafety";

		internal const string modName = "Jetpack Safety";

		internal const string modVersion = "1.2.0.0";
	}
	[BepInPlugin("PixelIndieDev_JetpackSafety", "Jetpack Safety", "1.2.0.0")]
	public class JetpackPlayerDamagePatchBase : BaseUnityPlugin
	{
		private readonly Harmony harmony = new Harmony("PixelIndieDev_JetpackSafety");

		private static JetpackPlayerDamagePatchBase instance;

		internal ManualLogSource logSource;

		private void Awake()
		{
			if ((Object)(object)instance == (Object)null)
			{
				instance = this;
			}
			logSource = Logger.CreateLogSource("PixelIndieDev_JetpackSafety");
			harmony.PatchAll(typeof(JetpackPlayerDamagePatchBase));
			harmony.PatchAll(typeof(JetpackPatch));
			harmony.PatchAll(typeof(PlayerControllerPatch));
			harmony.PatchAll(typeof(NetworkPatch));
			logSource.LogInfo((object)"Jetpack Safety (version - 1.2.0.0): patches applied successfully");
		}
	}
}
namespace JetpackSafety.Patches
{
	[HarmonyPatch(typeof(JetpackItem))]
	internal static class JetpackPatch
	{
		[HarmonyPatch("ExplodeJetpackServerRpc")]
		[HarmonyPrefix]
		[HarmonyPriority(0)]
		private static bool PreventExplosionsOnServer()
		{
			return false;
		}

		[HarmonyPatch("ExplodeJetpackClientRpc")]
		[HarmonyPrefix]
		[HarmonyPriority(0)]
		private static bool PreventExplosionsOnClient()
		{
			return false;
		}

		[HarmonyPatch("SetJetpackAudios")]
		[HarmonyPostfix]
		[HarmonyPriority(800)]
		private static void PreventBeeps(JetpackItem __instance, ref bool ___jetpackPlayingWarningBeep, AudioSource ___jetpackBeepsAudio)
		{
			if (___jetpackPlayingWarningBeep)
			{
				___jetpackPlayingWarningBeep = false;
				___jetpackBeepsAudio.Stop();
			}
		}
	}
	[HarmonyPatch(typeof(NetworkManager))]
	internal static class NetworkPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch("SetSingleton")]
		private static void RegisterPrefab()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("PixelIndieDev_JetpackSafety Prefab");
			((Object)val).hideFlags = (HideFlags)(((Object)val).hideFlags | 0x3D);
			Object.DontDestroyOnLoad((Object)(object)val);
			NetworkObject obj = val.AddComponent<NetworkObject>();
			typeof(NetworkObject).GetField("GlobalObjectIdHash", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(obj, GetHash("PixelIndieDev_JetpackSafety"));
			NetworkManager.Singleton.PrefabHandler.AddNetworkPrefab(val);
		}

		private static uint GetHash(string value)
		{
			return value?.Aggregate(17u, (uint current, char c) => (current * 31) ^ c) ?? 0;
		}
	}
	[HarmonyPatch(typeof(PlayerControllerB))]
	internal static class PlayerControllerPatch
	{
		private static bool isFlying = false;

		private static float gracePeriodDuration = 2.5f;

		private static float graceTimer = 0f;

		[HarmonyPatch("KillPlayer")]
		[HarmonyPrefix]
		[HarmonyPriority(0)]
		private static bool PreventDeath(PlayerControllerB __instance, CauseOfDeath causeOfDeath)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Invalid comparison between Unknown and I4
			if ((int)causeOfDeath == 2 && IsUsingJetpack(__instance))
			{
				return false;
			}
			return true;
		}

		[HarmonyPatch("DamagePlayer")]
		[HarmonyPrefix]
		[HarmonyPriority(0)]
		private static bool PreventDamage(PlayerControllerB __instance, CauseOfDeath causeOfDeath)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Invalid comparison between Unknown and I4
			if ((int)causeOfDeath == 2 && IsUsingJetpack(__instance))
			{
				return false;
			}
			return true;
		}

		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		[HarmonyPriority(0)]
		private static void CheckIfFlying(PlayerControllerB __instance)
		{
			if (IsJetpackActive(__instance))
			{
				graceTimer = 0f;
				isFlying = true;
			}
			else if (isFlying)
			{
				isFlying = false;
				graceTimer = gracePeriodDuration;
			}
			if (graceTimer > 0f)
			{
				graceTimer -= Time.deltaTime;
				if (graceTimer < 0f)
				{
					graceTimer = 0f;
				}
			}
		}

		private static bool IsJetpackActive(PlayerControllerB player)
		{
			if (player.jetpackControls)
			{
				return !player.disablingJetpackControls;
			}
			return false;
		}

		private static bool IsUsingJetpack(PlayerControllerB player)
		{
			if (!isFlying)
			{
				return graceTimer > 0f;
			}
			return true;
		}
	}
}