Decompiled source of SmartCraftStorage for SeneaL UI v1.0.0

SmartCraftStorageForSeneaLUI.dll

Decompiled 2 days ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using SeneaLUI.Core;
using SmartCraftStorage.Config;
using SmartCraftStorage.CraftingChestAccess;
using SmartCraftStorage.Shared;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("assembly_valheim")]
[assembly: IgnoresAccessChecksTo("SeneaL-UI")]
[assembly: IgnoresAccessChecksTo("SmartCraftStorage")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("SmartCraftStorageForSeneaLUI")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+291e7a96ddea4c490c9e9a903424f79bc709ad4b")]
[assembly: AssemblyProduct("SmartCraftStorageForSeneaLUI")]
[assembly: AssemblyTitle("SmartCraftStorageForSeneaLUI")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[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 SmartCraftStorageForSeneaLUI
{
	[BepInPlugin("alkeari.valheim.smartcraftstorageforsenealui", "SmartCraftStorage for SeneaL UI", "1.0.0")]
	[BepInProcess("valheim.exe")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public const string Guid = "alkeari.valheim.smartcraftstorageforsenealui";

		public const string Name = "SmartCraftStorage for SeneaL UI";

		private const string SmartCraftStorageGuid = "com.zellds.smartcraftstorage";

		private const string SeneaLUiGuid = "seneaL.valheim.ui";

		private Harmony _harmony;

		private void Awake()
		{
			_harmony = Harmony.CreateAndPatchAll(typeof(Plugin).Assembly, "alkeari.valheim.smartcraftstorageforsenealui");
			((BaseUnityPlugin)this).Logger.LogInfo((object)"SmartCraftStorage for SeneaL UI 1.0.0 loaded");
		}

		private void OnDestroy()
		{
			_harmony.UnpatchSelf();
		}
	}
	[HarmonyPatch(typeof(Stock))]
	internal static class StockPatches
	{
		[HarmonyPrefix]
		[HarmonyPatch("Count")]
		private static bool Count(Player p, string name, int quality, ref int __result)
		{
			if (!IsLocal(p))
			{
				return true;
			}
			__result = Stock.Own(((Humanoid)p).GetInventory(), name, quality) + ChestTotal(p, name, quality);
			return false;
		}

		[HarmonyPrefix]
		[HarmonyPatch("FromChests")]
		private static bool FromChests(Player p, string name, ref int __result)
		{
			if (!IsLocal(p))
			{
				return true;
			}
			__result = ChestTotal(p, name, -1);
			return false;
		}

		[HarmonyPrefix]
		[HarmonyPatch("Have")]
		private static bool Have(Player p, string name, ref bool __result)
		{
			if (!IsLocal(p))
			{
				return true;
			}
			__result = ((Humanoid)p).GetInventory().HaveItem(name, true);
			return false;
		}

		[HarmonyPrefix]
		[HarmonyPatch("Remove")]
		private static bool Remove(Player p, string name, int amount, int quality)
		{
			if (!IsLocal(p))
			{
				return true;
			}
			((Humanoid)p).GetInventory().RemoveItem(name, amount, quality, true);
			return false;
		}

		private static bool IsLocal(Player p)
		{
			if ((Object)(object)p != (Object)null)
			{
				return (Object)(object)p == (Object)(object)Player.m_localPlayer;
			}
			return false;
		}

		private static int ChestTotal(Player p, string name, int quality)
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			Player val = default(Player);
			if (!InventoryChestPatches.IsCraftingOrBuildingContext(((Humanoid)p).GetInventory(), ref val))
			{
				return 0;
			}
			int result = default(int);
			if (ChestCountCache.TryGet(name, quality, true, ref result))
			{
				return result;
			}
			int num = 0;
			foreach (Container item in NearbyContainers.Find(((Component)val).transform.position, ModConfig.CraftingChestRadius.Value, val))
			{
				num += UnlockedInventory.CountItems(item.GetInventory(), name, quality, true);
			}
			ChestCountCache.Store(name, quality, true, num);
			return num;
		}
	}
	internal static class PluginVersion
	{
		public const string Value = "1.0.0";
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}