Decompiled source of EnemyItemDisplays v1.1.1

plugins/EnemyItemDisplays.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HG;
using HG.Reflection;
using RoR2;
using RoR2.ContentManagement;
using SimpleJSON;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.ResourceManagement.AsyncOperations;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: OptIn]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("EnemyItemDisplays")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+40e7cded009553d63384f1a09d785d9ddceb2e02")]
[assembly: AssemblyProduct("EnemyItemDisplays")]
[assembly: AssemblyTitle("EnemyItemDisplays")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: UnverifiableCode]
namespace EnemyItemDisplays;

public class BookKeep
{
	public static int TotalAddedDisplays;

	public static int TotalPotentialDisplays;

	public static int MonstersAdded;

	private static int? totalVanillaItems;

	private static int? totalEnemies;

	public static int TotalVanillaItems => ItemDisplays.KeyAssetDisplayPrefabs.Keys.Count;

	public unsafe static int TotalEnemies
	{
		get
		{
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: 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_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: 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_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: 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)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			if (!totalEnemies.HasValue)
			{
				totalEnemies = 0;
				for (int i = 0; i < ContentManager.allLoadedContentPacks.Length; i++)
				{
					ReadOnlyContentPack val = Unsafe.Read<ReadOnlyContentPack>((void*)ContentManager.allLoadedContentPacks[i]);
					if (!(((ReadOnlyContentPack)(ref val)).identifier == "RoR2.BaseContent") && !(((ReadOnlyContentPack)(ref val)).identifier == "RoR2.DLC1"))
					{
						continue;
					}
					totalEnemies += ((ReadOnlyContentPack)(ref val)).bodyPrefabs.Length - ((ReadOnlyContentPack)(ref val)).survivorDefs.Length;
					AssetEnumerator<GameObject> enumerator = ((ReadOnlyContentPack)(ref val)).bodyPrefabs.GetEnumerator();
					try
					{
						while (enumerator.MoveNext())
						{
							GameObject current = enumerator.Current;
							Log.Message(((Object)current).name);
						}
					}
					finally
					{
						((IDisposable)enumerator).Dispose();
					}
				}
			}
			return totalVanillaItems.Value;
		}
	}

	public static void Print()
	{
		Log.Message($"Added iteme displays to {MonstersAdded} enemies. Total enemy item displays: {TotalAddedDisplays}/{TotalPotentialDisplays}");
	}
}
[BepInPlugin("com.TheTimeSweeper.EnemyItemDisplays", "EnemyItemDisplays", "1.1.0")]
public class EnemyItemDisplaysPlugin : BaseUnityPlugin
{
	public static Dictionary<string, string> IDRSFiles = new Dictionary<string, string>();

	public static ConfigEntry<bool> PrintUnused;

	public static ConfigEntry<bool> AllowStubs;

	public static PluginInfo PluginInfo;

	public const string RULES_FOLDER = "Rules";

	public const string EXPORT_FOLDER = "Export";

	private void fuck()
	{
		Awake();
		Init();
	}

	private void Awake()
	{
		Log.Init(((BaseUnityPlugin)this).Logger);
		PluginInfo = ((BaseUnityPlugin)this).Info;
		PrintUnused = ((BaseUnityPlugin)this).Config.Bind<bool>("Item Displays", "Export Unused Item Displays", false, "Exports ALL unused item displays into separate folder.\nIt exports every rule that body has and then adds the ones that are missing with dummy values. Also adds Child Locator entries for any bones not already in child locator.\nExport happens only if the body has IDRS, export happens for each body and some bodies share IDRS, so be mindful of that.");
		AllowStubs = ((BaseUnityPlugin)this).Config.Bind<bool>("Item Displays", "Allow Unused Child Locator Entries", false, "By default, the mod will skip IDRS with default values and additionalChildren entries in the .json files that do not have any IDRS entries. Enable this so that they are no longer skipped, and thus can be used for new sets.");
		string path = Path.Combine(Path.GetDirectoryName(PluginInfo.Location), "Rules");
		string[] files = Directory.GetFiles(path, "*.json", SearchOption.AllDirectories);
		string[] array = files;
		foreach (string text in array)
		{
			IDRSFiles.Add(Path.GetFileNameWithoutExtension(text), text);
		}
	}

