local typeof_ = (type(typeof) == "function" and typeof) or type local now = (type(time) == "function" and time) or os.clock local getrawmetatable_ = getrawmetatable local setreadonly_ = setreadonly local newcclosure_ = newcclosure local getnamecallmethod_ = getnamecallmethod local hookfunction_ = hookfunction local getgenv_ = getgenv local shared_ = shared local Players = game:GetService("Players") local ReplicatedStorage = game:GetService("ReplicatedStorage") local player = Players.LocalPlayer local registry = (type(getgenv_) == "function" and getgenv_()) or (type(shared_) == "table" and shared_) or _G local KEY = "__Split_AntiKick_InfStamina_Controller_v1__" local existing = registry[KEY] if type(existing) == "table" and type(existing.IsInstalled) == "function" and existing.IsInstalled() then existing.SetEnabled(true) return existing end local master, running = true, true local loopToken = 0 local warned = {} local function warnOnce(key, message) if warned[key] then return end warned[key] = true print("[anti_kick_inf_stamina] " .. key .. ": " .. tostring(message)) end local function wrap(fn) if type(newcclosure_) == "function" then return newcclosure_(fn) end return fn end local function unlock(mt) if type(setreadonly_) == "function" then setreadonly_(mt, false) end end local function lock(mt) if type(setreadonly_) == "function" then setreadonly_(mt, true) end end local function child(parent, name) if not parent then return nil end return parent:FindFirstChild(name) end local function safeRequire(module) local ok, value = pcall(require, module) if not ok or type(value) ~= "table" then return nil, tostring(value) end return value end local sprintingCache = nil local nextSprintingAt = 0 local resolveRetry, errorRetry = 0.25, 0.5 local function resolveSprinting(t) if sprintingCache then return sprintingCache end if t < nextSprintingAt then return nil end local systems = child(ReplicatedStorage, "Systems") local character = child(systems, "Character") local gameplay = child(character, "Game") local module = child(gameplay, "Sprinting") if not module then nextSprintingAt = t + resolveRetry return nil end local value, err = safeRequire(module) if not value then nextSprintingAt = t + errorRetry warnOnce("sprinting", "Sprinting require failed: " .. tostring(err)) return nil end sprintingCache = value return value end local KF = { enabled = true, installed = false, unavailable = nil, reason = "Stamina exceeds max possible cap", } KF.reasonLower = string.lower(KF.reason) local mt, originalNamecall, namecallHook local originalKick, kickTarget local directHooked, namecallHooked = false, false local function kfActive() return master and KF.enabled and KF.installed end local function matches(reason) if not kfActive() or typeof_(reason) ~= "string" then return false end if string.find(reason, KF.reason, 1, true) then return true end return string.find(string.lower(reason), KF.reasonLower, 1, true) ~= nil end local function kfRollbackDirect() if directHooked and kickTarget and originalKick and type(hookfunction_) == "function" then pcall(hookfunction_, kickTarget, originalKick) end directHooked = false end local function kfInstall() if KF.installed then return true end if type(getrawmetatable_) ~= "function" or type(getnamecallmethod_) ~= "function" then KF.unavailable = "getrawmetatable / getnamecallmethod unavailable" warnOnce("kickfilter", KF.unavailable) return false end mt = getrawmetatable_(game) if not mt or not mt.__namecall then KF.unavailable = "__namecall unavailable" warnOnce("kickfilter", KF.unavailable) return false end if type(hookfunction_) == "function" and player.Kick ~= nil then local target = player.Kick local ok, original = pcall(hookfunction_, target, function(self, reason) if self == player and matches(reason) then return end if originalKick then return originalKick(self, reason) end end) if ok and original then originalKick, kickTarget, directHooked = original, target, true end end originalNamecall = mt.__namecall namecallHook = wrap(function(self, ...) if getnamecallmethod_() == "Kick" and self == player then local reason = ... if matches(reason) then return end end return originalNamecall(self, ...) end) local ok = pcall(function() unlock(mt) mt.__namecall = namecallHook lock(mt) end) if not ok then kfRollbackDirect() KF.unavailable = "failed to install __namecall hook" warnOnce("kickfilter", KF.unavailable) return false end namecallHooked = true KF.installed = true KF.unavailable = nil return true end local function kfStop() KF.installed = false if namecallHooked and namecallHook and mt.__namecall == namecallHook then pcall(function() unlock(mt) mt.__namecall = originalNamecall lock(mt) end) end kfRollbackDirect() namecallHooked = false namecallHook = nil end local ST = { enabled = true, installed = false, unavailable = nil, Settings = { InfiniteStamina = true, MinStaminaValue = 0, MaxStaminaValue = 100, DrainStaminaValue = 10, RefillThreshold = 2, PollInterval = 0.1, IdleInterval = 0.25, ErrorBackoff = 1.0, MaxConsecutiveErrors = 5, ResolveRetry = 0.25, }, } local FIELDS = { "MinStamina", "MaxStamina", "StaminaDrain", "StaminaLoss", "StaminaLossDisabled", "Stamina", } local saved = nil local consecutiveErrors = 0 local function stActive() return running and master and ST.enabled and ST.installed and ST.Settings.InfiniteStamina end local function stSnapshot(m) if saved and saved.module == m then return end local values = {} for _, key in ipairs(FIELDS) do values[key] = m[key] end saved = { module = m, values = values } end local function stRestore() if not saved then return end for _, key in ipairs(FIELDS) do saved.module[key] = saved.values[key] end saved = nil end local function setField(m, key, value, existingOnly) local current = m[key] if existingOnly and current == nil then return end if current ~= value then m[key] = value end end local function staminaParts(m) local value = m.Stamina if typeof_(value) == "number" then return value, nil end if value ~= nil and (typeof_(value) == "Instance" or typeof_(value) == "table") then local ok, inner = pcall(function() return value.Value end) if ok and typeof_(inner) == "number" then return inner, value end end return nil, nil end local function stUpdate(m) stSnapshot(m) setField(m, "MinStamina", ST.Settings.MinStaminaValue) setField(m, "MaxStamina", ST.Settings.MaxStaminaValue) setField(m, "StaminaDrain", ST.Settings.DrainStaminaValue, true) setField(m, "StaminaLoss", ST.Settings.DrainStaminaValue, true) setField(m, "StaminaLossDisabled", false) local current, container = staminaParts(m) if current and current <= ST.Settings.RefillThreshold then local maximum = m.MaxStamina if typeof_(maximum) ~= "number" then maximum = ST.Settings.MaxStaminaValue end if container then container.Value = maximum else m.Stamina = maximum end end end local function stLoop() loopToken = loopToken + 1 local myToken = loopToken while running and loopToken == myToken do local interval = stActive() and ST.Settings.PollInterval or ST.Settings.IdleInterval task.wait(interval) if not (running and loopToken == myToken) then break end if not stActive() then stRestore() consecutiveErrors = 0 else local m = resolveSprinting(now()) if m then local ok, failure = pcall(stUpdate, m) if ok then consecutiveErrors = 0 else consecutiveErrors = consecutiveErrors + 1 warnOnce("stamina", "update error: " .. tostring(failure)) if consecutiveErrors >= ST.Settings.MaxConsecutiveErrors then task.wait(ST.Settings.ErrorBackoff) consecutiveErrors = 0 end end end end end end local function stInstall() if ST.installed then return true end ST.installed = true ST.unavailable = nil task.spawn(stLoop) return true end local function stStop() ST.installed = false loopToken = loopToken + 1 stRestore() consecutiveErrors = 0 end local controller = {} local KickFilter = { SetEnabled = function(value) KF.enabled = not not value end, IsEnabled = function() return KF.enabled end, IsInstalled = function() return KF.installed end, SetReason = function(value) assert(typeof_(value) == "string" and value ~= "", "reason must be a non-empty string") KF.reason = value KF.reasonLower = string.lower(value) end, GetReason = function() return KF.reason end, Status = function() return { Enabled = KF.enabled, Installed = KF.installed, Reason = KF.reason, Unavailable = KF.unavailable, } end, } local InfiniteStamina = { Settings = ST.Settings, SetEnabled = function(value) ST.enabled = not not value end, IsEnabled = function() return ST.enabled and ST.Settings.InfiniteStamina end, IsInstalled = function() return ST.installed end, Restore = function() stRestore() end, Status = function() return { Enabled = ST.enabled, Installed = ST.installed, Active = stActive(), ModuleResolved = sprintingCache ~= nil, } end, } controller.KickFilter = KickFilter controller.InfiniteStamina = InfiniteStamina controller.Settings = ST.Settings controller.SetReason = KickFilter.SetReason controller.GetReason = KickFilter.GetReason function controller.IsEnabled() return master end function controller.IsInstalled() return KF.installed or ST.installed end function controller.SetEnabled(value) master = not not value if not master then stRestore() end end function controller.Status() return { Enabled = master, KickFilter = KickFilter.Status(), InfiniteStamina = InfiniteStamina.Status(), Modules = { Sprinting = sprintingCache ~= nil }, } end function controller.Stop() master = false running = false loopToken = loopToken + 1 kfStop() stStop() sprintingCache = nil nextSprintingAt = 0 saved = nil registry[KEY] = nil end function controller.Restart() if KF.installed or ST.installed then return true end master = true running = true KF.enabled, ST.enabled = true, true ST.Settings.InfiniteStamina = true nextSprintingAt = 0 saved = nil return controller._install() end function controller._install() kfInstall() stInstall() registry[KEY] = controller return true end assert(controller._install(), "failed to install anti kick and infinite stamina") return controller