Decompiled source of CasperProtections v1.0.0

plugins/CasperProtections/CasperProtections.dll

Decompiled a week ago
using System;
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 CasperProtections.Patches;
using HarmonyLib;
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("CasperProtections")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("CasperProtections")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("77b95131-6918-4f34-8603-45953e40205b")]
[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 CasperProtections
{
	[BepInPlugin("com.casper.CasperProtections", "CasperProtections", "1.0.0")]
	public class CasperProtections : BaseUnityPlugin
	{
		private const string MyGUID = "com.casper.CasperProtections";

		private const string PluginName = "CasperProtections";

		private const string VersionString = "1.0.0";

		private static readonly Harmony Harmony = new Harmony("com.casper.CasperProtections");

		public static ManualLogSource Log = new ManualLogSource("CasperProtections");

		private void Awake()
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)"PluginName: CasperProtections, VersionString: 1.0.0 is loading...");
			Harmony.PatchAll();
			ApplyPatches();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"PluginName: CasperProtections, VersionString: 1.0.0 is loaded.");
			Log = ((BaseUnityPlugin)this).Logger;
		}

		private void ApplyPatches()
		{
			Harmony.CreateAndPatchAll(typeof(ProtPatches), (string)null);
		}
	}
}
namespace CasperProtections.Patches
{
	internal class ProtPatches
	{
		[HarmonyPatch(typeof(SafeSpeedTriggerZoneData), "SetSprintState")]
		public class SkipSetSprintStatePatch
		{
			private static bool Prefix(ref bool isOn)
			{
				isOn = false;
				return true;
			}
		}

		[HarmonyPatch(typeof(GridManager), "RegisterProtectedZone")]
		public class SkipRegisterProtectedZonePatch
		{
			private static bool Prefix(ref ProtectionZoneData protectionZone, ref byte strata)
			{
				return false;
			}
		}

		[HarmonyPatch(typeof(VoxelManager), "CanModifyVoxelAt")]
		public class PatchCanModifyVoxelAt
		{
			private static bool Prefix(ref bool __result)
			{
				__result = true;
				return false;
			}
		}

		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		public class PatchCanErase
		{
			private static readonly MachineTypeEnum[] ExcludedTypes;

			private static bool Prefix(CommonMachineInfo __instance, ref bool __result)
			{
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				//IL_0007: Unknown result type (might be due to invalid IL or missing references)
				if (ExcludedTypes.Contains(__instance.typeIndex))
				{
					return true;
				}
				__result = true;
				return false;
			}

			static PatchCanErase()
			{
				MachineTypeEnum[] array = new MachineTypeEnum[4];
				RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/);
				ExcludedTypes = (MachineTypeEnum[])(object)array;
			}
		}

		[HarmonyPatch(typeof(PlayerFirstPersonController), "LateUpdate")]
		public class Patch_PlayerFirstPersonController_LateUpdate
		{
			private static readonly FieldInfo runToggledOnField = typeof(PlayerFirstPersonController).GetField("runToggledOn", BindingFlags.Instance | BindingFlags.NonPublic);

			private static bool Prefix(PlayerFirstPersonController __instance)
			{
				//IL_0042: Unknown result type (might be due to invalid IL or missing references)
				//IL_0047: Unknown result type (might be due to invalid IL or missing references)
				if (runToggledOnField == null)
				{
					Debug.LogError((object)"Failed to access 'runToggledOn' field via reflection.");
					return true;
				}
				bool sprintHeld = InputHandler.instance.SprintHeld;
				runToggledOnField.SetValue(__instance, sprintHeld);
				Vector2 moveAxes = InputHandler.instance.MoveAxes;
				if (((Vector2)(ref moveAxes)).magnitude < 0.5f)
				{
					runToggledOnField.SetValue(__instance, false);
				}
				return true;
			}
		}
	}
}