	[SystemInitializer(new Type[]
	{
		typeof(BodyCatalog),
		typeof(ItemCatalog)
	})]
	private static void Init()
	{
		//IL_036a: Unknown result type (might be due to invalid IL or missing references)
		//IL_036f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0373: Unknown result type (might be due to invalid IL or missing references)
		//IL_0378: Unknown result type (might be due to invalid IL or missing references)
		//IL_037e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0383: Unknown result type (might be due to invalid IL or missing references)
		//IL_0388: Unknown result type (might be due to invalid IL or missing references)
		//IL_038d: Unknown result type (might be due to invalid IL or missing references)
		//IL_013e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0145: Expected O, but got Unknown
		//IL_0156: Unknown result type (might be due to invalid IL or missing references)
		//IL_015b: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_02fd: Unknown result type (might be due to invalid IL or missing references)
		ItemDisplays.PopulateDisplays();
		foreach (GameObject allBodyPrefab in BodyCatalog.allBodyPrefabs)
		{
			ModelLocator component = allBodyPrefab.GetComponent<ModelLocator>();
			if (!Object.op_Implicit((Object)(object)component) || !Object.op_Implicit((Object)(object)component.modelTransform))
			{
				continue;
			}
			CharacterModel component2 = ((Component)component.modelTransform).GetComponent<CharacterModel>();
			if (!Object.op_Implicit((Object)(object)component2))
			{
				continue;
			}
			ItemDisplayRuleSet itemDisplayRuleSet = component2.itemDisplayRuleSet;
			if (!Object.op_Implicit((Object)(object)itemDisplayRuleSet))
			{
				continue;
			}
			SimpleJsonExtensions.AdditionalChild[] array = Array.Empty<SimpleJsonExtensions.AdditionalChild>();
			List<string> list = new List<string>();
			if (IDRSFiles.TryGetValue(((Object)allBodyPrefab).name, out var value))
			{
				if (!File.Exists(value))
				{
					continue;
				}
				Log.Debug("Getting all text for " + ((Object)allBodyPrefab).name + " at " + value);
				JSONNode val = JSON.Parse(File.ReadAllText(value));
				ChildLocator component3 = ((Component)component2).GetComponent<ChildLocator>();
				if (!Object.op_Implicit((Object)(object)component3))
				{
					continue;
				}
				foreach (JSONNode item in val["keyAssetRules"].AsArray)
				{
					JSONNode val2 = item;
					KeyAssetRuleGroup karg = val2.AsArray.DeserializeKARG();
					if (!((object)(KeyAssetRuleGroup)(ref karg)).Equals((object?)null))
					{
						if (itemDisplayRuleSet.keyAssetRuleGroups.Where((KeyAssetRuleGroup keyAsset) => keyAsset.keyAsset == karg.keyAsset).Any())
						{
							Log.Info($"Skipping IDR for object {karg.keyAsset} ({karg.keyAssetAddress}) for body {((Object)allBodyPrefab).name} as body's IDRS already has an entry for it.");
							continue;
						}
						AddToUsedNames(list, karg);
						ArrayUtils.ArrayAppend<KeyAssetRuleGroup>(ref itemDisplayRuleSet.keyAssetRuleGroups, ref karg);
						BookKeep.TotalAddedDisplays++;
					}
				}
				array = val["additionalChildren"].AsArray.DeserializeAdditionalChildren();
				SimpleJsonExtensions.AdditionalChild[] array2 = array;
				for (int i = 0; i < array2.Length; i++)
				{
					SimpleJsonExtensions.AdditionalChild additionalChild = array2[i];
					if ((AllowStubs.Value || list.Contains(additionalChild.Name)) && !(additionalChild.Name == "ExampeChildName") && !(additionalChild.Name == "ExampleChildName2"))
					{
						Transform val3 = ((Component)component2).transform.Find(additionalChild.Path);
						if (!Object.op_Implicit((Object)(object)val3))
						{
							Log.Warning($"Error adding ChildLocator entry: Couldn't find transform for {additionalChild.Path} on body {allBodyPrefab}.");
							continue;
						}
						ref NameTransformPair[] transformPairs = ref component3.transformPairs;
						NameTransformPair val4 = new NameTransformPair
						{
							name = additionalChild.Name,
							transform = val3
						};
						ArrayUtils.ArrayAppend<NameTransformPair>(ref transformPairs, ref val4);
					}
				}
			}
			if (PrintUnused.Value)
			{
				DirectoryInfo directoryInfo = Directory.CreateDirectory(Path.Combine(Path.GetDirectoryName(PluginInfo.Location), "Export"));
				Enumerator<ReadOnlyContentPack> enumerator3 = ContentManager.allLoadedContentPacks.GetEnumerator();
				try
				{
					while (enumerator3.MoveNext())
					{
						ReadOnlyContentPack current2 = enumerator3.Current;
						if (((ReadOnlyContentPack)(ref current2)).bodyPrefabs.Contains(allBodyPrefab))
						{
							directoryInfo = Directory.CreateDirectory(Path.Combine(directoryInfo.FullName, string.Join("_", ((ReadOnlyContentPack)(ref current2)).identifier.Split(Path.GetInvalidFileNameChars()))));
							break;
						}
					}
				}
				finally
				{
					((IDisposable)enumerator3).Dispose();
				}
				array = GenerateAdditionalChildren(component2, array);
				string contents = ItemDisplayCheck.PrintUnused((IEnumerable<KeyAssetRuleGroup>)itemDisplayRuleSet.keyAssetRuleGroups, array, ((Object)allBodyPrefab).name);
				File.WriteAllText(Path.Combine(directoryInfo.FullName, ((Object)allBodyPrefab).name + ".json"), contents);
			}
			BookKeep.TotalPotentialDisplays += BookKeep.TotalVanillaItems;
			BookKeep.MonstersAdded++;
		}
		BookKeep.Print();
	}

