Decompiled source of PalletPaste v2.0.0

PalletPaste.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Diagnostics;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BoneLib;
using BoneLib.BoneMenu;
using LabFusion.Downloading;
using LabFusion.Downloading.ModIO;
using LabFusion.Utilities;
using MelonLoader;
using MelonLoader.Preferences;
using Microsoft.CodeAnalysis;
using PalletPaste;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(Core), "PalletPaste", "2.0.0", "Fizzyhex", null)]
[assembly: MelonColor(255, 20, 194, 215)]
[assembly: MelonAuthorColor(255, 108, 116, 230)]
[assembly: MelonAdditionalDependencies(new string[] { "LabFusion" })]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("PalletPaste")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+5c8be27d27ae656ccbcdde3c90dd886b73baf135")]
[assembly: AssemblyProduct("PalletPaste")]
[assembly: AssemblyTitle("PalletPaste")]
[assembly: NeutralResourcesLanguage("en-US")]
[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 PalletPaste
{
	public class Core : MelonMod
	{
		public override void OnUpdate()
		{
			if (Input.GetKey((KeyCode)306) && Input.GetKeyDown((KeyCode)118))
			{
				OnPaste();
			}
		}

		internal static void OnPaste(bool verbose = false)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: 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_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Expected O, but got Unknown
			string text = GUIUtility.systemCopyBuffer.Trim();
			if (!Downloader.IsModPageUrl(text))
			{
				if (verbose)
				{
					FusionNotifier.Send(new FusionNotification
					{
						Title = NotificationText.op_Implicit("Pallet Paste"),
						Message = NotificationText.op_Implicit("No mod.io link detected on clipboard!"),
						Type = (NotificationType)2
					});
				}
			}
			else
			{
				MelonLogger.Msg("Mod.io link detected: " + text.Trim());
				Downloader.DownloadFromModPageUrl(text.Trim());
			}
		}

		public override void OnInitializeMelon()
		{
			PalletPastePage.Create();
		}
	}
	public static class Downloader
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static DownloadCallback <0>__OnDownloadComplete;
		}

		public static void DownloadFromModPageUrl(string modPageUrl)
		{
			ModIOSettings.LoadToken((Action<string>)OnTokenLoaded);
			void OnTokenLoaded(string token)
			{
				//IL_002f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0039: Expected O, but got Unknown
				string modSlug = modPageUrl.Split('/')[^1];
				ModIOManagerPublic.GetModFromSlug(modSlug, (ModCallback)delegate(ModCallbackInfo info)
				{
					//IL_0000: Unknown result type (might be due to invalid IL or missing references)
					QueueDownload(info, modSlug);
				});
			}
		}

		public static void QueueDownload(ModCallbackInfo info, string displayName)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Invalid comparison between Unknown and I4
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Expected O, but got Unknown
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Expected O, but got Unknown
			//IL_00d0: Expected O, but got Unknown
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Expected O, but got Unknown
			if ((int)info.result == 1)
			{
				MelonLogger.Msg("Failed to get mod info");
				FusionNotifier.Send(new FusionNotification
				{
					Title = NotificationText.op_Implicit("Pallet Paste"),
					Message = NotificationText.op_Implicit("Failed to fetch mod info for " + displayName),
					Type = (NotificationType)2
				});
				return;
			}
			MelonLogger.Msg("Got mod info - downloading...");
			ModTransaction val = new ModTransaction
			{
				ModFile = new ModIOFile(((ModData)(ref info.data)).Id, (int?)null)
			};
			object obj = <>O.<0>__OnDownloadComplete;
			if (obj == null)
			{
				DownloadCallback val2 = OnDownloadComplete;
				<>O.<0>__OnDownloadComplete = val2;
				obj = (object)val2;
			}
			val.Callback = (DownloadCallback)obj;
			FusionNotifier.Send(new FusionNotification
			{
				Title = NotificationText.op_Implicit("Pallet Paste"),
				Message = NotificationText.op_Implicit(displayName + " was added to the download queue!")
			});
			ModIODownloader.EnqueueDownload(val);
			static void OnDownloadComplete(DownloadCallbackInfo transaction)
			{
				//IL_0000: Unknown result type (might be due to invalid IL or missing references)
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				//IL_0007: Invalid comparison between Unknown and I4
				if ((int)transaction.result == 1)
				{
					MelonLogger.Msg("Download failed!");
				}
				else
				{
					MelonLogger.Msg("Download succeeded!");
				}
			}
		}

		public static bool IsModPageUrl(string text)
		{
			string text2 = text.Replace("http://", "").Replace("https://", "");
			if (text2.Contains("bonelab/m/"))
			{
				return text2.StartsWith("mod.io");
			}
			return false;
		}
	}
	public static class ModIOManagerPublic
	{
		public static void GetModFromSlug(string modSlug, ModCallback modCallback)
		{
			string url = ModIOSettings.GameApiPath + "@" + modSlug;
			MelonLogger.Msg("Downloading mod file from '" + url + "'...");
			ModIOSettings.LoadToken((Action<string>)OnTokenLoaded);
			void OnTokenLoaded(string token)
			{
				//IL_0013: Unknown result type (might be due to invalid IL or missing references)
				if (string.IsNullOrWhiteSpace(token))
				{
					ModCallback obj = modCallback;
					if (obj != null)
					{
						obj.Invoke(ModCallbackInfo.FailedCallback);
					}
				}
				else
				{
					MelonCoroutines.Start((IEnumerator)typeof(ModIOManager).GetMethod("CoGetMod", BindingFlags.Static | BindingFlags.NonPublic).Invoke(null, new object[3] { url, token, modCallback }));
				}
			}
		}
	}
	internal static class PalletPastePage
	{
		private static MelonPreferences_Category _category;

		private static MelonPreferences_Entry<bool> _boneMenuEnabled;

		public static void Create()
		{
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			_category = MelonPreferences.CreateCategory("PalletPaste", "Pallet Paste");
			_boneMenuEnabled = _category.CreateEntry<bool>("BoneMenuEnabled", true, "BoneMenu Enabled", (string)null, false, false, (ValueValidator)null, (string)null);
			Page settingsPage;
			if (_boneMenuEnabled.Value)
			{
				Page val = Page.Root.CreatePage("Pallet Paste", Color.cyan, 0, true);
				val.CreateFunction("Paste!", Color.cyan, (Action)delegate
				{
					Core.OnPaste(verbose: true);
				});
				if (!HelperMethods.IsAndroid())
				{
					settingsPage = val.CreatePage("Settings (PC)", Color.white, 0, true);
					DrawSettings();
				}
			}
			void DrawSettings()
			{
				//IL_0029: Unknown result type (might be due to invalid IL or missing references)
				settingsPage.RemoveAll();
				settingsPage.CreateFunction(_boneMenuEnabled.Value ? "Hide from BoneMenu" : "Undo hide from BoneMenu", Color.red, (Action)delegate
				{
					if (_boneMenuEnabled.Value)
					{
						Menu.DisplayDialog("Disable this page?", "You will need to manually edit your MelonPreferences file to re-enable this page after game restart. Are you sure?", (Texture2D)null, (Action)delegate
						{
							_boneMenuEnabled.Value = false;
							_category.SaveToFile(true);
							Menu.CurrentPage = Page.Root;
							DrawSettings();
						}, (Action)null);
					}
					else
					{
						_boneMenuEnabled.Value = true;
						_category.SaveToFile(true);
						DrawSettings();
					}
				});
			}
		}
	}
	internal class PageExtras
	{
		[CompilerGenerated]
		private MelonPreferences_Category <category>P;

		[CompilerGenerated]
		private Page <page>P;

		public PageExtras(MelonPreferences_Category category, Page page)
		{
			<category>P = category;
			<page>P = page;
			base..ctor();
		}

		public BoolElement CreateBoolPref(ref MelonPreferences_Entry<bool> pref, string name, Color color, bool startValue, Action<bool> callback = null, string prefName = null)
		{
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			if (prefName == null)
			{
				prefName = name;
			}
			if (!<category>P.HasEntry(prefName))
			{
				pref = <category>P.CreateEntry<bool>(prefName, startValue, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			}
			MelonPreferences_Entry<bool> entry = pref;
			return <page>P.CreateBool(((MelonPreferences_Entry)pref).DisplayName, color, entry.Value, (Action<bool>)delegate(bool value)
			{
				Action<bool> action = callback;
				if (action != null)
				{
					Extensions.InvokeActionSafe<bool>(action, value);
				}
				entry.Value = value;
				<category>P.SaveToFile(true);
			});
		}
	}
}