using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using TooltipExpansion.CodeNShit.Monos;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("TooltipExpansion")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Azumatt")]
[assembly: AssemblyProduct("TooltipExpansion")]
[assembly: AssemblyCopyright("Copyright © 2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("4358610B-F3F4-4843-B7AF-98B7BC60DCDE")]
[assembly: AssemblyFileVersion("1.0.1")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.1.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
internal sealed class NullableAttribute : Attribute
{
public readonly byte[] NullableFlags;
public NullableAttribute(byte P_0)
{
NullableFlags = new byte[1] { P_0 };
}
public NullableAttribute(byte[] P_0)
{
NullableFlags = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
internal sealed class NullableContextAttribute : Attribute
{
public readonly byte Flag;
public NullableContextAttribute(byte P_0)
{
Flag = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace TooltipExpansion.CodeNShit
{
public static class Functions
{
public static void ConvertTextToScrollView(GameObject tooltip)
{
Transform val = Utils.FindChild(tooltip.transform, "Text", (IterativeSearchType)0);
if ((Object)(object)val == (Object)null)
{
TooltipExpansionPlugin.TooltipExpansionPluginLogger.LogWarning((object)"Tooltip does not contain a 'Text' object.");
return;
}
TMP_Text component = ((Component)val).GetComponent<TMP_Text>();
if ((Object)(object)component == (Object)null)
{
TooltipExpansionPlugin.TooltipExpansionPluginLogger.LogWarning((object)"Tooltip 'Text' object is missing TMP_Text component.");
return;
}
((Component)component).gameObject.GetOrAddComponent<ContentSizeFitter>().verticalFit = (FitMode)2;
component.ForceMeshUpdate(false, false);
Transform originalParent = val.parent;
val.GetSiblingIndex();
RectTransform originalTextRect = (RectTransform)(object)((val is RectTransform) ? val : null);
GameObject scrollRectGo = GenScrollView(ref originalParent, originalTextRect, component);
RectTransform viewportRT = GenViewPort(ref scrollRectGo, originalTextRect);
ScrollRect scrollRect = GenScrollRect(ref scrollRectGo, originalTextRect, ref viewportRT);
GenScrollBar(ref scrollRectGo, ref scrollRect);
((Component)scrollRect).gameObject.AddComponent<ScrollWheelHandler>();
((Component)scrollRect).gameObject.AddComponent<TooltipSizeAdjuster>();
}
private static GameObject GenScrollView(ref Transform originalParent, RectTransform originalTextRect, TMP_Text textComponent)
{
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
//IL_0045: Unknown result type (might be due to invalid IL or missing references)
//IL_0056: Unknown result type (might be due to invalid IL or missing references)
//IL_005e: Unknown result type (might be due to invalid IL or missing references)
//IL_006a: Unknown result type (might be due to invalid IL or missing references)
//IL_0076: 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_00a5: Unknown result type (might be due to invalid IL or missing references)
//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
//IL_00b3: 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_00e4: Unknown result type (might be due to invalid IL or missing references)
//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
//IL_0105: Unknown result type (might be due to invalid IL or missing references)
//IL_0182: Unknown result type (might be due to invalid IL or missing references)
//IL_019d: Unknown result type (might be due to invalid IL or missing references)
//IL_01ae: Expected O, but got Unknown
GameObject val = new GameObject("TooltipScrollView", new Type[3]
{
typeof(RectTransform),
typeof(ScrollRect),
typeof(Image)
});
val.transform.SetParent(originalParent, false);
val.transform.SetSiblingIndex(((Transform)originalTextRect).GetSiblingIndex());
RectTransform component = val.GetComponent<RectTransform>();
component.anchorMin = originalTextRect.anchorMin;
component.anchorMax = originalTextRect.anchorMax;
component.pivot = originalTextRect.pivot;
component.anchoredPosition = originalTextRect.anchoredPosition;
textComponent.rectTransform.SetSizeWithCurrentAnchors((Axis)1, textComponent.preferredHeight);
LayoutRebuilder.ForceRebuildLayoutImmediate(component);
Rect rect = originalTextRect.rect;
float width = ((Rect)(ref rect)).width;
rect = originalTextRect.rect;
float num = ((Rect)(ref rect)).height;
if (Mathf.Approximately(num, 0f))
{
num = textComponent.preferredHeight;
}
rect = InventoryGui.instance.m_recipeListScroll.handleRect.rect;
float num2 = width + ((Rect)(ref rect)).width;
component.sizeDelta = new Vector2(num2 + 5f, num);
LayoutElement val2 = val.AddComponent<LayoutElement>();
val2.preferredWidth = num2;
if (textComponent.preferredHeight > 460f && GuiScaler.m_largeGuiScale >= 1.11f && (Object)(object)UITooltip.m_hovered != (Object)null && ((Object)UITooltip.m_hovered).name == "JC_ItemBackground")
{
val2.minHeight = 460f;
val2.preferredHeight = 460f;
}
else
{
val2.minHeight = num;
val2.preferredHeight = textComponent.preferredHeight;
}
textComponent.ForceMeshUpdate(false, false);
Image component2 = val.GetComponent<Image>();
((Graphic)component2).color = new Color(0f, 0f, 0f, 0.2f);
((Graphic)component2).raycastTarget = true;
return val;
}
private static RectTransform GenViewPort(ref GameObject scrollRectGo, RectTransform? originalTextRect)
{
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
//IL_002a: Unknown result type (might be due to invalid IL or missing references)
//IL_004d: Unknown result type (might be due to invalid IL or missing references)
//IL_0062: 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)
GameObject val = new GameObject("TooltipViewport", new Type[2]
{
typeof(RectTransform),
typeof(RectMask2D)
});
val.transform.SetParent(scrollRectGo.transform, false);
RectTransform component = val.GetComponent<RectTransform>();
component.anchorMin = new Vector2(0f, 0f);
component.anchorMax = new Vector2(1f, 1f);
component.offsetMin = Vector2.zero;
component.offsetMax = Vector2.zero;
return component;
}
private static ScrollRect GenScrollRect(ref GameObject scrollRectGo, RectTransform originalTextRect, ref RectTransform viewportRT)
{
ScrollRect component = scrollRectGo.GetComponent<ScrollRect>();
component.viewport = viewportRT;
((Transform)originalTextRect).SetParent((Transform)(object)viewportRT, false);
component.content = originalTextRect;
component.horizontal = false;
component.vertical = true;
component.verticalScrollbarVisibility = (ScrollbarVisibility)1;
component.scrollSensitivity = 40f;
component.inertia = true;
component.movementType = (MovementType)2;
((UnityEventBase)component.onValueChanged).RemoveAllListeners();
return component;
}
private static void GenScrollBar(ref GameObject scrollRectGo, ref ScrollRect scrollRect)
{
Scrollbar newScrollbar = Object.Instantiate<Scrollbar>(InventoryGui.instance.m_recipeListScroll, scrollRectGo.transform);
newScrollbar.size = 0.4f;
((UnityEvent<Vector2>)(object)scrollRect.onValueChanged).AddListener((UnityAction<Vector2>)delegate
{
newScrollbar.size = 0.4f;
});
scrollRect.verticalScrollbar = newScrollbar;
}
private static T GetOrAddComponent<T>(this GameObject go) where T : Component
{
T val = go.GetComponent<T>();
if ((Object)(object)val == (Object)null)
{
val = go.AddComponent<T>();
}
return val;
}
}
[BepInPlugin("Azumatt.TooltipExpansion", "TooltipExpansion", "1.0.1")]
public class TooltipExpansionPlugin : BaseUnityPlugin
{
internal const string ModName = "TooltipExpansion";
internal const string ModVersion = "1.0.1";
internal const string Author = "Azumatt";
private const string ModGUID = "Azumatt.TooltipExpansion";
internal static string ConnectionError = "";
private readonly Harmony _harmony = new Harmony("Azumatt.TooltipExpansion");
public static readonly ManualLogSource TooltipExpansionPluginLogger = Logger.CreateLogSource("TooltipExpansion");
public void Awake()
{
Assembly executingAssembly = Assembly.GetExecutingAssembly();
_harmony.PatchAll(executingAssembly);
}
}
[HarmonyPatch(typeof(UITooltip), "OnHoverStart")]
public class UITooltip_OnHoverStart_Patch
{
private static void Postfix(UITooltip __instance, GameObject go)
{
if (!((Object)(object)InventoryGui.instance == (Object)null) && !((Object)(object)go == (Object)null) && (!(((Object)go).name != "JC_ItemBackground") || ((Object)go).name.StartsWith("InventoryElement")) && (Object)(object)UITooltip.m_tooltip != (Object)null && (Object)(object)UITooltip.m_tooltip.GetComponent<TooltipScrollInitializer>() == (Object)null)
{
UITooltip.m_tooltip.AddComponent<TooltipScrollInitializer>();
}
}
}
[HarmonyPatch(typeof(Utils), "ClampUIToScreen")]
public static class Utils_ClampUIToScreen_Patch
{
private static bool Prefix(RectTransform transform)
{
//IL_00be: Unknown result type (might be due to invalid IL or missing references)
//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)((Component)transform).GetComponentInParent<ScrollRect>() != (Object)null)
{
return false;
}
Vector3[] array = (Vector3[])(object)new Vector3[4];
transform.GetWorldCorners(array);
float num = 0f;
float num2 = 0f;
if (array[2].x > (float)Screen.width)
{
num = (float)Screen.width - array[2].x;
}
if (array[0].x < 0f)
{
num = 0f - array[0].x;
}
if (array[2].y > (float)Screen.height)
{
num2 = (float)Screen.height - array[2].y;
}
if (array[0].y < 0f)
{
num2 = 0f - array[0].y;
}
((Transform)transform).position = ((Transform)transform).position + new Vector3(num, num2, 0f);
return false;
}
}
}
namespace TooltipExpansion.CodeNShit.Monos
{
public class TooltipScrollInitializer : MonoBehaviour
{
private bool _initialized;
private void OnEnable()
{
if (!_initialized)
{
Functions.ConvertTextToScrollView(((Component)this).gameObject);
Canvas.ForceUpdateCanvases();
_initialized = true;
}
}
}
public class ScrollWheelHandler : MonoBehaviour
{
private ScrollRect _scrollRect;
private void Awake()
{
_scrollRect = ((Component)this).GetComponent<ScrollRect>();
if ((Object)(object)_scrollRect == (Object)null)
{
TooltipExpansionPlugin.TooltipExpansionPluginLogger.LogWarning((object)("ScrollWheelHandler: No ScrollRect found on " + ((Object)((Component)this).gameObject).name));
}
}
private void Update()
{
if (((Component)this).gameObject.activeInHierarchy && !((Object)(object)_scrollRect == (Object)null))
{
float axis = Input.GetAxis("Mouse ScrollWheel");
if (Mathf.Abs(axis) > float.Epsilon)
{
float num = _scrollRect.verticalNormalizedPosition + axis * 0.7f;
_scrollRect.verticalNormalizedPosition = Mathf.Clamp01(num);
}
}
}
}
public class TooltipSizeAdjuster : MonoBehaviour
{
public float maxHeight = 450f;
private ScrollRect _scrollRect;
private RectTransform _scrollViewRT;
private RectTransform _contentRT;
private void Awake()
{
_scrollRect = ((Component)this).GetComponent<ScrollRect>();
_scrollViewRT = ((Component)this).GetComponent<RectTransform>();
if ((Object)(object)_scrollRect != (Object)null)
{
_contentRT = _scrollRect.content;
}
}
private void Start()
{
AdjustSize();
}
public void AdjustSize()
{
//IL_002e: 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)_contentRT == (Object)null) && !((Object)(object)_scrollViewRT == (Object)null))
{
LayoutRebuilder.ForceRebuildLayoutImmediate(_contentRT);
Rect rect = _contentRT.rect;
float height = ((Rect)(ref rect)).height;
_scrollViewRT.SetSizeWithCurrentAnchors((Axis)1, (height < maxHeight) ? height : maxHeight);
}
}
}
}