	private static void AddToUsedNames(List<string> usedNames, KeyAssetRuleGroup karg)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: 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)
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		if (karg.displayRuleGroup.rules == null)
		{
			return;
		}
		for (int i = 0; i < karg.displayRuleGroup.rules.Length; i++)
		{
			if (!usedNames.Contains(karg.displayRuleGroup.rules[i].childName))
			{
				usedNames.Add(karg.displayRuleGroup.rules[i].childName);
			}
		}
	}

	private static SimpleJsonExtensions.AdditionalChild[] GenerateAdditionalChildren(CharacterModel characterModel, SimpleJsonExtensions.AdditionalChild[] existingArray = null)
	{
		List<SimpleJsonExtensions.AdditionalChild> list = ((existingArray != null) ? existingArray.ToList() : new List<SimpleJsonExtensions.AdditionalChild>());
		ChildLocator component = ((Component)((Component)characterModel).transform).GetComponent<ChildLocator>();
		Transform transform = ((Component)characterModel).transform;
		Transform[] componentsInChildren = ((Component)transform).GetComponentsInChildren<Transform>();
		for (int i = 0; i < componentsInChildren.Length; i++)
		{
			string name = ((Object)componentsInChildren[i]).name;
			if (name.Contains("IK"))
			{
				continue;
			}
			if (Object.op_Implicit((Object)(object)component))
			{
				bool flag = false;
				for (int j = 0; j < component.transformPairs.Length; j++)
				{
					if ((Object)(object)component.transformPairs[j].transform == (Object)(object)componentsInChildren[i])
					{
						flag = true;
					}
				}
				if (flag)
				{
					continue;
				}
			}
			list.Add(new SimpleJsonExtensions.AdditionalChild
			{
				Name = name,
				Path = Util.BuildPrefabTransformPath(transform, componentsInChildren[i], false, false)
			});
		}
		return list.ToArray();
	}
}
internal static class ItemDisplayCheck
{
	public static List<Object> allDisplayedItems;

