Decompiled source of OdinsBlessingForgeOfPotential v0.0.1

BepInEx/plugins/OdinsBlessingFoP.dll

Decompiled 2 weeks ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("OdinsBlessingFoP")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+dee99a09c315495dde64b757d374ae3cc6f6459d")]
[assembly: AssemblyProduct("OdinsBlessingFoP")]
[assembly: AssemblyTitle("OdinsBlessingFoP")]
[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 OdinsBlessingFoP
{
	[BepInPlugin("com.valheimmods.odinsblessingfop", "Odin's Blessing - Forge of Potential", "0.0.1")]
	public sealed class Plugin : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(ObjectDB), "Awake")]
		private static class ObjectDBAwakePatch
		{
			private static void Postfix(ObjectDB __instance)
			{
				Apply(__instance);
			}
		}

		[HarmonyPatch(typeof(ObjectDB), "CopyOtherDB")]
		private static class ObjectDBCopyPatch
		{
			private static bool Prepare()
			{
				return AccessTools.Method(typeof(ObjectDB), "CopyOtherDB", (Type[])null, (Type[])null) != null;
			}

			private static void Postfix(ObjectDB __instance)
			{
				Apply(__instance);
			}
		}

		private const string PluginGuid = "com.valheimmods.odinsblessingfop";

		private const string PluginName = "Odin's Blessing - Forge of Potential";

		private const string PluginVersion = "0.0.1";

		private Harmony _harmony;

		private void Awake()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			_harmony = new Harmony("com.valheimmods.odinsblessingfop");
			_harmony.PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Odin's Blessing - Forge of Potential has loaded.");
		}

		private void OnDestroy()
		{
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}

		private static void Apply(ObjectDB db)
		{
			if ((Object)(object)db == (Object)null || db.m_items == null)
			{
				return;
			}
			int num = 0;
			foreach (GameObject item in db.m_items)
			{
				if (!((Object)(object)item == (Object)null) && IsForgeIdol(((Object)item).name))
				{
					ItemDrop component = item.GetComponent<ItemDrop>();
					if (component?.m_itemData?.m_shared != null)
					{
						component.m_itemData.m_shared.m_upgradeChance = 1f;
						num++;
					}
				}
			}
			Debug.Log((object)$"[Oding's Blessing - Forge of Potential] Blessed {num} Forge Idols to 100% chance of success.");
		}

		private static bool IsForgeIdol(string name)
		{
			if (string.IsNullOrEmpty(name) || !name.StartsWith("Upgrader", StringComparison.Ordinal))
			{
				return false;
			}
			if (name.Length < 10 || name[8] < '0' || name[8] > '7')
			{
				return false;
			}
			return name.EndsWith("Weapon", StringComparison.Ordinal) || name.EndsWith("Armor", StringComparison.Ordinal);
		}
	}
}