using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using GiantPlayer;
using HarmonyLib;
using Il2Cpp;
using Il2CppHexabodyVR.PlayerController;
using Il2CppHurricaneVR.Framework.Core.Player;
using Il2CppHurricaneVR.Framework.Core.ScriptableObjects;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using MelonLoader;
using MelonLoader.Preferences;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Animations;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(Core), "GiantPlayer", "1.0.2", "geom2543", null)]
[assembly: MelonGame("Kubunautilus", "BrutalistickVR")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("GiantPlayer")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+12e4353dee9431330acbfc07082a54f2fb8e1956")]
[assembly: AssemblyProduct("GiantPlayer")]
[assembly: AssemblyTitle("GiantPlayer")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace GiantPlayer
{
internal static class Extras
{
private class Bar
{
public Transform T;
public Transform Src;
public Behaviour Pc;
public Vector3 Pos;
public Quaternion Rot;
}
internal static MelonPreferences_Entry<float> Strength;
internal static MelonPreferences_Entry<float> Health;
internal static MelonPreferences_Entry<float> Mass;
private static readonly Dictionary<IntPtr, Bar> Bars = new Dictionary<IntPtr, Bar>();
private static readonly Dictionary<string, (string src, Vector3 pos, Vector3 rot)> SceneOffsets = new Dictionary<string, (string, Vector3, Vector3)>
{
["HealthBar"] = ("LElbowPoint", new Vector3(0.0548749f, -1.6601223f, 0.44340134f), new Vector3(0f, -90f, 0f)),
["SlowmoBar"] = ("LElbowPoint", new Vector3(0.0548749f, -1.669122f, 0.46640015f), new Vector3(0f, -90f, -25.370993f)),
["MissionProgressCanvas"] = ("RElbowPoint", new Vector3(0.13179398f, 0.01147771f, 0.03440094f), new Vector3(63.000008f, 180f, 0f))
};
private static readonly Dictionary<IntPtr, (float force, float torque)> StrengthOrig = new Dictionary<IntPtr, (float, float)>();
private static readonly Dictionary<IntPtr, float> PunchOrig = new Dictionary<IntPtr, float>();
private static readonly Dictionary<IntPtr, float> MagComp = new Dictionary<IntPtr, float>();
private static readonly Dictionary<IntPtr, float> MassOrig = new Dictionary<IntPtr, float>();
private static readonly Dictionary<(IntPtr, int), JointDrive> DriveOrig = new Dictionary<(IntPtr, int), JointDrive>();
internal static bool Big => !Mathf.Approximately(Core.Current, 1f);
internal static void CreateEntries(MelonPreferences_Category cat)
{
Strength = cat.CreateEntry<float>("StrengthMultiplier", 10f, "Strength x", "Hand force/torque limit and punch force multiplier while big", false, false, (ValueValidator)null, (string)null);
Health = cat.CreateEntry<float>("HealthMultiplier", 10f, "Health x", "Damage taken is divided by this while big (= x health)", false, false, (ValueValidator)null, (string)null);
Mass = cat.CreateEntry<float>("MassMultiplier", 4f, "Weight x", "Body mass multiplier while big (leg/head springs are scaled with it so the body doesn't sag)", false, false, (ValueValidator)null, (string)null);
}
internal static void SceneReset()
{
Bars.Clear();
PunchOrig.Clear();
MagComp.Clear();
}
private static Transform FindChild(Transform root, string name)
{
foreach (Transform componentsInChild in ((Component)root).GetComponentsInChildren<Transform>(true))
{
if ((Object)(object)componentsInChild != (Object)null && ((Object)componentsInChild).name == name)
{
return componentsInChild;
}
}
return null;
}
internal static void BeforeScale(Transform rig, bool atX1)
{
//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
//IL_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)
foreach (KeyValuePair<string, (string, Vector3, Vector3)> sceneOffset in SceneOffsets)
{
Transform val = FindChild(rig, sceneOffset.Key);
Transform val2 = FindChild(rig, sceneOffset.Value.Item1);
if (!((Object)(object)val == (Object)null) && !((Object)(object)val2 == (Object)null) && !Bars.ContainsKey(((Il2CppObjectBase)val).Pointer))
{
ParentConstraint component = ((Component)val).GetComponent<ParentConstraint>();
if (!((Object)(object)component == (Object)null))
{
Bars[((Il2CppObjectBase)val).Pointer] = new Bar
{
T = val,
Src = val2,
Pc = (Behaviour)(object)component,
Pos = sceneOffset.Value.Item2,
Rot = Quaternion.Euler(sceneOffset.Value.Item3)
};
}
}
}
}
internal static void AfterScale(Instance log)
{
bool big = Big;
foreach (Bar value in Bars.Values)
{
if ((Object)(object)value.Pc != (Object)null)
{
value.Pc.enabled = !big;
}
}
if (Bars.Count > 0)
{
log.Msg($"Wrist bars: {Bars.Count} following the elbow at x{Core.Current}");
}
}
internal static void FollowBars()
{
//IL_005c: Unknown result type (might be due to invalid IL or missing references)
//IL_0067: Unknown result type (might be due to invalid IL or missing references)
//IL_006d: Unknown result type (might be due to invalid IL or missing references)
//IL_0073: Unknown result type (might be due to invalid IL or missing references)
//IL_0078: Unknown result type (might be due to invalid IL or missing references)
//IL_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_008e: Unknown result type (might be due to invalid IL or missing references)
//IL_0093: Unknown result type (might be due to invalid IL or missing references)
if (Bars.Count == 0 || !Big)
{
return;
}
float current = Core.Current;
foreach (Bar value in Bars.Values)
{
if (!((Object)(object)value.T == (Object)null) && !((Object)(object)value.Src == (Object)null))
{
value.T.SetPositionAndRotation(value.Src.position + value.Src.rotation * (value.Pos * current), value.Src.rotation * value.Rot);
}
}
}
private static void ApplyPd(PDStrength pd, float k)
{
if (!((Object)(object)pd == (Object)null))
{
if (!StrengthOrig.ContainsKey(((Il2CppObjectBase)pd).Pointer))
{
StrengthOrig[((Il2CppObjectBase)pd).Pointer] = (pd.MaxForce, pd.MaxTorque);
}
(float, float) tuple = StrengthOrig[((Il2CppObjectBase)pd).Pointer];
pd.MaxForce = tuple.Item1 * k;
pd.MaxTorque = tuple.Item2 * k;
}
}
internal static void ApplyStrength(Transform rig, Instance log)
{
float num = (Big ? Mathf.Max(0.01f, Strength.Value) : 1f);
int num2 = 0;
foreach (HVRHexaBodyHands componentsInChild in ((Component)rig).GetComponentsInChildren<HVRHexaBodyHands>(true))
{
if ((Object)(object)componentsInChild == (Object)null)
{
continue;
}
ApplyPd(componentsInChild.Strength, num);
ApplyPd(componentsInChild.OneHandedClimbStrength, num);
ApplyPd(componentsInChild.TwoHandedClimbStrength, num);
HVRHandStrengthHandler strengthHandler = componentsInChild.StrengthHandler;
if ((Object)(object)strengthHandler != (Object)null)
{
ApplyPd(strengthHandler.CurrentStrength, num);
if ((Object)(object)strengthHandler.CurrentStrength != (Object)null)
{
strengthHandler.UpdateStrength(strengthHandler.CurrentStrength);
}
}
num2++;
}
int num3 = 0;
foreach (PunchForceManager componentsInChild2 in ((Component)rig).GetComponentsInChildren<PunchForceManager>(true))
{
if (!((Object)(object)componentsInChild2 == (Object)null))
{
if (!PunchOrig.ContainsKey(((Il2CppObjectBase)componentsInChild2).Pointer))
{
PunchOrig[((Il2CppObjectBase)componentsInChild2).Pointer] = componentsInChild2.forceMultiplier;
}
componentsInChild2.forceMultiplier = PunchOrig[((Il2CppObjectBase)componentsInChild2).Pointer] * num;
num3++;
}
}
log.Msg($"Strength x{num} on {num2} hands, punch x{num} on {num3} punch components");
}
internal static void FixMag(GameObject mag, Transform rig)
{
//IL_0053: Unknown result type (might be due to invalid IL or missing references)
//IL_005b: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)mag == (Object)null || (Object)(object)rig == (Object)null)
{
return;
}
Transform transform = mag.transform;
if (transform.IsChildOf(rig))
{
float value;
float num = (MagComp.TryGetValue(((Il2CppObjectBase)mag).Pointer, out value) ? value : 1f);
float current = Core.Current;
if (!Mathf.Approximately(num, current))
{
transform.localScale *= num / current;
MagComp[((Il2CppObjectBase)mag).Pointer] = current;
}
}
}
internal static void FixPouchMags(Transform rig)
{
foreach (SpawnMagOnSocketGrab componentsInChild in ((Component)rig).GetComponentsInChildren<SpawnMagOnSocketGrab>(true))
{
if ((Object)(object)componentsInChild != (Object)null)
{
FixMag(componentsInChild.currentlySpawnedMag, rig);
}
}
foreach (WristPouchManager componentsInChild2 in ((Component)rig).GetComponentsInChildren<WristPouchManager>(true))
{
if ((Object)(object)componentsInChild2 != (Object)null)
{
FixMag(componentsInChild2.currentlySpawnedAmmo, rig);
}
}
}
internal static Transform RigOf(Component c)
{
HexaBodyPlayer4 body = Core.Body;
if ((Object)(object)body == (Object)null || (Object)(object)c == (Object)null)
{
return null;
}
Transform val = (((Object)(object)((Component)body).transform.parent != (Object)null) ? ((Component)body).transform.parent : ((Component)body).transform);
if (!c.transform.IsChildOf(val))
{
return null;
}
return val;
}
private static float SetMass(Rigidbody rb, float k)
{
if ((Object)(object)rb == (Object)null)
{
return 0f;
}
if (!MassOrig.ContainsKey(((Il2CppObjectBase)rb).Pointer))
{
MassOrig[((Il2CppObjectBase)rb).Pointer] = rb.mass;
}
rb.mass = MassOrig[((Il2CppObjectBase)rb).Pointer] * k;
return rb.mass;
}
private static JointDrive Scaled(IntPtr owner, int slot, JointDrive cur, float k)
{
//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_001c: 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)
(IntPtr, int) key = (owner, slot);
if (!DriveOrig.ContainsKey(key))
{
DriveOrig[key] = cur;
}
JointDrive result = DriveOrig[key];
((JointDrive)(ref result)).positionSpring = ((JointDrive)(ref result)).positionSpring * k;
((JointDrive)(ref result)).positionDamper = ((JointDrive)(ref result)).positionDamper * k;
if (!float.IsInfinity(((JointDrive)(ref result)).maximumForce) && ((JointDrive)(ref result)).maximumForce < 1E+30f)
{
((JointDrive)(ref result)).maximumForce = ((JointDrive)(ref result)).maximumForce * k;
}
return result;
}
private static void ScaleJoint(ConfigurableJoint j, float k)
{
//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_002c: 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_0045: Unknown result type (might be due to invalid IL or missing references)
//IL_004b: Unknown result type (might be due to invalid IL or missing references)
//IL_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_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_0090: 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)
if (!((Object)(object)j == (Object)null))
{
j.xDrive = Scaled(((Il2CppObjectBase)j).Pointer, 0, j.xDrive, k);
j.yDrive = Scaled(((Il2CppObjectBase)j).Pointer, 1, j.yDrive, k);
j.zDrive = Scaled(((Il2CppObjectBase)j).Pointer, 2, j.zDrive, k);
j.angularXDrive = Scaled(((Il2CppObjectBase)j).Pointer, 3, j.angularXDrive, k);
j.angularYZDrive = Scaled(((Il2CppObjectBase)j).Pointer, 4, j.angularYZDrive, k);
j.slerpDrive = Scaled(((Il2CppObjectBase)j).Pointer, 5, j.slerpDrive, k);
}
}
internal static void ApplyMass(HexaBodyPlayer4 b, Instance log)
{
//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)
if (!((Object)(object)b == (Object)null))
{
float num = (Big ? Mathf.Max(0.1f, Mass.Value) : 1f);
b._ballMass = SetMass(b.LocoBall, num);
b._kneeMass = SetMass(b.Knee, num);
b._headMass = SetMass(b.Head, num);
b._pelvisMass = SetMass(b.Pelvis, num);
ScaleJoint(b.JointLegTorso, num);
ScaleJoint(b.JointLegBall, num);
ScaleJoint(b.JointHead, num);
b._legYDrive = Scaled(((Il2CppObjectBase)b).Pointer, 99, b._legYDrive, num);
log.Msg($"Weight x{num}: body mass {b.CombinedMass:F0} kg");
}
}
internal static void Refund(PlayerHealthManager hm, float before)
{
if (Big && !((Object)(object)hm == (Object)null))
{
float num = Mathf.Max(1f, Health.Value);
float num2 = before - hm.health;
if (!(num2 <= 0f))
{
hm.health = before - num2 / num;
}
}
}
}
[HarmonyPatch(typeof(PlayerHealthManager), "HitByBullet")]
internal static class HpBulletPatch
{
private static void Prefix(PlayerHealthManager __instance, out float __state)
{
__state = __instance.health;
}
private static void Postfix(PlayerHealthManager __instance, float __state)
{
Extras.Refund(__instance, __state);
}
}
[HarmonyPatch(typeof(PlayerHealthManager), "BittenByZombie")]
internal static class HpBitePatch
{
private static void Prefix(PlayerHealthManager __instance, out float __state)
{
__state = __instance.health;
}
private static void Postfix(PlayerHealthManager __instance, float __state)
{
Extras.Refund(__instance, __state);
}
}
[HarmonyPatch(typeof(PlayerHealthManager), "HitByZombie")]
internal static class HpZombiePatch
{
private static void Prefix(PlayerHealthManager __instance, out float __state)
{
__state = __instance.health;
}
private static void Postfix(PlayerHealthManager __instance, float __state)
{
Extras.Refund(__instance, __state);
}
}
[HarmonyPatch(typeof(PlayerHealthManager), "HitDetected")]
internal static class HpMeleePatch
{
private static void Prefix(PlayerHealthManager __instance, out float __state)
{
__state = __instance.health;
}
private static void Postfix(PlayerHealthManager __instance, float __state)
{
Extras.Refund(__instance, __state);
}
}
[HarmonyPatch(typeof(PlayerJointsBugResolver), "ForceEnableJoints")]
internal static class RespawnPatch
{
private static void Postfix()
{
Core.Instance?.RepairAfterRespawn();
}
}
[HarmonyPatch(typeof(SpawnMagOnSocketGrab), "TrySpawningMag")]
internal static class PouchMagPatch
{
private static void Postfix(SpawnMagOnSocketGrab __instance)
{
try
{
Transform val = Extras.RigOf((Component)(object)__instance);
if ((Object)(object)val != (Object)null)
{
Extras.FixMag(__instance.currentlySpawnedMag, val);
}
}
catch
{
}
}
}
[HarmonyPatch(typeof(WristPouchManager), "TrySpawningMag")]
internal static class WristMagPatch
{
private static void Postfix(WristPouchManager __instance)
{
try
{
Transform val = Extras.RigOf((Component)(object)__instance);
if ((Object)(object)val != (Object)null)
{
Extras.FixMag(__instance.currentlySpawnedAmmo, val);
}
}
catch
{
}
}
}
public class Core : MelonMod
{
private struct BonePose
{
public Rigidbody rb;
public Transform t;
public Vector3 lp;
public Quaternion lr;
}
private static MelonPreferences_Category _cat;
private static MelonPreferences_Entry<bool> _enabled;
private static MelonPreferences_Entry<float> _scale;
private static MelonPreferences_Entry<bool> _scaleSpeed;
private static MelonPreferences_Entry<float> _applyDelay;
private static MelonPreferences_Entry<float> _torqueExp;
private static MelonPreferences_Entry<bool> _interpolate;
private static MelonPreferences_Entry<int> _iterMul;
internal static HexaBodyPlayer4 Body;
internal static float Current = 1f;
internal static Core Instance;
private float _diagTimer;
internal static readonly Dictionary<IntPtr, (Vector3 a, Vector3 ca)> OrigAnchors = new Dictionary<IntPtr, (Vector3, Vector3)>();
private static readonly Dictionary<IntPtr, (RigidbodyInterpolation interp, int it, int vit)> OrigRb = new Dictionary<IntPtr, (RigidbodyInterpolation, int, int)>();
private static readonly List<BonePose> RestPose = new List<BonePose>();
private static readonly List<ConfigurableJoint> LockedArmJoints = new List<ConfigurableJoint>();
private float _badTime;
private float _cooldown;
public override void OnInitializeMelon()
{
_cat = MelonPreferences.CreateCategory("GiantPlayer", "Giant Player");
_enabled = _cat.CreateEntry<bool>("Enabled", true, "Enabled", "Scale the player when a level loads", false, false, (ValueValidator)null, (string)null);
_scale = _cat.CreateEntry<float>("Scale", 2f, "Scale", "Player size multiplier (2 = twice as big)", false, false, (ValueValidator)null, (string)null);
_scaleSpeed = _cat.CreateEntry<bool>("ScaleWalkSpeed", true, "Scale walk speed", "Walk/run speed grows with size", false, false, (ValueValidator)null, (string)null);
_applyDelay = _cat.CreateEntry<float>("ApplyDelay", 1f, "Apply delay", "Seconds to wait after a level loads before scaling", false, false, (ValueValidator)null, (string)null);
_interpolate = _cat.CreateEntry<bool>("InterpolateBody", false, "Interpolate body", "Interpolate the visible body and hands between physics steps. Off = like the vanilla game. On makes the body lag behind the camera while running (looks like shaking)", false, false, (ValueValidator)null, (string)null);
_iterMul = _cat.CreateEntry<int>("BodySolverIterationsMultiplier", 2, "Body solver iterations x", "Physics solver iterations multiplier for the visible body while big (longer bones need more)", false, false, (ValueValidator)null, (string)null);
_torqueExp = _cat.CreateEntry<float>("RagdollTorqueExponent", 0f, "Ragdoll torque exponent", "Body joint torque is multiplied by Scale^this. 0 = unchanged, 1 = x Scale, 2 = x Scale^2 (stiffer, may shake)", false, false, (ValueValidator)null, (string)null);
Extras.CreateEntries(_cat);
_cat.SaveToFile(false);
Instance = this;
((MelonBase)this).LoggerInstance.Msg($"Loaded. Scale x{_scale.Value}. F7 = reset body, F8 = toggle size, F9 = re-apply.");
}
public override void OnSceneWasInitialized(int buildIndex, string sceneName)
{
Body = null;
Current = 1f;
OrigAnchors.Clear();
OrigRb.Clear();
Extras.SceneReset();
if (_enabled.Value)
{
MelonCoroutines.Start(ApplyWhenReady());
}
}
private IEnumerator ApplyWhenReady()
{
float wait = Mathf.Max(0f, _applyDelay.Value);
float t = 0f;
while (t < wait)
{
t += Time.unscaledDeltaTime;
yield return null;
}
for (int i = 0; i < 300; i++)
{
if (!((Object)(object)FindBody() == (Object)null))
{
break;
}
yield return null;
}
HexaBodyPlayer4 val = FindBody();
if (!((Object)(object)val == (Object)null))
{
SetScale(val, _scale.Value);
}
}
private void LogArmDiag()
{
//IL_0083: 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_00b6: Unknown result type (might be due to invalid IL or missing references)
_diagTimer += Time.unscaledDeltaTime;
if (_diagTimer < 3f)
{
return;
}
_diagTimer = 0f;
HexaBodyPlayer4 body = Body;
if ((Object)(object)body == (Object)null || !Object.op_Implicit((Object)(object)body))
{
return;
}
try
{
string value = "-";
if ((Object)(object)body.Camera != (Object)null && (Object)(object)body.LocoBall != (Object)null && (Object)(object)body.LocoCollider != (Object)null)
{
float num = body.LocoBall.position.y - body.LocoCollider.radius * ((Component)body.LocoCollider).transform.lossyScale.y;
float value2 = body.Camera.position.y - num;
value = $"cam={value2:F2} hexaCamH={body.CameraHeight:F2} eye={body.EyeHeight:F2}";
}
((MelonBase)this).LoggerInstance.Msg($"[diag x{Current}] {value} | L: {Side(body.LeftHand, body.LeftController)} | R: {Side(body.RightHand, body.RightController)}");
LogArmJointStretch(body);
}
catch (Exception ex)
{
((MelonBase)this).LoggerInstance.Warning("diag: " + ex.Message);
_diagTimer = -1000f;
}
static string Side(HexaHandsBase h, Transform ctrl)
{
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_0046: Unknown result type (might be due to invalid IL or missing references)
//IL_004d: 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_0079: 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_00a4: Unknown result type (might be due to invalid IL or missing references)
if (!((Object)(object)h == (Object)null) && !((Object)(object)ctrl == (Object)null))
{
Vector3 position = ((Component)h).transform.position;
float value3 = Vector3.Distance(position, ctrl.position);
float value4 = (((Object)(object)h.Shoulder != (Object)null) ? Vector3.Distance(position, h.Shoulder.position) : (-1f));
float value5 = (((Object)(object)h.Shoulder != (Object)null) ? Vector3.Distance(ctrl.position, h.Shoulder.position) : (-1f));
ConfigurableJoint joint = h.Joint;
object obj;
if (!((Object)(object)joint != (Object)null))
{
obj = "?";
}
else
{
Vector3 targetPosition = joint.targetPosition;
obj = ((Vector3)(ref targetPosition)).magnitude.ToString("F2");
}
string value6 = (string)obj;
return $"hand-ctrl={value3:F2} hand-shoulder={value4:F2} ctrl-shoulder={value5:F2} target={value6}";
}
return "-";
}
}
private void LogArmJointStretch(HexaBodyPlayer4 b)
{
//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_008f: Unknown result type (might be due to invalid IL or missing references)
//IL_0094: Unknown result type (might be due to invalid IL or missing references)
//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
//IL_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_00b5: Unknown result type (might be due to invalid IL or missing references)
//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
//IL_014e: 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)
Transform obj = (((Object)(object)((Component)b).transform.parent != (Object)null) ? ((Component)b).transform.parent : ((Component)b).transform);
StringBuilder stringBuilder = new StringBuilder();
foreach (ConfigurableJoint componentsInChild in ((Component)obj).GetComponentsInChildren<ConfigurableJoint>(false))
{
if ((Object)(object)componentsInChild == (Object)null)
{
continue;
}
string name = ((Object)((Component)componentsInChild).gameObject).name;
if (name.Contains("Shoulder") || name.Contains("Elbow") || name.Contains("Collarbone"))
{
Vector3 val = ((Joint)componentsInChild).anchor;
Vector3 val2 = ((Joint)componentsInChild).connectedAnchor;
if (OrigAnchors.TryGetValue(((Il2CppObjectBase)componentsInChild).Pointer, out (Vector3, Vector3) value))
{
(val, val2) = value;
}
Vector3 val3 = ((Component)componentsInChild).transform.TransformPoint(val);
Vector3 val4 = (((Object)(object)((Joint)componentsInChild).connectedBody != (Object)null) ? ((Component)((Joint)componentsInChild).connectedBody).transform.TransformPoint(val2) : val2);
string value2 = (((Object)(object)((Joint)componentsInChild).connectedBody != (Object)null) ? ((Object)((Joint)componentsInChild).connectedBody).name : "world");
StringBuilder stringBuilder2 = stringBuilder;
StringBuilder.AppendInterpolatedStringHandler handler = new StringBuilder.AppendInterpolatedStringHandler(4, 3, stringBuilder2);
handler.AppendFormatted(name);
handler.AppendLiteral("->");
handler.AppendFormatted(value2);
handler.AppendLiteral("=");
handler.AppendFormatted(Vector3.Distance(val3, val4), "F3");
handler.AppendLiteral(" ");
stringBuilder2.Append(ref handler);
}
}
if (stringBuilder.Length > 0)
{
((MelonBase)this).LoggerInstance.Msg($"[stretch x{Current}] " + stringBuilder);
}
}
public override void OnLateUpdate()
{
try
{
Extras.FollowBars();
}
catch
{
}
}
public override void OnUpdate()
{
LogArmDiag();
WatchBody();
Keyboard val = null;
try
{
val = Keyboard.current;
}
catch
{
}
if (val == null)
{
return;
}
if (((ButtonControl)val.f7Key).wasPressedThisFrame)
{
ResetBodyPose("F7");
}
else if (((ButtonControl)val.f8Key).wasPressedThisFrame)
{
HexaBodyPlayer4 val2 = FindBody();
if ((Object)(object)val2 != (Object)null)
{
SetScale(val2, Mathf.Approximately(Current, 1f) ? _scale.Value : 1f);
}
}
else if (((ButtonControl)val.f9Key).wasPressedThisFrame)
{
_cat.LoadFromFile(false);
HexaBodyPlayer4 val3 = FindBody();
if ((Object)(object)val3 != (Object)null)
{
SetScale(val3, _scale.Value);
}
}
}
private static HexaBodyPlayer4 FindBody()
{
if ((Object)(object)Body != (Object)null && !((Il2CppObjectBase)Body).WasCollected && Object.op_Implicit((Object)(object)Body))
{
return Body;
}
Body = Object.FindObjectOfType<HexaBodyPlayer4>();
return Body;
}
private void SetScale(HexaBodyPlayer4 body, float target)
{
//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
if (target <= 0.01f)
{
return;
}
float num = target / Current;
if (Mathf.Approximately(num, 1f))
{
return;
}
float current = Current;
try
{
Current = target;
Rescale(body, num);
((MelonBase)this).LoggerInstance.Msg($"Player scale set to x{target}");
}
catch (Exception ex)
{
((MelonBase)this).LoggerInstance.Error("Failed to scale player: " + ex);
Transform val = (((Object)(object)body != (Object)null && (Object)(object)((Component)body).transform.parent != (Object)null) ? ((Component)body).transform.parent : ((body != null) ? ((Component)body).transform : null));
if ((Object)(object)val == (Object)null || Mathf.Approximately(val.localScale.y, current))
{
Current = current;
}
}
}
private void Rescale(HexaBodyPlayer4 body, float r)
{
//IL_0066: Unknown result type (might be due to invalid IL or missing references)
//IL_006b: Unknown result type (might be due to invalid IL or missing references)
//IL_00c1: 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_00c9: 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_00d4: 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_00e6: Unknown result type (might be due to invalid IL or missing references)
//IL_0080: Unknown result type (might be due to invalid IL or missing references)
//IL_0085: 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_041c: 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_0202: Unknown result type (might be due to invalid IL or missing references)
//IL_0207: Unknown result type (might be due to invalid IL or missing references)
//IL_020b: Unknown result type (might be due to invalid IL or missing references)
//IL_0210: 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_0275: Unknown result type (might be due to invalid IL or missing references)
//IL_0278: Unknown result type (might be due to invalid IL or missing references)
//IL_025d: Unknown result type (might be due to invalid IL or missing references)
//IL_025f: Unknown result type (might be due to invalid IL or missing references)
//IL_0235: Unknown result type (might be due to invalid IL or missing references)
//IL_0293: Unknown result type (might be due to invalid IL or missing references)
//IL_0296: Unknown result type (might be due to invalid IL or missing references)
Transform val = (((Object)(object)((Component)body).transform.parent != (Object)null) ? ((Component)body).transform.parent : ((Component)body).transform);
try
{
Extras.BeforeScale(val, Mathf.Approximately(Current / r, 1f));
}
catch (Exception ex)
{
((MelonBase)this).LoggerInstance.Warning("Wrist bars (before): " + ex.Message);
}
Vector3 position = ((Component)body).transform.position;
if ((Object)(object)body.LocoBall != (Object)null)
{
position = body.LocoBall.position;
if ((Object)(object)body.LocoCollider != (Object)null)
{
position.y -= body.LocoCollider.radius * ((Component)body.LocoCollider).transform.lossyScale.y;
}
}
val.position = position + (val.position - position) * r;
val.localScale *= r;
body.EyeHeight *= r;
body.PlayerWaistHeight *= r;
body.BumperOffset *= r;
body.TipToesOffset *= r;
body.CameraCeilingOffset *= r;
body.PelvisMaxOffset *= r;
body.DefaultArmLength *= r;
body.GroundedRayLength *= r;
body.AirCrouchMaxHeight *= r;
body.FloorOffsetAdjustment *= r;
body.MinCameraHeight *= r;
body.CameraMoveThreshold *= r;
if (_scaleSpeed.Value)
{
body.WalkSpeed *= r;
body.RunSpeed *= r;
}
BakeHexaColliders(val, body, r);
Physics.SyncTransforms();
HashSet<IntPtr> hashSet = HexaOwnedJoints(body);
int num = 0;
foreach (Joint componentsInChild in ((Component)val).GetComponentsInChildren<Joint>(true))
{
if ((Object)(object)componentsInChild == (Object)null)
{
continue;
}
Vector3 anchor = componentsInChild.anchor;
Vector3 connectedAnchor = componentsInChild.connectedAnchor;
if (hashSet.Contains(((Il2CppObjectBase)componentsInChild).Pointer))
{
componentsInChild.anchor = anchor;
if (!componentsInChild.autoConfigureConnectedAnchor)
{
componentsInChild.connectedAnchor = connectedAnchor;
}
continue;
}
if (!OrigAnchors.ContainsKey(((Il2CppObjectBase)componentsInChild).Pointer))
{
OrigAnchors[((Il2CppObjectBase)componentsInChild).Pointer] = (anchor, connectedAnchor);
}
componentsInChild.autoConfigureConnectedAnchor = false;
componentsInChild.anchor = anchor * r;
if ((Object)(object)componentsInChild.connectedBody != (Object)null)
{
componentsInChild.connectedAnchor = connectedAnchor * r;
}
num++;
}
((MelonBase)this).LoggerInstance.Msg($"Scaled anchors of {num} ragdoll joints");
ScaleArms(val, body, r);
ScaleBodyIK(val, r);
ScaleRagdollJoints(val, body, r);
SmoothBody(val);
CaptureBodyPose(val);
try
{
Extras.FixPouchMags(val);
}
catch (Exception ex2)
{
((MelonBase)this).LoggerInstance.Warning("Pouch mags: " + ex2.Message);
}
try
{
Extras.ApplyMass(body, ((MelonBase)this).LoggerInstance);
}
catch (Exception ex3)
{
((MelonBase)this).LoggerInstance.Warning("Weight: " + ex3.Message);
}
try
{
Extras.ApplyStrength(val, ((MelonBase)this).LoggerInstance);
}
catch (Exception ex4)
{
((MelonBase)this).LoggerInstance.Warning("Strength: " + ex4.Message);
}
try
{
Extras.AfterScale(((MelonBase)this).LoggerInstance);
}
catch (Exception ex5)
{
((MelonBase)this).LoggerInstance.Warning("Wrist bars: " + ex5.Message);
}
body.CalibrateHeight(body.CalibratedHeight);
body.SetArmLength(body.DefaultArmLength);
foreach (Rigidbody componentsInChild2 in ((Component)val).GetComponentsInChildren<Rigidbody>(true))
{
if (!((Object)(object)componentsInChild2 == (Object)null) && !componentsInChild2.isKinematic)
{
componentsInChild2.linearVelocity = Vector3.zero;
componentsInChild2.angularVelocity = Vector3.zero;
}
}
}
private void BakeHexaColliders(Transform rig, HexaBodyPlayer4 body, float r)
{
//IL_009e: Unknown result type (might be due to invalid IL or missing references)
//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
//IL_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_00cf: 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_0131: 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_0177: 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_019f: Unknown result type (might be due to invalid IL or missing references)
//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
//IL_01b8: 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_0229: Unknown result type (might be due to invalid IL or missing references)
//IL_0273: Unknown result type (might be due to invalid IL or missing references)
//IL_0279: Unknown result type (might be due to invalid IL or missing references)
Collider[] obj = new Collider[6]
{
(Collider)body.LocoCollider,
(Collider)body.FenderCollider,
(Collider)body.KneeCollider,
(Collider)body.ChestCollider,
(Collider)body.NeckCollider,
(Collider)body.PelvisCollider
};
HashSet<IntPtr> hashSet = new HashSet<IntPtr>();
Il2CppArrayBase<Joint> componentsInChildren = ((Component)rig).GetComponentsInChildren<Joint>(true);
string text = "";
Collider[] array = (Collider[])(object)obj;
foreach (Collider val in array)
{
if ((Object)(object)val == (Object)null)
{
continue;
}
Transform transform = ((Component)val).transform;
if (!hashSet.Add(((Il2CppObjectBase)transform).Pointer))
{
continue;
}
text = text + ((Object)transform).name + " ";
transform.localScale /= r;
for (int j = 0; j < transform.childCount; j++)
{
Transform child = transform.GetChild(j);
child.localPosition *= r;
child.localScale *= r;
}
foreach (Collider component2 in ((Component)transform).GetComponents<Collider>())
{
SphereCollider val2 = ((Il2CppObjectBase)component2).TryCast<SphereCollider>();
if ((Object)(object)val2 != (Object)null)
{
val2.radius *= r;
val2.center *= r;
continue;
}
CapsuleCollider val3 = ((Il2CppObjectBase)component2).TryCast<CapsuleCollider>();
if ((Object)(object)val3 != (Object)null)
{
val3.radius *= r;
val3.height *= r;
val3.center *= r;
continue;
}
BoxCollider val4 = ((Il2CppObjectBase)component2).TryCast<BoxCollider>();
if ((Object)(object)val4 != (Object)null)
{
val4.size *= r;
val4.center *= r;
}
}
Rigidbody component = ((Component)transform).GetComponent<Rigidbody>();
foreach (Joint item in componentsInChildren)
{
if (!((Object)(object)item == (Object)null))
{
if (((Il2CppObjectBase)((Component)item).transform).Pointer == ((Il2CppObjectBase)transform).Pointer)
{
item.anchor *= r;
}
if ((Object)(object)component != (Object)null && (Object)(object)item.connectedBody != (Object)null && ((Il2CppObjectBase)item.connectedBody).Pointer == ((Il2CppObjectBase)component).Pointer && !item.autoConfigureConnectedAnchor)
{
item.connectedAnchor *= r;
}
}
}
}
body._originalLocoRadius *= r;
body._originalBumperRadius *= r;
((MelonBase)this).LoggerInstance.Msg("Baked scale into colliders: " + text);
}
private void ScaleArms(Transform rig, HexaBodyPlayer4 body, float r)
{
int num = 0;
foreach (HVRJointHand componentsInChild in ((Component)rig).GetComponentsInChildren<HVRJointHand>(true))
{
if (!((Object)(object)componentsInChild == (Object)null))
{
componentsInChild.ArmLength *= r;
componentsInChild.MaxTargetDistance *= r;
num++;
}
}
List<HexaHandsBase> list = new List<HexaHandsBase>();
foreach (HexaHandsBase componentsInChild2 in ((Component)rig).GetComponentsInChildren<HexaHandsBase>(true))
{
if ((Object)(object)componentsInChild2 != (Object)null)
{
list.Add(componentsInChild2);
}
}
if ((Object)(object)body.LeftHand != (Object)null && !list.Exists((HexaHandsBase x) => ((Il2CppObjectBase)x).Pointer == ((Il2CppObjectBase)body.LeftHand).Pointer))
{
list.Add(body.LeftHand);
}
if ((Object)(object)body.RightHand != (Object)null && !list.Exists((HexaHandsBase x) => ((Il2CppObjectBase)x).Pointer == ((Il2CppObjectBase)body.RightHand).Pointer))
{
list.Add(body.RightHand);
}
foreach (HexaHandsBase item in list)
{
item.DistanceThreshold *= r;
item.DownDistanceThreshold *= r;
item.StuckForce *= r;
item.DownMaxAllowedForce *= r;
num++;
}
((MelonBase)this).LoggerInstance.Msg($"Scaled {num} hand components");
}
private void SmoothBody(Transform rig)
{
//IL_006e: Unknown result type (might be due to invalid IL or missing references)
//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
//IL_01b1: 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)
bool flag = !Mathf.Approximately(Current, 1f);
int num = 0;
foreach (Rigidbody componentsInChild in ((Component)rig).GetComponentsInChildren<Rigidbody>(true))
{
if ((Object)(object)componentsInChild == (Object)null || !UnderVisibleBody(((Component)componentsInChild).transform))
{
continue;
}
if (!OrigRb.ContainsKey(((Il2CppObjectBase)componentsInChild).Pointer))
{
OrigRb[((Il2CppObjectBase)componentsInChild).Pointer] = (componentsInChild.interpolation, componentsInChild.solverIterations, componentsInChild.solverVelocityIterations);
}
(RigidbodyInterpolation, int, int) tuple = OrigRb[((Il2CppObjectBase)componentsInChild).Pointer];
if (flag)
{
if (_interpolate.Value)
{
componentsInChild.interpolation = (RigidbodyInterpolation)1;
}
int num2 = Math.Max(1, _iterMul.Value);
componentsInChild.solverIterations = tuple.Item2 * num2;
componentsInChild.solverVelocityIterations = tuple.Item3 * num2;
}
else
{
componentsInChild.interpolation = tuple.Item1;
componentsInChild.solverIterations = tuple.Item2;
componentsInChild.solverVelocityIterations = tuple.Item3;
}
num++;
}
HexaBodyPlayer4 body = Body;
if ((Object)(object)body != (Object)null)
{
HexaHandsBase[] array = (HexaHandsBase[])(object)new HexaHandsBase[2] { body.LeftHand, body.RightHand };
foreach (HexaHandsBase val in array)
{
if (!((Object)(object)val == (Object)null) && !((Object)(object)val.RigidBody == (Object)null))
{
Rigidbody rigidBody = val.RigidBody;
if (!OrigRb.ContainsKey(((Il2CppObjectBase)rigidBody).Pointer))
{
OrigRb[((Il2CppObjectBase)rigidBody).Pointer] = (rigidBody.interpolation, rigidBody.solverIterations, rigidBody.solverVelocityIterations);
}
rigidBody.interpolation = (RigidbodyInterpolation)((flag && _interpolate.Value) ? 1 : ((int)OrigRb[((Il2CppObjectBase)rigidBody).Pointer].interp));
}
}
}
((MelonBase)this).LoggerInstance.Msg($"Smoothed {num} body bones + hands (interpolate={_interpolate.Value && flag}, iterations x{((!flag) ? 1 : _iterMul.Value)})");
LogPhysicsSummary(rig);
}
private void CaptureBodyPose(Transform rig)
{
//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_008e: Unknown result type (might be due to invalid IL or missing references)
//IL_0093: Unknown result type (might be due to invalid IL or missing references)
//IL_011b: Unknown result type (might be due to invalid IL or missing references)
RestPose.Clear();
LockedArmJoints.Clear();
if (Mathf.Approximately(Current, 1f))
{
return;
}
foreach (Rigidbody componentsInChild in ((Component)rig).GetComponentsInChildren<Rigidbody>(true))
{
if (!((Object)(object)componentsInChild == (Object)null) && UnderVisibleBody(((Component)componentsInChild).transform))
{
RestPose.Add(new BonePose
{
rb = componentsInChild,
t = ((Component)componentsInChild).transform,
lp = ((Component)componentsInChild).transform.localPosition,
lr = ((Component)componentsInChild).transform.localRotation
});
}
}
foreach (ConfigurableJoint componentsInChild2 in ((Component)rig).GetComponentsInChildren<ConfigurableJoint>(true))
{
if (!((Object)(object)componentsInChild2 == (Object)null) && UnderVisibleBody(((Component)componentsInChild2).transform))
{
string name = ((Object)((Component)componentsInChild2).gameObject).name;
if ((name.Contains("Shoulder") || name.Contains("Elbow") || name.Contains("Collarbone")) && (int)componentsInChild2.xMotion == 0)
{
LockedArmJoints.Add(componentsInChild2);
}
}
}
}
private float MaxLockedStretch()
{
//IL_0038: 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_003f: Unknown result type (might be due to invalid IL or missing references)
//IL_0044: Unknown result type (might be due to invalid IL or missing references)
//IL_0071: 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_005c: Unknown result type (might be due to invalid IL or missing references)
//IL_0061: Unknown result type (might be due to invalid IL or missing references)
//IL_0064: Unknown result type (might be due to invalid IL or missing references)
//IL_0069: Unknown result type (might be due to invalid IL or missing references)
//IL_0096: Unknown result type (might be due to invalid IL or missing references)
//IL_0098: 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_009d: Unknown result type (might be due to invalid IL or missing references)
//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
float num = 0f;
foreach (ConfigurableJoint lockedArmJoint in LockedArmJoints)
{
if (!((Object)(object)lockedArmJoint == (Object)null) && ((Component)lockedArmJoint).gameObject.activeInHierarchy)
{
Vector3 val = ((Joint)lockedArmJoint).anchor;
Vector3 val2 = ((Joint)lockedArmJoint).connectedAnchor;
if (OrigAnchors.TryGetValue(((Il2CppObjectBase)lockedArmJoint).Pointer, out (Vector3, Vector3) value))
{
(val, val2) = value;
}
Vector3 val3 = ((Component)lockedArmJoint).transform.TransformPoint(val);
Vector3 val4 = (((Object)(object)((Joint)lockedArmJoint).connectedBody != (Object)null) ? ((Component)((Joint)lockedArmJoint).connectedBody).transform.TransformPoint(val2) : val2);
num = Mathf.Max(num, Vector3.Distance(val3, val4));
}
}
return num;
}
private void WatchBody()
{
//IL_0070: Unknown result type (might be due to invalid IL or missing references)
//IL_0075: Unknown result type (might be due to invalid IL or missing references)
if (Mathf.Approximately(Current, 1f) || LockedArmJoints.Count == 0)
{
return;
}
float unscaledDeltaTime = Time.unscaledDeltaTime;
if (_cooldown > 0f)
{
_cooldown -= unscaledDeltaTime;
return;
}
float num = 0.04f * Current;
HexaBodyPlayer4 body = Body;
if ((Object)(object)body == (Object)null || (Object)(object)body.Pelvis == (Object)null)
{
return;
}
Vector3 linearVelocity = body.Pelvis.linearVelocity;
linearVelocity.y = 0f;
if (((Vector3)(ref linearVelocity)).magnitude > 0.6f * Current)
{
_badTime = 0f;
return;
}
float num2;
try
{
num2 = MaxLockedStretch();
}
catch
{
return;
}
_badTime = ((num2 > num) ? (_badTime + unscaledDeltaTime) : 0f);
if (_badTime > 1.5f)
{
ResetBodyPose($"arm joints pulled apart by {num2:F2} m");
}
}
internal void RepairAfterRespawn()
{
//IL_0086: 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_00ab: Unknown result type (might be due to invalid IL or missing references)
//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
if (Mathf.Approximately(Current, 1f))
{
return;
}
HexaBodyPlayer4 body = Body;
if ((Object)(object)body == (Object)null)
{
return;
}
Transform obj = (((Object)(object)((Component)body).transform.parent != (Object)null) ? ((Component)body).transform.parent : ((Component)body).transform);
int num = 0;
foreach (Joint componentsInChild in ((Component)obj).GetComponentsInChildren<Joint>(true))
{
if (!((Object)(object)componentsInChild == (Object)null) && OrigAnchors.TryGetValue(((Il2CppObjectBase)componentsInChild).Pointer, out (Vector3, Vector3) value))
{
componentsInChild.autoConfigureConnectedAnchor = false;
componentsInChild.anchor = value.Item1 * Current;
if ((Object)(object)componentsInChild.connectedBody != (Object)null)
{
componentsInChild.connectedAnchor = value.Item2 * Current;
}
num++;
}
}
_cooldown = 2f;
((MelonBase)this).LoggerInstance.Msg($"Respawn: re-applied scaled anchors on {num} joints");
}
private void ResetBodyPose(string why)
{
//IL_005b: 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_0089: 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)
_badTime = 0f;
_cooldown = 1f;
if (RestPose.Count == 0)
{
return;
}
foreach (BonePose item in RestPose)
{
if (!((Object)(object)item.t == (Object)null) && !((Object)(object)item.rb == (Object)null))
{
item.t.localPosition = item.lp;
item.t.localRotation = item.lr;
if (!item.rb.isKinematic)
{
item.rb.linearVelocity = Vector3.zero;
item.rb.angularVelocity = Vector3.zero;
}
}
}
Physics.SyncTransforms();
((MelonBase)this).LoggerInstance.Msg("Body reset (" + why + ")");
}
private void LogPhysicsSummary(Transform rig)
{
try
{
StringBuilder sb = new StringBuilder();
StringBuilder stringBuilder = sb;
StringBuilder.AppendInterpolatedStringHandler handler = new StringBuilder.AppendInterpolatedStringHandler(9, 1, stringBuilder);
handler.AppendLiteral("fixedDt=");
handler.AppendFormatted(Time.fixedDeltaTime, "F4");
handler.AppendLiteral(" ");
stringBuilder.Append(ref handler);
HexaBodyPlayer4 body = Body;
if ((Object)(object)body != (Object)null)
{
Rb("pelvis", body.Pelvis);
Rb("head", body.Head);
Rb("knee", body.Knee);
Rb("loco", body.LocoBall);
if ((Object)(object)body.LeftHand != (Object)null)
{
Rb("handL", body.LeftHand.RigidBody);
}
if ((Object)(object)body.RightHand != (Object)null)
{
Rb("handR", body.RightHand.RigidBody);
}
}
foreach (Rigidbody componentsInChild in ((Component)rig).GetComponentsInChildren<Rigidbody>(true))
{
if (!((Object)(object)componentsInChild == (Object)null))
{
string name = ((Object)componentsInChild).name;
switch (name)
{
case "PlayerUpperChest":
case "CollarboneR":
case "RShoulderPoint":
case "RElbowPoint":
case "Chest":
case "PlayerPelvis":
Rb(name, componentsInChild);
break;
}
}
}
((MelonBase)this).LoggerInstance.Msg("[physics] " + sb);
void Rb(string label, Rigidbody rb)
{
//IL_0062: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)rb == (Object)null)
{
StringBuilder stringBuilder2 = sb;
StringBuilder stringBuilder3 = stringBuilder2;
StringBuilder.AppendInterpolatedStringHandler handler2 = new StringBuilder.AppendInterpolatedStringHandler(6, 1, stringBuilder2);
handler2.AppendFormatted(label);
handler2.AppendLiteral("=null ");
stringBuilder3.Append(ref handler2);
}
else
{
StringBuilder stringBuilder2 = sb;
StringBuilder stringBuilder4 = stringBuilder2;
StringBuilder.AppendInterpolatedStringHandler handler2 = new StringBuilder.AppendInterpolatedStringHandler(15, 5, stringBuilder2);
handler2.AppendFormatted(label);
handler2.AppendLiteral("[");
handler2.AppendFormatted<RigidbodyInterpolation>(rb.interpolation);
handler2.AppendLiteral(",kin=");
handler2.AppendFormatted(rb.isKinematic);
handler2.AppendLiteral(",m=");
handler2.AppendFormatted(rb.mass, "F1");
handler2.AppendLiteral(",it=");
handler2.AppendFormatted(rb.solverIterations);
handler2.AppendLiteral("] ");
stringBuilder4.Append(ref handler2);
}
}
}
catch (Exception ex)
{
((MelonBase)this).LoggerInstance.Warning("physics summary: " + ex.Message);
}
}
private static bool UnderVisibleBody(Transform t)
{
Transform val = t;
while ((Object)(object)val != (Object)null)
{
if (((Object)val).name == "PhysicalUpperbody")
{
return true;
}
val = val.parent;
}
return false;
}
private static HashSet<IntPtr> HexaOwnedJoints(HexaBodyPlayer4 body)
{
HashSet<IntPtr> set = new HashSet<IntPtr>();
Add((Joint)(object)body.JointLegTorso);
Add((Joint)(object)body.JointLegBall);
Add((Joint)(object)body.JointHead);
Add((Joint)(object)body._leftArmJoint);
Add((Joint)(object)body._rightArmJoint);
if ((Object)(object)body.LeftHand != (Object)null)
{
Add((Joint)(object)body.LeftHand.Joint);
}
if ((Object)(object)body.RightHand != (Object)null)
{
Add((Joint)(object)body.RightHand.Joint);
}
return set;
void Add(Joint j)
{
if ((Object)(object)j != (Object)null)
{
set.Add(((Il2CppObjectBase)j).Pointer);
}
}
}
private void ScaleRagdollJoints(Transform rig, HexaBodyPlayer4 body, float r)
{
//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_007c: Unknown result type (might be due to invalid IL or missing references)
//IL_0096: Unknown result type (might be due to invalid IL or missing references)
//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
//IL_00af: Unknown result type (might be due to invalid IL or missing references)
//IL_00ba: 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_00d3: Unknown result type (might be due to invalid IL or missing references)
//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
//IL_00fd: 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_0112: Unknown result type (might be due to invalid IL or missing references)
HashSet<IntPtr> hashSet = HexaOwnedJoints(body);
float num = Mathf.Pow(r, _torqueExp.Value);
int num2 = 0;
foreach (ConfigurableJoint componentsInChild in ((Component)rig).GetComponentsInChildren<ConfigurableJoint>(true))
{
if (!((Object)(object)componentsInChild == (Object)null) && !hashSet.Contains(((Il2CppObjectBase)componentsInChild).Pointer))
{
SoftJointLimit linearLimit = componentsInChild.linearLimit;
((SoftJointLimit)(ref linearLimit)).limit = ((SoftJointLimit)(ref linearLimit)).limit * r;
((SoftJointLimit)(ref linearLimit)).contactDistance = ((SoftJointLimit)(ref linearLimit)).contactDistance * r;
componentsInChild.linearLimit = linearLimit;
componentsInChild.projectionDistance *= r;
componentsInChild.xDrive = ScaleDrive(componentsInChild.xDrive, 1f, r);
componentsInChild.yDrive = ScaleDrive(componentsInChild.yDrive, 1f, r);
componentsInChild.zDrive = ScaleDrive(componentsInChild.zDrive, 1f, r);
componentsInChild.angularXDrive = ScaleDrive(componentsInChild.angularXDrive, num, num);
componentsInChild.angularYZDrive = ScaleDrive(componentsInChild.angularYZDrive, num, num);
componentsInChild.slerpDrive = ScaleDrive(componentsInChild.slerpDrive, num, num);
if (!float.IsInfinity(((Joint)componentsInChild).breakForce))
{
((Joint)componentsInChild).breakForce = ((Joint)componentsInChild).breakForce * r;
}
if (!float.IsInfinity(((Joint)componentsInChild).breakTorque))
{
((Joint)componentsInChild).breakTorque = ((Joint)componentsInChild).breakTorque * num;
}
num2++;
}
}
((MelonBase)this).LoggerInstance.Msg($"Scaled {num2} ragdoll joints");
}
private static JointDrive ScaleDrive(JointDrive d, float springDamperScale, float maxScale)
{
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
((JointDrive)(ref d)).positionSpring = ((JointDrive)(ref d)).positionSpring * springDamperScale;
((JointDrive)(ref d)).positionDamper = ((JointDrive)(ref d)).positionDamper * springDamperScale;
if (!float.IsInfinity(((JointDrive)(ref d)).maximumForce) && ((JointDrive)(ref d)).maximumForce < 1E+30f)
{
((JointDrive)(ref d)).maximumForce = ((JointDrive)(ref d)).maximumForce * maxScale;
}
return d;
}
private void ScaleBodyIK(Transform rig, float r)
{
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_0027: Unknown result type (might be due to invalid IL or missing references)
foreach (PlayerBodyIK componentsInChild in ((Component)rig).GetComponentsInChildren<PlayerBodyIK>(true))
{
if (!((Object)(object)componentsInChild == (Object)null))
{
componentsInChild.pelvisOffsetFromCamera *= r;
componentsInChild.cameraToUpperChestDistance *= r;
componentsInChild.cameraToPelvisDistance *= r;
ScaleCurve(componentsInChild.pelvisHeightFromBumperCurve, r, r);
ScaleCurve(componentsInChild.middleChestHeightFromPelvisCurve, r, 1f);
}
}
}
private static void ScaleCurve(AnimationCurve curve, float timeScale, float valueScale)
{
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_005d: Unknown result type (might be due to invalid IL or missing references)
if (curve == null)
{
return;
}
Il2CppStructArray<Keyframe> keys = curve.keys;
if (keys != null)
{
float num = valueScale / timeScale;
for (int i = 0; i < ((Il2CppArrayBase<Keyframe>)(object)keys).Length; i++)
{
Keyframe val = ((Il2CppArrayBase<Keyframe>)(object)keys)[i];
((Keyframe)(ref val)).time = ((Keyframe)(ref val)).time * timeScale;
((Keyframe)(ref val)).value = ((Keyframe)(ref val)).value * valueScale;
((Keyframe)(ref val)).inTangent = ((Keyframe)(ref val)).inTangent * num;
((Keyframe)(ref val)).outTangent = ((Keyframe)(ref val)).outTangent * num;
((Il2CppArrayBase<Keyframe>)(object)keys)[i] = val;
}
curve.keys = keys;
}
}
}
internal static class FloorOffsetFix
{
internal static void Apply(HexaCameraRig cam)
{
//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_0082: Unknown result type (might be due to invalid IL or missing references)
float current = Core.Current;
if ((Object)(object)cam == (Object)null || Mathf.Approximately(current, 1f))
{
return;
}
HexaBodyPlayer4 body = Core.Body;
if (!((Object)(object)body == (Object)null) && !((Object)(object)body.CameraRig == (Object)null) && !(((Il2CppObjectBase)body.CameraRig).Pointer != ((Il2CppObjectBase)cam).Pointer))
{
Transform floorOffsetTransform = cam.FloorOffsetTransform;
if (!((Object)(object)floorOffsetTransform == (Object)null))
{
Vector3 localPosition = floorOffsetTransform.localPosition;
localPosition.y = cam._floorOffset / current + cam.CameraYOffset;
floorOffsetTransform.localPosition = localPosition;
}
}
}
}
[HarmonyPatch(typeof(HexaBodyPlayer4), "ApplyCameraOffsets")]
internal static class ApplyCameraOffsetsPatch
{
private static void Postfix(HexaBodyPlayer4 __instance)
{
FloorOffsetFix.Apply(__instance.CameraRig);
}
}
[HarmonyPatch(typeof(HexaCameraRig), "UpdateFloorOffset")]
internal static class UpdateFloorOffsetPatch
{
private static void Postfix(HexaCameraRig __instance)
{
FloorOffsetFix.Apply(__instance);
}
}
[HarmonyPatch(typeof(HexaCameraRig), "Setup")]
internal static class CameraRigSetupPatch
{
private static void Postfix(HexaCameraRig __instance)
{
FloorOffsetFix.Apply(__instance);
}
}
[HarmonyPatch(/*Could not decode attribute arguments.*/)]
internal static class FloorOffsetSetterPatch
{
private static void Postfix(HexaCameraRig __instance)
{
FloorOffsetFix.Apply(__instance);
}
}
[HarmonyPatch(typeof(HexaBodyPlayer4), "HandleHMDMovement")]
internal static class HmdMovementPatch
{
private static void Prefix(HexaBodyPlayer4 __instance, out Vector3 __state)
{
//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_0022: Unknown result type (might be due to invalid IL or missing references)
//IL_0027: Unknown result type (might be due to invalid IL or missing references)
__state = Vector3.zero;
HexaCameraRig cameraRig = __instance.CameraRig;
if ((Object)(object)cameraRig != (Object)null)
{
__state = ((Component)cameraRig).transform.localPosition;
}
}
private static void Postfix(HexaBodyPlayer4 __instance, Vector3 __state)
{
//IL_0052: Unknown result type (might be due to invalid IL or missing references)
//IL_0057: Unknown result type (might be due to invalid IL or missing references)
//IL_0058: Unknown result type (might be due to invalid IL or missing references)
//IL_005d: Unknown result type (might be due to invalid IL or missing references)
//IL_006e: Unknown result type (might be due to invalid IL or missing references)
//IL_006f: Unknown result type (might be due to invalid IL or missing references)
//IL_0071: 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)
float current = Core.Current;
if (Mathf.Approximately(current, 1f) || (Object)(object)Core.Body == (Object)null || ((Il2CppObjectBase)__instance).Pointer != ((Il2CppObjectBase)Core.Body).Pointer)
{
return;
}
HexaCameraRig cameraRig = __instance.CameraRig;
if (!((Object)(object)cameraRig == (Object)null))
{
Transform transform = ((Component)cameraRig).transform;
Vector3 val = transform.localPosition - __state;
if (!(((Vector3)(ref val)).sqrMagnitude < 1E-12f))
{
transform.localPosition = __state + val / current;
}
}
}
}
[HarmonyPatch(typeof(HexaHandsBase), "UpdateJointAnchors")]
internal static class HandTargetPatch
{
private static readonly Dictionary<(IntPtr, int), float> Written = new Dictionary<(IntPtr, int), float>();
private static void Postfix(HexaHandsBase __instance)
{
//IL_0027: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
//IL_003b: Unknown result type (might be due to invalid IL or missing references)
//IL_0041: Unknown result type (might be due to invalid IL or missing references)
//IL_004f: 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_0063: 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)
float current = Core.Current;
if (!Mathf.Approximately(current, 1f))
{
ConfigurableJoint joint = __instance.Joint;
if (!((Object)(object)joint == (Object)null))
{
joint.targetPosition *= current;
joint.xDrive = ScaleCap(joint, 0, joint.xDrive, current);
joint.yDrive = ScaleCap(joint, 1, joint.yDrive, current);
joint.zDrive = ScaleCap(joint, 2, joint.zDrive, current);
}
}
}
private static JointDrive ScaleCap(ConfigurableJoint j, int axis, JointDrive d, float s)
{
//IL_0018: 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_0040: Unknown result type (might be due to invalid IL or missing references)
float maximumForce = ((JointDrive)(ref d)).maximumForce;
if (float.IsInfinity(maximumForce) || maximumForce > 1E+30f)
{
return d;
}
(IntPtr, int) key = (((Il2CppObjectBase)j).Pointer, axis);
if (Written.TryGetValue(key, out var value) && Mathf.Approximately(value, maximumForce))
{
return d;
}
((JointDrive)(ref d)).maximumForce = maximumForce * s;
Written[key] = ((JointDrive)(ref d)).maximumForce;
return d;
}
}
[HarmonyPatch(typeof(HexaHandsBase), "UpdateTargetVelocity")]
internal static class HandVelocityPatch
{
private static void Postfix(HexaHandsBase __instance)
{
//IL_0025: 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_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_006d: Unknown result type (might be due to invalid IL or missing references)
//IL_0075: Unknown result type (might be due to invalid IL or missing references)
//IL_007a: Unknown result type (might be due to invalid IL or missing references)
//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_005f: Unknown result type (might be due to invalid IL or missing references)
float current = Core.Current;
if (Mathf.Approximately(current, 1f))
{
return;
}
ConfigurableJoint joint = __instance.Joint;
if (!((Object)(object)joint == (Object)null))
{
Vector3 val = Vector3.zero;
HexaBodyPlayer4 hexaBody = __instance.HexaBody;
Rigidbody parentRigidBody = __instance.ParentRigidBody;
if ((Object)(object)hexaBody != (Object)null && (Object)(object)parentRigidBody != (Object)null)
{
val = ((Component)parentRigidBody).transform.InverseTransformDirection(hexaBody.HMDSpeed);
}
joint.targetVelocity = joint.targetVelocity * current - val * (current - 1f);
}
}
}
[HarmonyPatch(typeof(PlayerBodyIK), "SetNeckRotation")]
internal static class NeckPatch
{
private static void Postfix(PlayerBodyIK __instance)
{
//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_0039: Unknown result type (might be due to invalid IL or missing references)
float current = Core.Current;
if (!Mathf.Approximately(current, 1f))
{
Transform neckCylinderTransform = __instance.neckCylinderTransform;
if (!((Object)(object)neckCylinderTransform == (Object)null))
{
Vector3 localScale = neckCylinderTransform.localScale;
localScale.y /= current;
neckCylinderTransform.localScale = localScale;
}
}
}
}
[HarmonyPatch(typeof(HexaBodyPlayer4), "CalibrateHeight")]
internal static class CalibrateHeightPatch
{
private static void Prefix(HexaBodyPlayer4 __instance, out float __state)
{
__state = 1f;
if (!((Object)(object)Core.Body == (Object)null) && !(((Il2CppObjectBase)__instance).Pointer != ((Il2CppObjectBase)Core.Body).Pointer))
{
float current = Core.Current;
if (!Mathf.Approximately(current, 1f))
{
__state = current;
__instance.EyeHeight /= current;
}
}
}
private static void Postfix(HexaBodyPlayer4 __instance, float __state)
{
if (!Mathf.Approximately(__state, 1f))
{
__instance.EyeHeight *= __state;
__instance._scale *= __state;
__instance.SittingOffset *= __state;
}
}
}
}