Decompiled source of WeaponSling v1.0.6
Mods/WeaponSling.dll
Decompiled 2 days ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Text; using BoneLib; using BoneLib.BoneMenu; using Il2CppInterop.Runtime.InteropTypes.Arrays; using Il2CppSLZ.Marrow; using Il2CppSLZ.VRMK; using MelonLoader; using MelonLoader.Preferences; using Microsoft.CodeAnalysis; using UnityEngine; using UnityEngine.Rendering; using WeaponSling; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: MelonInfo(typeof(Main), "WeaponSling", "1.0.6", "NoXxy ", null)] [assembly: MelonGame("Stress Level Zero", "BONELAB")] [assembly: MelonAdditionalDependencies(new string[] { "BoneLib" })] [assembly: AssemblyVersion("0.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 WeaponSling { internal class Body { private const float ShoulderUp = 0.17f; private const float ShoulderSide = 0.11f; private const float BackDown = 0.1f; private const float BackSide = 0.15f; private const float BackBehind = 0.12f; private const float ReferenceShoulderWidth = 0.33f; private const float ReferenceHeight = 1.76f; private float _torsoRadius = 0.15f; private bool _hasForward; private float _nextCalibrate; private Avatar _avatar; private Transform _neck; private Transform _upperArmL; private Transform _upperArmR; private Transform _chestBone; public bool Valid { get; private set; } public Vector3 Chest { get; private set; } public Vector3 Up { get; private set; } = Vector3.up; public Vector3 Forward { get; private set; } = Vector3.forward; public Vector3 Right { get; private set; } = Vector3.right; public Rigidbody ChestRb { get; private set; } public float Scale { get; private set; } = 1f; public bool UsingSkeleton { get { if ((Object)(object)_upperArmL != (Object)null && (Object)(object)_upperArmR != (Object)null && (Object)(object)_neck != (Object)null) { return (Object)(object)_chestBone != (Object)null; } return false; } } public void Reset() { Valid = false; ChestRb = null; _hasForward = false; _avatar = null; _neck = (_upperArmL = (_upperArmR = (_chestBone = null))); _nextCalibrate = 0f; } public void Refresh(float dt) { //IL_020f: Unknown result type (might be due to invalid IL or missing references) //IL_0215: Unknown result type (might be due to invalid IL or missing references) //IL_021a: Unknown result type (might be due to invalid IL or missing references) //IL_021f: Unknown result type (might be due to invalid IL or missing references) //IL_0223: Unknown result type (might be due to invalid IL or missing references) //IL_0149: Unknown result type (might be due to invalid IL or missing references) //IL_0154: Unknown result type (might be due to invalid IL or missing references) //IL_0159: Unknown result type (might be due to invalid IL or missing references) //IL_015e: Unknown result type (might be due to invalid IL or missing references) //IL_0163: Unknown result type (might be due to invalid IL or missing references) //IL_017c: Unknown result type (might be due to invalid IL or missing references) //IL_0181: Unknown result type (might be due to invalid IL or missing references) //IL_0186: 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_005e: 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_01d9: Unknown result type (might be due to invalid IL or missing references) //IL_01de: Unknown result type (might be due to invalid IL or missing references) //IL_01f3: 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_01fc: 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_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_0092: 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_0118: 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_00bc: 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_00c5: 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_00dd: Unknown result type (might be due to invalid IL or missing references) //IL_00e2: Unknown result type (might be due to invalid IL or missing references) //IL_00f7: 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_0100: Unknown result type (might be due to invalid IL or missing references) Valid = false; Transform val = null; Transform val2 = null; try { val = Player.Chest; val2 = Player.Head; } catch (Exception) { } if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null) { return; } if (Time.unscaledTime >= _nextCalibrate) { TryCalibrate(log: false); } if ((Object)(object)ChestRb == (Object)null) { ChestRb = FindChestRigidbody(val); } Up = Vector3.up; bool flag = false; Vector3 val4; try { flag = UsingSkeleton; if (flag) { Vector3 val3 = Vector3.ProjectOnPlane(_upperArmR.position - _upperArmL.position, Vector3.up); if (((Vector3)(ref val3)).sqrMagnitude > 0.0025f) { val4 = Vector3.Cross(((Vector3)(ref val3)).normalized, Vector3.up); Vector3 normalized = ((Vector3)(ref val4)).normalized; Vector3 forward; if (!_hasForward || !(dt > 0f)) { forward = normalized; } else { val4 = Vector3.Slerp(Forward, normalized, 1f - Mathf.Exp((0f - dt) / 0.05f)); forward = ((Vector3)(ref val4)).normalized; } Forward = forward; _hasForward = true; } Chest = _chestBone.position; } } catch (Exception) { flag = false; _upperArmL = null; _nextCalibrate = Time.unscaledTime + 0.5f; } if (!flag) { Chest = val.position; Vector3 val5 = Vector3.ProjectOnPlane(val2.forward, Vector3.up); if (!_hasForward && ((Vector3)(ref val5)).sqrMagnitude < 0.0001f) { val5 = Vector3.ProjectOnPlane(-val2.up, Vector3.up); } if (((Vector3)(ref val5)).sqrMagnitude > 0.04f || (!_hasForward && ((Vector3)(ref val5)).sqrMagnitude > 0.0001f)) { ((Vector3)(ref val5)).Normalize(); if (!_hasForward) { Forward = val5; } else if (dt > 0f) { val4 = Vector3.Slerp(Forward, val5, 1f - Mathf.Exp((0f - dt) / 0.25f)); Forward = ((Vector3)(ref val4)).normalized; } _hasForward = true; } } val4 = Vector3.Cross(Up, Forward); Right = ((Vector3)(ref val4)).normalized; Valid = true; } public void TryCalibrate(bool log) { //IL_013f: Unknown result type (might be due to invalid IL or missing references) //IL_014a: Unknown result type (might be due to invalid IL or missing references) _nextCalibrate = Time.unscaledTime + 2f; Avatar val = null; try { val = Player.Avatar; } catch (Exception) { } if ((Object)(object)val == (Object)null) { return; } bool flag = (Object)(object)_avatar == (Object)null || (Object)(object)_avatar != (Object)(object)val || !UsingSkeleton; if (!flag && !log) { return; } _avatar = val; _neck = (_upperArmL = (_upperArmR = (_chestBone = null))); try { Animator animator = val.animator; if ((Object)(object)animator != (Object)null) { _neck = animator.GetBoneTransform((HumanBodyBones)9); _upperArmL = animator.GetBoneTransform((HumanBodyBones)13); _upperArmR = animator.GetBoneTransform((HumanBodyBones)14); _chestBone = animator.GetBoneTransform((HumanBodyBones)8); if ((Object)(object)_chestBone == (Object)null) { _chestBone = animator.GetBoneTransform((HumanBodyBones)54); } if ((Object)(object)_chestBone == (Object)null) { _chestBone = animator.GetBoneTransform((HumanBodyBones)7); } } } catch (Exception) { _neck = (_upperArmL = (_upperArmR = (_chestBone = null))); } string value; if (UsingSkeleton) { float num = Vector3.Distance(_upperArmL.position, _upperArmR.position); Scale = Mathf.Clamp(num / 0.33f, 0.4f, 3f); _torsoRadius = Mathf.Clamp(num * 0.45f, 0.06f, 0.5f); value = $"skeleton, shoulders {num * 100f:0} cm apart"; } else { float num2 = 0f; try { num2 = val.height; } catch (Exception) { } Scale = ((num2 > 0.1f) ? Mathf.Clamp(num2 / 1.76f, 0.4f, 3f) : 1f); _torsoRadius = 0.15f * Scale; value = "no usable skeleton, sized from height"; } _hasForward = false; if (flag || log) { Main.Log.Msg($"Calibrated to avatar '{((Object)val).name}' ({value}): size x{Scale:0.00}, torso radius {_torsoRadius * 100f:0} cm."); } } public Vector3 Shoulder(bool supportLeft) { //IL_0074: 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_0084: 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_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_00a9: Unknown result type (might be due to invalid IL or missing references) //IL_00b3: Unknown result type (might be due to invalid IL or missing references) //IL_00b8: Unknown result type (might be due to invalid IL or missing references) //IL_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_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_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_0052: 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_006d: 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) if (UsingSkeleton) { try { Transform val = (supportLeft ? _upperArmL : _upperArmR); return Vector3.Lerp(_neck.position, val.position, 0.55f) + Up * (0.05f * Scale) - Forward * (0.01f * Scale); } catch (Exception) { } } return Chest + (Up * 0.17f + Right * (supportLeft ? (-0.11f) : 0.11f) - Forward * 0.01f) * Scale; } public Vector3 BackPoint(bool supportLeft) { //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_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_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_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_004a: 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) return Chest + (-Up * 0.1f + Right * (supportLeft ? 0.15f : (-0.15f)) - Forward * 0.12f) * Scale; } public Vector3 RearHang(bool supportLeft) { //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_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_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_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_004a: 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) return Chest + (-Up * 0.12f + Right * (supportLeft ? 0.17f : (-0.17f)) + Forward * 0.06f) * Scale; } public Vector3 TorsoClosest(Vector3 p) { //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_0011: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_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_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_0037: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_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) //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_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_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) Vector3 val = Chest + Up * 0.1f * Scale; Vector3 val2 = -Up * 0.55f * Scale; float num = Mathf.Clamp01(Vector3.Dot(p - val, val2) / ((Vector3)(ref val2)).sqrMagnitude); return val + val2 * num; } public void Collide(ref Vector3 p) { //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_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_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_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_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_0058: Unknown result type (might be due to invalid IL or missing references) //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_0068: 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_0077: 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_008f: 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_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00a5: Unknown result type (might be due to invalid IL or missing references) //IL_00aa: 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_00c4: 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_00ed: Unknown result type (might be due to invalid IL or missing references) //IL_00f3: Unknown result type (might be due to invalid IL or missing references) //IL_00fd: 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 scale = Scale; float torsoRadius = _torsoRadius; PushOut(ref p, Chest + (Up * 0.06f + Forward * 0.02f) * scale, torsoRadius); PushOut(ref p, Chest + (-Up * 0.18f + Forward * 0.01f) * scale, torsoRadius); PushOut(ref p, Chest - Up * 0.38f * scale, torsoRadius * 0.93f); PushOut(ref p, Shoulder(supportLeft: true) - Up * 0.075f * scale, 0.07f * scale); PushOut(ref p, Shoulder(supportLeft: false) - Up * 0.075f * scale, 0.07f * scale); } public Vector3 Outward(Vector3 p) { //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_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_0019: 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_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_002e: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0035: 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_0045: Unknown result type (might be due to invalid IL or missing references) Vector3 val = Chest + Up * Vector3.Dot(p - Chest, Up); Vector3 val2 = p - val; if (!(((Vector3)(ref val2)).sqrMagnitude > 0.0001f)) { return Forward; } return ((Vector3)(ref val2)).normalized; } public float Contact(Vector3 p) { //IL_0000: 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_000d: 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_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_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_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_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) float num = Vector3.Dot(p - Chest, Up) / Scale; if (num > 0.32f || num < -0.55f) { return 0f; } Vector3 val = Chest + Up * Vector3.Dot(p - Chest, Up); float num2 = Vector3.Distance(p, val); return 1f - Mathf.Clamp01((num2 - _torsoRadius) / (0.06f * Scale)); } public bool Near(Vector3 p) { //IL_0000: 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_000c: Unknown result type (might be due to invalid IL or missing references) Vector3 val = p - Chest; return ((Vector3)(ref val)).sqrMagnitude < 0.64000005f * Scale * Scale; } private static void PushOut(ref Vector3 p, Vector3 center, float radius) { //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_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_0025: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) Vector3 val = p - center; float sqrMagnitude = ((Vector3)(ref val)).sqrMagnitude; if (!(sqrMagnitude >= radius * radius) && !(sqrMagnitude < 1E-08f)) { p = center + val * (radius / Mathf.Sqrt(sqrMagnitude)); } } private static Rigidbody FindChestRigidbody(Transform chest) { try { PhysicsRig physicsRig = Player.PhysicsRig; if ((Object)(object)physicsRig != (Object)null) { Rigidbody val = null; foreach (Rigidbody componentsInChild in ((Component)physicsRig).GetComponentsInChildren<Rigidbody>(true)) { if (!((Object)(object)componentsInChild == (Object)null)) { if (string.Equals(((Object)componentsInChild).name, "Chest", StringComparison.OrdinalIgnoreCase)) { return componentsInChild; } if (string.Equals(((Object)componentsInChild).name, "Pelvis", StringComparison.OrdinalIgnoreCase)) { val = componentsInChild; } } } if ((Object)(object)val != (Object)null) { return val; } } } catch (Exception) { } if (!((Object)(object)chest != (Object)null)) { return null; } return ((Component)chest).GetComponentInParent<Rigidbody>(); } } internal struct SlingPoints { public Vector3 Front; public Vector3 Rear; public Vector3 Side; public Vector3 Down; public Vector3 Muzzle; public Vector3 Butt; public float Length; public Renderer Renderer; } internal static class GunShape { private static readonly HashSet<string> Logged = new HashSet<string>(); public static void ForgetLogged() { Logged.Clear(); } public static bool Measure(Gun gun, Rigidbody rb, float minLength, out SlingPoints pts, out string reason) { //IL_00fe: 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_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_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_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_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_0129: 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_0136: 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_0164: 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_0168: Unknown result type (might be due to invalid IL or missing references) //IL_016d: 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_0176: 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_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_01aa: Unknown result type (might be due to invalid IL or missing references) //IL_01ac: Unknown result type (might be due to invalid IL or missing references) //IL_01b6: Unknown result type (might be due to invalid IL or missing references) //IL_01bb: 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_01c4: 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_01ce: Unknown result type (might be due to invalid IL or missing references) //IL_01d1: Unknown result type (might be due to invalid IL or missing references) //IL_01d3: Unknown result type (might be due to invalid IL or missing references) //IL_01e5: Unknown result type (might be due to invalid IL or missing references) //IL_01ea: Unknown result type (might be due to invalid IL or missing references) //IL_01ec: Unknown result type (might be due to invalid IL or missing references) //IL_01f1: 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_02f9: Unknown result type (might be due to invalid IL or missing references) //IL_02fd: 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_0307: Unknown result type (might be due to invalid IL or missing references) //IL_030a: Unknown result type (might be due to invalid IL or missing references) //IL_030c: Unknown result type (might be due to invalid IL or missing references) //IL_0313: Unknown result type (might be due to invalid IL or missing references) //IL_0318: Unknown result type (might be due to invalid IL or missing references) //IL_031d: Unknown result type (might be due to invalid IL or missing references) //IL_031f: 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_0354: Unknown result type (might be due to invalid IL or missing references) //IL_035e: Unknown result type (might be due to invalid IL or missing references) //IL_0363: Unknown result type (might be due to invalid IL or missing references) //IL_0368: 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) //IL_033d: Unknown result type (might be due to invalid IL or missing references) //IL_0344: Unknown result type (might be due to invalid IL or missing references) //IL_0349: Unknown result type (might be due to invalid IL or missing references) //IL_034e: Unknown result type (might be due to invalid IL or missing references) //IL_039c: 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_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_03ac: 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) //IL_03df: Unknown result type (might be due to invalid IL or missing references) //IL_03e1: Unknown result type (might be due to invalid IL or missing references) //IL_03e5: Unknown result type (might be due to invalid IL or missing references) //IL_03ea: Unknown result type (might be due to invalid IL or missing references) //IL_03ef: Unknown result type (might be due to invalid IL or missing references) //IL_03f2: Unknown result type (might be due to invalid IL or missing references) //IL_03f4: Unknown result type (might be due to invalid IL or missing references) //IL_03fb: Unknown result type (might be due to invalid IL or missing references) //IL_0400: Unknown result type (might be due to invalid IL or missing references) //IL_0405: Unknown result type (might be due to invalid IL or missing references) //IL_0407: Unknown result type (might be due to invalid IL or missing references) //IL_041c: Unknown result type (might be due to invalid IL or missing references) //IL_0421: Unknown result type (might be due to invalid IL or missing references) //IL_0428: Unknown result type (might be due to invalid IL or missing references) //IL_042d: Unknown result type (might be due to invalid IL or missing references) //IL_0432: 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_0550: 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_0560: Unknown result type (might be due to invalid IL or missing references) //IL_0562: Unknown result type (might be due to invalid IL or missing references) //IL_0569: Unknown result type (might be due to invalid IL or missing references) //IL_056b: Unknown result type (might be due to invalid IL or missing references) //IL_0572: Unknown result type (might be due to invalid IL or missing references) //IL_0574: Unknown result type (might be due to invalid IL or missing references) //IL_057b: Unknown result type (might be due to invalid IL or missing references) //IL_057d: Unknown result type (might be due to invalid IL or missing references) //IL_0581: Unknown result type (might be due to invalid IL or missing references) //IL_0586: Unknown result type (might be due to invalid IL or missing references) //IL_058b: Unknown result type (might be due to invalid IL or missing references) //IL_058f: Unknown result type (might be due to invalid IL or missing references) //IL_0594: Unknown result type (might be due to invalid IL or missing references) //IL_0599: Unknown result type (might be due to invalid IL or missing references) //IL_04c2: Unknown result type (might be due to invalid IL or missing references) //IL_04c7: Unknown result type (might be due to invalid IL or missing references) //IL_04cb: Unknown result type (might be due to invalid IL or missing references) //IL_04d0: 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_04d9: Unknown result type (might be due to invalid IL or missing references) //IL_04e1: Unknown result type (might be due to invalid IL or missing references) pts = default(SlingPoints); reason = null; if ((((Object)gun).name ?? "").IndexOf("SPAWN_GUN", StringComparison.OrdinalIgnoreCase) >= 0) { reason = "spawn tool, not a weapon"; return false; } Transform firePointTransform = gun.firePointTransform; Grip triggerGrip = gun.triggerGrip; if ((Object)(object)firePointTransform == (Object)null || (Object)(object)triggerGrip == (Object)null) { reason = "no fire point or trigger grip"; return false; } List<Collider> list = new List<Collider>(); List<Collider> list2 = new List<Collider>(); foreach (Collider componentsInChild in ((Component)gun).GetComponentsInChildren<Collider>(false)) { if (!((Object)(object)componentsInChild == (Object)null) && !componentsInChild.isTrigger && componentsInChild.enabled) { list2.Add(componentsInChild); Rigidbody attachedRigidbody = componentsInChild.attachedRigidbody; if ((Object)(object)attachedRigidbody != (Object)null && (Object)(object)attachedRigidbody == (Object)(object)rb) { list.Add(componentsInChild); } } } if (list.Count == 0) { list = list2; } if (list.Count == 0) { reason = "no colliders to measure"; return false; } Vector3 position = firePointTransform.position; Vector3 val = firePointTransform.forward; Vector3 normalized = ((Vector3)(ref val)).normalized; Vector3 val2 = ((Component)triggerGrip).transform.position - position; float num = Vector3.Dot(val2, normalized); Vector3 val3 = val2 - normalized * num; if (((Vector3)(ref val3)).sqrMagnitude < 0.0001f) { val3 = -firePointTransform.up; } ((Vector3)(ref val3)).Normalize(); val = Vector3.Cross(val3, normalized); Vector3 normalized2 = ((Vector3)(ref val)).normalized; if (num > -0.05f) { reason = "trigger grip is not behind the muzzle"; return false; } float num2 = float.MaxValue; float num3 = 0f; for (int i = -2; i <= 9; i++) { float num4 = (float)i * 0.02f; Vector3 origin = position + normalized * (num - 1.8f) + val3 * num4; if (Cast(list, origin, normalized, 1.8199999f, out var best)) { float num5 = Vector3.Dot(((RaycastHit)(ref best)).point - position, normalized); if (num5 < num2) { num2 = num5; num3 = num4; } } } if (num2 == float.MaxValue) { reason = "could not find the back of the gun"; return false; } float num6 = 0f - num2; float num7 = Mathf.Max(num - num2, 0f); if (num6 < Mathf.Max(minLength, 0.1f)) { reason = $"too small ({num6:0.00} m)"; return false; } if (num6 > 2.5f) { reason = $"too long ({num6:0.00} m)"; return false; } bool flag = num7 >= 0.12f; float num8 = num2 + Mathf.Clamp(num7 * 0.2f, 0.01f, 0.05f); Vector3 val4 = position + normalized * num8; RaycastHit best2; bool flag2 = Cast(list, val4 + val3 * 0.25f, -val3, 0.3f, out best2); Vector3 rear = ((!flag2) ? (val4 + val3 * (num3 + 0.02f)) : (((RaycastHit)(ref best2)).point + val3 * 0.004f)); float num9 = num + Mathf.Max(0.04f, 0.12f * num6); float num10 = Mathf.Min(Mathf.Max(num2 * 0.28f, num9), -0.02f); Vector3 front = position + normalized * num10 + val3 * 0.025f; float num11 = num10; bool flag3 = false; for (int j = 0; j < 20; j++) { float num12 = num10 - (float)j * 0.015f; if (num12 < num9) { break; } Vector3 val5 = position + normalized * num12; if (Cast(list, val5 + val3 * 0.09f, -val3, 0.12f, out var best3)) { front = ((RaycastHit)(ref best3)).point + val3 * 0.004f; num11 = num12; flag3 = true; break; } } if (num11 - num8 < 0.06f) { reason = "swivels would be too close together"; return false; } Renderer renderer = null; float num13 = -1f; foreach (MeshRenderer componentsInChild2 in ((Component)gun).GetComponentsInChildren<MeshRenderer>(false)) { if ((Object)(object)componentsInChild2 == (Object)null || !((Renderer)componentsInChild2).enabled) { continue; } Material sharedMaterial = ((Renderer)componentsInChild2).sharedMaterial; if (!((Object)(object)sharedMaterial == (Object)null) && !((Object)(object)sharedMaterial.shader == (Object)null)) { Bounds bounds = ((Renderer)componentsInChild2).bounds; Vector3 size = ((Bounds)(ref bounds)).size; float num14 = size.x * size.y * size.z; if (((Object)sharedMaterial.shader).name != null && ((Object)sharedMaterial.shader).name.Contains("LitMAS")) { num14 *= 10f; } if (num14 > num13) { num13 = num14; renderer = (Renderer)(object)componentsInChild2; } } } pts = new SlingPoints { Front = front, Rear = rear, Side = normalized2, Down = val3, Muzzle = position, Butt = position + normalized * num2 + val3 * num3, Length = num6, Renderer = renderer }; string name = ((Object)gun).name; if (name != null && Logged.Add(name)) { Main.Log.Msg($"Measured '{name}': {num6:0.00} m long, {(flag ? $"stock {num7:0.00} m" : "no stock")}. Rear swivel {(num8 - num2) * 100f:0} cm from the {(flag ? "butt" : "back of the grip")}{(flag2 ? "" : " (estimated)")}, front swivel {(0f - num11) * 100f:0} cm from the muzzle{(flag3 ? "" : " (estimated)")}. {list.Count} colliders."); } return true; } private static bool Cast(List<Collider> colliders, Vector3 origin, Vector3 dir, float distance, out RaycastHit best) { //IL_0002: 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_0013: 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_004c: 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) best = default(RaycastHit); bool result = false; float num = float.MaxValue; Ray val = default(Ray); ((Ray)(ref val))..ctor(origin, dir); RaycastHit val2 = default(RaycastHit); foreach (Collider collider in colliders) { try { if (collider.Raycast(val, ref val2, distance) && ((RaycastHit)(ref val2)).distance < num) { num = ((RaycastHit)(ref val2)).distance; best = val2; result = true; } } catch (Exception) { } } return result; } } internal class Hardware { private const float StudGap = 0.003f; private const float LoopHalfHeight = 0.008f; private const float Tube = 0.0018f; private static readonly Dictionary<int, Mesh> LoopMeshes = new Dictionary<int, Mesh>(); private readonly Transform _gunT; private readonly Vector3 _anchorLocal; private readonly Vector3 _sideLocal; private readonly Vector3 _downLocal; private readonly int _layer; private readonly Renderer _reference; private GameObject _stud; private GameObject _loop; private MeshFilter _loopFilter; private Vector3 _dir; private bool _hasDir; public Hardware(Transform gunT, Vector3 anchorLocal, Vector3 sideLocal, Vector3 downLocal, int layer, Renderer reference, float strapWidth) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) _gunT = gunT; _anchorLocal = anchorLocal; _sideLocal = sideLocal; _downLocal = downLocal; _layer = layer; _reference = reference; Build(strapWidth); } private void Build(float strapWidth) { //IL_0074: 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_007c: 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_0087: 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_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_00b6: 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_011e: Unknown result type (might be due to invalid IL or missing references) //IL_0128: Expected O, but got Unknown //IL_0151: 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_01ab: Unknown result type (might be due to invalid IL or missing references) //IL_01b1: Unknown result type (might be due to invalid IL or missing references) //IL_01b6: Unknown result type (might be due to invalid IL or missing references) //IL_01bb: Unknown result type (might be due to invalid IL or missing references) Material val = StrapLooks.Metal(_reference); float num = ParentScale(); try { _stud = GameObject.CreatePrimitive((PrimitiveType)2); ((Object)_stud).name = "WeaponSling Stud"; Collider component = _stud.GetComponent<Collider>(); if ((Object)(object)component != (Object)null) { Object.DestroyImmediate((Object)(object)component); } _stud.layer = _layer; Transform transform = _stud.transform; transform.SetParent(_gunT, false); Vector3 val2 = Down(); transform.position = Anchor() - val2 * 0.0015f; transform.rotation = Quaternion.FromToRotation(Vector3.up, val2); transform.localScale = new Vector3(0.008f, 0.0035f, 0.008f) / num; MeshRenderer component2 = _stud.GetComponent<MeshRenderer>(); if ((Object)(object)component2 != (Object)null) { if ((Object)(object)val != (Object)null) { ((Renderer)component2).sharedMaterial = val; } ((Renderer)component2).shadowCastingMode = (ShadowCastingMode)0; } } catch (Exception ex) { Main.Log.Warning("Could not add sling stud: " + ex.Message); } try { _loop = new GameObject("WeaponSling Swivel Loop"); _loop.layer = _layer; Transform transform2 = _loop.transform; transform2.SetParent(_gunT, false); transform2.localScale = Vector3.one / num; _loopFilter = _loop.AddComponent<MeshFilter>(); _loopFilter.sharedMesh = LoopMesh(strapWidth); MeshRenderer val3 = _loop.AddComponent<MeshRenderer>(); if ((Object)(object)val != (Object)null) { ((Renderer)val3).sharedMaterial = val; } ((Renderer)val3).shadowCastingMode = (ShadowCastingMode)0; StrapEnd(Anchor() + Down()); } catch (Exception ex2) { Main.Log.Warning("Could not add sling swivel: " + ex2.Message); } } public void Resize(float strapWidth) { if ((Object)(object)_loopFilter != (Object)null) { _loopFilter.sharedMesh = LoopMesh(strapWidth); } } public Vector3 StrapEnd(Vector3 toward) { //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_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_0015: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_001f: 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_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_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) //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_005a: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_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_006e: 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_0077: 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_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_0081: 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_00aa: 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_00bd: Unknown result type (might be due to invalid IL or missing references) //IL_00c2: Unknown result type (might be due to invalid IL or missing references) //IL_00c7: Unknown result type (might be due to invalid IL or missing references) //IL_00d8: Unknown result type (might be due to invalid IL or missing references) //IL_00dd: Unknown result type (might be due to invalid IL or missing references) //IL_00e2: Unknown result type (might be due to invalid IL or missing references) //IL_00e7: Unknown result type (might be due to invalid IL or missing references) //IL_0105: 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_010d: 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_0116: 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_00f7: 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_0169: 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_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_0137: 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_0143: 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_0152: Unknown result type (might be due to invalid IL or missing references) //IL_0155: Unknown result type (might be due to invalid IL or missing references) //IL_015a: Unknown result type (might be due to invalid IL or missing references) //IL_015f: Unknown result type (might be due to invalid IL or missing references) Vector3 val = Anchor(); Vector3 val2 = Down(); Vector3 val3 = _gunT.TransformDirection(_sideLocal); Vector3 normalized = ((Vector3)(ref val3)).normalized; Vector3 val4 = toward - val; if (((Vector3)(ref val4)).sqrMagnitude < 1E-06f) { val4 = val2; } ((Vector3)(ref val4)).Normalize(); float num = Vector3.Dot(val4, val2); if (num < 0.2f) { val3 = val4 + val2 * (0.2f - num); val4 = ((Vector3)(ref val3)).normalized; } Vector3 dir; if (!_hasDir) { dir = val4; } else { val3 = Vector3.Slerp(_dir, val4, 0.5f); dir = ((Vector3)(ref val3)).normalized; } _dir = dir; _hasDir = true; Vector3 val5 = normalized - _dir * Vector3.Dot(normalized, _dir); if (((Vector3)(ref val5)).sqrMagnitude < 1E-06f) { val5 = Vector3.Cross(_dir, Vector3.up); } if (((Vector3)(ref val5)).sqrMagnitude < 1E-06f) { val5 = Vector3.right; } ((Vector3)(ref val5)).Normalize(); val3 = Vector3.Cross(val5, _dir); Vector3 normalized2 = ((Vector3)(ref val3)).normalized; if ((Object)(object)_loop != (Object)null) { Transform transform = _loop.transform; transform.position = val + _dir * 0.011f; transform.rotation = Quaternion.LookRotation(normalized2, -_dir); } return val + _dir * 0.0172f; } public void Dispose() { try { if ((Object)(object)_stud != (Object)null) { Object.Destroy((Object)(object)_stud); } } catch (Exception) { } try { if ((Object)(object)_loop != (Object)null) { Object.Destroy((Object)(object)_loop); } } catch (Exception) { } _stud = null; _loop = null; } private Vector3 Anchor() { //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) return _gunT.TransformPoint(_anchorLocal); } private Vector3 Down() { //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_0014: Unknown result type (might be due to invalid IL or missing references) Vector3 val = _gunT.TransformDirection(_downLocal); return ((Vector3)(ref val)).normalized; } private float ParentScale() { //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_000c: 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_0019: Unknown result type (might be due to invalid IL or missing references) Vector3 lossyScale = _gunT.lossyScale; return Mathf.Max(Mathf.Abs(lossyScale.x + lossyScale.y + lossyScale.z) / 3f, 0.0001f); } private static Mesh LoopMesh(float strapWidth) { //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_00cf: 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_00dd: 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_00f3: Unknown result type (might be due to invalid IL or missing references) //IL_00fe: Unknown result type (might be due to invalid IL or missing references) //IL_0100: 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_010c: 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_0212: Unknown result type (might be due to invalid IL or missing references) //IL_0219: Expected O, but got Unknown int key = Mathf.RoundToInt(strapWidth * 1000f); if (LoopMeshes.TryGetValue(key, out var value) && (Object)(object)value != (Object)null) { return value; } float num = strapWidth * 0.5f + 0.004f; float num2 = 0.008f; Il2CppStructArray<Vector3> val = new Il2CppStructArray<Vector3>(108L); Il2CppStructArray<Vector3> val2 = new Il2CppStructArray<Vector3>(108L); Vector3 val3 = default(Vector3); for (int i = 0; i < 18; i++) { float num3 = (float)i * (float)Math.PI * 2f / 18f; ((Vector3)(ref val3))..ctor(num * Mathf.Cos(num3), num2 * Mathf.Sin(num3), 0f); Vector3 val4 = new Vector3(Mathf.Cos(num3) / num, Mathf.Sin(num3) / num2, 0f); Vector3 normalized = ((Vector3)(ref val4)).normalized; for (int j = 0; j < 6; j++) { float num4 = (float)j * (float)Math.PI * 2f / 6f; Vector3 val5 = normalized * Mathf.Cos(num4) + Vector3.forward * Mathf.Sin(num4); ((Il2CppArrayBase<Vector3>)(object)val)[i * 6 + j] = val3 + val5 * 0.0018f; ((Il2CppArrayBase<Vector3>)(object)val2)[i * 6 + j] = val5; } } Il2CppStructArray<int> val6 = new Il2CppStructArray<int>(648L); int num5 = 0; for (int k = 0; k < 18; k++) { int num6 = (k + 1) % 18; for (int l = 0; l < 6; l++) { int num7 = (l + 1) % 6; int num8 = k * 6 + l; int num9 = num6 * 6 + l; int num10 = k * 6 + num7; int num11 = num6 * 6 + num7; ((Il2CppArrayBase<int>)(object)val6)[num5++] = num8; ((Il2CppArrayBase<int>)(object)val6)[num5++] = num9; ((Il2CppArrayBase<int>)(object)val6)[num5++] = num10; ((Il2CppArrayBase<int>)(object)val6)[num5++] = num9; ((Il2CppArrayBase<int>)(object)val6)[num5++] = num11; ((Il2CppArrayBase<int>)(object)val6)[num5++] = num10; } } Mesh val7 = new Mesh(); ((Object)val7).name = "WeaponSling Loop"; ((Object)val7).hideFlags = (HideFlags)32; val7.vertices = val; val7.normals = val2; val7.triangles = val6; val7.RecalculateBounds(); LoopMeshes[key] = val7; return val7; } } public class Main : MelonMod { internal static Instance Log; internal static MelonPreferences_Entry<bool> Enabled; internal static MelonPreferences_Entry<bool> SlingsOnAllGuns; internal static MelonPreferences_Entry<bool> AutoSling; internal static MelonPreferences_Entry<string> Style; private SlingManager _manager; public override void OnInitializeMelon() { Log = ((MelonBase)this).LoggerInstance; MelonPreferences_Category obj = MelonPreferences.CreateCategory("WeaponSling"); Enabled = obj.CreateEntry<bool>("Enabled", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null); SlingsOnAllGuns = obj.CreateEntry<bool>("SlingsOnAllGuns", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null); AutoSling = obj.CreateEntry<bool>("AutoSling", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null); Style = obj.CreateEntry<string>("Style", "Black", (string)null, (string)null, false, false, (ValueValidator)null, (string)null); _manager = new SlingManager(); Hooking.OnGrabObject += OnGrabObject; Hooking.OnLevelUnloaded += OnLevelUnloaded; SlingMenu.TryCreate(_manager); Log.Msg("WeaponSling v1.0.6 by NoXxy loaded. "); } private void OnGrabObject(GameObject grabbed, Hand hand) { if (!Enabled.Value) { return; } try { _manager.OnGrab(grabbed, hand); } catch (Exception ex) { Log.Warning("Grab handling failed: " + ex.GetType().Name + ": " + ex.Message); } } private void OnLevelUnloaded() { _manager.Clear(); } public override void OnUpdate() { if (!Enabled.Value) { _manager.Clear(); return; } try { _manager.Update(); } catch (Exception e) { _manager.ReportError("update", e); } } public override void OnFixedUpdate() { if (!Enabled.Value) { return; } try { _manager.FixedUpdate(); } catch (Exception e) { _manager.ReportError("physics", e); } } public override void OnLateUpdate() { if (!Enabled.Value) { return; } try { _manager.LateUpdate(); } catch (Exception e) { _manager.ReportError("strap", e); } } } internal enum SlingState { Loose, Held, Hanging, StrapInHand } internal class Sling { public const int N = 24; public const int ShoulderIdx = 10; public const int BackIdx = 17; private const float FrontHang = 0.5f; private const float FrontHeld = 1.15f; private const float BackLength = 0.6f; private const float RearLength = 0.36f; private const float LooseSlack = 1.15f; private const float Damping = 0.985f; private const int Iterations = 12; private const float SpringStart = 300f; private const float SpringFull = 2500f; private const float SpringRamp = 0.6f; private const float Damper = 80f; private const float HandSpring = 3000f; private const float HandDamper = 100f; private const float ChestMassScale = 6f; private const float HandMassScale = 1.5f; public readonly Gun Gun; public readonly InteractableHost Host; public readonly Rigidbody Rb; public readonly int Id; public readonly Renderer GunRenderer; public float LastDistance; public float PendingDt; public int Errors; private readonly Transform _rbT; private readonly Vector3 _frontLocal; private readonly Vector3 _rearLocal; private readonly Vector3 _sideLocal; private readonly Vector3 _downLocal; private readonly Vector3 _muzzleLocal; private readonly Vector3 _stockLocal; private readonly float _looseLength; private readonly int _layer; private bool _supportLeft = true; private float _wornBlend; private float _frontLength = 0.5f; private readonly Vector3[] _p = (Vector3[])(object)new Vector3[24]; private readonly Vector3[] _prev = (Vector3[])(object)new Vector3[24]; private readonly Vector3[] _old = (Vector3[])(object)new Vector3[24]; private readonly float[] _invMass = new float[24]; private readonly float[] _rest = new float[23]; private bool _ropeReady; private Vector3 _lastFront; private float _floorY = float.NegativeInfinity; private bool _floorChecked; private int _floorFrame; private float _still; private StrapLook _look; private GameObject _strapGo; private Mesh _mesh; private MeshRenderer _strapRenderer; private Il2CppStructArray<Vector3> _verts; private Il2CppStructArray<Vector3> _normals; private Il2CppStructArray<Vector2> _uvs; private Hardware _frontHw; private Hardware _rearHw; private GameObject _buckle; private bool _visible = true; private ConfigurableJoint _frontJoint; private ConfigurableJoint _rearJoint; private Rigidbody _frontTarget; private Rigidbody _rearTarget; private bool _frontToShoulder; private bool _rearToBack; private float _jointSince; private int _jointBreaks; private float _savedDrag = -1f; private float _savedAngularDrag; private readonly List<Collider> _gunColliders = new List<Collider>(); private readonly List<KeyValuePair<Collider, Collider>> _ignored = new List<KeyValuePair<Collider, Collider>>(); private int _ignorePasses; private bool _restorePending; private float _restoreDeadline; private Hand _strapHand; private int _grabIdx; private const int VertsPerPoint = 8; public SlingState State { get; private set; } public bool Worn { get; private set; } public Hand StrapHand => _strapHand; public float Length { get; private set; } public bool Alive { get { try { return (Object)(object)Gun != (Object)null && (Object)(object)Rb != (Object)null && (Object)(object)_rbT != (Object)null; } catch (Exception) { return false; } } } private Sling(Gun gun, int id, Rigidbody rb, Renderer renderer, Vector3 frontWorld, Vector3 rearWorld, Vector3 sideWorld, Vector3 downWorld, Vector3 muzzleWorld, Vector3 stockWorld, StrapStyle style) { //IL_00c8: 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_00db: Unknown result type (might be due to invalid IL or missing references) //IL_00dd: Unknown result type (might be due to invalid IL or missing references) //IL_00e2: 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_00f0: Unknown result type (might be due to invalid IL or missing references) //IL_00f5: Unknown result type (might be due to invalid IL or missing references) //IL_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_0108: 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_0116: 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_0127: 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_012e: 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_0136: 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_01e5: 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_0215: 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_0221: Unknown result type (might be due to invalid IL or missing references) Gun = gun; Host = gun.host; Rb = rb; Id = id; GunRenderer = renderer; _rbT = ((Component)rb).transform; _frontLocal = _rbT.InverseTransformPoint(frontWorld); _rearLocal = _rbT.InverseTransformPoint(rearWorld); _sideLocal = _rbT.InverseTransformDirection(sideWorld); _downLocal = _rbT.InverseTransformDirection(downWorld); _muzzleLocal = _rbT.InverseTransformPoint(muzzleWorld); _stockLocal = _rbT.InverseTransformPoint(stockWorld); _looseLength = Mathf.Max(Vector3.Distance(frontWorld, rearWorld) * 1.15f, 0.15f); _layer = (((Object)(object)renderer != (Object)null) ? ((Component)renderer).gameObject.layer : ((Component)gun).gameObject.layer); foreach (Collider componentsInChild in ((Component)gun).GetComponentsInChildren<Collider>(true)) { if ((Object)(object)componentsInChild != (Object)null && !componentsInChild.isTrigger) { _gunColliders.Add(componentsInChild); } } _look = StrapLooks.Get(style, renderer); CreateStrapObject(); _frontHw = new Hardware(_rbT, _frontLocal, _sideLocal, _downLocal, _layer, renderer, _look.Width); _rearHw = new Hardware(_rbT, _rearLocal, _sideLocal, _downLocal, _layer, renderer, _look.Width); } public static Sling TryCreate(Gun gun, int id, StrapStyle style, float minLength, out string reason) { //IL_0052: 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_005e: 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_006a: 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) reason = null; InteractableHost host = gun.host; if ((Object)(object)host == (Object)null) { reason = "no interactable host"; return null; } Rigidbody rb = host.Rb; if ((Object)(object)rb == (Object)null) { reason = "no rigidbody"; return null; } if (!GunShape.Measure(gun, rb, minLength, out var pts, out reason)) { return null; } return new Sling(gun, id, rb, pts.Renderer, pts.Front, pts.Rear, pts.Side, pts.Down, pts.Muzzle, pts.Butt, style) { Length = pts.Length }; } public void SetWorn(bool worn) { Worn = worn; } public void SetWorn(bool worn, bool supportLeft) { Worn = worn; _supportLeft = supportLeft; } public void GrabStrap(Hand hand, int index) { _strapHand = hand; _grabIdx = index; } public void ReleaseStrap() { _strapHand = null; } public void Tick(Body body, Hand left, Hand right, List<Collider> playerColliders, float now, bool autoSling) { if (!((Component)Gun).gameObject.activeInHierarchy) { _strapHand = null; if (State != SlingState.Loose) { SetState(SlingState.Loose, body, playerColliders, now); } SetVisible(visible: false); return; } SetVisible(visible: true); bool num = (Object)(object)Host != (Object)null && Host.IsAttached; bool isKinematic = Rb.isKinematic; if ((Object)(object)_strapHand != (Object)null && (isKinematic || _strapHand.HasAttachedObject())) { _strapHand = null; } else if ((Object)(object)_strapHand == (Object)null) { _strapHand = null; } SlingState slingState = (num ? SlingState.Held : (((Object)(object)_strapHand != (Object)null) ? SlingState.StrapInHand : ((!isKinematic && Worn && autoSling && body.Valid && (Object)(object)body.ChestRb != (Object)null && (State == SlingState.Held || State == SlingState.Hanging || State == SlingState.StrapInHand)) ? SlingState.Hanging : SlingState.Loose))); if (slingState != State) { SetState(slingState, body, playerColliders, now); } if (State == SlingState.Held) { UpdateSupportSide(left, right); } if (State == SlingState.Hanging || State == SlingState.StrapInHand) { MaintainJoints(body, playerColliders, now); } if (_restorePending) { TryRestoreCollisions(body, now); } } private void SetState(SlingState target, Body body, List<Collider> playerColliders, float now) { DestroyJoints(); State = target; _still = 0f; switch (target) { case SlingState.Hanging: ConnectToBody(body, now); IgnoreBody(playerColliders); ApplyDrag(); return; case SlingState.StrapInHand: ConnectToHand(body, now); IgnoreBody(playerColliders); ApplyDrag(); return; case SlingState.Held: RestoreDrag(); return; } RestoreDrag(); if (_ignored.Count > 0) { _restorePending = true; _restoreDeadline = now + 3f; } } private void UpdateSupportSide(Hand left, Hand right) { //IL_001c: 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_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0037: 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_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) Grip triggerGrip = Gun.triggerGrip; if (!((Object)(object)triggerGrip == (Object)null)) { Vector3 position = ((Component)triggerGrip).transform.position; Vector3 val; int num; if (HoldsThis(left)) { val = Palm(left) - position; num = ((((Vector3)(ref val)).sqrMagnitude < 0.0144f) ? 1 : 0); } else { num = 0; } bool flag = (byte)num != 0; int num2; if (HoldsThis(right)) { val = Palm(right) - position; num2 = ((((Vector3)(ref val)).sqrMagnitude < 0.0144f) ? 1 : 0); } else { num2 = 0; } bool flag2 = (byte)num2 != 0; bool flag3 = _supportLeft; if (flag2 && !flag) { flag3 = true; } else if (flag && !flag2) { flag3 = false; } if (flag3 != _supportLeft) { _supportLeft = flag3; _wornBlend = Mathf.Min(_wornBlend, 0.4f); } } } private bool HoldsThis(Hand hand) { if ((Object)(object)hand == (Object)null || (Object)(object)Host == (Object)null) { return false; } int num = Host.HandCount(); for (int i = 0; i < num; i++) { Hand hand2 = Host.GetHand(i); if ((Object)(object)hand2 != (Object)null && (Object)(object)hand2 == (Object)(object)hand) { return true; } } return false; } private static float BodyScale(Body body) { if (!body.Valid) { return 1f; } return body.Scale; } private void UpdateRestLengths(Body body, float dt, Vector3 frontEnd) { //IL_001e: 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) float num = BodyScale(body); float num2 = 0.5f; if (State == SlingState.Held && body.Valid) { num2 = Mathf.Clamp(Vector3.Distance(frontEnd, body.Shoulder(_supportLeft)) / num * 1.05f + 0.03f, 0.5f, 1.15f); } if (_wornBlend <= 0f) { _frontLength = num2; } else { _frontLength = Mathf.MoveTowards(_frontLength, num2, dt * 2.5f); } float num3 = _looseLength / 23f; float num4 = Mathf.Lerp(num3, _frontLength * num / 10f, _wornBlend); float num5 = Mathf.Lerp(num3, 0.6f * num / 7f, _wornBlend); float num6 = Mathf.Lerp(num3, 0.36f * num / 6f, _wornBlend); for (int i = 0; i < 23; i++) { _rest[i] = ((i < 10) ? num4 : ((i < 17) ? num5 : num6)); } } private void ConnectToBody(Body body, float now) { //IL_001b: 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) //IL_0061: 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_0079: Unknown result type (might be due to invalid IL or missing references) Rigidbody chestRb = body.ChestRb; if (!((Object)(object)chestRb == (Object)null)) { float num = BodyScale(body); _frontJoint = MakeJoint(_frontLocal, chestRb, ((Component)chestRb).transform.InverseTransformPoint(body.Shoulder(_supportLeft)), 0.5f * num * 0.95f, 300f, 80f, 6f); _rearJoint = MakeJoint(_rearLocal, chestRb, ((Component)chestRb).transform.InverseTransformPoint(body.RearHang(_supportLeft)), 0.36f * num * 0.55f, 300f, 80f, 6f); _frontTarget = chestRb; _rearTarget = chestRb; _frontToShoulder = true; _rearToBack = true; _jointSince = now; _ignorePasses = 0; } } private void ConnectToHand(Body body, float now) { //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_01ea: Unknown result type (might be due to invalid IL or missing references) //IL_01f0: 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_0227: 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_0163: Unknown result type (might be due to invalid IL or missing references) //IL_0168: Unknown result type (might be due to invalid IL or missing references) //IL_0197: Unknown result type (might be due to invalid IL or missing references) //IL_019d: 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_009d: 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_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) Hand strapHand = _strapHand; Rigidbody val = (((Object)(object)strapHand != (Object)null) ? strapHand.rb : null); if (!((Object)(object)val == (Object)null)) { Vector3 connectedAnchor = ((Component)val).transform.InverseTransformPoint(Palm(strapHand)); Rigidbody val2 = (body.Valid ? body.ChestRb : null); float num = BodyScale(body); _frontToShoulder = false; _rearToBack = false; if (Worn && (Object)(object)val2 != (Object)null && _grabIdx <= 10) { float num2 = (float)_grabIdx * _rest[0]; _frontJoint = MakeJoint(_frontLocal, val, connectedAnchor, num2 * 0.95f, 3000f, 100f, 1.5f); _rearJoint = MakeJoint(_rearLocal, val2, ((Component)val2).transform.InverseTransformPoint(body.RearHang(_supportLeft)), 0.36f * num * 0.55f, 2500f, 80f, 6f); _frontTarget = val; _rearTarget = val2; _rearToBack = true; } else if (Worn && (Object)(object)val2 != (Object)null) { float num3 = (float)(23 - _grabIdx) * _rest[22]; _frontJoint = MakeJoint(_frontLocal, val2, ((Component)val2).transform.InverseTransformPoint(body.Shoulder(_supportLeft)), 0.5f * num * 0.95f, 2500f, 80f, 6f); _rearJoint = MakeJoint(_rearLocal, val, connectedAnchor, num3 * 0.95f, 3000f, 100f, 1.5f); _frontTarget = val2; _rearTarget = val; _frontToShoulder = true; } else { float num4 = _looseLength / 23f; _frontJoint = MakeJoint(_frontLocal, val, connectedAnchor, Mathf.Max((float)_grabIdx * num4, 0.03f), 3000f, 100f, 1.5f); _rearJoint = MakeJoint(_rearLocal, val, connectedAnchor, Mathf.Max((float)(23 - _grabIdx) * num4, 0.03f), 3000f, 100f, 1.5f); _frontTarget = val; _rearTarget = val; } _jointSince = now; _ignorePasses = 0; } } private ConfigurableJoint MakeJoint(Vector3 anchor, Rigidbody connected, Vector3 connectedAnchor, float limit, float spring, float damper, float connectedMassScale) { //IL_001f: 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_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_0089: Unknown result type (might be due to invalid IL or missing references) ConfigurableJoint obj = ((Component)Rb).gameObject.AddComponent<ConfigurableJoint>(); ((Joint)obj).autoConfigureConnectedAnchor = false; ((Joint)obj).connectedBody = connected; ((Joint)obj).anchor = anchor; ((Joint)obj).connectedAnchor = connectedAnchor; obj.xMotion = (ConfigurableJointMotion)1; obj.yMotion = (ConfigurableJointMotion)1; obj.zMotion = (ConfigurableJointMotion)1; obj.angularXMotion = (ConfigurableJointMotion)2; obj.angularYMotion = (ConfigurableJointMotion)2; obj.angularZMotion = (ConfigurableJointMotion)2; SoftJointLimit linearLimit = obj.linearLimit; ((SoftJointLimit)(ref linearLimit)).limit = Mathf.Max(limit, 0.02f); ((SoftJointLimit)(ref linearLimit)).contactDistance = 0.02f; ((SoftJointLimit)(ref linearLimit)).bounciness = 0f; obj.linearLimit = linearLimit; SetSpring(obj, spring, damper); ((Joint)obj).enableCollision = false; ((Joint)obj).enablePreprocessing = false; ((Joint)obj).connectedMassScale = connectedMassScale; ((Joint)obj).breakForce = 20000f; return obj; } private static void SetSpring(ConfigurableJoint j, float spring, float damper) { //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_0018: Unknown result type (might be due to invalid IL or missing references) SoftJointLimitSpring linearLimitSpring = j.linearLimitSpring; ((SoftJointLimitSpring)(ref linearLimitSpring)).spring = spring; ((SoftJointLimitSpring)(ref linearLimitSpring)).damper = damper; j.linearLimitSpring = linearLimitSpring; } private void MaintainJoints(Body body, List<Collider> playerColliders, float now) { //IL_0178: 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_021e: Unknown result type (might be due to invalid IL or missing references) //IL_0223: Unknown result type (might be due to invalid IL or missing references) //IL_0225: Unknown result type (might be due to invalid IL or missing references) //IL_0228: 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_0232: 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) //IL_01b0: Unknown result type (might be due to invalid IL or missing references) //IL_0244: Unknown result type (might be due to invalid IL or missing references) if (((Object)(object)_frontTarget != (Object)null && (Object)(object)_frontJoint == (Object)null) || ((Object)(object)_rearTarget != (Object)null && (Object)(object)_rearJoint == (Object)null)) { _jointBreaks++; if (_jointBreaks > 3) { Main.Log.Msg("Sling joint kept breaking, dropping the gun."); Worn = false; _strapHand = null; SetState(SlingState.Loose, body, playerColliders, now); } else { SetState(State, body, playerColliders, now); } return; } float num = Mathf.Clamp01((now - _jointSince) / 0.6f); if (num < 1f || now - _jointSince < 0.70000005f) { float spring = Mathf.Lerp(300f, 2500f, num * num); if ((Object)(object)_frontJoint != (Object)null && (Object)(object)_frontTarget == (Object)(object)body.ChestRb) { SetSpring(_frontJoint, spring, 80f); } if ((Object)(object)_rearJoint != (Object)null && (Object)(object)_rearTarget == (Object)(object)body.ChestRb) { SetSpring(_rearJoint, spring, 80f); } } if (body.Valid && (Object)(object)body.ChestRb != (Object)null) { Transform transform = ((Component)body.ChestRb).transform; if (_frontToShoulder && (Object)(object)_frontJoint != (Object)null) { UpdateConnectedAnchor(_frontJoint, transform.InverseTransformPoint(body.Shoulder(_supportLeft))); } if (_rearToBack && (Object)(object)_rearJoint != (Object)null) { UpdateConnectedAnchor(_rearJoint, transform.InverseTransformPoint(body.RearHang(_supportLeft))); } } float num2 = now - _jointSince; if ((_ignorePasses == 0 && num2 > 0.3f) || (_ignorePasses == 1 && num2 > 1.2f)) { _ignorePasses++; IgnoreBody(playerColliders); } if (State == SlingState.Hanging && body.Valid) { float num3 = 1.6f * body.Scale; Vector3 worldCenterOfMass = Rb.worldCenterOfMass; Vector3 val = worldCenterOfMass - body.Chest; if (((Vector3)(ref val)).sqrMagnitude > num3 * num3) { BringBack(body, worldCenterOfMass); } } } public void PushOutOfBody(Body body) { //IL_0044: 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_0049: 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_0074: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Unknown result type (might be due to invalid IL or missing references) //IL_0093: Unknown result type (might be due to invalid IL or missing references) //IL_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_00b2: 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_00d1: Unknown result type (might be due to invalid IL or missing references) //IL_00e0: 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) if ((State == SlingState.Hanging || State == SlingState.StrapInHand) && body.Valid && !Rb.isKinematic) { Vector3 bodyVel = (((Object)(object)body.ChestRb != (Object)null) ? body.ChestRb.velocity : Vector3.zero); float mass = Rb.mass * 0.2f; PushPoint(body, _rbT.TransformPoint(_frontLocal), 0.15f, bodyVel, mass); PushPoint(body, _rbT.TransformPoint(_rearLocal), 0.15f, bodyVel, mass); PushPoint(body, _rbT.TransformPoint(_muzzleLocal), 0.16f, bodyVel, mass); PushPoint(body, _rbT.TransformPoint(_stockLocal), 0.16f, bodyVel, mass); PushPoint(body, Rb.worldCenterOfMass, 0.18f, bodyVel, mass); } } private void PushPoint(Body body, Vector3 p, float radius, Vector3 bodyVel, float mass) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0036: 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_002f: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_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) //IL_004e: 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_0089: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Unknown result type (might be due to invalid IL or missing references) Vector3 val = body.TorsoClosest(p); Vector3 val2 = p - val; float magnitude = ((Vector3)(ref val2)).magnitude; float num = radius * body.Scale; if (!(magnitude >= num)) { Vector3 val3 = ((magnitude > 0.0001f) ? (val2 / magnitude) : body.Forward); float num2 = num - magnitude; float num3 = Vector3.Dot(Rb.GetPointVelocity(p) - bodyVel, val3); float num4 = num2 * 900f - Mathf.Min(num3, 0f) * 40f; if (!(num4 <= 0f)) { Rb.AddForceAtPosition(val3 * (Mathf.Min(num4, 60f) * mass), p, (ForceMode)0); } } } private static void UpdateConnectedAnchor(ConfigurableJoint j, Vector3 wanted) { //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_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_001c: Unknown result type (might be due to invalid IL or missing references) Vector3 val = ((Joint)j).connectedAnchor - wanted; if (((Vector3)(ref val)).sqrMagnitude > 0.0001f) { ((Joint)j).connectedAnchor = wanted; } } private void BringBack(Body body, Vector3 com) { //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_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_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_0036: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_0058: 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_006b: 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_0085: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Unknown result type (might be due to invalid IL or missing references) Vector3 val = body.Chest + (-body.Up * 0.3f + body.Forward * 0.18f) * body.Scale; Vector3 position = _rbT.position + (val - com); _rbT.position = position; Rb.position = position; Rb.velocity = (((Object)(object)body.ChestRb != (Object)null) ? body.ChestRb.velocity : Vector3.zero); Rb.angularVelocity = Vector3.zero; _ropeReady = false; } private void DestroyJoints() { if ((Object)(object)_frontJoint != (Object)null) { Object.Destroy((Object)(object)_frontJoint); } if ((Object)(object)_rearJoint != (Object)null) { Object.Destroy((Object)(object)_rearJoint); } _frontJoint = null; _rearJoint = null; _frontTarget = null; _rearTarget = null; _frontToShoulder = false; _rearToBack = false; } private void ApplyDrag() { if (_savedDrag < 0f) { _savedDrag = Rb.drag; _savedAngularDrag = Rb.angularDrag; } Rb.drag = Mathf.Max(_savedDrag, 0.4f); Rb.angularDrag = Mathf.Max(_savedAngularDrag, 1.5f); } private void RestoreDrag() { if (!(_savedDrag < 0f)) { try { Rb.drag = _savedDrag; Rb.angularDrag = _savedAngularDrag; } catch (Exception) { } _savedDrag = -1f; } } private void IgnoreBody(List<Collider> playerColliders) { if (playerColliders == null || playerColliders.Count == 0) { return; } if (_ignored.Count == 0) { foreach (Collider gunCollider in _gunColliders) { if ((Object)(object)gunCollider == (Object)null) { continue; } foreach (Collider playerCollider in playerColliders) { if (!((Object)(object)playerCollider == (Object)null)) { Physics.IgnoreCollision(gunCollider, playerCollider, true); _ignored.Add(new KeyValuePair<Collider, Collider>(gunCollider, playerCollider)); } } } } else { foreach (KeyValuePair<Collider, Collider> item in _ignored) { if ((Object)(object)item.Key != (Object)null && (Object)(object)item.Value != (Object)null) { Physics.IgnoreCollision(item.Key, item.Value, true); } } } _restorePending = false; } private void TryRestoreCollisions(Body body, float now) { //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_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) bool flag = !body.Valid || now > _restoreDeadline; if (!flag) { float num = 0.7f * body.Scale; Vector3 val = Rb.worldCenterOfMass - body.Chest; flag = ((Vector3)(ref val)).sqrMagnitude > num * num; } if (flag) { RestoreCollisions(); } } private void RestoreCollisions() { foreach (KeyValuePair<Collider, Collider> item in _ignored) { try { if ((Object)(object)item.Key != (Object)null && (Object)(object)item.Value != (Object)null) { Physics.IgnoreCollision(item.Key, item.Value, false); } } catch (Exception) { } } _ignored.Clear(); _restorePending = false; } public bool FindGrab(Vector3 palm, float radius, out int index, out float distSq) { //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_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_004c: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_006b: 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_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_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_0086: 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_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) index = -1; distSq = radius * radius; if (!_ropeReady || !_visible) { return false; } bool flag = _wornBlend > 0.5f; for (int i = 0; i < 23; i++) { Vector3 val = _p[i]; Vector3 val2 = _p[i + 1] - val; float sqrMagnitude = ((Vector3)(ref val2)).sqrMagnitude; float num = ((sqrMagnitude > 1E-08f) ? Mathf.Clamp01(Vector3.Dot(palm - val, val2) / sqrMagnitude) : 0f); Vector3 val3 = val + val2 * num - palm; float sqrMagnitude2 = ((Vector3)(ref val3)).sqrMagnitude; if (!(sqrMagnitude2 >= distSq)) { int num2 = ((num < 0.5f) ? i : (i + 1)); if (num2 < 1) { num2 = 1; } if (num2 > 22) { num2 = 22; } if (!flag || num2 <= 10 || num2 >= 17) { distSq = sqrMagnitude2; index = num2; } } } return index >= 0; } public static Vector3 Palm(Hand hand) { //IL_001d: 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) Transform palmPositionTransform = hand.palmPositionTransform; if (!((Object)(object)palmPositionTransform != (Object)null)) { return ((Component)hand).transform.position; } return palmPositionTransform.position; } public void Simulate(Body body, float dt, HashSet<int> playerColliders, bool world) { //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0040: 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_0052: 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_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_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_0076: 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_0087: 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_00a1: 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_00aa: 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_00bb: 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_00bd: 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_00df: Unknown result type (might be due to invalid IL or missing references) //IL_00e4: Unknown result type (might be due to invalid IL or missing references) //IL_00e9: Unknown result type (might be due to invalid IL or missing references) //IL_00ed: 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_00d1: 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_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_0160: Unknown result type (might be due to invalid IL or missing references) //IL_0162: 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_016c: 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_0187: 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_0191: Unknown result type (might be due to invalid IL or missing references) //IL_019d: 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_022e: Unknown result type (might be due to invalid IL or missing references) //IL_0236: Unknown result type (might be due to invalid IL or missing references) //IL_023b: 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_0254: Unknown result