using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Text; using BepInEx; using BepInEx.Logging; using HarmonyLib; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: AssemblyVersion("0.0.0.0")] namespace HowToFish.MoreKnives; internal sealed class KnifePart { public string Name; public Mesh Mesh; public Vector3 Position = Vector3.zero; public Quaternion Rotation = Quaternion.identity; public Vector3 Scale = Vector3.one; public PartMaterial Material; } internal sealed class KnifeAssetSet { public readonly List Parts = new List(); public Mesh InventoryMesh; public Material BladeMaterial; public Material GripMaterial; public Material AccentMaterial; } internal static class KnifeAssets { private static readonly Dictionary Cache = new Dictionary(); public static void WarmUp() { foreach (KnifeDefinition definition in KnifeCatalog.Definitions) { Get(definition); } } public static KnifeAssetSet Get(KnifeDefinition definition) { if (Cache.TryGetValue(definition.VariantCode, out var value)) { return value; } value = Build(definition); Cache.Add(definition.VariantCode, value); return value; } public static GameObject CreateWorldModel(KnifeDefinition definition, Transform parent, string suffix) { //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Expected O, but got Unknown //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Unknown result type (might be due to invalid IL or missing references) //IL_0093: Unknown result type (might be due to invalid IL or missing references) //IL_009b: Unknown result type (might be due to invalid IL or missing references) //IL_00a5: Unknown result type (might be due to invalid IL or missing references) //IL_00ad: Unknown result type (might be due to invalid IL or missing references) //IL_00b7: Unknown result type (might be due to invalid IL or missing references) KnifeAssetSet knifeAssetSet = Get(definition); GameObject val = new GameObject("MoreKnivesModel_" + definition.VariantCode + suffix); ((Object)val).hideFlags = (HideFlags)52; val.transform.SetParent(parent, false); foreach (KnifePart part in knifeAssetSet.Parts) { GameObject val2 = new GameObject(part.Name + suffix) { hideFlags = (HideFlags)52 }; val2.transform.SetParent(val.transform, false); val2.transform.localPosition = part.Position; val2.transform.localRotation = part.Rotation; val2.transform.localScale = part.Scale; val2.AddComponent().sharedMesh = part.Mesh; ((Renderer)val2.AddComponent()).sharedMaterial = GetMaterial(knifeAssetSet, part.Material); } SetLayerRecursively(val, ((Component)parent).gameObject.layer); return val; } public static Material GetBladeMaterial(KnifeDefinition definition) { return Get(definition).BladeMaterial; } private static KnifeAssetSet Build(KnifeDefinition definition) { //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_006e: Unknown result type (might be due to invalid IL or missing references) KnifeAssetSet knifeAssetSet = new KnifeAssetSet(); knifeAssetSet.BladeMaterial = CreateMaterial(definition.DisplayName + " Blade", definition.BladeColor, 0.88f, 0.76f); knifeAssetSet.GripMaterial = CreateMaterial(definition.DisplayName + " Grip", definition.GripColor, 0.08f, 0.28f); knifeAssetSet.AccentMaterial = CreateMaterial(definition.DisplayName + " Accent", definition.AccentColor, 0.68f, 0.58f); BuildParts(definition, knifeAssetSet.Parts); knifeAssetSet.InventoryMesh = CombineForInventory(definition, knifeAssetSet.Parts); return knifeAssetSet; } private static void BuildParts(KnifeDefinition definition, List parts) { //IL_0165: Unknown result type (might be due to invalid IL or missing references) //IL_016a: Unknown result type (might be due to invalid IL or missing references) //IL_017d: Unknown result type (might be due to invalid IL or missing references) //IL_0182: Unknown result type (might be due to invalid IL or missing references) //IL_0195: 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_01ad: Unknown result type (might be due to invalid IL or missing references) //IL_01b2: Unknown result type (might be due to invalid IL or missing references) //IL_01c6: Unknown result type (might be due to invalid IL or missing references) //IL_01cb: Unknown result type (might be due to invalid IL or missing references) //IL_01df: Unknown result type (might be due to invalid IL or missing references) //IL_01e4: Unknown result type (might be due to invalid IL or missing references) //IL_0296: Unknown result type (might be due to invalid IL or missing references) //IL_029b: 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_02b3: Unknown result type (might be due to invalid IL or missing references) //IL_02c6: Unknown result type (might be due to invalid IL or missing references) //IL_02cb: Unknown result type (might be due to invalid IL or missing references) //IL_0331: Unknown result type (might be due to invalid IL or missing references) //IL_0336: Unknown result type (might be due to invalid IL or missing references) //IL_034d: Unknown result type (might be due to invalid IL or missing references) //IL_0352: Unknown result type (might be due to invalid IL or missing references) //IL_0369: Unknown result type (might be due to invalid IL or missing references) //IL_036e: Unknown result type (might be due to invalid IL or missing references) if (definition.Shape == KnifeShape.Karambit || definition.Shape == KnifeShape.Talon) { BuildCurvedKnife(definition, parts); return; } if (definition.Shape == KnifeShape.DualDaggers) { BuildPushDagger(definition, parts); return; } if (definition.Shape == KnifeShape.Butterfly) { BuildButterfly(definition, parts); return; } if (definition.Shape == KnifeShape.Skeleton) { BuildSkeleton(definition, parts); return; } float bladeWidth = definition.BladeWidth; float lengthScale = definition.LengthScale; Vector2[] input = BladePolygon(definition.Shape, bladeWidth, lengthScale); Add(parts, "Blade", MeshBuilder.ExtrudePolygon(input, 0.035f, definition.DisplayName + " Blade"), PartMaterial.Blade); float num = Mathf.Clamp(bladeWidth * 0.78f, 0.105f, 0.17f); if (definition.Shape == KnifeShape.Paracord) { Add(parts, "ParacordCore", MeshBuilder.Box2D((0f - num) * 0.34f, 0f, num * 0.34f, 0.32f, 0.065f, "Paracord Core"), PartMaterial.Grip); for (int i = 0; i < 5; i++) { float num2 = 0.025f + (float)i * 0.058f; Add(parts, "ParacordWrap" + i, MeshBuilder.Box2D((0f - num) * 0.55f, num2, num * 0.55f, num2 + 0.035f, 0.082f, "Paracord Wrap"), PartMaterial.Accent); } } else { Vector2[] input2 = (Vector2[])(object)new Vector2[6] { new Vector2((0f - num) * 0.48f, 0f), new Vector2(num * 0.48f, 0f), new Vector2(num * 0.56f, 0.06f), new Vector2(num * 0.48f, 0.31f), new Vector2((0f - num) * 0.48f, 0.31f), new Vector2((0f - num) * 0.56f, 0.06f) }; Add(parts, "Grip", MeshBuilder.ExtrudePolygon(input2, 0.075f, definition.DisplayName + " Grip"), PartMaterial.Grip); } Add(parts, "Guard", MeshBuilder.Box2D((0f - bladeWidth) * 0.66f, 0.285f, bladeWidth * 0.66f, 0.335f, 0.075f, "Guard"), PartMaterial.Accent); Add(parts, "Pommel", MeshBuilder.Box2D((0f - num) * 0.58f, -0.018f, num * 0.58f, 0.035f, 0.08f, "Pommel"), PartMaterial.Accent); if (definition.Shape == KnifeShape.Gut) { Vector2[] input3 = (Vector2[])(object)new Vector2[3] { new Vector2(-0.02f, 0.61f), new Vector2(bladeWidth * 0.73f, 0.69f), new Vector2(bladeWidth * 0.54f, 0.79f) }; Add(parts, "GutHook", MeshBuilder.ExtrudePolygon(input3, 0.04f, "Gut Hook"), PartMaterial.Accent); } else if (definition.Shape == KnifeShape.M9Bayonet || definition.Shape == KnifeShape.Survival) { for (int j = 0; j < 5; j++) { float num3 = 0.47f + (float)j * 0.07f; Vector2[] input4 = (Vector2[])(object)new Vector2[3] { new Vector2((0f - bladeWidth) * 0.5f, num3), new Vector2((0f - bladeWidth) * 0.76f, num3 + 0.035f), new Vector2((0f - bladeWidth) * 0.48f, num3 + 0.065f) }; Add(parts, "Serration" + j, MeshBuilder.ExtrudePolygon(input4, 0.04f, "Serration"), PartMaterial.Accent); } } else if (definition.Shape == KnifeShape.Stiletto) { Add(parts, "CenterRidge", MeshBuilder.Box2D(-0.012f, 0.31f, 0.012f, lengthScale * 0.92f, 0.052f, "Stiletto Ridge"), PartMaterial.Accent); } else if (definition.Shape == KnifeShape.Nomad || definition.Shape == KnifeShape.Huntsman) { Add(parts, "Fuller", MeshBuilder.Box2D((0f - bladeWidth) * 0.18f, 0.42f, bladeWidth * 0.18f, lengthScale * 0.82f, 0.043f, "Blade Fuller"), PartMaterial.Accent); } } private static void BuildCurvedKnife(KnifeDefinition definition, List parts) { //IL_00ae: 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_00c4: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: Unknown result type (might be due to invalid IL or missing references) //IL_00da: 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_00f0: Unknown result type (might be due to invalid IL or missing references) //IL_00f5: Unknown result type (might be due to invalid IL or missing references) //IL_0106: Unknown result type (might be due to invalid IL or missing references) //IL_010b: Unknown result type (might be due to invalid IL or missing references) //IL_011c: Unknown result type (might be due to invalid IL or missing references) //IL_0121: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_008c: 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_01b6: Unknown result type (might be due to invalid IL or missing references) Vector2[] centerLine = (Vector2[])(object)((definition.Shape != KnifeShape.Karambit) ? new Vector2[6] { new Vector2(0f, 0.29f), new Vector2(0.15f, 0.45f), new Vector2(0.23f, 0.64f), new Vector2(0.19f, 0.83f), new Vector2(0.05f, 1f), new Vector2(-0.1f, 1.06f) } : new Vector2[6] { new Vector2(0f, 0.29f), new Vector2(0.12f, 0.43f), new Vector2(0.19f, 0.61f), new Vector2(0.16f, 0.78f), new Vector2(0.03f, 0.91f), new Vector2(-0.12f, 0.96f) }); Add(parts, "CurvedBlade", MeshBuilder.Ribbon(centerLine, definition.BladeWidth * 0.42f, 0.035f, definition.DisplayName + " Blade"), PartMaterial.Blade); Add(parts, "Grip", MeshBuilder.Box2D(-0.075f, 0.03f, 0.075f, 0.32f, 0.075f, "Curved Grip"), PartMaterial.Grip); Add(parts, "FingerRing", MeshBuilder.Torus(0.085f, 0.022f, 20, 7, "Finger Ring"), PartMaterial.Accent, new Vector3(0f, 0.02f, 0f)); Add(parts, "Guard", MeshBuilder.Box2D(-0.105f, 0.285f, 0.105f, 0.335f, 0.075f, "Curved Guard"), PartMaterial.Accent); } private static void BuildPushDagger(KnifeDefinition definition, List parts) { //IL_0012: 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_0028: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Unknown result type (might be due to invalid IL or missing references) Vector2[] input = (Vector2[])(object)new Vector2[5] { new Vector2(-0.105f, 0.24f), new Vector2(0.105f, 0.24f), new Vector2(0.075f, 0.57f), new Vector2(0f, 0.72f), new Vector2(-0.075f, 0.57f) }; Add(parts, "DaggerBlade", MeshBuilder.ExtrudePolygon(input, 0.045f, "Dagger Blade"), PartMaterial.Blade); Add(parts, "DaggerGrip", MeshBuilder.Box2D(-0.22f, 0.12f, 0.22f, 0.23f, 0.09f, "Dagger Grip"), PartMaterial.Grip); Add(parts, "DaggerGuard", MeshBuilder.Box2D(-0.135f, 0.225f, 0.135f, 0.275f, 0.085f, "Dagger Guard"), PartMaterial.Accent); } private static void BuildButterfly(KnifeDefinition definition, List parts) { //IL_0012: 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_0028: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_00ca: 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_0144: Unknown result type (might be due to invalid IL or missing references) Vector2[] input = (Vector2[])(object)new Vector2[5] { new Vector2(-0.05f, 0.3f), new Vector2(0.05f, 0.3f), new Vector2(0.045f, 0.76f), new Vector2(0f, 0.93f), new Vector2(-0.035f, 0.78f) }; Add(parts, "ButterflyBlade", MeshBuilder.ExtrudePolygon(input, 0.032f, "Butterfly Blade"), PartMaterial.Blade); Add(parts, "ButterflyHandleLeft", MeshBuilder.Box2D(-0.045f, -0.28f, 0.045f, 0f, 0.052f, "Butterfly Handle"), PartMaterial.Grip, new Vector3(-0.055f, 0.3f, 0f)); Add(parts, "ButterflyHandleRight", MeshBuilder.Box2D(-0.045f, -0.28f, 0.045f, 0f, 0.052f, "Butterfly Handle"), PartMaterial.Grip, new Vector3(0.055f, 0.3f, 0f)); Add(parts, "ButterflyHinge", MeshBuilder.Torus(0.055f, 0.014f, 16, 6, "Butterfly Hinge"), PartMaterial.Accent, new Vector3(0f, 0.3f, 0f)); } private static void BuildSkeleton(KnifeDefinition definition, List parts) { //IL_010f: Unknown result type (might be due to invalid IL or missing references) Vector2[] input = BladePolygon(KnifeShape.Skeleton, definition.BladeWidth, definition.LengthScale); Add(parts, "SkeletonBlade", MeshBuilder.ExtrudePolygon(input, 0.035f, "Skeleton Blade"), PartMaterial.Blade); Add(parts, "SkeletonRailLeft", MeshBuilder.Box2D(-0.075f, 0.02f, -0.045f, 0.31f, 0.06f, "Skeleton Rail"), PartMaterial.Grip); Add(parts, "SkeletonRailRight", MeshBuilder.Box2D(0.045f, 0.02f, 0.075f, 0.31f, 0.06f, "Skeleton Rail"), PartMaterial.Grip); for (int i = 0; i < 3; i++) { float num = 0.08f + (float)i * 0.085f; Add(parts, "SkeletonRung" + i, MeshBuilder.Box2D(-0.065f, num, 0.065f, num + 0.022f, 0.058f, "Skeleton Rung"), PartMaterial.Accent); } Add(parts, "SkeletonRing", MeshBuilder.Torus(0.075f, 0.018f, 18, 6, "Skeleton Ring"), PartMaterial.Accent, new Vector3(0f, 0.025f, 0f)); Add(parts, "SkeletonGuard", MeshBuilder.Box2D(-0.115f, 0.285f, 0.115f, 0.335f, 0.07f, "Skeleton Guard"), PartMaterial.Accent); } private static Vector2[] BladePolygon(KnifeShape shape, float width, float tip) { //IL_0066: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Unknown result type (might be due to invalid IL or missing references) //IL_007e: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_009d: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: Unknown result type (might be due to invalid IL or missing references) //IL_00b7: Unknown result type (might be due to invalid IL or missing references) //IL_00c7: Unknown result type (might be due to invalid IL or missing references) //IL_00cc: 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_00e7: 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_0107: Unknown result type (might be due to invalid IL or missing references) //IL_011a: Unknown result type (might be due to invalid IL or missing references) //IL_011f: 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_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_0161: Unknown result type (might be due to invalid IL or missing references) //IL_0166: Unknown result type (might be due to invalid IL or missing references) //IL_0181: Unknown result type (might be due to invalid IL or missing references) //IL_0186: 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_019e: Unknown result type (might be due to invalid IL or missing references) //IL_01b3: Unknown result type (might be due to invalid IL or missing references) //IL_01b8: 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_01d2: Unknown result type (might be due to invalid IL or missing references) //IL_01e2: 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_01fd: Unknown result type (might be due to invalid IL or missing references) //IL_0202: Unknown result type (might be due to invalid IL or missing references) //IL_0398: Unknown result type (might be due to invalid IL or missing references) //IL_039d: Unknown result type (might be due to invalid IL or missing references) //IL_03b0: Unknown result type (might be due to invalid IL or missing references) //IL_03b5: Unknown result type (might be due to invalid IL or missing references) //IL_03ca: Unknown result type (might be due to invalid IL or missing references) //IL_03cf: Unknown result type (might be due to invalid IL or missing references) //IL_03dc: Unknown result type (might be due to invalid IL or missing references) //IL_03e1: Unknown result type (might be due to invalid IL or missing references) //IL_03f7: Unknown result type (might be due to invalid IL or missing references) //IL_03fc: Unknown result type (might be due to invalid IL or missing references) //IL_021d: Unknown result type (might be due to invalid IL or missing references) //IL_0222: 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_023a: 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_0254: Unknown result type (might be due to invalid IL or missing references) //IL_0269: Unknown result type (might be due to invalid IL or missing references) //IL_026e: 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_0283: 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_02b9: Unknown result type (might be due to invalid IL or missing references) //IL_02be: Unknown result type (might be due to invalid IL or missing references) //IL_02cb: Unknown result type (might be due to invalid IL or missing references) //IL_02d0: Unknown result type (might be due to invalid IL or missing references) //IL_02e3: Unknown result type (might be due to invalid IL or missing references) //IL_02e8: Unknown result type (might be due to invalid IL or missing references) //IL_02f9: Unknown result type (might be due to invalid IL or missing references) //IL_02fe: Unknown result type (might be due to invalid IL or missing references) //IL_0319: Unknown result type (might be due to invalid IL or missing references) //IL_031e: Unknown result type (might be due to invalid IL or missing references) //IL_0331: Unknown result type (might be due to invalid IL or missing references) //IL_0336: Unknown result type (might be due to invalid IL or missing references) //IL_034b: Unknown result type (might be due to invalid IL or missing references) //IL_0350: Unknown result type (might be due to invalid IL or missing references) //IL_035d: Unknown result type (might be due to invalid IL or missing references) //IL_0362: Unknown result type (might be due to invalid IL or missing references) //IL_0378: Unknown result type (might be due to invalid IL or missing references) //IL_037d: Unknown result type (might be due to invalid IL or missing references) switch (shape) { case KnifeShape.M9Bayonet: return (Vector2[])(object)new Vector2[6] { new Vector2((0f - width) * 0.48f, 0.31f), new Vector2(width * 0.48f, 0.31f), new Vector2(width * 0.43f, tip * 0.72f), new Vector2(width * 0.18f, tip * 0.91f), new Vector2((0f - width) * 0.08f, tip), new Vector2((0f - width) * 0.4f, tip * 0.84f) }; case KnifeShape.Flip: case KnifeShape.Navaja: return (Vector2[])(object)new Vector2[5] { new Vector2((0f - width) * 0.45f, 0.3f), new Vector2(width * 0.45f, 0.3f), new Vector2(width * 0.4f, tip * 0.72f), new Vector2(0f, tip), new Vector2((0f - width) * 0.3f, tip * 0.82f) }; case KnifeShape.Gut: case KnifeShape.Falchion: return (Vector2[])(object)new Vector2[6] { new Vector2((0f - width) * 0.5f, 0.3f), new Vector2(width * 0.5f, 0.3f), new Vector2(width * 0.52f, tip * 0.62f), new Vector2(width * 0.3f, tip * 0.88f), new Vector2((0f - width) * 0.08f, tip), new Vector2((0f - width) * 0.46f, tip * 0.76f) }; case KnifeShape.Huntsman: case KnifeShape.Bowie: return (Vector2[])(object)new Vector2[6] { new Vector2((0f - width) * 0.52f, 0.3f), new Vector2(width * 0.52f, 0.3f), new Vector2(width * 0.48f, tip * 0.7f), new Vector2(width * 0.14f, tip * 0.88f), new Vector2((0f - width) * 0.16f, tip), new Vector2((0f - width) * 0.5f, tip * 0.82f) }; case KnifeShape.Stiletto: return (Vector2[])(object)new Vector2[4] { new Vector2((0f - width) * 0.48f, 0.3f), new Vector2(0f, tip), new Vector2(width * 0.48f, 0.3f), new Vector2(0f, 0.36f) }; case KnifeShape.Ursus: case KnifeShape.Survival: case KnifeShape.Nomad: return (Vector2[])(object)new Vector2[5] { new Vector2((0f - width) * 0.5f, 0.3f), new Vector2(width * 0.5f, 0.3f), new Vector2(width * 0.38f, tip * 0.78f), new Vector2(0f, tip), new Vector2((0f - width) * 0.42f, tip * 0.88f) }; default: return (Vector2[])(object)new Vector2[5] { new Vector2((0f - width) * 0.46f, 0.3f), new Vector2(width * 0.46f, 0.3f), new Vector2(width * 0.37f, tip * 0.79f), new Vector2(0f, tip), new Vector2((0f - width) * 0.34f, tip * 0.86f) }; } } private static void Add(List parts, string name, Mesh mesh, PartMaterial material) { //IL_0004: Unknown result type (might be due to invalid IL or missing references) Add(parts, name, mesh, material, Vector3.zero); } private static void Add(List parts, string name, Mesh mesh, PartMaterial material, Vector3 position) { //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) parts.Add(new KnifePart { Name = name, Mesh = mesh, Material = material, Position = position }); } private static Mesh CombineForInventory(KnifeDefinition definition, List parts) { //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_0036: 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_004d: 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_0059: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0063: 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_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: 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_00bd: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: Expected O, but got Unknown CombineInstance[] array = (CombineInstance[])(object)new CombineInstance[parts.Count]; Matrix4x4 val = Matrix4x4.Rotate(Quaternion.Euler(90f, 0f, 0f)); for (int i = 0; i < parts.Count; i++) { KnifePart knifePart = parts[i]; int num = i; CombineInstance val2 = default(CombineInstance); ((CombineInstance)(ref val2)).mesh = knifePart.Mesh; ((CombineInstance)(ref val2)).transform = val * Matrix4x4.TRS(knifePart.Position, knifePart.Rotation, knifePart.Scale); array[num] = val2; } Mesh val3 = new Mesh { name = "MoreKnives_" + definition.DisplayName.Replace(" ", string.Empty), hideFlags = (HideFlags)52 }; val3.CombineMeshes(array, true, true, false); val3.RecalculateBounds(); return val3; } private static Material GetMaterial(KnifeAssetSet assets, PartMaterial partMaterial) { return (Material)(partMaterial switch { PartMaterial.Grip => assets.GripMaterial, PartMaterial.Accent => assets.AccentMaterial, _ => assets.BladeMaterial, }); } private static Material CreateMaterial(string name, Color color, float metallic, float smoothness) { //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Expected O, but got Unknown //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_006a: Unknown result type (might be due to invalid IL or missing references) Shader val = Shader.Find("Universal Render Pipeline/Lit"); if (!Object.op_Implicit((Object)(object)val)) { val = Shader.Find("Standard"); } Material val2 = new Material(val); ((Object)val2).name = "MoreKnives " + name; ((Object)val2).hideFlags = (HideFlags)52; if (val2.HasProperty("_BaseColor")) { val2.SetColor("_BaseColor", color); } if (val2.HasProperty("_Color")) { val2.SetColor("_Color", color); } if (val2.HasProperty("_Metallic")) { val2.SetFloat("_Metallic", metallic); } if (val2.HasProperty("_Smoothness")) { val2.SetFloat("_Smoothness", smoothness); } if (val2.HasProperty("_Glossiness")) { val2.SetFloat("_Glossiness", smoothness); } return val2; } private static void SetLayerRecursively(GameObject gameObject, int layer) { //IL_001b: Unknown result type (might be due to invalid IL or missing references) gameObject.layer = layer; foreach (Transform item in gameObject.transform) { SetLayerRecursively(((Component)item).gameObject, layer); } } } internal static class MeshBuilder { public static Mesh Box2D(float xMin, float yMin, float xMax, float yMax, float thickness, string name) { //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) return ExtrudePolygon((Vector2[])(object)new Vector2[4] { new Vector2(xMin, yMin), new Vector2(xMax, yMin), new Vector2(xMax, yMax), new Vector2(xMin, yMax) }, thickness, name); } public static Mesh Ribbon(Vector2[] centerLine, float halfWidth, float thickness, string name) { //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_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_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_00ae: 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_00b6: Unknown result type (might be due to invalid IL or missing references) //IL_00bd: Unknown result type (might be due to invalid IL or missing references) //IL_00c2: Unknown result type (might be due to invalid IL or missing references) //IL_00c7: Unknown result type (might be due to invalid IL or missing references) //IL_00d0: Unknown result type (might be due to invalid IL or missing references) //IL_00d5: Unknown result type (might be due to invalid IL or missing references) //IL_00d8: 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_010f: Unknown result type (might be due to invalid IL or missing references) List list = new List(); Vector2[] array = (Vector2[])(object)new Vector2[centerLine.Length]; Vector2[] array2 = (Vector2[])(object)new Vector2[centerLine.Length]; Vector2 val2 = default(Vector2); for (int i = 0; i < centerLine.Length; i++) { Vector2 val = ((i != 0) ? ((i != centerLine.Length - 1) ? (centerLine[i + 1] - centerLine[i - 1]) : (centerLine[i] - centerLine[i - 1])) : (centerLine[1] - centerLine[0])); ((Vector2)(ref val)).Normalize(); ((Vector2)(ref val2))..ctor(0f - val.y, val.x); float num = Mathf.Lerp(1f, 0.12f, (float)i / (float)(centerLine.Length - 1)); array[i] = centerLine[i] + val2 * halfWidth * num; array2[i] = centerLine[i] - val2 * halfWidth * num; } list.AddRange(array); for (int num2 = array2.Length - 1; num2 >= 0; num2--) { list.Add(array2[num2]); } return ExtrudePolygon(list.ToArray(), thickness, name); } public static Mesh Torus(float radius, float tube, int segments, int sides, string name) { //IL_0068: Unknown result type (might be due to invalid IL or missing references) List list = new List(); List list2 = new List(); for (int i = 0; i < segments; i++) { float num = (float)i / (float)segments * (float)Math.PI * 2f; float num2 = Mathf.Cos(num); float num3 = Mathf.Sin(num); for (int j = 0; j < sides; j++) { float num4 = (float)j / (float)sides * (float)Math.PI * 2f; float num5 = radius + tube * Mathf.Cos(num4); list.Add(new Vector3(num2 * num5, num3 * num5, tube * Mathf.Sin(num4))); } } for (int k = 0; k < segments; k++) { int num6 = (k + 1) % segments; for (int l = 0; l < sides; l++) { int num7 = (l + 1) % sides; int item = k * sides + l; int item2 = num6 * sides + l; int item3 = num6 * sides + num7; int item4 = k * sides + num7; list2.Add(item); list2.Add(item2); list2.Add(item3); list2.Add(item); list2.Add(item3); list2.Add(item4); } } return Finish(name, list, list2); } public static Mesh ExtrudePolygon(Vector2[] input, float thickness, string name) { //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_008d: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_00a5: Unknown result type (might be due to invalid IL or missing references) if (input == null || input.Length < 3) { throw new ArgumentException("A polygon needs at least three points.", "input"); } List list = new List(input); if (SignedArea(list) < 0f) { list.Reverse(); } List list2 = Triangulate(list); List list3 = new List(); float num = thickness * 0.5f; for (int i = 0; i < list.Count; i++) { list3.Add(new Vector3(list[i].x, list[i].y, 0f - num)); } for (int j = 0; j < list.Count; j++) { list3.Add(new Vector3(list[j].x, list[j].y, num)); } List list4 = new List(); for (int k = 0; k < list2.Count; k += 3) { int num2 = list2[k]; int num3 = list2[k + 1]; int num4 = list2[k + 2]; list4.Add(num2); list4.Add(num4); list4.Add(num3); list4.Add(num2 + list.Count); list4.Add(num3 + list.Count); list4.Add(num4 + list.Count); } for (int l = 0; l < list.Count; l++) { int num5 = (l + 1) % list.Count; int item = l; int item2 = num5; int item3 = l + list.Count; int item4 = num5 + list.Count; list4.Add(item); list4.Add(item2); list4.Add(item4); list4.Add(item); list4.Add(item4); list4.Add(item3); } return Finish(name, list3, list4); } private static Mesh Finish(string name, List vertices, List triangles) { //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_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Expected O, but got Unknown Mesh val = new Mesh { name = "MoreKnives " + name, hideFlags = (HideFlags)52 }; val.SetVertices(vertices); val.SetTriangles(triangles, 0); val.RecalculateNormals(); val.RecalculateBounds(); return val; } private static float SignedArea(List polygon) { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0022: 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_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) float num = 0f; for (int i = 0; i < polygon.Count; i++) { Vector2 val = polygon[i]; Vector2 val2 = polygon[(i + 1) % polygon.Count]; num += val.x * val2.y - val2.x * val.y; } return num * 0.5f; } private static List Triangulate(List polygon) { //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_008c: 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_00ca: Unknown result type (might be due to invalid IL or missing references) //IL_00d2: Unknown result type (might be due to invalid IL or missing references) //IL_00da: Unknown result type (might be due to invalid IL or missing references) List list = new List(); for (int i = 0; i < polygon.Count; i++) { list.Add(i); } List list2 = new List(); int num = polygon.Count * polygon.Count; while (list.Count > 3 && num-- > 0) { bool flag = false; for (int j = 0; j < list.Count; j++) { int num2 = list[(j + list.Count - 1) % list.Count]; int num3 = list[j]; int num4 = list[(j + 1) % list.Count]; if (!IsConvex(polygon[num2], polygon[num3], polygon[num4])) { continue; } bool flag2 = false; for (int k = 0; k < list.Count; k++) { int num5 = list[k]; if (num5 != num2 && num5 != num3 && num5 != num4 && PointInTriangle(polygon[num5], polygon[num2], polygon[num3], polygon[num4])) { flag2 = true; break; } } if (!flag2) { list2.Add(num2); list2.Add(num3); list2.Add(num4); list.RemoveAt(j); flag = true; break; } } if (!flag) { break; } } if (list.Count == 3) { list2.Add(list[0]); list2.Add(list[1]); list2.Add(list[2]); } else if (list2.Count == 0) { for (int l = 1; l < polygon.Count - 1; l++) { list2.Add(0); list2.Add(l); list2.Add(l + 1); } } return list2; } private static bool IsConvex(Vector2 a, Vector2 b, Vector2 c) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Unknown result type (might be due to invalid IL or missing references) return Cross(b - a, c - b) > 1E-06f; } private static bool PointInTriangle(Vector2 point, Vector2 a, Vector2 b, Vector2 c) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_001a: 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_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_002f: 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) float num = Cross(b - a, point - a); float num2 = Cross(c - b, point - b); float num3 = Cross(a - c, point - c); bool flag = num < 0f || num2 < 0f || num3 < 0f; bool flag2 = num > 0f || num2 > 0f || num3 > 0f; return !(flag && flag2); } private static float Cross(Vector2 a, Vector2 b) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Unknown result type (might be due to invalid IL or missing references) return a.x * b.y - a.y * b.x; } } internal static class KnifeCatalog { public const byte VanillaKnifeId = 63; public const int VanillaKnifeCost = 45; public const byte FirstPurchaseId = 200; public const byte FirstVariantCode = 128; private static readonly Color Steel = new Color(0.62f, 0.68f, 0.72f); private static readonly Color DarkSteel = new Color(0.27f, 0.31f, 0.34f); private static readonly Color Black = new Color(0.055f, 0.065f, 0.075f); private static readonly Color Tan = new Color(0.34f, 0.25f, 0.16f); private static readonly Color Green = new Color(0.16f, 0.25f, 0.16f); private static readonly Color Blue = new Color(0.1f, 0.19f, 0.28f); private static readonly Color Red = new Color(0.38f, 0.08f, 0.07f); private static readonly List DefinitionsInternal = new List { New(0, "Bayonet", 45, KnifeShape.Bayonet, InspectStyle.Presentation, Steel, Green, DarkSteel, 0.135f, 1f), New(1, "M9 Bayonet", 45, KnifeShape.M9Bayonet, InspectStyle.BayonetSpin, DarkSteel, Black, Steel, 0.175f, 1.05f), New(2, "Flip Knife", 45, KnifeShape.Flip, InspectStyle.Flip, Steel, Black, DarkSteel, 0.155f, 0.82f), New(3, "Gut Knife", 45, KnifeShape.Gut, InspectStyle.Flip, Steel, Tan, DarkSteel, 0.195f, 0.88f), New(4, "Karambit", 45, KnifeShape.Karambit, InspectStyle.KarambitTwirl, DarkSteel, Black, Steel, 0.145f, 0.82f), New(5, "Huntsman Knife", 45, KnifeShape.Huntsman, InspectStyle.HeavyPresentation, DarkSteel, Green, Steel, 0.215f, 1.02f), New(6, "Butterfly Knife", 45, KnifeShape.Butterfly, InspectStyle.ButterflyFlourish, Steel, Blue, DarkSteel, 0.135f, 0.92f), New(7, "Falchion Knife", 45, KnifeShape.Falchion, InspectStyle.FalchionBalance, Steel, Black, DarkSteel, 0.19f, 0.91f), New(8, "Shadow Daggers", 45, KnifeShape.DualDaggers, InspectStyle.DualFlourish, DarkSteel, Red, Steel, 0.2f, 0.7f, dual: true), New(9, "Bowie Knife", 45, KnifeShape.Bowie, InspectStyle.HeavyPresentation, Steel, Tan, DarkSteel, 0.25f, 1.13f), New(10, "Navaja Knife", 45, KnifeShape.Navaja, InspectStyle.Flip, Steel, Tan, DarkSteel, 0.14f, 0.72f), New(11, "Stiletto Knife", 45, KnifeShape.Stiletto, InspectStyle.StilettoSnap, Steel, Red, DarkSteel, 0.085f, 0.94f), New(12, "Ursus Knife", 45, KnifeShape.Ursus, InspectStyle.BayonetSpin, DarkSteel, Black, Steel, 0.185f, 0.94f), New(13, "Talon Knife", 45, KnifeShape.Talon, InspectStyle.KarambitTwirl, Steel, Tan, DarkSteel, 0.16f, 0.88f), New(14, "Classic Knife", 45, KnifeShape.Classic, InspectStyle.Presentation, Steel, Black, DarkSteel, 0.16f, 0.98f), New(15, "Paracord Knife", 45, KnifeShape.Paracord, InspectStyle.SkeletonRoll, DarkSteel, Green, Steel, 0.18f, 0.96f), New(16, "Survival Knife", 45, KnifeShape.Survival, InspectStyle.SkeletonRoll, Steel, Green, DarkSteel, 0.19f, 0.95f), New(17, "Nomad Knife", 45, KnifeShape.Nomad, InspectStyle.HeavyPresentation, Steel, Tan, DarkSteel, 0.195f, 0.98f), New(18, "Skeleton Knife", 45, KnifeShape.Skeleton, InspectStyle.SkeletonRoll, DarkSteel, Black, Steel, 0.175f, 1f) }; private static readonly Dictionary ByPurchaseId = BuildPurchaseLookup(); private static readonly Dictionary ByVariantCode = BuildVariantLookup(); public static IList Definitions => DefinitionsInternal; public static bool TryGetByPurchaseId(byte id, out KnifeDefinition definition) { return ByPurchaseId.TryGetValue(id, out definition); } public static bool TryGetByVariantCode(byte code, out KnifeDefinition definition) { return ByVariantCode.TryGetValue(code, out definition); } public static bool TryGet(Item item, out KnifeDefinition definition) { definition = null; if (!Object.op_Implicit((Object)(object)item)) { return false; } if (!TryGetByVariantCode(item.CurSkin, out definition)) { return TryGetByPurchaseId(item.ID, out definition); } return true; } private static KnifeDefinition New(int index, string name, int price, KnifeShape shape, InspectStyle inspect, Color blade, Color grip, Color accent, float width, float length, bool dual = false) { //IL_0015: 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_0019: Unknown result type (might be due to invalid IL or missing references) return new KnifeDefinition((byte)(200 + index), (byte)(128 + index), name, price, shape, inspect, blade, grip, accent, width, length, dual); } private static Dictionary BuildPurchaseLookup() { Dictionary dictionary = new Dictionary(); foreach (KnifeDefinition item in DefinitionsInternal) { dictionary.Add(item.PurchaseId, item); } return dictionary; } private static Dictionary BuildVariantLookup() { Dictionary dictionary = new Dictionary(); foreach (KnifeDefinition item in DefinitionsInternal) { dictionary.Add(item.VariantCode, item); } return dictionary; } } internal enum KnifeShape { Bayonet, M9Bayonet, Flip, Gut, Karambit, Huntsman, Butterfly, Falchion, DualDaggers, Bowie, Navaja, Stiletto, Ursus, Talon, Classic, Paracord, Survival, Nomad, Skeleton } internal enum InspectStyle { Presentation, BayonetSpin, Flip, KarambitTwirl, ButterflyFlourish, FalchionBalance, DualFlourish, HeavyPresentation, StilettoSnap, SkeletonRoll } internal enum PartMaterial { Blade, Grip, Accent } internal sealed class KnifeDefinition { public byte PurchaseId { get; private set; } public byte VariantCode { get; private set; } public string DisplayName { get; private set; } public int Price { get; private set; } public KnifeShape Shape { get; private set; } public InspectStyle InspectStyle { get; private set; } public Color BladeColor { get; private set; } public Color GripColor { get; private set; } public Color AccentColor { get; private set; } public float BladeWidth { get; private set; } public float LengthScale { get; private set; } public bool Dual { get; private set; } public KnifeDefinition(byte purchaseId, byte variantCode, string displayName, int price, KnifeShape shape, InspectStyle inspectStyle, Color bladeColor, Color gripColor, Color accentColor, float bladeWidth, float lengthScale, bool dual = false) { //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result type (might be due to invalid IL or missing references) PurchaseId = purchaseId; VariantCode = variantCode; DisplayName = displayName; Price = price; Shape = shape; InspectStyle = inspectStyle; BladeColor = bladeColor; GripColor = gripColor; AccentColor = accentColor; BladeWidth = bladeWidth; LengthScale = lengthScale; Dual = dual; } } internal static class KnifeShopInstaller { private static bool _isInstalling; public static void TryInstall(ItemPurchasable source) { //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_00bb: Unknown result type (might be due to invalid IL or missing references) if (_isInstalling || !Object.op_Implicit((Object)(object)source) || Object.op_Implicit((Object)(object)((Component)source).GetComponent())) { return; } Item val = ReflectionUtil.Get(source, "_itemToPurchase"); if (!Object.op_Implicit((Object)(object)val) || val.ID != 63) { return; } _isInstalling = true; try { for (int i = 0; i < KnifeCatalog.Definitions.Count; i++) { KnifeDefinition knifeDefinition = KnifeCatalog.Definitions[i]; GameObject obj = Object.Instantiate(((Component)source).gameObject, ((Component)source).transform.parent); ((Object)obj).name = "More Knives - " + knifeDefinition.DisplayName; obj.AddComponent().DefinitionIndex = i; Transform transform = obj.transform; transform.position = ((Component)source).transform.position + CalculateOffset(((Component)source).transform, i); transform.rotation = ((Component)source).transform.rotation; ApplyDisplayModel(obj, knifeDefinition); } MoreKnivesPlugin.Log.LogInfo((object)("Added " + KnifeCatalog.Definitions.Count + " $" + 45 + " knife choices beside " + GetPath(((Component)source).transform))); } catch (Exception ex) { MoreKnivesPlugin.Log.LogError((object)("Could not install the More Knives shop rack: " + ex)); } finally { _isInstalling = false; } } private static Vector3 CalculateOffset(Transform source, int index) { //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_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) //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) int num = index % 5; int num2 = index / 5; float num3 = ((float)num - 2f) * 0.34f; float num4 = ((float)num2 + 1f) * 0.38f; return source.right * num3 + source.forward * num4 + Vector3.up * ((float)num2 * 0.012f); } private static void ApplyDisplayModel(GameObject purchaseObject, KnifeDefinition definition) { //IL_00f7: 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_0067: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0070: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Unknown result type (might be due to invalid IL or missing references) //IL_008b: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Unknown result type (might be due to invalid IL or missing references) //IL_0094: Unknown result type (might be due to invalid IL or missing references) //IL_0099: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: Unknown result type (might be due to invalid IL or missing references) //IL_00cd: 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_00d6: Unknown result type (might be due to invalid IL or missing references) GameObject[] array = ReflectionUtil.Get(purchaseObject.GetComponent(), "_modelsToOutline"); if (array == null || array.Length == 0 || !Object.op_Implicit((Object)(object)array[0])) { return; } KnifeAssetSet knifeAssetSet = KnifeAssets.Get(definition); MeshFilter[] componentsInChildren = array[0].GetComponentsInChildren(true); foreach (MeshFilter val in componentsInChildren) { if (!Object.op_Implicit((Object)(object)val)) { continue; } Mesh sharedMesh = val.sharedMesh; float num = 1f; if (Object.op_Implicit((Object)(object)sharedMesh)) { Bounds bounds = sharedMesh.bounds; Vector3 size = ((Bounds)(ref bounds)).size; if (((Vector3)(ref size)).magnitude > 0.0001f) { bounds = knifeAssetSet.InventoryMesh.bounds; size = ((Bounds)(ref bounds)).size; if (((Vector3)(ref size)).magnitude > 0.0001f) { bounds = sharedMesh.bounds; size = ((Bounds)(ref bounds)).size; float magnitude = ((Vector3)(ref size)).magnitude; bounds = knifeAssetSet.InventoryMesh.bounds; size = ((Bounds)(ref bounds)).size; num = magnitude / ((Vector3)(ref size)).magnitude; } } } val.sharedMesh = knifeAssetSet.InventoryMesh; Transform transform = ((Component)val).transform; transform.localScale *= Mathf.Clamp(num, 0.05f, 20f); MeshRenderer component = ((Component)val).GetComponent(); if (Object.op_Implicit((Object)(object)component)) { ((Renderer)component).sharedMaterial = knifeAssetSet.BladeMaterial; } } } private static string GetPath(Transform transform) { string text = ((Object)transform).name; Transform parent = transform.parent; while (Object.op_Implicit((Object)(object)parent)) { text = ((Object)parent).name + "/" + text; parent = parent.parent; } return text; } } internal sealed class KnifeShopMarker : MonoBehaviour { public int DefinitionIndex; public KnifeDefinition Definition { get { if (DefinitionIndex < 0 || DefinitionIndex >= KnifeCatalog.Definitions.Count) { return null; } return KnifeCatalog.Definitions[DefinitionIndex]; } } } internal sealed class KnifeVisualController : MonoBehaviour { private KnifeDefinition _definition; private GameObject _rightModel; private GameObject _leftModel; private GameObject _leftAnchor; private SkinnedMeshRenderer[] _vanillaKnifeRenderers; private Coroutine _inspectRoutine; private Transform _rightButterflyHandleA; private Transform _rightButterflyHandleB; private Transform _leftButterflyHandleA; private Transform _leftButterflyHandleB; private Quaternion _rightHandleARotation; private Quaternion _rightHandleBRotation; private Quaternion _leftHandleARotation; private Quaternion _leftHandleBRotation; public KnifeDefinition Definition => _definition; public static KnifeVisualController Ensure(Item item, KnifeDefinition definition) { KnifeVisualController knifeVisualController = ((Component)item).GetComponent(); if (!Object.op_Implicit((Object)(object)knifeVisualController)) { knifeVisualController = ((Component)item).gameObject.AddComponent(); } knifeVisualController.Apply(definition); return knifeVisualController; } public static void ApplyOrClear(Item item) { if (!Object.op_Implicit((Object)(object)item)) { return; } if (KnifeCatalog.TryGetByVariantCode(item.CurSkin, out var definition)) { Ensure(item, definition); return; } KnifeVisualController component = ((Component)item).GetComponent(); if (Object.op_Implicit((Object)(object)component)) { component.Clear(); } } public void Apply(KnifeDefinition definition) { //IL_0133: Unknown result type (might be due to invalid IL or missing references) //IL_0148: Unknown result type (might be due to invalid IL or missing references) //IL_015d: Unknown result type (might be due to invalid IL or missing references) //IL_0176: Unknown result type (might be due to invalid IL or missing references) //IL_019c: Unknown result type (might be due to invalid IL or missing references) //IL_01a6: Expected O, but got Unknown //IL_01c6: Unknown result type (might be due to invalid IL or missing references) //IL_01cb: Unknown result type (might be due to invalid IL or missing references) //IL_01cf: 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_01fa: 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_0230: Unknown result type (might be due to invalid IL or missing references) //IL_0245: Unknown result type (might be due to invalid IL or missing references) //IL_025a: Unknown result type (might be due to invalid IL or missing references) //IL_0264: Unknown result type (might be due to invalid IL or missing references) if (definition == null) { Clear(); } else { if (_definition != null && _definition.VariantCode == definition.VariantCode && Object.op_Implicit((Object)(object)_rightModel)) { return; } ClearGeneratedModels(); _definition = definition; Transform val = FindDeepChild(((Component)this).transform, "KnifeAnimated"); Transform val2 = (Object.op_Implicit((Object)(object)val) ? FindDeepChild(val, "r_IK") : null); Transform val3 = (Object.op_Implicit((Object)(object)val) ? FindDeepChild(val, "l_IK") : null); Transform val4 = (Object.op_Implicit((Object)(object)val2) ? FindDirectChild(val2, "Knife") : null); if (!Object.op_Implicit((Object)(object)val4)) { MoreKnivesPlugin.Log.LogWarning((object)("Could not find the vanilla knife bone on " + ((Object)((Component)this).gameObject).name)); return; } _vanillaKnifeRenderers = ((Component)val).GetComponentsInChildren(true); SkinnedMeshRenderer[] vanillaKnifeRenderers = _vanillaKnifeRenderers; foreach (SkinnedMeshRenderer val5 in vanillaKnifeRenderers) { if (Object.op_Implicit((Object)(object)val5) && ((Object)((Component)val5).gameObject).name == "Knife") { ((Renderer)val5).enabled = false; } } _rightModel = KnifeAssets.CreateWorldModel(definition, val4, "_R"); _rightModel.transform.localPosition = Vector3.zero; _rightModel.transform.localRotation = Quaternion.identity; _rightModel.transform.localScale = Vector3.one * (definition.Dual ? 7.8f : 9.43f); if (definition.Dual && Object.op_Implicit((Object)(object)val3)) { _leftAnchor = new GameObject("MoreKnivesLeftAnchor"); ((Object)_leftAnchor).hideFlags = (HideFlags)52; _leftAnchor.transform.SetParent(val3, false); Vector3 localPosition = val4.localPosition; localPosition.z = 0f - localPosition.z; _leftAnchor.transform.localPosition = localPosition; _leftAnchor.transform.localRotation = Quaternion.Inverse(val4.localRotation); _leftModel = KnifeAssets.CreateWorldModel(definition, _leftAnchor.transform, "_L"); _leftModel.transform.localPosition = Vector3.zero; _leftModel.transform.localRotation = Quaternion.identity; _leftModel.transform.localScale = Vector3.one * 7.8f; } Melee component = ((Component)this).GetComponent(); if (Object.op_Implicit((Object)(object)component)) { ReflectionUtil.Set(component, "_useBothHands", definition.Dual); } CacheAnimatedParts(); ResetPose(); } } public void PlayInspect() { if (_definition != null && Object.op_Implicit((Object)(object)_rightModel) && ((Component)this).gameObject.activeInHierarchy) { CancelInspect(); _inspectRoutine = ((MonoBehaviour)this).StartCoroutine(InspectAnimation()); } } public void CancelInspect() { if (_inspectRoutine != null) { ((MonoBehaviour)this).StopCoroutine(_inspectRoutine); _inspectRoutine = null; } ResetPose(); } public void Clear() { CancelInspect(); ClearGeneratedModels(); if (_vanillaKnifeRenderers != null) { SkinnedMeshRenderer[] vanillaKnifeRenderers = _vanillaKnifeRenderers; foreach (SkinnedMeshRenderer val in vanillaKnifeRenderers) { if (Object.op_Implicit((Object)(object)val) && ((Object)((Component)val).gameObject).name == "Knife") { ((Renderer)val).enabled = true; } } } Melee component = ((Component)this).GetComponent(); if (Object.op_Implicit((Object)(object)component)) { ReflectionUtil.Set(component, "_useBothHands", false); } _definition = null; } private IEnumerator InspectAnimation() { float start = Time.unscaledTime; while (Time.unscaledTime - start < 3.55f) { float time = Mathf.Clamp01((Time.unscaledTime - start) / 3.55f); ApplyInspectPose(time); yield return null; } ResetPose(); _inspectRoutine = null; } private void ApplyInspectPose(float time) { //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_001a: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_0399: Unknown result type (might be due to invalid IL or missing references) //IL_03aa: Unknown result type (might be due to invalid IL or missing references) //IL_03ab: Unknown result type (might be due to invalid IL or missing references) //IL_03cd: Unknown result type (might be due to invalid IL or missing references) //IL_03ce: Unknown result type (might be due to invalid IL or missing references) //IL_03e3: Unknown result type (might be due to invalid IL or missing references) //IL_03e5: Unknown result type (might be due to invalid IL or missing references) float num = Smooth01(time); float num2 = Mathf.Sin((float)Math.PI * time); Vector3 zero = Vector3.zero; Vector3 zero2 = Vector3.zero; Vector3 zero3 = Vector3.zero; float angleA = 0f; float angleB = 0f; switch (_definition.InspectStyle) { case InspectStyle.BayonetSpin: ((Vector3)(ref zero2))..ctor(18f * num2, 360f * num, -32f * num2); ((Vector3)(ref zero))..ctor(0.015f * num2, 0.018f * num2, -0.01f * num2); break; case InspectStyle.Flip: ((Vector3)(ref zero2))..ctor(220f * Mathf.Sin((float)Math.PI * time) * Mathf.Sin((float)Math.PI * time), 70f * num2, 360f * num); ((Vector3)(ref zero))..ctor(0.02f * Mathf.Sin((float)Math.PI * 2f * time), 0.015f * num2, 0f); break; case InspectStyle.KarambitTwirl: ((Vector3)(ref zero2))..ctor(22f * num2, 50f * num2, 720f * num); ((Vector3)(ref zero))..ctor(0.028f * Mathf.Sin((float)Math.PI * 2f * time), -0.018f * num2, 0f); break; case InspectStyle.ButterflyFlourish: ((Vector3)(ref zero2))..ctor(45f * num2, 360f * num, 180f * Mathf.Sin((float)Math.PI * 2f * time) * num2); ((Vector3)(ref zero))..ctor(0f, 0.02f * num2, -0.018f * num2); angleA = 165f * Mathf.Sin((float)Math.PI * 4f * time) * num2; angleB = -165f * Mathf.Sin((float)Math.PI * 4f * time + 0.8f) * num2; break; case InspectStyle.FalchionBalance: ((Vector3)(ref zero2))..ctor(-65f * num2, 115f * num2, 45f * Mathf.Sin((float)Math.PI * 2f * time)); ((Vector3)(ref zero))..ctor(0.025f * num2, 0.035f * num2, 0f); break; case InspectStyle.DualFlourish: ((Vector3)(ref zero2))..ctor(35f * num2, 360f * num, 80f * num2); ((Vector3)(ref zero3))..ctor(-35f * num2, -360f * num, -80f * num2); ((Vector3)(ref zero))..ctor(0.02f * num2, 0f, 0f); break; case InspectStyle.HeavyPresentation: ((Vector3)(ref zero2))..ctor(-48f * num2, 145f * num2, -24f * Mathf.Sin((float)Math.PI * 2f * time)); ((Vector3)(ref zero))..ctor(-0.018f * num2, 0.018f * num2, -0.028f * num2); break; case InspectStyle.StilettoSnap: ((Vector3)(ref zero2))..ctor(22f * num2, 720f * Smooth01(Mathf.Clamp01(time * 1.25f)), -18f * num2); ((Vector3)(ref zero))..ctor(0f, 0.028f * num2, 0f); break; case InspectStyle.SkeletonRoll: ((Vector3)(ref zero2))..ctor(360f * num, 70f * num2, 360f * num); ((Vector3)(ref zero))..ctor(0.018f * Mathf.Sin((float)Math.PI * 2f * time), 0.02f * num2, -0.012f * num2); break; default: ((Vector3)(ref zero2))..ctor(-32f * num2, 110f * num2, 18f * Mathf.Sin((float)Math.PI * 2f * time)); ((Vector3)(ref zero))..ctor(0f, 0.02f * num2, -0.02f * num2); break; } if (Object.op_Implicit((Object)(object)_rightModel)) { _rightModel.transform.localPosition = zero; _rightModel.transform.localRotation = Quaternion.Euler(zero2); } if (Object.op_Implicit((Object)(object)_leftModel)) { _leftModel.transform.localPosition = -zero; _leftModel.transform.localRotation = Quaternion.Euler(zero3); } SetButterflyHandleRotations(angleA, angleB); } private void CacheAnimatedParts() { //IL_00c7: Unknown result type (might be due to invalid IL or missing references) //IL_00ba: Unknown result type (might be due to invalid IL or missing references) //IL_00cc: 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_00df: 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_0111: 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_0116: Unknown result type (might be due to invalid IL or missing references) //IL_0136: Unknown result type (might be due to invalid IL or missing references) //IL_0129: Unknown result type (might be due to invalid IL or missing references) //IL_013b: Unknown result type (might be due to invalid IL or missing references) _rightButterflyHandleA = (Object.op_Implicit((Object)(object)_rightModel) ? FindDeepChild(_rightModel.transform, "ButterflyHandleLeft_R") : null); _rightButterflyHandleB = (Object.op_Implicit((Object)(object)_rightModel) ? FindDeepChild(_rightModel.transform, "ButterflyHandleRight_R") : null); _leftButterflyHandleA = (Object.op_Implicit((Object)(object)_leftModel) ? FindDeepChild(_leftModel.transform, "ButterflyHandleLeft_L") : null); _leftButterflyHandleB = (Object.op_Implicit((Object)(object)_leftModel) ? FindDeepChild(_leftModel.transform, "ButterflyHandleRight_L") : null); _rightHandleARotation = (Object.op_Implicit((Object)(object)_rightButterflyHandleA) ? _rightButterflyHandleA.localRotation : Quaternion.identity); _rightHandleBRotation = (Object.op_Implicit((Object)(object)_rightButterflyHandleB) ? _rightButterflyHandleB.localRotation : Quaternion.identity); _leftHandleARotation = (Object.op_Implicit((Object)(object)_leftButterflyHandleA) ? _leftButterflyHandleA.localRotation : Quaternion.identity); _leftHandleBRotation = (Object.op_Implicit((Object)(object)_leftButterflyHandleB) ? _leftButterflyHandleB.localRotation : Quaternion.identity); } private void SetButterflyHandleRotations(float angleA, float angleB) { //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_008b: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Unknown result type (might be due to invalid IL or missing references) //IL_00ae: 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) if (Object.op_Implicit((Object)(object)_rightButterflyHandleA)) { _rightButterflyHandleA.localRotation = _rightHandleARotation * Quaternion.Euler(0f, 0f, angleA); } if (Object.op_Implicit((Object)(object)_rightButterflyHandleB)) { _rightButterflyHandleB.localRotation = _rightHandleBRotation * Quaternion.Euler(0f, 0f, angleB); } if (Object.op_Implicit((Object)(object)_leftButterflyHandleA)) { _leftButterflyHandleA.localRotation = _leftHandleARotation * Quaternion.Euler(0f, 0f, 0f - angleA); } if (Object.op_Implicit((Object)(object)_leftButterflyHandleB)) { _leftButterflyHandleB.localRotation = _leftHandleBRotation * Quaternion.Euler(0f, 0f, 0f - angleB); } } private void ResetPose() { //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0064: Unknown result type (might be due to invalid IL or missing references) if (Object.op_Implicit((Object)(object)_rightModel)) { _rightModel.transform.localPosition = Vector3.zero; _rightModel.transform.localRotation = Quaternion.identity; } if (Object.op_Implicit((Object)(object)_leftModel)) { _leftModel.transform.localPosition = Vector3.zero; _leftModel.transform.localRotation = Quaternion.identity; } SetButterflyHandleRotations(0f, 0f); } private void ClearGeneratedModels() { if (Object.op_Implicit((Object)(object)_rightModel)) { Object.Destroy((Object)(object)_rightModel); } if (Object.op_Implicit((Object)(object)_leftModel)) { Object.Destroy((Object)(object)_leftModel); } if (Object.op_Implicit((Object)(object)_leftAnchor)) { Object.Destroy((Object)(object)_leftAnchor); } _rightModel = null; _leftModel = null; _leftAnchor = null; _rightButterflyHandleA = null; _rightButterflyHandleB = null; _leftButterflyHandleA = null; _leftButterflyHandleB = null; } private void OnDisable() { CancelInspect(); } private static float Smooth01(float value) { value = Mathf.Clamp01(value); return value * value * (3f - 2f * value); } private static Transform FindDirectChild(Transform parent, string name) { //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Expected O, but got Unknown foreach (Transform item in parent) { Transform val = item; if (((Object)val).name == name) { return val; } } return null; } private static Transform FindDeepChild(Transform parent, string name) { //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Expected O, but got Unknown if (!Object.op_Implicit((Object)(object)parent)) { return null; } foreach (Transform item in parent) { Transform val = item; if (((Object)val).name == name) { return val; } Transform val2 = FindDeepChild(val, name); if (Object.op_Implicit((Object)(object)val2)) { return val2; } } return null; } } [BepInPlugin("local.howtofish.moreknives", "How to Fish - More Knives", "0.1.0")] public sealed class MoreKnivesPlugin : BaseUnityPlugin { public const string PluginGuid = "local.howtofish.moreknives"; public const string PluginName = "How to Fish - More Knives"; public const string PluginVersion = "0.1.0"; internal static ManualLogSource Log; private Harmony _harmony; private void Awake() { //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Expected O, but got Unknown Log = ((BaseUnityPlugin)this).Logger; try { KnifeAssets.WarmUp(); _harmony = new Harmony("local.howtofish.moreknives"); _harmony.PatchAll(typeof(MoreKnivesPlugin).Assembly); ((BaseUnityPlugin)this).Logger.LogInfo((object)("Loaded " + KnifeCatalog.Definitions.Count + " knife variants; every knife costs $" + 45 + ".")); if (Environment.GetCommandLineArgs().Any((string argument) => argument == "-moreknives-selftest")) { ((MonoBehaviour)this).StartCoroutine(RunSelfTest()); } } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogError((object)("More Knives failed to initialize: " + ex)); } } private void OnDestroy() { if (_harmony != null) { _harmony.UnpatchSelf(); } } private IEnumerator RunSelfTest() { yield return (object)new WaitForSecondsRealtime(3f); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.AppendLine("How to Fish - More Knives self-test"); stringBuilder.AppendLine("UTC: " + DateTime.UtcNow.ToString("O")); stringBuilder.AppendLine("Game: " + Application.version); stringBuilder.AppendLine("Unity: " + Application.unityVersion); stringBuilder.AppendLine("Plugin: 0.1.0"); bool flag = true; Item val = ((IEnumerable)Resources.LoadAll("Items")).FirstOrDefault((Func)((Item item) => Object.op_Implicit((Object)(object)item) && item.ID == 63)); stringBuilder.AppendLine("Vanilla knife found: " + (Object.op_Implicit((Object)(object)val) ? "yes" : "no")); flag &= Object.op_Implicit((Object)(object)val); if (Object.op_Implicit((Object)(object)val)) { stringBuilder.AppendLine("Vanilla knife cost: $" + val.Cost); flag &= val.Cost == 45; } stringBuilder.AppendLine("Definitions: " + KnifeCatalog.Definitions.Count); flag &= KnifeCatalog.Definitions.Count == 19; foreach (KnifeDefinition definition in KnifeCatalog.Definitions) { KnifeAssetSet knifeAssetSet = KnifeAssets.Get(definition); int num = (Object.op_Implicit((Object)(object)knifeAssetSet.InventoryMesh) ? knifeAssetSet.InventoryMesh.vertexCount : 0); bool flag2 = definition.Price == 45 && num > 0; flag = flag && flag2; stringBuilder.AppendLine(string.Format("{0}: purchase={1} skin={2} price=${3} vertices={4} {5}", definition.DisplayName, definition.PurchaseId, definition.VariantCode, definition.Price, num, flag2 ? "PASS" : "FAIL")); } if (Object.op_Implicit((Object)(object)val)) { Item val2 = null; try { val2 = Object.Instantiate(val); int num2 = 0; foreach (KnifeDefinition definition2 in KnifeCatalog.Definitions) { bool flag3 = KnifeVisualController.Ensure(val2, definition2).Definition == definition2 && ((Component)val2).GetComponentsInChildren(true).Any((MeshFilter filter) => Object.op_Implicit((Object)(object)filter) && Object.op_Implicit((Object)(object)filter.sharedMesh) && ((Object)filter.sharedMesh).name.StartsWith("MoreKnives")); if (flag3) { num2++; } flag = flag && flag3; } stringBuilder.AppendLine("World models attached to vanilla knife hierarchy: " + num2 + "/19"); flag = flag && num2 == 19; } catch (Exception ex) { flag = false; stringBuilder.AppendLine("World model test exception: " + ex); } finally { if (Object.op_Implicit((Object)(object)val2)) { Collider val3 = ReflectionUtil.Get(val2, "_pickUpCollider"); Collider[] array = ReflectionUtil.Get(val2, "_worldColliders"); ItemManager.Remove(val2, val3, array); Object.Destroy((Object)(object)((Component)val2).gameObject); } } } stringBuilder.AppendLine("RESULT: " + (flag ? "PASS" : "FAIL")); string text = Path.Combine(Paths.BepInExRootPath, "more-knives-selftest.txt"); File.WriteAllText(text, stringBuilder.ToString()); ((BaseUnityPlugin)this).Logger.LogInfo((object)("More Knives self-test " + (flag ? "passed" : "failed") + ": " + text)); Application.Quit((!flag) ? 1 : 0); } } internal sealed class ShopSwapState { public Item Item; public byte OriginalId; public int OriginalCost; } internal sealed class PurchaseState { public KnifeDefinition Definition; public Item PreviousHeldItem; } internal static class ShopSwap { public static void Begin(ItemPurchasable purchasable, out ShopSwapState state) { state = null; KnifeShopMarker component = ((Component)purchasable).GetComponent(); if (Object.op_Implicit((Object)(object)component) && component.Definition != null) { Item val = ReflectionUtil.Get(purchasable, "_itemToPurchase"); if (Object.op_Implicit((Object)(object)val)) { state = new ShopSwapState { Item = val, OriginalId = val.ID, OriginalCost = val.Cost }; ReflectionUtil.Set(val, "_id", component.Definition.PurchaseId); ReflectionUtil.Set(val, "_cost", component.Definition.Price); } } } public static void End(ShopSwapState state) { if (state != null && Object.op_Implicit((Object)(object)state.Item)) { ReflectionUtil.Set(state.Item, "_id", state.OriginalId); ReflectionUtil.Set(state.Item, "_cost", state.OriginalCost); } } } [HarmonyPatch(typeof(ItemPurchasable), "Awake")] internal static class ItemPurchasableAwakePatch { private static void Postfix(ItemPurchasable __instance) { KnifeShopInstaller.TryInstall(__instance); } } [HarmonyPatch(typeof(ItemPurchasable), "Hover")] internal static class ItemPurchasableHoverPatch { private static void Prefix(ItemPurchasable __instance, out ShopSwapState __state) { ShopSwap.Begin(__instance, out __state); } private static void Postfix(ShopSwapState __state) { ShopSwap.End(__state); } } [HarmonyPatch(typeof(ItemPurchasable), "Interact")] internal static class ItemPurchasableInteractPatch { private static void Prefix(ItemPurchasable __instance, out ShopSwapState __state) { ShopSwap.Begin(__instance, out __state); } private static void Postfix(ShopSwapState __state) { ShopSwap.End(__state); } } [HarmonyPatch(typeof(PlayerHands), "PrepareForPurchasedItem")] internal static class PlayerHandsPurchasePatch { private static void Prefix(ref byte itemID) { if (KnifeCatalog.TryGetByPurchaseId(itemID, out var _)) { itemID = 63; } } } [HarmonyPatch(typeof(Server), "RpcLogic___BuyItem___4197152275")] internal static class ServerBuyItemPatch { private static void Prefix(ref byte __0, Player __1, out PurchaseState __state) { __state = null; if (KnifeCatalog.TryGetByPurchaseId(__0, out var definition)) { __state = new PurchaseState { Definition = definition, PreviousHeldItem = (Object.op_Implicit((Object)(object)__1) ? __1.Holding.HeldItem : null) }; __0 = 63; } } private static void Postfix(Player __1, PurchaseState __state) { if (__state != null && Object.op_Implicit((Object)(object)__1)) { Item heldItem = __1.Holding.HeldItem; if (Object.op_Implicit((Object)(object)heldItem) && !((Object)(object)heldItem == (Object)(object)__state.PreviousHeldItem) && heldItem.ID == 63) { heldItem._curSkin.Value = __state.Definition.VariantCode; KnifeVisualController.Ensure(heldItem, __state.Definition); MoreKnivesPlugin.Log.LogInfo((object)(((Object)__1).name + " bought " + __state.Definition.DisplayName + " for $" + __state.Definition.Price)); } } } } [HarmonyPatch(typeof(Item), "GetName")] internal static class ItemNamePatch { private static void Postfix(Item __instance, ref string __result) { if (KnifeCatalog.TryGet(__instance, out var definition)) { __result = definition.DisplayName; } } } [HarmonyPatch(/*Could not decode attribute arguments.*/)] internal static class ItemMeshPatch { private static void Postfix(Item __instance, ref Mesh __result) { if (KnifeCatalog.TryGetByVariantCode(__instance.CurSkin, out var definition)) { __result = KnifeAssets.Get(definition).InventoryMesh; } } } [HarmonyPatch(/*Could not decode attribute arguments.*/)] internal static class ItemInventoryScalePatch { private static void Postfix(Item __instance, ref float __result) { if (KnifeCatalog.TryGetByVariantCode(__instance.CurSkin, out var _)) { __result = 0.58f; } } } [HarmonyPatch(typeof(InventorySlot), "ApplySkin")] internal static class InventorySlotSkinPatch { private static bool Prefix(InventorySlot __instance, Item item) { if (!KnifeCatalog.TryGetByVariantCode((byte)(Object.op_Implicit((Object)(object)item) ? item.CurSkin : 0), out var definition)) { return true; } Renderer val = ReflectionUtil.Get(__instance, "_renderer"); if (Object.op_Implicit((Object)(object)val)) { val.sharedMaterial = KnifeAssets.Get(definition).BladeMaterial; } return false; } } [HarmonyPatch(typeof(Item), "OnCurSkinChange")] internal static class ItemCurSkinPatch { private static void Postfix(Item __instance) { KnifeVisualController.ApplyOrClear(__instance); } } [HarmonyPatch(typeof(Item), "OnStartClient")] internal static class ItemStartClientPatch { private static void Postfix(Item __instance) { KnifeVisualController.ApplyOrClear(__instance); } } [HarmonyPatch(typeof(Tool), "LoadFromSave")] internal static class ToolLoadFromSavePatch { private static void Postfix(Tool __instance) { KnifeVisualController.ApplyOrClear((Item)(object)__instance); } } [HarmonyPatch(typeof(Tool), "PlayInspectAnim")] internal static class ToolInspectPatch { private static void Postfix(Tool __instance) { if (Object.op_Implicit((Object)(object)((Item)__instance).Holder) && KnifeCatalog.TryGetByVariantCode(((Item)__instance).CurSkin, out var definition)) { KnifeVisualController.Ensure((Item)(object)__instance, definition).PlayInspect(); } } } [HarmonyPatch(typeof(Melee), "StartAttacking")] internal static class MeleeAttackPatch { private static void Prefix(Melee __instance) { KnifeVisualController component = ((Component)__instance).GetComponent(); if (Object.op_Implicit((Object)(object)component)) { component.CancelInspect(); } } } [HarmonyPatch(typeof(Tool), "OnDrop")] internal static class ToolDropPatch { private static void Postfix(Tool __instance) { KnifeVisualController component = ((Component)__instance).GetComponent(); if (Object.op_Implicit((Object)(object)component)) { component.CancelInspect(); } } } [HarmonyPatch(typeof(PlayerHolding), "ChangeSkinInput")] internal static class PlayerHoldingSkinInputPatch { private static bool Prefix(PlayerHolding __instance) { Item val = ReflectionUtil.Get(__instance, "_heldItem"); KnifeDefinition definition; if (Object.op_Implicit((Object)(object)val)) { return !KnifeCatalog.TryGetByVariantCode(val.CurSkin, out definition); } return true; } } internal static class ReflectionUtil { public static FieldInfo FindField(Type type, string name) { Type type2 = type; while (type2 != null) { FieldInfo field = type2.GetField(name, BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (field != null) { return field; } type2 = type2.BaseType; } throw new MissingFieldException(type.FullName, name); } public static T Get(object instance, string name) { return (T)FindField(instance.GetType(), name).GetValue(instance); } public static void Set(object instance, string name, object value) { FindField(instance.GetType(), name).SetValue(instance, value); } }