Decompiled source of ThomasTheJester v1.0.0

ThomasTheJester/ThomasTheJester.dll

Decompiled 10 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.Bootstrap;
using BepInEx.Configuration;
using HarmonyLib;
using LethalConfig;
using LethalConfig.ConfigItems;
using LethalConfig.ConfigItems.Options;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Networking;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("ThomasTheJester")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ThomasTheJester")]
[assembly: AssemblyTitle("ThomasTheJester")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace ThomasTheJester
{
	public class Config
	{
		public readonly ConfigEntry<bool> PatchPopUpTimerEntry;

		public Config(ConfigFile configFile, bool lethalConfigLoaded)
		{
			PatchPopUpTimerEntry = configFile.Bind<bool>("General", "patchPopUpTimer", true, "[Host Only] Define if the jester's pop up timer should fit the music length");
			if (lethalConfigLoaded)
			{
				DoLethalConfigStuff();
			}
		}

		private void DoLethalConfigStuff()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Expected O, but got Unknown
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected O, but got Unknown
			BoolCheckBoxConfigItem val = new BoolCheckBoxConfigItem(PatchPopUpTimerEntry, new BoolCheckBoxOptions
			{
				Name = "Patch Pop Up Timer"
			});
			LethalConfigManager.AddConfigItem((BaseConfigItem)(object)val);
		}
	}
	[HarmonyPatch(typeof(JesterAI))]
	public class JesterPatch
	{
		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		public static void Start(JesterAI __instance)
		{
			__instance.popGoesTheWeaselTheme = Plugin.Music;
		}

		[HarmonyPatch("SetJesterInitialValues")]
		[HarmonyPostfix]
		public static void SetJesterInitialValues(JesterAI __instance)
		{
			if (Plugin.ModConfig.PatchPopUpTimerEntry.Value)
			{
				__instance.popUpTimer = Plugin.Music.length;
			}
		}
	}
	[BepInPlugin("ThomasTheJester", "Thomas The Jester", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public const string GUID = "ThomasTheJester";

		public const string Name = "Thomas The Jester";

		public const string Version = "1.0.0";

		public static Config ModConfig { get; private set; }

		public static AudioClip Music { get; private set; }

		private void Awake()
		{
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			ModConfig = new Config(((BaseUnityPlugin)this).Config, IsLethalConfigLoaded());
			Music = LoadCustomMusic();
			if (!((Object)(object)Music == (Object)null))
			{
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Patching JesterAI...");
				new Harmony("ThomasTheJester").PatchAll(typeof(JesterPatch));
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin Thomas The Jester is loaded!");
			}
		}

		private AudioClip LoadCustomMusic()
		{
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Invalid comparison between Unknown and I4
			string text = ((BaseUnityPlugin)this).Info.Location.TrimEnd("ThomasTheJester.dll".ToCharArray());
			UnityWebRequest audioClip = UnityWebRequestMultimedia.GetAudioClip("File://" + text + "thomas.mp3", (AudioType)13);
			audioClip.SendWebRequest();
			while (!audioClip.isDone)
			{
			}
			if ((int)audioClip.result == 1)
			{
				return DownloadHandlerAudioClip.GetContent(audioClip);
			}
			((BaseUnityPlugin)this).Logger.LogError((object)"Failed to load the audio file!");
			return null;
		}

		private static bool IsLethalConfigLoaded()
		{
			return Chainloader.PluginInfos.Any((KeyValuePair<string, PluginInfo> pluginInfo) => pluginInfo.Value.Metadata.GUID.Equals("ainavt.lc.lethalconfig"));
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "ThomasTheJester";

		public const string PLUGIN_NAME = "ThomasTheJester";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}