Decompiled source of ShipHull v1.0.2

ShipHull.dll

Decompiled 2 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
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.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem;
using Il2CppSystem.Collections.Generic;
using Il2CppSystem.IO;
using Microsoft.CodeAnalysis;
using Steamworks.Data;
using WildSkies.Gameplay.ShipBuilding;
using WildSkies.Service;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("ShipHull")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyCopyright("Nines (Natives)")]
[assembly: AssemblyFileVersion("1.0.2.0")]
[assembly: AssemblyInformationalVersion("1.0.2")]
[assembly: AssemblyProduct("ShipHull")]
[assembly: AssemblyTitle("ShipHull")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.2.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 ShipHull
{
	[BepInPlugin("ShipHull", "ShipHull", "1.0.2")]
	public class Plugin : BasePlugin
	{
		internal static ManualLogSource Log;

		internal static Harmony harmonyInstance;

		private static ConfigEntry<int> ShipHull_MaxItemObjects;

		private static ConfigEntry<bool> ShipHull_DisableSafety;

		private static bool _enableShipHullDeserialize;

		public override void Load()
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			Log = ((BasePlugin)this).Log;
			ManualLogSource log = Log;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(18, 1, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Plugin ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("ShipHull");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" is loaded!");
			}
			log.LogInfo(val);
			ShipHull_MaxItemObjects = ((BasePlugin)this).Config.Bind<int>("ShipHull", "MaxItemObjects", 1024, "ShipHull.MaxItemObjects");
			ShipHull_DisableSafety = ((BasePlugin)this).Config.Bind<bool>("ShipHull", "DisableSafety", false, "ShipHull.DisableSafety");
			harmonyInstance = Harmony.CreateAndPatchAll(typeof(Plugin), (string)null);
		}

		public override bool Unload()
		{
			Harmony obj = harmonyInstance;
			if (obj != null)
			{
				obj.UnpatchSelf();
			}
			return true;
		}

		[HarmonyPatch(typeof(NetworkService), "CreateAndJoinNewRoom")]
		[HarmonyPrefix]
		public static void NetworkService_CreateAndJoinNewRoom(string roomName)
		{
			_enableShipHullDeserialize = roomName.EndsWith(" *") || ShipHull_DisableSafety.Value;
		}

		[HarmonyPatch(typeof(NetworkService), "SetupLobbyData")]
		[HarmonyPrefix]
		public static void NetworkService_SetupLobbyData(Lobby selectedLobby)
		{
			_enableShipHullDeserialize = ((Lobby)(ref selectedLobby)).GetData("name").EndsWith(" *");
		}

		[HarmonyPriority(300)]
		[HarmonyPatch(typeof(ShipHull), "Deserialize")]
		[HarmonyPrefix]
		public static bool ShipHull_Deserialize(BinaryReader reader, IItemService itemService, BuildingService buildingService, ICraftingService craftingService, ref ShipHull __result, bool __runOriginal)
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Expected O, but got Unknown
			if (!_enableShipHullDeserialize)
			{
				return true;
			}
			if (!__runOriginal)
			{
				return true;
			}
			if (ShipHull_MaxItemObjects.Value <= ShipHull.MAX_ITEM_OBJECTS)
			{
				return true;
			}
			try
			{
				int num = reader.ReadInt32();
				ShipHull val = new ShipHull(9);
				val.ShipDesignName = reader.ReadString();
				val.IsCrafted = reader.ReadBoolean();
				val.ShipSaveSlot = reader.ReadInt32();
				val.ShipHullVersion = reader.ReadInt32();
				val.ShipHullUUID = reader.ReadString();
				val._nextFaceID = reader.ReadInt32();
				val.ShipStatsPresetId = reader.ReadInt32();
				val.UseVisualShipHull = reader.ReadBoolean();
				val.VisualShipHullAttachmentIndex = reader.ReadInt32();
				int num2 = reader.ReadInt32();
				val.HullObjectDataList = Il2CppReferenceArray<HullObjectData>.op_Implicit((HullObjectData[])(object)new HullObjectData[ShipHull_MaxItemObjects.Value]);
				for (int i = 0; i < num2; i++)
				{
					HullObjectData val2 = (reader.ReadBoolean() ? HullObjectData.Deserialize(reader, num, itemService, buildingService, craftingService) : null);
					if (i < ((Il2CppArrayBase<HullObjectData>)(object)val.HullObjectDataList).Length)
					{
						((Il2CppArrayBase<HullObjectData>)(object)val.HullObjectDataList)[i] = val2;
					}
				}
				num2 = reader.ReadByte();
				val.HullEdgeCraftingItemIds.Clear();
				for (int j = 0; j < num2; j++)
				{
					val.HullEdgeCraftingItemIds.Add(itemService.GetItemIdFromUniqueId(reader.ReadUInt16()));
				}
				num2 = reader.ReadInt32();
				val.HullVertices.Clear();
				val.HullEdges.Clear();
				for (int k = 0; k < num2; k++)
				{
					ValueTuple<HullVertex, List<HullEdge>> obj = HullVertex.Deserialize(reader, num);
					HullVertex item = obj.Item1;
					val.HullVertices[item.ID] = item;
					Enumerator<HullEdge> enumerator = obj.Item2.GetEnumerator();
					while (enumerator.MoveNext())
					{
						HullEdge current = enumerator.Current;
						val.HullEdges[current.ID] = current;
					}
				}
				num2 = reader.ReadInt32();
				val.HullBlocks.Clear();
				val.HullFaces.Clear();
				for (int l = 0; l < num2; l++)
				{
					ValueTuple<HullBlock, List<HullFace>> val3 = HullBlock.Deserialize(reader, num, itemService, buildingService);
					HullBlock hullBlock = val3.Item1;
					val.HullBlocks[hullBlock.ID] = hullBlock;
					Enumerator<int, HullEdge> enumerator2 = val.HullEdges.Values.GetEnumerator();
					while (enumerator2.MoveNext())
					{
						HullEdge current2 = enumerator2.Current;
						if (!((IEnumerable<int>)current2.VertsIDs).Any((int x) => !hullBlock.VertsIDs.Contains(x)))
						{
							hullBlock.EdgesIDs.Add(current2.ID);
						}
					}
					Enumerator<HullFace> enumerator3 = val3.Item2.GetEnumerator();
					while (enumerator3.MoveNext())
					{
						HullFace current3 = enumerator3.Current;
						val.HullFaces[current3.ID] = current3;
						foreach (int item2 in (Il2CppArrayBase<int>)(object)current3.VertsIDs)
						{
							val.HullVertices[item2].LinkedFacesIDs.Add(current3.ID);
						}
					}
				}
				Enumerator<int, HullVertex> enumerator5 = val.HullVertices.GetEnumerator();
				while (enumerator5.MoveNext())
				{
					enumerator5.Current.Value.ResolveDependencies(val.HullFaces);
				}
				Enumerator<int, HullEdge> enumerator6 = val.HullEdges.GetEnumerator();
				while (enumerator6.MoveNext())
				{
					enumerator6.Current.Value.ResolveDependencies(val.HullVertices);
				}
				Enumerator<int, HullFace> enumerator7 = val.HullFaces.GetEnumerator();
				while (enumerator7.MoveNext())
				{
					enumerator7.Current.Value.ResolveDependencies(val.HullVertices);
				}
				Enumerator<int, HullBlock> enumerator8 = val.HullBlocks.GetEnumerator();
				while (enumerator8.MoveNext())
				{
					enumerator8.Current.Value.ResolveDependencies(val.HullVertices, val.HullEdges, val.HullFaces);
				}
				__result = val;
				return false;
			}
			catch
			{
				reader.BaseStream.Seek(0L, (SeekOrigin)0);
				return true;
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "ShipHull";

		public const string PLUGIN_NAME = "ShipHull";

		public const string PLUGIN_VERSION = "1.0.2";
	}
}