Decompiled source of ServersideQoL ContainerSizes BETA v1.99.4

ServersideQoL.ContainerSizes.dll

Decompiled 2 days ago
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 UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("ArgusMagnus")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyCopyright("ArgusMagnus")]
[assembly: AssemblyDescription("Make all container inventory sizes configurable")]
[assembly: AssemblyFileVersion("1.99.4.0")]
[assembly: AssemblyInformationalVersion("1.99.4-beta+80c81ad250a0109e44b175db632e72dae9da8db5")]
[assembly: AssemblyProduct("ServersideQoL.ContainerSizes")]
[assembly: AssemblyTitle("ServersideQoL.ContainerSizes")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/ArgusMagnus/ValheimServersideQoL")]
[assembly: AssemblyVersion("1.99.4.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<Config>
	{
		private const string Section = "ContainerSizes";

		public override ConfigEntry<bool> Enabled { get; } = ConfigBase<Config>.BindEx<bool>(cfg, "ContainerSizes", true, "Enables/disables the entire mod", (AcceptableValueBase)null, (Deprecated<Config>)null, "Enabled");

		public IReadOnlyDictionary<int, ConfigEntry<string>> ContainerSizes { get; } = (from x in ZNetScene.instance.m_prefabs
			where ConfigBase.PieceTablesByPieceName.ContainsKey(((Object)x).name)
			select (Name: ((Object)x).name, Container: x.GetComponentInChildren<Container>(), Piece: x.GetComponent<Piece>()) into x
			where x.Container != null && x.Piece != null
			select x).ToDictionary(((string Name, Container Container, Piece Piece) x) => StringExtensionMethods.GetStableHashCode(x.Name, true), ((string Name, Container Container, Piece Piece) x) => cfg.Bind<string>("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<ContainerRegistryProcessor>]
	public sealed class ContainerProcessor : Processor<PrefabInfo>
	{
		private readonly record struct ContainerSizeConfig(int Width, int Height, bool Growing);

		private readonly Dictionary<int, ContainerSizeConfig> _containerSizes = new Dictionary<int, ContainerSizeConfig>();

		protected override void Initialize()
		{
			_containerSizes.Clear();
			foreach (KeyValuePair<int, ConfigEntry<string>> containerSize in ConfigBase<Config>.Instance.ContainerSizes)
			{
				containerSize.Deconstruct(out var key, out var value);
				int key2 = key;
				ConfigEntry<string> val = value;
				Match match = Regex.Match(val.Value, "^(?<w>\\d+)x(?<h>\\d+)(?<g>\\+)?$");
				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<Peer> peers, PrefabInfo prefabInfo)
		{
			//IL_0167: 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_0413: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c8: Invalid comparison between Unknown and I4
			//IL_0253: Unknown result type (might be due to invalid IL or missing references)
			//IL_019d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_040d: Unknown result type (might be due to invalid IL or missing references)
			//IL_040f: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_040a: Unknown result type (might be due to invalid IL or missing references)
			//IL_034a: Unknown result type (might be due to invalid IL or missing references)
			//IL_034d: Invalid comparison between Unknown and I4
			//IL_0347: Unknown result type (might be due to invalid IL or missing references)
			ContainerState state = Processor.Instance<ContainerRegistryProcessor>().GetState(zdo, prefabInfo);
			ComponentFieldAccessor<Container> val = zdo.Fields<Container>();
			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<ItemData> items = inventory.Items;
					if (items != null && items.Count == 0)
					{
						val.Set((Func<Expression<Func<Container, int>>>)(() => (Container x) => x.m_width), width = value.Width, "C:\\repos\\Valheim.ServersideQoL\\ServersideQoL.ContainerSizes\\ContainerProcessor.cs", 44);
						val.Set((Func<Expression<Func<Container, int>>>)(() => (Container x) => x.m_height), height = value.Height, "C:\\repos\\Valheim.ServersideQoL\\ServersideQoL.ContainerSizes\\ContainerProcessor.cs", 45);
						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;
				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_034a;
						}
					}
					val3 = (ProcessResult)0;
				}
				goto IL_034a;
			}
			goto IL_03c5;
			IL_03c5:
			if ((int)val3 == 8 && !zdo.IsOwnerOrUnassigned())
			{
				ContainerRegistryProcessor obj = Processor.Instance<ContainerRegistryProcessor>();
				ZDOVars vars = zdo.Vars;
				zdo.DelaySchedulingFor(obj.RequestOwnership(zdo, ((ZDOVars)(ref vars)).GetCreator(0L), state, "C:\\repos\\Valheim.ServersideQoL\\ServersideQoL.ContainerSizes\\ContainerProcessor.cs", 99));
				val3 = (ProcessResult)32;
			}
			return val3;
			IL_034a:
			if ((int)val3 == 8)
			{
				val.Set((Func<Expression<Func<Container, int>>>)(() => (Container x) => x.m_width), width = value.Width, "C:\\repos\\Valheim.ServersideQoL\\ServersideQoL.ContainerSizes\\ContainerProcessor.cs", 92);
				val.Set((Func<Expression<Func<Container, int>>>)(() => (Container x) => x.m_height), height = value.Height, "C:\\repos\\Valheim.ServersideQoL\\ServersideQoL.ContainerSizes\\ContainerProcessor.cs", 93);
			}
			goto IL_03c5;
		}
	}
	[BepInPlugin("ArgusMagnus.ServersideQoL.ContainerSizes", "ServersideQoL.ContainerSizes", "1.99.4")]
	public sealed class ContainerSizesPlugin : ServersideQoLPluginBase<ContainerSizesPlugin, Config>
	{
		public const string Author = "ArgusMagnus";

		public const string PluginName = "ServersideQoL.ContainerSizes";

		public const string PluginGuid = "ArgusMagnus.ServersideQoL.ContainerSizes";

		public const string PluginVersion = "1.99.4";

		public const string PluginInformationalVersion = "1.99.4-beta";

		internal const string DependencyDirectory = "C:\\repos\\Valheim.ServersideQoL\\Dependencies\\";

		private DateTimeOffset BuildTimestamp { get; } = new DateTimeOffset(639209323755552856L, default(TimeSpan));

		protected override Config CreateConfigSingleton(ConfigFile configFile, Logger logger)
		{
			return new Config(configFile, logger);
		}

		protected override void RegisterProcessors(IProcessorCollection processors)
		{
			processors.Add<ContainerProcessor>();
		}

		private void Awake()
		{
			bool flag = true;
			ServersideQoLPluginBase<ContainerSizesPlugin, Config>.Logger.LogWarning((object)string.Format("You are running a pre-release version: {0} ({1})", "1.99.4-beta", BuildTimestamp.LocalDateTime));
		}
	}
}