Decompiled source of Bag Plus v1.0.0

plugins/Bag+/Bag+.dll

Decompiled 8 months ago
using System;
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.Configuration;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("BagSlot")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("BagSlot")]
[assembly: AssemblyCopyright("Copyright ©  2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("70034b0d-05ea-41e6-a276-46bca3101217")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace UltimateBag;

internal sealed class ConfigurationManagerAttributes
{
	public bool? ShowRangeAsPercent;

	public Action<ConfigEntryBase> CustomDrawer;

	public bool? Browsable;

	public string Category;

	public object DefaultValue;

	public bool? HideDefaultButton;

	public bool? HideSettingName;

	public string Description;

	public string DispName;

	public int? Order;

	public bool? ReadOnly;

	public bool? IsAdvanced;

	public Func<object, string> ObjToStr;

	public Func<string, object> StrToObj;
}
[HarmonyPatch]
[BepInPlugin("com.ness.UltimateBag", "Bag+", "1.0")]
public class UltimateBag : BaseUnityPlugin
{
	private const string ID = "com.ness.UltimateBag";

	private const string NAME = "Bag+";

	private const string VERSION = "1.0";

	public static ConfigEntry<string> PositionSlot1;

	public static ConfigEntry<string> PositionSlot2;

	public static ConfigEntry<bool> EnableSlot1;

	public static ConfigEntry<bool> EnableSlot2;

	public static ConfigEntry<bool> AddBoltBool;

	public static ConfigEntry<string> BoltColor;

	public static ConfigEntry<bool> AddSpiralBool;

	public static ConfigEntry<string> SpiralColor;

	public static ConfigEntry<bool> AddLanternBool;

	public static ConfigEntry<string> BagPrefabName;

	public static ConfigEntry<int> VisualSlot1;

	public static ConfigEntry<int> VisualSlot2;

	public static ConfigEntry<bool> EnableShield;

	public static ConfigEntry<int> ShieldVisual;

	public static AcceptableValueList<string> CurrentBag;

	public static ConfigEntry<bool> isStaffS1;

	public static ConfigEntry<bool> isStaffS2;

	public static ConfigEntry<bool> isSpearS1;

	public static ConfigEntry<bool> isSpearS2;

	public static ConfigEntry<bool> isBowS1;

	public static ConfigEntry<bool> isBowS2;

	public static ConfigEntry<bool> isSwordS1;

	public static ConfigEntry<bool> isSwordS2;

	public static ConfigEntry<bool> isHalberdS1;

	public static UltimateBag Instance { get; private set; }

	internal void Awake()
	{
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f9: Expected O, but got Unknown
		//IL_01be: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c8: Expected O, but got Unknown
		//IL_028d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0297: Expected O, but got Unknown
		//IL_036a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0374: Expected O, but got Unknown
		//IL_0403: Unknown result type (might be due to invalid IL or missing references)
		//IL_040d: Expected O, but got Unknown
		Instance = this;
		new Harmony("com.ness.UltimateBag").PatchAll();
		((BaseUnityPlugin)this).Logger.LogMessage((object)"Bag+ is awake");
		Update();
		BagPrefabName = ((BaseUnityPlugin)this).Config.Bind<string>("1.GENERAL", "Bag Visual", "5300120_PrimitiveSatchelBackpack_v", new ConfigDescription("Apply visual on the selected bag", (AcceptableValueBase)(object)new AcceptableValueList<string>(new string[18]
		{
			"5300000_AdventurerBackpack_v", "5300140_TraderFrameBackpack_v", "5300130_StrongBoxBackpack_v", "5300030_MasterTraderBackpack_v", "5300180_HornBackpack_v", "5300170_MageBackpack_v", "5380003_WeaverBackpack_v", "5300160_PreservationBackpack_v", "5300110_NomadBackpack_v", "5300041_ProspectorBackpackElite_v",
			"5300190_BoozuBackpack_v", "5300070_Wolfcase_v", "5300040_ProspectorBackpack_v", "5380002_ChalecedonyBackpack_v", "5380005_BrigandBackpack_v", "5300050_GlowstoneBackpack_v", "5380001_ChargedStoneBackpack_v", "5300120_PrimitiveSatchelBackpack_v"
		}), Array.Empty<object>()));
		EnableSlot1 = ((BaseUnityPlugin)this).Config.Bind<bool>("2. WEAPON SLOT 1", "Enable Weapon Slot 1", true, "Add a weapon on your bag");
		VisualSlot1 = ((BaseUnityPlugin)this).Config.Bind<int>("2. WEAPON SLOT 1", "Weapon ID", 2200000, "ItemID of the weapon you want to attach");
		PositionSlot1 = ((BaseUnityPlugin)this).Config.Bind<string>("2. WEAPON SLOT 1", "Weapon Type", "Sword", new ConfigDescription("Choose the type of weapon select in Slot1. Required for positionning.", (AcceptableValueBase)(object)new AcceptableValueList<string>(new string[10] { "Bow", "Spear", "Staff", "Axe(One Handed)", "Axe(Two Handed)", "Halberd", "Sword(One Handed)", "Sword(Two Handed)", "Mace(One Handed)", "Mace(Two Handed)" }), Array.Empty<object>()));
		EnableSlot2 = ((BaseUnityPlugin)this).Config.Bind<bool>("3. WEAPON SLOT 2", "Enable Weapon Slot 2", true, "Add a weapon on your bag");
		VisualSlot2 = ((BaseUnityPlugin)this).Config.Bind<int>("3. WEAPON SLOT 2", "Weapon ID", 2100999, "ItemID of the weapon you want to attach");
		PositionSlot2 = ((BaseUnityPlugin)this).Config.Bind<string>("3. WEAPON SLOT 2", "Weapon Type", "Sword", new ConfigDescription("Choose the type of weapon select in Slot1. Required for positionning.", (AcceptableValueBase)(object)new AcceptableValueList<string>(new string[10] { "Bow", "Spear", "Staff", "Axe(One Handed)", "Axe(Two Handed)", "Halberd", "Sword(One Handed)", "Sword(Two Handed)", "Mace(One Handed)", "Mace(Two Handed)" }), Array.Empty<object>()));
		EnableShield = ((BaseUnityPlugin)this).Config.Bind<bool>("4. SHIELD", "Enable Shield", false, "Replace the backpack by a shield");
		ShieldVisual = ((BaseUnityPlugin)this).Config.Bind<int>("4. SHIELD", "Shield ID", 2300050, "ItemID of the shield you want to attach");
		AddBoltBool = ((BaseUnityPlugin)this).Config.Bind<bool>("5.EFFECT", "Add Bolt Effect", true, "Add a bolt effect on your bag");
		BoltColor = ((BaseUnityPlugin)this).Config.Bind<string>("5.EFFECT", "Color Bolt Effect", "yellow", new ConfigDescription("Choose color of bolt effect on your bag", (AcceptableValueBase)(object)new AcceptableValueList<string>(new string[8] { "blue", "cyan", "gray", "green", "magenta", "red", "white", "yellow" }), Array.Empty<object>()));
		AddSpiralBool = ((BaseUnityPlugin)this).Config.Bind<bool>("6.EFFECT", "Add Spiral Effect", true, "Add a spiral effect on your bag");
		SpiralColor = ((BaseUnityPlugin)this).Config.Bind<string>("6.EFFECT", "Color Spiral Effect", "yellow", new ConfigDescription("Choose color of spiral effect on your bag", (AcceptableValueBase)(object)new AcceptableValueList<string>(new string[8] { "blue", "cyan", "gray", "green", "magenta", "red", "white", "yellow" }), Array.Empty<object>()));
		AddLanternBool = ((BaseUnityPlugin)this).Config.Bind<bool>("7.LANTERN", "Add Lantern", true, "Add a bolt effect on your bag");
	}

	private void Update()
	{
	}

	private static void ProcessVisualsExtend(Bag bag)
	{
		//IL_0831: Unknown result type (might be due to invalid IL or missing references)
		//IL_0832: Unknown result type (might be due to invalid IL or missing references)
		//IL_0857: Unknown result type (might be due to invalid IL or missing references)
		//IL_0858: Unknown result type (might be due to invalid IL or missing references)
		//IL_08b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_08b6: Unknown result type (might be due to invalid IL or missing references)
		if (!(((Item)bag).m_visualPrefabName == BagPrefabName.Value))
		{
			return;
		}
		Vector3 pos = default(Vector3);
		((Vector3)(ref pos))..ctor(-0.2101f, -0.0955f, -0.68f);
		Vector3 rot = default(Vector3);
		((Vector3)(ref rot))..ctor(1.0208f, 290.0177f, 179.9582f);
		Vector3 pos2 = default(Vector3);
		((Vector3)(ref pos2))..ctor(0.3f, -0.005f, -0.6f);
		Vector3 rot2 = default(Vector3);
		((Vector3)(ref rot2))..ctor(357.5089f, 61.8f, 2.906f);
		string value = PositionSlot1.Value;
		string value2 = PositionSlot2.Value;
		switch (value)
		{
		case "Staff":
			((Vector3)(ref pos))..ctor(-0.2101f, -0.0355f, -0.68f);
			((Vector3)(ref rot))..ctor(1.0208f, 290.0177f, 179.9582f);
			break;
		case "Bow":
			if (BagPrefabName.Value == "5380005_BrigandBackpack_v")
			{
				((Vector3)(ref pos))..ctor(-0.14f, 0.14f, 0f);
				((Vector3)(ref rot))..ctor(61.4246f, 141.3963f, 11.9091f);
			}
			else
			{
				((Vector3)(ref pos))..ctor(0.04f, -0.04f, -0.14f);
				((Vector3)(ref rot))..ctor(356.3531f, 290.784f, 353.7287f);
			}
			break;
		case "Spear":
			((Vector3)(ref pos))..ctor(-0.2901f, -0.0555f, -1f);
			((Vector3)(ref rot))..ctor(1.0208f, 290.0177f, 179.9582f);
			break;
		case "Axe(One Handed)":
			((Vector3)(ref pos))..ctor(-0.02f, 0f, -0.4f);
			((Vector3)(ref rot))..ctor(5.2877f, 293.8563f, 175.003f);
			break;
		case "Axe(Two Handed)":
			((Vector3)(ref pos))..ctor(0.22f, -0.095f, 0.24f);
			((Vector3)(ref rot))..ctor(2.8408f, 122.3997f, 188.2476f);
			break;
		case "Halberd":
			((Vector3)(ref pos))..ctor(0.24f, -0.09f, 0.48f);
			((Vector3)(ref rot))..ctor(351.9301f, 292.5178f, 356.499f);
			break;
		case "Sword(One Handed)":
			((Vector3)(ref pos))..ctor(-0.2413f, -0.031f, 0.2394f);
			((Vector3)(ref rot))..ctor(2.8648f, 59.127f, 179.9836f);
			break;
		case "Sword(Two Handed)":
			((Vector3)(ref pos))..ctor(0.24f, -0.09f, 0.48f);
			((Vector3)(ref rot))..ctor(351.9301f, 292.5178f, 356.499f);
			break;
		case "Mace(One Handed)":
			((Vector3)(ref pos))..ctor(-0.02f, 0f, -0.4f);
			((Vector3)(ref rot))..ctor(5.2877f, 293.8563f, 175.003f);
			break;
		case "Mace(Two Handed)":
			((Vector3)(ref pos))..ctor(-0.2101f, -0.0355f, -0.68f);
			((Vector3)(ref rot))..ctor(1.0208f, 290.0177f, 179.9582f);
			break;
		}
		switch (value2)
		{
		case "Staff":
			((Vector3)(ref pos2))..ctor(0.3f, -0.005f, -0.6f);
			((Vector3)(ref rot2))..ctor(357.5089f, 61.8f, 2.906f);
			break;
		case "Bow":
			((Vector3)(ref pos2))..ctor(-0.04f, -0.04f, -0.12f);
			((Vector3)(ref rot2))..ctor(2.734f, 64.5905f, 180.2475f);
			break;
		case "Spear":
			((Vector3)(ref pos2))..ctor(0.34f, -0.035f, -1.02f);
			((Vector3)(ref rot2))..ctor(2.5851f, 250.0005f, 179.022f);
			break;
		case "Axe(One Handed)":
			((Vector3)(ref pos2))..ctor(0.1f, 0f, -0.4f);
			((Vector3)(ref rot2))..ctor(358.5891f, 69.23f, 2.7964f);
			break;
		case "Axe(Two Handed)":
			((Vector3)(ref pos2))..ctor(-0.2f, 0.02f, 0.23f);
			((Vector3)(ref rot2))..ctor(347.9792f, 231.782f, 6.1241f);
			break;
		case "Halberd":
			((Vector3)(ref pos2))..ctor(-0.26f, -0.07f, 0.51f);
			((Vector3)(ref rot2))..ctor(8.9016f, 63.8621f, 181.4015f);
			break;
		case "Sword(One Handed)":
			((Vector3)(ref pos2))..ctor(0.28f, -0.08f, 0.24f);
			((Vector3)(ref rot2))..ctor(359.7222f, 120.5592f, 184.8041f);
			break;
		case "Sword(Two Handed)":
			((Vector3)(ref pos2))..ctor(-0.28f, -0.035f, 0.48f);
			((Vector3)(ref rot2))..ctor(2.734f, 64.5905f, 180.2475f);
			break;
		case "Mace(One Handed)":
			((Vector3)(ref pos2))..ctor(0.1f, 0f, -0.4f);
			((Vector3)(ref rot2))..ctor(358.5891f, 69.23f, 2.7964f);
			break;
		case "Mace(Two Handed)":
			((Vector3)(ref pos2))..ctor(0.3f, -0.005f, -0.6f);
			((Vector3)(ref rot2))..ctor(357.5089f, 61.8f, 2.906f);
			break;
		}
		Vector3 pos3 = default(Vector3);
		((Vector3)(ref pos3))..ctor(0.0499f, 0.025f, -0.28f);
		Vector3 rot3 = default(Vector3);
		((Vector3)(ref rot3))..ctor(333.5798f, 282.9698f, 353.0449f);
		if (AddBoltBool.Value)
		{
			AddBolt(bag, 0f, 0.2f, 0f, BoltColor.Value);
		}
		if (AddSpiralBool.Value)
		{
			AddSpiral(bag, 0f, 0.2f, 0f, SpiralColor.Value);
		}
		if (EnableSlot1.Value)
		{
			AddWeaponSlot1(bag, VerifItemID(VisualSlot1.Value, bag: false, bow: true), pos, rot);
		}
		if (EnableSlot2.Value)
		{
			AddWeaponSlot2(bag, VerifItemID(VisualSlot2.Value, bag: false, bow: false, twoh: true), pos2, rot2);
		}
		if (AddLanternBool.Value || BagPrefabName.Value == "5380005_BrigandBackpack_v")
		{
			AddLanternSlot(bag, 0.0686f, 0.1271f, -0.2781f);
		}
		if (EnableShield.Value)
		{
			AddShield(bag, VerifItemID(ShieldVisual.Value), pos3, rot3);
		}
	}

	private static void AddLanternSlot(Bag bag, float xPos, float yPos, float zPos)
	{
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		//IL_004d: Unknown result type (might be due to invalid IL or missing references)
		Transform obj = Object.Instantiate<Transform>(((Component)((Item)(Bag)ResourcesPrefabManager.ITEM_PREFABS["5300000"]).LoadedVisual).transform.Find("LanternSlotAnchor"));
		obj.parent = ((Component)((Item)bag).LoadedVisual).transform;
		bag.m_lanternSlot = ((Component)bag).GetComponentInChildren<BagSlotVisual>();
		obj.localPosition = new Vector3(xPos, yPos, zPos);
	}

	private static void AddWeaponSlot2(Bag bag, int itemID, Vector3 Pos, Vector3 Rot)
	{
		//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_0029: 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_0035: Unknown result type (might be due to invalid IL or missing references)
		GameObject obj = Object.Instantiate<GameObject>(GetVisuals(itemID));
		obj.transform.parent = ((Component)((Item)bag).LoadedVisual).transform;
		obj.transform.localPosition = Pos;
		obj.transform.localRotation = Quaternion.Euler(Rot);
	}

	private static void AddWeaponSlot1(Bag bag, int itemID, Vector3 Pos, Vector3 Rot)
	{
		//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_0029: 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_0035: Unknown result type (might be due to invalid IL or missing references)
		GameObject obj = Object.Instantiate<GameObject>(GetVisuals(itemID));
		obj.transform.parent = ((Component)((Item)bag).LoadedVisual).transform;
		obj.transform.localPosition = Pos;
		obj.transform.localRotation = Quaternion.Euler(Rot);
	}

	private static void AddShield(Bag bag, int itemID, Vector3 Pos, Vector3 Rot)
	{
		//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_0029: 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_0035: Unknown result type (might be due to invalid IL or missing references)
		GameObject obj = Object.Instantiate<GameObject>(GetVisuals(itemID));
		obj.transform.parent = ((Component)((Item)bag).LoadedVisual).transform;
		obj.transform.localPosition = Pos;
		obj.transform.localRotation = Quaternion.Euler(Rot);
		((Component)((Component)((Item)bag).LoadedVisual).transform.Find("model")).gameObject.SetActive(false);
	}

	private static void AddBolt(Bag bag, float x, float y, float z, string color = "yellow", bool hidelight = false)
	{
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_007c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0081: Unknown result type (might be due to invalid IL or missing references)
		//IL_008d: Unknown result type (might be due to invalid IL or missing references)
		//IL_009e: Unknown result type (might be due to invalid IL or missing references)
		Transform val = Object.Instantiate<Transform>(((Component)((Component)((Component)((Item)(Bag)ResourcesPrefabManager.ITEM_PREFABS["5300170"]).LoadedVisual).transform.Find("backpack")).transform.Find("_boltCrackling_Example_FX")).transform);
		val.parent = ((Component)((Item)bag).LoadedVisual).transform;
		val.localPosition = new Vector3(x, y, z);
		if (hidelight)
		{
			((Component)((Component)val).transform).GetComponentInChildren<Light>().intensity = 0f;
		}
		Color val2 = ToColor(color);
		((Component)((Component)val).transform).GetComponentInChildren<ParticleSystem>().startColor = val2;
		((Component)((Component)val).transform).GetComponentInChildren<Light>().color = val2;
		val.parent = ((Component)((Item)bag).LoadedVisual).transform;
	}

	private static void AddSpiral(Bag bag, float x, float y, float z, string color = "yellow")
	{
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_0064: Unknown result type (might be due to invalid IL or missing references)
		Transform obj = Object.Instantiate<Transform>(((Component)((Component)((Item)(Bag)ResourcesPrefabManager.ITEM_PREFABS["5300050"]).LoadedVisual).transform.Find("Particle System")).transform);
		obj.parent = ((Component)((Item)bag).LoadedVisual).transform;
		obj.localPosition = new Vector3(x, y, z);
		Color startColor = ToColor(color);
		((Component)((Component)obj).transform).GetComponentInChildren<ParticleSystem>().startColor = startColor;
		obj.parent = ((Component)((Item)bag).LoadedVisual).transform;
	}

	public static int VerifItemID(int itemid, bool bag = false, bool bow = false, bool twoh = false)
	{
		if (((Object)ResourcesPrefabManager.ITEM_PREFABS[itemid.ToString()]).name != null)
		{
			return itemid;
		}
		if (bag)
		{
			return 5300000;
		}
		if (bow)
		{
			return 2200000;
		}
		if (twoh)
		{
			return 2100999;
		}
		return 5300000;
	}

	public static Color ToColor(string color)
	{
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		return (Color)typeof(Color).GetProperty(color.ToLowerInvariant()).GetValue(null, null);
	}

	public static GameObject GetVisuals(int itemID)
	{
		string visualPrefabPath = ResourcesPrefabManager.ITEM_PREFABS[itemID.ToString()].m_visualPrefabPath;
		return ResourcesPrefabManager.Instance.m_itemVisualsBundle.LoadAsset<GameObject>(visualPrefabPath + ".prefab");
	}

	[HarmonyPatch(typeof(Bag), "BaseInit")]
	[HarmonyPrefix]
	private static void Bag_BaseInit_Pre(Bag __instance)
	{
		ProcessVisualsExtend(__instance);
	}
}