using System;
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 Il2Cpp;
using Il2CppActiveRagdoll;
using Il2CppHurricaneVR.Framework.Core;
using Il2CppHurricaneVR.Framework.Core.Grabbers;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem.Collections.Generic;
using MelonLoader;
using MelonLoader.Preferences;
using Microsoft.CodeAnalysis;
using ThrowAssist;
using UnityEngine;
using UnityEngine.Events;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(ThrowAssistMod), "BetterThrowing", "1.9.1", "SkIbidiRizTEAM", null)]
[assembly: MelonGame("Kubunautilus", "BrutalistickVR")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("BetterThrowing")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+29b4f0660e344850b9a0b58239268ab63bf3e70a")]
[assembly: AssemblyProduct("BetterThrowing")]
[assembly: AssemblyTitle("BetterThrowing")]
[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 ThrowAssist
{
public static class Ballistics
{
public static bool Solve(float flatDist, float heightDiff, float naturalHorizontalSpeed, float gravity, float drag, float maxFlightTime, float maxSpeed, out float horizontalSpeed, out float verticalSpeed, out float flightTime)
{
horizontalSpeed = 0f;
verticalSpeed = 0f;
flightTime = 0f;
if (flatDist < 0.05f || naturalHorizontalSpeed <= 0.01f || gravity <= 0f)
{
return false;
}
float num = flatDist / naturalHorizontalSpeed;
if (num < 0.1f)
{
num = 0.1f;
}
if (num > maxFlightTime)
{
num = maxFlightTime;
}
flightTime = num;
if (drag < 0.001f)
{
horizontalSpeed = flatDist / num;
verticalSpeed = heightDiff / num + 0.5f * gravity * num;
}
else
{
double num2 = Math.Exp((0f - drag) * num);
double num3 = 1.0 - num2;
if (num3 < 0.0001)
{
return false;
}
double num4 = drag;
horizontalSpeed = (float)((double)flatDist * num4 / num3);
verticalSpeed = (float)((num4 * (double)heightDiff + (double)(gravity * num)) / num3 - (double)gravity / num4);
}
return (float)Math.Sqrt(horizontalSpeed * horizontalSpeed + verticalSpeed * verticalSpeed) <= maxSpeed;
}
public static bool SolveStraight(float flatDist, float heightDiff, float minHorizontalSpeed, float gravity, float drag, float maxFlightTime, float maxSpeed, float maxExcessDeg, out float horizontalSpeed, out float verticalSpeed, out float flightTime)
{
horizontalSpeed = 0f;
verticalSpeed = 0f;
flightTime = 0f;
if (flatDist < 0.05f || gravity <= 0f)
{
return false;
}
float num = (float)Math.Atan2(heightDiff, flatDist);
float num2 = maxExcessDeg * (float)Math.PI / 180f;
float num3 = Math.Max(minHorizontalSpeed, 0.1f);
float num4 = 0f;
float num5 = 0f;
float num6 = 0f;
bool flag = false;
for (int i = 0; i < 14; i++)
{
if (!Solve(flatDist, heightDiff, num3, gravity, drag, maxFlightTime, maxSpeed, out var horizontalSpeed2, out var verticalSpeed2, out var flightTime2))
{
break;
}
num4 = horizontalSpeed2;
num5 = verticalSpeed2;
num6 = flightTime2;
flag = true;
if ((float)Math.Atan2(verticalSpeed2, horizontalSpeed2) - num <= num2)
{
break;
}
num3 *= 1.25f;
}
if (!flag)
{
return false;
}
horizontalSpeed = num4;
verticalSpeed = num5;
flightTime = num6;
return true;
}
}
internal sealed class ThrowTarget
{
public StickHealth Health;
public string Name;
}
internal static class TargetScan
{
private const float MinHeight = 1f;
public static List<ThrowTarget> Scan()
{
List<ThrowTarget> list = new List<ThrowTarget>();
StickHealth[] array;
try
{
array = Il2CppArrayBase<StickHealth>.op_Implicit(Object.FindObjectsOfType<StickHealth>());
}
catch
{
return list;
}
StickHealth[] array2 = array;
foreach (StickHealth val in array2)
{
if (!((Object)(object)val == (Object)null) && !val.isDead && !val.isBeingHeld && (!((Object)(object)val.pelvisGo == (Object)null) || !((Object)(object)val.upperChest == (Object)null) || !((Object)(object)val.jawBone == (Object)null)))
{
Transform root = ((Component)val).transform.root;
string text = (((Object)(object)root != (Object)null) ? ((Object)root).name : string.Empty);
if (!text.Contains("Hexa4Rig") && !text.Contains("Player") && !(Height(((Component)val).gameObject) < 1f))
{
list.Add(new ThrowTarget
{
Health = val,
Name = text
});
}
}
}
return list;
}
private static float Height(GameObject go)
{
//IL_0041: Unknown result type (might be due to invalid IL or missing references)
//IL_0046: Unknown result type (might be due to invalid IL or missing references)
//IL_004a: Unknown result type (might be due to invalid IL or missing references)
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
//IL_0061: 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_0070: 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)
Collider[] array;
try
{
array = Il2CppArrayBase<Collider>.op_Implicit(go.GetComponentsInChildren<Collider>());
}
catch
{
return 0f;
}
float num = float.MaxValue;
float num2 = float.MinValue;
Collider[] array2 = array;
foreach (Collider val in array2)
{
if ((Object)(object)val == (Object)null)
{
continue;
}
Bounds bounds = val.bounds;
Vector3 size = ((Bounds)(ref bounds)).size;
if (!(((Vector3)(ref size)).sqrMagnitude <= 0f))
{
if (((Bounds)(ref bounds)).min.y < num)
{
num = ((Bounds)(ref bounds)).min.y;
}
if (((Bounds)(ref bounds)).max.y > num2)
{
num2 = ((Bounds)(ref bounds)).max.y;
}
}
}
if (!(num2 > num))
{
return 0f;
}
return num2 - num;
}
}
public class ThrowAssistMod : MelonMod
{
private sealed class PendingThrow
{
public Rigidbody Body;
public HVRGrabbable Grabbable;
public HVRGrabberBase Grabber;
public Vector3 HandPos;
public Vector3 HandVel;
public float HandSpeed;
public float Age;
public int Frames;
public bool Applied;
public Vector3 AppliedVelocity;
public int Reassert;
public bool TipDone;
}
private sealed class IgnorePair
{
public Collider A;
public Collider B;
public float Left;
}
private sealed class HandSample
{
public Vector3 Pos;
public Vector3 Velocity;
public float Time;
}
private sealed class TipLock
{
public Rigidbody Body;
public Vector3 LocalDir;
public float Left;
public float Gain;
public float MaxRate;
}
private const float MaxReleaseWait = 0.5f;
private const float AimHeightOffset = 0.9f;
private const float ScanInterval = 2f;
private const float MaxFlightTime = 3f;
private const float HandIgnoreTime = 0.25f;
private const int ReassertFrames = 3;
private const float TipLockTime = 2.5f;
private MelonPreferences_Entry<bool> _enabled;
private MelonPreferences_Entry<bool> _aimAtHead;
private MelonPreferences_Entry<bool> _ignoreUnconscious;
private MelonPreferences_Entry<bool> _bladeFirst;
private MelonPreferences_Entry<bool> _log;
private MelonPreferences_Entry<bool> _assistRagdolls;
private MelonPreferences_Entry<bool> _knifeAssist;
private MelonPreferences_Entry<float> _strength;
private MelonPreferences_Entry<float> _maxAngle;
private MelonPreferences_Entry<float> _maxDistance;
private MelonPreferences_Entry<float> _minThrowSpeed;
private MelonPreferences_Entry<float> _minAimSpeed;
private MelonPreferences_Entry<float> _maxSpeed;
private MelonPreferences_Entry<float> _handThrowSpeed;
private MelonPreferences_Entry<float> _tipMinSpeed;
private MelonPreferences_Entry<float> _arc;
private MelonPreferences_Entry<float> _headChance;
private MelonPreferences_Entry<int> _assistLevel;
private readonly List<PendingThrow> _pending = new List<PendingThrow>();
private readonly List<IgnorePair> _ignores = new List<IgnorePair>();
private readonly List<TipLock> _locks = new List<TipLock>();
private readonly Dictionary<int, HVRGrabbable> _hooked = new Dictionary<int, HVRGrabbable>();
private readonly Dictionary<int, HandSample> _hands = new Dictionary<int, HandSample>();
private List<ThrowTarget> _targets = new List<ThrowTarget>();
private Action<HVRGrabberBase, HVRGrabbable> _releasedHandler;
private float _scanTimer;
private bool _errorLogged;
public override void OnInitializeMelon()
{
_enabled = MelonPreferences.CreateEntry<bool>("BetterThrowing", "Enabled", true, "Enabled", "Correct throws towards a target.", false, false, (ValueValidator)null);
_assistLevel = MelonPreferences.CreateEntry<int>("BetterThrowing", "AssistLevel", 4, "Assist level (1-5, 0 = manual)", "1 = light, 2 = medium, 3 = strong, 4 = maximum, 5 = extreme, 0 = manual MaxAngle/Strength/MinAimSpeed.", false, false, (ValueValidator)null);
_strength = MelonPreferences.CreateEntry<float>("BetterThrowing", "Strength", 1f, "Assist strength (0-1)", "Manual mode only. 1 = throw exactly at the target, 0.5 = halfway.", false, false, (ValueValidator)null);
_maxAngle = MelonPreferences.CreateEntry<float>("BetterThrowing", "MaxAngle", 35f, "Max aim angle, deg", "Manual mode only. Targets farther than this from the throw direction are ignored.", false, false, (ValueValidator)null);
_maxDistance = MelonPreferences.CreateEntry<float>("BetterThrowing", "MaxDistance", 20f, "Max target distance, m", "No target is picked beyond this distance.", false, false, (ValueValidator)null);
_minThrowSpeed = MelonPreferences.CreateEntry<float>("BetterThrowing", "MinThrowSpeed", 3f, "Min throw speed, m/s", "Slower body speed is not a throw, unless the hand moved faster (HandThrowSpeed).", false, false, (ValueValidator)null);
_handThrowSpeed = MelonPreferences.CreateEntry<float>("BetterThrowing", "HandThrowSpeed", 2.5f, "Hand speed for a throw, m/s", "If the body got less than MinThrowSpeed but the hand moved faster, it still counts as a throw.", false, false, (ValueValidator)null);
_tipMinSpeed = MelonPreferences.CreateEntry<float>("BetterThrowing", "TipMinSpeed", 6f, "Tip-first speed threshold, m/s", "Slower releases are regrips, not throws: the spear/knife pose is not changed.", false, false, (ValueValidator)null);
_headChance = MelonPreferences.CreateEntry<float>("BetterThrowing", "HeadChance", 25f, "Head chance, %", "Used when AimAtHead is off: some throws still aim at the head.", false, false, (ValueValidator)null);
_minAimSpeed = MelonPreferences.CreateEntry<float>("BetterThrowing", "MinAimSpeed", 8f, "Min aim speed, m/s", "Manual mode only. A weak throw still flies at least at this speed.", false, false, (ValueValidator)null);
_maxSpeed = MelonPreferences.CreateEntry<float>("BetterThrowing", "MaxSpeed", 30f, "Max throw speed, m/s", "If hitting the target needs more speed, the throw is left as is.", false, false, (ValueValidator)null);
_aimAtHead = MelonPreferences.CreateEntry<bool>("BetterThrowing", "AimAtHead", true, "Aim at head", "Otherwise the chest, or the belly if there is no chest. Never aims at arms or legs.", false, false, (ValueValidator)null);
_bladeFirst = MelonPreferences.CreateEntry<bool>("BetterThrowing", "BladeFirst", true, "Blade/point forward", "Rotate and hold spears and knives tip-first along the flight path.", false, false, (ValueValidator)null);
_arc = MelonPreferences.CreateEntry<float>("BetterThrowing", "Arc", 8f, "Throw arc, deg", "How much the throw may rise above the straight line to the target. Lower = flatter and faster. 0 = as flat as possible.", false, false, (ValueValidator)null);
_ignoreUnconscious = MelonPreferences.CreateEntry<bool>("BetterThrowing", "IgnoreUnconscious", false, "Ignore unconscious", "Do not assist throws at knocked-out or unconscious enemies.", false, false, (ValueValidator)null);
_log = MelonPreferences.CreateEntry<bool>("BetterThrowing", "Log", false, "Verbose log", "Print a line for every assisted throw to the MelonLoader console.", false, false, (ValueValidator)null);
_assistRagdolls = MelonPreferences.CreateEntry<bool>("BetterThrowing", "AssistRagdolls", true, "Assist thrown enemies", "Give the throw impulse to grabbed enemies and dummies too. Off = normal physics.", false, false, (ValueValidator)null);
_knifeAssist = MelonPreferences.CreateEntry<bool>("BetterThrowing", "KnifeAssist", true, "Stabilize knives", "Turn knives and daggers tip-first and stop the tumble in flight.", false, false, (ValueValidator)null);
_releasedHandler = OnReleased;
((MelonBase)this).LoggerInstance.Msg("BetterThrowing 1.9.1 загружен.");
}
public override void OnSceneWasLoaded(int buildIndex, string sceneName)
{
_targets.Clear();
_pending.Clear();
_locks.Clear();
}
public override void OnUpdate()
{
TickIgnores();
HoldTips(Time.deltaTime);
if (_enabled.Value)
{
TrackHands();
_scanTimer -= Time.deltaTime;
if (_scanTimer <= 0f)
{
_scanTimer = 2f;
_targets = TargetScan.Scan();
HookGrabbables();
}
ProcessPending(Time.deltaTime);
}
}
private void ProcessPending(float dt)
{
//IL_011a: Unknown result type (might be due to invalid IL or missing references)
//IL_014f: Unknown result type (might be due to invalid IL or missing references)
//IL_0151: Unknown result type (might be due to invalid IL or missing references)
//IL_0136: Unknown result type (might be due to invalid IL or missing references)
for (int num = _pending.Count - 1; num >= 0; num--)
{
PendingThrow pendingThrow = _pending[num];
pendingThrow.Age += dt;
pendingThrow.Frames++;
if ((Object)(object)pendingThrow.Body == (Object)null)
{
_pending.RemoveAt(num);
}
else if (pendingThrow.Applied)
{
Reassert(pendingThrow);
if (--pendingThrow.Reassert <= 0)
{
_pending.RemoveAt(num);
}
}
else
{
bool flag;
try
{
flag = (Object)(object)pendingThrow.Grabbable != (Object)null && pendingThrow.Grabbable.IsBeingHeld;
}
catch
{
flag = false;
}
if (flag)
{
_pending.RemoveAt(num);
}
else if (pendingThrow.Age > 0.5f)
{
_pending.RemoveAt(num);
}
else if (!pendingThrow.Body.isKinematic && pendingThrow.Frames >= 2)
{
bool flag2;
Vector3 applied;
try
{
flag2 = TryAssist(pendingThrow, out applied);
}
catch (Exception e)
{
LogErrorOnce(e);
flag2 = true;
applied = default(Vector3);
}
if (!flag2)
{
if (!pendingThrow.TipDone)
{
pendingThrow.TipDone = AlignTipFirst(pendingThrow, pendingThrow.Body.velocity);
}
}
else
{
pendingThrow.Applied = true;
pendingThrow.AppliedVelocity = applied;
pendingThrow.Reassert = 3;
}
}
}
}
}
private void Reassert(PendingThrow p)
{
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_0028: Unknown result type (might be due to invalid IL or missing references)
//IL_008c: 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_006e: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)p.Body == (Object)null || p.Body.isKinematic)
{
return;
}
Vector3 velocity;
try
{
velocity = p.Body.velocity;
}
catch
{
return;
}
bool flag = ((Vector3)(ref velocity)).sqrMagnitude < ((Vector3)(ref p.AppliedVelocity)).sqrMagnitude * 0.64f;
if (!flag && ((Vector3)(ref velocity)).sqrMagnitude > 0.01f && ((Vector3)(ref p.AppliedVelocity)).sqrMagnitude > 0.01f)
{
flag = Vector3.Angle(velocity, p.AppliedVelocity) > 12f;
}
if (!flag)
{
return;
}
try
{
p.Body.velocity = p.AppliedVelocity;
}
catch
{
}
}
private void TickIgnores()
{
//IL_0056: Unknown result type (might be due to invalid IL or missing references)
//IL_005b: Unknown result type (might be due to invalid IL or missing references)
//IL_0064: Unknown result type (might be due to invalid IL or missing references)
//IL_0069: Unknown result type (might be due to invalid IL or missing references)
//IL_006d: Unknown result type (might be due to invalid IL or missing references)
for (int num = _ignores.Count - 1; num >= 0; num--)
{
IgnorePair ignorePair = _ignores[num];
ignorePair.Left -= Time.unscaledDeltaTime;
bool flag = true;
try
{
int num2;
if (!((Object)(object)ignorePair.A == (Object)null) && !((Object)(object)ignorePair.B == (Object)null))
{
Bounds bounds = ignorePair.A.bounds;
Bounds bounds2 = ignorePair.B.bounds;
num2 = ((((Bounds)(ref bounds)).SqrDistance(((Bounds)(ref bounds2)).center) > 0.01f) ? 1 : 0);
}
else
{
num2 = 1;
}
flag = (byte)num2 != 0;
}
catch
{
}
if (!(ignorePair.Left > 0f) || flag)
{
try
{
if ((Object)(object)ignorePair.A != (Object)null && (Object)(object)ignorePair.B != (Object)null)
{
Physics.IgnoreCollision(ignorePair.A, ignorePair.B, false);
}
}
catch
{
}
_ignores.RemoveAt(num);
}
}
}
private void TrackHands()
{
//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_0100: Unknown result type (might be due to invalid IL or missing references)
//IL_0102: Unknown result type (might be due to invalid IL or missing references)
//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
float time = Time.time;
List<int> list = null;
foreach (KeyValuePair<int, HVRGrabbable> item in _hooked)
{
HVRGrabbable value = item.Value;
bool flag;
try
{
flag = (Object)(object)value != (Object)null;
}
catch
{
flag = false;
}
if (!flag)
{
(list ?? (list = new List<int>())).Add(item.Key);
continue;
}
bool isBeingHeld;
try
{
isBeingHeld = value.IsBeingHeld;
}
catch
{
continue;
}
if (!isBeingHeld)
{
continue;
}
HVRGrabberBase primaryGrabber;
try
{
primaryGrabber = value.PrimaryGrabber;
}
catch
{
continue;
}
if ((Object)(object)primaryGrabber == (Object)null)
{
continue;
}
Vector3 val = HandPosition(primaryGrabber);
if (_hands.TryGetValue(item.Key, out var value2))
{
float num = time - value2.Time;
if (num > 0.0001f)
{
value2.Velocity = (val - value2.Pos) / num;
}
}
else
{
value2 = new HandSample();
_hands[item.Key] = value2;
}
value2.Pos = val;
value2.Time = time;
}
if (list == null)
{
return;
}
foreach (int item2 in list)
{
_hooked.Remove(item2);
_hands.Remove(item2);
}
}
private void HoldTips(float dt)
{
//IL_0061: Unknown result type (might be due to invalid IL or missing references)
//IL_0066: Unknown result type (might be due to invalid IL or missing references)
//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
//IL_00be: 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_00d2: Unknown result type (might be due to invalid IL or missing references)
//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
//IL_013b: Unknown result type (might be due to invalid IL or missing references)
//IL_013f: Unknown result type (might be due to invalid IL or missing references)
for (int num = _locks.Count - 1; num >= 0; num--)
{
TipLock tipLock = _locks[num];
tipLock.Left -= dt;
if ((Object)(object)tipLock.Body == (Object)null || tipLock.Left <= 0f)
{
_locks.RemoveAt(num);
continue;
}
Vector3 velocity;
bool isKinematic;
try
{
velocity = tipLock.Body.velocity;
isKinematic = tipLock.Body.isKinematic;
}
catch
{
_locks.RemoveAt(num);
continue;
}
if (isKinematic || ((Vector3)(ref velocity)).sqrMagnitude < 4f)
{
_locks.RemoveAt(num);
continue;
}
Vector3 normalized = ((Vector3)(ref velocity)).normalized;
Vector3 val = ((Component)tipLock.Body).transform.TransformDirection(tipLock.LocalDir);
float num2 = Vector3.Angle(val, normalized);
Vector3 val2 = Vector3.Cross(val, normalized);
if (((Vector3)(ref val2)).sqrMagnitude < 1E-06f)
{
try
{
tipLock.Body.angularVelocity = Vector3.Project(tipLock.Body.angularVelocity, normalized);
}
catch
{
}
continue;
}
((Vector3)(ref val2)).Normalize();
float num3 = Mathf.Clamp(num2 * tipLock.Gain * ((float)Math.PI / 180f), 0f - tipLock.MaxRate, tipLock.MaxRate);
try
{
tipLock.Body.angularVelocity = val2 * num3;
}
catch
{
}
}
}
private void HookGrabbables()
{
HVRGrabbable[] array;
try
{
array = Il2CppArrayBase<HVRGrabbable>.op_Implicit(Object.FindObjectsOfType<HVRGrabbable>());
}
catch
{
return;
}
HVRGrabbable[] array2 = array;
foreach (HVRGrabbable val in array2)
{
if ((Object)(object)val == (Object)null)
{
continue;
}
int instanceID = ((Object)val).GetInstanceID();
if (!_hooked.TryGetValue(instanceID, out var value) || !((Object)(object)value != (Object)null))
{
try
{
((UnityEvent<HVRGrabberBase, HVRGrabbable>)(object)val.Released).AddListener(UnityAction<HVRGrabberBase, HVRGrabbable>.op_Implicit(_releasedHandler));
_hooked[instanceID] = val;
}
catch
{
}
}
}
}
private void OnReleased(HVRGrabberBase grabber, HVRGrabbable grabbable)
{
//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_0085: 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_00ff: Unknown result type (might be due to invalid IL or missing references)
//IL_0100: Unknown result type (might be due to invalid IL or missing references)
//IL_0106: Unknown result type (might be due to invalid IL or missing references)
//IL_0107: Unknown result type (might be due to invalid IL or missing references)
//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)grabbable == (Object)null)
{
return;
}
Rigidbody val = null;
try
{
val = grabbable.Rigidbody;
}
catch
{
}
if ((Object)(object)val == (Object)null)
{
try
{
val = ((Component)grabbable).GetComponentInChildren<Rigidbody>();
}
catch
{
return;
}
}
if ((Object)(object)val == (Object)null)
{
return;
}
foreach (PendingThrow item in _pending)
{
if ((Object)(object)item.Body == (Object)(object)val)
{
return;
}
}
Vector3 handPos = HandPosition(grabber);
IgnoreHandCollisions(grabbable, grabber, handPos);
if (_assistRagdolls.Value || !((Object)(object)((Component)val).GetComponentInParent<StickHealth>() != (Object)null))
{
Vector3 handVel = default(Vector3);
float handSpeed = 0f;
int instanceID = ((Object)grabbable).GetInstanceID();
if (_hands.TryGetValue(instanceID, out var value))
{
handVel = value.Velocity;
handSpeed = ((Vector3)(ref handVel)).magnitude;
}
_pending.Add(new PendingThrow
{
Body = val,
Grabbable = grabbable,
Grabber = grabber,
HandPos = handPos,
HandVel = handVel,
HandSpeed = handSpeed
});
}
}
private bool TryAssist(PendingThrow p, out Vector3 applied)
{
//IL_0001: 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_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_0043: Unknown result type (might be due to invalid IL or missing references)
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
//IL_0090: Unknown result type (might be due to invalid IL or missing references)
//IL_0095: Unknown result type (might be due to invalid IL or missing references)
//IL_009c: 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_017e: 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_0107: Unknown result type (might be due to invalid IL or missing references)
//IL_0109: Unknown result type (might be due to invalid IL or missing references)
//IL_010e: Unknown result type (might be due to invalid IL or missing references)
//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
//IL_0208: Unknown result type (might be due to invalid IL or missing references)
//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
//IL_0131: 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_01c8: Unknown result type (might be due to invalid IL or missing references)
//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
//IL_0145: Unknown result type (might be due to invalid IL or missing references)
//IL_0147: Unknown result type (might be due to invalid IL or missing references)
applied = default(Vector3);
Rigidbody body = p.Body;
Vector3 velocity = body.velocity;
float magnitude = ((Vector3)(ref velocity)).magnitude;
Vector3 val = velocity;
if (magnitude < _minThrowSpeed.Value)
{
if (p.HandSpeed < _handThrowSpeed.Value)
{
return false;
}
val = p.HandVel;
}
if (((Vector3)(ref val)).sqrMagnitude < 0.25f)
{
return false;
}
AssistPreset(out var angle, out var strength, out var minSpeed);
bool head = _aimAtHead.Value || Random.value * 100f < _headChance.Value;
Vector3 position = body.position;
ThrowTarget throwTarget = null;
Vector3 val2 = default(Vector3);
float num = angle;
float value = 0f;
foreach (ThrowTarget target in _targets)
{
if ((Object)(object)target.Health == (Object)null || (_ignoreUnconscious.Value && target.Health.isUnconscious) || !AimPoint(target.Health, head, out var aim))
{
continue;
}
Vector3 val3 = aim - position;
float magnitude2 = ((Vector3)(ref val3)).magnitude;
if (!(magnitude2 < 1f) && !(magnitude2 > _maxDistance.Value))
{
float num2 = Vector3.Angle(val, val3);
if (!(num2 >= num))
{
throwTarget = target;
val2 = aim;
num = num2;
value = magnitude2;
}
}
}
if (throwTarget == null)
{
return false;
}
float drag = DragOf(body);
if (!SolveAim(position, val2, minSpeed, drag, out var velocity2, out var flightTime))
{
return false;
}
Rigidbody pelvisRb = throwTarget.Health.pelvisRb;
if ((Object)(object)pelvisRb != (Object)null)
{
Vector3 val4 = pelvisRb.velocity * flightTime;
if (((Vector3)(ref val4)).sqrMagnitude > 0.0001f && !SolveAim(position, val2 + val4, minSpeed, drag, out velocity2, out flightTime))
{
return false;
}
}
applied = Vector3.Lerp(velocity, velocity2, Mathf.Clamp01(strength));
body.velocity = applied;
if (AlignTipFirst(p, applied))
{
p.TipDone = true;
}
if (_log.Value)
{
((MelonBase)this).LoggerInstance.Msg($"[Throw] ур.{_assistLevel.Value} {throwTarget.Name}: d={value:F1} м, угол={num:F1}°, скорость {magnitude:F1} -> {((Vector3)(ref applied)).magnitude:F1} м/с, рука {p.HandSpeed:F1}, timeScale={Time.timeScale:F2}");
}
return true;
}
private void AssistPreset(out float angle, out float strength, out float minSpeed)
{
switch (Mathf.Clamp(_assistLevel.Value, 0, 5))
{
case 1:
angle = 25f;
strength = 0.75f;
minSpeed = 10f;
break;
case 2:
angle = 35f;
strength = 1f;
minSpeed = 13f;
break;
case 3:
angle = 50f;
strength = 1f;
minSpeed = 17f;
break;
case 4:
angle = 70f;
strength = 1f;
minSpeed = 22f;
break;
case 5:
angle = 85f;
strength = 1f;
minSpeed = 27f;
break;
default:
angle = _maxAngle.Value;
strength = _strength.Value;
minSpeed = _minAimSpeed.Value;
break;
}
}
private bool AlignTipFirst(PendingThrow p, Vector3 velocity)
{
//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_0105: 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_014e: 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_0155: Unknown result type (might be due to invalid IL or missing references)
//IL_0160: Unknown result type (might be due to invalid IL or missing references)
//IL_0165: 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_0180: Unknown result type (might be due to invalid IL or missing references)
//IL_0182: Unknown result type (might be due to invalid IL or missing references)
//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
if (!_bladeFirst.Value || (Object)(object)p.Grabbable == (Object)null)
{
return true;
}
try
{
string text = ItemName(p.Grabbable, ((Component)p.Body).transform);
bool flag = text.Contains("combatknife") || (text.Contains("knife") && text.Contains("combat"));
bool flag2 = text.Contains("spear");
if (!flag && !flag2)
{
return true;
}
if (flag && !_knifeAssist.Value)
{
return true;
}
float magnitude;
try
{
Vector3 velocity2 = p.Body.velocity;
magnitude = ((Vector3)(ref velocity2)).magnitude;
}
catch
{
return true;
}
if (((p.HandSpeed > 0.1f) ? p.HandSpeed : magnitude) < _tipMinSpeed.Value)
{
return false;
}
if (((Vector3)(ref velocity)).sqrMagnitude < 0.01f)
{
return false;
}
if (!FindTip(p.Grabbable, p.HandPos, out var tipDir))
{
return true;
}
if (((Vector3)(ref tipDir)).sqrMagnitude < 0.0001f)
{
return true;
}
Vector3 normalized = ((Vector3)(ref velocity)).normalized;
Rigidbody rb = p.Body;
rb.rotation = Quaternion.FromToRotation(((Vector3)(ref tipDir)).normalized, normalized) * rb.rotation;
rb.angularVelocity = Vector3.Project(rb.angularVelocity, normalized);
_locks.RemoveAll((TipLock l) => (Object)(object)l.Body == (Object)(object)rb);
_locks.Add(new TipLock
{
Body = rb,
LocalDir = ((Component)rb).transform.InverseTransformDirection(tipDir),
Left = 2.5f,
Gain = (flag ? 12f : 8f),
MaxRate = (flag ? 30f : 12f)
});
if (_log.Value)
{
((MelonBase)this).LoggerInstance.Msg("[Tip] " + text + ": " + (flag ? "нож" : "копьё"));
}
return true;
}
catch (Exception e)
{
LogErrorOnce(e);
return true;
}
}
private bool FindTip(HVRGrabbable g, Vector3 handPos, out Vector3 tipDir)
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
tipDir = FarthestPoint(CollectColliders(g), handPos) - handPos;
return ((Vector3)(ref tipDir)).sqrMagnitude > 0.0001f;
}
private static string ItemName(HVRGrabbable g, Transform body)
{
string text = Norm(((Object)g).name) + "|" + Norm(((Object)body).name) + "|" + Norm(((Object)body.root).name);
try
{
MeleeWeaponWrapper componentInChildren = ((Component)g).GetComponentInChildren<MeleeWeaponWrapper>();
if ((Object)(object)componentInChildren != (Object)null && (Object)(object)componentInChildren.meleeWeaponSO != (Object)null)
{
text = text + "|" + Norm(((Object)componentInChildren.meleeWeaponSO).name);
}
}
catch
{
}
return text;
}
private static string Norm(string s)
{
if (string.IsNullOrEmpty(s))
{
return "";
}
List<char> list = new List<char>(s.Length);
string text = s.ToLowerInvariant();
foreach (char c in text)
{
if (char.IsLetterOrDigit(c))
{
list.Add(c);
}
}
return new string(list.ToArray());
}
private void IgnoreHandCollisions(HVRGrabbable g, HVRGrabberBase grabber, Vector3 handPos)
{
//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)grabber == (Object)null)
{
return;
}
try
{
Collider[] array = CollectColliders(g);
if (array.Length == 0)
{
return;
}
Transform root = ((Component)grabber).transform.root;
string text = (((Object)(object)root != (Object)null) ? ((Object)root).name : string.Empty);
Collider[] array2 = Il2CppArrayBase<Collider>.op_Implicit(((Component)((text.Contains("Hexa4Rig") || text.Contains("Player")) ? root : ((Component)grabber).transform)).GetComponentsInChildren<Collider>());
Collider[] array3 = array;
foreach (Collider val in array3)
{
if ((Object)(object)val == (Object)null)
{
continue;
}
Collider[] array4 = array2;
foreach (Collider val2 in array4)
{
if (!((Object)(object)val2 == (Object)null) && !((Object)(object)val2 == (Object)(object)val))
{
Bounds bounds = val2.bounds;
if (!(((Bounds)(ref bounds)).SqrDistance(handPos) > 0.04f))
{
Physics.IgnoreCollision(val, val2, true);
_ignores.Add(new IgnorePair
{
A = val,
B = val2,
Left = 0.25f
});
}
}
}
}
}
catch (Exception e)
{
LogErrorOnce(e);
}
}
private static Collider[] CollectColliders(HVRGrabbable g)
{
try
{
List<Collider> colliders = g.Colliders;
if (colliders != null && colliders.Count > 0)
{
Collider[] array = (Collider[])(object)new Collider[colliders.Count];
for (int i = 0; i < array.Length; i++)
{
array[i] = colliders[i];
}
return array;
}
}
catch
{
}
try
{
return Il2CppArrayBase<Collider>.op_Implicit(((Component)g).GetComponentsInChildren<Collider>());
}
catch
{
return (Collider[])(object)new Collider[0];
}
}
private static Vector3 HandPosition(HVRGrabberBase grabber)
{
//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_0009: 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_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_0034: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)grabber == (Object)null)
{
return Vector3.zero;
}
try
{
HVRHandGrabber val = (HVRHandGrabber)(object)((grabber is HVRHandGrabber) ? grabber : null);
if (val != null)
{
return val.HandWorldPosition;
}
}
catch
{
}
try
{
return ((Component)grabber).transform.position;
}
catch
{
return Vector3.zero;
}
}
private static Vector3 FarthestPoint(Collider[] colliders, Vector3 from)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
//IL_002a: Unknown result type (might be due to invalid IL or missing references)
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
//IL_003e: 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_005e: 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_007e: 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_009d: Unknown result type (might be due to invalid IL or missing references)
//IL_009e: Unknown result type (might be due to invalid IL or missing references)
//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
Vector3 result = from;
float num = 0f;
Vector3 val2 = default(Vector3);
foreach (Collider val in colliders)
{
if ((Object)(object)val == (Object)null)
{
continue;
}
Bounds bounds = val.bounds;
for (int j = 0; j < 8; j++)
{
((Vector3)(ref val2))..ctor(((j & 1) == 0) ? ((Bounds)(ref bounds)).min.x : ((Bounds)(ref bounds)).max.x, ((j & 2) == 0) ? ((Bounds)(ref bounds)).min.y : ((Bounds)(ref bounds)).max.y, ((j & 4) == 0) ? ((Bounds)(ref bounds)).min.z : ((Bounds)(ref bounds)).max.z);
Vector3 val3 = val2 - from;
float sqrMagnitude = ((Vector3)(ref val3)).sqrMagnitude;
if (sqrMagnitude > num)
{
num = sqrMagnitude;
result = val2;
}
}
}
return result;
}
private bool SolveAim(Vector3 origin, Vector3 aim, float horizontalSpeed, float drag, out Vector3 velocity, out float flightTime)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_0009: Unknown result type (might be due to invalid IL or missing references)
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: 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_0031: 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_0091: 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_008a: Unknown result type (might be due to invalid IL or missing references)
//IL_0098: Unknown result type (might be due to invalid IL or missing references)
//IL_009c: 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)
//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
velocity = default(Vector3);
Vector3 val = aim - origin;
Vector3 val2 = default(Vector3);
((Vector3)(ref val2))..ctor(val.x, 0f, val.z);
float magnitude = ((Vector3)(ref val2)).magnitude;
if (!Ballistics.SolveStraight(magnitude, val.y, horizontalSpeed, Mathf.Abs(Physics.gravity.y), drag, 3f, _maxSpeed.Value, _arc.Value, out var horizontalSpeed2, out var verticalSpeed, out flightTime))
{
return false;
}
Vector3 val3 = (Vector3)((magnitude > 0.001f) ? (val2 / magnitude) : new Vector3(0f, 0f, 1f));
velocity = val3 * horizontalSpeed2 + Vector3.up * verticalSpeed;
return true;
}
private static float DragOf(Rigidbody rb)
{
try
{
return Mathf.Clamp(rb.drag, 0f, 1.5f);
}
catch
{
return 0f;
}
}
private bool AimPoint(StickHealth h, bool head, out Vector3 aim)
{
//IL_0043: Unknown result type (might be due to invalid IL or missing references)
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
//IL_008a: Unknown result type (might be due to invalid IL or missing references)
//IL_0069: Unknown result type (might be due to invalid IL or missing references)
//IL_006e: Unknown result type (might be due to invalid IL or missing references)
//IL_0078: Unknown result type (might be due to invalid IL or missing references)
//IL_007d: Unknown result type (might be due to invalid IL or missing references)
//IL_0082: Unknown result type (might be due to invalid IL or missing references)
if (head && (Object)(object)h.jawBone != (Object)null)
{
aim = h.jawBone.transform.position;
return true;
}
if ((Object)(object)h.upperChest != (Object)null)
{
aim = h.upperChest.transform.position;
return true;
}
if ((Object)(object)h.pelvisGo != (Object)null)
{
aim = h.pelvisGo.transform.position + Vector3.up * 0.9f;
return true;
}
aim = default(Vector3);
return false;
}
private void LogErrorOnce(Exception e)
{
if (!_errorLogged)
{
_errorLogged = true;
((MelonBase)this).LoggerInstance.Error("BetterThrowing: ошибка при обработке броска (дальше молчу): " + e);
}
}
}
}