Decompiled source of GeorgianArmorSet v1.0.1

plugins/GeorgianArmorSet/GeorgianArmorSet.dll

Decompiled 5 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using HarmonyLib;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using Jotunn.Utils;
using MagicaCloth2;
using Newtonsoft.Json;
using UnityEngine;
using UnityEngine.Rendering;

[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: CompilationRelaxations(8)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace GeorgianArmorSet;

public static class DroppedItems
{
	private static GameObject Box(Transform parent, string name, Vector3 pos, Vector3 size, Material material)
	{
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = GameObject.CreatePrimitive((PrimitiveType)3);
		((Object)val).name = name;
		val.transform.SetParent(parent, false);
		val.transform.localPosition = pos;
		val.transform.localScale = size;
		Object.DestroyImmediate((Object)(object)val.GetComponent<Collider>());
		((Renderer)val.GetComponent<MeshRenderer>()).sharedMaterial = material;
		return val;
	}

	public static GameObject Build(GameObject item, int index)
	{
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0042: Expected O, but got Unknown
		//IL_0075: 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_009b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_0114: Unknown result type (might be due to invalid IL or missing references)
		//IL_0128: Unknown result type (might be due to invalid IL or missing references)
		//IL_037e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0383: Unknown result type (might be due to invalid IL or missing references)
		//IL_0177: Unknown result type (might be due to invalid IL or missing references)
		//IL_018b: 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_01d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_020f: Unknown result type (might be due to invalid IL or missing references)
		//IL_039e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0521: Unknown result type (might be due to invalid IL or missing references)
		//IL_03df: Unknown result type (might be due to invalid IL or missing references)
		//IL_03eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_03f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_028b: Unknown result type (might be due to invalid IL or missing references)
		//IL_029f: Unknown result type (might be due to invalid IL or missing references)
		//IL_02cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0540: Unknown result type (might be due to invalid IL or missing references)
		//IL_0545: Unknown result type (might be due to invalid IL or missing references)
		//IL_0573: Unknown result type (might be due to invalid IL or missing references)
		//IL_0578: Unknown result type (might be due to invalid IL or missing references)
		//IL_057d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0581: Unknown result type (might be due to invalid IL or missing references)
		//IL_0586: Unknown result type (might be due to invalid IL or missing references)
		//IL_058f: Unknown result type (might be due to invalid IL or missing references)
		//IL_05b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_05b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_05e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_05f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0604: Unknown result type (might be due to invalid IL or missing references)
		//IL_0609: Unknown result type (might be due to invalid IL or missing references)
		//IL_0428: Unknown result type (might be due to invalid IL or missing references)
		//IL_042f: Expected O, but got Unknown
		//IL_0556: Unknown result type (might be due to invalid IL or missing references)
		//IL_054b: Unknown result type (might be due to invalid IL or missing references)
		//IL_054d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0496: Unknown result type (might be due to invalid IL or missing references)
		//IL_049d: Unknown result type (might be due to invalid IL or missing references)
		//IL_04b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_04b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_04bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_04f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_0515: Unknown result type (might be due to invalid IL or missing references)
		Collider[] componentsInChildren = item.GetComponentsInChildren<Collider>(true);
		foreach (Collider val in componentsInChildren)
		{
			Object.DestroyImmediate((Object)(object)val);
		}
		GameObject val2 = new GameObject("Mountain Guardian dropped model");
		val2.transform.SetParent(item.transform, false);
		if (index < 2)
		{
			Material val3 = new Material(Plugin.MaterialFor("V3 Art skirt", index == 1));
			val3.mainTextureScale = new Vector2(0.72f, 0.6f);
			val3.mainTextureOffset = new Vector2(0.14f, 0.1f);
			GameObject val4 = Box(val2.transform, "Folded chokha", Vector3.zero, new Vector3(0.4f, 0.11f, 0.48f), val3);
			val4.GetComponent<MeshFilter>().sharedMesh = FoldMesh();
			Material material = Plugin.MaterialFor("V3 Art black leather", black: false);
			Material material2 = Plugin.MaterialFor("V3 Art antique brass", black: false);
			Box(val2.transform, "Black front placket", new Vector3(0f, 0.061f, 0f), new Vector3(0.075f, 0.012f, 0.48f), material);
			float[] array = new float[2] { -0.044f, 0.044f };
			foreach (float num in array)
			{
				Box(val2.transform, "Gold piping", new Vector3(num, 0.069f, 0f), new Vector3(0.009f, 0.006f, 0.48f), material2);
			}
			Box(val2.transform, "Folded hem", new Vector3(0f, 0.058f, -0.205f), new Vector3(0.4f, 0.015f, 0.065f), material);
			Box(val2.transform, "Hem piping", new Vector3(0f, 0.07f, -0.225f), new Vector3(0.4f, 0.006f, 0.008f), material2);
			float[] array2 = new float[2] { -1f, 1f };
			foreach (float num2 in array2)
			{
				for (int l = 0; l < 5; l++)
				{
					float num3 = num2 * (0.075f + (float)l * 0.023f);
					float num4 = 0.07f - (float)l * 0.01f;
					Box(val2.transform, "Silver gazyr", new Vector3(num3, 0.086f, num4), new Vector3(0.017f, 0.021f, 0.17f), Plugin.MaterialFor("V3 Art gazyr silver", black: false));
					Box(val2.transform, "Gazyr gold tip", new Vector3(num3, 0.086f, num4 + 0.093f), new Vector3(0.017f, 0.021f, 0.018f), material2);
				}
			}
		}
		else
		{
			string kind = ((index == 2) ? "legs" : ((index == 3) ? "helmet" : "cape"));
			Part[] array3 = Plugin.Data.parts.Where((Part part2) => part2.sex == "Male" && (part2.kind == kind || (index == 4 && part2.kind == "fur")) && (index != 2 || part2.name.Contains("Forged"))).ToArray();
			Bounds bounds = Plugin.MeshFor(array3[0]).bounds;
			Part[] array4 = array3;
			foreach (Part p in array4)
			{
				((Bounds)(ref bounds)).Encapsulate(Plugin.MeshFor(p).bounds);
			}
			float num6 = ((index == 2) ? 0.52f : ((index == 3) ? 0.38f : 0.64f)) / Mathf.Max(((Bounds)(ref bounds)).size.x, Mathf.Max(((Bounds)(ref bounds)).size.y, ((Bounds)(ref bounds)).size.z));
			Part[] array5 = array3;
			foreach (Part part in array5)
			{
				GameObject val5 = new GameObject(part.name);
				val5.transform.SetParent(val2.transform, false);
				val5.AddComponent<MeshFilter>().sharedMesh = Plugin.MeshFor(part);
				((Renderer)val5.AddComponent<MeshRenderer>()).sharedMaterials = part.materials.Select((string n) => Plugin.MaterialFor(n, black: false)).ToArray();
				val5.transform.localScale = Vector3.one * num6;
				val5.transform.localPosition = -((Bounds)(ref bounds)).center * num6;
			}
			if (index == 4)
			{
				val2.transform.localRotation = Quaternion.Euler(90f, 0f, 0f);
				val2.transform.localScale = new Vector3(1f, 0.36f, 1f);
			}
		}
		Bounds val6 = default(Bounds);
		bool flag = true;
		Renderer[] componentsInChildren2 = val2.GetComponentsInChildren<Renderer>();
		foreach (Renderer val7 in componentsInChildren2)
		{
			Bounds bounds2 = val7.bounds;
			if (flag)
			{
				val6 = bounds2;
				flag = false;
			}
			else
			{
				((Bounds)(ref val6)).Encapsulate(bounds2);
			}
		}
		Vector3 val8 = item.transform.InverseTransformPoint(((Bounds)(ref val6)).center);
		Vector3 size = ((Bounds)(ref val6)).size;
		Transform transform = val2.transform;
		transform.localPosition += new Vector3(0f, size.y * 0.5f - val8.y, 0f);
		BoxCollider val9 = item.AddComponent<BoxCollider>();
		val9.center = new Vector3(val8.x, size.y * 0.5f, val8.z);
		val9.size = Vector3.Max(size, new Vector3(0.08f, 0.08f, 0.08f));
		Rigidbody val10 = item.GetComponent<Rigidbody>() ?? item.AddComponent<Rigidbody>();
		val10.mass = ((index == 4) ? 4 : ((index == 3) ? 1 : 5));
		val10.useGravity = true;
		val10.isKinematic = false;
		val10.collisionDetectionMode = (CollisionDetectionMode)2;
		Transform[] componentsInChildren3 = val2.GetComponentsInChildren<Transform>();
		foreach (Transform val11 in componentsInChildren3)
		{
			((Component)val11).gameObject.layer = item.layer;
		}
		Plugin.ProtectLOD(val2);
		return val2;
	}

	private static Mesh FoldMesh()
	{
		//IL_0021: 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_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0075: 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_0091: Unknown result type (might be due to invalid IL or missing references)
		//IL_0096: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_0132: Unknown result type (might be due to invalid IL or missing references)
		//IL_0137: Unknown result type (might be due to invalid IL or missing references)
		//IL_0143: Unknown result type (might be due to invalid IL or missing references)
		//IL_0148: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_0201: Unknown result type (might be due to invalid IL or missing references)
		//IL_0203: Unknown result type (might be due to invalid IL or missing references)
		//IL_020b: 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_020f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0217: Unknown result type (might be due to invalid IL or missing references)
		//IL_0219: Unknown result type (might be due to invalid IL or missing references)
		//IL_021b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0223: Unknown result type (might be due to invalid IL or missing references)
		//IL_0225: Unknown result type (might be due to invalid IL or missing references)
		//IL_0227: Unknown result type (might be due to invalid IL or missing references)
		//IL_023e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0243: Unknown result type (might be due to invalid IL or missing references)
		//IL_0245: Unknown result type (might be due to invalid IL or missing references)
		//IL_025c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0261: Unknown result type (might be due to invalid IL or missing references)
		//IL_0263: Unknown result type (might be due to invalid IL or missing references)
		//IL_0275: Unknown result type (might be due to invalid IL or missing references)
		//IL_027c: Expected O, but got Unknown
		Vector2[] array = (Vector2[])(object)new Vector2[8]
		{
			new Vector2(-0.4f, -0.5f),
			new Vector2(0.4f, -0.5f),
			new Vector2(0.5f, -0.4f),
			new Vector2(0.5f, 0.4f),
			new Vector2(0.4f, 0.5f),
			new Vector2(-0.4f, 0.5f),
			new Vector2(-0.5f, 0.4f),
			new Vector2(-0.5f, -0.4f)
		};
		List<Vector3> vertices = new List<Vector3>();
		List<Vector2> uv = new List<Vector2>();
		List<int> triangles = new List<int>();
		Action<Vector3, Vector3, Vector3> action = delegate(Vector3 a, Vector3 b, Vector3 c)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: 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_003a: 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_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			int count = vertices.Count;
			vertices.AddRange((IEnumerable<Vector3>)(object)new Vector3[3] { a, b, c });
			uv.AddRange((IEnumerable<Vector2>)(object)new Vector2[3]
			{
				new Vector2(a.x + 0.5f, a.z + 0.5f),
				new Vector2(b.x + 0.5f, b.z + 0.5f),
				new Vector2(c.x + 0.5f, c.z + 0.5f)
			});
			triangles.AddRange(new int[3]
			{
				count,
				count + 1,
				count + 2
			});
		};
		Vector3 val3 = default(Vector3);
		Vector3 arg = default(Vector3);
		Vector3 val4 = default(Vector3);
		Vector3 val5 = default(Vector3);
		Vector3 val6 = default(Vector3);
		Vector3 val7 = default(Vector3);
		for (int num = 0; num < 8; num++)
		{
			Vector2 val = array[num];
			Vector2 val2 = array[(num + 1) % 8];
			((Vector3)(ref val3))..ctor(val.x, -0.5f, val.y);
			((Vector3)(ref arg))..ctor(val2.x, -0.5f, val2.y);
			((Vector3)(ref val4))..ctor(val.x, 0.28f, val.y);
			((Vector3)(ref val5))..ctor(val2.x, 0.28f, val2.y);
			((Vector3)(ref val6))..ctor(val.x * 0.91f, 0.5f, val.y * 0.94f);
			((Vector3)(ref val7))..ctor(val2.x * 0.91f, 0.5f, val2.y * 0.94f);
			action(val3, val4, val5);
			action(val3, val5, arg);
			action(val4, val6, val7);
			action(val4, val7, val5);
			action(new Vector3(0f, 0.5f, 0f), val7, val6);
			action(new Vector3(0f, -0.5f, 0f), val3, arg);
		}
		Mesh val8 = new Mesh();
		((Object)val8).name = "Folded cloth with softened corners";
		val8.SetVertices(vertices);
		val8.SetUVs(0, uv);
		val8.SetTriangles(triangles, 0);
		val8.RecalculateNormals();
		val8.RecalculateBounds();
		return val8;
	}

	public static Sprite Icon(int index)
	{
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_0066: Unknown result type (might be due to invalid IL or missing references)
		string path = Path.Combine(Plugin.Folder, "Icon_" + Plugin.Ids[index] + ".png");
		if (!File.Exists(path))
		{
			return null;
		}
		Texture2D val = Plugin.Texture(Path.GetFileName(path));
		((Texture)val).wrapMode = (TextureWrapMode)1;
		return Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f), 100f);
	}
}
public static class MountainGuardian
{
	[HarmonyPatch(typeof(Requirement), "GetAmount")]
	private class CostPatch
	{
		private static bool Prefix(Requirement __instance, int __0, ref int __result)
		{
			if (!Costs.TryGetValue(__instance, out var value))
			{
				return true;
			}
			__result = ((__0 >= 1 && __0 <= 4) ? value[__0 - 1] : 0);
			return false;
		}
	}

