Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of ChestSizeConfig v1.0.0
plugins/ChestSizeConfig/ChestSizeConfig.dll
Decompiled 12 hours agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using HarmonyLib; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")] [assembly: AssemblyCompany("ChestSizeConfig")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("ChestSizeConfig")] [assembly: AssemblyTitle("ChestSizeConfig")] [assembly: AssemblyVersion("1.0.0.0")] namespace ChestSizeConfig; [BepInPlugin("com.triston.chestsizeconfig", "Chest Size Config", "1.0.0")] public sealed class ChestSizeConfigPlugin : BaseUnityPlugin { public const string PluginGuid = "com.triston.chestsizeconfig"; public const string PluginName = "Chest Size Config"; public const string PluginVersion = "1.0.0"; internal static ChestSizeConfigPlugin Instance; internal static ConfigEntry<bool> Enabled; internal static ConfigEntry<bool> LogAppliedSizes; internal static ConfigEntry<string> WoodChest; internal static ConfigEntry<string> ReinforcedChest; internal static ConfigEntry<string> BlackMetalChest; internal static ConfigEntry<string> PersonalChest; internal static ConfigEntry<string> GraustenChest; internal static ConfigEntry<string> Wardrobe; internal static ConfigEntry<string> Barrel; internal static ConfigEntry<string> Cart; internal static ConfigEntry<string> Karve; internal static ConfigEntry<string> Longship; internal static ConfigEntry<string> Drakkar; internal static ConfigEntry<string> CustomContainers; private Harmony _harmony; private readonly HashSet<string> _reportedInvalidValues = new HashSet<string>(StringComparer.OrdinalIgnoreCase); private void Awake() { //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Expected O, but got Unknown Instance = this; BindConfiguration(); _harmony = new Harmony("com.triston.chestsizeconfig"); _harmony.PatchAll(Assembly.GetExecutingAssembly()); ((BaseUnityPlugin)this).Logger.LogInfo((object)"Chest Size Config 1.0.0 loaded. Default buildable chest capacity is 2x."); } private void OnDestroy() { if (_harmony != null) { _harmony.UnpatchSelf(); } if ((Object)(object)Instance == (Object)(object)this) { Instance = null; } } private void BindConfiguration() { Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("1 - General", "Enabled", true, "Master switch for all container resizing."); LogAppliedSizes = ((BaseUnityPlugin)this).Config.Bind<bool>("1 - General", "Log applied sizes", false, "Writes each resized container to the BepInEx log for troubleshooting."); WoodChest = ((BaseUnityPlugin)this).Config.Bind<string>("2 - Buildable Chests", "Wood chest", "double", "Use 'double' for twice the vanilla capacity (adds rows), 'vanilla' to leave it unchanged, or WIDTHxROWS such as 8x6. Restart the game after changing this value."); ReinforcedChest = ((BaseUnityPlugin)this).Config.Bind<string>("2 - Buildable Chests", "Reinforced chest", "double", "Use 'double' for twice the vanilla capacity (adds rows), 'vanilla' to leave it unchanged, or WIDTHxROWS such as 8x6. Restart the game after changing this value."); BlackMetalChest = ((BaseUnityPlugin)this).Config.Bind<string>("2 - Buildable Chests", "Black metal chest", "double", "Use 'double' for twice the vanilla capacity (adds rows), 'vanilla' to leave it unchanged, or WIDTHxROWS such as 8x6. Restart the game after changing this value."); PersonalChest = ((BaseUnityPlugin)this).Config.Bind<string>("2 - Buildable Chests", "Personal chest", "double", "Use 'double' for twice the vanilla capacity (adds rows), 'vanilla' to leave it unchanged, or WIDTHxROWS such as 8x6. Restart the game after changing this value."); GraustenChest = ((BaseUnityPlugin)this).Config.Bind<string>("2 - Buildable Chests", "Grausten chest", "double", "Use 'double' for twice the vanilla capacity (adds rows), 'vanilla' to leave it unchanged, or WIDTHxROWS such as 8x6. Restart the game after changing this value."); Wardrobe = ((BaseUnityPlugin)this).Config.Bind<string>("2 - Buildable Chests", "Wardrobe", "double", "Use 'double' for twice the vanilla capacity (adds rows), 'vanilla' to leave it unchanged, or WIDTHxROWS such as 8x6. Restart the game after changing this value."); Barrel = ((BaseUnityPlugin)this).Config.Bind<string>("2 - Buildable Chests", "Barrel", "double", "Use 'double' for twice the vanilla capacity (adds rows), 'vanilla' to leave it unchanged, or WIDTHxROWS such as 8x6. Restart the game after changing this value."); Cart = ((BaseUnityPlugin)this).Config.Bind<string>("3 - Transport Storage", "Cart", "vanilla", "Use 'double' for twice the vanilla capacity (adds rows), 'vanilla' to leave it unchanged, or WIDTHxROWS such as 8x6. Restart the game after changing this value."); Karve = ((BaseUnityPlugin)this).Config.Bind<string>("3 - Transport Storage", "Karve", "vanilla", "Use 'double' for twice the vanilla capacity (adds rows), 'vanilla' to leave it unchanged, or WIDTHxROWS such as 8x6. Restart the game after changing this value."); Longship = ((BaseUnityPlugin)this).Config.Bind<string>("3 - Transport Storage", "Longship", "vanilla", "Use 'double' for twice the vanilla capacity (adds rows), 'vanilla' to leave it unchanged, or WIDTHxROWS such as 8x6. Restart the game after changing this value."); Drakkar = ((BaseUnityPlugin)this).Config.Bind<string>("3 - Transport Storage", "Drakkar", "vanilla", "Use 'double' for twice the vanilla capacity (adds rows), 'vanilla' to leave it unchanged, or WIDTHxROWS such as 8x6. Restart the game after changing this value."); CustomContainers = ((BaseUnityPlugin)this).Config.Bind<string>("4 - Custom Containers", "Prefab sizes", string.Empty, "Optional semicolon-separated prefab rules for modded containers. Example: MyChest=8x6;OtherChest=double. Matching ignores case and '(Clone)'. Restart after editing."); } internal void ApplyConfiguredSize(Container container) { if (!Enabled.Value || (Object)(object)container == (Object)null) { return; } string text = NormalizeName(((Object)((Component)container).gameObject).name); if (!TryGetTransportRule(container, out var settingName, out var value) && !TryGetBuildableRule(text, out settingName, out value) && !TryGetCustomRule(text, out settingName, out value)) { return; } int width = container.m_width; int height = container.m_height; if (!TryResolveSize(value, width, height, out var width2, out var height2)) { ReportInvalid(settingName, value); return; } container.m_width = width2; container.m_height = height2; if (LogAppliedSizes.Value && (width != width2 || height != height2)) { ((BaseUnityPlugin)this).Logger.LogInfo((object)(settingName + " [" + text + "]: " + width + "x" + height + " -> " + width2 + "x" + height2)); } } private static bool TryGetBuildableRule(string name, out string settingName, out string value) { if (name.StartsWith("piece_chest_blackmetal", StringComparison.OrdinalIgnoreCase)) { return Rule("Black metal chest", BlackMetalChest, out settingName, out value); } if (name.StartsWith("piece_chest_private", StringComparison.OrdinalIgnoreCase)) { return Rule("Personal chest", PersonalChest, out settingName, out value); } if (name.StartsWith("piece_chest_grausten", StringComparison.OrdinalIgnoreCase)) { return Rule("Grausten chest", GraustenChest, out settingName, out value); } if (name.StartsWith("piece_chest_warderobe", StringComparison.OrdinalIgnoreCase) || name.StartsWith("piece_chest_wardrobe", StringComparison.OrdinalIgnoreCase)) { return Rule("Wardrobe", Wardrobe, out settingName, out value); } if (name.StartsWith("piece_chest_barrel", StringComparison.OrdinalIgnoreCase)) { return Rule("Barrel", Barrel, out settingName, out value); } if (name.StartsWith("piece_chest_wood", StringComparison.OrdinalIgnoreCase)) { return Rule("Wood chest", WoodChest, out settingName, out value); } if (name.Equals("piece_chest", StringComparison.OrdinalIgnoreCase)) { return Rule("Reinforced chest", ReinforcedChest, out settingName, out value); } settingName = null; value = null; return false; } private static bool TryGetTransportRule(Container container, out string settingName, out string value) { if ((Object)(object)container.m_wagon != (Object)null) { return Rule("Cart", Cart, out settingName, out value); } Ship componentInParent = ((Component)container).GetComponentInParent<Ship>(); if ((Object)(object)componentInParent == (Object)null) { settingName = null; value = null; return false; } string text = NormalizeName(((Object)((Component)componentInParent).gameObject).name); if (text.IndexOf("karve", StringComparison.OrdinalIgnoreCase) >= 0) { return Rule("Karve", Karve, out settingName, out value); } if (text.IndexOf("ashland", StringComparison.OrdinalIgnoreCase) >= 0 || text.IndexOf("drakkar", StringComparison.OrdinalIgnoreCase) >= 0) { return Rule("Drakkar", Drakkar, out settingName, out value); } if (text.IndexOf("vikingship", StringComparison.OrdinalIgnoreCase) >= 0 || text.IndexOf("longship", StringComparison.OrdinalIgnoreCase) >= 0) { return Rule("Longship", Longship, out settingName, out value); } settingName = null; value = null; return false; } private static bool TryGetCustomRule(string containerName, out string settingName, out string value) { string value2 = CustomContainers.Value; if (!string.IsNullOrWhiteSpace(value2)) { string[] array = value2.Split(new char[1] { ';' }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < array.Length; i++) { string[] array2 = array[i].Split(new char[1] { '=' }, 2); if (array2.Length == 2) { string text = NormalizeName(array2[0]); if (containerName.Equals(text, StringComparison.OrdinalIgnoreCase)) { settingName = "Custom container " + text; value = array2[1].Trim(); return true; } } } } settingName = null; value = null; return false; } private static bool Rule(string name, ConfigEntry<string> entry, out string settingName, out string value) { settingName = name; value = entry.Value; return true; } private static bool TryResolveSize(string rawValue, int vanillaWidth, int vanillaHeight, out int width, out int height) { width = vanillaWidth; height = vanillaHeight; string text = (rawValue ?? string.Empty).Trim(); if (text.Equals("vanilla", StringComparison.OrdinalIgnoreCase) || text.Equals("unchanged", StringComparison.OrdinalIgnoreCase) || text.Equals("off", StringComparison.OrdinalIgnoreCase)) { return true; } if (text.Equals("double", StringComparison.OrdinalIgnoreCase) || text.Equals("2x", StringComparison.OrdinalIgnoreCase)) { height = Mathf.Clamp(vanillaHeight * 2, 1, 30); return true; } string[] array = text.ToLowerInvariant().Split(new char[1] { 'x' }); if (array.Length == 2 && int.TryParse(array[0].Trim(), out var result) && int.TryParse(array[1].Trim(), out var result2) && result >= 1 && result <= 16 && result2 >= 1 && result2 <= 30) { width = result; height = result2; return true; } return false; } private void ReportInvalid(string settingName, string value) { string item = settingName + "=" + value; if (_reportedInvalidValues.Add(item)) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("Ignored invalid size for " + settingName + ": '" + value + "'. Use double, vanilla, or WIDTHxROWS such as 8x6.")); } } internal static string NormalizeName(string name) { if (string.IsNullOrEmpty(name)) { return string.Empty; } string text = name.Trim(); if (text.EndsWith("(Clone)", StringComparison.OrdinalIgnoreCase)) { text = text.Substring(0, text.Length - "(Clone)".Length).Trim(); } return text; } } [HarmonyPatch(typeof(Container), "Awake")] internal static class ContainerAwakePatch { private static void Prefix(Container __instance) { if ((Object)(object)ChestSizeConfigPlugin.Instance != (Object)null) { ChestSizeConfigPlugin.Instance.ApplyConfiguredSize(__instance); } } } [HarmonyPatch(typeof(Container), "Load")] internal static class ContainerLoadSafetyPatch { private static readonly FieldInfo InventoryWidthField = AccessTools.Field(typeof(Inventory), "m_width"); private static void Postfix(Container __instance) { Inventory val = (((Object)(object)__instance == (Object)null) ? null : __instance.GetInventory()); if (val != null) { int num = val.GetWidth(); int num2 = val.GetHeight(); List<ItemData> allItems = val.GetAllItems(); for (int i = 0; i < allItems.Count; i++) { ItemData val2 = allItems[i]; num = Math.Max(num, val2.m_gridPos.x + 1); num2 = Math.Max(num2, val2.m_gridPos.y + 1); } if (num > val.GetWidth() && InventoryWidthField != null) { InventoryWidthField.SetValue(val, num); } if (num2 > val.GetHeight()) { val.SetHeight(num2); } } } }