diff --git a/CS2-SimpleAdminApi/CS2-SimpleAdminApi.csproj b/CS2-SimpleAdminApi/CS2-SimpleAdminApi.csproj new file mode 100644 index 0000000..1491c0d --- /dev/null +++ b/CS2-SimpleAdminApi/CS2-SimpleAdminApi.csproj @@ -0,0 +1,15 @@ + + + + net8.0 + CS2_SimpleAdminApi + enable + enable + true + + + + + + + diff --git a/CS2-SimpleAdminApi/ICS2-SimpleAdminApi.cs b/CS2-SimpleAdminApi/ICS2-SimpleAdminApi.cs new file mode 100644 index 0000000..ec2962e --- /dev/null +++ b/CS2-SimpleAdminApi/ICS2-SimpleAdminApi.cs @@ -0,0 +1,31 @@ +using CounterStrikeSharp.API.Core; +using CounterStrikeSharp.API.Core.Capabilities; +using CounterStrikeSharp.API.Modules.Commands; +using CounterStrikeSharp.API.Modules.Entities; + +namespace CS2_SimpleAdminApi; + +public interface ICS2_SimpleAdminApi +{ + public static readonly PluginCapability PluginCapability = new("simpleadmin:api"); + + public PlayerInfo GetPlayerInfo(CCSPlayerController player); + + public string GetConnectionString(); + public string GetServerAddress(); + public int? GetServerId(); + + public Dictionary> GetPlayerMuteStatus(CCSPlayerController player); + + public event Action? OnPlayerPenaltied; + public event Action? OnPlayerPenaltiedAdded; + public event Action? OnAdminShowActivity; + + public void IssuePenalty(CCSPlayerController player, CCSPlayerController? admin, PenaltyType penaltyType, string reason, int duration = -1); + public void IssuePenalty(SteamID steamid, CCSPlayerController? admin, PenaltyType penaltyType, string reason, int duration = -1); + public void LogCommand(CCSPlayerController? caller, string command); + public void LogCommand(CCSPlayerController? caller, CommandInfo command); + public void ShowAdminActivity(string messageKey, string? callerName = null, bool dontPublish = false, params object[] messageArgs); + + public bool IsAdminSilent(CCSPlayerController player); +} \ No newline at end of file diff --git a/CS2-SimpleAdminApi/PenaltyType.cs b/CS2-SimpleAdminApi/PenaltyType.cs new file mode 100644 index 0000000..4cce6b8 --- /dev/null +++ b/CS2-SimpleAdminApi/PenaltyType.cs @@ -0,0 +1,11 @@ +namespace CS2_SimpleAdminApi; + +public enum PenaltyType +{ + Ban = 0, + Kick, + Mute, + Gag, + Silence, + Warn +} diff --git a/CS2-SimpleAdminApi/PlayerInfo.cs b/CS2-SimpleAdminApi/PlayerInfo.cs new file mode 100644 index 0000000..e9c6fb3 --- /dev/null +++ b/CS2-SimpleAdminApi/PlayerInfo.cs @@ -0,0 +1,38 @@ +using CounterStrikeSharp.API.Modules.Entities; + +namespace CS2_SimpleAdminApi; + +public class PlayerInfo( + int? userId, + int slot, + SteamID steamId, + string name, + string? ipAddress, + int totalBans = 0, + int totalMutes = 0, + int totalGags = 0, + int totalSilences = 0, + int totalWarns = 0) +{ + public int? UserId { get; } = userId; + public int Slot { get; } = slot; + public SteamID SteamId { get; } = steamId; + public string Name { get; } = name; + public string? IpAddress { get; } = ipAddress; + public int TotalBans { get; set; } = totalBans; + public int TotalMutes { get; set; } = totalMutes; + public int TotalGags { get; set; } = totalGags; + public int TotalSilences { get; set; } = totalSilences; + public int TotalWarns { get; set; } = totalWarns; + public bool WaitingForKick { get; set; } = false; + public List<(ulong SteamId, string PlayerName)> AccountsAssociated { get; set; } = []; + public DiePosition? DiePosition { get; set; } +} + +public class DiePosition(Vector_t position, QAngle_t angle) +{ + public Vector_t Position { get; } = position; + public QAngle_t Angle { get; } = angle; +} + + diff --git a/CS2-SimpleAdminApi/QAngle_t.cs b/CS2-SimpleAdminApi/QAngle_t.cs new file mode 100644 index 0000000..4245728 --- /dev/null +++ b/CS2-SimpleAdminApi/QAngle_t.cs @@ -0,0 +1,123 @@ +using CounterStrikeSharp.API.Core; +using System.Numerics; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +namespace CS2_SimpleAdminApi; + +public struct QAngle_t : IAdditionOperators, + ISubtractionOperators, + IMultiplyOperators, + IDivisionOperators +{ + public float X, Y, Z; + + public const int SIZE = 3; + + public unsafe float this[int i] + { + readonly get + { + if (i < 0 || i > SIZE) + { + throw new IndexOutOfRangeException(); + } + + fixed (void* ptr = &this) + { + return Unsafe.Read(Unsafe.Add(ptr, i)); + } + } + set + { + if (i < 0 || i > SIZE) + { + throw new IndexOutOfRangeException(); + } + + fixed (void* ptr = &this) + { + Unsafe.Write(Unsafe.Add(ptr, i), value); + } + } + } + + public QAngle_t() + { + } + + public unsafe QAngle_t(nint ptr) : this(MemoryMarshal.CreateReadOnlySpan(ref Unsafe.AsRef((void*)ptr), SIZE)) + { + } + + public QAngle_t(float x, float y, float z) + { + X = x; + Y = y; + Z = z; + } + + public QAngle_t(ReadOnlySpan values) + { + if (values.Length < SIZE) + { + throw new ArgumentOutOfRangeException(nameof(values)); + } + + this = Unsafe.ReadUnaligned(ref Unsafe.As(ref MemoryMarshal.GetReference(values))); + } + + public unsafe (Vector_t fwd, Vector_t right, Vector_t up) AngleVectors() + { + Vector_t fwd = default, right = default, up = default; + + nint pFwd = (nint)Unsafe.AsPointer(ref fwd); + nint pRight = (nint)Unsafe.AsPointer(ref right); + nint pUp = (nint)Unsafe.AsPointer(ref up); + + fixed (void* ptr = &this) + { + NativeAPI.AngleVectors((nint)ptr, pFwd, pRight, pUp); + } + + return ( fwd, right, up ); + } + + public unsafe void AngleVectors(out Vector_t fwd, out Vector_t right, out Vector_t up) + { + fixed (void* ptr = &this, pFwd = &fwd, pRight = &right, pUp = &up) + { + NativeAPI.AngleVectors((nint)ptr, (nint)pFwd, (nint)pRight, (nint)pUp); + } + } + + public readonly override string ToString() + { + return $"{X:n2} {Y:n2} {Z:n2}"; + } + + public static QAngle_t operator +(QAngle_t a, QAngle_t b) + { + return new QAngle_t(a.X + b.X, a.Y + b.Y, a.Z + b.Z); + } + + public static QAngle_t operator -(QAngle_t a, QAngle_t b) + { + return new QAngle_t(a.X - b.X, a.Y - b.Y, a.Z - b.Z); + } + + public static QAngle_t operator -(QAngle_t a) + { + return new QAngle_t(-a.X, -a.Y, -a.Z); + } + + public static QAngle_t operator *(QAngle_t a, float b) + { + return new QAngle_t(a.X * b, a.Y * b, a.Z * b); + } + + public static QAngle_t operator /(QAngle_t a, float b) + { + return new QAngle_t(a.X / b, a.Y / b, a.Z / b); + } +} \ No newline at end of file diff --git a/CS2-SimpleAdminApi/Vector_t.cs b/CS2-SimpleAdminApi/Vector_t.cs new file mode 100644 index 0000000..e01c214 --- /dev/null +++ b/CS2-SimpleAdminApi/Vector_t.cs @@ -0,0 +1,105 @@ +using System.Numerics; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +namespace CS2_SimpleAdminApi; + +public struct Vector_t : IAdditionOperators, + ISubtractionOperators, + IMultiplyOperators, + IDivisionOperators +{ + public float X, Y, Z; + + public const int SIZE = 3; + + public unsafe float this[int i] + { + readonly get + { + if (i < 0 || i > SIZE) + { + throw new IndexOutOfRangeException(); + } + + fixed (void* ptr = &this) + { + return Unsafe.Read(Unsafe.Add(ptr, i)); + } + } + set + { + if (i < 0 || i > SIZE) + { + throw new IndexOutOfRangeException(); + } + + fixed (void* ptr = &this) + { + Unsafe.Write(Unsafe.Add(ptr, i), value); + } + } + } + + public Vector_t() + { + } + + public unsafe Vector_t(nint ptr) : this(MemoryMarshal.CreateReadOnlySpan(ref Unsafe.AsRef((void*)ptr), SIZE)) + { + } + + public Vector_t(float x, float y, float z) + { + X = x; + Y = y; + Z = z; + } + + public Vector_t(ReadOnlySpan values) + { + if (values.Length < SIZE) + { + throw new ArgumentOutOfRangeException(nameof(values)); + } + + this = Unsafe.ReadUnaligned(ref Unsafe.As(ref MemoryMarshal.GetReference(values))); + } + + public void Scale(float scale) + { + X *= scale; + Y *= scale; + Z *= scale; + } + + public readonly override string ToString() + { + return $"{X:n2} {Y:n2} {Z:n2}"; + } + + public static Vector_t operator +(Vector_t a, Vector_t b) + { + return new Vector_t(a.X + b.X, a.Y + b.Y, a.Z + b.Z); + } + + public static Vector_t operator -(Vector_t a, Vector_t b) + { + return new Vector_t(a.X - b.X, a.Y - b.Y, a.Z - b.Z); + } + + public static Vector_t operator -(Vector_t a) + { + return new Vector_t(-a.X, -a.Y, -a.Z); + } + + public static Vector_t operator *(Vector_t a, float b) + { + return new Vector_t(a.X * b, a.Y * b, a.Z * b); + } + + public static Vector_t operator /(Vector_t a, float b) + { + return new Vector_t(a.X / b, a.Y / b, a.Z / b); + } +} \ No newline at end of file