Decompiled source of DraugrIronOre v1.0.1

BepInEx\plugins\DraugrIronOre.dll

Decompiled 2 days 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 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("DraugrIronOre")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("DraugrIronOre")]
[assembly: AssemblyTitle("DraugrIronOre")]
[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 DraugrIronOre
{
	[BepInPlugin("com.boombasketmods.draugrironore", "Draugr Iron Ore", "1.0.1")]
	public class DraugrIronOrePlugin : BaseUnityPlugin
	{
		public const string PluginGuid = "com.boombasketmods.draugrironore";

		public const string PluginName = "Draugr Iron Ore";

		public const string PluginVersion = "1.0.1";

		internal static ConfigEntry<float> DropChance;

		internal static ConfigEntry<int> MinAmount;

		internal static ConfigEntry<int> MaxAmount;

		internal static ConfigEntry<bool> IncludeElite;

		internal static ConfigEntry<bool> IncludeRanged;

		internal static ManualLogSource Log;

		private Harmony _harmony;

		private void Awake()
		{
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			DropChance = ((BaseUnityPlugin)this).Config.Bind<float>("Drops", "DropChance", 0.33f, "Chance that an eligible Draugr drops bonus Iron Ore (0.25 = 25%).");
			MinAmount = ((BaseUnityPlugin)this).Config.Bind<int>("Drops", "MinAmount", 1, "Minimum Iron Ore per successful bonus drop.");
			MaxAmount = ((BaseUnityPlugin)this).Config.Bind<int>("Drops", "MaxAmount", 3, "Maximum Iron Ore per successful bonus drop.");
			IncludeElite = ((BaseUnityPlugin)this).Config.Bind<bool>("Enemies", "IncludeEliteDraugr", true, "Also allow Draugr Elite to drop bonus Iron Ore.");
			IncludeRanged = ((BaseUnityPlugin)this).Config.Bind<bool>("Enemies", "IncludeRangedDraugr", true, "Also allow Draugr Ranged to drop bonus Iron Ore.");
			_harmony = new Harmony("com.boombasketmods.draugrironore");
			_harmony.PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)("Loaded. Draugr bonus Iron Ore chance: " + DropChance.Value));
		}

		private void OnDestroy()
		{
			if (_harmony != null)
			{
				_harmony.UnpatchSelf();
			}
		}
	}
	[HarmonyPatch(typeof(Character), "OnDeath")]
	internal static class CharacterOnDeathPatch
	{
		private static void Postfix(Character __instance)
		{
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if ((Object)(object)__instance == (Object)null || __instance.IsPlayer() || ((Object)(object)ZNet.instance != (Object)null && !ZNet.instance.IsServer()) || !IsTargetDraugr(((Object)((Component)__instance).gameObject).name.Replace("(Clone)", "").Trim()))
				{
					return;
				}
				float num = Mathf.Clamp01(DraugrIronOrePlugin.DropChance.Value);
				if (Random.value >= num || (Object)(object)ObjectDB.instance == (Object)null)
				{
					return;
				}
				GameObject itemPrefab = ObjectDB.instance.GetItemPrefab("IronOre");
				if ((Object)(object)itemPrefab == (Object)null)
				{
					DraugrIronOrePlugin.Log.LogWarning((object)"Could not find item prefab 'IronOre'. No bonus drop spawned.");
					return;
				}
				int num2 = Mathf.Max(1, DraugrIronOrePlugin.MinAmount.Value);
				int num3 = Mathf.Max(num2, DraugrIronOrePlugin.MaxAmount.Value);
				int stack = Random.Range(num2, num3 + 1);
				Vector3 val = ((Component)__instance).transform.position + Vector3.up * 0.25f;
				GameObject val2 = Object.Instantiate<GameObject>(itemPrefab, val, Quaternion.identity);
				ItemDrop component = val2.GetComponent<ItemDrop>();
				if ((Object)(object)component == (Object)null)
				{
					Object.Destroy((Object)(object)val2);
					DraugrIronOrePlugin.Log.LogWarning((object)"IronOre prefab has no ItemDrop component.");
				}
				else
				{
					component.m_itemData.m_stack = stack;
					val2.transform.position = val;
				}
			}
			catch (Exception ex)
			{
				DraugrIronOrePlugin.Log.LogError((object)("Bonus drop failed: " + ex));
			}
		}

		private static bool IsTargetDraugr(string prefabName)
		{
			if (string.Equals(prefabName, "Draugr", StringComparison.OrdinalIgnoreCase))
			{
				return true;
			}
			if (DraugrIronOrePlugin.IncludeElite.Value && string.Equals(prefabName, "Draugr_Elite", StringComparison.OrdinalIgnoreCase))
			{
				return true;
			}
			if (DraugrIronOrePlugin.IncludeRanged.Value && string.Equals(prefabName, "Draugr_Ranged", StringComparison.OrdinalIgnoreCase))
			{
				return true;
			}
			return false;
		}
	}
}