Decompiled source of Reidrheimr Faction Pack v1.0.3

ReidrheimrFactionPack/NewFactionGearMod.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
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 HarmonyLib;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Rendering;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyCompany("NewFactionGearMod")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.2.17.0")]
[assembly: AssemblyInformationalVersion("0.2.17-smooth-mead-icons")]
[assembly: AssemblyProduct("NewFactionGearMod")]
[assembly: AssemblyTitle("NewFactionGearMod")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.2.17.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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 NewFactionGearMod
{
	[HarmonyPatch(typeof(Fireplace), "UpdateFireplace")]
	internal static class BjornheimFireplacePatch
	{
		[HarmonyPrefix]
		private static void Prefix(Fireplace __instance, ZNetView ___m_nview)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Expected O, but got Unknown
			if (!((Object)__instance == (Object)null) && !((Object)___m_nview == (Object)null) && ___m_nview.IsValid())
			{
				___m_nview.GetZDO().Set("fuel", __instance.m_maxFuel);
			}
		}
	}
	[HarmonyPatch(typeof(ObjectDB), "CopyOtherDB")]
	internal static class BjornheimObjectDatabaseCopyPatch
	{
		[HarmonyPostfix]
		private static void Postfix()
		{
			GearRegistrar.OnObjectDatabaseReady(ObjectDB.instance);
		}
	}
	[HarmonyPatch(typeof(ObjectDB), "Awake")]
	internal static class BjornheimObjectDatabasePatch
	{
		[HarmonyPostfix]
		private static void Postfix(ObjectDB __instance)
		{
			GearRegistrar.OnObjectDatabaseReady(__instance);
		}
	}
	[HarmonyPatch(typeof(ZNetScene), "Awake")]
	internal static class BjornheimScenePatch
	{
		[HarmonyPostfix]
		private static void Postfix(ZNetScene __instance)
		{
			GearRegistrar.OnSceneReady(__instance);
		}
	}
	[HarmonyPatch(typeof(VisEquipment), "UpdateVisuals")]
	internal static class DarkHelmetAppearancePatch
	{
		internal static readonly int SkinColorId = Shader.PropertyToID("_SkinColor");

		internal static readonly Color CharcoalSkin = new Color(0.12f, 0.12f, 0.12f, 1f);

		private static readonly int DarkHelmetHash = StringExtensionMethods.GetStableHashCode("DarkHelmet");

		private static readonly int FenrirAltHelmetHash = StringExtensionMethods.GetStableHashCode("HelmetFenrirAlt");

		private static readonly Dictionary<VisEquipment, DarkHelmetSkinState> States = new Dictionary<VisEquipment, DarkHelmetSkinState>();

		private static readonly HashSet<DarkHelmetSkinState> ActiveStates = new HashSet<DarkHelmetSkinState>();

		private static void Postfix(VisEquipment __instance, int ___m_currentHelmetItemHash, GameObject ___m_helmetItemInstance)
		{
			if ((Object)(object)__instance == (Object)null || !__instance.m_isPlayer || __instance.m_isArmorStand)
			{
				return;
			}
			bool flag = ___m_currentHelmetItemHash == DarkHelmetHash || ___m_currentHelmetItemHash == FenrirAltHelmetHash;
			States.TryGetValue(__instance, out var value);
			if (flag && (Object)(object)__instance.m_bodyModel != (Object)null)
			{
				Material material = ((Renderer)__instance.m_bodyModel).material;
				if ((Object)(object)material != (Object)null && material.HasProperty(SkinColorId))
				{
					if ((Object)(object)value == (Object)null)
					{
						value = ((Component)__instance).gameObject.AddComponent<DarkHelmetSkinState>();
						value.Owner = __instance;
						States[__instance] = value;
					}
					if (!value.IsTinted)
					{
						ActiveStates.Add(value);
					}
					value.ApplySkin(material);
				}
				else if ((Object)(object)value != (Object)null && value.IsTinted)
				{
					value.RestoreSkin();
					ActiveStates.Remove(value);
				}
			}
			else if ((Object)(object)value != (Object)null && value.IsTinted)
			{
				if (flag)
				{
					value.RestoreSkin();
				}
				else
				{
					value.FinishVanillaRestore();
				}
				ActiveStates.Remove(value);
			}
			DarkHelmetGaze.Apply(__instance, flag, ___m_helmetItemInstance);
		}

		internal static void Forget(DarkHelmetSkinState state)
		{
			ActiveStates.Remove(state);
			VisEquipment owner = state.Owner;
			if (owner != null && States.TryGetValue(owner, out var value) && value == state)
			{
				States.Remove(owner);
			}
		}

		internal static void Cleanup()
		{
			foreach (DarkHelmetSkinState activeState in ActiveStates)
			{
				if ((Object)(object)activeState != (Object)null)
				{
					activeState.RestoreSkin();
				}
			}
			ActiveStates.Clear();
			List<DarkHelmetSkinState> list = new List<DarkHelmetSkinState>(States.Values);
			States.Clear();
			foreach (DarkHelmetSkinState item in list)
			{
				if ((Object)(object)item != (Object)null)
				{
					Object.Destroy((Object)(object)item);
				}
			}
			DarkHelmetGaze.Cleanup();
		}
	}
	internal sealed class DarkHelmetSkinState : MonoBehaviour
	{
		internal VisEquipment Owner;

		private Material _bodyMaterial;

		private Color _normalSkinColor;

		internal bool IsTinted { get; private set; }

		internal void ApplySkin(Material material)
		{
			//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_003a: Unknown result type (might be due to invalid IL or missing references)
			if (IsTinted && (Object)(object)_bodyMaterial != (Object)(object)material)
			{
				RestoreSkin();
			}
			_bodyMaterial = material;
			_normalSkinColor = material.GetColor(DarkHelmetAppearancePatch.SkinColorId);
			material.SetColor(DarkHelmetAppearancePatch.SkinColorId, DarkHelmetAppearancePatch.CharcoalSkin);
			IsTinted = true;
		}

		internal void RestoreSkin()
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			if (IsTinted && (Object)(object)_bodyMaterial != (Object)null && _bodyMaterial.HasProperty(DarkHelmetAppearancePatch.SkinColorId))
			{
				_bodyMaterial.SetColor(DarkHelmetAppearancePatch.SkinColorId, _normalSkinColor);
			}
			FinishVanillaRestore();
		}

		internal void FinishVanillaRestore()
		{
			_bodyMaterial = null;
			IsTinted = false;
		}

		private void OnDestroy()
		{
			RestoreSkin();
			DarkHelmetAppearancePatch.Forget(this);
		}
	}
	internal static class DarkHelmetGaze
	{
		private static readonly Dictionary<VisEquipment, DarkHelmetGazeState> States = new Dictionary<VisEquipment, DarkHelmetGazeState>();

		private static readonly Dictionary<Mesh, Mesh> GazeMeshes = new Dictionary<Mesh, Mesh>();

		private static Material _glowMaterial;

		private static bool _loggedUnavailable;

		internal static void Apply(VisEquipment owner, bool enabled, GameObject helmet)
		{
			if ((Object)(object)owner == (Object)null)
			{
				return;
			}
			States.TryGetValue(owner, out var value);
			if (!enabled)
			{
				if ((Object)(object)value != (Object)null)
				{
					value.Hide();
				}
				return;
			}
			if ((Object)(object)value == (Object)null)
			{
				value = ((Component)owner).gameObject.AddComponent<DarkHelmetGazeState>();
				value.Owner = owner;
				States[owner] = value;
			}
			value.Show(owner.m_bodyModel, helmet);
		}

		internal static Mesh GetGazeMesh(Mesh source)
		{
			if ((Object)(object)source == (Object)null || !source.isReadable)
			{
				LogUnavailable("The player body mesh is not readable; the faction helmet red iris layer could not be created.");
				return null;
			}
			if (GazeMeshes.TryGetValue(source, out var value))
			{
				return value;
			}
			Mesh val = CreateGazeMesh(source);
			GazeMeshes[source] = val;
			return val;
		}

		private static Mesh CreateGazeMesh(Mesh source)
		{
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: 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_01b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cd: 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_01e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0200: Unknown result type (might be due to invalid IL or missing references)
			//IL_020d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0214: Expected O, but got Unknown
			//IL_0112: 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_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: 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_014c: 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)
			if (source.subMeshCount == 0)
			{
				return null;
			}
			Vector3[] vertices = source.vertices;
			Vector3[] normals = source.normals;
			Vector2[] uv = source.uv;
			BoneWeight[] boneWeights = source.boneWeights;
			if (uv.Length != vertices.Length || normals.Length != vertices.Length || boneWeights.Length != vertices.Length)
			{
				LogUnavailable("The player body mesh has no compatible skinning data for the faction helmet red iris layer.");
				return null;
			}
			int[] triangles = source.GetTriangles(0);
			Dictionary<int, int> dictionary = new Dictionary<int, int>();
			List<Vector3> list = new List<Vector3>(8);
			List<Vector3> list2 = new List<Vector3>(8);
			List<Vector2> list3 = new List<Vector2>(8);
			List<BoneWeight> list4 = new List<BoneWeight>(8);
			List<int> list5 = new List<int>(12);
			for (int i = 0; i + 2 < triangles.Length; i += 3)
			{
				int num = triangles[i];
				int num2 = triangles[i + 1];
				int num3 = triangles[i + 2];
				if (!IsIrisUv(uv[num]) || !IsIrisUv(uv[num2]) || !IsIrisUv(uv[num3]))
				{
					continue;
				}
				for (int j = 0; j < 3; j++)
				{
					int num4 = triangles[i + j];
					if (!dictionary.TryGetValue(num4, out var value))
					{
						value = (dictionary[num4] = list.Count);
						list.Add(vertices[num4] + ((Vector3)(ref normals[num4])).normalized * 8.4E-06f);
						list2.Add(normals[num4]);
						list3.Add(uv[num4]);
						list4.Add(boneWeights[num4]);
					}
					list5.Add(value);
				}
			}
			if (list.Count != 8 || list5.Count != 12)
			{
				LogUnavailable("The player mesh does not contain the stock iris layout for the faction helmet red iris layer.");
				return null;
			}
			Mesh val = new Mesh
			{
				name = "NewFactionGear_DarkHelmetGazeMesh",
				vertices = list.ToArray(),
				normals = list2.ToArray(),
				uv = list3.ToArray(),
				boneWeights = list4.ToArray(),
				bindposes = source.bindposes,
				triangles = list5.ToArray()
			};
			val.RecalculateBounds();
			return val;
		}

		private static bool IsIrisUv(Vector2 uv)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			if (uv.x >= 0.46f && uv.x <= 0.5f && uv.y >= 0.902f)
			{
				return uv.y <= 0.922f;
			}
			return false;
		}

		internal static Material GetGlowMaterial(GameObject helmet)
		{
			//IL_0030: 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_0045: Expected O, but got Unknown
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_glowMaterial != (Object)null)
			{
				return _glowMaterial;
			}
			Shader val = FindHelmetShader(helmet);
			if ((Object)(object)val == (Object)null)
			{
				LogUnavailable("The equipped faction helmet has no loaded color shader for its red iris material.");
				return null;
			}
			_glowMaterial = new Material(val)
			{
				name = "NewFactionGear_DarkHelmetGlow"
			};
			Color val2 = default(Color);
			((Color)(ref val2))..ctor(0.85f, 0.008f, 0.004f, 1f);
			Color val3 = default(Color);
			((Color)(ref val3))..ctor(0.9f, 0.003f, 0.002f, 1f);
			_glowMaterial.SetColor("_Color", val2);
			_glowMaterial.SetTexture("_MainTex", (Texture)(object)Texture2D.whiteTexture);
			if (_glowMaterial.HasProperty("_EmissionColor"))
			{
				_glowMaterial.SetColor("_EmissionColor", val3);
				if (_glowMaterial.HasProperty("_EmissionMap"))
				{
					_glowMaterial.SetTexture("_EmissionMap", (Texture)(object)Texture2D.whiteTexture);
				}
				_glowMaterial.EnableKeyword("_EMISSION");
				_glowMaterial.globalIlluminationFlags = (MaterialGlobalIlluminationFlags)0;
			}
			if (_glowMaterial.HasProperty("_Glossiness"))
			{
				_glowMaterial.SetFloat("_Glossiness", 0f);
			}
			if (_glowMaterial.HasProperty("_Metallic"))
			{
				_glowMaterial.SetFloat("_Metallic", 0f);
			}
			Plugin.Log.LogInfo((object)("Faction helmet red irises use the loaded helmet shader '" + ((Object)val).name + "'."));
			return _glowMaterial;
		}

		private static Shader FindHelmetShader(GameObject helmet)
		{
			if ((Object)(object)helmet == (Object)null)
			{
				return null;
			}
			Shader result = null;
			Renderer[] componentsInChildren = helmet.GetComponentsInChildren<Renderer>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				Material[] sharedMaterials = componentsInChildren[i].sharedMaterials;
				foreach (Material val in sharedMaterials)
				{
					if (!((Object)(object)val == (Object)null) && !((Object)(object)val.shader == (Object)null) && val.HasProperty("_Color") && val.HasProperty("_MainTex"))
					{
						if (val.HasProperty("_EmissionColor"))
						{
							return val.shader;
						}
						result = val.shader;
					}
				}
			}
			return result;
		}

		internal static void Forget(VisEquipment owner, DarkHelmetGazeState state)
		{
			if (owner != null && States.TryGetValue(owner, out var value) && value == state)
			{
				States.Remove(owner);
			}
		}

		private static void LogUnavailable(string message)
		{
			if (!_loggedUnavailable)
			{
				_loggedUnavailable = true;
				Plugin.Log.LogWarning((object)message);
			}
		}

		internal static void Cleanup()
		{
			List<DarkHelmetGazeState> list = new List<DarkHelmetGazeState>(States.Values);
			States.Clear();
			foreach (DarkHelmetGazeState item in list)
			{
				if ((Object)(object)item != (Object)null)
				{
					item.Release();
					Object.Destroy((Object)(object)item);
				}
			}
			foreach (Mesh value in GazeMeshes.Values)
			{
				if ((Object)(object)value != (Object)null)
				{
					Object.Destroy((Object)(object)value);
				}
			}
			GazeMeshes.Clear();
			if ((Object)(object)_glowMaterial != (Object)null)
			{
				Object.Destroy((Object)(object)_glowMaterial);
				_glowMaterial = null;
			}
		}
	}
	internal sealed class DarkHelmetGazeState : MonoBehaviour
	{
		internal VisEquipment Owner;

		private SkinnedMeshRenderer _body;

		private Mesh _sourceMesh;

		private GameObject _helmet;

		private GameObject _gazeObject;

		private SkinnedMeshRenderer _gazeRenderer;

		private bool _setupFailed;

		internal void Show(SkinnedMeshRenderer body, GameObject helmet)
		{
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Expected O, but got Unknown
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fb: Invalid comparison between Unknown and I4
			if ((Object)(object)body == (Object)null || (Object)(object)body.sharedMesh == (Object)null || (Object)(object)helmet == (Object)null)
			{
				Hide();
				return;
			}
			if ((Object)(object)_body != (Object)(object)body || (Object)(object)_sourceMesh != (Object)(object)body.sharedMesh || (Object)(object)_helmet != (Object)(object)helmet || ((Object)(object)_gazeRenderer == (Object)null && !_setupFailed))
			{
				Release();
				_body = body;
				_sourceMesh = body.sharedMesh;
				_helmet = helmet;
				Mesh gazeMesh = DarkHelmetGaze.GetGazeMesh(_sourceMesh);
				Material glowMaterial = DarkHelmetGaze.GetGlowMaterial(helmet);
				if ((Object)(object)gazeMesh == (Object)null || (Object)(object)glowMaterial == (Object)null)
				{
					_setupFailed = true;
					return;
				}
				_gazeObject = new GameObject("NewFactionGear_DarkHelmetGaze");
				((Object)_gazeObject).hideFlags = (HideFlags)52;
				_gazeObject.layer = ((Component)body).gameObject.layer;
				_gazeObject.transform.SetParent(((Component)body).transform, false);
				_gazeRenderer = _gazeObject.AddComponent<SkinnedMeshRenderer>();
				_gazeRenderer.sharedMesh = gazeMesh;
				((Renderer)_gazeRenderer).sharedMaterial = glowMaterial;
				_gazeRenderer.bones = body.bones;
				_gazeRenderer.rootBone = body.rootBone;
				_gazeRenderer.quality = body.quality;
				((Renderer)_gazeRenderer).localBounds = ((Renderer)body).localBounds;
				_gazeRenderer.updateWhenOffscreen = body.updateWhenOffscreen;
				((Renderer)_gazeRenderer).shadowCastingMode = (ShadowCastingMode)0;
				((Renderer)_gazeRenderer).receiveShadows = false;
				((Renderer)_gazeRenderer).lightProbeUsage = (LightProbeUsage)0;
				((Renderer)_gazeRenderer).reflectionProbeUsage = (ReflectionProbeUsage)0;
			}
			if ((Object)(object)_gazeRenderer != (Object)null)
			{
				if (!_gazeObject.activeSelf)
				{
					_gazeObject.SetActive(true);
				}
				((Renderer)_gazeRenderer).enabled = ((Renderer)body).enabled && !((Renderer)body).forceRenderingOff && (int)((Renderer)body).shadowCastingMode != 3;
			}
		}

		internal void Hide()
		{
			if ((Object)(object)_gazeObject != (Object)null && _gazeObject.activeSelf)
			{
				_gazeObject.SetActive(false);
			}
		}

		internal void Release()
		{
			if ((Object)(object)_gazeObject != (Object)null)
			{
				_gazeObject.SetActive(false);
				Object.Destroy((Object)(object)_gazeObject);
			}
			_gazeObject = null;
			_gazeRenderer = null;
			_body = null;
			_sourceMesh = null;
			_helmet = null;
			_setupFailed = false;
		}

		private void OnDestroy()
		{
			Release();
			DarkHelmetGaze.Forget(Owner, this);
		}
	}
	internal static class FactionMeads
	{
		internal static int Register()
		{
			//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d6: Expected O, but got Unknown
			//IL_0207: Unknown result type (might be due to invalid IL or missing references)
			//IL_020d: Expected O, but got Unknown
			//IL_0217: Unknown result type (might be due to invalid IL or missing references)
			//IL_021d: Expected O, but got Unknown
			//IL_0227: Unknown result type (might be due to invalid IL or missing references)
			//IL_022d: Expected O, but got Unknown
			//IL_0237: Unknown result type (might be due to invalid IL or missing references)
			//IL_023d: Expected O, but got Unknown
			//IL_0272: Unknown result type (might be due to invalid IL or missing references)
			//IL_0278: Expected O, but got Unknown
			//IL_0282: Unknown result type (might be due to invalid IL or missing references)
			//IL_0288: Expected O, but got Unknown
			//IL_0293: Unknown result type (might be due to invalid IL or missing references)
			//IL_0299: Expected O, but got Unknown
			//IL_02a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a9: Expected O, but got Unknown
			GameObject prefab = PrefabManager.Instance.GetPrefab("MeadTasty");
			GameObject prefab2 = PrefabManager.Instance.GetPrefab("MeadBaseTasty");
			GameObject prefab3 = PrefabManager.Instance.GetPrefab("Pukeberries");
			ItemDrop val = (((Object)(object)prefab != (Object)null) ? prefab.GetComponent<ItemDrop>() : null);
			ItemDrop val2 = (((Object)(object)prefab2 != (Object)null) ? prefab2.GetComponent<ItemDrop>() : null);
			ItemDrop obj = (((Object)(object)prefab3 != (Object)null) ? prefab3.GetComponent<ItemDrop>() : null);
			StatusEffect obj2 = val?.m_itemData?.m_shared?.m_consumeStatusEffect;
			SE_Stats val3 = (SE_Stats)(object)((obj2 is SE_Stats) ? obj2 : null);
			StatusEffect obj3 = obj?.m_itemData?.m_shared?.m_consumeStatusEffect;
			SE_Puke val4 = (SE_Puke)(object)((obj3 is SE_Puke) ? obj3 : null);
			if ((Object)(object)val3 == (Object)null || (Object)(object)val4 == (Object)null || (Object)(object)val2 == (Object)null)
			{
				Plugin.Log.LogWarning((object)"Could not find the vanilla Tasty mead/base or Pukeberries effect; skipping Mealumba and Rolumba.");
				return 0;
			}
			GameObject prefab4 = PrefabManager.Instance.GetPrefab("fermenter");
			ItemConversion val5 = (((Object)(object)prefab4 != (Object)null) ? prefab4.GetComponent<Fermenter>() : null)?.m_conversion?.FirstOrDefault((Func<ItemConversion, bool>)((ItemConversion conversion) => conversion != null && (Object)(object)conversion.m_from != (Object)null && ((Object)conversion.m_from).name == "MeadBaseTasty"));
			if (val5 == null)
			{
				Plugin.Log.LogWarning((object)"Could not find the vanilla Tasty mead fermentation recipe; skipping Mealumba and Rolumba.");
				return 0;
			}
			SE_Puke val6 = Object.Instantiate<SE_Puke>(val4);
			((Object)val6).name = "NewFactionGear_MeadVomiting";
			((StatusEffect)val6).m_name = "Mead sickness";
			((StatusEffect)val6).m_tooltip = "Causes vomiting and removes eaten food for 10 seconds.";
			((StatusEffect)val6).m_ttl = 10f;
			((StatusEffect)val6).m_category = string.Empty;
			((StatusEffect)val6).m_cooldown = 0f;
			SE_Stats obj4 = ScriptableObject.CreateInstance<SE_Stats>();
			CopyStats(obj4, (SE_Stats)(object)val6);
			Object.Destroy((Object)(object)obj4);
			ItemManager.Instance.AddStatusEffect(new CustomStatusEffect((StatusEffect)(object)val6, false));
			return RegisterMead("Mealumba", "Alcoholic beverage made with nasty ingredients.", 0.2f, false, prefab, prefab2, val2, val3, val6, val5.m_producedItems, new RequirementConfig("Honey", 12, 0, true), new RequirementConfig("Bloodbag", 7, 0, true), new RequirementConfig("Entrails", 6, 0, true), new RequirementConfig("Guck", 4, 0, true)) + RegisterMead("Rolumba", "Royal jelly mead mix version of Mealumba.", 0.4f, true, prefab, prefab2, val2, val3, val6, val5.m_producedItems, new RequirementConfig("RoyalJelly", 15, 0, true), new RequirementConfig("Bilebag", 1, 0, true), new RequirementConfig("Honey", 10, 0, true), new RequirementConfig("MeadBaseMealumba", 1, 0, true));
		}

		private static int RegisterMead(string displayName, string description, float extraStaminaRegen, bool fireResistance, GameObject tastyPrefab, GameObject basePrefab, ItemDrop baseDrop, SE_Stats tastyEffect, SE_Puke vomitingEffect, int producedItems, params RequirementConfig[] requirements)
		{
			//IL_02a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ad: Expected O, but got Unknown
			//IL_02b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d4: Expected O, but got Unknown
			//IL_02cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d9: Expected O, but got Unknown
			//IL_02e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ed: Expected O, but got Unknown
			//IL_02f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0303: 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_0311: Unknown result type (might be due to invalid IL or missing references)
			//IL_031e: Expected O, but got Unknown
			//IL_0319: Unknown result type (might be due to invalid IL or missing references)
			//IL_0323: Expected O, but got Unknown
			//IL_0247: 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_0259: Unknown result type (might be due to invalid IL or missing references)
			//IL_025e: Unknown result type (might be due to invalid IL or missing references)
			string text = "Mead" + displayName;
			string text2 = "MeadBase" + displayName;
			ItemConfig val = GearRegistrar.CreateClonedItemConfig(baseDrop, text2, baseDrop.m_itemData.GetIcon());
			if (!val.Enabled || string.IsNullOrEmpty(val.CraftingStation))
			{
				Plugin.Log.LogWarning((object)("Could not find the vanilla Tasty mead base crafting recipe; skipping " + displayName + "."));
				return 0;
			}
			val.Name = displayName + " Mead Base";
			val.Description = description + " Ferment this base to make " + displayName + ".";
			val.Requirements = requirements;
			val.Amount = 1;
			val.RepairStation = string.Empty;
			GearSettings.BindRecipe(val, text2);
			GameObject val2 = Object.Instantiate<GameObject>(tastyPrefab, Plugin.PrefabRoot.transform, false);
			((Object)val2).name = text;
			GameObject val3 = Object.Instantiate<GameObject>(basePrefab, Plugin.PrefabRoot.transform, false);
			((Object)val3).name = text2;
			ItemDrop component = val2.GetComponent<ItemDrop>();
			ItemDrop component2 = val3.GetComponent<ItemDrop>();
			component.m_itemData.m_dropPrefab = val2;
			component2.m_itemData.m_dropPrefab = val3;
			MeadAppearance.Apply(val2, val3, val, fireResistance);
			SE_FactionMeadStats sE_FactionMeadStats = ScriptableObject.CreateInstance<SE_FactionMeadStats>();
			FieldInfo[] fields = typeof(StatusEffect).GetFields(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public);
			foreach (FieldInfo fieldInfo in fields)
			{
				fieldInfo.SetValue(sE_FactionMeadStats, fieldInfo.GetValue(tastyEffect));
			}
			((Object)sE_FactionMeadStats).name = "NewFactionGear_" + displayName;
			((StatusEffect)sE_FactionMeadStats).m_name = displayName;
			((StatusEffect)sE_FactionMeadStats).m_icon = component.m_itemData.GetIcon();
			((StatusEffect)sE_FactionMeadStats).m_tooltip = "Drinking also causes vomiting and removes eaten food for 10 seconds.";
			((StatusEffect)sE_FactionMeadStats).m_ttl = 300f;
			((StatusEffect)sE_FactionMeadStats).m_category = ((StatusEffect)tastyEffect).m_category;
			((StatusEffect)sE_FactionMeadStats).m_cooldown = ((StatusEffect)tastyEffect).m_cooldown;
			sE_FactionMeadStats.m_vomitingEffectHash = ((StatusEffect)vomitingEffect).NameHash();
			CopyStats(tastyEffect, (SE_Stats)(object)sE_FactionMeadStats);
			((SE_Stats)sE_FactionMeadStats).m_healthRegenMultiplier = 1.05f;
			((SE_Stats)sE_FactionMeadStats).m_staminaRegenMultiplier = ((SE_Stats)sE_FactionMeadStats).m_staminaRegenMultiplier + extraStaminaRegen;
			((SE_Stats)sE_FactionMeadStats).m_mods = ((tastyEffect.m_mods != null) ? new List<DamageModPair>(tastyEffect.m_mods) : new List<DamageModPair>());
			if (fireResistance)
			{
				((SE_Stats)sE_FactionMeadStats).m_mods.RemoveAll((DamageModPair modifier) => (int)modifier.m_type == 32);
				((SE_Stats)sE_FactionMeadStats).m_mods.Add(new DamageModPair
				{
					m_type = (DamageType)32,
					m_modifier = (DamageModifier)1
				});
			}
			component.m_itemData.m_shared.m_consumeStatusEffect = (StatusEffect)(object)sE_FactionMeadStats;
			component2.m_itemData.m_shared.m_consumeStatusEffect = (StatusEffect)(object)sE_FactionMeadStats;
			GearSettings.ApplyStats(component, text);
			GearSettings.ApplyStats(component2, text2);
			ItemManager.Instance.AddStatusEffect(new CustomStatusEffect((StatusEffect)(object)sE_FactionMeadStats, false));
			ItemManager.Instance.AddItem(new CustomItem(val2, false, new ItemConfig
			{
				Name = displayName,
				Description = description,
				Enabled = false
			}));
			ItemManager.Instance.AddItem(new CustomItem(val3, false, val));
			ItemManager.Instance.AddItemConversion(new CustomItemConversion((ConversionConfig)new FermenterConversionConfig
			{
				Station = "fermenter",
				FromItem = text2,
				ToItem = text,
				ProducedItems = producedItems
			}));
			Plugin.Log.LogInfo((object)("Registered " + displayName + " and its mead base, with 10-second vomiting and a separate 5-minute buff."));
			return 2;
		}

		private static void CopyStats(SE_Stats source, SE_Stats destination)
		{
			FieldInfo[] fields = typeof(SE_Stats).GetFields(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public);
			foreach (FieldInfo fieldInfo in fields)
			{
				fieldInfo.SetValue(destination, fieldInfo.GetValue(source));
			}
		}
	}
	internal sealed class SE_FactionMeadStats : SE_Stats
	{
		public int m_vomitingEffectHash;

		public override void Setup(Character character)
		{
			((SE_Stats)this).Setup(character);
			StartVomiting();
		}

		public override void ResetTime()
		{
			((SE_Stats)this).ResetTime();
			StartVomiting();
		}

		private void StartVomiting()
		{
			if ((Object)(object)((StatusEffect)this).m_character != (Object)null && ((StatusEffect)this).m_character.IsPlayer())
			{
				((StatusEffect)this).m_character.GetSEMan().AddStatusEffect(m_vomitingEffectHash, true, 0, 0f, (short)(-1));
			}
		}
	}
	internal static class GearRegistrar
	{
		private sealed class Gear
		{
			public string Prefab;

			public string DisplayName;

			public string Slot;

			public int[] Cost;

			public bool Body;
		}

		private static readonly string[] AshlandsMaterials = new string[5] { "FlametalNew", "AskHide", "CharredBone", "Eitr", "YmirRemains" };

		private static readonly string[] BjornheimWeaponPrefabs = new string[9] { "Blidhr_bal", "Blidhr_base_bal", "BowRazorStrikes", "FenrirSword_bal", "FenrirSword_base_bal", "Gugnir_bal", "Gugnir_base_bal", "HoundsSycle", "HoundsScythe" };

		private static readonly string[] BjornheimResourcePrefabs = new string[19]
		{
			"AcidSludge_bal", "Amethyst_bal", "AmethystSteel", "BlackTissue", "Bloodsteel", "DarkSteel", "DvergrHeart", "Electrum", "Frosteel", "GjallCore_bal",
			"GoldBar", "SeedFrost_bal", "SeekerBruteBlood", "MeadBaseLightingResistMedium_bal", "MeadBaseSpiritResistMedium_bal", "MediumSpiritPotion_bal", "MediumThunderPotion_bal", "DraugrInsygnia", "QueenCore"
		};

		private static readonly string[] BjornheimPiecePrefabs = new string[5] { "SacredForge", "sacredforge_ext1", "sacredforge_ext2", "sacredforge_ext3", "GrandForgeV2" };

		private static readonly string[] BjornheimEffectPrefabs = new string[12]
		{
			"SacredForgeAltar", "GrandForge", "Wave_Ground", "projectile_runeAxe", "fx_eikthyr_forwardshockwave1", "fx_Lightning1", "vfx_iceblocker_destroyed1", "vfx_scythExplosion", "vfx_scythe_ground", "vfx_scytheSpikeAoe",
			"fx_eikthyr_forwardshockwave2", "vfx_spiritbolt_explosion"
		};

		private static readonly Gear[] GearSet = BuildGearSet();

		private static AssetBundle _bundle;

		private static AssetBundle _bjornheimBundle;

		private static readonly Dictionary<string, Texture2D> TextureCache = new Dictionary<string, Texture2D>(StringComparer.OrdinalIgnoreCase);

		private static readonly Dictionary<string, Sprite> SpriteCache = new Dictionary<string, Sprite>(StringComparer.OrdinalIgnoreCase);

		private static readonly Dictionary<string, GameObject> BundlePrefabCache = new Dictionary<string, GameObject>(StringComparer.OrdinalIgnoreCase);

		private static readonly Dictionary<string, Sprite> BundleSpriteCache = new Dictionary<string, Sprite>(StringComparer.OrdinalIgnoreCase);

		private static Stream _bundleStream;

		private static Stream _bjornheimBundleStream;

		private static readonly List<StatusEffect> _bjornheimStatusEffects = new List<StatusEffect>();

		private static Sprite _spiritIcon;

		private static readonly List<Texture2D> LoadedTextures = new List<Texture2D>();

		private static readonly List<Sprite> LoadedSprites = new List<Sprite>();

		private static MethodInfo _loadImageMethod;

		private static bool _loadImageMethodLookupAttempted;

		private static readonly List<Material> OwnedMaterials = new List<Material>();

		private static bool _registered;

		internal static void OnObjectDatabaseReady(ObjectDB database)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Expected O, but got Unknown
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Expected O, but got Unknown
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Expected O, but got Unknown
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Expected O, but got Unknown
			if ((Object)database == (Object)null)
			{
				return;
			}
			if (_bjornheimStatusEffects != null)
			{
				foreach (StatusEffect effect in _bjornheimStatusEffects)
				{
					if ((Object)effect != (Object)null && !database.m_StatusEffects.Any((StatusEffect existing) => (Object)existing != (Object)null && ((Object)existing).name == ((Object)effect).name))
					{
						database.m_StatusEffects.Add(effect);
					}
				}
			}
			if ((Object)_spiritIcon != (Object)null)
			{
				StatusEffect val = ((IEnumerable<StatusEffect>)database.m_StatusEffects).FirstOrDefault((Func<StatusEffect, bool>)((StatusEffect val2) => (Object)val2 != (Object)null && ((Object)val2).name == "Spirit"));
				if ((Object)val != (Object)null)
				{
					val.m_icon = _spiritIcon;
				}
			}
			if ((Object)ZNetScene.instance != (Object)null)
			{
				OnSceneReady(ZNetScene.instance);
			}
		}

		internal static void OnSceneReady(ZNetScene scene)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			if (!((Object)scene == (Object)null) && scene.m_prefabs != null)
			{
				ApplySpiritDamageChanges(scene.m_prefabs);
				ApplyMonsterChanges(scene.m_prefabs);
				ApplyPortalRequirements(scene.m_prefabs);
				ApplyStationChanges(scene.m_prefabs);
			}
		}

		private static void ApplySpiritDamageChanges(List<GameObject> prefabs)
		{
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Expected O, but got Unknown
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Expected O, but got Unknown
			SetSpiritDamage(prefabs, "draugr_sword", 25f);
			SetSpiritDamage(prefabs, "draugr_bow", 15f);
			SetSpiritDamage(prefabs, "draugr_axe", 15f);
			SetSpiritDamage(prefabs, "skeleton_bow", 10f);
			SetSpiritDamage(prefabs, "skeleton_mace", 20f);
			SetSpiritDamage(prefabs, "skeleton_sword", 10f);
			SetSpiritDamage(prefabs, "skeleton_sword2", 20f);
			SetSpiritDamage(prefabs, "skeleton_bow2", 20f);
			SetSpiritDamage(prefabs, "imp_fireball_attack", 10f, addToBlunt: true);
			SetSpiritDamage(prefabs, "Ghost_attack", 10f);
			SetSpiritDamage(prefabs, "gd_king_shoot", 20f);
			SetSpiritDamage(prefabs, "Greydwarf_shaman_attack", 20f);
			SetSpiritDamage(prefabs, "GoblinKing_Beam", 20f);
			SetSpiritDamage(prefabs, "GoblinShaman_attack_fireball", 20f);
			GameObject val = FindPrefab(prefabs, "BowRazorStrikes");
			ItemDrop val2 = (((Object)val == (Object)null) ? null : val.GetComponent<ItemDrop>());
			if (!((Object)val2 == (Object)null))
			{
				SharedData shared = val2.m_itemData.m_shared;
				shared.m_damages.m_pierce = 94f;
				shared.m_damages.m_fire = 0f;
				shared.m_damages.m_frost = 10f;
				shared.m_damages.m_lightning = 10f;
				shared.m_damages.m_poison = 0f;
				shared.m_damages.m_spirit = 10f;
				shared.m_damagesPerLevel.m_pierce = 4f;
				shared.m_damagesPerLevel.m_fire = 0f;
				shared.m_damagesPerLevel.m_frost = 4f;
				shared.m_damagesPerLevel.m_lightning = 4f;
				shared.m_damagesPerLevel.m_poison = 0f;
				shared.m_damagesPerLevel.m_spirit = 4f;
			}
		}

		private static void SetSpiritDamage(List<GameObject> prefabs, string prefabName, float spirit, bool addToBlunt = false)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Expected O, but got Unknown
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Expected O, but got Unknown
			GameObject val = FindPrefab(prefabs, prefabName);
			ItemDrop val2 = (((Object)val == (Object)null) ? null : val.GetComponent<ItemDrop>());
			if (!((Object)val2 == (Object)null))
			{
				float spirit2 = val2.m_itemData.m_shared.m_damages.m_spirit;
				val2.m_itemData.m_shared.m_damages.m_spirit = spirit;
				if (addToBlunt && spirit2 != spirit)
				{
					val2.m_itemData.m_shared.m_damages.m_blunt += spirit;
				}
			}
		}

		private static void ApplyMonsterChanges(List<GameObject> prefabs)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Expected O, but got Unknown
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Expected O, but got Unknown
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Expected O, but got Unknown
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			foreach (GameObject prefab in prefabs)
			{
				if (!((Object)prefab == (Object)null))
				{
					Humanoid component = prefab.GetComponent<Humanoid>();
					if ((Object)component != (Object)null)
					{
						ApplyFactionSpiritResistance(component);
					}
				}
			}
			GameObject val = FindPrefab(prefabs, "Player");
			Humanoid val2 = (((Object)(object)val != (Object)null) ? val.GetComponent<Humanoid>() : null);
			if ((Object)val2 != (Object)null)
			{
				((Character)val2).m_damageModifiers.m_spirit = (DamageModifier)0;
			}
			AddMonsterDrop(prefabs, "Tick", "BlackTissue", 0.25f);
			AddMonsterDrop(prefabs, "Seeker", "AcidSludge_bal", 0.5f);
			AddMonsterDrop(prefabs, "SeekerBrute", "SeekerBruteBlood", 0.5f);
			AddMonsterDrop(prefabs, "DvergerMage", "DvergrHeart", 0.25f);
			AddMonsterDrop(prefabs, "SeekerQueen", "QueenCore", 0.15f);
			AddMonsterDrop(prefabs, "DvergerMageIce", "DvergrHeart", 0.25f);
			AddMonsterDrop(prefabs, "DvergerMageIce", "SeedFrost_bal", 0.75f);
			AddMonsterDrop(prefabs, "DvergerMageSupport", "DvergrHeart", 0.25f);
			AddMonsterDrop(prefabs, "DvergerMageSupport", "Amethyst_bal", 0.5f);
			AddMonsterDrop(prefabs, "DvergerMageFire", "DvergrHeart", 0.25f);
			AddMonsterDrop(prefabs, "DvergerMageFire", "Amethyst_bal", 0.25f);
			AddMonsterDrop(prefabs, "Dverger", "GoldBar", 0.25f);
			AddMonsterDrop(prefabs, "Gjall", "GjallCore_bal", 1f);
			AddMonsterDrop(prefabs, "Draugr", "DraugrInsygnia", 0.2f);
			AddMonsterDrop(prefabs, "Draugr_Ranged", "DraugrInsygnia", 0.2f);
			AddMonsterDrop(prefabs, "Draugr_Elite", "DraugrInsygnia", 0.5f);
		}

		private static void ApplyFactionSpiritResistance(Humanoid humanoid)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected I4, but got Unknown
			//IL_0039: 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_0060: 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_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			switch ((int)((Character)humanoid).m_faction)
			{
			case 0:
				((Character)humanoid).m_damageModifiers.m_spirit = (DamageModifier)0;
				break;
			case 1:
				((Character)humanoid).m_damageModifiers.m_spirit = (DamageModifier)1;
				break;
			case 5:
				((Character)humanoid).m_damageModifiers.m_spirit = (DamageModifier)5;
				break;
			case 2:
			case 3:
				((Character)humanoid).m_damageModifiers.m_spirit = (DamageModifier)2;
				break;
			case 6:
				((Character)humanoid).m_damageModifiers.m_spirit = (DamageModifier)1;
				break;
			case 4:
			case 8:
				((Character)humanoid).m_damageModifiers.m_spirit = (DamageModifier)5;
				break;
			case 7:
				break;
			}
		}

		private static void AddMonsterDrop(List<GameObject> prefabs, string monsterName, string itemName, float chance)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Expected O, but got Unknown
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Expected O, but got Unknown
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Expected O, but got Unknown
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Expected O, but got Unknown
			//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_0094: 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_00a2: 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_00b5: Expected O, but got Unknown
			GameObject val = FindPrefab(prefabs, monsterName);
			GameObject val2 = FindPrefab(prefabs, itemName);
			CharacterDrop val3 = (((Object)val == (Object)null) ? null : val.GetComponent<CharacterDrop>());
			if (!((Object)val3 == (Object)null) && !((Object)val2 == (Object)null) && !((Object)val2.GetComponent<ItemDrop>() == (Object)null) && !val3.m_drops.Any((Drop drop) => drop != null && (Object)drop.m_prefab != (Object)null && ((Object)drop.m_prefab).name == itemName))
			{
				val3.m_drops.Add(new Drop
				{
					m_prefab = val2,
					m_amountMin = 1,
					m_amountMax = 1,
					m_chance = chance,
					m_levelMultiplier = false
				});
			}
		}

		private static void ApplyPortalRequirements(List<GameObject> prefabs)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Expected O, but got Unknown
			GameObject val = FindPrefab(prefabs, "QueenCore");
			ItemDrop val2 = (((Object)val == (Object)null) ? null : val.GetComponent<ItemDrop>());
			if (!((Object)val2 == (Object)null))
			{
				AddPortalRequirement(FindPrefab(prefabs, "portal_wood"), val2);
				AddPortalRequirement(FindPrefab(prefabs, "portal_stone"), val2);
			}
		}

		private static void AddPortalRequirement(GameObject portal, ItemDrop core)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			//IL_0076: 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_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Expected O, but got Unknown
			Piece val = (((Object)portal == (Object)null) ? null : portal.GetComponent<Piece>());
			if (!((Object)val == (Object)null) && (val.m_resources == null || !val.m_resources.Any((Requirement requirement) => requirement != null && (Object)requirement.m_resItem != (Object)null && ((Object)requirement.m_resItem).name == "QueenCore")))
			{
				List<Requirement> list = ((val.m_resources == null) ? new List<Requirement>() : val.m_resources.ToList());
				list.Add(new Requirement
				{
					m_resItem = core,
					m_amount = 1,
					m_recover = true
				});
				val.m_resources = list.ToArray();
			}
		}

		private static void ApplyStationChanges(List<GameObject> prefabs)
		{
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Expected O, but got Unknown
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Expected O, but got Unknown
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Expected O, but got Unknown
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: Expected O, but got Unknown
			GameObject val = FindPrefab(prefabs, "fermenter");
			Fermenter fermenter = (((Object)(object)val != (Object)null) ? val.GetComponent<Fermenter>() : null);
			AddFermenterRecipe(fermenter, "MeadBaseLightingResistMedium_bal", "MediumThunderPotion_bal");
			AddFermenterRecipe(fermenter, "MeadBaseSpiritResistMedium_bal", "MediumSpiritPotion_bal");
			GameObject val2 = FindPrefab(prefabs, "smelter");
			Smelter val3 = (((Object)(object)val2 != (Object)null) ? val2.GetComponent<Smelter>() : null);
			if ((Object)val3 != (Object)null)
			{
				val3.m_secPerProduct = 6f;
				val3.m_fuelPerProduct = 3;
			}
			GameObject val4 = FindPrefab(prefabs, "blastfurnace");
			Smelter val5 = (((Object)(object)val4 != (Object)null) ? val4.GetComponent<Smelter>() : null);
			if ((Object)val5 != (Object)null && (Object)val3 != (Object)null)
			{
				val5.m_secPerProduct = 3f;
				val5.m_fuelPerProduct = 2;
				foreach (ItemConversion item in val3.m_conversion)
				{
					AddConversionIfMissing(val5.m_conversion, item);
				}
			}
			SetSmelterRate(prefabs, "charcoal_kiln", 10f);
			SetSmelterRate(prefabs, "piece_spinningwheel", 10f);
			SetSmelterRate(prefabs, "eitrrefinery", 10f);
			SetSmelterRate(prefabs, "windmill", 8f);
			GameObject val6 = FindPrefab(prefabs, "piece_sapcollector");
			SapCollector val7 = (((Object)(object)val6 != (Object)null) ? val6.GetComponent<SapCollector>() : null);
			if ((Object)val7 != (Object)null)
			{
				val7.m_secPerUnit = 15f;
				val7.m_maxLevel = 60;
			}
		}

		private static void AddFermenterRecipe(Fermenter fermenter, string inputName, string outputName)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Expected O, but got Unknown
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Expected O, but got Unknown
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Expected O, but got Unknown
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Expected O, but got Unknown
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Expected O, but got Unknown
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Expected O, but got Unknown
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Expected O, but got Unknown
			if (!((Object)fermenter == (Object)null))
			{
				if (fermenter.m_conversion == null)
				{
					fermenter.m_conversion = new List<ItemConversion>();
				}
				GameObject val = FindPrefab(ZNetScene.instance?.m_prefabs, inputName);
				GameObject val2 = FindPrefab(ZNetScene.instance?.m_prefabs, outputName);
				if ((Object)val == (Object)null)
				{
					val = FindBjornheimResource(inputName);
				}
				if ((Object)val2 == (Object)null)
				{
					val2 = FindBjornheimResource(outputName);
				}
				ItemDrop from = (((Object)val == (Object)null) ? null : val.GetComponent<ItemDrop>());
				ItemDrop val3 = (((Object)val2 == (Object)null) ? null : val2.GetComponent<ItemDrop>());
				if (!((Object)from == (Object)null) && !((Object)val3 == (Object)null) && !fermenter.m_conversion.Any((ItemConversion conversion) => conversion != null && (Object)conversion.m_from == (Object)from))
				{
					fermenter.m_conversion.Add(new ItemConversion
					{
						m_from = from,
						m_to = val3,
						m_producedItems = 6
					});
				}
			}
		}

		private static GameObject FindBjornheimResource(string prefabName)
		{
			string text = "Assets/Custom/Comission/FactionWeapons/Resources/" + prefabName + ".prefab";
			return LoadBundlePrefab(_bjornheimBundle, "weapons:" + text, text);
		}

		private static void AddConversionIfMissing(List<ItemConversion> conversions, ItemConversion conversion)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Expected O, but got Unknown
			if (conversion != null && !((Object)conversion.m_from == (Object)null) && !conversions.Any((ItemConversion existing) => existing != null && (Object)existing.m_from != (Object)null && ((Object)existing.m_from).name == ((Object)conversion.m_from).name))
			{
				conversions.Add(conversion);
			}
		}

		private static void SetSmelterRate(List<GameObject> prefabs, string prefabName, float secondsPerProduct)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Expected O, but got Unknown
			GameObject val = FindPrefab(prefabs, prefabName);
			Smelter val2 = (((Object)(object)val != (Object)null) ? val.GetComponent<Smelter>() : null);
			if ((Object)val2 != (Object)null)
			{
				val2.m_secPerProduct = secondsPerProduct;
			}
		}

		private static GameObject FindPrefab(List<GameObject> prefabs, string name)
		{
			return prefabs?.FirstOrDefault((Func<GameObject, bool>)((GameObject prefab) => (Object)prefab != (Object)null && ((Object)prefab).name == name));
		}

		private static GameObject LoadBundlePrefab(AssetBundle bundle, string cacheKey, string assetPath)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Expected O, but got Unknown
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Expected O, but got Unknown
			if (BundlePrefabCache.TryGetValue(cacheKey, out var value) && (Object)value != (Object)null)
			{
				return value;
			}
			if ((Object)bundle == (Object)null)
			{
				return null;
			}
			value = bundle.LoadAsset<GameObject>(assetPath);
			if ((Object)value != (Object)null)
			{
				BundlePrefabCache[cacheKey] = value;
			}
			return value;
		}

		private static Sprite LoadBundleSprite(AssetBundle bundle, string cacheKey, string assetPath)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Expected O, but got Unknown
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Expected O, but got Unknown
			if (BundleSpriteCache.TryGetValue(cacheKey, out var value) && (Object)value != (Object)null)
			{
				return value;
			}
			if ((Object)bundle == (Object)null)
			{
				return null;
			}
			value = bundle.LoadAsset<Sprite>(assetPath);
			if ((Object)value != (Object)null)
			{
				BundleSpriteCache[cacheKey] = value;
			}
			return value;
		}

		public static void Register()
		{
			if (_registered)
			{
				return;
			}
			_registered = true;
			PrefabManager.OnVanillaPrefabsAvailable -= Register;
			ConfigFile modConfig = Plugin.ModConfig;
			bool saveOnConfigSet = modConfig != null && modConfig.SaveOnConfigSet;
			if (modConfig != null)
			{
				modConfig.SaveOnConfigSet = false;
			}
			Stopwatch stopwatch = Stopwatch.StartNew();
			try
			{
				Plugin.Log.LogInfo((object)"Starting faction registration with configuration saves batched.");
				if (RegisterLoadedAssets())
				{
					GearSettings.CompleteStatDefaultMigration();
					stopwatch.Stop();
					Plugin.Log.LogInfo((object)$"Faction item registration completed in {stopwatch.Elapsed.TotalSeconds:F1} seconds.");
					if (modConfig != null)
					{
						Stopwatch stopwatch2 = Stopwatch.StartNew();
						modConfig.Save();
						stopwatch2.Stop();
						Plugin.Log.LogInfo((object)$"Saved {modConfig.Count} configuration entries once in {stopwatch2.Elapsed.TotalSeconds:F1} seconds.");
					}
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogError((object)("Faction startup failed: " + ex));
			}
			finally
			{
				if (modConfig != null)
				{
					modConfig.SaveOnConfigSet = saveOnConfigSet;
				}
			}
		}

		private static bool RegisterLoadedAssets()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Expected O, but got Unknown
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Expected O, but got Unknown
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Expected O, but got Unknown
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Expected O, but got Unknown
			//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b3: Expected O, but got Unknown
			if ((Object)_bundle == (Object)null)
			{
				_bundle = LoadBundle();
			}
			if ((Object)_bjornheimBundle == (Object)null)
			{
				_bjornheimBundle = LoadEmbeddedBundle(".Assets.factionweapons", out _bjornheimBundleStream);
			}
			if ((Object)_bundle == (Object)null)
			{
				Plugin.Log.LogError((object)"Could not load the embedded faction armor bundle.");
				return false;
			}
			int num = 0;
			Gear[] gearSet = GearSet;
			foreach (Gear gear in gearSet)
			{
				GameObject val = LoadBundlePrefab(_bundle, "armor:" + gear.Prefab, gear.Prefab);
				if ((Object)val == (Object)null)
				{
					Plugin.Log.LogWarning((object)("Armor asset '" + gear.Prefab + "' is missing from the bundle."));
					continue;
				}
				ItemDrop component = val.GetComponent<ItemDrop>();
				if ((Object)component == (Object)null)
				{
					Plugin.Log.LogWarning((object)("Armor asset '" + gear.Prefab + "' has no ItemDrop component."));
					continue;
				}
				ApplyArmorStats(component, gear.Body);
				GearSettings.ApplyStats(component, gear.Prefab);
				if (gear.Prefab == "ArmorHoundsChest")
				{
					ApplyVanillaBodyMaterial(component, "ArmorMageChest_Ashlands", "_ChestTex");
				}
				else if (gear.Prefab == "ArmorHoundsLegs")
				{
					ApplyVanillaBodyMaterial(component, "ArmorMageLegs_Ashlands", "_LegsTex");
				}
				ItemConfig val2 = CreateConfig(gear);
				GearSettings.ReplaceFactionIdol(val2, gear.Prefab, deerHide: false);
				GearSettings.BindRecipe(val2, gear.Prefab);
				ItemManager.Instance.AddItem(new CustomItem(val, true, val2));
				num++;
			}
			num += RegisterAshMageArmor();
			num += RegisterCapeStyles();
			int num2 = RegisterBjornheimWeapons();
			int num3 = RegisterBjornheimResources();
			int num4 = RegisterBjornheimPieces();
			int num5 = RegisterFactionBanners();
			int num6 = FactionMeads.Register();
			RegisterShieldStyles();
			Plugin.Log.LogInfo((object)$"Registered {num} faction armor and cape items, {num2} Bjornheim weapons, {num3} Bjornheim resources, {num4} Bjornheim forge pieces, {num5} banners, {num6} new mead items, and six shield style sets.");
			return true;
		}

		private static AssetBundle LoadBundle()
		{
			return LoadEmbeddedBundle(".Assets.factionarmors", out _bundleStream);
		}

		private static AssetBundle LoadEmbeddedBundle(string resourceSuffix, out Stream retainedStream)
		{
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Expected O, but got Unknown
			retainedStream = null;
			Assembly assembly = typeof(GearRegistrar).Assembly;
			string text = assembly.GetManifestResourceNames().FirstOrDefault((string name) => name.EndsWith(resourceSuffix, StringComparison.OrdinalIgnoreCase));
			if (text == null)
			{
				Plugin.Log.LogError((object)("Embedded resource '" + resourceSuffix + "' was not found."));
				return null;
			}
			Stream manifestResourceStream = assembly.GetManifestResourceStream(text);
			if (manifestResourceStream == null)
			{
				return null;
			}
			try
			{
				Stopwatch stopwatch = Stopwatch.StartNew();
				AssetBundle val = AssetBundle.LoadFromStream(manifestResourceStream, 0u, 1048576u);
				if ((Object)val == (Object)null)
				{
					manifestResourceStream.Dispose();
					return null;
				}
				retainedStream = manifestResourceStream;
				stopwatch.Stop();
				Plugin.Log.LogInfo((object)$"Opened embedded bundle '{resourceSuffix}' in {stopwatch.Elapsed.TotalSeconds:F1} seconds.");
				return val;
			}
			catch
			{
				manifestResourceStream.Dispose();
				throw;
			}
		}

		private static int RegisterBjornheimWeapons()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Expected O, but got Unknown
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Expected O, but got Unknown
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: 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_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Expected O, but got Unknown
			//IL_0195: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: Expected O, but got Unknown
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Expected O, but got Unknown
			if ((Object)_bjornheimBundle == (Object)null)
			{
				Plugin.Log.LogError((object)"Could not load the embedded Bjornheim weapon bundle.");
				return 0;
			}
			int num = RegisterBjornheimEffects();
			int num2 = 0;
			string[] bjornheimWeaponPrefabs = BjornheimWeaponPrefabs;
			foreach (string text in bjornheimWeaponPrefabs)
			{
				string text2 = "Assets/Custom/Comission/FactionWeapons/Weapons/" + text + ".prefab";
				GameObject val = LoadBundlePrefab(_bjornheimBundle, "weapons:" + text2, text2);
				if ((Object)val == (Object)null)
				{
					Plugin.Log.LogWarning((object)("Bjornheim weapon prefab '" + text + "' was not found in the bundle."));
					continue;
				}
				if ((Object)val.GetComponent<ItemDrop>() == (Object)null)
				{
					Plugin.Log.LogWarning((object)("Bjornheim weapon prefab '" + text + "' has no ItemDrop component."));
					continue;
				}
				val.SetActive(true);
				ApplyBjornheimWeaponAppearance(text, val);
				ItemConfig val2 = new ItemConfig
				{
					Name = BjornheimDisplayName(text),
					Description = "A recovered Bjornheim faction weapon.",
					Enabled = false
				};
				string text3 = ((!(text == "Blidhr_base_bal")) ? ((text == "Blidhr_bal") ? "bladhir_ico.png" : null) : "bladhir_base_ico.png");
				if (text3 != null)
				{
					Sprite val3 = LoadSprite("BjornheimArtifacts", text3);
					if ((Object)val3 != (Object)null)
					{
						val2.Icon = val3;
					}
				}
				ApplyWeaponRecipe(text, val2);
				ApplyFactionWeaponBalance(val.GetComponent<ItemDrop>(), text);
				GearSettings.ApplyStats(val.GetComponent<ItemDrop>(), text);
				GearSettings.BindRecipe(val2, text);
				ItemManager.Instance.AddItem(new CustomItem(val, true, val2));
				num2++;
			}
			Plugin.Log.LogInfo((object)$"Registered {num2} Bjornheim weapon items and loaded {num} weapon effect prefabs.");
			return num2;
		}

		private static void ApplyFactionWeaponBalance(ItemDrop drop, string prefabName)
		{
			SharedData val = drop?.m_itemData?.m_shared;
			if (val != null)
			{
				switch (prefabName)
				{
				case "HoundsScythe":
					val.m_damagesPerLevel.m_slash = 8f;
					val.m_damagesPerLevel.m_poison = 5f;
					val.m_damagesPerLevel.m_spirit = 5f;
					SetFactionWeaponStamina(val, 14f);
					break;
				case "Blidhr_bal":
					val.m_damagesPerLevel.m_slash = 8f;
					val.m_damagesPerLevel.m_fire = 5f;
					SetFactionWeaponStamina(val, 14f);
					break;
				case "Gugnir_bal":
					val.m_damagesPerLevel.m_pierce = 8f;
					val.m_damagesPerLevel.m_lightning = 7f;
					break;
				case "FenrirSword_bal":
					val.m_damages.m_slash = 100f;
					val.m_damagesPerLevel.m_slash = 7f;
					val.m_damagesPerLevel.m_frost = 7f;
					break;
				}
			}
		}

		private static void SetFactionWeaponStamina(SharedData shared, float stamina)
		{
			if (shared.m_attack != null)
			{
				shared.m_attack.m_attackStamina = stamina;
			}
			if (shared.m_secondaryAttack != null && Mathf.Approximately(shared.m_secondaryAttack.m_attackStamina, 18f))
			{
				shared.m_secondaryAttack.m_attackStamina = stamina;
			}
		}

		private static int RegisterBjornheimResources()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Expected O, but got Unknown
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Expected O, but got Unknown
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Expected O, but got Unknown
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Expected O, but got Unknown
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Expected O, but got Unknown
			if ((Object)_bjornheimBundle == (Object)null)
			{
				return 0;
			}
			int num = 0;
			string[] bjornheimResourcePrefabs = BjornheimResourcePrefabs;
			foreach (string text in bjornheimResourcePrefabs)
			{
				string text2 = "Assets/Custom/Comission/FactionWeapons/Resources/" + text + ".prefab";
				GameObject val = LoadBundlePrefab(_bjornheimBundle, "weapons:" + text2, text2);
				if ((Object)val == (Object)null)
				{
					Plugin.Log.LogWarning((object)("Bjornheim resource prefab '" + text + "' was not found in the bundle."));
					continue;
				}
				ItemDrop component = val.GetComponent<ItemDrop>();
				if ((Object)component == (Object)null)
				{
					Plugin.Log.LogWarning((object)("Bjornheim resource prefab '" + text + "' has no ItemDrop component."));
					continue;
				}
				val.SetActive(true);
				ItemConfig val2 = new ItemConfig
				{
					Name = BjornheimDisplayName(text),
					Description = "A recovered Bjornheim crafting material.",
					Enabled = false
				};
				ApplyResourceRecipe(text, val2);
				GearSettings.ApplyStats(component, text);
				GearSettings.BindRecipe(val2, text);
				ItemManager.Instance.AddItem(new CustomItem(val, true, val2));
				if (text == "MediumSpiritPotion_bal" || text == "MediumThunderPotion_bal")
				{
					StatusEffect consumeStatusEffect = component.m_itemData.m_shared.m_consumeStatusEffect;
					if ((Object)consumeStatusEffect != (Object)null && !_bjornheimStatusEffects.Contains(consumeStatusEffect))
					{
						_bjornheimStatusEffects.Add(consumeStatusEffect);
					}
				}
				num++;
			}
			_spiritIcon = LoadBundleSprite(_bjornheimBundle, "weapons:Assets/Custom/Comission/FactionWeapons/ico/spiritburn1.png", "Assets/Custom/Comission/FactionWeapons/ico/spiritburn1.png");
			return num;
		}

		private static int RegisterBjornheimPieces()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Expected O, but got Unknown
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Expected O, but got Unknown
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Expected O, but got Unknown
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Expected O, but got Unknown
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Expected O, but got Unknown
			if ((Object)_bjornheimBundle == (Object)null)
			{
				return 0;
			}
			int num = 0;
			string[] bjornheimPiecePrefabs = BjornheimPiecePrefabs;
			foreach (string text in bjornheimPiecePrefabs)
			{
				string text2 = "Assets/Custom/Comission/FactionWeapons/Pieces/" + text + ".prefab";
				GameObject val = LoadBundlePrefab(_bjornheimBundle, "weapons:" + text2, text2);
				if ((Object)val == (Object)null || (Object)val.GetComponent<Piece>() == (Object)null)
				{
					Plugin.Log.LogWarning((object)("Bjornheim forge piece '" + text + "' was missing or had no Piece component."));
					continue;
				}
				val.SetActive(true);
				PieceConfig val2 = new PieceConfig();
				val2.Name = BjornheimPieceDisplayName(text);
				val2.Description = "A recovered Bjornheim forge structure.";
				val2.PieceTable = "Hammer";
				val2.Requirements = (RequirementConfig[])(object)new RequirementConfig[1]
				{
					new RequirementConfig("SwordCheat", 1, 0, true)
				};
				PieceConfig val3 = val2;
				GearSettings.BindPieceRecipe(val3, text);
				PieceManager.Instance.AddPiece(new CustomPiece(val, true, val3));
				num++;
			}
			return num;
		}

		private static int RegisterBjornheimEffects()
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Expected O, but got Unknown
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			int num = 0;
			string[] bjornheimEffectPrefabs = BjornheimEffectPrefabs;
			foreach (string text in bjornheimEffectPrefabs)
			{
				string text2 = "Assets/Custom/Comission/FactionWeapons/Objects/" + text + ".prefab";
				GameObject val = LoadBundlePrefab(_bjornheimBundle, "weapons:" + text2, text2);
				if ((Object)val == (Object)null)
				{
					Plugin.Log.LogWarning((object)("Bjornheim weapon effect '" + text + "' was not found in the bundle."));
					continue;
				}
				val.SetActive(true);
				if (text == "Wave_Ground" || text == "vfx_spiritbolt_explosion")
				{
					RecolorWeaponParticles(val.transform, new Color(0f, 0.64f, 1f));
				}
				PrefabManager.Instance.AddPrefab(val);
				num++;
			}
			return num;
		}

		private static string BjornheimDisplayName(string prefabName)
		{
			return prefabName switch
			{
				"Blidhr_bal" => "Warden of Sea", 
				"Blidhr_base_bal" => "Salt Rune Axe", 
				"BowRazorStrikes" => "Bow of Razor Strikes", 
				"FenrirSword_bal" => "Fenrir Sword", 
				"FenrirSword_base_bal" => "Fenrir Sword (Base)", 
				"Gugnir_bal" => "Gugnir", 
				"Gugnir_base_bal" => "Spear of Penitents", 
				"HoundsSycle" => "Hounds Scythe (Base)", 
				"HoundsScythe" => "Hounds Scythe", 
				"AcidSludge_bal" => "Acid Sludge", 
				"Amethyst_bal" => "Amethyst", 
				"AmethystSteel" => "Amethyst Steel", 
				"BlackTissue" => "Black Tissue", 
				"Bloodsteel" => "Bloodsteel", 
				"DarkSteel" => "Dark Steel", 
				"DvergrHeart" => "Dvergr Heart", 
				"Electrum" => "Electrum", 
				"Frosteel" => "Frosteel", 
				"GjallCore_bal" => "Gjall Core", 
				"GoldBar" => "Gold Bar", 
				"SeedFrost_bal" => "Frost Seed", 
				"SeekerBruteBlood" => "Seeker Brute Blood", 
				"MeadBaseLightingResistMedium_bal" => "Mead Base: Lightning Resistance", 
				"MeadBaseSpiritResistMedium_bal" => "Mead Base: Spirit Resistance", 
				"MediumSpiritPotion_bal" => "Medium Spirit Potion", 
				"MediumThunderPotion_bal" => "Medium Thunder Potion", 
				"DraugrInsygnia" => "Draugr Insignia", 
				"QueenCore" => "Queen Core", 
				_ => prefabName, 
			};
		}

		private static string BjornheimPieceDisplayName(string prefabName)
		{
			return prefabName switch
			{
				"SacredForge" => "Sacred Forge", 
				"sacredforge_ext1" => "Sacred Forge Extension I", 
				"sacredforge_ext2" => "Sacred Forge Extension II", 
				"sacredforge_ext3" => "Sacred Forge Extension III", 
				"GrandForgeV2" => "Grand Forge", 
				_ => prefabName, 
			};
		}

		private static void ApplyWeaponRecipe(string prefabName, ItemConfig config)
		{
			if (prefabName == null)
			{
				return;
			}
			switch (prefabName.Length)
			{
			case 15:
				switch (prefabName[1])
				{
				case 'l':
					if (prefabName == "Blidhr_base_bal")
					{
						SetRecipe(config, "forge", 3, ("DarkSteel", 10, 5), ("ElderBark", 10, 2), ("Silver", 10, 2), ("AncientSeed", 15, 6));
					}
					break;
				case 'o':
					if (prefabName == "BowRazorStrikes")
					{
						SetRecipe(config, "piece_workbench", 1, ("Electrum", 15, 5), ("Eitr", 30, 2), ("MediumSpiritPotion_bal", 5, 2));
					}
					break;
				case 'e':
					if (prefabName == "FenrirSword_bal")
					{
						SetRecipe(config, "SacredForge", 1, ("FenrirSword_base_bal", 1, 0), ("Frosteel", 8, 4), ("SeedFrost_bal", 20, 10), ("Crystal", 20, 10));
					}
					break;
				case 'u':
					if (prefabName == "Gugnir_base_bal")
					{
						SetRecipe(config, "forge", 3, ("DarkSteel", 10, 5), ("ElderBark", 10, 2), ("Silver", 10, 2), ("MushroomYellow", 20, 5));
					}
					break;
				}
				break;
			case 10:
				switch (prefabName[0])
				{
				case 'B':
					if (prefabName == "Blidhr_bal")
					{
						SetRecipe(config, "SacredForge", 1, ("Blidhr_base_bal", 1, 0), ("AmethystSteel", 8, 4), ("AcidSludge_bal", 20, 10), ("YmirRemains", 20, 10));
					}
					break;
				case 'G':
					if (prefabName == "Gugnir_bal")
					{
						SetRecipe(config, "SacredForge", 1, ("Gugnir_base_bal", 1, 0), ("Electrum", 8, 4), ("GoldBar", 20, 10), ("Thunderstone", 20, 10));
					}
					break;
				}
				break;
			case 20:
				if (prefabName == "FenrirSword_base_bal")
				{
					SetRecipe(config, "forge", 3, ("DarkSteel", 10, 5), ("ElderBark", 10, 2), ("Silver", 10, 2), ("WolfPelt", 10, 2));
				}
				break;
			case 11:
				if (prefabName == "HoundsSycle")
				{
					SetRecipe(config, "forge", 3, ("DarkSteel", 10, 5), ("ElderBark", 10, 2), ("Silver", 10, 2), ("Bloodbag", 15, 6));
				}
				break;
			case 12:
				if (prefabName == "HoundsScythe")
				{
					SetRecipe(config, "SacredForge", 1, ("HoundsSycle", 1, 0), ("Bloodsteel", 8, 4), ("BlackTissue", 20, 10), ("SurtlingCore", 20, 10));
				}
				break;
			}
		}

		private static void ApplyResourceRecipe(string prefabName, ItemConfig config)
		{
			if (prefabName == null)
			{
				return;
			}
			switch (prefabName.Length)
			{
			case 8:
				switch (prefabName[0])
				{
				case 'E':
					if (prefabName == "Electrum")
					{
						SetRecipe(config, "SacredForge", 1, ("FlametalNew", 4, 0), ("DarkSteel", 3, 0), ("GjallCore_bal", 5, 0), ("Coal", 8, 0));
					}
					break;
				case 'F':
					if (prefabName == "Frosteel")
					{
						SetRecipe(config, "SacredForge", 1, ("FlametalNew", 4, 0), ("DarkSteel", 3, 0), ("SeedFrost_bal", 5, 0), ("Coal", 8, 0));
					}
					break;
				}
				break;
			case 7:
				if (prefabName == "GoldBar")
				{
					SetRecipe(config, "forge", 5, ("Coins", 999, 0), ("Coal", 10, 0));
				}
				break;
			case 10:
				if (prefabName == "Bloodsteel")
				{
					SetRecipe(config, "SacredForge", 1, ("FlametalNew", 4, 0), ("DarkSteel", 3, 0), ("SeekerBruteBlood", 5, 0), ("Coal", 8, 0));
				}
				break;
			case 9:
				if (prefabName == "DarkSteel")
				{
					SetRecipe(config, "forge", 3, ("Iron", 3, 0), ("Obsidian", 6, 0), ("Coal", 5, 0));
				}
				break;
			case 13:
				if (prefabName == "AmethystSteel")
				{
					SetRecipe(config, "SacredForge", 1, ("FlametalNew", 4, 0), ("DarkSteel", 3, 0), ("Amethyst_bal", 5, 0), ("Coal", 8, 0));
				}
				break;
			case 32:
				if (prefabName == "MeadBaseLightingResistMedium_bal")
				{
					SetRecipe(config, "piece_cauldron", 2, ("Thunderstone", 3, 0), ("Thistle", 5, 0), ("GreydwarfEye", 25, 0), ("TrophyFrostTroll", 2, 0));
				}
				break;
			case 30:
				if (prefabName == "MeadBaseSpiritResistMedium_bal")
				{
					SetRecipe(config, "piece_cauldron", 2, ("DraugrInsygnia", 6, 0), ("Honey", 10, 0), ("Bloodbag", 4, 0), ("TrophyGreydwarfShaman", 2, 0));
				}
				break;
			}
		}

		private static void SetRecipe(ItemConfig config, string station, int stationLevel, params (string prefab, int amount, int perLevel)[] requirements)
		{
			config.Enabled = true;
			config.CraftingStation = station;
			config.RepairStation = station;
			config.MinStationLevel = stationLevel;
			for (int i = 0; i < requirements.Length; i++)
			{
				(string, int, int) tuple = requirements[i];
				config.AddRequirement(tuple.Item1, tuple.Item2, tuple.Item3);
			}
		}

		private static void ApplyBjornheimWeaponAppearance(string prefabName, GameObject prefab)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Expected O, but got Unknown
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			if (prefabName == "Blidhr_bal" || prefabName == "Blidhr_base_bal")
			{
				RecolorWeaponParticles(prefab.transform, new Color(0f, 0.64f, 1f));
			}
			string text = ((!(prefabName == "Blidhr_base_bal")) ? ((prefabName == "Blidhr_bal") ? "RuneRock_1" : null) : "RuneRock_3 (1)");
			if (text == null)
			{
				return;
			}
			Transform val = FindChild(prefab.transform, text);
			if ((Object)val == (Object)null)
			{
				return;
			}
			Renderer[] components = ((Component)val).GetComponents<Renderer>();
			for (int i = 0; i < components.Length; i++)
			{
				Material[] materials = components[i].materials;
				foreach (Material val2 in materials)
				{
					if (val2.HasProperty("_EmissionColor"))
					{
						val2.SetColor("_EmissionColor", new Color(0f, 0.6f, 1f));
					}
				}
			}
		}

		private static void RecolorWeaponParticles(Transform parent, Color color)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Expected O, but got Unknown
			//IL_0016: 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)
			//IL_001e: 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_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: 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_003b: 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_0053: Unknown result type (might be due to invalid IL or missing references)
			ParticleSystem component = ((Component)parent).GetComponent<ParticleSystem>();
			if ((Object)component != (Object)null)
			{
				MainModule main = component.main;
				MinMaxGradient startColor = ((MainModule)(ref main)).startColor;
				Color color2 = ((MinMaxGradient)(ref startColor)).color;
				color.a = color2.a;
				((MainModule)(ref main)).startColor = MinMaxGradient.op_Implicit(color);
			}
			for (int i = 0; i < parent.childCount; i++)
			{
				RecolorWeaponParticles(parent.GetChild(i), color);
			}
		}

		private static Transform FindChild(Transform parent, string childName)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Expected O, but got Unknown
			for (int i = 0; i < parent.childCount; i++)
			{
				Transform child = parent.GetChild(i);
				if (((Object)child).name == childName)
				{
					return child;
				}
				Transform val = FindChild(child, childName);
				if ((Object)val != (Object)null)
				{
					return val;
				}
			}
			return null;
		}

		private static ItemConfig CreateConfig(Gear gear)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: 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_0042: 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)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Expected O, but got Unknown
			ItemConfig val = new ItemConfig
			{
				Name = GearSettings.DisplayName(gear.Prefab, gear.DisplayName),
				Description = GearSettings.Description(gear.Prefab, "Faction armor: " + gear.DisplayName + "."),
				CraftingStation = "forge",
				RepairStation = "forge",
				MinStationLevel = 2
			};
			for (int i = 0; i < gear.Cost.Length; i++)
			{
				if (gear.Cost[i] > 0)
				{
					val.AddRequirement(AshlandsMaterials[i], gear.Cost[i], 0);
				}
			}
			return val;
		}

		private static int RegisterAshMageArmor()
		{
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Expected O, but got Unknown
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Expected O, but got Unknown
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Expected O, but got Unknown
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Expected O, but got Unknown
			//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ae: Expected O, but got Unknown
			int num = 0;
			string[] array = new string[4] { "Drage", "Fenrir", "Freyr", "Hounds" };
			string[] array2 = new string[3] { "HelmetMage_Ashlands", "ArmorMageChest_Ashlands", "ArmorMageLegs_Ashlands" };
			string[] array3 = new string[3] { "Helmet", "Chest", "Legs" };
			ItemDrop sourceDrop = null;
			for (int i = 0; i < array2.Length; i++)
			{
				GameObject vanillaPrefab = GetVanillaPrefab(array2[i]);
				if ((Object)vanillaPrefab == (Object)null || !vanillaPrefab.TryGetComponent<ItemDrop>(ref sourceDrop))
				{
					Plugin.Log.LogWarning((object)("Could not find vanilla armor prefab '" + array2[i] + "'; skipping recolored mage armor."));
					continue;
				}
				string[] array4 = array;
				foreach (string text in array4)
				{
					string fileName = text + array3[i] + "_Icon.png";
					Texture2D val = LoadTexture("AshMage", text + "Tex.png");
					Sprite val2 = LoadSprite("AshMage", fileName);
					if (!((Object)val == (Object)null) && !((Object)val2 == (Object)null))
					{
						string text2 = text + array3[i];
						GameObject val3 = Object.Instantiate<GameObject>(vanillaPrefab, Plugin.PrefabRoot.transform, false);
						((Object)val3).name = text2;
						SetArmorTexture(val3, (Texture)val);
						ItemConfig val4 = CreateClonedItemConfig(sourceDrop, text2, val2);
						GearSettings.ReplaceFactionIdol(val4, text2, deerHide: false, logMissing: true);
						ApplyFactionArmorDefaults(val3.GetComponent<ItemDrop>());
						GearSettings.ApplyStats(val3.GetComponent<ItemDrop>(), text2);
						GearSettings.BindRecipe(val4, text2);
						ItemManager.Instance.AddItem(new CustomItem(val3, true, val4));
						num++;
					}
				}
			}
			return num;
		}

		private static int RegisterCapeStyles()
		{
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Expected O, but got Unknown
			//IL_0107: 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_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_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c2: Expected O, but got Unknown
			//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d4: Expected O, but got Unknown
			//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0202: Expected O, but got Unknown
			//IL_020f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0204: 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_021a: Unknown result type (might be due to invalid IL or missing references)
			//IL_021f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0226: Expected O, but got Unknown
			//IL_0273: Unknown result type (might be due to invalid IL or missing references)
			//IL_027d: Expected O, but got Unknown
			int num = 0;
			num += RegisterTexturedCapes("CapeLox", "CapeLox", new string[4] { "CapeLoxDragemesters", "CapeLoxFenrir", "CapeLoxFreyr", "CapeLoxHounds" }, deerHide: false);
			num += RegisterTexturedCapes("CapeAsh", "CapeAsh", new string[4] { "DrageAsh", "FenrirAsh", "FreyrAsh", "HoundsAsh" }, deerHide: false);
			num += RegisterTexturedCapes("CapeDeerHide", "CapeDeer", new string[4] { "CapeDeerHideDragemesters", "CapeDeerHideFenrir", "CapeDeerHideFreyr", "CapeDeerHideHounds" }, deerHide: true);
			GameObject vanillaPrefab = GetVanillaPrefab("CapeFeather");
			ItemDrop sourceDrop = null;
			if ((Object)vanillaPrefab != (Object)null && vanillaPrefab.TryGetComponent<ItemDrop>(ref sourceDrop))
			{
				string[] array = new string[4] { "Fenrir", "Dragemesters", "Freyr", "Hounds" };
				Color[] array2 = (Color[])(object)new Color[4]
				{
					Color.white,
					Color.yellow,
					new Color(0.12f, 0.28f, 0.88f, 1f),
					Color.red
				};
				Texture2D val = LoadTexture("CapeFeather", "CapeFeatherFenrir.png");
				for (int i = 0; i < array.Length; i++)
				{
					string text = "CapeFeathers" + array[i];
					Sprite val2 = LoadSprite("CapeFeather", text + "_Icon.png");
					Texture2D val3 = LoadTexture("CapeFeather", "CapeFeather" + array[i] + ".png");
					Texture2D val4 = val3 ?? val;
					if (!((Object)val4 == (Object)null) && !((Object)val2 == (Object)null))
					{
						GameObject val5 = Object.Instantiate<GameObject>(vanillaPrefab, Plugin.PrefabRoot.transform, false);
						((Object)val5).name = text;
						Color color = (((Object)val3 == (Object)null) ? array2[i] : Color.white);
						SetCapeAppearance(val5, (Texture)val4, color);
						string name = ((Object)val5).name;
						ItemConfig val6 = CreateClonedItemConfig(sourceDrop, name, val2);
						GearSettings.ReplaceFactionIdol(val6, name, deerHide: false, logMissing: true);
						ApplyFactionArmorDefaults(val5.GetComponent<ItemDrop>());
						GearSettings.ApplyStats(val5.GetComponent<ItemDrop>(), name);
						GearSettings.BindRecipe(val6, name);
						ItemManager.Instance.AddItem(new CustomItem(val5, true, val6));
						num++;
					}
				}
			}
			return num;
		}

		private static int RegisterTexturedCapes(string sourceName, string folder, string[] names, bool deerHide)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Expected O, but got Unknown
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Expected O, but got Unknown
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Expected O, but got Unknown
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Expected O, but got Unknown
			//IL_0160: 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_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Expected O, but got Unknown
			//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b8: Expected O, but got Unknown
			GameObject vanillaPrefab = GetVanillaPrefab(sourceName);
			ItemDrop sourceDrop = null;
			if ((Object)vanillaPrefab == (Object)null || !vanillaPrefab.TryGetComponent<ItemDrop>(ref sourceDrop))
			{
				Plugin.Log.LogWarning((object)("Could not find vanilla cape prefab '" + sourceName + "'."));
				return 0;
			}
			int num = 0;
			foreach (string text in names)
			{
				string fileName = text + "_Icon.png";
				if (deerHide)
				{
					fileName = text + ".png";
				}
				else if (folder == "CapeAsh")
				{
					fileName = text.Replace("Ash", "_Ash") + "_Icon.png";
				}
				string text2 = text + ".png";
				if (deerHide)
				{
					text2 = null;
				}
				else if (folder == "CapeAsh")
				{
					text2 = text.Replace("Ash", "_Ash") + ".png";
				}
				Sprite val = LoadSprite(folder, fileName);
				Texture2D val2 = ((text2 == null) ? null : LoadTexture(folder, text2));
				if (!((Object)val == (Object)null) && (deerHide || !((Object)val2 == (Object)null)))
				{
					GameObject val3 = Object.Instantiate<GameObject>(vanillaPrefab, Plugin.PrefabRoot.transform, false);
					((Object)val3).name = text;
					if ((Object)val2 != (Object)null)
					{
						SetCapeAppearance(val3, (Texture)val2, Color.white);
					}
					else
					{
						SetCapeTint(val3, GetFactionColor(text));
					}
					ItemConfig val4 = CreateClonedItemConfig(sourceDrop, text, val);
					GearSettings.ReplaceFactionIdol(val4, text, deerHide, logMissing: true);
					ApplyFactionArmorDefaults(val3.GetComponent<ItemDrop>());
					GearSettings.ApplyStats(val3.GetComponent<ItemDrop>(), text);
					GearSettings.BindRecipe(val4, text);
					ItemManager.Instance.AddItem(new CustomItem(val3, true, val4));
					num++;
				}
			}
			return num;
		}

		private static int RegisterFactionBanners()
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Expected O, but got Unknown
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Expected O, but got Unknown
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Expected O, but got Unknown
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Expected O, but got Unknown
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: 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_0133: 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_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Expected O, but got Unknown
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Expected O, but got Unknown
			GameObject vanillaPrefab = GetVanillaPrefab("piece_banner01");
			Piece val = null;
			if ((Object)vanillaPrefab == (Object)null || !vanillaPrefab.TryGetComponent<Piece>(ref val))
			{
				Plugin.Log.LogWarning((object)"Could not find vanilla banner piece; faction banners were skipped.");
				return 0;
			}
			int num = 0;
			string[] array = new string[5] { "Dragemesters", "Fenrir", "Freyr", "Hounds", "Server" };
			foreach (string text in array)
			{
				string text2 = "Banner" + text;
				Texture2D val2 = LoadTexture("Banners", text2 + ".png");
				Sprite val3 = LoadSprite("Banners", text2 + "_Icon.png");
				if (!((Object)val2 == (Object)null) && !((Object)val3 == (Object)null))
				{
					GameObject val4 = Object.Instantiate<GameObject>(vanillaPrefab, Plugin.PrefabRoot.transform, false);
					((Object)val4).name = text2;
					SetBannerTexture(val4, (Texture)val2);
					PieceConfig val5 = new PieceConfig
					{
						Name = GearSettings.DisplayName(text2, text2),
						Description = GearSettings.Description(text2, "The " + text + " faction banner."),
						PieceTable = "Hammer",
						Icon = val3,
						Requirements = CopyRequirements(val.m_resources)
					};
					GearSettings.BindPieceRecipe(val5, text2);
					PieceManager.Instance.AddPiece(new CustomPiece(val4, true, val5));
					num++;
				}
			}
			return num;
		}

		private static void RegisterShieldStyles()
		{
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Expected O, but got Unknown
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Expected O, but got Unknown
			//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b6: Expected O, but got Unknown
			//IL_0211: Unknown result type (might be due to invalid IL or missing references)
			//IL_021c: Expected O, but got Unknown
			//IL_0222: Unknown result type (might be due to invalid IL or missing references)
			//IL_022c: Expected O, but got Unknown
			string[] array = new string[6] { "ShieldBanded", "ShieldWood", "ShieldBlackmetal", "ShieldBlackmetalTower", "ShieldFlametal", "ShieldFlametalTower" };
			string[] array2 = new string[6] { "BandedShieldIcons", "WoodShieldIcons", "BlackmetalShieldIcons", "BlackmetalTowerShieldIcons", "FlametalShieldIcons", "FlametalTowerShieldIcons" };
			string[] array3 = new string[6] { "ShieldPaint_WoodBanded.png", "ShieldPaint_WoodBanded.png", "ShieldPaint_BlackMetal.png", "ShieldPaint_BlackMetal.png", "ShieldPaint_Flametal.png", "ShieldPaint_FlametalTower.png" };
			string[] array4 = new string[4] { "Hounds", "Freyr", "Fenrir", "Dragemesters" };
			ItemDrop val = null;
			for (int i = 0; i < array.Length; i++)
			{
				GameObject vanillaPrefab = GetVanillaPrefab(array[i]);
				if ((Object)vanillaPrefab == (Object)null || !vanillaPrefab.TryGetComponent<ItemDrop>(ref val))
				{
					Plugin.Log.LogWarning((object)("Could not find shield prefab '" + array[i] + "'."));
					continue;
				}
				List<Sprite> list = val.m_itemData.m_shared.m_icons.ToList();
				if (array[i].StartsWith("ShieldFlametal", StringComparison.Ordinal))
				{
					Sprite val2 = LoadSprite("misc", "IronGate_logo.png");
					if ((Object)val2 != (Object)null)
					{
						list.Add(val2);
					}
				}
				string[] array5 = array4;
				foreach (string text in array5)
				{
					Sprite val3 = LoadSprite(array2[i], array2[i].Replace("Icons", "") + text + "_Icon.png");
					if ((Object)val3 != (Object)null)
					{
						list.Add(val3);
					}
				}
				val.m_itemData.m_shared.m_icons = list.ToArray();
				val.m_itemData.m_shared.m_variants = list.Count;
				Texture2D val4 = LoadTexture("ShieldPaints", array3[i]);
				if ((Object)val4 != (Object)null)
				{
					SetShieldPaint(vanillaPrefab, (Texture)val4);
				}
			}
		}

		private static GameObject GetVanillaPrefab(string prefabName)
		{
			return PrefabManager.Instance.GetPrefab(prefabName);
		}

		internal static ItemConfig CreateClonedItemConfig(ItemDrop sourceDrop, string name, Sprite icon)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: 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_0036: Expected O, but got Unknown
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Expected O, but got Unknown
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Expected O, but got Unknown
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Expected O, but got Unknown
			ItemConfig val = new ItemConfig
			{
				Name = GearSettings.DisplayName(name, name),
				Description = GearSettings.Description(name, "Faction gear: " + name + "."),
				Icon = icon
			};
			ObjectDB menuObjectDatabase = GetMenuObjectDatabase();
			Recipe val2 = (((Object)menuObjectDatabase == (Object)null) ? null : menuObjectDatabase.GetRecipe(sourceDrop.m_itemData));
			if ((Object)val2 == (Object)null)
			{
				val.Enabled = false;
				return val;
			}
			val.CraftingStation = (((Object)val2.m_craftingStation == (Object)null) ? null : ((Object)val2.m_craftingStation).name);
			val.RepairStation = val.CraftingStation;
			val.MinStationLevel = val2.m_minStationLevel;
			val.Requirements = CopyRequirements(val2.m_resources);
			return val;
		}

		private static ObjectDB GetMenuObjectDatabase()
		{
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Expected O, but got Unknown
			object obj = typeof(PrefabManager).GetProperty("Instance", BindingFlags.Static | BindingFlags.Public)?.GetValue(null, null);
			PropertyInfo property = typeof(PrefabManager).GetProperty("MenuObjectDB", BindingFlags.Instance | BindingFlags.NonPublic);
			if (obj != null)
			{
				object obj2 = property?.GetValue(obj, null);
				return (ObjectDB)((obj2 is ObjectDB) ? obj2 : null);
			}
			return null;
		}

		private static RequirementConfig[] CopyRequirements(Requirement[] requirements)
		{
			if (requirements == null)
			{
				return (RequirementConfig[])(object)new RequirementConfig[0];
			}
			return requirements.Where((Requirement requirement) => requirement != null && (Object)requirement.m_resItem != (Object)null).Select((Func<Requirement, RequirementConfig>)((Requirement requirement) => new RequirementConfig(((Object)requirement.m_resItem).name, requirement.m_amount, requirement.m_amountPerLevel, requirement.m_recover))).ToArray();
		}

		private static Texture2D LoadTexture(string folder, string fileName)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Expected O, but got Unknown
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Expected O, but got Unknown
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			string key = folder + "/" + fileName;
			if (TextureCache.TryGetValue(key, out var value) && (Object)value != (Object)null)
			{
				return value;
			}
			byte[] array = ReadAssetBytes(folder, fileName);
			if (array == null)
			{
				return null;
			}
			bool flag = string.Equals(folder, "ShieldPaints", StringComparison.OrdinalIgnoreCase);
			Texture2D val = new Texture2D(2, 2, (TextureFormat)4, flag);
			MethodInfo methodInfo = FindLoadImage();
			if (methodInfo == null)
			{
				Plugin.Log.LogError((object)"Unity ImageConversion.LoadImage could not be located.");
				return null;
			}
			object obj = ((methodInfo.GetParameters().Length == 1) ? methodInfo.Invoke(val, new object[1] { array }) : methodInfo.Invoke(null, new object[2] { val, array }));
			if (!(obj is bool) || !(bool)obj)
			{
				return null;
			}
			if (flag)
			{
				((Texture)val).filterMode = (FilterMode)2;
				((Texture)val).anisoLevel = 8;
				val.Apply(true, false);
				Plugin.Log.LogInfo((object)($"Loaded shield paint {fileName}: {((Texture)val).width}x{((Texture)val).height}, " + $"mips={((Texture)val).mipmapCount}, filter={((Texture)val).filterMode}, aniso={((Texture)val).anisoLevel}."));
			}
			((Object)val).name = Path.GetFileNameWithoutExtension(fileName).Replace("_", "");
			LoadedTextures.Add(val);
			TextureCache[key] = val;
			return val;
		}

		internal static Sprite LoadSprite(string folder, string fileName)
		{
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Expected O, but got Unknown
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Expected O, but got Unknown
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			string key = folder + "/" + fileName;
			if (SpriteCache.TryGetValue(key, out var value) && (Object)value != (Object)null)
			{
				return value;
			}
			Texture2D val = LoadTexture(folder, fileName);
			if ((Object)val == (Object)null)
			{
				return null;
			}
			string name = Path.GetFileNameWithoutExtension(fileName).Replace("_Icon", "").Replace("_", "");
			Sprite val2 = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f));
			((Object)val2).name = name;
			LoadedSprites.Add(val2);
			SpriteCache[key] = val2;
			return val2;
		}

		private static byte[] ReadAssetBytes(string folder, string fileName)
		{
			string suffix = ".Assets." + folder + "." + fileName;
			Assembly assembly = typeof(GearRegistrar).Assembly;
			string text = assembly.GetManifestResourceNames().FirstOrDefault((string name) => name.EndsWith(suffix, StringComparison.OrdinalIgnoreCase));
			if (text == null)
			{
				Plugin.Log.LogWarning((object)("Embedded image '" + folder + "/" + fileName + "' was not found."));
				return null;
			}
			using Stream stream = assembly.GetManifestResourceStream(text);
			using MemoryStream memoryStream = new MemoryStream();
			stream.CopyTo(memoryStream);
			return memoryStream.ToArray();
		}

		private static MethodInfo FindLoadImage()
		{
			if (_loadImageMethodLookupAttempted)
			{
				return _loadImageMethod;
			}
			_loadImageMethodLookupAttempted = true;
			_loadImageMethod = typeof(Texture2D).GetMethod("LoadImage", new Type[1] { typeof(byte[]) });
			if (_loadImageMethod == null)
			{
				_loadImageMethod = Type.GetType("UnityEngine.ImageConversion, UnityEngine.ImageConversionModule")?.GetMethod("LoadImage", new Type[2]
				{
					typeof(Texture2D),
					typeof(byte[])
				});
			}
			return _loadImageMethod;
		}

		private static void SetCapeAppearance(GameObject cape, Texture texture, Color color)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			SetRendererAppearance(cape, texture, color, null, tintAll: true);
		}

		private static void SetCapeTint(GameObject cape, Color color)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			SetRendererAppearance(cape, null, color, null, tintAll: true);
		}

		private static void SetArmorTexture(GameObject prefab, Texture texture)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			SetRendererAppearance(prefab, texture, Color.white, "Custom/Creature", tintAll: false);
		}

		private static void SetBannerTexture(GameObject prefab, Texture texture)
		{
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Expected O, but got Unknown
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Expected O, but got Unknown
			int num = Shader.PropertyToID("_MainTex");
			int num2 = Shader.PropertyToID("_BaseMap");
			Renderer[] componentsInChildren = prefab.GetComponentsInChildren<Renderer>(true);
			int num3 = 0;
			for (int i = 0; i < componentsInCh