Decompiled source of More Ore Deposits v1.3.5

More Ore Deposits.dll

Decompiled 3 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using Configuration;
using HarmonyLib;
using Jotunn;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using Jotunn.Utils;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("More Ore Deposits")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("More Ore Deposits")]
[assembly: AssemblyCopyright("Copyright ©  2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("e3243d22-4307-4008-ba36-9f326008cde5")]
[assembly: AssemblyFileVersion("0.0.1.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.1.0")]
namespace MoreOreDeposits
{
	public class OreDropConfig
	{
		private Action<object, EventArgs> _action;

		public string OreName { get; set; }

		public ConfigEntry<int> DropMin { get; set; }

		public ConfigEntry<int> DropMax { get; set; }

		private static bool ValidateConfigEntry<T>(ConfigEntry<T> entry)
		{
			try
			{
				T value = (T)Convert.ChangeType(((ConfigEntryBase)entry).BoxedValue, typeof(T));
				entry.Value = value;
				return true;
			}
			catch
			{
				entry.Value = default(T);
				return false;
			}
		}

		public static OreDropConfig GetFromProps(BaseUnityPlugin instance, string oreName, int defaultMin, int defaultMax)
		{
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Expected O, but got Unknown
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Expected O, but got Unknown
			OreDropConfig config = new OreDropConfig();
			config.OreName = oreName;
			config.DropMin = instance.Config.Bind<int>("Server config", oreName + " Drop Min", defaultMin, new ConfigDescription("Minimum amount of " + oreName + " dropped from " + oreName + " deposits", (AcceptableValueBase)null, Array.Empty<object>()));
			config.DropMax = instance.Config.Bind<int>("Server config", oreName + " Drop Max", defaultMax, new ConfigDescription("Maximum amount of " + oreName + " dropped from " + oreName + " deposits", (AcceptableValueBase)null, Array.Empty<object>()));
			config.DropMin.SettingChanged += delegate
			{
				ValidateConfigEntry<int>(config.DropMin);
			};
			config.DropMax.SettingChanged += delegate
			{
				ValidateConfigEntry<int>(config.DropMax);
			};
			return config;
		}

		private void OnSettingChanged(object sender, EventArgs e)
		{
			if (_action != null)
			{
				_action(sender, e);
			}
		}

		public void AddSettingsChangedHandler(Action<object, EventArgs> action)
		{
			_action = action;
			DropMin.SettingChanged += OnSettingChanged;
			DropMax.SettingChanged += OnSettingChanged;
		}

		public void RemoveSettingsChangedHandler()
		{
			DropMin.SettingChanged -= OnSettingChanged;
			DropMax.SettingChanged -= OnSettingChanged;
			_action = null;
		}
	}
	[BepInPlugin("com.bepinex.MoreOreDeposits", "More Ore Deposits", "1.3.5")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	internal class MoreOreDeposits : BaseUnityPlugin, IPlugin
	{
		public const string PluginGUID = "com.bepinex.MoreOreDeposits";

		public const string PluginName = "More Ore Deposits";

		public const string PluginVersion = "1.3.5";

		public static CustomLocalization Localization = LocalizationManager.Instance.GetLocalization();

		private bool settingsUpdated;

		private OreDropConfig goldOreConfig;

		private OreDropConfig ironOreConfig;

		private OreDropConfig silverOreConfig;

		private OreDropConfig blackmetalOreConfig;

		private OreDropConfig coalOreConfig;

		private AssetBundle goldAssetBundle;

		private GameObject goldDepositPrefab;

		private GameObject goldOrePrefab;

		private AssetBundle ironAssetBundle;

		private GameObject ironDepositPrefab;

		private AssetBundle silverAssetBundle;

		private GameObject silverDepositPrefab;

		private AssetBundle blackmetalAssetBundle;

		private GameObject blackmetalDepositPrefab;

		private AssetBundle coalAssetBundle;

		private GameObject coalDepositPrefab;

		private AssetBundle translationBundle;

		private VegetationConfig goldDepositConfig = new VegetationConfig
		{
			Biome = (Biome)8,
			BlockCheck = true,
			Min = 0f,
			Max = 2f,
			GroundOffset = -0.3f,
			ScaleMin = 295f,
			ScaleMax = 296f,
			MinAltitude = 0f
		};

		private VegetationConfig ironDepositConfig = new VegetationConfig
		{
			Biome = (Biome)2,
			BlockCheck = true,
			Min = 0f,
			Max = 2f,
			GroundOffset = -0.3f,
			ScaleMin = 295f,
			ScaleMax = 296f,
			MinAltitude = 0f
		};

		private VegetationConfig silverDepositConfig = new VegetationConfig
		{
			Biome = (Biome)4,
			BlockCheck = true,
			Min = 0f,
			Max = 1f,
			GroundOffset = -1.3f,
			ScaleMin = 295f,
			ScaleMax = 296f,
			MaxAltitude = 100f
		};

		private VegetationConfig blackmetalDepositConfig = new VegetationConfig
		{
			Biome = (Biome)16,
			BlockCheck = true,
			Min = 0f,
			Max = 2f,
			GroundOffset = -0.3f,
			ScaleMin = 295f,
			ScaleMax = 296f,
			MinAltitude = 0f
		};

		private VegetationConfig coalDepositConfig = new VegetationConfig
		{
			Biome = (Biome)2,
			BlockCheck = true,
			Min = 0f,
			Max = 2f,
			GroundOffset = -0.3f,
			ScaleMin = 300f,
			ScaleMax = 300f,
			MinAltitude = 0f
		};

		ConfigFile IPlugin.Config => ((BaseUnityPlugin)this).Config;

		private void Awake()
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			Logger.LogInfo((object)"More Ore Deposits has Loaded");
			PrefabManager.OnVanillaPrefabsAvailable += OnPrefabsAvailable;
			new Harmony("com.bepinex.MoreOreDeposits").PatchAll();
			SynchronizationManager.OnConfigurationSynchronized += OnConfigurationSynchronized;
			((BaseUnityPlugin)this).Config.ConfigReloaded += OnConfigReloaded;
			new ConfigWatcher(this);
			InitializeOreConfigs();
		}

		private void OnPrefabsAvailable()
		{
			LoadAssets();
			CreateGoldOre();
			AddVegetation();
			AddlocalizationsEnglish();
			JSONS();
			PrefabManager.OnVanillaPrefabsAvailable -= OnPrefabsAvailable;
		}

		private void AddlocalizationsEnglish()
		{
			Localization = LocalizationManager.Instance.GetLocalization();
			CustomLocalization localization = Localization;
			string text = "English";
			localization.AddTranslation(ref text, new Dictionary<string, string>
			{
				{ "GoldOre_warp", "Gold ore" },
				{ "GoldOre_desc_warp", "Unrefined gold. Use a smelter to refine into gold coins." },
				{ "GoldDeposit_warp", "Gold" },
				{ "IronDeposit_warp", "Iron" },
				{ "SilverDepositSmall_warp", "Silver" },
				{ "BlackmetalDeposit_warp", "Blackmetal" },
				{ "CoalDeposit_warp", "Coal rock" }
			});
		}

		private void JSONS()
		{
			if (!((Object)(object)translationBundle == (Object)null))
			{
				TextAsset[] array = translationBundle.LoadAllAssets<TextAsset>();
				foreach (TextAsset val in array)
				{
					string text = ((Object)val).name.Replace("_MoreOreDeposits", "");
					Localization.AddJsonFile(text, val.text);
				}
			}
		}

		private void InitializeOreConfigs()
		{
			goldOreConfig = OreDropConfig.GetFromProps((BaseUnityPlugin)(object)this, "GoldOre", 1, 2);
			ironOreConfig = OreDropConfig.GetFromProps((BaseUnityPlugin)(object)this, "IronScrap", 2, 3);
			silverOreConfig = OreDropConfig.GetFromProps((BaseUnityPlugin)(object)this, "SilverOre", 1, 2);
			blackmetalOreConfig = OreDropConfig.GetFromProps((BaseUnityPlugin)(object)this, "BlackMetalScrap", 2, 3);
			coalOreConfig = OreDropConfig.GetFromProps((BaseUnityPlugin)(object)this, "Coal", 2, 3);
			goldOreConfig.AddSettingsChangedHandler(OnSettingsChanged);
			ironOreConfig.AddSettingsChangedHandler(OnSettingsChanged);
			silverOreConfig.AddSettingsChangedHandler(OnSettingsChanged);
			blackmetalOreConfig.AddSettingsChangedHandler(OnSettingsChanged);
			coalOreConfig.AddSettingsChangedHandler(OnSettingsChanged);
		}

		private void UpdateFeatures()
		{
			settingsUpdated = false;
			ConfigureDropOnDestroyed(goldDepositPrefab, goldOreConfig);
			ConfigureDropOnDestroyed(ironDepositPrefab, ironOreConfig);
			ConfigureDropOnDestroyed(silverDepositPrefab, silverOreConfig);
			ConfigureDropOnDestroyed(blackmetalDepositPrefab, blackmetalOreConfig);
			ConfigureDropOnDestroyed(coalDepositPrefab, coalOreConfig);
		}

		private void OnSettingsChanged(object sender, EventArgs e)
		{
			settingsUpdated = true;
		}

		private void OnConfigReloaded(object sender, EventArgs e)
		{
			if (settingsUpdated)
			{
				UpdateFeatures();
			}
		}

		private void OnConfigurationSynchronized(object sender, ConfigurationSynchronizationEventArgs e)
		{
			UpdateFeatures();
		}

		private DropData getDropDataFromEntry(OreDropConfig entry)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			DropData result = default(DropData);
			result.m_item = PrefabManager.Instance.GetPrefab(entry.OreName);
			result.m_stackMin = entry.DropMin.Value;
			result.m_stackMax = entry.DropMax.Value;
			result.m_weight = 1f;
			return result;
		}

		private void LoadAssets()
		{
			goldAssetBundle = AssetUtils.LoadAssetBundleFromResources("gold_bundle");
			AssetBundle obj = goldAssetBundle;
			goldDepositPrefab = ((obj != null) ? obj.LoadAsset<GameObject>("MineRock_gold") : null);
			AssetBundle obj2 = goldAssetBundle;
			goldOrePrefab = ((obj2 != null) ? obj2.LoadAsset<GameObject>("GoldOre") : null);
			ironAssetBundle = AssetUtils.LoadAssetBundleFromResources("iron_bundle");
			AssetBundle obj3 = ironAssetBundle;
			ironDepositPrefab = ((obj3 != null) ? obj3.LoadAsset<GameObject>("MineRock_iron") : null);
			silverAssetBundle = AssetUtils.LoadAssetBundleFromResources("silver_bundle");
			AssetBundle obj4 = silverAssetBundle;
			silverDepositPrefab = ((obj4 != null) ? obj4.LoadAsset<GameObject>("MineRock_silver_small") : null);
			blackmetalAssetBundle = AssetUtils.LoadAssetBundleFromResources("blackmetal_bundle");
			AssetBundle obj5 = blackmetalAssetBundle;
			blackmetalDepositPrefab = ((obj5 != null) ? obj5.LoadAsset<GameObject>("MineRock_blackmetal") : null);
			coalAssetBundle = AssetUtils.LoadAssetBundleFromResources("coal_bundle");
			AssetBundle obj6 = coalAssetBundle;
			coalDepositPrefab = ((obj6 != null) ? obj6.LoadAsset<GameObject>("MineRock_coal") : null);
			translationBundle = AssetUtils.LoadAssetBundleFromResources("translations_bundle");
			LogResourceNamesAndCheckErrors();
		}

		private void LogResourceNamesAndCheckErrors()
		{
			string[] manifestResourceNames = Assembly.GetExecutingAssembly().GetManifestResourceNames();
			Logger.LogInfo((object)("Embedded resources: " + string.Join(", ", manifestResourceNames)));
			CheckAssetBundle(goldAssetBundle, "gold");
			CheckAssetBundle(ironAssetBundle, "iron");
			CheckAssetBundle(silverAssetBundle, "silver");
			CheckAssetBundle(blackmetalAssetBundle, "blackmetal");
			CheckAssetBundle(coalAssetBundle, "coal");
		}

		private void CheckAssetBundle(AssetBundle bundle, string bundleName)
		{
			if ((Object)(object)bundle == (Object)null)
			{
				Logger.LogError((object)("Failed to load the " + bundleName + " asset bundle."));
			}
		}

		private void CreateGoldOre()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Expected O, but got Unknown
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Expected O, but got Unknown
			CustomItem val = new CustomItem(goldOrePrefab, false);
			ItemManager.Instance.AddItem(val);
			SmelterConversionConfig val2 = new SmelterConversionConfig();
			((ConversionConfig)val2).FromItem = "GoldOre";
			((ConversionConfig)val2).ToItem = "Coins";
			((ConversionConfig)val2).Station = Smelters.Smelter;
			ItemManager.Instance.AddItemConversion(new CustomItemConversion((ConversionConfig)(object)val2));
			ConfigureGoldOreAutoPickup("GoldOre");
		}

		private void ConfigureGoldOreAutoPickup(string itemName)
		{
			GameObject prefab = PrefabManager.Instance.GetPrefab(itemName);
			if ((Object)(object)prefab == (Object)null)
			{
				Debug.LogError((object)("Prefab '" + itemName + "' not found."));
				return;
			}
			ItemDrop component = prefab.GetComponent<ItemDrop>();
			if ((Object)(object)component == (Object)null)
			{
				Debug.LogError((object)("ItemDrop component not found on prefab '" + itemName + "'."));
			}
			else
			{
				component.m_autoPickup = true;
			}
		}

		private void AddVegetation()
		{
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Expected O, but got Unknown
			//IL_0186: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Expected O, but got Unknown
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: Expected O, but got Unknown
			//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b2: Expected O, but got Unknown
			//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c6: Expected O, but got Unknown
			if ((Object)(object)goldDepositPrefab == (Object)null || (Object)(object)ironDepositPrefab == (Object)null || (Object)(object)silverDepositPrefab == (Object)null || (Object)(object)blackmetalDepositPrefab == (Object)null || (Object)(object)coalDepositPrefab == (Object)null)
			{
				Logger.LogError((object)"One or more deposit prefabs are not loaded.");
				return;
			}
			ConfigureDestructible(goldDepositPrefab, 0, 30f);
			ConfigureDestructible(ironDepositPrefab, 1, 30f);
			ConfigureDestructible(silverDepositPrefab, 2, 30f);
			ConfigureDestructible(blackmetalDepositPrefab, 2, 30f);
			ConfigureDestructible(coalDepositPrefab, 0, 30f);
			ConfigureDropOnDestroyed(goldDepositPrefab, goldOreConfig);
			ConfigureDropOnDestroyed(ironDepositPrefab, ironOreConfig);
			ConfigureDropOnDestroyed(silverDepositPrefab, silverOreConfig);
			ConfigureDropOnDestroyed(blackmetalDepositPrefab, blackmetalOreConfig);
			ConfigureDropOnDestroyed(coalDepositPrefab, coalOreConfig);
			ConfigureHoverText(goldDepositPrefab, "$GoldDeposit_warp");
			ConfigureHoverText(ironDepositPrefab, "$IronDeposit_warp");
			ConfigureHoverText(silverDepositPrefab, "$SilverDepositSmall_warp");
			ConfigureHoverText(blackmetalDepositPrefab, "$BlackmetalDeposit_warp");
			ConfigureHoverText(coalDepositPrefab, "$CoalDeposit_warp");
			ConfigureBeacon(silverDepositPrefab);
			CustomVegetation val = new CustomVegetation(goldDepositPrefab, false, goldDepositConfig);
			CustomVegetation val2 = new CustomVegetation(ironDepositPrefab, false, ironDepositConfig);
			CustomVegetation val3 = new CustomVegetation(silverDepositPrefab, false, silverDepositConfig);
			CustomVegetation val4 = new CustomVegetation(blackmetalDepositPrefab, false, blackmetalDepositConfig);
			CustomVegetation val5 = new CustomVegetation(coalDepositPrefab, false, coalDepositConfig);
			ZoneManager.Instance.AddCustomVegetation(val);
			ZoneManager.Instance.AddCustomVegetation(val2);
			ZoneManager.Instance.AddCustomVegetation(val3);
			ZoneManager.Instance.AddCustomVegetation(val4);
			ZoneManager.Instance.AddCustomVegetation(val5);
		}

		private void ConfigureDestructible(GameObject prefab, int minToolTier, float health)
		{
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Expected O, but got Unknown
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Expected O, but got Unknown
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Expected O, but got Unknown
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Expected O, but got Unknown
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			Destructible val = prefab.GetComponent<Destructible>() ?? prefab.AddComponent<Destructible>();
			val.m_minToolTier = minToolTier;
			val.m_health = health;
			GameObject prefab2 = Cache.GetPrefab<GameObject>("vfx_RockDestroyed");
			GameObject prefab3 = Cache.GetPrefab<GameObject>("sfx_rock_destroyed");
			GameObject prefab4 = Cache.GetPrefab<GameObject>("vfx_RockHit");
			GameObject prefab5 = Cache.GetPrefab<GameObject>("sfx_rock_hit");
			val.m_destroyedEffect.m_effectPrefabs = (EffectData[])(object)new EffectData[2]
			{
				new EffectData
				{
					m_prefab = prefab2
				},
				new EffectData
				{
					m_prefab = prefab3
				}
			};
			val.m_hitEffect.m_effectPrefabs = (EffectData[])(object)new EffectData[2]
			{
				new EffectData
				{
					m_prefab = prefab4
				},
				new EffectData
				{
					m_prefab = prefab5
				}
			};
			val.m_damages.m_blunt = (DamageModifier)3;
			val.m_damages.m_slash = (DamageModifier)3;
			val.m_damages.m_pierce = (DamageModifier)3;
			val.m_damages.m_chop = (DamageModifier)3;
			val.m_damages.m_pickaxe = (DamageModifier)0;
			val.m_damages.m_fire = (DamageModifier)3;
			val.m_damages.m_frost = (DamageModifier)3;
			val.m_damages.m_lightning = (DamageModifier)3;
			val.m_damages.m_poison = (DamageModifier)3;
			val.m_damages.m_spirit = (DamageModifier)3;
		}

		private void ConfigureDropOnDestroyed(GameObject prefab, OreDropConfig oreConfig)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			(prefab.GetComponent<DropOnDestroyed>() ?? prefab.AddComponent<DropOnDestroyed>()).m_dropWhenDestroyed.m_drops = new List<DropData> { getDropDataFromEntry(oreConfig) };
		}

		private void ConfigureBeacon(GameObject prefab)
		{
			prefab.AddComponent<Beacon>().m_range = 30f;
		}

		private void ConfigureHoverText(GameObject prefab, string hoverText)
		{
			if ((Object)(object)prefab == (Object)null)
			{
				Logger.LogError((object)"Prefab is null. Cannot add HoverText.");
				return;
			}
			HoverText val = prefab.GetComponent<HoverText>();
			if ((Object)(object)val == (Object)null)
			{
				val = prefab.AddComponent<HoverText>();
			}
			val.m_text = hoverText;
		}
	}
	[HarmonyPatch(typeof(Smelter), "Spawn")]
	public static class SmelterProduceMore
	{
		public static void Prefix(Smelter __instance, string ore, ref int stack)
		{
			if (Object.op_Implicit((Object)(object)__instance) && ore == "GoldOre")
			{
				stack *= 20;
			}
		}
	}
}
namespace Configuration
{
	public class AcceptableValueConfigNote : AcceptableValueBase
	{
		public virtual string Note { get; }

