_G.CloneClass(BootupState)
function BootupState:at_enter()
    BootupState.orig.at_enter(self)

    local bltData = HT:getBltData()
    bltData.keybinds = {}
    for _, value in pairs(HT.keybinds) do
        table.insert(bltData.keybinds, value)
    end
    HT:setBltData(bltData)

    if HT:getSetting("initialized_version") ~= HT.version then
        HT:init()
    else
        HT.Updater:checkForUpdate()
    end

    -- Ensure every keybind that has NO key assigned gets its default. Runs every
    -- launch (not just once) so if BLT ever loses the bindings they re-bind. It
    -- only sets a default when HasKey() is false, so it never stomps a key the
    -- user chose themselves.
    pcall(function()
        if BLT and BLT.Keybinds then
            local changed = false
            for _, kb in pairs(HT.keybinds) do
                if kb.id and kb.pc and kb.pc ~= "" then
                    local bind = BLT.Keybinds:get_keybind(kb.id)
                    if bind and not bind:HasKey() then
                        bind:SetKey(kb.pc)
                        changed = true
                    end
                end
            end
            -- SetKey persists through SuperBLT's keybind manager. Newer builds no
            -- longer expose BLT.Keybinds:save(), so calling it aborts boot.
        end
    end)

    -- Auto-disable: a fresh game launch (including one after a crash or quit)
    -- should start with all live cheats OFF instead of silently re-enabling
    -- whatever was on last session.
    pcall(function()
        if HT.Reset and HT.Reset.disableVolatileSettings then
            HT.Reset:disableVolatileSettings()
        end
    end)

    -- Anti-cheat bypass is safe to keep on permanently, so re-apply it if the
    -- user left it enabled (it is intentionally NOT cleared by the reset above).
    pcall(function()
        if HT.AntiCheat and HT.AntiCheat.restore then
            HT.AntiCheat:restore()
        end
    end)

    -- Persistent QoL toggles (free preplanning, no pause, skip intro, etc.) are
    -- not cleared by the volatile reset, so re-apply them here.
    pcall(function()
        if HT.Extra and HT.Extra.reapplyPersistent then
            HT.Extra:reapplyPersistent()
        end
    end)
end
