Decompiled source of OutpostDockPump v1.0.0

BepInEx\plugins\OutpostDockPump\OutpostDockPump.dll

Decompiled 2 days ago
using System;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace OutpostDockPump;

[BepInPlugin("bill.outpostdockpump", "Outpost Dock Pump", "1.0.0")]
public sealed class OutpostDockPumpPlugin : BaseUnityPlugin
{
	private static ConfigEntry<bool> _enabled;

	private static ConfigEntry<float> _outpostPumpMultiplier;

	private static ManualLogSource _log;

	private void Awake()
	{
		//IL_0055: Unknown result type (might be due to invalid IL or missing references)
		_log = ((BaseUnityPlugin)this).Logger;
		_enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Enable draining a docked outpost when the player's pump room runs.");
		_outpostPumpMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("General", "OutpostPumpMultiplier", 0.1f, "Strength of outpost draining relative to the pump's normal water removal. 0.1 = about 3 seconds to drain a flooded outpost with an automatic pump.");
		new Harmony("bill.outpostdockpump").PatchAll();
		_log.LogInfo((object)"Outpost Dock Pump loaded.");
	}

	internal static void TryDrainDockedOutpost(E_SubmarineDamage damage, float amount)
	{
		try
		{
			if (_enabled == null || !_enabled.Value || (Object)(object)damage == (Object)null || amount <= 0f)
			{
				return;
			}
			CMD_ShipManager instance = CMD_ShipManager.Instance;
			if ((Object)(object)instance == (Object)null || (Object)(object)instance.playerShip == (Object)null || (Object)(object)instance.outpost == (Object)null || (Object)(object)damage.submarine != (Object)(object)instance.playerShip)
			{
				return;
			}
			CMD_OutpostManager instance2 = CMD_OutpostManager.Instance;
			if ((Object)(object)instance2 == (Object)null || !instance2.outpostGenerated)
			{
				return;
			}
			E_SubmarineDamage e_submarineDamage = instance.outpost.E_submarineDamage;
			CMD_Network instance3 = CMD_Network.Instance;
			if ((Object)(object)e_submarineDamage == (Object)null || (Object)(object)instance3 == (Object)null)
			{
				return;
			}
			float outpostWaterLevel = instance3.outpostWaterLevel;
			if (outpostWaterLevel <= 0f)
			{
				return;
			}
			float num = amount * _outpostPumpMultiplier.Value;
			if (!(num <= 0f))
			{
				if (num > outpostWaterLevel)
				{
					num = outpostWaterLevel;
				}
				e_submarineDamage.RemoveWaterFromShip(num);
			}
		}
		catch (Exception ex)
		{
			if (_log != null)
			{
				_log.LogError((object)("Failed to drain docked outpost: " + ex.Message));
			}
		}
	}
}
[HarmonyPatch(typeof(E_SubmarineDamage), "RemoveWaterFromShip")]
public static class PatchRemoveWaterFromShip
{
	private static void Prefix(E_SubmarineDamage __instance, float P_amount)
	{
		OutpostDockPumpPlugin.TryDrainDockedOutpost(__instance, P_amount);
	}
}