Decompiled source of ThinHull v0.0.1

ThinHull.dll

Decompiled 6 months ago
using System;
using System.Collections.Generic;
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.Logging;
using CG.Game;
using CG.Ship.Repair;
using CG.Space;
using Gameplay.Atmosphere;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using UnityEngine;
using VoidManager;
using VoidManager.MPModChecks;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("ThinHull")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Template")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ThinHull")]
[assembly: AssemblyTitle("ThinHull")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.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 ThinHull
{
	[HarmonyPatch(typeof(Atmosphere))]
	internal class AtmospherePatch
	{
		internal static Dictionary<HullBreach, Room> nearestRoom;

		private static readonly FieldInfo breachesField = AccessTools.Field(typeof(HullDamageController), "breaches");

		private const float airLeakRate = 0.4f;

		private const float heatLeakRate = 0.3f;

		[HarmonyPostfix]
		[HarmonyPatch("RoomsInitialize")]
		private static void RoomsInitialize()
		{
			CreateDictionary();
		}

		[HarmonyPostfix]
		[HarmonyPatch("RoomsShutdown")]
		private static void RoomsShutdown()
		{
			nearestRoom = null;
		}

		[HarmonyPrefix]
		[HarmonyPatch("LateUpdate")]
		private static void LateUpdate(Atmosphere __instance)
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Invalid comparison between Unknown and I4
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			if (!PhotonNetwork.IsMasterClient || nearestRoom == null)
			{
				return;
			}
			foreach (HullBreach key in nearestRoom.Keys)
			{
				if ((int)key.State.condition != 0)
				{
					Room val = nearestRoom[key];
					AtmosphereValues elementAt = __instance.Atmospheres.GetElementAt(val.RoomIndex);
					elementAt.Oxygen *= 1f - 0.4f / val.Volume * (float)key.State.condition;
					elementAt.Pressure = elementAt.Oxygen;
					float num = elementAt.Temperature + 273f;
					num *= 1f - 0.3f / val.Volume * (float)key.State.condition;
					elementAt.Temperature = num - 273f;
					__instance.Atmospheres.SetElement(val, elementAt);
				}
			}
		}

		internal static void CreateDictionary()
		{
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			nearestRoom = new Dictionary<HullBreach, Room>();
			AbstractPlayerControlledShip playerShip = ClientGame.Current.PlayerShip;
			HullDamageController val = ((playerShip != null) ? ((Component)playerShip).GetComponentInChildren<HullDamageController>() : null);
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			Vector3 val3 = default(Vector3);
			foreach (HullBreach item in (List<HullBreach>)breachesField.GetValue(val))
			{
				float num = float.MaxValue;
				Room value = null;
				foreach (RoomCollection s_roomCollection in RoomCollection.s_roomCollections)
				{
					Room[] rooms = s_roomCollection.Rooms;
					foreach (Room val2 in rooms)
					{
						s_roomCollection.RoomSphereIntersect(val2, ((Component)item).transform.position, 1000f, ref val3);
						Vector3 val4 = ((Component)item).transform.position - val3;
						float sqrMagnitude = ((Vector3)(ref val4)).sqrMagnitude;
						if (sqrMagnitude < num)
						{
							num = sqrMagnitude;
							value = val2;
						}
					}
				}
				nearestRoom.Add(item, value);
			}
		}
	}
	internal static class MyPluginInfo
	{
		internal const string PLUGIN_GUID = "id107.thinhull";

		internal const string PLUGIN_NAME = "Thin Hull";

		internal const string PLUGIN_VERSION = "0.0.1";
	}
	[BepInPlugin("id107.thinhull", "Thin Hull", "0.0.1")]
	[BepInProcess("Void Crew.exe")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class BepinPlugin : BaseUnityPlugin
	{
		internal static ManualLogSource Log;

		private void Awake()
		{
			Log = ((BaseUnityPlugin)this).Logger;
			Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "id107.thinhull");
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin id107.thinhull is loaded!");
		}
	}
	public class VoidManagerPlugin : VoidPlugin
	{
		public override MultiplayerType MPType => (MultiplayerType)4;

		public override string Author => "18107";

		public override string Description => "Makes hull breaches leak air from the ship";
	}
}