Decompiled source of smokeflare v1.0.1

OnionMilk_smokeflare.dll

Decompiled 11 months ago
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 GameNetcodeStuff;
using HarmonyLib;
using LethalLib.Modules;
using Microsoft.CodeAnalysis;
using OnionMilk_smokeflare;
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_smokeflare")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Smokeflare plugin for BepInEx (Lethal Company)")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("OnionMilk_smokeflare")]
[assembly: AssemblyTitle("OnionMilk_smokeflare")]
[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.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(GrabbableObject))]
	internal class GrabbableObjectPatches
	{
		private static Random rnd = null;

		private static Color[] colors = (Color[])(object)new Color[6]
		{
			Color.red,
			Color.green,
			Color.blue,
			Color.magenta,
			Color.yellow,
			Color.cyan
		};

		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		private static void Start(ref GrabbableObject __instance)
		{
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Expected O, but got Unknown
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			GrabbableObject obj = __instance;
			StunGrenadeItem val = (StunGrenadeItem)(object)((obj is StunGrenadeItem) ? obj : null);
			if (val != null)
			{
				if (rnd == null)
				{
					rnd = new Random(StartOfRound.Instance.randomMapSeed - 2137);
				}
				MeshRenderer component = ((Component)((Component)__instance).transform.Find("model/RetopoGroup1")).GetComponent<MeshRenderer>();
				Material val2 = new Material(((Renderer)component).sharedMaterial);
				int num = rnd.Next(Plugin.prefabs.Length);
				Color val3 = colors[num];
				val2.SetColor("_BaseColor", val3);
				if ((Object)(object)Plugin.prefabs[num] != (Object)null)
				{
					val.stunGrenadeExplosion = Plugin.prefabs[num];
				}
				((Renderer)component).sharedMaterial = val2;
			}
		}
	}
	[HarmonyPatch(typeof(StunGrenadeItem))]
	internal class StunGrenadeItemExplosionPatches
	{
		private static FieldInfo thrownByFld;

		[HarmonyPatch("ExplodeStunGrenade")]
		[HarmonyPrefix]
		private static void ExplodeStunGrenade(ref StunGrenadeItem __instance)
		{
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: 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_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			if (__instance == null || __instance.hasExploded)
			{
				return;
			}
			__instance.hasExploded = true;
			__instance.itemAudio.PlayOneShot(__instance.explodeSFX);
			WalkieTalkie.TransmitOneShotAudio(__instance.itemAudio, __instance.explodeSFX, 1f);
			Transform val = ((!((GrabbableObject)__instance).isInElevator) ? RoundManager.Instance.mapPropsContainer.transform : StartOfRound.Instance.elevatorTransform);
			GameObject obj = Object.Instantiate<GameObject>(__instance.stunGrenadeExplosion, ((Component)__instance).transform.position, Quaternion.identity, val);
			obj.transform.SetParent(((Component)__instance).transform);
			obj.transform.forward = ((Component)__instance).transform.right;
			((Component)__instance).gameObject.AddComponent<SmokeLightFade>();
			if (thrownByFld == null)
			{
				thrownByFld = typeof(StunGrenadeItem).GetField("playerThrownBy", BindingFlags.Instance | BindingFlags.NonPublic);
			}
			object? value = thrownByFld.GetValue(__instance);
			PlayerControllerB val2 = (PlayerControllerB)((value is PlayerControllerB) ? value : null);
			if (__instance.DestroyGrenade)
			{
				((GrabbableObject)__instance).DestroyObjectInHand(val2);
			}
			if (!((NetworkBehaviour)__instance).IsServer)
			{
				return;
			}
			IEnumerable<RedLocustBees> enumerable = from c in Physics.OverlapSphere(((Component)__instance).transform.position, Plugin.cfgRange.Value, LayerMask.GetMask(new string[1] { "Enemies" }))
				where c is CapsuleCollider
				select ((Component)c).GetComponentInParent<RedLocustBees>();
			if (!enumerable.Any())
			{
				return;
			}
			Vector3 position = ((Component)__instance).transform.position;
			foreach (RedLocustBees item in enumerable)
			{
				if (!((Object)(object)item == (Object)null))
				{
					((MonoBehaviour)__instance).StartCoroutine(BeeStartle(item, position));
				}
			}
		}

		private static IEnumerator BeeStartle(RedLocustBees bee, Vector3 exploPos)
		{
			//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)
			Plugin.Log("Bee found and startled!");
			Vector3 val = ((Component)bee).transform.position - exploPos;
			Vector3 normalized = ((Vector3)(ref val)).normalized;
			((EnemyAI)bee).SwitchToBehaviourState(2137);
			((EnemyAI)bee).moveTowardsDestination = true;
			RaycastHit val2 = default(RaycastHit);
			if (Physics.Raycast(((Component)bee).transform.position + 4f * normalized + 3f * Vector3.up, Vector3.down, ref val2, 10f))
			{
				((EnemyAI)bee).SetDestinationToPosition(((RaycastHit)(ref val2)).point, false);
			}
			else
			{
				((EnemyAI)bee).SetDestinationToPosition(((Component)bee).transform.position + 4f * normalized, false);
			}
			yield return null;
			for (float time = Plugin.cfgDuration.Value * 0.6f; time > 0f; time -= Time.deltaTime)
			{
				yield return null;
			}
			((EnemyAI)bee).SwitchToBehaviourState(0);
		}
	}
}
namespace OnionMilk_smokeflare
{
	[BepInPlugin("OnionMilk_smokeflare", "OnionMilk_smokeflare", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		private static Plugin instance;

		private readonly Harmony _harmony = new Harmony("OnionMilk.Smokeflare");

		public static ConfigEntry<bool> cfgEnabled;

		public static ConfigEntry<float> cfgDuration;

		public static ConfigEntry<float> cfgRange;

		public static ConfigEntry<float> cfgRarity;

		public static ConfigEntry<float> cfgNoiseRange;

		public static ConfigEntry<float> cfgNoiseLoudness;

		public static GameObject[] prefabs;

		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_smokeflare] " + msg));
		}

