Decompiled source of CustomContainerSizesForkOfAedenthorn v0.1.0

CustomContainerSizes.dll

Decompiled 5 hours ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using TMPro;
using UnityEngine;

[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.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+dbf6b255fa95639255e752ae11063f3acb851646")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace CustomContainerSizes;

[BepInPlugin("aedenthorn.CustomContainerSizes", "Custom Container Sizes", "0.7.0")]
public class BepInExPlugin : BaseUnityPlugin
{
	[HarmonyPatch(typeof(Container), "Awake")]
	private static class Container_Awake_Patch
	{
		private static void Postfix(Container __instance, Inventory ___m_inventory)
		{
			if (___m_inventory == null)
			{
				return;
			}
			Transform parent = ((Component)__instance).gameObject.transform.parent;
			Ship val = ((parent != null) ? ((Component)parent).GetComponent<Ship>() : null);
			if ((Object)(object)val != (Object)null)
			{
				Dbgl("container is on a ship: " + ((Object)val).name);
				if (((Object)val).name.ToLower().Contains("karve"))
				{
					Dbgl($"setting Karve chest size to {karveChestWidth.Value},{karveChestHeight.Value}");
					typeof(Inventory).GetField("m_width", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(___m_inventory, karveChestWidth.Value);
					typeof(Inventory).GetField("m_height", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(___m_inventory, karveChestHeight.Value);
				}
				else if (((Object)val).name.ToLower().Contains("ashland"))
				{
					Dbgl($"setting Drakkar chest size to {drakkarShipChestWidth.Value},{drakkarShipChestHeight.Value}");
					typeof(Inventory).GetField("m_width", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(___m_inventory, drakkarShipChestWidth.Value);
					typeof(Inventory).GetField("m_height", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(___m_inventory, drakkarShipChestHeight.Value);
				}
				else if (((Object)val).name.ToLower().Contains("vikingship"))
				{
					Dbgl($"setting VikingShip chest size to {vikingShipChestWidth.Value},{vikingShipChestHeight.Value}");
					typeof(Inventory).GetField("m_width", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(___m_inventory, vikingShipChestWidth.Value);
					typeof(Inventory).GetField("m_height", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(___m_inventory, vikingShipChestHeight.Value);
				}
			}
			else if (Object.op_Implicit((Object)(object)__instance.m_wagon))
			{
				Dbgl($"setting wagon size to {wagonWidth.Value},{wagonHeight.Value}");
				typeof(Inventory).GetField("m_width", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(___m_inventory, wagonWidth.Value);
				typeof(Inventory).GetField("m_height", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(___m_inventory, wagonHeight.Value);
			}
			else if (((Object)__instance).name.StartsWith("piece_chest_wood("))
			{
				Dbgl($"setting chest size to {chestWidth.Value},{chestHeight.Value}");
				typeof(Inventory).GetField("m_width", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(___m_inventory, chestWidth.Value);
				typeof(Inventory).GetField("m_height", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(___m_inventory, chestHeight.Value);
			}
			else if (((Object)__instance).name.StartsWith("piece_chest_private("))
			{
				Dbgl($"setting private chest size to {privateChestWidth.Value},{privateChestHeight.Value}");
				typeof(Inventory).GetField("m_width", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(___m_inventory, privateChestWidth.Value);
				typeof(Inventory).GetField("m_height", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(___m_inventory, privateChestHeight.Value);
			}
			else if (((Object)__instance).name.StartsWith("piece_chest_blackmetal("))
			{
				Dbgl($"setting black metal chest size to {blackMetalChestWidth.Value},{blackMetalChestHeight.Value}");
				typeof(Inventory).GetField("m_width", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(___m_inventory, blackMetalChestWidth.Value);
				typeof(Inventory).GetField("m_height", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(___m_inventory, blackMetalChestHeight.Value);
			}
			else if (((Object)__instance).name.StartsWith("piece_chest("))
			{
				Dbgl($"setting reinforced chest size to {reinforcedChestWidth.Value},{reinforcedChestHeight.Value}");
				typeof(Inventory).GetField("m_width", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(___m_inventory, reinforcedChestWidth.Value);
				typeof(Inventory).GetField("m_height", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(___m_inventory, reinforcedChestHeight.Value);
			}
		}
	}

	[HarmonyPatch(typeof(Terminal), "InputText")]
	private static class InputText_Patch
	{
		private static bool Prefix(Terminal __instance)
		{
			if (!modEnabled.Value)
			{
				return true;
			}
			string text = ((TMP_InputField)__instance.m_input).text;
			if (text.ToLower().Equals(typeof(BepInExPlugin).Namespace.ToLower() + " reset"))
			{
				((BaseUnityPlugin)context).Config.Reload();
				((BaseUnityPlugin)context).Config.Save();
				Traverse.Create((object)__instance).Method("AddString", new object[1] { text }).GetValue();
				Traverse.Create((object)__instance).Method("AddString", new object[1] { ((BaseUnityPlugin)context).Info.Metadata.Name + " config reloaded" }).GetValue();
				return false;
			}
			return true;
		}
	}

	private static readonly bool isDebug = true;

	private static BepInExPlugin context;

	private static ConfigEntry<bool> modEnabled;

	private static ConfigEntry<int> chestWidth;

	private static ConfigEntry<int> chestHeight;

	private static ConfigEntry<int> vikingShipChestWidth;

	private static ConfigEntry<int> vikingShipChestHeight;

	private static ConfigEntry<int> drakkarShipChestWidth;

	private static ConfigEntry<int> drakkarShipChestHeight;

	private static ConfigEntry<int> privateChestWidth;

	private static ConfigEntry<int> privateChestHeight;

	private static ConfigEntry<int> reinforcedChestWidth;

	private static ConfigEntry<int> reinforcedChestHeight;

	private static ConfigEntry<int> blackMetalChestWidth;

	private static ConfigEntry<int> blackMetalChestHeight;

	private static ConfigEntry<int> karveChestWidth;

	private static ConfigEntry<int> karveChestHeight;

	private static ConfigEntry<int> wagonWidth;

	private static ConfigEntry<int> wagonHeight;

	private static ConfigEntry<int> nexusID;

	public static void Dbgl(string str = "", bool pref = true)
	{
		if (isDebug)
		{
			Debug.Log((object)((pref ? (typeof(BepInExPlugin).Namespace + " ") : "") + str));
		}
	}

	private void Awake()
	{
		context = this;
		modEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Enable this mod");
		chestWidth = ((BaseUnityPlugin)this).Config.Bind<int>("Sizes", "ChestWidth", 5, "Number of items wide for chest containers");
		chestHeight = ((BaseUnityPlugin)this).Config.Bind<int>("Sizes", "ChestHeight", 2, "Number of items tall for chest containers");
		karveChestWidth = ((BaseUnityPlugin)this).Config.Bind<int>("Sizes", "KarveChestWidth", 2, "Number of items wide for Karve chest containers (max. 8)");
		karveChestHeight = ((BaseUnityPlugin)this).Config.Bind<int>("Sizes", "KarveChestHeight", 2, "Number of items tall for karve chest containers");
		vikingShipChestWidth = ((BaseUnityPlugin)this).Config.Bind<int>("Sizes", "VikingShipChestWidth", 6, "Number of items wide for longship chest containers (max. 8)");
		vikingShipChestHeight = ((BaseUnityPlugin)this).Config.Bind<int>("Sizes", "VikingShipChestHeight", 3, "Number of items tall for longship chest containers");
		drakkarShipChestWidth = ((BaseUnityPlugin)this).Config.Bind<int>("Sizes", "DrakkarShipChestWidth", 8, "Number of items wide for Drakkar chest containers (max. 8)");
		drakkarShipChestHeight = ((BaseUnityPlugin)this).Config.Bind<int>("Sizes", "DrakkarShipChestHeight", 4, "Number of items tall for Drakkar chest containers");
		privateChestWidth = ((BaseUnityPlugin)this).Config.Bind<int>("Sizes", "PrivateChestWidth", 3, "Number of items wide for private chest containers (max. 8)");
		privateChestHeight = ((BaseUnityPlugin)this).Config.Bind<int>("Sizes", "PrivateChestHeight", 2, "Number of items tall for private chest containers");
		reinforcedChestWidth = ((BaseUnityPlugin)this).Config.Bind<int>("Sizes", "ReinforcedChestWidth", 6, "Number of items wide for reinforced chest containers (max. 8)");
		reinforcedChestHeight = ((BaseUnityPlugin)this).Config.Bind<int>("Sizes", "ReinforcedChestHeight", 4, "Number of items tall for reinforced chest containers");
		blackMetalChestWidth = ((BaseUnityPlugin)this).Config.Bind<int>("Sizes", "BlackMetalChestWidth", 8, "Number of items wide for black metal chest containers (max. 8)");
		blackMetalChestHeight = ((BaseUnityPlugin)this).Config.Bind<int>("Sizes", "BlackMetalChestHeight", 4, "Number of items tall for black metal chest containers");
		wagonWidth = ((BaseUnityPlugin)this).Config.Bind<int>("Sizes", "WagonWidth", 6, "Number of items wide for chest containers (max. 8)");
		wagonHeight = ((BaseUnityPlugin)this).Config.Bind<int>("Sizes", "WagonHeight", 3, "Number of items tall for chest containers");
		nexusID = ((BaseUnityPlugin)this).Config.Bind<int>("General", "NexusID", 111, "Mod ID on the Nexus for update checks");
		nexusID.Value = 111;
		chestWidth.Value = Math.Min(chestWidth.Value, 8);
		karveChestWidth.Value = Math.Min(karveChestWidth.Value, 8);
		vikingShipChestWidth.Value = Math.Min(vikingShipChestWidth.Value, 8);
		drakkarShipChestWidth.Value = Math.Min(drakkarShipChestWidth.Value, 8);
		privateChestWidth.Value = Math.Min(privateChestWidth.Value, 8);
		reinforcedChestWidth.Value = Math.Min(reinforcedChestWidth.Value, 8);
		wagonWidth.Value = Math.Min(wagonWidth.Value, 8);
		((BaseUnityPlugin)this).Config.Save();
		if (modEnabled.Value)
		{
			Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), (string)null);
		}
	}
}