Decompiled source of SuperLandmine v1.1.3

plugins/SuperLandmine.dll

Decompiled 11 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 GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("SuperLandmine")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("SuperLandmine mod for Lethal Company")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1+05588e298c4ebb35ba7eda9a96c96de6cd6233e1")]
[assembly: AssemblyProduct("SuperLandmine")]
[assembly: AssemblyTitle("SuperLandmine")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.1.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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace SuperLandmine
{
	[BepInPlugin("Superlandmine", "SuperLandmine", "1.1.3")]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource log;

		public Harmony harmony = new Harmony("Superlandmine");

		public static ConfigEntry<int> config_LandmineMinAmount;

		public static ConfigEntry<int> config_LandmineMaxAmount;

		public static ConfigEntry<bool> config_EnableLandmineSound;

		public static ConfigEntry<bool> config_EnemyCanTriggerLandmine;

		public static ConfigEntry<bool> config_LandmineCanSpawnOutside;

		public static ConfigEntry<bool> config_UseDefaultLandmineSpawnRate;

		private void Awake()
		{
			log = ((BaseUnityPlugin)this).Logger;
			log.LogInfo((object)"Loading plugin SuperLandmine ...");
			ConfigSetup();
			harmony.PatchAll();
			log.LogInfo((object)"Plugin SuperLandmine loaded!");
		}

		private void ConfigSetup()
		{
			config_LandmineMinAmount = ((BaseUnityPlugin)this).Config.Bind<int>("Landmine min amount", "Value", 10, "Min landmine to be spawned in the map");
			config_LandmineMaxAmount = ((BaseUnityPlugin)this).Config.Bind<int>("Landmine max amount", "Value", 15, "Max landmine to be spawned in the map");
			config_EnableLandmineSound = ((BaseUnityPlugin)this).Config.Bind<bool>("Disable landmine sound", "Value", true, "Enable or disable landmine sound");
			config_EnemyCanTriggerLandmine = ((BaseUnityPlugin)this).Config.Bind<bool>("Enemy trigger landmine", "Value", true, "Enable or disable enemy can trigger landmine");
			config_LandmineCanSpawnOutside = ((BaseUnityPlugin)this).Config.Bind<bool>("Landmine can spawn outside", "Value", true, "Enable or disable landmine can spawn outside");
			config_UseDefaultLandmineSpawnRate = ((BaseUnityPlugin)this).Config.Bind<bool>("Use default landmine spawn rate", "Value", false, "Enable or disable default landmine spawn rate");
		}
	}
	internal class PluginInfo
	{
		public const string PLUGIN_GUID = "Superlandmine";

		public const string PLUGIN_NAME = "SuperLandmine";

		public const string PLUGIN_VERSION = "1.1.3";
	}
	public static class Utils
	{
		public class OutsideLandmineMarker : MonoBehaviour
		{
		}

		public const float MAX_RAYCAST_DIST = 30000f;

		public static (Vector3, Quaternion) projectToGround(Vector3 position)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: 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)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			Ray val = default(Ray);
			((Ray)(ref val))..ctor(position, Vector3.down);
			Quaternion item = Quaternion.identity;
			Vector3 item2 = position;
			RaycastHit val2 = default(RaycastHit);
			if (Physics.Raycast(val, ref val2, 30000f))
			{
				item2 = ((RaycastHit)(ref val2)).point;
				item = Quaternion.FromToRotation(Vector3.up, ((RaycastHit)(ref val2)).normal);
			}
			return (item2, item);
		}
	}
}
namespace SuperLandmine.Patchs
{
	[HarmonyPatch(typeof(Landmine))]
	public class SuperLandminePatch
	{
		[HarmonyPatch("PressMineClientRpc")]
		[HarmonyPostfix]
		public static void playTriggerSound(Landmine __instance)
		{
			Plugin.log.LogInfo((object)"Play trigger sound");
			__instance.mineAudio.volume = 1.3f;
			__instance.mineFarAudio.volume = 1.3f;
			Traverse.Create((object)__instance).Field("pressMineDebounceTimer").SetValue((object)0.5f);
			__instance.mineAudio.PlayOneShot(__instance.minePress, 1.3f);
			WalkieTalkie.TransmitOneShotAudio(__instance.mineAudio, __instance.minePress, 1f);
		}

		[HarmonyPatch("Detonate")]
		[HarmonyPrefix]
		public static void IncreaseAudioVolume(Landmine __instance)
		{
			Plugin.log.LogInfo((object)"Increase landmine volume and kill range");
			((MonoBehaviour)__instance).StartCoroutine(DelayedActions(__instance));
		}

