Decompiled source of UnstableLandmines v0.0.1

plugins/UnstableLandmines.dll

Decompiled 6 months ago
using System;
using System.Collections;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;
using UnstableLandmines.Patches;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("0Harmony")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: AssemblyCompany("UnstableLandmines")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+8be659dbfde85095de74fcb41b8da6c31d849cc3")]
[assembly: AssemblyProduct("UnstableLandmines")]
[assembly: AssemblyTitle("UnstableLandmines")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace UnstableLandmines
{
	[BepInPlugin("MasterAli2.UnstableLandmines", "Unstable Landmines", "1.0.0")]
	public class UnstableLandminesBase : BaseUnityPlugin
	{
		private const string modGUID = "MasterAli2.UnstableLandmines";

		private const string modName = "Unstable Landmines";

		private const string modVersion = "1.0.0";

		private readonly Harmony harmony = new Harmony("MasterAli2.UnstableLandmines");

		public static UnstableLandminesBase instance;

		public ConfigEntry<bool> configExperimental;

		public ConfigEntry<bool> configLandmineUnstabilityTick;

		public ConfigEntry<float> configLandmineTickDuration;

		public ConfigEntry<float> configRemoteExplosionChance;

		public ConfigEntry<float> configRemoteRange;

		internal ManualLogSource mls;

		private void Awake()
		{
			if ((Object)(object)instance == (Object)null)
			{
				instance = this;
			}
			SetupConfig();
			mls = Logger.CreateLogSource("MasterAli2.UnstableLandmines");
			mls.LogInfo((object)"UnstableLandmines has awaken");
			harmony.PatchAll(typeof(UnstableLandminesBase));
			harmony.PatchAll(typeof(UnstableLandminesPatch));
		}

		private void SetupConfig()
		{
			configLandmineTickDuration = ((BaseUnityPlugin)this).Config.Bind<float>("General", "LandmineTickDuration", 120f, "if the player is on the landmine for more than X seconds it will go boom if value is smaller than 0 it will be turned off");
			configRemoteExplosionChance = ((BaseUnityPlugin)this).Config.Bind<float>("General", "RemoteExplosionChance", 60f, "The chances of a landmine exploding after usage on a landmine (looking at it) the other x% will be the chance of disabling the landmine");
			configRemoteRange = ((BaseUnityPlugin)this).Config.Bind<float>("General", "RemoteRange", 10f, "The range the remote needs to be close to the landmine for it to take affect");
			configLandmineUnstabilityTick = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "configLandmineUnstabilityTick", false, "shuldd landmines randomly blew up randomly blew up? kinda experimental idk");
			configExperimental = ((BaseUnityPlugin)this).Config.Bind<bool>("Experimental", "Experimental", false, "Use Experimental features? [some things that make landmine go boom if use walkie near landmine (random)]");
		}
	}
}
namespace UnstableLandmines.Patches
{
	internal class UnstableLandminesPatch
	{
		[HarmonyPatch(typeof(Landmine), "Start")]
		[HarmonyPostfix]
		private static void LandmineStartPatch(Landmine __instance)
		{
			if (UnstableLandminesBase.instance.configLandmineUnstabilityTick.Value)
			{
				((MonoBehaviour)__instance).StartCoroutine(UnstabilityTimer(__instance));
			}
		}

		[HarmonyPatch(typeof(Landmine), "OnTriggerEnter")]
		[HarmonyPostfix]
		private static void LandmineOnTriggerEnterPatch(Collider other, Landmine __instance)
		{
			if (((Component)other).CompareTag("Player") && UnstableLandminesBase.instance.configLandmineTickDuration.Value > 0f && NetworkManager.Singleton.IsHost)
			{
				((MonoBehaviour)__instance).StartCoroutine(TickTimer(__instance));
			}
		}

		public static IEnumerator TickTimer(Landmine instance)
		{
			yield return (object)new WaitForSeconds(UnstableLandminesBase.instance.configLandmineTickDuration.Value);
			if (instance.mineActivated)
			{
				instance.TriggerMineOnLocalClientByExiting();
			}
		}

		public static IEnumerator UnstabilityTimer(Landmine instance)
		{
			yield return (object)new WaitForSeconds(Random.Range(TimeOfDay.Instance.lengthOfHours, TimeOfDay.Instance.totalTime));
			if (instance.mineActivated)
			{
				instance.TriggerMineOnLocalClientByExiting();
			}
		}

		[HarmonyPatch(typeof(RemoteProp), "ItemActivate")]
		[HarmonyPostfix]
		private static void RemoteItemActivatePatch()
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			Vector3 position = ((Component)GameNetworkManager.Instance.localPlayerController.visorCamera).transform.position;
			Vector3 forward = ((Component)GameNetworkManager.Instance.localPlayerController.visorCamera).transform.forward;
			RaycastHit val = default(RaycastHit);
			if (!Physics.Raycast(new Ray(position, forward), ref val, UnstableLandminesBase.instance.configRemoteRange.Value, 2097152) || ((Component)((RaycastHit)(ref val)).collider).gameObject.layer != 21)
			{
				return;
			}
			Landmine componentInChildren = ((Component)((RaycastHit)(ref val)).collider).gameObject.GetComponentInChildren<Landmine>();
			if ((Object)(object)componentInChildren != (Object)null)
			{
				if (Random.Range(0f, 1f) > UnstableLandminesBase.instance.configRemoteExplosionChance.Value)
				{
					componentInChildren.TriggerMineOnLocalClientByExiting();
					return;
				}
				componentInChildren.mineAnimator.SetTrigger("startIdle");
				componentInChildren.mineAnimator.speed = 0f;
				componentInChildren.mineActivated = false;
			}
		}

		[HarmonyPatch(typeof(WalkieTalkie), "ItemActivate")]
		[HarmonyPostfix]
		private static void WalkieTalkieItemActivatePatch(WalkieTalkie __instance)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			if (!UnstableLandminesBase.instance.configExperimental.Value)
			{
				return;
			}
			Collider[] array = Physics.OverlapSphere(((Component)__instance).transform.position, 10f, 2097152);
			for (int i = 0; i < array.Length; i++)
			{
				Landmine componentInChildren = ((Component)array[i]).gameObject.GetComponentInChildren<Landmine>();
				if ((Object)(object)componentInChildren != (Object)null)
				{
					float num = 1f / Mathf.Clamp(Vector3.Distance(((Component)__instance).transform.position, ((Component)array[i]).gameObject.transform.position), 1f, 10f) / 100f;
					if (Random.Range(0f, 1f) < num)
					{
						componentInChildren.TriggerMineOnLocalClientByExiting();
					}
				}
			}
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}