SpookTubeEX/Plugin.cs
2024-05-29 08:18:35 +10:00

82 lines
2.7 KiB
C#

using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
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 ConfigEntry<string> Username;
private void Awake()
{
// Config
URL = Config.Bind("Networking", "WebsocketURL", "ws://127.0.0.1:6969/upload.ws", "The ws[s]:// URL.");
Username = Config.Bind("Networking", "Username", "Guest", "Your display name.");
// 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)
{
Traverse traverse = new(__instance);
IPlayableVideo video = traverse.Field("m_replayVideo").GetValue<IPlayableVideo>();
int views = traverse.Field("m_replayViews").GetValue<int>();
CommentUI[] comments = traverse.Field("m_replayComments").GetValue<CommentUI[]>();
SpookedUploader.Upload(video, views, comments);
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;
}
}