Upload files to "Classes/EzVersionChecking"
This commit is contained in:
1 parent
e01dbf7209
commit
07baed88f8
3 files changed
+235
No files matched your search
@@ -0,0 +1,66 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Linq;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.Networking;
|
||||||
|
|
||||||
|
// i got permission from ZlothY: https://git.hamburbur.org/ZlothY/ZlothYNametag/src/branch/main/EzVersionChecking
|
||||||
|
namespace FortniteEmoteWheel.Classes.EzVersionChecking;
|
||||||
|
|
||||||
|
public class ContinousVersionChecking : MonoBehaviour
|
||||||
|
{
|
||||||
|
private const float CheckIntervalSeconds = 60f;
|
||||||
|
|
||||||
|
private IEnumerator Start()
|
||||||
|
{
|
||||||
|
float lastCheckTime = 0f;
|
||||||
|
|
||||||
|
while (!VersionCheckingInitializer.VersionOutdated)
|
||||||
|
{
|
||||||
|
yield return null;
|
||||||
|
|
||||||
|
if (Time.time - lastCheckTime < CheckIntervalSeconds)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
lastCheckTime = Time.time;
|
||||||
|
|
||||||
|
using UnityWebRequest request = UnityWebRequest.Get("https://deez.uk/data");
|
||||||
|
|
||||||
|
yield return request.SendWebRequest();
|
||||||
|
|
||||||
|
if (request.result != UnityWebRequest.Result.Success)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
JObject data = JObject.Parse(request.downloadHandler.text);
|
||||||
|
|
||||||
|
JToken modVersionInfo = ((JArray)data["modVersionInfo"])!
|
||||||
|
.FirstOrDefault(token => (string)token["modName"] == Constants.Name);
|
||||||
|
|
||||||
|
if (modVersionInfo == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
Version latestVersion = new((string)modVersionInfo["latestVersion"]!);
|
||||||
|
Version localVersion = new(Constants.Version);
|
||||||
|
|
||||||
|
VersionCheckingInitializer.LatestVersion = latestVersion;
|
||||||
|
VersionCheckingInitializer.OutdatedMessage = (string)modVersionInfo["outdatedMessage"];
|
||||||
|
|
||||||
|
if (localVersion < latestVersion)
|
||||||
|
{
|
||||||
|
VersionCheckingInitializer.VersionOutdated = true;
|
||||||
|
VersionCheckingInitializer.VersionOutdatedDetected?.Invoke();
|
||||||
|
Destroy(gameObject);
|
||||||
|
|
||||||
|
yield break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,124 @@
|
|||||||
|
using System.IO;
|
||||||
|
using System.Reflection;
|
||||||
|
using TMPro;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.UI;
|
||||||
|
|
||||||
|
namespace FortniteEmoteWheel.Classes.EzVersionChecking;
|
||||||
|
|
||||||
|
internal class PromotionManager : MonoBehaviour
|
||||||
|
{
|
||||||
|
public TextMeshProUGUI TextObj;
|
||||||
|
|
||||||
|
private GameObject imageObj;
|
||||||
|
private GameObject stumpObj;
|
||||||
|
private Image uiImage;
|
||||||
|
public static PromotionManager Instance { get; private set; }
|
||||||
|
|
||||||
|
private void Awake() => Instance = this;
|
||||||
|
|
||||||
|
public void Start() => GorillaTagger.OnPlayerSpawned(SpawnStumpObj);
|
||||||
|
|
||||||
|
private void Update()
|
||||||
|
{
|
||||||
|
if (stumpObj != null && Camera.main != null)
|
||||||
|
{
|
||||||
|
stumpObj.transform.LookAt(Camera.main.transform.position);
|
||||||
|
stumpObj.transform.Rotate(0f, 180f, 0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (VRRig.LocalRig != null)
|
||||||
|
uiImage.color = VRRig.LocalRig.playerColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SpawnStumpObj()
|
||||||
|
{
|
||||||
|
stumpObj = new GameObject("DEEZEMOTEWHEELPromoStump");
|
||||||
|
Canvas canvas = stumpObj.AddComponent<Canvas>();
|
||||||
|
canvas.renderMode = RenderMode.WorldSpace;
|
||||||
|
CanvasScaler scaler = stumpObj.AddComponent<CanvasScaler>();
|
||||||
|
scaler.dynamicPixelsPerUnit = 20f;
|
||||||
|
stumpObj.AddComponent<GraphicRaycaster>();
|
||||||
|
|
||||||
|
RectTransform canvasRect = stumpObj.GetComponent<RectTransform>();
|
||||||
|
canvasRect.sizeDelta = new Vector2(2f, 2f);
|
||||||
|
stumpObj.transform.position = new Vector3(-66.9419f, 13f, -82.6273f);
|
||||||
|
stumpObj.transform.localScale = Vector3.one * 0.002f;
|
||||||
|
stumpObj.transform.Rotate(0f, 180f, 0f);
|
||||||
|
|
||||||
|
GameObject bgObj = new("Background");
|
||||||
|
bgObj.transform.SetParent(stumpObj.transform, false);
|
||||||
|
|
||||||
|
Image bgImage = bgObj.AddComponent<Image>();
|
||||||
|
bgImage.color = new Color(0f, 0f, 0f, 0.8f);
|
||||||
|
bgImage.raycastTarget = false;
|
||||||
|
|
||||||
|
RectTransform bgRect = bgObj.GetComponent<RectTransform>();
|
||||||
|
bgRect.sizeDelta = new Vector2(400f, 300f);
|
||||||
|
bgRect.localScale = Vector3.one;
|
||||||
|
bgRect.anchoredPosition = Vector2.zero;
|
||||||
|
|
||||||
|
TextObj = new GameObject("Text").AddComponent<TextMeshProUGUI>();
|
||||||
|
TextObj.transform.SetParent(stumpObj.transform, false);
|
||||||
|
TextObj.font = LoadFont("comicbd");
|
||||||
|
TextObj.text =
|
||||||
|
$"<color=black>Deez's</color>\n<color=blue>{Constants.Name}</color>\n<color=white>Made By</color> <color=black>Deez</color>";
|
||||||
|
|
||||||
|
TextObj.fontSize = 50f;
|
||||||
|
TextObj.color = Color.paleVioletRed;
|
||||||
|
TextObj.alignment = TextAlignmentOptions.Center;
|
||||||
|
RectTransform textRect = TextObj.GetComponent<RectTransform>();
|
||||||
|
textRect.anchoredPosition = new Vector2(0f, -50f);
|
||||||
|
textRect.sizeDelta = new Vector2(400f, 200f);
|
||||||
|
|
||||||
|
Texture2D tex = LoadEmbeddedImage("emote.png");
|
||||||
|
|
||||||
|
if (tex == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
imageObj = new GameObject("EmoteIcon");
|
||||||
|
imageObj.transform.SetParent(stumpObj.transform, false);
|
||||||
|
uiImage = imageObj.AddComponent<Image>();
|
||||||
|
|
||||||
|
RectTransform imgRect = imageObj.GetComponent<RectTransform>();
|
||||||
|
|
||||||
|
float targetHeight = 100f;
|
||||||
|
float aspect = (float)tex.width / tex.height;
|
||||||
|
float targetWidth = targetHeight * aspect * 1f;
|
||||||
|
|
||||||
|
imgRect.sizeDelta = new Vector2(targetWidth, targetHeight);
|
||||||
|
imgRect.anchoredPosition = new Vector2(0f, 80f);
|
||||||
|
|
||||||
|
Sprite sprite = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), new Vector2(0.5f, 0.5f));
|
||||||
|
uiImage.sprite = sprite;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Texture2D LoadEmbeddedImage(string name)
|
||||||
|
{
|
||||||
|
using Stream stream = Assembly.GetExecutingAssembly()
|
||||||
|
.GetManifestResourceStream("FortniteEmoteWheel.Resources." + name);
|
||||||
|
|
||||||
|
if (stream == null) return null;
|
||||||
|
byte[] imageData = new byte[stream.Length];
|
||||||
|
stream.Read(imageData, 0, imageData.Length);
|
||||||
|
Texture2D texture = new(2, 2);
|
||||||
|
texture.LoadImage(imageData);
|
||||||
|
|
||||||
|
return texture;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static TMP_FontAsset LoadFont(string name)
|
||||||
|
{
|
||||||
|
Stream manifestResourceStream = Assembly.GetExecutingAssembly()
|
||||||
|
.GetManifestResourceStream("FortniteEmoteWheel.Resources." + name + ".ttf");
|
||||||
|
|
||||||
|
byte[] array = new byte[manifestResourceStream.Length];
|
||||||
|
manifestResourceStream.Read(array, 0, array.Length);
|
||||||
|
string text = Path.Combine(Application.temporaryCachePath, "TempFont.ttf");
|
||||||
|
File.WriteAllBytes(text, array);
|
||||||
|
TMP_FontAsset result = TMP_FontAsset.CreateFontAsset(new Font(text));
|
||||||
|
manifestResourceStream?.Dispose();
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
using UnityEngine;
|
||||||
|
using FortniteEmoteWheel.Classes.Admin;
|
||||||
|
|
||||||
|
// i got permission from ZlothY: https://git.hamburbur.org/ZlothY/ZlothYNametag/src/branch/main/EzVersionChecking
|
||||||
|
namespace FortniteEmoteWheel.Classes.EzVersionChecking;
|
||||||
|
|
||||||
|
public static class VersionCheckingInitializer
|
||||||
|
{
|
||||||
|
public static Action VersionOutdatedDetected;
|
||||||
|
|
||||||
|
public static bool VersionOutdated;
|
||||||
|
|
||||||
|
public static string OutdatedMessage;
|
||||||
|
|
||||||
|
public static Version LatestVersion;
|
||||||
|
|
||||||
|
public static void StartVersionChecking()
|
||||||
|
{
|
||||||
|
JObject data = HamburburData.Data;
|
||||||
|
|
||||||
|
JToken modVersionInfo =
|
||||||
|
((JArray)data["modVersionInfo"])!.FirstOrDefault(token => (string)token["modName"] ==
|
||||||
|
Constants.Name);
|
||||||
|
|
||||||
|
if (modVersionInfo != null)
|
||||||
|
{
|
||||||
|
LatestVersion = new Version(((string)modVersionInfo["latestVersion"])!);
|
||||||
|
|
||||||
|
OutdatedMessage = (string)modVersionInfo["outdatedMessage"];
|
||||||
|
|
||||||
|
Version localVersion = new(Constants.Version);
|
||||||
|
|
||||||
|
if (localVersion < LatestVersion)
|
||||||
|
VersionOutdated = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (VersionOutdated)
|
||||||
|
return;
|
||||||
|
|
||||||
|
new GameObject($"{Constants.Name} Version Checking").AddComponent<ContinousVersionChecking>();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user