Decompiled source of SpookTubeEX v1.3.3

BepInEx/plugins/com.redbigz.SpookTubeEX.dll

Decompiled 4 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Threading;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Photon.Pun;
using Steamworks;
using TMPro;
using UnityEngine;
using UnityEngine.Localization.PropertyVariants;
using UnityEngine.UI;
using WebSocketSharp;
using Zorro.Core;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("com.redbigz.SpookTubeEX")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Upload your videos to a website and watch others' videos!")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("SpookTubeEX")]
[assembly: AssemblyTitle("com.redbigz.SpookTubeEX")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace SpookTubeEX;

[BepInPlugin("com.redbigz.SpookTubeEX", "SpookTubeEX", "1.0.0")]
[ContentWarningPlugin("com.redbigz.SpookTubeEX", "SpookTubeEX", true)]
public class Plugin : BaseUnityPlugin
{
	private Harmony harmony;

	public static ConfigEntry<string> URL;

	internal static ManualLogSource Logger;

	private void Awake()
	{
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_004e: Expected O, but got Unknown
		Logger = ((BaseUnityPlugin)this).Logger;
		URL = ((BaseUnityPlugin)this).Config.Bind<string>("Networking", "WebsocketURL", "wss://spook.redbigz.com/api/upload", "The ws[s]:// URL.");
		Logger.LogInfo((object)"SpookTubeEX has loaded.");
		harmony = new Harmony("com.redbigz.SpookTubeEXPatch");
		harmony.PatchAll();
	}

	private void OnDestroy()
	{
		harmony.UnpatchSelf();
		Logger.LogInfo((object)"SpookTubeEX has unloaded.");
	}
}
[HarmonyPatch(typeof(UploadCompleteUI), "Replay")]
internal class ReplayPatch
{
	[HarmonyPrefix]
	private static bool Prefix(UploadCompleteUI __instance)
	{
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		if (!PhotonNetwork.IsMasterClient)
		{
			Modal.ShowError("Upload Error", "Only the host can upload videos to SpookTube.");
			return false;
		}
		object value = new Traverse((object)__instance).Field("m_replayVideo").GetValue();
		IPlayableVideo cameraRecording = (IPlayableVideo)((value is IPlayableVideo) ? value : null);
		GameObject gameObject = ((Component)((Component)__instance.m_videoPlayer).transform.parent.parent.parent).gameObject;
		GameObject obj = gameObject.FindObject("ShowVideoState");
		GameObject UploadingState = gameObject.FindObject("UploadingState");
		UploadingState.SetActive(true);
		obj.SetActive(false);
		SpookedUploader spookedUploader = new SpookedUploader();
		TextMeshProUGUI uploadingStatus = UploadingState.FindObject("Text (TMP) (1)").GetComponent<TextMeshProUGUI>();
		((TMP_Text)uploadingStatus).richText = true;
		string uploadingStatusDefaultText = "UPLOADING VIDEO...";
		Action<string> action = delegate(string text)
		{
			((TMP_Text)uploadingStatus).SetText(uploadingStatusDefaultText + "\n" + text, true);
		};
		action("<color=#C68E17>ESTABLISHING CONNECTION</color>");
		spookedUploader.Upload(cameraRecording, action, delegate
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			UploadingState.SetActive(false);
			((TMP_Text)uploadingStatus).SetText(uploadingStatusDefaultText, true);
			object value2 = new Traverse((object)GameObject.Find("/Tools/UploadMachine2").GetComponent<UploadVideoStation>()).Field("m_stateMachine").GetValue();
			((StateMachine<UploadVideoStationState>)((value2 is UploadVideoStationStateMachine) ? value2 : null)).SwitchState<UploadVideoState>();
		});
		return false;
	}
}
[HarmonyPatch(typeof(UploadCompleteUI), "PlayVideo")]
internal class VideoEndedUIInjection
{
	[HarmonyPostfix]
	private static void Postfix(UploadCompleteUI __instance)
	{
		GameObject obj = GameObject.Find("VideoDone/Replay/Text (TMP)");
		((Behaviour)obj.GetComponent<GameObjectLocalizer>()).enabled = false;
		((TMP_Text)obj.GetComponent<TextMeshProUGUI>()).SetText("UPLOAD TO THE DEEP DARK WEB", true);
		GameObject obj2 = ((Component)((Component)__instance.m_videoPlayer).transform.parent).gameObject.FindObject("VideoDone");
		GameObject parent = obj2.FindObject("Replay");
		GameObject val = obj2.FindObject("SaveVideo").FindObject("Image");
		parent.FindObject("Image").GetComponent<Image>().sprite = val.GetComponent<Image>().sprite;
		((Behaviour)((Component)obj2.transform.parent.parent.parent).gameObject.FindObject("UploadingState").FindObject("Text (TMP) (1)").GetComponent<GameObjectLocalizer>()).enabled = false;
	}
}
internal class SpookedUploader
{
	private WebSocket ws;