	[HarmonyPatch(typeof(ItemData), "GetArmor", new Type[]
	{
		typeof(int),
		typeof(float)
	})]
	private class ArmorPatch
	{
		private static bool Prefix(ItemData __instance, int __0, ref float __result)
		{
			int num = Index(__instance);
			if (num < 0)
			{
				return true;
			}
			__result = ((num == 4) ? CapeArmor : Armor)[Q(__0)];
			return false;
		}
	}

	[HarmonyPatch(typeof(Player), "GetEquipmentEitrRegenModifier")]
	private class RegenPatch
	{
		private static void Postfix(Player __instance, ref float __result)
		{
			string[] array = new string[3] { "m_helmetItem", "m_chestItem", "m_legItem" };
			foreach (string field in array)
			{
				ItemData val = Equipped((Humanoid)(object)__instance, field);
				int num = Index(val);
				if (num >= 0)
				{
					__result += Regen[num][Q(val.m_quality)];
				}
			}
		}
	}

	[HarmonyPatch(typeof(ItemData), "GetTooltip", new Type[]
	{
		typeof(ItemData),
		typeof(int),
		typeof(bool),
		typeof(float),
		typeof(int),
		typeof(bool)
	})]
	private class TooltipPatch
	{
		private static void Postfix(ItemData item, int qualityLevel, ref string __result)
		{
			int num = Index(item);
			if (num >= 0 && num < 4)
			{
				__result = __result + "\nEitr regeneration: <color=orange>+" + (Regen[num][Q(qualityLevel)] * 100f).ToString("0") + "%</color>";
			}
		}
	}

