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
14 changes: 7 additions & 7 deletions configs/addons/counterstrikesharp/gamedata/gamedata.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@
"signatures": {
"library": "server",
"windows": "44 88 4C 24 ? 53 57",
"linux": "55 48 8D 87 ? ? ? ? 48 89 E5 41 57 41 56 41 89 CE 41 55 45 89 CD"
"linux": "55 48 8D 87 ? ? ? ? 48 89 E5 41 57 41 89 CF"
}
},
"CCSPlayerPawnBase_PostThink": {
"signatures": {
"library": "server",
"windows": "48 ? ? 55 53 56 57 41 ? 48 ? ? ? 48 ? ? ? ? ? ? 4C 89 68",
"linux": "55 48 89 E5 41 56 41 55 41 54 53 48 89 FB 48 83 EC 40 E8 ? ? ? ? F3 0F 10 83"
"linux": "55 48 89 E5 41 57 49 89 FF 41 56 41 55 41 54 53 48 81 EC ? ? ? ? E8 ? ? ? ? 41 80 BF"
}
},
"CGameEventManager_Init": {
Expand Down Expand Up @@ -92,7 +92,7 @@
"signatures": {
"library": "server",
"windows": "48 89 5C 24 ? 57 48 83 EC ? 33 FF 4C 8B CA 8B D9",
"linux": "55 31 D2 48 89 E5 41 56 41 55 41 54"
"linux": "55 31 D2 48 89 E5 41 57 41 56 41 55 41 54 41 89 FC"
}
},
"CCSPlayer_ItemServices_GiveNamedItem": {
Expand Down Expand Up @@ -182,7 +182,7 @@
"LegacyGameEventListener": {
"signatures": {
"library": "server",
"windows": "48 8B 15 ? ? ? ? 48 85 D2 74 ? 83 F9 ? 77 ? 48 63 C1 48 C1 E0",
"windows": "48 8B 15 ? ? ? ? 48 85 D2 74 ? 83 F9 ? 77",
"linux": "48 8B 05 ? ? ? ? 48 85 C0 74 ? 83 FF ? 77 ? 48 63 FF 48 C1 E7 ? 48 8D 44 38"
}
},
Expand All @@ -209,7 +209,7 @@
"signatures": {
"library": "server",
"windows": "40 55 41 54 41 55 41 56 41 57 48 81 EC ? ? ? ? 48 8D 6C 24 ? 48 89 9D ? ? ? ? 45 33 ED",
"linux": "55 48 89 E5 41 57 41 56 49 89 F6 41 55 41 54 49 89 FC 53 48 89 D3 48 83 EC ? 48 85 D2"
"linux": "55 48 89 E5 41 57 41 56 41 55 49 89 FD 41 54 49 89 F4 53 48 89 D3 48 83 EC ? 48 85 D2"
}
},
"CBaseTrigger_StartTouch": {
Expand Down Expand Up @@ -242,7 +242,7 @@
"signatures": {
"library": "server",
"windows": "4C 89 4C 24 ? 48 89 4C 24 ? 53 56",
"linux": "55 48 89 E5 41 57 49 89 FF 41 56 41 55 41 54 49 89 D4 53 48 89 F3"
"linux": "55 48 89 E5 41 57 49 89 FF 41 56 41 55 41 54 49 89 D4 53 48 89 F3 48 83 EC ? 48 8D 05"
}
},
"IGameSystem_InitAllSystems_pFirst": {
Expand Down Expand Up @@ -297,4 +297,4 @@
"linux": "55 48 89 E5 41 57 49 89 F7 41 56 41 55 41 54 4D 89 C4"
}
}
}
}
66 changes: 66 additions & 0 deletions managed/CounterStrikeSharp.Tests.Native/GameTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using System.Linq;
using System.Numerics;
using System.Threading.Tasks;
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Utils;
using Xunit;

namespace NativeTestsPlugin;

public class GameTests
{
private CCSPlayerController player;
private readonly CCSPlayerPawn? pawn;

public GameTests()
{
this.player = Utilities.GetPlayers().First(p => p.LifeState == (byte)LifeState_t.LIFE_ALIVE);
this.pawn = player.PlayerPawn.Value;
}

[Fact]
public async Task Offset_CBasePlayerPawn_CommitSuicide()
{
Assert.Equal((byte)LifeState_t.LIFE_ALIVE, pawn.LifeState);

pawn.CommitSuicide(true, true);
await WaitOneFrame();
Assert.NotEqual((byte)LifeState_t.LIFE_ALIVE, pawn.LifeState);
}

[Fact]
public async Task Offset_CCSPlayer_ItemServices_RemoveWeapons()
{
Assert.True(pawn.WeaponServices.MyWeapons.Any());

player.RemoveWeapons();
await WaitOneFrame();

Assert.False(pawn.WeaponServices.MyWeapons.Any());
}

[Fact]
public async Task Offset_CBaseEntity_Teleport()
{
var originalPosition = pawn.AbsOrigin;
var newPosition = (Vector3)originalPosition + new Vector3(0, 0, 100);

pawn.Teleport(newPosition, null, null);
await WaitOneFrame();

Assert.Equal(newPosition, (Vector3)pawn.AbsOrigin);
}

[Fact]
public async Task Offset_CCSPlayerController_ChangeTeam()
{
var originalTeam = player.Team;
var newTeam = originalTeam == CsTeam.Terrorist ? CsTeam.CounterTerrorist : CsTeam.Terrorist;

player.ChangeTeam(newTeam);
await WaitOneFrame();

Assert.Equal(newTeam, player.Team);
}
}
4 changes: 2 additions & 2 deletions managed/CounterStrikeSharp.Tests.Native/ListenerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public async Task CanRegisterAndDeregisterListeners()
NativeAPI.IssueServerCommand("bot_quota 1");
}

[Fact]
[Fact(Skip = "Damage func broken")]
public async Task TakeDamageListenersAreFired()
{
int preCallCount = 0;
Expand Down Expand Up @@ -80,7 +80,7 @@ public async Task TakeDamageListenersAreFired()
}
}

[Fact]
[Fact(Skip = "Damage func broken")]
public async Task TakeDamageListenerCanBeCancelled()
{
int preCallCount = 0;
Expand Down
3 changes: 2 additions & 1 deletion managed/CounterStrikeSharp.Tests.Native/NativeTestsPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ public override void Load(bool hotReload)
{
gameThreadId = Thread.CurrentThread.ManagedThreadId;
// Loading blocks the game thread, so we use NextFrame to run our tests asynchronously.
Server.NextWorldUpdate(() => RunTests());
// Uncomment to run the tests on load
// Server.NextWorldUpdate(() => RunTests());
AddCommand("css_run_tests", "Runs the xUnit tests for the native plugin.", (player, info) => { RunTests(); });
}

Expand Down
3 changes: 2 additions & 1 deletion tooling/CodeGen.Natives/Scripts/GenerateGameEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ namespace CounterStrikeSharp.API.Core;

foreach (var (gameEvent, definition) in events)
{
File.WriteAllText(Path.Join(outputPath, $"Event{gameEvent.NamePascalCase}.g.cs"), template.Replace("<content>", definition));
File.WriteAllText(Path.Join(outputPath, $"Event{gameEvent.NamePascalCase}.g.cs"),
template.Replace("<content>", definition).ReplaceLineEndings("\r\n"));
}

Console.WriteLine($"Generated C# bindings for {allGameEvents.Count} game events successfully.");
Expand Down
Loading