CS# bug bypass for survival mode
All checks were successful
CI / build (push) Successful in 35s
CI / lint (push) Successful in 32s
CI / release (push) Successful in 5m12s

This commit is contained in:
Kamal Tufekcic 2026-07-10 03:01:19 +03:00
commit 8739fd3ac0
6 changed files with 29 additions and 6 deletions

View file

@ -0,0 +1,23 @@
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);
}
}