	public const string OathText = "Direct melee damage to a hostile creature restores 5 eitr. Shared cooldown: 4 seconds. One refund per attack. Requires Papakha, Chokha and Warrior's Trousers; either color and any quality.";

	public static readonly string[] Names = new string[5] { "Mountain Guardian Chokha — Burgundy", "Mountain Guardian Chokha — Black", "Mountain Guardian Warrior's Trousers", "Mountain Guardian Papakha", "Mountain Guardian Nabadi" };

	public static readonly int[] Armor = new int[4] { 24, 26, 32, 38 };

	public static readonly int[] CapeArmor = new int[4] { 4, 5, 8, 12 };

	public static readonly float[][] Regen = new float[5][]
	{
		new float[4] { 0.25f, 0.25f, 0.3f, 0.35f },
		new float[4] { 0.25f, 0.25f, 0.3f, 0.35f },
		new float[4] { 0.15f, 0.15f, 0.2f, 0.25f },
		new float[4] { 0.2f, 0.2f, 0.25f, 0.3f },
		new float[4]
	};

	public static readonly Dictionary<Requirement, int[]> Costs = new Dictionary<Requirement, int[]>();

	private static StatusEffect oath;

	public static int Index(ItemData item)
	{
		if (item == null)
		{
			return -1;
		}
		for (int i = 0; i < Names.Length; i++)
		{
			if (item.m_shared.m_name == Names[i])
			{
				return i;
			}
		}
		return -1;
	}

	public static int Q(int quality)
	{
		return Mathf.Clamp(quality, 1, 4) - 1;
	}

	public static ItemData Equipped(Humanoid h, string field)
	{
		return Traverse.Create((object)h).Field(field).GetValue<ItemData>();
	}

	public static bool HasSet(Player p)
	{
		if (Object.op_Implicit((Object)(object)p) && Index(Equipped((Humanoid)(object)p, "m_helmetItem")) == 3 && Index(Equipped((Humanoid)(object)p, "m_legItem")) == 2 && Index(Equipped((Humanoid)(object)p, "m_chestItem")) >= 0)
		{
			return Index(Equipped((Humanoid)(object)p, "m_chestItem")) < 2;
		}
		return false;
	}

	public static void Configure(CustomItem item, int i)
	{
		//IL_0113: Unknown result type (might be due to invalid IL or missing references)
		//IL_011d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0125: Unknown result type (might be due to invalid IL or missing references)
		//IL_012a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0180: Unknown result type (might be due to invalid IL or missing references)
		//IL_018a: Expected O, but got Unknown
		SharedData shared = item.ItemDrop.m_itemData.m_shared;
		shared.m_name = Names[i];
		shared.m_description = ((i == 4) ? "A mantle of dark mountain wool. Frost resistant; block stamina cost reduced by 10%." : "Worn by the guardians of the high mountains.");
		shared.m_armor = ((i == 4) ? 4 : 24);
		shared.m_armorPerLevel = 0f;
		shared.m_maxQuality = 4;
		shared.m_movementModifier = ((i < 3) ? (-0.02f) : 0f);
		shared.m_weight = ((i < 3) ? 5 : ((i == 3) ? 1 : 4));
		shared.m_useDurability = true;
		shared.m_canBeReparied = true;
		shared.m_maxDurability = ((i == 4) ? 1200 : 1000);
		shared.m_durabilityPerLevel = ((i == 4) ? 50 : 200);
		shared.m_maxStackSize = 1;
		shared.m_eitrRegenModifier = 0f;
		shared.m_blockStaminaModifier = ((i == 4) ? (-0.1f) : 0f);
		shared.m_equipStatusEffect = null;
		shared.m_setStatusEffect = null;
		shared.m_setName = "";
		shared.m_damageModifiers.Clear();
		if (i == 4)
		{
			shared.m_damageModifiers.Add(new DamageModPair
			{
				m_type = (DamageType)64,
				m_modifier = (DamageModifier)1
			});
		}
		else
		{
			if (!Object.op_Implicit((Object)(object)oath))
			{
				oath = ScriptableObject.CreateInstance<StatusEffect>();
				((Object)oath).name = "SGC_OathOfTheMountains";
				oath.m_name = "Oath of the Mountains";
				oath.m_tooltip = "Direct melee damage to a hostile creature restores 5 eitr. Shared cooldown: 4 seconds. One refund per attack. Requires Papakha, Chokha and Warrior's Trousers; either color and any quality.";
				ItemManager.Instance.AddStatusEffect(new CustomStatusEffect(oath, false));
			}
			shared.m_setName = "Mountain Guardian";
			shared.m_setSize = 3;
			shared.m_setStatusEffect = oath;
		}
		item.ItemDrop.m_itemData.m_durability = shared.m_maxDurability;
	}

