Decompiled source of M2 Modpack v3.1.1

BepInEx/plugins/GradedTeleportableItems.dll

Decompiled 18 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("GradedTeleportableItems")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("GradedTeleportableItems")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("f47f29bf-f2c5-4b8b-b161-4132dfb26c63")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace GradedTeleportableItems;

[BepInPlugin("VM.GradedTeleportableItems", "GradedTeleportableItems by VM", "1.0.0")]
[BepInProcess("valheim.exe")]
public class GradedTeleportableItems : BaseUnityPlugin
{
	private enum BossTrophy
	{
		TrophyEikthyr,
		TrophyTheElder,
		TrophyBonemass,
		TrophyDragonQueen,
		TrophyGoblinKing,
		TrophySeekerQueen
	}

	private static readonly Dictionary<BossTrophy, List<string>> itemsLevels = new Dictionary<BossTrophy, List<string>>
	{
		{
			BossTrophy.TrophyTheElder,
			new List<string> { "$item_tin", "$item_tinore", "$item_copper", "$item_copperore", "$item_copperscrap", "$item_bronze", "$item_bronzescrap" }
		},
		{
			BossTrophy.TrophyBonemass,
			new List<string> { "$item_iron", "$item_ironore", "$item_ironscrap" }
		},
		{
			BossTrophy.TrophyDragonQueen,
			new List<string> { "$item_silver", "$item_silverore", "$item_dragonegg" }
		},
		{
			BossTrophy.TrophyGoblinKing,
			new List<string> { "$item_blackmetal", "$item_blackmetalscrap" }
		},
		{
			BossTrophy.TrophySeekerQueen,
			new List<string> { "$item_dvergrneedle" }
		}
	};

	private const string modGUID = "VM.GradedTeleportableItems";

	private const string modName = "GradedTeleportableItems by VM";

	private const string modVersion = "1.0.0";

	private readonly Harmony harmony = new Harmony("VM.GradedTeleportableItems");

	private void Awake()
	{
		harmony.PatchAll();
	}

	public static void MakeItemTeleportable(Player player, ref ItemData itemData)
	{
		List<string> trophies = player.GetTrophies();
		if (trophies.Contains("TrophyTheElder") && itemsLevels[BossTrophy.TrophyTheElder].Contains(itemData.m_shared.m_name))
		{
			itemData.m_shared.m_teleportable = true;
		}
		else if (trophies.Contains("TrophyBonemass") && itemsLevels[BossTrophy.TrophyBonemass].Contains(itemData.m_shared.m_name))
		{
			itemData.m_shared.m_teleportable = true;
		}
		else if (trophies.Contains("TrophyDragonQueen") && itemsLevels[BossTrophy.TrophyDragonQueen].Contains(itemData.m_shared.m_name))
		{
			itemData.m_shared.m_teleportable = true;
		}
		else if (trophies.Contains("TrophyGoblinKing") && itemsLevels[BossTrophy.TrophyGoblinKing].Contains(itemData.m_shared.m_name))
		{
			itemData.m_shared.m_teleportable = true;
		}
		else if (trophies.Contains("TrophySeekerQueen") && itemsLevels[BossTrophy.TrophySeekerQueen].Contains(itemData.m_shared.m_name))
		{
			itemData.m_shared.m_teleportable = true;
		}
	}
}
internal class ContainerPatches
{
	[HarmonyPatch(typeof(Container), "Interact")]
	private class Container_Interact_Patch
	{
		[HarmonyPostfix]
		private static void Postfix(ref Inventory ___m_inventory, ref bool __result)
		{
			if (__result)
			{
				Player player = Player.m_localPlayer;
				___m_inventory.GetAllItems().ForEach(delegate(ItemData itemData)
				{
					GradedTeleportableItems.MakeItemTeleportable(player, ref itemData);
				});
			}
		}
	}
}
internal class InventoryPatches
{
	[HarmonyPatch(typeof(Inventory), "Changed")]
	private class Inventory_Changed_Patch
	{
		[HarmonyPrefix]
		private static void Prefix(ref Action ___m_onChanged, ref List<ItemData> ___m_inventory)
		{
			if (___m_onChanged == null)
			{
				return;
			}
			Player player = Player.m_localPlayer;
			if ((Object)(object)player != (Object)null)
			{
				___m_inventory.ForEach(delegate(ItemData itemData)
				{
					GradedTeleportableItems.MakeItemTeleportable(player, ref itemData);
				});
			}
		}
	}
}
internal class PlayerPatches
{
	[HarmonyPatch(typeof(Player), "Load")]
	private class Player_Load_Patch
	{
		[HarmonyPostfix]
		private static void Postfix(Player __instance, ref Inventory ___m_inventory)
		{
			___m_inventory.GetAllItems().ForEach(delegate(ItemData itemData)
			{
				GradedTeleportableItems.MakeItemTeleportable(__instance, ref itemData);
			});
		}
	}
}