Decompiled source of TombstoneDriveBy v1.0.0

plugins\TombstoneDriveBy.dll

Decompiled 2 months ago
using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Jotunn;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("TombstoneDriveBy")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("TombstoneDriveBy")]
[assembly: AssemblyCopyright("Copyright ©  2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("e3243d22-4307-4008-ba36-9f326008cde5")]
[assembly: AssemblyFileVersion("1.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
namespace TombstoneDriveBy
{
	[BepInPlugin("sephalon.TombstoneDriveBy", "TombstoneDriveBy", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[HarmonyPatch]
	internal class TombstoneDriveBy : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(TombStone), "Interact")]
		public static class Interact_Patch
		{
			private static bool Prefix(TombStone __instance, Humanoid character, bool hold, bool alt)
			{
				Logger.LogMessage((object)"Interact_Patch");
				if (hold)
				{
					return false;
				}
				if (__instance.m_container.GetInventory().NrOfItems() == 0)
				{
					return false;
				}
				if (!__instance.m_localOpened)
				{
					Game.instance.IncrementPlayerStat((PlayerStatType)((__instance.GetOwnerName() == Game.instance.GetPlayerProfile().GetName()) ? 52 : 53), 1f);
				}
				if (__instance.IsOwner())
				{
					currentTombStone = __instance;
					__instance.m_container.TakeAll(character);
					__instance.GiveBoost();
					return false;
				}
				Logger.LogMessage((object)"Somehow not the owner");
				return false;
			}
		}

		[HarmonyPatch(typeof(TombStone), "GiveBoost")]
		public static class GiveBoost_Patch
		{
			private static void Postfix(TombStone __instance)
			{
				StatusEffect lootStatusEffect = __instance.m_lootStatusEffect;
				SE_Stats val = (SE_Stats)(object)((lootStatusEffect is SE_Stats) ? lootStatusEffect : null);
				if (val != null)
				{
					Player val2 = __instance.FindOwner();
					if (Object.op_Implicit((Object)(object)val2))
					{
						((Character)val2).m_seman.RemoveStatusEffect((StatusEffect)(object)val, true);
						StatusEffect obj = ((StatusEffect)val).Clone();
						SE_Stats val3 = (SE_Stats)(object)((obj is SE_Stats) ? obj : null);
						((Object)val3).name = "TombstoneDriveByCorpseRun";
						val3.m_addMaxCarryWeight = GetCorpseRunCarryBonus();
						((Character)val2).m_seman.AddStatusEffect((StatusEffect)(object)val3, true, 0, 0f);
					}
				}
			}
		}

		public const string PluginGUID = "sephalon.TombstoneDriveBy";

		public const string PluginName = "TombstoneDriveBy";

		public const string PluginVersion = "1.0.0";

		public const string CustomCorpseRunName = "TombstoneDriveByCorpseRun";

		public ConfigEntry<int> config_corpseRunBuffValue;

		public static TombstoneDriveBy Instance;

		public List<ItemType> typePriority;

		public static TombStone currentTombStone;

		public void Awake()
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Expected O, but got Unknown
			Instance = this;
			currentTombStone = null;
			((BaseUnityPlugin)this).Config.SaveOnConfigSet = true;
			config_corpseRunBuffValue = ((BaseUnityPlugin)this).Config.Bind<int>("Config", "CorpseRunCarryBonus", 150, new ConfigDescription("The carry weight bonus when the corpse run buff is applied", (AcceptableValueBase)null, Array.Empty<object>()));
			SetUpPriorities();
			Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "sephalon.TombstoneDriveBy");
		}

		public void SetUpPriorities()
		{
			typePriority = new List<ItemType>();
			typePriority.Add((ItemType)7);
			typePriority.Add((ItemType)11);
			typePriority.Add((ItemType)6);
			typePriority.Add((ItemType)17);
			typePriority.Add((ItemType)18);
			typePriority.Add((ItemType)5);
			typePriority.Add((ItemType)14);
			typePriority.Add((ItemType)22);
			typePriority.Add((ItemType)20);
			typePriority.Add((ItemType)3);
			typePriority.Add((ItemType)4);
			typePriority.Add((ItemType)12);
			typePriority.Add((ItemType)9);
			typePriority.Add((ItemType)23);
			typePriority.Add((ItemType)2);
			typePriority.Add((ItemType)19);
			typePriority.Add((ItemType)1);
			typePriority.Add((ItemType)10);
			typePriority.Add((ItemType)16);
			typePriority.Add((ItemType)13);
			typePriority.Add((ItemType)15);
			typePriority.Add((ItemType)21);
			typePriority.Add((ItemType)0);
		}

		public static int GetCorpseRunCarryBonus()
		{
			return Instance.config_corpseRunBuffValue.Value;
		}

		[HarmonyPatch(typeof(Inventory), "MoveAll")]
		[HarmonyPriority(500)]
		private static bool Prefix(ref Inventory __instance, ref Inventory fromInventory)
		{
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_023a: Unknown result type (might be due to invalid IL or missing references)
			//IL_023f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0244: Unknown result type (might be due to invalid IL or missing references)
			if (((Humanoid)Player.m_localPlayer).m_inventory != __instance || !fromInventory.m_name.StartsWith("Grave"))
			{
				return true;
			}
			if ((Object)(object)InventoryGui.instance.m_currentContainer != (Object)null && InventoryGui.instance.m_currentContainer.m_inventory == fromInventory)
			{
				Logger.LogMessage((object)"Takeall while container is open.");
				return true;
			}
			float num = GetPlayerMaxCarryWithoutCorpseRunBonus() + (float)GetCorpseRunCarryBonus();
			Logger.LogMessage((object)$"takeall from tombstone. Current player max carry: {num}");
			List<ItemData> list = new List<ItemData>(fromInventory.GetAllItems());
			List<ItemData> list2 = new List<ItemData>();
			foreach (ItemData item in list)
			{
				list2.Add(item);
			}
			List<ItemData> list3 = new List<ItemData>();
			foreach (ItemData item2 in list2.ToList())
			{
				if (item2.m_gridPos.y == 0)
				{
					list3.Add(item2);
					list2.Remove(item2);
				}
			}
			foreach (ItemType item3 in Instance.typePriority)
			{
				foreach (ItemData item4 in list2.ToList())
				{
					if (item4.m_shared.m_itemType == item3)
					{
						list3.Add(item4);
						list2.Remove(item4);
					}
				}
			}
			foreach (ItemData item5 in list2.ToList())
			{
				list3.Add(item5);
			}
			Inventory inventory = ((Humanoid)Player.m_localPlayer).m_inventory;
			float num2 = inventory.GetTotalWeight();
			foreach (ItemData item6 in list3)
			{
				if (num2 + item6.GetWeight(-1) > num)
				{
					if (item6.m_stack <= 1)
					{
						continue;
					}
					int num3 = (int)((num - num2) / item6.GetNonStackedWeight());
					ItemData val = item6.Clone();
					val.m_stack = num3;
					val.m_gridPos = new Vector2i(item6.m_gridPos);
					if (num3 > 0)
					{
						if (!AddItemCorrectLocation(inventory, val))
						{
							return ExitMoveAll(__instance, fromInventory);
						}
						num2 += val.GetWeight(-1);
						item6.m_stack -= num3;
					}
				}
				else
				{
					if (!AddItemCorrectLocation(inventory, item6))
					{
						return ExitMoveAll(__instance, fromInventory);
					}
					fromInventory.RemoveItem(item6);
					num2 += item6.GetWeight(-1);
				}
			}
			return ExitMoveAll(__instance, fromInventory);
		}

		public static float GetPlayerMaxCarryWithoutCorpseRunBonus()
		{
			Player localPlayer = Player.m_localPlayer;
			float num = localPlayer.GetMaxCarryWeight();
			bool flag = false;
			foreach (StatusEffect statusEffect in ((Character)localPlayer).m_seman.m_statusEffects)
			{
				if (((Object)statusEffect).name == "TombstoneDriveByCorpseRun")
				{
					flag = true;
					break;
				}
			}
			if (flag)
			{
				num -= (float)Instance.config_corpseRunBuffValue.Value;
			}
			return num;
		}

		public static bool AddItemCorrectLocation(Inventory inv, ItemData item)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			if (inv.AddItem(item, item.m_gridPos))
			{
				return true;
			}
			return inv.AddItem(item);
		}

		public static bool ExitMoveAll(Inventory playerInv, Inventory tombStoneInv)
		{
			playerInv.Changed();
			tombStoneInv.Changed();
			if (tombStoneInv.m_inventory.Count != 0 && (Object)(object)currentTombStone != (Object)null)
			{
				currentTombStone.m_localOpened = true;
				currentTombStone.m_container.Interact((Humanoid)(object)Player.m_localPlayer, false, false);
			}
			currentTombStone = null;
			return false;
		}
	}
}
namespace TombstoneDriveBy.Properties
{
	[GeneratedCode("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
	[DebuggerNonUserCode]
	[CompilerGenerated]
	internal class Resources
	{
		private static ResourceManager resourceMan;

		private static CultureInfo resourceCulture;

		[EditorBrowsable(EditorBrowsableState.Advanced)]
		internal static ResourceManager ResourceManager
		{
			get
			{
				if (resourceMan == null)
				{
					resourceMan = new ResourceManager("TombstoneDriveBy.Properties.Resources", typeof(Resources).Assembly);
				}
				return resourceMan;
			}
		}

		[EditorBrowsable(EditorBrowsableState.Advanced)]
		internal static CultureInfo Culture
		{
			get
			{
				return resourceCulture;
			}
			set
			{
				resourceCulture = value;
			}
		}

		internal Resources()
		{
		}
	}
}