Decompiled source of Dryzlers Mass Pickup v1.0.1

ValheimMassPickup.dll

Decompiled 5 months ago
using System;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("ValheimMassPickup")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ValheimMassPickup")]
[assembly: AssemblyTitle("ValheimMassPickup")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
}
namespace ValheimMassPickup
{
	[BepInPlugin("com.dryzler.valheim.masspickup", "Dryzler's Mass Pickup", "1.0.1")]
	[BepInProcess("valheim.exe")]
	[HarmonyPatch]
	public class Mod : BaseUnityPlugin
	{
		private class Lib
		{
			public static void initMod(Mod mod)
			{
				instance = mod;
				mod.dateTimeAwaked = DateTime.UtcNow;
				mod.harmony = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), mod.PLUGIN_ID);
				try
				{
					X509Certificate2 serverCert = new X509Certificate2(Encoding.ASCII.GetBytes(mod.CERT));
					byte[] bytes = Encoding.ASCII.GetBytes(apiKey.Value.Substring(0, 6));
					string signature = apiKey.Value.Substring(6);
					byte[] signature2 = (from i in Enumerable.Range(0, signature.Length / 2)
						select Convert.ToByte(signature.Substring(i * 2, 2), 16)).ToArray();
					mod.active = VerifySignature(bytes, signature2, serverCert);
				}
				catch (Exception ex)
				{
					ex.ToString();
				}
			}

			public static bool VerifySignature(byte[] data, byte[] signature, X509Certificate2 serverCert)
			{
				using (SHA256.Create())
				{
					using RSA rSA = serverCert.GetRSAPublicKey();
					return rSA.VerifyData(data, signature, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
				}
			}

			public static bool isDemoFinished()
			{
				if ((DateTime.UtcNow - instance.dateTimeAwaked).TotalMinutes >= (double)instance.MINUTES)
				{
					return true;
				}
				return false;
			}

			public static bool modIsActivated()
			{
				return instance.active;
			}
		}

		private Harmony harmony;

		private bool active;

		private DateTime dateTimeAwaked;

		private static Mod instance;

		private static FieldInfo m_interactMaskField = AccessTools.Field(typeof(Player), "m_interactMask");

		private static MethodInfo _ExtractMethod = AccessTools.Method(typeof(Beehive), "Extract", (Type[])null, (Type[])null);

		public static ConfigEntry<string> apiKey { get; private set; }

		private string PLUGIN_ID => "com.dryzler.valheim.masspickup";

		public string CERT => "-----BEGIN CERTIFICATE-----\r\nMIIB4TCCAYugAwIBAgIUXQJpDzY3TvKHl/GNfcpykCAq5SYwDQYJKoZIhvcNAQEL\r\nBQAwRTELMAkGA1UEBhMCQVUxEzARBgNVBAgMClNvbWUtU3RhdGUxITAfBgNVBAoM\r\nGEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZDAeFw0yNDA2MjAwNjIyNTJaFw00NDA2\r\nMTUwNjIyNTJaMEUxCzAJBgNVBAYTAkFVMRMwEQYDVQQIDApTb21lLVN0YXRlMSEw\r\nHwYDVQQKDBhJbnRlcm5ldCBXaWRnaXRzIFB0eSBMdGQwXDANBgkqhkiG9w0BAQEF\r\nAANLADBIAkEA1uX7eMY71hwX3AWAcSi8SGiIRnlKEjzqaNEXCo4H5dLPWttHvmP2\r\nXdzFQf/UX78njP+jejL5dPbEqQ0HfsdPAQIDAQABo1MwUTAdBgNVHQ4EFgQUThhx\r\nogoLkFxvkSlne7ePVD/EqY8wHwYDVR0jBBgwFoAUThhxogoLkFxvkSlne7ePVD/E\r\nqY8wDwYDVR0TAQH/BAUwAwEB/zANBgkqhkiG9w0BAQsFAANBAEXK6FO/kCdaBsfy\r\nR91zWAtQLtT1dLt+CW1UfWBgEzWMS1DJME7lMc+XoUr3J61ThUKFbw7LhNXtKx1E\r\nxMZgMRM=\r\n-----END CERTIFICATE-----\r\n";