	public static void Recipe(CustomItem item, int i)
	{
		//IL_031b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0325: Expected O, but got Unknown
		Dictionary<string, int[]> costs = new Dictionary<string, int[]>();
		Action<string, int, int, int, int> action = delegate(string id, int a, int b, int c, int d)
		{
			costs.Add(id, new int[4] { a, b, c, d });
		};
		if (i < 2)
		{
			action("LinenThread", 25, 10, 0, 0);
			action("Eitr", 20, 10, 15, 0);
			action("Carapace", 12, 8, 0, 0);
			action("ScaleHide", 6, 3, 0, 0);
			action("AskHide", 0, 0, 8, 0);
			action("FlametalNew", 0, 0, 10, 0);
			action("MooseHide", 0, 0, 0, 8);
			action("Gold", 0, 0, 0, 10);
			action("NornThread", 0, 0, 0, 8);
			if (i == 0)
			{
				action("JuteRed", 5, 0, 0, 0);
			}
		}
		if (i == 2)
		{
			action("LinenThread", 15, 8, 0, 0);
			action("Eitr", 10, 5, 10, 0);
			action("Carapace", 8, 6, 0, 0);
			action("ScaleHide", 4, 2, 0, 0);
			action("AskHide", 0, 0, 6, 0);
			action("FlametalNew", 0, 0, 6, 0);
			action("MooseHide", 0, 0, 0, 6);
			action("Gold", 0, 0, 0, 6);
			action("NornThread", 0, 0, 0, 6);
		}
		if (i == 3)
		{
			action("WolfPelt", 8, 4, 0, 0);
			action("LinenThread", 10, 5, 0, 0);
			action("Eitr", 10, 5, 10, 0);
			action("Carapace", 4, 4, 0, 0);
			action("AskHide", 0, 0, 4, 0);
			action("FlametalNew", 0, 0, 4, 0);
			action("MooseHide", 0, 0, 0, 4);
			action("Gold", 0, 0, 0, 4);
			action("NornThread", 0, 0, 0, 4);
		}
		if (i == 4)
		{
			action("LoxPelt", 8, 4, 0, 0);
			action("WolfPelt", 6, 3, 0, 0);
			action("LinenThread", 10, 5, 0, 0);
			action("Eitr", 5, 5, 10, 10);
			action("AskHide", 0, 0, 6, 0);
			action("MorgenSinew", 0, 0, 2, 0);
			action("MooseHide", 0, 0, 0, 6);
			action("NornThread", 0, 0, 0, 6);
		}
		Recipe val = ScriptableObject.CreateInstance<Recipe>();
		((Object)val).name = "Recipe_" + Plugin.Ids[i];
		val.m_item = item.ItemDrop;
		val.m_amount = 1;
		val.m_enabled = true;
		val.m_minStationLevel = 1;
		GameObject prefab = PrefabManager.Instance.GetPrefab("piece_magetable");
		if (!Object.op_Implicit((Object)(object)prefab))
		{
			throw new Exception("Missing Galdr table");
		}
		val.m_craftingStation = prefab.GetComponent<CraftingStation>();
		val.m_repairStation = val.m_craftingStation;
		val.m_resources = costs.Select(delegate(KeyValuePair<string, int[]> k)
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Expected O, but got Unknown
			GameObject prefab2 = PrefabManager.Instance.GetPrefab(k.Key);
			if (!Object.op_Implicit((Object)(object)prefab2))
			{
				throw new Exception("Missing recipe resource: " + k.Key);
			}
			Requirement val2 = new Requirement();
			val2.m_resItem = prefab2.GetComponent<ItemDrop>();
			val2.m_amount = k.Value[0];
			val2.m_amountPerLevel = 0;
			val2.m_recover = true;
			Requirement val3 = val2;
			Costs[val3] = k.Value;
			return val3;
		}).ToArray();
		ItemManager.Instance.AddRecipe(new CustomRecipe(val, false, false));
	}
}
public class OathNetwork : MonoBehaviour
{
	private class Pending
	{
		public float until;

		public bool consumed;

		public HashSet<long> owners = new HashSet<long>();
	}

	public class Swing
	{
		public OathNetwork source;

		public int token;
	}

	private class Receipt
	{
		public Character victim;

		public Character attacker;

		public int token;

		public bool damaged;
	}

	[HarmonyPatch(typeof(Character), "Awake")]
	private class Register
	{
		private static void Postfix(Character __instance)
		{
			ZNetView val = View(__instance);
			if (Object.op_Implicit((Object)(object)val) && val.IsValid() && !Object.op_Implicit((Object)(object)((Component)__instance).GetComponent<OathNetwork>()))
			{
				((Component)__instance).gameObject.AddComponent<OathNetwork>().Setup(__instance, val);
			}
		}
	}

	[HarmonyPatch]
	private class AttackScope
	{
		private static IEnumerable<MethodBase> TargetMethods()
		{
			yield return AccessTools.Method(typeof(Attack), "DoMeleeAttack", (Type[])null, (Type[])null);
			yield return AccessTools.Method(typeof(Attack), "DoAreaAttack", (Type[])null, (Type[])null);
		}

		private static void Prefix(Attack __instance, out Swing __state)
		{
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			__state = current;
			current = null;
			Humanoid value = Traverse.Create((object)__instance).Field("m_character").GetValue<Humanoid>();
			Player val = (Player)(object)((value is Player) ? value : null);
			ItemData value2 = Traverse.Create((object)__instance).Field("m_weapon").GetValue<ItemData>();
			if (Object.op_Implicit((Object)(object)val) && !((Object)(object)val != (Object)(object)Player.m_localPlayer) && MountainGuardian.HasSet(val) && value2 != null && MeleeSkill(value2.m_shared.m_skillType))
			{
				OathNetwork component = ((Component)val).GetComponent<OathNetwork>();
				if (Object.op_Implicit((Object)(object)component))
				{
					current = component.Begin(__instance);
				}
			}
		}

		private static Exception Finalizer(Exception __exception, Swing __state)
		{
			current = __state;
			return __exception;
		}
	}

	[HarmonyPatch(typeof(Attack), "Start")]
	private class NewAttack
	{
		private static void Prefix(Attack __instance)
		{
			swings.Remove(__instance);
		}
	}

	[HarmonyPatch(typeof(Character), "Damage")]
	private class SendHit
	{
		[HarmonyPriority(0)]
		private static bool Prefix(Character __instance, HitData hit)
		{
			if (current == null || !Eligible(__instance, current.source.player, hit))
			{
				return true;
			}
			ZNetView val = View(__instance);
			if (!Object.op_Implicit((Object)(object)val) || !val.IsValid())
			{
				return true;
			}
			current.source.Send(__instance, hit, current);
			return false;
		}
	}

	[HarmonyPatch(typeof(Character), "ApplyDamage")]
	private class ConfirmHit
	{
		private static void Prefix(Character __instance, out float __state)
		{
			__state = ((receipt != null && (Object)(object)receipt.victim == (Object)(object)__instance) ? __instance.GetHealth() : (-1f));
		}

		private static void Postfix(Character __instance, float __state)
		{
			if (__state > 0f && receipt != null && (Object)(object)receipt.victim == (Object)(object)__instance && __instance.GetHealth() < __state)
			{
				receipt.damaged = true;
			}
		}
	}

	private const string HitRpc = "SGC_MountainMelee";

	private const string RefundRpc = "SGC_MountainRefund";

	private Character character;

	private ZNetView view;

	private Player player;

	private int nextToken;

	private float nextRefund;

	private readonly Dictionary<int, Pending> pending = new Dictionary<int, Pending>();

	private static readonly ConditionalWeakTable<Attack, Swing> swings = new ConditionalWeakTable<Attack, Swing>();

	[ThreadStatic]
	private static Swing current;

	[ThreadStatic]
	private static Receipt receipt;

	private static readonly MethodInfo damage = AccessTools.Method(typeof(Character), "RPC_Damage", (Type[])null, (Type[])null);

	private static ZNetView View(Character c)
	{
		return Traverse.Create((object)c).Field("m_nview").GetValue<ZNetView>();
	}

	public void Setup(Character c, ZNetView v)
	{
		character = c;
		view = v;
		player = (Player)(object)((c is Player) ? c : null);
		v.Register<ZPackage>("SGC_MountainMelee", (Action<long, ZPackage>)ReceiveHit);
		v.Register<int>("SGC_MountainRefund", (Action<long, int>)ReceiveRefund);
	}

	public static bool MeleeSkill(SkillType skill)
	{
		//IL_0048: Unknown result type (might be due to invalid IL or missing references)
		return new string[8] { "Swords", "Knives", "Clubs", "Polearms", "Spears", "Axes", "Unarmed", "Pickaxes" }.Contains<string>(((object)skill).ToString());
	}

