Decompiled source of HoldMySpear v1.0.1

HoldMySpear.dll

Decompiled 2 years ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using HoldMySpear.Patches;
using Microsoft.CodeAnalysis;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.6", FrameworkDisplayName = ".NET Framework 4.6")]
[assembly: AssemblyCompany("HoldMySpear")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("A simple spear ownership plugin.")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1")]
[assembly: AssemblyProduct("HoldMySpear")]
[assembly: AssemblyTitle("HoldMySpear")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.1.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 HoldMySpear
{
	[BepInPlugin("HoldMySpear", "HoldMySpear", "1.0.1")]
	public class Plugin : BaseUnityPlugin
	{
		private readonly Harmony harmony = new Harmony("HoldMySpear");

		private void Awake()
		{
			Logger.Sources.Add((ILogSource)(object)DropCheck.Logger);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin HoldMySpear is loaded!");
			Assembly executingAssembly = Assembly.GetExecutingAssembly();
			harmony.PatchAll(executingAssembly);
		}

		private void Destroy()
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin HoldMySpear destroyed.");
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "HoldMySpear";

		public const string PLUGIN_NAME = "HoldMySpear";

		public const string PLUGIN_VERSION = "1.0.1";
	}
}
namespace HoldMySpear.Patches
{
	public static class DropCheck
	{
		public static ManualLogSource Logger = new ManualLogSource("HoldMySpear.DropCheck");

		public static bool IsSpear(ItemData item)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Invalid comparison between Unknown and I4
			return (int)item.m_shared.m_skillType == 5;
		}

		public static bool Ownership(Dictionary<string, string> customData)
		{
			string playerName = Player.m_localPlayer.GetPlayerName();
			if (customData.ContainsKey("owner"))
			{
				return customData["owner"] == playerName;
			}
			return false;
		}
	}
	[HarmonyPatch(typeof(ItemDrop), "Pickup")]
	internal static class ItemDropPickup
	{
		private static bool Prefix(ItemDrop __instance)
		{
			if (!DropCheck.IsSpear(__instance.m_itemData))
			{
				return true;
			}
			DropCheck.Logger.LogInfo((object)"Found a spear!");
			string text = "(NOT SET)";
			if (__instance.m_itemData.m_customData.ContainsKey("owner"))
			{
				text = __instance.m_itemData.m_customData["owner"];
			}
			DropCheck.Logger.LogInfo((object)("(Pre) Spear owned by " + text));
			string playerName = Player.m_localPlayer.GetPlayerName();
			if (__instance.m_itemData.m_customData.ContainsKey("owner") && __instance.m_itemData.m_customData["owner"] != playerName)
			{
				return false;
			}
			__instance.m_itemData.m_customData["owner"] = playerName;
			text = __instance.m_itemData.m_customData["owner"];
			DropCheck.Logger.LogInfo((object)("Spear owned by " + text));
			return true;
		}
	}
	internal static class Utility
	{
		public static bool Addable(ItemData item)
		{
			bool flag = false;
			if (item == null || !(flag = DropCheck.IsSpear(item)))
			{
				return true;
			}
			if (!item.m_customData.ContainsKey("owner") && flag)
			{
				item.m_customData["owner"] = Player.m_localPlayer.GetPlayerName();
			}
			return DropCheck.Ownership(item.m_customData);
		}
	}
	[HarmonyPatch(typeof(Inventory), "CanAddItem", new Type[]
	{
		typeof(ItemData),
		typeof(int)
	})]
	internal static class ItemDropAddable
	{
		private static bool Prefix(Inventory __instance, ItemData item, int stack = -1)
		{
			return Utility.Addable(item);
		}
	}
	[HarmonyPatch(typeof(Inventory), "AddItem", new Type[] { typeof(ItemData) })]
	internal static class ItemDropAdd
	{
		private static bool Prefix(Inventory __instance, ItemData item)
		{
			return Utility.Addable(item);
		}
	}
}