using BepInEx; using BepInEx.Configuration; using HarmonyLib; using UnityEngine; using UnityEngine.UI; using TMPro; using Photon.Pun; using BepInEx.Logging; using UnityEngine.Localization.PropertyVariants; using System; using CWOffline; namespace SpookTubeEX; [BepInPlugin(MyPluginInfo.PLUGIN_GUID, MyPluginInfo.PLUGIN_NAME, MyPluginInfo.PLUGIN_VERSION)] [BepInIncompatibility("me.loaforc.Flashcard")] // No flashcard support [ContentWarningPlugin(MyPluginInfo.PLUGIN_GUID, MyPluginInfo.PLUGIN_NAME, true)] [BepInDependency("CWOffline", BepInDependency.DependencyFlags.HardDependency)] public class Plugin : BaseUnityPlugin { Harmony harmony; public static ConfigEntry URL; // public static void ModalProxy(string title, string message) => Modal.ShowError(title, message); internal new static ManualLogSource Logger; private void Awake() { Logger = base.Logger; // Config URL = Config.Bind("Networking", "WebsocketURL", "wss://spook.redbigz.com/api/upload", "The ws[s]:// URL."); // Plugin startup logic Logger.LogInfo($"SpookTubeEX has loaded."); // Create patches harmony = new("com.redbigz.SpookTubeEXPatch"); harmony.PatchAll(); } private void OnDestroy() { harmony.UnpatchSelf(); Logger.LogInfo($"SpookTubeEX has unloaded."); // Unpatch everything } } [HarmonyPatch(typeof(UploadCompleteUI), nameof(UploadCompleteUI.Replay))] class ReplayPatch { [HarmonyPrefix] static bool Prefix(UploadCompleteUI __instance) { if (CWOfflineAPI.IsGameOffline()) { Modal.ShowError("Upload Error", "Your device is offline."); return false; } if (!PhotonNetwork.IsMasterClient) { Modal.ShowError("Upload Error", "Only the host can upload videos to SpookTube."); return false; } IPlayableVideo video = new Traverse(__instance).Field("m_replayVideo").GetValue() as IPlayableVideo; GameObject States = __instance.m_videoPlayer.transform.parent.parent.parent.gameObject; GameObject ShowVideoState = Util.FindObject(States, "ShowVideoState"); GameObject UploadingState = Util.FindObject(States, "UploadingState"); // Show Uploading Screen UploadingState.SetActive(true); ShowVideoState.SetActive(false); SpookedUploader uploader = new(); 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(); }); return false; } } [HarmonyPatch(typeof(UploadCompleteUI), nameof(UploadCompleteUI.PlayVideo))] class VideoEndedUIInjection { [HarmonyPostfix] static void Postfix(UploadCompleteUI __instance) { // Edit Text GameObject text = GameObject.Find("VideoDone/Replay/Text (TMP)"); text.GetComponent() .enabled = false; // Disable Localise TextMeshProUGUI comp = text.GetComponent(); comp.SetText("UPLOAD TO THE DEEP DARK WEB"); // Edit Icon (there's no finds here because I forgot that postfixes existed and I'm too lazy to change it back) GameObject VideoDone = Util.FindObject(__instance.m_videoPlayer.transform.parent.gameObject, "VideoDone"); GameObject Replay = Util.FindObject(VideoDone, "Replay"); 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; } }