Decompiled source of KeepEnemyPower v1.0.64

BepInEx/plugins/KeepEnemyPower.dll

Decompiled 2 months ago
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using KeepEnemyPower.Patches;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: ComVisible(false)]
[assembly: Guid("54c69e4e-8e9f-4718-8342-958f866d451e")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("KeepEnemyPower")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+7855119de940324ff1397f41b9934b32e50d322e")]
[assembly: AssemblyProduct("KeepEnemyPower")]
[assembly: AssemblyTitle("KeepEnemyPower")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace KeepEnemyPower
{
	[BepInPlugin("JS03.KeepEnemyPower", "Keep Enemy Power", "1.0.64")]
	public class Plugin : BaseUnityPlugin
	{
		private const string modGUID = "JS03.KeepEnemyPower";

		private const string modName = "Keep Enemy Power";

		private const string modVersion = "1.0.64";

		public static ConfigEntry<bool> keepIndoorsPower;

		public static ConfigEntry<bool> keepOutdoorsPower;

		private readonly Harmony harmony = new Harmony("JS03.KeepEnemyPower");

		private static Plugin Instance;

		internal static ManualLogSource mls;

		private void Awake()
		{
			mls = Logger.CreateLogSource("JS03.KeepEnemyPower");
			mls.LogInfo((object)"Keep Enemy Power is now active");
			GenerateConfigValues();
			harmony.PatchAll(typeof(EnemyAIPatch));
		}

		internal void GenerateConfigValues()
		{
			keepIndoorsPower = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Keep Indoors Power", true, "Keeps the indoors enemy power when an indoor enemy dies");
			keepOutdoorsPower = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Keep Outdoors Power", true, "Keeps the outdoors enemy power when an outdoor enemy dies");
		}

		public static void LogToConsole(string message, string logType = "")
		{
			string text = logType.ToLower();
			string text2 = text;
			if (!(text2 == "warn"))
			{
				if (text2 == "error")
				{
					mls.LogError((object)message);
				}
				else
				{
					mls.LogInfo((object)message);
				}
			}
			else
			{
				mls.LogWarning((object)message);
			}
		}
	}
}
namespace KeepEnemyPower.Patches
{
	[HarmonyPatch(typeof(EnemyAI))]
	internal class EnemyAIPatch
	{
		[HarmonyPatch("SubtractFromPowerLevel")]
		[HarmonyPrefix]
		private static void CheckPreviousPower(EnemyAI __instance, ref bool ___removedPowerLevel)
		{
			if (!___removedPowerLevel)
			{
				if (__instance.enemyType.isDaytimeEnemy)
				{
					Plugin.LogToConsole("Previous Daytime Enemy Power -> " + RoundManager.Instance.currentDaytimeEnemyPower);
				}
				else if (__instance.isOutside)
				{
					Plugin.LogToConsole("Previous Outside Enemy Power -> " + RoundManager.Instance.currentOutsideEnemyPower);
				}
				else
				{
					Plugin.LogToConsole("Previous Inside Enemy Power -> " + RoundManager.Instance.currentEnemyPower);
				}
			}
		}

		[HarmonyPatch("SubtractFromPowerLevel")]
		[HarmonyPostfix]
		private static void KeepPowerLevel(EnemyAI __instance, ref bool ___removedPowerLevel)
		{
			if (!___removedPowerLevel)
			{
				return;
			}
			if (__instance.enemyType.isDaytimeEnemy)
			{
				if (Plugin.keepOutdoorsPower.Value)
				{
					___removedPowerLevel = false;
					RoundManager.Instance.currentDaytimeEnemyPower = Mathf.Max(RoundManager.Instance.currentDaytimeEnemyPower + __instance.enemyType.PowerLevel, 0f);
				}
				Plugin.LogToConsole("Current Daytime Enemy Power -> " + RoundManager.Instance.currentDaytimeEnemyPower);
			}
			else if (__instance.isOutside)
			{
				if (Plugin.keepOutdoorsPower.Value)
				{
					___removedPowerLevel = false;
					RoundManager.Instance.currentOutsideEnemyPower = Mathf.Max(RoundManager.Instance.currentOutsideEnemyPower + __instance.enemyType.PowerLevel, 0f);
				}
				Plugin.LogToConsole("Current Outside Enemy Power -> " + RoundManager.Instance.currentOutsideEnemyPower);
			}
			else
			{
				if (Plugin.keepIndoorsPower.Value)
				{
					___removedPowerLevel = false;
					RoundManager.Instance.currentEnemyPower = Mathf.Max(RoundManager.Instance.currentEnemyPower + __instance.enemyType.PowerLevel, 0f);
				}
				Plugin.LogToConsole("Current Inside Enemy Power -> " + RoundManager.Instance.currentEnemyPower);
			}
		}
	}
}