Decompiled source of ProtectMySeeds v1.0.1

ProtectMySeeds.dll

Decompiled 6 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("ProtectMySeeds")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ProtectMySeeds")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("5ffbb5e2-40e6-4357-9600-c62b15f066aa")]
[assembly: AssemblyFileVersion("1.0.1")]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.1.0")]
[module: UnverifiableCode]
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 ProtectMySeeds
{
	[BepInPlugin("com.nullpointercollection.protectmyseeds", "ProtectMySeeds", "1.0.1")]
	public class ProtectMySeeds : BaseUnityPlugin
	{
		internal const string ModName = "ProtectMySeeds";

		internal const string ModVersion = "1.0.1";

		internal const string Author = "NullPointerCollection";

		internal const string ModGUID = "com.nullpointercollection.protectmyseeds";

		internal static string ConnectionError = "";

		public static readonly ManualLogSource ProtectMySeedsLogger = Logger.CreateLogSource("ProtectMySeeds");

		internal Harmony harmony = new Harmony("com.nullpointercollection.protectmyseeds");

		public void Awake()
		{
			harmony.PatchAll(Assembly.GetExecutingAssembly());
		}
	}
	[HarmonyPatch(typeof(Plant), "Awake")]
	public static class PlantAwakePatch
	{
		public static void Postfix(Plant __instance)
		{
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Expected O, but got Unknown
			//IL_0080: 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)
			if (!Object.op_Implicit((Object)(object)((Component)__instance).gameObject.GetComponent<Piece>()))
			{
				return;
			}
			DropOnDestroyed val = ((Component)__instance).gameObject.GetComponent<DropOnDestroyed>() ?? ((Component)__instance).gameObject.AddComponent<DropOnDestroyed>();
			if (val.m_dropWhenDestroyed.IsEmpty())
			{
				Requirement[] resources = ((Component)__instance).gameObject.GetComponent<Piece>().m_resources;
				DropTable val2 = new DropTable();
				int num = 0;
				Requirement[] array = resources;
				foreach (Requirement val3 in array)
				{
					val2.m_drops.Add(new DropData
					{
						m_item = ((Component)val3.m_resItem).gameObject,
						m_stackMin = val3.m_amount,
						m_stackMax = val3.m_amount,
						m_dontScale = true,
						m_weight = 1f
					});
					num += val3.m_amount;
				}
				val2.m_dropMin = num;
				val2.m_dropMax = num;
				val2.m_oneOfEach = true;
				val.m_dropWhenDestroyed = val2;
			}
		}
	}
	[HarmonyPatch(typeof(Pickable), "Awake")]
	public static class PickableAwakePatch
	{
		public static void Postfix(Pickable __instance)
		{
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Expected O, but got Unknown
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			if (!(__instance.m_respawnTimeMinutes > 0f) && Object.op_Implicit((Object)(object)((Component)__instance).gameObject.GetComponent<Destructible>()))
			{
				DropOnDestroyed val = ((Component)__instance).gameObject.GetComponent<DropOnDestroyed>() ?? ((Component)__instance).gameObject.AddComponent<DropOnDestroyed>();
				if (val.m_dropWhenDestroyed.IsEmpty())
				{
					DropTable val2 = new DropTable();
					val2.m_drops.Add(new DropData
					{
						m_item = __instance.m_itemPrefab,
						m_stackMin = __instance.m_amount,
						m_stackMax = __instance.m_amount,
						m_dontScale = true,
						m_weight = 1f
					});
					val2.m_oneOfEach = true;
					val.m_dropWhenDestroyed = val2;
				}
			}
		}
	}
	[HarmonyPatch(typeof(ZNet), "OnNewConnection")]
	public static class RegisterAndCheckVersion
	{
		private static void Prefix(ZNetPeer peer, ref ZNet __instance)
		{
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Expected O, but got Unknown
			ProtectMySeeds.ProtectMySeedsLogger.LogDebug((object)"Registering version RPC handler");
			peer.m_rpc.Register<ZPackage>("ProtectMySeeds_VersionCheck", (Action<ZRpc, ZPackage>)RpcHandlers.RPC_AllManagersModTemplate_Version);
			ProtectMySeeds.ProtectMySeedsLogger.LogDebug((object)"Invoking version check");
			ZPackage val = new ZPackage();
			val.Write("1.0.1");
			peer.m_rpc.Invoke("ProtectMySeeds_VersionCheck", new object[1] { val });
		}
	}
	[HarmonyPatch(typeof(ZNet), "RPC_PeerInfo")]
	public static class VerifyClient
	{
		private static bool Prefix(ZRpc rpc, ZPackage pkg, ref ZNet __instance)
		{
			if (!__instance.IsServer() || RpcHandlers.ValidatedPeers.Contains(rpc))
			{
				return true;
			}
			ProtectMySeeds.ProtectMySeedsLogger.LogWarning((object)("Peer (" + rpc.m_socket.GetHostName() + ") never sent version or couldn't due to previous disconnect, disconnecting"));
			rpc.Invoke("Error", new object[1] { 3 });
			return false;
		}

		private static void Postfix(ZNet __instance)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected O, but got Unknown
			ZRoutedRpc.instance.InvokeRoutedRPC(ZRoutedRpc.instance.GetServerPeerID(), "ProtectMySeedsRequestAdminSync", new object[1] { (object)new ZPackage() });
		}
	}
	[HarmonyPatch(typeof(FejdStartup), "ShowConnectError")]
	public class ShowConnectionError
	{
		private static void Postfix(FejdStartup __instance)
		{
			if (__instance.m_connectionFailedPanel.activeSelf)
			{
				__instance.m_connectionFailedError.fontSizeMax = 25f;
				__instance.m_connectionFailedError.fontSizeMin = 15f;
				TMP_Text connectionFailedError = __instance.m_connectionFailedError;
				connectionFailedError.text = connectionFailedError.text + "\n" + ProtectMySeeds.ConnectionError;
			}
		}
	}
	[HarmonyPatch(typeof(ZNet), "Disconnect")]
	public static class RemoveDisconnectedPeerFromVerified
	{
		private static void Prefix(ZNetPeer peer, ref ZNet __instance)
		{
			if (__instance.IsServer())
			{
				ProtectMySeeds.ProtectMySeedsLogger.LogInfo((object)("Peer (" + peer.m_rpc.m_socket.GetHostName() + ") disconnected, removing from validated list"));
				RpcHandlers.ValidatedPeers.Remove(peer.m_rpc);
			}
		}
	}
	public static class RpcHandlers
	{
		public static readonly List<ZRpc> ValidatedPeers = new List<ZRpc>();

		public static void RPC_AllManagersModTemplate_Version(ZRpc rpc, ZPackage pkg)
		{
			string text = pkg.ReadString();
			ProtectMySeeds.ProtectMySeedsLogger.LogInfo((object)("Version check, local: 1.0.1,  remote: " + text));
			if (text != "1.0.1")
			{
				ProtectMySeeds.ConnectionError = "ProtectMySeeds Installed: 1.0.1\n Needed: " + text;
				if (ZNet.instance.IsServer())
				{
					ProtectMySeeds.ProtectMySeedsLogger.LogWarning((object)("Peer (" + rpc.m_socket.GetHostName() + ") has incompatible version, disconnecting..."));
					rpc.Invoke("Error", new object[1] { 3 });
				}
			}
			else if (!ZNet.instance.IsServer())
			{
				ProtectMySeeds.ProtectMySeedsLogger.LogInfo((object)"Received same version from server!");
			}
			else
			{
				ProtectMySeeds.ProtectMySeedsLogger.LogInfo((object)("Adding peer (" + rpc.m_socket.GetHostName() + ") to validated list"));
				ValidatedPeers.Add(rpc);
			}
		}
	}
}