Skip to content

Commit 3a67b06

Browse files
Cheater_Detection: fixes to menu etc
1 parent b3f3d29 commit 3a67b06

7 files changed

Lines changed: 224 additions & 50 deletions

File tree

Cheater_Detection/Core/player_cache.lua

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,17 @@ local TickEntityCache = require("Cheater_Detection.Utils.TickEntityCache"
3434

3535
local PlayerCache = {}
3636

37+
local function requestCosmeticScanIfEnabled(id)
38+
local adv = G.Menu and G.Menu.Advanced
39+
if not adv or adv.Cosmetics ~= true then
40+
return
41+
end
42+
local ok, cosmetic = pcall(require, "Cheater_Detection.detectors.cosmetic_abuse")
43+
if ok and cosmetic.RequestScan then
44+
cosmetic.RequestScan(id)
45+
end
46+
end
47+
3748
---@type table<string, table>
3849
local activeSet = {}
3950

@@ -245,6 +256,7 @@ function PlayerCache.SyncTick()
245256
}
246257
activeSet[id] = state
247258
anyNew = true
259+
requestCosmeticScanIfEnabled(id)
248260
DirtySystem.MarkDirty(id, "connected")
249261
DirtySystem.MarkDirty(id, "score")
250262
DirtySystem.MarkDirty(id, "flags")

Cheater_Detection/Core/scheduler.lua

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ local SteamLookup = require("Cheater_Detection.services.steam_lookup")
77
local HttpQueue = require("Cheater_Detection.services.http_queue")
88
local Fetcher = require("Cheater_Detection.Database.Fetcher")
99
local ValveCheck = require("Cheater_Detection.detectors.valve_check")
10+
local CosmeticAbuse = require("Cheater_Detection.detectors.cosmetic_abuse")
1011
local PlayerCache = require("Cheater_Detection.Core.player_cache")
1112
local G = require("Cheater_Detection.Utils.Globals")
1213
local Common = require("Cheater_Detection.Utils.Common")
@@ -28,7 +29,6 @@ local function detectorsNeedLiveCache()
2829
or (adv and adv.Bhop == true)
2930
or Common.IsDoubleTapDetectionEnabled()
3031
or (adv and adv.Choke == true)
31-
or (adv and adv.Cosmetics == true)
3232
end
3333

3434
local function syncPlayerCacheForMode()
@@ -68,6 +68,10 @@ function Scheduler.Tick()
6868
ValveCheck.Tick()
6969
end
7070

71+
if CosmeticAbuse.HasPendingWork() then
72+
CosmeticAbuse.ProcessPending()
73+
end
74+
7175
if Fetcher and Fetcher.Tick then
7276
local ok, err = pcall(Fetcher.Tick)
7377
if not ok then

Cheater_Detection/Main.lua

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -519,16 +519,6 @@ local function OnCreateMove(cmd)
519519
Profiler.End("FakeLag")
520520
end
521521

522-
if enableCosmetics then
523-
Profiler.Begin("Cosmetics")
524-
for _, pState in ipairs(activePlayers) do
525-
if not pState.wearablesScanned then
526-
CosmeticAbuse.ScanPlayer(pState)
527-
end
528-
end
529-
Profiler.End("Cosmetics")
530-
end
531-
532522
Profiler.End("PlayerScan_Loop")
533523
Profiler.End("CreateMove_Total")
534524
end

Cheater_Detection/Misc/Visuals/Menu.lua

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,6 @@ local function DrawMenu()
155155
TimMenu.BeginSector("Debug")
156156
Advanced.debug = TimMenu.Checkbox("Debug Mode", Advanced.debug == true)
157157
TimMenu.NextLine()
158-
TimMenu.Text("DEBUG ON = detectors run on YOU (self-test). OFF = you are never scanned.")
159-
TimMenu.NextLine()
160-
TimMenu.Text("Your flags: top-center HUD box. Others: WorldToScreen over head.")
161-
TimMenu.NextLine()
162158
Advanced.profiler = TimMenu.Checkbox("Performance Profiler", Advanced.profiler == true)
163159
TimMenu.NextLine()
164160
-- Debug category selector to reduce console spam
@@ -179,10 +175,6 @@ local function DrawMenu()
179175