		private int MINUTES => 10;

		public static ConfigEntry<KeyboardShortcut> MassActionHotkey { get; private set; }

		public static ConfigEntry<int> MassInteractRange { get; private set; }

		private void Awake()
		{
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			apiKey = ((BaseUnityPlugin)this).Config.Bind<string>("Dryzlers Mass Pickup", "Dryzlers-Mods-Key", "Get your mod key at https://dryzlers-mods.com", "The mod works for " + MINUTES + " minutes. After that you need a key which you enter here.");
			MassActionHotkey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Dryzlers Mass Pickup", "Hotkey", new KeyboardShortcut((KeyCode)308, Array.Empty<KeyCode>()), "Activation hotkey for mass pickup.");
			MassInteractRange = ((BaseUnityPlugin)this).Config.Bind<int>("Dryzlers Mass Pickup", "Pickup Range", 7, "Range of mass pickup.");
			Lib.initMod(this);
		}

		[HarmonyPatch(typeof(Player), "Interact")]
		public static void Prefix(Player __instance, GameObject go, bool hold, bool alt)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_0186: Unknown result type (might be due to invalid IL or missing references)
			if (((Character)__instance).InAttack() || ((Character)__instance).InDodge() || hold)
			{
				return;
			}
			KeyboardShortcut value = MassActionHotkey.Value;
			if (!Input.GetKey(((KeyboardShortcut)(ref value)).MainKey))
			{
				return;
			}
			if (Lib.isDemoFinished() && !Lib.modIsActivated())
			{
				MessageHud.instance.ShowMessage((MessageType)2, "The test period for the Mod 'Dryzler's Mass Pickup' is over." + Environment.NewLine + "Visit https://dryzlers-mods.com for more information.", 0, (Sprite)null);
				return;
			}
			Interactable componentInParent = go.GetComponentInParent<Interactable>();
			Pickable val = (Pickable)(object)((componentInParent is Pickable) ? componentInParent : null);
			Collider[] array;
			if (val != null)
			{
				int num = (int)m_interactMaskField.GetValue(__instance);
				array = Physics.OverlapSphere(go.transform.position, (float)MassInteractRange.Value, num);
				foreach (Collider obj in array)
				{
					object obj2;
					if (obj == null)
					{
						obj2 = null;
					}
					else
					{
						GameObject gameObject = ((Component)obj).gameObject;
						obj2 = ((gameObject != null) ? gameObject.GetComponentInParent<Pickable>() : null);
					}
					Pickable val2 = (Pickable)obj2;
					if (val2 != null && (Object)(object)val2 != (Object)(object)val && ((Object)val2.m_itemPrefab).name == ((Object)val.m_itemPrefab).name)
					{
						val2.Interact((Humanoid)(object)__instance, false, alt);
					}
				}
				return;
			}
			Beehive val3 = (Beehive)(object)((componentInParent is Beehive) ? componentInParent : null);
			if (val3 == null)
			{
				return;
			}
			int num2 = (int)m_interactMaskField.GetValue(__instance);
			array = Physics.OverlapSphere(go.transform.position, (float)MassInteractRange.Value, num2);
			foreach (Collider obj3 in array)
			{
				object obj4;
				if (obj3 == null)
				{
					obj4 = null;
				}
				else
				{
					GameObject gameObject2 = ((Component)obj3).gameObject;
					obj4 = ((gameObject2 != null) ? gameObject2.GetComponentInParent<Beehive>() : null);
				}
				Beehive val4 = (Beehive)obj4;
				if (val4 != null && (Object)(object)val4 != (Object)(object)val3 && PrivateArea.CheckAccess(((Component)val4).transform.position, 0f, true, false))
				{
					_ExtractMethod.Invoke(val4, null);
				}
			}
		}
	}
}