Skip to content

Commit 1496557

Browse files
committed
feat(CCSGameRules): TerminateRound
1 parent f80932a commit 1496557

File tree

4 files changed

+56
-3
lines changed

4 files changed

+56
-3
lines changed

managed/src/SwiftlyS2.Core/Modules/Schemas/Extensions/CCSGameRules.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using SwiftlyS2.Shared.SchemaDefinitions;
1+
using SwiftlyS2.Shared.Natives;
2+
using SwiftlyS2.Shared.SchemaDefinitions;
23
using SwiftlyS2.Shared.Schemas;
34

45
namespace SwiftlyS2.Shared.SchemaDefinitions;
@@ -10,5 +11,7 @@ public partial interface CCSGameRules
1011
/// </summary>
1112
/// <typeparam name="T">Entity Class</typeparam>
1213
/// <param name="controller">Player Controller</param>
13-
public T? FindPickerEntity<T>(CBasePlayerController controller) where T: ISchemaClass<T>;
14+
public T? FindPickerEntity<T>( CBasePlayerController controller ) where T : ISchemaClass<T>;
15+
16+
public void TerminateRound( RoundEndReason reason, float delay );
1417
}
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
using SwiftlyS2.Core.Natives;
2+
using SwiftlyS2.Shared.Natives;
23
using SwiftlyS2.Shared.SchemaDefinitions;
34
using SwiftlyS2.Shared.Schemas;
45

56
namespace SwiftlyS2.Core.SchemaDefinitions;
67

78
internal partial class CCSGameRulesImpl : CCSGameRules
89
{
9-
public T? FindPickerEntity<T>(CBasePlayerController controller) where T : ISchemaClass<T>
10+
public T? FindPickerEntity<T>( CBasePlayerController controller ) where T : ISchemaClass<T>
1011
{
1112
CBaseEntity ent = new CBaseEntityImpl(GameFunctions.FindPickerEntity(Address, controller.Address));
1213
return ent.As<T>();
1314
}
15+
16+
public void TerminateRound( RoundEndReason reason, float delay )
17+
{
18+
GameFunctions.TerminateRound(Address, (uint)reason, delay);
19+
}
1420
}

managed/src/SwiftlyS2.Core/Natives/GameFunctions.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ internal static class GameFunctions
1616
public static unsafe delegate* unmanaged< nint, nint, float, void > pSetOrAddAttribute;
1717
public static unsafe delegate* unmanaged< int, nint, nint > pGetWeaponCSDataFromKey;
1818
public static unsafe delegate* unmanaged< nint, uint, nint, byte, CUtlSymbolLarge, byte, int, nint, nint, void > pDispatchParticleEffect;
19+
public static unsafe delegate* unmanaged< nint, uint, float, nint, byte, void > pTerminateRound;
1920
public static int TeleportOffset => NativeOffsets.Fetch("CBaseEntity::Teleport");
2021
public static int CommitSuicideOffset => NativeOffsets.Fetch("CBasePlayerPawn::CommitSuicide");
2122
public static int GetSkeletonInstanceOffset => NativeOffsets.Fetch("CGameSceneNode::GetSkeletonInstance");
@@ -41,6 +42,22 @@ public static void Initialize()
4142
pSetOrAddAttribute = (delegate* unmanaged< nint, IntPtr, float, void >)NativeSignatures.Fetch("CAttributeList::SetOrAddAttributeValueByName");
4243
pGetWeaponCSDataFromKey = (delegate* unmanaged< int, nint, nint >)NativeSignatures.Fetch("GetWeaponCSDataFromKey");
4344
pDispatchParticleEffect = (delegate* unmanaged< nint, uint, nint, byte, CUtlSymbolLarge, byte, int, nint, nint, void >)NativeSignatures.Fetch("DispatchParticleEffect");
45+
pTerminateRound = (delegate* unmanaged< nint, uint, float, nint, byte, void >)NativeSignatures.Fetch("CGameRules::TerminateRound");
46+
}
47+
}
48+
49+
public unsafe static void TerminateRound( nint gameRules, uint reason, float delay )
50+
{
51+
try
52+
{
53+
unsafe
54+
{
55+
pTerminateRound(gameRules, reason, delay, 0, 0);
56+
}
57+
}
58+
catch (Exception e)
59+
{
60+
AnsiConsole.WriteException(e);
4461
}
4562
}
4663

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
namespace SwiftlyS2.Shared.Natives;
2+
3+
public enum RoundEndReason : uint
4+
{
5+
Unknown = 0x0u,
6+
TargetBombed = 0x1u,
7+
TerroristsEscaped = 0x4u,
8+
CTsPreventEscape = 0x5u,
9+
EscapingTerroristsNeutralized = 0x6u,
10+
BombDefused = 0x7u,
11+
CTsWin = 0x8u,
12+
TerroristsWin = 0x9u,
13+
RoundDraw = 0xAu,
14+
AllHostageRescued = 0xBu,
15+
TargetSaved = 0xCu,
16+
HostagesNotRescued = 0xDu,
17+
TerroristsNotEscaped = 0xEu,
18+
GameCommencing = 0x10u,
19+
20+
TerroristsSurrender = 0x11u,
21+
CTsSurrender = 0x12u,
22+
23+
TerroristsPlanted = 0x13u,
24+
CTsReachedHostage = 0x14u,
25+
SurvivalWin = 0x15u,
26+
SurvivalDraw = 0x16u,
27+
}

0 commit comments

Comments
 (0)