Decompiled source of Obtainable Stone Pickaxe and Upgradeable Antler Pickaxe v1.0.1

ObtainableStonePickaxe.dll

Decompiled 7 months ago
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using UnityEngine;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("ObtainableStonePickaxe")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ObtainableStonePickaxe")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("89cacab8-0387-4cad-bada-d6d45086586f")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.1.0")]
[module: UnverifiableCode]
namespace ObtainableStonePickaxe;

[BepInPlugin("goldenrevolver.ObtainableStonePickaxePlugin", "Obtainable Stone Pickaxe", "1.0.1")]
public class ObtainableStonePickaxePlugin : BaseUnityPlugin
{
	public const string NAME = "Obtainable Stone Pickaxe";

	public const string VERSION = "1.0.1";

	public static ConfigEntry<bool> ChangeStonePickaxeRecipe;

	public static ConfigEntry<bool> UpgradeableStonePickaxe;

	public static ConfigEntry<bool> UpgradeableAntlerPickaxe;

	public static ConfigEntry<bool> BronzePickaxeUpgradeFix;

	public static ConfigEntry<bool> EnableDebugMessages;

	protected void Awake()
	{
		LoadConfig();
		Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), (string)null);
	}

	private void LoadConfig()
	{
		string text = "1 - Upgrading";
		BronzePickaxeUpgradeFix = ((BaseUnityPlugin)this).Config.Bind<bool>(text, "BronzePickaxeUpgradeFix", true, "Whether to fix that the bronze pickaxe gains one less pickaxe damage than pierce damage per level, unlike all other pickaxes.");
		UpgradeableAntlerPickaxe = ((BaseUnityPlugin)this).Config.Bind<bool>(text, "UpgradeableAntlerPickaxe", true, "Enables upgrading of the antler pickaxe with the default upgrade formula.");
		UpgradeableStonePickaxe = ((BaseUnityPlugin)this).Config.Bind<bool>(text, "UpgradeableStonePickaxe", true, "Enables upgrading of the stone pickaxe with the default upgrade formula.");
		text = "9 - Debugging";
		EnableDebugMessages = ((BaseUnityPlugin)this).Config.Bind<bool>(text, "EnableDebugMessages", false, "Enable this if you can't break a rock with the stone pickaxe to see why the mod thinks it's not a rock. Tell this to the mod author if you think it's a bug.");
	}

	internal static void DebugLog(string message)
	{
		Debug.Log((object)("Obtainable Stone Pickaxe: " + message));
	}
}
[HarmonyPatch(typeof(ObjectDB), "Awake")]
internal static class PatchObjectDB
{
	private const string bronzePickaxe = "$item_pickaxe_bronze";

	private const string anterPickaxe = "$item_pickaxe_antler";

	private const string stonePickaxe = "$item_pickaxe_stone";

	private const string stoneAxe = "$item_axe_stone";

	public static void Postfix(ObjectDB __instance)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		Scene activeScene = SceneManager.GetActiveScene();
		if (((Scene)(ref activeScene)).name != "main")
		{
			return;
		}
		EffectList hitEffect = null;
		EffectList hitTerrainEffect = null;
		foreach (GameObject item in __instance.m_items)
		{
			if ((Object)(object)item == (Object)null)
			{
				continue;
			}
			ItemDrop component = item.GetComponent<ItemDrop>();
			if ((Object)(object)component == (Object)null)
			{
				continue;
			}
			SharedData shared = component.m_itemData.m_shared;
			if (shared.m_name == "$item_pickaxe_bronze" && ObtainableStonePickaxePlugin.BronzePickaxeUpgradeFix.Value)
			{
				shared.m_damagesPerLevel.m_pickaxe = shared.m_damagesPerLevel.m_pierce;
			}
			if (shared.m_name == "$item_pickaxe_antler")
			{
				hitEffect = shared.m_hitEffect;
				hitTerrainEffect = shared.m_hitTerrainEffect;
				if (ObtainableStonePickaxePlugin.UpgradeableAntlerPickaxe.Value)
				{
					shared.m_maxQuality = 4;
					shared.m_damagesPerLevel.m_pickaxe = 5f;
					shared.m_damagesPerLevel.m_pierce = 5f;
					shared.m_blockPowerPerLevel = 0f;
					shared.m_deflectionForcePerLevel = 5f;
					shared.m_durabilityPerLevel = 50f;
				}
			}
		}
		foreach (GameObject item2 in __instance.m_items)
		{
			if ((Object)(object)item2 == (Object)null)
			{
				continue;
			}
			ItemDrop component2 = item2.GetComponent<ItemDrop>();
			if ((Object)(object)component2 == (Object)null)
			{
				continue;
			}
			SharedData shared2 = component2.m_itemData.m_shared;
			if (shared2.m_name == "$item_pickaxe_stone")
			{
				shared2.m_hitEffect = hitEffect;
				shared2.m_hitTerrainEffect = hitTerrainEffect;
				shared2.m_deflectionForce = 20f;
				shared2.m_attack.m_attackStamina = 6f;
				shared2.m_toolTier = -18;
				if (ObtainableStonePickaxePlugin.UpgradeableStonePickaxe.Value)
				{
					shared2.m_maxQuality = 4;
					shared2.m_damagesPerLevel.m_pickaxe = 5f;
					shared2.m_damagesPerLevel.m_pierce = 5f;
					shared2.m_blockPowerPerLevel = 0f;
					shared2.m_deflectionForcePerLevel = 5f;
					shared2.m_durabilityPerLevel = 50f;
				}
			}
		}
		CraftingStation repairStation = null;
		foreach (Recipe recipe in __instance.m_recipes)
		{
			if (recipe.m_item?.m_itemData.m_shared.m_name == "$item_axe_stone")
			{
				repairStation = recipe.m_repairStation;
			}
		}
		foreach (Recipe recipe2 in __instance.m_recipes)
		{
			if (recipe2.m_item?.m_itemData.m_shared.m_name == "$item_pickaxe_stone")
			{
				recipe2.m_enabled = true;
				recipe2.m_craftingStation = null;
				recipe2.m_repairStation = repairStation;
			}
		}
	}
}
[HarmonyPatch]
internal static class RockPatches
{
	[HarmonyPatch(typeof(ZLog), "LogWarning")]
	internal static class PatchLog
	{
		public static bool Prefix(object o)
		{
			return !(o is string text) || !(text == "No stat for mine tier: " + -18);
		}
	}