	public static bool Eligible(Character target, Player attacker, HitData hit)
	{
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		if (Object.op_Implicit((Object)(object)target) && Object.op_Implicit((Object)(object)attacker) && !target.IsPlayer() && !target.IsTamed() && BaseAI.IsEnemy((Character)(object)attacker, target) && !hit.m_ranged)
		{
			return MeleeSkill(hit.m_skill);
		}
		return false;
	}

	private Swing Begin(Attack attack)
	{
		if (swings.TryGetValue(attack, out var value))
		{
			return value;
		}
		int[] array = (from k in pending
			where k.Value.until < Time.time
			select k.Key).ToArray();
		foreach (int key in array)
		{
			pending.Remove(key);
		}
		int num2 = ++nextToken;
		pending[num2] = new Pending
		{
			until = Time.time + 15f
		};
		Swing swing = new Swing();
		swing.source = this;
		swing.token = num2;
		value = swing;
		swings.Add(attack, value);
		return value;
	}

	private void Send(Character target, HitData hit, Swing swing)
	{
		//IL_006b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0071: Expected O, but got Unknown
		ZNetView val = View(target);
		if (pending.TryGetValue(swing.token, out var value))
		{
			value.owners.Add(val.GetZDO().GetOwner());
		}
		hit.m_weakSpot = (short)AccessTools.Method(typeof(Character), "FindWeakSpotIndex", (Type[])null, (Type[])null).Invoke(target, new object[1] { hit.m_hitCollider });
		ZPackage val2 = new ZPackage();
		val2.Write(swing.token);
		hit.Serialize(ref val2);
		val.InvokeRPC("SGC_MountainMelee", new object[1] { val2 });
	}

	private void ReceiveHit(long sender, ZPackage pkg)
	{
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Expected O, but got Unknown
		if (view.IsOwner())
		{
			int num = pkg.ReadInt();
			HitData val = new HitData();
			val.Deserialize(ref pkg);
			Character attacker = val.GetAttacker();
			Player val2 = (Player)(object)((attacker is Player) ? attacker : null);
			ZNetView val3 = (Object.op_Implicit((Object)(object)val2) ? View((Character)(object)val2) : null);
			Receipt receipt = OathNetwork.receipt;
			Receipt receipt2 = new Receipt();
			receipt2.victim = character;
			receipt2.attacker = (Character)(object)val2;
			receipt2.token = num;
			Receipt receipt3 = receipt2;
			OathNetwork.receipt = ((Object.op_Implicit((Object)(object)val3) && val3.IsValid() && val3.GetZDO().GetOwner() == sender && Eligible(character, val2, val)) ? receipt3 : null);
			try
			{
				damage.Invoke(character, new object[2] { sender, val });
			}
			finally
			{
				OathNetwork.receipt = receipt;
			}
			if (receipt3.damaged && Object.op_Implicit((Object)(object)val3) && val3.IsValid())
			{
				val3.InvokeRPC("SGC_MountainRefund", new object[1] { num });
			}
		}
	}

