using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using HarmonyLib; using TMPro; using UnityEngine; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: AssemblyVersion("0.0.0.0")] namespace Obelisk.VHModpackFix; [BepInPlugin("obelisk.vhmodpackfix", "VHModpackFix", "1.0.8")] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] public sealed class VHModpackFixPlugin : BaseUnityPlugin { public const string PluginGuid = "obelisk.vhmodpackfix"; public const string PluginName = "VHModpackFix"; public const string PluginVersion = "1.0.8"; private const string WaterMaterialName = "VHModpackFix_WaterWell"; private static readonly Harmony Harmony = new Harmony("obelisk.vhmodpackfix"); private static readonly Dictionary WaterMaterialCache = new Dictionary(StringComparer.OrdinalIgnoreCase); private static ConfigEntry _fixBalrondWaterWell; private static ConfigEntry _fixEpicLootCraftSuccessDialog; private static bool _balrondAddPrefabsPatched; private static bool _epicLootCraftSuccessDialogPatched; private static bool _waterWellPrefabFixed; private static Material _vanillaWaterMaterial; private static bool _vanillaWaterMaterialSearched; private void Awake() { _fixBalrondWaterWell = ((BaseUnityPlugin)this).Config.Bind("Fixes", "Fix Balrond water well material", true, "Replaces the Balrond water well WaterSurface material with a cached vanilla water clone and removes its WaterVolume updater."); _fixEpicLootCraftSuccessDialog = ((BaseUnityPlugin)this).Config.Bind("Fixes", "Fix EpicLoot craft success dialog", true, "Repositions and repopulates Epic Loot's enchant/rune success dialog when the vanilla UI template leaves it empty."); PatchBalrondAddPrefabs(); PatchEpicLootCraftSuccessDialog(); } private void OnDestroy() { Harmony.UnpatchSelf(); } private static void PatchBalrondAddPrefabs() { //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Expected O, but got Unknown if (!_balrondAddPrefabsPatched) { Type type = AccessTools.TypeByName("BalrondNature.ModResourceLoader"); MethodInfo methodInfo = ((type == null) ? null : AccessTools.Method(type, "AddPrefabsToZnetScene", (Type[])null, (Type[])null)); MethodInfo methodInfo2 = AccessTools.Method(typeof(VHModpackFixPlugin), "BalrondAddPrefabsToZnetScenePostfix", (Type[])null, (Type[])null); if (!(methodInfo == null) && !(methodInfo2 == null)) { Harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(methodInfo2), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); _balrondAddPrefabsPatched = true; } } } private static void PatchEpicLootCraftSuccessDialog() { if (!_epicLootCraftSuccessDialogPatched) { PatchEpicLootShow("EpicLoot.Crafting.CraftSuccessDialog", "EpicLootCraftSuccessDialogShowPostfix"); PatchEpicLootShow("EpicLoot.Crafting.AugmentChoiceDialog", "EpicLootAugmentChoiceDialogShowPostfix"); PatchEpicLootMethod("EpicLoot.Crafting.AugmentChoiceDialog", "OnClose", "EpicLootAugmentChoiceDialogOnClosePostfix"); _epicLootCraftSuccessDialogPatched = true; } } private static void PatchEpicLootShow(string typeName, string postfixName) { //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Expected O, but got Unknown Type type = AccessTools.TypeByName(typeName); MethodInfo methodInfo = ((type == null) ? null : AccessTools.Method(type, "Show", (Type[])null, (Type[])null)); MethodInfo methodInfo2 = AccessTools.Method(typeof(VHModpackFixPlugin), postfixName, (Type[])null, (Type[])null); if (methodInfo != null && methodInfo2 != null) { Harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(methodInfo2), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } } private static void PatchEpicLootMethod(string typeName, string methodName, string postfixName) { //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Expected O, but got Unknown Type type = AccessTools.TypeByName(typeName); MethodInfo methodInfo = ((type == null) ? null : AccessTools.Method(type, methodName, (Type[])null, (Type[])null)); MethodInfo methodInfo2 = AccessTools.Method(typeof(VHModpackFixPlugin), postfixName, (Type[])null, (Type[])null); if (methodInfo != null && methodInfo2 != null) { Harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(methodInfo2), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } } private static void BalrondAddPrefabsToZnetScenePostfix(ZNetScene zNetScene) { if ((Object)(object)zNetScene != (Object)null) { FixBalrondWaterWellPrefab(zNetScene); } } private static void EpicLootCraftSuccessDialogShowPostfix(object __instance, ItemData item) { if (!_fixEpicLootCraftSuccessDialog.Value || __instance == null || item == null) { return; } try { FixEpicLootCraftSuccessDialog(__instance, item); } catch (Exception ex) { Debug.LogWarning((object)("[VHModpackFix] Failed to fix EpicLoot craft success dialog: " + ex.Message)); } } private static void EpicLootAugmentChoiceDialogShowPostfix(object __instance, ItemData fromItem) { if (!_fixEpicLootCraftSuccessDialog.Value || __instance == null || fromItem == null) { return; } try { FixEpicLootAugmentChoiceDialog(__instance, fromItem); StopAugmentChoiceLoopAudio(__instance); } catch (Exception ex) { Debug.LogWarning((object)("[VHModpackFix] Failed to fix EpicLoot augment choice dialog: " + ex.Message)); } } private static void EpicLootAugmentChoiceDialogOnClosePostfix(object __instance) { StopAugmentChoiceLoopAudio(__instance); } private static void FixEpicLootCraftSuccessDialog(object dialog, ItemData item) { Component val = (Component)((dialog is Component) ? dialog : null); RectTransform val2 = (RectTransform)(((object)GetDialogField(dialog, "Frame")) ?? ((object)/*isinst with value type is only supported in some contexts*/)); if (!((Object)(object)val == (Object)null) && !((Object)(object)val2 == (Object)null) && !((Object)(object)InventoryGui.instance == (Object)null)) { TMP_Text nameText = GetDialogField(dialog, "NameText") ?? CreateDialogText(dialog, val2, "NameText"); TMP_Text obj = GetDialogField(dialog, "Description") ?? CreateDialogText(dialog, val2, "Description"); Image icon = GetDialogField(dialog, "Icon") ?? CreateDialogImage(dialog, val2); Image dialogField = GetDialogField(dialog, "MagicBG"); val.gameObject.SetActive(true); ConfigureCraftSuccessFrame(val2); ConfigureCraftSuccessName(nameText, item); ConfigureCraftSuccessIcon(icon, item); ConfigureCraftSuccessMagicBackground(dialogField); ConfigureCraftSuccessDescription(obj, FindParentByName((obj != null) ? obj.transform : null, "ScrollView"), item); } } private static void FixEpicLootAugmentChoiceDialog(object dialog, ItemData item) { Component val = (Component)((dialog is Component) ? dialog : null); Transform obj = ((val != null) ? val.transform.Find("Frame") : null); RectTransform val2 = (RectTransform)(object)((obj is RectTransform) ? obj : null); if (!((Object)(object)val == (Object)null) && !((Object)(object)val2 == (Object)null)) { TMP_Text dialogField = GetDialogField(dialog, "NameText"); TMP_Text dialogField2 = GetDialogField(dialog, "Description"); Image dialogField3 = GetDialogField(dialog, "Icon"); val.gameObject.SetActive(true); SetTextWithoutLayout(dialogField, SafeLocalize(GetDecoratedItemName(item)), (TextAlignmentOptions)514); SetTextWithoutLayout(dialogField2, SafeLocalize(item.GetTooltip(-1)), (TextAlignmentOptions)257); if ((Object)(object)dialogField3 != (Object)null) { ((Component)dialogField3).gameObject.SetActive(true); ((Behaviour)dialogField3).enabled = true; dialogField3.sprite = item.GetIcon(); dialogField3.preserveAspect = true; } RestoreAugmentChoiceScrollLayout(dialogField2); RestoreAugmentChoiceButtonsLayout(dialog); } } private static void SetTextWithoutLayout(TMP_Text text, string value, TextAlignmentOptions alignment) { //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)text == (Object)null)) { ((Component)text).gameObject.SetActive(true); ((Behaviour)text).enabled = true; text.text = value; text.textWrappingMode = (TextWrappingModes)1; text.alignment = alignment; ((Graphic)text).color = Color.white; } } private static void RestoreAugmentChoiceScrollLayout(TMP_Text description) { //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Unknown result type (might be due to invalid IL or missing references) Transform val = FindParentByName((description != null) ? description.transform : null, "ScrollView"); RectTransform val2 = (RectTransform)(object)((val is RectTransform) ? val : null); if (val2 != null) { ConfigureAugmentChoiceDescription(description); val2.anchorMin = new Vector2(0f, 0f); val2.anchorMax = new Vector2(1f, 1f); val2.pivot = new Vector2(0.5f, 0.5f); val2.anchoredPosition = new Vector2(0f, 50f); val2.sizeDelta = new Vector2(-20f, -300f); val2.SetInsetAndSizeFromParentEdge((Edge)2, 74f, 300f); val.SetSiblingIndex(1); } } private static void ConfigureAugmentChoiceDescription(TMP_Text description) { //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_0096: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: Unknown result type (might be due to invalid IL or missing references) //IL_00b1: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)description == (Object)null)) { description.fontSize = 18f; description.textWrappingMode = (TextWrappingModes)1; description.overflowMode = (TextOverflowModes)0; ((Graphic)description).raycastTarget = false; (((Component)description).GetComponent() ?? ((Component)description).gameObject.AddComponent()).verticalFit = (FitMode)2; RectTransform rectTransform = description.rectTransform; rectTransform.anchorMin = new Vector2(0f, 1f); rectTransform.anchorMax = new Vector2(1f, 1f); rectTransform.pivot = new Vector2(0f, 1f); rectTransform.anchoredPosition = new Vector2(4f, 4f); rectTransform.sizeDelta = new Vector2(0f, rectTransform.sizeDelta.y); } } private static void RestoreAugmentChoiceButtonsLayout(object dialog) { //IL_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_00be: Unknown result type (might be due to invalid IL or missing references) //IL_00d4: Unknown result type (might be due to invalid IL or missing references) //IL_00fd: Unknown result type (might be due to invalid IL or missing references) if (!(AccessTools.Field(dialog.GetType(), "EffectChoiceButtons")?.GetValue(dialog) is IEnumerable enumerable)) { return; } List