	private static void GatherAllItems()
	{
		//IL_0087: Unknown result type (might be due to invalid IL or missing references)
		//IL_008d: Invalid comparison between Unknown and I4
		allDisplayedItems = new List<Object>(ItemDisplays.KeyAssetDisplayPrefabs.Keys);
		allDisplayedItems.Sort(delegate(Object item1, Object item2)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			if (item1 is ItemDef && item2 is ItemDef)
			{
				ItemTier tier = ((ItemDef)((item1 is ItemDef) ? item1 : null)).tier;
				return ((Enum)(ItemTier)(ref tier)).CompareTo((object?)((ItemDef)((item2 is ItemDef) ? item2 : null)).tier);
			}
			if (item1 is ItemDef && item2 is EquipmentDef)
			{
				return 1;
			}
			return (item1 is EquipmentDef && item2 is ItemDef) ? (-1) : 0;
		});
		for (int num = allDisplayedItems.Count - 1; num >= 0; num--)
		{
			Object obj = allDisplayedItems[num];
			ItemDef val = (ItemDef)(object)((obj is ItemDef) ? obj : null);
			if (!Object.op_Implicit((Object)(object)val))
			{
				allDisplayedItems.Remove(allDisplayedItems[num]);
			}
			else if ((int)val.tier == 5)
			{
				allDisplayedItems.Remove((Object)(object)val);
			}
		}
	}

	public static string PrintUnused(ItemDisplayRuleSet itemDisplayRuleSet, SimpleJsonExtensions.AdditionalChild[] additionalChildren, string bodyName)
	{
		return PrintUnused((IEnumerable<KeyAssetRuleGroup>)itemDisplayRuleSet.keyAssetRuleGroups.ToList(), additionalChildren, bodyName);
	}

	public static string PrintUnused(IEnumerable<KeyAssetRuleGroup> ruleSet, SimpleJsonExtensions.AdditionalChild[] additionalChildren, string bodyName)
	{
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: Expected O, but got Unknown
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Expected O, but got Unknown
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Expected O, but got Unknown
		//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0101: Unknown result type (might be due to invalid IL or missing references)
		//IL_0109: Unknown result type (might be due to invalid IL or missing references)
		//IL_010b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0120: Unknown result type (might be due to invalid IL or missing references)
		//IL_0122: Unknown result type (might be due to invalid IL or missing references)
		//IL_0139: Unknown result type (might be due to invalid IL or missing references)
		//IL_0154: Unknown result type (might be due to invalid IL or missing references)
		//IL_0156: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01da: Unknown result type (might be due to invalid IL or missing references)
		//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_0225: Unknown result type (might be due to invalid IL or missing references)
		//IL_022a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0231: Unknown result type (might be due to invalid IL or missing references)
		//IL_0236: Unknown result type (might be due to invalid IL or missing references)
		//IL_023d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0242: Unknown result type (might be due to invalid IL or missing references)
		//IL_024a: Unknown result type (might be due to invalid IL or missing references)
		//IL_024f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0251: Unknown result type (might be due to invalid IL or missing references)
		//IL_027d: Unknown result type (might be due to invalid IL or missing references)
		Log.Info("generating item displays for " + bodyName);
		JSONObject val = new JSONObject();
		JSONArray val2 = new JSONArray();
		JSONArray val3 = new JSONArray();
		if (additionalChildren.Length == 0)
		{
			additionalChildren = new SimpleJsonExtensions.AdditionalChild[2]
			{
				new SimpleJsonExtensions.AdditionalChild
				{
					Name = "ExampleChildName",
					Path = "Example/Child/Path/To/Transform"
				},
				new SimpleJsonExtensions.AdditionalChild
				{
					Name = "ExampleChildName2",
					Path = "Example/Child/Path/To/Transform2"
				}
			};
		}
		SimpleJsonExtensions.AdditionalChild[] array = additionalChildren;
		foreach (SimpleJsonExtensions.AdditionalChild child in array)
		{
			((JSONNode)(object)val3).SerializeAdditionalChild(child);
		}
		((JSONNode)val)["additionalChildren"] = (JSONNode)(object)val3;
		if (allDisplayedItems == null)
		{
			GatherAllItems();
		}
		List<Object> list = new List<Object>(allDisplayedItems);
		string text = "";
		foreach (KeyAssetRuleGroup item in ruleSet)
		{
			((JSONNode)(object)val2).SerializeKARG(item);
			if (item.displayRuleGroup.rules != null && item.displayRuleGroup.rules.Length != 0)
			{
				list.Remove(item.keyAsset);
				if (string.IsNullOrEmpty(text))
				{
					text = item.displayRuleGroup.rules[0].childName;
				}
			}
		}
		foreach (Object item2 in list)
		{
			if (ItemDisplays.KeyAssetDisplayPrefabs.TryGetValue(item2, out var value))
			{
				KeyAssetRuleGroup val4 = default(KeyAssetRuleGroup);
				val4.keyAsset = item2;
				val4.displayRuleGroup = default(DisplayRuleGroup);
				KeyAssetRuleGroup ruleGroup = val4;
				ItemDisplayRule[] array2 = (ItemDisplayRule[])(object)new ItemDisplayRule[value.Count];
				for (int j = 0; j < value.Count; j++)
				{
					array2[j] = new ItemDisplayRule
					{
						childName = text,
						followerPrefab = ItemDisplays.LoadDisplay(value[j]),
						localAngles = Vector3.zero,
						localPos = Vector3.zero,
						localScale = Vector3.one,
						ruleType = (ItemDisplayRuleType)0
					};
				}
				ruleGroup.displayRuleGroup.rules = array2;
				((JSONNode)(object)val2).SerializeKARG(ruleGroup);
			}
		}
		((JSONNode)val)["keyAssetRules"] = (JSONNode)(object)val2;
		return ((object)val).ToString().Replace("\"additionalChildren\":[", "\"additionalChildren\":\n[\n").Replace("],\"keyAssetRules\":[", "\n],\n\"keyAssetRules\":[\n")
			.Replace("\"\",\"", "\"\",\n\"")
			.Replace("]]]],", "]\n]]],\n")
			.Replace("]]]]]", "]\n]]]\n]")
			.Replace("]],[", "]\n],\n[")
			.Replace("Transform\"],[\"ExampleChildName2", "Transform\"],\n[\"ExampleChildName2");
	}
}
internal static class ItemDisplays
{
	public static Dictionary<string, GameObject> itemDisplayPrefabs = new Dictionary<string, GameObject>();

