102 lines
3.6 KiB
C#
102 lines
3.6 KiB
C#
using BepInEx;
|
|
using BepInEx.Configuration;
|
|
using HarmonyLib;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using TMPro;
|
|
using Photon.Pun;
|
|
|
|
namespace SpookedTube;
|
|
|
|
[BepInPlugin(MyPluginInfo.PLUGIN_GUID, MyPluginInfo.PLUGIN_NAME, MyPluginInfo.PLUGIN_VERSION)]
|
|
[ContentWarningPlugin(MyPluginInfo.PLUGIN_GUID, MyPluginInfo.PLUGIN_NAME, true)]
|
|
public class Plugin : BaseUnityPlugin
|
|
{
|
|
Harmony harmony;
|
|
|
|
public static ConfigEntry<string> URL;
|
|
|
|
// public static void ModalProxy(string title, string message) => Modal.ShowError(title, message);
|
|
|
|
private void Awake()
|
|
{
|
|
// Config
|
|
URL = Config.Bind("Networking", "WebsocketURL", "ws://spook.redbigz.com/api/upload", "The ws[s]:// URL.");
|
|
|
|
// Plugin startup logic
|
|
Logger.LogInfo($"Spooktube has loaded.");
|
|
|
|
// Create patches
|
|
harmony = new("com.redbigz.SpookedTubePatch");
|
|
harmony.PatchAll();
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
harmony.UnpatchSelf();
|
|
|
|
Logger.LogInfo($"Spooktube has unloaded."); // Unpatch everything
|
|
}
|
|
}
|
|
|
|
[HarmonyPatch(typeof(UploadCompleteUI), nameof(UploadCompleteUI.Replay))]
|
|
class ReplayPatch
|
|
{
|
|
[HarmonyPrefix]
|
|
static bool Prefix(UploadCompleteUI __instance)
|
|
{
|
|
if (!PhotonNetwork.IsMasterClient)
|
|
{
|
|
// Modal.ShowError("Upload Error", "Only the host can upload videos to SpookedTube.");
|
|
return false;
|
|
}
|
|
|
|
IPlayableVideo video = new Traverse(__instance).Field("m_replayVideo").GetValue() as IPlayableVideo;
|
|
int views = new Traverse(__instance).Field("m_replayViews").GetValue<int>();
|
|
CommentUI[] comments = new Traverse(__instance).Field("m_replayComments").GetValue() as CommentUI[];
|
|
|
|
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();
|
|
|
|
uploader.Upload(video, views, comments, () =>
|
|
{
|
|
UploadingState.SetActive(false);
|
|
Util.FindObject(Util.FindObject(__instance.m_videoPlayer.transform.parent.parent.parent.parent.parent.gameObject, "SaveVideoToDesktopInteractable"), "CloseInt").GetComponent<CloseVideoInteractable>().Interact(null);
|
|
});
|
|
|
|
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<UnityEngine.Localization.PropertyVariants.GameObjectLocalizer>()
|
|
.enabled = false; // Disable Localiser
|
|
|
|
TextMeshProUGUI comp = text.GetComponent<TextMeshProUGUI>();
|
|
|
|
comp.SetText("UPLOAD TO SPOOKEDTUBE");
|
|
|
|
// 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<Image>().sprite = SaveImageElement.GetComponent<Image>().sprite;
|
|
}
|
|
} |