180176
TimMenu.BeginSector("Exploit Detection")
181177
Advanced.Choke = TimMenu.Checkbox("Fake Lag Detection (Experimental)", Advanced.Choke == true)
182-
local ft = globals.AbsoluteFrameTime()
183-
if ft and ft > 0 and (1.0 / ft) < 40 then
184-
TimMenu.Text("(OFF: Low FPS!)")
185-
end
186178
TimMenu.NextLine()
187179
Advanced.DoubleTap = TimMenu.Checkbox("Double Tap Detection (Experimental)", Common.IsDoubleTapDetectionEnabled())
188180
Advanced.AntiAim = TimMenu.Checkbox("Anti-Aim Detection", Advanced.AntiAim == true)
@@ -198,15 +190,6 @@ local function DrawMenu()
198190
TimMenu.NextLine()
199191
TimMenu.EndSector()
200192
TimMenu.NextLine()
201-
202-
TimMenu.BeginSector("Aim Detection")
203-
-- Disabled pending rework; forced off in Main.lua until silent aim is restored.
204-
Advanced.SilentAimbot = false
205-
Advanced.AimLock = false
206-
TimMenu.Text("Silent Aim / AimLock: disabled (coming back later)")
207-
TimMenu.NextLine()
208-
TimMenu.EndSector()
209-
TimMenu.NextLine()
210193
elseif G.Menu.currentTab == "Notifications" then
211194
local N = Notifications
212195
Misc.JoinNotifications = Misc.JoinNotifications or {}

Cheater_Detection/Utils/Commands.lua

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,17 @@ local function setupDiagnostics()
251251

252252
Commands.Register("cd_fl_status", function(_args)
253253
local block = FakeLag.GetDetectionBlockReason()
254+
local fps = FakeLag.GetFpsDiagnostics()
254255
printc(100, 220, 255, 255, "[CD] FakeLag diagnostic:")
255-
printc(200, 200, 200, 255, " min FPS need : >= 40 (smoothed)")
256+
printc(200, 200, 200, 255, " min FPS need : >= 40 (instant, 1s worst, 1s avg, smoothed)")
257+
if fps then
258+
printc(200, 200, 200, 255, string.format(
259+
" fps now : instant=%s 1s_worst=%s 1s_avg=%s smoothed=%.0f",
260+
fps.instant and string.format("%.0f", fps.instant) or "n/a",
261+
fps.rollingMin and string.format("%.0f", fps.rollingMin) or "n/a",
262+
fps.rollingAvg and string.format("%.0f", fps.rollingAvg) or "n/a",
263+
fps.smoothed or 0))
264+
end
256265
printc(200, 200, 200, 255, string.format(" allowed : %s", tostring(FakeLag.IsDetectionAllowed())))
257266
printc(200, 200, 200, 255, string.format(" block reason : %s", block or "none"))
258267
end)

Cheater_Detection/detectors/cosmetic_abuse.lua

Lines changed: 88 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ local regionCache = {}
2727
-- per-player scan results: id -> { regions = {region->count}, totalWearables = n }
2828
local playerScanData = {}
2929

30+
-- Event-driven queue (no CreateMove scan of all players).
31+
local pendingScanIds = {}
32+
local COSMETICS_SCANS_PER_TICK = 3
33+
local MAX_WEARABLE_SCAN_ATTEMPTS = 66
34+
3035
-- One entities.FindByClass("CTFWearable") pass per game tick, shared by all players.
3136
local wearableCacheTick = -1
3237
local wearablesByPlayerIndex = {}
@@ -195,10 +200,79 @@ function CosmeticAbuse.Init()
195200
end
196201

