Decompiled source of ForeverVibing v1.0.1

plugins/ForeverVibing/ForeverVibing.dll

Decompiled 2 months ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Threading.Tasks;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using BepInEx.NET.Common;
using BepInExResoniteShim;
using BepisLocaleLoader;
using Elements.Core;
using FrooxEngine;
using FrooxEngine.ProtoFlux;
using HarmonyLib;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(/*Could not decode attribute arguments.*/)]
[assembly: TargetFramework(".NETCoreApp,Version=v10.0", FrameworkDisplayName = ".NET 10.0")]
[assembly: AssemblyCompany("LeCloutPanda")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1+037272a226dbc53061c591c10f8193c791b1a954")]
[assembly: AssemblyProduct("ForeverVibing")]
[assembly: AssemblyTitle("ForeverVibing")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/lecloutpanda/ForeverVibing")]
[assembly: AssemblyVersion("1.0.1.0")]
[module: RefSafetyRules(11)]
namespace ForeverVibing;

[ResonitePlugin("dev.lecloutpanda.ForeverVibing", "ForeverVibing", "1.0.1", "LeCloutPanda", "https://github.com/lecloutpanda/ForeverVibing")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Plugin : BasePlugin
{
	[HarmonyPatch(typeof(ProtoFluxTool))]
	private static class VibesPatch
	{
		[CompilerGenerated]
		private sealed class <>c__DisplayClass3_0
		{
			[StructLayout((LayoutKind)3)]
			private struct <<ToggleCustomVibes>b__0>d : IAsyncStateMachine
			{
				public int <>1__state;

				public AsyncTaskMethodBuilder <>t__builder;

				public <>c__DisplayClass3_0 <>4__this;

				private TaskAwaiter<bool> <>u__1;

				private void MoveNext()
				{
					//IL_0060: 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_006c: Unknown result type (might be due to invalid IL or missing references)
					//IL_0021: Unknown result type (might be due to invalid IL or missing references)
					//IL_0030: Expected O, but got Unknown
					//IL_0030: Unknown result type (might be due to invalid IL or missing references)
					//IL_0035: Unknown result type (might be due to invalid IL or missing references)
					//IL_0049: Unknown result type (might be due to invalid IL or missing references)
					//IL_004a: Unknown result type (might be due to invalid IL or missing references)
					int num = <>1__state;
					<>c__DisplayClass3_0 <>c__DisplayClass3_ = <>4__this;
					try
					{
						TaskAwaiter<bool> val;
						if (num != 0)
						{
							val = <>c__DisplayClass3_.vibesRoot.LoadObjectAsync(new Uri(CUSTOM_VIBES_RESOURCE.Value), (Slot)null, (ReferenceTranslator)null, true, true, (Predicate<global::System.Type>)null).GetAwaiter();
							if (!val.IsCompleted)
							{
								num = (<>1__state = 0);
								<>u__1 = val;
								((AsyncTaskMethodBuilder)(ref <>t__builder)).AwaitUnsafeOnCompleted<TaskAwaiter<bool>, <<ToggleCustomVibes>b__0>d>(ref val, ref this);
								return;
							}
						}
						else
						{
							val = <>u__1;
							<>u__1 = default(TaskAwaiter<bool>);
							num = (<>1__state = -1);
						}
						val.GetResult();
						<>c__DisplayClass3_.vibesRoot.Name = "✨Vibes✨";
					}
					catch (global::System.Exception exception)
					{
						<>1__state = -2;
						((AsyncTaskMethodBuilder)(ref <>t__builder)).SetException(exception);
						return;
					}
					<>1__state = -2;
					((AsyncTaskMethodBuilder)(ref <>t__builder)).SetResult();
				}

				[DebuggerHidden]
				private void SetStateMachine(IAsyncStateMachine stateMachine)
				{
					((AsyncTaskMethodBuilder)(ref <>t__builder)).SetStateMachine(stateMachine);
				}
			}

			public Slot vibesRoot;

			[AsyncStateMachine(typeof(<<ToggleCustomVibes>b__0>d))]
			internal global::System.Threading.Tasks.Task <ToggleCustomVibes>b__0()
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_0007: Unknown result type (might be due to invalid IL or missing references)
				<<ToggleCustomVibes>b__0>d <<ToggleCustomVibes>b__0>d = default(<<ToggleCustomVibes>b__0>d);
				<<ToggleCustomVibes>b__0>d.<>t__builder = AsyncTaskMethodBuilder.Create();
				<<ToggleCustomVibes>b__0>d.<>4__this = this;
				<<ToggleCustomVibes>b__0>d.<>1__state = -1;
				((AsyncTaskMethodBuilder)(ref <<ToggleCustomVibes>b__0>d.<>t__builder)).Start<<<ToggleCustomVibes>b__0>d>(ref <<ToggleCustomVibes>b__0>d);
				return ((AsyncTaskMethodBuilder)(ref <<ToggleCustomVibes>b__0>d.<>t__builder)).Task;
			}
		}

		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		[HarmonyPrefix]
		private static bool IsVibing(ProtoFluxTool __instance, ref bool __result)
		{
			if (!ENABLED.Value)
			{
				return true;
			}
			__result = ((Component)__instance).Slot.FindChild("✨Vibes✨") != null;
			return false;
		}

		[HarmonyPatch("GenerateMenuItems")]
		[HarmonyPostfix]
		private static void CreateCustomMenuItem(ProtoFluxTool __instance, InteractionHandler tool, ContextMenu menu)
		{
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Expected O, but got Unknown
			if (((Component)__instance).Slot.ActiveUser == ((Worker)__instance).LocalUser && (!ENABLED.Value || !Engine.Current.IsAprilFools) && ENABLED.Value)
			{
				bool flag = (bool)AccessTools.Property(((object)__instance).GetType(), "AreVibesActive").GetValue((object)__instance);
				string text = (flag ? "On" : "Off");
				LocaleString val = LocaleString.op_Implicit("Vibe Coding Mode: " + text);
				Uri sparks = General.Sparks;
				colorX? val2 = (flag ? colorX.Yellow : colorX.Gray);
				menu.AddItem(ref val, sparks, ref val2).Button.LocalPressed += (ButtonEventHandler)delegate(IButton button, ButtonEventData eventData)
				{
					//IL_0028: Unknown result type (might be due to invalid IL or missing references)
					((MethodBase)AccessTools.Method(typeof(ProtoFluxTool), "ToggleVibes", (global::System.Type[])null, (global::System.Type[])null)).Invoke((object)__instance, new object[2] { button, eventData });
				};
			}
		}

		[HarmonyPatch("ToggleVibes")]
		[HarmonyPrefix]
		private static bool ToggleVibesPatch(ProtoFluxTool __instance)
		{
			if (((Component)__instance).Slot.ActiveUser != ((Worker)__instance).LocalUser)
			{
				return true;
			}
			if (!ENABLED.Value)
			{
				return true;
			}
			if (!USE_CUSTOM_VIBES.Value)
			{
				return true;
			}
			if (Utility.IsNullOrWhiteSpace(CUSTOM_VIBES_RESOURCE.Value))
			{
				return true;
			}
			try
			{
				bool areVibesACtive = (bool)AccessTools.Property(((object)__instance).GetType(), "AreVibesActive").GetValue((object)__instance);
				ToggleCustomVibes(__instance, areVibesACtive);
				return false;
			}
			catch (global::System.Exception)
			{
				return true;
			}
		}

		private static Slot ToggleCustomVibes(ProtoFluxTool instance, bool areVibesACtive)
		{
			<>c__DisplayClass3_0 CS$<>8__locals3 = new <>c__DisplayClass3_0();
			if (areVibesACtive)
			{
				((Component)instance).Slot.FindChild("✨Vibes✨").Destroy();
				return null;
			}
			CS$<>8__locals3.vibesRoot = ((Component)instance).Slot.AddSlot("✨Vibes✨", true);
			((Worker)instance).StartTask((Func<global::System.Threading.Tasks.Task>)([AsyncStateMachine(typeof(<>c__DisplayClass3_0.<<ToggleCustomVibes>b__0>d))] () =>
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_0007: Unknown result type (might be due to invalid IL or missing references)
				<>c__DisplayClass3_0.<<ToggleCustomVibes>b__0>d <<ToggleCustomVibes>b__0>d = default(<>c__DisplayClass3_0.<<ToggleCustomVibes>b__0>d);
				<<ToggleCustomVibes>b__0>d.<>t__builder = AsyncTaskMethodBuilder.Create();
				<<ToggleCustomVibes>b__0>d.<>4__this = CS$<>8__locals3;
				<<ToggleCustomVibes>b__0>d.<>1__state = -1;
				((AsyncTaskMethodBuilder)(ref <<ToggleCustomVibes>b__0>d.<>t__builder)).Start<<>c__DisplayClass3_0.<<ToggleCustomVibes>b__0>d>(ref <<ToggleCustomVibes>b__0>d);
				return ((AsyncTaskMethodBuilder)(ref <<ToggleCustomVibes>b__0>d.<>t__builder)).Task;
			}));
			InteractionHandler activeHandler = ((Tool)instance).ActiveHandler;
			if (activeHandler != null)
			{
				activeHandler.CloseContextMenu();
			}
			return CS$<>8__locals3.vibesRoot;
		}
	}

	internal static ManualLogSource? Log;

	private static ConfigEntry<bool> ENABLED;

	private static ConfigEntry<bool> USE_CUSTOM_VIBES;

	private static ConfigEntry<string> CUSTOM_VIBES_RESOURCE;

	public override void Load()
	{
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0054: Expected O, but got Unknown
		//IL_0082: Unknown result type (might be due to invalid IL or missing references)
		//IL_008d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0097: Expected O, but got Unknown
		//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00de: Expected O, but got Unknown
		Log = ((BasePlugin)this).Log;
		((BasePlugin)this).HarmonyInstance.PatchAll();
		ENABLED = ((BasePlugin)this).Config.Bind<bool>("Toggles", "Enabled", true, new ConfigDescription("Enable the mod", (AcceptableValueBase)null, new object[1] { (object)new ConfigLocale("Settings.dev.lecloutpanda.ForeverVibing.Toggles.Enabled", "Settings.dev.lecloutpanda.ForeverVibing.Toggles.Enabled.Description") }));
		USE_CUSTOM_VIBES = ((BasePlugin)this).Config.Bind<bool>("Toggles", "Use Custom Vibes", false, new ConfigDescription("Enable use of Custom Vibe Visuals", (AcceptableValueBase)null, new object[1] { (object)new ConfigLocale("Settings.dev.lecloutpanda.ForeverVibing.Toggles.UseCustomVibes.Enabled", "Settings.dev.lecloutpanda.ForeverVibing.Toggles.UseCustomVibes.Enabled.Description") }));
		CUSTOM_VIBES_RESOURCE = ((BasePlugin)this).Config.Bind<string>("Toggles", "Custom Vibes Visual Url", "", new ConfigDescription("The url to your custom vibe visuals", (AcceptableValueBase)null, new object[1] { (object)new ConfigLocale("Settings.dev.lecloutpanda.ForeverVibing.Toggles.UseCustomVibes.Url", "Settings.dev.lecloutpanda.ForeverVibing.Toggles.UseCustomVibes.Url.Description") }));
	}
}
public static class PluginMetadata
{
	public const string GUID = "dev.lecloutpanda.ForeverVibing";

	public const string NAME = "ForeverVibing";

	public const string VERSION = "1.0.1";

	public const string AUTHORS = "LeCloutPanda";

	public const string REPOSITORY_URL = "https://github.com/lecloutpanda/ForeverVibing";
}