Decompiled source of StackLimitsFixesAndCustomization v1.0.0

plugins/StackLimits/StackLimits.dll

Decompiled 2 months ago
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using EquinoxsModUtils;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("StackLimits")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("StackLimits")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("e1eed1dd-765c-465b-956d-6bb006ca326f")]
[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 StackLimits;

[BepInPlugin("StacklimitFixesCustomization", "Stack Limit Fixes and Customization", "1.0.0")]
public class StackLimits : BaseUnityPlugin
{
	private const string PluginName = "Stack Limit Fixes and Customization";

	private const string pluginGuid = "StacklimitFixesCustomization";

	private static ConfigEntry<bool> _loggingEnabled;

	private static ConfigEntry<string> _changedItemsConfigs;

	private static List<string> changedItemsList = new List<string>();

	private const string VersionString = "1.0.0";

	private void Awake()
	{
		_loggingEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Logging", "Logging Enabled", false, "Enable logging.");
		_changedItemsConfigs = ((BaseUnityPlugin)this).Config.Bind<string>("StackSizes", "ItemsToBeChanged", "Spectral Cube (Colorless) X100,Carbon Powder,Scrap Ore", "List of items for which an config entry will be created. Comma seperated list. Possible value: " + string.Join(",", Resources.SafeResources));
		changedItemsList = _changedItemsConfigs.Value.Split(new char[1] { ',' }).ToList().ConvertAll((string x) => x.Trim(new char[1] { ' ' }));
		Events.GameDefinesLoaded += OnGameDefinesLoaded;
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Stack Limit Fixes and Customization Version 1.0.0 has loaded.");
	}

	private void OnGameDefinesLoaded()
	{
		if (changedItemsList.Contains("Spectral Cube (Colorless) X100"))
		{
			Resources.GetResourceInfoByName("Spectral Cube (Colorless) X100", false).maxStackCount = 500;
		}
		if (changedItemsList.Contains("Carbon Powder"))
		{
			Resources.GetResourceInfoByName("Carbon Powder", false).maxStackCount = 1000;
		}
		if (changedItemsList.Contains("Scrap Ore"))
		{
			Resources.GetResourceInfoByName("Scrap Ore", false).maxStackCount = 500;
		}
		foreach (string changedItems in changedItemsList)
		{
			ResourceInfo resourceInfoByName = Resources.GetResourceInfoByName(changedItems, false);
			if ((Object)(object)resourceInfoByName != (Object)null)
			{
				ConfigEntry<int> val = ((BaseUnityPlugin)this).Config.Bind<int>("StackSizes", changedItems, resourceInfoByName.maxStackCount, "Max stack size in inventory, chests and machines for this item");
				resourceInfoByName.maxStackCount = val.Value;
				if (_loggingEnabled.Value)
				{
					((BaseUnityPlugin)this).Logger.LogInfo((object)$"Setting stack size of {resourceInfoByName} to {resourceInfoByName.maxStackCount}.");
				}
			}
			else
			{
				((BaseUnityPlugin)this).Logger.LogError((object)(changedItems + "is not a valid item identifier."));
			}
		}
	}
}