using System; using System.Collections; 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.Text; using BepInEx; using HarmonyLib; using Newtonsoft.Json; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.Events; 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("SeriousWikibook")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("SeriousWikibook")] [assembly: AssemblyCopyright("Copyright © 2026")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("ad8ce1b6-0bdb-406a-88db-cff7f8221c83")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: AssemblyVersion("1.0.0.0")] namespace SeriousWikiBook; [BepInPlugin("serious.outward.wikibook", "Serious Wiki Book", "1.21.11")] public class WikiBookPlugin : BaseUnityPlugin { public static readonly int[] WikiBookItemIDs = new int[2] { 5100500, 5100510 }; private const int CleanWaterItemID = 5600000; private static readonly HashSet s_equalBuySellItemIDs = new HashSet { 6200040, 6200070, 6200090, 6200100, 6200110, 6200130, 6200170 }; private static readonly HashSet s_equalBuySellItemNames = new HashSet(StringComparer.Ordinal) { "butchersamethyst", "tinyaquamarine", "largeemerald", "smallsapphire", "mediumruby", "hackmanite", "tourmaline" }; private static readonly HashSet s_unsellableItemIDs = new HashSet { 6200010 }; private static readonly HashSet s_unsellableItemNames = new HashSet(StringComparer.Ordinal) { "tsarstone" }; internal static int OpenActionID = -1; internal static WikiBookPlugin Instance; private GameObject m_wikiWindow; private InventoryMenu m_inventoryMenu; private CharacterUI m_characterUI; private bool m_wikiOpen; private CanvasGroup m_inventoryCanvasGroup; private float m_originalInventoryAlpha; private bool m_originalInventoryInteractable; private bool m_originalInventoryBlocksRaycasts; private InputField m_searchField; private RectTransform m_entryListContent; private ScrollRect m_entryListScrollRect; private Scrollbar m_entryListScrollbar; private RectTransform m_articleContent; private ScrollRect m_articleScrollRect; private Text m_articleTitle; private Text m_articleCategory; private GameObject m_lastSelectedWikiObject; private Button m_activeLeftSourceButton; private Coroutine m_focusCoroutine; private readonly List> m_articleButtonRows = new List>(); private WikiCategory m_currentCategory = WikiCategory.None; private WikiViewState m_currentViewState = WikiViewState.CategoryOverview; private readonly List m_items = new List(); private readonly List m_cookingRecipes = new List(); private readonly List m_alchemyRecipes = new List(); private readonly List m_craftingRecipes = new List(); private readonly List m_enchantments = new List(); private readonly Dictionary m_itemsByGameId = new Dictionary(); private readonly List m_allGameItemPrefabs = new List(); private readonly List m_allGameRecipes = new List(); private readonly List m_allGameEnchantmentRecipes = new List(); private readonly List m_allGameEnchantments = new List(); private readonly Dictionary> m_gameRecipesByResultItemId = new Dictionary>(); private readonly Dictionary> m_recipesByResultItemId = new Dictionary>(); private readonly Dictionary> m_recipesUsingItemId = new Dictionary>(); private readonly Dictionary> m_decraftRecipesUsingItemId = new Dictionary>(); private readonly Dictionary m_enchantmentRecipesByRecipeId = new Dictionary(); private readonly Dictionary> m_enchantmentRecipesByResultId = new Dictionary>(); private readonly Dictionary m_enchantmentsByPresetId = new Dictionary(); private readonly Dictionary> m_compatibleEnchantmentsByItemId = new Dictionary>(); private readonly Dictionary> m_compatibleItemsByEnchantmentResultId = new Dictionary>(); private WikiLocalizationData m_localizationData; private WikiCraftingOverrideFile m_craftingOverrideFile; private WikiLegacyUpgradeFile m_legacyUpgradeFile; private readonly Dictionary> m_legacyUpgradesBySourceItemId = new Dictionary>(); private readonly Dictionary> m_legacyUpgradesByResultItemId = new Dictionary>(); private readonly HashSet m_favorites = new HashSet(StringComparer.Ordinal); private readonly Dictionary m_leftMainToStar = new Dictionary(); private readonly Dictionary m_leftStarToMain = new Dictionary(); private readonly HashSet m_loggedUnsupportedEffectTypes = new HashSet(StringComparer.Ordinal); private string m_favoritesFilePath; private int m_lastBackHandledFrame = -1; private bool m_gameDataCacheBuilt; private Texture2D m_wikiBackgroundTexture; private Sprite m_wikiBackgroundSprite; private Sprite m_backgroundSprite; private Sprite m_buttonSprite; private Color m_buttonColor = Color.white; private Type m_buttonImageType = (Type)0; private Material m_buttonMaterial; private Transition m_buttonTransition = (Transition)1; private ColorBlock m_buttonColors; private SpriteState m_buttonSpriteState; private Font m_buttonFont; private FontStyle m_buttonFontStyle = (FontStyle)0; private Color m_buttonTextColor = Color.white; private int m_buttonFontSize = 20; private TextAnchor m_buttonTextAlignment = (TextAnchor)4; private Sprite m_separatorSprite; private Color m_separatorColor = Color.white; private Font m_outwardFont; private static readonly Dictionary s_englishUiText = new Dictionary(StringComparer.Ordinal); internal bool IsWikiOpen => m_wikiOpen; internal bool IsSearchFieldFocused { get { if (!m_wikiOpen || (Object)(object)m_searchField == (Object)null) { return false; } if (m_searchField.isFocused) { return true; } EventSystem current = EventSystem.current; return (Object)(object)current != (Object)null && (Object)(object)current.currentSelectedGameObject == (Object)(object)((Component)m_searchField).gameObject; } } internal static bool UseEnglishUi { get { try { LocalizationManager instance = LocalizationManager.Instance; if ((Object)(object)instance == (Object)null) { return false; } string text = instance.CurrentLanguage ?? ""; return text.StartsWith("en", StringComparison.OrdinalIgnoreCase) || text.IndexOf("english", StringComparison.OrdinalIgnoreCase) >= 0; } catch { return false; } } } internal static bool IsWikiBookItem(int itemId) { return Extensions.Contains(WikiBookItemIDs, itemId); } internal static string L(string german, string english) { return UseEnglishUi ? english : german; } internal static string GetOpenActionText() { return L("Öffnen", "Open"); } internal static string LocalizeUiText(string text) { if (string.IsNullOrEmpty(text)) { return text ?? ""; } if (TryGetJsonExactTranslation(text, out var translated)) { return translated; } if (!UseEnglishUi) { return text; } if (s_englishUiText.TryGetValue(text, out translated)) { return translated; } if (text.StartsWith("", StringComparison.Ordinal) && text.EndsWith("", StringComparison.Ordinal) && text.Length >= 7) { return "" + LocalizeUiText(text.Substring(3, text.Length - 7)) + ""; } if (text.StartsWith("• ", StringComparison.Ordinal)) { return "• " + LocalizeUiText(text.Substring(2)); } if (text.StartsWith("← Zurück zu ", StringComparison.Ordinal)) { return "← Back to " + text.Substring("← Zurück zu ".Length); } if (text.StartsWith("Gültige Items für ", StringComparison.Ordinal)) { return "Valid items for " + text.Substring("Gültige Items für ".Length); } if (text.StartsWith("Kategorie: ", StringComparison.Ordinal)) { return "Category: " + LocalizeUiText(text.Substring("Kategorie: ".Length)); } if (text.StartsWith("[Verzauberung] ", StringComparison.Ordinal)) { return "[Enchantment] " + text.Substring("[Verzauberung] ".Length); } if (text.StartsWith("[Kochrezepte] ", StringComparison.Ordinal)) { return "[Cooking] " + text.Substring("[Kochrezepte] ".Length); } if (text.StartsWith("[Alchemie] ", StringComparison.Ordinal)) { return "[Alchemy] " + text.Substring("[Alchemie] ".Length); } if (text.StartsWith("[Handwerk] ", StringComparison.Ordinal)) { return "[Crafting] " + text.Substring("[Handwerk] ".Length); } if (text.StartsWith("Verzauberung ", StringComparison.Ordinal)) { return "Enchantment " + text.Substring("Verzauberung ".Length); } if (text.StartsWith("Gewährt: ", StringComparison.Ordinal)) { return "Grants: " + LocalizeEnglishUnits(text.Substring("Gewährt: ".Length)); } if (text.StartsWith("Aufbau von „", StringComparison.Ordinal)) { return "Buildup of “" + text.Substring("Aufbau von „".Length).Replace("“", "”"); } if (text.StartsWith("Entfernt: ", StringComparison.Ordinal)) { return "Removes: " + text.Substring("Entfernt: ".Length); } if (text.StartsWith("Entfernt Statuseffekte mit „", StringComparison.Ordinal)) { return text.Replace("Entfernt Statuseffekte mit „", "Removes status effects containing “").Replace("“ im Namen", "” in their name"); } if (text.StartsWith("Entfernt Statuseffekte vom Typ: ", StringComparison.Ordinal)) { return "Removes status effects of type: " + text.Substring("Entfernt Statuseffekte vom Typ: ".Length); } if (text.StartsWith("Verzauberungsort: ", StringComparison.Ordinal)) { return "Enchanting Location: " + LocalizeUiText(text.Substring("Verzauberungsort: ".Length)); } if (text.StartsWith("Ausbau: ", StringComparison.Ordinal)) { return "Upgrade: " + LocalizeUiText(text.Substring("Ausbau: ".Length)); } if (text.EndsWith(" Treffer gefunden.", StringComparison.Ordinal)) { return text.Substring(0, text.Length - " Treffer gefunden.".Length) + " results found."; } if (text.StartsWith("Es werden maximal ", StringComparison.Ordinal) && text.EndsWith(" Treffer angezeigt.", StringComparison.Ordinal)) { string text2 = text.Substring("Es werden maximal ".Length, text.Length - "Es werden maximal ".Length - " Treffer angezeigt.".Length); return "A maximum of " + text2 + " results is shown."; } int num = text.IndexOf(':'); if (num > 0) { string text3 = text.Substring(0, num); string text4 = TranslateDynamicLabel(text3); if (!string.Equals(text3, text4, StringComparison.Ordinal)) { string text5 = text.Substring(num + 1); string text6 = (text5.StartsWith(" ", StringComparison.Ordinal) ? " " : ""); string text7 = text5.TrimStart(Array.Empty()); return text4 + ":" + text6 + LocalizeUiText(text7); } } return LocalizeEnglishUnits(ApplyEnglishPhraseReplacements(text)); } private static string TranslateDynamicLabel(string label) { if (string.IsNullOrEmpty(label)) { return label ?? ""; } if (TryGetJsonExactTranslation(label, out var translated)) { return translated; } if (s_englishUiText.TryGetValue(label, out translated)) { return translated; } if (string.Equals(label, "Kapazität", StringComparison.Ordinal)) { return "Capacity"; } if (label.EndsWith("-Resistenz", StringComparison.Ordinal)) { string text = label.Substring(0, label.Length - "-Resistenz".Length); return LocalizeUiText(text) + " Resistance"; } if (label.EndsWith("-Schadensmodifikator", StringComparison.Ordinal)) { string text2 = label.Substring(0, label.Length - "-Schadensmodifikator".Length); return LocalizeUiText(text2) + " Damage Modifier"; } if (label.EndsWith("-Bonusschaden", StringComparison.Ordinal)) { string text3 = label.Substring(0, label.Length - "-Bonusschaden".Length); return LocalizeUiText(text3) + " Bonus Damage"; } if (label.StartsWith("Aufbau von „", StringComparison.Ordinal)) { return "Buildup of “" + label.Substring("Aufbau von „".Length); } return label; } private static bool TryGetJsonExactTranslation(string text, out string translated) { translated = null; WikiBookPlugin instance = Instance; WikiLocalizationData wikiLocalizationData = (((Object)(object)instance == (Object)null) ? null : instance.m_localizationData); if (wikiLocalizationData == null || wikiLocalizationData.exact == null || string.IsNullOrEmpty(text)) { return false; } if (!wikiLocalizationData.exact.TryGetValue(text, out var value) || value == null) { return false; } translated = (UseEnglishUi ? value.en : value.de); if (string.IsNullOrWhiteSpace(translated)) { translated = (UseEnglishUi ? value.de : value.en); } return !string.IsNullOrWhiteSpace(translated); } private static string LocalizeDataKey(string key, string germanFallback, string englishFallback) { WikiBookPlugin instance = Instance; WikiLocalizationData wikiLocalizationData = (((Object)(object)instance == (Object)null) ? null : instance.m_localizationData); if (wikiLocalizationData != null && wikiLocalizationData.sourceTypeKeys != null && !string.IsNullOrWhiteSpace(key) && wikiLocalizationData.sourceTypeKeys.TryGetValue(key, out var value) && value != null) { string text = (UseEnglishUi ? value.en : value.de); if (string.IsNullOrWhiteSpace(text)) { text = (UseEnglishUi ? value.de : value.en); } if (!string.IsNullOrWhiteSpace(text)) { return text; } } return L(germanFallback, englishFallback); } private static string ApplyJsonReplacementRules(string text, IEnumerable rules) { if (string.IsNullOrEmpty(text) || rules == null) { return text ?? ""; } List list = (from rule in rules where rule != null && !string.IsNullOrEmpty(rule.de) orderby rule.de.Length descending select rule).ToList(); if (list.Count == 0) { return text; } StringBuilder stringBuilder = new StringBuilder(text.Length + 32); int num = 0; while (num < text.Length) { WikiReplacementRule wikiReplacementRule = null; foreach (WikiReplacementRule item in list) { if (num + item.de.Length > text.Length || string.CompareOrdinal(text, num, item.de, 0, item.de.Length) != 0) { continue; } wikiReplacementRule = item; break; } if (wikiReplacementRule == null) { stringBuilder.Append(text[num]); num++; } else { string text2 = (UseEnglishUi ? wikiReplacementRule.en : wikiReplacementRule.de); stringBuilder.Append(text2 ?? ""); num += wikiReplacementRule.de.Length; } } return stringBuilder.ToString(); } private static string ApplyEnglishPhraseReplacements(string text) { if (string.IsNullOrEmpty(text)) { return text ?? ""; } WikiBookPlugin instance = Instance; return ApplyJsonReplacementRules(text, (((Object)(object)instance == (Object)null) ? null : instance.m_localizationData)?.phraseReplacements); } private static string LocalizeEnglishUnits(string text) { if (string.IsNullOrEmpty(text)) { return text ?? ""; } WikiBookPlugin instance = Instance; text = ApplyJsonReplacementRules(text, (((Object)(object)instance == (Object)null) ? null : instance.m_localizationData)?.unitReplacements); return ApplyEnglishPhraseReplacements(text); } internal bool ShouldBlockInventoryHide(InventoryMenu menu) { if (!m_wikiOpen || !IsSearchFieldFocused) { return false; } return (Object)(object)m_inventoryMenu == (Object)null || (Object)(object)menu == (Object)(object)m_inventoryMenu; } internal bool ShouldHandleCharacterUICancel(CharacterUI characterUI) { if (!m_wikiOpen) { return false; } return (Object)(object)m_characterUI == (Object)null || (Object)(object)characterUI == (Object)(object)m_characterUI; } internal bool ShouldBlockCharacterUIInput(CharacterUI characterUI) { if (!m_wikiOpen) { return false; } if (!IsSearchFieldFocused) { return false; } return (Object)(object)m_characterUI == (Object)null || (Object)(object)characterUI == (Object)(object)m_characterUI; } private void Awake() { //IL_001d: Unknown result type (might be due to invalid IL or missing references) Instance = this; ((BaseUnityPlugin)this).Logger.LogInfo((object)"WikiBook 1.21.11 wird geladen..."); new Harmony("serious.outward.wikibook").PatchAll(); LoadWikiBackground(); LoadWikiData(); LoadFavorites(); ((BaseUnityPlugin)this).Logger.LogInfo((object)"WikiBook 1.21.11 wurde geladen."); } private void Update() { if (!m_wikiOpen) { return; } SyncSearchFieldWithCharacterUI(); EventSystem current = EventSystem.current; if ((Object)(object)current == (Object)null || (Object)(object)current.currentSelectedGameObject == (Object)null) { return; } GameObject currentSelectedGameObject = current.currentSelectedGameObject; if (!((Object)(object)currentSelectedGameObject == (Object)(object)m_lastSelectedWikiObject)) { m_lastSelectedWikiObject = currentSelectedGameObject; if ((Object)(object)m_entryListContent != (Object)null && currentSelectedGameObject.transform.IsChildOf((Transform)(object)m_entryListContent)) { EnsureListElementVisible(currentSelectedGameObject.GetComponent()); } if ((Object)(object)m_articleContent != (Object)null && currentSelectedGameObject.transform.IsChildOf((Transform)(object)m_articleContent)) { EnsureArticleElementVisible(currentSelectedGameObject.GetComponent()); } } } private void SyncSearchFieldWithCharacterUI() { if (m_wikiOpen && !((Object)(object)m_searchField == (Object)null) && m_searchField.isFocused && !((Object)(object)m_characterUI == (Object)null)) { GameObject gameObject = ((Component)m_searchField).gameObject; if ((Object)(object)m_characterUI.CurrentSelectedGameObject != (Object)(object)gameObject || (Object)(object)m_characterUI.EventSystemCurrentSelectedGo != (Object)(object)gameObject) { m_characterUI.SetSelectedGameObject(gameObject); } } } private void LoadWikiBackground() { //IL_008d: Unknown result type (might be due to invalid IL or missing references) //IL_0093: Expected O, but got Unknown //IL_00fe: Unknown result type (might be due to invalid IL or missing references) //IL_010d: Unknown result type (might be due to invalid IL or missing references) try { string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); if (string.IsNullOrEmpty(directoryName)) { return; } string text = Path.Combine(directoryName, "WikiBG.png"); ((BaseUnityPlugin)this).Logger.LogInfo((object)("Suche Wiki-Hintergrund: " + text)); if (!File.Exists(text)) { ((BaseUnityPlugin)this).Logger.LogWarning((object)"WikiBG.png wurde nicht gefunden."); return; } byte[] array = File.ReadAllBytes(text); if (array != null && array.Length != 0) { Texture2D val = new Texture2D(2, 2, (TextureFormat)5, false); if (!ImageConversion.LoadImage(val, array)) { Object.Destroy((Object)(object)val); ((BaseUnityPlugin)this).Logger.LogWarning((object)"WikiBG.png konnte nicht geladen werden."); return; } ((Object)val).name = "SeriousWikiBackgroundTexture"; ((Texture)val).wrapMode = (TextureWrapMode)1; ((Texture)val).filterMode = (FilterMode)1; m_wikiBackgroundTexture = val; m_wikiBackgroundSprite = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f), 100f); ((Object)m_wikiBackgroundSprite).name = "SeriousWikiBackgroundSprite"; ((BaseUnityPlugin)this).Logger.LogInfo((object)("WikiBG.png erfolgreich geladen: " + ((Texture)val).width + "x" + ((Texture)val).height)); } } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogError((object)"Fehler beim Laden von WikiBG.png:"); ((BaseUnityPlugin)this).Logger.LogError((object)ex); } } internal void OpenWiki() { if (m_wikiOpen) { return; } ((BaseUnityPlugin)this).Logger.LogInfo((object)"Versuche eigenständiges Wiki zu öffnen..."); if (m_items.Count == 0 && m_cookingRecipes.Count == 0 && m_alchemyRecipes.Count == 0 && m_craftingRecipes.Count == 0 && m_enchantments.Count == 0) { LoadWikiData(); } BuildGameDataCache(); m_inventoryMenu = Object.FindObjectOfType(); if ((Object)(object)m_inventoryMenu == (Object)null) { ((BaseUnityPlugin)this).Logger.LogError((object)"Kein InventoryMenu gefunden."); return; } ((BaseUnityPlugin)this).Logger.LogInfo((object)("InventoryMenu gefunden: " + ((Object)((Component)m_inventoryMenu).gameObject).name)); m_characterUI = ((Component)m_inventoryMenu).GetComponentInParent(); if ((Object)(object)m_characterUI == (Object)null) { m_characterUI = Object.FindObjectOfType(); } if ((Object)(object)m_characterUI != (Object)null) { ((BaseUnityPlugin)this).Logger.LogInfo((object)("CharacterUI gefunden. RewiredID=" + m_characterUI.RewiredID)); } else { ((BaseUnityPlugin)this).Logger.LogWarning((object)"Kein CharacterUI gefunden. Die native InputField-Sperre kann dann nicht greifen."); } ExtractOutwardStyles(); Canvas componentInParent = ((Component)m_inventoryMenu).GetComponentInParent(); if ((Object)(object)componentInParent == (Object)null || (Object)(object)componentInParent.rootCanvas == (Object)null) { ((BaseUnityPlugin)this).Logger.LogError((object)"Kein Root-Canvas gefunden."); return; } BuildWikiWindow(((Component)componentInParent.rootCanvas).transform); if (!((Object)(object)m_wikiWindow == (Object)null)) { m_inventoryCanvasGroup = ((Component)m_inventoryMenu).GetComponent(); if ((Object)(object)m_inventoryCanvasGroup != (Object)null) { m_originalInventoryAlpha = m_inventoryCanvasGroup.alpha; m_originalInventoryInteractable = m_inventoryCanvasGroup.interactable; m_originalInventoryBlocksRaycasts = m_inventoryCanvasGroup.blocksRaycasts; m_inventoryCanvasGroup.alpha = 0f; m_inventoryCanvasGroup.interactable = false; m_inventoryCanvasGroup.blocksRaycasts = false; ((BaseUnityPlugin)this).Logger.LogInfo((object)"Inventar wurde für das Wiki unsichtbar gemacht."); } m_wikiWindow.SetActive(true); m_wikiWindow.transform.SetAsLastSibling(); m_wikiOpen = true; m_lastSelectedWikiObject = null; ShowCategoryOverview(); ((BaseUnityPlugin)this).Logger.LogInfo((object)"Wiki wurde geöffnet."); } } private void BuildGameDataCache() { if (!m_gameDataCacheBuilt) { m_allGameItemPrefabs.Clear(); m_allGameRecipes.Clear(); m_allGameEnchantmentRecipes.Clear(); m_allGameEnchantments.Clear(); m_gameRecipesByResultItemId.Clear(); m_recipesByResultItemId.Clear(); m_recipesUsingItemId.Clear(); m_decraftRecipesUsingItemId.Clear(); m_enchantmentRecipesByRecipeId.Clear(); m_enchantmentRecipesByResultId.Clear(); m_enchantmentsByPresetId.Clear(); m_compatibleEnchantmentsByItemId.Clear(); m_compatibleItemsByEnchantmentResultId.Clear(); m_legacyUpgradesBySourceItemId.Clear(); m_legacyUpgradesByResultItemId.Clear(); bool flag = TryLoadItemPrefabsFromPrivateDictionary(); bool flag2 = TryLoadRecipesFromPrivateDictionary(); bool flag3 = TryLoadEnchantmentRecipesFromRecipeManager(); bool flag4 = TryLoadEnchantmentPrefabsFromPrivateDictionary(); if (!flag || !flag2) { TryLoadGameDataFromAssetBundles(!flag, !flag2); } TryLoadEnchantmentDataFromAssetBundles(!flag4, !flag3); ResolveLegacyUpgradeRuntimeData(); BuildGameRecipeLookups(); BuildRecipeRelationshipLookups(); BuildEnchantmentLookups(); BindWikiEnchantmentsToRuntime(); BuildEnchantmentCompatibilityLookups(); m_gameDataCacheBuilt = true; ((BaseUnityPlugin)this).Logger.LogInfo((object)"Outward-Spieldaten gecacht."); ((BaseUnityPlugin)this).Logger.LogInfo((object)("Echte Item-Prefabs: " + m_allGameItemPrefabs.Count)); ((BaseUnityPlugin)this).Logger.LogInfo((object)("Echte Rezepte: " + m_allGameRecipes.Count)); ((BaseUnityPlugin)this).Logger.LogInfo((object)("Echte Verzauberungsrezepte: " + m_allGameEnchantmentRecipes.Count)); ((BaseUnityPlugin)this).Logger.LogInfo((object)("Echte Verzauberungen: " + m_allGameEnchantments.Count)); ((BaseUnityPlugin)this).Logger.LogInfo((object)("Item->Herstellung Beziehungen: " + m_recipesByResultItemId.Count)); ((BaseUnityPlugin)this).Logger.LogInfo((object)("Item->Verwendet-in Beziehungen: " + m_recipesUsingItemId.Count)); ((BaseUnityPlugin)this).Logger.LogInfo((object)("Item->Verzauberungen Beziehungen: " + m_compatibleEnchantmentsByItemId.Count)); } } private void ResolveLegacyUpgradeRuntimeData() { m_legacyUpgradesBySourceItemId.Clear(); m_legacyUpgradesByResultItemId.Clear(); if (m_legacyUpgradeFile == null || m_legacyUpgradeFile.upgrades == null) { return; } int num = 0; int num2 = 0; int num3 = 0; int num4 = 0; foreach (WikiLegacyUpgradeData upgrade in m_legacyUpgradeFile.upgrades) { if (upgrade == null) { continue; } bool flag = upgrade.resolveMissingIdsFromRuntimeName || (m_legacyUpgradeFile.indexPolicy != null && (m_legacyUpgradeFile.indexPolicy.resolveZeroIdsFromRuntimeItemNames || m_legacyUpgradeFile.indexPolicy.resolveFromAliases)); int sourceItemId = upgrade.sourceItemId; int resultItemId = upgrade.resultItemId; if (flag) { upgrade.sourceItemId = ResolveLegacyRuntimeItemId(upgrade, source: true); upgrade.resultItemId = ResolveLegacyRuntimeItemId(upgrade, source: false); } if ((sourceItemId <= 0 && upgrade.sourceItemId > 0) || (resultItemId <= 0 && upgrade.resultItemId > 0)) { num4++; } bool flag2 = upgrade.includeSourceInItemIndex || upgrade.includeSourceInGlobalSearch || (m_legacyUpgradeFile.indexPolicy != null && (m_legacyUpgradeFile.indexPolicy.includeAllSourceItemsInItems || m_legacyUpgradeFile.indexPolicy.includeAllSourceItemsInGlobalSearch)); bool flag3 = upgrade.includeResultInItemIndex || upgrade.includeResultInGlobalSearch || (m_legacyUpgradeFile.indexPolicy != null && (m_legacyUpgradeFile.indexPolicy.includeAllResultItemsInItems || m_legacyUpgradeFile.indexPolicy.includeAllResultItemsInGlobalSearch)); if (upgrade.sourceItemId > 0) { num++; if (flag2) { EnsureWikiItemEntry(upgrade.sourceItemId, GetLegacyPreferredName(upgrade, source: true), "ADDED FROM LEGACY UPGRADES"); } AddToLookup(m_legacyUpgradesBySourceItemId, upgrade.sourceItemId, upgrade); } if (upgrade.resultItemId > 0) { num2++; WikiItemData wikiItemData = (flag3 ? EnsureWikiItemEntry(upgrade.resultItemId, GetLegacyPreferredName(upgrade, source: false), "ADDED FROM LEGACY UPGRADES") : GetItemByGameId(upgrade.resultItemId)); if (wikiItemData != null && string.IsNullOrWhiteSpace(wikiItemData.sourceTypeKey)) { wikiItemData.sourceTypeKey = ((!string.IsNullOrWhiteSpace(upgrade.sourceTypeKey)) ? upgrade.sourceTypeKey : m_legacyUpgradeFile.sourceTypeKey); } AddToLookup(m_legacyUpgradesByResultItemId, upgrade.resultItemId, upgrade); } if (upgrade.sourceItemId <= 0 || upgrade.resultItemId <= 0) { num3++; } } ((BaseUnityPlugin)this).Logger.LogInfo((object)("Legacy-Upgrades aufgelöst: Quellen=" + num + ", Ergebnisse=" + num2 + ", per Alias ergänzt=" + num4 + ", unvollständig=" + num3)); if (m_legacyUpgradeFile.validation != null && m_legacyUpgradeFile.validation.expectedUpgradeCount > 0 && m_legacyUpgradeFile.validation.expectedUpgradeCount != m_legacyUpgradeFile.upgrades.Count) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("Legacy-Upgrades: Erwartet=" + m_legacyUpgradeFile.validation.expectedUpgradeCount + ", geladen=" + m_legacyUpgradeFile.upgrades.Count)); } } private int ResolveLegacyRuntimeItemId(WikiLegacyUpgradeData upgrade, bool source) { if (upgrade == null) { return 0; } int num = (source ? upgrade.sourceItemId : upgrade.resultItemId); List requestedNames = GetLegacyLookupNames(upgrade, source).ToList(); Item cachedGameItemPrefab = GetCachedGameItemPrefab(num); bool flag = string.Equals(upgrade.idStatus, "verified", StringComparison.OrdinalIgnoreCase) || (m_legacyUpgradeFile != null && m_legacyUpgradeFile.indexPolicy != null && m_legacyUpgradeFile.indexPolicy.preferVerifiedItemIds); if ((Object)(object)cachedGameItemPrefab != (Object)null) { if (flag || LegacyRuntimeItemMatchesNames(cachedGameItemPrefab, requestedNames)) { return num; } ((BaseUnityPlugin)this).Logger.LogWarning((object)("Legacy-ID passt nicht zum Namen und wird neu aufgelöst: " + num + " | " + GetLegacyPreferredName(upgrade, source))); } string context = (source ? ("Quelle: " + GetLegacyPreferredName(upgrade, source: true)) : ("Ergebnis: " + GetLegacyPreferredName(upgrade, source: false))); return ResolveRuntimeItemIdByNames(requestedNames, context); } private IEnumerable GetLegacyLookupNames(WikiLegacyUpgradeData upgrade, bool source) { if (upgrade == null) { yield break; } string fallbackName = (source ? upgrade.sourceFallbackName : upgrade.resultFallbackName); string wikiName = (source ? upgrade.sourceWikiName : upgrade.resultWikiName); List aliases = (source ? upgrade.sourceAliases : upgrade.resultAliases); if (!string.IsNullOrWhiteSpace(fallbackName)) { yield return fallbackName; } if (!string.IsNullOrWhiteSpace(wikiName)) { yield return wikiName; } if (aliases == null) { yield break; } foreach (string alias in aliases) { if (!string.IsNullOrWhiteSpace(alias)) { yield return alias; } } } private string GetLegacyPreferredName(WikiLegacyUpgradeData upgrade, bool source) { if (upgrade == null) { return ""; } string text = (source ? upgrade.sourceFallbackName : upgrade.resultFallbackName); if (!string.IsNullOrWhiteSpace(text)) { return text; } string text2 = (source ? upgrade.sourceWikiName : upgrade.resultWikiName); if (!string.IsNullOrWhiteSpace(text2)) { return text2; } List list = (source ? upgrade.sourceAliases : upgrade.resultAliases); if (list != null) { string text3 = list.FirstOrDefault((string x) => !string.IsNullOrWhiteSpace(x)); if (!string.IsNullOrWhiteSpace(text3)) { return text3; } } return ""; } private bool LegacyRuntimeItemMatchesNames(Item item, IEnumerable requestedNames) { if ((Object)(object)item == (Object)null || requestedNames == null) { return false; } HashSet hashSet = new HashSet(from x in requestedNames.Where((string x) => !string.IsNullOrWhiteSpace(x)).Select(NormalizeLegacyItemName) where !string.IsNullOrWhiteSpace(x) select x, StringComparer.Ordinal); if (hashSet.Count == 0) { return true; } foreach (string runtimeItemNameAlias in GetRuntimeItemNameAliases(item)) { string text = NormalizeLegacyItemName(runtimeItemNameAlias); if (hashSet.Contains(text)) { return true; } foreach (string item2 in hashSet) { if (text.EndsWith(item2, StringComparison.Ordinal)) { return true; } } } return false; } private int ResolveRuntimeItemIdByNames(IEnumerable requestedNames, string context) { if (requestedNames == null) { return 0; } List list = (from x in requestedNames.Where((string x) => !string.IsNullOrWhiteSpace(x)).Select(NormalizeLegacyItemName) where !string.IsNullOrWhiteSpace(x) select x).Distinct(StringComparer.Ordinal).ToList(); if (list.Count == 0) { return 0; } int num = 0; List list2 = new List(); foreach (Item allGameItemPrefab in m_allGameItemPrefabs) { if (!IsPlayerFacingWikiItem(allGameItemPrefab)) { continue; } int num2 = 0; foreach (string runtimeItemNameAlias in GetRuntimeItemNameAliases(allGameItemPrefab)) { string text = NormalizeLegacyItemName(runtimeItemNameAlias); if (string.IsNullOrWhiteSpace(text)) { continue; } foreach (string item in list) { if (text == item) { num2 = Math.Max(num2, 1000); } else if (text.EndsWith(item, StringComparison.Ordinal) || item.EndsWith(text, StringComparison.Ordinal)) { num2 = Math.Max(num2, 950); } else if (item.Length >= 7 && text.Length >= 7 && (text.Contains(item) || item.Contains(text))) { num2 = Math.Max(num2, 700); } } } if (num2 > 0) { if (num2 > num) { num = num2; list2.Clear(); list2.Add(allGameItemPrefab); } else if (num2 == num) { list2.Add(allGameItemPrefab); } } } List list3 = (from item in list2 where (Object)(object)item != (Object)null group item by item.ItemID into @group select @group.First()).ToList(); if (num >= 700 && list3.Count == 1) { return list3[0].ItemID; } if (list3.Count > 1) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("Legacy-Itemname ist mehrdeutig: " + context + " | Treffer=" + list3.Count + " | Namen=" + string.Join(", ", requestedNames.ToArray()))); } else { ((BaseUnityPlugin)this).Logger.LogWarning((object)("Legacy-Item nicht aufgelöst: " + context + " | Namen=" + string.Join(", ", requestedNames.ToArray()))); } return 0; } private int ResolveRuntimeItemIdByName(string requestedName) { return ResolveRuntimeItemIdByNames(new string[1] { requestedName }, requestedName); } private string NormalizeLegacyItemName(string value) { string text = NormalizeLookupText(value); if (string.IsNullOrWhiteSpace(text)) { return ""; } int i; for (i = 0; i < text.Length && char.IsDigit(text[i]); i++) { } if (i > 0 && i < text.Length) { text = text.Substring(i); } return text.Replace("sabre", "saber").Replace("helmet", "helm"); } private Item GetCachedGameItemPrefab(int gameItemId) { if (gameItemId <= 0) { return null; } return ((IEnumerable)m_allGameItemPrefabs).FirstOrDefault((Func)((Item item) => (Object)(object)item != (Object)null && item.ItemID == gameItemId)); } private IEnumerable GetRuntimeItemNameAliases(Item item) { if (!((Object)(object)item == (Object)null)) { string displayName = GetGameItemDisplayName(item); if (!string.IsNullOrWhiteSpace(displayName)) { yield return displayName; } if (!string.IsNullOrWhiteSpace(((Object)item).name)) { yield return ((Object)item).name; } string reflectedName = GetStringMember(item, "Name", "EDITOR_Name", "EditorName", "ItemName", "PrefabName", "LocalizationKey", "LocalizationID"); if (!string.IsNullOrWhiteSpace(reflectedName)) { yield return reflectedName; } } } private bool TryLoadItemPrefabsFromPrivateDictionary() { try { FieldInfo fieldInfo = AccessTools.Field(typeof(ResourcesPrefabManager), "ITEM_PREFABS"); if (fieldInfo == null) { ((BaseUnityPlugin)this).Logger.LogWarning((object)"ITEM_PREFABS-Feld wurde nicht gefunden."); return false; } if (!(fieldInfo.GetValue(null) is IDictionary dictionary)) { ((BaseUnityPlugin)this).Logger.LogWarning((object)"ITEM_PREFABS konnte nicht als IDictionary gelesen werden."); return false; } HashSet hashSet = new HashSet(); foreach (DictionaryEntry item in dictionary) { object? value = item.Value; Item val = (Item)((value is Item) ? value : null); if (!((Object)(object)val == (Object)null) && val.ItemID > 0 && hashSet.Add(val.ItemID)) { m_allGameItemPrefabs.Add(val); } } ((BaseUnityPlugin)this).Logger.LogInfo((object)("ITEM_PREFABS per Reflection gelesen: " + m_allGameItemPrefabs.Count)); return m_allGameItemPrefabs.Count > 0; } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogError((object)"Fehler beim Lesen von ITEM_PREFABS:"); ((BaseUnityPlugin)this).Logger.LogError((object)ex); return false; } } private bool TryLoadRecipesFromPrivateDictionary() { try { FieldInfo fieldInfo = AccessTools.Field(typeof(RecipeManager), "m_recipes"); if (fieldInfo == null) { ((BaseUnityPlugin)this).Logger.LogWarning((object)"RecipeManager.m_recipes wurde nicht gefunden."); return false; } if (!(fieldInfo.GetValue(RecipeManager.Instance) is IDictionary dictionary)) { ((BaseUnityPlugin)this).Logger.LogWarning((object)"RecipeManager.m_recipes konnte nicht als IDictionary gelesen werden."); return false; } HashSet hashSet = new HashSet(); foreach (DictionaryEntry item in dictionary) { object? value = item.Value; Recipe val = (Recipe)((value is Recipe) ? value : null); if (!((Object)(object)val == (Object)null) && (val.RecipeID == 0 || hashSet.Add(val.RecipeID))) { m_allGameRecipes.Add(val); } } ((BaseUnityPlugin)this).Logger.LogInfo((object)("RecipeManager.m_recipes per Reflection gelesen: " + m_allGameRecipes.Count)); return m_allGameRecipes.Count > 0; } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogError((object)"Fehler beim Lesen von RecipeManager.m_recipes:"); ((BaseUnityPlugin)this).Logger.LogError((object)ex); return false; } } private void TryLoadGameDataFromAssetBundles(bool loadItems, bool loadRecipes) { try { HashSet hashSet = new HashSet(m_allGameItemPrefabs.Select((Item x) => x.ItemID)); HashSet hashSet2 = new HashSet(from x in m_allGameRecipes where (Object)(object)x != (Object)null select x.RecipeID); DictionaryExt> objectAssetsPerBundle = ResourcesPrefabManager.ObjectAssetsPerBundle; if (objectAssetsPerBundle == null) { return; } foreach (string key in objectAssetsPerBundle.Keys) { List list = objectAssetsPerBundle[key]; if (list == null) { continue; } foreach (Object item in list) { if (item == (Object)null) { continue; } if (loadItems) { GameObject val = (GameObject)(object)((item is GameObject) ? item : null); if ((Object)(object)val != (Object)null) { Item component = val.GetComponent(); if ((Object)(object)component != (Object)null && component.ItemID > 0 && hashSet.Add(component.ItemID)) { m_allGameItemPrefabs.Add(component); } } } if (loadRecipes) { Recipe val2 = (Recipe)(object)((item is Recipe) ? item : null); if ((Object)(object)val2 != (Object)null && (val2.RecipeID == 0 || hashSet2.Add(val2.RecipeID))) { m_allGameRecipes.Add(val2); } } } } ((BaseUnityPlugin)this).Logger.LogInfo((object)"Fallback-Asset-Suche abgeschlossen."); } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogError((object)"Fallback-Asset-Suche fehlgeschlagen:"); ((BaseUnityPlugin)this).Logger.LogError((object)ex); } } private bool TryLoadEnchantmentRecipesFromRecipeManager() { try { RecipeManager instance = RecipeManager.Instance; if (instance == null) { ((BaseUnityPlugin)this).Logger.LogWarning((object)"RecipeManager.Instance ist null. EnchantmentRecipe-Fallback wird benutzt."); return false; } MethodInfo method = typeof(RecipeManager).GetMethod("GetEnchantmentRecipes", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, Type.EmptyTypes, null); if (method == null) { ((BaseUnityPlugin)this).Logger.LogWarning((object)"RecipeManager.GetEnchantmentRecipes() wurde nicht gefunden. AssetBundle-Fallback wird benutzt."); return false; } object obj = method.Invoke(instance, null); if (!(obj is IEnumerable enumerable)) { ((BaseUnityPlugin)this).Logger.LogWarning((object)"GetEnchantmentRecipes() lieferte keine auflistbare Sammlung."); return false; } HashSet hashSet = new HashSet(); HashSet hashSet2 = new HashSet(StringComparer.Ordinal); foreach (object item2 in enumerable) { EnchantmentRecipe val = (EnchantmentRecipe)((item2 is EnchantmentRecipe) ? item2 : null); if ((Object)(object)val == (Object)null && item2 is DictionaryEntry) { object? value = ((DictionaryEntry)item2).Value; val = (EnchantmentRecipe)((value is EnchantmentRecipe) ? value : null); } if ((Object)(object)val == (Object)null && item2 != null) { try { PropertyInfo property = item2.GetType().GetProperty("Value", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (property != null) { object? value2 = property.GetValue(item2, null); val = (EnchantmentRecipe)((value2 is EnchantmentRecipe) ? value2 : null); } } catch { } } if ((Object)(object)val == (Object)null) { continue; } try { if (val.RecipeID < 0) { val.InitID(); } } catch { } int recipeID = val.RecipeID; string item = ((Object)val).name ?? ""; if ((recipeID > 0 && hashSet.Add(recipeID)) || (recipeID <= 0 && hashSet2.Add(item))) { m_allGameEnchantmentRecipes.Add(val); } } ((BaseUnityPlugin)this).Logger.LogInfo((object)("EnchantmentRecipes aus RecipeManager geladen: " + m_allGameEnchantmentRecipes.Count)); return m_allGameEnchantmentRecipes.Count > 0; } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogError((object)"Fehler beim Laden der EnchantmentRecipes aus RecipeManager:"); ((BaseUnityPlugin)this).Logger.LogError((object)ex); return false; } } private bool TryLoadEnchantmentPrefabsFromPrivateDictionary() { try { FieldInfo fieldInfo = AccessTools.Field(typeof(ResourcesPrefabManager), "ENCHANTMENT_PREFABS"); if (fieldInfo == null) { ((BaseUnityPlugin)this).Logger.LogWarning((object)"ENCHANTMENT_PREFABS-Feld wurde nicht gefunden. AssetBundle-Fallback wird benutzt."); return false; } if (!(fieldInfo.GetValue(null) is IDictionary dictionary)) { return false; } HashSet hashSet = new HashSet(); foreach (DictionaryEntry item in dictionary) { object? value = item.Value; Enchantment val = (Enchantment)((value is Enchantment) ? value : null); if ((Object)(object)val == (Object)null) { object? value2 = item.Value; GameObject val2 = (GameObject)((value2 is GameObject) ? value2 : null); if ((Object)(object)val2 != (Object)null) { val = val2.GetComponent(); } } if (!((Object)(object)val == (Object)null)) { int intMember = GetIntMember(val, "PresetID"); if (intMember > 0 && hashSet.Add(intMember)) { m_allGameEnchantments.Add(val); } } } ((BaseUnityPlugin)this).Logger.LogInfo((object)("ENCHANTMENT_PREFABS per Reflection gelesen: " + m_allGameEnchantments.Count)); return m_allGameEnchantments.Count > 0; } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("ENCHANTMENT_PREFABS konnten nicht gelesen werden: " + ex.Message)); return false; } } private void TryLoadEnchantmentDataFromAssetBundles(bool loadEnchantments, bool loadRecipes) { try { HashSet hashSet = new HashSet(); HashSet hashSet2 = new HashSet(StringComparer.Ordinal); HashSet hashSet3 = new HashSet(from x in m_allGameEnchantments select GetIntMember(x, "PresetID") into x where x > 0 select x); DictionaryExt> objectAssetsPerBundle = ResourcesPrefabManager.ObjectAssetsPerBundle; if (objectAssetsPerBundle == null) { return; } foreach (string key in objectAssetsPerBundle.Keys) { List list = objectAssetsPerBundle[key]; if (list == null) { continue; } foreach (Object item2 in list) { if (item2 == (Object)null) { continue; } if (loadRecipes) { EnchantmentRecipe val = (EnchantmentRecipe)(object)((item2 is EnchantmentRecipe) ? item2 : null); if ((Object)(object)val != (Object)null) { try { if (val.RecipeID < 0) { val.InitID(); } } catch { } int recipeID = val.RecipeID; string item = ((Object)val).name ?? ""; if ((recipeID > 0 && hashSet.Add(recipeID)) || (recipeID <= 0 && hashSet2.Add(item))) { m_allGameEnchantmentRecipes.Add(val); } } } if (!loadEnchantments) { continue; } GameObject val2 = (GameObject)(object)((item2 is GameObject) ? item2 : null); if ((Object)(object)val2 == (Object)null) { continue; } Enchantment component = val2.GetComponent(); if (!((Object)(object)component == (Object)null)) { int intMember = GetIntMember(component, "PresetID"); if (intMember > 0 && hashSet3.Add(intMember)) { m_allGameEnchantments.Add(component); } } } } ((BaseUnityPlugin)this).Logger.LogInfo((object)"Enchantment-Asset-Suche abgeschlossen."); } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogError((object)"Enchantment-Asset-Suche fehlgeschlagen:"); ((BaseUnityPlugin)this).Logger.LogError((object)ex); } } private void BuildGameRecipeLookups() { m_gameRecipesByResultItemId.Clear(); foreach (Recipe allGameRecipe in m_allGameRecipes) { if ((Object)(object)allGameRecipe == (Object)null || allGameRecipe.Results == null) { continue; } ItemReferenceQuantity[] results = allGameRecipe.Results; foreach (ItemReferenceQuantity val in results) { if (val.ItemID > 0) { AddToLookup(m_gameRecipesByResultItemId, val.ItemID, allGameRecipe); } } } } private IEnumerable GetAllWikiRecipes() { foreach (WikiRecipeData cookingRecipe in m_cookingRecipes) { yield return cookingRecipe; } foreach (WikiRecipeData alchemyRecipe in m_alchemyRecipes) { yield return alchemyRecipe; } foreach (WikiRecipeData craftingRecipe in m_craftingRecipes) { yield return craftingRecipe; } } private WikiCategory GetWikiCategoryForRecipe(WikiRecipeData recipe) { if (recipe == null) { return WikiCategory.Crafting; } if (m_cookingRecipes.Contains(recipe)) { return WikiCategory.Cooking; } if (m_alchemyRecipes.Contains(recipe)) { return WikiCategory.Alchemy; } if (m_craftingRecipes.Contains(recipe)) { return WikiCategory.Crafting; } string text = (recipe.category ?? "").ToLowerInvariant(); if (text.Contains("koch") || text.Contains("cook")) { return WikiCategory.Cooking; } if (text.Contains("alchem")) { return WikiCategory.Alchemy; } return WikiCategory.Crafting; } private bool RecipeMatchesWikiCategory(Recipe gameRecipe, WikiCategory category) { //IL_0011: 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) if ((Object)(object)gameRecipe == (Object)null) { return false; } string text = ((object)gameRecipe.CraftingStationType/*cast due to .constrained prefix*/).ToString().ToLowerInvariant(); return category switch { WikiCategory.Cooking => text.Contains("cook"), WikiCategory.Alchemy => text.Contains("alchem"), WikiCategory.Crafting => !text.Contains("cook") && !text.Contains("alchem"), _ => true, }; } private void BuildRecipeRelationshipLookups() { m_recipesByResultItemId.Clear(); m_recipesUsingItemId.Clear(); m_decraftRecipesUsingItemId.Clear(); foreach (WikiRecipeData allWikiRecipe in GetAllWikiRecipes()) { if (allWikiRecipe == null) { continue; } Recipe val = FindGameRecipe(allWikiRecipe); bool flag = IsDecraftRecipe(allWikiRecipe, val); if (!flag) { bool flag2 = false; if (allWikiRecipe.gameResultItemId > 0) { AddToLookup(m_recipesByResultItemId, allWikiRecipe.gameResultItemId, allWikiRecipe); flag2 = true; } if (allWikiRecipe.results != null) { foreach (WikiItemReference result in allWikiRecipe.results) { if (result != null && result.gameItemId > 0) { AddToLookup(m_recipesByResultItemId, result.gameItemId, allWikiRecipe); flag2 = true; } } } if (!flag2 && (Object)(object)val != (Object)null && val.Results != null && val.Results.Length != 0 && val.Results[0].ItemID > 0) { AddToLookup(m_recipesByResultItemId, val.Results[0].ItemID, allWikiRecipe); } } List effectiveRecipeIngredients = GetEffectiveRecipeIngredients(allWikiRecipe, val); List list = ResolveRuntimeIngredients(allWikiRecipe, val, effectiveRecipeIngredients); for (int i = 0; i < effectiveRecipeIngredients.Count; i++) { WikiItemReference wikiItemReference = effectiveRecipeIngredients[i]; if (wikiItemReference == null) { continue; } if (wikiItemReference.gameItemId > 0) { if (flag) { AddToLookup(m_decraftRecipesUsingItemId, wikiItemReference.gameItemId, allWikiRecipe); } else { AddToLookup(m_recipesUsingItemId, wikiItemReference.gameItemId, allWikiRecipe); } continue; } RecipeIngredient val2 = ((i < list.Count) ? list[i] : null); if (val2 == null) { continue; } List matchingItemsForRecipeIngredient = GetMatchingItemsForRecipeIngredient(val2, allWikiRecipe, val); foreach (Item item in matchingItemsForRecipeIngredient) { if (!((Object)(object)item == (Object)null) && item.ItemID > 0) { if (flag) { AddToLookup(m_decraftRecipesUsingItemId, item.ItemID, allWikiRecipe); } else { AddToLookup(m_recipesUsingItemId, item.ItemID, allWikiRecipe); } } } } } SortRecipeLookup(m_recipesByResultItemId); SortRecipeLookup(m_recipesUsingItemId); SortRecipeLookup(m_decraftRecipesUsingItemId); } private bool IsDecraftRecipe(WikiRecipeData wikiRecipe, Recipe gameRecipe) { string text = string.Join(" ", (wikiRecipe == null) ? "" : wikiRecipe.wikiId, (wikiRecipe == null) ? "" : wikiRecipe.fallbackName, (wikiRecipe == null) ? "" : wikiRecipe.category, (wikiRecipe == null) ? "" : wikiRecipe.station, ((Object)(object)gameRecipe == (Object)null) ? "" : gameRecipe.EDITOR_Name, ((Object)(object)gameRecipe == (Object)null) ? "" : gameRecipe.Name).ToLowerInvariant(); return text.Contains("decraft") || text.Contains("deconstruct") || text.Contains("dismantle") || text.Contains("salvage") || text.Contains("zerleg"); } private void BuildEnchantmentLookups() { m_enchantmentRecipesByRecipeId.Clear(); m_enchantmentRecipesByResultId.Clear(); m_enchantmentsByPresetId.Clear(); foreach (EnchantmentRecipe allGameEnchantmentRecipe in m_allGameEnchantmentRecipes) { if (!((Object)(object)allGameEnchantmentRecipe == (Object)null)) { if (allGameEnchantmentRecipe.RecipeID > 0 && !m_enchantmentRecipesByRecipeId.ContainsKey(allGameEnchantmentRecipe.RecipeID)) { m_enchantmentRecipesByRecipeId.Add(allGameEnchantmentRecipe.RecipeID, allGameEnchantmentRecipe); } if (allGameEnchantmentRecipe.ResultID > 0) { AddToLookup(m_enchantmentRecipesByResultId, allGameEnchantmentRecipe.ResultID, allGameEnchantmentRecipe); } } } foreach (Enchantment allGameEnchantment in m_allGameEnchantments) { if (!((Object)(object)allGameEnchantment == (Object)null)) { int intMember = GetIntMember(allGameEnchantment, "PresetID"); if (intMember > 0 && !m_enchantmentsByPresetId.ContainsKey(intMember)) { m_enchantmentsByPresetId.Add(intMember, allGameEnchantment); } } } } private void BindWikiEnchantmentsToRuntime() { int num = 0; foreach (WikiEnchantmentData enchantment in m_enchantments) { if (enchantment != null && enchantment.gameEnchantmentId <= 0) { EnchantmentRecipe val = FindRuntimeEnchantmentRecipeByName(enchantment); if (!((Object)(object)val == (Object)null)) { enchantment.gameRecipeId = val.RecipeID; enchantment.gameEnchantmentId = val.ResultID; num++; } } } ((BaseUnityPlugin)this).Logger.LogInfo((object)("Wiki-Verzauberungen an Runtime gebunden: " + num + "/" + m_enchantments.Count)); } private EnchantmentRecipe FindRuntimeEnchantmentRecipeByName(WikiEnchantmentData data) { if (data == null) { return null; } List list = new List(); AddNormalizedLookupTarget(list, data.fallbackName); AddNormalizedLookupTarget(list, data.wikiId); if (list.Count == 0) { return null; } EnchantmentRecipe val = null; int num = 0; foreach (EnchantmentRecipe allGameEnchantmentRecipe in m_allGameEnchantmentRecipes) { if ((Object)(object)allGameEnchantmentRecipe == (Object)null) { continue; } Enchantment gameEnchantmentByPresetId = GetGameEnchantmentByPresetId(allGameEnchantmentRecipe.ResultID); List list2 = new List(); if ((Object)(object)gameEnchantmentByPresetId != (Object)null) { AddNormalizedLookupTarget(list2, gameEnchantmentByPresetId.Name); AddNormalizedLookupTarget(list2, ((Object)gameEnchantmentByPresetId).name); } AddNormalizedLookupTarget(list2, ((Object)allGameEnchantmentRecipe).name); int num2 = 0; foreach (string item in list) { foreach (string item2 in list2) { if (item2 == item) { num2 = Math.Max(num2, 100); } else if (item2.EndsWith(item, StringComparison.Ordinal) || item.EndsWith(item2, StringComparison.Ordinal)) { num2 = Math.Max(num2, 90); } else if (item2.Contains(item) || item.Contains(item2)) { num2 = Math.Max(num2, 70); } } } if (num2 > num) { num = num2; val = allGameEnchantmentRecipe; } } return (num >= 70) ? val : null; } private void AddNormalizedLookupTarget(List targetList, string value) { string text = NormalizeLookupText(value); if (string.IsNullOrWhiteSpace(text)) { return; } if (!targetList.Contains(text)) { targetList.Add(text); } int i; for (i = 0; i < text.Length && char.IsDigit(text[i]); i++) { } if (i > 0 && i < text.Length) { string item = text.Substring(i); if (!targetList.Contains(item)) { targetList.Add(item); } } } private string NormalizeLookupText(string value) { if (string.IsNullOrWhiteSpace(value)) { return ""; } char[] value2 = value.ToLowerInvariant().Where(char.IsLetterOrDigit).ToArray(); return new string(value2); } private string GetLogicalEnchantmentKey(EnchantmentRecipe recipe) { if ((Object)(object)recipe == (Object)null) { return ""; } Enchantment gameEnchantmentByPresetId = GetGameEnchantmentByPresetId(recipe.ResultID); string value = ""; if ((Object)(object)gameEnchantmentByPresetId != (Object)null) { try { value = gameEnchantmentByPresetId.Name; } catch { } if (string.IsNullOrWhiteSpace(value)) { value = ((Object)gameEnchantmentByPresetId).name; } } if (string.IsNullOrWhiteSpace(value)) { value = ((Object)recipe).name; } return NormalizeLogicalEnchantmentName(value); } private string GetLogicalEnchantmentKey(WikiEnchantmentData data) { if (data == null) { return ""; } EnchantmentRecipe val = FindGameEnchantmentRecipe(data); if ((Object)(object)val != (Object)null) { return GetLogicalEnchantmentKey(val); } string value = ((!string.IsNullOrWhiteSpace(data.fallbackName)) ? data.fallbackName : data.wikiId); return NormalizeLogicalEnchantmentName(value); } private string NormalizeLogicalEnchantmentName(string value) { string text = NormalizeLookupText(value); if (string.IsNullOrWhiteSpace(text)) { return ""; } int i; for (i = 0; i < text.Length && char.IsDigit(text[i]); i++) { } if (i > 0 && i < text.Length) { text = text.Substring(i); } string[] array = new string[16] { "bodyarmor", "bodyarmour", "brustpanzer", "brustrüstung", "brustruestung", "chestarmor", "chest", "torso", "helmet", "helm", "head", "boots", "boot", "stiefel", "feet", "foot" }; bool flag; do { flag = false; string[] array2 = array; foreach (string text2 in array2) { if (text.Length > text2.Length && text.EndsWith(text2, StringComparison.Ordinal)) { text = text.Substring(0, text.Length - text2.Length); flag = true; break; } } } while (flag && text.Length > 0); return text; } private void BuildEnchantmentCompatibilityLookups() { m_compatibleEnchantmentsByItemId.Clear(); m_compatibleItemsByEnchantmentResultId.Clear(); foreach (EnchantmentRecipe allGameEnchantmentRecipe in m_allGameEnchantmentRecipes) { if ((Object)(object)allGameEnchantmentRecipe == (Object)null || allGameEnchantmentRecipe.ResultID <= 0) { continue; } foreach (Item allGameItemPrefab in m_allGameItemPrefabs) { if (IsPlayerFacingWikiItem(allGameItemPrefab)) { bool flag = false; try { flag = ((EquipmentData)(ref allGameEnchantmentRecipe.CompatibleEquipments)).Match(allGameItemPrefab); } catch { } if (flag) { AddToLookup(m_compatibleEnchantmentsByItemId, allGameItemPrefab.ItemID, allGameEnchantmentRecipe); AddToLookup(m_compatibleItemsByEnchantmentResultId, allGameEnchantmentRecipe.ResultID, allGameItemPrefab); } } } } foreach (KeyValuePair> item in m_compatibleEnchantmentsByItemId) { item.Value.Sort((EnchantmentRecipe a, EnchantmentRecipe b) => string.Compare(GetEnchantmentDisplayName(GetOrCreateWikiEnchantmentData(a)), GetEnchantmentDisplayName(GetOrCreateWikiEnchantmentData(b)), StringComparison.CurrentCultureIgnoreCase)); } foreach (KeyValuePair> item2 in m_compatibleItemsByEnchantmentResultId) { item2.Value.Sort((Item a, Item b) => string.Compare(GetGameItemDisplayName(a), GetGameItemDisplayName(b), StringComparison.CurrentCultureIgnoreCase)); } } private static void AddToLookup(Dictionary> lookup, TKey key, TValue value) { if (!lookup.TryGetValue(key, out var value2)) { value2 = new List(); lookup.Add(key, value2); } if (!value2.Contains(value)) { value2.Add(value); } } private void SortRecipeLookup(Dictionary> lookup) { foreach (KeyValuePair> item in lookup) { item.Value.Sort((WikiRecipeData a, WikiRecipeData b) => string.Compare(GetRecipeDisplayName(a), GetRecipeDisplayName(b), StringComparison.CurrentCultureIgnoreCase)); } } private void LoadWikiData() { try { m_items.Clear(); m_cookingRecipes.Clear(); m_alchemyRecipes.Clear(); m_craftingRecipes.Clear(); m_enchantments.Clear(); m_itemsByGameId.Clear(); m_legacyUpgradesBySourceItemId.Clear(); m_legacyUpgradesByResultItemId.Clear(); m_gameDataCacheBuilt = false; string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); if (string.IsNullOrEmpty(directoryName)) { return; } string text = Path.Combine(directoryName, "WikiData"); if (!Directory.Exists(text)) { ((BaseUnityPlugin)this).Logger.LogError((object)("WikiData-Ordner existiert nicht: " + text)); return; } m_localizationData = LoadLocalizationFile(Path.Combine(text, "localization.json")); m_items.AddRange(LoadItemFile(Path.Combine(text, "items.json"))); m_cookingRecipes.AddRange(LoadRecipeFile(Path.Combine(text, "cooking.json"))); m_alchemyRecipes.AddRange(LoadRecipeFile(Path.Combine(text, "alchemy.json"))); m_craftingRecipes.AddRange(LoadRecipeFile(Path.Combine(text, "crafting.json"))); m_enchantments.AddRange(LoadEnchantmentFile(Path.Combine(text, "enchantments.json"))); m_craftingOverrideFile = LoadCraftingOverrideFile(Path.Combine(text, "crafting_overrides.json")); ApplyCraftingOverrides(m_craftingOverrideFile); foreach (WikiItemData item in m_items) { if (item != null && item.gameItemId > 0 && !m_itemsByGameId.ContainsKey(item.gameItemId)) { m_itemsByGameId.Add(item.gameItemId, item); } } List list = LoadItemSourceFile(Path.Combine(text, "item_sources.json")); MergeItemSources(list); m_legacyUpgradeFile = LoadLegacyUpgradeFile(Path.Combine(text, "legacy_upgrades.json")); ((BaseUnityPlugin)this).Logger.LogInfo((object)"WikiData erfolgreich geladen."); ((BaseUnityPlugin)this).Logger.LogInfo((object)("Items: " + m_items.Count)); ((BaseUnityPlugin)this).Logger.LogInfo((object)("Kochrezepte: " + m_cookingRecipes.Count)); ((BaseUnityPlugin)this).Logger.LogInfo((object)("Alchemie: " + m_alchemyRecipes.Count)); ((BaseUnityPlugin)this).Logger.LogInfo((object)("Handwerk: " + m_craftingRecipes.Count)); ((BaseUnityPlugin)this).Logger.LogInfo((object)("Verzauberungen: " + m_enchantments.Count)); ((BaseUnityPlugin)this).Logger.LogInfo((object)("Item-Quellen: " + list.Count)); ((BaseUnityPlugin)this).Logger.LogInfo((object)("Crafting-Overrides: " + ((m_craftingOverrideFile != null && m_craftingOverrideFile.overrides != null) ? m_craftingOverrideFile.overrides.Count : 0))); ((BaseUnityPlugin)this).Logger.LogInfo((object)("Legacy-Upgrades geladen: " + ((m_legacyUpgradeFile != null && m_legacyUpgradeFile.upgrades != null) ? m_legacyUpgradeFile.upgrades.Count : 0))); } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogError((object)"Fehler beim Laden der WikiData:"); ((BaseUnityPlugin)this).Logger.LogError((object)ex); } } private WikiLocalizationData LoadLocalizationFile(string filePath) { if (!File.Exists(filePath)) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("localization.json wurde nicht gefunden: " + filePath)); return null; } try { WikiLocalizationData wikiLocalizationData = JsonConvert.DeserializeObject(File.ReadAllText(filePath)); ((BaseUnityPlugin)this).Logger.LogInfo((object)("Lokalisierung geladen: " + ((wikiLocalizationData != null && wikiLocalizationData.exact != null) ? wikiLocalizationData.exact.Count : 0) + " exakte Texte")); return wikiLocalizationData; } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogError((object)("Fehler beim Laden von localization.json: " + filePath)); ((BaseUnityPlugin)this).Logger.LogError((object)ex); return null; } } private WikiCraftingOverrideFile LoadCraftingOverrideFile(string filePath) { if (!File.Exists(filePath)) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("crafting_overrides.json wurde nicht gefunden: " + filePath)); return null; } try { return JsonConvert.DeserializeObject(File.ReadAllText(filePath)); } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogError((object)("Fehler beim Laden von crafting_overrides.json: " + filePath)); ((BaseUnityPlugin)this).Logger.LogError((object)ex); return null; } } private void ApplyCraftingOverrides(WikiCraftingOverrideFile file) { if (file == null || file.overrides == null) { return; } foreach (WikiRecipeData replacement in file.overrides) { if (replacement != null) { m_craftingRecipes.RemoveAll((WikiRecipeData existing) => CraftingRecipeMatchesOverride(existing, replacement)); if (string.IsNullOrWhiteSpace(replacement.category)) { replacement.category = "Handwerk"; } m_craftingRecipes.Add(replacement); } } } private bool CraftingRecipeMatchesOverride(WikiRecipeData existing, WikiRecipeData replacement) { if (existing == null || replacement == null) { return false; } if (!string.IsNullOrWhiteSpace(existing.wikiId) && !string.IsNullOrWhiteSpace(replacement.wikiId) && string.Equals(existing.wikiId, replacement.wikiId, StringComparison.OrdinalIgnoreCase)) { return true; } if (existing.gameResultItemId > 0 && replacement.gameResultItemId > 0 && existing.gameResultItemId == replacement.gameResultItemId) { return true; } if (!string.IsNullOrWhiteSpace(existing.fallbackName) && !string.IsNullOrWhiteSpace(replacement.fallbackName) && NormalizeLookupText(existing.fallbackName) == NormalizeLookupText(replacement.fallbackName)) { return true; } return false; } private WikiLegacyUpgradeFile LoadLegacyUpgradeFile(string filePath) { if (!File.Exists(filePath)) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("legacy_upgrades.json wurde nicht gefunden: " + filePath)); return null; } try { return JsonConvert.DeserializeObject(File.ReadAllText(filePath)); } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogError((object)("Fehler beim Laden von legacy_upgrades.json: " + filePath)); ((BaseUnityPlugin)this).Logger.LogError((object)ex); return null; } } private List LoadItemFile(string filePath) { if (!File.Exists(filePath)) { return new List(); } try { List list = JsonConvert.DeserializeObject>(File.ReadAllText(filePath)); return list ?? new List(); } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogError((object)("Fehler beim Laden der Item-Datei: " + filePath)); ((BaseUnityPlugin)this).Logger.LogError((object)ex); return new List(); } } private List LoadItemSourceFile(string filePath) { if (!File.Exists(filePath)) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("item_sources.json wurde nicht gefunden: " + filePath)); return new List(); } try { List list = JsonConvert.DeserializeObject>(File.ReadAllText(filePath)); return list ?? new List(); } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogError((object)("Fehler beim Laden der Item-Quellen-Datei: " + filePath)); ((BaseUnityPlugin)this).Logger.LogError((object)ex); return new List(); } } private void MergeItemSources(IEnumerable sources) { if (sources == null) { return; } foreach (WikiItemSourceData source in sources) { if (source == null || source.gameItemId <= 0) { continue; } WikiItemData wikiItemData = EnsureWikiItemEntry(source.gameItemId, source.fallbackName, "ADDED FROM ITEM SOURCES"); if (wikiItemData != null) { wikiItemData.sourceTypeKey = FirstNonEmpty(wikiItemData.sourceTypeKey, source.sourceTypeKey); wikiItemData.sourceType = FirstNonEmpty(wikiItemData.sourceType, source.sourceType); wikiItemData.sourceTypeDe = FirstNonEmpty(wikiItemData.sourceTypeDe, source.sourceTypeDe); wikiItemData.sourceTypeEn = FirstNonEmpty(wikiItemData.sourceTypeEn, source.sourceTypeEn); wikiItemData.locations = MergeUniqueStrings(wikiItemData.locations, source.locations); wikiItemData.dropsFrom = MergeUniqueStrings(wikiItemData.dropsFrom, source.dropsFrom); wikiItemData.questSources = MergeUniqueStrings(wikiItemData.questSources, source.questSources); wikiItemData.questRewards = MergeUniqueStrings(wikiItemData.questRewards, source.questRewards); wikiItemData.blacksmithSources = MergeUniqueStrings(wikiItemData.blacksmithSources, source.blacksmithSources); wikiItemData.sourceNotes = MergeUniqueStrings(wikiItemData.sourceNotes, source.sourceNotes); wikiItemData.locationsDe = MergeUniqueStrings(wikiItemData.locationsDe, source.locationsDe); wikiItemData.locationsEn = MergeUniqueStrings(wikiItemData.locationsEn, source.locationsEn); wikiItemData.dropsFromDe = MergeUniqueStrings(wikiItemData.dropsFromDe, source.dropsFromDe); wikiItemData.dropsFromEn = MergeUniqueStrings(wikiItemData.dropsFromEn, source.dropsFromEn); wikiItemData.questSourcesDe = MergeUniqueStrings(wikiItemData.questSourcesDe, source.questSourcesDe); wikiItemData.questSourcesEn = MergeUniqueStrings(wikiItemData.questSourcesEn, source.questSourcesEn); wikiItemData.questRewardsDe = MergeUniqueStrings(wikiItemData.questRewardsDe, source.questRewardsDe); wikiItemData.questRewardsEn = MergeUniqueStrings(wikiItemData.questRewardsEn, source.questRewardsEn); wikiItemData.blacksmithSourcesDe = MergeUniqueStrings(wikiItemData.blacksmithSourcesDe, source.blacksmithSourcesDe); wikiItemData.blacksmithSourcesEn = MergeUniqueStrings(wikiItemData.blacksmithSourcesEn, source.blacksmithSourcesEn); wikiItemData.sourceNotesDe = MergeUniqueStrings(wikiItemData.sourceNotesDe, source.sourceNotesDe); wikiItemData.sourceNotesEn = MergeUniqueStrings(wikiItemData.sourceNotesEn, source.sourceNotesEn); if (source.commission != null) { wikiItemData.commission = source.commission; } } } } private WikiItemData EnsureWikiItemEntry(int gameItemId, string fallbackName, string sourceStatus) { if (gameItemId <= 0) { return null; } if (!m_itemsByGameId.TryGetValue(gameItemId, out var value)) { value = new WikiItemData { gameItemId = gameItemId, fallbackName = fallbackName, fallbackDescription = "", sourceStatus = sourceStatus }; m_items.Add(value); m_itemsByGameId.Add(gameItemId, value); } else { if (string.IsNullOrWhiteSpace(value.fallbackName) && !string.IsNullOrWhiteSpace(fallbackName)) { value.fallbackName = fallbackName; } if (string.IsNullOrWhiteSpace(value.sourceStatus) && !string.IsNullOrWhiteSpace(sourceStatus)) { value.sourceStatus = sourceStatus; } } return value; } private static string FirstNonEmpty(string current, string incoming) { return (!string.IsNullOrWhiteSpace(incoming)) ? incoming.Trim() : current; } private static string SelectLocalizedSourceString(string legacy, string german, string english) { if (UseEnglishUi) { if (!string.IsNullOrWhiteSpace(english)) { return english; } if (!string.IsNullOrWhiteSpace(legacy)) { return legacy; } return german; } if (!string.IsNullOrWhiteSpace(german)) { return german; } if (!string.IsNullOrWhiteSpace(legacy)) { return legacy; } return english; } private static IEnumerable SelectLocalizedSourceList(IEnumerable legacy, IEnumerable german, IEnumerable english) { IEnumerable enumerable = (UseEnglishUi ? english : german); if (enumerable != null && enumerable.Any((string x) => !string.IsNullOrWhiteSpace(x))) { return enumerable; } if (legacy != null && legacy.Any((string x) => !string.IsNullOrWhiteSpace(x))) { return legacy; } return UseEnglishUi ? german : english; } private static List MergeUniqueStrings(List current, IEnumerable additional) { List list = ((current == null) ? new List() : (from x in current where !string.IsNullOrWhiteSpace(x) select x.Trim()).Distinct(StringComparer.CurrentCultureIgnoreCase).ToList()); if (additional == null) { return list; } foreach (string item in additional) { if (!string.IsNullOrWhiteSpace(item)) { string trimmed = item.Trim(); if (!list.Any((string x) => string.Equals(x, trimmed, StringComparison.CurrentCultureIgnoreCase))) { list.Add(trimmed); } } } return list; } private List LoadRecipeFile(string filePath) { if (!File.Exists(filePath)) { return new List(); } try { List list = JsonConvert.DeserializeObject>(File.ReadAllText(filePath)); ((BaseUnityPlugin)this).Logger.LogInfo((object)("Rezepte aus Datei geladen: " + (list?.Count ?? 0) + " | " + Path.GetFileName(filePath))); return list ?? new List(); } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogError((object)("Fehler beim Laden der Rezept-Datei: " + filePath)); ((BaseUnityPlugin)this).Logger.LogError((object)ex); return new List(); } } private List LoadEnchantmentFile(string filePath) { if (!File.Exists(filePath)) { return new List(); } try { List list = JsonConvert.DeserializeObject>(File.ReadAllText(filePath)); return list ?? new List(); } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogError((object)("Fehler beim Laden der Verzauberungs-Datei: " + filePath)); ((BaseUnityPlugin)this).Logger.LogError((object)ex); return new List(); } } private void LoadFavorites() { try { string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); if (string.IsNullOrEmpty(directoryName)) { return; } string text = Path.Combine(directoryName, "UserData"); Directory.CreateDirectory(text); m_favoritesFilePath = Path.Combine(text, "Favorites.json"); m_favorites.Clear(); if (!File.Exists(m_favoritesFilePath)) { return; } List list = JsonConvert.DeserializeObject>(File.ReadAllText(m_favoritesFilePath)); if (list == null) { return; } foreach (string item in list) { if (!string.IsNullOrWhiteSpace(item)) { m_favorites.Add(item); } } ((BaseUnityPlugin)this).Logger.LogInfo((object)("Favoriten geladen: " + m_favorites.Count)); } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogError((object)"Fehler beim Laden der Favoriten:"); ((BaseUnityPlugin)this).Logger.LogError((object)ex); } } private void SaveFavorites() { try { if (string.IsNullOrWhiteSpace(m_favoritesFilePath)) { string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); if (string.IsNullOrEmpty(directoryName)) { return; } string text = Path.Combine(directoryName, "UserData"); Directory.CreateDirectory(text); m_favoritesFilePath = Path.Combine(text, "Favorites.json"); } File.WriteAllText(m_favoritesFilePath, JsonConvert.SerializeObject((object)m_favorites.OrderBy((string x) => x).ToList(), (Formatting)1)); } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogError((object)"Fehler beim Speichern der Favoriten:"); ((BaseUnityPlugin)this).Logger.LogError((object)ex); } } private bool IsFavorite(string key) { return !string.IsNullOrWhiteSpace(key) && m_favorites.Contains(key); } private void ToggleFavorite(string key, Button starButton) { if (!string.IsNullOrWhiteSpace(key)) { if (!m_favorites.Add(key)) { m_favorites.Remove(key); } UpdateFavoriteStarButton(starButton, key); SaveFavorites(); if (m_currentCategory == WikiCategory.Favorites && m_currentViewState == WikiViewState.CategoryList) { RefreshCurrentCategoryList(((Object)(object)m_searchField == (Object)null) ? "" : m_searchField.text); } } } private void UpdateFavoriteStarButton(Button starButton, string key) { if (!((Object)(object)starButton == (Object)null)) { Text componentInChildren = ((Component)starButton).GetComponentInChildren(); if ((Object)(object)componentInChildren != (Object)null) { componentInChildren.text = (IsFavorite(key) ? "★" : "☆"); } } } internal void HandleWikiBack() { if (!m_wikiOpen || m_lastBackHandledFrame == Time.frameCount) { return; } m_lastBackHandledFrame = Time.frameCount; if (IsSearchFieldFocused && (Object)(object)m_searchField != (Object)null && !string.IsNullOrEmpty(m_searchField.text)) { ClearSearchFieldWithoutRefresh(); if (m_currentCategory == WikiCategory.None) { BuildCategoryOverviewList(); } else { RefreshCurrentCategoryList(""); } ReassertSearchFieldFocus(); } else if (IsSearchFieldFocused) { m_searchField.DeactivateInputField(); FocusFirstListButton(m_currentCategory != WikiCategory.None); } else if (m_currentViewState == WikiViewState.Article || m_currentViewState == WikiViewState.GenericIngredient) { ShowCategory(m_currentCategory); } else if (m_currentViewState == WikiViewState.CategoryList) { ShowCategoryOverview(); } else { CloseWiki(); } } private void FocusButtonReliable(Button button) { if (!((Object)(object)button == (Object)null)) { if (m_focusCoroutine != null) { ((MonoBehaviour)this).StopCoroutine(m_focusCoroutine); } m_focusCoroutine = ((MonoBehaviour)this).StartCoroutine(FocusButtonReliableCoroutine(button)); } } private IEnumerator FocusButtonReliableCoroutine(Button button) { yield return null; yield return null; Canvas.ForceUpdateCanvases(); if ((Object)(object)button == (Object)null || !((Component)button).gameObject.activeInHierarchy || !((Selectable)button).interactable) { yield break; } EventSystem es = EventSystem.current; if (!((Object)(object)es == (Object)null)) { es.SetSelectedGameObject((GameObject)null); yield return null; ((Selectable)button).Select(); es.SetSelectedGameObject(((Component)button).gameObject); yield return null; if ((Object)(object)es.currentSelectedGameObject != (Object)(object)((Component)button).gameObject) { ((Selectable)button).Select(); es.SetSelectedGameObject(((Component)button).gameObject); } m_focusCoroutine = null; ((BaseUnityPlugin)this).Logger.LogInfo((object)("UI-Fokus gesetzt auf: " + ((Object)((Component)button).gameObject).name)); } } private Button GetCurrentLeftButtonOrFallback() { EventSystem current = EventSystem.current; if ((Object)(object)current != (Object)null && (Object)(object)current.currentSelectedGameObject != (Object)null) { Button component = current.currentSelectedGameObject.GetComponent