using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using OnionMilk_crawlingmine;
using Unity.Netcode;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("OnionMilk_crawlingmine")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Crawling mine plugin for BepInEx (Lethal Company)")]
[assembly: AssemblyFileVersion("1.0.5.0")]
[assembly: AssemblyInformationalVersion("1.0.5")]
[assembly: AssemblyProduct("OnionMilk_crawlingmine")]
[assembly: AssemblyTitle("OnionMilk_crawlingmine")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.5.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 HealthMetrics.Patches
{
[HarmonyPatch(typeof(EnemyAI))]
internal class EnemyAIPatches
{
[HarmonyPatch("ChooseClosestNodeToPosition")]
[HarmonyPrefix]
private static void ChooseClosestNodeToPosition(ref EnemyAI __instance, Vector3 pos, bool avoidLineOfSight = false, int offset = 0)
{
if (__instance.allAINodes.Any((GameObject n) => (Object)(object)n == (Object)null || ((object)n).Equals((object?)null)))
{
__instance.allAINodes = __instance.allAINodes.Where((GameObject n) => (Object)(object)n != (Object)null && !((object)n).Equals((object?)null)).ToArray();
}
}
}
[HarmonyPatch(typeof(StartOfRound))]
internal class StartOfRoundPatches
{
[HarmonyPatch("ResetPooledObjects")]
[HarmonyPostfix]
private static void ResetPooledObjects(ref StartOfRound __instance, bool destroy = false)
{
LandminePatches.jumpTimer = new Dictionary<Landmine, float>();
}
}
[HarmonyPatch(typeof(Landmine))]
internal class LandminePatches
{
public static Dictionary<Landmine, float> jumpTimer;
private static Random rnd;
private static Coroutine crawlCoutine;
[HarmonyPatch("Start")]
[HarmonyPostfix]
private static void Start(ref Landmine __instance)
{
if (jumpTimer == null)
{
jumpTimer = new Dictionary<Landmine, float>();
}
if (rnd == null)
{
rnd = new Random(StartOfRound.Instance.randomMapSeed + 2137);
}
if (rnd.NextDouble() < (double)Plugin.cfgJumpMineSpawnChance.Value)
{
ScanNodeProperties componentInChildren = ((Component)((Component)__instance).transform.parent).GetComponentInChildren<ScanNodeProperties>();
componentInChildren.headerText = "Crawling Mine";
componentInChildren.subText = "It crawls around!";
if (((NetworkBehaviour)__instance).IsServer)
{
jumpTimer.Add(__instance, Time.time + GetInterval());
Plugin.Log("Planted!");
}
if (!Plugin.cfgCrawlingMineSound.Value)
{
DisableAudio(__instance);
}
}
if (!Plugin.cfgMineSound.Value)
{
DisableAudio(__instance);
}
}
private static void DisableAudio(Landmine __instance)
{
((Behaviour)__instance.mineAudio).enabled = false;
__instance.mineAudio.volume = 0f;
((Behaviour)__instance.mineFarAudio).enabled = false;
__instance.mineFarAudio.volume = 0f;
}
private static float GetInterval()
{
return Mathf.Max(0.5f, Random.Range(Plugin.cfgJumpIntervalMin.Value, Plugin.cfgJumpIntervalMax.Value));
}
private static float GetRange()
{
return Mathf.Max(0.5f, Random.Range(Plugin.cfgJumpRangeMin.Value, Plugin.cfgJumpRangeMax.Value));
}
[HarmonyPatch("Update")]
[HarmonyPrefix]
private static void SetOffMineAnimation(ref Landmine __instance)
{
if (crawlCoutine != null)
{
((MonoBehaviour)__instance).StopCoroutine(crawlCoutine);
}
}
[HarmonyPatch("Update")]
[HarmonyPostfix]
private static void Update(ref Landmine __instance)
{
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
//IL_0068: Unknown result type (might be due to invalid IL or missing references)
//IL_006f: Unknown result type (might be due to invalid IL or missing references)
//IL_0074: Unknown result type (might be due to invalid IL or missing references)
//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
if (((NetworkBehaviour)__instance).IsServer && jumpTimer.TryGetValue(__instance, out var value) && value < Time.time)
{
List<Vector3> list = new List<Vector3>();
float num = MathF.PI / 4f;
float range = GetRange();
for (int i = 0; i < 8; i++)
{
float num2 = num * (float)i;
IEnumerable<Vector3> collection = Raycast(((Component)__instance).transform.position + new Vector3(Mathf.Cos(num2), 0f, Mathf.Sin(num2)) * range);
list.AddRange(collection);
}
if (list.Count > 0)
{
Vector3 target = list[Random.Range(0, list.Count)];
crawlCoutine = ((MonoBehaviour)__instance).StartCoroutine(CrawlRoutine(__instance, target));
jumpTimer[__instance] = Time.time + GetInterval();
}
else
{
jumpTimer.Remove(__instance);
}
}
}
private static IEnumerator CrawlRoutine(Landmine mine, Vector3 target)
{
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
if (mine.hasExploded)
{
yield break;
}
float time = 0.5f;
Transform mineTransform = ((Component)mine).transform;
Vector3 orgPos = mineTransform.position;
while (time > 0f)
{
if (mine.hasExploded)
{
yield break;
}
float num = 1f - time / 0.5f;
Vector3 position = Vector3.Lerp(orgPos, target, num);
mineTransform.position = position;
time -= Time.deltaTime;
yield return null;
}
mineTransform.position = target;
}
private static IEnumerable<Vector3> Raycast(Vector3 pos)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
RaycastHit[] array = Physics.RaycastAll(pos + Vector3.up, Vector3.down, 2.5f);
if (array.Length != 0)
{
return array.Select((RaycastHit h) => ((RaycastHit)(ref h)).point);
}
return Array.Empty<Vector3>();
}
}
}
namespace OnionMilk_crawlingmine
{
[BepInPlugin("OnionMilk_crawlingmine", "OnionMilk_crawlingmine", "1.0.5")]
public class Plugin : BaseUnityPlugin
{
private static Plugin instance;
private readonly Harmony _harmony = new Harmony("OnionMilk.CrawlingMine");
public static ConfigEntry<bool> cfgEnabled;
public static ConfigEntry<float> cfgJumpMineSpawnChance;
public static ConfigEntry<bool> cfgMineSound;
public static ConfigEntry<bool> cfgCrawlingMineSound;
public static ConfigEntry<float> cfgJumpIntervalMin;
public static ConfigEntry<float> cfgJumpIntervalMax;
public static ConfigEntry<float> cfgJumpRangeMin;
public static ConfigEntry<float> cfgJumpRangeMax;
private static string getPath;
public static string GetPath
{
get
{
if (getPath == null)
{
getPath = Path.GetDirectoryName(Uri.UnescapeDataString(new UriBuilder(Assembly.GetExecutingAssembly().CodeBase).Path));
}
return getPath;
}
}
public static void Log(string msg)
{
((BaseUnityPlugin)instance).Logger.LogInfo((object)("[OnionMilk_crawlingmine] " + msg));
}
private void Awake()
{
instance = this;
cfgJumpRangeMax = ((BaseUnityPlugin)this).Config.Bind<float>("Settings", "minRangeInterval", 1f, "Minimal jump range of mine (minval: 0.5)");
cfgJumpRangeMin = ((BaseUnityPlugin)this).Config.Bind<float>("Settings", "maxRangeInterval", 3f, "Maximal jump range of mine (minval: 0.5)");
cfgJumpIntervalMax = ((BaseUnityPlugin)this).Config.Bind<float>("Settings", "minJumpInterval", 4f, "Minimal of interval after which mine would change it's position (minval: 0.5)");
cfgJumpIntervalMin = ((BaseUnityPlugin)this).Config.Bind<float>("Settings", "maxJumpInterval", 10f, "Maximal of interval after which mine would change it's position (minval: 0.5)");
cfgJumpMineSpawnChance = ((BaseUnityPlugin)this).Config.Bind<float>("Settings", "chance", 0.1f, "Chance of transforming regular mine into jumping one (0.0-1.0)");
cfgMineSound = ((BaseUnityPlugin)this).Config.Bind<bool>("Settings", "mineBeepSound", true, "let's you disable beeping sound");
cfgCrawlingMineSound = ((BaseUnityPlugin)this).Config.Bind<bool>("Settings", "crawlingMineBeepSound", true, "let's you disable beeping sound of crawling mine ;)");
cfgEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "enabled", true, "Is plugin enabled?");
if (cfgEnabled.Value)
{
Log("Mod loaded and set up!");
_harmony.PatchAll();
}
}
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "OnionMilk_crawlingmine";
public const string PLUGIN_NAME = "OnionMilk_crawlingmine";
public const string PLUGIN_VERSION = "1.0.5";
}
}