Decompiled source of wuwapacks v1.0.4
BepInEx/plugins/WuwaResourcePacks/WuwaResourcePacks.dll
Decompiled an hour ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Numerics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Threading; using BepInEx; using BepInEx.Configuration; using BepInEx.Core.Logging.Interpolation; using BepInEx.Logging; using BepInEx.Unity.IL2CPP; using GameData; using Gear; using HarmonyLib; using Il2CppInterop.Runtime.Attributes; using Il2CppInterop.Runtime.Injection; using Il2CppInterop.Runtime.InteropTypes; using Il2CppInterop.Runtime.InteropTypes.Arrays; using ItemSetup; using Microsoft.CodeAnalysis; using Player; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")] [assembly: AssemblyCompany("WuwaResourcePacks")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.4.0")] [assembly: AssemblyInformationalVersion("1.0.4")] [assembly: AssemblyProduct("WuwaResourcePacks")] [assembly: AssemblyTitle("WuwaResourcePacks")] [assembly: InternalsVisibleTo("WuwaQa")] [assembly: AssemblyVersion("1.0.4.0")] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class NullableAttribute : Attribute { public readonly byte[] NullableFlags; public NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] internal sealed class NullableContextAttribute : Attribute { public readonly byte Flag; public NullableContextAttribute(byte P_0) { Flag = P_0; } } } namespace WuwaResourcePacks { internal static class FpGear { internal const string Supports = "_SupportsFPSRendering"; internal const string Enable = "_EnableFPSRendering"; internal const string Keyword = "ENABLE_FPS_RENDERING"; private static readonly int SupportsId = Shader.PropertyToID("_SupportsFPSRendering"); private static readonly int EnableId = Shader.PropertyToID("_EnableFPSRendering"); internal static int Frames; internal static int Reads; internal static int Writes; private const int RecheckEvery = 300; internal static void Sync(PackVisual.Slot slot, Plugin plugin, PackKind kind) { if (slot == null) { return; } MeshRenderer stock = slot.Stock; if ((Object)(object)stock == (Object)null || slot.Materials == null || slot.Materials.Length == 0) { return; } Frames++; Material sharedMaterial = ((Renderer)stock).sharedMaterial; Reads++; if ((Object)(object)sharedMaterial == (Object)null) { return; } int instanceID = ((Object)sharedMaterial).GetInstanceID(); bool flag = instanceID != slot.SourceId || Frames % 300 == 0; float num; bool flag2; if (flag) { slot.SourceId = instanceID; slot.Source = sharedMaterial; slot.Supports = (sharedMaterial.HasProperty(SupportsId) ? 1 : 0); slot.HasEnable = sharedMaterial.HasProperty(EnableId); slot.StockSlots = SlotCount(stock); slot.Enable = float.NaN; slot.Keyword = false; if (slot.Supports == 0) { plugin?.Once($"fpgear/{kind}/none/{instanceID}", $"PACK_FPGEAR kind={kind} stock={((Object)sharedMaterial).name} instance={instanceID} supports=0 stock_slots={slot.StockSlots} " + "note=this stock material cannot receive the game's first-person gear state"); return; } num = (slot.HasEnable ? sharedMaterial.GetFloat(EnableId) : float.NaN); flag2 = sharedMaterial.IsKeywordEnabled("ENABLE_FPS_RENDERING"); } else { if (slot.Supports == 0) { return; } num = (slot.HasEnable ? sharedMaterial.GetFloat(EnableId) : float.NaN); flag2 = sharedMaterial.IsKeywordEnabled("ENABLE_FPS_RENDERING"); if (Same(num, slot.Enable) && flag2 == slot.Keyword) { return; } } Il2CppReferenceArray<Material> val = ((slot.StockSlots > 0) ? ((Renderer)stock).sharedMaterials : null); int num2 = 0; int num3 = 0; for (int i = 0; i < slot.Materials.Length; i++) { Material val2 = slot.Materials[i]; if ((Object)(object)val2 == (Object)null) { continue; } int num4 = ((slot.StockSlots == slot.Materials.Length) ? i : 0); Material val3 = sharedMaterial; if (val != null && ((Il2CppArrayBase<Material>)(object)val).Length > 0) { Material val4 = ((Il2CppArrayBase<Material>)(object)val)[(num4 < ((Il2CppArrayBase<Material>)(object)val).Length) ? num4 : 0]; if ((Object)(object)val4 != (Object)null) { val3 = val4; } } if (slot.StockSlots == slot.Materials.Length) { num3++; } float num5 = (val3.HasProperty(EnableId) ? val3.GetFloat(EnableId) : num); bool flag3 = val3.IsKeywordEnabled("ENABLE_FPS_RENDERING"); if (val2.HasProperty(EnableId) && !Same(val2.GetFloat(EnableId), num5)) { val2.SetFloat(EnableId, num5); num2++; } if (val2.IsKeywordEnabled("ENABLE_FPS_RENDERING") != flag3) { if (flag3) { val2.EnableKeyword("ENABLE_FPS_RENDERING"); } else { val2.DisableKeyword("ENABLE_FPS_RENDERING"); } num2++; } } slot.Enable = num; slot.Keyword = flag2; slot.Writes += num2; Writes += num2; string value = (float.IsFinite(num) ? num.ToString("F0") : "na"); plugin?.Once($"fpgear/{kind}/{instanceID}/{num}/{flag2}/{slot.StockSlots}/{slot.Materials.Length}", $"PACK_FPGEAR kind={kind} stock={((Object)sharedMaterial).name} instance={instanceID} replaced={flag} supports={slot.Supports == 1} enable={value} keyword={flag2} stock_slots={slot.StockSlots} art_slots={slot.Materials.Length} matched={num3} synced={num2} writes_total={slot.Writes}"); } private static int SlotCount(MeshRenderer renderer) { return ((Il2CppArrayBase<Material>)(object)((Renderer)renderer).sharedMaterials)?.Length ?? 0; } private static bool Same(float a, float b) { if (a != b) { if (float.IsNaN(a)) { return float.IsNaN(b); } return false; } return true; } internal static void Reset() { Frames = (Reads = (Writes = 0)); } } internal static class GhostCompat { private sealed class Lease { internal MeshFilter Filter; internal MeshRenderer Renderer; internal Mesh Stock; internal Material[] Tinted; internal bool Filled; } internal const string ModId = "HawChow.DropItemEverywhere"; private const string PreviewType = "HawChow.DropItemEverywhere.DropPreview"; private const BindingFlags Flags = BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic; private static bool failed; private const int MaxLeases = 32; private static readonly List<Lease> live = new List<Lease>(); internal static bool Installed { get; private set; } internal static void Install(Harmony hooks, Plugin plugin) { //IL_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_00b5: Expected O, but got Unknown Type type = Resolve(); if (type == null) { plugin.Once("ghost/absent", "PACK_GHOST idle: DropItemEverywhere is not loaded"); return; } MethodInfo method = type.GetMethod("ApplyGhostLook", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[1] { typeof(GameObject) }, null); if (method == null || method.ReturnType != typeof(void) || method.GetParameters()[0].ParameterType != typeof(GameObject)) { plugin.Once("ghost/noanchor", "PACK_GHOST idle: DropPreview.ApplyGhostLook(GameObject) is not the expected signature", warning: true); return; } try { hooks.Patch((MethodBase)method, (HarmonyMethod)null, new HarmonyMethod(typeof(GhostCompat), "AfterLook", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); Installed = true; plugin.Once("ghost/hook", "PACK_GHOST hook=DropPreview.ApplyGhostLook(GameObject) postfix"); } catch (Exception ex) { plugin.Once("ghost/hook/fail", "PACK_GHOST hook failed: " + ex.Message, warning: true); } } private static Type Resolve() { try { Type type = Type.GetType("HawChow.DropItemEverywhere.DropPreview, HawChow.DropItemEverywhere", throwOnError: false); if (type != null) { return type; } } catch { } Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); foreach (Assembly assembly in assemblies) { try { Type type2 = assembly.GetType("HawChow.DropItemEverywhere.DropPreview", throwOnError: false); if (type2 != null) { return type2; } } catch { } } return null; } internal static void Reset() { foreach (Lease item in live) { Release(item); } live.Clear(); failed = false; } private static void AfterLook(GameObject __0) { Plugin instance = Plugin.Instance; if (instance == null || (Object)(object)__0 == (Object)null) { return; } try { Reskin(instance, __0); } catch (Exception e) { Fail(e); } } private static void Reskin(Plugin plugin, GameObject root) { //IL_0094: Unknown result type (might be due to invalid IL or missing references) //IL_00a0: 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_00bd: Unknown result type (might be due to invalid IL or missing references) Prune(); int num = 0; foreach (MeshFilter componentsInChild in root.GetComponentsInChildren<MeshFilter>(true)) { if ((Object)(object)componentsInChild == (Object)null) { continue; } Mesh sharedMesh = componentsInChild.sharedMesh; MeshRenderer component = ((Component)componentsInChild).GetComponent<MeshRenderer>(); if ((Object)(object)sharedMesh == (Object)null || (Object)(object)component == (Object)null) { continue; } PackKind packKind = PickupKind(((Object)sharedMesh).name); if (packKind < PackKind.Ammo) { continue; } PackArt packArt = plugin.Art(packKind); if (packArt == null) { continue; } if (!packArt.Recall((ItemMode)2, ((Object)sharedMesh).name, out var mesh, out var _)) { mesh = packArt.Fitted(sharedMesh, PackVisual.FitFor(packKind, sharedMesh.bounds, packArt.Mesh.bounds, root.transform, ((Component)componentsInChild).transform, null, fp: false)); } Il2CppReferenceArray<Material> sharedMaterials = ((Renderer)component).sharedMaterials; if (sharedMaterials == null || ((Il2CppArrayBase<Material>)(object)sharedMaterials).Length == 0 || (Object)(object)((Il2CppArrayBase<Material>)(object)sharedMaterials)[0] == (Object)null) { plugin.Once($"ghost/{packKind}/bare", $"PACK_GHOST skip kind={packKind}: the clone has no tinted material to keep", warning: true); continue; } Lease lease = new Lease { Filter = componentsInChild, Renderer = component, Stock = sharedMesh, Tinted = Il2CppArrayBase<Material>.op_Implicit((Il2CppArrayBase<Material>)(object)sharedMaterials) }; componentsInChild.sharedMesh = mesh; int subMeshCount = mesh.subMeshCount; if (subMeshCount != ((Il2CppArrayBase<Material>)(object)sharedMaterials).Length) { Material[] array = (Material[])(object)new Material[subMeshCount]; for (int i = 0; i < subMeshCount; i++) { array[i] = ((Il2CppArrayBase<Material>)(object)sharedMaterials)[Math.Min(i, ((Il2CppArrayBase<Material>)(object)sharedMaterials).Length - 1)]; } ((Renderer)component).sharedMaterials = Il2CppReferenceArray<Material>.op_Implicit(array); lease.Filled = true; } live.Add(lease); num++; plugin.Once($"ghost/{packKind}", $"PACK_GHOST kind={packKind} node={((Object)component).name} stock={((Object)sharedMesh).name} mesh={((Object)mesh).name} slots={subMeshCount} tinted={((Il2CppArrayBase<Material>)(object)sharedMaterials).Length}"); } if (num > 0) { Trim(); } } private static PackKind PickupKind(string name) { return name.Trim() switch { "g_ammopack_thirdperson" => PackKind.Ammo, "g_medipack_thirdperson" => PackKind.Medical, "AmmoPack_Tool_Lod1" => PackKind.Tool, "g_DisinfectonPack_LOD1" => PackKind.Disinfection, _ => (PackKind)(-1), }; } private static void Prune() { for (int num = live.Count - 1; num >= 0; num--) { if ((Object)(object)live[num].Filter == (Object)null) { live.RemoveAt(num); } } } private static void Trim() { while (live.Count > 32) { Lease lease = live[0]; live.RemoveAt(0); Release(lease); } } private static void Release(Lease lease) { if ((Object)(object)lease.Filter != (Object)null && (Object)(object)lease.Filter.sharedMesh != (Object)(object)lease.Stock) { lease.Filter.sharedMesh = lease.Stock; } if (lease.Filled && (Object)(object)lease.Renderer != (Object)null && lease.Tinted != null) { ((Renderer)lease.Renderer).sharedMaterials = Il2CppReferenceArray<Material>.op_Implicit(lease.Tinted); } } private static void Fail(Exception e) { if (!failed) { failed = true; Plugin.Instance?.Once("ghost/fail", "PACK_GHOST skipped, original ghost kept: " + e.Message, warning: true); } } } internal sealed class PackArt { private readonly Texture2D[] images; private readonly Dictionary<(string, PackFit), Mesh> fitted = new Dictionary<(string, PackFit), Mesh>(); private readonly Dictionary<(ItemMode, string), (Mesh Mesh, PackFit Fit)> recent = new Dictionary<(ItemMode, string), (Mesh, PackFit)>(); private Material[] world; internal Mesh Mesh { get; } private PackArt(Mesh mesh, Texture2D[] textures) { Mesh = mesh; images = textures; } internal Mesh Fitted(Mesh stock, PackFit fit) { //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_007f: 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_009f: 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_00bc: 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) //IL_00c6: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: Unknown result type (might be due to invalid IL or missing references) //IL_00ce: Unknown result type (might be due to invalid IL or missing references) //IL_00d3: 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_00ed: 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_0117: Unknown result type (might be due to invalid IL or missing references) //IL_011e: Unknown result type (might be due to invalid IL or missing references) //IL_0123: Unknown result type (might be due to invalid IL or missing references) //IL_0128: Unknown result type (might be due to invalid IL or missing references) //IL_012b: Unknown result type (might be due to invalid IL or missing references) //IL_0130: 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_013d: 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_014c: Unknown result type (might be due to invalid IL or missing references) //IL_0154: Unknown result type (might be due to invalid IL or missing references) //IL_015b: Unknown result type (might be due to invalid IL or missing references) //IL_0163: Unknown result type (might be due to invalid IL or missing references) //IL_0168: Unknown result type (might be due to invalid IL or missing references) //IL_0171: Unknown result type (might be due to invalid IL or missing references) //IL_0177: Unknown result type (might be due to invalid IL or missing references) //IL_017c: 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) (string, PackFit) key = (((Object)stock).name, fit); if (fitted.TryGetValue(key, out var value) && (Object)(object)value != (Object)null) { return value; } if (fitted.Count >= 32) { throw new InvalidOperationException("Fit cache is full; kept vanilla"); } Mesh val = Object.Instantiate<Mesh>(Mesh); try { ((Object)val).name = ((Object)Mesh).name + "/" + ((Object)stock).name; Bounds bounds = Mesh.bounds; Vector3 center = ((Bounds)(ref bounds)).center; Vector3[] array = Il2CppArrayBase<Vector3>.op_Implicit((Il2CppArrayBase<Vector3>)(object)val.vertices); Vector3[] array2 = Il2CppArrayBase<Vector3>.op_Implicit((Il2CppArrayBase<Vector3>)(object)val.normals); Matrix4x4 m = Matrix4x4.TRS(Vector3.zero, fit.Rotation, new Vector3(fit.Scale, fit.Scale, fit.Scale)); Matrix4x4 m2 = Matrix4x4.Rotate(fit.Rotation); for (int i = 0; i < array.Length; i++) { Vector3 val2 = PackSurface.Point(m, new Vector3(array[i].x - center.x, array[i].y - center.y, array[i].z - center.z)); Vector3 center2 = fit.Center; array[i] = new Vector3(center2.x + val2.x, center2.y + val2.y, center2.z + val2.z); array2[i] = PackSurface.Point(m2, array2[i]); } val.vertices = Il2CppStructArray<Vector3>.op_Implicit(array); val.normals = Il2CppStructArray<Vector3>.op_Implicit(array2); val.RecalculateBounds(); val.UploadMeshData(true); fitted[key] = val; return val; } catch { Object.Destroy((Object)(object)val); throw; } } internal void Remember(ItemMode mode, Mesh stock, Mesh fitted, PackFit fit) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) recent[(mode, ((Object)stock).name)] = (fitted, fit); } internal bool Recall(ItemMode mode, string stock, out Mesh mesh, out PackFit fit) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) if (recent.TryGetValue((mode, stock), out (Mesh, PackFit) value) && (Object)(object)value.Item1 != (Object)null) { (mesh, fit) = value; return true; } mesh = null; fit = default(PackFit); return false; } internal static IEnumerator<string> Prepare(PackKind kind, Action<PackArt> publish) { using Stream source = typeof(PackArt).Assembly.GetManifestResourceStream($"art.{kind}.wpk") ?? throw new InvalidDataException($"Missing embedded model {kind}"); using BinaryReader r = new BinaryReader(source); if (r.ReadUInt32() != 827019351) { throw new InvalidDataException("Bad WPK signature"); } int n = r.ReadInt32(); int count = r.ReadInt32(); int groups = r.ReadInt32(); bool flag = ((n < 3 || n > 65000) ? true : false); bool flag2 = flag; if (!flag2) { bool flag3 = ((count < 3 || count > 240000) ? true : false); flag2 = flag3; } bool flag4 = flag2; if (!flag4) { bool flag3 = ((groups < 1 || groups > 4) ? true : false); flag4 = flag3; } if (flag4) { throw new InvalidDataException("Unsupported WPK mesh size"); } Texture2D array = (Vector3[])(object)new Vector3[n]; Vector3[] array2 = (Vector3[])(object)new Vector3[n]; Vector2[] array3 = (Vector2[])(object)new Vector2[n]; for (int i = 0; i < n; i++) { array[i] = new Vector3(Number(r), Number(r), Number(r)); array2[i] = new Vector3(Number(r), Number(r), Number(r)); array3[i] = new Vector2(Number(r), Number(r)); } Texture2D[] textures = (Texture2D[])(object)new Texture2D[groups]; Mesh mesh = null; bool complete = false; try { mesh = new Mesh { name = $"Wuwa/{kind}", hideFlags = (HideFlags)32 }; mesh.vertices = Il2CppStructArray<Vector3>.op_Implicit(array); mesh.normals = Il2CppStructArray<Vector3>.op_Implicit(array2); mesh.uv = Il2CppStructArray<Vector2>.op_Implicit(array3); mesh.subMeshCount = groups; yield return "vertices"; for (int k = 0; k < groups; k++) { int num = r.ReadInt32(); int png = r.ReadInt32(); flag4 = num < 3 || num > count || num % 3 != 0; if (!flag4) { flag2 = ((png < 33 || png > 16000000) ? true : false); flag4 = flag2; } if (flag4 || source.Length - source.Position < (long)num * 4L + png) { throw new InvalidDataException("Bad WPK section"); } count -= num; int[] array4 = new int[num]; for (int j = 0; j < num; j++) { array4[j] = r.ReadInt32(); if ((uint)array4[j] >= n) { throw new InvalidDataException("Bad WPK vertex index"); } } mesh.SetTriangles(new Il2CppStructArray<int>(array4), k, false, 0); yield return "indices"; byte[] array5 = r.ReadBytes(png); if (array5.Length != png || array5[0] != 137 || array5[1] != 80 || array5[2] != 78 || array5[3] != 71) { throw new InvalidDataException("Bad WPK texture"); } int num2 = k; Texture2D val = new Texture2D(2, 2, (TextureFormat)4, true) { name = $"Wuwa/{kind}/{k}", wrapMode = (TextureWrapMode)1, hideFlags = (HideFlags)32 }; Texture2D val2 = val; textures[num2] = val; if (!ImageConversion.LoadImage(val2, Il2CppStructArray<byte>.op_Implicit(array5), true)) { throw new InvalidDataException("PNG decode failed"); } yield return "texture"; } mesh.RecalculateBounds(); if (count != 0 || source.Position != source.Length) { throw new InvalidDataException("Bad WPK length"); } mesh.UploadMeshData(false); publish(new PackArt(mesh, textures)); complete = true; } finally { if (!complete) { if ((Object)(object)mesh != (Object)null) { Object.Destroy((Object)(object)mesh); } Texture2D[] array6 = textures; for (int l = 0; l < array6.Length; l++) { array = array6[l]; if ((Object)(object)array != (Object)null) { Object.Destroy((Object)(object)array); } } } } } internal Material[] Materials(Material source, bool firstPerson) { //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Expected O, but got Unknown //IL_0083: Expected O, but got Unknown //IL_00f3: Unknown result type (might be due to invalid IL or missing references) //IL_00fe: Unknown result type (might be due to invalid IL or missing references) //IL_0141: Unknown result type (might be due to invalid IL or missing references) if (!firstPerson && world != null) { return world; } Shader val = ((!firstPerson) ? Shader.Find("Standard") : (((Object)(object)source != (Object)null) ? source.shader : null)); if ((Object)(object)val == (Object)null || !val.isSupported || (firstPerson && !source.HasProperty("_MainTex"))) { return null; } Material[] array = (Material[])(object)new Material[images.Length]; try { for (int i = 0; i < array.Length; i++) { int num = i; Material val2 = (firstPerson ? new Material(source) : new Material(val)); Material val3 = val2; array[num] = val2; Material val4 = val3; ((Object)val4).name = $"{((Object)Mesh).name}/{(firstPerson ? "fp" : "world")}/{i}"; val4.mainTexture = (Texture)(object)images[i]; val4.mainTextureOffset = Vector2.zero; val4.mainTextureScale = Vector2.one; string[] array2 = new string[3] { "_Color", "_BaseColor", "_TintColor" }; foreach (string text in array2) { if (val4.HasProperty(text)) { val4.SetColor(text, Color.white); } } array2 = new string[4] { "_BumpMap", "_MetallicGlossMap", "_EmissiveMap", "_OcclusionMap" }; foreach (string text2 in array2) { if (val4.HasProperty(text2)) { val4.SetTexture(text2, (Texture)null); } } array2 = new string[4] { "_Metallic", "_Glossiness", "_Smoothness", "_EnableEmissive" }; foreach (string text3 in array2) { if (val4.HasProperty(text3)) { val4.SetFloat(text3, 0f); } } val4.DisableKeyword("ENABLE_EMISSIVE"); val4.DisableKeyword("_EMISSION"); val4.DisableKeyword("_NORMALMAP"); if (val4.HasProperty("_Cutoff")) { val4.SetFloat("_Cutoff", 0.35f); } if (!firstPerson) { val4.SetFloat("_Mode", 1f); val4.EnableKeyword("_ALPHATEST_ON"); val4.SetOverrideTag("RenderType", "TransparentCutout"); val4.renderQueue = 2450; ((Object)val4).hideFlags = (HideFlags)32; } } if (!firstPerson) { world = array; } return array; } catch { DestroyMaterials(array); throw; } } internal static void DestroyMaterials(Material[] mats) { if (mats == null) { return; } foreach (Material val in mats) { if ((Object)(object)val != (Object)null) { Object.Destroy((Object)(object)val); } } } internal void Dispose() { DestroyMaterials(world); Texture2D[] array = images; foreach (Texture2D val in array) { if ((Object)(object)val != (Object)null) { Object.Destroy((Object)(object)val); } } foreach (Mesh value in fitted.Values) { if ((Object)(object)value != (Object)null) { Object.Destroy((Object)(object)value); } } fitted.Clear(); recent.Clear(); if ((Object)(object)Mesh != (Object)null) { Object.Destroy((Object)(object)Mesh); } } private static float Number(BinaryReader r) { float num = r.ReadSingle(); if (!float.IsFinite(num)) { throw new InvalidDataException("Non-finite WPK value"); } return num; } } internal readonly struct PackFit { private struct Cand { internal Vector3 Center; internal float Near; internal float Other; internal float Rest; internal float Authored; internal float SignedL; internal float SignedR; internal int Hand; internal int Mode; internal bool Valid; } internal readonly Vector3 Center; internal readonly Quaternion Rotation; internal readonly float Scale; internal readonly float Overflow; internal readonly float GripSurface; internal readonly float Support; internal readonly float Other; internal readonly float Near; internal readonly float StockNear; internal readonly float Rest; internal readonly float Authored; internal readonly float Camera; internal readonly int Hand; internal readonly int Adjust; internal readonly Vector3 Shift; internal const float PickupGrowth = 1.225f; internal const float WorldGrowth = 1.08f; internal const float AxisCeiling = 1.225f; internal const float MaxAuthored = 0.05f; internal const float ContactFloor = 0.03f; internal const float ContactMargin = 0.01f; internal const float NoPenetration = 0.01f; private static readonly float[] CorrectionSteps = new float[3] { 0.03f, 0.06f, 0.09f }; internal const float CorrectionReach = 0.1f; internal const float CameraBudget = 0.295f; private const float Reach = 0.45f; internal PackFit(Vector3 center, Quaternion rotation, float scale, float overflow, float gripSurface, float support, float other, float near, float stockNear, float rest, float authored, float camera, int hand, int adjust, Vector3 shift) { //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_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_006e: 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) Center = center; Rotation = rotation; Scale = scale; Overflow = overflow; GripSurface = gripSurface; Support = support; Other = other; Near = near; StockNear = stockNear; Rest = rest; Authored = authored; Camera = camera; Hand = hand; Adjust = adjust; Shift = shift; } private static PackFit Report(Vector3 center, Quaternion rotation, float scale, float overflow, float gripSurface) { //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_002b: Unknown result type (might be due to invalid IL or missing references) return new PackFit(center, rotation, scale, overflow, gripSurface, -1f, -1f, -1f, -1f, -1f, -1f, -1f, -1, 0, Vector3.zero); } internal static PackFit MeasureFirstPerson(Bounds stock, Bounds art, Vector3 up, Vector3 facing, Vector3? left, Vector3? right, Mesh artMesh, Mesh stockMesh, Matrix4x4 stockToNode, float target, Vector3 host = default(Vector3), Vector3? gripPoint = null) { //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_0003: 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_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_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) //IL_001e: 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_0028: 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_0036: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_0056: 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_0062: Unknown result type (might be due to invalid IL or missing references) //IL_00aa: Unknown result type (might be due to invalid IL or missing references) //IL_00ad: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: Unknown result type (might be due to invalid IL or missing references) //IL_00cb: 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_00d0: 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_00d4: 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_00f1: Unknown result type (might be due to invalid IL or missing references) //IL_010e: 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_011d: Unknown result type (might be due to invalid IL or missing references) //IL_0124: Unknown result type (might be due to invalid IL or missing references) //IL_0131: Unknown result type (might be due to invalid IL or missing references) //IL_0138: Unknown result type (might be due to invalid IL or missing references) //IL_0146: Unknown result type (might be due to invalid IL or missing references) //IL_014d: 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_01bf: 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_01d5: Unknown result type (might be due to invalid IL or missing references) //IL_01da: Unknown result type (might be due to invalid IL or missing references) //IL_01ad: Unknown result type (might be due to invalid IL or missing references) //IL_01a4: Unknown result type (might be due to invalid IL or missing references) //IL_0270: Unknown result type (might be due to invalid IL or missing references) //IL_0275: Unknown result type (might be due to invalid IL or missing references) //IL_0277: Unknown result type (might be due to invalid IL or missing references) //IL_027c: 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_0280: Unknown result type (might be due to invalid IL or missing references) //IL_0203: Unknown result type (might be due to invalid IL or missing references) //IL_0226: Unknown result type (might be due to invalid IL or missing references) //IL_02ad: 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_02bb: Unknown result type (might be due to invalid IL or missing references) //IL_02c0: Unknown result type (might be due to invalid IL or missing references) //IL_044b: Unknown result type (might be due to invalid IL or missing references) //IL_044d: Unknown result type (might be due to invalid IL or missing references) //IL_0453: Unknown result type (might be due to invalid IL or missing references) //IL_04b4: Unknown result type (might be due to invalid IL or missing references) //IL_04bb: Unknown result type (might be due to invalid IL or missing references) //IL_0492: Unknown result type (might be due to invalid IL or missing references) //IL_0499: Unknown result type (might be due to invalid IL or missing references) //IL_0330: Unknown result type (might be due to invalid IL or missing references) //IL_0335: Unknown result type (might be due to invalid IL or missing references) //IL_0337: Unknown result type (might be due to invalid IL or missing references) //IL_0323: Unknown result type (might be due to invalid IL or missing references) //IL_0325: Unknown result type (might be due to invalid IL or missing references) //IL_0327: Unknown result type (might be due to invalid IL or missing references) //IL_0752: Unknown result type (might be due to invalid IL or missing references) //IL_0757: Unknown result type (might be due to invalid IL or missing references) //IL_077f: Unknown result type (might be due to invalid IL or missing references) //IL_0784: Unknown result type (might be due to invalid IL or missing references) //IL_0786: Unknown result type (might be due to invalid IL or missing references) //IL_078a: Unknown result type (might be due to invalid IL or missing references) //IL_078f: Unknown result type (might be due to invalid IL or missing references) //IL_0794: Unknown result type (might be due to invalid IL or missing references) //IL_0796: Unknown result type (might be due to invalid IL or missing references) //IL_0798: Unknown result type (might be due to invalid IL or missing references) //IL_079a: Unknown result type (might be due to invalid IL or missing references) //IL_079f: Unknown result type (might be due to invalid IL or missing references) //IL_033c: Unknown result type (might be due to invalid IL or missing references) //IL_033e: Unknown result type (might be due to invalid IL or missing references) //IL_0343: Unknown result type (might be due to invalid IL or missing references) //IL_0838: Unknown result type (might be due to invalid IL or missing references) //IL_083a: Unknown result type (might be due to invalid IL or missing references) //IL_083d: Unknown result type (might be due to invalid IL or missing references) //IL_083e: Unknown result type (might be due to invalid IL or missing references) //IL_085e: Unknown result type (might be due to invalid IL or missing references) //IL_0860: Unknown result type (might be due to invalid IL or missing references) //IL_0862: Unknown result type (might be due to invalid IL or missing references) //IL_07b8: Unknown result type (might be due to invalid IL or missing references) //IL_07bd: Unknown result type (might be due to invalid IL or missing references) //IL_07c7: Unknown result type (might be due to invalid IL or missing references) //IL_07cc: Unknown result type (might be due to invalid IL or missing references) //IL_07d1: Unknown result type (might be due to invalid IL or missing references) //IL_07d3: Unknown result type (might be due to invalid IL or missing references) //IL_0360: 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_0364: 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_036f: 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_0359: Unknown result type (might be due to invalid IL or missing references) //IL_035e: Unknown result type (might be due to invalid IL or missing references) //IL_04ed: Unknown result type (might be due to invalid IL or missing references) //IL_050e: Unknown result type (might be due to invalid IL or missing references) //IL_04f6: Unknown result type (might be due to invalid IL or missing references) //IL_04fd: Unknown result type (might be due to invalid IL or missing references) //IL_0502: Unknown result type (might be due to invalid IL or missing references) //IL_0507: Unknown result type (might be due to invalid IL or missing references) //IL_0509: Unknown result type (might be due to invalid IL or missing references) //IL_082b: Unknown result type (might be due to invalid IL or missing references) //IL_082f: Unknown result type (might be due to invalid IL or missing references) //IL_080b: Unknown result type (might be due to invalid IL or missing references) //IL_080d: Unknown result type (might be due to invalid IL or missing references) //IL_0819: Unknown result type (might be due to invalid IL or missing references) //IL_081e: Unknown result type (might be due to invalid IL or missing references) //IL_0528: Unknown result type (might be due to invalid IL or missing references) //IL_052a: Unknown result type (might be due to invalid IL or missing references) //IL_052c: Unknown result type (might be due to invalid IL or missing references) //IL_0531: Unknown result type (might be due to invalid IL or missing references) //IL_053b: Unknown result type (might be due to invalid IL or missing references) //IL_053d: Unknown result type (might be due to invalid IL or missing references) //IL_0544: Unknown result type (might be due to invalid IL or missing references) //IL_0546: Unknown result type (might be due to invalid IL or missing references) //IL_054b: Unknown result type (might be due to invalid IL or missing references) //IL_0552: Unknown result type (might be due to invalid IL or missing references) //IL_0554: Unknown result type (might be due to invalid IL or missing references) //IL_055b: Unknown result type (might be due to invalid IL or missing references) //IL_055d: Unknown result type (might be due to invalid IL or missing references) //IL_0562: Unknown result type (might be due to invalid IL or missing references) //IL_0569: Unknown result type (might be due to invalid IL or missing references) //IL_056b: Unknown result type (might be due to invalid IL or missing references) //IL_0572: Unknown result type (might be due to invalid IL or missing references) //IL_0574: Unknown result type (might be due to invalid IL or missing references) //IL_0579: Unknown result type (might be due to invalid IL or missing references) //IL_03b9: Unknown result type (might be due to invalid IL or missing references) //IL_03c0: Unknown result type (might be due to invalid IL or missing references) //IL_03c5: 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_03d5: 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_03e6: Unknown result type (might be due to invalid IL or missing references) //IL_05c4: Unknown result type (might be due to invalid IL or missing references) //IL_05c9: Unknown result type (might be due to invalid IL or missing references) //IL_05cb: Unknown result type (might be due to invalid IL or missing references) //IL_05d0: Unknown result type (might be due to invalid IL or missing references) //IL_05e9: Unknown result type (might be due to invalid IL or missing references) //IL_05f2: Unknown result type (might be due to invalid IL or missing references) //IL_05fc: Unknown result type (might be due to invalid IL or missing references) //IL_0601: Unknown result type (might be due to invalid IL or missing references) //IL_0606: Unknown result type (might be due to invalid IL or missing references) //IL_0618: Unknown result type (might be due to invalid IL or missing references) //IL_0724: Unknown result type (might be due to invalid IL or missing references) //IL_072b: Unknown result type (might be due to invalid IL or missing references) //IL_06f8: Unknown result type (might be due to invalid IL or missing references) //IL_06fd: Unknown result type (might be due to invalid IL or missing references) //IL_0709: Unknown result type (might be due to invalid IL or missing references) //IL_070e: Unknown result type (might be due to invalid IL or missing references) Quaternion rotation = Orient(stock, up, facing); Vector3 val = Sweep(((Bounds)(ref art)).extents, rotation); host = HostScale(host); Vector3 val2 = default(Vector3); ((Vector3)(ref val2))..ctor(val.x * host.x, val.y * host.y, val.z * host.z); float num = 2f * Mathf.Max(val2.x, Mathf.Max(val2.y, val2.z)); if (!(num > 0.0001f) || !(target > 0f)) { throw new InvalidOperationException("Invalid art bounds"); } float num2 = target / num; if (!float.IsFinite(num2)) { throw new InvalidOperationException("Invalid art scale"); } Vector3 val3 = val * num2; Vector3 val4 = ((((Vector3)(ref up)).sqrMagnitude > 1E-06f) ? ((Vector3)(ref up)).normalized : Vector3.up); float num3 = ScaleAlong(val4, host); string why; PackSurface.Entry entry = (((Object)(object)artMesh != (Object)null) ? PackSurface.Oriented(artMesh, rotation, num2, ((Bounds)(ref art)).center, out why) : null); PackSurface.Entry entry2 = (((Object)(object)stockMesh != (Object)null) ? PackSurface.From(stockMesh, stockToNode, out why) : null); float num4 = ((entry != null) ? PackSurface.Low(entry, val4) : (0f - (val3.x * Mathf.Abs(val4.x) + val3.y * Mathf.Abs(val4.y) + val3.z * Mathf.Abs(val4.z)))); bool flag = left.HasValue || right.HasValue; Vector3 point = ((left.HasValue && right.HasValue) ? ((left.Value + right.Value) * 0.5f) : (left.HasValue ? left.Value : (right.HasValue ? right.Value : ((Bounds)(ref stock)).center))); float num5 = -1f; if (entry2 != null && flag) { num5 = float.PositiveInfinity; if (left.HasValue) { num5 = Mathf.Min(num5, Dist(entry2, left.Value) * num3); } if (right.HasValue) { num5 = Mathf.Min(num5, Dist(entry2, right.Value) * num3); } if (!float.IsFinite(num5)) { num5 = -1f; } } float budget = 0.03f; if (num5 >= 0f) { budget = Mathf.Max(0.03f, num5 + 0.01f); } Vector3 val5 = Perp(((Bounds)(ref stock)).center, val4); float num6 = PerpHalf(val3, val4); Vector3? val6 = null; Vector3? val7 = null; if (left.HasValue && right.HasValue) { if (Vector3.Dot(left.Value, val4) <= Vector3.Dot(right.Value, val4)) { val6 = left; val7 = right; } else { val6 = right; val7 = left; } } else { val6 = left ?? right; } Cand c = default(Cand); Vector3 val10; for (int i = 0; i < 2; i++) { Vector3? val8 = ((i == 0) ? val6 : val7); if (!val8.HasValue) { continue; } for (int j = 0; j < 2; j++) { Vector3 val9 = ((j == 1) ? Perp(val8.Value, val4) : Perp(point, val4)) - val5; if (((Vector3)(ref val9)).magnitude > num6) { val9 = ((Vector3)(ref val9)).normalized * num6; } Cand cand = Seat(val5 + val9, val4, num4, val8.Value, entry2, num3, entry, left, right); cand.Mode = j; bool flag2 = Meets(cand, budget); bool flag3 = c.Valid && Meets(c, budget); bool flag4; if (!(flag2 && flag3)) { flag4 = ((flag2 == flag3) ? (Score(cand) < Score(c)) : flag2); } else { val10 = cand.Center - ((Bounds)(ref stock)).center; float sqrMagnitude = ((Vector3)(ref val10)).sqrMagnitude; val10 = c.Center - ((Bounds)(ref stock)).center; flag4 = sqrMagnitude < ((Vector3)(ref val10)).sqrMagnitude; } if (!c.Valid || flag4) { c = cand; } } } if (!c.Valid) { c = Seat(val5, val4, num4, ((Bounds)(ref stock)).center, entry2, num3, entry, left, right); } int num7 = ((c.Mode == 1) ? 2 : 0) + ((!val6.HasValue || c.Hand != ((!left.HasValue || !(val6.Value == left.Value)) ? 1 : 0)) ? 1 : 0); float num8 = CameraDistance(c.Center, gripPoint, host); if (!Feasible(c, budget, num8) && entry != null) { Vector3 val11 = ((val7.HasValue && val6.HasValue) ? Perp(val7.Value - val6.Value, val4) : Vector3.zero); if (((Vector3)(ref val11)).sqrMagnitude > 1E-08f) { ((Vector3)(ref val11)).Normalize(); Vector3 val12 = Vector3.Cross(val4, val11); Vector3[] array = (Vector3[])(object)new Vector3[6] { val4, -val4, val11, -val11, val12, -val12 }; float num9 = num8; for (int k = 0; k < CorrectionSteps.Length; k++) { Cand cand2 = default(Cand); float num10 = float.PositiveInfinity; float num11 = float.NegativeInfinity; float num12 = CorrectionSteps[k]; for (int l = 0; l < array.Length; l++) { if (!(num12 <= 0.1f)) { break; } val10 = Vector3.Scale(array[l], host); float magnitude = ((Vector3)(ref val10)).magnitude; if (!(magnitude > 1E-06f)) { continue; } Vector3 center = c.Center + array[l] * (num12 / magnitude); Cand cand3 = Probe(center, num3, entry, left, right); float num13 = CameraDistance(center, gripPoint, host); if ((!(num9 >= 0f) || !(num13 > num9 + 0.0001f)) && Feasible(cand3, budget, num13)) { float num14 = Clearance(cand3); if (!cand2.Valid || cand3.Near < num10 - 1E-05f || (Mathf.Abs(cand3.Near - num10) <= 1E-05f && num14 > num11)) { cand2 = cand3; num10 = cand3.Near; num11 = num14; } } } if (cand2.Valid) { cand2.Mode = c.Mode; cand2.Hand = c.Hand; cand2.Authored = c.Authored; Vector3? val13 = ((cand2.Hand == 0) ? left : right); if (val13.HasValue) { cand2.Rest = (Vector3.Dot(cand2.Center, val4) + num4 - Vector3.Dot(val13.Value, val4)) * num3; } c = cand2; num8 = CameraDistance(c.Center, gripPoint, host); num7 |= 4; break; } } } } Vector3 val14 = c.Center; float near = c.Near; float other = c.Other; float rest = c.Rest; float authored = c.Authored; Vector3 center2 = c.Center; Vector3 val15 = val14 - ((Bounds)(ref stock)).center; val10 = Vector3.Scale(val15, host); float magnitude2 = ((Vector3)(ref val10)).magnitude; if (magnitude2 > 0.45f) { val14 = ((Bounds)(ref stock)).center + val15 * (0.45f / magnitude2); Cand cand4 = Probe(val14, num3, entry, left, right); near = cand4.Near; other = cand4.Other; Vector3? val16 = ((c.Hand == 0) ? left : right); if (val16.HasValue) { rest = (Vector3.Dot(val14, val4) + num4 - Vector3.Dot(val16.Value, val4)) * num3; } num8 = CameraDistance(val14, gripPoint, host); } return new PackFit(val14, rotation, num2, Overshoot(stock, val3), near, near, other, near, num5, rest, authored, num8, c.Hand, num7, val14 - center2); } private static Cand Seat(Vector3 placed, Vector3 u, float artLow, Vector3 support, PackSurface.Entry body, float su, PackSurface.Entry shape, Vector3? left, Vector3? right) { //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_000e: 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_0018: 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_0027: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_005b: 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_0064: 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_0081: Unknown result type (might be due to invalid IL or missing references) float num = ((body != null) ? StockGap(body, support, u, su) : 0f); Vector3 val = placed + u * (Vector3.Dot(support, u) + num / su - artLow); Cand result = Probe(val, su, shape, left, right); result.Authored = ((body != null && shape != null) ? num : (-1f)); result.Rest = (Vector3.Dot(val, u) + artLow - Vector3.Dot(support, u)) * su; result.Hand = ((!left.HasValue || !(support == left.Value)) ? 1 : 0); return result; } private static Cand Probe(Vector3 center, float su, PackSurface.Entry shape, Vector3? left, Vector3? right) { //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_0064: 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_0096: Unknown result type (might be due to invalid IL or missing references) Cand result = new Cand { Center = center, Valid = true, Near = -1f, Other = -1f, SignedL = -1f, SignedR = -1f }; if (shape == null) { return result; } float num = float.PositiveInfinity; if (left.HasValue) { result.SignedL = Signed(shape, center, left.Value) * su; num = Mathf.Min(num, Mathf.Abs(result.SignedL)); } if (right.HasValue) { result.SignedR = Signed(shape, center, right.Value) * su; num = Mathf.Min(num, Mathf.Abs(result.SignedR)); } if (float.IsFinite(num)) { result.Near = num; } else { result.SignedL = (result.SignedR = -1f); } result.Other = ((!left.HasValue || !right.HasValue) ? ((result.SignedL >= 0f) ? result.SignedL : result.SignedR) : ((Mathf.Abs(result.SignedL) >= Mathf.Abs(result.SignedR)) ? result.SignedL : result.SignedR)); result.Rest = -1f; return result; } private static bool Meets(Cand c, float budget) { if (!(c.Near >= 0f) || c.Near > budget) { return false; } if (c.SignedL < -0.01f || c.SignedR < -0.01f) { return false; } return true; } private static bool Feasible(Cand c, float budget, float camera) { if (Meets(c, budget)) { if (!(camera < 0f)) { return camera <= 0.295f; } return true; } return false; } private static float Clearance(Cand c) { float num = float.PositiveInfinity; if (c.SignedL > -0.5f) { num = Mathf.Min(num, c.SignedL); } if (c.SignedR > -0.5f) { num = Mathf.Min(num, c.SignedR); } if (!float.IsFinite(num)) { return float.NegativeInfinity; } return num; } private static float CameraDistance(Vector3 center, Vector3? gripPoint, Vector3 host) { //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_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_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) if (!gripPoint.HasValue) { return -1f; } Vector3 val = Vector3.Scale(center - gripPoint.Value, host); return ((Vector3)(ref val)).magnitude; } private static float StockGap(PackSurface.Entry body, Vector3 palm, Vector3 u, float su) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) return Mathf.Clamp((PackSurface.Low(body, u) - Vector3.Dot(palm, u)) * su, 0f, 0.05f); } private static float Score(Cand c) { return ((c.SignedL < 0f) ? ((0f - c.SignedL) * 10f) : 0f) + ((c.SignedR < 0f) ? ((0f - c.SignedR) * 10f) : 0f) + ((c.Near < 0f) ? 999f : c.Near); } private static float Dist(PackSurface.Entry shape, Vector3 center, Vector3? palm) { //IL_000f: 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) if (shape != null && palm.HasValue && PackSurface.Nearest(shape, palm.Value - center, out var _, out var _, out var distance)) { return distance; } return -1f; } private static float Dist(PackSurface.Entry shape, Vector3 palm) { //IL_0001: 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) return Dist(shape, Vector3.zero, palm); } private static float Signed(PackSurface.Entry shape, Vector3 center, Vector3 palm) { //IL_0004: 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_0006: 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_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_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) if (shape == null || !PackSurface.Nearest(shape, palm - center, out var onSurface, out var normal, out var distance)) { return -1f; } if (!(Vector3.Dot(palm - center - onSurface, normal) >= 0f)) { return 0f - distance; } return distance; } internal static PackFit Measure(Bounds stock, Bounds art, Vector3 up, Vector3 facing, Vector3? grip, float growth) { //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_0003: 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_000a: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_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_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_0028: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_003b: 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_004e: 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_0089: Unknown result type (might be due to invalid IL or missing references) //IL_008a: Unknown result type (might be due to invalid IL or missing references) //IL_008f: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Unknown result type (might be due to invalid IL or missing references) //IL_0095: Unknown result type (might be due to invalid IL or missing references) //IL_0097: 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_009a: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: 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_00bc: Unknown result type (might be due to invalid IL or missing references) //IL_00c6: 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_00da: 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_0149: Unknown result type (might be due to invalid IL or missing references) //IL_0156: Unknown result type (might be due to invalid IL or missing references) //IL_015f: Unknown result type (might be due to invalid IL or missing references) //IL_016c: Unknown result type (might be due to invalid IL or missing references) //IL_0175: 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_0101: 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_01c9: Unknown result type (might be due to invalid IL or missing references) //IL_01cc: Unknown result type (might be due to invalid IL or missing references) //IL_01d1: Unknown result type (might be due to invalid IL or missing references) //IL_01d5: Unknown result type (might be due to invalid IL or missing references) //IL_01da: Unknown result type (might be due to invalid IL or missing references) //IL_01dc: Unknown result type (might be due to invalid IL or missing references) //IL_01e1: Unknown result type (might be due to invalid IL or missing references) //IL_01e5: Unknown result type (might be due to invalid IL or missing references) //IL_01ea: 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_0268: Unknown result type (might be due to invalid IL or missing references) //IL_026d: Unknown result type (might be due to invalid IL or missing references) //IL_026f: Unknown result type (might be due to invalid IL or missing references) //IL_0276: 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_01fc: Unknown result type (might be due to invalid IL or missing references) //IL_01fe: Unknown result type (might be due to invalid IL or missing references) //IL_0203: Unknown result type (might be due to invalid IL or missing references) //IL_028f: 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_027f: Unknown result type (might be due to invalid IL or missing references) //IL_0286: Unknown result type (might be due to invalid IL or missing references) //IL_02db: Unknown result type (might be due to invalid IL or missing references) //IL_02dd: Unknown result type (might be due to invalid IL or missing references) //IL_02e0: Unknown result type (might be due to invalid IL or missing references) //IL_02e1: Unknown result type (might be due to invalid IL or missing references) Quaternion val = Orient(stock, up, facing); Vector3 val2 = LongAxis(stock, up); Vector3 extents = ((Bounds)(ref art)).extents; Vector3 val3 = Sweep(extents, val); float num = 0.97f * Mathf.Min(((Bounds)(ref stock)).extents.x / val3.x, Mathf.Min(((Bounds)(ref stock)).extents.y / val3.y, ((Bounds)(ref stock)).extents.z / val3.z)); for (int i = 1; i <= 4; i++) { for (int j = -1; j <= 1; j += 2) { Quaternion val4 = Quaternion.AngleAxis(7.5f * (float)i * (float)j, val2) * val; Vector3 val5 = Sweep(extents, val4); float num2 = 0.97f * Mathf.Min(((Bounds)(ref stock)).extents.x / val5.x, Mathf.Min(((Bounds)(ref stock)).extents.y / val5.y, ((Bounds)(ref stock)).extents.z / val5.z)); if (num2 > num + 1E-05f) { num = num2; val = val4; val3 = val5; } } } if (!(num > 0f) || !float.IsFinite(num)) { throw new InvalidOperationException("Invalid stock bounds"); } float num3 = Mathf.Max(num * val3.x / ((Bounds)(ref stock)).extents.x, Mathf.Max(num * val3.y / ((Bounds)(ref stock)).extents.y, num * val3.z / ((Bounds)(ref stock)).extents.z)); float num4 = Mathf.Max(1f, growth); if (num3 > 0.0001f) { num4 = Mathf.Min(num4, 1.225f / num3); } num4 = Mathf.Max(1f, num4); num *= num4; Vector3 val6 = val3 * num; Vector3 val7 = ((Bounds)(ref stock)).extents - val6; Vector3 center = ((Bounds)(ref stock)).center; if (grip.HasValue) { Vector3 val8 = grip.Value - center; for (int k = 0; k < 3; k++) { ref Vector3 reference = ref center; int num5 = k; ((Vector3)(ref reference))[num5] = ((Vector3)(ref reference))[num5] + Mathf.Clamp(((Vector3)(ref val8))[k], 0f - Mathf.Max(0f, ((Vector3)(ref val7))[k]), Mathf.Max(0f, ((Vector3)(ref val7))[k])); } } else { Vector3 val9 = Abs(up); int num6 = ((!(val9.x > val9.y) || !(val9.x > val9.z)) ? ((val9.y > val9.z) ? 1 : 2) : 0); ref Vector3 reference = ref center; int num5 = num6; ((Vector3)(ref reference))[num5] = ((Vector3)(ref reference))[num5] - Mathf.Sign(((Vector3)(ref up))[num6]) * ((Vector3)(ref val7))[num6]; } return Report(center, val, num, Overshoot(stock, val6), -1f); } internal static float FirstPersonTarget(PackKind kind) { return kind switch { PackKind.Ammo => 0.405f, PackKind.Medical => 0.39f, PackKind.Tool => 0.405f, PackKind.Disinfection => 0.405f, _ => 0.38f, }; } private static Quaternion Orient(Bounds stock, Vector3 up, Vector3 facing) { //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_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_0028: 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_001e: 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_005c: 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_0042: 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_009b: Unknown result type (might be due to invalid IL or missing references) //IL_009c: Unknown result type (might be due to invalid IL or missing references) //IL_009d: Unknown result type (might be due to invalid IL or missing references) //IL_0095: Unknown result type (might be due to invalid IL or missing references) //IL_008e: 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) Vector3 val = LongAxis(stock, up); Vector3 val2 = Vector3.ProjectOnPlane(facing, val); if (((Vector3)(ref val2)).sqrMagnitude < 0.1f) { val2 = Vector3.ProjectOnPlane(up, val); } int num = ((!(((Bounds)(ref stock)).size.x >= ((Bounds)(ref stock)).size.y) || !(((Bounds)(ref stock)).size.x >= ((Bounds)(ref stock)).size.z)) ? ((((Bounds)(ref stock)).size.y >= ((Bounds)(ref stock)).size.z) ? 1 : 2) : 0); if (((Vector3)(ref val2)).sqrMagnitude < 0.1f) { val2 = ((num == 2) ? Vector3.up : Vector3.forward); } return Quaternion.LookRotation(val2, val); } private static Vector3 LongAxis(Bounds stock, Vector3 up) { //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_000e: 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_0016: 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_0039: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_003f: 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) //IL_0054: 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_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) Vector3 size = ((Bounds)(ref stock)).size; Vector3 val = Axis((!(size.x >= size.y) || !(size.x >= size.z)) ? ((size.y >= size.z) ? 1 : 2) : 0); if (Vector3.Dot(val, up) < -0.5f) { val = -val; } return val; } private static Vector3 Sweep(Vector3 extents, Quaternion rotation) { //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_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0021: 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_0027: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_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_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0047: 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) return extents.x * Abs(rotation * Vector3.right) + extents.y * Abs(rotation * Vector3.up) + extents.z * Abs(rotation * Vector3.forward); } private static Vector3 Perp(Vector3 point, Vector3 u) { //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_0003: 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_000e: Unknown result type (might be due to invalid IL or missing references) return point - u * Vector3.Dot(point, u); } private static float PerpHalf(Vector3 extents, Vector3 u) { return ((Vector3)(ref extents)).magnitude; } private static Vector3 HostScale(Vector3 host) { //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_001c: Unknown result type (might be due to invalid IL or missing references) //IL_000e: 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_0042: 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_0068: 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_008e: Unknown result type (might be due to invalid IL or missing references) if (((Vector3)(ref host)).sqrMagnitude < 1E-08f) { return Vector3.one; } host = Abs(host); if (!(host.x > 0.0001f) || !float.IsFinite(host.x)) { host.x = 1f; } if (!(host.y > 0.0001f) || !float.IsFinite(host.y)) { host.y = 1f; } if (!(host.z > 0.0001f) || !float.IsFinite(host.z)) { host.z = 1f; } return host; } private static float ScaleAlong(Vector3 u, Vector3 host) { //IL_0002: 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_000f: 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_001c: 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) Vector3 val = default(Vector3); ((Vector3)(ref val))..ctor(u.x * host.x, u.y * host.y, u.z * host.z); float num = ((Vector3)(ref val)).magnitude / Mathf.Max(((Vector3)(ref u)).magnitude, 1E-06f); if (!(num > 0.0001f) || !float.IsFinite(num)) { return 1f; } return num; } private static float Overshoot(Bounds stock, Vector3 extents) { //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_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) float num = 0f; for (int i = 0; i < 3; i++) { Vector3 extents2 = ((Bounds)(ref stock)).extents; if (((Vector3)(ref extents2))[i] > 0f) { float num2 = num; float num3 = ((Vector3)(ref extents))[i]; extents2 = ((Bounds)(ref stock)).extents; num = Mathf.Max(num2, num3 / ((Vector3)(ref extents2))[i] - 1f); } } return Mathf.Max(0f, num); } private static Vector3 Axis(int i) { //IL_0013: 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_0007: Unknown result type (might be due to invalid IL or missing references) return (Vector3)(i switch { 1 => Vector3.up, 0 => Vector3.right, _ => Vector3.forward, }); } private static Vector3 Abs(Vector3 v) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_000b: 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_0021: Unknown result type (might be due to invalid IL or missing references) return new Vector3(Mathf.Abs(v.x), Mathf.Abs(v.y), Mathf.Abs(v.z)); } } internal static class PackPose { internal struct Inputs { internal string StockName; internal int StockVertices; internal Bounds Stock; internal int ArtVertices; internal Bounds Art; internal Vector3 Host; internal Vector3 Up; internal Vector3 Facing; internal Vector3? Left; internal Vector3? Right; internal Vector3? Grip; internal float Target; } private struct Fnv { internal ulong A; internal uint B; internal void Add(int v) { A = (A ^ (uint)v) * 1099511628211L; B = (B ^ (uint)v) * 16777619; } internal void Add(float v) { Add(Mathf.RoundToInt(v * 100000f)); } internal void Add(Vector3 v) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) Add(v.x); Add(v.y); Add(v.z); } internal void Add(Bounds b) { //IL_0003: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) Add(((Bounds)(ref b)).center); Add(((Bounds)(ref b)).size); } internal void Add(string s) { Add(s?.Length ?? (-1)); if (s != null) { for (int i = 0; i < s.Length; i++) { Add((int)s[i]); } } } internal void Add(Vector3? v) { //IL_001c: Unknown result type (might be due to invalid IL or missing references) Add(v.HasValue ? 1 : 0); if (v.HasValue) { Add(v.Value); } } } internal readonly struct Bake { internal readonly ulong Key; internal readonly uint Alt; internal readonly PackFit Fit; internal Bake(ulong key, uint alt, PackFit fit) { Key = key; Alt = alt; Fit = fit; } } private struct Memo { internal uint Alt; internal PackFit Fit; } private static readonly Bake[] baked = new Bake[6] { new Bake(1387129546749211872uL, 2411665536u, new PackFit(new Vector3(0.0603f, 0.12858418f, -0.12095f), new Quaternion(0f, 0.7071068f, 0.7071068f, 0f), 0.4049999f, 0.5367701f, 0.007843423f, 0.007843423f, 0.035415985f, 0.007843423f, 0.127964f, 4.656613E-10f, 0f, 0.18654458f, 0, 0, new Vector3(0f, 0f, 0f))), new Bake(12842275550721625380uL, 2781843524u, new PackFit(new Vector3(-0.0495f, 0.14199999f, 0.20869994f), new Quaternion(0f, 0.7071068f, 0.7071068f, 0f), 0.40499982f, 0.5367696f, 0.026094686f, 0.026094686f, 0.09340533f, 0.026094686f, 0.07350781f, 4.656614E-10f, 0f, 0.25723517f, 0, 2, new Vector3(0f, 0f, 0f))), new Bake(992208471863941997uL, 199167469u, new PackFit(new Vector3(-0.14692861f, 0.19901806f, -0.07003288f), new Quaternion(0f, 0.7071068f, 0.7071068f, 0f), 0.3899999f, 0.93013775f, 0.026537664f, 0.026537664f, 0.24569657f, 0.026537664f, 0.117787756f, 0f, 0f, 0.25710076f, 0, 2, new Vector3(0f, 0f, 0f))), new Bake(12530715450931326917uL, 3174385733u, new PackFit(new Vector3(-0.1652f, 0.101f, 0.20619996f), new Quaternion(0f, 0.7071068f, 0.7071068f, 0f), 0.3899998f, 0.9301373f, 0.027664395f, 0.027664395f, 0.23092873f, 0.027664395f, 0.06769011f, -0.059999987f, 0f, 0.28286126f, 0, 6, new Vector3(0f, 0f, 0f))), new Bake(14392500218496206029uL, 3653002253u, new PackFit(new Vector3(0.16715631f, 0.16084999f, 0.44814998f), new Quaternion(0f, 0f, -0.7071068f, 0.7071068f), 1.0805125f, 1.2407732f, 0.013760376f, 0.013760376f, 0.086634725f, 0.013760376f, 0.084924355f, 0f, 0f, 0.24865653f, 0, 0, new Vector3(0f, 0f, 0f))), new Bake(7866698581188643906uL, 517613826u, new PackFit(new Vector3(0.01345f, 0.09025f, 0.026943862f), new Quaternion(0f, 0.7071068f, 0.7071068f, 0f), 0.39582574f, 0.84761965f, 0.014421902f, 0.014421902f, 0.07318724f, 0.014421902f, 0.06986626f, 0.010111605f, 0.010111605f, 0.17412029f, 0, 0, new Vector3(0f, 0f, 0f))) }; private const int Limit = 32; private static readonly Dictionary<ulong, Memo> memo = new Dictionary<ulong, Memo>(32); internal static int Path; internal static int BakedHits { get; private set; } internal static int MemoHits { get; private set; } internal static int Solves { get; private set; } internal static int Baked => baked.Length; internal static int Memoised => memo.Count; internal static ulong Key(in Inputs i, out uint alt) { //IL_004b: 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_0072: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_008c: Unknown result type (might be due to invalid IL or missing references) Fnv fnv = new Fnv { A = 14695981039346656037uL, B = 2166136261u }; fnv.Add(1); fnv.Add(i.StockName); fnv.Add(i.StockVertices); fnv.Add(i.Stock); fnv.Add(i.ArtVertices); fnv.Add(i.Art); fnv.Add(i.Host); fnv.Add(i.Up); fnv.Add(i.Facing); fnv.Add(i.Left); fnv.Add(i.Right); fnv.Add(i.Grip); fnv.Add(i.Target); alt = fnv.B; return fnv.A; } internal static bool TryBaked(ulong key, uint alt, out PackFit fit) { for (int i = 0; i < baked.Length; i++) { if (baked[i].Key == key && baked[i].Alt == alt) { fit = baked[i].Fit; BakedHits++; Path = 0; return true; } } fit = default(PackFit); return false; } internal static bool TryMemo(ulong key, uint alt, out PackFit fit) { if (memo.TryGetValue(key, out var value) && value.Alt == alt) { fit = value.Fit; MemoHits++; Path = 1; return true; } fit = default(PackFit); return false; } internal static void Remember(ulong key, uint alt, PackFit fit) { Solves++; Path = 2; if (memo.Count < 32) { memo[key] = new Memo { Alt = alt, Fit = fit }; } } internal static void Reset() { memo.Clear(); BakedHits = (MemoHits = (Solves = 0)); Path = 2; } } internal static class PackSurface { internal sealed class Entry { internal Vector3[] Points; internal int[] Triangles; } private const int MaxVertices = 262144; private const int MaxTriangles = 600000; private const int Limit = 8; private static readonly Dictionary<string, Entry> cache = new Dictionary<string, Entry>(); internal static int Reads; internal static int Builds; internal static int Queries; internal static int Overflows; internal static bool Readable { get; private set; } = true; internal static int Cached => cache.Count; internal static Entry Raw(Mesh mesh, out string why) { //IL_0065: 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) why = null; if ((Object)(object)mesh == (Object)null) { why = "no mesh"; return null; } string key = "raw:" + ((Object)mesh).GetInstanceID(); if (cache.TryGetValue(key, out var value) && value.Points != null) { if (value.Points.Length == mesh.vertexCount) { return value; } cache.Remove(key); } return Build(key, mesh, Quaternion.identity, 1f, Vector3.zero, out why); } internal static Entry Oriented(Mesh mesh, Quaternion rotation, float scale, Vector3 centre, out string why) { //IL_00f2: 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) why = null; if ((Object)(object)mesh == (Object)null) { why = "no mesh"; return null; } string key = "art:" + ((Object)mesh).GetInstanceID() + ":" + rotation.x.ToString("R") + "," + rotation.y.ToString("R") + "," + rotation.z.ToString("R") + "," + rotation.w.ToString("R") + ":" + scale.ToString("R"); if (cache.TryGetValue(key, out var value) && value.Points != null && value.Points.Length == mesh.vertexCount) { return value; } return Build(key, mesh, rotation, scale, centre, out why); } internal unsafe static Entry From(Mesh mesh, Matrix4x4 meshToNode, out string why) { //IL_0015: 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_0027: 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_0133: Unknown result type (might be due to invalid IL or missing references) //IL_0138: Unknown result type (might be due to invalid IL or missing references) //IL_013d: Unknown result type (might be due to invalid IL or missing references) why = null; if ((Object)(object)mesh == (Object)null) { why = "no mesh"; return null; } if (meshToNode.m33 == 0f) { meshToNode = Matrix4x4.identity; } string key = "map:" + ((Object)mesh).GetInstanceID() + ":" + ((object)(*(Matrix4x4*)(&meshToNode))/*cast due to .constrained prefix*/).GetHashCode(); if (cache.TryGetValue(key, out var value) && value.Points != null && value.Points.Length == mesh.vertexCount) { return value; } Vector3[] array; int[] array2; try { if (!mesh.isReadable) { why = "mesh is not readable"; return null; } array = Il2CppArrayBase<Vector3>.op_Implicit((Il2CppArrayBase<Vector3>)(object)mesh.vertices); array2 = Il2CppArrayBase<int>.op_Implicit((Il2CppArrayBase<int>)(object)mesh.triangles); Reads++; } catch (Exception ex) { why = ex.GetType().Name; return null; } if (array == null || array2 == null || array.Length < 3 || array2.Length < 3 || array2.Length % 3 != 0) { why = "mesh has no triangles"; return null; } if (array.Length > 262144 || array2.Length > 600000) { why = "mesh is not the authored art"; return null; } Vector3[] array3 = (Vector3[])(object)new Vector3[array.Length]; for (int i = 0; i < array.Length; i++) { array3[i] = Point(meshToNode, array[i]); } for (int j = 0; j < array2.Length; j++) { if ((uint)array2[j] >= (uint)array.Length) { why = "triangle index out of range"; return null; } } Entry entry = new Entry { Points = array3, Triangles = array2 }; Builds++; Insert(cache, key, entry); return entry; } private static Entry Build(string key, Mesh mesh, Quaternion rotation, float scale, Vector3 centre, out string why) { //IL_00a5: Unknown result type (might be due to invalid IL or missing references) //IL_00aa: Unknown result type (might be due to invalid IL or missing references) //IL_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_00b8: 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) //IL_00cf: 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_00f9: 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_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) why = null; Vector3[] array; int[] array2; try { if (!mesh.isReadable) { why = "mesh is not readable"; return null; } array = Il2CppArrayBase<Vector3>.op_Implicit((Il2CppArrayBase<Vector3>)(object)mesh.vertices); array2 = Il2CppArrayBase<int>.op_Implicit((Il2CppArrayBase<int>)(object)mesh.triangles); Reads++; } catch (Exception ex) { why = ex.GetType().Name; return null; } if (array == null || array2 == null || array.Length < 3 || array2.Length < 3 || array2.Length % 3 != 0) { why = "mesh has no triangles"; return null; } if (array.Length > 262144 || array2.Length > 600000) { why = "mesh is not the authored art"; return null; } Vector3[] array3 = (Vector3[])(object)new Vector3[array.Length]; Matrix4x4 m = Matrix4x4.TRS(Vector3.zero, rotation, new Vector3(scale, scale, scale)); for (int i = 0; i < array.Length; i++) { array3[i] = Point(m, new Vector3(array[i].x - centre.x, array[i].y - centre.y, array[i].z - centre.z)); } for (int j = 0; j < array2.Length; j++) { if ((uint)array2[j] >= (uint)array.Length) { why = "triangle index out of range"; return null; } } Builds++; Entry entry = new Entry { Points = array3, Triangles = array2 }; Insert(cache, key, entry); return entry; } private static void Insert(Dictionary<string, Entry> map, string key, Entry entry) { if (map.Count >= 8) { Overflows++; } else { map[key] = entry; } } internal static float Low(Entry e, Vector3 u) { //IL_001d: 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_0044: Unknown result type (might be due to invalid IL or missing references) float num = float.PositiveInfinity; Vector3[] points = e.Points; for (int i = 0; i < points.Length; i++) { float num2 = points[i].x * u.x + points[i].y * u.y + points[i].z * u.z; if (num2 < num) { num = num2; } } return num; } internal static float High(Entry e, Vector3 u) { //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) return 0f - Low(e, Neg(u)); } private static Vector3 Neg(Vector3 v) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000e: 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) return new Vector3(0f - v.x, 0f - v.y, 0f - v.z); } internal static bool Nearest(Entry e, Vector3 point, out Vector3 onSurface, out Vector3 normal, out float distance) { //IL_0001: 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_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_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0073: 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_0099: 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_0120: 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_013e: Unknown result type (might be due to invalid IL or missing references) onSurface = Vector3.zero; normal = Vector3.up; distance = float.PositiveInfinity; if (e?.Points == null) { return false; } Vector3[] points = e.Points; int[] triangles = e.Triangles; Vector3 vector = Managed(point); Vector3 v = default(Vector3); Vector3 vector2 = default(Vector3); float num = float.PositiveInfinity; Queries++; for (int i = 0; i < triangles.Length; i += 3) { Vector3 vector3 = Managed(points[triangles[i]]); Vector3 vector4 = Managed(points[triangles[i + 1]]); Vector3 vector5 = Managed(points[triangles[i + 2]]); Vector3 vector6 = Vector3.Cross(vector4 - vector3, vector5 - vector3); if (vector6.LengthSquared() > 1E-24f) { Vector3 vector7 = Closest(vector3, vector4, vector5, vector); float num2 = (vector - vector7).LengthSquared(); if (num2 < num) { num = num2; v = vector7; vector2 = vector6; } } } if (!float.IsFinite(num)) { return false; } onSurface = Unity(v); normal = Unity(vector2 / MathF.Sqrt(vector2.LengthSquared())); distance = MathF.Sqrt(num); return true; } internal static Vector3 Point(Matrix4x4 m, Vector3 p) { //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) //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0029: 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_0036: 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: 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_0059: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0066: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0073: 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_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_0090: Unknown result type (might be due to invalid IL or missing references) return new Vector3(m.m00 * p.x + m.m01 * p.y + m.m02 * p.z + m.m03, m.m10 * p.x + m.m11 * p.y + m.m12 * p.z + m.m13, m.m20 * p.x + m.m21 * p.y + m.m22 * p.z + m.m23); } private static Vector3 Managed(Vector3 v) { //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_000c: Unknown result type (might be due to invalid IL or missing references) return new Vector3(v.x, v.y, v.z); } private static Vector3 Unity(Vector3 v) { //IL_0012: Unknown result type (might be due to invalid IL or missing references) return new Vector3(v.X, v.Y, v.Z); } private static Vector3 Closest(Vector3 a, Vector3 b, Vector3 c, Vector3 p) { Vector3 vector = b - a; Vector3 vector2 = c - a; Vector3 vector3 = p - a; float num = Vector3.Dot(vector, vector3); float num2 = Vector3.Dot(vector2, vector3); if (num <= 0f && num2 <= 0f) { return a; } Vector3 vector4 = p - b; float num3 = Vector3.Dot(vector, vector4); float num4 = Vector3.Dot(vector2, vector4); if (num3 >= 0f && num4 <= num3) { return b; } float num5 = num * num4 - num3 * num2; if (num5 <= 0f && num >= 0f && num3 <= 0f) { return a + vector * (num / (num - num3)); } Vector3 vector5 = p - c; float num6 = Vector3.Dot(vector, vector5); float num7 = Vector3.Dot(vector2, vector5); if (num7 >= 0f && num6 <= num7) { return c; } float num8 = num6 * num2 - num * num7; if (num8 <= 0f && num2 >= 0f && num7 <= 0f) { return a + vector2 * (num2 / (num2 - num7)); } float num9 = num3 * num7 - num6 * num4; if (num9 <= 0f && num4 - num3 >= 0f && num6 - num7 >= 0f) { return b + (c - b) * ((num4 - num3) / (num4 - num3 + (num6 - num7))); } float num10 = 1f / (num9 + num8 + num5); return a + vector * (num8 * num10) + vector2 * (num5 * num10); } internal static void Clear() { cache.Clear(); Reads = (Builds = (Queries = (Overflows = 0))); } } public sealed class PackVisual : MonoBehaviour { internal sealed class Slot { internal MeshFilter Filter; internal MeshRenderer Stock; internal Mesh Original; internal Mesh Fitted; internal Material[] StockMaterials; internal Material[] Materials; internal GameObject Child; internal MeshRenderer Renderer; internal Transform Pivot; internal Quaternion Rest; internal bool SavedOff; internal bool Held; internal MaterialPropertyBlock Block; internal bool Cleared; internal Material Source; internal int SourceId; internal int StockSlots; internal float Enable = -1f; internal bool Keyword; internal int Writes; internal int Supports = -1; internal bool HasEnable; } private Plugin owner; private ItemMode mode; private PackKind kind; internal List<Slot> slots; private bool spinning; private float angle; public PackVisual(IntPtr pointer) : base(pointer) { } [HideFromIl2Cpp] internal static bool Apply(Plugin plugin, Transform root, PackKind kind, ItemMode mode) { //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Invalid comparison between Unknown and I4 //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Invalid comparison between Unknown and I4 //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_015e: Unknown result type (might be due to invalid IL or missing references) //IL_015f: 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_01b9: 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_01d7: Unknown result type (might be due to invalid IL or missing references) //IL_01d9: Invalid comparison between Unknown and I4 //IL_042c: Unknown result type (might be due to invalid IL or missing references) //IL_0249: Unknown result type (might be due to invalid IL or missing references) //IL_024e: Unknown result type (might be due to invalid IL or missing references) //IL_0251: Expected O, but got Unknown //IL_0256: Expected O, but got Unknown //IL_0295: Unknown result type (might be due to invalid IL or missing references) //IL_02a5: Unknown result type (might be due to invalid IL or missing references) //IL_02aa: Unknown result type (might be due to invalid IL or missing references) //IL_02ab: Unknown result type (might be due to invalid IL or missing references) //IL_02ad: 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_02bb: Unknown result type (might be due to invalid IL or missing references