Decompiled source of BossItemMerchant v1.0.9

BossItemMerchant.dll

Decompiled 3 days ago
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("BossItemMerchant")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("BossItemMerchant")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("7a66b20c-09c7-41b6-98a0-62c9e05ca129")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace BossItemMerchant;

[BepInPlugin("com.jorkhin.bossitemmerchant", "Boss Item Merchant", "1.0.8")]
public class Plugin : BaseUnityPlugin
{
	[HarmonyPatch(typeof(Trader), "GetAvailableItems")]
	public static class Trader_GetAvailableItems_Patch
	{
		public static void Postfix(Trader __instance, ref List<TradeItem> __result)
		{
			if (!((Object)(object)Player.m_localPlayer == (Object)null) && !((Object)(object)ObjectDB.instance == (Object)null))
			{
				if (HasBossKey("defeated_eikthyr"))
				{
					AddStoreItem(__result, "HardAntler", HardAntlerPrice.Value);
				}
				if (HasBossKey("defeated_gdking"))
				{
					AddStoreItem(__result, "CryptKey", CryptKeyPrice.Value);
				}
				if (HasBossKey("defeated_bonemass"))
				{
					AddStoreItem(__result, "Wishbone", WishbonePrice.Value);
				}
				if (HasBossKey("defeated_dragon"))
				{
					AddStoreItem(__result, "DragonTear", DragonTearPrice.Value);
				}
				if (HasBossKey("defeated_yagluth"))
				{
					AddStoreItem(__result, "YagluthDrop", YagluthDropPrice.Value);
				}
			}
		}

		private static bool HasBossKey(string key)
		{
			if ((Object)(object)Player.m_localPlayer != (Object)null && (((Humanoid)Player.m_localPlayer).HaveUniqueKey(key) || ((Humanoid)Player.m_localPlayer).HaveUniqueKey(key.ToLower())))
			{
				return true;
			}
			if ((Object)(object)ZoneSystem.instance != (Object)null && (ZoneSystem.instance.GetGlobalKey(key) || ZoneSystem.instance.GetGlobalKey(key.ToLower())))
			{
				return true;
			}
			return false;
		}

		private static void AddStoreItem(List<TradeItem> storeList, string prefabName, int price)
		{
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Expected O, but got Unknown
			GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(prefabName);
			if ((Object)(object)itemPrefab == (Object)null)
			{
				return;
			}
			ItemDrop itemDrop = itemPrefab.GetComponent<ItemDrop>();
			if (!((Object)(object)itemDrop == (Object)null) && itemDrop.m_itemData != null && itemDrop.m_itemData.m_shared != null && !storeList.Exists((TradeItem i) => (Object)(object)i.m_prefab != (Object)null && ((Object)i.m_prefab).name == ((Object)itemDrop).name))
			{
				if ((Object)(object)itemDrop.m_itemData.m_dropPrefab == (Object)null)
				{
					itemDrop.m_itemData.m_dropPrefab = itemPrefab;
				}
				TradeItem item = new TradeItem
				{
					m_prefab = itemDrop,
					m_price = price,
					m_stack = 1,
					m_tooltip = "",
					m_requiredGlobalKey = ""
				};
				storeList.Add(item);
			}
		}
	}

	public const string PluginGUID = "com.jorkhin.bossitemmerchant";

	public const string PluginName = "Boss Item Merchant";

	public const string PluginVersion = "1.0.8";

	private readonly Harmony harmony = new Harmony("com.jorkhin.bossitemmerchant");

	public static ConfigEntry<int> HardAntlerPrice;

	public static ConfigEntry<int> CryptKeyPrice;

	public static ConfigEntry<int> WishbonePrice;

	public static ConfigEntry<int> DragonTearPrice;

	public static ConfigEntry<int> YagluthDropPrice;

	private void Awake()
	{
		HardAntlerPrice = ((BaseUnityPlugin)this).Config.Bind<int>("Merchant Prices", "HardAntlerPrice", 100, "Gold cost for Hard Antler (Eikthyr)");
		CryptKeyPrice = ((BaseUnityPlugin)this).Config.Bind<int>("Merchant Prices", "CryptKeyPrice", 300, "Gold cost for Swamp Key (The Elder)");
		WishbonePrice = ((BaseUnityPlugin)this).Config.Bind<int>("Merchant Prices", "WishbonePrice", 600, "Gold cost for Wishbone (Bonemass)");
		DragonTearPrice = ((BaseUnityPlugin)this).Config.Bind<int>("Merchant Prices", "DragonTearPrice", 1000, "Gold cost for Dragon Tear (Moder)");
		YagluthDropPrice = ((BaseUnityPlugin)this).Config.Bind<int>("Merchant Prices", "YagluthDropPrice", 1500, "Gold cost for Torn Spirit (Yagluth)");
		harmony.PatchAll();
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Boss Item Merchant v1.0.8 loaded successfully!");
	}
}