		public AcceptableValueConfigNote(string note)
			: base(typeof(string))
		{
			if (string.IsNullOrEmpty(note))
			{
				throw new ArgumentException("A string with atleast 1 character is needed", "Note");
			}
			Note = note;
		}

		public override object Clamp(object value)
		{
			return value;
		}

		public override bool IsValid(object value)
		{
			return !string.IsNullOrEmpty(value as string);
		}

		public override string ToDescriptionString()
		{
			return "# Note: " + Note;
		}
	}
	public static class ConfigHelper
	{
		public static ConfigurationManagerAttributes GetAdminOnlyFlag()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Expected O, but got Unknown
			return new ConfigurationManagerAttributes
			{
				IsAdminOnly = true
			};
		}

		public static ConfigurationManagerAttributes GetTags(Action<ConfigEntryBase> action)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Expected O, but got Unknown
			return new ConfigurationManagerAttributes
			{
				CustomDrawer = action
			};
		}

		public static ConfigurationManagerAttributes GetTags()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Expected O, but got Unknown
			return new ConfigurationManagerAttributes();
		}

		public static ConfigEntry<T> Config<T>(this IPlugin instance, string group, string name, T value, ConfigDescription description)
		{
			return instance.Config.Bind<T>(group, name, value, description);
		}

		public static ConfigEntry<T> Config<T>(this IPlugin instance, string group, string name, T value, string description)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			return instance.Config(group, name, value, new ConfigDescription(description, (AcceptableValueBase)null, new object[1] { GetAdminOnlyFlag() }));
		}
	}
	public static class RequirementsEntry
	{
		public static RequirementConfig[] Deserialize(string reqs)
		{
			return ((IEnumerable<string>)reqs.Split(new char[1] { ',' })).Select((Func<string, RequirementConfig>)delegate(string r)
			{
				//IL_0012: Unknown result type (might be due to invalid IL or missing references)
				//IL_0017: Unknown result type (might be due to invalid IL or missing references)
				//IL_0020: Unknown result type (might be due to invalid IL or missing references)
				//IL_003c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0058: Unknown result type (might be due to invalid IL or missing references)
				//IL_0060: Expected O, but got Unknown
				string[] array = r.Split(new char[1] { ':' });
				int result;
				int result2;
				return new RequirementConfig
				{
					Item = array[0],
					Amount = ((array.Length <= 1 || !int.TryParse(array[1], out result)) ? 1 : result),
					AmountPerLevel = ((array.Length > 2 && int.TryParse(array[2], out result2)) ? result2 : 0),
					Recover = true
				};
			}).ToArray();
		}

		public static string Serialize(RequirementConfig[] reqs)
		{
			return string.Join(",", reqs.Select((RequirementConfig r) => (r.AmountPerLevel <= 0) ? $"{r.Item}:{r.Amount}" : $"{r.Item}:{r.Amount}:{r.AmountPerLevel}"));
		}
	}
	public static class SharedDrawers
	{
		private static BaseUnityPlugin configManager;

		private static BaseUnityPlugin GetConfigManager()
		{
			if ((Object)(object)configManager == (Object)null && Chainloader.PluginInfos.TryGetValue("com.bepis.bepinex.configurationmanager", out var value) && Object.op_Implicit((Object)(object)value.Instance))
			{
				configManager = value.Instance;
			}
			return configManager;
		}

		public static int GetRightColumnWidth()
		{
			int result = 130;
			BaseUnityPlugin val = GetConfigManager();
			if ((Object)(object)val != (Object)null)
			{
				PropertyInfo propertyInfo = ((object)val)?.GetType().GetProperty("RightColumnWidth", BindingFlags.Instance | BindingFlags.NonPublic);
				if (propertyInfo != null)
				{
					result = (int)propertyInfo.GetValue(val);
				}
			}
			return result;
		}

		public static void ReloadConfigDisplay()
		{
			BaseUnityPlugin val = GetConfigManager();
			if ((Object)(object)val != (Object)null)
			{
				((object)val).GetType().GetMethod("BuildSettingList").Invoke(val, Array.Empty<object>());
			}
		}

		public static Action<ConfigEntryBase> DrawReqConfigTable(bool hasUpgrades = false)
		{
			return delegate(ConfigEntryBase cfg)
			{
				//IL_005c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0061: Unknown result type (might be due to invalid IL or missing references)
				//IL_008d: Expected O, but got Unknown
				//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ee: Expected O, but got Unknown
				//IL_0163: Unknown result type (might be due to invalid IL or missing references)
				//IL_0168: Unknown result type (might be due to invalid IL or missing references)
				//IL_017d: Expected O, but got Unknown
				//IL_0125: Unknown result type (might be due to invalid IL or missing references)
				//IL_012a: Unknown result type (might be due to invalid IL or missing references)
				//IL_013f: Expected O, but got Unknown
				//IL_0184: Unknown result type (might be due to invalid IL or missing references)
				//IL_0189: Unknown result type (might be due to invalid IL or missing references)
				//IL_0191: Unknown result type (might be due to invalid IL or missing references)
				//IL_0199: Unknown result type (might be due to invalid IL or missing references)
				//IL_01a6: Expected O, but got Unknown
				//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
				//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
				//IL_01cf: Expected O, but got Unknown
				//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
				//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
				//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
				//IL_01f0: Expected O, but got Unknown
				List<RequirementConfig> list = new List<RequirementConfig>();
				bool flag = false;
				int rightColumnWidth = GetRightColumnWidth();
				GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
				foreach (RequirementConfig item in RequirementsEntry.Deserialize((string)cfg.BoxedValue).ToList())
				{
					GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
					string text = GUILayout.TextField(item.Item, new GUIStyle(GUI.skin.textField)
					{
						fixedWidth = rightColumnWidth - 33 - (hasUpgrades ? 37 : 0) - 21 - 21 - 12
					}, Array.Empty<GUILayoutOption>());
					string text2 = (string.IsNullOrEmpty(text) ? item.Item : text);
					flag = flag || text2 != item.Item;
					int num = item.Amount;
					if (int.TryParse(GUILayout.TextField(num.ToString(), new GUIStyle(GUI.skin.textField)
					{
						fixedWidth = 33f
					}, Array.Empty<GUILayoutOption>()), out var result) && result != num)
					{
						num = result;
						flag = true;
					}
					int num2 = item.AmountPerLevel;
					if (hasUpgrades && int.TryParse(GUILayout.TextField(num2.ToString(), new GUIStyle(GUI.skin.textField)
					{
						fixedWidth = 33f
					}, Array.Empty<GUILayoutOption>()), out var result2) && result2 != num2)
					{
						num2 = result2;
						flag = true;
					}
					if (GUILayout.Button("x", new GUIStyle(GUI.skin.button)
					{
						fixedWidth = 21f
					}, Array.Empty<GUILayoutOption>()))
					{
						flag = true;
					}
					else
					{
						list.Add(new RequirementConfig
						{
							Item = text2,
							Amount = num,
							AmountPerLevel = num2
						});
					}
					if (GUILayout.Button("+", new GUIStyle(GUI.skin.button)
					{
						fixedWidth = 21f
					}, Array.Empty<GUILayoutOption>()))
					{
						flag = true;
						list.Add(new RequirementConfig
						{
							Item = "<Prefab Name>",
							Amount = 1
						});
					}
					GUILayout.EndHorizontal();
				}
				GUILayout.EndVertical();
				if (flag)
				{
					cfg.BoxedValue = RequirementsEntry.Serialize(list.ToArray());
				}
			};
		}
	}
	public interface IPlugin
	{
		ConfigFile Config { get; }
	}
	public class ConfigWatcher
	{
		private BaseUnityPlugin configurationManager;

		private IPlugin plugin;

		public ConfigWatcher(IPlugin plugin)
		{
			if (plugin == null)
			{
				throw new ArgumentNullException("plugin");
			}
			this.plugin = plugin;
			CheckForConfigManager();
		}

		private void InitializeConfigWatcher()
		{
			string fileName = Path.GetFileName(plugin.Config.ConfigFilePath);
			FileSystemWatcher fileSystemWatcher = new FileSystemWatcher(Path.GetDirectoryName(plugin.Config.ConfigFilePath), fileName);
			fileSystemWatcher.Changed += OnConfigFileChangedCreatedOrRenamed;
			fileSystemWatcher.Created += OnConfigFileChangedCreatedOrRenamed;
			fileSystemWatcher.Renamed += OnConfigFileChangedCreatedOrRenamed;
			fileSystemWatcher.IncludeSubdirectories = true;
			fileSystemWatcher.SynchronizingObject = ThreadingHelper.SynchronizingObject;
			fileSystemWatcher.EnableRaisingEvents = true;
			Logger.LogDebug((object)"File system config watcher initialized.");
		}

		private void CheckForConfigManager()
		{
			PluginInfo value;
			if (GUIManager.IsHeadless())
			{
				InitializeConfigWatcher();
			}
			else if (Chainloader.PluginInfos.TryGetValue("com.bepis.bepinex.configurationmanager", out value) && Object.op_Implicit((Object)(object)value.Instance))
			{
				configurationManager = value.Instance;
				Logger.LogDebug((object)"Configuration manager found, hooking DisplayingWindowChanged");
				EventInfo @event = ((object)configurationManager).GetType().GetEvent("DisplayingWindowChanged");
				if (@event != null)
				{
					Action<object, object> action = OnConfigManagerDisplayingWindowChanged;
					Delegate handler = Delegate.CreateDelegate(@event.EventHandlerType, action.Target, action.Method);
					@event.AddEventHandler(configurationManager, handler);
				}
			}
			else
			{
				InitializeConfigWatcher();
			}
		}

		private void OnConfigFileChangedCreatedOrRenamed(object sender, FileSystemEventArgs e)
		{
			string configFilePath = plugin.Config.ConfigFilePath;
			if (!File.Exists(configFilePath))
			{
				return;
			}
			try
			{
				plugin.Config.SaveOnConfigSet = false;
				plugin.Config.Reload();
				plugin.Config.SaveOnConfigSet = true;
			}
			catch
			{
				Logger.LogError((object)("There was an issue with your " + Path.GetFileName(configFilePath) + " file."));
				Logger.LogError((object)"Please check the format and spelling.");
			}
		}

		private void OnConfigManagerDisplayingWindowChanged(object sender, object e)
		{
			if (!(bool)((object)configurationManager).GetType().GetProperty("DisplayingWindow").GetValue(configurationManager, null))
			{
				plugin.Config.SaveOnConfigSet = false;
				plugin.Config.Reload();
				plugin.Config.SaveOnConfigSet = true;
			}
		}
	}
}