Decompiled source of AutoAlarm v0.1.0

AutoAlarm.dll

Decompiled 9 months ago
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 BepInEx.Logging;
using HarmonyLib;

[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.0", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("AutoAlarm")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("My first plugin")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("AutoAlarm")]
[assembly: AssemblyTitle("AutoAlarm")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace AutoAlarm;

[BepInPlugin("AutoAlarm", "com.geeksville.dsp.AutoAlarm", "0.1.0")]
public class Plugin : BaseUnityPlugin
{
	public const string __NAME__ = "AutoAlarm";

	public const string __GUID__ = "com.geeksville.dsp.AutoAlarm";

	public static ConfigEntry<bool> autoMiners;

	public static ConfigEntry<bool> autoAssemblers;

	public static ConfigEntry<bool> autoTurrets;

	public static ConfigEntry<bool> autoBABs;

	public static ConfigEntry<bool> autoLabs;

	public static ConfigEntry<bool> autoStations;

	public static ConfigEntry<bool> autoFieldGens;

	public static ConfigEntry<bool> autoConstructionModules;

	private static ManualLogSource logger;

	private void Awake()
	{
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin AutoAlarm is loaded!");
		logger = ((BaseUnityPlugin)this).Logger;
		autoMiners = ((BaseUnityPlugin)this).Config.Bind<bool>("Defaults", "autoMiners", true, "Default to alarm-on for miners");
		autoAssemblers = ((BaseUnityPlugin)this).Config.Bind<bool>("Defaults", "autoAssemblers", false, "Default to alarm-on for assemblers");
		autoTurrets = ((BaseUnityPlugin)this).Config.Bind<bool>("Defaults", "autoTurrets", true, "Default to alarm-on for turrets");
		autoBABs = ((BaseUnityPlugin)this).Config.Bind<bool>("Defaults", "autoBABs", true, "Default to alarm-on for BABs");
		autoLabs = ((BaseUnityPlugin)this).Config.Bind<bool>("Defaults", "autoLabs", false, "Default to alarm-on for labs");
		autoStations = ((BaseUnityPlugin)this).Config.Bind<bool>("Defaults", "autoStations", true, "Default to alarm-on for stations");
		autoFieldGens = ((BaseUnityPlugin)this).Config.Bind<bool>("Defaults", "autoFieldGens", true, "Default to alarm-on for field generators");
		autoConstructionModules = ((BaseUnityPlugin)this).Config.Bind<bool>("Defaults", "autoSmelters", true, "Default to alarm-on for smelters");
		Harmony.CreateAndPatchAll(typeof(Plugin), (string)null);
	}

	private static void SetAlarms(int entityId)
	{
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		//IL_0055: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_007a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_009c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0095: Unknown result type (might be due to invalid IL or missing references)
		//IL_00be: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_0102: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0124: Unknown result type (might be due to invalid IL or missing references)
		//IL_011d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0146: Unknown result type (might be due to invalid IL or missing references)
		//IL_013f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0161: Unknown result type (might be due to invalid IL or missing references)
		logger.LogInfo((object)$"SetAlarms {entityId}");
		PlanetData localPlanet = GameMain.localPlanet;
		if (localPlanet == null)
		{
			logger.LogError((object)"No local planet!");
			return;
		}
		PlanetFactory factory = localPlanet.factory;
		EntityData val = factory.entityPool[entityId];
		int num = 0;
		if (val.assemblerId != 0 && autoAssemblers.Value)
		{
			num = val.assemblerId;
		}
		if (val.minerId != 0 && autoMiners.Value)
		{
			num = val.minerId;
		}
		if (val.turretId != 0 && autoTurrets.Value)
		{
			num = val.turretId;
		}
		if (val.battleBaseId != 0 && autoBABs.Value)
		{
			num = val.battleBaseId;
		}
		if (val.labId != 0 && autoLabs.Value)
		{
			num = val.labId;
		}
		if (val.stationId != 0 && autoStations.Value)
		{
			num = val.stationId;
		}
		if (val.fieldGenId != 0 && autoFieldGens.Value)
		{
			num = val.fieldGenId;
		}
		if (val.constructionModuleId != 0 && autoConstructionModules.Value)
		{
			num = val.constructionModuleId;
		}
		if (num != 0)
		{
			logger.LogInfo((object)$"Auto alarm enable for {num}");
			factory.EnableEntityWarning(entityId);
		}
		else
		{
			logger.LogDebug((object)$"No auto alarm for {entityId}");
		}
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(GameScenarioLogic), "NotifyOnBuild")]
	public static void OnBuild_PostFix(int entityId)
	{
		SetAlarms(entityId);
	}
}
public static class PluginInfo
{
	public const string PLUGIN_GUID = "AutoAlarm";

	public const string PLUGIN_NAME = "AutoAlarm";

	public const string PLUGIN_VERSION = "1.0.0";
}