		private static IEnumerator DelayedActions(Landmine __instance)
		{
			yield return (object)new WaitForSeconds(0.5f);
			__instance.mineAudio.volume = 1.2f;
			__instance.mineFarAudio.volume = 1.3f;
			__instance.mineAudio.pitch = Random.Range(0.93f, 1.07f);
			__instance.mineAudio.PlayOneShot(__instance.mineDetonate, 1.2f);
			Landmine.SpawnExplosion(((Component)__instance).transform.position + Vector3.up, true, 10f, 12f);
			yield return (object)new WaitForSeconds(0.5f);
		}

		[HarmonyPatch("Detonate")]
		[HarmonyPostfix]
		public static void disableSoundAfterExplode(Landmine __instance)
		{
			if (Plugin.config_EnableLandmineSound.Value)
			{
				__instance.mineAudio.volume = 0f;
				__instance.mineFarAudio.volume = 0f;
			}
		}

		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		public static void enabledLandMineSound(Landmine __instance)
		{
			if (Plugin.config_EnableLandmineSound.Value)
			{
				__instance.mineAudio.volume = 0f;
				__instance.mineFarAudio.volume = 0f;
			}
		}

		[HarmonyPatch("OnTriggerEnter")]
		[HarmonyPrefix]
		public static void anyObjectTriggerLandmineEnter(ref Collider other, Landmine __instance)
		{
			if (!Plugin.config_EnemyCanTriggerLandmine.Value)
			{
				return;
			}
			float value = Traverse.Create((object)__instance).Field("pressMineDebounceTimer").GetValue<float>();
			if (__instance.hasExploded || value > 0f)
			{
				return;
			}
			if (((Component)other).CompareTag("Player"))
			{
				PlayerControllerB component = ((Component)other).gameObject.GetComponent<PlayerControllerB>();
				if (!((Object)(object)component != (Object)(object)GameNetworkManager.Instance.localPlayerController) && (Object)(object)component != (Object)null && !component.isPlayerDead)
				{
					Traverse.Create((object)__instance).Field("localPlayerOnMine").SetValue((object)true);
					Traverse.Create((object)__instance).Field("pressMineDebounceTimer").SetValue((object)0.5f);
					__instance.PressMineServerRpc();
				}
			}
			else
			{
				if (!((Component)other).CompareTag("PlayerRagdoll") && !((Component)other).CompareTag("PhysicsProp") && !((Component)other).CompareTag("Enemy"))
				{
					return;
				}
				if (Object.op_Implicit((Object)(object)((Component)other).GetComponent<DeadBodyInfo>()))
				{
					if ((Object)(object)((Component)other).GetComponent<DeadBodyInfo>().playerScript != (Object)(object)GameNetworkManager.Instance.localPlayerController)
					{
						return;
					}
				}
				else if (Object.op_Implicit((Object)(object)((Component)other).GetComponent<GrabbableObject>()) && !((NetworkBehaviour)((Component)other).GetComponent<GrabbableObject>()).NetworkObject.IsOwner)
				{
					return;
				}
				Traverse.Create((object)__instance).Field("pressMineDebounceTimer").SetValue((object)0.5f);
				__instance.PressMineServerRpc();
			}
		}

