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 GlitnirCanvas v0.1.1
GlitnirCanvas.dll
Decompiled 2 hours agousing 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.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Logging; using HarmonyLib; using Microsoft.CodeAnalysis; using UnityEngine; 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: TargetFramework(".NETFramework,Version=v4.8.1", FrameworkDisplayName = ".NET Framework 4.8.1")] [assembly: AssemblyCompany("GlitnirCanvas")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("GlitnirCanvas")] [assembly: AssemblyTitle("GlitnirCanvas")] [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.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace GlitnirCanvas { public static class CanvasOverlay { [CompilerGenerated] private sealed class <FadeOutAndDestroy>d__11 : IEnumerator<object>, IDisposable, IEnumerator { private int <>1__state; private object <>2__current; public float duration; private GameObject <rootCopy>5__1; private CanvasGroup <groupCopy>5__2; private float <elapsed>5__3; object IEnumerator<object>.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public <FadeOutAndDestroy>d__11(int <>1__state) { this.<>1__state = <>1__state; } [DebuggerHidden] void IDisposable.Dispose() { <rootCopy>5__1 = null; <groupCopy>5__2 = null; <>1__state = -2; } private bool MoveNext() { switch (<>1__state) { default: return false; case 0: <>1__state = -1; <rootCopy>5__1 = _root; <groupCopy>5__2 = (((Object)(object)<rootCopy>5__1 != (Object)null) ? <rootCopy>5__1.AddComponent<CanvasGroup>() : null); _imageGroup = null; _rawImage = null; _coroutineRunner = null; _root = null; <elapsed>5__3 = 0f; break; case 1: <>1__state = -1; break; } if (<elapsed>5__3 < duration && (Object)(object)<groupCopy>5__2 != (Object)null) { <elapsed>5__3 += Time.deltaTime; <groupCopy>5__2.alpha = Mathf.Lerp(1f, 0f, <elapsed>5__3 / duration); <>2__current = null; <>1__state = 1; return true; } if ((Object)(object)<rootCopy>5__1 != (Object)null) { Object.Destroy((Object)(object)<rootCopy>5__1); } if ((Object)(object)_currentTexture != (Object)null) { Object.Destroy((Object)(object)_currentTexture); _currentTexture = null; } Plugin.Log.LogInfo((object)"[GlitnirCanvas] Overlay removido."); return false; } 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 <FadeTo>d__10 : IEnumerator<object>, IDisposable, IEnumerator { private int <>1__state; private object <>2__current; public float target; public float duration; private float <elapsed>5__1; private float <start>5__2; object IEnumerator<object>.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public <FadeTo>d__10(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; if ((Object)(object)_imageGroup == (Object)null) { return false; } <elapsed>5__1 = 0f; <start>5__2 = _imageGroup.alpha; break; case 1: <>1__state = -1; break; } if (<elapsed>5__1 < duration) { if ((Object)(object)_imageGroup == (Object)null) { return false; } <elapsed>5__1 += Time.deltaTime; _imageGroup.alpha = Mathf.Lerp(<start>5__2, target, <elapsed>5__1 / duration); <>2__current = null; <>1__state = 1; return true; } if ((Object)(object)_imageGroup != (Object)null) { _imageGroup.alpha = target; } return false; } 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 <Slideshow>d__9 : IEnumerator<object>, IDisposable, IEnumerator { private int <>1__state; private object <>2__current; public ImageFolder folder; private Texture2D <next>5__1; private Texture2D <old>5__2; object IEnumerator<object>.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public <Slideshow>d__9(int <>1__state) { this.<>1__state = <>1__state; } [DebuggerHidden] void IDisposable.Dispose() { <next>5__1 = null; <old>5__2 = null; <>1__state = -2; } private bool MoveNext() { //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Expected O, but got Unknown //IL_0115: Unknown result type (might be due to invalid IL or missing references) switch (<>1__state) { default: return false; case 0: <>1__state = -1; break; case 1: <>1__state = -1; if ((Object)(object)_root == (Object)null || (Object)(object)_imageGroup == (Object)null) { return false; } <>2__current = FadeTo(0f, 0.4f); <>1__state = 2; return true; case 2: <>1__state = -1; if ((Object)(object)_root == (Object)null || (Object)(object)_rawImage == (Object)null) { return false; } <next>5__1 = ImageManager.GetRandom(folder); if ((Object)(object)<next>5__1 != (Object)null) { <old>5__2 = _currentTexture; _currentTexture = <next>5__1; _rawImage.texture = (Texture)(object)<next>5__1; _rawImage.uvRect = CalculateUvRect(<next>5__1); if ((Object)(object)<old>5__2 != (Object)null) { Object.Destroy((Object)(object)<old>5__2); } <old>5__2 = null; } if ((Object)(object)_root == (Object)null || (Object)(object)_imageGroup == (Object)null) { return false; } <>2__current = FadeTo(1f, 0.4f); <>1__state = 3; return true; case 3: <>1__state = -1; <next>5__1 = null; break; } <>2__current = (object)new WaitForSeconds(4f); <>1__state = 1; 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(); } } private static GameObject _root; private static Texture2D _currentTexture; private static RawImage _rawImage; private static CanvasGroup _imageGroup; private static MonoBehaviour _coroutineRunner; public static bool IsVisible => (Object)(object)_root != (Object)null; public static void Show(ImageFolder folder) { //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Expected O, but got Unknown //IL_0091: Unknown result type (might be due to invalid IL or missing references) //IL_0097: Expected O, but got Unknown //IL_00b6: Unknown result type (might be due to invalid IL or missing references) //IL_00c2: Unknown result type (might be due to invalid IL or missing references) //IL_00ce: Unknown result type (might be due to invalid IL or missing references) //IL_00da: Unknown result type (might be due to invalid IL or missing references) //IL_00ef: Unknown result type (might be due to invalid IL or missing references) //IL_00ff: Unknown result type (might be due to invalid IL or missing references) //IL_0106: Expected O, but got Unknown //IL_0129: Unknown result type (might be due to invalid IL or missing references) //IL_0136: Unknown result type (might be due to invalid IL or missing references) //IL_0143: Unknown result type (might be due to invalid IL or missing references) //IL_0150: Unknown result type (might be due to invalid IL or missing references) //IL_0179: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)_root != (Object)null) { Hide(); } Texture2D random = ImageManager.GetRandom(folder); if (!((Object)(object)random == (Object)null)) { _currentTexture = random; _root = new GameObject("GlitnirCanvas_Overlay"); Object.DontDestroyOnLoad((Object)(object)_root); Canvas val = _root.AddComponent<Canvas>(); val.renderMode = (RenderMode)0; val.sortingOrder = 9999; _root.AddComponent<CanvasScaler>().uiScaleMode = (ScaleMode)1; _root.AddComponent<GraphicRaycaster>(); GameObject val2 = new GameObject("GlitnirCanvas_Background"); val2.transform.SetParent(_root.transform, false); RectTransform val3 = val2.AddComponent<RectTransform>(); val3.anchorMin = Vector2.zero; val3.anchorMax = Vector2.one; val3.offsetMin = Vector2.zero; val3.offsetMax = Vector2.zero; Image val4 = val2.AddComponent<Image>(); ((Graphic)val4).color = Color.black; GameObject val5 = new GameObject("GlitnirCanvas_Image"); val5.transform.SetParent(_root.transform, false); RectTransform val6 = val5.AddComponent<RectTransform>(); val6.anchorMin = Vector2.zero; val6.anchorMax = Vector2.one; val6.offsetMin = Vector2.zero; val6.offsetMax = Vector2.zero; _rawImage = val5.AddComponent<RawImage>(); _rawImage.texture = (Texture)(object)random; _rawImage.uvRect = CalculateUvRect(random); _imageGroup = val5.AddComponent<CanvasGroup>(); _imageGroup.alpha = 0f; _coroutineRunner = (MonoBehaviour)(object)_root.AddComponent<CoroutineRunner>(); _coroutineRunner.StartCoroutine(FadeTo(1f, 0.6f)); _coroutineRunner.StartCoroutine(Slideshow(folder)); Plugin.Log.LogInfo((object)"[GlitnirCanvas] Overlay exibido."); } } public static void Hide() { if ((Object)(object)_root != (Object)null && (Object)(object)_coroutineRunner != (Object)null) { _coroutineRunner.StartCoroutine(FadeOutAndDestroy(0.6f)); } else { DestroyAll(); } } [IteratorStateMachine(typeof(<Slideshow>d__9))] private static IEnumerator Slideshow(ImageFolder folder) { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new <Slideshow>d__9(0) { folder = folder }; } [IteratorStateMachine(typeof(<FadeTo>d__10))] private static IEnumerator FadeTo(float target, float duration) { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new <FadeTo>d__10(0) { target = target, duration = duration }; } [IteratorStateMachine(typeof(<FadeOutAndDestroy>d__11))] private static IEnumerator FadeOutAndDestroy(float duration) { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new <FadeOutAndDestroy>d__11(0) { duration = duration }; } private static void DestroyAll() { GameObject root = _root; _root = null; _rawImage = null; _imageGroup = null; _coroutineRunner = null; if ((Object)(object)root != (Object)null) { Object.Destroy((Object)(object)root); } if ((Object)(object)_currentTexture != (Object)null) { Object.Destroy((Object)(object)_currentTexture); _currentTexture = null; } Plugin.Log.LogInfo((object)"[GlitnirCanvas] Overlay removido."); } private static Rect CalculateUvRect(Texture2D tex) { //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_009d: Unknown result type (might be due to invalid IL or missing references) //IL_0070: 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_00a0: Unknown result type (might be due to invalid IL or missing references) float num = (float)Screen.width / (float)Screen.height; float num2 = (float)((Texture)tex).width / (float)((Texture)tex).height; if (Mathf.Approximately(num, num2)) { return new Rect(0f, 0f, 1f, 1f); } if (num2 > num) { float num3 = num / num2; return new Rect((1f - num3) / 2f, 0f, num3, 1f); } float num4 = num2 / num; return new Rect(0f, (1f - num4) / 2f, 1f, num4); } } public class CoroutineRunner : MonoBehaviour { } public static class ImageManager { private static string _loadingFolder; private static string _teleportFolder; private static readonly Random Rng = new Random(); private static MethodInfo _loadImageMethod; public static void Init() { string path = Path.Combine(Paths.PluginPath, "GlitnirCanvas", "images"); _loadingFolder = Path.Combine(path, "loading"); _teleportFolder = Path.Combine(path, "teleport"); Directory.CreateDirectory(_loadingFolder); Directory.CreateDirectory(_teleportFolder); Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); foreach (Assembly assembly in assemblies) { if (assembly.GetName().Name == "UnityEngine.ImageConversionModule") { Type type = assembly.GetType("UnityEngine.ImageConversion"); if (type != null) { _loadImageMethod = type.GetMethod("LoadImage", new Type[2] { typeof(Texture2D), typeof(byte[]) }); } break; } } Plugin.Log.LogInfo((object)("[GlitnirCanvas] Pasta loading: " + _loadingFolder)); Plugin.Log.LogInfo((object)("[GlitnirCanvas] Pasta teleport: " + _teleportFolder)); Plugin.Log.LogInfo((object)$"[GlitnirCanvas] LoadImage encontrado: {_loadImageMethod != null}"); } public static Texture2D GetRandom(ImageFolder folder) { string text = ((folder == ImageFolder.Loading) ? _loadingFolder : _teleportFolder); string[] array = (from f in Directory.GetFiles(text, "*.*") where f.EndsWith(".png", StringComparison.OrdinalIgnoreCase) || f.EndsWith(".jpg", StringComparison.OrdinalIgnoreCase) || f.EndsWith(".jpeg", StringComparison.OrdinalIgnoreCase) select f).ToArray(); if (array.Length == 0) { Plugin.Log.LogWarning((object)("[GlitnirCanvas] Nenhuma imagem em: " + text)); return null; } for (int i = 0; i < Mathf.Min(3, array.Length); i++) { string path = array[Rng.Next(array.Length)]; Plugin.Log.LogInfo((object)("[GlitnirCanvas] Tentando: " + Path.GetFileName(path))); Texture2D val = TryLoad(path); if ((Object)(object)val != (Object)null) { return val; } } Plugin.Log.LogError((object)"[GlitnirCanvas] Nenhuma imagem válida encontrada após 3 tentativas."); return null; } private static Texture2D TryLoad(string path) { //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Expected O, but got Unknown try { byte[] array = File.ReadAllBytes(path); if (array.Length < 8) { Plugin.Log.LogWarning((object)("[GlitnirCanvas] Arquivo muito pequeno, ignorando: " + Path.GetFileName(path))); return null; } Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false); if (_loadImageMethod != null) { _loadImageMethod.Invoke(null, new object[2] { val, array }); if (((Texture)val).width <= 2 && ((Texture)val).height <= 2) { Plugin.Log.LogWarning((object)("[GlitnirCanvas] Imagem corrompida ou inválida: " + Path.GetFileName(path))); Object.Destroy((Object)(object)val); return null; } return val; } Plugin.Log.LogError((object)"[GlitnirCanvas] LoadImage não encontrado!"); return null; } catch (Exception ex) { Plugin.Log.LogWarning((object)("[GlitnirCanvas] Erro ao carregar " + Path.GetFileName(path) + ": " + ex.Message)); return null; } } } public enum ImageFolder { Loading, Teleport } [BepInPlugin("glitnir.canvas", "GlitnirCanvas", "1.0.0")] public class Plugin : BaseUnityPlugin { public const string PluginGUID = "glitnir.canvas"; public const string PluginName = "GlitnirCanvas"; public const string PluginVersion = "1.0.0"; internal static ManualLogSource Log; private readonly Harmony _harmony = new Harmony("glitnir.canvas"); private void Awake() { Log = ((BaseUnityPlugin)this).Logger; ImageManager.Init(); _harmony.PatchAll(); Log.LogInfo((object)"GlitnirCanvas 1.0.0 carregado!"); } private void OnDestroy() { _harmony.UnpatchSelf(); } } } namespace GlitnirCanvas.Patches { [HarmonyPatch] public static class LoadingPatch { [HarmonyPatch(typeof(ZNet), "SetServer")] [HarmonyPostfix] private static void OnSetServer() { if (!CanvasOverlay.IsVisible) { CanvasOverlay.Show(ImageFolder.Loading); } } [HarmonyPatch(typeof(Player), "OnSpawned")] [HarmonyPostfix] private static void OnPlayerSpawned() { if (CanvasOverlay.IsVisible) { CanvasOverlay.Hide(); } } [HarmonyPatch(typeof(ZNet), "Disconnect")] [HarmonyPostfix] private static void OnDisconnect() { if (CanvasOverlay.IsVisible) { CanvasOverlay.Hide(); } } } [HarmonyPatch] public static class TeleportPatch { [CompilerGenerated] private sealed class <WaitAndHide>d__1 : IEnumerator<object>, IDisposable, IEnumerator { private int <>1__state; private object <>2__current; private Player <player>5__1; private bool <isTeleporting>5__2; private bool <isSleeping>5__3; private bool <isAttached>5__4; object IEnumerator<object>.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public <WaitAndHide>d__1(int <>1__state) { this.<>1__state = <>1__state; } [DebuggerHidden] void IDisposable.Dispose() { <player>5__1 = null; <>1__state = -2; } private bool MoveNext() { //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Expected O, but got Unknown //IL_0107: Unknown result type (might be due to invalid IL or missing references) //IL_0111: Expected O, but got Unknown //IL_00d8: Unknown result type (might be due to invalid IL or missing references) //IL_00e2: Expected O, but got Unknown switch (<>1__state) { default: return false; case 0: <>1__state = -1; <>2__current = (object)new WaitForSeconds(1f); <>1__state = 1; return true; case 1: <>1__state = -1; goto IL_00fa; case 2: <>1__state = -1; <player>5__1 = null; goto IL_00fa; case 3: { <>1__state = -1; CanvasOverlay.Hide(); return false; } IL_00fa: <player>5__1 = Player.m_localPlayer; if (!((Object)(object)<player>5__1 == (Object)null)) { <isTeleporting>5__2 = ((Character)<player>5__1).IsTeleporting(); <isSleeping>5__3 = <player>5__1.IsSleeping(); <isAttached>5__4 = ((Character)<player>5__1).IsAttached(); if (<isTeleporting>5__2 || <isSleeping>5__3 || <isAttached>5__4) { <>2__current = (object)new WaitForSeconds(0.2f); <>1__state = 2; return true; } } <>2__current = (object)new WaitForSeconds(0.5f); <>1__state = 3; 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(); } } [HarmonyPatch(typeof(Player), "TeleportTo")] [HarmonyPostfix] private static void OnTeleportTo(bool __result) { if (__result) { CanvasOverlay.Show(ImageFolder.Teleport); if ((Object)(object)Player.m_localPlayer != (Object)null) { ((MonoBehaviour)Player.m_localPlayer).StartCoroutine(WaitAndHide()); } } } [IteratorStateMachine(typeof(<WaitAndHide>d__1))] private static IEnumerator WaitAndHide() { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new <WaitAndHide>d__1(0); } } }