	public static Dictionary<Object, List<string>> KeyAssetDisplayPrefabs = new Dictionary<Object, List<string>>();

	public static void PopulateDisplays()
	{
		PopulateDisplaysFromBody("MercBody");
	}

	private static void PopulateDisplaysFromBody(string bodyName)
	{
		GameObject obj = LegacyResourcesAPI.Load<GameObject>("Prefabs/CharacterBodies/" + bodyName);
		object obj2;
		if (obj == null)
		{
			obj2 = null;
		}
		else
		{
			ModelLocator component = obj.GetComponent<ModelLocator>();
			obj2 = ((component == null) ? null : ((Component)component.modelTransform).GetComponent<CharacterModel>()?.itemDisplayRuleSet);
		}
		ItemDisplayRuleSet val = (ItemDisplayRuleSet)obj2;
		if ((Object)(object)val == (Object)null)
		{
			Log.Error("couldn't load ItemDisplayRuleSet from " + bodyName + ". Check if name was entered correctly");
			return;
		}
		KeyAssetRuleGroup[] keyAssetRuleGroups = val.keyAssetRuleGroups;
		for (int i = 0; i < keyAssetRuleGroups.Length; i++)
		{
			ItemDisplayRule[] rules = keyAssetRuleGroups[i].displayRuleGroup.rules;
			bool flag = KeyAssetDisplayPrefabs.ContainsKey(keyAssetRuleGroups[i].keyAsset);
			for (int j = 0; j < rules.Length; j++)
			{
				GameObject followerPrefab = rules[j].followerPrefab;
				if (!Object.op_Implicit((Object)(object)followerPrefab))
				{
					continue;
				}
				string key = ((Object)followerPrefab).name?.ToLowerInvariant();
				if (!itemDisplayPrefabs.ContainsKey(key))
				{
					itemDisplayPrefabs[key] = followerPrefab;
				}
				if (!flag)
				{
					if (!KeyAssetDisplayPrefabs.ContainsKey(keyAssetRuleGroups[i].keyAsset))
					{
						KeyAssetDisplayPrefabs[keyAssetRuleGroups[i].keyAsset] = new List<string>();
					}
					KeyAssetDisplayPrefabs[keyAssetRuleGroups[i].keyAsset].Add(((Object)followerPrefab).name);
				}
			}
		}
	}

	public static GameObject LoadDisplay(string name)
	{
		if (itemDisplayPrefabs.ContainsKey(name.ToLowerInvariant()) && Object.op_Implicit((Object)(object)itemDisplayPrefabs[name.ToLowerInvariant()]))
		{
			return itemDisplayPrefabs[name.ToLowerInvariant()];
		}
		Log.Error("item display " + name + " returned null");
		return null;
	}
}
internal static class Log
{
	internal static ManualLogSource _logSource;

