Add indicator for uploads
This commit is contained in:
parent
440485d4c3
commit
79bdba573b
30
Plugin.cs
30
Plugin.cs
|
@ -6,6 +6,8 @@ using UnityEngine.UI;
|
|||
using TMPro;
|
||||
using Photon.Pun;
|
||||
using BepInEx.Logging;
|
||||
using UnityEngine.Localization.PropertyVariants;
|
||||
using System;
|
||||
|
||||
namespace SpookTubeEX;
|
||||
|
||||
|
@ -68,10 +70,22 @@ class ReplayPatch
|
|||
|
||||
SpookedUploader uploader = new();
|
||||
|
||||
uploader.Upload(video, () =>
|
||||
TextMeshProUGUI uploadingStatus = Util.FindObject(UploadingState, "Text (TMP) (1)").GetComponent<TextMeshProUGUI>();
|
||||
uploadingStatus.richText = true;
|
||||
string uploadingStatusDefaultText = "UPLOADING VIDEO...";
|
||||
|
||||
Action<string> setTextViewable = (string text) =>
|
||||
{
|
||||
uploadingStatus.SetText($"{uploadingStatusDefaultText}\n{text}");
|
||||
};
|
||||
|
||||
setTextViewable("<color=#C68E17>ESTABLISHING CONNECTION</color>");
|
||||
|
||||
uploader.Upload(video, setTextViewable, () =>
|
||||
{
|
||||
UploadingState.SetActive(false);
|
||||
|
||||
uploadingStatus.SetText(uploadingStatusDefaultText);
|
||||
|
||||
// Util.FindObject(Util.FindObject(__instance.m_videoPlayer.transform.parent.parent.parent.parent.parent.gameObject, "SaveVideoToDesktopInteractable"), "CloseInt").GetComponent<CloseVideoInteractable>().Interact(null);
|
||||
UploadVideoStationStateMachine stateMachine = new Traverse(GameObject.Find("/Tools/UploadMachine2").GetComponent<UploadVideoStation>()).Field("m_stateMachine").GetValue() as UploadVideoStationStateMachine;
|
||||
stateMachine.SwitchState<UploadVideoState>();
|
||||
|
@ -91,7 +105,7 @@ class VideoEndedUIInjection
|
|||
GameObject text = GameObject.Find("VideoDone/Replay/Text (TMP)");
|
||||
|
||||
text.GetComponent<UnityEngine.Localization.PropertyVariants.GameObjectLocalizer>()
|
||||
.enabled = false; // Disable Localiser
|
||||
.enabled = false; // Disable Localise
|
||||
|
||||
TextMeshProUGUI comp = text.GetComponent<TextMeshProUGUI>();
|
||||
|
||||
|
@ -103,5 +117,15 @@ class VideoEndedUIInjection
|
|||
GameObject SaveImageElement = Util.FindObject(Util.FindObject(VideoDone, "SaveVideo"), "Image");
|
||||
GameObject ImageElement = Util.FindObject(Replay, "Image");
|
||||
ImageElement.GetComponent<Image>().sprite = SaveImageElement.GetComponent<Image>().sprite;
|
||||
|
||||
Util.FindObject(
|
||||
Util.FindObject(
|
||||
VideoDone.transform.parent.parent.parent.gameObject,
|
||||
"UploadingState"
|
||||
),
|
||||
"Text (TMP) (1)"
|
||||
)
|
||||
.GetComponent<UnityEngine.Localization.PropertyVariants.GameObjectLocalizer>()
|
||||
.enabled = false;
|
||||
}
|
||||
}
|
44
Uploader.cs
44
Uploader.cs
|
@ -17,7 +17,7 @@ namespace SpookTubeEX;
|
|||
|
||||
class SpookedUploader
|
||||
{
|
||||
void UploadThread(MessageEventArgs evt, WebSocket ws, string path, string uuid)
|
||||
void UploadThread(MessageEventArgs evt, WebSocket ws, string path, string uuid, Action<string> setViewableLogText)
|
||||
{
|
||||
// Begin Upload
|
||||
byte[] byteArray = File.ReadAllBytes(path);
|
||||
|
@ -32,6 +32,7 @@ class SpookedUploader
|
|||
byte[] buffer = byteArray.Skip(offset * chunkSize).Take(chunkSize).ToArray();
|
||||
offset += 1;
|
||||
|
||||
ShowStatus(setViewableLogText, uuid, "stream", $"{offset}/{expectedChunks}");
|
||||
Plugin.Logger.LogInfo($"(UPLOAD {uuid}) - {offset}/{expectedChunks} (~{Math.Ceiling((double)buffer.Length / 1000)} KB)");
|
||||
|
||||
List<byte> msgList = new List<byte>();
|
||||
|
@ -43,8 +44,32 @@ class SpookedUploader
|
|||
}
|
||||
}
|
||||
|
||||
void ShowStatus(Action<string> setViewableLogText, string uuid, string logType, string message = "")
|
||||
{
|
||||
if (uuid.Length == 0) uuid = "...";
|
||||
|
||||
string msg = "";
|
||||
|
||||
switch (logType) {
|
||||
case "error":
|
||||
msg = $"<color=red>{message}</color>\n<color=red><size=50%>CHECK CONSOLE FOR MORE DETAILS</size></color>";
|
||||
break;
|
||||
case "stream":
|
||||
msg = $"STREAMING VIDEO ({message})";
|
||||
break;
|
||||
case "complete":
|
||||
msg = $"<color=#2E8B57>UPLOAD COMPLETE</color>";
|
||||
break;
|
||||
default:
|
||||
msg = message;
|
||||
break;
|
||||
}
|
||||
|
||||
setViewableLogText($"{msg}\n<mspace=0.13em><size=20%>UUID: {uuid.ToUpper()}</size></mspace>");
|
||||
}
|
||||
|
||||
WebSocket ws;
|
||||
public void Upload(IPlayableVideo cameraRecording, Action onUpload)
|
||||
public void Upload(IPlayableVideo cameraRecording, Action<string> setViewableLogText, Action onUpload)
|
||||
{
|
||||
if (cameraRecording.TryGetVideoPath(out string path))
|
||||
{
|
||||
|
@ -74,25 +99,24 @@ class SpookedUploader
|
|||
{
|
||||
uuid = evt.Data.Substring(5);
|
||||
|
||||
ShowStatus(setViewableLogText, uuid, "stream", "0/?");
|
||||
Plugin.Logger.LogInfo($"Your video has been assigned the UUID {uuid}. Beginning upload...");
|
||||
|
||||
// Start upload thread
|
||||
new Thread(new ThreadStart(() => UploadThread(evt, ws, path, uuid))).Start();
|
||||
new Thread(new ThreadStart(() => UploadThread(evt, ws, path, uuid, setViewableLogText))).Start();
|
||||
}
|
||||
|
||||
if (evt.Data.StartsWith("fin")) // On upload complete
|
||||
{
|
||||
ws.Close();
|
||||
|
||||
ShowStatus(setViewableLogText, uuid, "complete");
|
||||
Plugin.Logger.LogInfo($"Upload Complete. Redirecting to {viewableUrl}...");
|
||||
|
||||
Application.OpenURL($"{viewableUrl}/#{uuid}");
|
||||
|
||||
onUpload();
|
||||
}
|
||||
|
||||
if (evt.Data.StartsWith("us")) // On heuristics error
|
||||
{
|
||||
ShowStatus(setViewableLogText, uuid, "error", "HEUR ERROR");
|
||||
Plugin.Logger.LogError($"SpookTubeEX has experienced a heuristics error. Please contact ModMail at https://discord.gg/Gw2f86B2vC with this UUID in your ticket request: {uuid}\nThis is an automated service, so trolling will get your IP blocked from accessing anything with SpookTubeEX and your Discord account banned from the server. DO NOT SHARE THIS UUID WITH ANYONE!");
|
||||
}
|
||||
};
|
||||
|
@ -108,9 +132,13 @@ class SpookedUploader
|
|||
ws.Send(SteamUser.GetSteamID().m_SteamID.ToString());
|
||||
};
|
||||
|
||||
ws.OnClose += (sender, evt) => {
|
||||
onUpload();
|
||||
};
|
||||
|
||||
Plugin.Logger.LogInfo($"Connecting to {ws.Url}...");
|
||||
|
||||
ws.Connect();
|
||||
ws.ConnectAsync();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue