Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions managed/src/SwiftlyS2.Shared/Misc/BitFieldHelper.cs
Original file line number Diff line number Diff line change
@@ -1,55 +1,55 @@
namespace SwiftlyS2.Shared.Misc;
namespace SwiftlyS2.Shared.Misc;

static class BitFieldHelper
internal static class BitFieldHelper
{
public static int GetBits(ref byte data, int index, int bitCount)
public static int GetBits( ref byte data, int index, int bitCount )
{
if (index < 0 || index + bitCount > 8) throw new ArgumentOutOfRangeException();
int mask = (1 << bitCount) - 1;
var mask = (1 << bitCount) - 1;
return (data >> index) & mask;
}

public static void SetBits(ref byte data, int index, int bitCount, int value)
public static void SetBits( ref byte data, int index, int bitCount, int value )
{
if (index < 0 || index + bitCount > 8) throw new ArgumentOutOfRangeException();
int mask = ((1 << bitCount) - 1) << index;
var mask = ((1 << bitCount) - 1) << index;
data = (byte)((data & ~mask) | ((value << index) & mask));
}

public static int GetBits(ref int data, int index, int bitCount)
public static int GetBits( ref int data, int index, int bitCount )
{
if (index < 0 || index + bitCount > 32) throw new ArgumentOutOfRangeException();
int mask = (1 << bitCount) - 1;
var mask = (1 << bitCount) - 1;
return (data >> index) & mask;
}

public static void SetBits(ref int data, int index, int bitCount, int value)
public static void SetBits( ref int data, int index, int bitCount, int value )
{
if (index < 0 || index + bitCount > 32) throw new ArgumentOutOfRangeException();
int mask = ((1 << bitCount) - 1) << index;
var mask = ((1 << bitCount) - 1) << index;
data = (data & ~mask) | ((value << index) & mask);
}

public static long GetBits(ref long data, int index, int bitCount)
public static long GetBits( ref long data, int index, int bitCount )
{
if (index < 0 || index + bitCount > 64) throw new ArgumentOutOfRangeException();
long mask = (1L << bitCount) - 1;
var mask = (1L << bitCount) - 1;
return (data >> index) & mask;
}

public static void SetBits(ref long data, int index, int bitCount, long value)
public static void SetBits( ref long data, int index, int bitCount, long value )
{
if (index < 0 || index + bitCount > 64) throw new ArgumentOutOfRangeException();
long mask = ((1L << bitCount) - 1) << index;
var mask = ((1L << bitCount) - 1) << index;
data = (data & ~mask) | ((value << index) & mask);
}

public static bool GetBit(ref byte data, int index) => GetBits(ref data, index, 1) != 0;
public static void SetBit(ref byte data, int index, bool value) => SetBits(ref data, index, 1, value ? 1 : 0);
public static bool GetBit( ref byte data, int index ) => GetBits(ref data, index, 1) != 0;
public static void SetBit( ref byte data, int index, bool value ) => SetBits(ref data, index, 1, value ? 1 : 0);

public static bool GetBit(ref int data, int index) => GetBits(ref data, index, 1) != 0;
public static void SetBit(ref int data, int index, bool value) => SetBits(ref data, index, 1, value ? 1 : 0);
public static bool GetBit( ref int data, int index ) => GetBits(ref data, index, 1) != 0;
public static void SetBit( ref int data, int index, bool value ) => SetBits(ref data, index, 1, value ? 1 : 0);

public static bool GetBit(ref long data, int index) => GetBits(ref data, index, 1) != 0;
public static void SetBit(ref long data, int index, bool value) => SetBits(ref data, index, 1, value ? 1 : 0);
public static bool GetBit( ref long data, int index ) => GetBits(ref data, index, 1) != 0;
public static void SetBit( ref long data, int index, bool value ) => SetBits(ref data, index, 1, value ? 1 : 0);
}
36 changes: 36 additions & 0 deletions managed/src/SwiftlyS2.Shared/Natives/Structs/CMoveData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Reference: https://github.com/KZGlobalTeam/cs2kz-metamod/blob/8d4038394173f1c10d763346d45cd3ccbc0091aa/src/sdk/datatypes.h#L252-L278

using System.Runtime.InteropServices;

namespace SwiftlyS2.Shared.Natives;

[StructLayout(LayoutKind.Sequential)]
public unsafe struct CMoveData
{
public CMoveDataBase Base; // class CMoveData : public CMoveDataBase

public Vector OutWishVel;
public QAngle OldAngles;

/// <summary>
/// World space input vector. Used to compare against the movement services' previous rotation for ground movement stuff.
/// </summary>
public Vector InputRotated;

/// <summary>
/// Continuous acceleration in units per second squared (u/s²).
/// </summary>
public Vector ContinuousAcceleration;

/// <summary>
/// Immediate delta in u/s. Air acceleration bypasses per second acceleration,
/// applies up to half of its impulse to the velocity and the rest goes straight into this.
/// </summary>
public Vector FrameVelocityDelta;

public float MaxSpeed;
public float ClientMaxSpeed;
public float FrictionDecel;
public bool InAir;
public bool GameCodeMovedPlayer; // true if usercmd cmd number == (m_nGameCodeHasMovedPlayerAfterCommand + 1)
}
46 changes: 46 additions & 0 deletions managed/src/SwiftlyS2.Shared/Natives/Structs/CMoveDataBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Reference: https://github.com/KZGlobalTeam/cs2kz-metamod/blob/8d4038394173f1c10d763346d45cd3ccbc0091aa/src/sdk/datatypes.h#L165-L250

