Decompiled source of FeastProgress v0.1.0

FeastProgress.dll

Decompiled 2 days ago
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace FeastProgress;

[BepInPlugin("j1ga.feastprogress", "FeastProgress", "0.1.0")]
public class FeastProgressPlugin : BaseUnityPlugin
{
	private sealed class Spice
	{
		public string Prefab;

		public ConfigEntry<string> Key;

		public string Vanilla;
	}

	[HarmonyPatch(typeof(Trader), "GetAvailableItems")]
	private static class Trader_GetAvailableItems_Patch
	{
		private static void Prefix(Trader __instance)
		{
			ApplyKeys(__instance);
		}
	}

	public const string Guid = "j1ga.feastprogress";

	public const string Name = "FeastProgress";

	public const string Version = "0.1.0";

	private static ConfigEntry<bool> _enabled;

	private static readonly Dictionary<string, Spice> _spices = new Dictionary<string, Spice>(StringComparer.Ordinal);

	private Harmony _harmony;

	private void Awake()
	{
		//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e6: Expected O, but got Unknown
		_enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("01 General", "Enabled", true, "Off: every spice comes with the boss the game ties it to.");
		BindSpice("SpiceForests", "defeated_gdking", "Meadows, Black Forest and Swamp feasts", "the Elder (defeated_gdking)");
		BindSpice("SpiceOceans", "defeated_serpent", "Ocean feast", "a sea serpent (defeated_serpent)");
		BindSpice("SpiceMountains", "defeated_bonemass", "Mountain feast", "Moder (defeated_dragon)");
		BindSpice("SpicePlains", "defeated_dragon", "Plains feast", "Yagluth (defeated_goblinking)");
		BindSpice("SpiceMistlands", "defeated_goblinking", "Mistlands feast", "the Queen (defeated_queen)");
		BindSpice("SpiceAshlands", "defeated_queen", "Ashlands feast", "Fader (defeated_fader)");
		BindSpice("SpiceDeepNorth", "defeated_fader", "Deep North feast", "the last Deep North boss (defeated_frozenking_p3)");
		_harmony = new Harmony("j1ga.feastprogress");
		_harmony.PatchAll(typeof(FeastProgressPlugin).Assembly);
		((BaseUnityPlugin)this).Logger.LogInfo((object)"FeastProgress 0.1.0 loaded.");
	}

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

	private void BindSpice(string prefab, string key, string feasts, string vanilla)
	{
		Spice spice = new Spice();
		spice.Prefab = prefab;
		spice.Key = ((BaseUnityPlugin)this).Config.Bind<string>("02 Spices", prefab, key, "Boss key after which the Bog Witch sells this spice (" + feasts + "). In the game: after " + vanilla + ". Keys: defeated_eikthyr, defeated_gdking, defeated_bonemass, defeated_dragon, defeated_goblinking, defeated_queen, defeated_fader, defeated_frozenking_p3, defeated_serpent. Empty: sold from the start.");
		_spices[prefab] = spice;
	}

	private static void ApplyKeys(Trader trader)
	{
		if ((Object)(object)trader == (Object)null || trader.m_items == null)
		{
			return;
		}
		foreach (TradeItem item in trader.m_items)
		{
			if (item != null && !((Object)(object)item.m_prefab == (Object)null) && _spices.TryGetValue(((Object)((Component)item.m_prefab).gameObject).name, out var value))
			{
				if (value.Vanilla == null)
				{
					value.Vanilla = item.m_requiredGlobalKey ?? "";
				}
				string text = (_enabled.Value ? (value.Key.Value ?? "").Trim() : value.Vanilla);
				if (item.m_requiredGlobalKey != text)
				{
					item.m_requiredGlobalKey = text;
				}
			}
		}
	}
}