General: - Jester's no-damage state no longer applies to players who do not hold the skill. The shared health helper checked Jester's internal table without verifying the current assignment, so a single stale entry silently cancelled damage across every skill that deals damage through it. - Jester's per-round reset no longer aborts when the holder is dead, which previously left the table populated for the following rounds. - The per-round reset now covers every skill used on the current map instead of only the ones held in the round that just ended, so a skill nobody drew still clears state left over from an earlier round. - Skills that track another player as a target are now notified when that player disconnects. Controller indexes are reused, so a leftover entry applied to whoever connected into that index next. Affects Poison, Deaf, Darkness, Glitch, Magnifier, Legless, No Rifles, Jammer and Jester. - Aimbot no longer retains raw native pointers after a hit is handled. They were never cleared and were written back to later, which could corrupt memory the engine had already freed. - An exception inside a skill's OnTick no longer cancels the tick of every skill after it in the same frame. - Cooldowns configured low enough to truncate to zero no longer throw (Poison, Regeneration, Hot Bomb, Healing Smoke, Toxic Smoke). - Round changes are cheaper: Long Knife no longer detaches a detour it never attached, and Wild Throw skips its player sweep when it has nothing to unwind. Skill improvements: - Second Chance: now survives several lethal hits landing in the same tick (shotgun, two attackers) and restores health inside the damage hook instead of a frame later. It also runs after skills that modify damage, so One-Shot and Soldier are seen at their final value instead of the raw one. - Spectator: returning to your own view no longer leaves the camera handle set, which made the tick handler reset the weapon cooldown every frame and play as rapid fire. The manual toggle is unchanged. - Radar Hack: players hidden behind a replacement model (Chicken) are shown on the radar again. Only Ghost, Ninja and C4 Camouflage hide the pawn itself, so render alpha alone no longer decides. - Focus: weapon_accuracy_nospread is reference counted, so one holder losing the skill no longer removes the effect from the others still holding it. - Friendly Fire: mp_autokick is restored at the end of the round instead of staying disabled for the rest of the map, and is no longer executed on every friendly hit. - Reactive Armor / Iana: no longer restore health for a player who no longer holds the skill. - Free Planter / Short Fuse: each restores mp_c4timer only when it actually changed it, so overlapping rounds cannot write back the wrong value. - Illusionist: the replica movement timer now stops on map change. - Ghost / Ninja / C4 Camouflage: the bomb is located once per transmit instead of once per receiver and hidden player, and the pass is skipped when nobody is hidden.
219 lines
No EOL
9.7 KiB
C#
219 lines
No EOL
9.7 KiB
C#
using CounterStrikeSharp.API;
|
|
using CounterStrikeSharp.API.Core;
|
|
using CounterStrikeSharp.API.Modules.Memory.DynamicFunctions;
|
|
using CounterStrikeSharp.API.Modules.Utils;
|
|
using static src.jRandomSkills;
|
|
using System.Collections.Concurrent;
|
|
using src.utils;
|
|
using CounterStrikeSharp.API.Modules.Timers;
|
|
using Timer = CounterStrikeSharp.API.Modules.Timers.Timer;
|
|
|
|
namespace src.player.skills
|
|
{
|
|
public class Illusionist : ISkill
|
|
{
|
|
private const Skills skillName = Skills.Illusionist;
|
|
private static readonly ConcurrentDictionary<uint, PlayerSkillInfo> SkillPlayerInfo = [];
|
|
private static readonly ConcurrentDictionary<int, Timer> ActiveTimers = [];
|
|
private static readonly object setLock = new();
|
|
|
|
public static void LoadSkill()
|
|
{
|
|
SkillUtils.RegisterSkill(skillName, SkillsInfo.GetValue<string>(skillName, "color"));
|
|
}
|
|
|
|
public static void NewRound()
|
|
{
|
|
ClearAllReplicas();
|
|
lock (setLock)
|
|
SkillPlayerInfo.Clear();
|
|
}
|
|
|
|
private static void ClearAllReplicas()
|
|
{
|
|
foreach (var timer in ActiveTimers.Values) timer?.Kill();
|
|
ActiveTimers.Clear();
|
|
|
|
var entities = Utilities.FindAllEntitiesByDesignerName<CDynamicProp>("prop_dynamic_override");
|
|
foreach (var entity in entities)
|
|
if (entity != null && entity.IsValid && entity.Entity != null && !string.IsNullOrEmpty(entity.Entity.Name) && (entity.Entity.Name?.StartsWith("Illusionist_") ?? false))
|
|
EntityManager.DestroyEntity(entity.Index);
|
|
}
|
|
|
|
public static void OnTick()
|
|
{
|
|
foreach (var player in Utilities.GetPlayers())
|
|
{
|
|
if (player == null || !player.IsValid ) continue;
|
|
|
|
var playerInfo = PlayerManager.GetPlayerByIndex(player!.Index);
|
|
if (playerInfo?.Skill == skillName)
|
|
if (SkillPlayerInfo.TryGetValue(player.Index, out var skillInfo))
|
|
UpdateHUD(player, skillInfo);
|
|
}
|
|
}
|
|
|
|
public static void EnableSkill(CCSPlayerController player)
|
|
{
|
|
SkillPlayerInfo.TryAdd(player.Index, new PlayerSkillInfo
|
|
{
|
|
SteamID = player.Index,
|
|
CanUse = true,
|
|
Cooldown = DateTime.MinValue,
|
|
});
|
|
}
|
|
|
|
public static void DisableSkill(CCSPlayerController player)
|
|
{
|
|
if (player == null) return;
|
|
SkillPlayerInfo.TryRemove(player.Index, out _);
|
|
EntityManager.DestroyPlayerEntities(player.Index);
|
|
SkillUtils.ResetPrintHTML(player);
|
|
}
|
|
|
|
private static void UpdateHUD(CCSPlayerController player, PlayerSkillInfo skillInfo)
|
|
{
|
|
float cooldown = 0;
|
|
if (skillInfo != null)
|
|
{
|
|
float time = (int)Math.Ceiling((skillInfo.Cooldown.AddSeconds(SkillsInfo.GetValue<float>(skillName, "cooldown")) - DateTime.Now).TotalSeconds);
|
|
cooldown = Math.Max(time, 0);
|
|
|
|
if (cooldown == 0 && skillInfo?.CanUse == false)
|
|
skillInfo.CanUse = true;
|
|
}
|
|
|
|
var playerInfo = PlayerManager.GetPlayerByIndex(player!.Index);
|
|
if (playerInfo == null) return;
|
|
|
|
if (cooldown == 0)
|
|
playerInfo.PrintHTML = null;
|
|
else
|
|
playerInfo.PrintHTML = $"{player.GetTranslation("hud_info", $"<font color='#FF0000'>{cooldown}</font>")}";
|
|
}
|
|
|
|
public static void UseSkill(CCSPlayerController player)
|
|
{
|
|
if (player == null || !player.IsValid || player.LifeState != (byte)LifeState_t.LIFE_ALIVE) return;
|
|
|
|
if (SkillPlayerInfo.TryGetValue(player.Index, out var skillInfo) && skillInfo.CanUse)
|
|
{
|
|
skillInfo.CanUse = false;
|
|
skillInfo.Cooldown = DateTime.Now;
|
|
CreateReplica(player);
|
|
}
|
|
}
|
|
|
|
private static void CreateReplica(CCSPlayerController player)
|
|
{
|
|
var playerPawn = player.PlayerPawn.Value;
|
|
if (playerPawn == null || !playerPawn.IsValid) return;
|
|
if (playerPawn.AbsOrigin == null || playerPawn.AbsRotation == null) return;
|
|
|
|
var replica = EntityManager.CreateTrackedPropOverride(player.Index);
|
|
if (replica == null || !replica.IsValid) return;
|
|
|
|
replica.Collision.SolidType = SolidType_t.SOLID_VPHYSICS;
|
|
replica.CBodyComponent!.SceneNode!.Owner!.Entity!.Flags = (uint)(replica.CBodyComponent!.SceneNode!.Owner!.Entity!.Flags & ~(1 << 2));
|
|
|
|
replica.SetModel(playerPawn!.CBodyComponent!.SceneNode!.GetSkeletonInstance().ModelState.ModelName);
|
|
replica.Entity!.Name = replica.Globalname = $"Illusionist_{Server.TickCount}_{(player.Team == CsTeam.CounterTerrorist ? "CT" : "TT")}";
|
|
|
|
replica.UseAnimGraph = false;
|
|
replica.DispatchSpawn();
|
|
|
|
float distance = 40;
|
|
Vector startPos = playerPawn.AbsOrigin + SkillUtils.GetForwardVector(playerPawn.AbsRotation) * distance;
|
|
QAngle angle = new(0, playerPawn.EyeAngles.Y, 0);
|
|
replica.Teleport(startPos, angle, new Vector(0, 0, -100));
|
|
|
|
bool ducking = ((PlayerFlags)playerPawn.Flags).HasFlag(PlayerFlags.FL_DUCKING);
|
|
|
|
string animName = ducking ? "crouch_new_knife_n" : "run_new_knife_n";
|
|
replica.AcceptInput("SetAnimation", value: animName);
|
|
replica.AcceptInput("SetPlaybackRate", value: "1.0");
|
|
|
|
float speed = ducking ? 1.25f : 3.5f;
|
|
Vector forwardVec = SkillUtils.GetForwardVector(angle);
|
|
int replicaIndex = (int)replica.Index;
|
|
|
|
Instance.AddTickTimer(10, () => {
|
|
var moveTimer = Instance.AddTickTimer(1, () =>
|
|
{
|
|
if (replica == null || !replica.IsValid)
|
|
{
|
|
if (ActiveTimers.TryRemove(replicaIndex, out var timer)) timer?.Kill();
|
|
return;
|
|
}
|
|
|
|
if (ducking && Server.TickCount % 50 == 0)
|
|
{
|
|
replica.AcceptInput("SetAnimation", value: animName);
|
|
replica.AcceptInput("SetPlaybackRate", value: "1.0");
|
|
}
|
|
|
|
Vector currentPos = replica.AbsOrigin!;
|
|
Vector nexPos = new(
|
|
currentPos.X + (forwardVec.X * speed),
|
|
currentPos.Y + (forwardVec.Y * speed),
|
|
currentPos.Z
|
|
);
|
|
replica.Teleport(nexPos, null, null);
|
|
}, TimerFlags.REPEAT | TimerFlags.STOP_ON_MAPCHANGE);
|
|
ActiveTimers.TryAdd(replicaIndex, moveTimer);
|
|
}, TimerFlags.STOP_ON_MAPCHANGE);
|
|
|
|
float duration = SkillsInfo.GetValue<float>(skillName, ducking ? "durationCrouch" : "durationRun");
|
|
Instance.AddTimer(duration, () =>
|
|
{
|
|
if (replica != null && replica.IsValid)
|
|
{
|
|
EntityManager.DestroyEntity(replica.Index);
|
|
if (ActiveTimers.TryRemove(replicaIndex, out var timer)) timer?.Kill();
|
|
}
|
|
}, CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE);
|
|
}
|
|
|
|
public static void OnTakeDamage(DynamicHook h)
|
|
{
|
|
CEntityInstance param = h.GetParam<CEntityInstance>(0);
|
|
CTakeDamageInfo param2 = h.GetParam<CTakeDamageInfo>(1);
|
|
|
|
if (param == null || param.Entity == null || param2 == null || param2.Attacker == null || param2.Attacker.Value == null)
|
|
return;
|
|
|
|
if (string.IsNullOrEmpty(param.Entity.Name)) return;
|
|
if (!param.Entity.Name.StartsWith("Illusionist_")) return;
|
|
|
|
var replica = param.As<CDynamicProp>();
|
|
if (replica == null || !replica.IsValid) return;
|
|
|
|
replica.EmitSound("GlassBottle.BulletImpact", volume: 1f);
|
|
if (ActiveTimers.TryRemove((int)replica.Index, out var timer)) timer?.Kill();
|
|
EntityManager.DestroyEntity(replica.Index);
|
|
|
|
CCSPlayerPawn attackerPawn = new(param2.Attacker.Value.Handle);
|
|
if (attackerPawn.DesignerName != "player") return;
|
|
|
|
var attackerTeam = attackerPawn.TeamNum;
|
|
var replicaTeam = replica.Globalname.EndsWith("CT") ? 3 : 2;
|
|
SkillUtils.TakeHealth(attackerPawn, attackerTeam != replicaTeam ? SkillsInfo.GetValue<int>(skillName, "EnemyTeamDamage") : SkillsInfo.GetValue<int>(skillName, "YourTeamDamage"));
|
|
}
|
|
|
|
public class PlayerSkillInfo
|
|
{
|
|
public ulong SteamID { get; set; }
|
|
public bool CanUse { get; set; }
|
|
public DateTime Cooldown { get; set; }
|
|
}
|
|
|
|
public class SkillConfig(Skills skill = skillName, bool active = true, string color = "#42f5ef", CsTeam onlyTeam = CsTeam.None, bool disableOnFreezeTime = true, bool needsTeammates = false, string requiredPermission = "", float? hudDuration = null, float? descriptionHudDuration = null, int maxPerServer = 2, Rarity rarity = Rarity.Common, float cooldown = 30f, float durationRun = 5, float durationCrouch = 12, int yourTeamDamage = 10, int enemyTeamDamage = 20) : SkillsInfo.DefaultSkillInfo(skill, active, color, onlyTeam, disableOnFreezeTime, needsTeammates, requiredPermission, hudDuration, descriptionHudDuration, maxPerServer, rarity)
|
|
{
|
|
public float Cooldown { get; set; } = cooldown;
|
|
public float DurationRun { get; set; } = durationRun;
|
|
public float DurationCrouch { get; set; } = durationCrouch;
|
|
public int YourTeamDamage { get; set; } = yourTeamDamage;
|
|
public int EnemyTeamDamage { get; set; } = enemyTeamDamage;
|
|
}
|
|
}
|
|
} |