	private void UploadThread(MessageEventArgs evt, WebSocket ws, string path, string uuid, Action<string> setViewableLogText)
	{
		byte[] array = File.ReadAllBytes(path);
		int num = 0;
		double num2 = Math.Ceiling((double)array.Length / 512000.0);
		while (array.Length > num * 512000)
		{
			byte[] array2 = array.Skip(num * 512000).Take(512000).ToArray();
			num++;
			ShowStatus(setViewableLogText, uuid, "stream", $"{num}/{num2}");
			Plugin.Logger.LogInfo((object)$"(UPLOAD {uuid}) - {num}/{num2} (~{Math.Ceiling((double)array2.Length / 1000.0)} KB)");
			List<byte> list = new List<byte>();
			list.AddRange(new byte[1] { 36 });
			list.AddRange(array2);
			ws.Send(list.ToArray());
		}
	}

	private void ShowStatus(Action<string> setViewableLogText, string uuid, string logType, string message = "")
	{
		if (uuid.Length == 0)
		{
			uuid = "...";
		}
		string text = "";
		setViewableLogText(logType switch
		{
			"error" => "<color=red>" + message + "</color>\n<color=red><size=50%>CHECK CONSOLE FOR MORE DETAILS</size></color>", 
			"stream" => "STREAMING VIDEO (" + message + ")", 
			"complete" => "<color=#2E8B57>UPLOAD COMPLETE</color>", 
			_ => message, 
		} + "\n<mspace=0.13em><size=20%>UUID: " + uuid.ToUpper() + "</size></mspace>");
	}

	public void Upload(IPlayableVideo cameraRecording, Action<string> setViewableLogText, Action onUpload)
	{
		//IL_007b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: Expected O, but got Unknown
		string path = default(string);
		if (!cameraRecording.TryGetVideoPath(ref path))
		{
			return;
		}
		if (!File.Exists(path))
		{
			Modal.ShowError("Path Nonexistent", "Can't find " + path);
			return;
		}
		ws = new WebSocket(Plugin.URL.Value, Array.Empty<string>());
		string viewableUrl = "";
		string uuid = "";
		ws.OnMessage += delegate(object sender, MessageEventArgs evt)
		{
			if (evt.Data.StartsWith("url:"))
			{
				viewableUrl = evt.Data.Substring(4);
				Plugin.Logger.LogInfo((object)("Server reports origin as " + viewableUrl + "."));
			}
			if (evt.Data.StartsWith("uuid:"))
			{
				uuid = evt.Data.Substring(5);
				ShowStatus(setViewableLogText, uuid, "stream", "0/?");
				Plugin.Logger.LogInfo((object)("Your video has been assigned the UUID " + uuid + ". Beginning upload..."));
				new Thread((ThreadStart)delegate
				{
					UploadThread(evt, ws, path, uuid, setViewableLogText);
				}).Start();
			}
			if (evt.Data.StartsWith("fin"))
			{
				ShowStatus(setViewableLogText, uuid, "complete");
				Plugin.Logger.LogInfo((object)("Upload Complete. Redirecting to " + viewableUrl + "..."));
				Application.OpenURL(viewableUrl + "/#" + uuid);
			}
			if (evt.Data.StartsWith("us"))
			{
				ShowStatus(setViewableLogText, uuid, "error", "HEUR ERROR");
				Plugin.Logger.LogError((object)("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!"));
			}
		};
		ws.OnError += delegate(object sender, ErrorEventArgs evt)
		{
			ShowStatus(setViewableLogText, uuid, "error", "WS ERROR");
			Plugin.Logger.LogError((object)evt.Message);
		};
		ws.OnOpen += delegate
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			ws.Send("persona:" + SteamFriends.GetPersonaName());
			ws.Send(SteamUser.GetSteamID().m_SteamID.ToString());
		};
		ws.OnClose += delegate
		{
			onUpload();
		};
		Plugin.Logger.LogInfo((object)$"Connecting to {ws.Url}...");
		ws.ConnectAsync();
	}
}
internal static class Util
{
	public static GameObject FindObject(this GameObject parent, string name)
	{
		Transform[] componentsInChildren = parent.GetComponentsInChildren<Transform>(true);
		foreach (Transform val in componentsInChildren)
		{
			if (((Object)val).name.StartsWith(name))
			{
				return ((Component)val).gameObject;
			}
		}
		return null;
	}
}
public static class MyPluginInfo
{
	public const string PLUGIN_GUID = "com.redbigz.SpookTubeEX";

	public const string PLUGIN_NAME = "SpookTubeEX";

	public const string PLUGIN_VERSION = "1.0.0";
}