Decompiled source of LethalRadiation v1.2.2

BepInEx/plugins/LethalRadiation.dll

Decompiled 3 months ago
using System;
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 GameNetcodeStuff;
using HarmonyLib;
using LethalRadiation.Patches;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("LethalRadiation")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Makes removeing the apparatus actaully cause radiation in the facility which can harm players overtime.")]
[assembly: AssemblyFileVersion("1.2.2.0")]
[assembly: AssemblyInformationalVersion("1.2.2")]
[assembly: AssemblyProduct("LethalRadiation")]
[assembly: AssemblyTitle("LethalRadiation")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.2.2.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 LethalRadiation
{
	internal class LRConfig
	{
		public static ConfigEntry<bool> DamageEnabled;

		public static ConfigEntry<int> BaseDamage;

		public static ConfigEntry<int> DamageInterval;

		public static ConfigEntry<bool> BlurEnabled;

		public static ConfigEntry<float> BaseBlur;

		public static ConfigEntry<float> BlurInterval;

		public static ConfigEntry<bool> OverrideApparatusValue;

		public static ConfigEntry<int> ApparatusValue;

		public static void Setup()
		{
			DamageEnabled = Plugin.Instance.Config.Bind<bool>("Damage", "Enable", true, "Determines if radiation should do damage to the player at the top of each hour");
			BaseDamage = Plugin.Instance.Config.Bind<int>("Damage", "BaseAmount", 10, "The starting amount of damage radiation will do to players before it is increased");
			DamageInterval = Plugin.Instance.Config.Bind<int>("Damage", "DamageIncreaseAmount", 1, "How much damage increases by at the top of each hour");
			BlurEnabled = Plugin.Instance.Config.Bind<bool>("Screen Blur", "Enable", true, "Determine if radiation should cause a player's screen to get blurry while in the building");
			BaseBlur = Plugin.Instance.Config.Bind<float>("Screen Blur", "BaseAmount", 0.02f, "The starting amount of screen blur radiation will cause before it is increased");
			BlurInterval = Plugin.Instance.Config.Bind<float>("Screen Blur", "BlurIncreaseAmount", 0.02f, "How much screen blur gets worse by at the top of each hour");
			OverrideApparatusValue = Plugin.Instance.Config.Bind<bool>("Apparatus", "OverrideApparatusValue", false, "Determines if the value of the apparatus should be overrided by the Value variable below");
			ApparatusValue = Plugin.Instance.Config.Bind<int>("Apparatus", "Value", 80, "The scrap value of the apparatus. [NOTE] Will not work if OverrideApparatusValue is set to false");
		}
	}
	[BepInPlugin("LethalRadiation", "LethalRadiation", "1.2.2")]
	[BepInProcess("Lethal Company.exe")]
	public class Plugin : BaseUnityPlugin
	{
		private readonly Harmony harmony = new Harmony("LethalRadiation");

		public static int CurrentDamageAmount;

		public static float CurrentBlurAmount;

		public static int CurrentHour;

		public static bool IsLungDocked;

		public static BaseUnityPlugin Instance { get; private set; }

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = (BaseUnityPlugin)(object)this;
			}
			LRConfig.Setup();
			CurrentDamageAmount = LRConfig.BaseDamage.Value;
			CurrentBlurAmount = LRConfig.BaseBlur.Value;
			CurrentHour = 0;
			IsLungDocked = true;
			harmony.PatchAll(typeof(EntranceTeleportPatch));
			harmony.PatchAll(typeof(LungPropPatch));
			harmony.PatchAll(typeof(Plugin));
			harmony.PatchAll(typeof(RoundManagerPatch));
			harmony.PatchAll(typeof(TimeOfDayPatch));
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin LethalRadiation is loaded!");
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "LethalRadiation";

		public const string PLUGIN_NAME = "LethalRadiation";

		public const string PLUGIN_VERSION = "1.2.2";
	}
}
namespace LethalRadiation.Patches
{
	[HarmonyPatch(typeof(EntranceTeleport))]
	internal class EntranceTeleportPatch
	{
		private static bool radiationPresentLastCheck;

		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		private static void UpdatePatch(ref bool ___enemyNearLastCheck, ref bool ___isEntranceToBuilding, ref InteractTrigger ___triggerScript)
		{
			if (!((Object)(object)___triggerScript == (Object)null) && ___isEntranceToBuilding)
			{
				if (!Plugin.IsLungDocked && !___enemyNearLastCheck && !radiationPresentLastCheck)
				{
					radiationPresentLastCheck = true;
					___triggerScript.hoverTip = "[Radiation detected!]";
				}
				else
				{
					radiationPresentLastCheck = false;
					___triggerScript.hoverTip = "Enter: [LMB]";
				}
			}
		}
	}
	[HarmonyPatch(typeof(LungProp))]
	internal class LungPropPatch
	{
		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		private static void StartPatch(LungProp __instance)
		{
			if (LRConfig.OverrideApparatusValue.Value)
			{
				((GrabbableObject)__instance).scrapValue = LRConfig.ApparatusValue.Value;
			}
		}