	internal static void Init(ManualLogSource logSource)
	{
		_logSource = logSource;
	}

	internal static void Debug(object data)
	{
		_logSource.LogDebug(data);
	}

	internal static void Error(object data)
	{
		_logSource.LogError(data);
	}

	internal static void Fatal(object data)
	{
		_logSource.LogFatal(data);
	}

	internal static void Info(object data)
	{
		_logSource.LogInfo(data);
	}

	internal static void Message(object data)
	{
		_logSource.LogMessage(data);
	}

	internal static void Warning(object data)
	{
		_logSource.LogWarning(data);
	}
}
public static class SimpleJsonExtensions
{
	public struct AdditionalChild
	{
		public string Name;

		public string Path;

		public AdditionalChild(string name, string path)
		{
			Name = name;
			Path = path;
		}
	}

	public static AdditionalChild[] DeserializeAdditionalChildren(this JSONArray node)
	{
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Expected O, but got Unknown
		List<AdditionalChild> list = new List<AdditionalChild>();
		if ((JSONNode)(object)node == (object)null)
		{
			return Array.Empty<AdditionalChild>();
		}
		foreach (JSONArray item in node)
		{
			JSONArray val = item;
			list.Add(new AdditionalChild(JSONNode.op_Implicit(((JSONNode)val)[0]), JSONNode.op_Implicit(((JSONNode)val)[1])));
		}
		return list.ToArray();
	}

