Decompiled source of TrophyIdols v1.0.0

TrophyIdols.dll

Decompiled 8 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using Jotunn;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using Jotunn.Utils;
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(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")]
[assembly: AssemblyCompany("TrophyIdols")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("TrophyIdols")]
[assembly: AssemblyTitle("TrophyIdols")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[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 TrophyIdols
{
	[BepInPlugin("peachyyy.trophyidols", "Trophy Idols", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
	public class TrophyIdolsPlugin : BaseUnityPlugin
	{
		private class Tier
		{
			public int Index;

			public string Material;

			public string Station;

			public int StationLevel;

			public string Trophies;
		}

		private class Built
		{
			public Tier Tier;

			public ConfigEntry<string> Station;

			public ConfigEntry<int> Level;

			public ConfigEntry<string> Trophies;

			public Recipe Weapon;

			public Recipe Armor;
		}

		public const string Guid = "peachyyy.trophyidols";

		public const string ModName = "Trophy Idols";

		public const string Version = "1.0.0";

		private static readonly Tier[] Tiers = new Tier[7]
		{
			new Tier
			{
				Index = 1,
				Material = "Bronze",
				Station = "forge",
				StationLevel = 1,
				Trophies = "TrophyBoar,TrophyDeer,TrophyNeck,TrophyGreydwarf,TrophyGreydwarfBrute,TrophyGreydwarfShaman,TrophySkeleton,TrophyForestTroll"
			},
			new Tier
			{
				Index = 2,
				Material = "Iron",
				Station = "forge",
				StationLevel = 2,
				Trophies = "TrophyDraugr,TrophyDraugrFem,TrophyDraugrElite,TrophyLeech,TrophyBlob,TrophyWraith,TrophySurtling,TrophyAbomination"
			},
			new Tier
			{
				Index = 3,
				Material = "Silver",
				Station = "forge",
				StationLevel = 3,
				Trophies = "TrophyWolf,TrophyHatchling,TrophyFenring,TrophyCultist,TrophySGolem,TrophyUlv,TrophyFrostTroll"
			},
			new Tier
			{
				Index = 4,
				Material = "Black Metal",
				Station = "forge",
				StationLevel = 4,
				Trophies = "TrophyGoblin,TrophyGoblinBrute,TrophyGoblinShaman,TrophyLox,TrophyDeathsquito,TrophyGrowth"
			},
			new Tier
			{
				Index = 5,
				Material = "Black Marble",
				Station = "blackforge",
				StationLevel = 1,
				Trophies = "TrophySeeker,TrophySeekerBrute,TrophyGjall,TrophyTick,TrophyDvergr,TrophyHare"
			},
			new Tier
			{
				Index = 6,
				Material = "Flametal",
				Station = "blackforge",
				StationLevel = 3,
				Trophies = "TrophyCharredMelee,TrophyCharredArcher,TrophyCharredMage,TrophyMorgen,TrophyAsksvin,TrophyVolture"
			},
			new Tier
			{
				Index = 7,
				Material = "Bloodgold",
				Station = "blackforge",
				StationLevel = 4,
				Trophies = "TrophyBarka,TrophyEyelessOne,TrophyFrostBlob,TrophyHexen,TrophyKrigen,TrophyLavaBlob,TrophyMoose,TrophyPulp,TrophySeal,TrophyWrithan"
			}
		};

		private readonly List<Built> _built = new List<Built>();

		private readonly HashSet<string> _warned = new HashSet<string>();

		private ConfigEntry<int> _trophyCost;

		private ConfigEntry<T> Bind<T>(string section, string key, T def, string desc)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected O, but got Unknown
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Expected O, but got Unknown
			return ((BaseUnityPlugin)this).Config.Bind<T>(section, key, def, new ConfigDescription(desc, (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
			{
				IsAdminOnly = true
			} }));
		}

		private void Awake()
		{
			_trophyCost = Bind("General", "TrophiesPerIdol", 1, "How many trophies (of any one kind from the tier's list) one idol costs.");
			Tier[] tiers = Tiers;
			foreach (Tier tier in tiers)
			{
				string section = $"Tier{tier.Index} {tier.Material}";
				_built.Add(new Built
				{
					Tier = tier,
					Station = Bind(section, "CraftingStation", tier.Station, "Crafting station prefab (forge, blackforge, piece_workbench, piece_artisanstation, ...)."),
					Level = Bind(section, "MinStationLevel", tier.StationLevel, "Minimum level of that station."),
					Trophies = Bind(section, "Trophies", tier.Trophies, "Comma-separated trophy prefab names. Any ONE of them can be used for an idol of this tier.")
				});
			}
			PrefabManager.OnVanillaPrefabsAvailable += Build;
			ItemManager.OnItemsRegistered += ApplyAll;
			SynchronizationManager.OnConfigurationSynchronized += delegate
			{
				ApplyAll();
			};
			((BaseUnityPlugin)this).Config.SettingChanged += delegate
			{
				ApplyAll();
			};
		}

		private void Build()
		{
			PrefabManager.OnVanillaPrefabsAvailable -= Build;
			foreach (Built item in _built)
			{
				int index = item.Tier.Index;
				if ((Object)(object)GetDrop($"Upgrader{index}Weapon") == (Object)null || (Object)(object)GetDrop($"Upgrader{index}Armor") == (Object)null)
				{
					Logger.LogWarning((object)$"[TrophyIdols] Upgrader{index}Weapon/Armor not found, skipping tier {index}");
					continue;
				}
				item.Weapon = AddRecipe($"Upgrader{index}Weapon", item);
				item.Armor = AddRecipe($"Upgrader{index}Armor", item);
			}
			ApplyAll();
		}

		private Recipe AddRecipe(string itemName, Built b)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Expected O, but got Unknown
			RecipeConfig val = new RecipeConfig();
			val.Name = "Recipe_TT_" + itemName;
			val.Item = itemName;
			val.Amount = 1;
			val.CraftingStation = b.Station.Value;
			val.MinStationLevel = b.Level.Value;
			val.RequireOnlyOneIngredient = true;
			val.Requirements = (RequirementConfig[])(object)new RequirementConfig[0];
			RecipeConfig val2 = val;
			CustomRecipe val3 = new CustomRecipe(val2);
			ItemManager.Instance.AddRecipe(val3);
			return val3.Recipe;
		}

		private void ApplyAll()
		{
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Expected O, but got Unknown
			foreach (Built item in _built)
			{
				if ((Object)(object)item.Weapon == (Object)null || (Object)(object)item.Armor == (Object)null)
				{
					continue;
				}
				List<Requirement> list = new List<Requirement>();
				string[] array = (item.Trophies.Value ?? "").Split(new char[1] { ',' }, StringSplitOptions.RemoveEmptyEntries);
				foreach (string text in array)
				{
					string text2 = text.Trim();
					if (text2.Length != 0)
					{
						ItemDrop drop = GetDrop(text2);
						if ((Object)(object)drop == (Object)null)
						{
							WarnOnce("Trophy '" + text2 + "' not found, ignored");
							continue;
						}
						list.Add(new Requirement
						{
							m_resItem = drop,
							m_amount = Math.Max(1, _trophyCost.Value),
							m_amountPerLevel = 0,
							m_recover = false
						});
					}
				}
				CraftingStation val = null;
				GameObject prefab = Cache.GetPrefab<GameObject>(item.Station.Value);
				if ((Object)(object)prefab != (Object)null)
				{
					val = prefab.GetComponent<CraftingStation>();
				}
				if ((Object)(object)val == (Object)null)
				{
					WarnOnce($"Crafting station '{item.Station.Value}' not found for tier {item.Tier.Index}, recipes disabled");
				}
				bool flag = list.Count > 0 && (Object)(object)val != (Object)null;
				Fill(item.Weapon, list, val, item.Level.Value, flag);
				Fill(item.Armor, list, val, item.Level.Value, flag);
			}
		}

		private static void Fill(Recipe r, List<Requirement> reqs, CraftingStation station, int level, bool on)
		{
			r.m_resources = reqs.ToArray();
			r.m_craftingStation = station;
			r.m_minStationLevel = level;
			r.m_requireOnlyOneIngredient = true;
			r.m_enabled = on;
		}

		private static ItemDrop GetDrop(string prefab)
		{
			GameObject prefab2 = Cache.GetPrefab<GameObject>(prefab);
			return ((Object)(object)prefab2 == (Object)null) ? null : prefab2.GetComponent<ItemDrop>();
		}

		private void WarnOnce(string msg)
		{
			if (_warned.Add(msg))
			{
				Logger.LogWarning((object)("[TrophyIdols] " + msg));
			}
		}
	}
}