Decompiled source of FlametalPickaxe v1.0.1

plugins/FlametalPickaxe.dll

Decompiled a month ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using Jotunn.Utils;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("FlametalPickaxe")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("FlametalPickaxe")]
[assembly: AssemblyTitle("FlametalPickaxe")]
[assembly: AssemblyVersion("1.0.0.0")]
[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 FlametalPickaxe
{
	[BepInPlugin("com.flametalpickaxe.mod", "Flametal Pickaxe", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class FlametalPickaxePlugin : BaseUnityPlugin
	{
		private const string ItemPrefabName = "FlametalPickaxe";

		private void Awake()
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Flametal Pickaxe initializing.");
			PrefabManager.OnVanillaPrefabsAvailable += RegisterPickaxe;
		}

		private void RegisterPickaxe()
		{
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: 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_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Expected O, but got Unknown
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Expected O, but got Unknown
			PrefabManager.OnVanillaPrefabsAvailable -= RegisterPickaxe;
			try
			{
				string text = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "flametalpickaxe.png");
				Sprite val = AssetUtils.LoadSpriteFromFile(text);
				if ((Object)(object)val == (Object)null)
				{
					((BaseUnityPlugin)this).Logger.LogWarning((object)("Custom icon could not be loaded: " + text));
				}
				else
				{
					((BaseUnityPlugin)this).Logger.LogInfo((object)"Custom icon loaded successfully!");
				}
				ItemConfig val2 = new ItemConfig
				{
					Name = "Flametal Pickaxe",
					Description = "A powerful Flametal pickaxe capable of breaking exceptionally tough stone.",
					CraftingStation = "blackforge",
					Amount = 1,
					Icon = val
				};
				val2.AddRequirement("FlametalNew", 25, 0);
				val2.AddRequirement("Blackwood", 10, 0);
				GameObject prefab = PrefabManager.Instance.GetPrefab("PickaxeBlackMetal");
				if ((Object)(object)prefab == (Object)null)
				{
					((BaseUnityPlugin)this).Logger.LogError((object)"Vanilla Black Metal Pickaxe prefab not found.");
					return;
				}
				CustomItem val3 = new CustomItem("FlametalPickaxe", "PickaxeBlackMetal", val2);
				ItemDrop component = prefab.GetComponent<ItemDrop>();
				if ((Object)(object)component == (Object)null || (Object)(object)val3.ItemDrop == (Object)null || component.m_itemData?.m_shared == null || val3.ItemDrop.m_itemData?.m_shared == null)
				{
					((BaseUnityPlugin)this).Logger.LogError((object)"Pickaxe validation failed: missing item data.");
					return;
				}
				SharedData shared = component.m_itemData.m_shared;
				SharedData shared2 = val3.ItemDrop.m_itemData.m_shared;
				if (shared == shared2)
				{
					((BaseUnityPlugin)this).Logger.LogError((object)"Unsafe shared item data detected. Flametal Pickaxe registration aborted.");
					return;
				}
				int toolTier = shared.m_toolTier;
				int maxQuality = shared.m_maxQuality;
				shared2.m_toolTier = 6;
				shared2.m_maxQuality = 1;
				if (shared.m_toolTier != toolTier || shared.m_maxQuality != maxQuality)
				{
					((BaseUnityPlugin)this).Logger.LogError((object)"Vanilla pickaxe data changed unexpectedly!");
					return;
				}
				((BaseUnityPlugin)this).Logger.LogInfo((object)("Vanilla Black Metal tool tier: " + shared.m_toolTier));
				((BaseUnityPlugin)this).Logger.LogInfo((object)("Flametal Pickaxe tool tier: " + shared2.m_toolTier));
				if ((Object)(object)val != (Object)null)
				{
					val3.ItemDrop.m_itemData.m_shared.m_icons = (Sprite[])(object)new Sprite[1] { val };
					((BaseUnityPlugin)this).Logger.LogInfo((object)"Flametal Pickaxe sprite assigned.");
				}
				if (ItemManager.Instance.AddItem(val3))
				{
					((BaseUnityPlugin)this).Logger.LogInfo((object)"Flametal Pickaxe registered successfully!");
				}
				else
				{
					((BaseUnityPlugin)this).Logger.LogError((object)"Failed to register Flametal Pickaxe.");
				}
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("Flametal Pickaxe error: " + ex));
			}
		}
	}
}