Decompiled source of EnchantingLibrary v1.0.0

plugins/EnchantingLibrary.dll

Decompiled 2 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using SideLoader;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("OutwardModTemplate")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("OutwardModTemplate")]
[assembly: AssemblyCopyright("Copyright ©  2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("c5450fe0-edcf-483f-b9ea-4b1ef9d36da7")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace EnchantingLibrary;

public static class ConfigElements
{
	public static ConfigEntry<float> chanceOfRecipeInLibrary_S;

	public static ConfigEntry<float> chanceOfRecipeInLibrary_NS;

	public static ConfigEntry<float> chanceOfRecipeInLibrary_NSEL;

	public static ConfigEntry<int> moddedItemIDSearchRange;

	public static void Init(ConfigFile config)
	{
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Expected O, but got Unknown
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: Expected O, but got Unknown
		//IL_009a: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a4: Expected O, but got Unknown
		//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dc: Expected O, but got Unknown
		chanceOfRecipeInLibrary_S = config.Bind<float>("Enchanting Library", "Chance of Recipe in Library (Sor.)", 1f, new ConfigDescription("The chance of a recipe being in the Forgotten Research Laboratory.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
		chanceOfRecipeInLibrary_NS = config.Bind<float>("Enchanting Library", "Chance of Recipe in Library (New Sir.)", 1f, new ConfigDescription("The chance of a recipe being in the New Sirocco Library.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
		chanceOfRecipeInLibrary_NSEL = config.Bind<float>("Enchanting Library", "Chance of Recipe in Library (New Sir. Ext. Lib.)", 1f, new ConfigDescription("The chance of a recipe being in the New Sirocco Extended Library.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
		moddedItemIDSearchRange = config.Bind<int>("Enchanting Library (advanced)", "Stop searching after X itemIDs without finding a real item", 100000, new ConfigDescription("Searches the last X itemrange for modded items", (AcceptableValueBase)(object)new AcceptableValueRange<int>(10000, 200000), Array.Empty<object>()));
	}
}
[BepInPlugin("johbenji.enchantinglibrary", "Enchanting Library", "1.0.0")]
public class EnchantingLibraryPlugin : BaseUnityPlugin
{
	public enum bookCategory
	{
		Weapon,
		Armor,
		BodyArmor,
		Helmet,
		Boots,
		Bow,
		Chakram,
		Dagger,
		Lantern,
		Lexicon,
		Modded
	}

	public enum enchantingType
	{
		Sorobor,
		NewSirocco,
		NewSiroccoExtended,
		Invalid
	}

	private struct BookShelfData
	{
		public Vector3 position;

		public Vector3 rotation;

		public BookShelfData(Vector3 position, Vector3 rotation)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			this.position = position;
			this.rotation = rotation;
		}
	}

	[HarmonyPatch(typeof(ItemContainer), "ShowContent")]
	public static class TextSwapPatch
	{
		private static void Postfix(ItemContainer __instance, Character _character)
		{
			GameObject child = GetChild(((Component)__instance).gameObject, "Decorative-RecipeBook");
			if ((Object)(object)child == (Object)null || (Object)(object)_character == (Object)null)
			{
				return;
			}
			CharacterUI characterUI = _character.CharacterUI;
			if ((Object)(object)_character.CharacterUI == (Object)null)
			{
				return;
			}
			GameObject child2 = GetChild(((Component)characterUI).gameObject, "Canvas");
			if ((Object)(object)child2 == (Object)null)
			{
				return;
			}
			GameObject child3 = GetChild(child2, "GameplayPanels");
			if ((Object)(object)child3 == (Object)null)
			{
				return;
			}
			GameObject child4 = GetChild(child3, "Menus");
			if ((Object)(object)child4 == (Object)null)
			{
				return;
			}
			GameObject child5 = GetChild(child4, "CharacterMenus");
			if ((Object)(object)child5 == (Object)null)
			{
				return;
			}
			GameObject child6 = GetChild(child5, "ExtraPanel");
			if ((Object)(object)child6 == (Object)null)
			{
				return;
			}
			GameObject child7 = GetChild(child6, "Content");
			if ((Object)(object)child7 == (Object)null)
			{
				return;
			}
			GameObject child8 = GetChild(child7, "TopPanel");
			if ((Object)(object)child8 == (Object)null)
			{
				return;
			}
			GameObject child9 = GetChild(child8, "lblContainerName");
			if (!((Object)(object)child9 == (Object)null))
			{
				Text component = child9.GetComponent<Text>();
				if ((Object)(object)component != (Object)null)
				{
					component.text = "Recipe Book";
				}
			}
		}

		private static GameObject GetChild(GameObject parent, string childName)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			foreach (Transform item in parent.transform)
			{
				Transform val = item;
				if (((Object)val).name == childName)
				{
					return ((Component)val).gameObject;
				}
			}
			return null;
		}
	}

	public const string GUID = "johbenji.enchantinglibrary";

	public const string NAME = "Enchanting Library";

	public const string VERSION = "1.0.0";

	internal static ManualLogSource Log;

	public static Dictionary<bookCategory, List<int>> EnchantingLibrary = new Dictionary<bookCategory, List<int>>
	{
		{
			bookCategory.Weapon,
			new List<int>()
		},
		{
			bookCategory.Armor,
			new List<int>()
		},
		{
			bookCategory.BodyArmor,
			new List<int>()
		},
		{
			bookCategory.Helmet,
			new List<int>()
		},
		{
			bookCategory.Boots,
			new List<int>()
		},
		{
			bookCategory.Bow,
			new List<int>()
		},
		{
			bookCategory.Chakram,
			new List<int>()
		},
		{
			bookCategory.Dagger,
			new List<int>()
		},
		{
			bookCategory.Lantern,
			new List<int>()
		},
		{
			bookCategory.Lexicon,
			new List<int>()
		},
		{
			bookCategory.Modded,
			new List<int>()
		}
	};

	public static List<int> BasicNewSiroccoLibrary = new List<int>();

	public static List<int> AdvancedNewSiroccoLibrary = new List<int>();

	private static Dictionary<bookCategory, BookShelfData> EnchantingInfrastructure = new Dictionary<bookCategory, BookShelfData>();

	private int range;

	public static EnchantingLibraryPlugin Instance { get; private set; }

	internal void Awake()
	{
		//IL_007c: Unknown result type (might be due to invalid IL or missing references)
		Instance = this;
		Log = ((BaseUnityPlugin)this).Logger;
		ConfigElements.Init(((BaseUnityPlugin)this).Config);
		range = ConfigElements.moddedItemIDSearchRange.Value;
		SL.BeforePacksLoaded += BeforePacksLoaded;
		SL.OnPacksLoaded += OnPacksLoaded;
		SL.OnSceneLoaded += OnSceneLoaded;
		SL.OnGameplayResumedAfterLoading += OnGameplayResumedAfterLoading;
		new Harmony("johbenji.enchantinglibrary").PatchAll();
	}

	internal void BeforePacksLoaded()
	{
		SetBookcases();
		AddVanillaWeapons();
		AddVanillaArmor();
		AddVanillaBodyArmor();
		AddVanillaHelmet();
		AddVanillaBoots();
		AddVanillaBow();
		AddVanillaChakram();
		AddVanillaDagger();
		AddVanillaLantern();
		AddVanillaLexicon();
		SetBasicNewSirrocoRecipe();
		SetAdvancedNewSiroccoRecipe();
		int num = 0;
		for (int i = 0; i < EnchantingLibrary.Count; i++)
		{
			bookCategory bookCategory = (bookCategory)i;
			if (bookCategory != bookCategory.Modded)
			{
				num += EnchantingLibrary[bookCategory].Count;
			}
		}
		Log.LogMessage((object)$"Enchanting Library Plugin loaded vanilla enchantments. Total added = {num}");
	}

	private void SetBookcases()
	{
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: 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)
		//IL_0063: Unknown result type (might be due to invalid IL or missing references)
		//IL_0088: Unknown result type (might be due to invalid IL or missing references)
		//IL_009c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c1: 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_00fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_010e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0133: Unknown result type (might be due to invalid IL or missing references)
		//IL_0147: Unknown result type (might be due to invalid IL or missing references)
		//IL_016d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0181: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a6: 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_01df: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0218: Unknown result type (might be due to invalid IL or missing references)
		//IL_022c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0252: Unknown result type (might be due to invalid IL or missing references)
		//IL_0266: Unknown result type (might be due to invalid IL or missing references)
		EnchantingInfrastructure.Add(bookCategory.Weapon, new BookShelfData(new Vector3(-34.6631f, -20.735f, 67.4f), new Vector3(0f, 270f, 0f)));
		EnchantingInfrastructure.Add(bookCategory.Armor, new BookShelfData(new Vector3(-45.7143f, -20.74f, 62.77f), new Vector3(0f, 90f, 0f)));
		EnchantingInfrastructure.Add(bookCategory.BodyArmor, new BookShelfData(new Vector3(-23.65f, -20.7427f, 81.202f), new Vector3(0f, 180f, 0f)));
		EnchantingInfrastructure.Add(bookCategory.Helmet, new BookShelfData(new Vector3(-7.3f, -20.74f, 80.898f), new Vector3(0f, 180f, 0f)));
		EnchantingInfrastructure.Add(bookCategory.Boots, new BookShelfData(new Vector3(13.67f, -20.73f, 69.21f), new Vector3(0f, 0f, 0f)));
		EnchantingInfrastructure.Add(bookCategory.Bow, new BookShelfData(new Vector3(8.01f, -20.74f, 95.8f), new Vector3(0f, 180f, 0f)));
		EnchantingInfrastructure.Add(bookCategory.Lexicon, new BookShelfData(new Vector3(25.943f, -20.73f, 72.8492f), new Vector3(0f, 270f, 0f)));
		EnchantingInfrastructure.Add(bookCategory.Lantern, new BookShelfData(new Vector3(25.95f, -20.1f, 79.9f), new Vector3(0f, 270f, 0f)));
		EnchantingInfrastructure.Add(bookCategory.Chakram, new BookShelfData(new Vector3(8.236f, -20.75f, 99.2f), new Vector3(0f, 0f, 0f)));
		EnchantingInfrastructure.Add(bookCategory.Dagger, new BookShelfData(new Vector3(7.7f, -20.74f, 110.69f), new Vector3(0f, 180f, 0f)));
		EnchantingInfrastructure.Add(bookCategory.Modded, new BookShelfData(new Vector3(-9.7961f, -20.735f, 32.68f), new Vector3(0f, 270f, 0f)));
	}

	private void AddVanillaWeapons()
	{
		List<int> recipeScrollItemIDs = new List<int>
		{
			5800062, 5800035, 5800044, 5800063, 5800061, 5800043, 5800004, 5800040, 5800003, 5800010,
			5800012, 5800014, 5800011, 5800064, 5800001, 5800002, 5800013, 5800005, 5800007, 5800008,
			5800009, 5800006, 5800065, 5800033
		};
		AddMultipleEnchantmentsToLibrary(recipeScrollItemIDs, bookCategory.Weapon);
	}

	private void AddVanillaArmor()
	{
		List<int> recipeScrollItemIDs = new List<int>
		{
			5800066, 5800052, 5800045, 5800055, 5800058, 5800049, 5800057, 5800056, 5800054, 5800053,
			5800050, 5800051, 5800034, 5800047
		};
		AddMultipleEnchantmentsToLibrary(recipeScrollItemIDs, bookCategory.Armor);
	}

	private void AddVanillaBodyArmor()
	{
		List<int> recipeScrollItemIDs = new List<int> { 5800027, 5800038, 5800025, 5800026, 5800024, 5800028, 5800069, 5800030, 5800039 };
		AddMultipleEnchantmentsToLibrary(recipeScrollItemIDs, bookCategory.BodyArmor);
	}

	private void AddVanillaHelmet()
	{
		List<int> recipeScrollItemIDs = new List<int> { 5800036, 5800037, 5800061, 5800041, 5800068, 5800029 };
		AddMultipleEnchantmentsToLibrary(recipeScrollItemIDs, bookCategory.Helmet);
	}

	private void AddVanillaBoots()
	{
		List<int> recipeScrollItemIDs = new List<int> { 5800023, 5800022, 5800067, 5800042, 5800048 };
		AddMultipleEnchantmentsToLibrary(recipeScrollItemIDs, bookCategory.Boots);
	}

	private void AddVanillaBow()
	{
		List<int> recipeScrollItemIDs = new List<int> { 5800046, 5800032, 5800059, 5800060 };
		AddMultipleEnchantmentsToLibrary(recipeScrollItemIDs, bookCategory.Bow);
	}

	private void AddVanillaChakram()
	{
		List<int> recipeScrollItemIDs = new List<int> { 5800031 };
		AddMultipleEnchantmentsToLibrary(recipeScrollItemIDs, bookCategory.Chakram);
	}

	private void AddVanillaDagger()
	{
		List<int> recipeScrollItemIDs = new List<int> { 5800015 };
		AddMultipleEnchantmentsToLibrary(recipeScrollItemIDs, bookCategory.Dagger);
	}

	private void AddVanillaLantern()
	{
		List<int> recipeScrollItemIDs = new List<int> { 5800019, 5800020, 5800018, 5800017 };
		AddMultipleEnchantmentsToLibrary(recipeScrollItemIDs, bookCategory.Lantern);
	}

	private void AddVanillaLexicon()
	{
		List<int> recipeScrollItemIDs = new List<int> { 5800016 };
		AddMultipleEnchantmentsToLibrary(recipeScrollItemIDs, bookCategory.Lexicon);
	}

	private void SetBasicNewSirrocoRecipe()
	{
		List<int> recipeScrollItemIDs = new List<int> { 5800071, 5800070, 5800078, 5800076, 5800077, 5800075, 5800073, 5800074 };
		AddMultipleEnchantmentsToLibrary(recipeScrollItemIDs, bookCategory.Weapon, enchantingType.NewSirocco);
	}

	private void SetAdvancedNewSiroccoRecipe()
	{
		List<int> recipeScrollItemIDs = new List<int> { 5800087, 5800079, 5800085, 5800082, 5800084, 5800083, 5800080, 5800081, 5800086 };
		AddMultipleEnchantmentsToLibrary(recipeScrollItemIDs, bookCategory.Weapon, enchantingType.NewSiroccoExtended);
		AddMultipleEnchantmentsToLibrary(BasicNewSiroccoLibrary, bookCategory.Weapon, enchantingType.NewSiroccoExtended);
	}

	internal void OnPacksLoaded()
	{
		AddModEnchantments();
	}

	private void AddModEnchantments()
	{
		Log.LogMessage((object)$"Searching for modded enchantments in the initial range (-2, {-2 - range})...");
		int num = -2 - range;
		int num2 = -2;
		int num3 = 0;
		for (int num4 = -2; num4 > num; num4--)
		{
			num2--;
			Item itemPrefab = ResourcesPrefabManager.Instance.GetItemPrefab(num4);
			if (!((Object)(object)itemPrefab == (Object)null) && (Object)(object)itemPrefab != (Object)null)
			{
				num = num4 - range;
				if (itemPrefab is EnchantmentRecipeItem)
				{
					num3++;
					EnchantmentRecipeItem val = (EnchantmentRecipeItem)(object)((itemPrefab is EnchantmentRecipeItem) ? itemPrefab : null);
					EnchantmentRecipe[] recipes = val.Recipes;
					Log.LogMessage((object)$"Adding modded enchantment recipe with itemID: {num4} to the library.");
					if (recipes != null && recipes.Length != 0)
					{
						if (recipes[0].TableIsInBuilding)
						{
							QuestEventReference questEvent = recipes[0].QuestEvent;
							if (questEvent != null)
							{
								if (questEvent.EventUID != "")
								{
									AddEnchantmentToLibrary(num4, bookCategory.Weapon, enchantingType.NewSiroccoExtended);
								}
								else
								{
									AddEnchantmentToLibrary(num4, bookCategory.Weapon, enchantingType.NewSirocco);
									AddEnchantmentToLibrary(num4, bookCategory.Weapon, enchantingType.NewSiroccoExtended);
								}
							}
							else
							{
								AddEnchantmentToLibrary(num4, bookCategory.Weapon, enchantingType.NewSirocco);
								AddEnchantmentToLibrary(num4, bookCategory.Weapon, enchantingType.NewSiroccoExtended);
							}
						}
						else
						{
							AddEnchantmentToLibrary(num4, bookCategory.Modded);
						}
					}
				}
			}
		}
		Log.LogMessage((object)$"Finished adding {num3} modded enchantments to the library. Last checked itemID: {num2}.");
	}

	public static void AddEnchantmentToLibrary(int recipeScrollItemID, bookCategory category, enchantingType? enchantingMethod = null)
	{
		if (enchantingMethod.HasValue)
		{
			if (enchantingMethod.Value == enchantingType.Sorobor)
			{
				EnchantingLibrary[category].Add(recipeScrollItemID);
			}
			else if (enchantingMethod.Value == enchantingType.NewSirocco)
			{
				BasicNewSiroccoLibrary.Add(recipeScrollItemID);
			}
			else if (enchantingMethod.Value == enchantingType.NewSiroccoExtended)
			{
				AdvancedNewSiroccoLibrary.Add(recipeScrollItemID);
			}
		}
		else
		{
			EnchantingLibrary[category].Add(recipeScrollItemID);
		}
	}

	public static void AddMultipleEnchantmentsToLibrary(List<int> recipeScrollItemIDs, bookCategory category, enchantingType? enchantingMethod = null)
	{
		if (enchantingMethod.HasValue)
		{
			if (enchantingMethod.Value == enchantingType.Sorobor)
			{
				for (int i = 0; i < recipeScrollItemIDs.Count; i++)
				{
					AddEnchantmentToLibrary(recipeScrollItemIDs[i], category);
				}
			}
			else if (enchantingMethod.Value == enchantingType.NewSirocco)
			{
				for (int j = 0; j < recipeScrollItemIDs.Count; j++)
				{
					AddEnchantmentToLibrary(recipeScrollItemIDs[j], category, enchantingType.NewSirocco);
				}
			}
			else if (enchantingMethod.Value == enchantingType.NewSiroccoExtended)
			{
				for (int k = 0; k < recipeScrollItemIDs.Count; k++)
				{
					AddEnchantmentToLibrary(recipeScrollItemIDs[k], category, enchantingType.NewSiroccoExtended);
				}
			}
		}
		else
		{
			for (int l = 0; l < recipeScrollItemIDs.Count; l++)
			{
				AddEnchantmentToLibrary(recipeScrollItemIDs[l], category);
			}
		}
	}

	internal void OnSceneLoaded()
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		Scene activeScene = SceneManager.GetActiveScene();
		string name = ((Scene)(ref activeScene)).name;
		if (name == "AntiqueField_Dungeon2")
		{
			Adjust_AntiqueField_Dungeon2();
		}
		if (name == "NewSirocco")
		{
			Adjust_NewSirocco();
		}
	}

	private void Adjust_AntiqueField_Dungeon2()
	{
		//IL_0004: Unknown result type (might be due to invalid IL or missing references)
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_005c: Expected O, but got Unknown
		//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_0103: Unknown result type (might be due to invalid IL or missing references)
		//IL_0108: Unknown result type (might be due to invalid IL or missing references)
		bool flag = false;
		Scene activeScene = SceneManager.GetActiveScene();
		GameObject[] rootGameObjects = ((Scene)(ref activeScene)).GetRootGameObjects();
		foreach (GameObject val in rootGameObjects)
		{
			if (((Object)val).name == "EnchantingLibrary")
			{
				flag = true;
				break;
			}
		}
		if (flag)
		{
			return;
		}
		GameObject val2 = new GameObject("EnchantingLibrary");
		for (int j = 0; j < EnchantingInfrastructure.Count; j++)
		{
			bookCategory key = (bookCategory)j;
			if (!EnchantingInfrastructure.TryGetValue(key, out var value))
			{
				Log.LogMessage((object)("Could not find shelf data for category: " + key));
				continue;
			}
			GameObject val3 = Object.Instantiate<GameObject>(((Component)ResourcesPrefabManager.Instance.GetItemPrefab(1000000)).gameObject);
			((Object)val3).name = "1000000_Chest_" + key;
			val3.transform.position = value.position;
			val3.transform.rotation = Quaternion.Euler(value.rotation);
			val3.transform.parent = val2.transform;
			ItemContainer component = val3.GetComponent<ItemContainer>();
			if ((Object)(object)component == (Object)null)
			{
				Log.LogMessage((object)("Could not find ItemContainer component on " + ((Object)val3).name));
				continue;
			}
			List<int> value2;
			List<int> list = (EnchantingLibrary.TryGetValue(key, out value2) ? value2 : null);
			if (list == null)
			{
				Log.LogMessage((object)("Could not find items for category: " + key));
				continue;
			}
			if (list.Count == 0)
			{
				Log.LogMessage((object)("No items found for category: " + key));
				continue;
			}
			for (int k = 0; k < list.Count; k++)
			{
				float value3 = ConfigElements.chanceOfRecipeInLibrary_S.Value;
				if (!(Random.value > value3))
				{
					Item itemPrefab = ResourcesPrefabManager.Instance.GetItemPrefab(list[k]);
					if (!((Object)(object)itemPrefab == (Object)null))
					{
						GameObject val4 = Object.Instantiate<GameObject>(((Component)itemPrefab).gameObject, ((Component)component).transform);
					}
				}
			}
			Log.LogMessage((object)$"Added enchanting library with {list.Count} items for the category: {key.ToString()}.");
		}
	}

	private enchantingType NewSiroccoBaseObject(out GameObject targetObject, out GameObject rootObject)
	{
		//IL_0004: Unknown result type (might be due to invalid IL or missing references)
		//IL_0009: 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_00e0: Expected O, but got Unknown
		enchantingType enchantingType = enchantingType.Invalid;
		Scene activeScene = SceneManager.GetActiveScene();
		GameObject[] rootGameObjects = ((Scene)(ref activeScene)).GetRootGameObjects();
		foreach (GameObject val in rootGameObjects)
		{
			if (!((Object)val).name.Contains("9400181_EnchantingGuild"))
			{
				continue;
			}
			GameObject child = GetChild(val, "9400181_EnchantingGuild_v");
			if (!((Object)(object)child != (Object)null))
			{
				continue;
			}
			GameObject child2 = GetChild(child, "Building");
			if (!((Object)(object)child2 != (Object)null))
			{
				continue;
			}
			GameObject child3 = GetChild(child2, "BuildingVisual");
			if (!((Object)(object)child3 != (Object)null))
			{
				continue;
			}
			GameObject child4 = GetChild(child3, "prf_env_bld_BaseBuild_EnchantingGuild_A");
			if (!((Object)(object)child4 != (Object)null))
			{
				continue;
			}
			foreach (Transform item in child4.transform)
			{
				Transform val2 = item;
				if ((((Object)val2).name == "3-Finished" || ((Object)val2).name == "5-Upgrade_B") && ((Component)val2).gameObject.activeSelf)
				{
					enchantingType = enchantingType.NewSirocco;
				}
				else if (((Object)val2).name == "4-Upgrade_A" && ((Component)val2).gameObject.activeSelf)
				{
					enchantingType = enchantingType.NewSiroccoExtended;
				}
				if (enchantingType == enchantingType.Invalid)
				{
					continue;
				}
				GameObject child5 = GetChild(((Component)val2).gameObject, "Props");
				if ((Object)(object)child5 != (Object)null)
				{
					GameObject child6 = GetChild(child5, "mdl_env_propBookCaseBookOpenA");
					if ((Object)(object)child6 != (Object)null)
					{
						targetObject = child6;
						rootObject = ((Component)val2).gameObject;
						return enchantingType;
					}
				}
			}
		}
		targetObject = null;
		rootObject = null;
		return enchantingType.Invalid;
	}

	private void Adjust_NewSirocco()
	{
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		//IL_009c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a3: Expected O, but got Unknown
		//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0114: Unknown result type (might be due to invalid IL or missing references)
		GameObject targetObject;
		GameObject rootObject;
		enchantingType enchantingType = NewSiroccoBaseObject(out targetObject, out rootObject);
		if (enchantingType == enchantingType.Invalid)
		{
			return;
		}
		if ((Object)(object)targetObject == (Object)null)
		{
			Log.LogMessage((object)"targetObject object is null, cannot proceed.");
			return;
		}
		bool flag = false;
		Scene activeScene = SceneManager.GetActiveScene();
		GameObject[] rootGameObjects = ((Scene)(ref activeScene)).GetRootGameObjects();
		foreach (GameObject val in rootGameObjects)
		{
			if (((Object)val).name == "EnchantingLibrary")
			{
				flag = true;
				break;
			}
		}
		if (flag)
		{
			return;
		}
		GameObject val2 = new GameObject("EnchantingLibrary");
		val2.transform.position = targetObject.transform.position - 0.95f * new Vector3(0f, 0.5444031f, 0f);
		GameObject val3 = Object.Instantiate<GameObject>(((Component)ResourcesPrefabManager.Instance.GetItemPrefab(1000000)).gameObject);
		val3.transform.parent = val2.transform;
		val3.transform.localPosition = Vector3.zero;
		ItemContainer component = val3.GetComponent<ItemContainer>();
		if ((Object)(object)component == (Object)null)
		{
			Log.LogMessage((object)("Could not find ItemContainer component on " + ((Object)val3).name));
			return;
		}
		List<int> list;
		switch (enchantingType)
		{
		case enchantingType.NewSirocco:
			list = BasicNewSiroccoLibrary;
			break;
		case enchantingType.NewSiroccoExtended:
			list = AdvancedNewSiroccoLibrary;
			break;
		default:
			Log.LogMessage((object)"Could not find enchanting type for New Sirocco");
			return;
		}
		if (list.Count == 0)
		{
			Log.LogMessage((object)"No items found to be enchanted");
			return;
		}
		for (int j = 0; j < list.Count; j++)
		{
			float num = 1f;
			switch (enchantingType)
			{
			case enchantingType.NewSirocco:
				num = ConfigElements.chanceOfRecipeInLibrary_NS.Value;
				break;
			case enchantingType.NewSiroccoExtended:
				num = ConfigElements.chanceOfRecipeInLibrary_NSEL.Value;
				break;
			}
			if (!(Random.value > num))
			{
				Item itemPrefab = ResourcesPrefabManager.Instance.GetItemPrefab(list[j]);
				if (!((Object)(object)itemPrefab == (Object)null))
				{
					GameObject val4 = Object.Instantiate<GameObject>(((Component)itemPrefab).gameObject, ((Component)component).transform);
				}
			}
		}
		Log.LogMessage((object)$"Added enchanting library with {list.Count} items.");
	}

	internal void OnGameplayResumedAfterLoading()
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		Scene activeScene = SceneManager.GetActiveScene();
		string name = ((Scene)(ref activeScene)).name;
		if (name == "AntiqueField_Dungeon2")
		{
			((MonoBehaviour)Instance).StartCoroutine(SwapVisuals(insertBookMesh: true));
		}
		if (name == "NewSirocco")
		{
			((MonoBehaviour)Instance).StartCoroutine(SwapVisuals(insertBookMesh: true));
		}
	}

	private IEnumerator SwapVisuals(bool insertBookMesh)
	{
		yield return (object)new WaitForSeconds(0.1f);
		Scene activeScene = SceneManager.GetActiveScene();
		GameObject[] rootGameObjects = ((Scene)(ref activeScene)).GetRootGameObjects();
		foreach (GameObject obj in rootGameObjects)
		{
			if (!((Object)obj).name.StartsWith("EnchantingLibrary"))
			{
				continue;
			}
			for (int j = 0; j < obj.transform.childCount; j++)
			{
				GameObject childObject = ((Component)obj.transform.GetChild(j)).gameObject;
				if (!((Object)childObject).name.StartsWith("1000000_Chest"))
				{
					continue;
				}
				ChangeInteractionPoint(childObject, "InteractionHolder");
				GameObject visual = GetChild(childObject, "1000000_ChestSimpleA_v");
				if ((Object)(object)visual != (Object)null)
				{
					GameObject truevisual = GetChild(visual, "mdl_env_propChestSculpt_c (1)");
					if ((Object)(object)truevisual != (Object)null)
					{
						Object.Destroy((Object)(object)truevisual);
					}
					else
					{
						Log.LogMessage((object)"Could not find true visual: mdl_env_propChestSculpt_c (1)");
					}
				}
				else
				{
					Log.LogMessage((object)"Could not find visual: 1000000_ChestSimpleA");
				}
				ChangeName(childObject, "InteractionHolder", "Open <color=#D6A260>Recipe Book</color>");
				ChangeOpenSoundOverride(childObject, (Sounds)15000);
				if (insertBookMesh)
				{
					SpawnLexiconBookMesh(childObject);
				}
			}
		}
	}

	private void SpawnLexiconBookMesh(GameObject parentObject)
	{
		//IL_0076: Unknown result type (might be due to invalid IL or missing references)
		//IL_0097: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
		Transform itemVisualPrefab = ResourcesPrefabManager.Instance.GetItemVisualPrefab("Assets/_Prefabs/_ItemsAssets/5000000_Others/5100000_Trinkets/5100500_BookLexicon_v");
		if ((Object)(object)itemVisualPrefab != (Object)null)
		{
			GameObject gameObject = ((Component)itemVisualPrefab).gameObject;
			if ((Object)(object)gameObject != (Object)null)
			{
				GameObject val = Object.Instantiate<GameObject>(gameObject, parentObject.transform);
				((Object)val).name = "Decorative-RecipeBook";
				if ((Object)(object)val != (Object)null)
				{
					val.transform.localPosition = new Vector3(-0.06f, 0.47f, 0.3f);
					val.transform.localRotation = Quaternion.Euler(25.4058f, 0f, 122.4376f);
					val.transform.localScale = new Vector3(1.25f, 1.25f, 1.25f);
				}
			}
			else
			{
				Log.LogMessage((object)"Could not find lexicon visual prefab at path: Assets/_Prefabs/_ItemsAssets/5000000_Others/5100000_Trinkets/5100500_BookLexicon_v");
			}
		}
		else
		{
			Log.LogMessage((object)"Could not find lexicon visual prefab at path: Assets/_Prefabs/_ItemsAssets/5000000_Others/5100000_Trinkets/5100500_BookLexicon_v");
		}
	}

	private void ChangeOpenSoundOverride(GameObject obj, Sounds newSound)
	{
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		ItemContainer component = obj.GetComponent<ItemContainer>();
		if ((Object)(object)component != (Object)null)
		{
			component.OpenSoundOverride = newSound;
		}
		else
		{
			Log.LogMessage((object)("Could not find ItemContainer component on " + ((Object)obj).name));
		}
	}

	private void ChangeInteractionPoint(GameObject obj, string targetStartsWith)
	{
		for (int i = 0; i < obj.transform.childCount; i++)
		{
			Transform child = obj.transform.GetChild(i);
			if (((Object)child).name.StartsWith(targetStartsWith))
			{
				InteractionTriggerBase component = ((Component)child).GetComponent<InteractionTriggerBase>();
				if ((Object)(object)component != (Object)null)
				{
					component.m_ignoreEnvironmentCollider = true;
				}
			}
		}
	}

	private void ChangeName(GameObject obj, string targetStartsWith, string newName)
	{
		TreasureChest component = obj.GetComponent<TreasureChest>();
		if ((Object)(object)component != (Object)null)
		{
			((Item)component).Name = "Recipe Book";
		}
		GameObject childStartsWith = GetChildStartsWith(obj, targetStartsWith);
		if ((Object)(object)childStartsWith != (Object)null)
		{
			InteractionActivator component2 = childStartsWith.GetComponent<InteractionActivator>();
			if ((Object)(object)component2 != (Object)null)
			{
				((EventActivator)component2).m_overrideHoldText = newName;
			}
			else
			{
				Log.LogMessage((object)("Could not find InteractionActivator component on " + ((Object)childStartsWith).name));
			}
		}
		else
		{
			Log.LogMessage((object)("Could not find interaction object starting with: " + targetStartsWith + " on " + ((Object)obj).name));
		}
	}

	private GameObject GetChild(GameObject parent, string childName)
	{
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Expected O, but got Unknown
		foreach (Transform item in parent.transform)
		{
			Transform val = item;
			if (((Object)val).name == childName)
			{
				return ((Component)val).gameObject;
			}
		}
		return null;
	}

	private GameObject GetChildStartsWith(GameObject parent, string childNameStartsWith)
	{
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Expected O, but got Unknown
		foreach (Transform item in parent.transform)
		{
			Transform val = item;
			if (((Object)val).name.StartsWith(childNameStartsWith))
			{
				return ((Component)val).gameObject;
			}
		}
		return null;
	}
}