		private void Awake()
		{
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			instance = this;
			cfgRange = ((BaseUnityPlugin)this).Config.Bind<float>("Settings", "range", 4f, "Range of flare influence (bees and mines)");
			cfgDuration = ((BaseUnityPlugin)this).Config.Bind<float>("Settings", "duration", 10f, "Rarity of flare soawning");
			cfgRarity = ((BaseUnityPlugin)this).Config.Bind<float>("Settings", "rarity", 20f, "Duration of flare flaming");
			cfgNoiseRange = ((BaseUnityPlugin)this).Config.Bind<float>("Settings", "noiseRange", 10f, "Noise range of flare alarming enemies");
			cfgNoiseLoudness = ((BaseUnityPlugin)this).Config.Bind<float>("Settings", "rarity", 0.5f, "Noise loudness of flare alarming enemies");
			cfgEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "enabled", true, "Is mod enabled?");
			if (!cfgEnabled.Value)
			{
				return;
			}
			AssetBundle val = AssetBundle.LoadFromFile(Path.Combine(GetPath, "smokeflare"));
			Item val2 = val.LoadAsset<Item>("Assets/SMOKE_FLARE/SmokeFlareItem.asset");
			GameObject spawnPrefab = val2.spawnPrefab;
			prefabs = (GameObject[])(object)new GameObject[6];
			for (int i = 0; i < prefabs.Length; i++)
			{
				prefabs[i] = val.LoadAsset<GameObject>($"Assets/SMOKE_FLARE/Smoke{i}.prefab");
				if ((Object)(object)prefabs[i] != (Object)null)
				{
					MainModule main = prefabs[i].GetComponent<ParticleSystem>().main;
					((MainModule)(ref main)).duration = cfgDuration.Value;
					NetworkPrefabs.RegisterNetworkPrefab(prefabs[i]);
				}
			}
			NetworkPrefabs.RegisterNetworkPrefab(spawnPrefab);
			Utilities.FixMixerGroups(spawnPrefab);
			Items.RegisterScrap(val2, Mathf.RoundToInt(1f * cfgRarity.Value), (LevelTypes)96);
			Items.RegisterScrap(val2, Mathf.RoundToInt(3f * cfgRarity.Value), (LevelTypes)28);
			Items.RegisterScrap(val2, Mathf.RoundToInt(2f * cfgRarity.Value), (LevelTypes)896);
			TerminalNode obj = ScriptableObject.CreateInstance<TerminalNode>();
			obj.clearPreviousText = true;
			obj.displayText = "Smoke Flare";
			_harmony.PatchAll();
			Log("Mod is loaded!");
		}
	}
	public class SmokeLightFade : MonoBehaviour
	{
		private Light light;

		private void Start()
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			ParticleSystem component = ((Component)this).GetComponent<ParticleSystem>();
			light = ((Component)this).GetComponentInChildren<Light>();
			MainModule main = component.main;
			((MonoBehaviour)this).StartCoroutine(FadeOut(((MainModule)(ref main)).duration));
		}

		public void PlayNoise()
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			RoundManager.Instance.PlayAudibleNoise(((Component)this).transform.position, Plugin.cfgNoiseRange.Value, Plugin.cfgNoiseLoudness.Value, 1, StartOfRound.Instance.hangarDoorsClosed, 0);
		}

		private IEnumerator FadeOut(float duration)
		{
			PlayNoise();
			float startIntensity = light.intensity;
			float startFade = duration * 0.25f;
			for (float timer = duration; timer > 0f; timer -= Time.deltaTime)
			{
				if (timer < startFade)
				{
					float num = timer / startFade;
					light.intensity = num * startIntensity;
				}
				yield return null;
			}
			light.intensity = 0f;
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "OnionMilk_smokeflare";

		public const string PLUGIN_NAME = "OnionMilk_smokeflare";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}