using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("CanvasUtil")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+cf62804bd0cc7276e22a306e96a1178bf555e6cc")]
[assembly: AssemblyProduct("CanvasUtil")]
[assembly: AssemblyTitle("CanvasUtil")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/flibber-hk/Silksong.CanvasUtil")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.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 BepInEx
{
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
[Conditional("CodeGeneration")]
internal sealed class BepInAutoPluginAttribute : Attribute
{
public BepInAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
{
}
}
}
namespace BepInEx.Preloader.Core.Patching
{
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
[Conditional("CodeGeneration")]
internal sealed class PatcherAutoPluginAttribute : Attribute
{
public PatcherAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
{
}
}
}
namespace CanvasUtil
{
public static class CanvasUtil
{
[CompilerGenerated]
private sealed class <FadeInCanvasGroup>d__12 : IEnumerator<object>, IEnumerator, IDisposable
{
private int <>1__state;
private object <>2__current;
public CanvasGroup cg;
private float <loopFailsafe>5__2;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <FadeInCanvasGroup>d__12(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<>1__state = -2;
}
private bool MoveNext()
{
switch (<>1__state)
{
default:
return false;
case 0:
<>1__state = -1;
<loopFailsafe>5__2 = 0f;
cg.alpha = 0f;
((Component)cg).gameObject.SetActive(true);
goto IL_00c7;
case 1:
<>1__state = -1;
goto IL_00c7;
case 2:
{
<>1__state = -1;
return false;
}
IL_00c7:
if (cg.alpha < 1f)
{
CanvasGroup obj = cg;
obj.alpha += Time.unscaledDeltaTime * 3.2f;
<loopFailsafe>5__2 += Time.unscaledDeltaTime;
if (cg.alpha >= 0.95f)
{
cg.alpha = 1f;
}
else if (!(<loopFailsafe>5__2 >= 2f))
{
<>2__current = null;
<>1__state = 1;
return true;
}
}
cg.alpha = 1f;
cg.interactable = true;
((Component)cg).gameObject.SetActive(true);
<>2__current = null;
<>1__state = 2;
return true;
}
}
bool IEnumerator.MoveNext()
{
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
return this.MoveNext();
}
[DebuggerHidden]
void IEnumerator.Reset()
{
throw new NotSupportedException();
}
}
[CompilerGenerated]
private sealed class <FadeOutCanvasGroup>d__13 : IEnumerator<object>, IEnumerator, IDisposable
{
private int <>1__state;
private object <>2__current;
public CanvasGroup cg;
private float <loopFailsafe>5__2;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <FadeOutCanvasGroup>d__13(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<>1__state = -2;
}
private bool MoveNext()
{
switch (<>1__state)
{
default:
return false;
case 0:
<>1__state = -1;
<loopFailsafe>5__2 = 0f;
cg.interactable = false;
goto IL_00a0;
case 1:
<>1__state = -1;
goto IL_00a0;
case 2:
{
<>1__state = -1;
return false;
}
IL_00a0:
if (cg.alpha > 0.05f)
{
CanvasGroup obj = cg;
obj.alpha -= Time.unscaledDeltaTime * 3.2f;
<loopFailsafe>5__2 += Time.unscaledDeltaTime;
if (!(cg.alpha <= 0.05f) && !(<loopFailsafe>5__2 >= 2f))
{
<>2__current = null;
<>1__state = 1;
return true;
}
}
cg.alpha = 0f;
((Component)cg).gameObject.SetActive(false);
<>2__current = null;
<>1__state = 2;
return true;
}
}
bool IEnumerator.MoveNext()
{
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
return this.MoveNext();
}
[DebuggerHidden]
void IEnumerator.Reset()
{
throw new NotSupportedException();
}
}
public static GameObject CreateBasePanel(GameObject parent, RectData rd)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Expected O, but got Unknown
//IL_0035: Unknown result type (might be due to invalid IL or missing references)
GameObject val = new GameObject();
if ((Object)(object)parent != (Object)null)
{
val.transform.SetParent(parent.transform);
val.transform.localScale = new Vector3(1f, 1f, 1f);
}
val.AddComponent<CanvasRenderer>();
AddRectTransform(val, rd);
return val;
}
public static void AddRectTransform(GameObject go, RectData rd)
{
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_002c: 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)
RectTransform obj = go.AddComponent<RectTransform>();
obj.anchorMax = rd.AnchorMax;
obj.anchorMin = rd.AnchorMin;
obj.pivot = rd.AnchorPivot;
obj.sizeDelta = rd.RectSizeDelta;
obj.anchoredPosition = rd.AnchorPosition;
}
public static GameObject CreateCanvas(RenderMode renderMode, int referencePixelsPerUnit)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
GameObject obj = CreateCanvas(renderMode);
obj.GetComponent<CanvasScaler>().referencePixelsPerUnit = referencePixelsPerUnit;
return obj;
}
public static GameObject CreateCanvas(RenderMode renderMode, Vector2 size)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
GameObject obj = CreateCanvas(renderMode);
obj.GetComponent<CanvasScaler>().referenceResolution = size;
return obj;
}
private static GameObject CreateCanvas(RenderMode renderMode)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_002c: Expected O, but got Unknown
GameObject val = new GameObject();
val.AddComponent<Canvas>().renderMode = renderMode;
val.AddComponent<CanvasScaler>().uiScaleMode = (ScaleMode)1;
val.AddComponent<GraphicRaycaster>();
val.AddComponent<CanvasGroup>();
return val;
}
public static GameObject CreateTextPanel(GameObject parent, string text, int fontSize, TextAnchor textAnchor, RectData rectData, Font font)
{
//IL_002b: Unknown result type (might be due to invalid IL or missing references)
GameObject obj = CreateBasePanel(parent, rectData);
Text obj2 = obj.AddComponent<Text>();
obj2.font = font;
obj2.text = text;
obj2.supportRichText = true;
obj2.fontSize = fontSize;
obj2.alignment = textAnchor;
return obj;
}
public static GameObject CreateTextPanel(GameObject parent, string text, int fontSize, TextAnchor textAnchor, RectData rectData, bool bold = true)
{
//IL_0028: Unknown result type (might be due to invalid IL or missing references)
Font val = (bold ? Fonts.TrajanBold : Fonts.TrajanNormal);
if ((Object)(object)val == (Object)null)
{
throw new ArgumentException("Could not load Trajan font");
}
return CreateTextPanel(parent, text, fontSize, textAnchor, rectData, val);
}
public static GameObject CreateImagePanel(GameObject parent, Sprite sprite, RectData rectData)
{
GameObject obj = CreateBasePanel(parent, rectData);
Image obj2 = obj.AddComponent<Image>();
obj2.sprite = sprite;
obj2.preserveAspect = true;
obj2.useSpriteMesh = true;
return obj;
}
public static GameObject CreateButton(GameObject parent, Action<int> action, int id, Sprite spr, string text, int fontSize, TextAnchor textAnchor, RectData rectData, bool bold = true, params Sprite[] extraSprites)
{
//IL_0021: 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_0060: Expected O, but got Unknown
//IL_0077: Unknown result type (might be due to invalid IL or missing references)
//IL_009e: Unknown result type (might be due to invalid IL or missing references)
//IL_00a0: 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)
Action<int> action2 = action;
GameObject obj = CreateBasePanel(parent, rectData);
CreateTextPanel(obj, text, fontSize, textAnchor, rectData, bold);
Image val = obj.AddComponent<Image>();
val.sprite = spr;
Button val2 = obj.AddComponent<Button>();
((Selectable)val2).targetGraphic = (Graphic)(object)val;
((UnityEvent)val2.onClick).AddListener((UnityAction)delegate
{
action2(id);
});
if (extraSprites.Length == 3)
{
((Selectable)val2).transition = (Transition)2;
((Selectable)val2).targetGraphic = (Graphic)(object)val;
SpriteState val3 = default(SpriteState);
((SpriteState)(ref val3)).highlightedSprite = extraSprites[0];
((SpriteState)(ref val3)).pressedSprite = extraSprites[1];
((SpriteState)(ref val3)).disabledSprite = extraSprites[2];
SpriteState spriteState = val3;
((Selectable)val2).spriteState = spriteState;
return obj;
}
((Selectable)val2).transition = (Transition)0;
return obj;
}
public static GameObject CreateToggle(GameObject parent, Action<bool> action, Sprite boxBgSprite, Sprite boxFgSprite, string text, int fontSize, TextAnchor textAnchor, RectData rectData, bool bold = true, bool isOn = false)
{
//IL_0059: Unknown result type (might be due to invalid IL or missing references)
//IL_0075: Unknown result type (might be due to invalid IL or missing references)
//IL_0095: Unknown result type (might be due to invalid IL or missing references)
//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
Action<bool> action2 = action;
GameObject obj = CreateBasePanel(parent, rectData);
GameObject val = CreateImagePanel(obj, boxBgSprite, rectData);
GameObject val2 = CreateImagePanel(val, boxFgSprite, rectData);
Toggle val3 = obj.AddComponent<Toggle>();
val3.isOn = isOn;
((Selectable)val3).targetGraphic = (Graphic)(object)val.GetComponent<Image>();
val3.graphic = (Graphic)(object)val2.GetComponent<Image>();
((Selectable)val3).transition = (Transition)1;
ColorBlock val4 = default(ColorBlock);
((ColorBlock)(ref val4)).normalColor = new Color(1f, 1f, 1f, 1f);
((ColorBlock)(ref val4)).highlightedColor = new Color(1f, 1f, 1f, 1f);
((ColorBlock)(ref val4)).pressedColor = new Color(0.8f, 0.8f, 0.8f, 1f);
((ColorBlock)(ref val4)).disabledColor = new Color(0.8f, 0.8f, 0.8f, 0.5f);
((ColorBlock)(ref val4)).fadeDuration = 0.1f;
ColorBlock colors = val4;
((Selectable)val3).colors = colors;
((UnityEvent<bool>)(object)val3.onValueChanged).AddListener((UnityAction<bool>)delegate(bool b)
{
action2(b);
});
ToggleGroup component = parent.GetComponent<ToggleGroup>();
if ((Object)(object)component != (Object)null)
{
val3.group = component;
}
return obj;
}
public static GameObject CreateToggleGroup()
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: 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_004c: Unknown result type (might be due to invalid IL or missing references)
//IL_005b: Expected O, but got Unknown
//IL_005b: Unknown result type (might be due to invalid IL or missing references)
//IL_0063: Expected O, but got Unknown
GameObject val = new GameObject();
AddRectTransform(val, new RectData(new Vector2(0f, 0f), new Vector2(0f, 0f), new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f)));
val.AddComponent<ToggleGroup>();
return val;
}
public static GameObject CreateRectMask2DPanel(GameObject parent, RectData rectData)
{
GameObject obj = CreateBasePanel(parent, rectData);
obj.AddComponent<RectMask2D>();
return obj;
}
[IteratorStateMachine(typeof(<FadeInCanvasGroup>d__12))]
public static IEnumerator FadeInCanvasGroup(CanvasGroup cg)
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <FadeInCanvasGroup>d__12(0)
{
cg = cg
};
}
[IteratorStateMachine(typeof(<FadeOutCanvasGroup>d__13))]
public static IEnumerator FadeOutCanvasGroup(CanvasGroup cg)
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <FadeOutCanvasGroup>d__13(0)
{
cg = cg
};
}
}
[BepInPlugin("io.github.flibber-hk.canvasutil", "CanvasUtil", "1.0.0")]
public class CanvasUtilPlugin : BaseUnityPlugin
{
public const string Id = "io.github.flibber-hk.canvasutil";
public static string Name => "CanvasUtil";
public static string Version => "1.0.0";
private void Awake()
{
((BaseUnityPlugin)this).Logger.LogInfo((object)("Plugin " + Name + " (io.github.flibber-hk.canvasutil) has loaded!"));
}
}
public class DebugPanel : MonoBehaviour
{
[RequireComponent(typeof(Text))]
private class TextUpdate : MonoBehaviour
{
private Text _text;
public Func<string>? Generator { get; set; }
private void Awake()
{
_text = ((Component)this).GetComponent<Text>();
}
private void Update()
{
_text.text = Generator?.Invoke() ?? string.Empty;
}
}
private const int FONT_SIZE = 18;
private GameObject basePanel;
private static readonly string[] OSFonts = new string[4] { "Consolas", "Menlo", "Courier New", "DejaVu Mono" };
private static Font? _font;
public Text Text { get; private set; }
public static Font DefaultFont
{
get
{
if ((Object)(object)_font == (Object)null)
{
_font = Font.CreateDynamicFontFromOSFont(OSFonts, 18);
}
return _font;
}
}
public static DebugPanel Create(Func<string>? generator = null)
{
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_0044: 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_0062: Unknown result type (might be due to invalid IL or missing references)
//IL_0071: Unknown result type (might be due to invalid IL or missing references)
//IL_0080: 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_00c7: Unknown result type (might be due to invalid IL or missing references)
//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
GameObject obj = CanvasUtil.CreateCanvas((RenderMode)0, new Vector2(1920f, 1080f));
((Object)obj).name = "DebugPanel Canvas";
CanvasGroup component = obj.GetComponent<CanvasGroup>();
component.interactable = false;
component.blocksRaycasts = false;
Object.DontDestroyOnLoad((Object)(object)obj);
GameObject val = CanvasUtil.CreateBasePanel(obj, new RectData(new Vector2(550f, 700f), new Vector2(100f, -300f), new Vector2(0f, 1f), new Vector2(0f, 1f), new Vector2(0f, 1f)));
((Graphic)val.AddComponent<Image>()).color = new Color(0f, 0f, 0f, 0.25f);
GameObject val2 = CanvasUtil.CreateTextPanel(val, string.Empty, 18, (TextAnchor)0, new RectData(new Vector2(500f, 650f), new Vector2(25f, -25f)), DefaultFont);
if (generator != null)
{
val2.AddComponent<TextUpdate>().Generator = generator;
}
DebugPanel debugPanel = obj.AddComponent<DebugPanel>();
debugPanel.Text = val2.GetComponent<Text>();
debugPanel.basePanel = val;
return debugPanel;
}
public void SetText(string s)
{
Text.text = s;
}
public void SetPanelVisible(bool visible)
{
GameObject obj = basePanel;
if (obj != null)
{
obj.SetActive(visible);
}
}
}
public static class Fonts
{
private static Font? _trajanBold;
private static Font? _trajanNormal;
private static readonly Dictionary<string, Font> fonts = new Dictionary<string, Font>();
public static Font? TrajanBold
{
get
{
if (!Object.op_Implicit((Object)(object)_trajanBold))
{
CreateFonts();
}
return _trajanBold;
}
}
public static Font? TrajanNormal
{
get
{
if (!Object.op_Implicit((Object)(object)_trajanNormal))
{
CreateFonts();
}
return _trajanNormal;
}
}
private static void CreateFonts()
{
Font[] array = Resources.FindObjectsOfTypeAll<Font>();
foreach (Font val in array)
{
if ((Object)(object)val != (Object)null && ((Object)val).name == "TrajanPro-Bold")
{
_trajanBold = val;
}
if ((Object)(object)val != (Object)null && ((Object)val).name == "TrajanPro-Regular")
{
_trajanNormal = val;
}
}
}
public static Font? GetFont(string fontName)
{
if (fonts.ContainsKey(fontName))
{
return fonts[fontName];
}
Font[] array = Resources.FindObjectsOfTypeAll<Font>();
foreach (Font val in array)
{
if ((Object)(object)val != (Object)null && ((Object)val).name == fontName)
{
fonts.Add(fontName, val);
break;
}
}
if (!fonts.TryGetValue(fontName, out Font value))
{
return null;
}
return value;
}
}
public class RectData
{
public Vector2 AnchorMax;
public Vector2 AnchorMin;
public Vector2 AnchorPivot;
public Vector2 AnchorPosition;
public Vector2 RectSizeDelta;
public RectData(Vector2 sizeDelta, Vector2 anchorPosition)
: this(sizeDelta, anchorPosition, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f))
{
}//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
//IL_002b: Unknown result type (might be due to invalid IL or missing references)
public RectData(Vector2 sizeDelta, Vector2 anchorPosition, Vector2 min, Vector2 max)
: this(sizeDelta, anchorPosition, min, max, new Vector2(0.5f, 0.5f))
{
}//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0003: Unknown result type (might be due to invalid IL or missing references)
//IL_0004: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
public RectData(Vector2 sizeDelta, Vector2 anchorPosition, Vector2 min, Vector2 max, Vector2 pivot)
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
RectSizeDelta = sizeDelta;
AnchorPosition = anchorPosition;
AnchorMin = min;
AnchorMax = max;
AnchorPivot = pivot;
}
}
}