Fix issues with icon loading
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
@@ -40,8 +41,12 @@ public class CustomIconLoader : MonoBehaviour
|
|||||||
var cachedIcon = BazookaManager.Instance.iconCache.FirstOrDefault(icon => icon.ID == obj.ID);
|
var cachedIcon = BazookaManager.Instance.iconCache.FirstOrDefault(icon => icon.ID == obj.ID);
|
||||||
if (cachedIcon != null)
|
if (cachedIcon != null)
|
||||||
{
|
{
|
||||||
try { Tools.RenderFromBase64(Tools.FixIconData(cachedIcon.Data).Item1, obj.GetComponent<Image>()); }
|
var (d, h) = Tools.FixIconData(cachedIcon.Data);
|
||||||
catch { Tools.RenderFromBase64(Tools.FixIconData(cachedIcon.Data).Item1, obj.GetComponent<SpriteRenderer>()); }
|
if (d != null && h != null && Tools.Sha512Sum(Convert.FromBase64String(d)) == h)
|
||||||
|
{
|
||||||
|
try { Tools.RenderFromBase64(d, obj.GetComponent<Image>()); }
|
||||||
|
catch { Tools.RenderFromBase64(d, obj.GetComponent<SpriteRenderer>()); }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Destroy(obj);
|
Destroy(obj);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -166,8 +166,8 @@ public class IconMarketplaceDownloadIcon : MonoBehaviour
|
|||||||
{
|
{
|
||||||
GameObject newIcon = Instantiate(sample, content.transform);
|
GameObject newIcon = Instantiate(sample, content.transform);
|
||||||
newIcon.name = "IconEntry";
|
newIcon.name = "IconEntry";
|
||||||
|
var (d, h) = Tools.FixIconData(entry.Data);
|
||||||
Tools.RenderFromBase64(Tools.FixIconData(entry.Data).Item1, newIcon.transform.GetChild(0).GetChild(0).GetComponent<Image>());
|
if (d != null && h != null && Tools.Sha512Sum(Convert.FromBase64String(d)) == h) Tools.RenderFromBase64(d, newIcon.transform.GetChild(0).GetChild(0).GetComponent<Image>());
|
||||||
newIcon.transform.GetChild(1).GetComponent<TMP_Text>().text = "Bird Name: " + entry.Name;
|
newIcon.transform.GetChild(1).GetComponent<TMP_Text>().text = "Bird Name: " + entry.Name;
|
||||||
newIcon.transform.GetChild(2).GetComponent<TMP_Text>().text = "Price " + Tools.FormatWithCommas(entry.Price) + " coins";
|
newIcon.transform.GetChild(2).GetComponent<TMP_Text>().text = "Price " + Tools.FormatWithCommas(entry.Price) + " coins";
|
||||||
newIcon.transform.GetChild(3).GetComponent<TMP_Text>().text = "Designer Name: " + entry.CreatorUsername;
|
newIcon.transform.GetChild(3).GetComponent<TMP_Text>().text = "Designer Name: " + entry.CreatorUsername;
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ public class Iconsmenu : MonoBehaviour
|
|||||||
[SerializeField] private GameObject previewBirdObject;
|
[SerializeField] private GameObject previewBirdObject;
|
||||||
[SerializeField] private ColorPanel iconColorPanel;
|
[SerializeField] private ColorPanel iconColorPanel;
|
||||||
[SerializeField] private ColorPanel overlayColorPanel;
|
[SerializeField] private ColorPanel overlayColorPanel;
|
||||||
private Dictionary<string, Button> customIcons = new();
|
private readonly Dictionary<string, Button> customIcons = new();
|
||||||
|
|
||||||
private void Start()
|
private void Start()
|
||||||
{
|
{
|
||||||
@@ -136,12 +136,11 @@ public class Iconsmenu : MonoBehaviour
|
|||||||
if (customIconData.Selected != null)
|
if (customIconData.Selected != null)
|
||||||
foreach (var icon in customIconData.Purchased)
|
foreach (var icon in customIconData.Purchased)
|
||||||
{
|
{
|
||||||
if (icon == customIconData.Selected) SelectCustomIcon(icon);
|
if (icon == customIconData.Selected) SelectCustomIcon(icon, false);
|
||||||
customIcons[icon].interactable = icon != customIconData.Selected;
|
customIcons[icon].interactable = icon != customIconData.Selected;
|
||||||
}
|
}
|
||||||
|
|
||||||
var objects = FindObjectsByType<WaitingForCustomIcon>(FindObjectsSortMode.None);
|
RenderIcons();
|
||||||
if (objects.Length != 0) CustomIconLoader.Init(objects);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ToggleKit()
|
private void ToggleKit()
|
||||||
@@ -217,14 +216,13 @@ public class Iconsmenu : MonoBehaviour
|
|||||||
else previewOverlay.sprite = Resources.Load<Sprite>("Icons/Overlays/overlay_" + overlayID);
|
else previewOverlay.sprite = Resources.Load<Sprite>("Icons/Overlays/overlay_" + overlayID);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SelectCustomIcon(string icon)
|
void SelectCustomIcon(string icon, bool renderIcons = true)
|
||||||
{
|
{
|
||||||
var customData = BazookaManager.Instance.GetCustomBirdIconData();
|
var customData = BazookaManager.Instance.GetCustomBirdIconData();
|
||||||
customData.Selected = icon;
|
customData.Selected = icon;
|
||||||
BazookaManager.Instance.SetCustomBirdIconData(customData);
|
BazookaManager.Instance.SetCustomBirdIconData(customData);
|
||||||
var waitingForCustomIcon = previewBird.AddComponent<WaitingForCustomIcon>();
|
previewBird.AddComponent<WaitingForCustomIcon>().ID = icon;
|
||||||
waitingForCustomIcon.ID = icon;
|
if (renderIcons) RenderIcons();
|
||||||
CustomIconLoader.Init(new[] { waitingForCustomIcon });
|
|
||||||
previewBird.color = Color.white;
|
previewBird.color = Color.white;
|
||||||
previewOverlay.gameObject.SetActive(false);
|
previewOverlay.gameObject.SetActive(false);
|
||||||
previewOverlay.sprite = null;
|
previewOverlay.sprite = null;
|
||||||
@@ -239,4 +237,10 @@ public class Iconsmenu : MonoBehaviour
|
|||||||
{
|
{
|
||||||
if (Keyboard.current.escapeKey.wasPressedThisFrame) await SceneManager.LoadSceneAsync("MainMenu");
|
if (Keyboard.current.escapeKey.wasPressedThisFrame) await SceneManager.LoadSceneAsync("MainMenu");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RenderIcons()
|
||||||
|
{
|
||||||
|
var objects = FindObjectsByType<WaitingForCustomIcon>(FindObjectsSortMode.None);
|
||||||
|
if (objects.Length != 0) CustomIconLoader.Init(objects);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
|
using System.Security.Cryptography;
|
||||||
|
using System.Text;
|
||||||
using TMPro;
|
using TMPro;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
@@ -66,26 +68,45 @@ public static class Tools
|
|||||||
|
|
||||||
public static (string, string) FixIconData(string i)
|
public static (string, string) FixIconData(string i)
|
||||||
{
|
{
|
||||||
int t = i.Length;
|
try
|
||||||
int h = 128;
|
{
|
||||||
int d = t - h;
|
int t = i.Length;
|
||||||
int a = d / 4;
|
int h = 128;
|
||||||
int b = h / 4;
|
int d = t - h;
|
||||||
|
int a = d / 4;
|
||||||
|
int b = h / 4;
|
||||||
|
|
||||||
string D = string.Concat(
|
string D = string.Concat(
|
||||||
i.Substring(0, a),
|
i.Substring(0, a),
|
||||||
i.Substring(a + b, a),
|
i.Substring(a + b, a),
|
||||||
i.Substring(a * 2 + b * 2, a),
|
i.Substring(a * 2 + b * 2, a),
|
||||||
i.Substring(a * 3 + b * 3, d - a * 3)
|
i.Substring(a * 3 + b * 3, d - a * 3)
|
||||||
);
|
);
|
||||||
|
|
||||||
string H = string.Concat(
|
string H = string.Concat(
|
||||||
i.Substring(a, b),
|
i.Substring(a, b),
|
||||||
i.Substring(a * 2 + b, b),
|
i.Substring(a * 2 + b, b),
|
||||||
i.Substring(a * 3 + b * 2, b),
|
i.Substring(a * 3 + b * 2, b),
|
||||||
i.Substring(a * 4 + b * 3, b)
|
i.Substring(a * 4 + b * 3, b)
|
||||||
);
|
);
|
||||||
|
|
||||||
return (D, H);
|
return (D, H);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return (null, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string Sha512Sum(byte[] data)
|
||||||
|
{
|
||||||
|
using var sha512 = SHA512.Create();
|
||||||
|
var hash = sha512.ComputeHash(data);
|
||||||
|
|
||||||
|
var sb = new StringBuilder(hash.Length * 2);
|
||||||
|
foreach (var b in hash)
|
||||||
|
sb.Append(b.ToString("x2"));
|
||||||
|
|
||||||
|
return sb.ToString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user