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 OctoArsenal v0.5.27
plugins/OctoArsenal/OctoArsenal.dll
Decompiled 21 hours 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.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.IO.Compression; using System.Linq; using System.Reflection; using System.Reflection.Emit; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Text; using BepInEx; using BepInEx.Bootstrap; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using Microsoft.CodeAnalysis; using OctoArsenal; using OctoArsenal.Carrier; using OctoPack.Quiver; using TMPro; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.Rendering; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: AssemblyTitle("OctoArsenal")] [assembly: AssemblyDescription("Expandable Valheim weapons by Octodad")] [assembly: AssemblyCompany("Octodad")] [assembly: AssemblyProduct("OctoArsenal")] [assembly: AssemblyFileVersion("0.5.27.0")] [assembly: AssemblyMetadata("AI_Assisted_Creation", "Created and maintained with assistance from OpenAI Codex.")] [assembly: AssemblyMetadata("AI_Model_Vendor", "OpenAI")] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyVersion("0.5.27.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace OctoPack.Quiver { internal static class Ammo { private const BindingFlags Instance = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic; private static readonly FieldInfo Character = typeof(Attack).GetField("m_character", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); private static readonly FieldInfo Weapon = typeof(Attack).GetField("m_weapon", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); internal static bool Matches(ItemData item, string required) { //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Invalid comparison between Unknown and I4 if (item?.m_shared != null && item.m_stack > 0 && (int)item.m_shared.m_itemType == 9 && !string.IsNullOrEmpty(required)) { return item.m_shared.m_ammoType == required; } return false; } internal static ItemData Choose(ItemData selected, Inventory player, Inventory quiver, string required) { if (Matches(selected, required) && (player.ContainsItem(selected) || quiver.ContainsItem(selected))) { return selected; } for (int i = 0; i < 3; i++) { ItemData itemAt = quiver.GetItemAt(i, 0); if (Matches(itemAt, required)) { return itemAt; } } return null; } private static ItemData Candidate(Humanoid character, ItemData weapon) { Items.State active = Items.Active; if (character == null || (Object)(object)character != (Object)(object)Player.m_localPlayer || active == null || !active.Valid || !Items.ArrowType(weapon?.m_shared?.m_ammoType)) { return null; } return Choose(character.GetAmmoItem(), character.GetInventory(), active.Inventory, weapon.m_shared.m_ammoType); } internal static Inventory InventoryFor(Humanoid character, ItemData weapon) { ItemData val = Candidate(character, weapon); if (val == null || !Items.Active.Inventory.ContainsItem(val)) { return character.GetInventory(); } return Items.Active.Inventory; } internal static void Prepare(Humanoid character, ItemData weapon) { ItemData val = Candidate(character, weapon); if (val != null && Items.Active.Inventory.ContainsItem(val) && (character.GetAmmoItem() != val || !val.m_equipped)) { Items.AssignAmmo(character, val); } } private static void PrepareStatic(Humanoid __0, ItemData __1) { Prepare(__0, __1); } private static void PrepareUse(Attack __instance) { object? value = Character.GetValue(__instance); object? character = ((value is Humanoid) ? value : null); object? value2 = Weapon.GetValue(__instance); Prepare((Humanoid)character, (ItemData)((value2 is ItemData) ? value2 : null)); } private static IEnumerable<CodeInstruction> StaticCode(IEnumerable<CodeInstruction> instructions) { return InventoryCode(instructions, instance: false); } private static IEnumerable<CodeInstruction> InstanceCode(IEnumerable<CodeInstruction> instructions) { return InventoryCode(instructions, instance: true); } internal static IEnumerable<CodeInstruction> InventoryCode(IEnumerable<CodeInstruction> instructions, bool instance) { MethodInfo getInventory = typeof(Humanoid).GetMethod("GetInventory"); MethodInfo replacement = typeof(Ammo).GetMethod("InventoryFor", BindingFlags.Static | BindingFlags.NonPublic); foreach (CodeInstruction instruction in instructions) { if (instruction.operand is MethodInfo methodInfo && methodInfo == getInventory) { instruction.opcode = (instance ? OpCodes.Ldarg_0 : OpCodes.Ldarg_1); instruction.operand = null; yield return instruction; if (instance) { yield return new CodeInstruction(OpCodes.Ldfld, (object)Weapon); } yield return new CodeInstruction(OpCodes.Call, (object)replacement); } else { yield return instruction; } } } internal static void Patch(Harmony harmony) { //IL_009c: 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_00ca: Unknown result type (might be due to invalid IL or missing references) //IL_00d6: Expected O, but got Unknown string[] array = new string[4] { "FindAmmo", "HaveAmmo", "EquipAmmoItem", "UseAmmo" }; foreach (string text in array) { bool flag = text == "UseAmmo"; MethodInfo method = typeof(Attack).GetMethod(text, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); if (method == null) { throw new MissingMethodException(typeof(Attack).FullName, text); } harmony.Patch((MethodBase)method, (text == "FindAmmo") ? ((HarmonyMethod)null) : new HarmonyMethod(typeof(Ammo), flag ? "PrepareUse" : "PrepareStatic", (Type[])null) { priority = 800 }, (HarmonyMethod)null, new HarmonyMethod(typeof(Ammo), flag ? "InstanceCode" : "StaticCode", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null); } } } internal static class ArrowTailGeometry { internal sealed class Part { internal Mesh Mesh; internal Material[] Materials; } internal sealed class Shape { internal readonly List<Part> Parts = new List<Part>(); internal Bounds Bounds; } private struct Vertex { internal Vector3 P; internal Vector3 N; internal Vector2 UV; internal static Vertex Mix(Vertex a, Vertex b, float t) { //IL_000b: 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_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_0024: 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_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_0038: 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_0045: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_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) Vertex result = new Vertex { P = Vector3.Lerp(a.P, b.P, t) }; Vector3 val = Vector3.Lerp(a.N, b.N, t); result.N = ((Vector3)(ref val)).normalized; result.UV = Vector2.Lerp(a.UV, b.UV, t); return result; } } private static readonly Dictionary<(GameObject, bool), Shape> cache = new Dictionary<(GameObject, bool), Shape>(); internal static Shape Get(GameObject prefab, bool forward) { //IL_0186: Unknown result type (might be due to invalid IL or missing references) //IL_01d7: Unknown result type (might be due to invalid IL or missing references) //IL_01e7: Unknown result type (might be due to invalid IL or missing references) //IL_01ae: Unknown result type (might be due to invalid IL or missing references) //IL_01be: Unknown result type (might be due to invalid IL or missing references) //IL_0694: Unknown result type (might be due to invalid IL or missing references) //IL_0699: Unknown result type (might be due to invalid IL or missing references) //IL_00ca: Unknown result type (might be due to invalid IL or missing references) //IL_00cf: Unknown result type (might be due to invalid IL or missing references) //IL_00d7: Unknown result type (might be due to invalid IL or missing references) //IL_00e3: Unknown result type (might be due to invalid IL or missing references) //IL_00e8: Unknown result type (might be due to invalid IL or missing references) //IL_00ed: Unknown result type (might be due to invalid IL or missing references) //IL_00f8: Unknown result type (might be due to invalid IL or missing references) //IL_00ff: Unknown result type (might be due to invalid IL or missing references) //IL_0220: Unknown result type (might be due to invalid IL or missing references) //IL_022c: Unknown result type (might be due to invalid IL or missing references) //IL_0231: Unknown result type (might be due to invalid IL or missing references) //IL_0236: Unknown result type (might be due to invalid IL or missing references) //IL_0254: Unknown result type (might be due to invalid IL or missing references) //IL_0259: Unknown result type (might be due to invalid IL or missing references) //IL_025d: Unknown result type (might be due to invalid IL or missing references) //IL_0262: Unknown result type (might be due to invalid IL or missing references) //IL_06c3: Unknown result type (might be due to invalid IL or missing references) //IL_027d: Unknown result type (might be due to invalid IL or missing references) //IL_0282: Unknown result type (might be due to invalid IL or missing references) //IL_0287: Unknown result type (might be due to invalid IL or missing references) //IL_0294: Unknown result type (might be due to invalid IL or missing references) //IL_0299: Unknown result type (might be due to invalid IL or missing references) //IL_029e: Unknown result type (might be due to invalid IL or missing references) //IL_02a2: Unknown result type (might be due to invalid IL or missing references) //IL_02a7: Unknown result type (might be due to invalid IL or missing references) //IL_02b2: Unknown result type (might be due to invalid IL or missing references) //IL_02b7: Unknown result type (might be due to invalid IL or missing references) //IL_0125: Unknown result type (might be due to invalid IL or missing references) //IL_012a: Unknown result type (might be due to invalid IL or missing references) //IL_012f: Unknown result type (might be due to invalid IL or missing references) //IL_0134: Unknown result type (might be due to invalid IL or missing references) //IL_0139: Unknown result type (might be due to invalid IL or missing references) //IL_015a: Unknown result type (might be due to invalid IL or missing references) //IL_013f: Unknown result type (might be due to invalid IL or missing references) //IL_0141: Unknown result type (might be due to invalid IL or missing references) //IL_0146: Unknown result type (might be due to invalid IL or missing references) //IL_014b: Unknown result type (might be due to invalid IL or missing references) //IL_0522: Unknown result type (might be due to invalid IL or missing references) //IL_0527: Unknown result type (might be due to invalid IL or missing references) //IL_053e: Unknown result type (might be due to invalid IL or missing references) //IL_0558: Expected O, but got Unknown //IL_0397: Unknown result type (might be due to invalid IL or missing references) //IL_0382: Unknown result type (might be due to invalid IL or missing references) //IL_03c2: Unknown result type (might be due to invalid IL or missing references) //IL_03ad: Unknown result type (might be due to invalid IL or missing references) //IL_048f: Unknown result type (might be due to invalid IL or missing references) //IL_049d: Unknown result type (might be due to invalid IL or missing references) //IL_04ab: Unknown result type (might be due to invalid IL or missing references) //IL_03ef: Unknown result type (might be due to invalid IL or missing references) //IL_03fc: Unknown result type (might be due to invalid IL or missing references) //IL_0408: Unknown result type (might be due to invalid IL or missing references) (GameObject, bool) key = (prefab, forward); if (cache.TryGetValue(key, out var value)) { return value; } Shape shape = new Shape(); bool flag = false; List<MeshFilter> list = new List<MeshFilter>(); MeshFilter[] componentsInChildren = prefab.GetComponentsInChildren<MeshFilter>(true); foreach (MeshFilter val in componentsInChildren) { MeshRenderer component = ((Component)val).GetComponent<MeshRenderer>(); if (!Object.op_Implicit((Object)(object)component) || !((Renderer)component).enabled || !Object.op_Implicit((Object)(object)val.sharedMesh)) { continue; } bool flag2 = true; Transform val2 = ((Component)val).transform; while (Object.op_Implicit((Object)(object)val2) && (Object)(object)val2 != (Object)(object)prefab.transform) { if (!((Component)val2).gameObject.activeSelf) { flag2 = false; } val2 = val2.parent; } if (!flag2) { continue; } list.Add(val); Bounds bounds = val.sharedMesh.bounds; Matrix4x4 val3 = prefab.transform.worldToLocalMatrix * ((Component)val).transform.localToWorldMatrix; for (int j = 0; j < 8; j++) { Vector3 val4 = ((Matrix4x4)(ref val3)).MultiplyPoint3x4(((Bounds)(ref bounds)).center + Vector3.Scale(((Bounds)(ref bounds)).extents, new Vector3((float)(((j & 1) != 0) ? 1 : (-1)), (float)(((j & 2) != 0) ? 1 : (-1)), (float)(((j & 4) != 0) ? 1 : (-1))))); if (!flag) { shape.Bounds = new Bounds(val4, Vector3.zero); flag = true; } else { ((Bounds)(ref shape.Bounds)).Encapsulate(val4); } } } if (!flag || ((Bounds)(ref shape.Bounds)).size.z < 0.05f) { cache[key] = shape; return shape; } float num = (forward ? (((Bounds)(ref shape.Bounds)).min.z + ((Bounds)(ref shape.Bounds)).size.z * 0.65f) : (((Bounds)(ref shape.Bounds)).max.z - ((Bounds)(ref shape.Bounds)).size.z * 0.65f)); try { foreach (MeshFilter item in list) { Mesh sharedMesh = item.sharedMesh; Matrix4x4 val5 = prefab.transform.worldToLocalMatrix * ((Component)item).transform.localToWorldMatrix; Read(sharedMesh, out var positions, out var normals, out var uv, out var groups); Vertex[] array = new Vertex[positions.Length]; Matrix4x4 inverse = ((Matrix4x4)(ref val5)).inverse; Matrix4x4 transpose = ((Matrix4x4)(ref inverse)).transpose; for (int k = 0; k < array.Length; k++) { int num2 = k; Vertex vertex = new Vertex { P = ((Matrix4x4)(ref val5)).MultiplyPoint3x4(positions[k]) }; Vector3 val6 = ((Matrix4x4)(ref transpose)).MultiplyVector(normals[k]); vertex.N = ((Vector3)(ref val6)).normalized; vertex.UV = uv[k]; array[num2] = vertex; } List<Vector3> list2 = new List<Vector3>(); List<Vector3> list3 = new List<Vector3>(); List<Vector2> list4 = new List<Vector2>(); List<int[]> list5 = new List<int[]>(); foreach (int[] item2 in groups) { List<int> list6 = new List<int>(); for (int l = 0; l + 2 < item2.Length; l += 3) { List<Vertex> list7 = new List<Vertex> { array[item2[l]], array[item2[l + 1]], array[item2[l + 2]] }; List<Vertex> list8 = new List<Vertex>(); for (int m = 0; m < 3; m++) { Vertex vertex2 = list7[m]; Vertex b = list7[(m + 1) % 3]; bool num3 = (forward ? (vertex2.P.z <= num) : (vertex2.P.z >= num)); bool flag3 = (forward ? (b.P.z <= num) : (b.P.z >= num)); if (num3) { list8.Add(vertex2); } if (num3 != flag3) { list8.Add(Vertex.Mix(vertex2, b, (num - vertex2.P.z) / (b.P.z - vertex2.P.z))); } } for (int n = 1; n + 1 < list8.Count; n++) { Vertex[] array2 = new Vertex[3] { list8[0], list8[n], list8[n + 1] }; for (int i = 0; i < array2.Length; i++) { Vertex vertex3 = array2[i]; list6.Add(list2.Count); list2.Add(vertex3.P); list3.Add(vertex3.N); list4.Add(vertex3.UV); } } } list5.Add(list6.ToArray()); } if (list2.Count != 0) { Mesh val7 = new Mesh { name = "OctoArsenal_ArrowTail_" + ((Object)sharedMesh).name, indexFormat = (IndexFormat)(list2.Count > 65535) }; val7.SetVertices(list2); val7.SetNormals(list3); val7.SetUVs(0, list4); val7.subMeshCount = list5.Count; for (int num4 = 0; num4 < list5.Count; num4++) { val7.SetTriangles(list5[num4], num4); } val7.RecalculateBounds(); val7.RecalculateTangents(); shape.Parts.Add(new Part { Mesh = val7, Materials = ((Renderer)((Component)item).GetComponent<MeshRenderer>()).sharedMaterials }); } } } catch (Exception ex) { foreach (Part part in shape.Parts) { Object.Destroy((Object)(object)part.Mesh); } shape.Parts.Clear(); Plugin.Instance?.Warn("Could not build headless arrow visual for " + ((Object)prefab).name + ": " + ex.Message); } if (shape.Parts.Count > 0) { shape.Bounds = shape.Parts[0].Mesh.bounds; foreach (Part part2 in shape.Parts) { ((Bounds)(ref shape.Bounds)).Encapsulate(part2.Mesh.bounds); } } cache[key] = shape; return shape; } private static void Read(Mesh mesh, out Vector3[] positions, out Vector3[] normals, out Vector2[] uv, out List<int[]> groups) { //IL_0120: Unknown result type (might be due to invalid IL or missing references) //IL_0125: Unknown result type (might be due to invalid IL or missing references) //IL_0144: Unknown result type (might be due to invalid IL or missing references) //IL_0149: Unknown result type (might be due to invalid IL or missing references) //IL_0160: Unknown result type (might be due to invalid IL or missing references) //IL_0165: Unknown result type (might be due to invalid IL or missing references) //IL_0192: Unknown result type (might be due to invalid IL or missing references) //IL_024a: Unknown result type (might be due to invalid IL or missing references) //IL_024f: Unknown result type (might be due to invalid IL or missing references) //IL_01c0: Unknown result type (might be due to invalid IL or missing references) //IL_01c5: Unknown result type (might be due to invalid IL or missing references) groups = new List<int[]>(); if (mesh.isReadable) { positions = mesh.vertices; normals = mesh.normals; uv = mesh.uv; if (normals.Length != positions.Length) { normals = (Vector3[])(object)new Vector3[positions.Length]; } if (uv.Length != positions.Length) { uv = (Vector2[])(object)new Vector2[positions.Length]; } for (int i = 0; i < mesh.subMeshCount; i++) { groups.Add(mesh.GetIndices(i)); } return; } Dictionary<int, byte[]> streams = new Dictionary<int, byte[]>(); float[] array = Attribute((VertexAttribute)0, 3); float[] array2 = Attribute((VertexAttribute)1, 3); float[] array3 = Attribute((VertexAttribute)4, 2); positions = (Vector3[])(object)new Vector3[mesh.vertexCount]; normals = (Vector3[])(object)new Vector3[mesh.vertexCount]; uv = (Vector2[])(object)new Vector2[mesh.vertexCount]; for (int j = 0; j < mesh.vertexCount; j++) { positions[j] = new Vector3(array[j * 3], array[j * 3 + 1], array[j * 3 + 2]); normals[j] = new Vector3(array2[j * 3], array2[j * 3 + 1], array2[j * 3 + 2]); uv[j] = new Vector2(array3[j * 2], array3[j * 2 + 1]); } GraphicsBuffer indexBuffer = mesh.GetIndexBuffer(); try { if ((int)mesh.indexFormat == 0) { ushort[] array4 = new ushort[indexBuffer.count]; indexBuffer.GetData((Array)array4); for (int k = 0; k < mesh.subMeshCount; k++) { SubMeshDescriptor subMesh = mesh.GetSubMesh(k); int[] array5 = new int[((SubMeshDescriptor)(ref subMesh)).indexCount]; for (int l = 0; l < array5.Length; l++) { array5[l] = array4[((SubMeshDescriptor)(ref subMesh)).indexStart + l] + ((SubMeshDescriptor)(ref subMesh)).baseVertex; } groups.Add(array5); } return; } int[] array6 = new int[indexBuffer.count]; indexBuffer.GetData((Array)array6); for (int m = 0; m < mesh.subMeshCount; m++) { SubMeshDescriptor subMesh2 = mesh.GetSubMesh(m); int[] array7 = new int[((SubMeshDescriptor)(ref subMesh2)).indexCount]; for (int n = 0; n < array7.Length; n++) { array7[n] = array6[((SubMeshDescriptor)(ref subMesh2)).indexStart + n] + ((SubMeshDescriptor)(ref subMesh2)).baseVertex; } groups.Add(array7); } } finally { ((IDisposable)indexBuffer)?.Dispose(); } unsafe float[] Attribute(VertexAttribute attribute, int minimum) { //IL_0006: 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_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_0035: 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_0043: Invalid comparison between Unknown and I4 //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Invalid comparison between Unknown and I4 //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: Unknown result type (might be due to invalid IL or missing references) //IL_00c2: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Invalid comparison between Unknown and I4 //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Invalid comparison between Unknown and I4 //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Invalid comparison between Unknown and I4 if (!mesh.HasVertexAttribute(attribute)) { return new float[mesh.vertexCount * minimum]; } VertexAttributeFormat format = mesh.GetVertexAttributeFormat(attribute); int num = (((int)format == 0) ? 4 : (((int)format == 1 || (int)format == 4 || (int)format == 5) ? 2 : (((int)format == 2 || (int)format == 3) ? 1 : 0))); if (num == 0) { throw new InvalidOperationException("Unsupported native vertex format for " + ((object)(*(VertexAttribute*)(&attribute))/*cast due to .constrained prefix*/).ToString()); } int vertexAttributeStream = mesh.GetVertexAttributeStream(attribute); int vertexBufferStride = mesh.GetVertexBufferStride(vertexAttributeStream); int vertexAttributeOffset = mesh.GetVertexAttributeOffset(attribute); int vertexAttributeDimension = mesh.GetVertexAttributeDimension(attribute); if (!streams.TryGetValue(vertexAttributeStream, out var data)) { GraphicsBuffer vertexBuffer = mesh.GetVertexBuffer(vertexAttributeStream); try { data = new byte[mesh.vertexCount * vertexBufferStride]; vertexBuffer.GetData((Array)data); } finally { ((IDisposable)vertexBuffer)?.Dispose(); } streams[vertexAttributeStream] = data; } float[] array8 = new float[mesh.vertexCount * minimum]; for (int num2 = 0; num2 < mesh.vertexCount; num2++) { for (int num3 = 0; num3 < Math.Min(minimum, vertexAttributeDimension); num3++) { array8[num2 * minimum + num3] = Component(num2 * vertexBufferStride + vertexAttributeOffset + num3 * num); } } return array8; float Component(int at) { //IL_0001: 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_001c: Invalid comparison between Unknown and I4 //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Invalid comparison between Unknown and I4 //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Invalid comparison between Unknown and I4 //IL_0070: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Invalid comparison between Unknown and I4 if ((int)format == 0) { return BitConverter.ToSingle(data, at); } if ((int)format == 2) { return (float)(int)data[at] / 255f; } if ((int)format == 3) { return Math.Max(-1f, (float)(sbyte)data[at] / 127f); } if ((int)format == 4) { return (float)(int)BitConverter.ToUInt16(data, at) / 65535f; } if ((int)format == 5) { return Math.Max(-1f, (float)BitConverter.ToInt16(data, at) / 32767f); } ushort num4 = BitConverter.ToUInt16(data, at); int num5 = (num4 >> 10) & 0x1F; int num6 = num4 & 0x3FF; float num7 = num5 switch { 31 => (num6 == 0) ? float.PositiveInfinity : float.NaN, 0 => (float)((double)num6 * Math.Pow(2.0, -24.0)), _ => (float)((1.0 + (double)num6 / 1024.0) * Math.Pow(2.0, num5 - 15)), }; if ((num4 & 0x8000) == 0) { return num7; } return 0f - num7; } } } internal static void Dispose() { foreach (Shape value in cache.Values) { foreach (Part part in value.Parts) { Object.Destroy((Object)(object)part.Mesh); } } cache.Clear(); } } internal static class Items { internal sealed class State { internal ItemData Item; internal Inventory Inventory; internal bool Valid; internal bool Loading; internal DateTime RetryAfter; internal void Save() { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Expected O, but got Unknown if (Valid && !Loading) { ZPackage val = new ZPackage(); Inventory.Save(val); Item.m_customData["OctoPack.Quiver.Inventory.v1"] = val.GetBase64(); } } } internal const string Marker = "OctoPack.Quiver.Item.v1"; internal const string Wanted = "OctoPack.Quiver.Equipped.v1"; internal const string Data = "OctoPack.Quiver.Inventory.v1"; internal const string Net = "OctoPack.Quiver.Visible.v1"; private static readonly ConditionalWeakTable<ItemData, State> states = new ConditionalWeakTable<ItemData, State>(); private static readonly ConditionalWeakTable<Inventory, State> inventories = new ConditionalWeakTable<Inventory, State>(); internal static State Active; private static Recipe recipe; private static ObjectDB db; private static GameObject cache; private static int lastScraps = -1; private static int lastHide = -1; private static int lastWood = -1; private static int lastStation = -1; private static ObjectDB ammoDB; private static string arrowAmmoType; internal static readonly string[] NetSlots = new string[3] { "OctoPack.Quiver.Visible.v10", "OctoPack.Quiver.Visible.v11", "OctoPack.Quiver.Visible.v12" }; internal static readonly string[] NetCounts = new string[3] { "OctoPack.Quiver.Visible.v10Count", "OctoPack.Quiver.Visible.v11Count", "OctoPack.Quiver.Visible.v12Count" }; private static readonly FieldInfo AmmoField = typeof(Humanoid).GetField("m_ammoItem", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); internal static bool Is(ItemData item) { if (item?.m_customData != null) { return item.m_customData.ContainsKey("OctoPack.Quiver.Item.v1"); } return false; } internal static bool ArrowType(string type) { ObjectDB instance = ObjectDB.instance; if (instance != ammoDB || string.IsNullOrEmpty(arrowAmmoType)) { GameObject val = (Object.op_Implicit((Object)(object)instance) ? instance.GetItemPrefab("ArrowWood") : null); arrowAmmoType = ((!Object.op_Implicit((Object)(object)val)) ? null : val.GetComponent<ItemDrop>()?.m_itemData.m_shared.m_ammoType); ammoDB = instance; } if (!string.IsNullOrEmpty(type) && !string.IsNullOrEmpty(arrowAmmoType)) { return type == arrowAmmoType; } return false; } internal static bool Arrow(ItemData item) { //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Invalid comparison between Unknown and I4 if (item?.m_shared != null && (int)item.m_shared.m_itemType == 9) { return ArrowType(item.m_shared.m_ammoType); } return false; } internal static bool Owned(Inventory inv) { State value; if (inv != null) { return inventories.TryGetValue(inv, out value); } return false; } internal static bool AllowAdd(Inventory __instance, object[] __args, ref bool __result) { if (__instance == null || !inventories.TryGetValue(__instance, out var value)) { return true; } if (value.Loading) { return true; } foreach (object obj in __args) { ItemData val = (ItemData)((obj is ItemData) ? obj : null); if (val == null) { GameObject val2 = (GameObject)((obj is GameObject) ? obj : null); if (val2 != null) { val = val2.GetComponent<ItemDrop>()?.m_itemData; } } if (val != null && !Arrow(val)) { __result = false; return false; } } return true; } internal static bool Selected(ItemData item) { if (Is(item) && item.m_customData.TryGetValue("OctoPack.Quiver.Equipped.v1", out var value)) { return value == "1"; } return false; } private static bool Eligible(Player p, ItemData item) { if (Object.op_Implicit((Object)(object)p) && (Object)(object)p == (Object)(object)Player.m_localPlayer && !((Character)p).IsDead() && ((Humanoid)p).GetInventory().ContainsItem(item)) { return BackpackBridge.IsBackpackSlot(p, item); } return false; } internal static State For(ItemData item) { //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_0078: Expected O, but got Unknown //IL_0116: Unknown result type (might be due to invalid IL or missing references) //IL_0120: Expected O, but got Unknown if (states.TryGetValue(item, out var value)) { if (value.Valid || value.Loading || DateTime.UtcNow < value.RetryAfter) { return value; } inventories.Remove(value.Inventory); } else { value = new State { Item = item }; states.Add(item, value); } value.Inventory = new Inventory("Quiver", (Sprite)null, 3, 1); inventories.Add(value.Inventory, value); value.Loading = true; value.Valid = false; value.RetryAfter = DateTime.UtcNow.AddSeconds(5.0); try { if (item.m_customData.TryGetValue("OctoPack.Quiver.Inventory.v1", out var value2) && !string.IsNullOrEmpty(value2)) { byte[] array = Convert.FromBase64String(value2); if (array.Length < 6 || BitConverter.ToInt32(array, 0) != 110) { throw new InvalidOperationException("Unsupported saved quiver format."); } int num = BitConverter.ToUInt16(array, 4); if (num > 3) { throw new InvalidOperationException("Too many saved quiver stacks."); } value.Inventory.Load(new ZPackage(value2)); if (value.Inventory.GetAllItems().Count != num) { throw new InvalidOperationException("One or more stored arrow prefabs are unavailable."); } } HashSet<int> hashSet = new HashSet<int>(); foreach (ItemData allItem in value.Inventory.GetAllItems()) { if (!Arrow(allItem) || allItem.m_stack < 1 || allItem.m_gridPos.y != 0 || allItem.m_gridPos.x < 0 || allItem.m_gridPos.x >= 3 || !hashSet.Add(allItem.m_gridPos.x)) { throw new InvalidOperationException("Invalid quiver contents; original saved data retained."); } allItem.m_equipped = false; } value.Valid = true; } catch (Exception ex) { Plugin.Instance?.Warn("Quiver inventory could not load; saved contents will not be overwritten. Will retry. " + ex); } finally { value.Loading = false; } State captured = value; if (value.Valid) { Inventory inventory = value.Inventory; inventory.m_onChanged = (Action)Delegate.Combine(inventory.m_onChanged, (Action)delegate { captured.Save(); Player localPlayer = Player.m_localPlayer; if (Object.op_Implicit((Object)(object)localPlayer) && ((Humanoid)localPlayer).GetInventory().ContainsItem(captured.Item)) { Changed(((Humanoid)localPlayer).GetInventory()); } }); } return value; } internal static void Changed(Inventory inventory) { InventoryRefresh.Notify(inventory); } internal static void Decorate(ItemData item) { //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Expected O, but got Unknown //IL_0088: Unknown result type (might be due to invalid IL or missing references) if (Is(item) && item.m_shared != null && !(item.m_shared.m_name == "OctoPack Quiver")) { item.m_shared = (SharedData)typeof(object).GetMethod("MemberwiseClone", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(item.m_shared, null); SharedData shared = item.m_shared; shared.m_name = "OctoPack Quiver"; shared.m_description = "Equip from a backpack slot. Holds three arrow stacks at 25% less weight. Cannot be worn with the lantern arm."; shared.m_icons = (Sprite[])(object)new Sprite[1] { Model.Icon() }; shared.m_itemType = (ItemType)1; shared.m_questItem = false; shared.m_equipStatusEffect = null; shared.m_useDurability = false; shared.m_maxStackSize = 1; shared.m_maxQuality = 1; shared.m_weight = 2f; } } private static void Mark(ItemData item) { item.m_customData["OctoPack.Quiver.Item.v1"] = "1"; item.m_customData["OctoPack.Quiver.Equipped.v1"] = "0"; Decorate(item); } internal static bool Arm(ItemData item) { if (item == null) { return false; } foreach (string key in item.m_customData.Keys) { if (key.IndexOf("LanternArm", StringComparison.OrdinalIgnoreCase) >= 0 && key.IndexOf("Item", StringComparison.OrdinalIgnoreCase) >= 0) { return true; } } return item.m_shared.m_name == "OctoPack Lantern Arm"; } internal static bool ArmSelected(ItemData item) { if (!Arm(item)) { return false; } foreach (KeyValuePair<string, string> customDatum in item.m_customData) { if (customDatum.Key.IndexOf("Equipped", StringComparison.OrdinalIgnoreCase) >= 0 && customDatum.Value == "1") { return true; } } return item.m_equipped; } internal static void ClearArm(Player p) { foreach (ItemData allItem in ((Humanoid)p).GetInventory().GetAllItems()) { if (!Arm(allItem)) { continue; } ((Humanoid)p).UnequipItem(allItem, false); foreach (string item in new List<string>(allItem.m_customData.Keys)) { if (item.IndexOf("Equipped", StringComparison.OrdinalIgnoreCase) >= 0) { allItem.m_customData[item] = "0"; } } allItem.m_equipped = false; } } internal static void Disable() { if (Active != null) { Active.Save(); ClearAmmo(Active); Active.Item.m_equipped = false; Active.Item.m_customData["OctoPack.Quiver.Equipped.v1"] = "0"; Active = null; } Player localPlayer = Player.m_localPlayer; if (!Object.op_Implicit((Object)(object)localPlayer)) { return; } foreach (ItemData allItem in ((Humanoid)localPlayer).GetInventory().GetAllItems()) { if (Is(allItem)) { allItem.m_customData["OctoPack.Quiver.Equipped.v1"] = "0"; allItem.m_equipped = false; } } } private static void Enable(Player p, ItemData item) { if (!Eligible(p, item)) { if (p != null) { ((Character)p).Message((MessageType)2, "Move the quiver into a backpack slot first.", 0, (Sprite)null, false); } return; } State state = For(item); if (!state.Valid) { ((Character)p).Message((MessageType)2, "Quiver saved data could not be loaded; check the log.", 0, (Sprite)null, false); return; } OctoArsenal.Carrier.Items.Disable(); Disable(); ClearArm(p); item.m_customData["OctoPack.Quiver.Equipped.v1"] = "1"; Active = state; item.m_equipped = true; Tick(); } internal static bool Use(Humanoid __instance, ItemData item) { Player val = (Player)(object)((__instance is Player) ? __instance : null); if ((Object)(object)val != (Object)(object)Player.m_localPlayer) { return true; } if (Arm(item)) { if (!ArmSelected(item) && BackpackBridge.IsBackpackSlot(val, item)) { Disable(); } return true; } if (Is(item)) { if (Selected(item)) { Disable(); } else { Enable(val, item); } return false; } if (Active != null && Active.Inventory.ContainsItem(item)) { Select(item.m_gridPos.x); return false; } return true; } internal static bool Equip(Humanoid __instance, ItemData item, ref bool __result) { Player val = (Player)(object)((__instance is Player) ? __instance : null); if ((Object)(object)val != (Object)(object)Player.m_localPlayer) { return true; } if (Arm(item)) { if (BackpackBridge.IsBackpackSlot(val, item)) { Disable(); } return true; } if (Is(item)) { Enable(val, item); __result = Active != null && Active.Item == item; return false; } if (Active != null && Active.Inventory.ContainsItem(item)) { Select(item.m_gridPos.x); __result = true; return false; } return true; } internal static bool Unequip(Humanoid __instance, ItemData item) { if ((Object)(object)__instance != (Object)(object)Player.m_localPlayer) { return true; } if (Is(item)) { if (Active?.Item == item) { Disable(); } else { item.m_customData["OctoPack.Quiver.Equipped.v1"] = "0"; item.m_equipped = false; } return false; } return true; } internal static void IsEquipped(Humanoid __instance, ItemData item, ref bool __result) { if (Is(item)) { __result = (Object)(object)__instance == (Object)(object)Player.m_localPlayer && Active?.Item == item; } } internal static void Select(int slot) { Player localPlayer = Player.m_localPlayer; State active = Active; ItemData val = ((active != null) ? active.Inventory.GetItemAt(slot, 0) : null); if (Object.op_Implicit((Object)(object)localPlayer) && val != null) { AssignAmmo((Humanoid)(object)localPlayer, val); Active.Save(); ((Character)localPlayer).Message((MessageType)1, Localization.instance.Localize(val.m_shared.m_name), 0, (Sprite)null, false); } } internal static void AssignAmmo(Humanoid character, ItemData item) { ItemData ammoItem = character.GetAmmoItem(); if (ammoItem != null && ammoItem != item) { ammoItem.m_equipped = false; } AmmoField.SetValue(character, item); if (item != null) { item.m_equipped = true; } } internal static bool Hotbar(Player __instance, int __0) { //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_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Invalid comparison between Unknown and I4 //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) if ((Object)(object)__instance != (Object)(object)Player.m_localPlayer || Active == null || !Object.op_Implicit((Object)(object)Plugin.Instance)) { return true; } ConfigEntry<KeyboardShortcut>[] keys = Plugin.Instance.Keys; foreach (ConfigEntry<KeyboardShortcut> val in keys) { KeyboardShortcut value = val.Value; if ((int)((KeyboardShortcut)(ref value)).MainKey == 48 + __0) { value = val.Value; if (((KeyboardShortcut)(ref value)).IsPressed()) { return false; } } } return true; } private static void ClearAmmo(State state) { Player localPlayer = Player.m_localPlayer; if (Object.op_Implicit((Object)(object)localPlayer)) { ItemData ammoItem = ((Humanoid)localPlayer).GetAmmoItem(); if (ammoItem != null && state.Inventory.ContainsItem(ammoItem)) { ammoItem.m_equipped = false; AmmoField.SetValue(localPlayer, null); } } } internal static void Tick() { Player localPlayer = Player.m_localPlayer; if (!Object.op_Implicit((Object)(object)localPlayer)) { if (Active != null) { Active.Save(); Active = null; } return; } State state = null; bool flag = false; foreach (ItemData allItem in ((Humanoid)localPlayer).GetInventory().GetAllItems()) { if (ArmSelected(allItem) && BackpackBridge.IsBackpackSlot(localPlayer, allItem)) { flag = true; } } foreach (ItemData allItem2 in ((Humanoid)localPlayer).GetInventory().GetAllItems()) { if (Is(allItem2)) { Decorate(allItem2); if (allItem2.m_equipped = state == null && !flag && Selected(allItem2) && Eligible(localPlayer, allItem2) && For(allItem2).Valid) { state = For(allItem2); } } } if (Active != state) { if (Active != null) { Active.Save(); ClearAmmo(Active); } Active = state; } ZNetView component = ((Component)localPlayer).GetComponent<ZNetView>(); ZDO val = (Object.op_Implicit((Object)(object)component) ? component.GetZDO() : null); if (!Object.op_Implicit((Object)(object)component) || !component.IsOwner() || val == null) { return; } bool flag2 = Active != null; if (val.GetBool("OctoPack.Quiver.Visible.v1", false) != flag2) { val.Set("OctoPack.Quiver.Visible.v1", flag2); } for (int i = 0; i < 3; i++) { State active = Active; ItemData val2 = ((active != null) ? active.Inventory.GetItemAt(i, 0) : null); string text = (Object.op_Implicit((Object)(object)val2?.m_dropPrefab) ? ((Object)val2.m_dropPrefab).name : ""); int num = ((val2 != null) ? Math.Min(3, val2.m_stack) : 0); if (val.GetString(NetSlots[i], "") != text) { val.Set(NetSlots[i], text); } if (val.GetInt(NetCounts[i], 0) != num) { val.Set(NetCounts[i], num); } } } internal static void Flush() { Active?.Save(); } internal static void Death(Player __instance) { if ((Object)(object)__instance == (Object)(object)Player.m_localPlayer) { Flush(); ClearAmmoIfActive(); } } private static void ClearAmmoIfActive() { if (Active != null) { ClearAmmo(Active); } } internal static void Loaded(Inventory __instance) { foreach (ItemData allItem in __instance.GetAllItems()) { Decorate(allItem); } } internal static void Weight(ItemData __instance, ref float __result) { if (!Is(__instance)) { return; } State state = For(__instance); if (!state.Valid) { return; } float num = 0f; foreach (ItemData allItem in state.Inventory.GetAllItems()) { num += allItem.GetWeight(-1); } __result += num * 0.75f; } internal static void EnsureRecipe() { //IL_00b9: Unknown result type (might be due to invalid IL or missing references) //IL_00c3: Expected O, but got Unknown //IL_00dd: Unknown result type (might be due to invalid IL or missing references) //IL_00e2: 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) ObjectDB instance = ObjectDB.instance; if (!Object.op_Implicit((Object)(object)instance) || !Object.op_Implicit((Object)(object)ZNetScene.instance)) { return; } if ((Object)(object)db == (Object)(object)instance && Object.op_Implicit((Object)(object)recipe)) { UpdateCosts(); return; } GameObject itemPrefab = instance.GetItemPrefab("Wishbone"); GameObject prefab = ZNetScene.instance.GetPrefab("piece_workbench"); CraftingStation val = ((prefab != null) ? prefab.GetComponent<CraftingStation>() : null); if (Object.op_Implicit((Object)(object)itemPrefab) && Object.op_Implicit((Object)(object)val) && Object.op_Implicit((Object)(object)instance.GetItemPrefab("LeatherScraps")) && Object.op_Implicit((Object)(object)instance.GetItemPrefab("DeerHide")) && Object.op_Implicit((Object)(object)instance.GetItemPrefab("FineWood"))) { Dispose(); db = instance; cache = new GameObject("QuiverRecipeCache"); cache.SetActive(false); Object.DontDestroyOnLoad((Object)(object)cache); GameObject val2 = new GameObject("Wishbone"); val2.SetActive(false); val2.transform.SetParent(cache.transform, false); ItemDrop val3 = val2.AddComponent<ItemDrop>(); val3.m_itemData = itemPrefab.GetComponent<ItemDrop>().m_itemData.Clone(); val3.m_itemData.m_dropPrefab = itemPrefab; val3.m_itemData.m_customData = new Dictionary<string, string>(); Mark(val3.m_itemData); recipe = ScriptableObject.CreateInstance<Recipe>(); ((Object)recipe).name = "Recipe_OctoPack_Quiver"; recipe.m_item = val3; recipe.m_amount = 1; recipe.m_enabled = true; recipe.m_craftingStation = (recipe.m_repairStation = val); UpdateCosts(); db.m_recipes.Add(recipe); Player localPlayer = Player.m_localPlayer; if (Object.op_Implicit((Object)(object)localPlayer)) { AccessTools.Method(typeof(Player), "UpdateKnownRecipesList", (Type[])null, (Type[])null).Invoke(localPlayer, null); } } } private static void UpdateCosts() { Plugin instance = Plugin.Instance; int value = instance.Scraps.Value; int value2 = instance.Hide.Value; int value3 = instance.Wood.Value; int value4 = instance.StationLevel.Value; if (value != lastScraps || value2 != lastHide || value3 != lastWood || value4 != lastStation) { recipe.m_minStationLevel = value4; recipe.m_resources = (Requirement[])(object)new Requirement[3] { Cost("LeatherScraps", value), Cost("DeerHide", value2), Cost("FineWood", value3) }; lastScraps = value; lastHide = value2; lastWood = value3; lastStation = value4; } } private static Requirement Cost(string name, int amount) { //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_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Expected O, but got Unknown return new Requirement { m_resItem = db.GetItemPrefab(name).GetComponent<ItemDrop>(), m_amount = amount }; } internal static void BeforeCraft(InventoryGui __instance, Player player, out HashSet<ItemData> __state) { __state = ((Object.op_Implicit((Object)(object)recipe) && AccessTools.Field(typeof(InventoryGui), "m_craftRecipe").GetValue(__instance) == recipe && Object.op_Implicit((Object)(object)player)) ? new HashSet<ItemData>(((Humanoid)player).GetInventory().GetAllItems()) : null); } internal static void AfterCraft(Player player, HashSet<ItemData> __state) { if (!Object.op_Implicit((Object)(object)player) || __state == null) { return; } foreach (ItemData allItem in ((Humanoid)player).GetInventory().GetAllItems()) { if (!__state.Contains(allItem) && Object.op_Implicit((Object)(object)allItem.m_dropPrefab) && ((Object)allItem.m_dropPrefab).name == "Wishbone") { Mark(allItem); } } Changed(((Humanoid)player).GetInventory()); } internal static void Dispose() { if (Object.op_Implicit((Object)(object)db) && Object.op_Implicit((Object)(object)recipe)) { db.m_recipes.Remove(recipe); } if (Object.op_Implicit((Object)(object)recipe)) { Object.Destroy((Object)(object)recipe); } if (Object.op_Implicit((Object)(object)cache)) { Object.Destroy((Object)(object)cache); } recipe = null; cache = null; db = null; lastScraps = (lastHide = (lastWood = (lastStation = -1))); ammoDB = null; arrowAmmoType = null; } } internal static class Model { private static readonly List<Mesh> meshes = new List<Mesh>(); private static readonly List<Material> materials = new List<Material>(); private static readonly List<Texture2D> textures = new List<Texture2D>(); private static readonly List<int> slots = new List<int>(); private static Texture2D iconTexture; private static Sprite icon; private static byte[] Resource(string name) { using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(name); using MemoryStream memoryStream = new MemoryStream(); if (stream == null) { throw new FileNotFoundException(name); } stream.CopyTo(memoryStream); return memoryStream.ToArray(); } internal static Sprite Icon() { //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Expected O, but got Unknown //IL_0058: 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) if (Object.op_Implicit((Object)(object)icon)) { return icon; } iconTexture = new Texture2D(2, 2); ImageConversion.LoadImage(iconTexture, Resource("Quiver.Icon")); icon = Sprite.Create(iconTexture, new Rect(0f, 0f, (float)((Texture)iconTexture).width, (float)((Texture)iconTexture).height), new Vector2(0.5f, 0.5f), 128f); return icon; } private static string Text(BinaryReader r) { int num = r.ReadInt32(); if (num < 0 || num > 1024) { throw new InvalidDataException(); } return Encoding.UTF8.GetString(r.ReadBytes(num)); } private static Vector3 V(BinaryReader r) { //IL_0012: Unknown result type (might be due to invalid IL or missing references) return new Vector3(r.ReadSingle(), r.ReadSingle(), r.ReadSingle()); } private static void Load(Material fallback) { //IL_008e: Unknown result type (might be due to invalid IL or missing references) //IL_0095: Expected O, but got Unknown //IL_012b: Unknown result type (might be due to invalid IL or missing references) //IL_0122: Unknown result type (might be due to invalid IL or missing references) //IL_0132: Expected O, but got Unknown //IL_0142: Unknown result type (might be due to invalid IL or missing references) //IL_01f6: Unknown result type (might be due to invalid IL or missing references) //IL_01fb: Unknown result type (might be due to invalid IL or missing references) //IL_0205: Unknown result type (might be due to invalid IL or missing references) //IL_020a: Unknown result type (might be due to invalid IL or missing references) //IL_021f: Unknown result type (might be due to invalid IL or missing references) //IL_0224: Unknown result type (might be due to invalid IL or missing references) //IL_0262: Unknown result type (might be due to invalid IL or missing references) //IL_0267: Unknown result type (might be due to invalid IL or missing references) //IL_0271: Expected O, but got Unknown if (meshes.Count > 0) { return; } using MemoryStream stream = new MemoryStream(Resource("Quiver.Model")); using GZipStream input = new GZipStream(stream, CompressionMode.Decompress); using BinaryReader binaryReader = new BinaryReader(input); if (binaryReader.ReadInt32() != 827740495) { throw new InvalidDataException("Quiver model header"); } int num = binaryReader.ReadInt32(); for (int i = 0; i < num; i++) { int num2 = binaryReader.ReadInt32(); int num3 = binaryReader.ReadInt32(); byte[] array = binaryReader.ReadBytes(checked(num2 * num3 * 4)); if (array.Length != num2 * num3 * 4) { throw new InvalidDataException("Truncated quiver texture"); } Texture2D val = new Texture2D(num2, num3, (TextureFormat)4, false); textures.Add(val); val.LoadRawTextureData(array); val.Apply(false, true); } num = binaryReader.ReadInt32(); Color val2 = default(Color); for (int j = 0; j < num; j++) { string name = Text(binaryReader); int num4 = binaryReader.ReadInt32(); ((Color)(ref val2))..ctor(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle()); float num5 = binaryReader.ReadSingle(); float num6 = binaryReader.ReadSingle(); Shader val3 = Shader.Find("Standard"); Material val4 = (Object.op_Implicit((Object)(object)val3) ? new Material(val3) : new Material(fallback)); ((Object)val4).name = name; val4.SetColor("_Color", val2); if (num4 >= 0) { val4.SetTexture("_MainTex", (Texture)(object)textures[num4]); } val4.SetFloat("_Metallic", num5); val4.SetFloat("_Glossiness", 1f - num6); materials.Add(val4); } num = binaryReader.ReadInt32(); for (int k = 0; k < num; k++) { string name2 = Text(binaryReader); slots.Add(binaryReader.ReadInt32()); int num7 = binaryReader.ReadInt32(); Vector3[] array2 = (Vector3[])(object)new Vector3[num7]; Vector3[] array3 = (Vector3[])(object)new Vector3[num7]; Vector2[] array4 = (Vector2[])(object)new Vector2[num7]; for (int l = 0; l < num7; l++) { array2[l] = V(binaryReader); array3[l] = V(binaryReader); array4[l] = new Vector2(binaryReader.ReadSingle(), binaryReader.ReadSingle()); } int num8 = binaryReader.ReadInt32(); int[] array5 = new int[num8]; for (int m = 0; m < num8; m++) { array5[m] = binaryReader.ReadInt32(); } Mesh val5 = new Mesh { name = name2 }; val5.vertices = array2; val5.normals = array3; val5.uv = array4; val5.triangles = array5; val5.RecalculateTangents(); val5.RecalculateBounds(); meshes.Add(val5); } } internal static Transform Create(Transform parent) { //IL_0022: 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_005f: 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) Renderer componentInChildren = ((Component)parent).GetComponentInChildren<Renderer>(); Load(Object.op_Implicit((Object)(object)componentInChildren) ? componentInChildren.sharedMaterial : null); Transform transform = new GameObject("OctoPackQuiver").transform; transform.SetParent(parent, false); for (int i = 0; i < meshes.Count; i++) { GameObject val = new GameObject(((Object)meshes[i]).name) { layer = ((Component)parent).gameObject.layer }; val.transform.SetParent(transform, false); val.AddComponent<MeshFilter>().sharedMesh = meshes[i]; ((Renderer)val.AddComponent<MeshRenderer>()).sharedMaterial = materials[slots[i]]; } return transform; } internal static void Dispose() { foreach (Mesh mesh in meshes) { Object.Destroy((Object)(object)mesh); } foreach (Material material in materials) { Object.Destroy((Object)(object)material); } foreach (Texture2D texture in textures) { Object.Destroy((Object)(object)texture); } meshes.Clear(); materials.Clear(); textures.Clear(); slots.Clear(); if (Object.op_Implicit((Object)(object)icon)) { Object.Destroy((Object)(object)icon); } if (Object.op_Implicit((Object)(object)iconTexture)) { Object.Destroy((Object)(object)iconTexture); } icon = null; iconTexture = null; } } [DefaultExecutionOrder(3200)] internal sealed class QuiverRig : MonoBehaviour { private Player owner; private Transform root; private Transform model; private StoredArrowVisuals arrows; private float next; private Matrix4x4 bodyToMount; private ZNetView view; private readonly string[] remoteNames = new string[3]; private readonly int[] remoteCounts = new int[3] { -1, -1, -1 }; private ObjectDB remoteDB; internal static void Reconcile() { foreach (Player allPlayer in Player.GetAllPlayers()) { Transform packRoot = BackpackBridge.GetPackRoot(allPlayer); if (Object.op_Implicit((Object)(object)packRoot) && !Object.op_Implicit((Object)(object)((Component)packRoot).GetComponent<QuiverRig>())) { QuiverRig quiverRig = ((Component)packRoot).gameObject.AddComponent<QuiverRig>(); quiverRig.owner = allPlayer; quiverRig.root = packRoot; quiverRig.view = ((Component)allPlayer).GetComponent<ZNetView>(); } } } private void LateUpdate() { //IL_015c: Unknown result type (might be due to invalid IL or missing references) //IL_0161: Unknown result type (might be due to invalid IL or missing references) //IL_0172: Unknown result type (might be due to invalid IL or missing references) //IL_0177: Unknown result type (might be due to invalid IL or missing references) //IL_0187: Unknown result type (might be due to invalid IL or missing references) //IL_0192: Unknown result type (might be due to invalid IL or missing references) //IL_00df: 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_00ef: Unknown result type (might be due to invalid IL or missing references) //IL_00f4: Unknown result type (might be due to invalid IL or missing references) if (!Object.op_Implicit((Object)(object)owner) || !Object.op_Implicit((Object)(object)Plugin.Instance)) { return; } if (!Object.op_Implicit((Object)(object)view)) { view = ((Component)owner).GetComponent<ZNetView>(); } ZDO val = (Object.op_Implicit((Object)(object)view) ? view.GetZDO() : null); bool num; if (!((Object)(object)owner == (Object)(object)Player.m_localPlayer)) { if (val == null) { goto IL_0084; } num = val.GetBool("OctoPack.Quiver.Visible.v1", false); } else { num = Items.Active != null; } if (num) { if (!Object.op_Implicit((Object)(object)model)) { Transform val2 = Find(root, "BackpackSpring") ?? root; bodyToMount = val2.worldToLocalMatrix * root.localToWorldMatrix; model = Model.Create(val2); arrows = ((Component)model).gameObject.AddComponent<StoredArrowVisuals>(); } if (!((Component)model).gameObject.activeSelf) { ((Component)model).gameObject.SetActive(true); } Plugin instance = Plugin.Instance; ApprovedFit.Pose pose = ApprovedFit.For("Quiver"); model.localPosition = ((Matrix4x4)(ref bodyToMount)).MultiplyPoint3x4(pose.Position); model.localRotation = Quaternion.Euler(pose.Rotation); model.localScale = Vector3.one * pose.Scale; arrows.MotionEnabled = instance.Sway.Value; if ((Object)(object)owner == (Object)(object)Player.m_localPlayer) { arrows.BindInventory(Items.Active.Inventory); } else { if (val == null || !(Time.unscaledTime >= next)) { return; } next = Time.unscaledTime + 0.2f; if (remoteDB != ObjectDB.instance) { for (int i = 0; i < 3; i++) { remoteNames[i] = null; remoteCounts[i] = -1; } remoteDB = ObjectDB.instance; } for (int j = 0; j < 3; j++) { string text = val.GetString(Items.NetSlots[j], ""); int num2 = Mathf.Clamp(val.GetInt(Items.NetCounts[j], 0), 0, 3); ObjectDB instance2 = ObjectDB.instance; if (remoteDB != instance2 || !(remoteNames[j] == text) || remoteCounts[j] != num2) { GameObject val3 = (Object.op_Implicit((Object)(object)instance2) ? instance2.GetItemPrefab(text) : null); object obj; if (!Object.op_Implicit((Object)(object)val3)) { obj = null; } else { ItemDrop component = val3.GetComponent<ItemDrop>(); obj = ((component != null) ? component.m_itemData.Clone() : null); } ItemData val4 = (ItemData)obj; if (val4 != null) { val4.m_stack = num2; } arrows.SetSlot(j, val4); if (string.IsNullOrEmpty(text) || val4 != null) { remoteNames[j] = text; remoteCounts[j] = num2; } } } } return; } goto IL_0084; IL_0084: if (Object.op_Implicit((Object)(object)model) && ((Component)model).gameObject.activeSelf) { ((Component)model).gameObject.SetActive(false); } } private static Transform Find(Transform root, string name) { Transform[] componentsInChildren = ((Component)root).GetComponentsInChildren<Transform>(); foreach (Transform val in componentsInChildren) { if (((Object)val).name == name) { return val; } } return null; } private void OnDestroy() { if (Object.op_Implicit((Object)(object)model)) { ((Component)model).gameObject.SetActive(false); Object.Destroy((Object)(object)((Component)model).gameObject); } } internal static void DisposeAll() { QuiverRig[] array = Object.FindObjectsByType<QuiverRig>((FindObjectsInactive)1, (FindObjectsSortMode)0); foreach (QuiverRig quiverRig in array) { if (Object.op_Implicit((Object)(object)quiverRig.model)) { ((Component)quiverRig.model).gameObject.SetActive(false); } Object.Destroy((Object)(object)quiverRig); } } } internal static class Panel { private static RectTransform panel; private static InventoryGrid grid; private static InventoryGui owner; private static readonly Vector3[] corners = (Vector3[])(object)new Vector3[4]; internal static Vector2? PreviewOffset; private static readonly TMP_Text[] labels = (TMP_Text[])(object)new TMP_Text[3]; private static readonly MethodInfo Selected = AccessTools.Method(typeof(InventoryGui), "OnSelectedItem", (Type[])null, (Type[])null); private static readonly MethodInfo Released = AccessTools.Method(typeof(InventoryGui), "OnReleasedItem", (Type[])null, (Type[])null); private static readonly MethodInfo GuiUpdate = AccessTools.Method(typeof(InventoryGrid), "UpdateGui", (Type[])null, (Type[])null); private static readonly FieldInfo InventoryField = AccessTools.Field(typeof(InventoryGrid), "m_inventory"); private static readonly FieldInfo DragField = AccessTools.Field(typeof(InventoryGui), "m_dragItem"); private static readonly Action<InventoryGrid, Player, ItemData> UpdateGrid = (Action<InventoryGrid, Player, ItemData>)GuiUpdate.CreateDelegate(typeof(Action<InventoryGrid, Player, ItemData>)); private static readonly List<InventoryElement> elements = new List<InventoryElement>(3); private static readonly List<GameObject> bindings = new List<GameObject>(3); private static Inventory boundInventory; private static int gridChildren = -1; private static bool labelsDirty = true; private static ConfigEntry<KeyboardShortcut>[] subscribedKeys; private static void ShortcutChanged(object sender, EventArgs e) { labelsDirty = true; } internal static void Tick() { //IL_020e: Unknown result type (might be due to invalid IL or missing references) //IL_0213: Unknown result type (might be due to invalid IL or missing references) InventoryGui instance = InventoryGui.instance; Player localPlayer = Player.m_localPlayer; if (!Object.op_Implicit((Object)(object)instance) || !Object.op_Implicit((Object)(object)localPlayer) || !InventoryGui.IsVisible() || Items.Active == null) { if (Object.op_Implicit((Object)(object)panel)) { ((Component)panel).gameObject.SetActive(false); } return; } if ((Object)(object)owner != (Object)(object)instance || !Object.op_Implicit((Object)(object)panel)) { Dispose(); Create(instance); } ((Component)panel).gameObject.SetActive(true); Position(); if (boundInventory != Items.Active.Inventory) { boundInventory = Items.Active.Inventory; InventoryField.SetValue(grid, boundInventory); } object? value = DragField.GetValue(instance); ItemData arg = (ItemData)((value is ItemData) ? value : null); UpdateGrid(grid, localPlayer, arg); if (gridChildren != ((Component)grid).transform.childCount || bindings.Count == 0 || !Object.op_Implicit((Object)(object)bindings[0])) { gridChildren = ((Component)grid).transform.childCount; elements.Clear(); bindings.Clear(); ((Component)grid).GetComponentsInChildren<InventoryElement>(true, elements); foreach (InventoryElement element in elements) { Transform val = ((Component)element).transform.Find("binding"); if (Object.op_Implicit((Object)(object)val)) { bindings.Add(((Component)val).gameObject); } } } foreach (GameObject binding in bindings) { if (Object.op_Implicit((Object)(object)binding) && binding.activeSelf) { binding.SetActive(false); } } if (labelsDirty) { for (int i = 0; i < 3; i++) { labels[i].text = ((object)Plugin.Instance.Keys[i].Value/*cast due to .constrained prefix*/).ToString().Replace("LeftAlt", "Alt").Replace("Alpha", ""); } labelsDirty = false; } } private static void Position() { //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Expected O, but got Unknown //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_0068: 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_0091: 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_0096: 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_00a8: 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_00b5: Unknown result type (might be due to invalid IL or missing references) //IL_00c1: Unknown result type (might be due to invalid IL or missing references) RectTransform val = (RectTransform)((Transform)panel).parent; Transform obj = ((Transform)val).Find("OctoPackPanel"); RectTransform val2 = (RectTransform)(object)((obj is RectTransform) ? obj : null); if (!Object.op_Implicit((Object)(object)val2) || !((Component)val2).gameObject.activeInHierarchy) { Transform obj2 = ((Transform)val).Find("Bkg"); val2 = (RectTransform)(object)((obj2 is RectTransform) ? obj2 : null); } if (!Object.op_Implicit((Object)(object)val2)) { val2 = val; } val2.GetWorldCorners(corners); Vector3 val3 = ((Transform)val).InverseTransformPoint(corners[2]); Vector2 val4 = (Vector2)(((??)PreviewOffset) ?? Plugin.Instance.PanelPosition.Value); ((Transform)panel).localPosition = new Vector3(val3.x + 12f + val4.x, val3.y + val4.y, 0f); } private static RectTransform Rect(string name, Transform parent) { //IL_0014: 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_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Expected O, but got Unknown RectTransform val = (RectTransform)new GameObject(name, new Type[1] { typeof(RectTransform) }) { layer = ((Component)parent).gameObject.layer }.transform; ((Transform)val).SetParent(parent, false); return val; } private static void Create(InventoryGui gui) { //IL_0074: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Expected O, but got Unknown //IL_0094: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Expected O, but got Unknown //IL_00ca: Unknown result type (might be due to invalid IL or missing references) //IL_00d1: Unknown result type (might be due to invalid IL or missing references) //IL_00e7: Unknown result type (might be due to invalid IL or missing references) //IL_014c: Unknown result type (might be due to invalid IL or missing references) //IL_0158: Unknown result type (might be due to invalid IL or missing references) //IL_01c1: Unknown result type (might be due to invalid IL or missing references) //IL_01ee: Unknown result type (might be due to invalid IL or missing references) //IL_01f5: Unknown result type (might be due to invalid IL or missing references) //IL_01f7: Unknown result type (might be due to invalid IL or missing references) //IL_01f8: Unknown result type (might be due to invalid IL or missing references) //IL_01ff: Unknown result type (might be due to invalid IL or missing references) //IL_020c: Unknown result type (might be due to invalid IL or missing references) //IL_021b: Unknown result type (might be due to invalid IL or missing references) //IL_0231: Unknown result type (might be due to invalid IL or missing references) //IL_0274: Unknown result type (might be due to invalid IL or missing references) //IL_027b: Unknown result type (might be due to invalid IL or missing references) //IL_027d: Unknown result type (might be due to invalid IL or missing references) //IL_027e: Unknown result type (might be due to invalid IL or missing references) //IL_0285: Unknown result type (might be due to invalid IL or missing references) //IL_0298: Unknown result type (might be due to invalid IL or missing references) //IL_02ae: Unknown result type (might be due to invalid IL or missing references) //IL_049b: Unknown result type (might be due to invalid IL or missing references) //IL_04a2: Unknown result type (might be due to invalid IL or missing references) //IL_04a4: Unknown result type (might be due to invalid IL or missing references) //IL_04a5: Unknown result type (might be due to invalid IL or missing references) //IL_04ac: Unknown result type (might be due to invalid IL or missing references) //IL_04c5: Unknown result type (might be due to invalid IL or missing references) //IL_04d7: Unknown result type (might be due to invalid IL or missing references) //IL_050d: Unknown result type (might be due to invalid IL or missing references) owner = gui; labelsDirty = true; subscribedKeys = Plugin.Instance.Keys; ConfigEntry<KeyboardShortcut>[] array = subscribedKeys; for (int i = 0; i < array.Length; i++) { array[i].SettingChanged += ShortcutChanged; } InventoryGrid obj = (InventoryGrid)AccessTools.Field(typeof(InventoryGui), "m_playerGrid").GetValue(gui); Component val = (Component)AccessTools.Field(typeof(InventoryGui), "m_player").GetValue(gui); panel = Rect("OctoPackQuiverPanel", val.transform); RectTransform obj2 = panel; RectTransform obj3 = panel; Vector2 val2 = default(Vector2); ((Vector2)(ref val2))..ctor(0.5f, 0.5f); obj3.anchorMax = val2; obj2.anchorMin = val2; panel.pivot = new Vector2(0f, 1f); Image val3 = ((Component)panel).gameObject.AddComponent<Image>(); Transform obj4 = val.transform.Find("Bkg"); Image val4 = ((obj4 != null) ? ((Component)obj4).GetComponent<Image>() : null); if (Object.op_Implicit((Object)(object)val4)) { val3.sprite = val4.sprite; val3.overrideSprite = val4.overrideSprite; ((Graphic)val3).material = ((Graphic)val4).material; ((Graphic)val3).color = ((Graphic)val4).color; val3.type = val4.type; val3.pixelsPerUnitMultiplier = val4.pixelsPerUnitMultiplier; } ((Graphic)val3).raycastTarget = false; float num = (float)AccessTools.Field(typeof(InventoryGrid), "m_elementSpace").GetValue(obj); if (num < 10f) { num = 70f; } panel.sizeDelta = new Vector2(num * 3f + 20f, num + 44f); RectTransform obj5 = Rect("MoveQuiverPanel", (Transform)(object)panel); Vector2 val5 = default(Vector2); ((Vector2)(ref val5))..ctor(0f, 1f); obj5.pivot = val5; val2 = (obj5.anchorMin = (obj5.anchorMax = val5)); obj5.sizeDelta = new Vector2(panel.sizeDelta.x, 28f); Image obj6 = ((Component)obj5).gameObject.AddComponent<Image>(); ((Graphic)obj6).color = Color.clear; ((Graphic)obj6).raycastTarget = true; ((Component)obj5).gameObject.AddComponent<QuiverPanelDrag>(); RectTransform val8 = Rect("QuiverArrowSlots", (Transform)(object)panel); ((Vector2)(ref val5))..ctor(0f, 1f); val8.pivot = val5; val2 = (val8.anchorMin = (val8.anchorMax = val5)); val8.anchoredPosition = new Vector2(10f, -30f); val8.sizeDelta = new Vector2(num * 3f, num); grid = ((Component)val8).gameObject.AddComponent<InventoryGrid>(); string[] array2 = new string[7] { "m_elementPrefab", "m_elementSpace", "m_uiGroup", "m_tooltipAnchor", "m_foodEitrColor", "m_foodHealthColor", "m_foodStaminaColor" }; foreach (string text in array2) { AccessTools.Field(typeof(InventoryGrid), text).SetValue(grid, AccessTools.Field(typeof(InventoryGrid), text).GetValue(obj)); } AccessTools.Field(typeof(InventoryGrid), "m_gridRoot").SetValue(grid, val8); grid.m_onSelected = OnSelected; grid.m_onRightClick = delegate(InventoryGrid g, ItemData item, Vector2i pos) { //IL_0003: Unknown result type (might be due to invalid IL or missing references) if (item != null) { Items.Select(pos.x); } }; grid.m_onReleased = delegate(InventoryGrid g, ItemData item, Vector2i pos) { //IL_001a: 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) if (!Object.op_Implicit((Object)(object)g)) { Released.Invoke(owner, new object[3] { null, null, pos }); } else if (DragField.GetValue(owner) != null) { OnSelected(g, item, pos, (Modifier)0); } }; grid.CanDropDragOntoItem = (ItemData item) => true; TMP_FontAsset val11 = null; TMP_Text[] componentsInChildren = ((Component)gui).GetComponentsInChildren<TMP_Text>(true); foreach (TMP_Text val12 in componentsInChildren) { if (Object.op_Implicit((Object)(object)val12.font)) { val11 = val12.font; break; } } if (!Object.op_Implicit((Object)(object)val11)) { val11 = TMP_Settings.defaultFontAsset; } for (int num2 = 0; num2 < 3; num2++) { RectTransform obj7 = Rect("Shortcut" + num2, (Transform)(object)panel); ((Vector2)(ref val5))..ctor(0f, 1f); obj7.pivot = val5; val2 = (obj7.anchorMin = (obj7.anchorMax = val5)); obj7.anchoredPosition = new Vector2(10f + (float)num2 * num, -4f); obj7.sizeDelta = new Vector2(num, 24f); TextMeshProUGUI val15 = ((Component)obj7).gameObject.AddComponent<TextMeshProUGUI>(); if (Object.op_Implicit((Object)(object)val11)) { ((TMP_Text)val15).font = val11; } ((TMP_Text)val15).fontSize = 15f; ((Graphic)val15).color = Color.white; ((TMP_Text)val15).alignment = (TextAlignmentOptions)514; ((Graphic)val15).raycastTarget = false; labels[num2] = (TMP_Text)(object)val15; } } private static void OnSelected(InventoryGrid selected, ItemData item, Vector2i pos, Modifier modifier) { //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Invalid comparison between Unknown and I4 //IL_0068: 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) if (Items.Active != null) { object? value = DragField.GetValue(owner); ItemData val = (ItemData)((value is ItemData) ? value : null); if (val == null && (int)modifier == 2 && item != null) { ((Humanoid)Player.m_localPlayer).GetInventory().MoveItemToThis(Items.Active.Inventory, item); } else if (val == null || Items.Arrow(val)) { Selected.Invoke(owner, new object[4] { selected, item, pos, modifier }); } } } internal static bool Drop(InventoryGrid __instance, Inventory __0, ItemData __1, int __2, Vector2i __3, ref bool __result) { //IL_0043: 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_0017: 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_002a: Unknown result type (might be due to invalid IL or missing references) Inventory inventory = __instance.GetInventory(); if (Items.Owned(inventory) && (!Items.Arrow(__1) || __3.y != 0 || __3.x < 0 || __3.x > 2)) { __result = false; return false; } if (Items.Owned(__0)) { ItemData itemAt = inventory.GetItemAt(__3.x, __3.y); if (itemAt != null && !Items.Arrow(itemAt)) { __result = false; return false; } } return true; } internal static void Dispose() { if (subscribedKeys != null) { ConfigEntry<KeyboardShortcut>[] array = subscribedKeys; for (int i = 0; i < array.Length; i++) { array[i].SettingChanged -= ShortcutChanged; } } subscribedKeys = null; if (Object.op_Implicit((Object)(object)panel)) { Object.Destroy((Object)(object)((Component)panel).gameObject); } panel = null; grid = null; owner = null; PreviewOffset = null; boundInventory = null; gridChildren = -1; bindings.Clear(); elements.Clear(); labelsDirty = true; } } internal sealed class QuiverPanelDrag : MonoBehaviour, IBeginDragHandler, IEventSystemHandler, IDragHandler, IEndDragHandler { private Vector2 start; private Vector2 offset; public void OnBeginDrag(PointerEventData e) { //IL_0010: 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_002c: Expected O, but got Unknown //IL_0038: 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) RectTransformUtility.ScreenPointToLocalPointInRectangle((RectTransform)((Component)this).transform.parent.parent, e.position, e.pressEventCamera, ref start); offset = Plugin.Instance.PanelPosition.Value; } public void OnDrag(PointerEventData e) { //IL_0010: 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_0028: Expected O, but got Unknown //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0031: 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) Vector2 val = default(Vector2); if (RectTransformUtility.ScreenPointToLocalPointInRectangle((RectTransform)((Component)this).transform.parent.parent, e.position, e.pressEventCamera, ref val)) { Panel.PreviewOffset = offset + val - start; } } public void OnEndDrag(PointerEventData e) { //IL_0027: Unknown result type (might be due to invalid IL or missing references) if (Object.op_Implicit((Object)(object)Plugin.Instance) && Panel.PreviewOffset.HasValue) { Plugin.Instance.PanelPosition.Value = Panel.PreviewOffset.Value; } Panel.PreviewOffset = null; } } internal sealed class Plugin : MonoBehaviour { private ConfigFile Config; private ManualLogSource Logger; internal static Plugin Instance; internal ConfigEntry<Vector2> PanelPosition; internal ConfigEntry<bool> Sway; internal ConfigEntry<int> Scraps; internal ConfigEntry<int> Hide; internal ConfigEntry<int> Wood; internal ConfigEntry<int> StationLevel; internal readonly ConfigEntry<KeyboardShortcut>[] Keys = new ConfigEntry<KeyboardShortcut>[3]; private Harmony harmony; private float next; private float nextInventory; internal void Initialize(ConfigFile config, ManualLogSource logger) { //IL_002f: 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_00de: Unknown result type (might be due to invalid IL or missing references) //IL_00e8: Expected O, but got Unknown //IL_0111: Unknown result type (might be due to invalid IL or missing references) //IL_011b: Expected O, but got Unknown //IL_0144: Unknown result type (might be due to invalid IL or missing references) //IL_014e: Expected O, but got Unknown //IL_0176: Unknown result type (might be due to invalid IL or missing references) //IL_0180: Expected O, but got Unknown //IL_0193: Unknown result type (might be due to invalid IL or missing references) //IL_019d: Expected O, but got Unknown Config = config; Logger = logger; Instance = this; PanelPosition = Config.Bind<Vector2>("Quiver.Interface", "BackpackPanelOffset", new Vector2(48f, -108.75f), "Offset from the backpack panel's top-right edge. Drag the shortcut heading to reposition; position is saved."); Sway = Config.Bind<bool>("Quiver.Motion", "ArrowSway", true, "Independent constrained arrow movement."); for (int i = 0; i < 3; i++) { Keys[i] = Config.Bind<KeyboardShortcut>("Quiver.Shortcuts", "Slot" + (i + 1), new KeyboardShortcut((KeyCode)(49 + i), (KeyCode[])(object)new KeyCode[1] { (KeyCode)308 }), "Equip arrows in this fixed quiver slot."); } Scraps = Config.Bind<int>("Quiver.Recipe", "LeatherScraps", 10, new ConfigDescription("Crafting cost.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 100), Array.Empty<object>())); Hide = Config.Bind<int>("Quiver.Recipe", "DeerHide", 5, new ConfigDescription("Crafting cost.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 100), Array.Empty<object>())); Wood = Config.Bind<int>("Quiver.Recipe", "FineWood", 5, new ConfigDescription("Crafting cost.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 100), Array.Empty<object>())); StationLevel = Config.Bind<int>("Quiver.Recipe", "WorkbenchLevel", 2, new ConfigDescription("Required workbench level.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 5), Array.Empty<object>())); if (Application.isBatchMode) { return; } harmony = new Harmony("Octodad.OctoArsenal.Quiver"); try { Hooks.Patch(harmony); Logger.LogInfo((object)"Quiver 0.1.0 loaded; craft at workbench, place in backpack, then right-click to equip."); } catch (Exception ex) { harmony.UnpatchSelf(); Logger.LogError((object)("Quiver hooks failed: " + ex)); ((Behaviour)this).enabled = false; } } private void Update() { //IL_00b7: Unknown result type (might be due to invalid IL or missing references) //IL_00bc: Unknown result type (might be due to invalid IL or missing references) if (Application.isBatchMode) { return; } try { if (Time.unscaledTime >= nextInventory) { nextInventory = Time.unscaledTime + 0.1f; Items.Tick(); } if (Time.unscaledTime >= next) { next = Time.unscaledTime + 1f; Items.EnsureRecipe(); QuiverRig.Reconcile(); } Player localPlayer = Player.m_localPlayer; if (Object.op_Implicit((Object)(object)localPlayer) && !((Character)localPlayer).IsDead() && !((Character)localPlayer).IsTeleporting() && !InventoryGui.IsVisible() && (!Object.op_Implicit((Object)(object)Chat.instance) || !Chat.instance.HasFocus()) && (!Object.op_Implicit((Object)(object)Console.instance) || !Console.IsVisible()) && !TextInput.IsVisible()) { for (int i = 0; i < 3; i++) { KeyboardShortcut value = Keys[i].Value; if (((KeyboardShortcut)(ref value)).IsDown()) { Items.Select(i); } } } Panel.Tick(); } catch (Exception ex) { Logger.LogError((object)ex); ((Behaviour)this).enabled = false; } } internal void Warn(string message) { Logger.LogWarning((object)message); } private void OnDestroy() { Items.Flush(); Panel.Dispose(); QuiverRig.DisposeAll(); Harmony obj = harmony; if (obj != null) { obj.UnpatchSelf(); } Items.Dispose(); Model.Dispose(); ArrowTailGeometry.Dispose(); Instance = null; } } internal static class Hooks { internal static void Patch(Harmony h) { //IL_014e: Unknown result type (might be due to invalid IL or missing references) //IL_015c: Expected O, but got Unknown //IL_02b1: Unknown result type (might be due to invalid IL or missing references) //IL_02be: Expected O, but got Unknown //IL_0250: Unknown result type (might be due to invalid IL or missing references) //IL_025d: Expected O, but got Unknown Hook(h, typeof(Humanoid), "UseItem", typeof(Items), "Use"); Hook(h, typeof(Humanoid), "EquipItem", typeof(Items), "Equip"); Hook(h, typeof(Humanoid), "UnequipItem", typeof(Items), "Unequip"); Hook(h, typeof(Humanoid), "IsItemEquiped", typeof(Items), null, "IsEquipped"); Hook(h, typeof(InventoryGui), "DoCrafting", typeof(Items), "BeforeCraft", "AfterCraft"); Hook(h, typeof(InventoryGrid), "DropItem", typeof(Panel), "Drop"); foreach (MethodInfo declaredMethod in AccessTools.GetDeclaredMethods(typeof(Inventory))) { if ((declaredMethod.Name == "AddItem" || declaredMethod.Name == "CanAddItem") && declaredMethod.ReturnType == typeof(bool)) { h.Patch((MethodBase)declaredMethod, new HarmonyMethod(typeof(Items), "AllowAdd", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } } Hook(h, typeof(Player), "Save", typeof(Items), "Flush"); Hook(h, typeof(Player), "CreateTombStone", typeof(Items), "Death"); Hook(h, typeof(Player), "UseHotbarItem", typeof(Items), "Hotbar"); foreach (MethodInfo declaredMethod2 in AccessTools.GetDeclaredMethods(typeof(Inventory))) { if (declaredMethod2.Name == "Load" && declaredMethod2.GetParameters().Length != 0 && declaredMethod2.GetParameters()[0].ParameterType == typeof(ZPackage)) { h.Patch((MethodBase)declaredMethod2, (HarmonyMethod)null, new HarmonyMethod(typeof(Items), "Loaded", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } } h.Patch((MethodBase)AccessTools.Method(typeof(ItemData), "GetWeight", new Type[1] { typeof(int) }, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(Items), "Weight", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); Ammo.Patch(h); } private static void Hook(Harmony h, Type type, string method, Type patch, string prefix = null, string postfix = null) { //IL_0025: 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_0040: Unknown result type (might be due to invalid IL or missing references) MethodInfo methodInfo = AccessTools.Method(type, method, (Type[])null, (Type[])null) ?? throw new MissingMethodException(type.Name, method); h.Patch((MethodBase)methodInfo, (prefix == null) ? ((HarmonyMethod)null) : new HarmonyMethod(patch, prefix, (Type[])null) { priority = 800 }, (postfix == null) ? ((HarmonyMethod)null) : new HarmonyMethod(patch, postfix, (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } } [DefaultExecutionOrder(3300)] public sealed class StoredArrowVisuals : MonoBehaviour { private sealed class Arrow { internal int Slot; internal int Index; internal Transform Pivot; internal Vector3 Rest; internal Vector2 Offset; internal Vector2 Velocity; internal Vector2 Drive; internal Vector3 RestAngles; internal float Lift; internal float LiftVelocity; } private const int Slots = 3; private const int PerSlot = 2; private static readonly Vector3[] rests = (Vector3[])(object)new Vector3[6] { new Vector3(-0.038f, 0.1f, -0.018f), new Vector3(0.026f, 0.135f, 0.023f), new Vector3(-0.006f, 0.17f, 0.035f), new Vector3(0.042f, 0.115f, -0.013f), new Vector3(-0.027f, 0.15f, 0.023f), new Vector3(0.008f, 0.18f, -0.032f) }; private readonly List<Arrow> arrows = new List<Arrow>(); private readonly GameObject[] prefabs = (GameObject[])(object)new GameObject[3]; private readonly int[] counts = new int[3]; private readonly HashSet<string> warned = new HashSet<string>(); private Inventory inventory; private float nextRefresh; private Vector3 previousPosition; private Vector3 previousVelocity; private Quaternion previousRotation; private bool sampled; public bool MotionEnabled = true; public bool ProjectileTipFacesForward = true; public void BindInventory(Inventory threeSlotInventory) { if (inventory != threeSlotInventory) { inventory = threeSlotInventory; nextRefresh = 0f; } } public void SetSlot(int slot, ItemData item) { //IL_00c2: 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_0160: Unknown result type (might be due to invalid IL or missing references) //IL_0165: Unknown result type (might be due to invalid IL or missing references) //IL_0192: Unknown result type (might be due to invalid IL or missing references) //IL_0197: Unknown result type (might be due to invalid IL or missing references) if (slot < 0 || slot >= 3) { throw new ArgumentOutOfRangeException("slot"); } GameObject val = ((Items.Arrow(item) && item.m_shared.m_attack != null) ? item.m_shared.m_attack.m_attackProjectile : null); int num = ((Object.op_Implicit((Object)(object)val) && item.m_stack > 0) ? Mathf.Min(2, item.m_stack) : 0); if ((Object)(object)prefabs[slot] == (Object)(object)val && counts[slot] == num) { return; } ClearSlot(slot); prefabs[slot] = val; counts[slot] = num; if (!Object.op_Implicit((Object)(object)val) || num == 0) { return; } for (int i = 0; i < num; i++) { Transform transform = new GameObject("QuiverSlot" + slot + "Arrow" + i).transform; transform.SetParent(((Component)this).transform, false); int num2 = slot * 2 + i; transform.localPosition = rests[num2]; bool projectileTipFacesForward = ProjectileTipFacesForward; if (!BuildMeshOnly(val, transform, projectileTipFacesForward)) { Object.Destroy((Object)(object)((Component)transform).gameObject); if (warned.Add(((Object)val).name)) { Debug.LogWarning((object)("OctoPack quiver: no supported static arrow mesh in " + ((Object)val).name)); } break; } arrows.Add(new Arrow { Slot = slot, Index = i, Pivot = transform, Rest = transform.localPosition, RestAngles = new Vector3((float)(num2 % 3 - 1) * 1.5f, (float)num2 * 137.5f, (float)((num2 % 2 != 0) ? 1 : (-1)) * 1.8f) }); } } private bool BuildMeshOnly(GameObject prefab, Transform pivot, bool tipForward) { //IL_001c: 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_0058: 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_0076: Unknown result type (might be due to invalid IL or missing references) //IL_00b3: Unknown result type (might be due to invalid IL or missing references) //IL_00b8: 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_00ec: Unknown result type (might be due to invalid IL or missing references) //IL_00e5: Unknown result type (might be due to invalid IL or missing references) //IL_00f1: Unknown result type (might be due to invalid IL or missing references) //IL_00f6: Unknown result type (might be due to invalid IL or missing references) //IL_00fb: Unknown result type (might be due to invalid IL or missing references) //IL_0101: Unknown result type (might be due to invalid IL or missing references) //IL_010d: Unknown result type (might be due to invalid IL or missing references) //IL_012a: Unknown result type (might be due to invalid IL or missing references) //IL_011c: Unknown result type (might be due to invalid IL or missing references) //IL_013a: Unknown result type (might be due to invalid IL or missing references) //IL_0142: Unknown result type (might be due to invalid IL or missing references) //IL_014a: Unknown result type (might be due to invalid IL or missing references) //IL_014c: Unknown result type (might be due to invalid IL or missing references) //IL_014e: Unknown result type (might be due to invalid IL or missing references) //IL_0150: Unknown result type (might be due to invalid IL or missing references) //IL_0155: 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) ArrowTailGeometry.Shape shape = ArrowTailGeometry.Get(prefab, tipForward); if (shape.Parts.Count == 0) { return false; } Transform transform = new GameObject("NativeArrowShaftAndFletching").transform; transform.SetParent(pivot, false); foreach (ArrowTailGeometry.Part part in shape.Parts) { GameObject val = new GameObject(((Object)part.Mesh).name) { layer = ((Component)this).gameObject.layer }; val.transform.SetParent(transform, false); val.AddComponent<MeshFilter>().sharedMesh = part.Mesh; ((Renderer)val.AddComponent<MeshRenderer>()).sharedMaterials = part.Materials; } Bounds bounds = shape.Bounds; float num = 0.68f / ((Bounds)(ref bounds)).size.z; Vector3 val2 = default(Vector3); ((Vector3)(ref val2))..ctor(num * 0.65f, num * 0.65f, num); Quaternion val3 = Quaternion.FromToRotation(tipForward ? Vector3.forward : Vector3.back, Vector3.down); Vector3 val4 = default(Vector3); ((Vector3)(ref val4))..ctor(((Bounds)(ref bounds)).center.x, ((Bounds)(ref bounds)).center.y, tipForward ? ((Bounds)(ref bounds)).max.z : ((Bounds)(ref bounds)).min.z); transform.localRotation = val3; transform.localScale = val2; transform.localPosition = -(val3 * Vector3.Scale(val4, val2)); return true; } private void LateUpdate() { //IL_00b3: Unknown result type (might be due to invalid IL or missing references) //IL_00b8: Unknown result type (might be due to invalid IL or missing references) //IL_00bf: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: Unknown result type (might be due to invalid IL or missing references) //IL_00fa: Unknown result type (might be due to invalid IL or missing references) //IL_00fb: 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_00df: Unknown result type (might be due to invalid IL or missing references) //IL_00e4: 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_0102: Unknown result type (might be due to invalid IL or missing references) //IL_0104: Unknown result type (might be due to invalid IL or missing references) //IL_0109: Unknown result type (might be due to invalid IL or missing references) //IL_010f: Unknown result type (might be due to invalid IL or missing references) //IL_0114: Unknown result type (might be due to invalid IL or missing references) //IL_011b: Unknown result type (might be due to invalid IL or missing references) //IL_011d: Unknown result type (might be due to invalid IL or missing references) //IL_0122: Unknown result type (might be due to invalid IL or missing references) //IL_0128: Unknown result type (might be due to invalid IL or missing references) //IL_012d: Unknown result type (might be due to invalid IL or missing references) //IL_0132: Unknown result type (might be due to invalid IL or missing references) //IL_0135: Unknown result type (might be due to invalid IL or missing references) //IL_013a: Unknown result type (might be due to invalid IL or missing references) //IL_013f: Unknown result type (might be due to invalid IL or missing references) //IL_0140: Unknown result type (might be due to invalid IL or missing references) //IL_0145: Unknown result type (might be due to invalid IL or missing references) //IL_0177: Unknown result type (might be due to invalid IL or missing references) //IL_0183: Unknown result type (might be due to invalid IL or missing references) //IL_018f: Unknown result type (might be due to invalid IL or missing references) //IL_0192: Unknown result type (might be due to invalid IL or missing references) //IL_0193: Unknown result type (might be due to invalid IL or missing references) //IL_0199: Unknown result type (might be due to invalid IL or missing references) //IL_019a: Unknown result type (might be due to invalid IL or missing references) //IL_01a0: Unknown result type (might be due to invalid IL or missing references) //IL_01a1: Unknown result type (might be due to invalid IL or missing references) //IL_01a6: Unknown result type (might be due to invalid IL or missing references) //IL_01ae: Unknown result type (might be due to invalid IL or missing references) //IL_01b6: Unknown result type (might be due to invalid IL or missing references) //IL_01c0: Unknown result type (might be due to invalid IL or missing references) //IL_01c5: Unknown result type (might be due to invalid IL or missing references) //IL_01cd: Unknown result type (might be due to invalid IL or missing references) //IL_01d4: Unknown result type (might be due to invalid IL or missing references) //IL_01de: Unknown result type (might be due to invalid IL or missing references) //IL_01e3: Unknown result type (might be due to invalid IL or missing references) //IL_01ed: Unknown result type (might be due to invalid IL or missing references) //IL_01f2: Unknown result type (might be due to invalid IL or missing references) //IL_018a: Unknown result type (might be due to invalid IL or missing references) //IL_02a1: Unknown result type (might be due to invalid IL or missing references) //IL_02a6: Unknown result type (might be due to invalid IL or missing references) //IL_02c5: Unknown result type (might be due to invalid IL or missing references) //IL_02ca: Unknown result type (might be due to invalid IL or missing references) //IL_0230: Unknown result type (might be due to invalid IL or missing references) //IL_0235: Unknown result type (might be due to invalid IL or missing references) //IL_0236: Unknown result type (might be due to invalid IL or missing references) //IL_0238: Unknown result t