Decompiled source of SharedRecipeFinderReborn v1.0.1

SharedRecipeFinderReborn.dll

Decompiled 2 weeks ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")]
[assembly: AssemblyCompany("SharedRecipeFinderReborn")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1")]
[assembly: AssemblyProduct("SharedRecipeFinderReborn")]
[assembly: AssemblyTitle("SharedRecipeFinderReborn")]
[assembly: AssemblyVersion("1.0.1.0")]
namespace SharedRecipeFinderReborn;

[BepInPlugin("soulemper0r.sharedrecipefinderreborn", "SharedRecipeFinderReborn", "1.0.1")]
[BepInProcess("valheim.exe")]
[BepInIncompatibility("vnoisy.sharedrecipefinder.plugin")]
public sealed class Plugin : BaseUnityPlugin
{
	[HarmonyPatch(typeof(InventoryGui), "Show", new Type[]
	{
		typeof(Container),
		typeof(int)
	})]
	internal static class InventoryShowPatch
	{
		[HarmonyPostfix]
		private static void Postfix(Container __0)
		{
			if (_enabled == null || !_enabled.Value || (Object)(object)__0 == (Object)null)
			{
				return;
			}
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null)
			{
				return;
			}
			try
			{
				Inventory inventory = __0.GetInventory();
				if (inventory == null)
				{
					return;
				}
				foreach (ItemData allItem in inventory.GetAllItems())
				{
					if (allItem?.m_shared != null)
					{
						localPlayer.AddKnownItem(allItem);
					}
				}
			}
			catch (Exception ex)
			{
				_log.LogWarning((object)("Container discovery failed: " + ex));
			}
		}
	}

	public const string PluginGuid = "soulemper0r.sharedrecipefinderreborn";

	public const string PluginName = "SharedRecipeFinderReborn";

	public const string PluginVersion = "1.0.1";

	private static ConfigEntry<bool> _enabled;

	private static ManualLogSource _log;

	private Harmony _harmony;

	private void Awake()
	{
		//IL_0031: Unknown result type (might be due to invalid IL or missing references)
		//IL_003b: Expected O, but got Unknown
		_log = ((BaseUnityPlugin)this).Logger;
		_enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Discover items and unlock recipes when opening a container, without taking its contents.");
		_harmony = new Harmony("soulemper0r.sharedrecipefinderreborn");
		try
		{
			_harmony.PatchAll(typeof(Plugin).Assembly);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"1.0.1: container recipe discovery enabled.");
		}
		catch (Exception ex)
		{
			_harmony.UnpatchSelf();
			((BaseUnityPlugin)this).Logger.LogError((object)("Could not install container discovery patch: " + ex));
		}
	}

	private void OnDestroy()
	{
		Harmony harmony = _harmony;
		if (harmony != null)
		{
			harmony.UnpatchSelf();
		}
	}
}