Add Extensions

This commit is contained in:
ShookEagle
2025-07-25 10:41:17 -05:00
parent c9083a3630
commit f010bce92c
3 changed files with 57 additions and 1 deletions

View File

@@ -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;
}
}

View File

@@ -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;
}
}

View File

@@ -4,6 +4,7 @@
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>