	private void ReceiveRefund(long sender, int token)
	{
		if (Object.op_Implicit((Object)(object)player) && view.IsOwner() && pending.TryGetValue(token, out var value) && !value.consumed && !(value.until < Time.time) && value.owners.Contains(sender))
		{
			value.consumed = true;
			if (MountainGuardian.HasSet(player) && !(Time.time < nextRefund) && !(((Character)player).GetMaxEitr() <= 0f))
			{
				nextRefund = Time.time + 4f;
				((Character)player).AddEitr(Mathf.Min(5f, Mathf.Max(0f, ((Character)player).GetMaxEitr() - player.GetEitr())));
			}
		}
	}
}
[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
[BepInPlugin("private.georgian.armortest", "Mountain Guardian", "1.0.1")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Plugin : BaseUnityPlugin
{
	[HarmonyPatch(typeof(VisEquipment), "UpdateEquipmentVisuals")]
	private class VisualPatch
	{
		private static void Postfix(VisEquipment __instance)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Invalid comparison between Unknown and I4
			if (Ready && (int)SystemInfo.graphicsDeviceType != 4 && Object.op_Implicit((Object)(object)__instance.m_bodyModel))
			{
				ArmorVisuals armorVisuals = ((Component)__instance).GetComponent<ArmorVisuals>();
				if (!Object.op_Implicit((Object)(object)armorVisuals))
				{
					armorVisuals = ((Component)__instance).gameObject.AddComponent<ArmorVisuals>();
				}
				armorVisuals.Refresh(__instance);
			}
		}
	}

	public static Plugin Instance;

	public static AssetData Data;

	public static string Folder;

	public static readonly string[] Ids = new string[5] { "SGC_ChokhaBurgundy", "SGC_ChokhaBlack", "SGC_ChokhaLegs", "SGC_Papakha", "SGC_Nabadi" };

	public static readonly Dictionary<int, int> Slots = new Dictionary<int, int>();

	private static readonly Dictionary<string, Texture2D> Textures = new Dictionary<string, Texture2D>();

	private static readonly Dictionary<string, Material> Materials = new Dictionary<string, Material>();

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

	private static Material source;

	public static bool Ready;

	private void Awake()
	{
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		Instance = this;
		Folder = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "Assets");
		new Harmony("private.georgian.armortest").PatchAll();
		PrefabManager.OnVanillaPrefabsAvailable += Register;
	}

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

	public static void Log(string text)
	{
		((BaseUnityPlugin)Instance).Logger.LogInfo((object)text);
	}

	public static void Error(Exception e)
	{
		((BaseUnityPlugin)Instance).Logger.LogError((object)e);
	}

	private void Register()
	{
		//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
		//IL_0103: Expected O, but got Unknown
		//IL_012c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0132: Expected O, but got Unknown
		//IL_020c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0216: Expected O, but got Unknown
		PrefabManager.OnVanillaPrefabsAvailable -= Register;
		try
		{
			Data = JsonConvert.DeserializeObject<AssetData>(File.ReadAllText(Path.Combine(Folder, "armor.json")));
			if (Data.schema != 1 || Data.parts.Length == 0)
			{
				throw new Exception("Invalid armor asset schema");
			}
			source = PrefabManager.Instance.GetPrefab("CapeLox").GetComponentsInChildren<SkinnedMeshRenderer>(true).SelectMany((SkinnedMeshRenderer r) => ((Renderer)r).sharedMaterials)
				.First((Material m) => Object.op_Implicit((Object)(object)m) && ((Object)m.shader).name == "Custom/Creature");
			string[] array = new string[5] { "ArmorRagsChest", "ArmorRagsChest", "ArmorRagsLegs", "HelmetLeather", "CapeLox" };
			for (int num = 0; num < Ids.Length; num++)
			{
				string obj = Ids[num];
				string obj2 = array[num];
				ItemConfig val = new ItemConfig();
				val.Name = MountainGuardian.Names[num];
				val.Description = "Mountain Guardian armor.";
				val.Requirements = (RequirementConfig[])(object)new RequirementConfig[0];
				CustomItem val2 = new CustomItem(obj, obj2, val);
				GameObject itemPrefab = val2.ItemPrefab;
				SharedData shared = val2.ItemDrop.m_itemData.m_shared;
				Transform[] array2 = ((IEnumerable)itemPrefab.transform).Cast<Transform>().ToArray();
				foreach (Transform val3 in array2)
				{
					if (((Object)val3).name.StartsWith("attach"))
					{
						Object.DestroyImmediate((Object)(object)((Component)val3).gameObject);
					}
				}
				LODGroup[] componentsInChildren = itemPrefab.GetComponentsInChildren<LODGroup>(true);
				foreach (LODGroup val4 in componentsInChildren)
				{
					Object.DestroyImmediate((Object)(object)val4);
				}
				Renderer[] componentsInChildren2 = itemPrefab.GetComponentsInChildren<Renderer>(true);
				foreach (Renderer val5 in componentsInChildren2)
				{
					if (!(val5 is ParticleSystemRenderer))
					{
						val5.enabled = false;
					}
				}
				MountainGuardian.Configure(val2, num);
				if (num < 3)
				{
					Material armorMaterial = shared.m_armorMaterial;
					shared.m_armorMaterial = new Material(armorMaterial);
					shared.m_armorMaterial.SetTexture((num == 2) ? "_LegsTex" : "_ChestTex", (Texture)(object)Texture((num == 2) ? "Georgian_Legs_Male.png" : (((num == 1) ? "Black_" : "") + "Burgundy_Chest_Male.png")));
				}
				DroppedItems.Build(itemPrefab, num);
				Sprite val6 = DroppedItems.Icon(num);
				if (Object.op_Implicit((Object)(object)val6))
				{
					shared.m_icons = (Sprite[])(object)new Sprite[1] { val6 };
					if (num == 3 && Object.op_Implicit((Object)(object)shared.m_setStatusEffect))
					{
						shared.m_setStatusEffect.m_icon = val6;
					}
				}
				if (!ItemManager.Instance.AddItem(val2))
				{
					throw new Exception("Registration failed: " + Ids[num]);
				}
				Slots.Add(StringExtensionMethods.GetStableHashCode(Ids[num]), num);
				MountainGuardian.Recipe(val2, num);
			}
			Ready = true;
			Log("MOUNTAIN_GUARDIAN_REGISTERED: " + string.Join(", ", Ids));
		}
		catch (Exception e)
		{
			Error(e);
		}
	}

	public static void ProtectLOD(GameObject root)
	{
		//IL_005b: 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)
		Renderer[] array = (from r in root.GetComponentsInChildren<Renderer>(true)
			where r.enabled && (r is MeshRenderer || r is SkinnedMeshRenderer)
			select r).ToArray();
		if (array.Length != 0)
		{
			LODGroup val = root.GetComponent<LODGroup>() ?? root.AddComponent<LODGroup>();
			val.SetLODs((LOD[])(object)new LOD[1]
			{
				new LOD(0.001f, array)
			});
			val.RecalculateBounds();
		}
	}

	public static Texture2D Texture(string file)
	{
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Expected O, but got Unknown
		if (Textures.TryGetValue(file, out var value))
		{
			return value;
		}
		value = new Texture2D(2, 2, (TextureFormat)4, false, Data.linearTextures != null && Data.linearTextures.Contains(file));
		if (!ImageConversion.LoadImage(value, File.ReadAllBytes(Path.Combine(Folder, file))))
		{
			throw new Exception("Invalid texture " + file);
		}
		((Object)value).name = file;
		((Texture)value).filterMode = (FilterMode)0;
		((Texture)value).wrapMode = (TextureWrapMode)0;
		Textures[file] = value;
		return value;
	}

	public static Matrix4x4 Mat(float[] a)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		Matrix4x4 result = default(Matrix4x4);
		for (int i = 0; i < 4; i++)
		{
			for (int j = 0; j < 4; j++)
			{
				((Matrix4x4)(ref result))[i, j] = a[i * 4 + j];
			}
		}
		return result;
	}

	public static Material MaterialFor(string name, bool black)
	{
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0064: Expected O, but got Unknown
		//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
		string text = name + (black ? "_black" : "");
		if (Materials.TryGetValue(text, out var value))
		{
			return value;
		}
		MaterialData materialData = Data.materials.First((MaterialData x) => x.name == name);
		value = new Material(source);
		((Object)value).name = text;
		string text2 = ((black && !string.IsNullOrEmpty(materialData.blackTexture)) ? materialData.blackTexture : materialData.texture);
		value.mainTexture = (Texture)(object)(string.IsNullOrEmpty(text2) ? null : Texture(text2));
		value.mainTextureScale = Vector2.one;
		value.mainTextureOffset = Vector2.zero;
		if (value.HasProperty("_Color"))
		{
			value.SetColor("_Color", (Color)(string.IsNullOrEmpty(text2) ? new Color(materialData.color[0], materialData.color[1], materialData.color[2], materialData.color[3]) : Color.white));
		}
		string[] array = new string[3] { "_BumpMap", "_MetallicGlossMap", "_EmissionMap" };
		foreach (string text3 in array)
		{
			if (value.HasProperty(text3))
			{
				value.SetTexture(text3, (Texture)null);
			}
		}
		if (value.HasProperty("_Glossiness"))
		{
			value.SetFloat("_Glossiness", 0.08f);
		}
		if (value.HasProperty("_Metallic"))
		{
			value.SetFloat("_Metallic", 0f);
		}
		if (value.HasProperty("_Cull"))
		{
			value.SetFloat("_Cull", 0f);
		}
		value.DisableKeyword("_NORMALMAP");
		value.DisableKeyword("_METALLICGLOSSMAP");
		Materials[text] = value;
		return value;
	}

	public static Mesh MeshFor(Part p)
	{
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Expected O, but got Unknown
		//IL_0093: Unknown result type (might be due to invalid IL or missing references)
		//IL_0098: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fa: 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_01ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
		if (Meshes.TryGetValue(p.name, out var value))
		{
			return value;
		}
		int num = p.positions.Length / 3;
		Mesh val = new Mesh();
		((Object)val).name = p.name;
		val.indexFormat = (IndexFormat)1;
		value = val;
		Vector3[] array = (Vector3[])(object)new Vector3[num];
		Vector3[] array2 = (Vector3[])(object)new Vector3[num];
		Vector2[] array3 = (Vector2[])(object)new Vector2[num];
		BoneWeight[] array4 = (BoneWeight[])(object)new BoneWeight[num];
		for (int i = 0; i < num; i++)
		{
			ref Vector3 reference = ref array[i];
			reference = new Vector3(p.positions[3 * i], p.positions[3 * i + 1], p.positions[3 * i + 2]);
			ref Vector3 reference2 = ref array2[i];
			reference2 = new Vector3(p.normals[3 * i], p.normals[3 * i + 1], p.normals[3 * i + 2]);
			ref Vector2 reference3 = ref array3[i];
			reference3 = new Vector2(p.uv[2 * i], p.uv[2 * i + 1]);
			ref BoneWeight reference4 = ref array4[i];
			BoneWeight val2 = default(BoneWeight);
			((BoneWeight)(ref val2)).boneIndex0 = p.boneIndices[4 * i];
			((BoneWeight)(ref val2)).boneIndex1 = p.boneIndices[4 * i + 1];
			((BoneWeight)(ref val2)).boneIndex2 = p.boneIndices[4 * i + 2];
			((BoneWeight)(ref val2)).boneIndex3 = p.boneIndices[4 * i + 3];
			((BoneWeight)(ref val2)).weight0 = p.boneWeights[4 * i];
			((BoneWeight)(ref val2)).weight1 = p.boneWeights[4 * i + 1];
			((BoneWeight)(ref val2)).weight2 = p.boneWeights[4 * i + 2];
			((BoneWeight)(ref val2)).weight3 = p.boneWeights[4 * i + 3];
			reference4 = val2;
		}
		value.vertices = array;
		value.normals = array2;
		value.uv = array3;
		value.boneWeights = array4;
		value.bindposes = Data.bindPoses.Select(Mat).ToArray();
		value.subMeshCount = p.materials.Length;
		for (int j = 0; j < p.materials.Length; j++)
		{
			List<int> list = new List<int>();
			for (int k = 0; k < p.materialIndices.Length; k++)
			{
				if (p.materialIndices[k] == j)
				{
					list.Add(p.triangles[3 * k]);
					list.Add(p.triangles[3 * k + 1]);
					list.Add(p.triangles[3 * k + 2]);
				}
			}
			value.SetTriangles(list, j);
		}
		value.RecalculateBounds();
		Meshes[p.name] = value;
		return value;
	}
}
public class AssetData
{
	public int schema;

