Skip to content

Commit

Permalink
Add methods to respawn players (#114)
Browse files Browse the repository at this point in the history
  • Loading branch information
KillStr3aK authored Nov 24, 2023
1 parent 123f419 commit ea35964
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 0 deletions.
13 changes: 13 additions & 0 deletions configs/addons/counterstrikesharp/gamedata/gamedata.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,19 @@
"linux": 89
}
},
"CCSPlayerController_Respawn": {
"offsets": {
"windows": 241,
"linux": 243
}
},
"CCSPlayerPawn_Respawn": {
"signatures": {
"library": "server",
"windows": "\\x40\\x53\\x48\\x83\\xEC\\x20\\x8B\\x91\\x38\\x0B\\x00\\x00\\x48\\x8B\\xD9",
"linux": "\\x8B\\x8F\\x40\\x0E\\x00\\x00\\x83\\xF9\\xFF\\x0F\\x84\\xD9\\x01"
}
},
"GiveNamedItem": {
"signatures": {
"library": "server",
Expand Down
5 changes: 5 additions & 0 deletions managed/CounterStrikeSharp.API/Core/Model/CBasePlayerPawn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ namespace CounterStrikeSharp.API.Core;

public partial class CBasePlayerPawn
{
/// <summary>
/// Force player suicide
/// </summary>
/// <param name="explode"></param>
/// <param name="force"></param>
public void CommitSuicide(bool explode, bool force)
{
VirtualFunction.CreateVoid<IntPtr, bool, bool>(Handle, GameData.GetOffset("CBasePlayerPawn_CommitSuicide"))(Handle, explode, force);
Expand Down
25 changes: 25 additions & 0 deletions managed/CounterStrikeSharp.API/Core/Model/CCSPlayerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,31 @@ public void RemoveWeapons()
itemServices.RemoveWeapons();
}

/// <summary>
/// Force player suicide
/// </summary>
/// <param name="explode"></param>
/// <param name="force"></param>
public void CommitSuicide(bool explode, bool force)
{
if (!PlayerPawn.IsValid) return;
if (!PlayerPawn.Value.IsValid) return;

PlayerPawn.Value.CommitSuicide(explode, force);
}

/// <summary>
/// Respawn player
/// </summary>
public void Respawn()
{
if (!PlayerPawn.IsValid) return;
if (!PlayerPawn.Value.IsValid) return;

VirtualFunctions.CCSPlayerPawn_Respawn(PlayerPawn.Value.Handle);
VirtualFunction.CreateVoid<IntPtr>(Handle, GameData.GetOffset("CCSPlayerController_Respawn"))(Handle);
}

public bool IsBot => ((PlayerFlags)Flags).HasFlag(PlayerFlags.FL_FAKECLIENT);

/// <summary>
Expand Down
19 changes: 19 additions & 0 deletions managed/CounterStrikeSharp.API/Core/Model/CCSPlayerPawn.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using CounterStrikeSharp.API.Modules.Memory;

namespace CounterStrikeSharp.API.Core;

public partial class CCSPlayerPawn
{
/// <summary>
/// Respawn player
/// </summary>
public void Respawn()
{
if (!Controller.IsValid) return;
if (!Controller.Value.IsValid) return;

VirtualFunctions.CCSPlayerPawn_Respawn(Handle);
VirtualFunction.CreateVoid<IntPtr>(Controller.Value.Handle, GameData.GetOffset("CCSPlayerController_Respawn"))(Controller.Value.Handle);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using System.Reflection.Metadata;

using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Entities.Constants;
using CounterStrikeSharp.API.Modules.Utils;
Expand Down Expand Up @@ -34,4 +36,6 @@ public static class VirtualFunctions
public static Func<string, int, IntPtr> UTIL_CreateEntityByName = VirtualFunction.Create<string, int, IntPtr>(GameData.GetSignature("UTIL_CreateEntityByName"));

public static Action<IntPtr, IntPtr> CBaseEntity_DispatchSpawn = VirtualFunction.CreateVoid<IntPtr, IntPtr>(GameData.GetSignature("CBaseEntity_DispatchSpawn"));

public static Action<IntPtr> CCSPlayerPawn_Respawn = VirtualFunction.CreateVoid<IntPtr>(GameData.GetSignature("CCSPlayerPawn_Respawn"));
}

0 comments on commit ea35964

Please sign in to comment.