public static bool TryGetSkin(string json, GraphicsDevice graphics, out Texture2D texture, out bool isSlim) { isSlim = false; try { TexturesResponse r = JsonConvert.DeserializeObject <TexturesResponse>(json); if (r != null) { string url = r.textures?.SKIN?.url; if (url != null) { byte[] data; using (WebClient wc = new WebClient()) { data = wc.DownloadData(url); } using (MemoryStream ms = new MemoryStream(data)) { texture = Texture2D.FromStream(graphics, ms); } isSlim = (r.textures.SKIN.metadata?.model == "slim"); return(true); } } } catch { } texture = null; return(false); }
public static bool TryGetSkin(string json, GraphicsDevice graphics, out PooledTexture2D texture, out bool isSlim) { isSlim = false; try { TexturesResponse r = JsonConvert.DeserializeObject <TexturesResponse>(json); if (r != null) { string url = r.textures?.SKIN?.url; if (url != null) { byte[] data; using (WebClient wc = new WebClient()) { data = wc.DownloadData(url); } ManualResetEvent resetEvent = new ManualResetEvent(false); PooledTexture2D text = null; Alex.Instance.UIThreadQueue.Enqueue( () => { using (MemoryStream ms = new MemoryStream(data)) { text = GpuResourceManager.GetTexture2D( "SkinUtils", graphics, ms); // Texture2D.FromStream(graphics, ms); } resetEvent.Set(); }); resetEvent.WaitOne(); texture = text; isSlim = (r.textures.SKIN.metadata?.model == "slim"); return(true); } } } catch (Exception ex) { Log.Warn(ex, $"Could not retrieve skin: {ex.ToString()}"); } texture = null; return(false); }