Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of EliteEquipment v0.4.5
plugins\EliteEquipment.dll
Decompiled 3 weeks ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections; using System.Collections.Concurrent; using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.IO; using System.IO.Compression; using System.Linq; using System.Linq.Expressions; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Serialization; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using System.Text; using System.Text.RegularExpressions; using System.Threading; using BepInEx; using BepInEx.Bootstrap; using BepInEx.Configuration; using BepInEx.Logging; using BundlePrefabs; using Charter; using ConfigReload; using EliteCraftingLink; using EliteEquipment.Boots; using EliteEquipment.Casters; using EliteEquipment.Core; using EliteEquipment.Fitted; using EliteEquipment.Shields; using EliteEquipment.Weapons; using HarmonyLib; using ItemCopies; using LocalEffects; using MagicaCloth2; using Microsoft.CodeAnalysis; using PatchGuard; using PlateColumn; using StatusTemplates; using SyncedConfig; using TMPro; using Translations; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.Events; using UnityEngine.Rendering; using UnityEngine.UI; using YamlConfig; using YamlDotNet.Core; using YamlDotNet.Core.Events; using YamlDotNet.Core.Tokens; using YamlDotNet.Helpers; using YamlDotNet.RepresentationModel; using YamlDotNet.Serialization; using YamlDotNet.Serialization.BufferedDeserialization; using YamlDotNet.Serialization.BufferedDeserialization.TypeDiscriminators; using YamlDotNet.Serialization.Callbacks; using YamlDotNet.Serialization.Converters; using YamlDotNet.Serialization.EventEmitters; using YamlDotNet.Serialization.NamingConventions; using YamlDotNet.Serialization.NodeDeserializers; using YamlDotNet.Serialization.NodeTypeResolvers; using YamlDotNet.Serialization.ObjectFactories; using YamlDotNet.Serialization.ObjectGraphTraversalStrategies; using YamlDotNet.Serialization.ObjectGraphVisitors; using YamlDotNet.Serialization.Schemas; using YamlDotNet.Serialization.TypeInspectors; using YamlDotNet.Serialization.TypeResolvers; using YamlDotNet.Serialization.Utilities; using YamlDotNet.Serialization.ValueDeserializers; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: IgnoresAccessChecksTo("assembly_guiutils")] [assembly: IgnoresAccessChecksTo("assembly_utils")] [assembly: IgnoresAccessChecksTo("assembly_valheim")] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: AssemblyCompany("EliteEquipment")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyDescription("EliteEquipment: boots split from the leggings, new shields and weapons, and a caster class")] [assembly: AssemblyFileVersion("0.4.5.0")] [assembly: AssemblyInformationalVersion("0.4.5+4958e6e28f49370e9871253dd69c30bb27b0fad3")] [assembly: AssemblyProduct("EliteEquipment")] [assembly: AssemblyTitle("EliteEquipment")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("0.4.5.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class NullableAttribute : Attribute { public readonly byte[] NullableFlags; public NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] internal sealed class NullableContextAttribute : Attribute { public readonly byte Flag; public NullableContextAttribute(byte P_0) { Flag = P_0; } } [CompilerGenerated] [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 EliteEquipment { [BepInPlugin("milkyteam.eliteequipment", "EliteEquipment", "0.4.5")] [BepInDependency(/*Could not decode attribute arguments.*/)] public class Plugin : BaseUnityPlugin { public const string PluginGuid = "milkyteam.eliteequipment"; public const string PluginName = "EliteEquipment"; public const string PluginVersion = "0.4.5"; public static ManualLogSource Log { get; private set; } public static SyncedConfiguration Synced { get; private set; } public static ConfigEntry<bool> LockConfiguration { get; private set; } private void Awake() { //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Expected O, but got Unknown Log = ((BaseUnityPlugin)this).Logger; Synced = new SyncedConfiguration((BaseUnityPlugin)(object)this, ((BaseUnityPlugin)this).Logger, "EliteEquipment", "0.4.5"); LockConfiguration = Synced.BindLocking("General", "Lock Configuration", defaultValue: true, "[Server Only] Clients cannot change synced settings while connected to a server that has this on."); Harmony harmony = new Harmony("milkyteam.eliteequipment"); Lang.Install(harmony, Assembly.GetExecutingAssembly(), "EliteEquipment", ((BaseUnityPlugin)this).Logger); BootsModule.Initialize(Synced); ShieldsModule.Initialize(Synced); WeaponsModule.Initialize(Synced); CastersModule.Initialize(Synced); int num = PatchEverything(harmony); Synced.Finish(harmony); Log.LogInfo((object)("Loading [EliteEquipment 0.4.5]" + ((num > 0) ? $" with {num} failed patches, see above" : ""))); Guard.Install(harmony, ((BaseUnityPlugin)this).Logger, Assembly.GetExecutingAssembly()); } private static int PatchEverything(Harmony harmony) { int num = 0; Type[] typesFromAssembly = AccessTools.GetTypesFromAssembly(Assembly.GetExecutingAssembly()); foreach (Type type in typesFromAssembly) { if (type.GetCustomAttributes(typeof(HarmonyPatch), inherit: true).Length != 0) { try { harmony.CreateClassProcessor(type).Patch(); } catch (Exception ex) { num++; Log.LogError((object)("Patch " + type.FullName + " failed to apply: " + ex.Message)); } } } return num; } } } namespace EliteEquipment.Weapons { public sealed class HandSkin { public const int RightHand = 29; public const int LeftHand = 10; public static readonly Matrix4x4 RightAttach = Matrix4x4.TRS(new Vector3(0f, 0.00105f, 0.0003f), new Quaternion(-0.5f, -0.5f, 0.5f, 0.5f), Vector3.one * 0.01f); public static readonly Matrix4x4 LeftAttach = Matrix4x4.TRS(new Vector3(0f, 0.00105f, 0.0003f), new Quaternion(0.5f, 0.5f, 0.5f, 0.5f), Vector3.one * 0.01f); private readonly Matrix4x4[] bindposes; private readonly List<Vector3> vertices = new List<Vector3>(); private readonly List<Vector3> normals = new List<Vector3>(); private readonly List<Vector2> uvs = new List<Vector2>(); private readonly List<int> triangles = new List<int>(); private readonly List<BoneWeight> weights = new List<BoneWeight>(); public HandSkin(Mesh game) { bindposes = game.bindposes; if (bindposes == null || bindposes.Length <= 29) { throw new InvalidOperationException(((Object)game).name + " has no hand bind poses"); } } public Matrix4x4 Hand(int bone, Matrix4x4 attach) { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0011: 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) return ((Matrix4x4)(ref bindposes[bone])).inverse * attach; } public void Add(Mesh mesh, Func<Vector3, (int bone, Matrix4x4 matrix)> place) { //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0056: 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_007e: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Unknown result type (might be due to invalid IL or missing references) //IL_0087: 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) //IL_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Unknown result type (might be due to invalid IL or missing references) //IL_00ba: 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) int count = vertices.Count; Vector3[] array = mesh.vertices; Vector3[] array2 = mesh.normals; Vector2[] uv = mesh.uv; for (int i = 0; i < array.Length; i++) { var (boneIndex, val) = place(array[i]); vertices.Add(((Matrix4x4)(ref val)).MultiplyPoint3x4(array[i])); List<Vector3> list = normals; Vector3 item; if (i >= array2.Length) { item = Vector3.up; } else { Vector3 val2 = ((Matrix4x4)(ref val)).MultiplyVector(array2[i]); item = ((Vector3)(ref val2)).normalized; } list.Add(item); uvs.Add((i < uv.Length) ? uv[i] : Vector2.zero); List<BoneWeight> list2 = weights; BoneWeight item2 = default(BoneWeight); ((BoneWeight)(ref item2)).boneIndex0 = boneIndex; ((BoneWeight)(ref item2)).weight0 = 1f; list2.Add(item2); } int[] array3 = mesh.triangles; foreach (int num in array3) { triangles.Add(count + num); } } public Mesh Finish(string name) { //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_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0062: Expected O, but got Unknown Mesh val = new Mesh { name = name }; val.SetVertices(vertices); val.SetNormals(normals); val.SetUVs(0, uvs); val.SetTriangles(triangles, 0); val.boneWeights = weights.ToArray(); val.bindposes = bindposes; val.RecalculateBounds(); return val; } } public static class WeaponFist { private const float Middle = -0.1f; private static readonly Matrix4x4 LeftFromRight = Matrix4x4.Rotate(Quaternion.Euler(180f, 0f, 0f)) * Matrix4x4.Translate(new Vector3(0f, 0f, 0.2f)); public static void Wear(GameObject item, GameObject model, Material material, WeaponSet set) { Transform obj = item.transform.Find("attach_skin"); SkinnedMeshRenderer val = ((obj != null) ? ((Component)obj).GetComponentInChildren<SkinnedMeshRenderer>(true) : null); Transform obj2 = model.transform.Find("model"); MeshFilter val2 = ((obj2 != null) ? ((Component)obj2).GetComponentInChildren<MeshFilter>(true) : null); if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null) { Plugin.Log.LogWarning((object)("EliteEquipment: the " + set.Prefab + " is missing a part (attach_skin or model); it keeps the game's look")); return; } val.sharedMesh = Held(val.sharedMesh, val2.sharedMesh, set.Asset); if ((Object)(object)material != (Object)null) { ((Renderer)val).sharedMaterials = (Material[])(object)new Material[1] { material }; } Dropped(item.transform.Find("attach"), model.transform, val2.sharedMesh, material); } private static Mesh Held(Mesh game, Mesh claws, string name) { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //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_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) HandSkin handSkin = new HandSkin(game); Matrix4x4 right = handSkin.Hand(29, HandSkin.RightAttach); Matrix4x4 left = handSkin.Hand(10, HandSkin.LeftAttach) * LeftFromRight; handSkin.Add(claws, (Vector3 vertex) => (!(vertex.z > -0.1f)) ? (bone: 10, matrix: left) : (bone: 29, matrix: right)); return handSkin.Finish(name + "_held"); } private static void Dropped(Transform attach, Transform root, Mesh claws, Material material) { //IL_008b: Unknown result type (might be due to invalid IL or missing references) //IL_0090: 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_009b: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: Unknown result type (might be due to invalid IL or missing references) MeshFilter val = (((Object)(object)attach != (Object)null) ? ((Component)attach).GetComponent<MeshFilter>() : null); if (!((Object)(object)val == (Object)null)) { val.sharedMesh = claws; MeshRenderer component = ((Component)attach).GetComponent<MeshRenderer>(); if ((Object)(object)component != (Object)null && (Object)(object)material != (Object)null) { ((Renderer)component).sharedMaterials = (Material[])(object)new Material[1] { material }; } BoxCollider component2 = ((Component)attach).GetComponent<BoxCollider>(); Transform val2 = root.Find("col_box_claws"); BoxCollider val3 = (((Object)(object)val2 != (Object)null) ? ((Component)val2).GetComponent<BoxCollider>() : null); if (!((Object)(object)component2 == (Object)null) && !((Object)(object)val3 == (Object)null)) { Matrix4x4 val4 = WeaponParts.Relative(root, val2); component2.center = ((Matrix4x4)(ref val4)).MultiplyPoint3x4(val3.center); component2.size = val3.size; } } } } public static class WeaponIcons { private static readonly EliteEquipment.Core.GameIcons icons = new EliteEquipment.Core.GameIcons("SwordBronze", "SwordIron", "SwordSilver", "SwordBlackmetal", "SwordMistwalker", "SwordNiedhogg", "SwordDyrnwyn", "SwordGold", "SwordWood", "Bow", "BowFineWood", "BowHuntsman", "BowDraugrFang", "BowSpineSnap", "BowAshlands", "BowAshlandsRoot", "BowAshlandsStorm", "BowGold", "Club", "MaceBronze", "MaceIron", "MaceSilver", "MaceNeedle", "MaceEldner", "MaceGold", "KnifeFlint", "KnifeCopper", "KnifeButcher", "KnifeChitin", "KnifeSilver", "KnifeBlackMetal", "KnifeSkollAndHati", "KnifeGold", "THSwordKrom", "THSwordSlayer", "THSwordGold", "SpearFlint", "SpearBronze", "SpearElderbark", "SpearWolfFang", "SpearCarapace", "SpearSplitner", "SpearGold", "AtgeirBronze", "AtgeirIron", "AtgeirBlackmetal", "AtgeirHimminAfl", "AtgeirGold", "AxeStone", "AxeFlint", "AxeBronze", "AxeIron", "AxeBlackMetal", "AxeJotunBane", "AxeGold", "Battleaxe", "BattleaxeCrystal", "BattleaxeBlackmetal", "BattleaxeSkullSplittur", "BattleaxeGold", "AxeEarly", "AxeBerzerkr", "FistBjornClaw", "FistFenrirClaw", "FistBjornUndeadClaw", "FistGold"); public static void Prepare(List<GameObject> prefabs, AssetBundle bundle) { icons.Prepare(prefabs, bundle); } public static void Apply(bool on) { icons.Apply(on); } } public static class WeaponItem { public static GameObject Build(WeaponSet set, GameObject game, GameObject look, AssetBundle bundle) { GameObject val = PrefabBench.Copy(game, set.Prefab); GameObject model = EmbeddedBundle.Prefab(bundle, set.Asset); Material material = WeaponParts.Material(look, set); if (set.Kind == WeaponKind.Dual) { WeaponPair.Wear(val, model, material, set); } else if (set.Kind == WeaponKind.Fist) { WeaponFist.Wear(val, model, material, set); } else { WeaponModel.Wear(val, model, material, set); } set.Projectile = WeaponProjectile.Build(set, val, model, material); SharedData shared = val.GetComponent<ItemDrop>().m_itemData.m_shared; Describe(shared, set, bundle); Damage(shared, set); return val; } private static void Describe(SharedData shared, WeaponSet set, AssetBundle bundle) { shared.m_name = set.Token; shared.m_description = set.DescriptionToken; Sprite val = bundle.LoadAsset<Sprite>(set.Asset + "_icon"); if ((Object)(object)val != (Object)null) { shared.m_icons = (Sprite[])(object)new Sprite[1] { val }; return; } Plugin.Log.LogWarning((object)("EliteEquipment: the bundle has no " + set.Asset + "_icon; the " + set.Prefab + " shows the " + set.Base + " icon")); } private static void Damage(SharedData shared, WeaponSet set) { //IL_0028: 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_0037: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result type (might be due to invalid IL or missing references) float num = ((DamageTypes)(ref set.Damage)).GetTotalDamage() / Mathf.Max(1f, ((DamageTypes)(ref shared.m_damages)).GetTotalDamage()); DamageTypes damagesPerLevel = ((DamageTypes)(ref shared.m_damagesPerLevel)).Clone(); ((DamageTypes)(ref damagesPerLevel)).Modify(num); shared.m_damagesPerLevel = damagesPerLevel; shared.m_damages = set.Damage; } } public static class WeaponItems { [HarmonyPatch(typeof(ZNetScene), "Awake")] private static class ScenePatch { [HarmonyPrefix] private static void Prefix(ZNetScene __instance) { Prepare(__instance.m_prefabs, scene: true); } } [HarmonyPatch(typeof(ObjectDB), "Awake")] private static class DatabasePatch { [HarmonyPrefix] private static void Prefix(ObjectDB __instance) { Prepare(__instance.m_items, scene: false); } } [HarmonyPatch(typeof(ObjectDB), "CopyOtherDB")] private static class CopyPatch { [HarmonyPrefix] private static void Prefix(ObjectDB other) { Prepare(other.m_items, scene: false); } } private const string Bundle = "ee_weapons"; private const string Probe = "THSwordKrom"; private static bool built; private static void Prepare(List<GameObject> prefabs, bool scene) { try { Build(prefabs); foreach (WeaponSet item in WeaponSets.All) { AddOnce(prefabs, item.Item); if (scene) { AddOnce(prefabs, item.Projectile); } } } catch (Exception arg) { Plugin.Log.LogError((object)$"EliteEquipment: the weapons could not be made: {arg}"); } } private static void Build(List<GameObject> prefabs) { if (built || prefabs == null || (Object)(object)Find(prefabs, "THSwordKrom") == (Object)null) { return; } built = true; AssetBundle bundle = EmbeddedBundle.Load(typeof(WeaponItems).Assembly, "ee_weapons"); WeaponIcons.Prepare(prefabs, bundle); foreach (WeaponSet item in WeaponSets.All) { try { BuildSet(item, prefabs, bundle); } catch (Exception arg) { Plugin.Log.LogError((object)$"EliteEquipment: the {item.Prefab} could not be made and is not in the game: {arg}"); } } } private static void BuildSet(WeaponSet set, List<GameObject> prefabs, AssetBundle bundle) { GameObject val = Find(prefabs, set.Base); if ((Object)(object)val == (Object)null || (Object)(object)val.GetComponent<ItemDrop>() == (Object)null) { Plugin.Log.LogWarning((object)("EliteEquipment: the game's " + set.Base + " was not found: there is no " + set.Prefab)); } else { set.Item = WeaponItem.Build(set, val, Find(prefabs, set.Look), bundle); } } private static void AddOnce(List<GameObject> prefabs, GameObject prefab) { if ((Object)(object)prefab != (Object)null && !prefabs.Contains(prefab)) { prefabs.Add(prefab); } } private static GameObject Find(List<GameObject> prefabs, string name) { return prefabs.Find((GameObject p) => (Object)(object)p != (Object)null && ((Object)p).name == name); } } public static class WeaponModel { private const string Holder = "attach"; private const string Name = "ee_model"; public static void Wear(GameObject item, GameObject model, Material material, WeaponSet set) { //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Unknown result type (might be due to invalid IL or missing references) Transform val = item.transform.Find("attach"); if ((Object)(object)val == (Object)null) { Plugin.Log.LogWarning((object)("EliteEquipment: the " + set.Base + " copy has no attach; the " + set.Prefab + " shows the game's model")); } else { WeaponParts.RemoveGameModel(val); GameObject val2 = WeaponParts.Place(model, val, Vector3.zero, Quaternion.identity, material); ((Object)val2).name = "ee_model"; WeaponParts.Glow(val, (Renderer)(object)val2.GetComponentInChildren<MeshRenderer>(true)); WeaponParts.Trail(val, set); WeaponParts.NoLod(item); } } } public static class WeaponPair { private static readonly Vector3 RightDropped = new Vector3(0.0591f, 0.0066f, 0.1622f); private static readonly Quaternion RightDroppedTurn = new Quaternion(-0.0364f, -0.9718f, 0.041f, 0.2292f); private static readonly Vector3 LeftDropped = new Vector3(-0.2084f, -0.0119f, 0.1941f); private static readonly Quaternion LeftDroppedTurn = new Quaternion(0.9676f, 0.1477f, 0.2044f, 0.0116f); public static void Wear(GameObject item, GameObject model, Material material, WeaponSet set) { Transform obj = item.transform.Find("attach_skin"); SkinnedMeshRenderer val = ((obj != null) ? ((Component)obj).GetComponentInChildren<SkinnedMeshRenderer>(true) : null); Transform val2 = model.transform.Find("model"); Transform val3 = model.transform.Find("left"); if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null || (Object)(object)val3 == (Object)null) { Plugin.Log.LogWarning((object)("EliteEquipment: the " + set.Prefab + " is missing a part (attach_skin, model or left); it keeps the game's look")); return; } val.sharedMesh = Held(val.sharedMesh, model.transform, val2, val3, set.Asset); if ((Object)(object)material != (Object)null) { ((Renderer)val).sharedMaterials = (Material[])(object)new Material[1] { material }; } Dropped(item.transform.Find("attach"), model.transform, val2, val3, material); } private static Mesh Held(Mesh game, Transform root, Transform right, Transform left, string name) { //IL_000b: 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) HandSkin handSkin = new HandSkin(game); AddAxe(handSkin, root, right, 29, HandSkin.RightAttach); AddAxe(handSkin, left, left, 10, HandSkin.LeftAttach); return handSkin.Finish(name + "_held"); } private static void AddAxe(HandSkin skin, Transform frame, Transform part, int bone, Matrix4x4 attach) { //IL_003b: 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_0049: Unknown result type (might be due to invalid IL or missing references) //IL_004e: 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) MeshFilter[] componentsInChildren = ((Component)part).GetComponentsInChildren<MeshFilter>(true); foreach (MeshFilter val in componentsInChildren) { Matrix4x4 matrix = skin.Hand(bone, attach) * WeaponParts.Relative(frame, ((Component)val).transform); skin.Add(val.sharedMesh, (Vector3 vertex) => (bone: bone, matrix: matrix)); } } private static void Dropped(Transform attach, Transform root, Transform right, Transform left, Material material) { //IL_0017: 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_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) if (!((Object)(object)attach == (Object)null)) { WeaponParts.RemoveGameModel(attach); GameObject val = WeaponParts.Place(((Component)right).gameObject, attach, RightDropped, RightDroppedTurn, material); GameObject val2 = WeaponParts.Place(((Component)left).gameObject, attach, LeftDropped, LeftDroppedTurn, material); Box(root.Find("col_box_axe"), root, val.transform); Box(root.Find("col_box_left_axe"), left, val2.transform); } } private static void Box(Transform source, Transform frame, Transform axe) { //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result type (might be due to invalid IL or missing references) BoxCollider val = (((Object)(object)source != (Object)null) ? ((Component)source).GetComponent<BoxCollider>() : null); if (!((Object)(object)val == (Object)null)) { Matrix4x4 val2 = WeaponParts.Relative(frame, source); BoxCollider obj = ((Component)axe).gameObject.AddComponent<BoxCollider>(); obj.center = ((Matrix4x4)(ref val2)).MultiplyPoint3x4(val.center); obj.size = val.size; } } } public static class WeaponParts { public static Material Material(GameObject look, WeaponSet set) { Material val = (((Object)(object)look != (Object)null) ? GameMaterials.Borrow(look, set.LookPart) : null); if ((Object)(object)val == (Object)null) { Plugin.Log.LogWarning((object)("EliteEquipment: no " + set.Look + "/" + set.LookPart + " material for the " + set.Prefab + "; it draws untextured")); } if (!((Object)(object)val != (Object)null)) { return null; } return GameMaterials.Unstyled(val); } public static GameObject Place(GameObject source, Transform parent, Vector3 position, Quaternion rotation, Material material) { //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Unknown result type (might be due to invalid IL or missing references) GameObject val = Object.Instantiate<GameObject>(source, parent, false); val.transform.localPosition = position; val.transform.localRotation = rotation; val.transform.localScale = Vector3.one; if ((Object)(object)material != (Object)null) { GameMaterials.Apply(val, (string placeholder) => material); } Transform[] componentsInChildren = val.GetComponentsInChildren<Transform>(true); for (int num = 0; num < componentsInChildren.Length; num++) { ((Component)componentsInChildren[num]).gameObject.layer = ((Component)parent).gameObject.layer; } return val; } public static void RemoveGameModel(Transform parent) { for (int num = parent.childCount - 1; num >= 0; num--) { GameObject gameObject = ((Component)parent.GetChild(num)).gameObject; if ((Object)(object)gameObject.GetComponent<MeshFilter>() != (Object)null || (Object)(object)gameObject.GetComponent<SkinnedMeshRenderer>() != (Object)null || (Object)(object)gameObject.GetComponent<Light>() != (Object)null) { Object.DestroyImmediate((Object)(object)gameObject); } } } public static void Glow(Transform attach, Renderer ours) { //IL_0019: 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_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Invalid comparison between Unknown and I4 //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Invalid comparison between Unknown and I4 if ((Object)(object)ours == (Object)null) { return; } ParticleSystem[] componentsInChildren = ((Component)attach).GetComponentsInChildren<ParticleSystem>(true); for (int i = 0; i < componentsInChildren.Length; i++) { ShapeModule shape = componentsInChildren[i].shape; if ((int)((ShapeModule)(ref shape)).shapeType == 13) { MeshRenderer val = (MeshRenderer)(object)((ours is MeshRenderer) ? ours : null); if (val != null) { ((ShapeModule)(ref shape)).meshRenderer = val; continue; } } if ((int)((ShapeModule)(ref shape)).shapeType == 14) { SkinnedMeshRenderer val2 = (SkinnedMeshRenderer)(object)((ours is SkinnedMeshRenderer) ? ours : null); if (val2 != null) { ((ShapeModule)(ref shape)).skinnedMeshRenderer = val2; } } } } public static void Trail(Transform attach, WeaponSet set) { //IL_0071: 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_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) Transform val = GameMaterials.Find(attach, "trail"); Transform val2 = (((Object)(object)val != (Object)null) ? val.Find("base") : null); Transform val3 = (((Object)(object)val != (Object)null) ? val.Find("tip") : null); if (!((Object)(object)val2 == (Object)null) && !((Object)(object)val3 == (Object)null) && set.TrailBase.HasValue && set.TrailTip.HasValue) { val2.position = attach.TransformPoint(set.TrailBase.Value); val3.position = attach.TransformPoint(set.TrailTip.Value); } } public static void NoLod(GameObject item) { LODGroup component = item.GetComponent<LODGroup>(); if ((Object)(object)component != (Object)null) { Object.DestroyImmediate((Object)(object)component); } } public static Matrix4x4 Relative(Transform frame, Transform part) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) return frame.worldToLocalMatrix * part.localToWorldMatrix; } } public static class WeaponProjectile { public static GameObject Build(WeaponSet set, GameObject item, GameObject model, Material material) { //IL_0067: 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) //IL_0072: Unknown result type (might be due to invalid IL or missing references) SharedData shared = item.GetComponent<ItemDrop>().m_itemData.m_shared; GameObject val = shared.m_secondaryAttack?.m_attackProjectile; if (!set.Thrown || (Object)(object)val == (Object)null) { return null; } GameObject val2 = PrefabBench.Copy(val, "EE_projectile_" + set.Asset.Substring(3)); WeaponParts.RemoveGameModel(val2.transform); Collider[] componentsInChildren = WeaponParts.Place(model, val2.transform, set.ThrownPosition, Quaternion.Euler(set.ThrownRotation), material).GetComponentsInChildren<Collider>(true); for (int i = 0; i < componentsInChildren.Length; i++) { Object.DestroyImmediate((Object)(object)componentsInChildren[i]); } shared.m_secondaryAttack.m_attackProjectile = val2; return val2; } } public static class WeaponRecipes { private static readonly Dictionary<WeaponSet, Recipe> made = new Dictionary<WeaponSet, Recipe>(); public static void Install(ObjectDB db) { if ((Object)(object)db == (Object)null) { return; } foreach (WeaponSet item in WeaponSets.All) { Recipe val = (((Object)(object)item.Item != (Object)null) ? RecipeBeside.Find(db, item.Beside) : null); if (!((Object)(object)val == (Object)null)) { if (!made.TryGetValue(item, out var value)) { value = (made[item] = RecipeBeside.Create(item.Item)); } RecipeBeside.Install(db, value, val, item.Cost, WeaponsSettings.On); } } } } public enum WeaponKind { Held, Dual, Fist } public sealed class WeaponSet { public WeaponKind Kind; public string Prefab; public string Asset; public string Base; public string Beside; public string Look; public string LookPart; public DamageTypes Damage; public RecipePart[] Cost; public Vector3? TrailBase; public Vector3? TrailTip; public bool Thrown; public Vector3 ThrownPosition; public Vector3 ThrownRotation; public GameObject Item; public GameObject Projectile; public string Token => Lang.Token(Asset); public string DescriptionToken => Lang.Token(Asset + "_desc"); } public static class WeaponSets { private const string Sword = "Viking_Sword (1)"; public static readonly IReadOnlyList<WeaponSet> All = new List<WeaponSet> { Greatsword("Bronze", "SwordBronze", "Viking_Sword (1)", Hit(46f), P("Wood", 4, 2), P("Bronze", 12, 6), P("LeatherScraps", 3, 2)), Greatsword("Iron", "SwordIron", "Viking_Sword (1)", Hit(72f), P("Wood", 4, 2), P("Iron", 30, 15), P("LeatherScraps", 4, 2)), Greatsword("Silver", "SwordSilver", "Viking_Sword (1)", Hit(98f, 0f, 0f, 0f, 30f), P("Wood", 4, 2), P("Silver", 60, 30), P("Iron", 8, 4), P("LeatherScraps", 4, 2)), Greatsword("Black Metal", "SwordBlackmetal", "default", Hit(124f), P("FineWood", 4), P("BlackMetal", 30, 15), P("LinenThread", 8, 5)), Dual("Bronze", "AxeBronze", "Viking_Axe", "AxeBronze", Hit(48f, 0f, 0f, 42f), P("Wood", 8), P("Bronze", 12, 6), P("LeatherScraps", 4, 2)), Dual("Iron", "AxeIron", "Viking_Axe", "AxeIron", Hit(67f, 0f, 0f, 50f), P("Wood", 8), P("Iron", 30, 15), P("LeatherScraps", 4, 2)), Dual("Silver", "KnifeSilver", "default", "SwordSilver", Hit(85f, 0f, 0f, 57f, 15f), P("Wood", 6), P("Silver", 40, 20), P("LeatherScraps", 4, 2)), Dual("Black Metal", "AxeBlackMetal", "Model", "AxeBlackMetal", Hit(103f, 0f, 0f, 65f), P("FineWood", 8), P("BlackMetal", 30, 15), P("LinenThread", 6, 4)), Dual("Carapace", "SpearCarapace", "carapacespear", "SpearCarapace", Hit(122f, 0f, 0f, 72f), P("YggdrasilWood", 8), P("Carapace", 16, 8), P("Mandible", 2, 1)), Dual("Bloodgold", "AxeGold", "Model", "AxeGold", Hit(158f, 0f, 0f, 88f), P("Gold", 30, 15), P("Frostwood", 15, 5), P("MoldAxe", 1)), Fist("ee_fist_flint", "KnifeFlint", "knife", "AxeFlint", Hit(0f, 0f, 14f), P("Wood", 4, 2), P("Flint", 6, 3), P("LeatherScraps", 4, 2)), Fist("ee_fist_iron", "SwordIron", "Viking_Sword (1)", "SwordIron", Hit(42f), P("Wood", 2), P("Iron", 20, 10), P("LeatherScraps", 6, 3)), Fist("ee_fist_flametal", "ShieldFlametal", "default", "THSwordSlayer", Hit(100f), P("FlametalNew", 20, 10), P("AskHide", 4, 2), P("MorgenSinew", 2, 1)), Held("ee_knife_iron", "KnifeSilver", "SwordIron", "Viking_Sword (1)", "SwordIron", Hit(18f, 18f), P("Wood", 2, 1), P("Iron", 10, 5), P("LeatherScraps", 2, 1)), Held("ee_knife_flametal", "KnifeBlackMetal", "THSwordSlayer", "default", "SpearSplitner", Hit(60f, 60f), P("Blackwood", 4), P("FlametalNew", 10, 5), P("AskHide", 2, 1)), Held("ee_atgeir_silver", "AtgeirBlackmetal", "SwordSilver", "Viking_Sword (1)", "SwordSilver", Hit(0f, 85f, 0f, 0f, 15f), P("Wood", 10), P("Silver", 30, 15), P("Iron", 4, 2), P("LeatherScraps", 3, 1)), Held("ee_atgeir_flametal", "AtgeirBlackmetal", "SpearSplitner", "default", "SpearSplitner", Hit(0f, 150f), P("Blackwood", 10), P("FlametalNew", 30, 15), P("AskHide", 4, 2)), Trail(Held("ee_axe_silver", "AxeBlackMetal", "ShieldSilver", "model", "SwordSilver", Hit(80f, 0f, 0f, 55f, 15f), P("Wood", 4), P("Silver", 20, 10), P("Iron", 2, 1), P("LeatherScraps", 2, 1)), new Vector3(0.24f, 0f, 0.5f), new Vector3(0.25f, 0f, 0.78f)), Trail(Held("ee_axe_flametal", "AxeBlackMetal", "ShieldFlametal", "default", "SpearSplitner", Hit(140f, 0f, 0f, 80f), P("Blackwood", 4), P("FlametalNew", 20, 10), P("AskHide", 2, 1)), new Vector3(0.26f, 0f, 0.48f), new Vector3(0.27f, 0f, 0.8f)), Trail(Held("ee_battleaxe_flametal", "BattleaxeBlackmetal", "AxeBerzerkr", "default", "THSwordSlayer", Hit(160f, 0f, 0f, 60f), P("Blackwood", 10), P("FlametalNew", 30, 15), P("AskHide", 5, 3)), new Vector3(0.2f, 0f, 1f), new Vector3(0.43f, 0f, 1.4f)), Held("ee_bow_blackmetal", "BowDraugrFang", "AtgeirBlackmetal", "default", "SwordBlackmetal", Hit(0f, 60f), P("FineWood", 10, 5), P("BlackMetal", 15, 8), P("LinenThread", 10, 5)), Throw(Held("ee_spear_blackmetal", "SpearWolfFang", "AtgeirBlackmetal", "default", "SwordBlackmetal", Hit(0f, 95f), P("FineWood", 10, 5), P("BlackMetal", 10, 5), P("LinenThread", 4, 2)), new Vector3(0f, 0f, -0.854f), new Vector3(0f, 180f, 0f)) }; private static DamageTypes Hit(float slash = 0f, float pierce = 0f, float blunt = 0f, float chop = 0f, float spirit = 0f) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) return new DamageTypes { m_slash = slash, m_pierce = pierce, m_blunt = blunt, m_chop = chop, m_spirit = spirit }; } private static RecipePart P(string item, int amount, int perLevel = 0) { return new RecipePart(item, amount, perLevel); } private static WeaponSet Held(string asset, string game, string look, string part, string beside, DamageTypes damage, params RecipePart[] cost) { //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Unknown result type (might be due to invalid IL or missing references) return new WeaponSet { Prefab = "EE_" + asset.Substring(3), Asset = asset, Base = game, Look = look, LookPart = part, Beside = beside, Damage = damage, Cost = cost }; } private static WeaponSet Greatsword(string tier, string sword, string part, DamageTypes damage, params RecipePart[] cost) { //IL_0018: Unknown result type (might be due to invalid IL or missing references) return Held("ee_greatsword_" + Key(tier), "THSwordKrom", sword, part, sword, damage, cost); } private static WeaponSet Dual(string tier, string look, string part, string beside, DamageTypes damage, params RecipePart[] cost) { //IL_0018: Unknown result type (might be due to invalid IL or missing references) WeaponSet weaponSet = Held("ee_dualaxes_" + Key(tier), "AxeBerzerkr", look, part, beside, damage, cost); weaponSet.Kind = WeaponKind.Dual; return weaponSet; } private static WeaponSet Fist(string asset, string look, string part, string beside, DamageTypes damage, params RecipePart[] cost) { //IL_0009: Unknown result type (might be due to invalid IL or missing references) WeaponSet weaponSet = Held(asset, "FistFenrirClaw", look, part, beside, damage, cost); weaponSet.Kind = WeaponKind.Fist; return weaponSet; } private static WeaponSet Trail(WeaponSet set, Vector3 trailBase, Vector3 trailTip) { //IL_0001: 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) set.TrailBase = trailBase; set.TrailTip = trailTip; return set; } private static WeaponSet Throw(WeaponSet set, Vector3 position, Vector3 rotation) { //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) set.Thrown = true; set.ThrownPosition = position; set.ThrownRotation = rotation; return set; } private static string Key(string tier) { return tier.Replace(" ", "").ToLowerInvariant(); } } public static class WeaponsModule { public static void Initialize(SyncedConfiguration synced) { WeaponsSettings.Initialize(synced); WeaponsSettings.Enabled.SettingChanged += delegate { Guard.Run("weapons switch", WeaponsSwitch.Changed); }; } } public static class WeaponsSettings { public const string Section = "3. Weapons"; public const string Key = "Weapons"; public static ConfigEntry<bool> Enabled { get; private set; } public static bool On { get { if (Enabled != null) { return Enabled.Value; } return false; } } public static void Initialize(SyncedConfiguration synced) { Enabled = synced.Bind("3. Weapons", "Weapons", true, "Adds the weapons the game has none of for a biome: Bronze, Iron, Silver and Black Metal Greatswords; Bronze, Iron, Silver, Black Metal, Carapace and Bloodgold Dual Axes; Flint Knuckles, Iron and Flametal Claws; Iron and Flametal Daggers; Silver and Flametal Atgeirs; Silver and Flametal Axes; a Flametal Greataxe; a Black Metal Bow and Spear - each crafted beside a game weapon of its tier; and gives the game's weapons of those kinds icons drawn the same way. Off: they cannot be crafted (weapons already made stay and still work) and the game's icons come back.", true, null); } } public static class WeaponsSwitch { [HarmonyPatch(typeof(ObjectDB), "Awake")] private static class AwakePatch { [HarmonyPostfix] private static void Postfix(ObjectDB __instance) { Apply(__instance); } } [HarmonyPatch(typeof(ObjectDB), "CopyOtherDB")] private static class CopyPatch { [HarmonyPostfix] private static void Postfix(ObjectDB __instance) { Apply(__instance); } } public static void Changed() { Apply(ObjectDB.instance); } private static void Apply(ObjectDB db) { WeaponRecipes.Install(db); WeaponIcons.Apply(WeaponsSettings.On); } } } namespace EliteEquipment.Shields { public static class ShieldIcons { private static readonly EliteEquipment.Core.GameIcons icons = new EliteEquipment.Core.GameIcons("ShieldBronzeBuckler", "ShieldIronBuckler", "ShieldCarapaceBuckler", "ShieldGoldBuckler", "ShieldWood", "ShieldBanded", "ShieldRoots", "ShieldSerpentscale", "ShieldSilver", "ShieldBlackmetal", "ShieldCarapace", "ShieldFlametal", "ShieldGold", "ShieldWoodTower", "ShieldBoneTower", "ShieldIronTower", "ShieldBlackmetalTower", "ShieldFlametalTower", "ShieldGoldTower"); public static void Prepare(List<GameObject> prefabs, AssetBundle bundle) { icons.Prepare(prefabs, bundle); } public static void Apply(bool on) { icons.Apply(on); } } public static class ShieldItem { private const float BlockPerLevel = 6f; private const float DurabilityPerLevel = 50f; public static GameObject Build(ShieldSet set, GameObject game, GameObject look, AssetBundle bundle) { GameObject obj = PrefabBench.Copy(game, set.Prefab); ShieldModel.Wear(obj, game, look, EmbeddedBundle.Prefab(bundle, set.Asset), set); SharedData shared = obj.GetComponent<ItemDrop>().m_itemData.m_shared; Describe(shared, set, bundle); Stats(shared, set); return obj; } private static void Describe(SharedData shared, ShieldSet set, AssetBundle bundle) { shared.m_name = set.Token; shared.m_description = set.DescriptionToken; shared.m_variants = 0; Sprite val = bundle.LoadAsset<Sprite>(set.Asset + "_icon"); if ((Object)(object)val != (Object)null) { shared.m_icons = (Sprite[])(object)new Sprite[1] { val }; return; } Plugin.Log.LogWarning((object)("EliteEquipment: the bundle has no " + set.Asset + "_icon; the " + set.Prefab + " shows the " + set.Base + " icon")); } private static void Stats(SharedData shared, ShieldSet set) { shared.m_blockPower = set.Block; shared.m_blockPowerPerLevel = 6f; shared.m_deflectionForce = set.Deflection; shared.m_deflectionForcePerLevel = set.DeflectionPerLevel; shared.m_timedBlockBonus = set.Kind.Parry; shared.m_perfectBlockAdrenaline = set.Kind.Adrenaline; shared.m_movementModifier = set.Kind.Movement; shared.m_maxDurability = set.Durability; shared.m_durabilityPerLevel = 50f; shared.m_weight = set.Weight; shared.m_damageModifiers = new List<DamageModPair>(); } } public static class ShieldItems { [HarmonyPatch(typeof(ZNetScene), "Awake")] private static class ScenePatch { [HarmonyPrefix] private static void Prefix(ZNetScene __instance) { Prepare(__instance.m_prefabs); } } [HarmonyPatch(typeof(ObjectDB), "Awake")] private static class DatabasePatch { [HarmonyPrefix] private static void Prefix(ObjectDB __instance) { Prepare(__instance.m_items); } } [HarmonyPatch(typeof(ObjectDB), "CopyOtherDB")] private static class CopyPatch { [HarmonyPrefix] private static void Prefix(ObjectDB other) { Prepare(other.m_items); } } private const string Bundle = "ee_shields"; private const string Probe = "ShieldIronBuckler"; private static bool built; private static void Prepare(List<GameObject> prefabs) { try { Build(prefabs); foreach (ShieldSet item in ShieldSets.All) { if ((Object)(object)item.Item != (Object)null && !prefabs.Contains(item.Item)) { prefabs.Add(item.Item); } } } catch (Exception arg) { Plugin.Log.LogError((object)$"EliteEquipment: the shields could not be made: {arg}"); } } private static void Build(List<GameObject> prefabs) { if (built || prefabs == null || (Object)(object)Find(prefabs, "ShieldIronBuckler") == (Object)null) { return; } built = true; AssetBundle bundle = EmbeddedBundle.Load(typeof(ShieldItems).Assembly, "ee_shields"); ShieldIcons.Prepare(prefabs, bundle); foreach (ShieldSet item in ShieldSets.All) { try { BuildSet(item, prefabs, bundle); } catch (Exception arg) { Plugin.Log.LogError((object)$"EliteEquipment: the {item.Prefab} could not be made and is not in the game: {arg}"); } } } private static void BuildSet(ShieldSet set, List<GameObject> prefabs, AssetBundle bundle) { GameObject val = Find(prefabs, set.Base); if ((Object)(object)val == (Object)null || (Object)(object)val.GetComponent<ItemDrop>() == (Object)null) { Plugin.Log.LogWarning((object)("EliteEquipment: the game's " + set.Base + " was not found: there is no " + set.Prefab)); return; } GameObject val2 = ((set.Look != null) ? Find(prefabs, set.Look) : null); if (set.Look != null && (Object)(object)val2 == (Object)null) { Plugin.Log.LogWarning((object)("EliteEquipment: the game's " + set.Look + " was not found: the " + set.Prefab + " wears its own look")); } set.Item = ShieldItem.Build(set, val, val2, bundle); } private static GameObject Find(List<GameObject> prefabs, string name) { return prefabs.Find((GameObject p) => (Object)(object)p != (Object)null && ((Object)p).name == name); } } public sealed class ShieldKind { public static readonly ShieldKind Buckler = new ShieldKind(2.5f, 5f, -0.05f, new Vector3(0.49f, -0.87f, -0.055f), new Vector3(0.012f, -0.056f, 0.998f)); public static readonly ShieldKind Round = new ShieldKind(1.5f, 5f, -0.05f, new Vector3(0.296f, -0.955f, -0.023f), new Vector3(0f, 0f, 1f)); public static readonly ShieldKind Tower = new ShieldKind(0f, 0f, -0.1f, new Vector3(0.225f, -0.972f, -0.064f), new Vector3(-0.155f, -0.1f, 0.983f)); public readonly float Parry; public readonly float Adrenaline; public readonly float Movement; public readonly Quaternion Hold; private ShieldKind(float parry, float adrenaline, float movement, Vector3 front, Vector3 up) { //IL_001c: 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_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Unknown result type (might be due to invalid IL or missing references) Parry = parry; Adrenaline = adrenaline; Movement = movement; Hold = Quaternion.LookRotation(front, up); } } public static class ShieldModel { private const string Holder = "attach"; private const string ModelName = "model"; private const string Grip = "grip"; public static void Wear(GameObject item, GameObject game, GameObject look, GameObject model, ShieldSet set) { //IL_00e3: Unknown result type (might be due to invalid IL or missing references) Transform val = item.transform.Find("attach") ?? item.transform; Material material = (((Object)(object)look != (Object)null) ? GameLook(look) : Look(game, model, set)); for (int num = val.childCount - 1; num >= 0; num--) { Object.DestroyImmediate((Object)(object)((Component)val.GetChild(num)).gameObject); } GameObject val2 = Object.Instantiate<GameObject>(model, val, false); ((Object)val2).name = "model"; if ((Object)(object)material != (Object)null) { GameMaterials.Apply(val2, (string placeholder) => material); } Transform[] componentsInChildren = val2.GetComponentsInChildren<Transform>(true); for (int num2 = 0; num2 < componentsInChildren.Length; num2++) { ((Component)componentsInChildren[num2]).gameObject.layer = ((Component)val).gameObject.layer; } Place(val2.transform, val, ((Object)item).name, set.Kind.Hold); } private static void Place(Transform model, Transform holder, string name, Quaternion hold) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0071: 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_0028: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) model.localRotation = hold; model.localScale = Vector3.one; Transform val = model.Find("grip"); if ((Object)(object)val != (Object)null) { model.localPosition = -(hold * val.localPosition); return; } Plugin.Log.LogWarning((object)("EliteEquipment: " + name + "'s model has no grip point; it is held by its middle")); model.localPosition = Vector3.zero; Bounds val2 = ModelBounds.In(((Component)model).gameObject, holder); model.localPosition = -((Bounds)(ref val2)).center; } private static Material GameLook(GameObject look) { Material val = GameMaterials.Borrow(look, "attach"); if (!((Object)(object)val != (Object)null)) { return null; } return GameMaterials.Unstyled(val); } private static Material Look(GameObject game, GameObject model, ShieldSet set) { Material val = GameMaterials.Borrow(game, "attach"); Renderer componentInChildren = model.GetComponentInChildren<Renderer>(true); if ((Object)(object)val == (Object)null || (Object)(object)componentInChildren == (Object)null || (Object)(object)componentInChildren.sharedMaterial == (Object)null) { return null; } Material sharedMaterial = componentInChildren.sharedMaterial; return GameMaterials.Metal(GameMaterials.Plain(GameMaterials.Dress(val, sharedMaterial), set.Gloss), sharedMaterial, set.MetalGloss); } } public static class ShieldRecipes { private static readonly Dictionary<ShieldSet, Recipe> made = new Dictionary<ShieldSet, Recipe>(); public static void Install(ObjectDB db) { if ((Object)(object)db == (Object)null) { return; } foreach (ShieldSet item in ShieldSets.All) { Recipe val = (((Object)(object)item.Item != (Object)null) ? RecipeBeside.Find(db, item.Shield) : null); if (!((Object)(object)val == (Object)null)) { if (!made.TryGetValue(item, out var value)) { value = (made[item] = RecipeBeside.Create(item.Item)); } RecipeBeside.Install(db, value, val, item.Cost, ShieldsSettings.On); } } } } public sealed class ShieldSet { public ShieldKind Kind; public string Prefab; public string Asset; public string Base; public string Shield; public string Look; public float Block; public float Deflection; public float DeflectionPerLevel; public float Weight; public float Durability; public float Gloss; public float MetalGloss; public RecipePart[] Cost; public GameObject Item; public string Token => Lang.Token(Word); public string DescriptionToken => Lang.Token(Word + "_desc"); public string Word => Asset; } public static class ShieldSets { private const string MetalBase = "ShieldIronBuckler"; public static readonly IReadOnlyList<ShieldSet> All = new List<ShieldSet> { new ShieldSet { Kind = ShieldKind.Buckler, Prefab = "EE_BucklerWood", Asset = "ee_buckler_wood", Base = "ShieldWood", Shield = "ShieldWood", Block = 4f, Deflection = 20f, DeflectionPerLevel = 0f, Weight = 3f, Durability = 200f, Gloss = 0.1f, MetalGloss = 0f, Cost = new RecipePart[3] { new RecipePart("Wood", 8, 4), new RecipePart("LeatherScraps", 4, 2), new RecipePart("Resin", 2, 1) } }, new ShieldSet { Kind = ShieldKind.Round, Prefab = "EE_ShieldBronze", Asset = "ee_shield_bronze", Base = "ShieldBanded", Shield = "ShieldBronzeBuckler", Block = 30f, Deflection = 30f, DeflectionPerLevel = 5f, Weight = 5f, Durability = 200f, Gloss = 0.2f, MetalGloss = 0.62f, Cost = new RecipePart[2] { new RecipePart("Wood", 10, 5), new RecipePart("Bronze", 8, 4) } }, new ShieldSet { Kind = ShieldKind.Buckler, Prefab = "EE_BucklerSilver", Asset = "ee_buckler_silver", Base = "ShieldIronBuckler", Shield = "ShieldSilver", Look = "ShieldSilver", Block = 45f, Deflection = 30f, DeflectionPerLevel = 5f, Weight = 4f, Durability = 200f, Gloss = 0.29f, MetalGloss = 0.65f, Cost = new RecipePart[2] { new RecipePart("Silver", 10, 5), new RecipePart("FineWood", 4, 1) } }, new ShieldSet { Kind = ShieldKind.Tower, Prefab = "EE_TowerSilver", Asset = "ee_tower_silver", Base = "ShieldIronTower", Shield = "ShieldSilver", Look = "ShieldSilver", Block = 78f, Deflection = 125f, DeflectionPerLevel = 5f, Weight = 5f, Durability = 200f, Gloss = 0.29f, MetalGloss = 0.65f, Cost = new RecipePart[2] { new RecipePart("FineWood", 15, 10), new RecipePart("Silver", 10, 5) } }, new ShieldSet { Kind = ShieldKind.Buckler, Prefab = "EE_BucklerBlackmetal", Asset = "ee_buckler_blackmetal", Base = "ShieldIronBuckler", Shield = "ShieldBlackmetal", Look = "ShieldBlackmetal", Block = 61f, Deflection = 40f, DeflectionPerLevel = 5f, Weight = 4f, Durability = 200f, Gloss = 0.19f, MetalGloss = 0.65f, Cost = new RecipePart[3] { new RecipePart("BlackMetal", 10, 5), new RecipePart("FineWood", 4, 1), new RecipePart("Chain", 2, 1) } }, new ShieldSet { Kind = ShieldKind.Tower, Prefab = "EE_TowerCarapace", Asset = "ee_tower_carapace", Base = "ShieldBlackmetalTower", Shield = "ShieldCarapace", Look = "ShieldCarapace", Block = 122f, Deflection = 150f, DeflectionPerLevel = 5f, Weight = 5f, Durability = 250f, Gloss = 0.5f, MetalGloss = 0f, Cost = new RecipePart[3] { new RecipePart("Carapace", 25, 12), new RecipePart("ScaleHide", 5, 3), new RecipePart("Eitr", 10, 3) } }, new ShieldSet { Kind = ShieldKind.Buckler, Prefab = "EE_BucklerFlametal", Asset = "ee_buckler_flametal", Base = "ShieldIronBuckler", Shield = "ShieldFlametal", Block = 83f, Deflection = 40f, DeflectionPerLevel = 5f, Weight = 4f, Durability = 300f, Gloss = 0.26f, MetalGloss = 0.77f, Cost = new RecipePart[3] { new RecipePart("FlametalNew", 10, 5), new RecipePart("Blackwood", 4, 1), new RecipePart("AskHide", 2, 1) } } }; } public static class ShieldsModule { public static void Initialize(SyncedConfiguration synced) { ShieldsSettings.Initialize(synced); ShieldsSettings.Enabled.SettingChanged += delegate { Guard.Run("shields switch", ShieldsSwitch.Changed); }; } } public static class ShieldsSettings { public const string Section = "2. Shields"; public const string Key = "Shields"; public static ConfigEntry<bool> Enabled { get; private set; } public static bool On { get { if (Enabled != null) { return Enabled.Value; } return false; } } public static void Initialize(SyncedConfiguration synced) { Enabled = synced.Bind("2. Shields", "Shields", true, "Adds the shields the game has none of for a biome: the Wood (Meadows, workbench), Silver (Mountains, forge), Black Metal (Plains, forge) and Flametal Buckler (Ashlands, black forge), the Bronze Shield (Black Forest, forge), the Silver (forge) and Carapace Tower Shield (black forge), each crafted beside that biome's shield; and gives the game's bucklers, round and tower shields icons drawn the same way. A buckler blocks less than a shield and parries far better (2.5x against 1.5x); a tower shield cannot parry and slows you more. Off: they cannot be crafted (shields already made stay and still work) and the game's icons come back.", true, null); } } public static class ShieldsSwitch { [HarmonyPatch(typeof(ObjectDB), "Awake")] private static class AwakePatch { [HarmonyPostfix] private static void Postfix(ObjectDB __instance) { Apply(__instance); } } [HarmonyPatch(typeof(ObjectDB), "CopyOtherDB")] private static class CopyPatch { [HarmonyPostfix] private static void Postfix(ObjectDB __instance) { Apply(__instance); } } public static void Changed() { Apply(ObjectDB.instance); } private static void Apply(ObjectDB db) { ShieldRecipes.Install(db); ShieldIcons.Apply(ShieldsSettings.On); } } } namespace EliteEquipment.Fitted { internal sealed class BodyEnvelope { public const float Low = 0.3f; public const float High = 1.2f; private const float Step = 0.02f; private const int Sectors = 36; private readonly float[,] radius; public Vector2 Axis { get; } public BodyEnvelope(BodySurface body) { //IL_0008: 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_0036: 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_0046: 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_0060: 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) //IL_008f: Unknown result type (might be due to invalid IL or missing references) Axis = HipAxis(body); radius = new float[Mathf.CeilToInt(45.000004f) + 1, 36]; for (int i = 0; i < body.Rest.Length; i++) { Vector3 val = body.Rest[i]; if (!body.Upper[i] && !(val.y < 0.3f) && !(val.y > 1.2f)) { int num = Band(val.y); int num2 = Sector(Angle(val)); radius[num, num2] = Mathf.Max(radius[num, num2], Distance(val)); } } for (int j = 0; j < radius.GetLength(0); j++) { FillBand(j); } } public float At(Vector3 rest) { //IL_0006: 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) return radius[Band(Mathf.Clamp(rest.y, 0.3f, 1.2f)), Sector(Angle(rest))]; } public float Distance(Vector3 rest) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) Vector2 val = new Vector2(rest.x - Axis.x, rest.z - Axis.y); return ((Vector2)(ref val)).magnitude; } public Vector3 Outward(Vector3 rest) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0017: 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_0029: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) Vector3 val = new Vector3(rest.x - Axis.x, 0f, rest.z - Axis.y); return ((Vector3)(ref val)).normalized; } private float Angle(Vector3 rest) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) return Mathf.Atan2(rest.z - Axis.y, rest.x - Axis.x); } private static int Band(float height) { return Mathf.RoundToInt((height - 0.3f) / 0.02f); } private static int Sector(float angle) { return ((int)Mathf.Floor((angle + (float)Math.PI) / ((float)Math.PI * 2f) * 36f) % 36 + 36) % 36; } private static Vector2 HipAxis(BodySurface body) { //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_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_0023: 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_0075: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_003d: 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) //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) Vector2 val = Vector2.zero; int num = 0; for (int i = 0; i < body.Rest.Length; i++) { Vector3 val2 = body.Rest[i]; if (!body.Upper[i] && val2.y >= 0.84f && val2.y <= 1.12f) { val += new Vector2(val2.x, val2.z); num++; } } if (num <= 0) { return Vector2.zero; } return val / (float)num; } private void FillBand(int band) { float[] array = new float[36]; for (int i = 0; i < 36; i++) { array[i] = radius[band, i]; int num = 1; while (array[i] <= 0f && num <= 18) { array[i] = Mathf.Max(radius[band, (i + num) % 36], radius[band, (i - num + 36) % 36]); num++; } } for (int j = 0; j < 36; j++) { radius[band, j] = array[j]; } } } internal sealed class BodySurface { public const float Scale = 95f; private static readonly string[] UpperBones = new string[11] { "Arm", "Hand", "Shoulder", "Neck", "Head", "Jaw", "Thumb", "Index", "Middle", "Ring", "Pinky" }; private readonly Vector3Int[] places; public Mesh Mesh { get; } public Vector3[] Vertices { get; } public BoneWeight[] Weights { get; } public Vector2[] Uvs { get; } public int[] Triangles { get; } public Vector3[] Rest { get; } public Vector3[] Outward { get; } public bool[] Upper { get; } private BodySurface(Mesh mesh, string[] bones) { Mesh = mesh; Vertices = mesh.vertices; Weights = mesh.boneWeights; Uvs = mesh.uv; Triangles = mesh.GetTriangles(0); Rest = Array.ConvertAll(Vertices, ToRest); places = Array.ConvertAll(Rest, (Vector3 rest) => Vector3Int.RoundToInt(rest * 2000f)); Outward = Welded(mesh.normals); Upper = UpperOf(Weights, bones); } public static BodySurface Of(Mesh mesh, string[] bones) { //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)mesh == (Object)null || !mesh.isReadable || mesh.vertexCount == 0 || mesh.boneWeights.Length != mesh.vertexCount) { return null; } Bounds bounds = mesh.bounds; float num = ((Bounds)(ref bounds)).size.z * 95f; if (!(num > 1.4f) || !(num < 2.4f)) { return null; } return new BodySurface(mesh, bones); } public static Vector3 ToRest(Vector3 p) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) return new Vector3(95f * p.x, 95f * p.z, -95f * p.y); } public static Vector3 FromRest(Vector3 r) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Unknown result type (might be due to invalid IL or missing references) return new Vector3(r.x / 95f, (0f - r.z) / 95f, r.y / 95f); } public Vector3 Out(int vertex, float metres) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) return Vertices[vertex] + Outward[vertex] * (metres / 95f); } public Vector3Int Place(int vertex) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) return places[vertex]; } private Vector3[] Welded(Vector3[] normals) { //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_002a: 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_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Unknown result type (might be due to invalid IL or missing references) //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) //IL_0065: Unknown result type (might be due to invalid IL or missing references) //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) Dictionary<Vector3Int, Vector3> dictionary = new Dictionary<Vector3Int, Vector3>(); for (int i = 0; i < normals.Length; i++) { dictionary[Place(i)] = (dictionary.TryGetValue(Place(i), out var value) ? value : Vector3.zero) + normals[i]; } Vector3[] array = (Vector3[])(object)new Vector3[normals.Length]; for (int j = 0; j < normals.Length; j++) { int num = j; Vector3 val = dictionary[Place(j)]; array[num] = ((Vector3)(ref val)).normalized; } return array; } public static bool[] UpperOf(BoneWeight[] weights, string[] bones) { //IL_0035: 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) bool[] upperBone = Array.ConvertAll(bones, (string name) => Array.Exists(UpperBones, (string part) => name != null && name.Contains(part))); bool[] array = new bool[weights.Length]; for (int num = 0; num < array.Length; num++) { BoneWeight val = weights[num]; array[num] = On(upperBone, ((BoneWeight)(ref val)).boneIndex0, ((BoneWeight)(ref val)).weight0) + On(upperBone, ((BoneWeight)(ref val)).boneIndex1, ((BoneWeight)(ref val)).weight1) + On(upperBone, ((BoneWeight)(ref val)).boneIndex2, ((BoneWeight)(ref val)).weight2) + On(upperBone, ((BoneWeight)(ref val)).boneIndex3, ((BoneWeight)(ref val)).weight3) >= 0.02f; } return array; } private static float On(bool[] upperBone, int bone, float weight) { if (bone < 0 || bone >= upperBone.Length || !upperBone[bone]) { return 0f; } return weight; } } internal static class BoneBlend { public static BoneWeight Mix(BoneWeight a, BoneWeight b, float t) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0076: 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) Dictionary<int, float> dictionary = new Dictionary<int, float>(); Add(dictionary, a, 1f - t); Add(dictionary, b, t); List<KeyValuePair<int, float>> list = new List<KeyValuePair<int, float>>(dictionary); list.Sort((KeyValuePair<int, float> x, KeyValuePair<int, float> y) => y.Value.CompareTo(x.Value)); float num = 0f; for (int num2 = 0; num2 < list.Count && num2 < 4; num2++) { num += list[num2].Value; } BoneWeight w = default(BoneWeight); for (int num3 = 0; num3 < list.Count && num3 < 4; num3++) { Set(ref w, num3, list[num3].Key, (num > 0f) ? (list[num3].Value / num) : 0f); } return w; } private static void Add(Dictionary<int, float> sums, BoneWeight w, float share) { Put(sums, ((BoneWeight)(ref w)).boneIndex0, ((BoneWeight)(ref w)).weight0 * share); Put(sums, ((BoneWeight)(ref w)).boneIndex1, ((BoneWeight)(ref w)).weight1 * share); Put(sums, ((BoneWeight)(ref w)).boneIndex2, ((BoneWeight)(ref w)).weight2 * share); Put(sums, ((BoneWeight)(ref w)).boneIndex3, ((BoneWeight)(ref w)).weight3 * share); } private static void Put(Dictionary<int, float> sums, int bone, float weight) { if (weight > 0f) { sums[bone] = (sums.TryGetValue(bone, out var value) ? value : 0f) + weight; } } private static void Set(ref BoneWeight w, int slot, int bone, float weight) { switch (slot) { case 0: ((BoneWeight)(ref w)).boneIndex0 = bone; ((BoneWeight)(ref w)).weight0 = weight; break; case 1: ((BoneWeight)(ref w)).boneIndex1 = bone; ((BoneWeight)(ref w)).weight1 = weight; break; case 2: ((BoneWeight)(ref w)).boneIndex2 = bone; ((BoneWeight)(ref w)).weight2 = weight; break; default: ((BoneWeight)(ref w)).boneIndex3 = bone; ((BoneWeight)(ref w)).weight3 = weight; break; } } } internal static class BootTop { private static readonly Dictionary<(Mesh, BootSet), float> known = new Dictionary<(Mesh, BootSet), float>(); public static float Of(BodySurface body, BootSet boots) { if (boots == null) { return 0f; } if (!known.TryGetValue((body.Mesh, boots), out var value)) { value = (known[(body.Mesh, boots)] = Mathf.Max(MeshTop(boots), PaintTop(body, boots))); } return value; } public static void Clear() { known.Clear(); } private static float MeshTop(BootSet boots) { Transform val = (((Object)(object)boots.Item != (Object)null) ? boots.Item.transform.Find("attach_skin") : null); float num = 0f; if ((Object)(object)val == (Object)null) { return num; } SkinnedMeshRenderer[] componentsInChildren = ((Component)val).GetComponentsInChildren<SkinnedMeshRenderer>(true); foreach (SkinnedMeshRenderer val2 in componentsInChildren) { num = Mathf.Max(num, Highest(val2.sharedMesh)); } return num; } private static float Highest(Mesh mesh) { if ((Object)(object)mesh == (Object)null || !mesh.isReadable) { return 0f; } Vector3[] vertices = mesh.vertices; float num = 0f; int[] triangles = mesh.triangles; foreach (int num2 in triangles) { num = Mathf.Max(num, vertices[num2].z * 95f); } return num; } private static float PaintTop(BodySurface body, BootSet boots) { //IL_0023: Unknown result type (might be due to invalid IL or missing references) Paint paint = PaintCut.Boots(boots); float num = 0f; int num2 = 0; while (paint != null && num2 < body.Uvs.Length) { if (!body.Upper[num2] && Painted(paint, body.Uvs[num2])) { num = Mathf.Max(num, body.Rest[num2].y); } num2++; } return num; } private static bool Painted(Paint paint, Vector2 uv) { //IL_0000: 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) int x = Mathf.Clamp((int)(uv.x * (float)paint.Width), 0, paint.Width - 1); int y = Mathf.Clamp((int)((1f - uv.y) * (float)paint.Height), 0, paint.Height - 1); return paint.Pixels[paint.Index(x, y)].a > 8; } } internal static class ChestCloth { private const float Top = 1.2f; private const float BeltRow = 0.05f; private const float Fixed = 0.03f; private const float Room = 0.015f; private const float Near = 0.05f; public static void Hang(ChestVertices v, float bottom) { //IL_014c: 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) //IL_015a: Unknown result type (might be due to invalid IL or missing references) //IL_0167: Unknown result type (might be due to invalid IL or missing references) //IL_0173: Unknown result type (might be due to invalid IL or missing references) //IL_0178: Unknown result type (might be due to invalid IL or missing references) //IL_0197: Unknown result type (might be due to invalid IL or missing references) //IL_019c: Unknown result type (might be due to invalid IL or missing references) List<int> list = Front(v); List<int> list2 = list.FindAll((int i) => v.Rest[i].y > 1.01f); if (list.Count == 0 || list2.Count == 0) { return; } float num = float.MaxValue; foreach (int item in list) { num = Mathf.Min(num, v.Rest[item].y); } float num2 = ((num < bottom) ? ((1.06f - bottom) / (1.06f - num)) : 1f); Vector3 val = default(Vector3); foreach (int item2 in list) { int num3 = Nearest(v, list2, v.Rest[item2].x); ((Vector3)(ref val))..ctor(v.Rest[item2].x, 1.06f - (1.06f - v.Rest[item2].y) * num2, v.Rest[num3].z); v.Rest[item2] = new Vector3(val.x, val.y, Mathf.Max(val.z, Clear(v, val))); v.Weights[item2] = v.Weights[num3]; } } private static float Clear(ChestVertices v, Vector3 at) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0047: 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_0060: 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) //IL_007a: Unknown result type (might be due to invalid IL or missing references) float num = v.Envelope.Axis.y + v.Envelope.At(at) + v.Thickness + 0.015f; for (int i = 0; i < v.Rest.Length; i++) { Vector3 val = v.Rest[i]; if (v.Kind[i] == ChestPart.Plate && !(Mathf.Abs(val.x - at.x) > 0.05f) && !(Mathf.Abs(val.y - at.y) > 0.05f)) { num = Mathf.Max(num, val.z + 0.015f); } } return num; } public static Mesh Split(Mesh chest, ChestVertices v, ChestShape shape) { //IL_00b5: Unknown result type (might be due to invalid IL or missing references) int[] triangles = chest.GetTriangles(0); List<int> list = new List<int>(triangles.Length); List<int> list2 = new List<int>(); for (int i = 0; i < triangles.Length; i += 3) { int num = triangles[i]; int num2 = triangles[i + 1]; int num3 = triangles[i + 2]; if (!IsCloth(v, shape, num) || !IsCloth(v, shape, num2) || !IsCloth(v, shape, num3)) { list.AddRange(new int[3] { num, num2, num3 }); } else if (v.Rest[num].z + v.Rest[num2].z + v.Rest[num3].z > 3f * v.Envelope.Axis.y) { list2.AddRange(new int[3] { num, num2, num3 }); } } if (list2.Count == 0) { return null; } Mesh result = Compact(chest, v, list2); chest.SetTriangles(list, 0); return result; } private static bool IsCloth(ChestVertices v, ChestShape shape, int i) { //IL_002b: Unknown result type (might be due to invalid IL or missing references) if (v.Rest[i].y < 1.2f && v.Kind[i] != ChestPart.Arm) { return shape.IsCloth(v.Uv[i]); } return false; } private static Mesh Compact(Mesh chest, ChestVertices v, List<int> triangles) { //IL_0070: 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_0090: Unknown result type (might be due to invalid IL or missing references) //IL_0099: Expected O, but got Unknown //IL_0099: Unknown result type (might be due to invalid IL or missing references) //IL_00a1: Unknown result type (might be due to invalid IL or missing references) //IL_00ad: Unknown result type (might be due to invalid IL or missing references) //IL_00af: Unknown result type (might be due to invalid IL or missing references) //IL_00ba: Expected O, but got Unknown Dictionary<int, int> dictionary = new Dictionary<int, int>(); List<int> list = new List<int>(); List<int> list2 = new List<int>(triangles.Count); foreach (int triangle in triangles) { if (!dictionary.TryGetValue(triangle, out var value)) { value = (dictionary[triangle] = list.Count); list.Add(triangle); } list2.Add(value); } Mesh val = new Mesh { name = ((Object)chest).name.Replace("_ee_fitted", "_ee_cloth") }; Fill(val, chest, v, list); val.SetTriangles(list2, 0); val.bindposes = chest.bindposes; val.bounds = chest.bounds; return val; } private static void Fill(Mesh mesh, Mesh chest, ChestVertices v, List<int> used) { Vector3[] vertices = chest.vertices; Vector3[] normals = chest.normals; Vector4[] tangents = chest.tangents; Vector2[] uv = chest.uv; BoneWeight[] weights = chest.boneWeights; mesh.SetVertices(used.ConvertAll((int i) => vertices[i])); mesh.SetNormals(used.ConvertAll((int i) => normals[i])); if (tangents.Length == vertices.Length) { mesh.SetTangents(used.ConvertAll((int i) => tangents[i])); } mesh.SetUVs(0, used.ConvertAll((int i) => uv[i])); mesh.SetUVs(1, used.ConvertAll((Converter<int, Vector2>)((int i) => new Vector2((v.Rest[i].y >= 1.03f) ? 0.25f : 0.75f, 0.5f)))); mesh.boneWeights = used.ConvertAll((int i) => weights[i]).ToArray(); } private static List<int> Front(ChestVertices v) { //IL_002c: Unknown result type (might be due to invalid IL or missing references) List<int> list = new List<int>(); for (int i = 0; i < v.Rest.Length; i++) { if (v.Kind[i] == ChestPart.Cloth && v.Rest[i].z > v.Envelope.Axis.y) { list.Add(i); } } return list; } private static int Nearest(ChestVertices v, List<int> among, float x) { int num = among[0]; foreach (int item in among) { if (Mathf.Abs(v.Rest[item].x - x) < Mathf.Abs(v.Rest[num].x - x)) { num = item; } } return num; } } internal static class ChestClothSim { private const string Template = "CapeLinen"; private const float ThighRadius = 0.09f; private const float ThighReach = 0.04f; private const float Wind = 0.05f; private static readonly string[][] Legs = new string[2][] { new string[2] { "LeftUpLeg", "LeftLeg" }, new string[2] { "RightUpLeg", "RightLeg" } }; private static Texture2D paint; public static GameObject Attach(VisEquipment vis, SkinnedMeshRenderer chest, Mesh cloth) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Expected O, but got Unknown //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_0095: Unknown result type (might be due to invalid IL or missing references) //IL_00ad: Unknown result type (might be due to invalid IL or missing references) GameObject val = new GameObject("EE_ChestCloth") { layer = ((Component)chest).gameObject.layer }; Transform transform = ((Component)vis.m_bodyModel).transform; val.transform.SetParent(transform.parent, false); val.transform.localPosition = transform.localPosition; val.transform.localRotation = transform.localRotation; val.transform.localScale = transform.localScale; SkinnedMeshRenderer val2 = val.AddComponent<SkinnedMeshRenderer>(); val2.sharedMesh = cloth; val2.bones = chest.bones; val2.rootBone = chest.rootBone; ((Renderer)val2).localBounds = ((Renderer)chest).localBounds; ((Renderer)val2).sharedMaterial = ((Renderer)chest).sharedMaterial; ((Renderer)val2).shadowCastingMode = ((Renderer)chest).shadowCastingMode; Simulate(vis, val, val2); return val; } private static void Simulate(VisEquipment vis, GameObject holder, SkinnedMeshRenderer renderer) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Expected O, but got Unknown try { GameObject val = new GameObject("EE_ChestCloth_Cloth"); val.SetActive(false); val.transform.SetParent(holder.transform, false); MagicaCloth obj = val.AddComponent<MagicaCloth>(); Configure(obj, renderer, Thighs(renderer, holder.AddComponent<ClothColliders>())); val.SetActive(true); obj.Initialize(); obj.DisableAutoBuild(); if (!obj.BuildAndRun()) { Plugin.Log.LogWarning((object)"EliteEquipment: the chest's cloth simulation did not build; it hangs without moving"); } } catch (Exception ex) { Plugin.Log.LogWarning((object)("EliteEquipment: the chest's cloth will hang without moving: " + ex.Message)); } } private static void Configure(MagicaCloth cloth, SkinnedMeshRenderer renderer, List<ColliderComponent> colliders) { //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) MagicaCloth val = Cape(); if ((Object)(object)val != (Object)null) { cloth.SerializeData.Import(val, true); } ClothSerializeData serializeData = cloth.SerializeData; serializeData.clothType = (ClothType)0; serializeData.sourceRenderers = new List<Renderer> { (Renderer)(object)renderer }; serializeData.rootBones = new List<Transform>(); serializeData.paintMode = (PaintMode)1; serializeData.paintMaps = new List<Texture2D> { Paint() }; serializeData.paintMapUvChannel = 1; serializeData.wind.influence = 0.05f; serializeData.colliderCollisionConstraint.colliderList = new List<ColliderComponent>(colliders ?? new List<ColliderComponent>()); } private static List<ColliderComponent> Thighs(SkinnedMeshRenderer renderer, ClothColliders made) { List<ColliderComponent> list = new List<ColliderComponent>(); string[][] legs = Legs; foreach (string[] array in legs) { int num = Bone(renderer, array[0]); int num2 = Bone(renderer, array[1]); if (num >= 0 && num2 >= 0) { list.Add(Thigh(renderer, made, num, num2)); } } return list; } private static ColliderComponent Thigh(SkinnedMeshRenderer renderer, ClothColliders made, int hip, int knee) { //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_001c: 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_0026: 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_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Expected O, but got Unknown //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0070: 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_007f: Unknown result type (might be due to invalid IL or missing references) //IL_008f: 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_009c: Unknown result type (might be due to invalid IL or missing references) //IL_009d: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: 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_00c0: 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) //IL_00dd: 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_00ea: 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_00f0: 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) Matrix4x4[] bindposes = renderer.sharedMesh.bindposes; Matrix4x4 inverse = ((Matrix4x4)(ref bindposes[hip])).inverse; Vector3 val = ((Matrix4x4)(ref inverse)).MultiplyPoint3x4(Vector3.zero); inverse = ((Matrix4x4)(ref bindposes[knee])).inverse; Vector3 val2 = ((Matrix4x4)(ref inverse)).MultiplyPoint3x4(Vector3.zero); GameObject val3 = new GameObject("EE_ChestClothThigh"); val3.transform.SetParent(renderer.bones[hip], false); val3.transform.localPosition = ((Matrix4x4)(ref bindposes[hip])).MultiplyPoint3x4((val + val2) / 2f); Transform transform = val3.transform; Vector3 up = Vector3.up; Vector3 val4 = ((Matrix4x4)(ref bindposes[hip])).MultiplyVector(val2 - val); transform.localRotation = Quaternion.FromToRotation(up, ((Vector3)(ref val4)).normalized); val3.transform.localScale = Vector3.one; MagicaCapsuleCollider obj = val3.AddComponent<MagicaCapsuleCollider>(); obj.direction = (Direction)1; float x = val3.transform.lossyScale.x; val4 = BodySurface.ToRest(val2 - val); float num = ((Vector3)(ref val4)).magnitude + 0.08f; obj.SetSize(0.09f / x, 0.09f / x, num / x); ((ColliderComponent)obj).UpdateParameters(); made.Made.Add(val3); return (ColliderComponent)(object)obj; } private static int Bone(SkinnedMeshRenderer renderer, string name) { int num = Array.FindIndex(renderer.bones, (Transform bone) => (Object)(object)bone != (Object)null && ((Object)bone).name == name); if (num >= renderer.sharedMesh.bindposes.Length) { return -1; } return num; } private static MagicaCloth Cape() { GameObject val = (((Object)(object)ObjectDB.instance != (Object)null) ? ObjectDB.instance.GetItemPrefab("CapeLinen") : null); if (!((Object)(object)val != (Object)null)) { return null; } return val.GetComponentInChildren<MagicaCloth>(true); } private static Texture2D Paint() { //IL_0017: 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_0027: 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: Expected O, but got Unknown //IL_0053: 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_006b: Unknown result type (might be due to invalid IL or missing references) //IL_0070: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)paint != (Object)null) { return paint; } paint = new Texture2D(2, 1, (TextureFormat)4, false) { name = "EE_ChestClothPaint", filterMode = (FilterMode)0, wrapMode = (TextureWrapMode)1 }; paint.SetPixels32((Color32[])(object)new Color32[2] { new Color32(byte.MaxValue, (byte)0, (byte)0, byte.MaxValue), new Color32((byte)0, byte.MaxValue, (byte)0, byte.MaxValue) }); paint.Apply(false, false); return paint; } public static void Detach(GameObject holder) { if ((Object)(object)holder != (Object)null) { Object.Destroy((Object)(object)holder); } } } public static class ChestFit { [HarmonyPatch(typeof(VisEquipment), "SetChestEquipped")] private static class ChestPatch { [HarmonyPostfix] private static void Postfix(VisEquipment __instance, bool __result) { if (__result) { FittedLook.ChestChanged(__instance); } } } private sealed class Swap { public SkinnedMeshRenderer Renderer { get; } public Mesh Own { get; } public Mesh DrawnIn { get; } public GameObject Cloth { get; set; } public Swap(SkinnedMeshRenderer renderer, Mesh own, Mesh drawnIn) { Renderer = renderer; Own = own; DrawnIn = drawnIn; } } private static readonly Dictionary<(Mesh, Mesh, int), ChestParts> made = new Dictionary<(Mesh, Mesh, int), ChestParts>(); private static readonly Dictionary<Mesh, BodyEnvelope> envelopes = new Dictionary<Mesh, BodyEnvelope>(); private static readonly ConditionalWeakTable<VisEquipment, List<Swap>> worn = new ConditionalWeakTable<VisEquipment, List<Swap>>(); internal static int Release(HashSet<Object> used) { int num = 0; foreach (var item in new List<(Mesh, Mesh, int)>(made.Keys)) { ChestParts chestParts = made[item]; if (chestParts != null && used.Contains((Object)(object)chestParts.Chest)) { continue; } made.Remove(item); if (chestParts != null) { Object.Destroy((Object)(object)chestParts.Chest); if ((Object)(object)chestParts.Cloth != (Object)null) { Object.Destroy((Object)(object)chestParts.Cloth); } num++; } } envelopes.Clear(); return num; } internal static void Fit(VisEquipment vis, BodySurface body, float thickness) { Unfit(vis); ChestShape chestShape = ChestShape.Of(vis.m_currentChestItemHash); if (body == null || chestShape == null || vis.m_chestItemInstances == null) { return; } List<Swap> list = new List<Swap>(); foreach (GameObject chestItemInstance in vis.m_chestItemInstances) { if ((Object)(object)chestItemInstance == (Object)null) { continue; } SkinnedMeshRenderer[] componentsInChildren = chestItemInstance.GetComponentsInChildren<SkinnedMeshRenderer>(true); foreach (SkinnedMeshRenderer renderer in componentsInChildren) { ChestParts chestParts = Get(renderer, body, thickness, chestShape); if (chestParts != null) { list.Add(Wear(vis, renderer, chestParts)); } } } worn.Add(vis, list); } internal static void Unfit(VisEquipment vis) { if (!worn.TryGetValue(vis, out var value)) { return; } worn.Remove(vis); foreach (Swap item in value) { if ((Object)(object)item.Renderer != (Object)null && (Object)(object)item.Renderer.sharedMesh == (Object)(object)item.DrawnIn) { item.Renderer.sharedMesh = item.Own; } ChestClothSim.Detach(item.Cloth); } } private static Swap Wear(VisEquipment vis, SkinnedMeshRenderer renderer, ChestParts parts) { Swap swap = new Swap(renderer, renderer.sharedMesh, parts.Chest); renderer.sharedMesh = parts.Chest; if ((Object)(object)parts.Cloth != (Object)null) { swap.Cloth = ChestClothSim.Attach(vis, renderer, parts.Cloth); } return swap; } private static ChestParts Get(SkinnedMeshRenderer renderer, BodySurface body, float thickness, ChestShape shape) { Mesh sharedMesh = renderer.sharedMesh; if ((Object)(object)sharedMesh == (Object)null || sharedMesh.subMeshCount != 1 || renderer.bones == null) { return null; } (Mesh, Mesh, int) key = (sharedMesh, body.Mesh, Mathf.RoundToInt(thickness * 1000f)); if (!made.TryGetValue(key, out var value)) { value = (made[key] = Guarded(sharedMesh, Array.ConvertAll(renderer.bones, (Transform bone) => (!((Object)(object)bone != (Object)null)) ? null : ((Object)bone).name), body, thickness, shape)); } return value; } private static ChestParts Guarded(Mesh own, string[] bones, BodySurface body, float thickness, ChestShape shape) { try { if (!envelopes.TryGetValue(body.Mesh, out var value)) { value = (envelopes[body.Mesh] = new BodyEnvelope(body)); } return ChestPull.Make(own, bones, body, value, thickness, shape); } catch (Exception ex) { Plugin.Log.LogWarning((object)("EliteEquipment: the chest " + ((Object)own).name + " could not be drawn in over fitted leggings: " + ex.Message)); return null; } } } internal static class ChestPull { private const float Settled = 0.03f; private const float Tenth = 0.1f; private const float FollowDepth = 0.35f; private const float FollowMost = 0.75f; private const float FollowBehind = 0.2f; public static ChestParts Make(Mesh source, string[] bones, BodySurface body, BodyEnvelope envelope, float thickness, ChestShape shape) { Mesh[] array = MeshCut.Cut(source, new bool[source.GetIndexCount(0) / 3], null); Object.Destroy((Object)(object)array[1]); Mesh val = array[0]; ((Object)val).name = ((Object)source).name + "_ee_fitted"; ChestVertices chestVertices = new ChestVertices(Array.ConvertAll(val.vertices, BodySurface.ToRest), val.uv, val.boneWeights, BodySurface.UpperOf(val.boneWeights, bones), envelope); chestVertices.Measure(thickness, shape); float num = LeanPlates(chestVertices); Reweight(chestVertices); Follow(chestVertices, body); ChestCloth.Hang(chestVertices, shape.ClothBottom); val.vertices = Array.ConvertAll(chestVertices.Rest, BodySurface.FromRest); val.boneWeights = chestVertices.Weights; Mesh val2 = ChestCloth.Split(val, chestVertices, shape); val.UploadMeshData(true); Plugin.Log.LogInfo((object)string.Format("EliteEquipment: {0} drawn in over fitted leggings: plates lean in by up to {1:0.0} cm; front cloth {2}", ((Object)source).name, num * 100f, ((Object)(object)val2 != (Object)null) ? ("on its own, ending at " + shape.ClothBottom.ToString("0.00") + " m") : "not found")); return new ChestParts(val, val2); } private static float LeanPlates(ChestVertices v) { //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Unknown result type (might be due to invalid IL or missing references) float[] array = Smooth(Rates(v), 3, 3); float num = 0f; for (int i = 0; i < v.Rest.Length; i++) { if (v.Kind[i] == ChestPart.Plate) { float num2 = array[v.Sector(i)] * v.Depth(i); num = Mathf.Max(num, num2); ref Vector3 reference = ref v.Rest[i]; reference -= v.Envelope.Outward(v.Rest[i]) * num2; } } return num; } private static float[] Rates(ChestVertices v) { List<float>[] array = new List<float>[36]; for (int i = 0; i < array.Length; i++) { array[i] = new List<float>(); } for (int j = 0; j < v.Rest.Length; j++) { if (v.Kind[j] == ChestPart.Plate && v.Depth(j) > 0.03f) { array[v.Sector(j)].Add(Mathf.Max(0f, v.Excess[j]) / v.Depth(j)); } } float[] array2 = new float[array.Length]; float num = 0f; int num2 = 0; for (int k = 0; k < array.Length; k++) { array[k].Sort(); array2[k] = ((array[k].Count > 0) ? array[k][(int)((float)array[k].Count * 0.1f)] : (-1f)); num += ((array2[k] >= 0f) ? array2[k] : 0f); num2 += ((array2[k] >= 0f) ? 1 : 0); } for (int l = 0; l < array2.Length; l++) { array2[l] = ((array2[l] >= 0f) ? array2[l] : ((num2 > 0) ? (num / (float)num2) : 0f)); } return array2; } private static float[] Smooth(float[] rate, int width, int passes) { for (int