Decompiled source of TurretDownTime v0.1.0

TurretDownTime.dll

Decompiled 8 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 HarmonyLib;
using Microsoft.CodeAnalysis;
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("TurretDownTime")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Configures how long turrets stay off when disabled from the console.")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0")]
[assembly: AssemblyProduct("TurretDownTime")]
[assembly: AssemblyTitle("TurretDownTime")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.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 TurretDownTime
{
	[BepInPlugin("com.slightlyinteractive.lethalcompany.turretdowntime", "Turret Down Time", "1.0.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		public struct PluginConfig
		{
			public ConfigEntry<int> minTime;

			public ConfigEntry<int> medianTime;

			public ConfigEntry<int> maxTime;

			public ConfigEntry<bool> linear;
		}

		private const string PLUGIN_GUID = "com.slightlyinteractive.lethalcompany.turretdowntime";

		private const string PLUGIN_NAME = "Turret Down Time";

		private const string PLUGIN_VERSION = "1.0.0.0";

		public static PluginConfig config;

		private readonly Harmony harmony = new Harmony("com.slightlyinteractive.lethalcompany.turretdowntime");

		private void Awake()
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin com.slightlyinteractive.lethalcompany.turretdowntime is loaded!");
			config.minTime = ((BaseUnityPlugin)this).Config.Bind<int>("General", "Minimum Time", 5, "The minimum time that the turret will be disabled for.");
			config.medianTime = ((BaseUnityPlugin)this).Config.Bind<int>("General", "Median Time", 45, "The median time that the turret will be disabled for. A time closer to the median is more likely to be chosen than one close to the minimum or maximum.");
			config.maxTime = ((BaseUnityPlugin)this).Config.Bind<int>("General", "Maximum Time", 85, "The maximum time that the turret will be disabled for.");
			config.linear = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Linear Probability Distribution", false, "If set to true, we ignore the median and pick any time between minimum and maximum. Any time will have the same probability of being chosen as any other.");
			harmony.PatchAll();
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "TurretDownTime";

		public const string PLUGIN_NAME = "TurretDownTime";

		public const string PLUGIN_VERSION = "0.1.0";
	}
}
namespace TurretDownTime.Patches
{
	[HarmonyPatch(typeof(Turret))]
	internal class TurretPatch
	{
		[HarmonyPrefix]
		[HarmonyPatch("ToggleTurretEnabled")]
		private static bool PatchToggleTurretEnabled(ref bool enabled, ref bool ___turretActive, ref float ___turretInterval)
		{
			if (enabled && !___turretActive && ___turretInterval > 0f)
			{
				return false;
			}
			if (!enabled & ___turretActive)
			{
				___turretInterval = CalcDuration();
			}
			return true;
		}

		[HarmonyPrefix]
		[HarmonyPatch("Update")]
		private static bool PatchUpdate(ref bool ___turretActive, ref float ___turretInterval, Turret __instance)
		{
			if (!___turretActive)
			{
				___turretInterval -= Time.deltaTime;
				if (___turretInterval <= 0f)
				{
					___turretInterval = 0f;
					__instance.ToggleTurretEnabled(true);
				}
			}
			return true;
		}

		private static float CalcDuration()
		{
			float num = Plugin.config.minTime.Value;
			float num2 = Plugin.config.medianTime.Value;
			float num3 = Plugin.config.maxTime.Value;
			Random random = new Random();
			if (Plugin.config.linear.Value)
			{
				return random.Next((int)num, (int)num3 + 1);
			}
			float num4 = random.Next(1, 7) + random.Next(1, 7);
			if (num4 <= 7f)
			{
				float num5 = (num2 - num) / 5f;
				return (float)Math.Floor(num + (num4 - 2f) * num5);
			}
			float num6 = (num3 - num2) / 5f;
			return (float)Math.Floor(num2 + (num4 - 7f) * num6);
		}
	}
}