local packages = {}

table.insert(packages, "levels/instances/unique/hlm_random_right003/world")
table.insert(packages, "levels/instances/unique/hlm_gate_base/world")
table.insert(packages, "levels/instances/unique/hlm_door_wooden_white_green/world")
table.insert(packages, "levels/instances/unique/hlm_reader/world")
table.insert(packages, "levels/instances/unique/hlm_vault/world")
table.insert(packages, "levels/instances/unique/hlm_box_contraband001/world")
table.insert(packages, "levels/instances/unique/hox_fbi_armory/world")
table.insert(packages, "levels/instances/unique/mus_security_barrier/world")
table.insert(packages, "levels/instances/unique/san_box_tree001/world")
table.insert(packages, "levels/narratives/vlad/ukrainian_job/world_sounds")
table.insert(packages, "levels/narratives/vlad/jewelry_store/world_sounds")

if HT:getSetting("enable_driving_packages_loading") then
    table.insert(packages, "levels/narratives/bain/cage/world/world")
    table.insert(packages, "levels/narratives/vlad/shout/world/world")
    table.insert(packages, "levels/narratives/vlad/jolly/world/world")
    table.insert(packages, "levels/narratives/pbr/jerry/world/world")
    table.insert(packages, "levels/narratives/elephant/born/world/world")
end

for key, value in pairs(packages) do
    if not PackageManager:package_exists(value) then
        goto continue
    end
    if PackageManager:loaded(value) then
        goto continue
    end
    PackageManager:load(value)
    ::continue::
end

-- Auto-reset volatile cheats whenever the game returns to the main menu/crime.net.
-- Setup:load_start_menu is the single catch-all for EVERY "leave the heist" path:
-- aborting a mission, terminating a contract to pick a new one, being kicked,
-- disconnecting, or continuing from the end screen. The earlier menumanager hooks
-- only caught the Abort-dialog and Restart paths, which is why terminating a
-- contract to select a new one left cheats running.
--
-- This is done here (the lib/setups/gamesetup post-hook) rather than in coresetup
-- because the base Setup class lives in lib/setups/setup.lua, which loads AFTER
-- coresetup -- so _G.Setup doesn't exist yet at coresetup time. By the time
-- gamesetup runs, Setup is defined, and GameSetup inherits load_start_menu from
-- it (GameSetup does not override it), so this covers every setup instance.
pcall(function()
    if _G.Setup and not _G.Setup.__ht_reset_hooked then
        _G.CloneClass(Setup)
        function Setup:load_start_menu(...)
            pcall(function()
                if HT.Reset and HT.Reset.all then
                    HT.Reset:all(true)
                end
            end)
            return Setup.orig.load_start_menu(self, ...)
        end
        _G.Setup.__ht_reset_hooked = true
    end
end)
