Decompiled source of VoiceContent v0.10.5

BepInEx/plugins/VoiceContent/Notest.VoiceContent.dll

Decompiled 7 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using ContentLibrary;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using MyceliumNetworking;
using Photon.Pun;
using Photon.Realtime;
using Steamworks;
using UnityEngine;
using VoiceContent;
using VoiceContent.Localization;
using VoiceRecognitionAPI;
using Zorro.Core;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("")]
[assembly: AssemblyCompany("Notest.VoiceContent")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.10.4.0")]
[assembly: AssemblyInformationalVersion("0.10.4+6511435fa256ed73f628fe64ae3bdc85805c65c2")]
[assembly: AssemblyProduct("VoiceContent")]
[assembly: AssemblyTitle("Notest.VoiceContent")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.10.4.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
public class VoiceContentProvider : ContentProvider
{
	private string nickName;

	private int actorNumber;

	private string typeOfComment;

	public VoiceContentProvider(string type, string? playerNickName, int? playerActorNumber)
	{
		if (playerNickName != null && playerActorNumber.HasValue)
		{
			nickName = playerNickName;
			actorNumber = playerActorNumber.Value;
		}
		else
		{
			nickName = Player.localPlayer.refs.view.Owner.NickName;
			actorNumber = Player.localPlayer.refs.view.Owner.ActorNumber;
		}
		typeOfComment = type;
	}

	public override void GetContent(List<ContentEventFrame> contentEvents, float seenAmount, Camera camera, float time)
	{
		//IL_0045: Unknown result type (might be due to invalid IL or missing references)
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: Unknown result type (might be due to invalid IL or missing references)
		switch (typeOfComment)
		{
		case "swear":
			contentEvents.Add(new ContentEventFrame((ContentEvent)(object)new VoiceSwearContentEvent(nickName, actorNumber), seenAmount, time));
			break;
		case "like":
			contentEvents.Add(new ContentEventFrame((ContentEvent)(object)new VoiceLikeContentEvent(nickName, actorNumber), seenAmount, time));
			break;
		case "sponsor":
			contentEvents.Add(new ContentEventFrame((ContentEvent)(object)new VoiceSponsorContentEvent(nickName, actorNumber), seenAmount, time));
			break;
		default:
			global::VoiceContent.VoiceContent.Logger.LogError((object)("typeOfComment not recognized: " + typeOfComment));
			break;
		}
	}
}
public class VoiceLikeContentEvent : PlayerBaseEvent
{
	public string[] LIKE_COMMENTS = new string[21]
	{
		"haha like and subscribe? maybe i will", "liking this!", "I am liking and subscribing.", "sir yes sir", "they said the thing lol", "stupid spooktuber segment", "I DID WHAT YOU SAID!!", "i got that hater in me, i will not be liking and subscribing", "Nice job on the SpookTuber segment", "What a nice SpookTube channel. I will be subscribing thank you very much.",
		"You deserve more subscribers", "lmao, this channel is great", "AND DONT FORGET TO HIT THAT NOTIFICATION BELL TO NOT MISS ANY OF MY VIDEOS", "i am begign you to not include these spooktuber segments anymore", "I know they're corny but I absolutely love these spooktuber segments", "I love your chanel i watch all of your videos i liked and hit the notifiction bell", "No option to not recommend this channel.", "This segment will get ingrained in my brain, if I hear like and subscribe in my dreams I'm lbaming you", "Love your vids.......", "you guys say that every single time haha",
		"Usually I find thse spooktuber segments cringe but I subbed because of it"
	};

	public VoiceLikeContentEvent()
	{
	}

	public VoiceLikeContentEvent(string playerName, int actorNumber)
		: base(playerName, actorNumber)
	{
	}

	public override float GetContentValue()
	{
		return 8f;
	}

	public override ushort GetID()
	{
		return ContentHandler.GetEventID("VoiceLikeContentEvent");
	}

	public override string GetName()
	{
		return "Player said YouTuber keyword";
	}

	public override Comment GenerateComment()
	{
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: Expected O, but got Unknown
		global::VoiceContent.VoiceContent.Logger.LogDebug((object)"YouTuber phrase comment generated!");
		return new Comment(((PlayerBaseEvent)this).FixPlayerName(ArrayExtensions.GetRandom<string>(LIKE_COMMENTS)));
	}
}
public class VoiceSponsorContentEvent : PlayerBaseEvent
{
	public string[] SPONSOR_COMMENTS = new string[21]
	{
		"why do you guys even take sponsors?", "insta skip on that sponsor segment", "might check that sponsor", "lol great sponsor", "tired of so many sponsors nowadays", "MORE SPONSORS??", "RAID SHADOW LEGENDS!", "Cringe sponsor segment, at least it was quick to skip", "Surprisingly good sponsor segment", "I actually went to that sponsor",
		"That sponsor is not that bad, have used their services", "LOL How did any sponsor accept this sponsorship deal", "respect on the sponsors to give you full agency", "Hope you guys were being honest on that sponsor segment", "OMG you guys have sponsors??", "grats on the sponsorship deal", "im in my deathbed and the last thing im hearing is this stupid sponsor segment goodbye", "i thought u got enough money already y do u have sponsors", "THIS VIDEO IS BROUGHT TO YOU BY SPONSORBLOCK!!!1", "sellouts.",
		"Certified based sponsor"
	};

	public VoiceSponsorContentEvent()
	{
	}

	public VoiceSponsorContentEvent(string playerName, int actorNumber)
		: base(playerName, actorNumber)
	{
	}

	public override float GetContentValue()
	{
		return 5f;
	}

	public override ushort GetID()
	{
		return ContentHandler.GetEventID("VoiceSponsorContentEvent");
	}

	public override string GetName()
	{
		return "Player said sponsor keyword";
	}

	public override Comment GenerateComment()
	{
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: Expected O, but got Unknown
		global::VoiceContent.VoiceContent.Logger.LogDebug((object)"Sponsor segment comment generated!");
		return new Comment(((PlayerBaseEvent)this).FixPlayerName(ArrayExtensions.GetRandom<string>(SPONSOR_COMMENTS)));
	}
}
public class VoiceSwearContentEvent : PlayerBaseEvent
{
	public string[] SWEAR_COMMENTS = new string[23]
	{
		"stop swearing, my dog watches this!", "you just ruined my family outing where we watch diving bell videos...", "My son is starting to learn how to swear because of <playername>! Shameful.", "like this comment if you think kids should stop using spooktube so we get more channels that swear", "lol they cussed", "I thought this content was for kids.", "you folk swear a lot", "<playername> swears a lot", "hehe swears", "How many swears do you people know?",
		"All channels are family friendly nowadays so this is a breath of fresh air", "Nice comedic timing on those swears", "And to think I showed my kids this content. For shame.", "I thought this channel was family friendly!!!!", "Liking just because of that moment you swore", "It's nice to see channels that don't fall to being family friendly", "Such vulgar profanity.", "how are there so many kids in spooktube lol its the last place i expected to get hit by family friendliness", "my mom says im not allowed to swear so you shouldt either", "swearing is bad for you",
		"Legit subscribed when you swore lol", "LMAO, nice!", "based spooktuber that swears"
	};

	public VoiceSwearContentEvent()
	{
	}

	public VoiceSwearContentEvent(string playerName, int actorNumber)
		: base(playerName, actorNumber)
	{
	}

	public override float GetContentValue()
	{
		return 5f;
	}

	public override ushort GetID()
	{
		return ContentHandler.GetEventID("VoiceSwearContentEvent");
	}

	public override string GetName()
	{
		return "Player said swear keyword";
	}

	public override Comment GenerateComment()
	{
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: Expected O, but got Unknown
		global::VoiceContent.VoiceContent.Logger.LogDebug((object)"Swear comment generated!");
		return new Comment(((PlayerBaseEvent)this).FixPlayerName(ArrayExtensions.GetRandom<string>(SWEAR_COMMENTS)));
	}
}
namespace VoiceContent
{
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("Notest.VoiceContent", "VoiceContent", "0.10.4")]
	public class VoiceContent : BaseUnityPlugin
	{
		public const string modGUID = "Notest.VoiceContent";

		public const string modName = "VoiceContent";

		public const string modVersion = "0.10.4";

		public const uint modID = 2215935315u;

		private Dictionary<string, List<string>>? localizedLists;

		private string[]? swearWords;

		private string[]? youtuberPhrases;

		private string[]? sponsorPhrases;

		private ConfigEntry<string>? configLocalizationLanguage;

		private ConfigEntry<string>? configVoiceRecognitionAPI;

		public static VoiceContent Instance { get; private set; }

		internal static ManualLogSource Logger { get; private set; }

		internal static Harmony? Harmony { get; set; }

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			Instance = this;
			configLocalizationLanguage = ((BaseUnityPlugin)this).Config.Bind<string>("General", "Language", "en", "Which language should the VoiceContent mod uses for its localization. \n (Available for Windows API: en)");
			configVoiceRecognitionAPI = ((BaseUnityPlugin)this).Config.Bind<string>("General", "Voice Recognition Api", "Windows", "Which voice recognition API the VoiceContent mod should use. (Available: Windows)");
			swearWords = LocalizationData.GetLocalizedList(configLocalizationLanguage.Value, "swearWords").ToArray();
			youtuberPhrases = LocalizationData.GetLocalizedList(configLocalizationLanguage.Value, "youtuberPhrases").ToArray();
			sponsorPhrases = LocalizationData.GetLocalizedList(configLocalizationLanguage.Value, "sponsorPhrases").ToArray();
			if (swearWords.Any() && youtuberPhrases.Any() && sponsorPhrases.Any())
			{
				Logger.LogInfo((object)("Successfully loaded localization " + configLocalizationLanguage.Value + " for mod Notest.VoiceContent"));
			}
			else
			{
				Logger.LogError((object)("Failed to load localization " + configLocalizationLanguage.Value + " for mod Notest.VoiceContent"));
			}
			Patch();
			Logger.LogInfo((object)"Notest.VoiceContent v0.10.4 has loaded!");
			MyceliumNetwork.RegisterNetworkObject((object)this, 2215935315u, 0);
			ContentHandler.AssignEvent((ContentEvent)(object)new VoiceLikeContentEvent());
			ContentHandler.AssignEvent((ContentEvent)(object)new VoiceSwearContentEvent());
			ContentHandler.AssignEvent((ContentEvent)(object)new VoiceSponsorContentEvent());
			Voice.ListenForPhrases(youtuberPhrases, (Action<string>)delegate
			{
				Logger.LogDebug((object)"YouTuber phrase was said");
				HandlePhrase("like");
			});
			Voice.ListenForPhrases(sponsorPhrases, (Action<string>)delegate
			{
				Logger.LogDebug((object)"Sponsor segment phrase was said");
				HandlePhrase("sponsor");
			});
			Voice.ListenForPhrases(swearWords, (Action<string>)delegate
			{
				Logger.LogDebug((object)"Swear word was said");
				HandlePhrase("swear");
			});
		}

		private static Player? GetPlayerWithCamera()
		{
			Player[] playerList = PhotonNetwork.PlayerList;
			GlobalPlayerData val2 = default(GlobalPlayerData);
			foreach (Player val in playerList)
			{
				if (GlobalPlayerData.TryGetPlayerData(val, ref val2) && val2.inventory.GetItems().Any((ItemDescriptor item) => ((Object)item.item).name == "Camera"))
				{
					return val;
				}
			}
			return null;
		}

		private void HandlePhrase(string phraseType)
		{
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			Player playerWithCamera = GetPlayerWithCamera();
			if (playerWithCamera != null)
			{
				if (playerWithCamera.IsLocal)
				{
					Logger.LogDebug((object)"Local player is the one holding the camera, creating provider");
					CreateProvider(phraseType);
					return;
				}
				Logger.LogDebug((object)"Local player is not the one holding the camera");
				CSteamID val = default(CSteamID);
				if (SteamAvatarHandler.TryGetSteamIDForPlayer(playerWithCamera, ref val))
				{
					Logger.LogDebug((object)"Got steamID successfully");
					Player owner = Player.localPlayer.refs.view.Owner;
					MyceliumNetwork.RPCTarget(2215935315u, "ReplicateProvider", val, (ReliableType)1, new object[3] { phraseType, owner.NickName, owner.ActorNumber });
				}
				else
				{
					Logger.LogDebug((object)"Could not get SteamId");
				}
				CreateProvider(phraseType);
			}
			else
			{
				Logger.LogDebug((object)"Could not get player holding camera, if any");
			}
		}

		[CustomRPC]
		private void ReplicateProvider(string type, string playerNickName, int playerActorNumber)
		{
			Logger.LogDebug((object)("Asked to replicate provider of type " + type));
			CreateProvider(type, playerNickName, playerActorNumber);
		}

		private void CreateProvider(string type, string? playerNickName = null, int? playerActorNumber = null)
		{
			VoiceContentProvider voiceContentProvider = new VoiceContentProvider(type, playerNickName, playerActorNumber);
			ContentHandler.ManualPoll((ContentProvider)(object)voiceContentProvider, 1f, 100);
		}

		internal static void Patch()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			if (Harmony == null)
			{
				Harmony = new Harmony("Notest.VoiceContent");
			}
			Logger.LogDebug((object)"Patching...");
			Harmony.PatchAll();
			Logger.LogDebug((object)"Finished patching!");
		}

		internal static void Unpatch()
		{
			Logger.LogDebug((object)"Unpatching...");
			Harmony? harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			Logger.LogDebug((object)"Finished unpatching!");
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "Notest.VoiceContent";

		public const string PLUGIN_NAME = "VoiceContent";

		public const string PLUGIN_VERSION = "0.10.4";
	}
}
namespace VoiceContent.Patches
{
	[HarmonyPatch(typeof(UploadCompleteUI))]
	internal class UploadCompleteUIPatches
	{
		[HarmonyPrefix]
		[HarmonyPatch("DisplayVideoEval")]
		public static void DisplayVideoEvalPrefix(ref UploadCompleteUI __instance)
		{
			VoiceContent.Logger.LogInfo((object)$"DisplayVideoEval was called: {__instance.m_videoPlayer.length}");
			float num = (float)__instance.m_videoPlayer.length;
			for (int i = 0; i < 1000000; i++)
			{
				num = (float)__instance.m_videoPlayer.length;
				if (num > 0.01f)
				{
					break;
				}
			}
			VoiceContent.Logger.LogInfo((object)$"DisplayVideoEval was called: {__instance.m_videoPlayer.length}");
		}
	}
}
namespace VoiceContent.Localization
{
	public static class LocalizationData
	{
		private static readonly Dictionary<string, Dictionary<string, List<string>>> data = new Dictionary<string, Dictionary<string, List<string>>>
		{
			["en"] = new Dictionary<string, List<string>>
			{
				["swearWords"] = new List<string>
				{
					"fuck", "shit", "cunt", "bitch", "bastard", "asshole", "bullshit", "cock", "twat", "wanker",
					"bellend", "slut", "prick", "pussy", "motherfucker", "hell", "kill yourself"
				},
				["youtuberPhrases"] = new List<string>
				{
					"like and subscribe", "don't forget to share", "hit that subscribe button", "like comment and subscribe", "don't forget to subscribe", "let's jump right into it", "give this video a thumbs up", "that like button", "the like button", "that notification bell",
					"the notification bell", "that subscribe button", "the subscribe button", "before starting this video"
				},
				["sponsorPhrases"] = new List<string>
				{
					"i want to give a huge shoutout to our sponsor", "i want to give a shoutout to our sponsor", "i want to take a quick moment to thank", "video is sponsored by", "video is made possible by", "video is brought to you by", "episode is sponsored by", "episode is brought to you by", "episode is made possible by", "before we begin i want to thank",
					"promo code", "discount code", "star code", "creator code", "patreon", "gfuel", "temu", "nordvpn", "private internet access", "expressvpn",
					"audible", "skillshare", "squarespace", "raid shadow legends", "raycon", "hello fresh", "manscaped", "betterhelp", "grammarly", "blue apron",
					"dollar shave club", "rocket money", "fortnite", "honkai star rail", "genshin impact", "paypal", "surfshark"
				}
			},
			["pt-BR"] = new Dictionary<string, List<string>>
			{
				["swearWords"] = new List<string>
				{
					"porra", "caralho", "cacete", "merda", "bosta", "buceta", "filho da puta", "arrombado", "otario", "pau no cu",
					"se mata"
				},
				["youtuberPhrases"] = new List<string> { "curta e inscreva-se", "não esqueça de compartilhar", "ativa o sininho", "deixa o like", "manda pros amigos", "arrasta pra cima" },
				["sponsorPhrases"] = new List<string>
				{
					"codigo de desconto", "patreon", "gfuel", "temu", "nordvpn", "private internet access", "expressvpn", "audible", "skillshare", "squarespace",
					"raid shadow legends", "raycon", "hello fresh", "manscaped", "betterhelp", "grammarly", "blue apron", "dollar shave club", "rocket money", "fortnite",
					"honkai star rail", "genshin impact", "paypal"
				}
			}
		};

		public static List<string> GetLocalizedList(string languageCode, string key)
		{
			if (data.TryGetValue(languageCode, out Dictionary<string, List<string>> value) && value.TryGetValue(key, out var value2))
			{
				return value2;
			}
			return new List<string>();
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}