Decompiled source of Steamboat Willie Ship v0.0.0

Custom Ship Loader.dll

Decompiled 10 months ago
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("Custom Ship Loader")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Custom Ship Loader")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("61919b5d-ca9a-4f8a-8095-f457218404fe")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Custom_Ship_Loader
{
	[BepInPlugin("01Ryan.CustomShipLoader", "Custom Ship Loader", "1.0.0")]
	public class CustomShipLoaderBase : BaseUnityPlugin
	{
		private const string modGUID = "01Ryan.CustomShipLoader";

		private const string modName = "Custom Ship Loader";

		private const string modVersion = "1.0.0";

		private readonly Harmony harmony = new Harmony("01Ryan.CustomShipLoader");

		public static CustomShipLoaderBase Instance;

		public static ConfigFile config;

		public static GameObject CustomShip;

		private void Awake()
		{
			Instance = this;
			config = ((BaseUnityPlugin)this).Config;
			Config.Load();
			string text = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), Config.ShipFileName.Value);
			AssetBundle val = AssetBundle.LoadFromFile(text);
			CustomShip = val.LoadAsset<GameObject>("Assets/Custom Ships/Prefabs/" + Config.UnityPrefabAssetName.Value + ".prefab");
			harmony.PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)(Config.UnityPrefabAssetName.Value + " is ready to depart!"));
		}
	}
	public class Config
	{
		public static ConfigEntry<string> ShipFileName;

		public static ConfigEntry<string> UnityPrefabAssetName;

		public static void Load()
		{
			ShipFileName = CustomShipLoaderBase.config.Bind<string>("Info", "ShipFileName", "steamboatwillie", "What ship file should be loaded?");
			UnityPrefabAssetName = CustomShipLoaderBase.config.Bind<string>("Info", "UnityPrefabAssetName", "Steamboat Willie", "What is the internal name of the ship's prefab?");
		}
	}
}
namespace Custom_Ship_Loader.Patches
{
	[HarmonyPatch(typeof(StartOfRound))]
	internal class LoadShipPatch
	{
		[HarmonyPrefix]
		[HarmonyPatch("Start")]
		private static void ReplaceShipPatch()
		{
			GameObject val = GameObject.Find("HangarShip");
			GameObject val2 = Object.Instantiate<GameObject>(CustomShipLoaderBase.CustomShip, val.transform);
			SyncChildren(val.transform, val2.transform);
			val2.SetActive(true);
			StartOfRound[] array = Object.FindObjectsOfType<StartOfRound>();
			foreach (StartOfRound val3 in array)
			{
				val3.shipBounds = ((Component)val2.transform.Find("ShipBoundsTrigger")).GetComponent<Collider>();
				val3.shipInnerRoomBounds = ((Component)val2.transform.Find("ShipInnerRoomBoundsTrigger")).GetComponent<Collider>();
			}
			CleanUpChildren(val);
		}

		private static void SyncChildren(Transform src, Transform dst)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: 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_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			foreach (Transform item in ((Component)src).transform)
			{
				Transform val = item;
				if ((Object)(object)((Component)dst).transform.Find(((Object)val).name) != (Object)null)
				{
					Transform val2 = ((Component)dst).transform.Find(((Object)val).name);
					if (Object.op_Implicit((Object)(object)((Component)val).GetComponent<AutoParentToShip>()))
					{
						AutoParentToShip component = ((Component)val).GetComponent<AutoParentToShip>();
						((Component)val).transform.SetLocalPositionAndRotation(val2.localPosition, val2.localRotation);
						component.positionOffset = val2.localPosition;
						component.rotationOffset = val2.localEulerAngles;
					}
					else
					{
						((Component)val).transform.SetLocalPositionAndRotation(val2.localPosition, val2.localRotation);
					}
					val.localScale = val2.localScale;
					if (val.childCount > 0)
					{
						SyncChildren(val, val2);
					}
					if (((Object)val2).name == "ShipBoundsTrigger" || ((Object)val2).name == "ShipInnerRoomBoundsTrigger")
					{
						((Component)val).gameObject.SetActive(false);
					}
					else
					{
						((Component)val2).gameObject.SetActive(false);
					}
				}
				else
				{
					((Component)val).gameObject.SetActive(false);
				}
			}
		}

		private static void CleanUpChildren(GameObject root)
		{
			for (int i = 0; i < root.transform.childCount; i++)
			{
				if (!((Component)root.transform.GetChild(i)).gameObject.activeSelf && Object.op_Implicit((Object)(object)((Component)root.transform.GetChild(i)).gameObject.GetComponentInChildren<MeshRenderer>()))
				{
					Object.Destroy((Object)(object)((Component)root.transform.GetChild(i)).gameObject);
				}
			}
		}
	}
}