Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of VHModpackFix v1.0.8
VHModpackFix.dll
Decompiled 2 hours agousing 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<string, Material> WaterMaterialCache = new Dictionary<string, Material>(StringComparer.OrdinalIgnoreCase); private static ConfigEntry<bool> _fixBalrondWaterWell; private static ConfigEntry<bool> _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<bool>("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<bool>("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<RectTransform>(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<TMP_Text>(dialog, "NameText") ?? CreateDialogText(dialog, val2, "NameText"); TMP_Text obj = GetDialogField<TMP_Text>(dialog, "Description") ?? CreateDialogText(dialog, val2, "Description"); Image icon = GetDialogField<Image>(dialog, "Icon") ?? CreateDialogImage(dialog, val2); Image dialogField = GetDialogField<Image>(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<TMP_Text>(dialog, "NameText"); TMP_Text dialogField2 = GetDialogField<TMP_Text>(dialog, "Description"); Image dialogField3 = GetDialogField<Image>(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<ContentSizeFitter>() ?? ((Component)description).gameObject.AddComponent<ContentSizeFitter>()).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<Button> list = new List<Button>(); foreach (object item in enumerable) { Button val = (Button)((item is Button) ? item : null); if (val != null && (Object)(object)val != (Object)null) { list.Add(val); } } for (int i = 0; i < list.Count; i++) { Transform transform = ((Component)list[i]).transform; RectTransform val2 = (RectTransform)(object)((transform is RectTransform) ? transform : null); if (!((Object)(object)val2 == (Object)null)) { val2.anchorMin = new Vector2(0.5f, 0f); val2.anchorMax = new Vector2(0.5f, 0f); val2.pivot = new Vector2(0.5f, 0.5f); val2.anchoredPosition = new Vector2(0f, 55f + (float)(list.Count - 1 - i) * 45f); val2.SetSizeWithCurrentAnchors((Axis)0, 300f); val2.SetSizeWithCurrentAnchors((Axis)1, 40f); ((Transform)val2).SetAsLastSibling(); } } } private static void StopAugmentChoiceLoopAudio(object dialog) { Component val = (Component)((dialog is Component) ? dialog : null); AudioSource dialogField = GetDialogField<AudioSource>(dialog, "_audioSource"); if ((Object)(object)dialogField != (Object)null) { dialogField.loop = false; dialogField.Stop(); } if ((Object)(object)val == (Object)null) { return; } AudioSource val2 = (((Object)(object)val.transform.parent != (Object)null) ? ((Component)val.transform.parent).GetComponent<AudioSource>() : null); if ((Object)(object)val2 != (Object)null) { val2.loop = false; val2.Stop(); } AudioSource[] componentsInChildren = val.GetComponentsInChildren<AudioSource>(true); foreach (AudioSource val3 in componentsInChildren) { if ((Object)(object)val3 != (Object)null) { val3.loop = false; val3.Stop(); } } } private static TMP_Text CreateDialogText(object dialog, RectTransform frame, string fieldName) { TMP_Text val = ((!(fieldName == "Description")) ? InventoryGui.instance?.m_recipeName : InventoryGui.instance?.m_recipeDecription); if ((Object)(object)val == (Object)null) { return null; } TMP_Text val2 = Object.Instantiate<TMP_Text>(val, (Transform)(object)frame); ((Object)val2).name = "VHModpackFix" + fieldName; SetDialogField(dialog, fieldName, val2); return val2; } private static Image CreateDialogImage(object dialog, RectTransform frame) { Image val = InventoryGui.instance?.m_recipeIcon; if ((Object)(object)val == (Object)null) { return null; } Image val2 = Object.Instantiate<Image>(val, (Transform)(object)frame); ((Object)val2).name = "VHModpackFixIcon"; SetDialogField(dialog, "Icon", val2); return val2; } private static void ConfigureCraftSuccessFrame(RectTransform frame) { frame.SetSizeWithCurrentAnchors((Axis)0, 380f); frame.SetSizeWithCurrentAnchors((Axis)1, 550f); ((Transform)frame).SetAsLastSibling(); ((Component)frame).gameObject.SetActive(true); } private static void ConfigureCraftSuccessName(TMP_Text nameText, ItemData item) { //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Unknown result type (might be due to invalid IL or missing references) //IL_008e: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: 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) //IL_00cc: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)nameText == (Object)null)) { ((Component)nameText).gameObject.SetActive(true); ((Behaviour)nameText).enabled = true; nameText.text = SafeLocalize(GetDecoratedItemName(item)); nameText.fontSize = 22f; nameText.textWrappingMode = (TextWrappingModes)1; nameText.alignment = (TextAlignmentOptions)514; ((Graphic)nameText).color = Color.white; RectTransform rectTransform = nameText.rectTransform; ((Transform)rectTransform).SetParent((Transform)(object)GetDialogFrame(nameText.transform), false); rectTransform.anchorMin = new Vector2(0f, 1f); rectTransform.anchorMax = new Vector2(1f, 1f); rectTransform.pivot = new Vector2(0.5f, 1f); rectTransform.anchoredPosition = new Vector2(0f, -18f); rectTransform.sizeDelta = new Vector2(-32f, 44f); nameText.transform.SetAsLastSibling(); } } private static void ConfigureCraftSuccessIcon(Image icon, ItemData item) { //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0078: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_008d: 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_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00b6: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)icon == (Object)null)) { ((Component)icon).gameObject.SetActive(true); ((Behaviour)icon).enabled = true; icon.sprite = item.GetIcon(); icon.preserveAspect = true; ((Graphic)icon).color = Color.white; RectTransform val = (RectTransform)((Component)icon).transform; ((Transform)val).SetParent((Transform)(object)GetDialogFrame(((Component)icon).transform), false); val.anchorMin = new Vector2(0.5f, 1f); val.anchorMax = new Vector2(0.5f, 1f); val.pivot = new Vector2(0.5f, 0.5f); val.anchoredPosition = new Vector2(0f, -86f); val.sizeDelta = new Vector2(72f, 72f); ((Component)icon).transform.SetAsLastSibling(); } } private static void ConfigureCraftSuccessMagicBackground(Image magicBG) { //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0021: 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) //IL_003e: 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_0053: 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_0068: 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_007d: Unknown result type (might be due to invalid IL or missing references) //IL_0091: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)magicBG == (Object)null)) { ((Component)magicBG).gameObject.SetActive(true); RectTransform val = (RectTransform)((Component)magicBG).transform; ((Transform)val).SetParent((Transform)(object)GetDialogFrame(((Component)magicBG).transform), false); val.anchorMin = new Vector2(0.5f, 1f); val.anchorMax = new Vector2(0.5f, 1f); val.pivot = new Vector2(0.5f, 0.5f); val.anchoredPosition = new Vector2(0f, -86f); val.sizeDelta = new Vector2(82f, 82f); ((Component)magicBG).transform.SetSiblingIndex(0); } } private static void ConfigureCraftSuccessDescription(TMP_Text description, Transform scrollView, ItemData item) { //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_00f1: Unknown result type (might be due to invalid IL or missing references) //IL_0106: Unknown result type (might be due to invalid IL or missing references) //IL_011b: Unknown result type (might be due to invalid IL or missing references) //IL_0130: Unknown result type (might be due to invalid IL or missing references) //IL_0141: Unknown result type (might be due to invalid IL or missing references) //IL_014b: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Unknown result type (might be due to invalid IL or missing references) //IL_00a5: Unknown result type (might be due to invalid IL or missing references) //IL_00ba: Unknown result type (might be due to invalid IL or missing references) //IL_00cf: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)description == (Object)null)) { ((Component)description).gameObject.SetActive(true); ((Behaviour)description).enabled = true; description.text = SafeLocalize(item.GetTooltip(-1)); description.fontSize = 18f; description.textWrappingMode = (TextWrappingModes)1; description.alignment = (TextAlignmentOptions)257; ((Graphic)description).color = Color.white; RectTransform val = (RectTransform)(object)((scrollView is RectTransform) ? scrollView : null); if (val != null) { RectTransform dialogFrame = GetDialogFrame(scrollView); ((Transform)val).SetParent((Transform)(object)dialogFrame, false); val.anchorMin = new Vector2(0f, 0f); val.anchorMax = new Vector2(1f, 1f); val.pivot = new Vector2(0.5f, 0.5f); val.offsetMin = new Vector2(12f, 58f); val.offsetMax = new Vector2(-12f, -138f); scrollView.SetAsLastSibling(); } 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(6f, -6f); rectTransform.sizeDelta = new Vector2(-12f, rectTransform.sizeDelta.y); } } private static RectTransform GetDialogFrame(Transform child) { //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Expected O, but got Unknown Transform val = child; while ((Object)(object)val != (Object)null && (Object)(object)val.parent != (Object)null) { if (((Object)val).name == "Frame") { return (RectTransform)val; } val = val.parent; } Transform parent = child.parent; return (RectTransform)(object)((parent is RectTransform) ? parent : null); } private static Transform FindParentByName(Transform child, string parentName) { Transform val = child; while ((Object)(object)val != (Object)null) { if (string.Equals(((Object)val).name, parentName, StringComparison.Ordinal)) { return val; } val = val.parent; } return null; } private static T GetDialogField<T>(object instance, string fieldName) where T : Object { object? obj = AccessTools.Field(instance.GetType(), fieldName)?.GetValue(instance); return (T)((obj is T) ? obj : null); } private static void SetDialogField(object instance, string fieldName, object value) { AccessTools.Field(instance.GetType(), fieldName)?.SetValue(instance, value); } private static string SafeLocalize(string text) { Type type = AccessTools.TypeByName("Localization"); if (type == null) { return text; } object obj = AccessTools.Field(type, "instance")?.GetValue(null) ?? AccessTools.Property(type, "instance")?.GetValue(null); MethodInfo methodInfo = AccessTools.Method(type, "Localize", new Type[1] { typeof(string) }, (Type[])null); if (obj == null || !(methodInfo != null)) { return text; } return (methodInfo.Invoke(obj, new object[1] { text }) as string) ?? text; } private static string GetDecoratedItemName(ItemData item) { Type type = AccessTools.TypeByName("EpicLoot.ItemDataExtensions"); MethodInfo methodInfo = ((type == null) ? null : AccessTools.Method(type, "GetDecoratedName", new Type[2] { typeof(ItemData), typeof(string) }, (Type[])null)); if (methodInfo != null && methodInfo.Invoke(null, new object[2] { item, null }) is string text && !string.IsNullOrEmpty(text)) { return text; } return item.m_shared.m_name; } private static void FixBalrondWaterWellPrefab(ZNetScene zNetScene) { if (_fixBalrondWaterWell.Value && !_waterWellPrefabFixed && !((Object)(object)zNetScene == (Object)null)) { GameObject val = zNetScene.m_prefabs.Find((GameObject obj) => (Object)(object)obj != (Object)null && ((Object)obj).name == "piece_waterwell_bal"); if (!((Object)(object)val == (Object)null) && FixBalrondWaterWellObject(val)) { _waterWellPrefabFixed = true; } } } private static bool FixBalrondWaterWellObject(GameObject root) { Transform val = root.transform.Find("water"); Transform val2 = ((val != null) ? val.Find("WaterSurface") : null); Renderer val3 = (((Object)(object)val2 != (Object)null) ? ((Component)val2).GetComponent<Renderer>() : null); if ((Object)(object)val3 == (Object)null) { return false; } Transform val4 = val.Find("WaterVolume"); if ((Object)(object)val4 != (Object)null) { MonoBehaviour[] components = ((Component)val4).GetComponents<MonoBehaviour>(); foreach (MonoBehaviour val5 in components) { if ((Object)(object)val5 != (Object)null && ((object)val5).GetType().Name == "WaterVolume") { Object.DestroyImmediate((Object)(object)val5); } } } Material val6 = CreateVanillaWaterMaterial(); if ((Object)(object)val6 != (Object)null) { val3.sharedMaterial = val6; return true; } return false; } private static Material CreateVanillaWaterMaterial() { //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Expected O, but got Unknown Material vanillaWaterMaterial = GetVanillaWaterMaterial(); if ((Object)(object)vanillaWaterMaterial == (Object)null) { return null; } string text = CleanUnityObjectName(((Object)vanillaWaterMaterial).name); if (WaterMaterialCache.TryGetValue(text, out var value) && (Object)(object)value != (Object)null) { return value; } Material val = new Material(vanillaWaterMaterial) { name = "VHModpackFix_WaterWell_" + text, enableInstancing = vanillaWaterMaterial.enableInstancing }; WaterMaterialCache[text] = val; return val; } private static Material GetVanillaWaterMaterial() { if (_vanillaWaterMaterialSearched) { return _vanillaWaterMaterial; } _vanillaWaterMaterialSearched = true; _vanillaWaterMaterial = FindLoadedMaterial("water") ?? FindLoadedMaterial("water_lod") ?? FindLoadedMaterial("water_interior_cave") ?? FindLoadedMaterial("BarberWater_mat") ?? FindLoadedMaterial("water_surface"); return _vanillaWaterMaterial; } private static Material FindLoadedMaterial(string name) { Material[] array = Resources.FindObjectsOfTypeAll<Material>(); foreach (Material val in array) { if ((Object)(object)val != (Object)null && string.Equals(CleanUnityObjectName(((Object)val).name), name, StringComparison.OrdinalIgnoreCase)) { return val; } } return null; } private static string CleanUnityObjectName(string name) { return (name ?? "").Replace(" (Instance)", "").Trim(); } }