using System; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.Linq; using System.Linq.Expressions; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Text.RegularExpressions; using BepInEx; using BepInEx.Configuration; using Microsoft.CodeAnalysis; using ServersideQoL.Processors; using ServersideQoL.Utilities; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("ArgusMagnus")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyCopyright("ArgusMagnus")] [assembly: AssemblyDescription("Make all container inventory sizes configurable and optionally let the grow infinitely if the contain only one item type")] [assembly: AssemblyFileVersion("2.0.1.0")] [assembly: AssemblyInformationalVersion("2.0.1+5cb319fbf5621bf6723410a84d5d65328079c58b")] [assembly: AssemblyProduct("ServersideQoL.ContainerSizes")] [assembly: AssemblyTitle("ServersideQoL.ContainerSizes")] [assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/ArgusMagnus/ValheimServersideQoL")] [assembly: AssemblyVersion("2.0.1.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class NullableAttribute : Attribute { public readonly byte[] NullableFlags; public NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] internal sealed class NullableContextAttribute : Attribute { public readonly byte Flag; public NullableContextAttribute(byte P_0) { Flag = P_0; } } [CompilerGenerated] [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 ServersideQoL.ContainerSizes { public sealed class Config : ConfigBase { private const string Section = "ContainerSizes"; public override ConfigEntry Enabled { get; } = ConfigBase.BindEx(cfg, "ContainerSizes", true, "Enables/disables the entire mod", (AcceptableValueBase)null, (Deprecated)null, "Enabled"); public IReadOnlyDictionary> ContainerSizes { get; } = (from x in ZNetScene.instance.m_prefabs where ConfigBase.PieceTablesByPieceName.ContainsKey(((Object)x).name) select (Name: ((Object)x).name, Container: x.GetComponentInChildren(), Piece: x.GetComponent()) into x where x.Container != null && x.Piece != null select x).ToDictionary(((string Name, Container Container, Piece Piece) x) => StringExtensionMethods.GetStableHashCode(x.Name), ((string Name, Container Container, Piece Piece) x) => cfg.Bind("ContainerSizes", FormattableString.Invariant($"InventorySize_{x.Name}"), FormattableString.Invariant($"{x.Container.m_width}x{x.Container.m_height}"), FormattableString.Invariant($"Inventory size for '{Localization.instance.Localize(x.Piece.m_name)}'.\r\nIf you append '+' to the end (e.g. '{x.Container.m_width}x{x.Container.m_height}+'),\r\nthe inventory size will keep expanding as long as only one type of item is stored inside."))); public Config(ConfigFile cfg, Logger logger) : base(cfg, logger) { } } [Processor("9212deb1-7a75-40e6-b74a-79843d5fe465")] [RunBefore] public sealed class ContainerProcessor : Processor { private readonly record struct ContainerSizeConfig(int Width, int Height, bool Growing); private readonly Dictionary _containerSizes = new Dictionary(); protected override void Initialize() { _containerSizes.Clear(); foreach (KeyValuePair> containerSize in ConfigBase.Instance.ContainerSizes) { containerSize.Deconstruct(out var key, out var value); int key2 = key; ConfigEntry val = value; Match match = Regex.Match(val.Value, "^(?\\d+)x(?\\d+)(?\\+)?$"); if (match == null || !match.Success) { ((Processor)this).Logger.LogWarning((object)("Invalid container size config value: " + val.Value)); } else { _containerSizes.Add(key2, new ContainerSizeConfig(int.Parse(match.Groups["w"].Value, CultureInfo.InvariantCulture), int.Parse(match.Groups["h"].Value, CultureInfo.InvariantCulture), match.Groups["g"].Success)); } } } protected override ProcessResult Process(ServersideQoLZDO zdo, IReadOnlyList peers, PrefabInfo prefabInfo) { //IL_01f8: Unknown result type (might be due to invalid IL or missing references) //IL_021f: Unknown result type (might be due to invalid IL or missing references) //IL_02d6: Unknown result type (might be due to invalid IL or missing references) //IL_02d9: Invalid comparison between Unknown and I4 //IL_0348: Unknown result type (might be due to invalid IL or missing references) //IL_034b: Invalid comparison between Unknown and I4 //IL_0389: Unknown result type (might be due to invalid IL or missing references) //IL_035d: Unknown result type (might be due to invalid IL or missing references) //IL_0362: Unknown result type (might be due to invalid IL or missing references) //IL_0368: Unknown result type (might be due to invalid IL or missing references) //IL_036e: Unknown result type (might be due to invalid IL or missing references) //IL_0370: Unknown result type (might be due to invalid IL or missing references) //IL_0382: Unknown result type (might be due to invalid IL or missing references) //IL_0387: Unknown result type (might be due to invalid IL or missing references) //IL_0188: Unknown result type (might be due to invalid IL or missing references) //IL_0197: Unknown result type (might be due to invalid IL or missing references) //IL_02d4: Unknown result type (might be due to invalid IL or missing references) ContainerState state = Processor.Instance().GetState(zdo, prefabInfo.Container); ComponentFieldAccessor val = zdo.Fields(); IInventory inventory = state.GetInventory(); int width = inventory.Inventory.GetWidth(); int height = inventory.Inventory.GetHeight(); int num2; int num; int height2; if (!_containerSizes.TryGetValue(zdo.ZDO.GetPrefab(), out var value)) { value = new ContainerSizeConfig(width, height, Growing: false); } else { int width2 = value.Width; height2 = value.Height; num = width; num2 = height; if ((width2 != num || height2 != num2) && inventory != null) { List items = inventory.Items; if (items != null && items.Count == 0) { val.Set((Func>>)(() => (Container x) => x.m_width), width = value.Width, "C:\\repos\\Valheim.ServersideQoL\\ServersideQoL.ContainerSizes\\ContainerProcessor.cs", 46); val.Set((Func>>)(() => (Container x) => x.m_height), height = value.Height, "C:\\repos\\Valheim.ServersideQoL\\ServersideQoL.ContainerSizes\\ContainerProcessor.cs", 47); return (ProcessResult)8; } } } if (!value.Growing) { int width3 = value.Width; num2 = value.Height; num = width; height2 = height; if (width3 == num && num2 == height2) { return (ProcessResult)2; } } bool flag = true; if (value.Growing) { flag = false; if (inventory.Items.Count == 1) { flag = true; } else if (inventory.Items.Count > 1) { ItemDataKey val2 = default(ItemDataKey); ((ItemDataKey)(ref val2))..ctor(inventory.Items[0]); int num3 = 1; while (!flag && num3 < inventory.Items.Count) { flag = val2 != new ItemDataKey(inventory.Items[num3]); num3++; } } if (!flag) { value = value with { Height = Math.Max(value.Height, Mathf.CeilToInt((float)inventory.Items.Count / (float)value.Width) + 1) }; } } ProcessResult val3 = (ProcessResult)0; int num4 = width; height2 = height; num = value.Width; num2 = value.Height; if (num4 != num || height2 != num2) { val3 = (ProcessResult)8; if (flag && inventory.Items.Count > value.Width * value.Height) { bool flag2 = false; int num5 = value.Height; while (!flag2 && num5 <= height) { int num6 = value.Width; while (!flag2 && num6 <= width) { if (inventory.Items.Count <= num6 * num5) { flag2 = true; value = value with { Width = num6, Height = num5 }; } num6++; } num5++; } if (flag2) { int num7 = width; num2 = height; num = value.Width; height2 = value.Height; if (num7 != num || num2 != height2) { goto IL_02d6; } } val3 = (ProcessResult)0; } goto IL_02d6; } goto IL_0348; IL_02d6: if ((int)val3 == 8) { val.Set((Func>>)(() => (Container x) => x.m_width), width = value.Width, "C:\\repos\\Valheim.ServersideQoL\\ServersideQoL.ContainerSizes\\ContainerProcessor.cs", 99); val.Set((Func>>)(() => (Container x) => x.m_height), height = value.Height, "C:\\repos\\Valheim.ServersideQoL\\ServersideQoL.ContainerSizes\\ContainerProcessor.cs", 100); } goto IL_0348; IL_0348: if ((int)val3 == 8 && !zdo.IsOwnerOrUnassigned()) { ContainerRegistryProcessor obj = Processor.Instance(); ZDOVars vars = zdo.Vars; val3 = ((Processor)this).ScheduleReprocessing(obj.RequestOwnership(zdo, ((ZDOVars)(ref vars)).GetCreator(default(PlayerID)), state, "C:\\repos\\Valheim.ServersideQoL\\ServersideQoL.ContainerSizes\\ContainerProcessor.cs", 105)); } return val3; } } [BepInPlugin("ArgusMagnus.ServersideQoL.ContainerSizes", "ServersideQoL.ContainerSizes", "2.0.1")] public sealed class ContainerSizesPlugin : ServersideQoLPluginBase { public const string Author = "ArgusMagnus"; public const string PluginName = "ServersideQoL.ContainerSizes"; public const string PluginGuid = "ArgusMagnus.ServersideQoL.ContainerSizes"; public const string PluginVersion = "2.0.1"; public const string PluginInformationalVersion = "2.0.1"; private DateTimeOffset BuildTimestamp { get; } = new DateTimeOffset(639246168460350896L, default(TimeSpan)); protected override Config CreateConfigSingleton(ConfigFile configFile, Logger logger) { return new Config(configFile, logger); } protected override void RegisterProcessors(IProcessorCollection processors) { processors.Add(); } private void Awake() { } } }