v1.2.3.b1
Revive skills (Second Chance / Phoenix / Re-Zombie) — unified "on death" logic: - Intercept the lethal hit before it is applied. Previously they reacted after the death was already committed, so one-shots, fall damage and skill-based kills were missed (Phoenix and Re-Zombie were rewritten from a post-death handler to pre-damage interception). Killer Flash: - Kills through real damage instead of forcing a suicide, so revive skills can intercept. Baseball: - Fixed a rare server crash from decoy grenades: a freed decoy's entity index could be reused by another entity and written to (use-after-free). Decoy tracking is now validated per tick (DesignerName gate) and cleared every round. Native crash hardening: - Aimbot: guard the hit-group native pointer before writing (avoids writing to freed/null memory). - Wallhack: detach the glow when the target dies or disconnects (stale FollowEntity on a freed pawn). - Spectator / Cypher / FalconEye / ThirdEye: null-guard the camera SceneNode walk and re-validate the target before teleport/parent (cross-frame freed-entity deref). - CServerSideClient.ForceFullUpdate now bails on a null client handle. Performance: - Added a per-tick player/bomb cache (PlayerManager.GetTickPlayers / GetTickBomb). - Migrated 82 skills from per-skill Utilities.GetPlayers() to the one shared per-tick scan, and the HUD loop reuses it. Much lower per-tick cost at high player counts (verified 10v10). RayTrace: - Prints a single notice when the module is not installed; dependent skills (Long Zeus, Long Knife, Iana, Cypher, Noclip, Shade + the skill-use aim check) no-op instead of failing silently (#43).
This commit is contained in:
parent
c7ee500957
commit
0e86f54e0a
113 changed files with 717 additions and 437 deletions
|
|
@ -100,7 +100,11 @@ namespace jRandomSkills.src.utils
|
|||
set => Field<int>(m_nDeltaTick) = value;
|
||||
}
|
||||
|
||||
public void ForceFullUpdate() => DeltaTick = -1;
|
||||
public void ForceFullUpdate()
|
||||
{
|
||||
if (Handle == nint.Zero) return;
|
||||
DeltaTick = -1;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
|
|||
|
|
@ -91,7 +91,7 @@ namespace src.utils
|
|||
public string DisableHUDOnDeathPermission { get; set; }
|
||||
public bool DisableSkillsOnRoundEnd { get; set; }
|
||||
public LanguageSystem LanguageSystem { get; set; }
|
||||
public HtmlHudCustomisation HtmlHudCustomisation { get; set; }
|
||||
public HtmlHudCustomisation HtmlHudCustomisation { get; set; }
|
||||
public ChatMessage ChatMessage { get; set; }
|
||||
public NormalCommands NormalCommands { get; set; }
|
||||
public VotingCommands VotingCommands { get; set; }
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ using Vector = CounterStrikeSharp.API.Modules.Utils.Vector;
|
|||
|
||||
namespace jRandomSkills.src.utils
|
||||
{
|
||||
public struct CustomTraceResult (TraceResult result, Vector startPos, ulong mask, ulong contents, bool drawBeam)
|
||||
public struct CustomTraceResult(TraceResult result, Vector startPos, ulong mask, ulong contents, bool drawBeam)
|
||||
{
|
||||
public float StartPosX = startPos.X;
|
||||
public float StartPosY = startPos.Y;
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ namespace src.utils
|
|||
LoadAllLanguages();
|
||||
LoadPlayersLanguage();
|
||||
}
|
||||
|
||||
|
||||
private static void SetLangCode()
|
||||
{
|
||||
defaultLangCode = Config.LoadedConfig.LanguageSystem.DefaultLangCode;
|
||||
|
|
@ -82,10 +82,10 @@ namespace src.utils
|
|||
var translation = GetTranslation(skill.ToString().ToLowerInvariant(), langCode);
|
||||
if (!translation.Contains("{0}"))
|
||||
return translation;
|
||||
|
||||
|
||||
if (!translation.Contains(' '))
|
||||
return translation.Replace("{0}", "").Trim();
|
||||
|
||||
|
||||
var parts = translation.Split(' ', StringSplitOptions.RemoveEmptyEntries);
|
||||
var filtered = parts.Where(p => !p.Contains("{0}"));
|
||||
return string.Join(' ', filtered);
|
||||
|
|
@ -279,7 +279,7 @@ namespace src.utils
|
|||
public static void ChangePlayerLanguage(CCSPlayerController? player, string language)
|
||||
{
|
||||
if (player == null || !player.IsValid) return;
|
||||
_playersLanguage.AddOrUpdate(player.SteamID, language, (k,v) => language);
|
||||
_playersLanguage.AddOrUpdate(player.SteamID, language, (k, v) => language);
|
||||
SavePlayersLanguage();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,31 @@ namespace src.utils
|
|||
{
|
||||
private static readonly ConcurrentDictionary<uint, jSkill_PlayerInfo> playersByIndex = [];
|
||||
|
||||
private static int cachedTick = int.MinValue;
|
||||
private static List<CCSPlayerController> cachedControllers = [];
|
||||
private static CC4? cachedBomb;
|
||||
|
||||
private static void EnsureTickCache()
|
||||
{
|
||||
int tick = Server.TickCount;
|
||||
if (tick == cachedTick) return;
|
||||
cachedTick = tick;
|
||||
cachedControllers = Utilities.GetPlayers();
|
||||
cachedBomb = Utilities.FindAllEntitiesByDesignerName<CC4>("weapon_c4").FirstOrDefault();
|
||||
}
|
||||
|
||||
public static List<CCSPlayerController> GetTickPlayers()
|
||||
{
|
||||
EnsureTickCache();
|
||||
return cachedControllers;
|
||||
}
|
||||
|
||||
public static CC4? GetTickBomb()
|
||||
{
|
||||
EnsureTickCache();
|
||||
return cachedBomb != null && cachedBomb.IsValid ? cachedBomb : null;
|
||||
}
|
||||
|
||||
public static void Register(jSkill_PlayerInfo playerInfo)
|
||||
{
|
||||
if (playerInfo == null) return;
|
||||
|
|
@ -37,7 +62,7 @@ namespace src.utils
|
|||
if (!player.ControllingBot)
|
||||
return player;
|
||||
|
||||
return Utilities.GetPlayers().FirstOrDefault(p =>
|
||||
return Utilities.GetPlayers().FirstOrDefault(p =>
|
||||
p != null &&
|
||||
p.IsValid &&
|
||||
p.IsBot &&
|
||||
|
|
|
|||
|
|
@ -15,6 +15,30 @@ namespace src.utils
|
|||
{
|
||||
private static PluginCapability<CRayTraceInterface> RayTraceInterface { get; } = new("raytrace:craytraceinterface");
|
||||
|
||||
private static bool missingModuleLogged;
|
||||
|
||||
private static CRayTraceInterface? GetInterface()
|
||||
{
|
||||
try
|
||||
{
|
||||
var rayTrace = RayTraceInterface.Get();
|
||||
if (rayTrace != null) return rayTrace;
|
||||
}
|
||||
catch { }
|
||||
|
||||
if (!missingModuleLogged)
|
||||
{
|
||||
missingModuleLogged = true;
|
||||
Server.PrintToConsole("[jRandomSkills] RayTrace module not found - skills that need it do nothing: " +
|
||||
"LongZeus, LongKnife, Iana, Cypher, Noclip, Shade (and the skill-use button's aim check). " +
|
||||
"Install RayTrace-CSS-API and RayTrace-MM: https://github.com/FUNPLAY-pro-CS2/Ray-Trace/releases");
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static bool IsAvailable => GetInterface() != null;
|
||||
|
||||
public static CustomTraceResult? TraceShape(CCSPlayerController player, Vector startPos, Vector endPos, ulong? mask = null, ulong? contents = null)
|
||||
{
|
||||
if (player == null || !player.IsValid) return null;
|
||||
|
|
@ -28,10 +52,7 @@ namespace src.utils
|
|||
playerPawn.CBodyComponent?.SceneNode == null)
|
||||
return null;
|
||||
|
||||
CRayTraceInterface? rayTrace;
|
||||
try { rayTrace = RayTraceInterface.Get(); }
|
||||
catch { return null; }
|
||||
|
||||
var rayTrace = GetInterface();
|
||||
if (rayTrace == null)
|
||||
return null;
|
||||
|
||||
|
|
@ -114,10 +135,7 @@ namespace src.utils
|
|||
playerPawn.CBodyComponent?.SceneNode == null)
|
||||
return null;
|
||||
|
||||
CRayTraceInterface? rayTrace;
|
||||
try { rayTrace = RayTraceInterface.Get(); }
|
||||
catch { return null; }
|
||||
|
||||
var rayTrace = GetInterface();
|
||||
if (rayTrace == null)
|
||||
return null;
|
||||
|
||||
|
|
|
|||
|
|
@ -275,6 +275,22 @@ namespace src.utils
|
|||
return null;
|
||||
}
|
||||
|
||||
public static HitGroup_t GetHitGroup(CTakeDamageInfo? info)
|
||||
{
|
||||
if (info == null || info.Handle == nint.Zero) return HitGroup_t.HITGROUP_GENERIC;
|
||||
|
||||
int offset = GameData.GetOffset("CTakeDamageInfo_HitGroup");
|
||||
if (offset <= 0) return HitGroup_t.HITGROUP_GENERIC;
|
||||
|
||||
nint hitGroupPointer = Marshal.ReadIntPtr(info.Handle, offset);
|
||||
if (hitGroupPointer == nint.Zero) return HitGroup_t.HITGROUP_GENERIC;
|
||||
|
||||
nint hitGroupData = Marshal.ReadIntPtr(hitGroupPointer, 16);
|
||||
if (hitGroupData == nint.Zero) return HitGroup_t.HITGROUP_GENERIC;
|
||||
|
||||
return (HitGroup_t)Marshal.ReadInt32(hitGroupData, 56);
|
||||
}
|
||||
|
||||
public static void CreateHEGrenadeProjectile(Vector pos, QAngle angle, Vector vel, int teamNum)
|
||||
{
|
||||
HEGrenadeProjectile_CreateFunc.Value?.Invoke(pos.Handle, angle.Handle, vel.Handle, vel.Handle, IntPtr.Zero, 44, teamNum);
|
||||
|
|
@ -285,15 +301,40 @@ namespace src.utils
|
|||
SmokeGrenadeProjectile_CreateFunc.Value?.Invoke(pos.Handle, angle.Handle, vel.Handle, vel.Handle, IntPtr.Zero, 45, teamNum);
|
||||
}
|
||||
|
||||
// True when this hit would be nullified by the server's friendly-fire rules (same-team hit,
|
||||
// mp_friendlyfire 0 and mp_teammates_are_enemies 0). The TakeDamage pre-hook still sees the raw
|
||||
// damage, so lethal victim-side skills (SecondLife/Phoenix) must skip it — otherwise they "revive"
|
||||
// a teammate that was never going to take damage.
|
||||
public static bool IsFriendlyFireBlocked(CTakeDamageInfo? info, CCSPlayerPawn? victimPawn)
|
||||
{
|
||||
if (info == null || victimPawn == null || !victimPawn.IsValid) return false;
|
||||
|
||||
var attackerEnt = info.Attacker?.Value;
|
||||
if (attackerEnt == null || !attackerEnt.IsValid) return false; // world/no attacker -> real damage
|
||||
if (attackerEnt.Handle == victimPawn.Handle) return false; // self damage applies
|
||||
|
||||
var attackerPawn = new CCSPlayerPawn(attackerEnt.Handle);
|
||||
if (!attackerPawn.IsValid || attackerPawn.DesignerName != "player") return false; // non-player inflictor
|
||||
if (attackerPawn.TeamNum != victimPawn.TeamNum) return false; // enemy -> real damage
|
||||
|
||||
bool ff = ConVar.Find("mp_friendlyfire")?.GetPrimitiveValue<bool>() ?? false;
|
||||
bool tae = ConVar.Find("mp_teammates_are_enemies")?.GetPrimitiveValue<bool>() ?? false;
|
||||
return !ff && !tae; // same team + FF off -> engine will zero this damage
|
||||
}
|
||||
|
||||
public static bool TakeHealth(CCSPlayerPawn? pawn, int damage)
|
||||
{
|
||||
if (pawn == null || !pawn.IsValid || pawn.LifeState != (byte)LifeState_t.LIFE_ALIVE)
|
||||
return false;
|
||||
|
||||
CCSPlayerController? victim = null;
|
||||
jSkill_PlayerInfo? playerInfo = null;
|
||||
|
||||
var player = pawn.Controller.Value;
|
||||
if (player != null && player.IsValid && player.SteamID != 0)
|
||||
if (player != null && player.IsValid)
|
||||
{
|
||||
var playerInfo = PlayerManager.GetPlayerByIndex(player!.Index);
|
||||
victim = player.As<CCSPlayerController>();
|
||||
playerInfo = PlayerManager.GetPlayerByIndex(player!.Index);
|
||||
if (playerInfo == null) return false;
|
||||
|
||||
if (playerInfo.Skill == Skills.Jester && Jester.GetJesterInfo(player.Index)?.Active == true)
|
||||
|
|
@ -301,9 +342,22 @@ namespace src.utils
|
|||
|
||||
if (playerInfo.Skill == Skills.GodMode && GodMode.HaveHodMode(player.Index))
|
||||
return false;
|
||||
|
||||
if (playerInfo.Skill == Skills.Armored)
|
||||
damage = (int)Math.Round(damage * (playerInfo.SkillChance ?? 1f));
|
||||
}
|
||||
|
||||
int newHealth = (int)(pawn.Health - damage);
|
||||
if (newHealth <= 0 && playerInfo != null)
|
||||
{
|
||||
if (playerInfo.Skill == Skills.SecondLife && SecondLife.TryConsumeRevive(victim, pawn))
|
||||
return true;
|
||||
if (playerInfo.Skill == Skills.Phoenix && Phoenix.TryConsumeRevive(victim, pawn))
|
||||
return true;
|
||||
if (playerInfo.Skill == Skills.ReZombie && ReZombie.TryBecomeZombie(victim, pawn))
|
||||
return true;
|
||||
}
|
||||
|
||||
pawn.Health = newHealth;
|
||||
Utilities.SetStateChanged(pawn, "CBaseEntity", "m_iHealth");
|
||||
|
||||
|
|
@ -336,7 +390,7 @@ namespace src.utils
|
|||
public static void ForceFullUpdate(CCSPlayerController player, List<(uint PlayerIndex, QAngle LastAngle)>? batchList = null, INetworkGameServer? networkGameServer = null)
|
||||
{
|
||||
if (!Config.LoadedConfig.EnableFullForceUpdate) return;
|
||||
if (player == null || !player.IsValid) return;
|
||||
if (player == null || !player.IsValid || player.IsBot) return;
|
||||
|
||||
var pawn = player.PlayerPawn?.Value;
|
||||
if (pawn == null || !pawn.IsValid || pawn.AbsOrigin == null) return;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue