23 lines
1.2 KiB
C#
23 lines
1.2 KiB
C#
using System;
|
|
using CounterStrikeSharp.API.Core;
|
|
using CounterStrikeSharp.API.Modules.Memory;
|
|
|
|
namespace Outnumbered.Engine;
|
|
|
|
// Workaround, pending a CounterStrikeSharp release carrying the upstream fix: CSSharp's
|
|
// CCSPlayerController.Respawn() calls SetPawn(PlayerPawn.Value), which faults inside the engine's
|
|
// network-state change code when the pawn is DEAD — the usual respawn case — on the current CS2
|
|
// build (a bot respawned right after we kill it took the crash). This mirrors CSSharp's Respawn()
|
|
// but only re-attaches a LIVE pawn; the CCSPlayerController_Respawn vfunc re-creates the pawn on
|
|
// respawn regardless. Revert every SafeRespawn() call back to .Respawn() once the fixed package ships.
|
|
internal static class RespawnFix
|
|
{
|
|
public static void SafeRespawn(this CCSPlayerController controller)
|
|
{
|
|
if (controller is not { IsValid: true }) return;
|
|
var pawn = controller.PlayerPawn.Value;
|
|
if (pawn == null) return;
|
|
if (pawn is { IsValid: true, Health: > 0 }) controller.SetPawn(pawn);
|
|
VirtualFunction.CreateVoid<IntPtr>(controller.Handle, GameData.GetOffset("CCSPlayerController_Respawn"))(controller.Handle);
|
|
}
|
|
}
|