Decompiled source of CruiserSafety v1.0.0

BepInEx/plugins/CruiserSafety.dll

Decompiled 3 hours 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 CruiserSafety.Patches;
using GameNetcodeStuff;
using HarmonyLib;
using Unity.Netcode;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("CruiserSafety")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("CruiserSafety")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("a7ad4e0c-a8e3-41c1-94d7-01ce05e7092c")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace CruiserSafety
{
	internal static class ModInfo
	{
		internal const string modGUID = "PixelIndieDev_CruiserSafety";

		internal const string modName = "Cruiser Safety";

		internal const string modVersion = "1.0.0.0";
	}
	[BepInPlugin("PixelIndieDev_CruiserSafety", "Cruiser Safety", "1.0.0.0")]
	public class CruiserDamagePatchBase : BaseUnityPlugin
	{
		private readonly Harmony harmony = new Harmony("PixelIndieDev_CruiserSafety");

		private static CruiserDamagePatchBase instance;

		internal ManualLogSource logSource;

		private void Awake()
		{
			if ((Object)(object)instance == (Object)null)
			{
				instance = this;
			}
			logSource = Logger.CreateLogSource("PixelIndieDev_CruiserSafety");
			harmony.PatchAll(typeof(CruiserDamagePatchBase));
			harmony.PatchAll(typeof(CruiserDamagePatch));
			harmony.PatchAll(typeof(NetworkPatch));
			logSource.LogInfo((object)"Cruiser Safety (version - 1.0.0.0): patches applied successfully");
		}
	}
}
namespace CruiserSafety.Patches
{
	[HarmonyPatch(typeof(VehicleController))]
	internal class CruiserDamagePatch
	{
		[HarmonyPatch("DamagePlayerInVehicle")]
		[HarmonyPrefix]
		private static bool PatchVehicle(VehicleController __instance, Vector3 vel, float magnitude)
		{
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			if (__instance.localPlayerInPassengerSeat || __instance.localPlayerInControl)
			{
				if (magnitude > 24f)
				{
					HUDManager.Instance.ShakeCamera((ScreenShakeType)3);
				}
				else
				{
					HUDManager.Instance.ShakeCamera((ScreenShakeType)1);
				}
			}
			else if ((Object)(object)__instance.physicsRegion.physicsTransform == (Object)(object)GameNetworkManager.Instance.localPlayerController.physicsParent && (Object)(object)GameNetworkManager.Instance.localPlayerController.overridePhysicsParent == (Object)null)
			{
				HUDManager.Instance.ShakeCamera((ScreenShakeType)0);
				PlayerControllerB localPlayerController = GameNetworkManager.Instance.localPlayerController;
				localPlayerController.externalForceAutoFade += vel;
			}
			return false;
		}
	}
	[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_CruiserSafety 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_CruiserSafety"));
			NetworkManager.Singleton.PrefabHandler.AddNetworkPrefab(val);
		}

		private static uint GetHash(string value)
		{
			return value?.Aggregate(17u, (uint current, char c) => (current * 31) ^ c) ?? 0;
		}
	}
}