mirror of
https://github.com/edgegamers/Jailbreak.git
synced 2025-12-06 04:42:57 -08:00
Add Extensions
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
using System.Drawing;
|
||||
using System.Numerics;
|
||||
using CounterStrikeSharp.API;
|
||||
using CounterStrikeSharp.API.Core;
|
||||
using CounterStrikeSharp.API.Modules.Memory;
|
||||
using CounterStrikeSharp.API.Modules.UserMessages;
|
||||
using CounterStrikeSharp.API.Modules.Utils;
|
||||
using Vector = CounterStrikeSharp.API.Modules.Utils.Vector;
|
||||
|
||||
namespace Jailbreak.Public.Extensions;
|
||||
|
||||
@@ -179,4 +181,22 @@ public static class PlayerExtensions {
|
||||
color.R | color.G << 8 | color.B << 16 | color.A << 24);
|
||||
fadeMsg.Send(player);
|
||||
}
|
||||
|
||||
public static Vector3 GetEyeOrigin(this CCSPlayerPawn pawn) {
|
||||
var origin = pawn.AbsOrigin;
|
||||
if (origin == null) return Vector3.Zero;
|
||||
|
||||
return new Vector3(origin.X, origin.Y,
|
||||
origin.Z + pawn.CameraServices?.OldPlayerViewOffsetZ ?? 0.0f);
|
||||
}
|
||||
|
||||
public static void GetEyeForward(this CCSPlayerPawn pawn, float distance,
|
||||
out Vector3 forward, out Vector3 target) {
|
||||
var angles =
|
||||
new Vector3(pawn.EyeAngles.X, pawn.EyeAngles.Y, pawn.EyeAngles.Z);
|
||||
angles.AngleVectors(out forward, out _, out _);
|
||||
|
||||
var eyeOrigin = pawn.GetEyeOrigin();
|
||||
target = eyeOrigin + forward * distance;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
using CounterStrikeSharp.API.Modules.Utils;
|
||||
using System.Numerics;
|
||||
using CounterStrikeSharp.API.Core;
|
||||
using Vector = CounterStrikeSharp.API.Modules.Utils.Vector;
|
||||
|
||||
namespace Jailbreak.Public.Extensions;
|
||||
|
||||
@@ -50,4 +52,37 @@ public static class VectorExtensions {
|
||||
HorizontalDistanceSquared(this Vector vector, Vector other) {
|
||||
return MathF.Pow(vector.X - other.X, 2) + MathF.Pow(vector.Y - other.Y, 2);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts a CounterStrikeSharp Vector Into a Vector3 Class
|
||||
/// </summary>
|
||||
/// <param name="vector"></param>
|
||||
/// <returns></returns>
|
||||
public static Vector3 Into(this Vector vector) {
|
||||
return new Vector3(vector.X, vector.Y, vector.Z);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts the given angle vector (pitch, yaw, roll) into directional unit vectors:
|
||||
/// forward, right, and up.
|
||||
/// Useful for translating eye angles or view angles into world-space directions.
|
||||
/// Wraps the native `AngleVectors` call from the engine.
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <param name="forward"></param>
|
||||
/// <param name="right"></param>
|
||||
/// <param name="up"></param>
|
||||
public static void AngleVectors(this Vector3 input, out Vector3 forward,
|
||||
out Vector3 right, out Vector3 up) {
|
||||
Vector3 tmpForward, tmpRight, tmpUp;
|
||||
|
||||
unsafe {
|
||||
NativeAPI.AngleVectors((nint)(&input), (nint)(&tmpForward),
|
||||
(nint)(&tmpRight), (nint)(&tmpUp));
|
||||
}
|
||||
|
||||
forward = tmpForward;
|
||||
right = tmpRight;
|
||||
up = tmpUp;
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
Reference in New Issue
Block a user