Decompiled source of TieredPortals v1.0.0

plugins/Tiered Portals.dll

Decompiled a day ago
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("Tiered Portals")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Tiered Portals")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("03da83b4-7327-4382-910d-faca40c72ad9")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace TieredPortals;

[BepInPlugin("com.ethan.tieredportals", "Tiered Portals", "1.0.0")]
public class TieredPortals : BaseUnityPlugin
{
	public static ConfigEntry<bool> Enabled;

	public static ConfigEntry<string> ElderUnlocks;

	public static ConfigEntry<string> BonemassUnlocks;

	public static ConfigEntry<string> ModerUnlocks;

	public static ConfigEntry<string> YagluthUnlocks;

	public static ConfigEntry<string> QueenUnlocks;

	private static Dictionary<string, List<string>> unlockTable;

	private void Awake()
	{
		//IL_0157: Unknown result type (might be due to invalid IL or missing references)
		//IL_015d: Expected O, but got Unknown
		Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Enable or disable the mod");
		ElderUnlocks = ((BaseUnityPlugin)this).Config.Bind<string>("BossUnlocks", "ElderUnlocks", "CopperOre, TinOre, Bronze", (ConfigDescription)null);
		BonemassUnlocks = ((BaseUnityPlugin)this).Config.Bind<string>("BossUnlocks", "BonemassUnlocks", "IronScrap, Iron", (ConfigDescription)null);
		ModerUnlocks = ((BaseUnityPlugin)this).Config.Bind<string>("BossUnlocks", "ModerUnlocks", "SilverOre, Silver", (ConfigDescription)null);
		YagluthUnlocks = ((BaseUnityPlugin)this).Config.Bind<string>("BossUnlocks", "YagluthUnlocks", "BlackMetalScrap, BlackMetal", (ConfigDescription)null);
		QueenUnlocks = ((BaseUnityPlugin)this).Config.Bind<string>("BossUnlocks", "QueenUnlocks", "Carapace, Mandible, RefinedEitr", (ConfigDescription)null);
		unlockTable = new Dictionary<string, List<string>>
		{
			{
				"defeated_gdking",
				ParseList(ElderUnlocks.Value)
			},
			{
				"defeated_bonemass",
				ParseList(BonemassUnlocks.Value)
			},
			{
				"defeated_dragon",
				ParseList(ModerUnlocks.Value)
			},
			{
				"defeated_goblinking",
				ParseList(YagluthUnlocks.Value)
			},
			{
				"defeated_queen",
				ParseList(QueenUnlocks.Value)
			}
		};
		Harmony val = new Harmony("com.ethan.tieredportals");
		val.PatchAll();
	}

	private static List<string> ParseList(string csv)
	{
		return (from s in csv.Split(new char[1] { ',' })
			select s.Trim() into s
			where !string.IsNullOrEmpty(s)
			select s).ToList();
	}

	public static bool IsItemUnlocked(string itemName)
	{
		if ((Object)(object)ZoneSystem.instance == (Object)null)
		{
			return false;
		}
		foreach (KeyValuePair<string, List<string>> item in unlockTable)
		{
			if (!ZoneSystem.instance.GetGlobalKey(item.Key) || !item.Value.Any((string unlock) => itemName.Contains(unlock)))
			{
				continue;
			}
			return true;
		}
		return false;
	}
}
[HarmonyPatch(typeof(Player), "IsTeleportable")]
public static class TeleportPatch
{
	private static void Postfix(Player __instance, ItemData item, ref bool __result)
	{
		if (TieredPortals.Enabled.Value && !__result && item != null && item.m_shared != null)
		{
			string name = item.m_shared.m_name;
			if (TieredPortals.IsItemUnlocked(name))
			{
				__result = true;
			}
		}
	}
}