Decompiled source of DeckSmithUtil v1.0.0

DeckSmithUtil.dll

Decompiled 6 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using UnityEngine;
using UnityEngine.Networking;
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(".NETStandard,Version=v2.1", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("DeckSmithUtil")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("DeckSmithUtil")]
[assembly: AssemblyTitle("DeckSmithUtil")]
[assembly: AssemblyVersion("1.0.0.0")]
public class DeckSmithUtil : MonoBehaviour
{
	public class TextureFuture
	{
		public delegate void OnCompleteDelegate(Texture2D texture);

		public bool Ready { get; set; }

		public event OnCompleteDelegate OnComplete;

		internal void LoadTexture(Texture2D texture)
		{
			this.OnComplete?.Invoke(texture);
		}
	}

	internal static Dictionary<string, Texture2D> cachedTextures = new Dictionary<string, Texture2D>();

	private static DeckSmithUtil _instance;

	public static DeckSmithUtil Instance
	{
		get
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			if ((Object)(object)_instance == (Object)null)
			{
				GameObject val = new GameObject("DeckSmith Singleton");
				_instance = val.AddComponent<DeckSmithUtil>();
			}
			return _instance;
		}
	}

	public GameObject GetArtFromUrl(string url)
	{
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Expected O, but got Unknown
		TextureFuture textureFuture = new TextureFuture();
		GameObject val = new GameObject("Web Card Art");
		val.AddComponent<WebCardArt>().TextureFuture = textureFuture;
		((MonoBehaviour)this).StartCoroutine(GetTexture(url, textureFuture));
		return val;
	}

	internal IEnumerator GetTexture(string url, TextureFuture future)
	{
		yield return (object)new WaitUntil((Func<bool>)(() => future.Ready));
		if (cachedTextures.TryGetValue(url, out var t))
		{
			future.LoadTexture(t);
			yield break;
		}
		UnityWebRequest uwr = UnityWebRequestTexture.GetTexture(url);
		try
		{
			yield return uwr.SendWebRequest();
			if (uwr.isNetworkError || uwr.isHttpError)
			{
				Debug.Log(uwr.error);
				yield break;
			}
			Texture2D texture = DownloadHandlerTexture.GetContent(uwr);
			future.LoadTexture(texture);
		}
		finally
		{
			((IDisposable)uwr)?.Dispose();
		}
	}
}
public class WebCardArt : MonoBehaviour
{
	private RawImage renderer;

	internal DeckSmithUtil.TextureFuture TextureFuture { get; set; }

	private void Start()
	{
		renderer = ((Component)this).gameObject.AddComponent<RawImage>();
		TextureFuture.OnComplete += SetTexture;
		TextureFuture.Ready = true;
	}

	private void SetTexture(Texture2D texture)
	{
		renderer.texture = (Texture)(object)texture;
	}

	private void Update()
	{
		//IL_0012: 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_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		RectTransform component = ((Component)this).GetComponent<RectTransform>();
		if (component != null)
		{
			component.anchorMin = Vector2.zero;
			component.anchorMax = Vector2.one;
			component.pivot = Vector2.one / 2f;
			component.sizeDelta = Vector2.zero;
			Debug.Log("Found RectTransform");
		}
		else
		{
			Debug.Log("Didn't find RectTransform :(");
		}
	}
}