		[HarmonyPatch("OnTriggerExit")]
		[HarmonyPrefix]
		public static void anyObjectTriggerLandmineExit(ref Collider other, Landmine __instance)
		{
			if (!Plugin.config_EnemyCanTriggerLandmine.Value)
			{
				return;
			}
			bool value = Traverse.Create((object)__instance).Field("mineActivated").GetValue<bool>();
			if (__instance.hasExploded || !value)
			{
				return;
			}
			if (((Component)other).CompareTag("Player"))
			{
				PlayerControllerB component = ((Component)other).gameObject.GetComponent<PlayerControllerB>();
				if ((Object)(object)component != (Object)null && !component.isPlayerDead && !((Object)(object)component != (Object)(object)GameNetworkManager.Instance.localPlayerController))
				{
					Traverse.Create((object)__instance).Field("localPlayerOnMine").SetValue((object)false);
					Traverse.Create((object)__instance).Method("TriggerMineOnLocalClientByExiting", Array.Empty<object>()).GetValue();
				}
			}
			else
			{
				if (!((Component)other).CompareTag("PlayerRagdoll") && !((Component)other).CompareTag("PhysicsProp") && !((Component)other).CompareTag("Enemy"))
				{
					return;
				}
				if (Object.op_Implicit((Object)(object)((Component)other).GetComponent<DeadBodyInfo>()))
				{
					if ((Object)(object)((Component)other).GetComponent<DeadBodyInfo>().playerScript != (Object)(object)GameNetworkManager.Instance.localPlayerController)
					{
						return;
					}
				}
				else if (Object.op_Implicit((Object)(object)((Component)other).GetComponent<GrabbableObject>()) && !((NetworkBehaviour)((Component)other).GetComponent<GrabbableObject>()).NetworkObject.IsOwner)
				{
					return;
				}
				Traverse.Create((object)__instance).Method("TriggerMineOnLocalClientByExiting", Array.Empty<object>()).GetValue();
			}
		}
	}
	[HarmonyPatch(typeof(RoundManager))]
	public class RoundManagerPatch
	{
		[HarmonyPatch("LoadNewLevel")]
		[HarmonyPrefix]
		public static void spawnLanmineInside(ref SelectableLevel newLevel)
		{
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Expected O, but got Unknown
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Expected O, but got Unknown
			if (Plugin.config_UseDefaultLandmineSpawnRate.Value)
			{
				return;
			}
			Plugin.log.LogInfo((object)"Load landmine");
			SelectableLevel val = newLevel;
			SpawnableMapObject[] spawnableMapObjects = val.spawnableMapObjects;
			if (val.spawnableMapObjects.Length == 0)
			{
				return;
			}
			Plugin.log.LogInfo((object)"Spawn landmine inside");
			SpawnableMapObject[] array = spawnableMapObjects;
			foreach (SpawnableMapObject val2 in array)
			{
				if ((Object)val2.prefabToSpawn.GetComponentInChildren<Landmine>() != (Object)null)
				{
					val2.numberToSpawn = new AnimationCurve((Keyframe[])(object)new Keyframe[2]
					{
						new Keyframe(0f, (float)Plugin.config_LandmineMinAmount.Value),
						new Keyframe(1f, (float)Plugin.config_LandmineMaxAmount.Value)
					});
				}
			}
		}

		[HarmonyPatch("SpawnOutsideHazards")]
		[HarmonyPrefix]
		public static void spawnLandmineOutside(RoundManager __instance)
		{
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Expected O, but got Unknown
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Expected O, but got Unknown
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_019b: Unknown result type (might be due to invalid IL or missing references)
			//IL_019d: Unknown result type (might be due to invalid IL or missing references)
			if (!Plugin.config_LandmineCanSpawnOutside.Value || !((NetworkBehaviour)__instance).IsServer || !((NetworkBehaviour)__instance).IsHost)
			{
				return;
			}
			Utils.OutsideLandmineMarker[] array = Object.FindObjectsOfType<Utils.OutsideLandmineMarker>();
			Utils.OutsideLandmineMarker[] array2 = array;
			foreach (Utils.OutsideLandmineMarker outsideLandmineMarker in array2)
			{
				Object.Destroy((Object)(object)((Component)outsideLandmineMarker).gameObject);
			}
			Plugin.log.LogInfo((object)"Load landmine");
			SelectableLevel currentLevel = __instance.currentLevel;
			SpawnableMapObject[] spawnableMapObjects = currentLevel.spawnableMapObjects;
			if (currentLevel.spawnableMapObjects.Length == 0)
			{
				return;
			}
			Plugin.log.LogInfo((object)"Spawn landmine outside");
			SpawnableMapObject[] array3 = spawnableMapObjects;
			foreach (SpawnableMapObject val in array3)
			{
				if (!((Object)val.prefabToSpawn.GetComponentInChildren<Landmine>() != (Object)null))
				{
					continue;
				}
				AnimationCurve val2 = new AnimationCurve((Keyframe[])(object)new Keyframe[2]
				{
					new Keyframe(0f, (float)Plugin.config_LandmineMinAmount.Value),
					new Keyframe(1f, (float)Plugin.config_LandmineMaxAmount.Value)
				});
				Transform[] shipSpawnPathPoints = __instance.shipSpawnPathPoints;
				for (int k = 0; k < shipSpawnPathPoints.Length; k++)
				{
					for (int l = 0; (float)l < val2.Evaluate(Random.Range(0f, 1f)); l++)
					{
						Random random = new Random();
						Vector3 val3 = __instance.GetRandomNavMeshPositionInBoxPredictable(shipSpawnPathPoints[k].position, 300f, __instance.navHit, random, -5);
						Quaternion val4;
						(val3, val4) = Utils.projectToGround(val3);
						Plugin.log.LogInfo((object)("Spawn landmine outside at" + ((object)(Vector3)(ref val3)).ToString()));
						GameObject val5 = Object.Instantiate<GameObject>(val.prefabToSpawn, val3, val4);
						val5.SetActive(true);
						val5.GetComponent<NetworkObject>().Spawn(false);
						val5.AddComponent<Utils.OutsideLandmineMarker>();
					}
				}
			}
		}
	}
}