Decompiled source of JonekPoisonArrowsMod v1.0.0

JonekPoisonArrowMod/Jonek_NPoisonArrowMod.dll

Decompiled 2 days ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using Jotunn.Utils;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("Jonek_NPoisonArrowMod")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Jonek_NPoisonArrowMod")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("a12f3d79-4e20-45c1-a36d-cce2fb32c93b")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace JonekMods.PoisonArrows;

[BepInPlugin("pl.jonek.poisonarrows", "Jonek - Poison Arrows", "1.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class PoisonArrowMod : BaseUnityPlugin
{
	public const string ModGuid = "pl.jonek.poisonarrows";

	public const string ModName = "Jonek - Poison Arrows";

	public const string ModVersion = "1.0.0";

	private const string PoisonArrowPrefab = "Jonek_PoisonArrow";

	private bool itemsRegistered;

	private ConfigEntry<int> woodCost;

	private ConfigEntry<int> featherCost;

	private ConfigEntry<int> pukeberryCost;

	private ConfigEntry<int> craftAmount;

	private ConfigEntry<float> pierceDamage;

	private ConfigEntry<float> poisonDamage;

	private void Awake()
	{
		woodCost = ((BaseUnityPlugin)this).Config.Bind<int>("Recipe", "Wood", 8, "Wood required to craft Poison Arrows.");
		featherCost = ((BaseUnityPlugin)this).Config.Bind<int>("Recipe", "Feathers", 2, "Feathers required to craft Poison Arrows.");
		pukeberryCost = ((BaseUnityPlugin)this).Config.Bind<int>("Recipe", "Pukeberries", 2, "Pukeberries required to craft Poison Arrows.");
		craftAmount = ((BaseUnityPlugin)this).Config.Bind<int>("Recipe", "CraftAmount", 20, "How many Poison Arrows are crafted at once.");
		pierceDamage = ((BaseUnityPlugin)this).Config.Bind<float>("Balance", "PierceDamage", 12f, "Pierce damage dealt by Poison Arrows.");
		poisonDamage = ((BaseUnityPlugin)this).Config.Bind<float>("Balance", "PoisonDamage", 10f, "Poison damage dealt by Poison Arrows.");
		PrefabManager.OnVanillaPrefabsAvailable += RegisterItems;
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Poison Arrows loaded. Waiting for vanilla prefabs.");
	}

	private void RegisterItems()
	{
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Expected O, but got Unknown
		//IL_004a: Unknown result type (might be due to invalid IL or missing references)
		//IL_004f: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0067: Unknown result type (might be due to invalid IL or missing references)
		//IL_007f: Unknown result type (might be due to invalid IL or missing references)
		//IL_008b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0094: Expected O, but got Unknown
		//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f5: Expected O, but got Unknown
		if (itemsRegistered)
		{
			return;
		}
		try
		{
			CustomItem val = new CustomItem("Jonek_PoisonArrow", "ArrowPoison");
			ConfigurePoisonArrow(val);
			if (!ItemManager.Instance.AddItem(val))
			{
				throw new Exception("Jotunn rejected Poison Arrow.");
			}
			RecipeConfig val2 = new RecipeConfig
			{
				Name = "Recipe_Jonek_PoisonArrow",
				Item = "Jonek_PoisonArrow",
				Amount = Mathf.Max(1, craftAmount.Value),
				CraftingStation = "piece_workbench",
				MinStationLevel = 1
			};
			val2.AddRequirement("Wood", Mathf.Max(1, woodCost.Value), 0);
			val2.AddRequirement("Feathers", Mathf.Max(1, featherCost.Value), 0);
			val2.AddRequirement("Pukeberries", Mathf.Max(1, pukeberryCost.Value), 0);
			CustomRecipe val3 = new CustomRecipe(val2);
			if (!ItemManager.Instance.AddRecipe(val3))
			{
				throw new Exception("Jotunn rejected Poison Arrow recipe.");
			}
			itemsRegistered = true;
			PrefabManager.OnVanillaPrefabsAvailable -= RegisterItems;
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Poison Arrow registered successfully.");
			((BaseUnityPlugin)this).Logger.LogInfo((object)("Poison Arrow recipe registered: Wood=" + woodCost.Value + ", Feathers=" + featherCost.Value + ", Pukeberries=" + pukeberryCost.Value + ", Amount=" + craftAmount.Value));
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)("Error while registering Poison Arrow: " + ex));
		}
	}

	private void ConfigurePoisonArrow(CustomItem poisonArrow)
	{
		SharedData shared = poisonArrow.ItemDrop.m_itemData.m_shared;
		shared.m_name = "Poison Arrow";
		shared.m_description = "Simple arrows coated with toxic pukeberry juice.";
		shared.m_damages.m_pierce = pierceDamage.Value;
		shared.m_damages.m_poison = poisonDamage.Value;
		shared.m_maxStackSize = 200;
		SetIcon(shared, "poison_arrow.png");
	}

	private void SetIcon(SharedData data, string fileName)
	{
		string directoryName = Path.GetDirectoryName(typeof(PoisonArrowMod).Assembly.Location);
		string text = Path.Combine(directoryName, "Assets", fileName);
		if (!File.Exists(text))
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)("Icon not found: " + text + ". Keeping vanilla icon."));
			return;
		}
		Sprite val = AssetUtils.LoadSpriteFromFile(text);
		if ((Object)(object)val != (Object)null)
		{
			data.m_icons = (Sprite[])(object)new Sprite[1] { val };
		}
	}
}