		[HarmonyPatch("EquipItem")]
		[HarmonyPrefix]
		private static void EquipItemPatch(ref bool ___isLungDocked)
		{
			if (___isLungDocked)
			{
				Plugin.IsLungDocked = false;
			}
		}
	}
	[HarmonyPatch(typeof(RoundManager))]
	internal class RoundManagerPatch
	{
		[HarmonyPatch("ResetEnemySpawningVariables")]
		[HarmonyPrefix]
		private static void ResetEnemySpawningVariablesPatch()
		{
			Plugin.IsLungDocked = true;
			Plugin.CurrentDamageAmount = LRConfig.BaseDamage.Value;
			Plugin.CurrentBlurAmount = LRConfig.BaseBlur.Value;
			Plugin.CurrentHour = 0;
			Debug.Log((object)$"LR variables reset! docked? {Plugin.IsLungDocked}");
		}
	}
	[HarmonyPatch(typeof(TimeOfDay))]
	internal class TimeOfDayPatch
	{
		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		private static void UpdatePatch(TimeOfDay __instance)
		{
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)GameNetworkManager.Instance == (Object)null || Plugin.IsLungDocked)
			{
				return;
			}
			PlayerControllerB localPlayerController = GameNetworkManager.Instance.localPlayerController;
			if (__instance.hour != Plugin.CurrentHour)
			{
				Debug.Log((object)$"Hour changed, hour: {__instance.hour}, currentHour: {Plugin.CurrentHour}, docked: {Plugin.IsLungDocked}, damage value: {LRConfig.DamageInterval.Value}, total damage: {Plugin.CurrentDamageAmount}, blur value: {LRConfig.BlurInterval.Value}, blur amount: {Plugin.CurrentBlurAmount}");
				if (LRConfig.DamageEnabled.Value && !localPlayerController.isPlayerDead && localPlayerController.isPlayerControlled && localPlayerController.isInsideFactory)
				{
					localPlayerController.DamagePlayer(Plugin.CurrentDamageAmount, false, true, (CauseOfDeath)0, 0, false, default(Vector3));
				}
				Plugin.CurrentDamageAmount += LRConfig.DamageInterval.Value;
				Plugin.CurrentBlurAmount += LRConfig.BlurInterval.Value;
				Plugin.CurrentHour = __instance.hour;
			}
			if (LRConfig.BlurEnabled.Value && !localPlayerController.isPlayerDead && localPlayerController.isPlayerControlled && localPlayerController.isInsideFactory && localPlayerController.drunkness <= Plugin.CurrentBlurAmount)
			{
				localPlayerController.drunkness = Plugin.CurrentBlurAmount;
			}
		}
	}
}