	public string[] boneNames;

	public string[] linearTextures;

	public float[] rendererToPlayer;

	public float[][] bindPoses;

	public MaterialData[] materials;

	public Part[] parts;
}
public class MaterialData
{
	public string name;

	public string texture;

	public string blackTexture;

	public float[] color;
}
public class Part
{
	public string name;

	public string sex;

	public string kind;

	public string[] materials;

	public float[] positions;

	public float[] normals;

	public float[] uv;

	public float[] boneWeights;

	public float[] follow;

	public int[] boneIndices;

	public int[] triangles;

	public int[] materialIndices;

	public int[] sourceIndices;

	public int[] fixedVertices;

	[JsonProperty("fixed")]
	public int[] pins;
}
public class ArmorVisuals : MonoBehaviour
{
	private readonly GameObject[] roots = (GameObject[])(object)new GameObject[4];

	private readonly int[] active = new int[4];

	private int model = -99;

	private bool failed;

	public void Refresh(VisEquipment vis)
	{
		if (failed)
		{
			return;
		}
		try
		{
			int num = ((vis.m_models != null && vis.m_models.Length > 1 && (Object)(object)vis.m_bodyModel.sharedMesh == (Object)(object)vis.m_models[1].m_mesh) ? 1 : 0);
			string text = ((num == 1) ? "Female" : "Male");
			string[] array = new string[4] { "m_currentChestItemHash", "m_currentLegItemHash", "m_currentHelmetItemHash", "m_currentShoulderItemHash" };
			for (int i = 0; i < 4; i++)
			{
				int num2 = Traverse.Create((object)vis).Field(array[i]).GetValue<int>();
				if (!Plugin.Slots.TryGetValue(num2, out var value))
				{
					num2 = 0;
				}
				if (active[i] != num2 || model != num)
				{
					if (Object.op_Implicit((Object)(object)roots[i]))
					{
						roots[i].SetActive(false);
						Object.Destroy((Object)(object)roots[i]);
					}
					roots[i] = null;
					active[i] = num2;
					if (num2 != 0)
					{
						roots[i] = Build(vis, text, value);
					}
				}
			}
			model = num;
			if (Plugin.Slots.TryGetValue(active[0], out var value2))
			{
				((Renderer)vis.m_bodyModel).material.SetTexture("_ChestTex", (Texture)(object)Plugin.Texture(((value2 == 1) ? "Black_" : "") + "Burgundy_Chest_" + text + ".png"));
			}
			if (active[1] != 0)
			{
				((Renderer)vis.m_bodyModel).material.SetTexture("_LegsTex", (Texture)(object)Plugin.Texture("Georgian_Legs_" + text + ".png"));
			}
		}
		catch (Exception e)
		{
			failed = true;
			Plugin.Error(e);
		}
	}

	private GameObject Build(VisEquipment vis, string sex, int item)
	{
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0042: Expected O, but got Unknown
		//IL_0069: Unknown result type (might be due to invalid IL or missing references)
		//IL_006e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0072: Unknown result type (might be due to invalid IL or missing references)
		//IL_0077: Unknown result type (might be due to invalid IL or missing references)
		//IL_0081: Unknown result type (might be due to invalid IL or missing references)
		//IL_0086: Unknown result type (might be due to invalid IL or missing references)
		//IL_0098: Unknown result type (might be due to invalid IL or missing references)
		//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_0171: Unknown result type (might be due to invalid IL or missing references)
		//IL_0178: Expected O, but got Unknown
		//IL_0225: Unknown result type (might be due to invalid IL or missing references)
		//IL_0239: Unknown result type (might be due to invalid IL or missing references)
		//IL_023e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0293: Unknown result type (might be due to invalid IL or missing references)
		//IL_029a: Expected O, but got Unknown
		//IL_0342: Unknown result type (might be due to invalid IL or missing references)
		//IL_034f: Unknown result type (might be due to invalid IL or missing references)
		//IL_043e: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = new GameObject("SGC armor visual " + Plugin.Ids[item]);
		val.transform.SetParent(((Component)vis.m_bodyModel).transform, false);
		Matrix4x4 val2 = Plugin.Mat(Plugin.Data.rendererToPlayer);
		Matrix4x4 inverse = ((Matrix4x4)(ref val2)).inverse;
		val.transform.localPosition = Vector4.op_Implicit(((Matrix4x4)(ref inverse)).GetColumn(3));
		val.transform.localRotation = ((Matrix4x4)(ref inverse)).rotation;
		val.transform.localScale = ((Matrix4x4)(ref inverse)).lossyScale;
		string kind = ((item < 2) ? "chest" : ((item == 2) ? "legs" : ((item == 3) ? "helmet" : "cape")));
		Transform[] bones = Plugin.Data.boneNames.Select((string n) => vis.m_bodyModel.bones.First((Transform b) => ((Object)b).name == n)).ToArray();
		SkinnedMeshRenderer val3 = null;
		Part part = null;
		Part part2 = null;
		foreach (Part item2 in Plugin.Data.parts.Where((Part p) => p.sex == sex && (p.kind == kind || (item == 4 && p.kind == "fur"))))
		{
			if (item2.kind == "fur")
			{
				part2 = item2;
				continue;
			}
			GameObject val4 = new GameObject(item2.name);
			val4.layer = ((Component)vis.m_bodyModel).gameObject.layer;
			val4.transform.SetParent(val.transform, false);
			SkinnedMeshRenderer val5 = val4.AddComponent<SkinnedMeshRenderer>();
			val5.sharedMesh = Plugin.MeshFor(item2);
			((Renderer)val5).sharedMaterials = item2.materials.Select((string n) => Plugin.MaterialFor(n, item == 1)).ToArray();
			val5.bones = bones;
			val5.rootBone = vis.m_bodyModel.rootBone;
			val5.updateWhenOffscreen = true;
			((Renderer)val5).localBounds = new Bounds(new Vector3(0f, 1f, 0f), new Vector3(3f, 3f, 3f));
			if (item2.kind == "cape")
			{
				val3 = val5;
				part = item2;
			}
		}
		if (Object.op_Implicit((Object)(object)val3) && part2 != null)
		{
			GameObject val6 = new GameObject("Nabadi moving wool");
			val6.transform.SetParent(val.transform, false);
			MeshFilter val7 = val6.AddComponent<MeshFilter>();
			val7.sharedMesh = Object.Instantiate<Mesh>(Plugin.MeshFor(part2));
			((Renderer)val6.AddComponent<MeshRenderer>()).sharedMaterials = part2.materials.Select((string n) => Plugin.MaterialFor(n, black: false)).ToArray();
			FurFollow furFollow = val6.AddComponent<FurFollow>();
			furFollow.Setup(val3, val7.sharedMesh, part2.follow);
			MagicaCloth val8 = ((Component)val3).gameObject.AddComponent<MagicaCloth>();
			val8.DisableAutoBuild();
			ClothSerializeData serializeData = val8.SerializeData;
			serializeData.clothType = (ClothType)0;
			serializeData.cullingSettings.cameraCullingMode = (CameraCullingMode)0;
			serializeData.sourceRenderers.Add((Renderer)(object)val3);
			serializeData.gravity = 5f;
			serializeData.damping.SetValue(0.18f);
			serializeData.radius.SetValue(0.014f);
			serializeData.triangleBendingConstraint.stiffness = 0.65f;
			serializeData.angleRestorationConstraint.useAngleRestoration = true;
			serializeData.angleRestorationConstraint.stiffness.SetValue(0.35f);
			serializeData.angleLimitConstraint.useAngleLimit = true;
			serializeData.angleLimitConstraint.limitAngle.SetValue(65f);
			serializeData.wind.influence = 0.35f;
			serializeData.reductionSetting.simpleDistance = 0f;
			serializeData.reductionSetting.shapeDistance = 0f;
			serializeData.colliderCollisionConstraint.colliderList.AddRange(vis.m_clothColliders);
			serializeData.colliderCollisionConstraint.mode = (Mode)1;
			val8.GetSerializeData2().vertexAttributeList.Add(part.pins.Select((int p) => (p != 1) ? VertexAttribute.Move : VertexAttribute.Fixed).ToArray());
			val8.OnBuildComplete = (Action<MagicaCloth, bool>)Delegate.Combine(val8.OnBuildComplete, (Action<MagicaCloth, bool>)delegate(MagicaCloth c, bool ok)
			{
				//IL_0039: Unknown result type (might be due to invalid IL or missing references)
				//IL_003e: Unknown result type (might be due to invalid IL or missing references)
				object[] array = new object[6] { "NABADI_CLOTH_BUILD ", sex, " success=", ok, " result=", null };
				ResultCode result = c.Process.Result;
				array[5] = ((ResultCode)(ref result)).GetResultInformation();
				Plugin.Log(string.Concat(array));
			});
			PlayerClothWindShelter val9 = ((Component)val3).gameObject.AddComponent<PlayerClothWindShelter>();
			Player componentInParent = ((Component)vis).GetComponentInParent<Player>();
			if (Object.op_Implicit((Object)(object)componentInParent))
			{
				val9.SetPlayer(componentInParent);
			}
			bool flag = val8.BuildAndRun();
			Plugin.Log("NABADI_CLOTH_REQUEST " + sex + " accepted=" + flag + " colliders=" + vis.m_clothColliders.Count);
		}
		Plugin.ProtectLOD(val);
		Plugin.Log("ARMOR_VISUAL " + Plugin.Ids[item] + " " + sex);
		return val;
	}