	public static void SerializeAdditionalChild(this JSONNode node, AdditionalChild child)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: 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_002b: Expected O, but got Unknown
		JSONArray val = new JSONArray();
		((JSONNode)val).Add(JSONNode.op_Implicit(child.Name));
		((JSONNode)val).Add(JSONNode.op_Implicit(child.Path));
		JSONArray val2 = val;
		node.Add((JSONNode)(object)val2);
	}

	public static KeyAssetRuleGroup DeserializeKARG(this JSONArray node)
	{
		//IL_0003: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: 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)
		//IL_0037: Invalid comparison between Unknown and I4
		//IL_0017: 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_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0051: 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_0056: Invalid comparison between Unknown and I4
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_0220: Unknown result type (might be due to invalid IL or missing references)
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_0093: Unknown result type (might be due to invalid IL or missing references)
		//IL_0099: Unknown result type (might be due to invalid IL or missing references)
		//IL_009b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dd: Expected O, but got Unknown
		//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_0104: Unknown result type (might be due to invalid IL or missing references)
		//IL_0113: Unknown result type (might be due to invalid IL or missing references)
		//IL_0118: Unknown result type (might be due to invalid IL or missing references)
		//IL_0126: Unknown result type (might be due to invalid IL or missing references)
		//IL_012a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0130: Unknown result type (might be due to invalid IL or missing references)
		//IL_0214: Unknown result type (might be due to invalid IL or missing references)
		//IL_0216: Unknown result type (might be due to invalid IL or missing references)
		//IL_021b: Unknown result type (might be due to invalid IL or missing references)
		//IL_021c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0139: Unknown result type (might be due to invalid IL or missing references)
		//IL_013d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0143: Unknown result type (might be due to invalid IL or missing references)
		//IL_0168: Unknown result type (might be due to invalid IL or missing references)
		//IL_017d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0191: Unknown result type (might be due to invalid IL or missing references)
		//IL_019b: Expected O, but got Unknown
		//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_01de: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e5: 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_014e: Unknown result type (might be due to invalid IL or missing references)
		KeyAssetRuleGroup result = default(KeyAssetRuleGroup);
		if ((JSONNode)(object)node == (object)null)
		{
			return result;
		}
		string text = JSONNode.op_Implicit(((JSONNode)node)[0]);
		Object val = null;
		ItemIndex val2 = ItemCatalog.FindItemIndex(text);
		if ((int)val2 != -1)
		{
			val = (Object)(object)ItemCatalog.GetItemDef(val2);
		}
		EquipmentIndex val3 = EquipmentCatalog.FindEquipmentIndex(text);
		if ((int)val3 != -1)
		{
			val = (Object)(object)EquipmentCatalog.GetEquipmentDef(val3);
		}
		if (!Object.op_Implicit(val))
		{
			Log.Info("Couldn't create Item Display Rule for " + text + ", wasn't able to find EquipmentDef\\ItemDef");
			return default(KeyAssetRuleGroup);
		}
		result.keyAsset = val;
		DisplayRuleGroup displayRuleGroup = default(DisplayRuleGroup);
		JSONArray asArray = ((JSONNode)node)[1].AsArray;
		foreach (JSONArray item in asArray)
		{
			JSONArray val4 = item;
			Vector3 val5 = ((JSONNode)(object)((JSONNode)val4)[3].AsArray).ReadVector3();
			Vector3 val6 = ((JSONNode)(object)((JSONNode)val4)[4].AsArray).ReadVector3();
			Vector3 val7 = ((JSONNode)(object)((JSONNode)val4)[5].AsArray).ReadVector3();
			if (EnemyItemDisplaysPlugin.AllowStubs.Value || !(val5 == default(Vector3)) || !(val6 == default(Vector3)) || !(val7 == Vector3.one))
			{
				ItemDisplayRule val8 = default(ItemDisplayRule);
				val8.ruleType = (ItemDisplayRuleType)((JSONNode)val4)[0].AsInt;
				val8.followerPrefabAddress = new AssetReferenceGameObject(JSONNode.op_Implicit(((JSONNode)val4)[1]));
				val8.followerPrefab = ItemDisplays.LoadDisplay(JSONNode.op_Implicit(((JSONNode)val4)[0]));
				val8.childName = JSONNode.op_Implicit(((JSONNode)val4)[2]);
				val8.localPos = val5;
				val8.localAngles = val6;
				val8.localScale = val7;
				((DisplayRuleGroup)(ref displayRuleGroup)).AddDisplayRule(val8);
			}
		}
		result.displayRuleGroup = displayRuleGroup;
		return result;
	}

	public static void SerializeKARG(this JSONNode node, KeyAssetRuleGroup ruleGroup)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Expected O, but got Unknown
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_007b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0081: Expected O, but got Unknown
		//IL_0082: Unknown result type (might be due to invalid IL or missing references)
		//IL_0083: Unknown result type (might be due to invalid IL or missing references)
		//IL_009b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_010c: Unknown result type (might be due to invalid IL or missing references)
		//IL_010d: Unknown result type (might be due to invalid IL or missing references)
		//IL_011f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0120: Unknown result type (might be due to invalid IL or missing references)
		//IL_0125: Unknown result type (might be due to invalid IL or missing references)
		//IL_0127: Unknown result type (might be due to invalid IL or missing references)
		//IL_0140: Expected O, but got Unknown
		//IL_0146: Unknown result type (might be due to invalid IL or missing references)
		//IL_0147: 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_014e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0167: Expected O, but got Unknown
		//IL_016d: Unknown result type (might be due to invalid IL or missing references)
		//IL_016e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0173: Unknown result type (might be due to invalid IL or missing references)
		//IL_0175: Unknown result type (might be due to invalid IL or missing references)
		//IL_018e: Expected O, but got Unknown
		//IL_0196: Expected O, but got Unknown
		//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
		JSONArray val = new JSONArray();
		Object val2 = ruleGroup.keyAsset;
		if (ruleGroup.keyAsset == (Object)null && ruleGroup.keyAssetAddress != null && ((AssetReference)ruleGroup.keyAssetAddress).RuntimeKeyIsValid())
		{
			AsyncOperationHandle<Object> val3 = ((AssetReference)ruleGroup.keyAssetAddress).LoadAssetAsync<Object>();
			val2 = val3.WaitForCompletion();
			Addressables.Release<Object>(val3);
		}
		if (!(val2 == (Object)null))
		{
			((JSONNode)val).Add(JSONNode.op_Implicit(val2.name));
			JSONArray val4 = new JSONArray();
			ItemDisplayRule[] rules = ruleGroup.displayRuleGroup.rules;
			foreach (ItemDisplayRule val5 in rules)
			{
				JSONArray val6 = new JSONArray();
				((JSONNode)val6).Add(JSONNode.op_Implicit(((Object)(object)val5.followerPrefab != (Object)null) ? ((Object)val5.followerPrefab).name : ""));
				((JSONNode)val6).Add(JSONNode.op_Implicit((val5.followerPrefabAddress != null && ((AssetReference)val5.followerPrefabAddress).RuntimeKeyIsValid()) ? ((AssetReference)val5.followerPrefabAddress).AssetGUID : ""));
				((JSONNode)val6).Add(JSONNode.op_Implicit(val5.childName));
				((JSONNode)val6).Add(((JSONNode)new JSONArray()).WriteVector3(val5.localPos));
				((JSONNode)val6).Add(((JSONNode)new JSONArray()).WriteVector3(val5.localAngles));
				((JSONNode)val6).Add(((JSONNode)new JSONArray()).WriteVector3(val5.localScale));
				JSONArray val7 = val6;
				((JSONNode)val4).Add((JSONNode)(object)val7);
			}
			((JSONNode)val).Add((JSONNode)(object)val4);
			node.Add((JSONNode)(object)val);
		}
	}

	public static Vector2 ReadVector2(this JSONNode node, Vector2 aDefault)
	{
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0055: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		if (node.IsObject)
		{
			return new Vector2(node["x"].AsFloat, node["y"].AsFloat);
		}
		if (node.IsArray)
		{
			return new Vector2(node[0].AsFloat, node[1].AsFloat);
		}
		return aDefault;
	}

	public static Vector2 ReadVector2(this JSONNode node, string aXName, string aYName)
	{
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: 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)
		if (node.IsObject)
		{
			return new Vector2(node[aXName].AsFloat, node[aYName].AsFloat);
		}
		return Vector2.zero;
	}

	public static Vector2 ReadVector2(this JSONNode node)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		return node.ReadVector2(Vector2.zero);
	}

	public static JSONNode WriteVector2(this JSONNode node, Vector2 aVec, string aXName = "x", string aYName = "y")
	{
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: 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_0066: Unknown result type (might be due to invalid IL or missing references)
		if (node.IsObject)
		{
			node[aXName].AsFloat = aVec.x;
			node[aYName].AsFloat = aVec.y;
		}
		else if (node.IsArray)
		{
			((JSONArray)((node is JSONArray) ? node : null)).inline = true;
			node[0].AsFloat = aVec.x;
			node[1].AsFloat = aVec.y;
		}
		return node;
	}

	public static Vector3 ReadVector3(this JSONNode node, Vector3 aDefault)
	{
		//IL_004d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: Unknown result type (might be due to invalid IL or missing references)
		//IL_009d: 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)
		//IL_0095: Unknown result type (might be due to invalid IL or missing references)
		//IL_009a: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
		if (node.IsObject)
		{
			return new Vector3(MathF.Round(node["x"].AsFloat, 3), MathF.Round(node["y"].AsFloat, 3), MathF.Round(node["z"].AsFloat, 3));
		}
		if (node.IsArray)
		{
			return new Vector3(MathF.Round(node[0].AsFloat, 3), MathF.Round(node[1].AsFloat, 3), MathF.Round(node[2].AsFloat, 3));
		}
		return aDefault;
	}

	public static Vector3 ReadVector3(this JSONNode node, string aXName, string aYName, string aZName)
	{
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: 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_003f: Unknown result type (might be due to invalid IL or missing references)
		if (node.IsObject)
		{
			return new Vector3(node[aXName].AsFloat, node[aYName].AsFloat, node[aZName].AsFloat);
		}
		return Vector3.zero;
	}

	public static Vector3 ReadVector3(this JSONNode node)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		return node.ReadVector3(Vector3.zero);
	}

	public static JSONNode WriteVector3(this JSONNode node, Vector3 aVec, string aXName = "x", string aYName = "y", string aZName = "z")
	{
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0067: Unknown result type (might be due to invalid IL or missing references)
		//IL_007a: 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)
		if (node.IsObject)
		{
			node[aXName].AsFloat = aVec.x;
			node[aYName].AsFloat = aVec.y;
			node[aZName].AsFloat = aVec.z;
		}
		else if (node.IsArray)
		{
			((JSONArray)((node is JSONArray) ? node : null)).inline = true;
			node[0].AsFloat = aVec.x;
			node[1].AsFloat = aVec.y;
			node[2].AsFloat = aVec.z;
		}
		return node;
	}
}