diff --git a/Plugin.cs b/Plugin.cs index 308b1a7..7893732 100644 --- a/Plugin.cs +++ b/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(); + uploadingStatus.richText = true; + string uploadingStatusDefaultText = "UPLOADING VIDEO..."; + + Action setTextViewable = (string text) => + { + uploadingStatus.SetText($"{uploadingStatusDefaultText}\n{text}"); + }; + + setTextViewable("ESTABLISHING CONNECTION"); + + 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().Interact(null); UploadVideoStationStateMachine stateMachine = new Traverse(GameObject.Find("/Tools/UploadMachine2").GetComponent()).Field("m_stateMachine").GetValue() as UploadVideoStationStateMachine; stateMachine.SwitchState(); @@ -91,7 +105,7 @@ class VideoEndedUIInjection GameObject text = GameObject.Find("VideoDone/Replay/Text (TMP)"); text.GetComponent() - .enabled = false; // Disable Localiser + .enabled = false; // Disable Localise TextMeshProUGUI comp = text.GetComponent(); @@ -103,5 +117,15 @@ class VideoEndedUIInjection GameObject SaveImageElement = Util.FindObject(Util.FindObject(VideoDone, "SaveVideo"), "Image"); GameObject ImageElement = Util.FindObject(Replay, "Image"); ImageElement.GetComponent().sprite = SaveImageElement.GetComponent().sprite; + + Util.FindObject( + Util.FindObject( + VideoDone.transform.parent.parent.parent.gameObject, + "UploadingState" + ), + "Text (TMP) (1)" + ) + .GetComponent() + .enabled = false; } } \ No newline at end of file diff --git a/Uploader.cs b/Uploader.cs index b18cfd2..d4e7476 100644 --- a/Uploader.cs +++ b/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 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 msgList = new List(); @@ -43,8 +44,32 @@ class SpookedUploader } } + void ShowStatus(Action setViewableLogText, string uuid, string logType, string message = "") + { + if (uuid.Length == 0) uuid = "..."; + + string msg = ""; + + switch (logType) { + case "error": + msg = $"{message}\nCHECK CONSOLE FOR MORE DETAILS"; + break; + case "stream": + msg = $"STREAMING VIDEO ({message})"; + break; + case "complete": + msg = $"UPLOAD COMPLETE"; + break; + default: + msg = message; + break; + } + + setViewableLogText($"{msg}\nUUID: {uuid.ToUpper()}"); + } + WebSocket ws; - public void Upload(IPlayableVideo cameraRecording, Action onUpload) + public void Upload(IPlayableVideo cameraRecording, Action 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(); } } } \ No newline at end of file