Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of SeatedCapeFix v0.1.1
plugins/SeatedCapeFix.dll
Decompiled 4 days agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using MagicaCloth2; using Microsoft.CodeAnalysis; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: IgnoresAccessChecksTo("assembly_valheim")] [assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")] [assembly: AssemblyCompany("SeatedCapeFix")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0+034f94cf4649d587d6fab0c8b01914c1062002fa")] [assembly: AssemblyProduct("SeatedCapeFix")] [assembly: AssemblyTitle("SeatedCapeFix")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.0.0")] [module: UnverifiableCode] [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 SeatedCapeFix { public class CapeSeat : MonoBehaviour { public enum Back { Drop, Wall, Floor, Backrest, Guess } internal static float SeatSearch = 0.5f; internal static float ButtDepth = 0.12f; internal static float MaxBack = 0.8f; internal static float RowStep = 0.1f; internal static float SideStep = 0.05f; internal static float HalfWidth = 0.45f; internal static float Bump = 0.06f; internal static float Radius = 0.15f; internal static float GuessEdge = 0.25f; internal static float MinWall = 0.2f; internal static float Backrest = 0.3f; internal static float WallHeight = 0.12f; internal static float MinFloorWidth = 0.4f; internal static float HullWallHeight = 0.45f; internal static float HullReach = 0.8f; internal static float WallProbe = 1f; internal static float Lift = 0.01f; internal static float Interval = 0.5f; private const int MaxRows = 12; private static int s_mask; private static int s_probeFrame = -1; private Player m_player; private VisEquipment m_vis; private Transform m_hips; private GameObject m_root; private readonly List<MagicaCapsuleCollider> m_rows = new List<MagicaCapsuleCollider>(); private MagicaPlaneCollider m_wall; private MagicaPlaneCollider m_floor; private MagicaPlaneCollider m_left; private MagicaPlaneCollider m_right; private ColliderComponent[] m_all = (ColliderComponent[])(object)new ColliderComponent[0]; private readonly List<ColliderComponent> m_use = new List<ColliderComponent>(); private bool m_on; private bool m_wasVisible; private float m_nextProbe; private readonly List<float> m_rowsD = new List<float>(); private readonly List<float> m_rowsY = new List<float>(); private readonly List<float> m_rowsL = new List<float>(); private readonly List<float> m_rowsR = new List<float>(); private readonly List<Vector3> m_wallL = new List<Vector3>(); private readonly List<Vector3> m_wallR = new List<Vector3>(); private bool m_hull; private readonly List<MagicaCloth> m_cloths = new List<MagicaCloth>(); private readonly List<MagicaCloth> m_appliedCloths = new List<MagicaCloth>(); private readonly List<ColliderComponent> m_applied = new List<ColliderComponent>(); private readonly HashSet<List<ColliderComponent>> m_changed = new HashSet<List<ColliderComponent>>(); private float m_hipsY; private float m_widthMin; private float m_widthMax; private int m_rowsUsed; private bool m_noCloth; public string Info { get { if (m_on) { if (!m_noCloth) { if (Kind != Back.Guess) { return string.Format(CultureInfo.InvariantCulture, "{0} seat at {1:0.000} (hips {2:0.000}) back {3:0.00} rows {4} width {5:0.00}..{6:0.00}", Kind, SeatHeight, m_hipsY, BackDistance, m_rowsUsed, m_widthMin, m_widthMax).Replace(" width 0.00..0.00", "") + (m_hull ? " hull" : ""); } return string.Format(CultureInfo.InvariantCulture, "Guess seat at {0:0.000} (hips {1:0.000}) back {2:0.00}", SeatHeight, m_hipsY, BackDistance); } return "no cloth"; } return "off"; } } public bool On => m_on; public bool SeatFound => Kind != Back.Guess; public Back Kind { get; private set; } public float SeatHeight { get; private set; } public float BackDistance { get; private set; } private static int Mask { get { if (s_mask == 0) { return s_mask = LayerMask.GetMask(new string[6] { "Default", "static_solid", "Default_small", "piece", "terrain", "vehicle" }); } return s_mask; } } private void Awake() { m_player = ((Component)this).GetComponent<Player>(); m_vis = ((Component)this).GetComponent<VisEquipment>(); } private void LateUpdate() { bool flag = Plugin.Enabled.Value && Object.op_Implicit((Object)(object)m_player) && Object.op_Implicit((Object)(object)((Character)m_player).m_nview) && ((Character)m_player).m_nview.IsValid() && ((Character)m_player).IsSitting() && FindHips(); if (flag != m_on) { if (flag) { Begin(); } else { End(); } } else if (m_on) { bool flag2 = Visible(); if (flag2 && !m_wasVisible) { m_nextProbe = 0f; } m_wasVisible = flag2; if (flag2 && !(Time.time < m_nextProbe) && s_probeFrame != Time.frameCount) { s_probeFrame = Time.frameCount; m_nextProbe = Time.time + Interval; Refresh(); } } } private void OnDestroy() { if (m_on) { Sync(null); } } private bool FindHips() { if (Object.op_Implicit((Object)(object)m_hips)) { return true; } if (Object.op_Implicit((Object)(object)m_vis) && m_vis.m_boneMap.TryGetValue("Hips", out m_hips)) { return Object.op_Implicit((Object)(object)m_hips); } return false; } private bool Visible() { if (Object.op_Implicit((Object)(object)m_vis) && Object.op_Implicit((Object)(object)m_vis.m_bodyModel) && ((Renderer)m_vis.m_bodyModel).isVisible) { return true; } foreach (MagicaCloth cloth in m_cloths) { if (!Object.op_Implicit((Object)(object)cloth)) { continue; } foreach (Renderer sourceRenderer in cloth.SerializeData.sourceRenderers) { if (Object.op_Implicit((Object)(object)sourceRenderer) && sourceRenderer.isVisible) { return true; } } } return false; } private void Begin() { m_on = true; if (!Object.op_Implicit((Object)(object)m_root)) { Build(); } Refresh(); m_wasVisible = Visible(); m_nextProbe = Time.time + Interval; if (Plugin.DebugLog.Value) { Plugin.Log.LogInfo((object)(m_player.GetPlayerName() + " sits: " + Info)); } } private void End() { m_on = false; long timestamp = Stopwatch.GetTimestamp(); Sync(null); Perf.AddEnd(Stopwatch.GetTimestamp() - timestamp); if (Plugin.DebugLog.Value) { Plugin.Log.LogInfo((object)(m_player.GetPlayerName() + " stands up")); } } private void Refresh() { long timestamp = Stopwatch.GetTimestamp(); Collect(); m_noCloth = m_cloths.Count == 0; if (m_noCloth) { m_use.Clear(); } else { Probe(); } long timestamp2 = Stopwatch.GetTimestamp(); Apply(m_use); Perf.Add(timestamp2 - timestamp, Stopwatch.GetTimestamp() - timestamp2); } private void Build() { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Expected O, but got Unknown //IL_002d: 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_0056: 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_00ea: Unknown result type (might be due to invalid IL or missing references) m_root = new GameObject("SeatedCapeFix"); m_root.transform.SetParent(((Component)this).transform, false); float x = ((Component)this).transform.lossyScale.x; if (Mathf.Abs(x) > 0.0001f) { m_root.transform.localScale = Vector3.one / x; } for (int i = 0; i < 12; i++) { MagicaCapsuleCollider val = Child("SeatRow" + i).AddComponent<MagicaCapsuleCollider>(); val.direction = (Direction)0; val.alignedOnCenter = true; m_rows.Add(val); } m_floor = Child("SeatFloor").AddComponent<MagicaPlaneCollider>(); m_wall = Child("SeatWall").AddComponent<MagicaPlaneCollider>(); ((Component)m_wall).transform.localRotation = Quaternion.Euler(90f, 0f, 0f); m_left = Child("SeatHullLeft").AddComponent<MagicaPlaneCollider>(); m_right = Child("SeatHullRight").AddComponent<MagicaPlaneCollider>(); List<ColliderComponent> list = new List<ColliderComponent>((IEnumerable<ColliderComponent>)m_rows) { (ColliderComponent)(object)m_floor, (ColliderComponent)(object)m_wall, (ColliderComponent)(object)m_left, (ColliderComponent)(object)m_right }; m_all = list.ToArray(); } private GameObject Child(string name) { //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_001e: Expected O, but got Unknown GameObject val = new GameObject(name); val.transform.SetParent(m_root.transform, false); return val; } private void Probe() { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_0018: 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_0067: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_00f9: 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_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_008e: Unknown result type (might be due to invalid IL or missing references) //IL_00bd: Unknown result type (might be due to invalid IL or missing references) //IL_00cc: Unknown result type (might be due to invalid IL or missing references) //IL_0193: Unknown result type (might be due to invalid IL or missing references) //IL_019f: Unknown result type (might be due to invalid IL or missing references) //IL_0465: Unknown result type (might be due to invalid IL or missing references) //IL_046b: Unknown result type (might be due to invalid IL or missing references) //IL_0470: 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_0486: Unknown result type (might be due to invalid IL or missing references) //IL_048a: Unknown result type (might be due to invalid IL or missing references) //IL_048f: Unknown result type (might be due to invalid IL or missing references) //IL_04c3: Unknown result type (might be due to invalid IL or missing references) //IL_04d2: Unknown result type (might be due to invalid IL or missing references) //IL_04e2: Unknown result type (might be due to invalid IL or missing references) //IL_02ed: Unknown result type (might be due to invalid IL or missing references) //IL_0302: 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_037a: Unknown result type (might be due to invalid IL or missing references) //IL_03a6: Unknown result type (might be due to invalid IL or missing references) //IL_023f: Unknown result type (might be due to invalid IL or missing references) //IL_0544: Unknown result type (might be due to invalid IL or missing references) //IL_054e: Unknown result type (might be due to invalid IL or missing references) //IL_0510: Unknown result type (might be due to invalid IL or missing references) //IL_0516: Unknown result type (might be due to invalid IL or missing references) //IL_0251: Unknown result type (might be due to invalid IL or missing references) //IL_0567: Unknown result type (might be due to invalid IL or missing references) //IL_057b: Unknown result type (might be due to invalid IL or missing references) Vector3 val = ((Component)this).transform.InverseTransformPoint(m_hips.position); m_hipsY = val.y; m_use.Clear(); int num = 0; m_rowsUsed = 0; m_widthMin = (m_widthMax = 0f); m_hull = false; if (!Down(new Vector3(val.x, val.y + 0.05f, val.z), 0.05f + SeatSearch, out var localY)) { Kind = Back.Guess; SeatHeight = val.y - ButtDepth; BackDistance = GuessEdge; float num2 = GuessEdge * 0.5f; Row(num++, val.x, SeatHeight - num2, val.z - (GuessEdge - num2), num2, 0.5f); m_rowsUsed = num; return; } Back back = Back.Floor; float num3 = MaxBack; float num4 = Horizontal(new Vector3(val.x, localY + WallHeight, val.z - MinWall), Vector3.back, MaxBack - MinWall) + MinWall; float num5 = localY; List<float> rowsD = m_rowsD; List<float> rowsY = m_rowsY; List<float> rowsL = m_rowsL; List<float> rowsR = m_rowsR; rowsD.Clear(); rowsY.Clear(); rowsL.Clear(); rowsR.Clear(); int num6 = 0; float num7 = 0f; while (num7 <= MaxBack + 0.001f) { if (num7 >= num4) { back = Back.Wall; num3 = num4; break; } float z = val.z - num7; if (!Surface(val.x, z, num5, out var y) || y < num5 - Bump) { back = Back.Drop; num3 = Mathf.Max(num7 - SideStep * 0.5f, 0.05f); break; } if (y > num5 + Bump) { if (!(num7 < MinWall)) { back = Back.Wall; num3 = num7 - SideStep * 0.5f; break; } } else { num5 = y; if (num6 % Mathf.Max(1, Mathf.RoundToInt(RowStep / SideStep)) == 0) { if (!m_hull && num7 >= MinWall && Narrow(val.x, z, y)) { if (!SideWalls(val.x, z, y)) { back = Back.Drop; num3 = num7 - RowStep * 0.5f; break; } m_hull = true; } rowsD.Add(num7); rowsY.Add(y); } } num7 += SideStep; num6++; } SeatHeight = localY; BackDistance = num3; if (back == Back.Wall && num3 < Backrest) { back = Back.Backrest; } Kind = back; switch (back) { case Back.Drop: { float radius = Radius; for (int i = 0; i < rowsD.Count; i++) { if (num >= 12) { break; } float z2 = val.z - rowsD[i]; rowsL.Add(Side(val.x, z2, rowsY[i], -1f)); rowsR.Add(Side(val.x, z2, rowsY[i], 1f)); float num10 = rowsD[i]; if (num10 > num3 - radius) { num10 = num3 - radius; } Row(num++, val.x + (rowsR[i] - rowsL[i]) * 0.5f, rowsY[i] - radius, val.z - num10, radius, rowsL[i] + rowsR[i]); if (num10 >= num3 - radius) { break; } } break; } default: { float num8 = 0f; int num9 = rowsD.Count - 1; if (num9 > 0 && rowsD[num9] > rowsD[0]) { num8 = (rowsY[num9] - rowsY[0]) / (rowsD[num9] - rowsD[0]); } Transform transform = ((Component)m_floor).transform; Vector3 pos = new Vector3(0f, localY + Lift, val.z); Vector3 up = Vector3.up; Vector3 val2 = new Vector3(0f, 1f, num8); Place(transform, pos, Quaternion.FromToRotation(up, ((Vector3)(ref val2)).normalized)); m_use.Add((ColliderComponent)(object)m_floor); if (back == Back.Wall) { Place(((Component)m_wall).transform, new Vector3(0f, 0f, val.z - num3 + Lift), ((Component)m_wall).transform.localRotation); m_use.Add((ColliderComponent)(object)m_wall); } if (!m_hull && rowsD.Count > 0 && SideWalls(val.x, val.z - rowsD[0], rowsY[0])) { m_hull = true; } if (m_hull && HullWalls(val.x, rowsD, rowsY, val.z) && Clear(((Component)m_left).transform, val) && Clear(((Component)m_right).transform, val)) { m_use.Add((ColliderComponent)(object)m_left); m_use.Add((ColliderComponent)(object)m_right); } else { m_hull = false; } break; } case Back.Backrest: m_hull = false; break; } m_rowsUsed = num; m_widthMin = ((rowsL.Count > 0) ? Min(rowsL, rowsR) : 0f); m_widthMax = ((rowsL.Count > 0) ? Max(rowsL, rowsR) : 0f); } private static void Place(Transform t, Vector3 pos, Quaternion rot) { //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_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_000f: 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) if (t.localPosition != pos) { t.localPosition = pos; } if (t.localRotation != rot) { t.localRotation = rot; } } private static float Min(List<float> l, List<float> r) { float num = float.MaxValue; for (int i = 0; i < l.Count; i++) { num = Mathf.Min(num, l[i] + r[i]); } return num; } private static float Max(List<float> l, List<float> r) { float num = 0f; for (int i = 0; i < l.Count; i++) { num = Mathf.Max(num, l[i] + r[i]); } return num; } private void Row(int i, float x, float centerY, float z, float r, float width) { //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_0044: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Unknown result type (might be due to invalid IL or missing references) MagicaCapsuleCollider val = m_rows[i]; Place(((Component)val).transform, new Vector3(x, centerY + Lift, z), Quaternion.identity); Vector3 val2 = default(Vector3); ((Vector3)(ref val2))..ctor(r, r, Mathf.Max(width, 0.1f)); if (((ColliderComponent)val).GetSize() != val2) { val.SetSize(r, r, val2.z); ((ColliderComponent)val).UpdateParameters(); } m_use.Add((ColliderComponent)(object)val); } private bool Surface(float x, float z, float level, out float y) { //IL_000a: Unknown result type (might be due to invalid IL or missing references) return Down(new Vector3(x, level + WallProbe, z), WallProbe + Bump * 2f, out y); } private float Side(float x, float z, float level, float dir, float other = 0f, float enough = float.MaxValue) { //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) float num = Horizontal(new Vector3(x, level + WallHeight, z), Vector3.right * dir, HalfWidth); float num2 = 0f; float y; for (float num3 = SideStep; num3 <= HalfWidth + 0.001f && num3 < num && Surface(x + dir * num3, z, level, out y); num3 += SideStep) { if (Mathf.Abs(y - level) > Bump) { break; } num2 = num3; if (other + num2 >= enough) { break; } } return num2; } private bool SideWalls(float x, float z, float level) { //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_001d: 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_004a: Unknown result type (might be due to invalid IL or missing references) for (float num = -1f; num <= 1f; num += 2f) { if (Horizontal(new Vector3(x, level + WallHeight, z), Vector3.right * num, HullReach) == float.MaxValue) { return false; } if (Horizontal(new Vector3(x, level + HullWallHeight, z), Vector3.right * num, HullReach) == float.MaxValue) { return false; } } return true; } private bool HullWalls(float x, List<float> rowsD, List<float> rowsY, float hipsZ) { //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_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_0090: 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) m_wallL.Clear(); m_wallR.Clear(); for (int i = 0; i < rowsD.Count; i++) { float num = hipsZ - rowsD[i]; for (int j = 0; j < 2; j++) { float num2 = rowsY[i] + ((j == 0) ? WallHeight : HullWallHeight); float num3 = Horizontal(new Vector3(x, num2, num), Vector3.left, HullReach); float num4 = Horizontal(new Vector3(x, num2, num), Vector3.right, HullReach); if (num3 != float.MaxValue) { m_wallL.Add(new Vector3(x - num3, num2, num)); } if (num4 != float.MaxValue) { m_wallR.Add(new Vector3(x + num4, num2, num)); } } } if (FitWall(m_wallL, 1f, ((Component)m_left).transform)) { return FitWall(m_wallR, -1f, ((Component)m_right).transform); } return false; } private bool Clear(Transform plane, Vector3 hips) { //IL_0000: 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_0018: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) return Vector3.Dot(new Vector3(hips.x, SeatHeight + 0.1f, hips.z) - plane.localPosition, plane.localRotation * Vector3.up) > 0.15f; } private static bool FitWall(List<Vector3> pts, float inward, Transform plane) { //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_007f: 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_0092: 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_00a5: 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_00b7: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: Unknown result type (might be due to invalid IL or missing references) //IL_00d1: 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_00e6: Unknown result type (might be due to invalid IL or missing references) //IL_00ed: Unknown result type (might be due to invalid IL or missing references) //IL_00fb: Unknown result type (might be due to invalid IL or missing references) //IL_0230: Unknown result type (might be due to invalid IL or missing references) //IL_0235: Unknown result type (might be due to invalid IL or missing references) //IL_0239: Unknown result type (might be due to invalid IL or missing references) //IL_023e: Unknown result type (might be due to invalid IL or missing references) //IL_0240: 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_0283: 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_0299: 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) if (pts.Count < 2) { return false; } double num = 0.0; double num2 = 0.0; double num3 = 0.0; double num4 = 0.0; double num5 = 0.0; double num6 = pts.Count; double num7 = 0.0; double num8 = 0.0; double num9 = 0.0; foreach (Vector3 pt in pts) { num += (double)(pt.y * pt.y); num2 += (double)(pt.y * pt.z); num3 += (double)pt.y; num4 += (double)(pt.z * pt.z); num5 += (double)pt.z; num7 += (double)(pt.x * pt.y); num8 += (double)(pt.x * pt.z); num9 += (double)pt.x; } double num10 = num * (num4 * num6 - num5 * num5) - num2 * (num2 * num6 - num5 * num3) + num3 * (num2 * num5 - num4 * num3); double num11; double num12; double num13; if (Math.Abs(num10) > 1E-09) { num11 = (num7 * (num4 * num6 - num5 * num5) - num2 * (num8 * num6 - num5 * num9) + num3 * (num8 * num5 - num4 * num9)) / num10; num12 = (num * (num8 * num6 - num9 * num5) - num7 * (num2 * num6 - num5 * num3) + num3 * (num2 * num9 - num8 * num3)) / num10; num13 = (num * (num4 * num9 - num5 * num8) - num2 * (num2 * num9 - num3 * num8) + num7 * (num2 * num5 - num4 * num3)) / num10; } else { double num14 = num * num6 - num3 * num3; if (Math.Abs(num14) < 1E-09) { return false; } num11 = (num7 * num6 - num3 * num9) / num14; num12 = 0.0; num13 = (num9 - num11 * num3) / num6; } Vector3 val = new Vector3(inward, (0f - (float)num11) * inward, (0f - (float)num12) * inward); Vector3 normalized = ((Vector3)(ref val)).normalized; if (Mathf.Abs(normalized.y) > 0.8f) { return false; } float num15 = (float)(num3 / num6); float num16 = (float)(num5 / num6); Vector3 val2 = default(Vector3); ((Vector3)(ref val2))..ctor((float)(num11 * (double)num15 + num12 * (double)num16 + num13), num15, num16); Place(plane, val2 + normalized * Lift, Quaternion.FromToRotation(Vector3.up, normalized)); return true; } private bool Narrow(float x, float z, float level) { float num = Side(x, z, level, -1f, 0f, MinFloorWidth); if (num >= MinFloorWidth) { return false; } float num2 = Side(x, z, level, 1f, num, MinFloorWidth); return num + num2 < MinFloorWidth; } private float Horizontal(Vector3 localOrigin, Vector3 localDir, float dist) { //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) Transform transform = ((Component)this).transform; RaycastHit val = default(RaycastHit); if (!Physics.Raycast(transform.TransformPoint(localOrigin), transform.TransformDirection(localDir), ref val, dist, Mask, (QueryTriggerInteraction)1)) { return float.MaxValue; } return ((RaycastHit)(ref val)).distance; } private bool Down(Vector3 localOrigin, float dist, out float localY) { //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) localY = 0f; Transform transform = ((Component)this).transform; RaycastHit val = default(RaycastHit); if (!Physics.Raycast(transform.TransformPoint(localOrigin), -transform.up, ref val, dist, Mask, (QueryTriggerInteraction)1)) { return false; } localY = transform.InverseTransformPoint(((RaycastHit)(ref val)).point).y; return true; } private void Collect() { ((Component)this).GetComponentsInChildren<MagicaCloth>(true, m_cloths); } private void Sync(List<ColliderComponent> use) { Collect(); Apply(use); } private void Apply(List<ColliderComponent> use) { int num = use?.Count ?? 0; if (Same(m_cloths, m_appliedCloths) && num == m_applied.Count) { bool flag = true; for (int i = 0; i < num && flag; i++) { flag = (Object)(object)use[i] == (Object)(object)m_applied[i]; } if (flag) { return; } } m_changed.Clear(); foreach (MagicaCloth cloth in m_cloths) { if (!Object.op_Implicit((Object)(object)cloth)) { continue; } List<ColliderComponent> colliderList = cloth.SerializeData.colliderCollisionConstraint.colliderList; ColliderComponent[] all = m_all; foreach (ColliderComponent val in all) { if (Object.op_Implicit((Object)(object)val)) { bool flag2 = use?.Contains(val) ?? false; if (flag2 && !colliderList.Contains(val)) { colliderList.Add(val); m_changed.Add(colliderList); } else if (!flag2 && colliderList.Remove(val)) { m_changed.Add(colliderList); } } } } foreach (MagicaCloth cloth2 in m_cloths) { if (Object.op_Implicit((Object)(object)cloth2) && m_changed.Contains(cloth2.SerializeData.colliderCollisionConstraint.colliderList)) { cloth2.SetParameterChange(); } } m_appliedCloths.Clear(); m_appliedCloths.AddRange(m_cloths); m_applied.Clear(); if (use != null) { m_applied.AddRange(use); } } private static bool Same(List<MagicaCloth> a, List<MagicaCloth> b) { if (a.Count != b.Count) { return false; } for (int i = 0; i < a.Count; i++) { if ((Object)(object)a[i] != (Object)(object)b[i]) { return false; } } return true; } } internal static class Perf { internal static int Count; internal static int Ends; internal static long Ticks; internal static long MaxTicks; internal static long MaxProbe; internal static long MaxApply; internal static long MaxEnd; internal static long First = -1L; internal static void Add(long probe, long apply) { long num = probe + apply; if (First < 0) { First = num; } Count++; Ticks += num; if (num > MaxTicks) { MaxTicks = num; } if (probe > MaxProbe) { MaxProbe = probe; } if (apply > MaxApply) { MaxApply = apply; } } internal static void AddEnd(long ticks) { Ends++; if (ticks > MaxEnd) { MaxEnd = ticks; } } internal static void Reset() { Count = (Ends = 0); Ticks = (MaxTicks = (MaxProbe = (MaxApply = (MaxEnd = 0L)))); } internal static double Ms(long ticks) { return (double)ticks * 1000.0 / (double)Stopwatch.Frequency; } } [BepInPlugin("rgeraskin.SeatedCapeFix", "SeatedCapeFix", "0.1.1")] public class Plugin : BaseUnityPlugin { public const string Guid = "rgeraskin.SeatedCapeFix"; public const string Name = "SeatedCapeFix"; public const string Version = "0.1.1"; internal static ConfigEntry<bool> Enabled; internal static ConfigEntry<bool> DebugLog; internal static ManualLogSource Log; private void Awake() { //IL_0050: Unknown result type (might be due to invalid IL or missing references) Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Cloth collides with the seat while sitting."); DebugLog = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "Log", false, "Log the seat each sitting player's cloth is given."); Log = ((BaseUnityPlugin)this).Logger; new Harmony("rgeraskin.SeatedCapeFix").PatchAll(); PreJit(typeof(CapeSeat)); PreJit(typeof(Perf)); } private static void PreJit(Type type) { MethodInfo[] methods = type.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); foreach (MethodInfo methodInfo in methods) { if (!methodInfo.IsAbstract && !methodInfo.ContainsGenericParameters) { try { methodInfo.MethodHandle.GetFunctionPointer(); } catch (Exception ex) { Log.LogDebug((object)("pre-JIT " + methodInfo.Name + ": " + ex.Message)); } } } } } [HarmonyPatch(typeof(Player), "Awake")] internal static class PlayerAwakePatch { private static void Postfix(Player __instance) { ((Component)__instance).gameObject.AddComponent<CapeSeat>(); } } } namespace System.Runtime.CompilerServices { [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] internal sealed class IgnoresAccessChecksToAttribute : Attribute { public IgnoresAccessChecksToAttribute(string assemblyName) { } } }