197202
function CosmeticAbuse.InvalidatePlayer(id)
203+
id = id and tostring(id)
204+
if not id then
205+
return
206+
end
198207
playerScanData[id] = nil
208+
pendingScanIds[id] = nil
209+
local state = PlayerCache.GetByID(id)
210+
if state then
211+
state.wearablesScanned = nil
212+
state.wearableScanAttempts = nil
213+
end
214+
end
215+
216+
function CosmeticAbuse.RequestScan(id)
217+
if not id or not isEnabled() then
218+
return
219+
end
220+
id = tostring(id)
221+
if not id:match("^7656119%d+$") then
222+
return
223+
end
224+
pendingScanIds[id] = true
199225
local state = PlayerCache.GetByID(id)
200226
if state then
201227
state.wearablesScanned = nil
228+
state.wearableScanAttempts = nil
229+
end
230+
playerScanData[id] = nil
231+
end
232+
233+
function CosmeticAbuse.HasPendingWork()
234+
return next(pendingScanIds) ~= nil
235+
end
236+
237+
function CosmeticAbuse.ProcessPending(maxScans)
238+
if not isEnabled() then
239+
for k in pairs(pendingScanIds) do
240+
pendingScanIds[k] = nil
241+
end
242+
return
243+
end
244+
245+
local limit = maxScans or COSMETICS_SCANS_PER_TICK
246+
local processed = 0
247+
for id in pairs(pendingScanIds) do
248+
if processed >= limit then
249+
break
250+
end
251+
local state = PlayerCache.GetByID(id)
252+
if not state or not state.pdata or not state.pdata.isAlive or state.pdata.isDormant then
253+
pendingScanIds[id] = nil
254+
else
255+
CosmeticAbuse.ScanPlayer(state)
256+
processed = processed + 1
257+
if state.wearablesScanned then
258+
pendingScanIds[id] = nil
259+
elseif (state.wearableScanAttempts or 0) >= MAX_WEARABLE_SCAN_ATTEMPTS then
260+
pendingScanIds[id] = nil
261+
end
262+
end
263+
end
264+
end
265+
266+
function CosmeticAbuse.OnSessionReset()
267+
for k in pairs(pendingScanIds) do
268+
pendingScanIds[k] = nil
269+
end
270+
for _, state in pairs(PlayerCache.GetActiveTable()) do
271+
if state and state.id then
272+
state.wearablesScanned = nil
273+
state.wearableScanAttempts = nil
274+
CosmeticAbuse.RequestScan(state.id)
275+
end
202276
end
203277
end
204278

@@ -223,7 +297,7 @@ function CosmeticAbuse.ScanPlayer(playerState)
223297
if scanned == nil then
224298
local attempts = (playerState.wearableScanAttempts or 0) + 1
225299
playerState.wearableScanAttempts = attempts
226-
if attempts < 66 then
300+
if attempts < MAX_WEARABLE_SCAN_ATTEMPTS then
227301
return
228302
end
229303
playerState.wearablesScanned = true
@@ -251,12 +325,8 @@ function CosmeticAbuse.ScanPlayer(playerState)
251325
end
252326
end
253327

254-
local function scanPlayerById(id)
255-
if not id or not isEnabled() then return end
256-
local state = PlayerCache.GetByID(tostring(id))
257-
if state then
258-
CosmeticAbuse.ScanPlayer(state)
259-
end
328+
local function queueScanById(id)
329+
CosmeticAbuse.RequestScan(id)
260330
end
261331

262332
local function onPlayerSpawn(event)
@@ -266,7 +336,7 @@ local function onPlayerSpawn(event)
266336
if not ent or not ent:IsValid() then return end
267337
local id = tostring(Common.GetSteamID64(ent))
268338
if id:match("^7656119%d+$") then
269-
scanPlayerById(id)
339+
queueScanById(id)
270340
end
271341
end
272342

@@ -277,13 +347,20 @@ local function onPlayerChangeClass(event)
277347
if not ent or not ent:IsValid() then return end
278348
local id = tostring(Common.GetSteamID64(ent))
279349
if id:match("^7656119%d+$") then
280-
CosmeticAbuse.InvalidatePlayer(id)
281-
scanPlayerById(id)
350+
CosmeticAbuse.RequestScan(id)
282351
end
283352
end
284353

285-
Events.Subscribe("OnPlayerJoinTeam", scanPlayerById)
354+
local function onSessionReset(_event)
355+
if not isEnabled() then return end
356+
CosmeticAbuse.OnSessionReset()
357+
end
358+
359+
Events.Subscribe("OnPlayerJoinTeam", queueScanById)
286360
Events.Register("FireGameEvent", "CosmeticAbuse_Spawn", onPlayerSpawn, "player_spawn")
287361
Events.Register("FireGameEvent", "CosmeticAbuse_ClassChange", onPlayerChangeClass, "player_changeclass")
362+
Events.Register("FireGameEvent", "CosmeticAbuse_NewMap", onSessionReset, "game_newmap")
363+
Events.Register("FireGameEvent", "CosmeticAbuse_RoundStart", onSessionReset, "teamplay_round_start")
364+
Events.Register("FireGameEvent", "CosmeticAbuse_RoundEnd", onSessionReset, "round_end")
288365

289366
return CosmeticAbuse

0 commit comments

Comments
 (0)