Decompiled source of NH ChaosBuckler v1.0.0

plugins/NH_ChaosBuckler/NH_ChaosBuckler.dll

Decompiled 2 weeks ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Logging;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using Jotunn.Utils;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("NH_ChaosBuckler")]
[assembly: AssemblyProduct("NH Chaos Buckler")]
[assembly: AssemblyDescription("Nostalgia Heroes - Chaos Buckler (NH_ChaosBuckler): custom buckler visual, icon and Forge recipe")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace NH_ChaosBuckler;

[BepInPlugin("com.nostalgiaheroes.chaosbuckler", "NH Chaos Buckler", "1.0.0")]
[BepInDependency("com.jotunn.jotunn", "2.30.2")]
public sealed class Plugin : BaseUnityPlugin
{
	public const string PluginGUID = "com.nostalgiaheroes.chaosbuckler";

	public const string PluginName = "NH Chaos Buckler";

	public const string PluginVersion = "1.0.0";

	private const string BundleFile = "nh_chaosbuckler";

	private const string VisualAssetName = "NH_VoidforgedShield_Visual";

	private const string VisualRuntimeName = "NH_ChaosBuckler_VisualRuntime";

	private const string IconAssetName = "NH_VoidforgedShield_Icon";

	private const string IconFile = "NH_ChaosBuckler_Icon.png";

	private const string ItemName = "NH_ChaosBuckler";

	private const string BaseItem = "ShieldBronzeBuckler";

	private const string VanillaMeshPath = "attach/model (1)";

	private static readonly Vector3 VisualLocalPosition = Vector3.zero;

	private static readonly Quaternion VisualLocalRotation = Quaternion.identity;

	private static readonly Vector3 VisualLocalScale = Vector3.one;

	private static readonly Vector3 ExpectedModelLocalPos = new Vector3(0.027f, -0.022f, 0.004f);

	private static readonly Quaternion ExpectedModelLocalRot = new Quaternion(-0.67647475f, -0.16067502f, -0.6910052f, 0.19767976f);

	private static readonly Vector3 ExpectedModelLocalScale = new Vector3(0.27806982f, 0.27806982f, 0.27806997f);

	private AssetBundle bundle;

	private GameObject visualPrefab;

	private Sprite iconSprite;

	private void Awake()
	{
		//IL_0159: Unknown result type (might be due to invalid IL or missing references)
		//IL_015e: 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_0185: Unknown result type (might be due to invalid IL or missing references)
		//IL_0228: Unknown result type (might be due to invalid IL or missing references)
		//IL_022d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0249: Unknown result type (might be due to invalid IL or missing references)
		//IL_024e: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			string directoryName = Path.GetDirectoryName(typeof(Plugin).Assembly.Location);
			string text = Path.Combine(directoryName, "nh_chaosbuckler");
			if (!File.Exists(text))
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("NHCB: bundle missing: " + text));
				return;
			}
			bundle = AssetUtils.LoadAssetBundle(text);
			if (!Object.op_Implicit((Object)(object)bundle))
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("NHCB: failed to load bundle " + text));
				return;
			}
			visualPrefab = bundle.LoadAsset<GameObject>("NH_VoidforgedShield_Visual");
			if (!Object.op_Implicit((Object)(object)visualPrefab))
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("NHCB: bundle has no prefab NH_VoidforgedShield_Visual; assets: " + string.Join(", ", bundle.GetAllAssetNames())));
				return;
			}
			((Object)visualPrefab).name = "NH_ChaosBuckler_VisualRuntime";
			((BaseUnityPlugin)this).Logger.LogInfo((object)("NHCB: bundle loaded, visual prefab found: NH_VoidforgedShield_Visual (renamed in memory to " + ((Object)visualPrefab).name + ")"));
			iconSprite = bundle.LoadAsset<Sprite>("NH_VoidforgedShield_Icon");
			Rect rect;
			if (Object.op_Implicit((Object)(object)iconSprite))
			{
				ManualLogSource logger = ((BaseUnityPlugin)this).Logger;
				string[] obj = new string[6]
				{
					"NHCB: icon sprite found in bundle: ",
					((Object)iconSprite).name,
					" ",
					null,
					null,
					null
				};
				rect = iconSprite.rect;
				obj[3] = ((int)((Rect)(ref rect)).width).ToString();
				obj[4] = "x";
				rect = iconSprite.rect;
				obj[5] = ((int)((Rect)(ref rect)).height).ToString();
				logger.LogInfo((object)string.Concat(obj));
			}
			else
			{
				string text2 = Path.Combine(directoryName, "NH_ChaosBuckler_Icon.png");
				((BaseUnityPlugin)this).Logger.LogWarning((object)("NHCB: icon sprite NH_VoidforgedShield_Icon not in bundle (assets: " + string.Join(", ", bundle.GetAllAssetNames()) + "); trying file " + text2));
				if (File.Exists(text2))
				{
					iconSprite = AssetUtils.LoadSpriteFromFile(text2);
				}
				if (Object.op_Implicit((Object)(object)iconSprite))
				{
					((Object)iconSprite).name = "NH_VoidforgedShield_Icon";
					ManualLogSource logger2 = ((BaseUnityPlugin)this).Logger;
					rect = iconSprite.rect;
					string text3 = ((int)((Rect)(ref rect)).width).ToString();
					rect = iconSprite.rect;
					logger2.LogInfo((object)("NHCB: icon loaded from file " + text3 + "x" + (int)((Rect)(ref rect)).height));
				}
				else
				{
					((BaseUnityPlugin)this).Logger.LogWarning((object)"NHCB: no icon file either; will fall back to a RenderManager render");
				}
			}
			PrefabManager.OnVanillaPrefabsAvailable += RegisterItem;
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)("NHCB: Awake failed: " + ex));
		}
	}

	private void RegisterItem()
	{
		//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fb: Expected O, but got Unknown
		//IL_013a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0140: Expected O, but got Unknown
		//IL_014a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0150: Expected O, but got Unknown
		//IL_0185: Unknown result type (might be due to invalid IL or missing references)
		//IL_018b: Expected O, but got Unknown
		//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_0297: Unknown result type (might be due to invalid IL or missing references)
		//IL_029c: Unknown result type (might be due to invalid IL or missing references)
		//IL_02bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c2: Unknown result type (might be due to invalid IL or missing references)
		PrefabManager.OnVanillaPrefabsAvailable -= RegisterItem;
		CustomItem val = null;
		try
		{
			if (!Object.op_Implicit((Object)(object)PrefabManager.Instance.GetPrefab("ShieldBronzeBuckler")))
			{
				throw new InvalidOperationException("vanilla base prefab missing: ShieldBronzeBuckler");
			}
			GameObject prefab = PrefabManager.Instance.GetPrefab("NH_ChaosBuckler");
			if (Object.op_Implicit((Object)(object)prefab))
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("NHCB: GetPrefab(\"NH_ChaosBuckler\") returned '" + ((Object)prefab).name + "' (" + (((Object)(object)prefab == (Object)(object)visualPrefab) ? "our bundle visual via a stale cache entry" : "another object") + ")"));
				if ((Object)(object)prefab == (Object)(object)visualPrefab)
				{
					Cache.Clear<GameObject>();
					prefab = PrefabManager.Instance.GetPrefab("NH_ChaosBuckler");
				}
				if (Object.op_Implicit((Object)(object)prefab))
				{
					throw new InvalidOperationException("prefab name already taken: NH_ChaosBuckler -> " + ((Object)prefab).name);
				}
			}
			else
			{
				((BaseUnityPlugin)this).Logger.LogInfo((object)"NHCB: GetPrefab(\"NH_ChaosBuckler\") returned null; name is free");
			}
			ItemConfig val2 = new ItemConfig();
			val2.Name = "Chaos Buckler";
			val2.Description = "A skull-faced buckler, its cracks glowing with raw chaos.";
			val2.CraftingStation = CraftingStations.Forge;
			val2.MinStationLevel = 1;
			val2.Requirements = (RequirementConfig[])(object)new RequirementConfig[2]
			{
				new RequirementConfig("Bronze", 10, 5, true),
				new RequirementConfig("Wood", 4, 2, true)
			};
			ItemConfig val3 = val2;
			if (Object.op_Implicit((Object)(object)iconSprite))
			{
				val3.Icons = (Sprite[])(object)new Sprite[1] { iconSprite };
			}
			val = new CustomItem("NH_ChaosBuckler", "ShieldBronzeBuckler", val3);
			if (!Object.op_Implicit((Object)(object)val.ItemPrefab) || !Object.op_Implicit((Object)(object)val.ItemDrop))
			{
				throw new InvalidOperationException("failed to clone ShieldBronzeBuckler");
			}
			SwapVisual(val.ItemPrefab);
			if (!Object.op_Implicit((Object)(object)iconSprite))
			{
				Sprite val4 = RenderManager.Instance.Render(val.ItemPrefab, RenderManager.IsometricRotation);
				if (Object.op_Implicit((Object)(object)val4))
				{
					((Object)val4).name = "NH_VoidforgedShield_Icon_Rendered";
					iconSprite = val4;
					((BaseUnityPlugin)this).Logger.LogWarning((object)"NHCB: using RenderManager fallback icon");
				}
			}
			if (Object.op_Implicit((Object)(object)iconSprite))
			{
				val.ItemDrop.m_itemData.m_shared.m_icons = (Sprite[])(object)new Sprite[1] { iconSprite };
			}
			Sprite[] icons = val.ItemDrop.m_itemData.m_shared.m_icons;
			if (icons != null && icons.Length != 0 && Object.op_Implicit((Object)(object)icons[0]))
			{
				ManualLogSource logger = ((BaseUnityPlugin)this).Logger;
				string[] obj = new string[6]
				{
					"NHCB: icon set ",
					((Object)icons[0]).name,
					" ",
					null,
					null,
					null
				};
				Rect rect = icons[0].rect;
				obj[3] = ((int)((Rect)(ref rect)).width).ToString();
				obj[4] = "x";
				rect = icons[0].rect;
				obj[5] = ((int)((Rect)(ref rect)).height).ToString();
				logger.LogInfo((object)string.Concat(obj));
			}
			else
			{
				((BaseUnityPlugin)this).Logger.LogError((object)"NHCB: item has NO icon (m_icons empty)");
			}
			SharedData shared = val.ItemDrop.m_itemData.m_shared;
			((BaseUnityPlugin)this).Logger.LogInfo((object)("NHCB: stats (placeholder, cloned from ShieldBronzeBuckler): type=" + ((object)Unsafe.As<ItemType, ItemType>(ref shared.m_itemType)/*cast due to .constrained prefix*/).ToString() + " blockArmor=" + shared.m_blockPower + " (+" + shared.m_blockPowerPerLevel + "/lvl) deflection=" + shared.m_deflectionForce + " (+" + shared.m_deflectionForcePerLevel + "/lvl) parryBonus=" + shared.m_timedBlockBonus + " durability=" + shared.m_maxDurability + " (+" + shared.m_durabilityPerLevel + "/lvl) weight=" + shared.m_weight + " maxQuality=" + shared.m_maxQuality + " moveSpeed=" + shared.m_movementModifier));
			if (val.Recipe == null || (Object)(object)val.Recipe.Recipe == (Object)null)
			{
				throw new InvalidOperationException("Jotunn created no recipe for NH_ChaosBuckler");
			}
			((BaseUnityPlugin)this).Logger.LogInfo((object)("NHCB: recipe added (PLACEHOLDER forge 1: Bronze 10, Wood 4; upgrade amountPerLevel Bronze 5, Wood 2) name=" + ((Object)val.Recipe.Recipe).name));
			if (!ItemManager.Instance.AddItem(val))
			{
				throw new InvalidOperationException("ItemManager rejected NH_ChaosBuckler");
			}
			((BaseUnityPlugin)this).Logger.LogInfo((object)"NHCB: NH_ChaosBuckler registered (clone of ShieldBronzeBuckler); test with: spawn NH_ChaosBuckler");
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)("NHCB: NH_ChaosBuckler registration failed: " + ex));
			if (val != null && Object.op_Implicit((Object)(object)val.ItemPrefab))
			{
				Object.Destroy((Object)(object)val.ItemPrefab);
			}
		}
	}

	private void SwapVisual(GameObject clone)
	{
		//IL_0074: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: 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_0098: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0115: Unknown result type (might be due to invalid IL or missing references)
		//IL_011a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0228: Unknown result type (might be due to invalid IL or missing references)
		//IL_012c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0131: 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_0148: Unknown result type (might be due to invalid IL or missing references)
		//IL_0409: Unknown result type (might be due to invalid IL or missing references)
		//IL_041a: Unknown result type (might be due to invalid IL or missing references)
		//IL_042b: Unknown result type (might be due to invalid IL or missing references)
		//IL_018d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0192: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_0351: Unknown result type (might be due to invalid IL or missing references)
		//IL_0356: Unknown result type (might be due to invalid IL or missing references)
		//IL_0371: Unknown result type (might be due to invalid IL or missing references)
		//IL_0376: Unknown result type (might be due to invalid IL or missing references)
		//IL_0391: Unknown result type (might be due to invalid IL or missing references)
		//IL_0396: Unknown result type (might be due to invalid IL or missing references)
		//IL_0288: Unknown result type (might be due to invalid IL or missing references)
		//IL_028e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0295: Unknown result type (might be due to invalid IL or missing references)
		//IL_029a: Unknown result type (might be due to invalid IL or missing references)
		//IL_029f: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_02aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_0305: Unknown result type (might be due to invalid IL or missing references)
		//IL_030a: Unknown result type (might be due to invalid IL or missing references)
		//IL_06c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_06cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_06e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_06eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0704: Unknown result type (might be due to invalid IL or missing references)
		//IL_0709: Unknown result type (might be due to invalid IL or missing references)
		//IL_0504: Unknown result type (might be due to invalid IL or missing references)
		//IL_050a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0516: Unknown result type (might be due to invalid IL or missing references)
		//IL_051b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0520: Unknown result type (might be due to invalid IL or missing references)
		//IL_0525: Unknown result type (might be due to invalid IL or missing references)
		//IL_052e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0533: Unknown result type (might be due to invalid IL or missing references)
		//IL_0548: Unknown result type (might be due to invalid IL or missing references)
		//IL_054d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0568: Unknown result type (might be due to invalid IL or missing references)
		//IL_056f: Unknown result type (might be due to invalid IL or missing references)
		LogHierarchy(clone.transform, clone.transform);
		Transform val = clone.transform.Find("attach");
		if (!Object.op_Implicit((Object)(object)val))
		{
			throw new InvalidOperationException("clone has no 'attach' child");
		}
		if (Object.op_Implicit((Object)(object)clone.transform.Find("attach_back")))
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)"NHCB: clone has an 'attach_back' child; the custom visual is only installed under 'attach'");
		}
		ManualLogSource logger = ((BaseUnityPlugin)this).Logger;
		string[] obj = new string[7] { "NHCB: attach localPos=", null, null, null, null, null, null };
		Vector3 val2 = val.localPosition;
		obj[1] = ((Vector3)(ref val2)).ToString("F4");
		obj[2] = " localRot=";
		Quaternion val3 = val.localRotation;
		obj[3] = ((Quaternion)(ref val3)).ToString("F5");
		obj[4] = " localScale=";
		val2 = val.localScale;
		obj[5] = ((Vector3)(ref val2)).ToString("F4");
		obj[6] = " (game data: pos (-0.0100, -0.0410, 0.0410) rot (0.94764, 0.27949, -0.15388, -0.01334); reset by the game when equipped)";
		logger.LogInfo((object)string.Concat(obj));
		Transform val4 = clone.transform.Find("attach/model (1)");
		MeshRenderer[] array;
		if (Object.op_Implicit((Object)(object)val4) && Object.op_Implicit((Object)(object)((Component)val4).GetComponent<MeshRenderer>()))
		{
			array = (MeshRenderer[])(object)new MeshRenderer[1] { ((Component)val4).GetComponent<MeshRenderer>() };
			if (Vector3.Distance(val4.localPosition, ExpectedModelLocalPos) < 0.001f && Quaternion.Angle(val4.localRotation, ExpectedModelLocalRot) < 0.5f && Vector3.Distance(val4.localScale, ExpectedModelLocalScale) < 0.001f)
			{
				((BaseUnityPlugin)this).Logger.LogInfo((object)"NHCB: attach/model (1) transform matches the game data the shield mesh was fitted to");
			}
			else
			{
				ManualLogSource logger2 = ((BaseUnityPlugin)this).Logger;
				string[] obj2 = new string[7] { "NHCB: attach/model (1) transform differs from the fitted game data (expected pos ", null, null, null, null, null, null };
				val2 = ExpectedModelLocalPos;
				obj2[1] = ((Vector3)(ref val2)).ToString("F4");
				obj2[2] = " rot ";
				val3 = ExpectedModelLocalRot;
				obj2[3] = ((Quaternion)(ref val3)).ToString("F5");
				obj2[4] = " scale ";
				val2 = ExpectedModelLocalScale;
				obj2[5] = ((Vector3)(ref val2)).ToString("F5");
				obj2[6] = "); check the arm placement in game";
				logger2.LogWarning((object)string.Concat(obj2));
			}
		}
		else
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)"NHCB: attach/model (1) not found or has no MeshRenderer; hiding every MeshRenderer under attach instead");
			array = ((Component)val).GetComponentsInChildren<MeshRenderer>(true);
		}
		if (array.Length == 0)
		{
			throw new InvalidOperationException("no vanilla MeshRenderer under attach");
		}
		int layer = ((Component)array[0]).gameObject.layer;
		Bounds val5 = default(Bounds);
		bool flag = false;
		MeshRenderer[] array2 = array;
		foreach (MeshRenderer val6 in array2)
		{
			((Renderer)val6).enabled = false;
			Transform transform = ((Component)val6).transform;
			MeshFilter component = ((Component)val6).GetComponent<MeshFilter>();
			string text = "";
			if (Object.op_Implicit((Object)(object)component) && Object.op_Implicit((Object)(object)component.sharedMesh))
			{
				Bounds val7 = ToSpace(component.sharedMesh.bounds, val.worldToLocalMatrix * transform.localToWorldMatrix);
				if (!flag)
				{
					val5 = val7;
					flag = true;
				}
				else
				{
					((Bounds)(ref val5)).Encapsulate(val7);
				}
				string[] obj3 = new string[6]
				{
					" mesh=",
					((Object)component.sharedMesh).name,
					" boundsInAttach center=",
					null,
					null,
					null
				};
				val2 = ((Bounds)(ref val7)).center;
				obj3[3] = ((Vector3)(ref val2)).ToString("F4");
				obj3[4] = " size=";
				val2 = ((Bounds)(ref val7)).size;
				obj3[5] = ((Vector3)(ref val2)).ToString("F4");
				text = string.Concat(obj3);
			}
			ManualLogSource logger3 = ((BaseUnityPlugin)this).Logger;
			string[] obj4 = new string[11]
			{
				"NHCB: vanilla renderer hidden: ",
				GetPath(transform, clone.transform),
				" localPos=",
				null,
				null,
				null,
				null,
				null,
				null,
				null,
				null
			};
			val2 = transform.localPosition;
			obj4[3] = ((Vector3)(ref val2)).ToString("F4");
			obj4[4] = " localRot=";
			val3 = transform.localRotation;
			obj4[5] = ((Quaternion)(ref val3)).ToString("F5");
			obj4[6] = " localScale=";
			val2 = transform.localScale;
			obj4[7] = ((Vector3)(ref val2)).ToString("F5");
			obj4[8] = " layer=";
			obj4[9] = ((Component)transform).gameObject.layer.ToString();
			obj4[10] = text;
			logger3.LogInfo((object)string.Concat(obj4));
		}
		GameObject val8 = Object.Instantiate<GameObject>(visualPrefab, val, false);
		((Object)val8).name = "NH_ChaosBuckler_VisualRuntime";
		val8.transform.localPosition = VisualLocalPosition;
		val8.transform.localRotation = VisualLocalRotation;
		val8.transform.localScale = VisualLocalScale;
		int num = 0;
		Collider[] componentsInChildren = val8.GetComponentsInChildren<Collider>(true);
		foreach (Collider val9 in componentsInChildren)
		{
			Object.DestroyImmediate((Object)(object)val9);
			num++;
		}
		Transform[] componentsInChildren2 = val8.GetComponentsInChildren<Transform>(true);
		foreach (Transform val10 in componentsInChildren2)
		{
			((Component)val10).gameObject.layer = layer;
		}
		MeshRenderer[] componentsInChildren3 = val8.GetComponentsInChildren<MeshRenderer>(true);
		foreach (MeshRenderer val11 in componentsInChildren3)
		{
			MeshFilter component2 = ((Component)val11).GetComponent<MeshFilter>();
			Mesh val12 = (Object.op_Implicit((Object)(object)component2) ? component2.sharedMesh : null);
			Material sharedMaterial = ((Renderer)val11).sharedMaterial;
			Shader val13 = (Object.op_Implicit((Object)(object)sharedMaterial) ? sharedMaterial.shader : null);
			string text2 = "";
			if (Object.op_Implicit((Object)(object)val12))
			{
				Bounds val14 = ToSpace(val12.bounds, val.worldToLocalMatrix * ((Component)val11).transform.localToWorldMatrix);
				val2 = ((Bounds)(ref val14)).center;
				string text3 = ((Vector3)(ref val2)).ToString("F4");
				val2 = ((Bounds)(ref val14)).size;
				text2 = " boundsInAttach center=" + text3 + " size=" + ((Vector3)(ref val2)).ToString("F4");
				if (flag)
				{
					float num2 = Vector3.Distance(((Bounds)(ref val14)).center, ((Bounds)(ref val5)).center);
					text2 = text2 + " centerOffsetFromVanilla=" + num2.ToString("F4") + "m";
					if (num2 > 0.08f)
					{
						((BaseUnityPlugin)this).Logger.LogWarning((object)("NHCB: custom visual center is " + num2.ToString("F3") + " m from the vanilla buckler center; check arm placement"));
					}
				}
			}
			((BaseUnityPlugin)this).Logger.LogInfo((object)("NHCB: visual renderer " + ((Object)val11).name + " mesh=" + (Object.op_Implicit((Object)(object)val12) ? (((Object)val12).name + " verts=" + val12.vertexCount) : "<null>") + text2 + " material=" + (Object.op_Implicit((Object)(object)sharedMaterial) ? ((Object)sharedMaterial).name : "<null>") + " shader=" + (Object.op_Implicit((Object)(object)val13) ? ((Object)val13).name : "<null>") + " supported=" + (Object.op_Implicit((Object)(object)val13) && val13.isSupported)));
		}
		ManualLogSource logger4 = ((BaseUnityPlugin)this).Logger;
		string[] obj5 = new string[10] { "NHCB: visual installed under attach at pos ", null, null, null, null, null, null, null, null, null };
		val2 = VisualLocalPosition;
		obj5[1] = ((Vector3)(ref val2)).ToString("F4");
		obj5[2] = " rot ";
		val3 = VisualLocalRotation;
		obj5[3] = ((Quaternion)(ref val3)).ToString("F5");
		obj5[4] = " scale ";
		val2 = VisualLocalScale;
		obj5[5] = ((Vector3)(ref val2)).ToString("F3");
		obj5[6] = "; colliders removed from visual=";
		obj5[7] = num.ToString();
		obj5[8] = "; layer=";
		obj5[9] = layer.ToString();
		logger4.LogInfo((object)string.Concat(obj5));
	}

	private void LogHierarchy(Transform t, Transform root)
	{
		//IL_0083: Unknown result type (might be due to invalid IL or missing references)
		//IL_0088: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_0131: Unknown result type (might be due to invalid IL or missing references)
		//IL_0138: Expected O, but got Unknown
		StringBuilder stringBuilder = new StringBuilder();
		Component[] components = ((Component)t).GetComponents<Component>();
		foreach (Component val in components)
		{
			if (Object.op_Implicit((Object)(object)val) && !(val is Transform))
			{
				stringBuilder.Append(((object)val).GetType().Name).Append(' ');
			}
		}
		ManualLogSource logger = ((BaseUnityPlugin)this).Logger;
		string[] obj = new string[13]
		{
			"NHCB: prefab ",
			((Object)(object)t == (Object)(object)root) ? ((Object)t).name : GetPath(t, root),
			" localPos=",
			null,
			null,
			null,
			null,
			null,
			null,
			null,
			null,
			null,
			null
		};
		Vector3 val2 = t.localPosition;
		obj[3] = ((Vector3)(ref val2)).ToString("F4");
		obj[4] = " localRot=";
		Quaternion localRotation = t.localRotation;
		obj[5] = ((Quaternion)(ref localRotation)).ToString("F5");
		obj[6] = " localScale=";
		val2 = t.localScale;
		obj[7] = ((Vector3)(ref val2)).ToString("F4");
		obj[8] = " layer=";
		obj[9] = ((Component)t).gameObject.layer.ToString();
		obj[10] = " components=[";
		obj[11] = stringBuilder.ToString().Trim();
		obj[12] = "]";
		logger.LogInfo((object)string.Concat(obj));
		foreach (Transform item in t)
		{
			Transform t2 = item;
			LogHierarchy(t2, root);
		}
	}

	private static Bounds ToSpace(Bounds b, Matrix4x4 m)
	{
		//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_000a: 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)
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_0015: 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_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: 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_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_004b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a4: 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_0051: Unknown result type (might be due to invalid IL or missing references)
		//IL_006e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		//IL_0082: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: Unknown result type (might be due to invalid IL or missing references)
		//IL_0088: 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_0092: Unknown result type (might be due to invalid IL or missing references)
		Vector3 center = ((Bounds)(ref b)).center;
		Vector3 extents = ((Bounds)(ref b)).extents;
		Bounds result = default(Bounds);
		((Bounds)(ref result))..ctor(((Matrix4x4)(ref m)).MultiplyPoint3x4(center + new Vector3(0f - extents.x, 0f - extents.y, 0f - extents.z)), Vector3.zero);
		for (int i = 1; i < 8; i++)
		{
			((Bounds)(ref result)).Encapsulate(((Matrix4x4)(ref m)).MultiplyPoint3x4(center + new Vector3(((i & 1) != 0) ? extents.x : (0f - extents.x), ((i & 2) != 0) ? extents.y : (0f - extents.y), ((i & 4) != 0) ? extents.z : (0f - extents.z))));
		}
		return result;
	}

	private static string GetPath(Transform t, Transform root)
	{
		string text = ((Object)t).name;
		while (Object.op_Implicit((Object)(object)t.parent) && (Object)(object)t.parent != (Object)(object)root)
		{
			t = t.parent;
			text = ((Object)t).name + "/" + text;
		}
		return text;
	}

	private void OnDestroy()
	{
		PrefabManager.OnVanillaPrefabsAvailable -= RegisterItem;
	}
}