Decompiled source of DragonBallTV v1.1.0

DragonBallTV.dll

Decompiled 11 months ago
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using DragonBallTV.Core;
using HarmonyLib;
using UnityEngine;
using UnityEngine.Video;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("DragonBallTV")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("DragonBallTV")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("84d804f7-defd-4a6c-86f9-a52e4d1b9d01")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace DragonBallTV.Patches
{
	[HarmonyPatch]
	public static class TVPatches
	{
		[HarmonyPatch(typeof(TVScript), "__initializeVariables")]
		[HarmonyPostfix]
		public static void ReplaceVideos(TVScript __instance)
		{
			List<VideoClip> list = new List<VideoClip>();
			List<AudioClip> list2 = new List<AudioClip>();
			list.Add(Assets.GetAsset<VideoClip>("MakafushigiAdventureVideo"));
			list2.Add(Assets.GetAsset<AudioClip>("MakafushigiAdventureAudio"));
			list.Add(Assets.GetAsset<VideoClip>("ChaLaHeadChaLaVideo"));
			list2.Add(Assets.GetAsset<AudioClip>("ChaLaHeadChaLaAudio"));
			list.Add(Assets.GetAsset<VideoClip>("SuperSaiyanVideo"));
			list2.Add(Assets.GetAsset<AudioClip>("SuperSaiyanAudio"));
			list.Add(Assets.GetAsset<VideoClip>("DragonSoulVideo"));
			list2.Add(Assets.GetAsset<AudioClip>("DragonSoulAudio"));
			list.Add(Assets.GetAsset<VideoClip>("BattleOfGodsVideo"));
			list2.Add(Assets.GetAsset<AudioClip>("BattleOfGodsAudio"));
			list.Add(Assets.GetAsset<VideoClip>("DanDanVideo"));
			list2.Add(Assets.GetAsset<AudioClip>("DanDanAudio"));
			__instance.tvClips = list.ToArray();
			__instance.tvAudioClips = list2.ToArray();
			__instance.tvSFX.volume = DragonBallTVBase.Instance.Volume.Value;
		}
	}
}
namespace DragonBallTV.Core
{
	public static class Assets
	{
		public static AssetBundle AssetBundle { get; private set; }

		private static Dictionary<string, Object> AssetList { get; set; }

		private static string AssemblyName => Assembly.GetExecutingAssembly().FullName.Split(new char[1] { ',' })[0];

		public static void PopulateAssets()
		{
			if ((Object)(object)AssetBundle != (Object)null)
			{
				Logging.LogWarning("Attempted to load the asset bundle but the bundle was not null!");
				return;
			}
			string name = AssemblyName + ".dbtv";
			using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(name))
			{
				AssetBundle = AssetBundle.LoadFromStream(stream);
			}
			AssetList = new Dictionary<string, Object>();
			Object[] array = AssetBundle.LoadAllAssets();
			foreach (Object val in array)
			{
				AssetList.Add(val.name, val);
			}
		}

		public static T GetAsset<T>(string name) where T : Object
		{
			if (!AssetList.TryGetValue(name, out var value))
			{
				Logging.LogError("Attempted to load asset of name " + name + " but no asset of that name exists!");
				return default(T);
			}
			T val = (T)(object)((value is T) ? value : null);
			if ((Object)(object)val == (Object)null)
			{
				Logging.LogError("Attempted to load an asset of type " + typeof(T).Name + " but asset of name " + name + " does not match this type!");
				return default(T);
			}
			return val;
		}
	}
	public static class Logging
	{
		public static void LogInfo(object message)
		{
			DragonBallTVBase.Instance.PluginLogger.LogMessage(message);
		}

		public static void LogDebug(object message)
		{
			DragonBallTVBase.Instance.PluginLogger.LogDebug(message);
		}

		public static void LogWarning(object message)
		{
			DragonBallTVBase.Instance.PluginLogger.LogWarning(message);
		}

		public static void LogError(object message)
		{
			DragonBallTVBase.Instance.PluginLogger.LogError(message);
		}
	}
	[BepInPlugin("Vulf.DragonBallTV", "Dragon Ball TV", "1.1.0")]
	public class DragonBallTVBase : BaseUnityPlugin
	{
		private static DragonBallTVBase _instance;

		public static DragonBallTVBase Instance
		{
			get
			{
				return _instance;
			}
			private set
			{
				if ((Object)(object)Instance != (Object)null && (Object)(object)value != (Object)(object)Instance)
				{
					((BaseUnityPlugin)Instance).Logger.LogWarning((object)"An instance of class of type DragonBallTVBase was created but one already exists! Destroying duplicate!");
					Object.Destroy((Object)(object)value);
				}
				else
				{
					_instance = value;
				}
			}
		}

		private Harmony Harmony { get; set; }

		public ManualLogSource PluginLogger => ((BaseUnityPlugin)this).Logger;

		public ConfigEntry<float> Volume { get; private set; }

		public void Awake()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			Instance = this;
			Harmony = new Harmony("Vulf.DragonBallTV");
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Loading mod...");
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Populating assets...");
			Assets.PopulateAssets();
			Volume = ((BaseUnityPlugin)this).Config.Bind<float>("Sound", "TV Volume", 0.75f, "How loud the TV is on a scale of 0 to 1 (clientside). Set this to 0 to mute the audio completely.");
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Patching...");
			Harmony.PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Mod loaded successfully!");
		}
	}
	public class PluginInfo
	{
		public const string GUID = "Vulf.DragonBallTV";

		public const string NAME = "Dragon Ball TV";

		public const string VERSION = "1.1.0";

		public const string ASSET_BUNDLE_NAME = "dbtv";
	}
}