Decompiled source of ServersideQoL Recycler v2.6.1

ServersideQoL.Recycler.dll

Decompiled 3 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using Microsoft.CodeAnalysis;
using ServersideQoL.Processors;
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("Turns obliterators into recyclers which return a (configurable) percentage of the original crafting ingredients")]
[assembly: AssemblyFileVersion("2.6.1.0")]
[assembly: AssemblyInformationalVersion("2.6.1+d8963bf9a56c0f89681db42b6be4140385232584")]
[assembly: AssemblyProduct("ServersideQoL.Recycler")]
[assembly: AssemblyTitle("ServersideQoL.Recycler")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/ArgusMagnus/ValheimServersideQoL")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("2.6.1.0")]
[module: UnverifiableCode]
[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.Recycler
{
	public sealed class Config : ConfigBase<Config>
	{
		public override ConfigEntry<bool> Enabled { get; } = ConfigBase<Config>.BindEx<bool>(cfg, true, "Enables/disables the entire mod", (IAcceptableValueBase<bool>)null, (Deprecated<Config>)null, "Enabled");

		public ConfigEntry<int> ReturnPercentage { get; } = ConfigBase<Config>.BindEx<int>(cfg, 50, "", (IAcceptableValueBase<int>)(object)new AcceptableValueRange<int>(1, 100), (Deprecated<Config>)null, "ReturnPercentage");

		public Config(ConfigFile cfg, Logger logger)
			: base(cfg, logger)
		{
		}
	}
	[Processor("1076579e-2a9c-45db-a85c-949f89ea266c")]
	[RunBefore<IncineratorRegistryProcessor>]
	public sealed class IncineratorProcessor : Processor<PrefabInfo>
	{
		public const string Id = "1076579e-2a9c-45db-a85c-949f89ea266c";

		private readonly Dictionary<ItemDrop, ItemData> _ingredients = new Dictionary<ItemDrop, ItemData>();

		protected override ProcessResult Process(ServersideQoLZDO zdo, IReadOnlyList<Peer> peers, PrefabInfo prefabInfo)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			_ingredients.Clear();
			ItemEnumerable availableItems = Processor.Instance<IncineratorRegistryProcessor>().GetAvailableItems(zdo);
			ItemEnumerator enumerator = ((ItemEnumerable)(ref availableItems)).GetEnumerator();
			try
			{
				while (((ItemEnumerator)(ref enumerator)).MoveNext())
				{
					ItemData current = ((ItemEnumerator)(ref enumerator)).Current;
					if (AddIngredients(_ingredients, current))
					{
						Processor.Instance<IncineratorRegistryProcessor>().ReserveItem(current);
					}
				}
			}
			finally
			{
				((ItemEnumerator)(ref enumerator)).Dispose();
			}
			if (_ingredients.Count != 0)
			{
				float num = (float)ConfigBase<Config>.Instance.ReturnPercentage.Value * 0.01f;
				foreach (ItemData value3 in _ingredients.Values)
				{
					float num2 = (float)value3.m_stack * num;
					value3.m_stack = (int)num2;
					if (num2 > (float)value3.m_stack && Random.value <= num2 - (float)value3.m_stack)
					{
						value3.m_stack++;
					}
					Processor.Instance<IncineratorRegistryProcessor>().AddConversionResult(value3, false);
				}
				return (ProcessResult)0;
			}
			return (ProcessResult)0;
			static bool AddIngredients(Dictionary<ItemDrop, ItemData> ingredients, ItemData item, bool dismantleNonCraftable = true)
			{
				//IL_000b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0010: Unknown result type (might be due to invalid IL or missing references)
				//IL_0013: Unknown result type (might be due to invalid IL or missing references)
				//IL_0018: Unknown result type (might be due to invalid IL or missing references)
				IReadOnlyList<ItemData> ingredients2 = Extensions.GetIngredients(item);
				if (ingredients2 != null)
				{
					Enumerator<ItemData> enumerator3 = ListExtensions.Enumerate<ItemData>(ingredients2).GetEnumerator();
					try
					{
						while (enumerator3.MoveNext())
						{
							ItemData current3 = enumerator3.Current;
							if (!AddIngredients(ingredients, current3, dismantleNonCraftable: false))
							{
								ItemDrop component = current3.m_dropPrefab.GetComponent<ItemDrop>();
								if (ingredients.TryGetValue(component, out ItemData value))
								{
									ItemData obj = value;
									obj.m_stack += current3.m_stack;
								}
								else
								{
									ingredients.Add(component, current3);
								}
							}
						}
					}
					finally
					{
						((IDisposable)enumerator3/*cast due to .constrained prefix*/).Dispose();
					}
					return true;
				}
				Recipe recipe = ObjectDB.instance.GetRecipe(item);
				if (recipe == null || recipe.m_requireOnlyOneIngredient)
				{
					return false;
				}
				if (!dismantleNonCraftable && !recipe.m_enabled)
				{
					return false;
				}
				bool result = false;
				float num3 = (float)item.m_stack / (float)recipe.m_amount;
				for (int i = 1; i <= item.m_quality; i++)
				{
					for (int j = 0; j < recipe.m_resources.Length; j++)
					{
						Requirement val = recipe.m_resources[j];
						if (val != null && val.m_resItem != null && val.m_upgraderResource == i > item.m_shared.m_maxQuality)
						{
							if (!ingredients.TryGetValue(val.m_resItem, out ItemData value2))
							{
								ingredients.Add(val.m_resItem, value2 = val.m_resItem.m_itemData.Clone());
								value2.m_dropPrefab = ((Component)val.m_resItem).gameObject;
								value2.m_stack = 0;
							}
							ItemData obj2 = value2;
							obj2.m_stack += Mathf.FloorToInt((float)val.GetAmount(i) * num3);
							result = true;
						}
					}
				}
				return result;
			}
		}
	}
	[BepInPlugin("ArgusMagnus.ServersideQoL.Recycler", "ServersideQoL.Recycler", "2.6.1")]
	public sealed class RecyclerPlugin : ServersideQoLPluginBase<RecyclerPlugin, Config>
	{
		public const string Author = "ArgusMagnus";

		public const string PluginName = "ServersideQoL.Recycler";

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

		public const string PluginVersion = "2.6.1";

		public const string PluginInformationalVersion = "2.6.1";

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

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

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

		private void Awake()
		{
		}
	}
}