	[HarmonyPatch(typeof(Destructible), "RPC_Damage")]
	internal static class PatchDestructible
	{
		public static void Prefix(Destructible __instance, HitData hit, ref int __state)
		{
			if (hit == null || hit.m_toolTier != -18)
			{
				return;
			}
			__state = __instance.m_minToolTier;
			if ((Object)(object)__instance.m_spawnWhenDestroyed == (Object)null)
			{
				if (__instance.m_onDestroyed == null)
				{
					return;
				}
				DropOnDestroyed component = ((Component)__instance).GetComponent<DropOnDestroyed>();
				if ((Object)(object)component != (Object)null)
				{
					bool flag = DropsOnlyStones(component.m_dropWhenDestroyed);
					ObtainableStonePickaxePlugin.DebugLog($"Destructable {((Object)__instance).name}: {flag}");
					if (flag)
					{
						__instance.m_minToolTier = -18;
					}
				}
				return;
			}
			MineRock5 component2 = __instance.m_spawnWhenDestroyed.GetComponent<MineRock5>();
			if ((Object)(object)component2 != (Object)null)
			{
				bool flag2 = DropsOnlyStones(component2.m_dropItems);
				ObtainableStonePickaxePlugin.DebugLog($"Destructable MineRock5 {((Object)component2).name}: {flag2}");
				if (flag2)
				{
					__instance.m_minToolTier = -18;
				}
				return;
			}
			MineRock component3 = __instance.m_spawnWhenDestroyed.GetComponent<MineRock>();
			if ((Object)(object)component3 != (Object)null)
			{
				bool flag3 = DropsOnlyStones(component3.m_dropItems);
				ObtainableStonePickaxePlugin.DebugLog($"Destructable MineRock {((Object)component3).name}: {flag3}");
				if (flag3)
				{
					__instance.m_minToolTier = -18;
				}
			}
		}

		public static void Postfix(Destructible __instance, HitData hit, ref int __state)
		{
			if (hit != null && hit.m_toolTier == -18)
			{
				__instance.m_minToolTier = __state;
			}
		}
	}

	[HarmonyPatch(typeof(MineRock), "RPC_Hit")]
	internal static class PatchMineRock
	{
		public static void Prefix(MineRock __instance, HitData hit, ref int __state)
		{
			if (hit != null && hit.m_toolTier == -18)
			{
				__state = __instance.m_minToolTier;
				bool flag = DropsOnlyStones(__instance.m_dropItems);
				ObtainableStonePickaxePlugin.DebugLog($"MineRock {((Object)__instance).name}: {flag}");
				if (flag)
				{
					__instance.m_minToolTier = -18;
				}
			}
		}

		public static void Postfix(MineRock __instance, HitData hit, ref int __state)
		{
			if (hit != null && hit.m_toolTier == -18)
			{
				__instance.m_minToolTier = __state;
			}
		}
	}

	[HarmonyPatch(typeof(MineRock5), "DamageArea")]
	internal static class PatchMineRock5
	{
		public static void Prefix(MineRock5 __instance, HitData hit, ref int __state)
		{
			if (hit != null && hit.m_toolTier == -18)
			{
				__state = __instance.m_minToolTier;
				bool flag = DropsOnlyStones(__instance.m_dropItems);
				ObtainableStonePickaxePlugin.DebugLog($"MineRock5 {((Object)__instance).name}: {flag}");
				if (flag)
				{
					__instance.m_minToolTier = -18;
				}
			}
		}

		public static void Postfix(MineRock5 __instance, HitData hit, ref int __state)
		{
			if (hit != null && hit.m_toolTier == -18)
			{
				__instance.m_minToolTier = __state;
			}
		}
	}

	internal const int stonePickaxeTier = -18;

	public static bool DropsOnlyStones(DropTable dropTable)
	{
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		if (dropTable == null)
		{
			return false;
		}
		bool result = false;
		foreach (DropData drop in dropTable.m_drops)
		{
			if ((Object)(object)drop.m_item == (Object)null)
			{
				continue;
			}
			ItemDrop component = drop.m_item.GetComponent<ItemDrop>();
			if (!((Object)(object)component == (Object)null))
			{
				if (!(component.m_itemData.m_shared.m_name == "$item_stone"))
				{
					return false;
				}
				result = true;
			}
		}
		return result;
	}
}