using System.Runtime.InteropServices;
using SwiftlyS2.Shared.Misc;
using SwiftlyS2.Shared.SchemaDefinitions;

namespace SwiftlyS2.Shared.Natives;

[StructLayout(LayoutKind.Sequential)]
public unsafe struct CMoveDataBase
{
private byte _bitfield0; // Bitfield members

public bool HasZeroFrametime {
get => BitFieldHelper.GetBit(ref _bitfield0, 0);
set => BitFieldHelper.SetBit(ref _bitfield0, 0, value);
}

public bool IsLateCommand {
get => BitFieldHelper.GetBit(ref _bitfield0, 1);
set => BitFieldHelper.SetBit(ref _bitfield0, 1, value);
}

public CHandle<CCSPlayerPawn> PlayerHandle;
public QAngle AbsViewAngles;
public QAngle ViewAngles;
public Vector LastMovementImpulses;
public float ForwardMove;
public float SideMove; // Warning! Flipped compared to CS:GO, moving right gives negative value
public float UpMove;
public Vector Velocity;
public QAngle Angles;
public Vector Unknown; // Unused. Probably pulled from engine upstream.
public CUtlVector<SubtickMove> SubtickMoves;
public CUtlVector<SubtickMove> AttackSubtickMoves;
public bool HasSubtickInputs;
public float UnknownFloat; // Set to 1.0 during SetupMove, never change during gameplay. Is apparently used for weapon services stuff.
public CUtlVector<TouchListT> TouchList;
public Vector CollisionNormal;
public Vector GroundNormal;
public Vector AbsOrigin;
public int TickCount;
public int TargetTick;
public float SubtickStartFraction;
public float SubtickEndFraction;
}
39 changes: 39 additions & 0 deletions managed/src/SwiftlyS2.Shared/Natives/Structs/SubtickMove.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Reference: https://github.com/KZGlobalTeam/cs2kz-metamod/blob/8d4038394173f1c10d763346d45cd3ccbc0091aa/src/sdk/datatypes.h#L141-L163

using System.Runtime.InteropServices;

namespace SwiftlyS2.Shared.Natives;

[StructLayout(LayoutKind.Explicit, Size = 0x20, Pack = 1)]
public struct SubtickMove
{
[FieldOffset(0x00)]
public float When;

[FieldOffset(0x04)]
private readonly int Padding0;

[FieldOffset(0x08)]
public ulong Button;

// Union: pressed (bool) or analogMove struct
[FieldOffset(0x10)]
public bool Pressed;

[FieldOffset(0x10)]
public float AnalogForwardDelta;

[FieldOffset(0x14)]
public float AnalogLeftDelta;

[FieldOffset(0x18)]
public float PitchDelta;

[FieldOffset(0x1C)]
public float YawDelta;

public readonly bool IsAnalogInput()
{
return Button == 0;
}
}
12 changes: 12 additions & 0 deletions managed/src/SwiftlyS2.Shared/Natives/Structs/TouchListT.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Reference: https://github.com/KZGlobalTeam/cs2kz-metamod/blob/8d4038394173f1c10d763346d45cd3ccbc0091aa/src/sdk/datatypes.h#L135-L139

using System.Runtime.InteropServices;

namespace SwiftlyS2.Shared.Natives;

[StructLayout(LayoutKind.Sequential)]
public struct TouchListT
{
public Vector DeltaVelocity;
public CGameTrace Trace;
}
18 changes: 18 additions & 0 deletions managed/src/TestPlugin/TestPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -637,13 +637,31 @@ public void GetIpCommand( ICommandContext context )

// Core.Menus.OpenMenu(player, settingsMenu);
// }

[Command("ed")]
public void EndRoundCommand( ICommandContext _ )
{
var gameRules = Core.EntitySystem.GetGameRules()!;
gameRules.TerminateRound(RoundEndReason.CTsWin, 10.0f);
}

[Command("sizecheck")]
public void SizeCheckCommand( ICommandContext _ )
{
unsafe
{
var moveDataSize = sizeof(CMoveData);
var moveDataBaseSize = sizeof(CMoveDataBase);
var subtickMoveSize = sizeof(SubtickMove);
var touchListSize = sizeof(TouchListT);

Console.WriteLine($"CMoveData size: {moveDataSize} bytes");
Console.WriteLine($"CMoveDataBase size: {moveDataBaseSize} bytes");
Console.WriteLine($"SubtickMove size: {subtickMoveSize} bytes");
Console.WriteLine($"TouchListT size: {touchListSize} bytes");
}
}

[Command("tm")]
public void TestMenuCommand( ICommandContext context )
{
Expand Down
Loading