using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using Microsoft.CodeAnalysis; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: AssemblyCompany("TrollChests")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0+1de1cf287554d79b0172d91a9eebd1413e43138a")] [assembly: AssemblyProduct("TrollChests")] [assembly: AssemblyTitle("TrollChests")] [assembly: AssemblyVersion("1.0.0.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace TrollChests { public class BodyMap { public struct Weights { public int B0; public int B1; public int B2; public int B3; public float W0; public float W1; public float W2; public float W3; } public struct Hit { public int Tri; public float A; public float B; public float C; public bool Ok; } private readonly Vector3[] pts; private readonly Vector3[] nrm; private readonly Vector2[] uv; private readonly Weights[] weights; private readonly int[] tris; private readonly int[] cellTri; private readonly Vector2[] cellBary; private readonly float[] cellZ; private readonly int nx; private readonly int ny; private readonly float x0; private readonly float y0; private readonly float cell; public int FallbackBone = -1; public bool HasUV => uv != null; public BodyMap(Vector3[] pts, Vector3[] normals, Vector2[] uv, Weights[] weights, int[] tris, float cellSize) { //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Unknown result type (might be due to invalid IL or missing references) //IL_008a: 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_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: Unknown result type (might be due to invalid IL or missing references) this.pts = pts; nrm = ((normals != null && normals.Length == pts.Length) ? normals : null); this.uv = ((uv != null && uv.Length == pts.Length) ? uv : null); this.weights = ((weights != null && weights.Length == pts.Length) ? weights : null); this.tris = tris; float num = float.MaxValue; float num2 = float.MinValue; float num3 = float.MaxValue; float num4 = float.MinValue; foreach (Vector3 val in pts) { num = Mathf.Min(num, val.x); num2 = Mathf.Max(num2, val.x); num3 = Mathf.Min(num3, val.y); num4 = Mathf.Max(num4, val.y); } cell = cellSize; x0 = num - cell; y0 = num3 - cell; nx = Mathf.CeilToInt((num2 - num) / cell) + 3; ny = Mathf.CeilToInt((num4 - num3) / cell) + 3; cellTri = new int[nx * ny]; cellBary = (Vector2[])(object)new Vector2[nx * ny]; cellZ = new float[nx * ny]; for (int j = 0; j < cellTri.Length; j++) { cellTri[j] = -1; cellZ[j] = float.MinValue; } for (int k = 0; k + 2 < tris.Length; k += 3) { Raster(k); } } private void Raster(int t) { //IL_000e: 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_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_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_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_005b: 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_0068: 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_0087: Unknown result type (might be due to invalid IL or missing references) //IL_008d: Unknown result type (might be due to invalid IL or missing references) //IL_0093: Unknown result type (might be due to invalid IL or missing references) //IL_00c5: 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_00d1: Unknown result type (might be due to invalid IL or missing references) //IL_00fc: 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_0108: 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_013e: Unknown result type (might be due to invalid IL or missing references) //IL_0144: Unknown result type (might be due to invalid IL or missing references) //IL_01a4: 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_01b7: Unknown result type (might be due to invalid IL or missing references) //IL_01c0: Unknown result type (might be due to invalid IL or missing references) //IL_01cf: Unknown result type (might be due to invalid IL or missing references) //IL_01d8: Unknown result type (might be due to invalid IL or missing references) //IL_01e2: Unknown result type (might be due to invalid IL or missing references) //IL_01eb: Unknown result type (might be due to invalid IL or missing references) //IL_0224: Unknown result type (might be due to invalid IL or missing references) //IL_022d: Unknown result type (might be due to invalid IL or missing references) //IL_0237: Unknown result type (might be due to invalid IL or missing references) //IL_027d: Unknown result type (might be due to invalid IL or missing references) //IL_0282: Unknown result type (might be due to invalid IL or missing references) Vector3 val = pts[tris[t]]; Vector3 val2 = pts[tris[t + 1]]; Vector3 val3 = pts[tris[t + 2]]; float num = (val2.x - val.x) * (val3.y - val.y) - (val2.y - val.y) * (val3.x - val.x); if (Mathf.Abs(num) < 1E-09f) { return; } int num2 = Mathf.Max(0, Mathf.CeilToInt((Mathf.Min(val.x, Mathf.Min(val2.x, val3.x)) - x0) / cell)); int num3 = Mathf.Min(nx - 1, Mathf.FloorToInt((Mathf.Max(val.x, Mathf.Max(val2.x, val3.x)) - x0) / cell)); int num4 = Mathf.Max(0, Mathf.CeilToInt((Mathf.Min(val.y, Mathf.Min(val2.y, val3.y)) - y0) / cell)); int num5 = Mathf.Min(ny - 1, Mathf.FloorToInt((Mathf.Max(val.y, Mathf.Max(val2.y, val3.y)) - y0) / cell)); for (int i = num4; i <= num5; i++) { float num6 = y0 + (float)i * cell; for (int j = num2; j <= num3; j++) { float num7 = x0 + (float)j * cell; float num8 = ((val2.x - num7) * (val3.y - num6) - (val2.y - num6) * (val3.x - num7)) / num; float num9 = ((val3.x - num7) * (val.y - num6) - (val3.y - num6) * (val.x - num7)) / num; float num10 = 1f - num8 - num9; if (!(num8 < -0.0001f) && !(num9 < -0.0001f) && !(num10 < -0.0001f)) { float num11 = num8 * val.z + num9 * val2.z + num10 * val3.z; int num12 = i * nx + j; if (!(num11 <= cellZ[num12])) { cellZ[num12] = num11; cellTri[num12] = t; cellBary[num12] = new Vector2(num8, num9); } } } } } public Hit At(float x, float y) { //IL_00bb: Unknown result type (might be due to invalid IL or missing references) //IL_00c0: Unknown result type (might be due to invalid IL or missing references) //IL_00d3: Unknown result type (might be due to invalid IL or missing references) //IL_00d8: Unknown result type (might be due to invalid IL or missing references) //IL_00eb: Unknown result type (might be due to invalid IL or missing references) //IL_00f0: Unknown result type (might be due to invalid IL or missing references) //IL_00f2: 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_0108: Unknown result type (might be due to invalid IL or missing references) //IL_0111: Unknown result type (might be due to invalid IL or missing references) //IL_0118: 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_0127: 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_013c: 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_014f: 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_0168: Unknown result type (might be due to invalid IL or missing references) //IL_0172: Unknown result type (might be due to invalid IL or missing references) //IL_017b: Unknown result type (might be due to invalid IL or missing references) //IL_01a1: Unknown result type (might be due to invalid IL or missing references) //IL_01a6: Unknown result type (might be due to invalid IL or missing references) int num = Mathf.RoundToInt((x - x0) / cell); int num2 = Mathf.RoundToInt((y - y0) / cell); for (int i = 0; i <= 3; i++) { for (int j = -i; j <= i; j++) { for (int k = -i; k <= i; k++) { if (Mathf.Max(Mathf.Abs(k), Mathf.Abs(j)) != i) { continue; } int num3 = num + k; int num4 = num2 + j; if (num3 < 0 || num4 < 0 || num3 >= nx || num4 >= ny) { continue; } int num5 = cellTri[num4 * nx + num3]; if (num5 >= 0) { Vector3 val = pts[tris[num5]]; Vector3 val2 = pts[tris[num5 + 1]]; Vector3 val3 = pts[tris[num5 + 2]]; float num6 = (val2.x - val.x) * (val3.y - val.y) - (val2.y - val.y) * (val3.x - val.x); float num7 = ((val2.x - x) * (val3.y - y) - (val2.y - y) * (val3.x - x)) / num6; float num8 = ((val3.x - x) * (val.y - y) - (val3.y - y) * (val.x - x)) / num6; if (i > 0) { Vector2 val4 = cellBary[num4 * nx + num3]; num7 = val4.x; num8 = val4.y; } float num9 = 1f - num7 - num8; num7 = Mathf.Max(0f, num7); num8 = Mathf.Max(0f, num8); num9 = Mathf.Max(0f, num9); float num10 = num7 + num8 + num9; return new Hit { Tri = num5, A = num7 / num10, B = num8 / num10, C = num9 / num10, Ok = true }; } } } } return default(Hit); } public bool Covered(float x, float y) { int num = Mathf.RoundToInt((x - x0) / cell); int num2 = Mathf.RoundToInt((y - y0) / cell); if (num >= 0 && num2 >= 0 && num < nx && num2 < ny) { return cellTri[num2 * nx + num] >= 0; } return false; } public float Height(float x, float y) { Hit hit = At(x, y); if (!hit.Ok) { return float.NaN; } return hit.A * pts[tris[hit.Tri]].z + hit.B * pts[tris[hit.Tri + 1]].z + hit.C * pts[tris[hit.Tri + 2]].z; } public float SmoothHeight(float x, float y, float radius) { float num = 0f; float num2 = 0f; for (int i = 0; i < 9; i++) { float num3 = (float)i * (float)Math.PI * 2f / 8f; float num4 = ((i == 0) ? 0f : radius); float num5 = Height(x + Mathf.Cos(num3) * num4, y + Mathf.Sin(num3) * num4); if (!float.IsNaN(num5)) { float num6 = ((i == 0) ? 2f : 1f); num += num5 * num6; num2 += num6; } } if (!(num2 > 0f)) { return float.NaN; } return num / num2; } public Vector3 Point(Hit h) { //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_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Unknown result type (might be due to invalid IL or missing references) return h.A * pts[tris[h.Tri]] + h.B * pts[tris[h.Tri + 1]] + h.C * pts[tris[h.Tri + 2]]; } public Vector3 Normal(Hit h) { //IL_00a0: 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_00c5: Unknown result type (might be due to invalid IL or missing references) //IL_00ca: Unknown result type (might be due to invalid IL or missing references) //IL_00cf: Unknown result type (might be due to invalid IL or missing references) //IL_00ef: Unknown result type (might be due to invalid IL or missing references) //IL_00f4: Unknown result type (might be due to invalid IL or missing references) //IL_00f9: 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_0101: 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_0036: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0055: 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_0057: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Unknown result type (might be due to invalid IL or missing references) //IL_0070: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_0080: 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_007e: Unknown result type (might be due to invalid IL or missing references) Vector3 val4; if (nrm == null) { Vector3 val = pts[tris[h.Tri]]; Vector3 val2 = pts[tris[h.Tri + 1]]; Vector3 val3 = pts[tris[h.Tri + 2]]; val4 = Vector3.Cross(val2 - val, val3 - val); Vector3 normalized = ((Vector3)(ref val4)).normalized; if (!(normalized.z < 0f)) { return normalized; } return -normalized; } val4 = h.A * nrm[tris[h.Tri]] + h.B * nrm[tris[h.Tri + 1]] + h.C * nrm[tris[h.Tri + 2]]; return ((Vector3)(ref val4)).normalized; } public Vector2 UV(Hit h) { //IL_0080: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_0046: 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_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0070: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Unknown result type (might be due to invalid IL or missing references) if (uv != null) { return h.A * uv[tris[h.Tri]] + h.B * uv[tris[h.Tri + 1]] + h.C * uv[tris[h.Tri + 2]]; } return Vector2.zero; } public void AddWeights(Hit h, float scale, Dictionary into) { if (weights == null) { Add(into, FallbackBone, scale); return; } Corner(weights[tris[h.Tri]], h.A * scale, into); Corner(weights[tris[h.Tri + 1]], h.B * scale, into); Corner(weights[tris[h.Tri + 2]], h.C * scale, into); } private static void Corner(Weights w, float s, Dictionary into) { if (!(s <= 0f)) { if (w.W0 > 0f) { Add(into, w.B0, w.W0 * s); } if (w.W1 > 0f) { Add(into, w.B1, w.W1 * s); } if (w.W2 > 0f) { Add(into, w.B2, w.W2 * s); } if (w.W3 > 0f) { Add(into, w.B3, w.W3 * s); } } } private static void Add(Dictionary d, int bone, float w) { d.TryGetValue(bone, out var value); d[bone] = value + w; } public bool FitIslandUV(float cx, float cy, float r, out Vector3 mu, out Vector3 mv) { //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_0020: 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_01be: Unknown result type (might be due to invalid IL or missing references) //IL_025a: Unknown result type (might be due to invalid IL or missing references) //IL_026a: Unknown result type (might be due to invalid IL or missing references) //IL_0278: Unknown result type (might be due to invalid IL or missing references) //IL_0287: Unknown result type (might be due to invalid IL or missing references) //IL_0297: 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_03eb: Unknown result type (might be due to invalid IL or missing references) //IL_03f0: Unknown result type (might be due to invalid IL or missing references) //IL_03fe: Unknown result type (might be due to invalid IL or missing references) //IL_0403: Unknown result type (might be due to invalid IL or missing references) //IL_032c: Unknown result type (might be due to invalid IL or missing references) //IL_0331: Unknown result type (might be due to invalid IL or missing references) //IL_0333: Unknown result type (might be due to invalid IL or missing references) //IL_0338: Unknown result type (might be due to invalid IL or missing references) mu = (mv = Vector3.zero); if (uv == null) { return false; } int num = Mathf.RoundToInt((cx - x0) / cell); int num2 = Mathf.RoundToInt((cy - y0) / cell); if (num < 0 || num2 < 0 || num >= nx || num2 >= ny || cellTri[num2 * nx + num] < 0) { return false; } Func func = delegate(int k) { //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: 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) int num19 = cellTri[k]; Vector2 val3 = cellBary[k]; return val3.x * uv[tris[num19]] + val3.y * uv[tris[num19 + 1]] + (1f - val3.x - val3.y) * uv[tris[num19 + 2]]; }; HashSet hashSet = new HashSet(); Queue queue = new Queue(); queue.Enqueue(num2 * nx + num); hashSet.Add(num2 * nx + num); double sxx = 0.0; double sxy = 0.0; double sx = 0.0; double syy = 0.0; double sy = 0.0; double n = 0.0; double num3 = 0.0; double num4 = 0.0; double num5 = 0.0; double num6 = 0.0; double num7 = 0.0; double num8 = 0.0; int num9 = Mathf.CeilToInt(r / cell); int[] array = new int[4] { 1, -1, 0, 0 }; int[] array2 = new int[4] { 0, 0, 1, -1 }; while (queue.Count > 0) { int num10 = queue.Dequeue(); int num11 = num10 % nx; int num12 = num10 / nx; Vector2 val = func(num10); double num13 = x0 + (float)num11 * cell; double num14 = y0 + (float)num12 * cell; sxx += num13 * num13; sxy += num13 * num14; sx += num13; syy += num14 * num14; sy += num14; n++; num3 += num13 * (double)val.x; num4 += num14 * (double)val.x; num5 += (double)val.x; num6 += num13 * (double)val.y; num7 += num14 * (double)val.y; num8 += (double)val.y; for (int num15 = 0; num15 < 4; num15++) { int num16 = num11 + array[num15]; int num17 = num12 + array2[num15]; int num18 = num17 * nx + num16; if (num16 >= 0 && num17 >= 0 && num16 < nx && num17 < ny && !hashSet.Contains(num18) && cellTri[num18] >= 0 && (num16 - num) * (num16 - num) + (num17 - num2) * (num17 - num2) <= num9 * num9) { Vector2 val2 = func(num18) - val; if (!(((Vector2)(ref val2)).sqrMagnitude > 0.0009f)) { hashSet.Add(num18); queue.Enqueue(num18); } } } } if (n < 6.0) { return false; } double det = Det(sxx, sxy, sx, sxy, syy, sy, sx, sy, n); if (Math.Abs(det) < 1E-12) { return false; } mu = Solve(num3, num4, num5); mv = Solve(num6, num7, num8); return true; Vector3 Solve(double b0, double b1, double b2) { //IL_009c: Unknown result type (might be due to invalid IL or missing references) return new Vector3((float)(Det(b0, sxy, sx, b1, syy, sy, b2, sy, n) / det), (float)(Det(sxx, b0, sx, sxy, b1, sy, sx, b2, n) / det), (float)(Det(sxx, sxy, b0, sxy, syy, b1, sx, sy, b2) / det)); } } private static double Det(double a, double b, double c, double d, double e, double f, double g, double h, double i) { return a * (e * i - f * h) - b * (d * i - f * g) + c * (d * h - e * g); } } public enum Outfit { Bikini, HalterTop } public class ChestBuilder { public struct Settings { public float Size; public float Projection; public float Sag; public float Up; public float Forward; public float Spacing; public Outfit Outfit; } public class Result { public readonly List Verts = new List(); public readonly List Normals = new List(); public readonly List UV = new List(); public readonly List> Weights = new List>(); public readonly List Skin = new List(); public readonly List Fabric = new List(); public readonly Vector3[] PivotPos = (Vector3[])(object)new Vector3[2]; public readonly Vector3[] TipPos = (Vector3[])(object)new Vector3[2]; public float Width; } private struct Dome { public int Side; public Vector3 M; public float R; public float Depth; public float WallZ; public Vector3 N; public Vector3 X; public Vector3 Y; public bool UvAffine; public Vector3 Mu; public Vector3 Mv; } public const int PivotL = -1; public const int TipL = -2; public const int PivotR = -3; public const int TipR = -4; private const int Seg = 40; private const int RingsIn = 9; private const int RingsOut = 21; private readonly BodyMap body; private readonly Settings set; private readonly Result res = new Result(); private static readonly Vector2[] Cup = MakeCup(); public static int Pivot(int side) { if (side >= 0) { return -3; } return -1; } public static int Tip(int side) { if (side >= 0) { return -4; } return -2; } public static Result Build(BodyMap body, Settings s) { return new ChestBuilder(body, s).Run(); } private ChestBuilder(BodyMap body, Settings s) { this.body = body; set = s; } private Result Run() { //IL_00b3: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: Unknown result type (might be due to invalid IL or missing references) //IL_00cb: Unknown result type (might be due to invalid IL or missing references) //IL_00d0: Unknown result type (might be due to invalid IL or missing references) //IL_00d5: Unknown result type (might be due to invalid IL or missing references) //IL_00d9: Unknown result type (might be due to invalid IL or missing references) //IL_00de: Unknown result type (might be due to invalid IL or missing references) //IL_00e5: Unknown result type (might be due to invalid IL or missing references) //IL_00eb: Unknown result type (might be due to invalid IL or missing references) //IL_00f0: Unknown result type (might be due to invalid IL or missing references) //IL_00f6: Unknown result type (might be due to invalid IL or missing references) //IL_0100: Unknown result type (might be due to invalid IL or missing references) //IL_0105: Unknown result type (might be due to invalid IL or missing references) //IL_010a: 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_0113: 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_0121: Unknown result type (might be due to invalid IL or missing references) //IL_0126: 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_0131: Unknown result type (might be due to invalid IL or missing references) //IL_0136: Unknown result type (might be due to invalid IL or missing references) //IL_0142: Unknown result type (might be due to invalid IL or missing references) //IL_0166: Unknown result type (might be due to invalid IL or missing references) //IL_016c: Unknown result type (might be due to invalid IL or missing references) //IL_0184: Unknown result type (might be due to invalid IL or missing references) //IL_018a: Unknown result type (might be due to invalid IL or missing references) //IL_0192: Unknown result type (might be due to invalid IL or missing references) //IL_0198: Unknown result type (might be due to invalid IL or missing references) //IL_01b5: Unknown result type (might be due to invalid IL or missing references) //IL_01ba: 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_0156: 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_0160: Unknown result type (might be due to invalid IL or missing references) //IL_01d9: Unknown result type (might be due to invalid IL or missing references) //IL_01df: Unknown result type (might be due to invalid IL or missing references) float size = set.Size; res.Width = size; Vector2 val = default(Vector2); for (int i = 0; i < 2; i++) { Dome d = new Dome { Side = ((i != 0) ? 1 : (-1)) }; d.R = 0.5f * size; d.Depth = d.R * set.Projection / 0.6f; ((Vector2)(ref val))..ctor((float)d.Side * (0.92f * d.R + set.Spacing), set.Up - set.Sag * 0.3f * d.R); Vector3 val2 = Forward(val) + Vector3.right * ((float)d.Side * 0.2f); d.N = ((Vector3)(ref val2)).normalized; val2 = Vector3.up - d.N * Vector3.Dot(Vector3.up, d.N); d.Y = ((Vector3)(ref val2)).normalized; d.X = Vector3.Cross(d.Y, d.N); if (Vector3.Dot(d.X, Vector3.right * (float)d.Side) < 0f) { d.X = -d.X; } float num = (d.WallZ = SkinZ(val.x, val.y)); d.M = new Vector3(val.x, val.y, num) + d.N * (0.3f * d.Depth + set.Forward); if (body.HasUV) { d.UvAffine = body.FitIslandUV(val.x, val.y, 1.2f * size, out d.Mu, out d.Mv); } BuildDome(d, i); } return res; } private Vector3 Forward(Vector2 c) { //IL_0013: 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_0027: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0055: 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_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_0064: 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_0094: Unknown result type (might be due to invalid IL or missing references) //IL_0078: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_0085: 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_008e: 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) float num = 0.35f * set.Size; float num2 = SkinZ(c.x, c.y + num) - SkinZ(c.x, c.y - num); Vector3 val = new Vector3(0f, -0.5f * num2 / (2f * num), 1f); Vector3 normalized = ((Vector3)(ref val)).normalized; float num3 = Vector3.Angle(normalized, Vector3.forward); if (num3 > 15f) { val = Vector3.Lerp(Vector3.forward, normalized, 15f / num3); normalized = ((Vector3)(ref val)).normalized; } return normalized; } private float SkinZ(float x, float y) { float num = body.SmoothHeight(x, y, 0.1f * set.Size); if (!float.IsNaN(num)) { return num; } return 0f; } private static float Smooth(float t) { t = Mathf.Clamp01(t); return t * t * (3f - 2f * t); } private static Vector3 Dir(float rho, float cosT, float sinT) { //IL_001b: Unknown result type (might be due to invalid IL or missing references) float num = rho * (float)Math.PI; float num2 = Mathf.Sin(num); return new Vector3(num2 * cosT, num2 * sinT, Mathf.Cos(num)); } private Vector3 Ball(Dome d, float rho, float cosT, float sinT) { //IL_0004: 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_0020: 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_002d: 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_003a: 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_0057: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_008d: Unknown result type (might be due to invalid IL or missing references) //IL_008f: 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_009e: 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_00b4: Unknown result type (might be due to invalid IL or missing references) //IL_00d1: Unknown result type (might be due to invalid IL or missing references) //IL_00d6: Unknown result type (might be due to invalid IL or missing references) //IL_00dc: 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_0104: Unknown result type (might be due to invalid IL or missing references) //IL_0109: Unknown result type (might be due to invalid IL or missing references) //IL_0114: Unknown result type (might be due to invalid IL or missing references) //IL_011c: Unknown result type (might be due to invalid IL or missing references) //IL_0132: 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_017d: Unknown result type (might be due to invalid IL or missing references) //IL_017e: Unknown result type (might be due to invalid IL or missing references) //IL_0183: Unknown result type (might be due to invalid IL or missing references) //IL_0191: Unknown result type (might be due to invalid IL or missing references) Vector3 val = Dir(rho, cosT, sinT); if (val.y <= 0f) { return Lower(d, val); } float y = val.y; float num = Mathf.Sqrt(val.x * val.x + val.z * val.z); float num2 = ((num > 1E-05f) ? (val.x / num) : 0f); float num3 = ((num > 1E-05f) ? (val.z / num) : 1f); Vector3 val2 = Lower(d, new Vector3(num2, 0f, num3)); float num4 = val2.z - SkinZ(val2.x, val2.y); Vector3 val3 = d.M + d.X * (d.R * num2 * (1f - 0.45f * y * y)) + d.Y * (1.35f * d.R * y * (1f - 0.4f * num2 * num2)); val3.y += (val2.y - d.M.y) * (1f - y); float z = SkinZ(val3.x, val3.y) + num4 * Mathf.Pow(1f - y * y, 1.3f) - 0.02f * set.Size * y; val3.z = z; return Vector3.Lerp(Lower(d, val), val3, Smooth(y / 0.6f)); } private Vector3 Lower(Dome d, Vector3 u) { //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0037: 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_0052: 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_007c: Unknown result type (might be due to invalid IL or missing references) //IL_00a1: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: 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_00d8: Unknown result type (might be due to invalid IL or missing references) //IL_00df: Unknown result type (might be due to invalid IL or missing references) //IL_00e4: Unknown result type (might be due to invalid IL or missing references) //IL_00ea: Unknown result type (might be due to invalid IL or missing references) //IL_00f1: Unknown result type (might be due to invalid IL or missing references) //IL_00f6: Unknown result type (might be due to invalid IL or missing references) //IL_00fc: Unknown result type (might be due to invalid IL or missing references) //IL_0103: Unknown result type (might be due to invalid IL or missing references) //IL_0108: Unknown result type (might be due to invalid IL or missing references) float num = 0.9599311f * set.Sag; float num2 = Mathf.Cos(num); float num3 = Mathf.Sin(num); Vector3 val = default(Vector3); ((Vector3)(ref val))..ctor(u.x, u.y * num2 - u.z * num3, u.y * num3 + u.z * num2); float num4 = Mathf.Max(0f, 0f - val.y); float num5 = d.R * val.x * (1f + 0.15f * num4); if (val.x > 0f) { num5 *= 1f + 0.12f * num4; } float num6 = d.R * val.y * (1f + 0.15f * set.Sag); float num7 = d.Depth * val.z; return d.M + d.X * num5 + d.Y * num6 + d.N * num7; } private Vector3 Surface(Dome d, float rho, float cosT, float sinT) { //IL_0006: 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_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0154: 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_0085: Unknown result type (might be due to invalid IL or missing references) //IL_008b: Unknown result type (might be due to invalid IL or missing references) Vector3 val = Ball(d, rho, cosT, sinT); float num = 0.004f * set.Size; if (val.x * (float)d.Side < num) { val.x = (float)d.Side * num; } float num2 = body.Height(val.x, val.y); float num3 = Smooth((0f - sinT) * Mathf.Sin(rho * (float)Math.PI) * 2f); if (num3 > 0f && !float.IsNaN(num2)) { num2 = Mathf.Lerp(num2, SkinZ(val.x, val.y), num3); } if (!float.IsNaN(num2)) { float num4 = val.z - num2; float num5 = -0.015f * set.Size; float num6 = d.R * Mathf.Lerp(0.1f, 0.25f, Smooth(sinT * Mathf.Sin(rho * (float)Math.PI) * 0.8f + 0.5f)); num6 = Mathf.Lerp(num6, 0.01f * d.R, num3); val.z = num2 + 0.5f * (num4 + num5 + Mathf.Sqrt((num4 - num5) * (num4 - num5) + num6 * num6)) - 0.5f * num6 * Fade(num4 - num5, num6); } return val; } private static float Fade(float t, float k) { return Smooth((0f - t) / (1.5f * k)); } private float Above(Vector3 p) { //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_0020: Unknown result type (might be due to invalid IL or missing references) float num = body.Height(p.x, p.y); if (!float.IsNaN(num)) { return p.z - num; } return 10f * set.Size; } private float OutfitEdge(Dome d, float cosT, float sinT) { //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Unknown result type (might be due to invalid IL or missing references) if (set.Outfit == Outfit.Bikini) { return 0.32f * RayToPolygon(cosT, sinT, Cup); } Vector2 a = default(Vector2); ((Vector2)(ref a))..ctor(-1.1f, -0.25f); Vector2 b = default(Vector2); ((Vector2)(ref b))..ctor(0.45f, 1.1f); float num = RayToLine(cosT, sinT, a, b); return 0.6f * Mathf.Min(1f, num); } private static Vector2[] MakeCup() { //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_0070: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Unknown result type (might be due to invalid IL or missing references) //IL_0078: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_008c: Unknown result type (might be due to invalid IL or missing references) //IL_008e: 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) List list = new List((IEnumerable)(object)new Vector2[3] { new Vector2(0f, 0.5f), new Vector2(-0.5f, -0.25f), new Vector2(0.5f, -0.25f) }); for (int i = 0; i < 3; i++) { List list2 = new List(); for (int j = 0; j < list.Count; j++) { Vector2 val = list[j]; Vector2 val2 = list[(j + 1) % list.Count]; list2.Add(Vector2.Lerp(val, val2, 0.25f)); list2.Add(Vector2.Lerp(val, val2, 0.75f)); } list = list2; } return list.ToArray(); } private static float RayToPolygon(float u, float v, Vector2[] poly) { //IL_000e: 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) float num = 1f; for (int i = 0; i < poly.Length; i++) { float num2 = RayToLine(u, v, poly[i], poly[(i + 1) % poly.Length], segment: true); if (num2 < num) { num = num2; } } return num; } private static float RayToLine(float u, float v, Vector2 a, Vector2 b, bool segment = false) { //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_0009: 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_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_003a: 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_004b: 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) Vector2 val = b - a; float num = u * val.y - v * val.x; if (Mathf.Abs(num) < 1E-06f) { return 10f; } float num2 = (a.x * val.y - a.y * val.x) / num; float num3 = (a.x * v - a.y * u) / num; if (num2 <= 0f || (segment && (num3 < -0.0001f || num3 > 1.0001f))) { return 10f; } return num2; } private void BuildDome(Dome d, int k) { //IL_0267: Unknown result type (might be due to invalid IL or missing references) //IL_026c: Unknown result type (might be due to invalid IL or missing references) //IL_02d3: Unknown result type (might be due to invalid IL or missing references) //IL_02e2: Unknown result type (might be due to invalid IL or missing references) //IL_02e9: Unknown result type (might be due to invalid IL or missing references) //IL_02ee: Unknown result type (might be due to invalid IL or missing references) //IL_02f3: Unknown result type (might be due to invalid IL or missing references) //IL_0336: Unknown result type (might be due to invalid IL or missing references) //IL_033a: Unknown result type (might be due to invalid IL or missing references) //IL_032f: Unknown result type (might be due to invalid IL or missing references) //IL_033f: Unknown result type (might be due to invalid IL or missing references) //IL_0347: 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_0376: Unknown result type (might be due to invalid IL or missing references) //IL_037d: Unknown result type (might be due to invalid IL or missing references) //IL_039a: Unknown result type (might be due to invalid IL or missing references) //IL_039d: Unknown result type (might be due to invalid IL or missing references) //IL_03b3: Unknown result type (might be due to invalid IL or missing references) //IL_03b8: Unknown result type (might be due to invalid IL or missing references) //IL_03bd: Unknown result type (might be due to invalid IL or missing references) int baseIndex = res.Verts.Count; int rings = 30; float[] array = new float[40]; float[] array2 = new float[40]; float[] array3 = new float[40]; for (int i = 0; i < 40; i++) { float num = (float)Math.PI * 2f * (float)i / 40f; array[i] = Mathf.Cos(num); array2[i] = Mathf.Sin(num); array3[i] = Mathf.Clamp(OutfitEdge(d, array[i], array2[i]), 0.05f, 0.9f); } float[] array4 = new float[40]; for (int j = 0; j < 40; j++) { array4[j] = 0.25f * array3[(j + 40 - 1) % 40] + 0.5f * array3[j] + 0.25f * array3[(j + 1) % 40]; } array3 = array4; AddVertex(d, 0f, 1f, 0f); for (int l = 1; l < rings; l++) { for (int m = 0; m < 40; m++) { AddVertex(d, Rho(l, array3[m]), array[m], array2[m]); } } AddVertex(d, 1f, 1f, 0f); int back = res.Verts.Count - 1; for (int n = 0; n < rings; n++) { List l2 = ((n < 9) ? res.Fabric : res.Skin); for (int num2 = 0; num2 < 40; num2++) { if (n == 0) { Tri(l2, Idx(0, 0), Idx(1, num2), Idx(1, num2 + 1)); } else if (n == rings - 1) { Tri(l2, Idx(n, num2), Idx(rings, 0), Idx(n, num2 + 1)); } else { Quad(l2, Idx(n, num2), Idx(n + 1, num2), Idx(n + 1, num2 + 1), Idx(n, num2 + 1)); } } } Orient(baseIndex); Vector3 val = Vector3.zero; float num3 = 0f; for (int num4 = baseIndex; num4 < res.Verts.Count; num4++) { res.Weights[num4].TryGetValue(Pivot(d.Side), out var value); res.Weights[num4].TryGetValue(Tip(d.Side), out var value2); float num5 = value + value2; val += res.Verts[num4] * num5; num3 += num5; } res.TipPos[k] = ((num3 > 0f) ? (val / num3) : d.M); Vector3 val2 = default(Vector3); ((Vector3)(ref val2))..ctor(d.M.x, d.M.y + 1.1f * d.R, 0f); val2.z = SkinZ(val2.x, val2.y); res.PivotPos[k] = val2 - d.N * (0.15f * set.Size); Normals(baseIndex); Strings(d); int Idx(int num6, int num7) { if (num6 != 0) { if (num6 != rings) { return baseIndex + 1 + (num6 - 1) * 40 + num7 % 40; } return back; } return baseIndex; } } private float Rho(int i, float edge) { if (i <= 9) { return edge * (float)i / 9f; } return Mathf.Lerp(edge, 1f, (float)(i - 9) / 21f); } private void Orient(int from) { //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_008d: Unknown result type (might be due to invalid IL or missing references) //IL_0092: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_00b6: Unknown result type (might be due to invalid IL or missing references) //IL_00bb: Unknown result type (might be due to invalid IL or missing references) //IL_00c0: Unknown result type (might be due to invalid IL or missing references) float num = 0f; List[] array = new List[2] { res.Skin, res.Fabric }; foreach (List list in array) { for (int j = 0; j + 2 < list.Count; j += 3) { int num2 = list[j]; int num3 = list[j + 1]; int num4 = list[j + 2]; if (num2 == from || num3 == from || num4 == from) { num += Vector3.Cross(res.Verts[num3] - res.Verts[num2], res.Verts[num4] - res.Verts[num2]).z; } } } if (num >= 0f) { return; } array = new List[2] { res.Skin, res.Fabric }; foreach (List list2 in array) { for (int k = 0; k + 2 < list2.Count; k += 3) { if (list2[k] >= from) { int value = list2[k + 1]; list2[k + 1] = list2[k + 2]; list2[k + 2] = value; } } } } private void AddVertex(Dome d, float rho, float cosT, float sinT) { //IL_0006: 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_0017: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_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_0057: Unknown result type (might be due to invalid IL or missing references) Vector3 val = Surface(d, rho, cosT, sinT); res.Verts.Add(val); res.Normals.Add(Vector3.zero); res.UV.Add(SkinUV(d, val)); res.Weights.Add(DomeWeights(d, val, sinT * Mathf.Sin(rho * (float)Math.PI))); } private Dictionary DomeWeights(Dome d, Vector3 p, float up) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0055: 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_0076: 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 = Smooth(Above(p) / (0.55f * d.R)); num *= 1f - 0.35f * Smooth(up * 1.5f); float num2 = Smooth((0f - up) * 1.6f + 0.1f); Dictionary dictionary = new Dictionary(); BodyMap.Hit h = body.At(p.x, p.y); if (!h.Ok) { h = body.At(d.M.x, d.M.y); } if (h.Ok) { body.AddWeights(h, 1f - num, dictionary); } else { num = 1f; } Add(dictionary, Pivot(d.Side), num * (1f - num2)); Add(dictionary, Tip(d.Side), num * num2); return dictionary; } private static void Add(Dictionary d, int bone, float w) { if (!(w <= 0f)) { d.TryGetValue(bone, out var value); d[bone] = value + w; } } private Vector2 SkinUV(Dome d, Vector3 p) { //IL_0019: 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_000d: 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_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0075: 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_0080: 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_008b: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Unknown result type (might be due to invalid IL or missing references) //IL_0095: 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_00a3: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_00b5: Unknown result type (might be due to invalid IL or missing references) //IL_00be: Unknown result type (might be due to invalid IL or missing references) //IL_00ca: Unknown result type (might be due to invalid IL or missing references) //IL_00d4: Unknown result type (might be due to invalid IL or missing references) //IL_00dc: Unknown result type (might be due to invalid IL or missing references) //IL_00e6: Unknown result type (might be due to invalid IL or missing references) //IL_00ef: Unknown result type (might be due to invalid IL or missing references) //IL_0102: Unknown result type (might be due to invalid IL or missing references) //IL_010c: Unknown result type (might be due to invalid IL or missing references) //IL_0114: Unknown result type (might be due to invalid IL or missing references) //IL_011e: Unknown result type (might be due to invalid IL or missing references) //IL_0127: 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_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_014f: Unknown result type (might be due to invalid IL or missing references) //IL_0158: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0188: Unknown result type (might be due to invalid IL or missing references) //IL_0170: 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_0173: Unknown result type (might be due to invalid IL or missing references) //IL_0178: Unknown result type (might be due to invalid IL or missing references) //IL_018b: Unknown result type (might be due to invalid IL or missing references) //IL_018c: Unknown result type (might be due to invalid IL or missing references) //IL_018f: Unknown result type (might be due to invalid IL or missing references) //IL_01a7: Unknown result type (might be due to invalid IL or missing references) if (!body.HasUV) { return Vector2.zero; } BodyMap.Hit h = body.At(p.x, p.y); Vector2 val = (h.Ok ? body.UV(h) : Vector2.zero); if (!d.UvAffine) { return val; } Vector2 val2 = default(Vector2); ((Vector2)(ref val2))..ctor(d.M.x, d.M.y); Vector2 val3 = val2 + (new Vector2(p.x, p.y) - val2) * 0.5f; Vector2 val4 = default(Vector2); ((Vector2)(ref val4))..ctor(d.Mu.x * val3.x + d.Mu.y * val3.y + d.Mu.z, d.Mv.x * val3.x + d.Mv.y * val3.y + d.Mv.z); Vector2 val5 = default(Vector2); ((Vector2)(ref val5))..ctor(d.Mu.x * p.x + d.Mu.y * p.y + d.Mu.z, d.Mv.x * p.x + d.Mv.y * p.y + d.Mv.z); if (h.Ok) { Vector2 val6 = val - val5; if (!(((Vector2)(ref val6)).sqrMagnitude > 0.0009f)) { return Vector2.Lerp(val, val4, Smooth(Above(p) / (0.25f * d.R))); } } return val4; } private void Normals(int from) { //IL_008e: 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_00c0: Unknown result type (might be due to invalid IL or missing references) //IL_0106: Unknown result type (might be due to invalid IL or missing references) //IL_010b: Unknown result type (might be due to invalid IL or missing references) //IL_011a: Unknown result type (might be due to invalid IL or missing references) //IL_011f: Unknown result type (might be due to invalid IL or missing references) //IL_0127: Unknown result type (might be due to invalid IL or missing references) //IL_012e: Unknown result type (might be due to invalid IL or missing references) //IL_01b7: 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_015a: Unknown result type (might be due to invalid IL or missing references) //IL_016f: Unknown result type (might be due to invalid IL or missing references) //IL_0191: Unknown result type (might be due to invalid IL or missing references) //IL_0196: Unknown result type (might be due to invalid IL or missing references) //IL_019a: Unknown result type (might be due to invalid IL or missing references) //IL_019f: Unknown result type (might be due to invalid IL or missing references) //IL_01a3: Unknown result type (might be due to invalid IL or missing references) //IL_01a8: Unknown result type (might be due to invalid IL or missing references) Vector3[] acc = (Vector3[])(object)new Vector3[res.Verts.Count - from]; Face(res.Skin); Face(res.Fabric); float num = 0.5f * set.Size; float num2 = 0f; float num3 = float.MinValue; for (int i = from; i < res.Verts.Count; i++) { if (res.Verts[i].z > num3) { num3 = res.Verts[i].z; num2 = res.Verts[i].y; } } for (int j = from; j < res.Verts.Count; j++) { Vector3 normalized = ((Vector3)(ref acc[j - from])).normalized; Vector3 val = res.Verts[j]; BodyMap.Hit h = body.At(val.x, val.y); if (h.Ok && val.y > num2) { float num4 = 1f - (1f - Smooth(Above(val) / (0.35f * num))) * Smooth((val.y - num2) / (0.5f * num)); Vector3 val2 = Vector3.Lerp(body.Normal(h), normalized, num4); normalized = ((Vector3)(ref val2)).normalized; } res.Normals[j] = normalized; } void Face(List list) { //IL_0053: 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_0069: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_008b: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Unknown result type (might be due to invalid IL or missing references) //IL_0095: 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_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_00b5: Unknown result type (might be due to invalid IL or missing references) //IL_00b7: Unknown result type (might be due to invalid IL or missing references) //IL_00bc: Unknown result type (might be due to invalid IL or missing references) //IL_00d5: Unknown result type (might be due to invalid IL or missing references) //IL_00da: Unknown result type (might be due to invalid IL or missing references) //IL_00dc: Unknown result type (might be due to invalid IL or missing references) //IL_00e1: Unknown result type (might be due to invalid IL or missing references) //IL_00fa: Unknown result type (might be due to invalid IL or missing references) //IL_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_0106: Unknown result type (might be due to invalid IL or missing references) for (int k = 0; k + 2 < list.Count; k += 3) { int num5 = list[k]; int num6 = list[k + 1]; int num7 = list[k + 2]; if (num5 >= from && num6 >= from && num7 >= from) { Vector3 val3 = Vector3.Cross(res.Verts[num6] - res.Verts[num5], res.Verts[num7] - res.Verts[num5]); ref Vector3 reference = ref acc[num5 - from]; reference += val3; ref Vector3 reference2 = ref acc[num6 - from]; reference2 += val3; ref Vector3 reference3 = ref acc[num7 - from]; reference3 += val3; } } } } private static void Tri(List l, int a, int b, int c) { l.Add(a); l.Add(c); l.Add(b); } private static void Quad(List l, int a, int b, int c, int d2) { Tri(l, a, b, c); Tri(l, a, c, d2); } private void Strings(Dome d) { //IL_00fc: 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_004e: 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_008c: 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_00ae: Unknown result type (might be due to invalid IL or missing references) //IL_00c5: Unknown result type (might be due to invalid IL or missing references) //IL_00cd: Unknown result type (might be due to invalid IL or missing references) //IL_00e4: Unknown result type (might be due to invalid IL or missing references) float width = ((set.Outfit == Outfit.Bikini) ? 0.022f : 0.06f) * set.Size; float size = set.Size; if (set.Outfit == Outfit.Bikini) { Ribbon(d, ParamDir(0f, 1f), new Vector2((float)d.Side * 0.3f * size, set.Up + 0.8f * size), width); Ribbon(d, ParamDir(-1f, 0.1f), new Vector2(0f, d.M.y + 0.1f * d.R), width); Ribbon(d, ParamDir(1f, 0.05f), SideOfBody(d, d.M.y + 0.1f * d.R), width); } else { Ribbon(d, ParamDir(0.42f, 0.9f), new Vector2((float)d.Side * 0.3f * size, set.Up + 0.8f * size), width); } } private static Vector2 ParamDir(float u, float v) { //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_000a: Unknown result type (might be due to invalid IL or missing references) Vector2 val = new Vector2(u, v); return ((Vector2)(ref val)).normalized; } private Vector2 SideOfBody(Dome d, float y) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Unknown result type (might be due to invalid IL or missing references) float num = d.M.x; for (float num2 = 0.05f * set.Size; Mathf.Abs(num) < 6f * set.Size && body.Covered(num + (float)d.Side * num2, y); num += (float)d.Side * num2) { } return new Vector2(num - (float)d.Side * 0.05f * set.Size, y); } private void Ribbon(Dome d, Vector2 dir, Vector2 target, float width) { //IL_0024: 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_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Unknown result type (might be due to invalid IL or missing references) //IL_0091: Unknown result type (might be due to invalid IL or missing references) //IL_00ae: Unknown result type (might be due to invalid IL or missing references) //IL_00f2: Unknown result type (might be due to invalid IL or missing references) //IL_0105: Unknown result type (might be due to invalid IL or missing references) //IL_0114: Unknown result type (might be due to invalid IL or missing references) //IL_0115: Unknown result type (might be due to invalid IL or missing references) //IL_0117: Unknown result type (might be due to invalid IL or missing references) //IL_011c: Unknown result type (might be due to invalid IL or missing references) //IL_0150: Unknown result type (might be due to invalid IL or missing references) //IL_0152: Unknown result type (might be due to invalid IL or missing references) //IL_015a: Unknown result type (might be due to invalid IL or missing references) //IL_015f: Unknown result type (might be due to invalid IL or missing references) //IL_0167: Unknown result type (might be due to invalid IL or missing references) //IL_016e: Unknown result type (might be due to invalid IL or missing references) //IL_0190: Unknown result type (might be due to invalid IL or missing references) //IL_0195: Unknown result type (might be due to invalid IL or missing references) //IL_0199: Unknown result type (might be due to invalid IL or missing references) //IL_01a7: Unknown result type (might be due to invalid IL or missing references) //IL_01bb: Unknown result type (might be due to invalid IL or missing references) //IL_01c2: Unknown result type (might be due to invalid IL or missing references) //IL_01db: Unknown result type (might be due to invalid IL or missing references) //IL_01e0: Unknown result type (might be due to invalid IL or missing references) //IL_01e3: Unknown result type (might be due to invalid IL or missing references) //IL_01e5: Unknown result type (might be due to invalid IL or missing references) //IL_01e8: Unknown result type (might be due to invalid IL or missing references) //IL_01ed: Unknown result type (might be due to invalid IL or missing references) //IL_01f8: 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_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_0281: Unknown result type (might be due to invalid IL or missing references) //IL_0285: Unknown result type (might be due to invalid IL or missing references) //IL_028a: 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_0294: Unknown result type (might be due to invalid IL or missing references) //IL_0296: Unknown result type (might be due to invalid IL or missing references) //IL_029b: Unknown result type (might be due to invalid IL or missing references) //IL_029f: Unknown result type (might be due to invalid IL or missing references) //IL_02ac: Unknown result type (might be due to invalid IL or missing references) //IL_02b1: 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_02bd: Unknown result type (might be due to invalid IL or missing references) //IL_02c2: Unknown result type (might be due to invalid IL or missing references) //IL_02c9: Unknown result type (might be due to invalid IL or missing references) //IL_02cb: Unknown result type (might be due to invalid IL or missing references) //IL_02db: 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_02f0: Unknown result type (might be due to invalid IL or missing references) //IL_02f5: Unknown result type (might be due to invalid IL or missing references) //IL_02f7: Unknown result type (might be due to invalid IL or missing references) //IL_030f: Unknown result type (might be due to invalid IL or missing references) //IL_0324: Unknown result type (might be due to invalid IL or missing references) //IL_0387: Unknown result type (might be due to invalid IL or missing references) //IL_0399: Unknown result type (might be due to invalid IL or missing references) //IL_039e: Unknown result type (might be due to invalid IL or missing references) //IL_03b2: Unknown result type (might be due to invalid IL or missing references) //IL_03c4: Unknown result type (might be due to invalid IL or missing references) //IL_03c9: Unknown result type (might be due to invalid IL or missing references) //IL_03ce: Unknown result type (might be due to invalid IL or missing references) //IL_03d6: Unknown result type (might be due to invalid IL or missing references) float num = 0.006f * set.Size; List list = new List(); List list2 = new List(); List> list3 = new List>(); float x = dir.x; float y = dir.y; for (float num2 = Mathf.Max(0.05f, OutfitEdge(d, x, y) * 0.97f); num2 < 0.95f; num2 += 0.025f) { Vector3 val = Surface(d, num2, x, y); Vector3 val2 = SurfaceNormal(d, num2, x, y); list.Add(val + val2 * num); list2.Add(val2); list3.Add(DomeWeights(d, val, y * Mathf.Sin(num2 * (float)Math.PI))); if (Above(val) < 0.02f * set.Size) { break; } } if (list.Count == 0) { return; } Vector2 val3 = default(Vector2); ((Vector2)(ref val3))..ctor(list[list.Count - 1].x, list[list.Count - 1].y); Vector2 val4 = target - val3; float magnitude = ((Vector2)(ref val4)).magnitude; int num3 = Mathf.Max(1, Mathf.CeilToInt(magnitude / (0.08f * set.Size))); for (int i = 1; i <= num3; i++) { Vector2 val5 = Vector2.Lerp(val3, target, (float)i / (float)num3); BodyMap.Hit h = body.At(val5.x, val5.y); if (!h.Ok) { break; } Vector3 val6 = body.Point(h); val6.x = val5.x; val6.y = val5.y; val6.z = body.Height(val5.x, val5.y); Vector3 val7 = body.Normal(h); list.Add(val6 + val7 * num); list2.Add(val7); Dictionary dictionary = new Dictionary(); body.AddWeights(h, 1f, dictionary); list3.Add(dictionary); } if (list.Count < 2) { return; } int count = res.Verts.Count; for (int j = 0; j < list.Count; j++) { Vector3 val8 = list[Mathf.Min(j + 1, list.Count - 1)] - list[Mathf.Max(j - 1, 0)]; Vector3 normalized = ((Vector3)(ref val8)).normalized; val8 = Vector3.Cross(list2[j], normalized); Vector3 val9 = ((Vector3)(ref val8)).normalized * (0.5f * width); Vector3[] array = (Vector3[])(object)new Vector3[2] { -val9, val9 }; foreach (Vector3 val10 in array) { res.Verts.Add(list[j] + val10); res.Normals.Add(list2[j]); res.UV.Add(Vector2.zero); res.Weights.Add(list3[j]); } } for (int l = 0; l + 1 < list.Count; l++) { int num4 = count + 2 * l; if (Vector3.Dot(Vector3.Cross(res.Verts[num4 + 2] - res.Verts[num4], res.Verts[num4 + 1] - res.Verts[num4]), list2[l]) >= 0f) { Tri(num4, num4 + 2, num4 + 1); Tri(num4 + 1, num4 + 2, num4 + 3); } else { Tri(num4, num4 + 1, num4 + 2); Tri(num4 + 1, num4 + 3, num4 + 2); } } void Tri(int a, int b, int c) { res.Fabric.Add(a); res.Fabric.Add(b); res.Fabric.Add(c); } } private Vector3 SurfaceNormal(Dome d, float rho, float cosT, float sinT) { //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_003b: 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_0066: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Unknown result type (might be due to invalid IL or missing references) //IL_0091: Unknown result type (might be due to invalid IL or missing references) //IL_0096: Unknown result type (might be due to invalid IL or missing references) //IL_0097: 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_009e: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: 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_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00b1: 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_00b5: 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_00bc: 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_00cd: Unknown result type (might be due to invalid IL or missing references) float num = Mathf.Atan2(sinT, cosT); Vector3 val = Surface(d, Mathf.Max(0f, rho - 0.01f), cosT, sinT); Vector3 val2 = Surface(d, Mathf.Min(1f, rho + 0.01f), cosT, sinT); Vector3 val3 = Surface(d, Mathf.Max(rho, 0.02f), Mathf.Cos(num - 0.04f), Mathf.Sin(num - 0.04f)); Vector3 val4 = Vector3.Cross(Surface(d, Mathf.Max(rho, 0.02f), Mathf.Cos(num + 0.04f), Mathf.Sin(num + 0.04f)) - val3, val2 - val); Vector3 normalized = ((Vector3)(ref val4)).normalized; if (!(Vector3.Dot(normalized, val - d.M) < 0f)) { return normalized; } return -normalized; } } public class JiggleSim { public struct Params { public float Stiffness; public float Damping; public float Gravity; public float Exaggeration; } public struct Capsule { public Vector3 A; public Vector3 B; public float R; } private class Side { public Vector3 Pos; public Vector3 Vel; public Vector3 PrevAnchor; public Vector3 AnchorVel; public Vector3 LowPos; public Vector3 LowVel; public Vector3 MassAccel; } private readonly Side[] sides = new Side[2] { new Side(), new Side() }; private Vector3 prevOrigin; private Vector3 originVel; private Vector3 prevOriginVel; private Vector3 frameAccel; private bool primed; public readonly Vector3[] Offset = (Vector3[])(object)new Vector3[2]; public readonly Vector3[] Low = (Vector3[])(object)new Vector3[2]; public void Reset() { primed = false; } public void Step(float dt, Matrix4x4 rigToWorld, Matrix4x4 worldToRig, Vector3 origin, Vector3[] tipRest, float W, Params p, Capsule[] caps, int capCount) { //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_009d: Unknown result type (might be due to invalid IL or missing references) //IL_00a0: 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_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_00c3: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: Unknown result type (might be due to invalid IL or missing references) //IL_00ce: 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_00d9: Unknown result type (might be due to invalid IL or missing references) //IL_00df: Unknown result type (might be due to invalid IL or missing references) //IL_00e9: Unknown result type (might be due to invalid IL or missing references) //IL_00ee: Unknown result type (might be due to invalid IL or missing references) //IL_00f2: Unknown result type (might be due to invalid IL or missing references) //IL_00f7: Unknown result type (might be due to invalid IL or missing references) //IL_010c: Unknown result type (might be due to invalid IL or missing references) //IL_0111: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_0078: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_0080: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Unknown result type (might be due to invalid IL or missing references) //IL_0085: 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_008c: 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_0119: 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_0125: Unknown result type (might be due to invalid IL or missing references) //IL_0148: Unknown result type (might be due to invalid IL or missing references) //IL_0157: Unknown result type (might be due to invalid IL or missing references) //IL_015c: Unknown result type (might be due to invalid IL or missing references) //IL_0166: Unknown result type (might be due to invalid IL or missing references) //IL_016b: Unknown result type (might be due to invalid IL or missing references) //IL_0170: Unknown result type (might be due to invalid IL or missing references) //IL_018b: Unknown result type (might be due to invalid IL or missing references) //IL_0190: Unknown result type (might be due to invalid IL or missing references) //IL_0195: Unknown result type (might be due to invalid IL or missing references) //IL_01ef: Unknown result type (might be due to invalid IL or missing references) //IL_01f4: Unknown result type (might be due to invalid IL or missing references) //IL_01f8: Unknown result type (might be due to invalid IL or missing references) //IL_01fd: 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_021b: Unknown result type (might be due to invalid IL or missing references) //IL_0220: Unknown result type (might be due to invalid IL or missing references) //IL_0227: Unknown result type (might be due to invalid IL or missing references) //IL_0229: Unknown result type (might be due to invalid IL or missing references) //IL_019e: Unknown result type (might be due to invalid IL or missing references) //IL_01a0: Unknown result type (might be due to invalid IL or missing references) //IL_01a1: Unknown result type (might be due to invalid IL or missing references) //IL_01a3: Unknown result type (might be due to invalid IL or missing references) //IL_01a8: Unknown result type (might be due to invalid IL or missing references) //IL_01aa: 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_01be: 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_01c1: 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_01c8: 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_01cb: Unknown result type (might be due to invalid IL or missing references) //IL_01d0: 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_01d3: 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_01dd: Unknown result type (might be due to invalid IL or missing references) //IL_01df: Unknown result type (might be due to invalid IL or missing references) //IL_01e4: Unknown result type (might be due to invalid IL or missing references) //IL_01e6: Unknown result type (might be due to invalid IL or missing references) //IL_029d: Unknown result type (might be due to invalid IL or missing references) //IL_02a2: Unknown result type (might be due to invalid IL or missing references) //IL_02a6: 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_02c8: Unknown result type (might be due to invalid IL or missing references) //IL_02ca: Unknown result type (might be due to invalid IL or missing references) //IL_02d3: Unknown result type (might be due to invalid IL or missing references) //IL_02da: Unknown result type (might be due to invalid IL or missing references) //IL_02df: Unknown result type (might be due to invalid IL or missing references) //IL_02e4: Unknown result type (might be due to invalid IL or missing references) //IL_02e9: Unknown result type (might be due to invalid IL or missing references) //IL_02ee: Unknown result type (might be due to invalid IL or missing references) //IL_02f0: Unknown result type (might be due to invalid IL or missing references) //IL_02f5: Unknown result type (might be due to invalid IL or missing references) //IL_02fa: Unknown result type (might be due to invalid IL or missing references) //IL_02ff: Unknown result type (might be due to invalid IL or missing references) //IL_0303: Unknown result type (might be due to invalid IL or missing references) //IL_0308: Unknown result type (might be due to invalid IL or missing references) //IL_030d: Unknown result type (might be due to invalid IL or missing references) //IL_0314: Unknown result type (might be due to invalid IL or missing references) //IL_031b: Unknown result type (might be due to invalid IL or missing references) //IL_0320: 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_0552: Unknown result type (might be due to invalid IL or missing references) //IL_0557: Unknown result type (might be due to invalid IL or missing references) //IL_0559: Unknown result type (might be due to invalid IL or missing references) //IL_055e: Unknown result type (might be due to invalid IL or missing references) //IL_0563: 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_057e: Unknown result type (might be due to invalid IL or missing references) //IL_035d: Unknown result type (might be due to invalid IL or missing references) //IL_0364: Unknown result type (might be due to invalid IL or missing references) //IL_036b: Unknown result type (might be due to invalid IL or missing references) //IL_0370: Unknown result type (might be due to invalid IL or missing references) //IL_0375: Unknown result type (might be due to invalid IL or missing references) //IL_0377: Unknown result type (might be due to invalid IL or missing references) //IL_037c: Unknown result type (might be due to invalid IL or missing references) //IL_0381: Unknown result type (might be due to invalid IL or missing references) //IL_0385: Unknown result type (might be due to invalid IL or missing references) //IL_038f: Unknown result type (might be due to invalid IL or missing references) //IL_0394: Unknown result type (might be due to invalid IL or missing references) //IL_0396: Unknown result type (might be due to invalid IL or missing references) //IL_0398: Unknown result type (might be due to invalid IL or missing references) //IL_0339: 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_034a: Unknown result type (might be due to invalid IL or missing references) //IL_034f: Unknown result type (might be due to invalid IL or missing references) //IL_0354: Unknown result type (might be due to invalid IL or missing references) //IL_03fe: Unknown result type (might be due to invalid IL or missing references) //IL_0402: Unknown result type (might be due to invalid IL or missing references) //IL_0404: Unknown result type (might be due to invalid IL or missing references) //IL_0409: Unknown result type (might be due to invalid IL or missing references) //IL_040e: Unknown result type (might be due to invalid IL or missing references) //IL_0417: Unknown result type (might be due to invalid IL or missing references) //IL_041e: Unknown result type (might be due to invalid IL or missing references) //IL_0423: Unknown result type (might be due to invalid IL or missing references) //IL_0425: Unknown result type (might be due to invalid IL or missing references) //IL_042c: Unknown result type (might be due to invalid IL or missing references) //IL_0433: Unknown result type (might be due to invalid IL or missing references) //IL_0438: Unknown result type (might be due to invalid IL or missing references) //IL_0440: Unknown result type (might be due to invalid IL or missing references) //IL_0469: Unknown result type (might be due to invalid IL or missing references) //IL_046e: Unknown result type (might be due to invalid IL or missing references) //IL_0477: Unknown result type (might be due to invalid IL or missing references) //IL_047c: Unknown result type (might be due to invalid IL or missing references) //IL_0481: Unknown result type (might be due to invalid IL or missing references) //IL_0488: Unknown result type (might be due to invalid IL or missing references) //IL_048d: 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_0498: Unknown result type (might be due to invalid IL or missing references) //IL_049d: Unknown result type (might be due to invalid IL or missing references) //IL_04a4: Unknown result type (might be due to invalid IL or missing references) //IL_04a9: Unknown result type (might be due to invalid IL or missing references) //IL_04ae: Unknown result type (might be due to invalid IL or missing references) //IL_04b6: Unknown result type (might be due to invalid IL or missing references) //IL_04bd: Unknown result type (might be due to invalid IL or missing references) //IL_04c4: Unknown result type (might be due to invalid IL or missing references) //IL_04c9: Unknown result type (might be due to invalid IL or missing references) //IL_04ce: Unknown result type (might be due to invalid IL or missing references) //IL_03a3: Unknown result type (might be due to invalid IL or missing references) //IL_03a5: Unknown result type (might be due to invalid IL or missing references) //IL_03a7: Unknown result type (might be due to invalid IL or missing references) //IL_03ac: Unknown result type (might be due to invalid IL or missing references) //IL_03b1: Unknown result type (might be due to invalid IL or missing references) //IL_03b5: Unknown result type (might be due to invalid IL or missing references) //IL_03ba: Unknown result type (might be due to invalid IL or missing references) //IL_03be: 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_03cf: 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_04f2: 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_04fa: Unknown result type (might be due to invalid IL or missing references) //IL_04ff: Unknown result type (might be due to invalid IL or missing references) //IL_0506: Unknown result type (might be due to invalid IL or missing references) //IL_050b: Unknown result type (might be due to invalid IL or missing references) //IL_03e4: Unknown result type (might be due to invalid IL or missing references) //IL_03e9: Unknown result type (might be due to invalid IL or missing references) //IL_03ed: Unknown result type (might be due to invalid IL or missing references) //IL_03f2: Unknown result type (might be due to invalid IL or missing references) //IL_03f7: Unknown result type (might be due to invalid IL or missing references) //IL_0520: Unknown result type (might be due to invalid IL or missing references) //IL_0525: Unknown result type (might be due to invalid IL or missing references) //IL_0529: Unknown result type (might be due to invalid IL or missing references) //IL_052e: Unknown result type (might be due to invalid IL or missing references) //IL_0533: Unknown result type (might be due to invalid IL or missing references) dt = Mathf.Min(dt, 0.05f); if (dt <= 0f) { return; } Vector3 val = ((Matrix4x4)(ref rigToWorld)).MultiplyVector(Vector3.right); float magnitude = ((Vector3)(ref val)).magnitude; int num = Mathf.Clamp(Mathf.CeilToInt(dt * 120f), 1, 6); int num2; if (primed) { val = origin - prevOrigin; num2 = ((((Vector3)(ref val)).sqrMagnitude > 25f * magnitude * magnitude) ? 1 : 0); } else { num2 = 1; } bool flag = (byte)num2 != 0; if (flag) { val = (frameAccel = Vector3.zero); val = (originVel = (prevOriginVel = val)); } else { originVel = Vector3.Lerp(originVel, (origin - prevOrigin) / dt, 1f - Mathf.Exp((0f - dt) / 0.03f)); Vector3 val2 = Vector3.ClampMagnitude((originVel - prevOriginVel) / dt, 100f); frameAccel = Vector3.Lerp(frameAccel, val2, 1f - Mathf.Exp((0f - dt) / 0.06f)); } prevOrigin = origin; prevOriginVel = originVel; Vector3 val3 = default(Vector3); ((Vector3)(ref val3))..ctor(0f, -9.81f * p.Gravity, 0f); Vector3 val4 = val3 - Vector3.ClampMagnitude((p.Exaggeration - 1f) * frameAccel, 20f); for (int i = 0; i < 2; i++) { Side side = sides[i]; Vector3 val5 = ((Matrix4x4)(ref rigToWorld)).MultiplyPoint3x4(tipRest[i]); if (flag) { val = (side.Pos = (side.PrevAnchor = val5)); val = (side.MassAccel = Vector3.zero); val = (side.LowVel = val); val = (side.LowPos = val); val = (side.Vel = (side.AnchorVel = val)); } side.AnchorVel = Vector3.Lerp(side.AnchorVel, (val5 - side.PrevAnchor) / dt, 1f - Mathf.Exp((0f - dt) / 0.03f)); side.PrevAnchor = val5; float num3 = dt / (float)num; float num4 = W * magnitude; float stiffness = p.Stiffness; float damping = p.Damping; float num5 = 1f / (0.04f * num4 * num4); float num6 = stiffness * 2.5f; float num7 = 0.12f * num4; float num8 = 1f - Mathf.Exp((0f - num3) / 0.03f); float num9 = 1.5f * num4; for (int j = 0; j < num; j++) { Vector3 vel = side.Vel; Vector3 val6 = side.Pos - val5; Vector3 val7 = (0f - stiffness) * (1f + ((Vector3)(ref val6)).sqrMagnitude * num5) * val6 - damping * (side.Vel - side.AnchorVel) + val4; side.Vel += val7 * num3; Vector3 val8 = side.Vel - side.AnchorVel; if (((Vector3)(ref val8)).sqrMagnitude > num9 * num9) { side.Vel = side.AnchorVel + val8 * (num9 / ((Vector3)(ref val8)).magnitude); } Vector3 val9 = ((Matrix4x4)(ref worldToRig)).MultiplyVector(side.Pos + side.Vel * num3 - val5); Vector3 val10 = Constrain(i, val9, W, tipRest, caps, capCount); if (val10 != val9) { val = ((Matrix4x4)(ref rigToWorld)).MultiplyVector(val10 - val9); Vector3 normalized = ((Vector3)(ref val)).normalized; float num10 = Vector3.Dot(side.Vel - side.AnchorVel, normalized); if (num10 < 0f) { side.Vel -= normalized * num10; } } side.Pos = val5 + ((Matrix4x4)(ref rigToWorld)).MultiplyVector(val10); side.MassAccel = Vector3.Lerp(side.MassAccel, (side.Vel - vel) / num3, num8); side.LowVel += ((0f - num6) * (1f + ((Vector3)(ref side.LowPos)).sqrMagnitude / (0.25f * num7 * num7)) * side.LowPos - damping * side.LowVel - side.MassAccel + val3 * 0.3f) * num3; side.LowPos += side.LowVel * num3; if (((Vector3)(ref side.LowPos)).sqrMagnitude > num7 * num7) { Vector3 normalized2 = ((Vector3)(ref side.LowPos)).normalized; side.LowPos = normalized2 * num7; float num11 = Vector3.Dot(side.LowVel, normalized2); if (num11 > 0f) { side.LowVel -= normalized2 * num11; } } } Offset[i] = ((Matrix4x4)(ref worldToRig)).MultiplyVector(side.Pos - val5); Low[i] = ((Matrix4x4)(ref worldToRig)).MultiplyVector(side.LowPos); } primed = true; } private static Vector3 Constrain(int k, Vector3 d, float W, Vector3[] tipRest, Capsule[] caps, int capCount) { //IL_0000: 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_000d: 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_003c: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0064: 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_006a: Unknown result type (might be due to invalid IL or missing references) //IL_0080: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Unknown result type (might be due to invalid IL or missing references) //IL_0088: 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_008b: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Unknown result type (might be due to invalid IL or missing references) //IL_00e7: Unknown result type (might be due to invalid IL or missing references) //IL_00ef: Unknown result type (might be due to invalid IL or missing references) //IL_00c6: Unknown result type (might be due to invalid IL or missing references) //IL_00c7: Unknown result type (might be due to invalid IL or missing references) //IL_00cb: 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_00d7: Unknown result type (might be due to invalid IL or missing references) //IL_00dc: Unknown result type (might be due to invalid IL or missing references) d = Vector3.ClampMagnitude(d, 0.35f * W); if (d.z < -0.12f * W) { d.z = -0.12f * W; } float num = ((k == 0) ? 1f : (-1f)); if (d.x * num > 0.06f * W) { d.x = num * 0.06f * W; } Vector3 val = tipRest[k] + d; float num2 = 0.38f * W; for (int i = 0; i < capCount; i++) { Capsule cap = caps[i]; Vector3 val2 = Closest(cap, val); Vector3 val3 = val - val2; float magnitude = ((Vector3)(ref val3)).magnitude; float num3 = cap.R + num2; if (magnitude < num3 && magnitude > 1E-05f) { float num4 = Mathf.Min(num3 - magnitude, 0.3f * W); d += val3 / magnitude * num4; } } return Vector3.ClampMagnitude(d, 0.4f * W); } private static Vector3 Closest(Capsule cap, Vector3 x) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0011: 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_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_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) Vector3 val = cap.B - cap.A; return cap.A + val * Mathf.Clamp01(Vector3.Dot(x - cap.A, val) / Mathf.Max(((Vector3)(ref val)).sqrMagnitude, 1E-06f)); } } [BepInPlugin("cyntrex.TrollChests", "BigTiddyTrolls", "2.0.0")] public class Plugin : BaseUnityPlugin { private const string Guid = "cyntrex.TrollChests"; private const string Version = "2.0.0"; internal static ManualLogSource Log; internal static ConfigEntry BoneName; internal static ConfigEntry OutfitChoice; internal static ConfigEntry Size; internal static ConfigEntry Projection; internal static ConfigEntry Sag; internal static ConfigEntry Forward; internal static ConfigEntry Up; internal static ConfigEntry Spacing; internal static ConfigEntry Stiffness; internal static ConfigEntry Damping; internal static ConfigEntry Exaggeration; internal static ConfigEntry Gravity; private Harmony harmony; private FileSystemWatcher watcher; private volatile bool fileChanged; private float reloadAt = -1f; private void Awake() { //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Expected O, but got Unknown //IL_00a7: Unknown result type (might be due to invalid IL or missing references) //IL_00b1: Expected O, but got Unknown //IL_00e4: Unknown result type (might be due to invalid IL or missing references) //IL_00ee: Expected O, but got Unknown //IL_018d: Unknown result type (might be due to invalid IL or missing references) //IL_0197: Expected O, but got Unknown //IL_01ca: Unknown result type (might be due to invalid IL or missing references) //IL_01d4: Expected O, but got Unknown //IL_0207: Unknown result type (might be due to invalid IL or missing references) //IL_0211: Expected O, but got Unknown //IL_0244: Unknown result type (might be due to invalid IL or missing references) //IL_024e: Expected O, but got Unknown Log = ((BaseUnityPlugin)this).Logger; BoneName = ((BaseUnityPlugin)this).Config.Bind("Placement", "BoneName", "", "Bone to attach to. Empty = auto (deepest bone named chest/spine). Bone lists are printed to the log."); Size = ((BaseUnityPlugin)this).Config.Bind("Placement", "Size", 1.8f, new ConfigDescription("Width of each breast, in meters at troll scale 1.", (AcceptableValueBase)(object)new AcceptableValueRange(0.3f, 3f), Array.Empty())); Projection = ((BaseUnityPlugin)this).Config.Bind("Placement", "Projection", 0.6f, new ConfigDescription("How far they stick out, as a fraction of their width.", (AcceptableValueBase)(object)new AcceptableValueRange(0.2f, 1.2f), Array.Empty())); Sag = ((BaseUnityPlugin)this).Config.Bind("Placement", "Sag", 0.6f, new ConfigDescription("How much the shape hangs (0 = perky, 1 = heavy).", (AcceptableValueBase)(object)new AcceptableValueRange(0f, 1f), Array.Empty())); Forward = ((BaseUnityPlugin)this).Config.Bind("Placement", "Forward", 0f, "Push the bulk out (+) or in (-) from the chest, in meters."); Up = ((BaseUnityPlugin)this).Config.Bind("Placement", "Up", -0.8f, "Height on the chest, relative to the chest bone, in meters."); Spacing = ((BaseUnityPlugin)this).Config.Bind("Placement", "Spacing", 0f, "Extra gap between the two sides, in meters (0 = they meet at the cleavage)."); Stiffness = ((BaseUnityPlugin)this).Config.Bind("Physics", "Stiffness", 30f, new ConfigDescription("How firmly they hold their position. Lower = heavier, slower, floppier.", (AcceptableValueBase)(object)new AcceptableValueRange(5f, 150f), Array.Empty())); Damping = ((BaseUnityPlugin)this).Config.Bind("Physics", "Damping", 4f, new ConfigDescription("How fast the wobble dies down. Lower = keeps bouncing longer.", (AcceptableValueBase)(object)new AcceptableValueRange(0.5f, 20f), Array.Empty())); Gravity = ((BaseUnityPlugin)this).Config.Bind("Physics", "Gravity", 1f, new ConfigDescription("How hard gravity pulls them down while moving. Higher = saggier.", (AcceptableValueBase)(object)new AcceptableValueRange(0f, 3f), Array.Empty())); Exaggeration = ((BaseUnityPlugin)this).Config.Bind("Physics", "Exaggeration", 1.5f, new ConfigDescription("Extra throw from the troll's own movement, on top of real inertia (capped). 1 = physically real.", (AcceptableValueBase)(object)new AcceptableValueRange(1f, 4f), Array.Empty())); OutfitChoice = ((BaseUnityPlugin)this).Config.Bind("Look", "Outfit", Outfit.Bikini, "Bikini: micro bikini. HalterTop: a deep-V halter top."); ConfigEntryBase[] shape = (ConfigEntryBase[])(object)new ConfigEntryBase[8] { (ConfigEntryBase)BoneName, (ConfigEntryBase)Size, (ConfigEntryBase)Projection, (ConfigEntryBase)Sag, (ConfigEntryBase)Forward, (ConfigEntryBase)Up, (ConfigEntryBase)Spacing, (ConfigEntryBase)OutfitChoice }; ((BaseUnityPlugin)this).Config.SettingChanged += delegate(object _, SettingChangedEventArgs e) { if (Array.IndexOf(shape, e.ChangedSetting) >= 0) { Reattach(); } }; try { watcher = new FileSystemWatcher(Path.GetDirectoryName(((BaseUnityPlugin)this).Config.ConfigFilePath), Path.GetFileName(((BaseUnityPlugin)this).Config.ConfigFilePath)); watcher.Changed += delegate { fileChanged = true; }; watcher.EnableRaisingEvents = true; } catch (Exception ex) { Log.LogWarning((object)("Not watching the config file: " + ex.Message)); } harmony = Harmony.CreateAndPatchAll(typeof(Plugin), "cyntrex.TrollChests"); foreach (Character allCharacter in Character.GetAllCharacters()) { Rig.TryAttach(allCharacter); } } private static void Reattach() { Rig.DetachAll(); foreach (Character allCharacter in Character.GetAllCharacters()) { Rig.TryAttach(allCharacter); } } private void Update() { if (fileChanged) { fileChanged = false; reloadAt = Time.realtimeSinceStartup + 0.3f; } if (reloadAt > 0f && Time.realtimeSinceStartup >= reloadAt) { reloadAt = -1f; try { ((BaseUnityPlugin)this).Config.Reload(); Log.LogInfo((object)"Config file changed, reloaded"); } catch (Exception ex) { Log.LogWarning((object)("Couldn't reload the config: " + ex.Message)); } } } private void OnDestroy() { watcher?.Dispose(); Harmony obj = harmony; if (obj != null) { obj.UnpatchSelf(); } Rig.DetachAll(); } [HarmonyPostfix] [HarmonyPriority(0)] [HarmonyPatch(typeof(Character), "Awake")] private static void CharacterAwake(Character __instance) { Rig.TryAttach(__instance); } } public class Rig : MonoBehaviour { private class Kind { public Matrix4x4 MeshToRig; public Matrix4x4 RigToSpine; public BodyMap Map; public bool Skinned; public readonly Dictionary Meshes = new Dictionary(); } private class Built { public Mesh Mesh; public ChestBuilder.Result R; } private const float MaxSimDistance = 80f; private const float ArmThickness = 0.3f; private static readonly string[] armBones = new string[6] { "LeftArm", "LeftForeArm", "LeftHand", "RightArm", "RightForeArm", "RightHand" }; private static readonly List all = new List(); private static readonly HashSet dumped = new HashSet(); private static readonly Dictionary kinds = new Dictionary(); private static readonly Dictionary topMaterials = new Dictionary(); private Transform spine; private Matrix4x4 rigToSpine; private Quaternion rigRot; private SkinnedMeshRenderer smr; private LODGroup lodGroup; private readonly Transform[] pivots = (Transform[])(object)new Transform[2]; private readonly Transform[] tips = (Transform[])(object)new Transform[2]; private readonly JiggleSim sim = new JiggleSim(); private ChestBuilder.Result built; private Transform[] arms; private readonly JiggleSim.Capsule[] capsules = new JiggleSim.Capsule[4]; private bool atRest; private static readonly Color Straw = new Color(0.78f, 0.66f, 0.38f); public static void TryAttach(Character c) { if ((Object)(object)c == (Object)null || c is Player || (!IsTroll(c.m_name) && !IsTroll(((Object)((Component)c).gameObject).name)) || (Object)(object)((Component)c).GetComponentInChildren(true) != (Object)null) { return; } try { Attach(c); } catch (Exception arg) { Plugin.Log.LogError((object)$"Couldn't attach to {((Object)((Component)c).gameObject).name}: {arg}"); } } private static void Attach(Character c) { //IL_00ca: Unknown result type (might be due to invalid IL or missing references) //IL_00cf: Unknown result type (might be due to invalid IL or missing references) //IL_00da: Unknown result type (might be due to invalid IL or missing references) //IL_00df: Unknown result type (might be due to invalid IL or missing references) //IL_00e4: Unknown result type (might be due to invalid IL or missing references) //IL_00e7: Unknown result type (might be due to invalid IL or missing references) //IL_00f1: Unknown result type (might be due to invalid IL or missing references) //IL_00f2: Unknown result type (might be due to invalid IL or missing references) //IL_00f7: 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_010a: Unknown result type (might be due to invalid IL or missing references) //IL_0117: Unknown result type (might be due to invalid IL or missing references) //IL_011c: Unknown result type (might be due to invalid IL or missing references) //IL_011e: Unknown result type (might be due to invalid IL or missing references) //IL_0125: Unknown result type (might be due to invalid IL or missing references) //IL_012a: Unknown result type (might be due to invalid IL or missing references) //IL_012f: Unknown result type (might be due to invalid IL or missing references) //IL_0133: Unknown result type (might be due to invalid IL or missing references) //IL_0180: Unknown result type (might be due to invalid IL or missing references) //IL_0187: Expected O, but got Unknown //IL_01c4: 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_01cd: Unknown result type (might be due to invalid IL or missing references) //IL_01cf: Unknown result type (might be due to invalid IL or missing references) //IL_03a2: Unknown result type (might be due to invalid IL or missing references) //IL_03a7: Unknown result type (might be due to invalid IL or missing references) //IL_03af: Unknown result type (might be due to invalid IL or missing references) //IL_03b4: 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_03d7: 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_0347: Unknown result type (might be due to invalid IL or missing references) //IL_034c: 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_0357: Unknown result type (might be due to invalid IL or missing references) //IL_036d: Unknown result type (might be due to invalid IL or missing references) //IL_01fa: Unknown result type (might be due to invalid IL or missing references) //IL_0221: 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_0232: Unknown result type (might be due to invalid IL or missing references) //IL_023b: Unknown result type (might be due to invalid IL or missing references) //IL_0242: Unknown result type (might be due to invalid IL or missing references) //IL_03ff: Unknown result type (might be due to invalid IL or missing references) //IL_025c: Unknown result type (might be due to invalid IL or missing references) //IL_0282: Unknown result type (might be due to invalid IL or missing references) //IL_0295: Unknown result type (might be due to invalid IL or missing references) //IL_029a: Unknown result type (might be due to invalid IL or missing references) Transform[] bones = ((Component)((Component)c).transform).GetComponentsInChildren(true); if (dumped.Add(((Object)((Component)c).gameObject).name)) { Plugin.Log.LogDebug((object)("Bones of " + ((Object)((Component)c).gameObject).name + ": " + string.Join(", ", bones.Select((Transform b) => ((Object)b).name)))); } SkinnedMeshRenderer val = Body(c); if ((Object)(object)val == (Object)null) { Plugin.Log.LogWarning((object)(((Object)((Component)c).gameObject).name + ": no body mesh, skipped")); return; } Transform val2 = FindBone(bones, ((Component)c).transform); Quaternion val3 = Quaternion.Inverse(val2.rotation) * ((Component)c).transform.rotation; Quaternion val4 = BindFrame(val, val2, val3) ?? val3; float num = ((Component)c).transform.lossyScale.x / val2.lossyScale.x; Matrix4x4 val5 = Matrix4x4.TRS(Vector3.zero, val4, Vector3.one * num); Kind kind = GetKind(val, val2, val5, ((Object)((Component)c).gameObject).name); ChestBuilder.Settings settings = CurrentSettings(); if (!kind.Meshes.TryGetValue(settings, out var value)) { value = (kind.Meshes[settings] = BuildMesh(kind, val, settings)); } GameObject val6 = new GameObject("TrollChests"); val6.layer = ((Component)val).gameObject.layer; val6.transform.SetParent(((Component)val).transform.parent, false); Rig rig = val6.AddComponent(); rig.spine = val2; rig.rigToSpine = val5; rig.rigRot = val4; rig.built = value.R; for (int num2 = 0; num2 < 2; num2++) { Transform transform = new GameObject((num2 == 0) ? "TrollChests_PivotL" : "TrollChests_PivotR").transform; transform.SetParent(val2, false); transform.localPosition = ((Matrix4x4)(ref val5)).MultiplyPoint3x4(value.R.PivotPos[num2]); transform.localRotation = val4; transform.localScale = Vector3.one * num; Transform transform2 = new GameObject((num2 == 0) ? "TrollChests_TipL" : "TrollChests_TipR").transform; transform2.SetParent(transform, false); transform2.localPosition = value.R.TipPos[num2] - value.R.PivotPos[num2]; rig.pivots[num2] = transform; rig.tips[num2] = transform2; } SkinnedMeshRenderer val7 = (rig.smr = val6.AddComponent()); Transform[] second = (Transform[])(object)new Transform[4] { rig.pivots[0], rig.tips[0], rig.pivots[1], rig.tips[1] }; Vector3 size; if (kind.Skinned) { val7.bones = val.bones.Concat(second).ToArray(); val7.rootBone = val.rootBone; Bounds localBounds = ((Renderer)val).localBounds; size = ((Bounds)(ref localBounds)).size; ((Bounds)(ref localBounds)).Expand(((Vector3)(ref size)).magnitude * 0.3f); ((Renderer)val7).localBounds = localBounds; } else { val7.bones = ((IEnumerable)(object)new Transform[1] { val2 }).Concat(second).ToArray(); val7.rootBone = val2; Bounds bounds = value.Mesh.bounds; Vector3 val8 = ((Matrix4x4)(ref val5)).MultiplyPoint3x4(((Bounds)(ref bounds)).center); Vector3 one = Vector3.one; size = ((Bounds)(ref bounds)).size; ((Renderer)val7).localBounds = new Bounds(val8, one * (((Vector3)(ref size)).magnitude * num * 1.5f)); } val7.sharedMesh = value.Mesh; val7.updateWhenOffscreen = false; ((Renderer)val7).shadowCastingMode = ((Renderer)val).shadowCastingMode; ((Renderer)val7).receiveShadows = ((Renderer)val).receiveShadows; Material sharedMaterial = ((Renderer)val).sharedMaterial; ((Renderer)val7).sharedMaterials = (Material[])(object)new Material[2] { sharedMaterial, TopMaterial(c, sharedMaterial) }; LODGroup componentInChildren = ((Component)c).GetComponentInChildren(); if ((Object)(object)componentInChildren != (Object)null) { LOD[] lODs = componentInChildren.GetLODs(); for (int num3 = 0; num3 < lODs.Length; num3++) { if (lODs[num3].renderers != null && lODs[num3].renderers.Contains((Renderer)(object)val)) { lODs[num3].renderers = lODs[num3].renderers.Concat((IEnumerable)(object)new Renderer[1] { (Renderer)val7 }).ToArray(); } } componentInChildren.SetLODs(lODs); rig.lodGroup = componentInChildren; } Transform[] source = armBones.Select((string n) => ((IEnumerable)bones).FirstOrDefault((Func)((Transform x) => ((Object)x).name == n))).ToArray(); if (source.All((Transform x) => (Object)(object)x != (Object)null)) { rig.arms = source; } all.Add(rig); Plugin.Log.LogInfo((object)("Attached to " + ((Object)((Component)c).gameObject).name + " (" + c.m_name + ") on '" + ((Object)val2).name + "', " + (kind.Skinned ? "skinned to the body" : "rigid on the chest bone") + ", arms " + ((rig.arms != null) ? "found" : "not found"))); } private static ChestBuilder.Settings CurrentSettings() { return new ChestBuilder.Settings { Size = Plugin.Size.Value, Projection = Plugin.Projection.Value, Sag = Plugin.Sag.Value, Up = Plugin.Up.Value, Forward = Plugin.Forward.Value, Spacing = Plugin.Spacing.Value, Outfit = Plugin.OutfitChoice.Value }; } private static Kind GetKind(SkinnedMeshRenderer body, Transform bone, Matrix4x4 rigToSpine, string name) { //IL_002a: 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_00f2: Unknown result type (might be due to invalid IL or missing references) //IL_00f9: Expected O, but got Unknown //IL_0107: Unknown result type (might be due to invalid IL or missing references) //IL_0112: Unknown result type (might be due to invalid IL or missing references) //IL_0117: Unknown result type (might be due to invalid IL or missing references) //IL_011c: Unknown result type (might be due to invalid IL or missing references) //IL_0121: Unknown result type (might be due to invalid IL or missing references) //IL_0124: Unknown result type (might be due to invalid IL or missing references) //IL_0129: Unknown result type (might be due to invalid IL or missing references) //IL_012a: Unknown result type (might be due to invalid IL or missing references) //IL_012f: Unknown result type (might be due to invalid IL or missing references) //IL_0134: Unknown result type (might be due to invalid IL or missing references) //IL_0139: Unknown result type (might be due to invalid IL or missing references) //IL_013b: 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_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0078: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_0183: Unknown result type (might be due to invalid IL or missing references) //IL_0188: Unknown result type (might be due to invalid IL or missing references) //IL_018d: Unknown result type (might be due to invalid IL or missing references) //IL_0212: Unknown result type (might be due to invalid IL or missing references) //IL_0217: Unknown result type (might be due to invalid IL or missing references) //IL_01b7: Unknown result type (might be due to invalid IL or missing references) //IL_01bc: Unknown result type (might be due to invalid IL or missing references) //IL_01c1: Unknown result type (might be due to invalid IL or missing references) //IL_01c5: Unknown result type (might be due to invalid IL or missing references) //IL_01ca: Unknown result type (might be due to invalid IL or missing references) Mesh sharedMesh = body.sharedMesh; int num = Array.IndexOf(body.bones, bone); string key = $"{((Object)sharedMesh).GetInstanceID()}/{num}/{rigToSpine}"; if (kinds.TryGetValue(key, out var value)) { return value; } value = new Kind { RigToSpine = rigToSpine }; BodyMap.Weights[] weights = null; Vector3[] vertices; Vector3[] normals; Vector2[] uv; int[] triangles; if (sharedMesh.isReadable && num >= 0) { value.MeshToRig = ((Matrix4x4)(ref rigToSpine)).inverse * sharedMesh.bindposes[num]; vertices = sharedMesh.vertices; normals = sharedMesh.normals; uv = sharedMesh.uv; triangles = sharedMesh.triangles; BoneWeight[] boneWeights = sharedMesh.boneWeights; if (boneWeights.Length == vertices.Length) { weights = boneWeights.Select((BoneWeight x) => new BodyMap.Weights { B0 = ((BoneWeight)(ref x)).boneIndex0, B1 = ((BoneWeight)(ref x)).boneIndex1, B2 = ((BoneWeight)(ref x)).boneIndex2, B3 = ((BoneWeight)(ref x)).boneIndex3, W0 = ((BoneWeight)(ref x)).weight0, W1 = ((BoneWeight)(ref x)).weight1, W2 = ((BoneWeight)(ref x)).weight2, W3 = ((BoneWeight)(ref x)).weight3 }).ToArray(); value.Skinned = true; } } else { Mesh val = new Mesh(); body.BakeMesh(val); Matrix4x4 val2 = Matrix4x4.TRS(((Component)body).transform.position, ((Component)body).transform.rotation, Vector3.one); Matrix4x4 val3 = bone.localToWorldMatrix * rigToSpine; value.MeshToRig = ((Matrix4x4)(ref val3)).inverse * val2; vertices = val.vertices; normals = val.normals; uv = val.uv; triangles = val.triangles; Object.Destroy((Object)(object)val); } for (int num2 = 0; num2 < vertices.Length; num2++) { vertices[num2] = ((Matrix4x4)(ref value.MeshToRig)).MultiplyPoint3x4(vertices[num2]); } if (normals != null) { for (int num3 = 0; num3 < normals.Length; num3++) { Vector3[] array = normals; int num4 = num3; Vector3 val4 = ((Matrix4x4)(ref value.MeshToRig)).MultiplyVector(normals[num3]); array[num4] = ((Vector3)(ref val4)).normalized; } } value.Map = new BodyMap(vertices, normals, uv, weights, triangles, Plugin.Size.Value * 0.02f) { FallbackBone = 0 }; if (!value.Skinned) { value.MeshToRig = Matrix4x4.identity; } kinds[key] = value; Plugin.Log.LogInfo((object)string.Format("Measured {0}: {1} body vertices, {2}", name, vertices.Length, value.Skinned ? "bind pose, bone weights" : (sharedMesh.isReadable ? "bone not skinned" : "mesh not readable"))); return value; } private static Built BuildMesh(Kind kind, SkinnedMeshRenderer body, ChestBuilder.Settings s) { //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_0059: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_006a: Expected O, but got Unknown //IL_012e: Unknown result type (might be due to invalid IL or missing references) //IL_0147: 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_0151: Unknown result type (might be due to invalid IL or missing references) //IL_015c: Unknown result type (might be due to invalid IL or missing references) //IL_0161: Unknown result type (might be due to invalid IL or missing references) //IL_0175: Unknown result type (might be due to invalid IL or missing references) //IL_017a: Unknown result type (might be due to invalid IL or missing references) //IL_017f: Unknown result type (might be due to invalid IL or missing references) //IL_018a: Unknown result type (might be due to invalid IL or missing references) //IL_018f: Unknown result type (might be due to invalid IL or missing references) float realtimeSinceStartup = Time.realtimeSinceStartup; ChestBuilder.Result result = ChestBuilder.Build(kind.Map, s); Matrix4x4 rigToMesh = ((Matrix4x4)(ref kind.MeshToRig)).inverse; int nb = ((!kind.Skinned) ? 1 : body.bones.Length); Mesh val = new Mesh { name = "TrollChests" }; val.SetVertices(result.Verts.Select((Vector3 p) => ((Matrix4x4)(ref rigToMesh)).MultiplyPoint3x4(p)).ToList()); val.SetNormals(result.Normals.Select(delegate(Vector3 x) { //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_000f: Unknown result type (might be due to invalid IL or missing references) Vector3 val2 = ((Matrix4x4)(ref rigToMesh)).MultiplyVector(x); return ((Vector3)(ref val2)).normalized; }).ToList()); val.SetUVs(0, result.UV); val.subMeshCount = 2; val.SetTriangles(result.Skin, 0); val.SetTriangles(result.Fabric, 1); val.boneWeights = result.Weights.Select((Dictionary w) => Top4(w, Bone)).ToArray(); List list = new List(); if (kind.Skinned) { list.AddRange(body.sharedMesh.bindposes); } else { list.Add(kind.RigToSpine); } for (int num = 0; num < 2; num++) { list.Add(Matrix4x4.Translate(-result.PivotPos[num]) * kind.MeshToRig); list.Add(Matrix4x4.Translate(-result.TipPos[num]) * kind.MeshToRig); } val.bindposes = list.ToArray(); val.RecalculateTangents(); val.RecalculateBounds(); val.UploadMeshData(false); Plugin.Log.LogInfo((object)$"Built chest ({s.Outfit}, size {s.Size}): {result.Verts.Count} vertices, {(result.Skin.Count + result.Fabric.Count) / 3} triangles in {(Time.realtimeSinceStartup - realtimeSinceStartup) * 1000f:0} ms"); return new Built { Mesh = val, R = result }; int Bone(int id) { if (id < 0) { return nb + (-id - 1); } if (!kind.Skinned) { return 0; } return id; } } private static BoneWeight Top4(Dictionary w, Func bone) { //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_008b: Unknown result type (might be due to invalid IL or missing references) //IL_012b: Unknown result type (might be due to invalid IL or missing references) KeyValuePair[] array = (from kv in w where kv.Value > 0.0001f orderby kv.Value descending select kv).Take(4).ToArray(); float num = array.Sum((KeyValuePair kv) => kv.Value); BoneWeight result = default(BoneWeight); if (num <= 0f) { return result; } for (int num2 = 0; num2 < array.Length; num2++) { int num3 = bone(array[num2].Key); float num4 = array[num2].Value / num; switch (num2) { case 0: ((BoneWeight)(ref result)).boneIndex0 = num3; ((BoneWeight)(ref result)).weight0 = num4; break; case 1: ((BoneWeight)(ref result)).boneIndex1 = num3; ((BoneWeight)(ref result)).weight1 = num4; break; case 2: ((BoneWeight)(ref result)).boneIndex2 = num3; ((BoneWeight)(ref result)).weight2 = num4; break; case 3: ((BoneWeight)(ref result)).boneIndex3 = num3; ((BoneWeight)(ref result)).weight3 = num4; break; } } return result; } public static void DetachAll() { Rig[] array = all.ToArray(); foreach (Rig rig in array) { if (Object.op_Implicit((Object)(object)rig)) { rig.Remove(); } } all.Clear(); foreach (Kind value in kinds.Values) { foreach (Built value2 in value.Meshes.Values) { if (Object.op_Implicit((Object)(object)value2.Mesh)) { Object.Destroy((Object)(object)value2.Mesh); } } } kinds.Clear(); foreach (Material value3 in topMaterials.Values) { if (Object.op_Implicit((Object)(object)value3)) { Object.Destroy((Object)(object)value3.mainTexture); Object.Destroy((Object)(object)value3); } } topMaterials.Clear(); } private void Remove() { Transform[] array = pivots; foreach (Transform val in array) { if (Object.op_Implicit((Object)(object)val)) { val.SetParent((Transform)null, false); ((Component)val).gameObject.SetActive(false); Object.Destroy((Object)(object)((Component)val).gameObject); } } ((Component)this).transform.SetParent((Transform)null, false); ((Component)this).gameObject.SetActive(false); Object.Destroy((Object)(object)((Component)this).gameObject); } private void OnDestroy() { all.Remove(this); Transform[] array = pivots; foreach (Transform val in array) { if (Object.op_Implicit((Object)(object)val)) { Object.Destroy((Object)(object)((Component)val).gameObject); } } if (!Object.op_Implicit((Object)(object)lodGroup)) { return; } LOD[] lODs = lodGroup.GetLODs(); for (int j = 0; j < lODs.Length; j++) { if (lODs[j].renderers != null) { lODs[j].renderers = lODs[j].renderers.Where((Renderer r) => Object.op_Implicit((Object)(object)r) && (Object)(object)r != (Object)(object)smr).ToArray(); } } lodGroup.SetLODs(lODs); } private static bool IsTroll(string s) { if (s != null) { return s.IndexOf("troll", StringComparison.OrdinalIgnoreCase) >= 0; } return false; } private static Transform FindBone(Transform[] bones, Transform root) { string want = Plugin.BoneName.Value.Trim(); if (want != "") { return ((IEnumerable)bones).FirstOrDefault((Func)((Transform b) => ((Object)b).name == want)) ?? root; } Transform val = null; int num = -1; foreach (Transform val2 in bones) { string text = ((Object)val2).name.ToLowerInvariant(); if (text.Contains("chest")) { return val2; } if (text.Contains("spine")) { int num3 = Depth(val2, root); if (num3 > num) { val = val2; num = num3; } } } return val ?? root; } private static int Depth(Transform t, Transform root) { int num = 0; while ((Object)(object)t != (Object)(object)root && (Object)(object)t != (Object)null) { num++; t = t.parent; } return num; } private static Quaternion? BindFrame(SkinnedMeshRenderer body, Transform bone, Quaternion now) { //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_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_0094: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00b1: Unknown result type (might be due to invalid IL or missing references) //IL_0180: Unknown result type (might be due to invalid IL or missing references) //IL_00c2: Unknown result type (might be due to invalid IL or missing references) //IL_00c7: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: 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_010f: Unknown result type (might be due to invalid IL or missing references) //IL_0114: Unknown result type (might be due to invalid IL or missing references) //IL_0119: 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_012a: Unknown result type (might be due to invalid IL or missing references) //IL_012c: Unknown result type (might be due to invalid IL or missing references) //IL_013e: 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) int num = Array.IndexOf(body.bones, bone); Matrix4x4[] bindposes = body.sharedMesh.bindposes; if (num < 0 || num >= bindposes.Length) { return null; } Matrix4x4 val = bindposes[num]; Vector3[] array = ((IEnumerable)(object)new Vector4[3] { ((Matrix4x4)(ref val)).GetColumn(0), ((Matrix4x4)(ref val)).GetColumn(1), ((Matrix4x4)(ref val)).GetColumn(2) }).Select(delegate(Vector4 a) { //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_0006: 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) Vector3 val5 = Vector4.op_Implicit(a); return ((Vector3)(ref val5)).normalized; }).ToArray(); Quaternion value = now; float num2 = float.MaxValue; Vector3[] array2 = array; foreach (Vector3 val2 in array2) { Vector3[] array3 = array; foreach (Vector3 val3 in array3) { if (val2 == val3) { continue; } int[] array4 = new int[2] { 1, -1 }; foreach (int num6 in array4) { int[] array5 = new int[2] { 1, -1 }; foreach (int num8 in array5) { Quaternion val4 = Quaternion.LookRotation(val2 * (float)num6, val3 * (float)num8); float num9 = Quaternion.Angle(val4, now); if (num9 < num2) { num2 = num9; value = val4; } } } } } return value; } private static SkinnedMeshRenderer Body(Character c) { return (from s in ((Component)c).GetComponentsInChildren(true) where (Object)(object)s.sharedMesh != (Object)null && (Object)(object)((Renderer)s).sharedMaterial != (Object)null && !Object.op_Implicit((Object)(object)((Component)s).GetComponent()) orderby s.sharedMesh.vertexCount descending select s).FirstOrDefault(); } private static Material TopMaterial(Character c, Material skin) { //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: Unknown result type (might be due to invalid IL or missing references) //IL_00b8: Unknown result type (might be due to invalid IL or missing references) //IL_00bf: Expected O, but got Unknown //IL_00c3: 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_00d7: Unknown result type (might be due to invalid IL or missing references) //IL_00e2: Unknown result type (might be due to invalid IL or missing references) //IL_00eb: Expected O, but got Unknown //IL_010c: Unknown result type (might be due to invalid IL or missing references) //IL_00af: Unknown result type (might be due to invalid IL or missing references) Renderer val = ((IEnumerable)((Component)c).GetComponentsInChildren(true)).FirstOrDefault((Func)((Renderer r) => ((Object)r).name.IndexOf("hair", StringComparison.OrdinalIgnoreCase) >= 0 && (Object)(object)r.sharedMaterial != (Object)null)); Material key = (((Object)(object)val != (Object)null) ? val.sharedMaterial : skin); if (topMaterials.TryGetValue(key, out var value)) { return value; } Renderer obj = ((val is SkinnedMeshRenderer) ? val : null); object obj2 = ((obj != null) ? ((SkinnedMeshRenderer)obj).sharedMesh : null); if (obj2 == null) { if (val == null) { obj2 = null; } else { MeshFilter component = ((Component)val).GetComponent(); obj2 = ((component != null) ? component.sharedMesh : null); } } Mesh val2 = (Mesh)obj2; Color val3 = (((Object)(object)val != (Object)null) ? AverageColor(val.sharedMaterial, ((Object)(object)val2 != (Object)null && val2.isReadable) ? val2.uv : null) : Straw); Texture2D val4 = new Texture2D(1, 1); val4.SetPixel(0, 0, val3); val4.Apply(); value = new Material(skin) { name = "TrollChests_Top", mainTexture = (Texture)(object)val4 }; topMaterials[key] = value; Plugin.Log.LogDebug((object)$"Top color for {((Object)((Component)c).gameObject).name}: {val3}"); return value; } private static Color AverageColor(Material m, Vector2[] uvs) { //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Expected O, but got Unknown //IL_0076: 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_0093: 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_001d: Unknown result type (might be due to invalid IL or missing references) //IL_013f: Unknown result type (might be due to invalid IL or missing references) //IL_0144: 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_0154: 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_0158: Unknown result type (might be due to invalid IL or missing references) //IL_015d: Unknown result type (might be due to invalid IL or missing references) //IL_0185: Unknown result type (might be due to invalid IL or missing references) //IL_018a: Unknown result type (might be due to invalid IL or missing references) //IL_017e: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: Unknown result type (might be due to invalid IL or missing references) //IL_00be: Unknown result type (might be due to invalid IL or missing references) //IL_00fc: 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_0103: Unknown result type (might be due to invalid IL or missing references) //IL_018f: Unknown result type (might be due to invalid IL or missing references) //IL_0111: Unknown result type (might be due to invalid IL or missing references) //IL_0113: Unknown result type (might be due to invalid IL or missing references) //IL_0115: Unknown result type (might be due to invalid IL or missing references) //IL_011a: Unknown result type (might be due to invalid IL or missing references) //IL_01b9: Unknown result type (might be due to invalid IL or missing references) //IL_019e: Unknown result type (might be due to invalid IL or missing references) //IL_01a1: Unknown result type (might be due to invalid IL or missing references) //IL_01a6: Unknown result type (might be due to invalid IL or missing references) //IL_01ab: Unknown result type (might be due to invalid IL or missing references) Texture mainTexture = m.mainTexture; if ((Object)(object)mainTexture == (Object)null) { if (!m.HasProperty("_Color")) { return Straw; } return m.color; } RenderTexture temporary = RenderTexture.GetTemporary(256, 256, 0, (RenderTextureFormat)0); RenderTexture active = RenderTexture.active; Graphics.Blit(mainTexture, temporary); RenderTexture.active = temporary; Texture2D val = new Texture2D(256, 256, (TextureFormat)4, false); val.ReadPixels(new Rect(0f, 0f, 256f, 256f), 0, 0); RenderTexture.active = active; RenderTexture.ReleaseTemporary(temporary); Color val2 = Color.clear; int num = 0; Color[] pixels = val.GetPixels(); if (uvs != null && uvs.Length != 0) { foreach (Vector2 val3 in uvs) { int num2 = (int)(Mathf.Repeat(val3.x, 1f) * 255f); int num3 = (int)(Mathf.Repeat(val3.y, 1f) * 255f); Color val4 = pixels[num3 * 256 + num2]; if (val4.a > 0.5f) { val2 += val4; num++; } } } else { Color[] array = pixels; foreach (Color val5 in array) { if (val5.a > 0.5f) { val2 += val5; num++; } } } Object.Destroy((Object)(object)val); Color val6 = ((num > 0) ? (val2 / (float)num) : Straw); if (m.HasProperty("_Color")) { val6 *= m.color; } val6.a = 1f; return val6; } private void LateUpdate() { //IL_00a7: 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_00b7: Unknown result type (might be due to invalid IL or missing references) //IL_00ba: Unknown result type (might be due to invalid IL or missing references) //IL_00bf: Unknown result type (might be due to invalid IL or missing references) //IL_00c2: Unknown result type (might be due to invalid IL or missing references) //IL_00c7: Unknown result type (might be due to invalid IL or missing references) //IL_00cc: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_01a8: Unknown result type (might be due to invalid IL or missing references) //IL_01a9: Unknown result type (might be due to invalid IL or missing references) //IL_01b0: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_01ef: Unknown result type (might be due to invalid IL or missing references) //IL_0201: Unknown result type (might be due to invalid IL or missing references) //IL_0107: 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) if (built == null || !Object.op_Implicit((Object)(object)spine)) { return; } Camera main = Camera.main; if (((Renderer)smr).isVisible) { Vector3 val; if ((Object)(object)main != (Object)null) { val = ((Component)main).transform.position - ((Component)this).transform.position; if (((Vector3)(ref val)).sqrMagnitude > 6400f) { goto IL_005d; } } atRest = false; Matrix4x4 rigToWorld = spine.localToWorldMatrix * rigToSpine; Matrix4x4 inverse = ((Matrix4x4)(ref rigToWorld)).inverse; val = ((Matrix4x4)(ref rigToWorld)).MultiplyVector(Vector3.right); float magnitude = ((Vector3)(ref val)).magnitude; int capCount = 0; if (arms != null) { for (int i = 0; i < 6; i += 3) { capsules[capCount++] = Arm(arms[i], arms[i + 1], inverse, magnitude); capsules[capCount++] = Arm(arms[i + 1], arms[i + 2], inverse, magnitude); } } JiggleSim.Params p = new JiggleSim.Params { Stiffness = Plugin.Stiffness.Value, Damping = Plugin.Damping.Value, Gravity = Plugin.Gravity.Value, Exaggeration = Plugin.Exaggeration.Value }; sim.Step(Time.deltaTime, rigToWorld, inverse, spine.position, built.TipPos, built.Width, p, capsules, capCount); for (int j = 0; j < 2; j++) { Pose(j, sim.Offset[j], sim.Low[j]); } return; } goto IL_005d; IL_005d: if (!atRest) { for (int k = 0; k < 2; k++) { Pose(k, Vector3.zero, Vector3.zero); } atRest = true; } sim.Reset(); } private static JiggleSim.Capsule Arm(Transform a, Transform b, Matrix4x4 worldToRig, float meters) { //IL_000d: 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_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) return new JiggleSim.Capsule { A = ((Matrix4x4)(ref worldToRig)).MultiplyPoint3x4(a.position), B = ((Matrix4x4)(ref worldToRig)).MultiplyPoint3x4(b.position), R = 0.3f * Vector3.Distance(a.position, b.position) / meters }; } private void Pose(int k, Vector3 d, Vector3 low) { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_005f: 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) Vector3 val = built.TipPos[k] - built.PivotPos[k]; Quaternion val2 = Quaternion.FromToRotation(val, val + d); pivots[k].localRotation = rigRot * val2; tips[k].localPosition = val + Quaternion.Inverse(val2) * low; } } }