public void Queue(SpriteDownloadInfo emote)
 {
     _spriteDownloadQueue.Push(emote);
 }
        public static IEnumerator Download(string spritePath, SpriteDownloadInfo spriteDownloadInfo, bool isRetry = false)
        {
            Instance._loaderBusy = true;
            if (!CachedSprites.ContainsKey(spriteDownloadInfo.index))
            {
                string origSpritePath = spritePath;

                string spriteCachePath = "Cache\\Sprites";
                if (!Directory.Exists(spriteCachePath))
                {
                    Directory.CreateDirectory(spriteCachePath);
                }

                string typePath = $"{spriteCachePath}\\{ImageTypeNames.Get(spriteDownloadInfo.type)}";
                if (!Directory.Exists(typePath))
                {
                    Directory.CreateDirectory(typePath);
                }

                bool   localPathExists = false;
                string localFilePath   = $"{typePath}\\{spriteDownloadInfo.index}";
                if (File.Exists(localFilePath))
                {
                    localPathExists = true;
                    spritePath      = $"{Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase).Replace("\\Plugins", "")}\\{localFilePath}";
                    //Plugin.Log("Local path exists!");
                }
                else
                {
                    if (spriteDownloadInfo.type == ImageType.Emoji)
                    {
                        Plugin.Log($"Local path did not exist for Emoji {spriteDownloadInfo.index}!");
                        while (!CachedSprites.TryAdd(spriteDownloadInfo.index, new CachedSpriteData((Sprite)null)))
                        {
                            yield return(null);
                        }
                        Instance._loaderBusy = false;
                        yield break;
                    }
                    //Plugin.Log($"Path {spritePath} does not exist!");
                }

                Sprite sprite;
                using (var web = UnityWebRequestTexture.GetTexture(spritePath, true)) {
                    yield return(web.SendWebRequest());

                    if (web.isNetworkError || web.isHttpError)
                    {
                        Plugin.Log($"An error occured when requesting emote {spriteDownloadInfo.index}, Message: \"{web.error}\"");
                        if (spriteDownloadInfo.type == ImageType.BTTV_Animated)
                        {
                            while (!CachedSprites.TryAdd(spriteDownloadInfo.index, null))
                            {
                                yield return(null);
                            }
                        }
                        else
                        {
                            while (!CachedSprites.TryAdd(spriteDownloadInfo.index, new CachedSpriteData((Sprite)null)))
                            {
                                yield return(null);
                            }
                        }
                        sprite = null;
                    }
                    else
                    {
                        //Plugin.Log("Success loading emote!");
                        if (spriteDownloadInfo.type == ImageType.BTTV_Animated)
                        {
                            while (!CachedSprites.TryAdd(spriteDownloadInfo.index, null))
                            {
                                yield return(null);
                            }
                            yield return(AnimatedSpriteDecoder.Process(web.downloadHandler.data, GetTextureListCallback, spriteDownloadInfo.index));

                            if (!localPathExists)
                            {
                                SpriteSaveQueue.Push(new TextureSaveInfo(localFilePath, web.downloadHandler.data));
                            }
                        }
                        else
                        {
                            var tex = DownloadHandlerTexture.GetContent(web);

                            bool success = false;
                            try
                            {
                                sprite  = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), new Vector2(0, 0), Plugin.PixelsPerUnit);
                                success = true;
                            }
                            catch (Exception e)
                            {
                                Plugin.Log(e.ToString());
                                if (File.Exists(localFilePath))
                                {
                                    File.Delete(localFilePath);
                                }
                                sprite = null;
                            }

                            if (!success && !isRetry)
                            {
                                yield return(Download(origSpritePath, spriteDownloadInfo, true));

                                yield break;
                            }

                            while (!CachedSprites.TryAdd(spriteDownloadInfo.index, new CachedSpriteData(sprite)))
                            {
                                yield return(null);
                            }
                            if (!localPathExists && success)
                            {
                                SpriteSaveQueue.Push(new TextureSaveInfo(localFilePath, web.downloadHandler.data));
                            }
                        }
                    }
                }
                //Plugin.Log($"Web request completed, {CachedSprites.Count} emotes now cached!");
            }
            Instance.waitForFrames = 2;
            Instance._loaderBusy   = false;
        }