Decompiled source of VTMaxwellRobot v1.0.0

Maxwell.dll

Decompiled a year ago
using System;
using System.Collections;
using System.Diagnostics;
using System.IO;
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 HarmonyLib;
using Maxwell.Patches;
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("Maxwell")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("My first plugin")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Maxwell")]
[assembly: AssemblyTitle("Maxwell")]
[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 Maxwell
{
	public class SharedCoroutineStarter : MonoBehaviour
	{
		private static SharedCoroutineStarter _instance;

		public static Coroutine StartCoroutine(IEnumerator routine)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_instance == (Object)null)
			{
				_instance = new GameObject("Shared Coroutine Starter").AddComponent<SharedCoroutineStarter>();
				Object.DontDestroyOnLoad((Object)(object)_instance);
			}
			return ((MonoBehaviour)_instance).StartCoroutine(routine);
		}
	}
	[BepInPlugin("com.bepinex.plugin.MaxwellRobot", "Maxwell Robot", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		private const string modGUID = "com.bepinex.plugin.MaxwellRobot";

		private const string modName = "Maxwell Robot";

		private const string modVersion = "1.0.0";

		private readonly Harmony harmony = new Harmony("com.bepinex.plugin.MaxwellRobot");

		private static Plugin Instance;

		private ConfigEntry<bool> IsEnabled;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin is loaded!");
			IsEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General.Toggles", "Enable the maxwell theme", true, "Whether or not to enable the mod");
			if (IsEnabled.Value)
			{
				LogInfo("Plugin is enabled.");
				harmony.PatchAll(typeof(StartOfRoundPatch));
				harmony.PatchAll(typeof(RobotToySound));
			}
			else
			{
				LogInfo("Plugin is disabled.");
			}
		}

		public static void LogInfo(string message)
		{
			((BaseUnityPlugin)Instance).Logger.Log((LogLevel)16, (object)message);
		}

		public static void LogWarning(string message)
		{
			((BaseUnityPlugin)Instance).Logger.Log((LogLevel)4, (object)message);
		}

		public static void LogError(string message)
		{
			((BaseUnityPlugin)Instance).Logger.Log((LogLevel)2, (object)message);
		}

		public static void LogError(Exception ex)
		{
			((BaseUnityPlugin)Instance).Logger.Log((LogLevel)2, (object)ex);
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "Maxwell";

		public const string PLUGIN_NAME = "Maxwell";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace Maxwell.Patches
{
	internal static class AudioLoad
	{
		private static bool FirstRun = true;

		private static readonly string FilePath = Path.Combine(Paths.PluginPath, "RobotToySound", "maxwell.wav");

		public static AudioClip Clip = null;

		public static bool FinishedLoading = false;

		public static bool FileFound = true;

		public static void Load()
		{
			if (FirstRun)
			{
				FirstRun = false;
				if (!File.Exists(FilePath))
				{
					FileFound = false;
					Plugin.LogError("File " + FilePath + " not found");
				}
				else
				{
					SharedCoroutineStarter.StartCoroutine(LoadAudioClip(FilePath));
				}
			}
		}

		private static IEnumerator LoadAudioClip(string filePath)
		{
			Plugin.LogInfo("Loading " + FilePath);
			UnityWebRequest loader = UnityWebRequestMultimedia.GetAudioClip(filePath, (AudioType)20);
			loader.SendWebRequest();
			while (!loader.isDone)
			{
				yield return null;
			}
			if (loader.error != null)
			{
				Plugin.LogError("Error loading " + FilePath + "\n" + loader.error);
				FileFound = false;
				yield break;
			}
			AudioClip clip = DownloadHandlerAudioClip.GetContent(loader);
			if (Object.op_Implicit((Object)(object)clip) && (int)clip.loadState == 2)
			{
				Plugin.LogInfo("Loaded " + FilePath);
				((Object)clip).name = Path.GetFileName(filePath);
				Clip = clip;
				FinishedLoading = true;
			}
		}
	}
	[HarmonyPatch(typeof(AnimatedItem))]
	internal class RobotToySound
	{
		[HarmonyPatch("EquipItem")]
		[HarmonyPrefix]
		private static void Prefix(AnimatedItem __instance)
		{
			if (((Object)__instance.grabAudio).name != ((Object)AudioLoad.Clip).name && ((Object)__instance.grabAudio).name == "RobotToyCheer")
			{
				Plugin.LogInfo("Set robot audio to maxwell");
				__instance.grabAudio = AudioLoad.Clip;
			}
		}
	}
	[HarmonyPatch(typeof(StartOfRound))]
	internal class StartOfRoundPatch
	{
		[HarmonyPatch("Start")]
		private static void Prefix()
		{
			AudioLoad.Load();
		}
	}
}