using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using BoneLib;
using BoneLib.Notifications;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSLZ.Bonelab;
using Il2CppSLZ.Marrow;
using Il2CppSLZ.Marrow.AI;
using Il2CppSystem;
using Il2CppSystem.Collections.Generic;
using LabFusion.Entities;
using LabFusion.Network;
using LabFusion.Network.Serialization;
using LabFusion.Player;
using LabFusion.SDK.Modules;
using MelonLoader;
using PorterJoueurs;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(/*Could not decode attribute arguments.*/)]
[assembly: MelonInfo(typeof(Main), "PorterJoueurs", "1.0.0", "fulyx34", null)]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
[assembly: AssemblyVersion("0.0.0.0")]
namespace PorterJoueurs;
public class Main : MelonMod
{
private sealed class NpcCarry
{
public AIBrain Brain;
public Rigidbody[] Rbs;
public Rigidbody Pelvis;
public int Axis = -1;
public Vector3 SmoothFwd;
}
[Serializable]
[CompilerGenerated]
private sealed class <>c
{
public static readonly <>c <>9 = new <>c();
public static Action <>9__41_0;
public static Action<LevelInfo> <>9__41_1;
public static Action<RigManager> <>9__41_2;
public static Action <>9__49_0;
public static Action <>9__49_1;
internal void <OnInitializeMelon>b__41_0()
{
ForceStopAll(notify: false);
StopNpc();
_brains.Clear();
_radialShown = null;
}
internal void <OnInitializeMelon>b__41_1(LevelInfo _)
{
_radialShown = null;
}
internal void <OnInitializeMelon>b__41_2(RigManager rig)
{
if ((Object)(object)rig != (Object)null && (Object)(object)rig == (Object)(object)Player.RigManager)
{
ForceStopAll(notify: true);
StopNpc();
}
}
internal void <ActionFor>b__49_0()
{
if (_npc != null)
{
StopNpc();
}
else
{
StopCarrying(notifyOther: true);
}
}
internal void <ActionFor>b__49_1()
{
StopCarried(notifyOther: true);
}
}
private const float PickupRange = 2.5f;
private const float BackOffset = 0.28f;
private const float HeightOffset = 0.15f;
private const float MaxLeash = 2f;
private const float AckTimeout = 3f;
private const string LabelCarry = "Porter";
private const string LabelDrop = "Poser";
private const string LabelGetDown = "Descendre";
internal const byte ActStart = 1;
internal const byte ActStop = 2;
internal const byte ActAck = 3;
internal const byte ActRefuse = 4;
private static byte? _carrying;
private static bool _carryConfirmed;
private static float _ackDeadline;
private static byte? _carriedBy;
private static string _radialShown;
private static float _radialCheck;
private static bool _handlerOk;
private static Rigidbody[] _myRbs;
private static Vector3 _lastCarrierPos;
private static Vector3 _carrierVel;
private static bool _hasLast;
private static int _fwdAxis = -1;
private static Vector3 _smoothFwd;
private static bool _ballLocoDisabled;
private static float _nextTeleport;
private static bool _turnInit;
private static int _turnMode;
private static float _turnSign = 1f;
private static float _targetRigYaw;
private static float _lastCarrierYaw;
private static float _lastRigYaw;
private static float _probeCmd;
private static float _probeMeas;
private static NpcCarry _npc;
private static readonly List<ValueTuple<AIBrain, Rigidbody>> _brains = new List<ValueTuple<AIBrain, Rigidbody>>();
private static float _brainScan;
private static readonly Dictionary<long, ValueTuple<Collider, Collider>> _ignored = new Dictionary<long, ValueTuple<Collider, Collider>>();
private static float _ignoreRefresh;
private static bool _warnedFull;
private static readonly Vector3[] Axes = (Vector3[])(object)new Vector3[6]
{
Vector3.forward,
Vector3.back,
Vector3.right,
Vector3.left,
Vector3.up,
Vector3.down
};
public override void OnInitializeMelon()
{
//IL_0014: 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_001f: Expected O, but got Unknown
object obj = <>c.<>9__41_0;
if (obj == null)
{
Action val = delegate
{
ForceStopAll(notify: false);
StopNpc();
_brains.Clear();
_radialShown = null;
};
<>c.<>9__41_0 = val;
obj = (object)val;
}
Hooking.OnLevelUnloaded += (Action)obj;
Hooking.OnLevelLoaded += delegate
{
_radialShown = null;
};
Hooking.OnPlayerDeath += delegate(RigManager rig)
{
if ((Object)(object)rig != (Object)null && (Object)(object)rig == (Object)(object)Player.RigManager)
{
ForceStopAll(notify: true);
StopNpc();
}
};
}
public override void OnLateInitializeMelon()
{
try
{
ModuleMessageManager.RegisterHandler<CarryMessage>();
_handlerOk = true;
((MelonBase)this).LoggerInstance.Msg("Message réseau enregistré.");
}
catch (global::System.Exception ex)
{
((MelonBase)this).LoggerInstance.Error("Impossible d'enregistrer le message réseau (Fusion absent ?) : " + (object)ex);
}
}
public override void OnUpdate()
{
if (!_handlerOk)
{
return;
}
try
{
if (!NetworkInfo.HasServer && (_carrying.HasValue || _carriedBy.HasValue))
{
ForceStopAll(notify: false);
}
if (_npc != null)
{
if ((Object)(object)_npc.Brain == (Object)null || (Object)(object)_npc.Pelvis == (Object)null || NetworkInfo.HasServer)
{
StopNpc();
}
else if (Time.time > _ignoreRefresh)
{
_ignoreRefresh = Time.time + 2f;
IgnoreWithObject(((Component)_npc.Brain).gameObject);
}
}
if (_carrying.HasValue && !_carryConfirmed && Time.time > _ackDeadline)
{
Notify("Porter", "Pas de réponse : l'autre joueur doit aussi avoir le mod PorterJoueurs.", (NotificationType)1);
StopCarrying(notifyOther: false);
}
if (_carrying.HasValue && (Object)(object)GetRig(_carrying.Value) == (Object)null)
{
StopCarrying(notifyOther: false);
}
if (_carriedBy.HasValue && (Object)(object)GetRig(_carriedBy.Value) == (Object)null)
{
StopCarried(notifyOther: false);
}
byte? b = _carrying ?? _carriedBy;
if (b.HasValue && Time.time > _ignoreRefresh)
{
_ignoreRefresh = Time.time + 2f;
IgnoreWith(GetRig(b.Value), ignore: true);
}
if (_carriedBy.HasValue)
{
AlignToCarrier(Time.deltaTime);
}
UpdateRadial();
}
catch (global::System.Exception ex)
{
((MelonBase)this).LoggerInstance.Error(((object)ex).ToString());
}
}
public override void OnFixedUpdate()
{
if (_npc != null)
{
try
{
FollowNpc(Time.fixedDeltaTime);
}
catch (global::System.Exception ex)
{
((MelonBase)this).LoggerInstance.Error(((object)ex).ToString());
StopNpc();
}
}
if (!_carriedBy.HasValue)
{
return;
}
try
{
FollowCarrier(Time.fixedDeltaTime);
}
catch (global::System.Exception ex2)
{
((MelonBase)this).LoggerInstance.Error(((object)ex2).ToString());
StopCarried(notifyOther: true);
}
}
private void UpdateRadial()
{
string text = null;
if (_carriedBy.HasValue)
{
text = "Descendre";
}
else if (_carrying.HasValue || _npc != null)
{
text = "Poser";
}
else if (FindNearest().HasValue || (Object)(object)FindNearestNpc() != (Object)null)
{
text = "Porter";
}
UIRig instance = UIRig.Instance;
bool flag = (Object)(object)instance != (Object)null && (Object)(object)instance.popUpMenu != (Object)null && instance.popUpMenu.isActive;
if ((flag && text == "Porter" && _radialShown == null) || (flag && text == null && _radialShown == "Porter"))
{
return;
}
SetRadial(text);
if (text != null && Time.time > _radialCheck)
{
_radialCheck = Time.time + 1f;
if (!RadialHas(text))
{
_radialShown = null;
SetRadial(text);
}
}
}
private static void SetRadial(string want)
{
if (want == _radialShown || (Object)(object)UIRig.Instance == (Object)null)
{
return;
}
try
{
if (_radialShown != null)
{
RadialSetItem(_radialShown, null);
}
if (want != null)
{
RadialSetItem(want, ActionFor(want));
}
_radialShown = want;
MelonLogger.Msg("[Porter] menu rapide : " + (want ?? "(rien)"));
}
catch (global::System.Exception ex)
{
MelonLogger.Error("[Porter] menu : " + ex.Message);
}
}
private static void RadialSetItem(string name, Action action)
{
//IL_0093: Unknown result type (might be due to invalid IL or missing references)
//IL_009d: Expected I4, but got Unknown
//IL_010b: Unknown result type (might be due to invalid IL or missing references)
//IL_0115: Expected O, but got Unknown
UIRig instance = UIRig.Instance;
object obj;
if (instance == null)
{
obj = null;
}
else
{
PopUpMenuView popUpMenu = instance.popUpMenu;
obj = ((popUpMenu != null) ? popUpMenu.radialPageView : null);
}
PageView val = (PageView)obj;
Page val2 = ((val != null) ? val.m_HomePage : null);
if (val2 == null)
{
return;
}
List<PageItem> items = val2.items;
for (int num = items.Count - 1; num >= 0; num--)
{
if (items[num] != null && items[num].name == name)
{
items.RemoveAt(num);
}
}
if (action != null)
{
HashSet<int> val3 = new HashSet<int>();
for (int i = 0; i < items.Count; i++)
{
if (items[i] != null)
{
val3.Add((int)items[i].direction);
}
}
int num2 = -1;
for (int j = 0; j < 8; j++)
{
if (!val3.Contains(j))
{
num2 = j;
break;
}
}
if (num2 < 0)
{
if (!_warnedFull)
{
_warnedFull = true;
Notify("Porter", "Le menu rapide est plein : impossible d'ajouter \"" + name + "\".", (NotificationType)1);
}
}
else
{
items.Add(new PageItem(name, (Directions)num2, Action.op_Implicit(action)));
}
}
val.Render(val2);
}
private static Action ActionFor(string label)
{
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_001a: Expected O, but got Unknown
//IL_005b: Unknown result type (might be due to invalid IL or missing references)
//IL_0060: Unknown result type (might be due to invalid IL or missing references)
//IL_0066: Expected O, but got Unknown
//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_0046: Expected O, but got Unknown
if (!(label == "Porter"))
{
if (label == "Poser")
{
object obj = <>c.<>9__49_0;
if (obj == null)
{
Action val = delegate
{
if (_npc != null)
{
StopNpc();
}
else
{
StopCarrying(notifyOther: true);
}
};
<>c.<>9__49_0 = val;
obj = (object)val;
}
return (Action)obj;
}
object obj2 = <>c.<>9__49_1;
if (obj2 == null)
{
Action val2 = delegate
{
StopCarried(notifyOther: true);
};
<>c.<>9__49_1 = val2;
obj2 = (object)val2;
}
return (Action)obj2;
}
return new Action(OnCarryPressed);
}
private static bool RadialHas(string label)
{
try
{
UIRig instance = UIRig.Instance;
object obj;
if (instance == null)
{
obj = null;
}
else
{
PopUpMenuView popUpMenu = instance.popUpMenu;
if (popUpMenu == null)
{
obj = null;
}
else
{
PageView radialPageView = popUpMenu.radialPageView;
obj = ((radialPageView != null) ? radialPageView.m_HomePage : null);
}
}
Page val = (Page)obj;
if (val == null)
{
return false;
}
List<PageItem> items = val.items;
for (int i = 0; i < items.Count; i++)
{
if (items[i] != null && items[i].name == label)
{
return true;
}
}
}
catch
{
}
return false;
}
private static void OnCarryPressed()
{
if (_carrying.HasValue || _carriedBy.HasValue || _npc != null)
{
return;
}
byte? carrying = FindNearest();
if (!carrying.HasValue)
{
AIBrain val = FindNearestNpc();
if ((Object)(object)val != (Object)null)
{
StartNpc(val);
}
else
{
Notify("Porter", "Personne n'est assez près de toi.", (NotificationType)1);
}
}
else
{
_carrying = carrying;
_carryConfirmed = false;
_ackDeadline = Time.time + 3f;
Send(carrying.Value, 1);
}
}
private static void StopCarrying(bool notifyOther)
{
if (_carrying.HasValue)
{
byte value = _carrying.Value;
_carrying = null;
_carryConfirmed = false;
RestoreCollisions();
if (notifyOther)
{
Send(value, 2);
}
}
}
private static void StopCarried(bool notifyOther)
{
if (!_carriedBy.HasValue)
{
return;
}
byte value = _carriedBy.Value;
_carriedBy = null;
RestoreCollisions();
_myRbs = null;
_hasLast = false;
_fwdAxis = -1;
_turnInit = false;
if (_ballLocoDisabled)
{
try
{
PhysicsRig physicsRig = Player.PhysicsRig;
if (physicsRig != null)
{
physicsRig.EnableBallLoco();
}
}
catch
{
}
_ballLocoDisabled = false;
}
if (notifyOther)
{
Send(value, 2);
}
}
private static void ForceStopAll(bool notify)
{
StopCarrying(notify);
StopCarried(notify);
}
internal static void OnMessage(byte sender, byte action)
{
//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)
switch (action)
{
case 1:
if (_carrying.HasValue || _carriedBy.HasValue || (Object)(object)GetRig(sender) == (Object)null)
{
Send(sender, 4);
break;
}
_carriedBy = sender;
_hasLast = false;
_fwdAxis = -1;
_myRbs = null;
_smoothFwd = Vector3.zero;
_turnInit = false;
_ignoreRefresh = 0f;
try
{
PhysicsRig physicsRig = Player.PhysicsRig;
if (physicsRig != null)
{
physicsRig.DisableBallLoco();
}
_ballLocoDisabled = true;
}
catch
{
}
Send(sender, 3);
Notify("Porter", NameOf(sender) + " te porte. Menu rapide → \"Descendre\" pour descendre.", (NotificationType)0);
break;
case 3:
if (_carrying == sender)
{
_carryConfirmed = true;
_ignoreRefresh = 0f;
Notify("Porter", "Tu portes " + NameOf(sender) + ". Menu rapide → \"Poser\" pour le poser.", (NotificationType)3);
}
break;
case 4:
if (_carrying == sender)
{
_carrying = null;
_carryConfirmed = false;
Notify("Porter", NameOf(sender) + " ne peut pas être porté pour l'instant.", (NotificationType)1);
}
break;
case 2:
if (_carriedBy == sender)
{
StopCarried(notifyOther: false);
}
if (_carrying == sender)
{
StopCarrying(notifyOther: false);
Notify("Porter", NameOf(sender) + " est descendu.", (NotificationType)0);
}
break;
}
}
private static void Send(byte target, byte action)
{
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
try
{
MessageRelay.RelayModule<CarryMessage, CarryData>(new CarryData
{
Action = action
}, new MessageRoute(target, (NetworkChannel)0));
}
catch (global::System.Exception ex)
{
MelonLogger.Error("[Porter] envoi : " + ex.Message);
}
}
private static RigManager GetRig(byte smallId)
{
NetworkPlayer val = null;
if (!NetworkPlayerManager.TryGetPlayer(smallId, ref val) || val == null || !val.HasRig)
{
return null;
}
RigRefs rigRefs = val.RigRefs;
if (rigRefs == null || !rigRefs.IsValid)
{
return null;
}
return rigRefs.RigManager;
}
private static string NameOf(byte smallId)
{
NetworkPlayer val = null;
if (NetworkPlayerManager.TryGetPlayer(smallId, ref val) && val != null && !string.IsNullOrEmpty(val.Username))
{
return val.Username;
}
return "Le joueur";
}
private static byte? FindNearest()
{
//IL_0033: 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_009b: Unknown result type (might be due to invalid IL or missing references)
//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
Transform head = Player.Head;
if ((Object)(object)head == (Object)null || !NetworkInfo.HasServer)
{
return null;
}
byte? result = null;
float num = 2.5f;
Enumerator<PlayerID> enumerator = PlayerIDManager.PlayerIDs.GetEnumerator();
try
{
while (enumerator.MoveNext())
{
PlayerID current = enumerator.Current;
if (current == null || current.IsMe)
{
continue;
}
NetworkPlayer val = null;
if (!NetworkPlayerManager.TryGetPlayer(current.SmallID, ref val) || val == null || !val.HasRig)
{
continue;
}
RigRefs rigRefs = val.RigRefs;
if (rigRefs != null && rigRefs.IsValid && !((Object)(object)rigRefs.Head == (Object)null))
{
float num2 = Vector3.Distance(head.position, rigRefs.Head.position);
if (num2 < num)
{
num = num2;
result = current.SmallID;
}
}
}
return result;
}
finally
{
((global::System.IDisposable)enumerator/*cast due to .constrained prefix*/).Dispose();
}
}
private static void FollowCarrier(float dt)
{
//IL_0070: Unknown result type (might be due to invalid IL or missing references)
//IL_0075: Unknown result type (might be due to invalid IL or missing references)
//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
//IL_007d: Unknown result type (might be due to invalid IL or missing references)
//IL_007e: Unknown result type (might be due to invalid IL or missing references)
//IL_0083: 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_0098: 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_00d2: 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_00b4: Unknown result type (might be due to invalid IL or missing references)
//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
//IL_00a8: 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_011b: Unknown result type (might be due to invalid IL or missing references)
//IL_0120: Unknown result type (might be due to invalid IL or missing references)
//IL_0122: 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_0153: Unknown result type (might be due to invalid IL or missing references)
//IL_0133: Unknown result type (might be due to invalid IL or missing references)
//IL_0138: Unknown result type (might be due to invalid IL or missing references)
//IL_014c: 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_0174: 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_0179: Unknown result type (might be due to invalid IL or missing references)
//IL_017b: Unknown result type (might be due to invalid IL or missing references)
//IL_017c: 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_0197: Unknown result type (might be due to invalid IL or missing references)
//IL_019c: Unknown result type (might be due to invalid IL or missing references)
//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
//IL_01da: Unknown result type (might be due to invalid IL or missing references)
//IL_020b: Unknown result type (might be due to invalid IL or missing references)
//IL_020d: Unknown result type (might be due to invalid IL or missing references)
//IL_0217: Unknown result type (might be due to invalid IL or missing references)
//IL_021c: 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_0245: Unknown result type (might be due to invalid IL or missing references)
//IL_024a: Unknown result type (might be due to invalid IL or missing references)
//IL_0251: Unknown result type (might be due to invalid IL or missing references)
//IL_025b: Unknown result type (might be due to invalid IL or missing references)
//IL_0260: Unknown result type (might be due to invalid IL or missing references)
//IL_0265: Unknown result type (might be due to invalid IL or missing references)
//IL_0292: Unknown result type (might be due to invalid IL or missing references)
RigManager rig = GetRig(_carriedBy.Value);
PhysicsRig physicsRig = Player.PhysicsRig;
if ((Object)(object)rig == (Object)null || (Object)(object)physicsRig == (Object)null)
{
StopCarried(notifyOther: true);
return;
}
PhysTorso val = (((Object)(object)rig.physicsRig != (Object)null) ? rig.physicsRig.torso : null);
if ((Object)(object)val == (Object)null || (Object)(object)val.rbPelvis == (Object)null)
{
return;
}
Transform transform = ((Component)val.rbPelvis).transform;
Vector3 position = transform.position;
if (_hasLast)
{
Vector3 val2 = (position - _lastCarrierPos) / Mathf.Max(dt, 0.001f);
if (((Vector3)(ref val2)).sqrMagnitude > 400f)
{
val2 = Vector3.zero;
}
_carrierVel = Vector3.Lerp(_carrierVel, val2, 0.35f);
}
else
{
_carrierVel = Vector3.zero;
}
_lastCarrierPos = position;
_hasLast = true;
Transform head = null;
NetworkPlayer val3 = null;
if (NetworkPlayerManager.TryGetPlayer(_carriedBy.Value, ref val3) && ((val3 != null) ? val3.RigRefs : null) != null)
{
head = val3.RigRefs.Head;
}
Vector3 val4 = BodyForward(transform, head, ref _fwdAxis);
_smoothFwd = ((_smoothFwd == Vector3.zero) ? val4 : Vector3.Slerp(_smoothFwd, val4, 1f - Mathf.Exp(-8f * dt)));
Vector3 val5 = ((((Vector3)(ref _smoothFwd)).sqrMagnitude > 0.01f) ? ((Vector3)(ref _smoothFwd)).normalized : val4);
Vector3 val6 = position + Vector3.up * 0.15f - val5 * 0.28f;
Rigidbody val7 = (((Object)(object)physicsRig.torso != (Object)null) ? physicsRig.torso.rbPelvis : null);
if ((Object)(object)val7 == (Object)null)
{
return;
}
Vector3 val8 = val6 - val7.position;
if (((Vector3)(ref val8)).magnitude > 2f)
{
if (Time.time >= _nextTeleport)
{
_nextTeleport = Time.time + 0.5f;
Player.RigManager.Teleport(val6 - Vector3.up * 0.9f, val5, true);
}
return;
}
if (_myRbs == null || _myRbs.Length == 0)
{
_myRbs = BodyRbs(physicsRig);
}
Vector3 velocity = _carrierVel + Vector3.ClampMagnitude(val8 * 12f, 8f);
for (int i = 0; i < _myRbs.Length; i++)
{
Rigidbody val9 = _myRbs[i];
if ((Object)(object)val9 == (Object)null)
{
_myRbs = null;
break;
}
if (!val9.isKinematic)
{
val9.velocity = velocity;
}
}
}
private static float Yaw(Vector3 flatDir)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
return Mathf.Atan2(flatDir.x, flatDir.z) * 57.29578f;
}
private static void AlignToCarrier(float dt)
{
//IL_005a: 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_007e: Unknown result type (might be due to invalid IL or missing references)
//IL_0083: Unknown result type (might be due to invalid IL or missing references)
//IL_0088: Unknown result type (might be due to invalid IL or missing references)
//IL_008a: Unknown result type (might be due to invalid IL or missing references)
//IL_008c: Unknown result type (might be due to invalid IL or missing references)
//IL_0098: 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_01a4: Unknown result type (might be due to invalid IL or missing references)
if (_turnMode >= 2 || ((Vector3)(ref _smoothFwd)).sqrMagnitude < 0.01f)
{
return;
}
OpenControllerRig controllerRig = Player.ControllerRig;
Transform head = Player.Head;
if ((Object)(object)controllerRig == (Object)null || (Object)(object)head == (Object)null)
{
return;
}
Transform obj = (((Object)(object)controllerRig.vrRoot != (Object)null) ? controllerRig.vrRoot : ((Component)controllerRig).transform);
float num = Yaw(((Vector3)(ref _smoothFwd)).normalized);
float y = obj.eulerAngles.y;
if (!_turnInit)
{
_turnInit = true;
Vector3 val = Flat(head.forward);
float num2 = ((val == Vector3.zero) ? y : Yaw(val));
_targetRigYaw = y + Mathf.DeltaAngle(num2, num);
_lastCarrierYaw = num;
_lastRigYaw = y;
_probeCmd = 0f;
_probeMeas = 0f;
return;
}
_targetRigYaw += Mathf.DeltaAngle(_lastCarrierYaw, num);
_lastCarrierYaw = num;
float num3 = Mathf.DeltaAngle(_lastRigYaw, y);
_lastRigYaw = y;
float num4 = Mathf.DeltaAngle(y, _targetRigYaw);
if (Mathf.Abs(num4) < 2f)
{
_probeCmd = 0f;
_probeMeas = 0f;
return;
}
float num5 = Mathf.Sign(num4);
if (_turnMode == 0)
{
float num6 = Mathf.Clamp(num4 / 25f, -1f, 1f);
controllerRig.SmoothRotate(num6 * _turnSign, dt);
_probeCmd += Mathf.Abs(num6) * dt;
}
else
{
float num7 = Mathf.Clamp(num4, -150f * dt, 150f * dt);
((Component)controllerRig).transform.RotateAround(head.position, Vector3.up, num7);
_probeCmd += Mathf.Abs(num7) / 150f;
}
_probeMeas += num3 * num5;
if (_probeCmd > 0.35f)
{
if (_turnMode == 0 && _probeMeas < -3f)
{
_turnSign = 0f - _turnSign;
MelonLogger.Msg("[Porter] rotation : sens inversé");
}
else if (Mathf.Abs(_probeMeas) < 2f)
{
_turnMode++;
MelonLogger.Msg("[Porter] rotation : passage au mode " + _turnMode);
}
_probeCmd = 0f;
_probeMeas = 0f;
}
}
private static Rigidbody[] BodyRbs(PhysicsRig rig)
{
List<Rigidbody> val = new List<Rigidbody>();
PhysTorso torso = rig.torso;
if ((Object)(object)torso != (Object)null)
{
if ((Object)(object)torso.rbPelvis != (Object)null)
{
val.Add(torso.rbPelvis);
}
if ((Object)(object)torso.rbSpine != (Object)null)
{
val.Add(torso.rbSpine);
}
if ((Object)(object)torso.rbChest != (Object)null)
{
val.Add(torso.rbChest);
}
if ((Object)(object)torso.rbNeck != (Object)null)
{
val.Add(torso.rbNeck);
}
if ((Object)(object)torso.rbHead != (Object)null)
{
val.Add(torso.rbHead);
}
}
if ((Object)(object)rig.rbKnee != (Object)null)
{
val.Add(rig.rbKnee);
}
if ((Object)(object)rig.rbFeet != (Object)null)
{
val.Add(rig.rbFeet);
}
if (val.Count == 0)
{
global::System.Collections.Generic.IEnumerator<Rigidbody> enumerator = ((Component)rig).GetComponentsInChildren<Rigidbody>(true).GetEnumerator();
try
{
while (((global::System.Collections.IEnumerator)enumerator).MoveNext())
{
Rigidbody current = enumerator.Current;
if ((Object)(object)current != (Object)null)
{
val.Add(current);
}
}
}
finally
{
((global::System.IDisposable)enumerator)?.Dispose();
}
}
return val.ToArray();
}
private static Vector3 BodyForward(Transform pel, Transform head, ref int axis)
{
//IL_008a: Unknown result type (might be due to invalid IL or missing references)
//IL_008f: Unknown result type (might be due to invalid IL or missing references)
//IL_0094: 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_009a: Unknown result type (might be due to invalid IL or missing references)
//IL_009b: Unknown result type (might be due to invalid IL or missing references)
//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
//IL_00a7: 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_000f: Unknown result type (might be due to invalid IL or missing references)
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: 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_003d: 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_0049: 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_0057: Unknown result type (might be due to invalid IL or missing references)
//IL_0059: Unknown result type (might be due to invalid IL or missing references)
if (axis < 0)
{
Vector3 val = (((Object)(object)head != (Object)null) ? Flat(head.forward) : Flat(pel.forward));
float num = -2f;
for (int i = 0; i < Axes.Length; i++)
{
Vector3 val2 = Flat(pel.TransformDirection(Axes[i]));
if (!(val2 == Vector3.zero))
{
float num2 = Vector3.Dot(val2, val);
if (num2 > num)
{
num = num2;
axis = i;
}
}
}
if (axis < 0)
{
axis = 0;
}
}
Vector3 val3 = Flat(pel.TransformDirection(Axes[axis]));
if (!(val3 == Vector3.zero))
{
return val3;
}
return Vector3.forward;
}
private static AIBrain FindNearestNpc()
{
//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_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_00e9: 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_008a: Unknown result type (might be due to invalid IL or missing references)
Transform head = Player.Head;
if ((Object)(object)head == (Object)null || NetworkInfo.HasServer)
{
return null;
}
if (Time.time > _brainScan)
{
_brainScan = Time.time + 1f;
_brains.Clear();
global::System.Collections.Generic.IEnumerator<AIBrain> enumerator = Object.FindObjectsOfType<AIBrain>().GetEnumerator();
try
{
while (((global::System.Collections.IEnumerator)enumerator).MoveNext())
{
AIBrain current = enumerator.Current;
if (!((Object)(object)current == (Object)null) && ((Component)current).gameObject.activeInHierarchy)
{
Rigidbody val = NpcPelvis(current);
if ((Object)(object)val != (Object)null)
{
_brains.Add(new ValueTuple<AIBrain, Rigidbody>(current, val));
}
}
}
}
finally
{
((global::System.IDisposable)enumerator)?.Dispose();
}
}
AIBrain result = null;
float num = 2.5f;
Enumerator<ValueTuple<AIBrain, Rigidbody>> enumerator2 = _brains.GetEnumerator();
try
{
while (enumerator2.MoveNext())
{
ValueTuple<AIBrain, Rigidbody> current2 = enumerator2.Current;
AIBrain item = current2.Item1;
Rigidbody item2 = current2.Item2;
if (!((Object)(object)item == (Object)null) && !((Object)(object)item2 == (Object)null))
{
float num2 = Vector3.Distance(head.position, item2.position);
if (num2 < num)
{
num = num2;
result = item;
}
}
}
return result;
}
finally
{
((global::System.IDisposable)enumerator2/*cast due to .constrained prefix*/).Dispose();
}
}
private static Rigidbody NpcPelvis(AIBrain b)
{
Rigidbody val = null;
global::System.Collections.Generic.IEnumerator<Rigidbody> enumerator = ((Component)b).GetComponentsInChildren<Rigidbody>(false).GetEnumerator();
try
{
while (((global::System.Collections.IEnumerator)enumerator).MoveNext())
{
Rigidbody current = enumerator.Current;
if (!((Object)(object)current == (Object)null))
{
string text = ((Object)current).name.ToLowerInvariant();
if (text.Contains("pelvis") || text.Contains("hip"))
{
return current;
}
if ((Object)(object)val == (Object)null || current.mass > val.mass)
{
val = current;
}
}
}
return val;
}
finally
{
((global::System.IDisposable)enumerator)?.Dispose();
}
}
private static void StartNpc(AIBrain brain)
{
Il2CppArrayBase<Rigidbody> componentsInChildren = ((Component)brain).GetComponentsInChildren<Rigidbody>(false);
Rigidbody[] array = (Rigidbody[])(object)new Rigidbody[componentsInChildren.Length];
for (int i = 0; i < componentsInChildren.Length; i++)
{
array[i] = componentsInChildren[i];
}
_npc = new NpcCarry
{
Brain = brain,
Rbs = array,
Pelvis = NpcPelvis(brain)
};
_ignoreRefresh = 0f;
IgnoreWithObject(((Component)brain).gameObject);
Notify("Porter (test solo)", "Tu portes un PNJ. Menu rapide → \"Poser\" pour le poser.", (NotificationType)3);
}
private static void StopNpc()
{
if (_npc != null)
{
_npc = null;
RestoreCollisions();
}
}
private static void FollowNpc(float dt)
{
//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_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_00a2: Unknown result type (might be due to invalid IL or missing references)
//IL_0083: Unknown result type (might be due to invalid IL or missing references)
//IL_0088: Unknown result type (might be due to invalid IL or missing references)
//IL_009b: 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_00cb: 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_00d0: Unknown result type (might be due to invalid IL or missing references)
//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
//IL_00d7: 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_00e6: Unknown result type (might be due to invalid IL or missing references)
//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
//IL_0105: Unknown result type (might be due to invalid IL or missing references)
//IL_010a: Unknown result type (might be due to invalid IL or missing references)
//IL_010f: Unknown result type (might be due to invalid IL or missing references)
//IL_0112: Unknown result type (might be due to invalid IL or missing references)
//IL_0117: Unknown result type (might be due to invalid IL or missing references)
//IL_0129: Unknown result type (might be due to invalid IL or missing references)
//IL_012b: Unknown result type (might be due to invalid IL or missing references)
//IL_0132: Unknown result type (might be due to invalid IL or missing references)
//IL_013c: Unknown result type (might be due to invalid IL or missing references)
//IL_0141: Unknown result type (might be due to invalid IL or missing references)
//IL_0146: Unknown result type (might be due to invalid IL or missing references)
//IL_017a: Unknown result type (might be due to invalid IL or missing references)
//IL_017f: Unknown result type (might be due to invalid IL or missing references)
//IL_0181: Unknown result type (might be due to invalid IL or missing references)
//IL_0195: Unknown result type (might be due to invalid IL or missing references)
//IL_0191: 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_01a9: Unknown result type (might be due to invalid IL or missing references)
PhysicsRig physicsRig = Player.PhysicsRig;
Rigidbody val = (((Object)(object)physicsRig != (Object)null && (Object)(object)physicsRig.torso != (Object)null) ? physicsRig.torso.rbPelvis : null);
if ((Object)(object)val == (Object)null || (Object)(object)_npc.Pelvis == (Object)null)
{
return;
}
Vector3 val2 = BodyForward(((Component)val).transform, Player.Head, ref _npc.Axis);
_npc.SmoothFwd = ((_npc.SmoothFwd == Vector3.zero) ? val2 : Vector3.Slerp(_npc.SmoothFwd, val2, 1f - Mathf.Exp(-8f * dt)));
Vector3 val3 = ((((Vector3)(ref _npc.SmoothFwd)).sqrMagnitude > 0.01f) ? ((Vector3)(ref _npc.SmoothFwd)).normalized : val2);
Vector3 val4 = val.position + Vector3.up * 0.15f - val3 * 0.28f - _npc.Pelvis.position;
Vector3 velocity = val.velocity;
bool flag = ((Vector3)(ref val4)).magnitude > 2f;
Vector3 val5 = velocity + Vector3.ClampMagnitude(val4 * 12f, 8f);
Rigidbody[] rbs = _npc.Rbs;
foreach (Rigidbody val6 in rbs)
{
if (!((Object)(object)val6 == (Object)null) && !val6.isKinematic)
{
if (flag)
{
val6.position += val4;
}
val6.velocity = (flag ? velocity : val5);
val6.angularVelocity *= 0.8f;
}
}
}
private static Vector3 Flat(Vector3 v)
{
//IL_0022: 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)
v.y = 0f;
if (!(((Vector3)(ref v)).sqrMagnitude < 0.0001f))
{
return ((Vector3)(ref v)).normalized;
}
return Vector3.zero;
}
private static void IgnoreWith(RigManager other, bool ignore)
{
//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
RigManager rigManager = Player.RigManager;
if ((Object)(object)other == (Object)null || (Object)(object)rigManager == (Object)null || (Object)(object)rigManager.physicsRig == (Object)null || (Object)(object)other.physicsRig == (Object)null)
{
return;
}
Il2CppArrayBase<Collider> componentsInChildren = ((Component)rigManager.physicsRig).GetComponentsInChildren<Collider>(true);
Il2CppArrayBase<Collider> componentsInChildren2 = ((Component)other.physicsRig).GetComponentsInChildren<Collider>(true);
for (int i = 0; i < componentsInChildren.Length; i++)
{
Collider val = componentsInChildren[i];
if ((Object)(object)val == (Object)null)
{
continue;
}
for (int j = 0; j < componentsInChildren2.Length; j++)
{
Collider val2 = componentsInChildren2[j];
if (!((Object)(object)val2 == (Object)null))
{
long num = ((long)((Object)val).GetInstanceID() << 32) ^ (uint)((Object)val2).GetInstanceID();
if (!_ignored.ContainsKey(num))
{
Physics.IgnoreCollision(val, val2, ignore);
_ignored[num] = new ValueTuple<Collider, Collider>(val, val2);
}
}
}
}
}
private static void IgnoreWithObject(GameObject other)
{
//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
RigManager rigManager = Player.RigManager;
if ((Object)(object)other == (Object)null || (Object)(object)rigManager == (Object)null || (Object)(object)rigManager.physicsRig == (Object)null)
{
return;
}
Il2CppArrayBase<Collider> componentsInChildren = ((Component)rigManager.physicsRig).GetComponentsInChildren<Collider>(true);
Il2CppArrayBase<Collider> componentsInChildren2 = other.GetComponentsInChildren<Collider>(true);
for (int i = 0; i < componentsInChildren.Length; i++)
{
Collider val = componentsInChildren[i];
if ((Object)(object)val == (Object)null)
{
continue;
}
for (int j = 0; j < componentsInChildren2.Length; j++)
{
Collider val2 = componentsInChildren2[j];
if (!((Object)(object)val2 == (Object)null))
{
long num = ((long)((Object)val).GetInstanceID() << 32) ^ (uint)((Object)val2).GetInstanceID();
if (!_ignored.ContainsKey(num))
{
Physics.IgnoreCollision(val, val2, true);
_ignored[num] = new ValueTuple<Collider, Collider>(val, val2);
}
}
}
}
}
private static void RestoreCollisions()
{
//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_0014: 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)
Enumerator<long, ValueTuple<Collider, Collider>> enumerator = _ignored.Values.GetEnumerator();
try
{
while (enumerator.MoveNext())
{
ValueTuple<Collider, Collider> current = enumerator.Current;
Collider item = current.Item1;
Collider item2 = current.Item2;
try
{
if ((Object)(object)item != (Object)null && (Object)(object)item2 != (Object)null)
{
Physics.IgnoreCollision(item, item2, false);
}
}
catch
{
}
}
}
finally
{
((global::System.IDisposable)enumerator/*cast due to .constrained prefix*/).Dispose();
}
_ignored.Clear();
}
private static void Notify(string title, string msg, NotificationType type)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
//IL_0024: 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_003b: Expected O, but got Unknown
try
{
Notifier.Send(new Notification
{
Title = NotificationText.op_Implicit(title),
Message = NotificationText.op_Implicit(msg),
Type = type,
PopupLength = 3f,
ShowTitleOnPopup = true
});
}
catch
{
MelonLogger.Msg("[Porter] " + msg);
}
}
}
public class CarryData : INetSerializable
{
public byte Action;
public int? GetSize()
{
return 1;
}
public void Serialize(INetSerializer serializer)
{
serializer.SerializeValue(ref Action);
}
}
public class CarryMessage : ModuleMessageHandler
{
protected override void OnHandleMessage(ReceivedMessage received)
{
CarryData carryData = ((ReceivedMessage)(ref received)).ReadData<CarryData>();
if (((ReceivedMessage)(ref received)).Sender.HasValue)
{
Main.OnMessage(((ReceivedMessage)(ref received)).Sender.Value, carryData.Action);
}
}
}