	private void OnDestroy()
	{
		GameObject[] array = roots;
		foreach (GameObject val in array)
		{
			if (Object.op_Implicit((Object)(object)val))
			{
				Object.Destroy((Object)(object)val);
			}
		}
	}
}
[DefaultExecutionOrder(32000)]
public class FurFollow : MonoBehaviour
{
	private SkinnedMeshRenderer cage;

	private Mesh target;

	private Mesh baked;

	private Mesh inner;

	private float[] map;

	private Vector3[] vertices;

	public void Setup(SkinnedMeshRenderer source, Mesh mesh, float[] mapping)
	{
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Expected O, but got Unknown
		//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b2: Expected O, but got Unknown
		cage = source;
		target = mesh;
		map = mapping;
		baked = new Mesh();
		vertices = (Vector3[])(object)new Vector3[map.Length / 6];
		inner = Object.Instantiate<Mesh>(source.sharedMesh);
		((Object)inner).name = "Nabadi inner lining";
		for (int i = 0; i < inner.subMeshCount; i++)
		{
			int[] triangles = inner.GetTriangles(i);
			for (int j = 0; j < triangles.Length; j += 3)
			{
				int num = triangles[j];
				triangles[j] = triangles[j + 2];
				triangles[j + 2] = num;
			}
			inner.SetTriangles(triangles, i);
		}
		GameObject val = new GameObject("Nabadi inner lining");
		val.layer = ((Component)source).gameObject.layer;
		val.transform.SetParent(((Component)this).transform, false);
		val.AddComponent<MeshFilter>().sharedMesh = inner;
		((Renderer)val.AddComponent<MeshRenderer>()).sharedMaterials = ((Renderer)source).sharedMaterials;
	}

	private void LateUpdate()
	{
		//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00da: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ec: 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_0100: Unknown result type (might be due to invalid IL or missing references)
		//IL_0105: Unknown result type (might be due to invalid IL or missing references)
		//IL_0107: Unknown result type (might be due to invalid IL or missing references)
		//IL_0108: Unknown result type (might be due to invalid IL or missing references)
		//IL_0117: Unknown result type (might be due to invalid IL or missing references)
		//IL_011c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0121: Unknown result type (might be due to invalid IL or missing references)
		//IL_0123: Unknown result type (might be due to invalid IL or missing references)
		//IL_0124: 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_012b: Unknown result type (might be due to invalid IL or missing references)
		//IL_012c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0131: Unknown result type (might be due to invalid IL or missing references)
		//IL_0136: Unknown result type (might be due to invalid IL or missing references)
		//IL_013a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0149: Unknown result type (might be due to invalid IL or missing references)
		//IL_014e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0153: Unknown result type (might be due to invalid IL or missing references)
		if (Object.op_Implicit((Object)(object)cage) && Object.op_Implicit((Object)(object)target))
		{
			cage.BakeMesh(baked);
			Vector3[] array = baked.vertices;
			inner.vertices = array;
			inner.normals = baked.normals.Select((Vector3 n) => -n).ToArray();
			inner.RecalculateBounds();
			for (int num = 0; num < vertices.Length; num++)
			{
				int num2 = num * 6;
				Vector3 val = array[(int)map[num2]];
				Vector3 val2 = array[(int)map[num2 + 1]];
				Vector3 val3 = array[(int)map[num2 + 2]];
				ref Vector3 reference = ref vertices[num];
				Vector3 val4 = val + (val2 - val) * map[num2 + 3] + (val3 - val) * map[num2 + 4];
				Vector3 val5 = Vector3.Cross(val2 - val, val3 - val);
				reference = val4 + ((Vector3)(ref val5)).normalized * map[num2 + 5];
			}
			target.vertices = vertices;
			target.RecalculateNormals();
			target.RecalculateBounds();
		}
	}

	private void OnDestroy()
	{
		if (Object.op_Implicit((Object)(object)baked))
		{
			Object.Destroy((Object)(object)baked);
		}
		if (Object.op_Implicit((Object)(object)target))
		{
			Object.Destroy((Object)(object)target);
		}
		if (Object.op_Implicit((Object)(object)inner))
		{
			Object.Destroy((Object)(object)inner);
		}
	}
}