Decompiled source of NoUnrepairableDamage v1.0.9

NoUnrepairableDamage.dll

Decompiled 2 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using CG.Game;
using CG.Ship.Repair;
using CG.Space;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using VoidManager;
using VoidManager.MPModChecks;
using VoidManager.Utilities;

[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("NoUnrepairableDamage")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.9.0")]
[assembly: AssemblyInformationalVersion("1.0.9")]
[assembly: AssemblyProduct("No Unrepairable Damage")]
[assembly: AssemblyTitle("NoUnrepairableDamage")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.9.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 NoUnrepairableDamage
{
	[BepInPlugin("NoUnrepairableDamage", "No Unrepairable Damage", "1.0.9")]
	[BepInProcess("Void Crew.exe")]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Log;

		private void Awake()
		{
			Log = ((BaseUnityPlugin)this).Logger;
			Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "NoUnrepairableDamage");
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin NoUnrepairableDamage is loaded!");
		}
	}
	[HarmonyPatch(typeof(HullDamageController), "OnRepairedBreach")]
	internal class HullDamageControllerPatch
	{
		private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Expected O, but got Unknown
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Expected O, but got Unknown
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Expected O, but got Unknown
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Expected O, but got Unknown
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Expected O, but got Unknown
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Expected O, but got Unknown
			List<CodeInstruction> list = new List<CodeInstruction>
			{
				new CodeInstruction(OpCodes.Ldarg_0, (object)null),
				new CodeInstruction(OpCodes.Ldfld, (object)null),
				new CodeInstruction(OpCodes.Dup, (object)null),
				new CodeInstruction(OpCodes.Callvirt, (object)null),
				new CodeInstruction(OpCodes.Ldloc_0, (object)null),
				new CodeInstruction(OpCodes.Add, (object)null)
			};
			List<CodeInstruction> list2 = new List<CodeInstruction>();
			list2.Add(new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(HullDamageControllerPatch), "ClampHitpoints", (Type[])null, (Type[])null)));
			List<CodeInstruction> list3 = list2;
			return HarmonyHelpers.PatchBySequence(instructions, (IEnumerable<CodeInstruction>)list, (IEnumerable<CodeInstruction>)list3, (PatchMode)1, (CheckMode)2, false);
		}

		[HarmonyPostfix]
		private static void PostfixOnRepairedBreach(ref HullBreach breach, HullDamageController __instance, PlayerControlledShip ___playerShip)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Invalid comparison between Unknown and I4
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Invalid comparison between Unknown and I4
			List<HullBreach> list = new List<HullBreach>();
			foreach (HullBreach breach2 in __instance.Breaches)
			{
				if ((int)breach2.State.condition == 2 || (int)breach2.State.condition == 1)
				{
					list.Add(breach2);
				}
			}
			if (list.Count == 0)
			{
				((OrbitObject)___playerShip).HitPoints = ((OrbitObject)___playerShip).MaxHitPointsValue;
			}
		}

		private static float ClampHitpoints(float hitpoints)
		{
			return Mathf.Min(((OrbitObject)ClientGame.Current.PlayerShip).MaxHitPointsValue, hitpoints);
		}
	}
	[HarmonyPatch(typeof(HullState), "SetRepairableHp")]
	public class HullStatePatch
	{
		[HarmonyPrefix]
		private static bool PrefixSetRepairableHp(ref float newRepairableHp, ref float newUnrepairableHp)
		{
			newRepairableHp += newUnrepairableHp;
			newUnrepairableHp = 0f;
			return true;
		}
	}
	internal class VoidManagerPlugin : VoidPlugin
	{
		public override MultiplayerType MPType => (MultiplayerType)14;

		public override string Author => "Arpharel, Miranoff";

		public override string Description => "Allows you to repair your ship to full health. Hull Breach is required to be able to repair to full.";
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "NoUnrepairableDamage";

		public const string PLUGIN_NAME = "No Unrepairable Damage";

		public const string PLUGIN_VERSION = "1.0.9";
	}
}