Decompiled source of ReservedJsonSlots v1.0.1

BepInEx/plugins/JsonReservedSlots.dll

Decompiled 2 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using JsonReservedSlots.JsonTypes;
using Microsoft.CodeAnalysis;
using Newtonsoft.Json;
using ReservedItemSlotCore.Data;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("JsonReservedSlots")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("JsonReservedSlots")]
[assembly: AssemblyTitle("JsonReservedSlots")]
[assembly: AssemblyVersion("1.0.0.0")]
[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.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;
		}
	}
	[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 JsonReservedSlots
{
	[BepInPlugin("JacobG5.JsonReservedSlots", "JsonReservedSlots", "1.0.1")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class JsonReservedSlotsCore : BaseUnityPlugin
	{
		private const string modGUID = "JacobG5.JsonReservedSlots";

		private const string modName = "JsonReservedSlots";

		private const string modVersion = "1.0.1";

		private readonly Harmony harmony = new Harmony("JacobG5.JsonReservedSlots");

		public static JsonReservedSlotsCore Instance;

		public ManualLogSource mls;

		public static ConfigEntry<bool> createDefaults;

		public readonly string JsonReservedSlotsPath = Paths.ConfigPath + "\\JsonReservedSlots";

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			mls = Logger.CreateLogSource("JacobG5.JsonReservedSlots");
			mls.LogInfo((object)JsonReservedSlotsPath);
			createDefaults = ((BaseUnityPlugin)this).Config.Bind<bool>("Core", "CreateDefaults", true, "Creates an example reserved slot json for Belt bags when directory doesn't exist.");
			if (!Directory.Exists(JsonReservedSlotsPath))
			{
				mls.LogInfo((object)"Generating Defaults.");
				CreateDefaultJsonSlots();
			}
			mls.LogInfo((object)"Reading Json Files...");
			ReadJsonSlots();
		}

		public void CreateDefaultJsonSlots()
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Expected I4, but got Unknown
			Directory.CreateDirectory(JsonReservedSlotsPath);
			string text = "";
			foreach (PlayerBone value in Enum.GetValues(typeof(PlayerBone)))
			{
				text += $"{(object)value}: {(int)value}\n";
			}
			File.WriteAllText(JsonReservedSlotsPath + "\\PlayerBones.txt", text);
			if (createDefaults.Value)
			{
				ReservedSlotInfo reservedSlotInfo = new ReservedSlotInfo();
				reservedSlotInfo.reservedSlotName = "utility_belt";
				reservedSlotInfo.slotPriority = 50;
				reservedSlotInfo.purchasePrice = 150;
				reservedSlotInfo.itemsForSlot = new ReservedItemInfo[1]
				{
					new ReservedItemInfo
					{
						itemName = "Belt bag"
					}
				};
				ReservedSlotInfo reservedSlotInfo2 = reservedSlotInfo;
				string contents = JsonConvert.SerializeObject((object)reservedSlotInfo2, (Formatting)1);
				File.WriteAllText(JsonReservedSlotsPath + "\\UtilityBeltSlot.json", contents);
			}
		}

		public void ReadJsonSlots()
		{
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Invalid comparison between Unknown and I4
			//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01be: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e1: Expected O, but got Unknown
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: Expected O, but got Unknown
			List<ReservedSlotInfo> list = new List<ReservedSlotInfo>();
			try
			{
				string[] files = Directory.GetFiles(JsonReservedSlotsPath);
				foreach (string text in files)
				{
					mls.LogInfo((object)(text ?? ""));
					if (text.EndsWith(".json"))
					{
						ReservedSlotInfo reservedSlotInfo = JsonConvert.DeserializeObject<ReservedSlotInfo>(File.ReadAllText(text));
						if (reservedSlotInfo != null)
						{
							list.Add(reservedSlotInfo);
						}
						else
						{
							mls.LogInfo((object)(Path.GetFileName(text) + " could not be parsed!"));
						}
					}
				}
			}
			catch (Exception arg)
			{
				mls.LogWarning((object)$"Something went wrong reading JSON files!\n{arg}");
			}
			foreach (ReservedSlotInfo item in list)
			{
				ReservedItemSlotData val = ReservedItemSlotData.CreateReservedItemSlotData(item.reservedSlotName, item.slotPriority, item.purchasePrice);
				mls.LogInfo((object)$"{item.itemsForSlot.Length}");
				for (int j = 0; j < item.itemsForSlot.Length; j++)
				{
					mls.LogInfo((object)$"{item.itemsForSlot[j].bone}");
					if ((int)item.itemsForSlot[j].bone == 0)
					{
						val.AddItemToReservedItemSlot(new ReservedItemData(item.itemsForSlot[j].itemName, (PlayerBone)0, default(Vector3), default(Vector3)));
					}
					else
					{
						val.AddItemToReservedItemSlot(new ReservedItemData(item.itemsForSlot[j].itemName, item.itemsForSlot[j].bone, item.itemsForSlot[j].position.GetUnityVector(), item.itemsForSlot[j].rotation.GetUnityVector()));
					}
				}
			}
		}
	}
}
namespace JsonReservedSlots.JsonTypes
{
	public class ReservedSlotInfo
	{
		public string reservedSlotName;

		public int slotPriority = 500;

		public int purchasePrice = 120;

		public ReservedItemInfo[] itemsForSlot;
	}
	public class ReservedItemInfo
	{
		public string itemName;

		public PlayerBone bone = (PlayerBone)0;

		public ReservedVector position = new ReservedVector();

		public ReservedVector rotation = new ReservedVector();
	}
	public class ReservedVector
	{
		public float x = 0f;

		public float y = 0f;

		public float z = 0f;

		public Vector3 GetUnityVector()
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			return new Vector3(x, y, z);
		}
	}
}