-- ENGINE LOCALS local pcall = pcall local ipairs = ipairs local pairs = pairs local type = type local tonumber = tonumber local tostring = tostring local rawset = rawset local rawget = rawget local next = next local unpack = unpack local string_upper = string.upper local string_lower = string.lower local string_sub = string.sub local P_RemoveMobj = P_RemoveMobj local P_SpawnMobj = P_SpawnMobj local P_SetOrigin = P_SetOrigin local CONS_Printf = CONS_Printf local S_StopSound = S_StopSound local S_StopSoundByID = S_StopSoundByID local S_IdPlaying = S_IdPlaying local S_SoundPlaying = S_SoundPlaying local FixedMul = FixedMul local cos = cos local sin = sin local function initialize_spawned_ambient(mobj, mobj_type) if not (mobj and mobj.valid) then return end if (mobj.flags & MF_AMBIENT) == 0 then return end if mobj_type == MT_AMBIENT then return end local info = mobjinfo[mobj_type] if not info then return end local interval = info.spawnhealth if type(interval) ~= "number" or interval <= 0 then interval = TICRATE end mobj.threshold = info.seesound mobj.health = interval end local function guard_ambient_interval(mobj) if not (mobj and mobj.valid) then return end if (mobj.flags & MF_AMBIENT) == 0 then return end local info = mobjinfo[mobj.type] local interval = mobj.health if type(interval) ~= "number" or interval <= 0 then interval = info and info.spawnhealth or 0 if type(interval) ~= "number" or interval <= 0 then interval = TICRATE end mobj.health = interval end if mobj.type ~= MT_AMBIENT and info and (not mobj.threshold or mobj.threshold <= 0) and info.seesound and info.seesound > 0 then mobj.threshold = info.seesound end end -- CONFIGURATION AND MAPPINGS local always_protected = {} local conditionally_protected = {} local purge_protected = {} local protected_types_initialized = false local general_mappings = { ["FIRE"] = { "MT_FLAME", "MT_FIRE", "MT_FIREBALL", "MT_FLAMEJET", "MT_FIREJET", "MT_FIREPARTICLE", "MT_FIRETRAIL", "MT_SPARK", "MT_FIREBAR", "MT_LAVAFALL", "MT_LAVATRAIL" }, ["FIRES"] = { "MT_FLAME", "MT_FIRE", "MT_FIREBALL", "MT_FLAMEJET", "MT_FIREJET", "MT_FIREPARTICLE", "MT_FIRETRAIL", "MT_SPARK", "MT_FIREBAR", "MT_LAVAFALL", "MT_LAVATRAIL" }, ["FLAME"] = { "MT_FLAME", "MT_FIRE", "MT_FIREBALL", "MT_FLAMEJET", "MT_FIREJET", "MT_FIREPARTICLE", "MT_FIRETRAIL", "MT_SPARK", "MT_FIREBAR", "MT_LAVAFALL", "MT_LAVATRAIL" }, ["FLAMES"] = { "MT_FLAME", "MT_FIRE", "MT_FIREBALL", "MT_FLAMEJET", "MT_FIREJET", "MT_FIREPARTICLE", "MT_FIRETRAIL", "MT_SPARK", "MT_FIREBAR", "MT_LAVAFALL", "MT_LAVATRAIL" }, ["SPRING"] = { "MT_YELLOWSPRING", "MT_REDSPRING", "MT_BLUESPRING", "MT_YELLOWDIAG", "MT_REDDIAG", "MT_BLUEDIAG", "MT_YELLOWSPRINGBALL", "MT_REDSPRINGBALL", "MT_YELLOWHORIZ", "MT_REDHORIZ", "MT_BLUEHORIZ" }, ["SPRINGS"] = { "MT_YELLOWSPRING", "MT_REDSPRING", "MT_BLUESPRING", "MT_YELLOWDIAG", "MT_REDDIAG", "MT_BLUEDIAG", "MT_YELLOWSPRINGBALL", "MT_REDSPRINGBALL", "MT_YELLOWHORIZ", "MT_REDHORIZ", "MT_BLUEHORIZ" }, ["RING"] = { "MT_RING", "MT_FLINGRING" }, ["RINGS"] = { "MT_RING", "MT_FLINGRING" }, ["CHECKPOINT"] = { "MT_STARPOST" }, ["CHECKPOINTS"] = { "MT_STARPOST" }, ["SIGN"] = { "MT_SIGN" }, ["SIGNS"] = { "MT_SIGN" }, ["GOALSIGN"] = { "MT_SIGN" }, ["GOALSIGNS"] = { "MT_SIGN" }, ["BANNER"] = { "MT_CEZBANNER1", "MT_CEZBANNER2", "MT_CEZPOLE1", "MT_CEZPOLE2", "MT_WAVINGFLAG1", "MT_WAVINGFLAG2", "MT_WAVINGFLAGSEG1", "MT_WAVINGFLAGSEG2", "MT_WALLBANNER", "MT_BANNER", "MT_FLAG", "MT_FLAGS", "MT_GOTFLAG", "MT_FINISHFLAG" }, ["BANNERS"] = { "MT_CEZBANNER1", "MT_CEZBANNER2", "MT_CEZPOLE1", "MT_CEZPOLE2", "MT_WAVINGFLAG1", "MT_WAVINGFLAG2", "MT_WAVINGFLAGSEG1", "MT_WAVINGFLAGSEG2", "MT_WALLBANNER", "MT_BANNER", "MT_FLAG", "MT_FLAGS", "MT_GOTFLAG", "MT_FINISHFLAG" }, ["FLAG"] = { "MT_GOTFLAG", "MT_FINISHFLAG", "MT_WAVINGFLAG1", "MT_WAVINGFLAG2", "MT_WAVINGFLAGSEG1", "MT_WAVINGFLAGSEG2", "MT_CEZBANNER1", "MT_CEZBANNER2", "MT_WALLBANNER", "MT_BANNER" }, ["FLAGS"] = { "MT_GOTFLAG", "MT_FINISHFLAG", "MT_WAVINGFLAG1", "MT_WAVINGFLAG2", "MT_WAVINGFLAGSEG1", "MT_WAVINGFLAGSEG2", "MT_CEZBANNER1", "MT_CEZBANNER2", "MT_WALLBANNER", "MT_BANNER" }, ["CHECKER"] = { "MT_GOTFLAG", "MT_FINISHFLAG" }, ["CHECKERS"] = { "MT_GOTFLAG", "MT_FINISHFLAG" }, ["PINE"] = { "MT_PINETREE", "MT_PINEPOLE" }, ["PINES"] = { "MT_PINETREE", "MT_PINEPOLE" }, ["TREE"] = { "MT_PINETREE", "MT_PINEPOLE", "MT_PALMTREE", "MT_JUNGLEPALM", "MT_BIG_PALMTREE_TRUNK", "MT_BIG_PALMTREE_TOP", "MT_PALMTREE_TRUNK", "MT_PALMTREE_TOP" }, ["TREES"] = { "MT_PINETREE", "MT_PINEPOLE", "MT_PALMTREE", "MT_JUNGLEPALM", "MT_BIG_PALMTREE_TRUNK", "MT_BIG_PALMTREE_TOP", "MT_PALMTREE_TRUNK", "MT_PALMTREE_TOP" }, ["PALM"] = { "MT_PALMTREE", "MT_JUNGLEPALM", "MT_BIG_PALMTREE_TRUNK", "MT_BIG_PALMTREE_TOP", "MT_PALMTREE_TRUNK", "MT_PALMTREE_TOP" }, ["PALMS"] = { "MT_PALMTREE", "MT_JUNGLEPALM", "MT_BIG_PALMTREE_TRUNK", "MT_BIG_PALMTREE_TOP", "MT_PALMTREE_TRUNK", "MT_PALMTREE_TOP" }, ["PALMTREE"] = { "MT_PALMTREE", "MT_JUNGLEPALM", "MT_BIG_PALMTREE_TRUNK", "MT_BIG_PALMTREE_TOP", "MT_PALMTREE_TRUNK", "MT_PALMTREE_TOP" }, ["PALMTREES"] = { "MT_PALMTREE", "MT_JUNGLEPALM", "MT_BIG_PALMTREE_TRUNK", "MT_BIG_PALMTREE_TOP", "MT_PALMTREE_TRUNK", "MT_PALMTREE_TOP" }, ["STUMP"] = { "MT_BIG_PALMTREE_TRUNK", "MT_PALMTREE_TRUNK" }, ["STUMPS"] = { "MT_BIG_PALMTREE_TRUNK", "MT_PALMTREE_TRUNK" }, ["PALMSTUMP"] = { "MT_BIG_PALMTREE_TRUNK", "MT_PALMTREE_TRUNK" }, ["PALMSTUMPS"] = { "MT_BIG_PALMTREE_TRUNK", "MT_PALMTREE_TRUNK" }, ["CACTUS"] = { "MT_CACTI1", "MT_CACTI2", "MT_CACTI3", "MT_CACTI4", "MT_CACTI5", "MT_CACTI6", "MT_CACTI7", "MT_CACTI8", "MT_CACTI9", "MT_CACTI10", "MT_CACTI11", "MT_CACTITINYSEG", "MT_CACTISMALLSEG", "MT_CACTUS", "MT_CACTUSTALL", "MT_CACTUSMID", "MT_CACTUSBOTTOM", "MT_CACTUSTOP", "MT_CACTUS_SEG", "MT_CACTUS_SEGMENT", "MT_CACTUS_BASE", "MT_CACTI_BASE", "MT_CACTI_SEG", "MT_CACTI_SEGMENT", "MT_CACTUS1", "MT_CACTUS2", "MT_CACTUS3", "MT_CACTUS4", "MT_CACTUS5", "MT_CACTUS6", "MT_CACTUS7", "MT_CACTUS8", "MT_CACTUS9", "MT_CACTUS10", "MT_CACTUS11" }, ["CACTI"] = { "MT_CACTI1", "MT_CACTI2", "MT_CACTI3", "MT_CACTI4", "MT_CACTI5", "MT_CACTI6", "MT_CACTI7", "MT_CACTI8", "MT_CACTI9", "MT_CACTI10", "MT_CACTI11", "MT_CACTITINYSEG", "MT_CACTISMALLSEG", "MT_CACTUS", "MT_CACTUSTALL", "MT_CACTUSMID", "MT_CACTUSBOTTOM", "MT_CACTUSTOP", "MT_CACTUS_SEG", "MT_CACTUS_SEGMENT", "MT_CACTUS_BASE", "MT_CACTI_BASE", "MT_CACTI_SEG", "MT_CACTI_SEGMENT", "MT_CACTUS1", "MT_CACTUS2", "MT_CACTUS3", "MT_CACTUS4", "MT_CACTUS5", "MT_CACTUS6", "MT_CACTUS7", "MT_CACTUS8", "MT_CACTUS9", "MT_CACTUS10", "MT_CACTUS11" }, ["MINECART"] = { "MT_MINECART", "MT_MINECARTSEG", "MT_MINECARTSPAWNER", "MT_MINECARTEND", "MT_MINECARTENDSOLID", "MT_MINECARTBUMPER" }, ["MINECARTS"] = { "MT_MINECART", "MT_MINECARTSEG", "MT_MINECARTSPAWNER", "MT_MINECARTEND", "MT_MINECARTENDSOLID", "MT_MINECARTBUMPER" }, ["MINECARTBUMPER"] = { "MT_MINECARTEND", "MT_MINECARTENDSOLID", "MT_MINECARTBUMPER" }, ["MINECARTBUMPERS"] = { "MT_MINECARTEND", "MT_MINECARTENDSOLID", "MT_MINECARTBUMPER" }, ["FLICKY"] = { "MT_FLICKY_01", "MT_FLICKY_02", "MT_FLICKY_03", "MT_FLICKY_04", "MT_FLICKY_05", "MT_FLICKY_06", "MT_FLICKY_07", "MT_FLICKY_08", "MT_FLICKY_09", "MT_FLICKY_10", "MT_FLICKY_11", "MT_FLICKY_12", "MT_FLICKY_13", "MT_FLICKY_14", "MT_FLICKY_15", "MT_FLICKY_16", "MT_BIRD", "MT_SQRL", "MT_BUNNY", "MT_CHICK", "MT_SEAL", "MT_PIG", "MT_COW", "MT_FLICKY", "MT_SECRETFLICKY_01", "MT_SECRETFLICKY_02" }, ["FLICKIES"] = { "MT_FLICKY_01", "MT_FLICKY_02", "MT_FLICKY_03", "MT_FLICKY_04", "MT_FLICKY_05", "MT_FLICKY_06", "MT_FLICKY_07", "MT_FLICKY_08", "MT_FLICKY_09", "MT_FLICKY_10", "MT_FLICKY_11", "MT_FLICKY_12", "MT_FLICKY_13", "MT_FLICKY_14", "MT_FLICKY_15", "MT_FLICKY_16", "MT_BIRD", "MT_SQRL", "MT_BUNNY", "MT_CHICK", "MT_SEAL", "MT_PIG", "MT_COW", "MT_FLICKY", "MT_SECRETFLICKY_01", "MT_SECRETFLICKY_02" }, ["ANIMAL"] = { "MT_FLICKY_01", "MT_FLICKY_02", "MT_FLICKY_03", "MT_FLICKY_04", "MT_FLICKY_05", "MT_FLICKY_06", "MT_FLICKY_07", "MT_FLICKY_08", "MT_FLICKY_09", "MT_FLICKY_10", "MT_FLICKY_11", "MT_FLICKY_12", "MT_FLICKY_13", "MT_FLICKY_14", "MT_FLICKY_15", "MT_FLICKY_16", "MT_BIRD", "MT_SQRL", "MT_BUNNY", "MT_CHICK", "MT_SEAL", "MT_PIG", "MT_COW", "MT_FLICKY", "MT_SECRETFLICKY_01", "MT_SECRETFLICKY_02" }, ["ANIMALS"] = { "MT_FLICKY_01", "MT_FLICKY_02", "MT_FLICKY_03", "MT_FLICKY_04", "MT_FLICKY_05", "MT_FLICKY_06", "MT_FLICKY_07", "MT_FLICKY_08", "MT_FLICKY_09", "MT_FLICKY_10", "MT_FLICKY_11", "MT_FLICKY_12", "MT_FLICKY_13", "MT_FLICKY_14", "MT_FLICKY_15", "MT_FLICKY_16", "MT_BIRD", "MT_SQRL", "MT_BUNNY", "MT_CHICK", "MT_SEAL", "MT_PIG", "MT_COW", "MT_FLICKY", "MT_SECRETFLICKY_01", "MT_SECRETFLICKY_02" } } local light_flags = {} local function safe_get_mt(name) if not name or type(name) ~= "string" then return nil end local ok, val = pcall(function() return _G[name] end) if ok and type(val) == "number" and val >= 0 then return val end return nil end local function is_spawned_player_copy(mobj) return mobj and mobj.valid and mobj.type == MT_PLAYER and mobj.player == nil and mobj.clearobjects_player_copy == true end local function is_protected_player_mobj(mobj) if not mobj or not mobj.valid then return false end if mobj.player ~= nil then return true end return mobj.type == MT_PLAYER and not is_spawned_player_copy(mobj) end local function init_protected_types() if protected_types_initialized then return end protected_types_initialized = true local always_names = { "MT_PLAYER", "MT_TELEPORTMAN", "MT_TUBEWAYPOINT", "MT_NIGHTSDRONE", "MT_AXIS", "MT_SKYBOX", "MT_SKYBOXVIEWPOINT", "MT_SKYBOXCENTER", "MT_AXISTRANSFER", "MT_AXISTRANSFERLINE", "MT_POLYANCHOR", "MT_POLYSPAWN", "MT_WAYPOINT", "MT_PATPOINT", "MT_ALTVIEWMAN", "MT_VIEWPOINT", "MT_FOF_TARGET", "MT_SECTOR_CONTROL", "MT_CAMERA", "MT_SPECTATOR", "MT_SMALLGRABCHAIN", "MT_BIGGRABCHAIN", "MT_SMALLMACECHAIN", "MT_BIGMACECHAIN", "MT_SMALLMACE", "MT_BIGMACE", "MT_CHAIN", "MT_CEZCHAIN", "MT_CEZHOOK", "MT_CEZROPE", "MT_CHAINPOINT", "MT_CHAINMACEPOINT", "MT_CUSTOMMACEPOINT", "MT_MACEPOINT", "MT_CRUSHCHAIN", "MT_FIREBAR", "MT_FIREBARSEG", "MT_FJSPINAXISA", "MT_FJSPINAXISB", "MT_RAYCAST", "MT_WATERZONE", "MT_RAIN", "MT_SNOW" } for _, name in ipairs(always_names) do local val = safe_get_mt(name) if val ~= nil then always_protected[val] = true end end local purge_names = { "MT_PLAYER", "MT_PLAYERSTART", "MT_DEATHMATCHSTART", "MT_REDTEAMSTART", "MT_BLUETEAMSTART", "MT_TELEPORTMAN", "MT_TUBEWAYPOINT", "MT_SKYBOX", "MT_SKYBOXVIEWPOINT", "MT_SKYBOXCENTER", "MT_ALTVIEWMAN", "MT_VIEWPOINT" } for _, name in ipairs(purge_names) do local val = safe_get_mt(name) if val ~= nil then purge_protected[val] = true end end local conditional_names = { "MT_STARPOST", "MT_STARPOSTFLASH", "MT_SIGN", "MT_SIGNPOST", "MT_GOALSIGN", "MT_GOALPOST", "MT_ENDSIGN", "MT_CAPSULE", "MT_EGGMANCAPSULE", "MT_NIGHTSGOAL", "MT_LEVELEND", "MT_SMALLGRABCHAIN", "MT_BIGGRABCHAIN", "MT_SMALLMACECHAIN", "MT_BIGMACECHAIN", "MT_SMALLMACE", "MT_BIGMACE", "MT_CHAIN", "MT_CEZCHAIN", "MT_CEZHOOK", "MT_CEZROPE", "MT_CHAINPOINT", "MT_CHAINMACEPOINT", "MT_CUSTOMMACEPOINT", "MT_MACEPOINT", "MT_CRUSHCHAIN", "MT_BLUESPRINGBALL", "MT_YELLOWSPRINGBALL", "MT_REDSPRINGBALL", "MT_YELLOWSPRING", "MT_REDSPRING", "MT_BLUESPRING", "MT_YELLOWDIAG", "MT_REDDIAG", "MT_BLUEDIAG", "MT_YELLOWHORIZ", "MT_REDHORIZ", "MT_BLUEHORIZ", "MT_YELLOWBOOSTER", "MT_REDBOOSTER", "MT_BOOSTERSEG", "MT_BOOSTERROLLER", "MT_FAN", "MT_STEAM", "MT_BUMPER", "MT_BALLOON", "MT_DUSTDEVIL" } for _, name in ipairs(conditional_names) do local val = safe_get_mt(name) if val ~= nil then conditionally_protected[val] = true end end for k, v in pairs(_G) do if type(k) == "string" and k:sub(1,3) == "MT_" and type(v) == "number" then local upper = string_upper(k) if upper:find("SPRING") or upper:find("BUMPER") or upper:find("BALLOON") or upper:find("STARPOST") or upper:find("SIGNPOST") or upper:find("GOALPOST") or upper:find("ENDSIGN") or upper:find("CAPSULE") or upper:find("CHECKPOINT") or upper:find("GRABCHAIN") or upper:find("MACE") or upper:find("CHAIN") or upper:find("BOOSTER") or upper:find("AXIS") then conditionally_protected[v] = true end end end end local whitelist_type_cache = nil rawset(_G, "clearobjects_whitelist", {}) local function save_whitelist() if netgame and not isserver then return end if not (io and io.openlocal) then return end local f = io.openlocal("client/DylanSahr's Addons/clearobjects_whitelist.dat", "w") if f then for _, item in ipairs(clearobjects_whitelist) do local name = item.name or "" local by = item.added_by or "Server" f:write(name .. "|" .. by .. "\n") end f:close() end end local function load_whitelist() whitelist_type_cache = nil rawset(_G, "clearobjects_whitelist", {}) if not (io and io.openlocal) then return end local f = io.openlocal("client/DylanSahr's Addons/clearobjects_whitelist.dat", "r") if f then for line in f:lines() do local clean = line:match("^%s*(.-)%s*$") if #clean > 0 then local sep = clean:find("|") local name = clean local by = "Server" if sep then name = clean:sub(1, sep - 1):match("^%s*(.-)%s*$") by = clean:sub(sep + 1):match("^%s*(.-)%s*$") end if #name > 0 then table.insert(clearobjects_whitelist, { name = name, added_by = by }) end end end f:close() end end load_whitelist() local getMobjType local function build_whitelist_type_set() if whitelist_type_cache then return whitelist_type_cache end local whitelist_types = {} if not clearobjects_whitelist then whitelist_type_cache = whitelist_types return whitelist_types end for _, item in ipairs(clearobjects_whitelist) do local w_name = item.name if w_name then local w_type = getMobjType(w_name) if w_type ~= nil then whitelist_types[w_type] = true end local clean_w = string_upper(w_name:match("^%s*(.-)%s*$")):gsub("[^A-Z0-9_]", "") if general_mappings and general_mappings[clean_w] then for _, const_name in ipairs(general_mappings[clean_w]) do local val = safe_get_mt(const_name) if val ~= nil then whitelist_types[val] = true end end end end end whitelist_type_cache = whitelist_types return whitelist_types end local function is_object_whitelisted(mobj, mode, whitelist_types) if mode ~= "all" or not mobj or not mobj.valid then return false end return whitelist_types and whitelist_types[mobj.type] == true or false end addHook("NetVars", function(net) clearobjects_whitelist = net($) or {} whitelist_type_cache = nil end) -- HELPERS AND CACHES local ENGINE_LOG_PRIMARY_PATH = "ClearObjects-engine-log.txt" local ENGINE_LOG_CANDIDATE_PATHS = { "client/ClearObjects/live-engine-log.txt", ENGINE_LOG_PRIMARY_PATH, "client/latest-log.txt", "client/ClearObjects-engine-log.txt", "latest-log.txt", "log.txt" } local function recreate_engine_log_snapshot(source_path) if source_path == ENGINE_LOG_PRIMARY_PATH or not io or not io.openlocal then return false end local restored = false local ok = pcall(function() local exists_ok, existing = pcall(io.openlocal, ENGINE_LOG_PRIMARY_PATH, "r") if exists_ok and existing then existing:close() return end local source_ok, source = pcall(io.openlocal, source_path, "r") if not source_ok or not source then return end local output_ok, output = pcall(io.openlocal, ENGINE_LOG_PRIMARY_PATH, "w") if not output_ok or not output then source:close() return end while true do local chunk = source:read(8192) if not chunk then break end output:write(chunk) end source:close() output:close() restored = true end) return ok and restored end local function open_engine_log_for_read() local restricted_client = netgame and not isserver for _, path in ipairs(ENGINE_LOG_CANDIDATE_PATHS) do if not restricted_client or string_sub(path, 1, 7) == "client/" then if io and io.openlocal then local ok, f = pcall(io.openlocal, path, "r") if ok and f then recreate_engine_log_snapshot(path) return f end end end end return nil end local type_cache = {} local flag_cache = {} local mobj_direct_lookup = {} local reverse_mt_cache = {} local reverse_mt_inferred = {} local reverse_state_cache = {} local reverse_state_score = {} local declared_mobj_names = {} local declared_state_names = {} local sprite_name_cache = {} local mobj_cache_initialized = false local engine_mobj_names_scanned = false local logged_mobj_names_scanned = false local debug_registry_needs_scan = true local mobj_name_cache_dirty = true local state_name_cache_dirty = true local scan_type_cache = nil local list_flag_cache = nil local refresh_state_name_cache local get_spawnstate_type_name local original_freeslot = rawget(_G, "freeslot") if type(original_freeslot) == "function" then rawset(_G, "freeslot", function(...) local names = {...} local results = {original_freeslot(...)} for _, name in ipairs(names) do if type(name) == "string" then local upper = string_upper(name) local ok, value = pcall(function() return _G[upper] end) if ok and type(value) == "number" then if upper:sub(1,3) == "MT_" then declared_mobj_names[upper] = value mobj_name_cache_dirty = true elseif upper:sub(1,2) == "S_" then declared_state_names[upper] = value state_name_cache_dirty = true end end end end return unpack(results) end) end local known_srb2_mt_names = { "MT_PLAYER", "MT_THOK", "MT_FLINGRING", "MT_RING", "MT_NIGHTSSTAR", "MT_COIN", "MT_OVERLAY", "MT_TELEPORTMAN", "MT_TUBEWAYPOINT", "MT_NIGHTSDRONE", "MT_AXIS", "MT_SKYBOX", "MT_SKYBOXVIEWPOINT", "MT_SKYBOXCENTER", "MT_AXISTRANSFER", "MT_AXISTRANSFERLINE", "MT_POLYANCHOR", "MT_POLYSPAWN", "MT_WAYPOINT", "MT_PATPOINT", "MT_ALTVIEWMAN", "MT_VIEWPOINT", "MT_SOUND", "MT_MUSIC3D", "MT_FOF_TARGET", "MT_SECTOR_CONTROL", "MT_CAMERA", "MT_SPECTATOR", "MT_BLUECRAWLA", "MT_REDCRAWLA", "MT_GFZFOWER", "MT_GFZFLOWER", "MT_GOLDBUZZ", "MT_REDBUZZ", "MT_JETJAW", "MT_CRAWLACOMMANDER", "MT_DETON", "MT_SKIM", "MT_POINTY", "MT_FISH", "MT_EGGMAN", "MT_EGGMOBILE", "MT_BOSS1", "MT_BOSS2", "MT_BOSS3", "MT_BOSS4", "MT_METALSONIC", "MT_BLACKEGGMAN", "MT_CYBRAKDEMON", "MT_MINUS", "MT_BANPYRA", "MT_PTERANAN", "MT_BASH", "MT_PYREFLY", "MT_BUMBLEBORE", "MT_SPRINGSHELL", "MT_STARPOST", "MT_SIGN", "MT_SIGNPOST", "MT_GOALPOST", "MT_ENDSIGN", "MT_CAPSULE", "MT_CHECKPOINT", "MT_SPRING", "MT_YELLOWSPRING", "MT_REDSPRING", "MT_BLUESPRING", "MT_DIAGYELLOWSPRING", "MT_DIAGREDSPRING", "MT_YELLOWDIAG", "MT_YELLOWHORIZ", "MT_REDDIAG", "MT_REDHORIZ", "MT_YELLOWSPRINGBALL", "MT_REDSPRINGBALL", "MT_BOUNCE", "MT_BUMPER", "MT_BALLOON", "MT_CANNON", "MT_STEAM", "MT_FAN", "MT_BUBBLES", "MT_MINECART", "MT_SPIKE", "MT_WALLSPIKE", "MT_CHAIN", "MT_CHAINPOINT", "MT_GARGOYLE", "MT_TNT", "MT_SPIN", "MT_CEZBANNER1", "MT_CEZBANNER2", "MT_CEZPOLE1", "MT_CEZPOLE2", "MT_WAVINGFLAG1", "MT_WAVINGFLAG2", "MT_WAVINGFLAGSEG1", "MT_WAVINGFLAGSEG2", "MT_CEZBARREL", "MT_CEZFLOWER", "MT_CEZROPE", "MT_CEZCHAIN", "MT_CEZHOOK", "MT_PINE", "MT_TREEO1", "MT_TREEO2", "MT_TREEO3", "MT_FLOWER1", "MT_FLOWER2", "MT_FLOWER3", "MT_BUSHO1", "MT_BUSHO2", "MT_BUSH1", "MT_BUSH2", "MT_SHRUB1", "MT_SHRUB2", "MT_PALMTREE", "MT_JUNGLEPALM", "MT_BIG_PALMTREE_TRUNK", "MT_BIG_PALMTREE_TOP", "MT_PALMTREE_TRUNK", "MT_PALMTREE_TOP", "MT_CACTUS", "MT_SNOWMAN", "MT_ROCK1", "MT_ROCK2", "MT_ROCK3", "MT_STALAGMITE", "MT_STALACTITE", "MT_FIRE", "MT_FLAME", "MT_CANDLE", "MT_TORCH", "MT_HEART", "MT_HEART1", "MT_HEART2", "MT_RUNNER", "MT_NIGHTSSPIKE", "MT_CAMPFIRE", "MT_LAMP", "MT_LIGHT", "MT_FOG" } local engine_mobj_name_blob = [[ MT_NULL MT_UNKNOWN MT_THOK MT_PLAYER MT_TAILSOVERLAY MT_METALJETFUME MT_BLUECRAWLA MT_REDCRAWLA MT_GFZFISH MT_GOLDBUZZ MT_REDBUZZ MT_JETTBOMBER MT_JETTGUNNER MT_CRAWLACOMMANDER MT_DETON MT_SKIM MT_TURRET MT_POPUPTURRET MT_SPINCUSHION MT_CRUSHSTACEAN MT_CRUSHCLAW MT_CRUSHCHAIN MT_BANPYURA MT_BANPSPRING MT_JETJAW MT_SNAILER MT_VULTURE MT_POINTY MT_POINTYBALL MT_ROBOHOOD MT_FACESTABBER MT_FACESTABBERSPEAR MT_EGGGUARD MT_EGGSHIELD MT_GSNAPPER MT_SNAPPER_LEG MT_SNAPPER_HEAD MT_MINUS MT_MINUSDIRT MT_SPRINGSHELL MT_YELLOWSHELL MT_UNIDUS MT_UNIBALL MT_CANARIVORE MT_CANARIVORE_GAS MT_PYREFLY MT_PYREFLY_FIRE MT_PTERABYTESPAWNER MT_PTERABYTEWAYPOINT MT_PTERABYTE MT_DRAGONBOMBER MT_DRAGONWING MT_DRAGONTAIL MT_DRAGONMINE MT_BOSSEXPLODE MT_SONIC3KBOSSEXPLODE MT_BOSSFLYPOINT MT_EGGTRAP MT_BOSS3WAYPOINT MT_BOSS9GATHERPOINT MT_BOSSJUNK MT_EGGMOBILE MT_JETFUME1 MT_EGGMOBILE_BALL MT_EGGMOBILE_TARGET MT_EGGMOBILE_FIRE MT_EGGMOBILE2 MT_EGGMOBILE2_POGO MT_GOOP MT_GOOPTRAIL MT_EGGMOBILE3 MT_FAKEMOBILE MT_SHOCKWAVE MT_EGGMOBILE4 MT_EGGMOBILE4_MACE MT_JETFLAME MT_EGGROBO1 MT_EGGROBO1JET MT_FANG MT_BROKENROBOT MT_VWREF MT_VWREB MT_PROJECTORLIGHT MT_FBOMB MT_TNTDUST MT_FSGNA MT_FSGNB MT_FANGWAYPOINT MT_BLACKEGGMAN MT_BLACKEGGMAN_HELPER MT_BLACKEGGMAN_GOOPFIRE MT_BLACKEGGMAN_MISSILE MT_CYBRAKDEMON MT_CYBRAKDEMON_ELECTRIC_BARRIER MT_CYBRAKDEMON_MISSILE MT_CYBRAKDEMON_FLAMESHOT MT_CYBRAKDEMON_FLAMEREST MT_CYBRAKDEMON_TARGET_RETICULE MT_CYBRAKDEMON_TARGET_DOT MT_CYBRAKDEMON_NAPALM_BOMB_LARGE MT_CYBRAKDEMON_NAPALM_BOMB_SMALL MT_CYBRAKDEMON_NAPALM_FLAMES MT_CYBRAKDEMON_VILE_EXPLOSION MT_METALSONIC_RACE MT_METALSONIC_BATTLE MT_MSSHIELD_FRONT MT_MSGATHER MT_RING MT_FLINGRING MT_BLUESPHERE MT_FLINGBLUESPHERE MT_BOMBSPHERE MT_REDTEAMRING MT_BLUETEAMRING MT_TOKEN MT_REDFLAG MT_BLUEFLAG MT_EMBLEM MT_EMERALD1 MT_EMERALD2 MT_EMERALD3 MT_EMERALD4 MT_EMERALD5 MT_EMERALD6 MT_EMERALD7 MT_EMERHUNT MT_EMERALDSPAWN MT_FLINGEMERALD MT_FAN MT_STEAM MT_BUMPER MT_BALLOON MT_YELLOWSPRING MT_REDSPRING MT_BLUESPRING MT_YELLOWDIAG MT_REDDIAG MT_BLUEDIAG MT_YELLOWHORIZ MT_REDHORIZ MT_BLUEHORIZ MT_BOOSTERSEG MT_BOOSTERROLLER MT_YELLOWBOOSTER MT_REDBOOSTER MT_BUBBLES MT_SIGN MT_SPIKEBALL MT_SPINFIRE MT_SPIKE MT_WALLSPIKE MT_WALLSPIKEBASE MT_STARPOST MT_BIGMINE MT_BLASTEXECUTOR MT_CANNONLAUNCHER MT_BOXSPARKLE MT_RING_BOX MT_PITY_BOX MT_ATTRACT_BOX MT_FORCE_BOX MT_ARMAGEDDON_BOX MT_WHIRLWIND_BOX MT_ELEMENTAL_BOX MT_SNEAKERS_BOX MT_INVULN_BOX MT_1UP_BOX MT_EGGMAN_BOX MT_MIXUP_BOX MT_MYSTERY_BOX MT_GRAVITY_BOX MT_RECYCLER_BOX MT_SCORE1K_BOX MT_SCORE10K_BOX MT_FLAMEAURA_BOX MT_BUBBLEWRAP_BOX MT_THUNDERCOIN_BOX MT_PITY_GOLDBOX MT_ATTRACT_GOLDBOX MT_FORCE_GOLDBOX MT_ARMAGEDDON_GOLDBOX MT_WHIRLWIND_GOLDBOX MT_ELEMENTAL_GOLDBOX MT_SNEAKERS_GOLDBOX MT_INVULN_GOLDBOX MT_EGGMAN_GOLDBOX MT_GRAVITY_GOLDBOX MT_FLAMEAURA_GOLDBOX MT_BUBBLEWRAP_GOLDBOX MT_THUNDERCOIN_GOLDBOX MT_RING_REDBOX MT_RING_BLUEBOX MT_RING_ICON MT_PITY_ICON MT_ATTRACT_ICON MT_FORCE_ICON MT_ARMAGEDDON_ICON MT_WHIRLWIND_ICON MT_ELEMENTAL_ICON MT_SNEAKERS_ICON MT_INVULN_ICON MT_1UP_ICON MT_EGGMAN_ICON MT_MIXUP_ICON MT_GRAVITY_ICON MT_RECYCLER_ICON MT_SCORE1K_ICON MT_SCORE10K_ICON MT_FLAMEAURA_ICON MT_BUBBLEWRAP_ICON MT_THUNDERCOIN_ICON MT_ROCKET MT_LASER MT_TORPEDO MT_TORPEDO2 MT_ENERGYBALL MT_MINE MT_JETTBULLET MT_TURRETLASER MT_CANNONBALL MT_CANNONBALLDECOR MT_ARROW MT_DEMONFIRE MT_LETTER MT_TUTORIALPLANT MT_TUTORIALLEAF MT_TUTORIALFLOWER MT_TUTORIALFLOWERF MT_GFZFLOWER1 MT_GFZFLOWER2 MT_GFZFLOWER3 MT_BLUEBERRYBUSH MT_BERRYBUSH MT_BUSH MT_GFZTREE MT_GFZBERRYTREE MT_GFZCHERRYTREE MT_CHECKERTREE MT_CHECKERSUNSETTREE MT_FHZTREE MT_FHZPINKTREE MT_POLYGONTREE MT_BUSHTREE MT_BUSHREDTREE MT_SPRINGTREE MT_THZFLOWER1 MT_THZFLOWER2 MT_THZFLOWER3 MT_THZTREE MT_THZTREEBRANCH MT_ALARM MT_GARGOYLE MT_BIGGARGOYLE MT_SEAWEED MT_WATERDRIP MT_WATERDROP MT_CORAL1 MT_CORAL2 MT_CORAL3 MT_CORAL4 MT_CORAL5 MT_BLUECRYSTAL MT_KELP MT_ANIMALGAETOP MT_ANIMALGAESEG MT_DSZSTALAGMITE MT_DSZ2STALAGMITE MT_LIGHTBEAM MT_CHAIN MT_FLAME MT_FLAMEPARTICLE MT_EGGSTATUE MT_MACEPOINT MT_CHAINMACEPOINT MT_SPRINGBALLPOINT MT_CHAINPOINT MT_HIDDEN_SLING MT_FIREBARPOINT MT_CUSTOMMACEPOINT MT_SMALLMACECHAIN MT_BIGMACECHAIN MT_SMALLMACE MT_BIGMACE MT_SMALLGRABCHAIN MT_BIGGRABCHAIN MT_BLUESPRINGBALL MT_YELLOWSPRINGBALL MT_REDSPRINGBALL MT_SMALLFIREBAR MT_BIGFIREBAR MT_CEZFLOWER MT_CEZPOLE1 MT_CEZPOLE2 MT_CEZBANNER1 MT_CEZBANNER2 MT_PINETREE MT_CEZBUSH1 MT_CEZBUSH2 MT_CANDLE MT_CANDLEPRICKET MT_FLAMEHOLDER MT_FIRETORCH MT_WAVINGFLAG1 MT_WAVINGFLAG2 MT_WAVINGFLAGSEG1 MT_WAVINGFLAGSEG2 MT_CRAWLASTATUE MT_FACESTABBERSTATUE MT_SUSPICIOUSFACESTABBERSTATUE MT_BRAMBLES MT_BIGTUMBLEWEED MT_LITTLETUMBLEWEED MT_CACTI1 MT_CACTI2 MT_CACTI3 MT_CACTI4 MT_CACTI5 MT_CACTI6 MT_CACTI7 MT_CACTI8 MT_CACTI9 MT_CACTI10 MT_CACTI11 MT_CACTITINYSEG MT_CACTISMALLSEG MT_ARIDSIGN_CAUTION MT_ARIDSIGN_CACTI MT_ARIDSIGN_SHARPTURN MT_OILLAMP MT_TNTBARREL MT_PROXIMITYTNT MT_DUSTDEVIL MT_DUSTLAYER MT_ARIDDUST MT_MINECART MT_MINECARTSEG MT_MINECARTSPAWNER MT_MINECARTEND MT_MINECARTENDSOLID MT_MINECARTSIDEMARK MT_MINECARTSPARK MT_SALOONDOOR MT_SALOONDOORCENTER MT_TRAINCAMEOSPAWNER MT_TRAINSEG MT_TRAINDUSTSPAWNER MT_TRAINSTEAMSPAWNER MT_MINECARTSWITCHPOINT MT_FLAMEJET MT_VERTICALFLAMEJET MT_FLAMEJETFLAME MT_FJSPINAXISA MT_FJSPINAXISB MT_FLAMEJETFLAMEB MT_LAVAFALL MT_LAVAFALL_LAVA MT_LAVAFALLROCK MT_ROLLOUTSPAWN MT_ROLLOUTROCK MT_BIGFERNLEAF MT_BIGFERN MT_JUNGLEPALM MT_TORCHFLOWER MT_WALLVINE_LONG MT_WALLVINE_SHORT MT_GLAREGOYLE MT_GLAREGOYLEUP MT_GLAREGOYLEDOWN MT_GLAREGOYLELONG MT_TARGET MT_GREENFLAME MT_BLUEGARGOYLE MT_STALAGMITE0 MT_STALAGMITE1 MT_STALAGMITE2 MT_STALAGMITE3 MT_STALAGMITE4 MT_STALAGMITE5 MT_STALAGMITE6 MT_STALAGMITE7 MT_STALAGMITE8 MT_STALAGMITE9 MT_XMASPOLE MT_CANDYCANE MT_SNOWMAN MT_SNOWMANHAT MT_LAMPPOST1 MT_LAMPPOST2 MT_HANGSTAR MT_MISTLETOE MT_SSZTREE MT_SSZTREE_BRANCH MT_SSZTREE2 MT_SSZTREE2_BRANCH MT_XMASBLUEBERRYBUSH MT_XMASBERRYBUSH MT_XMASBUSH MT_FHZICE1 MT_FHZICE2 MT_ROSY MT_CDLHRT MT_JACKO1 MT_JACKO2 MT_JACKO3 MT_HHZTREE_TOP MT_HHZTREE_PART MT_HHZSHROOM MT_HHZGRASS MT_HHZTENTACLE1 MT_HHZTENTACLE2 MT_HHZSTALAGMITE_TALL MT_HHZSTALAGMITE_SHORT MT_BSZTALLFLOWER_RED MT_BSZTALLFLOWER_PURPLE MT_BSZTALLFLOWER_BLUE MT_BSZTALLFLOWER_CYAN MT_BSZTALLFLOWER_YELLOW MT_BSZTALLFLOWER_ORANGE MT_BSZFLOWER_RED MT_BSZFLOWER_PURPLE MT_BSZFLOWER_BLUE MT_BSZFLOWER_CYAN MT_BSZFLOWER_YELLOW MT_BSZFLOWER_ORANGE MT_BSZSHORTFLOWER_RED MT_BSZSHORTFLOWER_PURPLE MT_BSZSHORTFLOWER_BLUE MT_BSZSHORTFLOWER_CYAN MT_BSZSHORTFLOWER_YELLOW MT_BSZSHORTFLOWER_ORANGE MT_BSZTULIP_RED MT_BSZTULIP_PURPLE MT_BSZTULIP_BLUE MT_BSZTULIP_CYAN MT_BSZTULIP_YELLOW MT_BSZTULIP_ORANGE MT_BSZCLUSTER_RED MT_BSZCLUSTER_PURPLE MT_BSZCLUSTER_BLUE MT_BSZCLUSTER_CYAN MT_BSZCLUSTER_YELLOW MT_BSZCLUSTER_ORANGE MT_BSZBUSH_RED MT_BSZBUSH_PURPLE MT_BSZBUSH_BLUE MT_BSZBUSH_CYAN MT_BSZBUSH_YELLOW MT_BSZBUSH_ORANGE MT_BSZVINE_RED MT_BSZVINE_PURPLE MT_BSZVINE_BLUE MT_BSZVINE_CYAN MT_BSZVINE_YELLOW MT_BSZVINE_ORANGE MT_BSZSHRUB MT_BSZCLOVER MT_BIG_PALMTREE_TRUNK MT_BIG_PALMTREE_TOP MT_PALMTREE_TRUNK MT_PALMTREE_TOP MT_DBALL MT_EGGSTATUE2 MT_GINE MT_PPAL MT_PPEL MT_ELEMENTAL_ORB MT_ATTRACT_ORB MT_FORCE_ORB MT_ARMAGEDDON_ORB MT_WHIRLWIND_ORB MT_PITY_ORB MT_FLAMEAURA_ORB MT_BUBBLEWRAP_ORB MT_THUNDERCOIN_ORB MT_THUNDERCOIN_SPARK MT_IVSP MT_SUPERSPARK MT_FLICKY_01 MT_FLICKY_01_CENTER MT_FLICKY_02 MT_FLICKY_02_CENTER MT_FLICKY_03 MT_FLICKY_03_CENTER MT_FLICKY_04 MT_FLICKY_04_CENTER MT_FLICKY_05 MT_FLICKY_05_CENTER MT_FLICKY_06 MT_FLICKY_06_CENTER MT_FLICKY_07 MT_FLICKY_07_CENTER MT_FLICKY_08 MT_FLICKY_08_CENTER MT_FLICKY_09 MT_FLICKY_09_CENTER MT_FLICKY_10 MT_FLICKY_10_CENTER MT_FLICKY_11 MT_FLICKY_11_CENTER MT_FLICKY_12 MT_FLICKY_12_CENTER MT_FLICKY_13 MT_FLICKY_13_CENTER MT_FLICKY_14 MT_FLICKY_14_CENTER MT_FLICKY_15 MT_FLICKY_15_CENTER MT_FLICKY_16 MT_FLICKY_16_CENTER MT_SECRETFLICKY_01 MT_SECRETFLICKY_01_CENTER MT_SECRETFLICKY_02 MT_SECRETFLICKY_02_CENTER MT_SEED MT_RAIN MT_SNOWFLAKE MT_SPLISH MT_LAVASPLISH MT_SMOKE MT_SMALLBUBBLE MT_MEDIUMBUBBLE MT_EXTRALARGEBUBBLE MT_WATERZAP MT_SPINDUST MT_TFOG MT_PARTICLE MT_PARTICLEGEN MT_SCORE MT_DROWNNUMBERS MT_GOTEMERALD MT_LOCKON MT_LOCKONINF MT_TAG MT_GOTFLAG MT_FINISHFLAG MT_AMBIENT MT_CORK MT_LHRT MT_REDRING MT_BOUNCERING MT_RAILRING MT_INFINITYRING MT_AUTOMATICRING MT_EXPLOSIONRING MT_SCATTERRING MT_GRENADERING MT_BOUNCEPICKUP MT_RAILPICKUP MT_AUTOPICKUP MT_EXPLODEPICKUP MT_SCATTERPICKUP MT_GRENADEPICKUP MT_THROWNBOUNCE MT_THROWNINFINITY MT_THROWNAUTOMATIC MT_THROWNSCATTER MT_THROWNEXPLOSION MT_THROWNGRENADE MT_COIN MT_FLINGCOIN MT_GOOMBA MT_BLUEGOOMBA MT_FIREFLOWER MT_FIREBALL MT_FIREBALLTRAIL MT_SHELL MT_PUMA MT_PUMATRAIL MT_HAMMER MT_KOOPA MT_KOOPAFLAME MT_AXE MT_MARIOBUSH1 MT_MARIOBUSH2 MT_TOAD MT_AXIS MT_AXISTRANSFER MT_AXISTRANSFERLINE MT_NIGHTSDRONE MT_NIGHTSDRONE_MAN MT_NIGHTSDRONE_SPARKLING MT_NIGHTSDRONE_GOAL MT_NIGHTSPARKLE MT_NIGHTSLOOPHELPER MT_NIGHTSBUMPER MT_HOOP MT_HOOPCOLLIDE MT_HOOPCENTER MT_NIGHTSCORE MT_NIGHTSCHIP MT_FLINGNIGHTSCHIP MT_NIGHTSSTAR MT_FLINGNIGHTSSTAR MT_NIGHTSSUPERLOOP MT_NIGHTSDRILLREFILL MT_NIGHTSHELPER MT_NIGHTSEXTRATIME MT_NIGHTSLINKFREEZE MT_EGGCAPSULE MT_IDEYAANCHOR MT_NIGHTOPIANHELPER MT_PIAN MT_SHLEEP MT_PENGUINATOR MT_POPHAT MT_POPSHOT MT_POPSHOT_TRAIL MT_HIVEELEMENTAL MT_BUMBLEBORE MT_BUGGLE MT_SMASHINGSPIKEBALL MT_CACOLANTERN MT_CACOSHARD MT_CACOFIRE MT_SPINBOBERT MT_SPINBOBERT_FIRE1 MT_SPINBOBERT_FIRE2 MT_HANGSTER MT_TELEPORTMAN MT_ALTVIEWMAN MT_CRUMBLEOBJ MT_TUBEWAYPOINT MT_PUSH MT_GHOST MT_OVERLAY MT_ANGLEMAN MT_POLYANCHOR MT_POLYSPAWN MT_SKYBOX MT_SPARK MT_EXPLODE MT_UWEXPLODE MT_DUST MT_ROCKSPAWNER MT_FALLINGROCK MT_ROCKCRUMBLE1 MT_ROCKCRUMBLE2 MT_ROCKCRUMBLE3 MT_ROCKCRUMBLE4 MT_ROCKCRUMBLE5 MT_ROCKCRUMBLE6 MT_ROCKCRUMBLE7 MT_ROCKCRUMBLE8 MT_ROCKCRUMBLE9 MT_ROCKCRUMBLE10 MT_ROCKCRUMBLE11 MT_ROCKCRUMBLE12 MT_ROCKCRUMBLE13 MT_ROCKCRUMBLE14 MT_ROCKCRUMBLE15 MT_ROCKCRUMBLE16 MT_GFZDEBRIS MT_BRICKDEBRIS MT_WOODDEBRIS MT_REDBRICKDEBRIS MT_BLUEBRICKDEBRIS MT_YELLOWBRICKDEBRIS MT_NAMECHECK MT_RAY MT_OLDK ]] local engine_mobj_names = {} for name in engine_mobj_name_blob:gmatch("MT_[A-Z0-9_]+") do table.insert(engine_mobj_names, name) end engine_mobj_name_blob = nil local known_srb2_display_titles = { ["MT_CEZBANNER1"] = "Red Banner Sheet", ["MT_CEZBANNER2"] = "Blue Banner Sheet", ["MT_CEZPOLE1"] = "Red Banner Pole", ["MT_CEZPOLE2"] = "Blue Banner Pole", ["MT_WAVINGFLAG1"] = "Red Waving Flag", ["MT_WAVINGFLAG2"] = "Blue Waving Flag", ["MT_WAVINGFLAGSEG1"] = "Red Waving Flag Segment", ["MT_WAVINGFLAGSEG2"] = "Blue Waving Flag Segment", ["MT_BIG_PALMTREE_TRUNK"] = "Large Palm Tree Trunk", ["MT_BIG_PALMTREE_TOP"] = "Large Palm Tree Top", ["MT_PALMTREE_TRUNK"] = "Palm Tree Trunk", ["MT_PALMTREE_TOP"] = "Palm Tree Top", ["MT_YELLOWSPRING"]= "Yellow Spring", ["MT_REDSPRING"] = "Red Spring", ["MT_BLUESPRING"] = "Blue Spring", ["MT_YELLOWDIAG"] = "Yellow Diagonal Spring", ["MT_YELLOWHORIZ"] = "Yellow Horizontal Spring", ["MT_REDDIAG"] = "Red Diagonal Spring", ["MT_REDHORIZ"] = "Red Horizontal Spring", ["MT_REDSPRINGBALL"] = "Red Spring Ball", ["MT_YELLOWSPRINGBALL"] = "Yellow Spring Ball", ["MT_BLUESPRINGBALL"] = "Blue Spring Ball", ["MT_BOOSTERSEG"] = "Booster Segment", ["MT_BOOSTERROLLER"] = "Booster Roller", ["MT_FLICKY_15"] = "Flicky 15", ["MT_GRENADERING"] = "Grenade Ring", ["MT_OVERLAY"] = "Visual Overlay", ["MT_STARPOST"] = "Starpost Checkpoint", ["MT_CHAINPOINT"] = "Chain Link Anchor", ["MT_POLYANCHOR"] = "Polyobject Anchor", ["MT_POLYSPAWN"] = "Polyobject Spawn", ["MT_SKYBOX"] = "Skybox Viewpoint", ["MT_SIGN"] = "Level End Signpost", ["MT_BLUECRAWLA"] = "Blue Crawla", ["MT_REDCRAWLA"] = "Red Crawla", ["MT_THOK"] = "Thok Object", ["MT_RING"] = "Ring", ["MT_SPIN"] = "Spin Dust/Object", ["MT_SPIKE"] = "Floor Spike", ["MT_WALLSPIKE"] = "Wall Spike", ["MT_BUBBLES"] = "Air Bubbles", ["MT_ACKACK"] = "Ackack Enemy Cannon" } local known_doomednum_table = { [800] = {mt = "MT_GFZFLOWER", display = "GFZ Flower"}, [801] = {mt = "MT_FLOWER1", display = "GFZ Red Flower"}, [802] = {mt = "MT_FLOWER2", display = "GFZ Blue Flower"}, [803] = {mt = "MT_FLOWER3", display = "GFZ Purple Flower"}, [804] = {mt = "MT_SHRUB1", display = "GFZ Shrub"}, [805] = {mt = "MT_PINE", display = "Pine Tree"}, [806] = {mt = "MT_BUSHO1", display = "Berry Bush"}, [807] = {mt = "MT_BUSHO2", display = "Bush"}, [808] = {mt = "MT_PALMTREE", display = "Palm Tree"}, [809] = {mt = "MT_CACTUS", display = "Cactus"}, [810] = {mt = "MT_SNOWMAN", display = "Snowman"}, [811] = {mt = "MT_ROCK1", display = "GFZ Rock"}, [812] = {mt = "MT_ROCK2", display = "GFZ Mossy Rock"}, [813] = {mt = "MT_STALAGMITE",display = "Stalagmite"}, [814] = {mt = "MT_STALACTITE",display = "Stalactite"}, [815] = {mt = "MT_CEZFLOWER", display = "CEZ Flower"}, [816] = {mt = "MT_CEZBARREL", display = "CEZ Wooden Barrel"}, [817] = {mt = "MT_CEZPOLE1", display = "Red Banner Pole"}, [818] = {mt = "MT_CEZPOLE2", display = "Blue Banner Pole"}, [1117] = {mt = "MT_CEZPOLE1", display = "Red Banner Pole"}, [1118] = {mt = "MT_CEZPOLE2", display = "Blue Banner Pole"}, [1128] = {mt = "MT_WAVINGFLAG1", display = "Red Waving Flag"}, [1129] = {mt = "MT_WAVINGFLAG2", display = "Blue Waving Flag"}, [1473] = {mt = "MT_BIG_PALMTREE_TOP", display = "Large Palm Tree"}, [1475] = {mt = "MT_PALMTREE_TOP", display = "Palm Tree"}, [300] = {mt = "MT_RING", display = "Ring"}, [301] = {mt = "MT_FLINGRING", display = "Dropped Ring"}, [302] = {mt = "MT_BOUNCE", display = "Bouncing Ring"}, [400] = {mt = "MT_SUPERRING", display = "Super Ring Monitor (10 Rings)"}, [401] = {mt = "MT_PITYTV", display = "Pity Shield Monitor"}, [402] = {mt = "MT_ATTRACTTV", display = "Attract Shield Monitor"}, [403] = {mt = "MT_BLACKTV", display = "Armageddon Shield Monitor"}, [404] = {mt = "MT_FORCE2TV", display = "Force Shield Monitor"}, [405] = {mt = "MT_EGGMANBOX", display = "Eggman Box"}, [406] = {mt = "MT_1UPBOX", display = "1-Up Extra Life Monitor"}, [407] = {mt = "MT_MIXUPBOX", display = "Teleport Mix-up Monitor"}, [408] = {mt = "MT_RECYCLER", display = "Recycler Monitor"}, [409] = {mt = "MT_SNEAKERTV", display = "Super Sneakers Speed Monitor"}, [410] = {mt = "MT_INVINCIBILITY",display = "Invincibility Monitor"}, [411] = {mt = "MT_GRAVITYBOX", display = "Gravity Boots Monitor"}, [310] = {mt = "MT_YELLOWSPRING", display = "Yellow Spring"}, [311] = {mt = "MT_REDSPRING", display = "Red Spring"}, [312] = {mt = "MT_YELLOWDIAG", display = "Yellow Diagonal Spring"}, [313] = {mt = "MT_REDDIAG", display = "Red Diagonal Spring"}, [314] = {mt = "MT_YELLOWHORIZ", display = "Yellow Horizontal Spring"}, [315] = {mt = "MT_REDHORIZ", display = "Red Horizontal Spring"}, [320] = {mt = "MT_YELLOWSPRING", display = "Yellow Spring"}, [321] = {mt = "MT_REDSPRING", display = "Red Spring"}, [322] = {mt = "MT_BLUESPRING", display = "Blue Spring"}, [323] = {mt = "MT_YELLOWHORIZ", display = "Yellow Horizontal Spring"}, [324] = {mt = "MT_REDHORIZ", display = "Red Horizontal Spring"}, [325] = {mt = "MT_YELLOWDIAG", display = "Yellow Diagonal Spring"}, [326] = {mt = "MT_REDDIAG", display = "Red Diagonal Spring"}, [330] = {mt = "MT_STARPOST", display = "Starpost Checkpoint"}, [331] = {mt = "MT_SIGN", display = "Level End Signpost"}, [332] = {mt = "MT_CAPSULE", display = "Egg Capsule"}, [700] = {mt = "MT_WATERDRIP", display = "Water Dripper"}, [701] = {mt = "MT_FLAME", display = "Flame Jet"}, [702] = {mt = "MT_STEAM", display = "Steam Jet"}, [703] = {mt = "MT_SPIKE", display = "Floor Spike"}, [704] = {mt = "MT_WALLSPIKE", display = "Wall Spike"}, [705] = {mt = "MT_GARGOYLE", display = "Gargoyle Statue"}, [706] = {mt = "MT_BUMPER", display = "Nights Bumper"}, [707] = {mt = "MT_BALLOON", display = "Nights Balloon"}, [708] = {mt = "MT_FAN", display = "Fan Vent"}, [709] = {mt = "MT_MINECART", display = "Minecart"}, [710] = {mt = "MT_BUBBLES", display = "Air Bubbles"}, [730] = {mt = "MT_CEZBANNER1",display = "Red Banner Sheet"}, [731] = {mt = "MT_CEZBANNER2",display = "Blue Banner Sheet"}, [732] = {mt = "MT_CEZPOLE1", display = "Red Banner Pole"}, [733] = {mt = "MT_CEZPOLE2", display = "Blue Banner Pole"}, [1] = {mt = "MT_BLUECRAWLA", display = "Blue Crawla"}, [2] = {mt = "MT_REDCRAWLA", display = "Red Crawla"}, [3] = {mt = "MT_GOLDBUZZ", display = "Gold Buzz"}, [4] = {mt = "MT_REDBUZZ", display = "Red Buzz"}, [5] = {mt = "MT_JETJAW", display = "Jetty-Syn Bomber"}, [6] = {mt = "MT_CRAWLACOMMANDER",display = "Crawla Commander"}, [7] = {mt = "MT_DETON", display = "Deton Bomb Enemy"}, [8] = {mt = "MT_SKIM", display = "Skim Water Enemy"}, [9] = {mt = "MT_POINTY", display = "Pointy Spike Enemy"}, [102] = {mt = "MT_ACKACK", display = "Ackack Enemy Cannon"} } local function cache_authoritative_mobj_name(name, value) if type(name) ~= "string" or type(value) ~= "number" then return end local upper = string_upper(name) if upper:sub(1,3) ~= "MT_" then return end if reverse_mt_cache[value] == nil or reverse_mt_inferred[value] then reverse_mt_cache[value] = upper reverse_mt_inferred[value] = nil end local norm = upper:sub(4):gsub("_", "") mobj_direct_lookup[norm] = value mobj_direct_lookup[upper] = value end local function cache_inferred_mobj_name(name, value) if reverse_mt_cache[value] == nil or reverse_mt_inferred[value] then reverse_mt_cache[value] = name reverse_mt_inferred[value] = true end return reverse_mt_cache[value] end local function harvest_logged_mobj_names() if logged_mobj_names_scanned then return end logged_mobj_names_scanned = true if netgame and not isserver then return end local engine_log = open_engine_log_for_read() if not engine_log then return end for line in engine_log:lines() do local upper_line = string_upper(line) local name = upper_line:match("MOBJTYPE%s+(MT_[A-Z0-9_]+)%s+ALLOCATED") if name then local value = safe_get_mt(name) if value ~= nil then declared_mobj_names[name] = value cache_authoritative_mobj_name(name, value) end end end engine_log:close() end local function harvest_debug_mobj_names() if not debug_registry_needs_scan then return end debug_registry_needs_scan = false local dbg = rawget(_G, "debug") if type(dbg) ~= "table" or type(dbg.getregistry) ~= "function" or type(dbg.getupvalue) ~= "function" then return end local ok_registry, registry = pcall(dbg.getregistry) if not ok_registry or type(registry) ~= "table" then return end local visited = {} local budget = 12000 local function visit(value, depth) if budget <= 0 or depth > 4 then return end local value_type = type(value) if value_type ~= "table" and value_type ~= "function" then return end if visited[value] then return end visited[value] = true budget = budget - 1 if value_type == "function" then for i = 1, 64 do local ok_upvalue, upname, upvalue = pcall(dbg.getupvalue, value, i) if not ok_upvalue or upname == nil then break end if type(upname) == "string" and upname:sub(1,3) == "MT_" and type(upvalue) == "number" then cache_authoritative_mobj_name(upname, upvalue) elseif type(upvalue) == "table" or type(upvalue) == "function" then visit(upvalue, depth + 1) end end return end for key, child in pairs(value) do budget = budget - 1 if budget <= 0 then break end if type(key) == "string" and key:sub(1,3) == "MT_" and type(child) == "number" then cache_authoritative_mobj_name(key, child) elseif type(child) == "table" or type(child) == "function" then visit(child, depth + 1) end end end pcall(visit, registry, 0) end local function refresh_mobj_type_cache(force_refresh) if not force_refresh and not mobj_name_cache_dirty then return end mobj_name_cache_dirty = false for _, name in ipairs(known_srb2_mt_names) do local val = safe_get_mt(name) if val ~= nil then cache_authoritative_mobj_name(name, val) end end if not engine_mobj_names_scanned then engine_mobj_names_scanned = true for _, name in ipairs(engine_mobj_names) do local val = safe_get_mt(name) if val ~= nil then cache_authoritative_mobj_name(name, val) end end end for name, value in pairs(declared_mobj_names) do cache_authoritative_mobj_name(name, value) end harvest_logged_mobj_names() for k, v in pairs(_G) do if type(k) == "string" and type(v) == "number" and k:sub(1,3) == "MT_" then cache_authoritative_mobj_name(k, v) end end harvest_debug_mobj_names() end addHook("AddonLoaded", function() logged_mobj_names_scanned = false debug_registry_needs_scan = true mobj_name_cache_dirty = true state_name_cache_dirty = true protected_types_initialized = false whitelist_type_cache = nil scan_type_cache = nil list_flag_cache = nil end) local function init_mobj_type_cache() if mobj_cache_initialized then return end mobj_cache_initialized = true refresh_mobj_type_cache() end local function getMobjFlag(name) if not name then return nil, nil end local rawName = string_upper(name:match("^%s*(.-)%s*$")):gsub("[^A-Z0-9_]", "") if flag_cache[rawName] ~= nil then return flag_cache[rawName].val, flag_cache[rawName].is_flags2 end local searchName = rawName if searchName:sub(1,4) == "MF2_" then searchName = searchName:sub(5) elseif searchName:sub(1,3) == "MF_" then searchName = searchName:sub(4) end if searchName == "BOUNCY" or searchName == "BOUNCING" then searchName = "BOUNCE" end local val = safe_get_mt("MF_" .. searchName) if val ~= nil then flag_cache[rawName] = {val = val, is_flags2 = false} return val, false end val = safe_get_mt("MF2_" .. searchName) if val ~= nil then flag_cache[rawName] = {val = val, is_flags2 = true} return val, true end return nil, nil end local function get_listable_mobj_flags() if list_flag_cache then return list_flag_cache end local all_flags = {} for k, v in pairs(_G) do if type(k) == "string" and type(v) == "number" and v ~= 0 then if k:sub(1,4) == "MF2_" then all_flags[#all_flags + 1] = {name=k, val=v, is2=true} elseif k:sub(1,3) == "MF_" then all_flags[#all_flags + 1] = {name=k, val=v, is2=false} end end end list_flag_cache = all_flags return all_flags end local function is_fire_object(mobj, scan_context) if not mobj or not mobj.valid then return false end local mf_fire = scan_context and scan_context.mf_fire or rawget(_G, "MF_FIRE") if mf_fire ~= nil and (mobj.flags & mf_fire) ~= 0 then return true end local mf2_fire = scan_context and scan_context.mf2_fire or rawget(_G, "MF2_FIRE") if mf2_fire ~= nil and (mobj.flags2 & mf2_fire) ~= 0 then return true end return false end local hostile_mobj_flags = MF_ENEMY | MF_BOSS local function is_hostile_mobj(mobj) if not mobj or not mobj.valid then return false end if (mobj.flags & hostile_mobj_flags) ~= 0 then return true end local info = mobjinfo[mobj.type] return info and (info.flags & hostile_mobj_flags) ~= 0 or false end local function is_attached_to_player(mobj, scan_context) if not mobj or not mobj.valid then return false end if is_protected_player_mobj(mobj) then return true end local mt_overlay = scan_context and scan_context.mt_overlay or safe_get_mt("MT_OVERLAY") if mt_overlay ~= nil and mobj.type == mt_overlay then if mobj.target and mobj.target.valid and is_protected_player_mobj(mobj.target) then return true end end if scan_context then return scan_context.player_attachments[mobj] == true end for p in players.iterate do if p and p.valid then if p.mo == mobj then return true end if p.followmobj == mobj then return true end if p.awayviewmobj == mobj then return true end end end return false end local function get_object_type_context() if scan_type_cache then return scan_type_cache end local context = { banner_types = {}, goal_types = {}, flicky_types = {}, mt_overlay = safe_get_mt("MT_OVERLAY"), mt_chain = safe_get_mt("MT_CHAIN"), mt_chainpoint = safe_get_mt("MT_CHAINPOINT"), mt_starpost = safe_get_mt("MT_STARPOST"), mt_sign = safe_get_mt("MT_SIGN"), mt_gotflag = safe_get_mt("MT_GOTFLAG"), mt_finishflag = safe_get_mt("MT_FINISHFLAG"), mt_bumper = safe_get_mt("MT_BUMPER"), mt_balloon = safe_get_mt("MT_BALLOON"), mt_smallgrabchain = safe_get_mt("MT_SMALLGRABCHAIN"), mt_biggrabchain = safe_get_mt("MT_BIGGRABCHAIN"), mt_ring = safe_get_mt("MT_RING"), mt_flingring = safe_get_mt("MT_FLINGRING"), mt_token = safe_get_mt("MT_TOKEN"), mf_ring = safe_get_mt("MF_RING"), mf_fire = safe_get_mt("MF_FIRE"), mf2_fire = safe_get_mt("MF2_FIRE") } for _, const_name in ipairs(general_mappings["BANNER"] or {}) do local val = safe_get_mt(const_name) if val ~= nil then context.banner_types[val] = true end end local goal_names = { "MT_SIGN", "MT_SIGNPOST", "MT_GOALSIGN", "MT_GOALPOST", "MT_ENDSIGN", "MT_LEVELEND", "MT_NIGHTSGOAL" } for _, const_name in ipairs(goal_names) do local val = safe_get_mt(const_name) if val ~= nil then context.goal_types[val] = true end end local flicky_names = { "MT_FLICKY_01", "MT_FLICKY_02", "MT_FLICKY_03", "MT_FLICKY_04", "MT_FLICKY_05", "MT_FLICKY_06", "MT_FLICKY_07", "MT_FLICKY_08", "MT_FLICKY_09", "MT_FLICKY_10", "MT_FLICKY_11", "MT_FLICKY_12", "MT_FLICKY_13", "MT_FLICKY_14", "MT_FLICKY_15", "MT_FLICKY_16", "MT_BIRD", "MT_SQRL", "MT_BUNNY", "MT_CHICK", "MT_SEAL", "MT_PIG", "MT_COW", "MT_FLICKY", "MT_SECRETFLICKY_01", "MT_SECRETFLICKY_02" } for _, const_name in ipairs(flicky_names) do local val = safe_get_mt(const_name) if val ~= nil then context.flicky_types[val] = true end end scan_type_cache = context return context end local function build_object_scan_context() local types = get_object_type_context() local context = { banner_results = {}, chain_results = {}, grabbable_chain_results = {}, banner_types = types.banner_types, goal_types = types.goal_types, flicky_types = types.flicky_types, player_attachments = {}, mt_overlay = types.mt_overlay, mt_chain = types.mt_chain, mt_chainpoint = types.mt_chainpoint, mt_starpost = types.mt_starpost, mt_sign = types.mt_sign, mt_gotflag = types.mt_gotflag, mt_finishflag = types.mt_finishflag, mt_bumper = types.mt_bumper, mt_balloon = types.mt_balloon, mt_smallgrabchain = types.mt_smallgrabchain, mt_biggrabchain = types.mt_biggrabchain, mt_ring = types.mt_ring, mt_flingring = types.mt_flingring, mt_token = types.mt_token, mf_ring = types.mf_ring, mf_fire = types.mf_fire, mf2_fire = types.mf2_fire } local attachment_frontier = {} local function add_player_attachment(attachment) if attachment and attachment.valid and not context.player_attachments[attachment] then context.player_attachments[attachment] = true attachment_frontier[#attachment_frontier + 1] = attachment end end for p in players.iterate do if p and p.valid then add_player_attachment(p.mo) add_player_attachment(p.followmobj) add_player_attachment(p.awayviewmobj) local direct_attachments = { p.heldChao, p.heldKimiko, p.heldGARDEVOIR, p.pet } for _, attachment in ipairs(direct_attachments) do add_player_attachment(attachment) end local attachment_lists = { p.heldChaos, p.heldKimikos, p.heldGARDEVOIRs, p.tdfCarryOrder } for _, list in ipairs(attachment_lists) do if type(list) == "table" then for _, attachment in ipairs(list) do add_player_attachment(attachment) end end end end end while #attachment_frontier > 0 do local next_frontier = {} for _, attachment in ipairs(attachment_frontier) do local linked_objects = {attachment.hnext, attachment.hprev} for _, linked in ipairs(linked_objects) do if linked and linked.valid and not context.player_attachments[linked] then context.player_attachments[linked] = true next_frontier[#next_frontier + 1] = linked end end end attachment_frontier = next_frontier end return context end local function init_light_flags() if #light_flags > 0 then return end local names = {"SCENERY", "AMBIENT", "FIRE"} for _, name in ipairs(names) do local val, is_flags2 = getMobjFlag(name) if val ~= nil then table.insert(light_flags, {val = val, is_flags2 = is_flags2}) end end end local function is_valid_mobj_type_number(mobj_type) if type(mobj_type) ~= "number" or mobj_type < 0 then return false end local ok, info = pcall(function() return mobjinfo[mobj_type] end) return ok and info ~= nil end getMobjType = function(name) if not name then return nil end local rawInput = name:match("^%s*(.-)%s*$") if not rawInput then return nil end local num = tonumber(rawInput) if num ~= nil and num >= 0 then if is_valid_mobj_type_number(num) then return num end return nil end local cleanKey = string_upper(rawInput):gsub("[^A-Z0-9_]", "") if type_cache[cleanKey] ~= nil then return type_cache[cleanKey] end init_mobj_type_cache() local searchNorm = cleanKey if searchNorm:sub(1,3) == "MT_" then searchNorm = searchNorm:sub(4) end searchNorm = searchNorm:gsub("_", "") if mobj_direct_lookup[searchNorm] ~= nil then type_cache[cleanKey] = mobj_direct_lookup[searchNorm] return mobj_direct_lookup[searchNorm] end local typeName = cleanKey if typeName:sub(1,3) ~= "MT_" then typeName = "MT_" .. typeName end local val = safe_get_mt(typeName) if val ~= nil then cache_authoritative_mobj_name(typeName, val) type_cache[cleanKey] = val return val end return nil end local function max(a, b) if a > b then return a end return b end local known_type_id_table = { [0] = {mt = "MT_NULL", display = "Null Object"}, [1] = {mt = "MT_UNKNOWN", display = "Unknown Object"}, [2] = {mt = "MT_THOK", display = "Thok Object"}, [3] = {mt = "MT_PLAYER", display = "Player"}, [4] = {mt = "MT_TAILSOVERLAY", display = "Tails Overlay"}, [5] = {mt = "MT_METALJETFUME", display = "Metal Sonic Jet Fume"}, [6] = {mt = "MT_BLUECRAWLA", display = "Blue Crawla"}, [7] = {mt = "MT_REDCRAWLA", display = "Red Crawla"}, [8] = {mt = "MT_GFZFISH", display = "Greenflower Fish"}, [9] = {mt = "MT_GOLDBUZZ", display = "Gold Buzz"}, [10] = {mt = "MT_REDBUZZ", display = "Red Buzz"} } local function get_mobj_type_name(mobj_type, mobj_sample) if mobj_type == nil then return "MT_UNKNOWN" end init_mobj_type_cache() if reverse_mt_cache[mobj_type] and not reverse_mt_inferred[mobj_type] then return reverse_mt_cache[mobj_type] end if mobj_type ~= nil and known_type_id_table[mobj_type] then local formatted = known_type_id_table[mobj_type].mt if safe_get_mt(formatted) == mobj_type then cache_authoritative_mobj_name(formatted, mobj_type) return formatted end end local doomednum = 0 pcall(function() if mobjinfo and mobj_type ~= nil and mobjinfo[mobj_type] then doomednum = mobjinfo[mobj_type].doomednum or 0 end end) if doomednum > 0 and known_doomednum_table[doomednum] then local formatted = known_doomednum_table[doomednum].mt if safe_get_mt(formatted) == mobj_type then cache_authoritative_mobj_name(formatted, mobj_type) return formatted end end for k, v in pairs(_G) do if type(k) == "string" and type(v) == "number" and v == mobj_type then local upper_k = string_upper(k) if upper_k:sub(1,3) == "MT_" then cache_authoritative_mobj_name(upper_k, mobj_type) end end end if reverse_mt_cache[mobj_type] and not reverse_mt_inferred[mobj_type] then return reverse_mt_cache[mobj_type] end local info_name = "" pcall(function() if mobjinfo and mobj_type ~= nil and mobjinfo[mobj_type] then local n = mobjinfo[mobj_type].name if type(n) == "string" and n ~= "" then info_name = n end end end) if info_name == "" and mobj_sample and mobj_sample.valid then pcall(function() local n = mobj_sample.info.name if type(n) == "string" and n ~= "" then info_name = n end end) end if info_name ~= "" then local formatted = "" if info_name:upper():sub(1,3) == "MT_" then formatted = info_name:upper() else local clean_var = info_name:upper():gsub("[^A-Z0-9_]", "_"):gsub("_+", "_"):gsub("^_", ""):gsub("_$", "") if clean_var ~= "" then formatted = "MT_" .. clean_var end end if formatted ~= "" then local verified = safe_get_mt(formatted) if verified == mobj_type then cache_authoritative_mobj_name(formatted, mobj_type) return formatted end end end if get_spawnstate_type_name then local state_type_name = get_spawnstate_type_name(mobj_sample, mobj_type) if state_type_name ~= "" then cache_authoritative_mobj_name(state_type_name, mobj_type) return state_type_name end end local spr_name = "" pcall(function() if mobj_sample and mobj_sample.valid and mobj_sample.sprite ~= nil and sprnames and sprnames[mobj_sample.sprite] then local sn = tostring(sprnames[mobj_sample.sprite]):match("^%s*(.-)%s*$"):upper():gsub("[^A-Z0-9_]", "") if sn ~= "" and sn ~= "NULL" and sn ~= "UNK" then spr_name = sn end end end) if spr_name == "" then pcall(function() if mobjinfo and mobj_type ~= nil and mobjinfo[mobj_type] and sprnames then local s = mobjinfo[mobj_type].sprite if s ~= nil and sprnames[s] then local sn = tostring(sprnames[s]):match("^%s*(.-)%s*$"):upper():gsub("[^A-Z0-9_]", "") if sn ~= "" and sn ~= "NULL" and sn ~= "UNK" then spr_name = sn end end end end) end if spr_name ~= "" then sprite_name_cache[mobj_type] = spr_name end if doomednum > 0 then local formatted = "MT_THING_" .. tostring(doomednum) return cache_inferred_mobj_name(formatted, mobj_type) end local fallback = "MT_TYPE_" .. tostring(mobj_type) return cache_inferred_mobj_name(fallback, mobj_type) end local function format_mt_display_name(mt_name) if not mt_name or mt_name == "" or mt_name == "MT_UNKNOWN" then return "" end local s = mt_name if s:sub(1,3) == "MT_" then s = s:sub(4) end if s:sub(1,6) == "THING_" then return "Thing #" .. s:sub(7) end if s:sub(1,5) == "TYPE_" then return "Type #" .. s:sub(6) end local words = {} for word in s:gmatch("[^_]+") do local formatted_word = word:sub(1,1):upper() .. word:sub(2):lower() table.insert(words, formatted_word) end return table.concat(words, " ") end local function cache_state_name(name, value, declared) if type(name) ~= "string" or type(value) ~= "number" then return end local upper = string_upper(name) if upper:sub(1,2) ~= "S_" then return end local score = 0 if not upper:match("%d+$") then score = score + 10 end if declared then score = score + 40 end if upper ~= "S_NULL" and upper ~= "S_INVISIBLE" and upper ~= "S_SPAWNSTATE" then score = score + 20 end if upper:find("FIRSTFREESLOT", 1, true) or upper:find("LASTFREESLOT", 1, true) or upper == "S_NUMSTATES" then score = score - 100 end if reverse_state_cache[value] == nil or score > (reverse_state_score[value] or -1000) then reverse_state_cache[value] = upper reverse_state_score[value] = score end end refresh_state_name_cache = function(force_refresh) if not force_refresh and not state_name_cache_dirty then return end state_name_cache_dirty = false for name, value in pairs(declared_state_names) do cache_state_name(name, value, true) end for k, v in pairs(_G) do if type(k) == "string" and type(v) == "number" and k:sub(1,2) == "S_" then cache_state_name(k, v, false) end end end local function init_state_name_cache() if state_name_cache_dirty or next(reverse_state_cache) == nil then refresh_state_name_cache() end end local function get_spawnstate_number(mobj_sample, mobj_type) local state_num = nil pcall(function() if mobjinfo and mobj_type ~= nil and mobjinfo[mobj_type] then state_num = mobjinfo[mobj_type].spawnstate end end) if state_num == nil and mobj_sample and mobj_sample.valid then pcall(function() state_num = mobj_sample.info.spawnstate end) end return state_num end local function get_spawnstate_enum_name(mobj_sample, mobj_type) local state_num = get_spawnstate_number(mobj_sample, mobj_type) if state_num == nil then return "" end init_state_name_cache() local state_name = reverse_state_cache[state_num] if not state_name or state_name == "S_NULL" or state_name == "S_INVISIBLE" or state_name == "S_SPAWNSTATE" then return "" end return state_name end get_spawnstate_type_name = function(mobj_sample, mobj_type) local state_name = get_spawnstate_enum_name(mobj_sample, mobj_type) if state_name == "" then return "" end local raw_name = state_name:sub(3):gsub("%d+$", ""):gsub("_$", "") if raw_name == "" then return "" end local candidates = {raw_name} local stripped = raw_name:gsub("_SPAWNSTATE$", ""):gsub("_SPAWN$", "") :gsub("_IDLE$", ""):gsub("_STND$", ""):gsub("_STAND$", "") if stripped ~= "" and stripped ~= raw_name then table.insert(candidates, stripped) end for _, candidate in ipairs(candidates) do local mt_name = "MT_" .. candidate if safe_get_mt(mt_name) == mobj_type then return mt_name end end return "" end local function get_spawnstate_display_name(mobj_sample, mobj_type) local state_name = get_spawnstate_enum_name(mobj_sample, mobj_type) if state_name == "" then return "" end local raw_name = state_name:sub(3):gsub("%d+$", "") if raw_name == "" then return "" end return format_mt_display_name("MT_" .. raw_name) end local function get_mobj_display_name(mobj_sample, mobj_type) local display = "" pcall(function() if mobjinfo and mobj_type ~= nil and mobjinfo[mobj_type] then local n = mobjinfo[mobj_type].name if type(n) == "string" and n ~= "" then display = n end end end) if display == "" and mobj_sample and mobj_sample.valid then pcall(function() local n = mobj_sample.info.name if type(n) == "string" and n ~= "" then display = n end end) end local mt_name = (mobj_type ~= nil and reverse_mt_cache[mobj_type]) or "" local has_authoritative_mt_name = mt_name ~= "" and not reverse_mt_inferred[mobj_type] if display == "" and has_authoritative_mt_name and known_srb2_display_titles[mt_name] then display = known_srb2_display_titles[mt_name] end if display == "" and has_authoritative_mt_name then display = format_mt_display_name(mt_name) end if display == "" then display = get_spawnstate_display_name(mobj_sample, mobj_type) end if display == "" and mobj_type ~= nil and known_type_id_table[mobj_type] then display = known_type_id_table[mobj_type].display end local doomednum = 0 pcall(function() if mobjinfo and mobj_type ~= nil and mobjinfo[mobj_type] then doomednum = mobjinfo[mobj_type].doomednum or 0 end end) if display == "" and doomednum > 0 and known_doomednum_table[doomednum] then display = known_doomednum_table[doomednum].display end if display == "" and sprite_name_cache[mobj_type] then display = format_mt_display_name("MT_" .. sprite_name_cache[mobj_type]) end if display == "" and mt_name ~= "" then display = format_mt_display_name(mt_name) end if display == "" then local type_label = mobj_type ~= nil and tostring(mobj_type) or "Unknown" display = "Object Type #" .. type_label end return display end local function is_banner_object(mobj, scan_context) if not mobj or not mobj.valid then return false end local mt = mobj.type if scan_context and scan_context.banner_results[mt] ~= nil then return scan_context.banner_results[mt] end local is_banner = scan_context and scan_context.banner_types[mt] == true or false if not is_banner and not scan_context then local clean_banner = general_mappings["BANNER"] if clean_banner then for _, const_name in ipairs(clean_banner) do local val = safe_get_mt(const_name) if val ~= nil and mt == val then is_banner = true break end end end end local mt_name = nil if not is_banner then mt_name = get_mobj_type_name(mt, mobj) end if mt_name and mt_name ~= "" then local u = mt_name:upper() if u:find("BANNER") or u:find("POLE") or u:find("FLAG") then is_banner = true end end if not is_banner then local display = get_mobj_display_name(mobj, mt):upper() if display ~= "" and (display:find("BANNER") or display:find("POLE") or display:find("FLAG")) then is_banner = true end end if scan_context then scan_context.banner_results[mt] = is_banner end return is_banner end local function is_light_scenery_object(mobj, scan_context) if not mobj or not mobj.valid then return false end if mobj.player ~= nil or mobj.type == MT_PLAYER then return false end local flags = mobj.flags local flags2 = mobj.flags2 local info = mobjinfo[mobj.type] local info_flags = info and info.flags or 0 if (flags & (MF_SCENERY | MF_AMBIENT | MF_FIRE)) ~= 0 or (info_flags & (MF_SCENERY | MF_AMBIENT | MF_FIRE)) ~= 0 or is_fire_object(mobj, scan_context) or is_banner_object(mobj, scan_context) then return true end local mt = mobj.type local mt_name = get_mobj_type_name(mt, mobj) if mt_name and mt_name ~= "" then local u = string_upper(mt_name) if u:find("POLE") or u:find("BANNER") or u:find("FLAG") or u:find("TORCH") or u:find("FLAME") or u:find("CANDLE") or u:find("LAMP") or u:find("STATUE") or u:find("GARGOYLE") or u:find("GOYLE") or u:find("TREE") or u:find("BUSH") or u:find("FLOWER") or u:find("PLANT") or u:find("STALAGMITE") or u:find("CORAL") or u:find("SEAWEED") or u:find("KELP") or u:find("CACTI") or u:find("CACTUS") or u:find("FERN") or u:find("VINE") or u:find("TUMBLEWEED") or u:find("ROCK") or u:find("DEBRIS") or u:find("SHROOM") then return true end end return false end local function remove_single_mobj(mobj) if not mobj or not mobj.valid or is_protected_player_mobj(mobj) then return false end local called = pcall(P_RemoveMobj, mobj) return called and not mobj.valid end local traverse_token = 0 local traverse_marks = setmetatable({}, {__mode = "k"}) local tracked_objects = {} local tracked_object_set = setmetatable({}, {__mode = "k"}) local feature_state = { tracked_registry_complete = false, clearable_spike_chain_type_set = nil, saved_objectcolor_preference = "none", player_copies_by_target = {}, player_copy_registry = setmetatable({}, {__mode = "k"}), player_copy_generations = setmetatable({}, {__mode = "k"}), clone_appearance_cache = {}, allowattach_players = {}, saved_allowattach_preference = "on", allowattach_restore_attempted = false, priority_removals = {}, priority_removal_head = 1, priority_removal_tail = 0, priority_removal_types = nil, pending_removal_tail = 0, compact_registry_when_idle = false, next_object_serial = 0 } feature_state.has_terminal_permission = function(player, level_name, tighten_in_ringslinger) if not player or not player.valid then return false end if #player == 0 then return true end if IsPlayerAdmin and IsPlayerAdmin(player) then return true end local term = rawget(_G, "terminal") if type(term) ~= "table" or type(term.permissions) ~= "table" or type(term.permissions.text) ~= "table" then return false end local required = term.permissions.text[level_name] if tighten_in_ringslinger then local ringslinger_rule = rawget(_G, "GTR_RINGSLINGER") if type(ringslinger_rule) == "number" and (gametyperules & ringslinger_rule) ~= 0 then required = term.permissions.text.L3 end end local granted = player.servperm or 0 return type(required) == "number" and type(granted) == "number" and (granted & required) == required end feature_state.is_priority_removal = function(mobj) if not mobj or not mobj.valid then return false end if not feature_state.priority_removal_types then feature_state.priority_removal_types = {} local transient_names = { "MT_SOUND", "MT_MUSIC3D", "MT_OVERLAY", "MT_PARTICLEGEN", "MT_PARTICLE", "MT_SUPERSPARK", "MT_SPARK", "MT_BOXSPARKLE", "MT_THUNDERCOIN_SPARK", "MT_FLAMEPARTICLE", "MT_SMOKE", "MT_DUST", "MT_TFOG", "MT_EXPLODE", "MT_UWEXPLODE" } for _, type_name in ipairs(transient_names) do local mobj_type = safe_get_mt(type_name) if mobj_type ~= nil then feature_state.priority_removal_types[mobj_type] = true end end end if feature_state.priority_removal_types[mobj.type] then return true end if mobj.fuse ~= nil and mobj.fuse > 0 then return true end return mobj.spawnpoint == nil and (mobj.flags & (MF_SCENERY | MF_NOSECTOR)) ~= 0 end feature_state.is_invisible_controller = function(mobj) if not (mobj and mobj.valid) then return false end local hidden = mobj.sprite == SPR_NULL or (mobj.flags2 & MF2_DONTDRAW) ~= 0 or (mobj.alpha ~= nil and mobj.alpha <= 0) or (mobj.spritexscale ~= nil and mobj.spritexscale < 1) or (mobj.spriteyscale ~= nil and mobj.spriteyscale < 1) if not hidden then return false end if feature_state.is_priority_removal(mobj) then return false end if mobj.spawned_by ~= nil or is_spawned_player_copy(mobj) then return false end return true end local pending_removal_set local function track_object_for_traversal(mobj) if not (mobj and mobj.valid) or tracked_object_set[mobj] then return end if mobj.clearobjects_serial == nil then feature_state.next_object_serial = (feature_state.next_object_serial or 0) + 1 mobj.clearobjects_serial = feature_state.next_object_serial end tracked_object_set[mobj] = true tracked_objects[#tracked_objects + 1] = mobj end addHook("MobjSpawn", function(mobj) if (mobj.flags & MF_AMBIENT) ~= 0 then guard_ambient_interval(mobj) end track_object_for_traversal(mobj) end) addHook("MapThingSpawn", function(mobj) if (mobj.flags & MF_AMBIENT) ~= 0 then guard_ambient_interval(mobj) end track_object_for_traversal(mobj) end) addHook("MapChange", function() tracked_objects = {} tracked_object_set = setmetatable({}, {__mode = "k"}) feature_state.tracked_registry_complete = false feature_state.next_object_serial = 0 feature_state.player_copies_by_target = {} feature_state.player_copy_registry = setmetatable({}, {__mode = "k"}) feature_state.player_copy_generations = setmetatable({}, {__mode = "k"}) feature_state.clone_appearance_cache = {} end) local function traverse_all_objects(consider_fn) traverse_token = (traverse_token or 0) + 1 local current_token = traverse_token local function handle_mobj(mobj) if not (mobj and mobj.valid) then return end if pending_removal_set and pending_removal_set[mobj] then return end if traverse_marks[mobj] == current_token then return end traverse_marks[mobj] = current_token track_object_for_traversal(mobj) consider_fn(mobj) end local old_count = #tracked_objects local write_index = 1 for read_index = 1, old_count do local mobj = tracked_objects[read_index] if mobj and mobj.valid and not (pending_removal_set and pending_removal_set[mobj]) then tracked_objects[write_index] = mobj write_index = write_index + 1 if traverse_marks[mobj] ~= current_token then traverse_marks[mobj] = current_token consider_fn(mobj) end end end for index = write_index, old_count do tracked_objects[index] = nil end if not feature_state.tracked_registry_complete then for mobj in mobjs.iterate() do handle_mobj(mobj) end pcall(function() for mt in mapthings.iterate do if mt and mt.mobj then handle_mobj(mt.mobj) end end end) pcall(function() for sec in sectors.iterate do if sec and sec.valid then for mobj in sec.thinglist() do handle_mobj(mobj) end end end end) feature_state.tracked_registry_complete = true end end local MAX_REMOVAL_RETRIES = 3 local pending_removals = {} pending_removal_set = setmetatable({}, {__mode = "k"}) local pending_removal_head = 1 local function queue_object_removal(mobj) if not mobj or not mobj.valid or is_protected_player_mobj(mobj) then return false end if pending_removal_set[mobj] then return false end local priority = feature_state.is_priority_removal(mobj) pending_removal_set[mobj] = true if priority then feature_state.priority_removal_tail = (feature_state.priority_removal_tail or 0) + 1 feature_state.priority_removals[feature_state.priority_removal_tail] = mobj else feature_state.pending_removal_tail = (feature_state.pending_removal_tail or 0) + 1 pending_removals[feature_state.pending_removal_tail] = mobj end feature_state.compact_registry_when_idle = true return true end feature_state.sort_pending_removal_queues = function() local priority = {} local normal = {} local controllers = {} for i = feature_state.priority_removal_head or 1, feature_state.priority_removal_tail or 0 do local mobj = feature_state.priority_removals[i] if mobj and mobj.valid and pending_removal_set[mobj] then priority[#priority + 1] = mobj end end for i = pending_removal_head or 1, feature_state.pending_removal_tail or 0 do local mobj = pending_removals[i] if mobj and mobj.valid and pending_removal_set[mobj] then normal[#normal + 1] = mobj controllers[mobj] = feature_state.is_invisible_controller(mobj) end end local function earlier_spawn(a, b) local a_serial = a.clearobjects_serial or 2147483647 local b_serial = b.clearobjects_serial or 2147483647 if a_serial ~= b_serial then return a_serial < b_serial end if a.type ~= b.type then return a.type < b.type end if a.x ~= b.x then return a.x < b.x end if a.y ~= b.y then return a.y < b.y end if a.z ~= b.z then return a.z < b.z end if a.angle ~= b.angle then return a.angle < b.angle end return false end table.sort(priority, earlier_spawn) table.sort(normal, function(a, b) if controllers[a] ~= controllers[b] then return controllers[b] end return earlier_spawn(a, b) end) feature_state.priority_removals = priority feature_state.priority_removal_head = 1 feature_state.priority_removal_tail = #priority pending_removals = normal pending_removal_head = 1 feature_state.pending_removal_tail = #normal end feature_state.compact_tracked_registry = function() local compacted = {} tracked_object_set = setmetatable({}, {__mode = "k"}) for _, mobj in ipairs(tracked_objects) do if mobj and mobj.valid and not pending_removal_set[mobj] then tracked_object_set[mobj] = true compacted[#compacted + 1] = mobj end end tracked_objects = compacted end local function move_object_for_rally(mobj, x, y, z, angle) if not mobj or not mobj.valid or is_protected_player_mobj(mobj) then return false end if pending_removal_set[mobj] then return false end local placed = pcall(P_SetOrigin, mobj, x, y, z) if not placed or not mobj.valid then return false end pcall(function() mobj.angle = angle mobj.momx = 0 mobj.momy = 0 mobj.momz = 0 end) return mobj.valid end feature_state.remove_queued_snapshot = function(objects, first, last) for index = first, last do local mobj = objects[index] objects[index] = nil if mobj then if mobj.valid and pending_removal_set[mobj] then for attempt = 1, MAX_REMOVAL_RETRIES do if remove_single_mobj(mobj) or not mobj.valid then break end end end pending_removal_set[mobj] = nil end end end addHook("PostThinkFrame", function() if feature_state.priority_removal_tail > 0 or feature_state.pending_removal_tail > 0 then local priority = feature_state.priority_removals local priority_head = feature_state.priority_removal_head local priority_tail = feature_state.priority_removal_tail local normal = pending_removals local normal_head = pending_removal_head local normal_tail = feature_state.pending_removal_tail feature_state.priority_removals = {} feature_state.priority_removal_head = 1 feature_state.priority_removal_tail = 0 pending_removals = {} pending_removal_head = 1 feature_state.pending_removal_tail = 0 feature_state.remove_queued_snapshot(priority, priority_head, priority_tail) feature_state.remove_queued_snapshot(normal, normal_head, normal_tail) end if feature_state.priority_removal_tail == 0 and feature_state.pending_removal_tail == 0 and feature_state.compact_registry_when_idle then feature_state.compact_tracked_registry() feature_state.compact_registry_when_idle = false end end) addHook("MapLoad", function() pending_removals = {} pending_removal_set = setmetatable({}, {__mode = "k"}) pending_removal_head = 1 feature_state.pending_removal_tail = 0 feature_state.priority_removals = {} feature_state.priority_removal_head = 1 feature_state.priority_removal_tail = 0 feature_state.compact_registry_when_idle = false traverse_marks = setmetatable({}, {__mode = "k"}) feature_state.tracked_registry_complete = #tracked_objects > 0 end) addHook("NetVars", function(net) feature_state.next_object_serial = net(feature_state.next_object_serial or 0) local registry = {} for _, mobj in ipairs(tracked_objects) do if mobj and mobj.valid then registry[#registry + 1] = mobj end end local registry_count = net(#registry) registry = net(registry) or {} tracked_objects = {} feature_state.tracked_registry_complete = net(feature_state.tracked_registry_complete) tracked_object_set = setmetatable({}, {__mode = "k"}) for index = 1, registry_count do local mobj = registry[index] if mobj and mobj.valid then tracked_objects[#tracked_objects + 1] = mobj tracked_object_set[mobj] = true else feature_state.tracked_registry_complete = false end end traverse_token = 0 traverse_marks = setmetatable({}, {__mode = "k"}) local remaining_priority = {} local remaining_normal = {} if feature_state.priority_removals then for i = feature_state.priority_removal_head or 1, feature_state.priority_removal_tail or 0 do local mobj = feature_state.priority_removals[i] if mobj and mobj.valid then remaining_priority[#remaining_priority + 1] = mobj end end end if pending_removals then for i = pending_removal_head or 1, feature_state.pending_removal_tail or 0 do local mobj = pending_removals[i] if mobj and mobj.valid then remaining_normal[#remaining_normal + 1] = mobj end end end local priority_count = net(#remaining_priority) local normal_count = net(#remaining_normal) remaining_priority = net(remaining_priority) or {} remaining_normal = net(remaining_normal) or {} feature_state.priority_removals = {} feature_state.priority_removal_head = 1 feature_state.priority_removal_tail = 0 pending_removals = {} pending_removal_head = 1 feature_state.pending_removal_tail = 0 pending_removal_set = setmetatable({}, {__mode = "k"}) for index = 1, priority_count do local mobj = remaining_priority[index] if mobj and mobj.valid then pending_removal_set[mobj] = true feature_state.priority_removal_tail = feature_state.priority_removal_tail + 1 feature_state.priority_removals[feature_state.priority_removal_tail] = mobj end end for index = 1, normal_count do local mobj = remaining_normal[index] if mobj and mobj.valid then pending_removal_set[mobj] = true feature_state.pending_removal_tail = feature_state.pending_removal_tail + 1 pending_removals[feature_state.pending_removal_tail] = mobj end end feature_state.compact_registry_when_idle = #remaining_priority > 0 or #remaining_normal > 0 end) local function calculate_spawn_coords(mo, i, total_qty, shape_name, dist_option, is_tower) local formation_scale = mo.scale or FRACUNIT local base_dist = 100 local base_shape = 120 local base_spacing = 80 local step_height = 64 if dist_option == "short" then base_dist = 250 base_shape = 300 base_spacing = 150 step_height = 64 elseif dist_option == "medium" or dist_option == "med" then base_dist = 500 base_shape = 600 base_spacing = 300 step_height = 96 elseif dist_option == "far" then base_dist = 750 base_shape = 900 base_spacing = 450 step_height = 128 end local items_per_layer = 10 local active_shape = shape_name local layer = 0 local item_idx = i local count_in_layer = total_qty if is_tower or shape_name == "tower" then layer = (i - 1) / items_per_layer item_idx = ((i - 1) % items_per_layer) + 1 count_in_layer = items_per_layer if not active_shape or active_shape == "tower" then active_shape = "circle" end end local z_offset = layer * FixedMul(step_height * FRACUNIT, formation_scale) if active_shape == "self" or dist_option == "self" then return mo.x, mo.y, mo.z + z_offset end local cosA = cos(mo.angle) local sinA = sin(mo.angle) if not active_shape or active_shape == "default" then local scaled_dist = FixedMul(base_dist * FRACUNIT, formation_scale) local spawnX = mo.x + FixedMul(scaled_dist, cosA) local spawnY = mo.y + FixedMul(scaled_dist, sinA) return spawnX, spawnY, mo.z + z_offset end local x_rel = 0 local y_rel = 0 if active_shape == "circle" then local R = base_shape local angle_offset = (item_idx - 1) * 360 / count_in_layer local angle_i = mo.angle + (angle_offset * ANG1) local scaled_radius = FixedMul(R * FRACUNIT, formation_scale) local spawnX = mo.x + FixedMul(scaled_radius, cos(angle_i)) local spawnY = mo.y + FixedMul(scaled_radius, sin(angle_i)) return spawnX, spawnY, mo.z + z_offset elseif active_shape == "square" then local S = base_shape local t = (item_idx - 1) * 4000 / count_in_layer if t < 1000 then x_rel = S y_rel = -S + 2 * S * t / 1000 elseif t < 2000 then x_rel = S - 2 * S * (t - 1000) / 1000 y_rel = S elseif t < 3000 then x_rel = -S y_rel = S - 2 * S * (t - 2000) / 1000 else x_rel = -S + 2 * S * (t - 3000) / 1000 y_rel = -S end elseif active_shape == "triangle" then local R = base_shape local t = (item_idx - 1) * 3000 / count_in_layer if t < 1000 then x_rel = R - 3 * R * t / 2000 y_rel = R * 866 * t / 1000000 elseif t < 2000 then x_rel = -R / 2 y_rel = R * 866 / 1000 - R * 1732 * (t - 1000) / 1000000 else x_rel = -R / 2 + 3 * R * (t - 2000) / 2000 y_rel = -R * 866 / 1000 + R * 866 * (t - 2000) / 1000000 end elseif active_shape == "line" then local row = (item_idx - 1) / 3 local col = (item_idx - 1) % 3 x_rel = base_dist + row * base_spacing y_rel = (1 - col) * base_spacing elseif active_shape == "straight" or active_shape == "singleline" or active_shape == "1line" then x_rel = base_dist + (item_idx - 1) * base_spacing y_rel = 0 end local x_rel_fixed = FixedMul(x_rel * FRACUNIT, formation_scale) local y_rel_fixed = FixedMul(y_rel * FRACUNIT, formation_scale) local spawnX = mo.x + FixedMul(x_rel_fixed, cosA) - FixedMul(y_rel_fixed, sinA) local spawnY = mo.y + FixedMul(x_rel_fixed, sinA) + FixedMul(y_rel_fixed, cosA) return spawnX, spawnY, mo.z + z_offset end local chain_mace_type_set = nil local function init_chain_mace_types() if chain_mace_type_set ~= nil then return end chain_mace_type_set = {} feature_state.clearable_spike_chain_type_set = {} local names = { "MT_SMALLGRABCHAIN", "MT_BIGGRABCHAIN", "MT_SMALLMACECHAIN", "MT_BIGMACECHAIN", "MT_SMALLMACE", "MT_BIGMACE", "MT_CHAIN", "MT_CEZCHAIN", "MT_CEZHOOK", "MT_CEZROPE", "MT_CHAINPOINT", "MT_CHAINMACEPOINT", "MT_CUSTOMMACEPOINT", "MT_MACEPOINT", "MT_CRUSHCHAIN", "MT_FIREBAR", "MT_FIREBARSEG", "MT_AXIS", "MT_AXISTRANSFER", "MT_AXISTRANSFERLINE", "MT_FJSPINAXISA", "MT_FJSPINAXISB", "MT_EGGMOBILE4_MACE" } for _, n in ipairs(names) do local val = safe_get_mt(n) if val ~= nil then chain_mace_type_set[val] = true end end local clearable_names = { "MT_SPIKEBALL", "MT_SMASHINGSPIKEBALL", "MT_POINTYBALL", "MT_SMALLMACECHAIN", "MT_BIGMACECHAIN", "MT_SMALLMACE", "MT_BIGMACE", "MT_CHAIN", "MT_CHAINPOINT", "MT_CHAINMACEPOINT", "MT_CUSTOMMACEPOINT", "MT_MACEPOINT" } for _, n in ipairs(clearable_names) do local val = safe_get_mt(n) if val ~= nil then feature_state.clearable_spike_chain_type_set[val] = true end end end feature_state.is_clearable_spike_chain_component = function(mobj) if not (mobj and mobj.valid) then return false end init_chain_mace_types() return feature_state.clearable_spike_chain_type_set[mobj.type] == true end local function is_grabbable_chain_component(mobj, scan_context) if not (mobj and mobj.valid) then return false end if scan_context and scan_context.grabbable_chain_results[mobj] == true then return true end local mt_smallgrab = scan_context and scan_context.mt_smallgrabchain or safe_get_mt("MT_SMALLGRABCHAIN") local mt_biggrab = scan_context and scan_context.mt_biggrabchain or safe_get_mt("MT_BIGGRABCHAIN") local mt_chainpoint = scan_context and scan_context.mt_chainpoint or safe_get_mt("MT_CHAINPOINT") local mobj_type = mobj.type if (mt_smallgrab ~= nil and mobj_type == mt_smallgrab) or (mt_biggrab ~= nil and mobj_type == mt_biggrab) or (mt_chainpoint ~= nil and mobj_type == mt_chainpoint) then if scan_context then scan_context.grabbable_chain_results[mobj] = true end return true end local first_parent = mobj.tracer if not (first_parent and first_parent.valid) or first_parent == mobj then return false end local curr = first_parent local depth = 0 local is_grabbable = false while curr and curr.valid and depth < 8 do local curr_type = curr.type if (mt_smallgrab ~= nil and curr_type == mt_smallgrab) or (mt_biggrab ~= nil and curr_type == mt_biggrab) or (mt_chainpoint ~= nil and curr_type == mt_chainpoint) then is_grabbable = true break end local parent = curr.tracer if not (parent and parent.valid) or parent == curr then break end curr = parent depth = depth + 1 end if scan_context and is_grabbable then scan_context.grabbable_chain_results[mobj] = true end return is_grabbable end local function is_linked_to_chain_anchor(mobj, scan_context) if not mobj or not mobj.valid then return false end if scan_context and scan_context.chain_results[mobj] ~= nil then return scan_context.chain_results[mobj] end if is_banner_object(mobj, scan_context) then if scan_context then scan_context.chain_results[mobj] = false end return false end init_chain_mace_types() if chain_mace_type_set[mobj.type] then if scan_context then scan_context.chain_results[mobj] = true end return true end local curr = mobj local depth = 0 local is_grab_chain = false while curr and curr.valid and depth < 32 do if chain_mace_type_set[curr.type] then is_grab_chain = true break end if curr.spawnpoint then local t = curr.spawnpoint.type if (t >= 730 and t <= 745) or t == 734 or t == 735 then is_grab_chain = true break end end local parent = curr.target if not parent or not parent.valid or parent == curr then parent = curr.tracer end if not parent or not parent.valid or parent == curr then parent = curr.owner end if not parent or not parent.valid or parent == curr then parent = curr.hnext end if not parent or not parent.valid or parent == curr then parent = curr.hprev end if parent == curr or not parent then break end curr = parent depth = depth + 1 end if scan_context then scan_context.chain_results[mobj] = is_grab_chain end return is_grab_chain end local function is_unsafe_command_spawn_type(mobj_type) local mt_player = safe_get_mt("MT_PLAYER") local mt_null = safe_get_mt("MT_NULL") return mobj_type == mt_player or mobj_type == mt_null end -- COMMAND AUDIT local command_audit = {} local audited_command_names = {} local command_audit_last = {} local MAX_AUDITED_COMMANDS_PER_PLAYER = 128 local function get_audit_skin_name(player) local skin_name = "" if not player then return skin_name end pcall(function() local skin = skins[player.skin] if skin and skin.name then skin_name = skin.name end end) return skin_name end local function normalize_audited_command(command_text) if type(command_text) ~= "string" then return "" end return string_lower(command_text:gsub("^%s+", ""):gsub("%s+$", ""):gsub("%s+", " ")) end local function record_player_command(player, command_text) if not isserver or not player or not player.valid then return end local normalized = normalize_audited_command(command_text) if normalized == "" or normalized == "listcommands" then return end local player_num = #player local now = leveltime or 0 local last = command_audit_last[player_num] if last and last.text == normalized and last.tic == now then return end command_audit_last[player_num] = {text = normalized, tic = now} local player_name = player.name or ("Player " .. player_num) local skin_name = get_audit_skin_name(player) local entry = command_audit[player_num] if not entry or entry.identity ~= string_lower(player_name) then entry = { identity = string_lower(player_name), name = player_name, skin = skin_name, counts = {}, order = {} } command_audit[player_num] = entry else entry.name = player_name entry.skin = skin_name end if entry.counts[normalized] then entry.counts[normalized] = entry.counts[normalized] + 1 elseif #entry.order < MAX_AUDITED_COMMANDS_PER_PLAYER then entry.counts[normalized] = 1 entry.order[#entry.order + 1] = normalized end end local function audit_command_text(name, arg1, ...) local parts = {name} if arg1 ~= nil then parts[#parts + 1] = arg1 end for _, argument in ipairs({...}) do if argument ~= nil then parts[#parts + 1] = argument end end return table.concat(parts, " ") end local function register_clearobjects_command(name, fn, flags) local command_flags = flags or 0 local lower_name = string_lower(name) audited_command_names[lower_name] = true if (command_flags & COM_LOCAL) ~= 0 or lower_name == "listcommands" then return COM_AddCommand(name, fn, command_flags) end local wrapped = function(player, arg1, ...) record_player_command(player, audit_command_text(name, arg1, ...)) return fn(player, arg1, ...) end return COM_AddCommand(name, wrapped, command_flags) end rawset(_G, "ClearObjects_RecordExternalCommand", function(player, name, arg1, ...) if type(name) ~= "string" or name == "" then return end if string_sub(name, 1, 2) == "__" then return end record_player_command(player, audit_command_text(name, arg1, ...)) end) -- CLEAROBJECTS local clearobjects_handler = function(player, arg1, ...) if gamestate ~= GS_LEVEL then CONS_Printf(player, "This can only be used inside of a level.") return end if not arg1 then CONS_Printf(player, "Usage: clearobjects ") return end init_protected_types() local mode = "none" local parsed_flags = {} local parsed_types = {} local type_names_requested = {} local lowercase_arg1 = string_lower(arg1) if lowercase_arg1 == "whitelist" then local sub_target = ... if not sub_target then if not clearobjects_whitelist or #clearobjects_whitelist == 0 then CONS_Printf(player, "No objects are currently whitelisted.") return end local updated = false for _, item in ipairs(clearobjects_whitelist) do if item.added_by_node ~= nil then local p_node = item.added_by_node if players[p_node] and players[p_node].valid then local new_name = players[p_node].name if item.added_by ~= new_name then item.added_by = new_name updated = true end end end end if updated then save_whitelist() end CONS_Printf(player, "Whitelisted objects:") for _, item in ipairs(clearobjects_whitelist) do local display_str = item.name if item.added_by and #item.added_by > 0 then display_str = display_str .. " (" .. item.added_by .. ")" end CONS_Printf(player, display_str) end return end local target_name = sub_target:match("^%s*(.-)%s*$") if #target_name == 0 then CONS_Printf(player, "Usage: clearobjects whitelist [object_name]") return end local lower_target = string_lower(target_name) local existing_index = nil for idx, item in ipairs(clearobjects_whitelist) do if string_lower(item.name) == lower_target then existing_index = idx break end end if existing_index then local removed_name = clearobjects_whitelist[existing_index].name table.remove(clearobjects_whitelist, existing_index) whitelist_type_cache = nil save_whitelist() CONS_Printf(player, "Removed " .. removed_name .. " from the clearobjects whitelist.") else local p_name = player.name or "Server" table.insert(clearobjects_whitelist, { name = target_name, added_by = p_name, added_by_node = #player }) whitelist_type_cache = nil save_whitelist() CONS_Printf(player, "Added " .. target_name .. " to the clearobjects whitelist.") end return elseif lowercase_arg1 == "all" then mode = "all" elseif lowercase_arg1 == "strict" then mode = "strict" elseif lowercase_arg1 == "purge" then mode = "purge" elseif lowercase_arg1 == "light" then mode = "light" init_light_flags() elseif lowercase_arg1 == "self" then mode = "self" elseif lowercase_arg1 == "other" or lowercase_arg1 == "others" then mode = "other" elseif lowercase_arg1 == "everyone" then mode = "everyone" elseif lowercase_arg1 == "flags" or lowercase_arg1 == "flag" then mode = "flags" local flag_names = {} for _, name in ipairs({...}) do table.insert(flag_names, name) end if #flag_names == 0 then CONS_Printf(player, "Usage: clearobjects ") return end for _, name in ipairs(flag_names) do local val, is_flags2 = getMobjFlag(name) if val ~= nil then table.insert(parsed_flags, {val = val, is_flags2 = is_flags2, name = name}) else CONS_Printf(player, "Unknown flag: " .. name) end end if #parsed_flags == 0 then return end elseif lowercase_arg1 == "type" or lowercase_arg1 == "types" then mode = "types" local type_names = {} for _, name in ipairs({...}) do table.insert(type_names, name) end type_names_requested = type_names if #type_names == 0 then CONS_Printf(player, "Usage: clearobjects ") return end for _, name in ipairs(type_names) do local clean_name = string_upper(name:match("^%s*(.-)%s*$")):gsub("[^A-Z0-9_]", "") if general_mappings[clean_name] then for _, const_name in ipairs(general_mappings[clean_name]) do local val = safe_get_mt(const_name) if val ~= nil then table.insert(parsed_types, val) end end else local val = getMobjType(name) if val ~= nil then table.insert(parsed_types, val) else CONS_Printf(player, "This object type doesn't exist: " .. name) end end end if #parsed_types == 0 then return end else local flagVal, is_flags2 = getMobjFlag(arg1) if flagVal ~= nil then mode = "flags" local flag_names = {arg1} for _, name in ipairs({...}) do table.insert(flag_names, name) end for _, name in ipairs(flag_names) do local val, f2 = getMobjFlag(name) if val ~= nil then table.insert(parsed_flags, {val = val, is_flags2 = f2, name = name}) else CONS_Printf(player, "Unknown flag: " .. name) end end if #parsed_flags == 0 then return end else local clean_arg1 = string_upper(arg1:match("^%s*(.-)%s*$")):gsub("[^A-Z0-9_]", "") local is_type = false if general_mappings[clean_arg1] then is_type = true else local tVal = getMobjType(arg1) if tVal ~= nil then is_type = true end end if is_type then mode = "types" local type_names = {arg1} for _, name in ipairs({...}) do table.insert(type_names, name) end type_names_requested = type_names for _, name in ipairs(type_names) do local clean_name = string_upper(name:match("^%s*(.-)%s*$")):gsub("[^A-Z0-9_]", "") if general_mappings[clean_name] then for _, const_name in ipairs(general_mappings[clean_name]) do local val = safe_get_mt(const_name) if val ~= nil then table.insert(parsed_types, val) end end else local val = getMobjType(name) if val ~= nil then table.insert(parsed_types, val) else CONS_Printf(player, "This object type doesn't exist: " .. name) end end end if #parsed_types == 0 then return end else CONS_Printf(player, "Unknown argument: " .. arg1) return end end end local removed = 0 local parsed_type_set = {} for _, parsed_type in ipairs(parsed_types) do parsed_type_set[parsed_type] = true end local banner_alias_requested = false for _, name in ipairs(type_names_requested) do local clean = string_upper(name):gsub("[^A-Z0-9_]", "") if clean == "BANNER" or clean == "BANNERS" or clean == "CEZBANNER" or clean == "FLAG" or clean == "FLAGS" then banner_alias_requested = true break end end local whitelist_types = build_whitelist_type_set() local scan_context = build_object_scan_context() local player_num = #player local function overlay_has_protected_owner(mobj) if scan_context.mt_overlay == nil or mobj.type ~= scan_context.mt_overlay then return false end local owner = mobj.target for _ = 1, 16 do if not (owner and owner.valid) or owner == mobj then return false end if is_protected_player_mobj(owner) then return true end local owner_type = owner.type local owner_explicit = mode == "types" and parsed_type_set[owner_type] == true if mode ~= "purge" and not owner_explicit then if always_protected[owner_type] or scan_context.goal_types[owner_type] or (mode == "all" and conditionally_protected[owner_type]) or (mode == "all" and is_object_whitelisted(owner, mode, whitelist_types)) or ((mode == "all" or mode == "strict") and is_grabbable_chain_component(owner, scan_context)) then return true end end if owner_type ~= scan_context.mt_overlay then return false end owner = owner.target end return false end local function is_protected_mobj(mobj) if not mobj or not mobj.valid then return true end if is_protected_player_mobj(mobj) then return true end local mobj_type = mobj.type if is_object_whitelisted(mobj, mode, whitelist_types) then return true end if (mode == "all" or mode == "strict") and is_grabbable_chain_component(mobj, scan_context) then return true end local mt_gotflag = scan_context.mt_gotflag local mt_finishflag = scan_context.mt_finishflag if (mt_gotflag ~= nil and mobj_type == mt_gotflag) or (mt_finishflag ~= nil and mobj_type == mt_finishflag) then return false end local is_flicky = scan_context.flicky_types[mobj_type] == true if is_flicky then return false end local is_monitor = (mobj.flags & MF_MONITOR) ~= 0 or (mobj_type and mobjinfo[mobj_type] and (mobjinfo[mobj_type].flags & MF_MONITOR) ~= 0) local is_destroyed = is_monitor and (mobj.health <= 0 or (mobj.info and mobj.state == mobj.info.deathstate)) if is_destroyed then return false end if (mode == "all" or mode == "purge") and is_monitor then return false end local is_protected = false local clearable_spike_chain = feature_state.is_clearable_spike_chain_component(mobj) local explicitly_requested_chain = mode == "types" and parsed_type_set[mobj_type] == true and clearable_spike_chain local clear_spike_chain = clearable_spike_chain and (mode == "all" or mode == "purge" or explicitly_requested_chain) local protect_always = always_protected[mobj_type] and not clear_spike_chain local protect_conditional = conditionally_protected[mobj_type] and not clear_spike_chain local protect_linked_chain = false if mode ~= "all" and mode ~= "purge" and not clear_spike_chain then protect_linked_chain = is_linked_to_chain_anchor(mobj, scan_context) end if mode == "types" then is_protected = protect_always if protect_conditional and not parsed_type_set[mobj_type] and not (banner_alias_requested and is_banner_object(mobj, scan_context)) then is_protected = true end if protect_linked_chain and not parsed_type_set[mobj_type] then is_protected = true end elseif mode == "all" then is_protected = protect_always or (protect_conditional and mobj_type ~= scan_context.mt_balloon and not (banner_alias_requested and is_banner_object(mobj, scan_context))) elseif mode == "purge" then is_protected = purge_protected[mobj_type] == true elseif mode == "strict" then local is_starpost_bumper_or_balloon = mobj_type == scan_context.mt_starpost or mobj_type == scan_context.mt_bumper or mobj_type == scan_context.mt_balloon local is_ring_or_token = (scan_context.mf_ring ~= nil and (mobj.flags & scan_context.mf_ring) ~= 0) or mobj_type == scan_context.mt_ring or mobj_type == scan_context.mt_flingring or mobj_type == scan_context.mt_token is_protected = protect_always or (protect_conditional and not is_starpost_bumper_or_balloon and not is_banner_object(mobj, scan_context)) or protect_linked_chain or is_ring_or_token else is_protected = protect_always or (protect_conditional and not is_banner_object(mobj, scan_context)) or protect_linked_chain end if is_spawned_player_copy(mobj) then is_protected = false end if (mode == "all" or mode == "strict" or mode == "purge") and is_hostile_mobj(mobj) then if mode == "purge" then is_protected = purge_protected[mobj_type] == true else is_protected = protect_always == true end end local goal_is_explicit = mode == "types" and parsed_type_set[mobj_type] == true if scan_context.goal_types[mobj_type] and mode ~= "purge" and not goal_is_explicit then is_protected = true end if is_attached_to_player(mobj, scan_context) then is_protected = true end if overlay_has_protected_owner(mobj) then is_protected = true end if mode == "light" and (mobj.flags & MF_NOSECTOR) ~= 0 and not is_light_scenery_object(mobj, scan_context) then is_protected = true end return is_protected end local deferred_controller_removals = {} local function consider_mobj(mobj) if not mobj or not mobj.valid then return end local mobj_type = mobj.type local is_protected = is_protected_mobj(mobj) if not is_protected then local removeMe = false if mode == "all" or mode == "strict" or mode == "purge" then removeMe = true elseif mode == "light" then if is_light_scenery_object(mobj, scan_context) then removeMe = true else for _, f in ipairs(light_flags) do if f.is_flags2 then if (mobj.flags2 & f.val) ~= 0 then removeMe = true break end else if (mobj.flags & f.val) ~= 0 then removeMe = true break end end end end elseif mode == "self" then if mobj.spawned_by == player_num then removeMe = true end elseif mode == "other" then if mobj.spawned_by ~= nil and mobj.spawned_by ~= player_num then removeMe = true end elseif mode == "everyone" then if mobj.spawned_by ~= nil then removeMe = true end elseif mode == "flags" then local match = false for _, f in ipairs(parsed_flags) do if f.is_flags2 then if (mobj.flags2 & f.val) ~= 0 then match = true break end else if (mobj.flags & f.val) ~= 0 then match = true break end end end if match then removeMe = true end elseif mode == "types" then local match = parsed_type_set[mobj_type] == true if not match and banner_alias_requested and is_banner_object(mobj, scan_context) then match = true end if match then removeMe = true end end if removeMe then if (mode == "all" or mode == "strict" or mode == "purge") and feature_state.is_invisible_controller(mobj) then deferred_controller_removals[#deferred_controller_removals + 1] = mobj elseif queue_object_removal(mobj) then removed = removed + 1 end end end end traverse_all_objects(consider_mobj) for _, controller in ipairs(deferred_controller_removals) do if queue_object_removal(controller) then removed = removed + 1 end end if removed > 0 then feature_state.sort_pending_removal_queues() end if removed > 0 then CONS_Printf(player, "Removed " .. removed .. " objects.") else CONS_Printf(player, "No matching objects found.") end end register_clearobjects_command("clearobjects", clearobjects_handler, COM_ADMIN) -- LISTOBJECTS register_clearobjects_command("listobjects", function(player, arg1) if gamestate ~= GS_LEVEL then CONS_Printf(player, "This can only be used inside of a level.") return end refresh_mobj_type_cache() local mode = "types" local filter_type = nil if arg1 then local lower1 = string_lower(arg1:match("^%s*(.-)%s*$") or arg1) if lower1 == "flags" or lower1 == "flag" then mode = "flags" else local clean = string_upper(arg1:match("^%s*(.-)%s*$")):gsub("[^A-Z0-9_]", "") if general_mappings[clean] then filter_type = {} for _, const_name in ipairs(general_mappings[clean]) do local val = safe_get_mt(const_name) if val ~= nil then filter_type[val] = true end end else local val = getMobjType(arg1) if val ~= nil then filter_type = {[val] = true} else CONS_Printf(player, "Unknown argument: " .. arg1) CONS_Printf(player, "Usage: listobjects | listobjects | listobjects flags") return end end end end if mode == "flags" then local all_flags = get_listable_mobj_flags() local flag_data = {} local type_name_cache = {} local total = 0 traverse_all_objects(function(mobj) if mobj.player and mobj.player.valid then return end total = total + 1 local mobj_type = mobj.type local mt_name = type_name_cache[mobj_type] if not mt_name then mt_name = get_mobj_type_name(mobj_type, mobj) type_name_cache[mobj_type] = mt_name end local mobj_flags = mobj.flags local mobj_flags2 = mobj.flags2 for _, fi in ipairs(all_flags) do local has = fi.is2 and (mobj_flags2 & fi.val) ~= 0 or not fi.is2 and (mobj_flags & fi.val) ~= 0 if has then if not flag_data[fi.name] then flag_data[fi.name] = {count=0, types={}} end flag_data[fi.name].count = flag_data[fi.name].count + 1 flag_data[fi.name].types[mt_name] = true end end end) if total == 0 then CONS_Printf(player, "No objects found.") return end local sorted = {} for fname, fd in pairs(flag_data) do local type_list = {} for mt_name in pairs(fd.types) do table.insert(type_list, mt_name) end table.sort(type_list) table.insert(sorted, {name=fname, count=fd.count, types=type_list}) end table.sort(sorted, function(a, b) if a.count ~= b.count then return a.count > b.count end return a.name < b.name end) CONS_Printf(player, "Objects by flag (" .. total .. " total):") local maxw = 58 local indent = " " for _, fg in ipairs(sorted) do local hdr = fg.name .. " (x" .. fg.count .. "): " local cur = hdr local started = false for i, tname in ipairs(fg.types) do local part = tname .. (i < #fg.types and ", " or "") if started and (#cur + #part) > maxw then CONS_Printf(player, cur) cur = indent .. part else cur = cur .. part started = true end end if cur ~= "" then CONS_Printf(player, cur) end end return end local type_counts = {} local type_samples = {} local total = 0 traverse_all_objects(function(mobj) if mobj.player and mobj.player.valid then return end local mt = mobj.type if filter_type and not filter_type[mt] then return end type_counts[mt] = (type_counts[mt] or 0) + 1 if not type_samples[mt] then type_samples[mt] = mobj end total = total + 1 end) if total == 0 then CONS_Printf(player, "No objects found.") return end local name_counts = {} local name_display = {} refresh_state_name_cache() for mt, cnt in pairs(type_counts) do local sample = type_samples[mt] local mt_name = get_mobj_type_name(mt, sample) local display = get_mobj_display_name(sample, mt) name_counts[mt_name] = (name_counts[mt_name] or 0) + cnt if display ~= "" and (not name_display[mt_name] or name_display[mt_name] == "") then name_display[mt_name] = display end end local entries = {} for mt_name, cnt in pairs(name_counts) do local display = name_display[mt_name] or "" if display == "" then display = format_mt_display_name(mt_name) end if display == "" then display = "Unnamed Object" end table.insert(entries, {mt_name=mt_name, count=cnt, display=display}) end table.sort(entries, function(a, b) if a.count ~= b.count then return a.count > b.count end return a.mt_name < b.mt_name end) local C_WHITE = string.char(0x80) local C_YELLOW = string.char(0x82) local C_PURPLE = string.char(0x81) local hdr = filter_type and (C_WHITE .. "Filtered objects (" .. C_YELLOW .. total .. C_WHITE .. " total):") or (C_WHITE .. "Objects in map (" .. C_YELLOW .. total .. C_WHITE .. " total, " .. C_YELLOW .. #entries .. C_WHITE .. " types):") CONS_Printf(player, hdr) for _, e in ipairs(entries) do local line = C_WHITE .. "(x" .. e.count .. ") " .. C_YELLOW .. e.mt_name line = line .. " " .. C_PURPLE .. "\"" .. e.display .. "\"" CONS_Printf(player, line) end end, COM_ADMIN) local function can_use_warptoobject(player) return feature_state.has_terminal_permission(player, "L2", true) end -- WARPTOOBJECT register_clearobjects_command("warptoobject", function(player, arg1, ...) if gamestate ~= GS_LEVEL then CONS_Printf(player, "This can only be used inside of a level.") return end if not player or not player.valid or not player.mo or not player.mo.valid or player.playerstate ~= PST_LIVE then CONS_Printf(player, "You must be alive and inside of a level to warp to an object.") return end if not can_use_warptoobject(player) then CONS_Printf(player, "You need Level 2 permissions to use this!") return end local name_parts = {} if arg1 ~= nil then name_parts[#name_parts + 1] = arg1 end for _, part in ipairs({...}) do if part ~= nil then name_parts[#name_parts + 1] = part end end if #name_parts == 0 then CONS_Printf(player, "Usage: warptoobject ") CONS_Printf(player, "Examples: warptoobject plushkimiko") CONS_Printf(player, " warptoobject MT_PLUSH_KIMIKO") return end local requested_name = table.concat(name_parts, " ") local requested_type = getMobjType(requested_name) if requested_type == nil then CONS_Printf(player, "Unknown object type: " .. requested_name) return end local matches = {} local nearest_index = nil local nearest_distance = nil for mobj in mobjs.iterate() do if mobj and mobj.valid and mobj ~= player.mo and mobj.type == requested_type then matches[#matches + 1] = mobj local distance = R_PointToDist2(player.mo.x, player.mo.y, mobj.x, mobj.y) if nearest_distance == nil or distance < nearest_distance then nearest_index = #matches nearest_distance = distance end end end if nearest_index == nil then CONS_Printf(player, "No " .. requested_name .. " objects are currently in the map.") return end local destination_index = nearest_index local nearest = matches[nearest_index] local cycle_distance = player.mo.radius + nearest.radius + FRACUNIT if #matches > 1 and nearest_distance <= cycle_distance then destination_index = nearest_index + 1 if destination_index > #matches then destination_index = 1 end end local destination = matches[destination_index] if not destination or not destination.valid then CONS_Printf(player, "That object disappeared before it could be reached.") return end local type_name = get_mobj_type_name(requested_type, destination) P_SetOrigin(player.mo, destination.x, destination.y, destination.z) player.mo.momx = 0 player.mo.momy = 0 player.mo.momz = 0 player.mo.angle = destination.angle CONS_Printf(player, "Warped to " .. type_name .. " (" .. destination_index .. "/" .. #matches .. ").") end) -- REPLACEOBJECTS register_clearobjects_command("replaceobjects", function(player, arg1, arg2, arg3, ...) if gamestate ~= GS_LEVEL then CONS_Printf(player, "This can only be used inside of a level.") return end if not arg1 then CONS_Printf(player, "Usage: replaceobjects [target] ") CONS_Printf(player, "By type: replaceobjects ring sonic") CONS_Printf(player, "By flag: replaceobjects solid ring") CONS_Printf(player, "By flag: replaceobjects MF_NOTHINK ring") CONS_Printf(player, "Explicit: replaceobjects flag noclip ring") return end init_protected_types() local mode = "none" local parsed_types = {} local parsed_flags = {} local replacement_name = nil local lowercase_arg1 = string_lower(arg1) local function tryFlag(s) local fval, fis2 = getMobjFlag(s) if fval ~= nil then return {val = fval, is_flags2 = fis2} end return nil end if lowercase_arg1 == "all" then mode = "all" replacement_name = arg2 elseif lowercase_arg1 == "strict" then mode = "strict" replacement_name = arg2 elseif lowercase_arg1 == "purge" then mode = "purge" replacement_name = arg2 elseif lowercase_arg1 == "flag" or lowercase_arg1 == "flags" then mode = "flags" if not arg2 or not arg3 then CONS_Printf(player, "Usage: replaceobjects flag ") CONS_Printf(player, "Example: replaceobjects flag solid ring") return end local f = tryFlag(arg2) if not f then CONS_Printf(player, "Unknown flag: " .. arg2) return end table.insert(parsed_flags, f) replacement_name = arg3 elseif lowercase_arg1 == "type" or lowercase_arg1 == "types" then mode = "types" if not arg2 or not arg3 then CONS_Printf(player, "Usage: replaceobjects type ") return end local clean_name = string_upper(arg2:match("^%s*(.-)%s*$")):gsub("[^A-Z0-9_]", "") if general_mappings[clean_name] then for _, const_name in ipairs(general_mappings[clean_name]) do local val = safe_get_mt(const_name) if val ~= nil then table.insert(parsed_types, val) end end else local val = getMobjType(arg2) if val ~= nil then table.insert(parsed_types, val) else CONS_Printf(player, "Target object type doesn't exist: " .. arg2) return end end replacement_name = arg3 else if arg2 then local clean_arg1 = string_upper(arg1:match("^%s*(.-)%s*$")):gsub("[^A-Z0-9_]", "") local has_mf_prefix = (clean_arg1:sub(1,3) == "MF_" or clean_arg1:sub(1,4) == "MF2_") local found_as_type = false if general_mappings[clean_arg1] then found_as_type = true mode = "types" for _, const_name in ipairs(general_mappings[clean_arg1]) do local val = safe_get_mt(const_name) if val ~= nil then table.insert(parsed_types, val) end end else local val = getMobjType(arg1) if val ~= nil then found_as_type = true mode = "types" table.insert(parsed_types, val) end end if found_as_type then replacement_name = arg2 elseif has_mf_prefix then local f = tryFlag(arg1) if f then mode = "flags" table.insert(parsed_flags, f) replacement_name = arg2 else CONS_Printf(player, "Unknown flag: " .. arg1) return end else CONS_Printf(player, "Unknown argument, type, or flag: " .. arg1) CONS_Printf(player, "Tip: to replace by flag, use: replaceobjects flag ") CONS_Printf(player, "Tip: to replace by type, use: replaceobjects type ") return end else CONS_Printf(player, "Usage: replaceobjects [target] ") CONS_Printf(player, "By type: replaceobjects ring sonic") CONS_Printf(player, "By flag: replaceobjects flag solid ring OR replaceobjects MF_NOTHINK ring") return end end if not replacement_name then CONS_Printf(player, "You must specify a replacement object type.") return end local replacement_mtype = getMobjType(replacement_name) if not replacement_mtype then CONS_Printf(player, "Replacement object type doesn't exist: " .. replacement_name) return end if is_unsafe_command_spawn_type(replacement_mtype) then CONS_Printf(player, "That engine-owned object type cannot be spawned safely.") return end local replaced = 0 local to_replace = {} local parsed_type_set = {} for _, parsed_type in ipairs(parsed_types) do parsed_type_set[parsed_type] = true end local scan_context = build_object_scan_context() local player_num = #player local function is_protected_mobj(mobj) if not mobj or not mobj.valid then return true end if is_protected_player_mobj(mobj) then return true end local mobj_type = mobj.type local is_protected = false if mode == "types" or mode == "purge" then is_protected = always_protected[mobj_type] if mode == "types" and conditionally_protected[mobj_type] and not parsed_type_set[mobj_type] then is_protected = true end elseif mode == "strict" then local is_starpost_bumper_or_balloon = mobj_type == scan_context.mt_starpost or mobj_type == scan_context.mt_bumper or mobj_type == scan_context.mt_balloon local is_ring_or_token = (scan_context.mf_ring ~= nil and (mobj.flags & scan_context.mf_ring) ~= 0) or mobj_type == scan_context.mt_ring or mobj_type == scan_context.mt_flingring or mobj_type == scan_context.mt_token is_protected = always_protected[mobj_type] or (conditionally_protected[mobj_type] and not is_starpost_bumper_or_balloon and not is_banner_object(mobj, scan_context)) or is_linked_to_chain_anchor(mobj, scan_context) or is_ring_or_token else is_protected = always_protected[mobj_type] or (conditionally_protected[mobj_type] and not is_banner_object(mobj, scan_context)) or is_linked_to_chain_anchor(mobj, scan_context) end if is_spawned_player_copy(mobj) then is_protected = false end local goal_is_explicit = mode == "types" and parsed_type_set[mobj_type] == true if scan_context.goal_types[mobj_type] and mode ~= "purge" and not goal_is_explicit then is_protected = true end if is_attached_to_player(mobj, scan_context) then is_protected = true end return is_protected end local function consider_mobj(mobj) if not mobj or not mobj.valid then return end local mobj_type = mobj.type local is_protected = is_protected_mobj(mobj) if not is_protected then local replaceMe = false if mode == "all" or mode == "strict" or mode == "purge" then replaceMe = true elseif mode == "types" then replaceMe = parsed_type_set[mobj_type] == true elseif mode == "flags" then local allMatch = #parsed_flags > 0 for _, fe in ipairs(parsed_flags) do local chk if fe.is_flags2 then chk = (mobj.flags2 & fe.val) ~= 0 else chk = (mobj.flags & fe.val) ~= 0 end if not chk then allMatch = false break end end replaceMe = allMatch end if replaceMe then table.insert(to_replace, mobj) end end end traverse_all_objects(consider_mobj) for _, mobj in ipairs(to_replace) do if mobj and mobj.valid then local mX, mY, mZ = mobj.x, mobj.y, mobj.z local mAng = mobj.angle local mScale = mobj.scale local mDestScale = mobj.destscale local spBy = mobj.spawned_by remove_single_mobj(mobj) local spawned, new_mo = pcall(P_SpawnMobj, mX, mY, mZ, replacement_mtype) if not spawned then new_mo = nil end if new_mo and new_mo.valid then initialize_spawned_ambient(new_mo, replacement_mtype) new_mo.angle = mAng if mScale ~= nil then new_mo.scale = mScale end if mDestScale ~= nil then new_mo.destscale = mDestScale end if spBy ~= nil then new_mo.spawned_by = spBy elseif player and player.valid then new_mo.spawned_by = player_num end end replaced = replaced + 1 end end CONS_Printf(player, "Replaced " .. replaced .. " objects with " .. string_upper(replacement_name) .. ".") end, COM_ADMIN) -- REPLACETEXTURES register_clearobjects_command("replacetextures", function(player, old_name, new_name, scope) if gamestate ~= GS_LEVEL then CONS_Printf(player, "This can only be used inside of a level.") return end if not old_name or not new_name then CONS_Printf(player, "Usage: replacetextures [all/walls/flats/floors/ceilings]") return end local old_upper = string_upper(old_name) local new_upper = string_upper(new_name) local requested_scope = scope and string_lower(scope) or "all" if requested_scope ~= "all" and requested_scope ~= "walls" and requested_scope ~= "flats" and requested_scope ~= "floors" and requested_scope ~= "ceilings" then CONS_Printf(player, "Unknown scope: " .. requested_scope) CONS_Printf(player, "Use all, walls, flats, floors, or ceilings.") return end local replace_walls = requested_scope == "all" or requested_scope == "walls" local replace_floors = requested_scope == "all" or requested_scope == "flats" or requested_scope == "floors" local replace_ceilings = requested_scope == "all" or requested_scope == "flats" or requested_scope == "ceilings" local wall_count, floor_count, ceiling_count = 0, 0, 0 if replace_walls then local old_texture = R_CheckTextureNumForName(old_upper) local new_texture = R_CheckTextureNumForName(new_upper) if old_texture >= 0 and new_texture >= 0 then for side in sides.iterate do if side.toptexture == old_texture then side.toptexture = new_texture wall_count = wall_count + 1 end if side.midtexture == old_texture then side.midtexture = new_texture wall_count = wall_count + 1 end if side.bottomtexture == old_texture then side.bottomtexture = new_texture wall_count = wall_count + 1 end end elseif requested_scope == "walls" then CONS_Printf(player, "One or both wall textures do not exist: " .. old_upper .. ", " .. new_upper) return end end if replace_floors or replace_ceilings then for sector in sectors.iterate do if replace_floors and string_upper(sector.floorpic or "") == old_upper then sector.floorpic = new_upper floor_count = floor_count + 1 end if replace_ceilings and string_upper(sector.ceilingpic or "") == old_upper then sector.ceilingpic = new_upper ceiling_count = ceiling_count + 1 end end end CONS_Printf(player, "Replaced " .. (wall_count + floor_count + ceiling_count) .. " texture use(s): " .. wall_count .. " wall, " .. floor_count .. " floor, " .. ceiling_count .. " ceiling.") end, COM_ADMIN) -- PLAYER TARGETING local function find_spawn_target_player(target) if not target then return nil, "missing" end local target_number = tonumber(target) if target_number ~= nil then if target_number < 0 or target_number >= 32 then return nil, "Player number " .. target .. " is out of range (0 to 31)." end local numbered_player = players[target_number] if numbered_player and numbered_player.valid then return numbered_player end return nil, "No connected player has player number " .. target .. "." end local wanted = string_lower(target) local partial_match = nil local partial_count = 0 for candidate in players.iterate do local candidate_name = string_lower(candidate.name or "") if candidate_name == wanted then return candidate end if #wanted > 0 and string_sub(candidate_name, 1, #wanted) == wanted then partial_match = candidate partial_count = partial_count + 1 end end if partial_count == 1 then return partial_match elseif partial_count > 1 then return nil, "More than one player name starts with '" .. target .. "'. Please type more of the name." end return nil, "No connected player matches '" .. target .. "'." end local last_death_positions = {} local attached_players = {} feature_state.normalize_allowattach_preference = function(value) if type(value) ~= "string" then return nil end local lowered = string_lower(value):gsub("^%s+", ""):gsub("%s+$", "") if lowered == "on" or lowered == "yes" or lowered == "true" or lowered == "1" then return "on" end if lowered == "off" or lowered == "no" or lowered == "false" or lowered == "0" then return "off" end return nil end feature_state.load_allowattach_preference = function() feature_state.saved_allowattach_preference = "on" if not (io and io.openlocal) then return end local ok, file = pcall(io.openlocal, "client/DylanSahr's Addons/clearobjects_allowattach.dat", "r") if not ok or not file then return end for line in file:lines() do local saved = feature_state.normalize_allowattach_preference(line) if saved then feature_state.saved_allowattach_preference = saved end break end file:close() end feature_state.save_allowattach_preference = function(player, value) if not (player and player.valid and consoleplayer and consoleplayer.valid) then return end if player ~= consoleplayer then return end local saved = feature_state.normalize_allowattach_preference(value) if not saved then return end feature_state.saved_allowattach_preference = saved if io and io.openlocal then local ok, file = pcall(io.openlocal, "client/DylanSahr's Addons/clearobjects_allowattach.dat", "w") if ok and file then file:write(saved .. "\n") file:close() end end end feature_state.allowattach_enabled = function(player) if not (player and player.valid) then return false end return feature_state.allowattach_players[#player] ~= false end feature_state.load_allowattach_preference() addHook("MobjDeath", function(target) if not (target and target.valid and target.player and target.player.valid) then return end local player = target.player last_death_positions[#player] = { map = gamemap, x = target.x, y = target.y, z = target.z, angle = target.angle } end, MT_PLAYER) -- WARPTOBODY register_clearobjects_command("warptobody", function(player) if not (player and player.valid and player.mo and player.mo.valid) then return end local death = last_death_positions[#player] if not death then CONS_Printf(player, "You do not have a recorded death position yet.") return end if death.map ~= gamemap then CONS_Printf(player, "Your last death position was on a different map.") return end P_SetOrigin(player.mo, death.x, death.y, death.z) player.mo.angle = death.angle or player.mo.angle player.mo.momx = 0 player.mo.momy = 0 player.mo.momz = 0 CONS_Printf(player, "Warped to your last death position.") end) local function attachment_would_cycle(player_num, target_num) local current = target_num for _ = 1, 32 do if current == player_num then return true end current = attached_players[current] if current == nil then return false end end return true end -- ATTACHMENT COMMANDS COM_AddCommand("__co_allowattach_sync", function(player, value) if not (player and player.valid) then return end local normalized = feature_state.normalize_allowattach_preference(value) if not normalized then return end local player_num = #player local enabled = normalized == "on" feature_state.allowattach_players[player_num] = enabled feature_state.save_allowattach_preference(player, normalized) local detached_self = false local detached_followers = 0 if not enabled then if attached_players[player_num] ~= nil then attached_players[player_num] = nil detached_self = true end for attached_num, target_num in pairs(attached_players) do if target_num == player_num then attached_players[attached_num] = nil detached_followers = detached_followers + 1 local attached_player = players[attached_num] if attached_player and attached_player.valid then CONS_Printf(attached_player, player.name .. " turned allowattach off, so you were detached.") end end end end if enabled then CONS_Printf(player, "allowattach is ON. Level 2 and Level 3 players may attach to you.") else local suffix = "" if detached_self or detached_followers > 0 then suffix = " Existing attachments were removed." end CONS_Printf(player, "allowattach is OFF. You cannot attach to anyone, and nobody can attach to you." .. suffix) end end) register_clearobjects_command("allowattach", function(player, value) if not (player and player.valid) then return end if not value then local enabled = feature_state.allowattach_players[#player] if enabled == nil then enabled = feature_state.saved_allowattach_preference ~= "off" end CONS_Printf(player, "allowattach is " .. (enabled and "ON" or "OFF") .. ".") CONS_Printf(player, "Usage: allowattach ") return end local normalized = feature_state.normalize_allowattach_preference(value) if not normalized then CONS_Printf(player, "Usage: allowattach ") return end feature_state.save_allowattach_preference(player, normalized) COM_BufAddText(player, "__co_allowattach_sync " .. normalized) end, COM_LOCAL) register_clearobjects_command("attachto", function(player, target_spec) if not (player and player.valid) then return end local player_num = #player if not target_spec then local current = attached_players[player_num] if current ~= nil then attached_players[player_num] = nil CONS_Printf(player, "You are no longer attached to another player.") else CONS_Printf(player, "Usage: attachto ") end return end local lowered = string_lower(target_spec) if lowered == "off" or lowered == "none" or lowered == "detach" then attached_players[player_num] = nil CONS_Printf(player, "You are no longer attached to another player.") return end local allowed = feature_state.has_terminal_permission(player, "L2", true) if not allowed then CONS_Printf(player, "You need Level 2 or Level 3 permissions to use attachto.") return end if not feature_state.allowattach_enabled(player) then CONS_Printf(player, "Your allowattach is off. Use 'allowattach on' before attaching to someone.") return end local target_player, target_error = find_spawn_target_player(target_spec) if not target_player then CONS_Printf(player, target_error) return end if target_player == player then CONS_Printf(player, "You cannot attach to yourself.") return end if not feature_state.allowattach_enabled(target_player) then CONS_Printf(player, target_player.name .. " has allowattach turned off.") return end if attachment_would_cycle(player_num, #target_player) then CONS_Printf(player, "That attachment would create a player loop.") return end attached_players[player_num] = #target_player CONS_Printf(player, "Attached to " .. target_player.name .. ". Use attachto off to detach.") end) addHook("PostThinkFrame", function() if next(attached_players) == nil then return end for player in players.iterate do local player_num = #player local target_num = attached_players[player_num] if target_num ~= nil then local target = players[target_num] if not feature_state.allowattach_enabled(player) or not feature_state.allowattach_enabled(target) then attached_players[player_num] = nil elseif player.mo and player.mo.valid and target and target.valid and target.mo and target.mo.valid and target.mo.health > 0 then if player.mo.x ~= target.mo.x or player.mo.y ~= target.mo.y or player.mo.z ~= target.mo.z then P_SetOrigin(player.mo, target.mo.x, target.mo.y, target.mo.z) end player.mo.momx = target.mo.momx player.mo.momy = target.mo.momy player.mo.momz = target.mo.momz elseif not target or not target.valid then attached_players[player_num] = nil end end end end) addHook("PlayerQuit", function(player) if not player then return end local quitting_num = #player attached_players[quitting_num] = nil feature_state.allowattach_players[quitting_num] = nil last_death_positions[quitting_num] = nil for player_num, target_num in pairs(attached_players) do if target_num == quitting_num then attached_players[player_num] = nil end end end) addHook("NetVars", function(net) last_death_positions = net($) or {} attached_players = net($) or {} feature_state.allowattach_players = net(feature_state.allowattach_players) or {} if consoleplayer and consoleplayer.valid and feature_state.allowattach_players[#consoleplayer] == nil then feature_state.allowattach_restore_attempted = false end end) addHook("ThinkFrame", function() if feature_state.allowattach_restore_attempted then return end if gamestate ~= GS_LEVEL then return end if not (consoleplayer and consoleplayer.valid) then return end if feature_state.allowattach_players[#consoleplayer] ~= nil then feature_state.allowattach_restore_attempted = true return end feature_state.allowattach_restore_attempted = true local saved = feature_state.saved_allowattach_preference or "on" COM_BufAddText(consoleplayer, "__co_allowattach_sync " .. saved) end) -- TRACKVIEW local tracked_viewpoints = {} local function set_tracked_viewpoint(player, target_spec) if not player or not player.valid then return end if not target_spec then CONS_Printf(player, "Usage: trackview ") return end local lowered = string_lower(target_spec) if lowered == "none" or lowered == "off" then tracked_viewpoints[#player] = nil return end local target_player, target_error = find_spawn_target_player(target_spec) if not target_player then CONS_Printf(player, target_error) return end tracked_viewpoints[#player] = #target_player end COM_AddCommand("trackview", set_tracked_viewpoint, COM_ADMIN) COM_AddCommand("trackviewpoint", set_tracked_viewpoint, COM_ADMIN) local last_tracked_viewpoint = nil addHook("ThinkFrame", function() if not (consoleplayer and consoleplayer.valid) then return end local current_target = nil if displayplayer and displayplayer.valid and displayplayer ~= consoleplayer then current_target = #displayplayer end if current_target == last_tracked_viewpoint then return end last_tracked_viewpoint = current_target local can_track = (#consoleplayer == 0) if not can_track then pcall(function() can_track = IsPlayerAdmin(consoleplayer) end) end if not can_track then return end if current_target ~= nil then COM_BufAddText(consoleplayer, "trackview " .. current_target) else COM_BufAddText(consoleplayer, "trackview none") end end) addHook("NetVars", function(net) tracked_viewpoints = net($) or {} end) -- COLOR COMMANDS local function normalize_color_name(name) if not name then return "" end return string_upper(name):gsub("^SKINCOLOR_", ""):gsub("[^A-Z0-9]", "") end local function get_skincolor_label(color_id) local label = "Color #" .. tostring(color_id) pcall(function() local info = skincolors[color_id] if info and info.name and info.name ~= "" then label = info.name end end) return label end local function resolve_object_skincolor(name) if not name then return nil end local numeric = tonumber(name) if numeric ~= nil then local valid = false pcall(function() valid = numeric >= 1 and numeric < #skincolors and skincolors[numeric] ~= nil end) if valid then return numeric, get_skincolor_label(numeric) end return nil end local wanted = normalize_color_name(name) if wanted == "" then return nil end local constant_value = nil pcall(function() constant_value = _G["SKINCOLOR_" .. wanted] end) if type(constant_value) == "number" then return constant_value, get_skincolor_label(constant_value) end for color_id = 1, #skincolors - 1 do local info = skincolors[color_id] if info and normalize_color_name(info.name) == wanted then return color_id, info.name end end return nil end local function resolve_skin_preferred_color(name) if not name then return nil end local wanted = string_lower(name):gsub("^%s+", ""):gsub("%s+$", "") local found_skin = nil pcall(function() found_skin = skins[wanted] end) if not found_skin then pcall(function() for skin in skins.iterate do if string_lower(skin.name or "") == wanted then found_skin = skin break end end end) end if found_skin and type(found_skin.prefcolor) == "number" then return found_skin.prefcolor, found_skin.name or name end return nil end local cv_clearobjects_objectcolor = CV_RegisterVar({ name = "clearobjects_objectcolor", defaultvalue = "none", flags = CV_SAVE }) feature_state.normalize_objectcolor_preference = function(value) if type(value) ~= "string" then return "none" end local cleaned = string_lower(value):gsub("^%s+", ""):gsub("%s+$", "") if cleaned == "skin" or cleaned == "none" then return cleaned end local numeric = tonumber(cleaned) if numeric ~= nil and numeric >= 0 then return tostring(numeric) end return "none" end feature_state.load_objectcolor_preference = function() feature_state.saved_objectcolor_preference = "none" if not (io and io.openlocal) then return end local ok, file = pcall(io.openlocal, "client/DylanSahr's Addons/clearobjects_objectcolor.dat", "r") if not ok or not file then return end for line in file:lines() do feature_state.saved_objectcolor_preference = feature_state.normalize_objectcolor_preference(line) break end file:close() end feature_state.load_objectcolor_preference() local objectcolor_modes = {} local objectcolor_values = {} local player_colorized = {} local carried_color_restores = {} local followed_color_objects = {} local animated_color_objects = {} local followed_skincolors = {} local color_tracking_rebuild_needed = false local objectcolor_restore_attempted = false local function save_objectcolor_preference(player, value) if not (player and player.valid and consoleplayer and consoleplayer.valid) then return end if player ~= consoleplayer then return end if not value or value == "" then return end local saved = feature_state.normalize_objectcolor_preference(value) feature_state.saved_objectcolor_preference = saved if cv_clearobjects_objectcolor and cv_clearobjects_objectcolor.string ~= saved then pcall(CV_Set, cv_clearobjects_objectcolor, saved) end if io and io.openlocal then local ok, file = pcall(io.openlocal, "client/DylanSahr's Addons/clearobjects_objectcolor.dat", "w") if ok and file then file:write(saved .. "\n") file:close() end end end local function get_player_object_color(player) if not player then return 0 end local color = player.skincolor if color == nil and player.mo and player.mo.valid then color = player.mo.color end if color == nil then color = 0 end return color end local function resolve_animated_object_color(color) local resolver = rawget(_G, "XMomentumResolveAnimatedSkinColor") if type(resolver) == "function" then local resolved = resolver(color, true, leveltime) if type(resolved) == "number" then return resolved end end return color end local function is_animated_object_color(color) local resolver = rawget(_G, "XMomentumResolveAnimatedSkinColor") if type(resolver) ~= "function" or type(color) ~= "number" then return false end local first = resolver(color, true, 0) local second = resolver(color, true, 2) local third = resolver(color, true, 4) return type(first) == "number" and type(second) == "number" and type(third) == "number" and (first ~= second or second ~= third) end local function track_forced_color_object(obj) if obj.clearobjects_color_tracked then return end if obj.clearobjects_forced_color_mode == "skin" then local target_num = obj.clearobjects_color_target if target_num == nil then return end local objects = followed_color_objects[target_num] if not objects then objects = {} followed_color_objects[target_num] = objects end obj.clearobjects_color_tracked = true obj.clearobjects_color_track_kind = "skin" objects[#objects + 1] = obj elseif obj.clearobjects_forced_color_mode == "color" and is_animated_object_color(obj.clearobjects_forced_color_value) then obj.clearobjects_color_tracked = true obj.clearobjects_color_track_kind = "animated" animated_color_objects[#animated_color_objects + 1] = obj end end local function mark_forced_object_color(obj, mode, color_value, target_player) if not (obj and obj.valid) then return false end if not obj.clearobjects_forced_objectcolor then obj.clearobjects_original_color = obj.color obj.clearobjects_original_colorized = obj.colorized and 1 or 0 end local applied_color = color_value if mode == "skin" or applied_color == nil then applied_color = get_player_object_color(target_player) end obj.color = resolve_animated_object_color(applied_color) obj.colorized = true obj.clearobjects_forced_objectcolor = true obj.clearobjects_forced_color_mode = mode obj.clearobjects_forced_color_value = color_value obj.clearobjects_color_target = #target_player track_forced_color_object(obj) return true end local function clear_forced_object_color(obj) if not (obj and obj.valid and obj.clearobjects_forced_objectcolor) then return false end obj.color = obj.clearobjects_original_color or 0 obj.colorized = obj.clearobjects_original_colorized == 1 obj.clearobjects_original_color = nil obj.clearobjects_original_colorized = nil obj.clearobjects_forced_objectcolor = nil obj.clearobjects_forced_color_mode = nil obj.clearobjects_forced_color_value = nil obj.clearobjects_color_target = nil obj.clearobjects_color_tracked = nil obj.clearobjects_color_track_kind = nil if feature_state.player_copy_generations then feature_state.player_copy_generations[obj] = nil end return true end local function rebuild_forced_color_tracking() followed_color_objects = {} animated_color_objects = {} followed_skincolors = {} traverse_all_objects(function(obj) if obj and obj.valid and obj.clearobjects_forced_objectcolor then obj.clearobjects_color_tracked = nil obj.clearobjects_color_track_kind = nil track_forced_color_object(obj) end end) end local function update_followed_color_objects(player_num, next_color) local objects = followed_color_objects[player_num] if not objects then return end local write_index = 1 for read_index = 1, #objects do local obj = objects[read_index] if obj and obj.valid and obj.clearobjects_forced_objectcolor and obj.clearobjects_forced_color_mode == "skin" and obj.clearobjects_color_target == player_num then objects[write_index] = obj write_index = write_index + 1 if obj.color ~= next_color then obj.color = next_color end if not obj.colorized then obj.colorized = true end elseif obj and obj.valid and obj.clearobjects_color_track_kind == "skin" then obj.clearobjects_color_tracked = nil obj.clearobjects_color_track_kind = nil end end for index = write_index, #objects do objects[index] = nil end if #objects == 0 then followed_color_objects[player_num] = nil end end local function update_animated_color_objects() local write_index = 1 for read_index = 1, #animated_color_objects do local obj = animated_color_objects[read_index] if obj and obj.valid and obj.clearobjects_forced_objectcolor and obj.clearobjects_forced_color_mode == "color" then animated_color_objects[write_index] = obj write_index = write_index + 1 local next_color = resolve_animated_object_color(obj.clearobjects_forced_color_value) if next_color ~= nil then if obj.color ~= next_color then obj.color = next_color end if not obj.colorized then obj.colorized = true end end elseif obj and obj.valid and obj.clearobjects_color_track_kind == "animated" then obj.clearobjects_color_tracked = nil obj.clearobjects_color_track_kind = nil end end for index = write_index, #animated_color_objects do animated_color_objects[index] = nil end end local last_xmomentum_animation_step = -1 addHook("ThinkFrame", function() if color_tracking_rebuild_needed and gamestate == GS_LEVEL then rebuild_forced_color_tracking() color_tracking_rebuild_needed = false end if #animated_color_objects == 0 and next(followed_color_objects) == nil then last_xmomentum_animation_step = -1 return end local resolver_active = type(rawget(_G, "XMomentumResolveAnimatedSkinColor")) == "function" local animation_step = leveltime >> 1 if resolver_active and #animated_color_objects > 0 and animation_step != last_xmomentum_animation_step then last_xmomentum_animation_step = animation_step update_animated_color_objects() elseif not resolver_active or #animated_color_objects == 0 then last_xmomentum_animation_step = -1 end for player in players.iterate do local player_num = #player if followed_color_objects[player_num] then local color = resolve_animated_object_color(get_player_object_color(player)) if followed_skincolors[player_num] ~= color then followed_skincolors[player_num] = color update_followed_color_objects(player_num, color) end else followed_skincolors[player_num] = nil end end end) local function save_carried_color_list(destination, objects) if not objects then return end for index, obj in ipairs(objects) do if obj and obj.valid and obj.clearobjects_forced_objectcolor then destination[#destination + 1] = { index = index, mode = obj.clearobjects_forced_color_mode or "skin", color = obj.clearobjects_forced_color_value, target = obj.clearobjects_color_target } end end end local function save_carried_color_order(destination, objects) if type(objects) ~= "table" then return end for index, obj in ipairs(objects) do if obj and obj.valid and obj.clearobjects_forced_objectcolor then destination[#destination + 1] = { index = index, mobjtype = obj.type, mode = obj.clearobjects_forced_color_mode or "skin", color = obj.clearobjects_forced_color_value, target = obj.clearobjects_color_target } end end end addHook("NetVars", function(net) objectcolor_modes = net($) or {} objectcolor_values = net($) or {} player_colorized = net($) or {} carried_color_restores = net($) or {} if consoleplayer and consoleplayer.valid and objectcolor_modes[#consoleplayer] == nil then objectcolor_restore_attempted = false end color_tracking_rebuild_needed = true end) addHook("PlayerQuit", function(player) if not player then return end if objectcolor_modes then objectcolor_modes[#player] = nil end if objectcolor_values then objectcolor_values[#player] = nil end if player_colorized then player_colorized[#player] = nil end if carried_color_restores then carried_color_restores[#player] = nil end if followed_color_objects then followed_color_objects[#player] = nil end if followed_skincolors then followed_skincolors[#player] = nil end end) addHook("MapChange", function() carried_color_restores = {} for player in players.iterate do local saved = {order = {}, kimiko = {}, gardevoir = {}, tries = 0} save_carried_color_order(saved.order, player.tdfCarryOrder) if #saved.order == 0 then save_carried_color_list(saved.kimiko, player.heldKimikos) save_carried_color_list(saved.gardevoir, player.heldGARDEVOIRs) end if #saved.order > 0 or #saved.kimiko > 0 or #saved.gardevoir > 0 then carried_color_restores[#player] = saved end end followed_color_objects = {} animated_color_objects = {} followed_skincolors = {} color_tracking_rebuild_needed = false end) local function restore_carried_color_list(player, saved, objects) if #saved == 0 then return true end if not objects then return false end for _, appearance in ipairs(saved) do local obj = objects[appearance.index] if not (obj and obj.valid) then return false end end for _, appearance in ipairs(saved) do local target_player = appearance.target ~= nil and players[appearance.target] or nil if not (target_player and target_player.valid) then target_player = player end mark_forced_object_color(objects[appearance.index], appearance.mode, appearance.color, target_player) end return true end local function restore_carried_color_order(player, saved) if #saved == 0 then return true end local objects = player.tdfCarryOrder if type(objects) ~= "table" then return false end for _, appearance in ipairs(saved) do local obj = objects[appearance.index] if not (obj and obj.valid) then return false end if appearance.mobjtype ~= nil and obj.type ~= appearance.mobjtype then return false end end for _, appearance in ipairs(saved) do local target_player = appearance.target ~= nil and players[appearance.target] or nil if not (target_player and target_player.valid) then target_player = player end mark_forced_object_color(objects[appearance.index], appearance.mode, appearance.color, target_player) end return true end local function sync_player_carried_plushies(player) if not (player and player.valid) then return end local pnum = #player local mode = objectcolor_modes[pnum] or "none" if mode == "none" then return end if leveltime ~= nil and ((leveltime + pnum) % 5) ~= 0 then return end local color_val = objectcolor_values[pnum] local carried = {} if player.tdfCarryOrder and type(player.tdfCarryOrder) == "table" then for _, obj in ipairs(player.tdfCarryOrder) do if obj and obj.valid then carried[#carried + 1] = obj end end end if player.heldKimiko and player.heldKimiko.valid then carried[#carried + 1] = player.heldKimiko end if player.heldGARDEVOIR and player.heldGARDEVOIR.valid then carried[#carried + 1] = player.heldGARDEVOIR end if player.heldChao and player.heldChao.valid then carried[#carried + 1] = player.heldChao end if player.pet and player.pet.valid then carried[#carried + 1] = player.pet end for _, list in ipairs({player.heldKimikos, player.heldGARDEVOIRs, player.heldChaos}) do if list and type(list) == "table" then for _, obj in ipairs(list) do if obj and obj.valid then carried[#carried + 1] = obj end end end end for _, obj in ipairs(carried) do local spawned_for_player = obj.spawned_by == pnum local already_forced = obj.clearobjects_forced_objectcolor == true if mode ~= "none" and (spawned_for_player or already_forced) then if not already_forced or not obj.colorized then mark_forced_object_color(obj, mode, color_val, player) end end end end addHook("PlayerThink", function(player) if not player_colorized then player_colorized = {} end if not carried_color_restores then carried_color_restores = {} end local player_num = #player if not player_colorized[player_num] and not carried_color_restores[player_num] and (objectcolor_modes[player_num] == nil or objectcolor_modes[player_num] == "none") then return end if player_colorized[player_num] and player.mo and player.mo.valid then local mo = player.mo if not mo.colorized then mo.colorized = true end local fullbright = rawget(_G, "RF_FULLBRIGHT") if type(fullbright) == "number" and (mo.renderflags & fullbright) == 0 then mo.renderflags = $ | fullbright mo.clearobjects_colorize_added_fullbright = true end end sync_player_carried_plushies(player) local saved = carried_color_restores[player_num] if not saved then return end saved.tries = (saved.tries or 0) + 1 local restored = false if saved.order and #saved.order > 0 then restored = restore_carried_color_order(player, saved.order) else local kimiko_ready = restore_carried_color_list(player, saved.kimiko or {}, player.heldKimikos) local gardevoir_ready = restore_carried_color_list(player, saved.gardevoir or {}, player.heldGARDEVOIRs) restored = kimiko_ready and gardevoir_ready end if restored or saved.tries > 5*TICRATE then carried_color_restores[player_num] = nil end end) addHook("ThinkFrame", function() if objectcolor_restore_attempted then return end if gamestate ~= GS_LEVEL then return end if not (consoleplayer and consoleplayer.valid) then return end if objectcolor_modes[#consoleplayer] ~= nil then objectcolor_restore_attempted = true return end local allowed = #consoleplayer == 0 if not allowed and IsPlayerAdmin then pcall(function() allowed = IsPlayerAdmin(consoleplayer) end) end if not allowed then return end objectcolor_restore_attempted = true local saved = feature_state.saved_objectcolor_preference or "none" COM_BufAddText(consoleplayer, "objectcolor " .. saved) end) register_clearobjects_command("colorize", function(player, value) if not player or not player.valid then return end if not player_colorized then player_colorized = {} end local enabled = player_colorized[#player] == true if value then local lowered = string_lower(value) if lowered == "on" or lowered == "yes" or lowered == "1" then enabled = true elseif lowered == "off" or lowered == "none" or lowered == "no" or lowered == "0" then enabled = false else CONS_Printf(player, "Usage: colorize [on/off]") return end else enabled = not enabled end if enabled then player_colorized[#player] = true if player.mo and player.mo.valid then local mo = player.mo mo.colorized = true local fullbright = rawget(_G, "RF_FULLBRIGHT") if type(fullbright) == "number" and (mo.renderflags & fullbright) == 0 then mo.renderflags = $ | fullbright mo.clearobjects_colorize_added_fullbright = true end end CONS_Printf(player, "You are now colorized!") else player_colorized[#player] = nil if player.mo and player.mo.valid then local mo = player.mo mo.colorized = false local fullbright = rawget(_G, "RF_FULLBRIGHT") if mo.clearobjects_colorize_added_fullbright and type(fullbright) == "number" then mo.renderflags = $ & ~fullbright end mo.clearobjects_colorize_added_fullbright = nil end CONS_Printf(player, "You are no longer colorized.") end end) register_clearobjects_command("objectcolor", function(player, value) if not player or not player.valid then return end local player_num = #player if not value then local mode = objectcolor_modes[player_num] or "none" if mode == "none" then CONS_Printf(player, "Object color: none (objects keep their regular palette).") elseif mode == "color" then local color_id = objectcolor_values[player_num] or 0 CONS_Printf(player, "Object color: " .. get_skincolor_label(color_id) .. " (" .. color_id .. ").") else CONS_Printf(player, "Object color: skin (uses each target player's skin color).") end CONS_Printf(player, "Usage: objectcolor ") return end local function apply_objectcolor_to_spawned(p_num, mode, color_val, target_p) local count = 0 for _, obj in ipairs(tracked_objects) do if obj and obj.valid and obj.spawned_by == p_num then if mode == "none" then if clear_forced_object_color(obj) then count = count + 1 end else if mark_forced_object_color(obj, mode, color_val, target_p) then count = count + 1 end end end end return count end local lowered = string_lower(value):gsub("^%s+", ""):gsub("%s+$", "") if lowered == "clear" then objectcolor_modes[player_num] = "none" objectcolor_values[player_num] = nil save_objectcolor_preference(player, "none") local cleared = apply_objectcolor_to_spawned(player_num, "none", nil, player) followed_color_objects[player_num] = nil CONS_Printf(player, "Restored the regular colors of " .. cleared .. " spawned objects.") return elseif lowered == "none" or lowered == "off" or lowered == "default" then objectcolor_modes[player_num] = "none" objectcolor_values[player_num] = nil save_objectcolor_preference(player, "none") CONS_Printf(player, "Newly spawned objects will keep their regular color. Use 'objectcolor clear' to restore existing objects too.") return elseif lowered == "skin" or lowered == "player" or lowered == "current" or lowered == "self" or lowered == "me" then objectcolor_modes[player_num] = "skin" objectcolor_values[player_num] = nil save_objectcolor_preference(player, "skin") CONS_Printf(player, "Newly spawned objects will use your current player's color.") return end local matched_player = nil for p in players.iterate do if p and p.valid then if string_lower(p.name or "") == lowered or (p.mo and p.mo.valid and string_lower(p.mo.skin or "") == lowered) or (p.skin and string_lower(tostring(p.skin)) == lowered) then matched_player = p break end end end if matched_player then local cur_color = get_player_object_color(matched_player) objectcolor_modes[player_num] = "color" objectcolor_values[player_num] = cur_color save_objectcolor_preference(player, tostring(cur_color)) CONS_Printf(player, "Newly spawned objects will use " .. matched_player.name .. "'s current color (" .. get_skincolor_label(cur_color) .. ").") return end local color_id, color_label = resolve_object_skincolor(value) if color_id == nil then color_id, color_label = resolve_skin_preferred_color(value) end if color_id == nil then CONS_Printf(player, "Unknown skin color or skin: " .. value) CONS_Printf(player, "Examples: objectcolor red, objectcolor skin, objectcolor self, objectcolor none") return end if color_id == 0 then objectcolor_modes[player_num] = "none" objectcolor_values[player_num] = nil save_objectcolor_preference(player, "none") CONS_Printf(player, "Newly spawned objects will keep their regular color. Use 'objectcolor clear' to restore existing objects too.") return end objectcolor_modes[player_num] = "color" objectcolor_values[player_num] = color_id save_objectcolor_preference(player, tostring(color_id)) CONS_Printf(player, "Newly spawned objects will use " .. color_label .. " (" .. color_id .. ").") end, COM_ADMIN) -- DOFOR register_clearobjects_command("dofor", function(player, target_spec, command_name, ...) if not player or not player.valid then return end if #player ~= 0 then CONS_Printf(player, "Only player 0 can use dofor.") return end if not target_spec or not command_name then CONS_Printf(player, "Usage: dofor [arguments]") CONS_Printf(player, "Examples: dofor 1 suicide") CONS_Printf(player, " dofor Jojo setrings 9999") CONS_Printf(player, " dofor 2 say frhugbbryjev") CONS_Printf(player, " dofor Jojo quit") CONS_Printf(player, " dofor all colorize") return end local target_players = {} if string_lower(target_spec) == "all" then for candidate in players.iterate do if candidate and candidate.valid then target_players[#target_players + 1] = candidate end end else local target_player, target_error = find_spawn_target_player(target_spec) if not target_player then CONS_Printf(player, target_error) return end target_players[1] = target_player end local command_arguments = {...} local command_parts = {command_name} for _, argument in ipairs(command_arguments) do command_parts[#command_parts + 1] = argument end local command_text = table.concat(command_parts, " ") if #command_text > 240 then CONS_Printf(player, "That dofor command is too long (maximum: 240 characters).") return end local command_key = string_lower(command_name) if command_key:sub(1,1) == "/" or command_key:sub(1,1) == "\\" then command_key = command_key:sub(2) command_text = command_text:sub(2) end if command_key == "setrings" or command_key == "rings" then local ring_count = tonumber(command_arguments[1]) if ring_count == nil or (ring_count % 1) ~= 0 then CONS_Printf(player, "Usage: dofor setrings ") return end if ring_count < 0 then ring_count = 0 end if ring_count > 9999 then ring_count = 9999 end for _, target_player in ipairs(target_players) do target_player.rings = ring_count record_player_command(target_player, "setrings " .. ring_count) end if #target_players == 1 then local target_player = target_players[1] CONS_Printf(player, "Set " .. target_player.name .. " (#" .. #target_player .. ") to " .. ring_count .. " rings.") else CONS_Printf(player, "Set " .. #target_players .. " players to " .. ring_count .. " rings.") end return elseif command_key == "warpto" or command_key == "teleport" or command_key == "goto" then local dest_spec = command_arguments[1] if not dest_spec then CONS_Printf(player, "Usage: dofor warpto ") return end local dest_player, dest_error = find_spawn_target_player(dest_spec) if not dest_player then CONS_Printf(player, dest_error) return end if not (dest_player.mo and dest_player.mo.valid) then CONS_Printf(player, "Destination player " .. dest_player.name .. " is not currently spawned.") return end for _, target_player in ipairs(target_players) do if target_player and target_player.valid and target_player.mo and target_player.mo.valid then P_SetOrigin(target_player.mo, dest_player.mo.x, dest_player.mo.y, dest_player.mo.z) target_player.mo.angle = dest_player.mo.angle target_player.drawangle = dest_player.mo.angle target_player.mo.momx = 0 target_player.mo.momy = 0 target_player.mo.momz = 0 record_player_command(target_player, command_text) end end if #target_players == 1 then local target_player = target_players[1] CONS_Printf(player, "Warped " .. target_player.name .. " (#" .. #target_player .. ") to " .. dest_player.name .. " (#" .. #dest_player .. ").") else CONS_Printf(player, "Warped " .. #target_players .. " players to " .. dest_player.name .. " (#" .. #dest_player .. ").") end return elseif command_key == "suicide" or command_key == "kill" or command_key == "die" then for _, target_player in ipairs(target_players) do if target_player and target_player.valid then if target_player.pflags & PF_GODMODE then target_player.pflags = $ & ~PF_GODMODE end if target_player.mo and target_player.mo.valid then P_DamageMobj(target_player.mo, nil, nil, 10000, DMG_INSTAKILL) end record_player_command(target_player, "suicide") end end if #target_players == 1 then local target_player = target_players[1] CONS_Printf(player, "Killed " .. target_player.name .. " (#" .. #target_player .. ").") else CONS_Printf(player, "Killed " .. #target_players .. " players.") end return elseif command_key == "skin" and command_arguments[1] then local skin_name = command_arguments[1] skin_name = string_lower(skin_name) for _, target_player in ipairs(target_players) do if target_player and target_player.valid then pcall(function() SetPlayerSkin(target_player, skin_name) end) pcall(function() R_SetPlayerSkin(target_player, skin_name) end) record_player_command(target_player, "skin " .. skin_name) end end if #target_players == 1 then CONS_Printf(player, "Changed " .. target_players[1].name .. " to skin " .. skin_name .. ".") else CONS_Printf(player, "Changed " .. #target_players .. " players to skin " .. skin_name .. ".") end return end for _, target_player in ipairs(target_players) do if not audited_command_names[command_key] then record_player_command(target_player, command_text) end local formatted_cmd = command_text .. "\n" COM_BufInsertText(target_player, formatted_cmd) end if #target_players == 1 then local target_player = target_players[1] CONS_Printf(player, "Dofor " .. target_player.name .. " (#" .. #target_player .. "): " .. command_text) else CONS_Printf(player, "Dofor all (" .. #target_players .. " players): " .. command_text) end end, COM_ADMIN) -- SPAWNOBJECTS local function is_ringslinger_gametype() local ringslinger_rule = rawget(_G, "GTR_RINGSLINGER") return type(ringslinger_rule) == "number" and (gametyperules & ringslinger_rule) ~= 0 end local function has_spawnobjects_level3(player) return feature_state.has_terminal_permission(player, "L3", true) end local function can_use_spawnobjects(player) if #player == 0 then return true end if is_ringslinger_gametype() then return has_spawnobjects_level3(player) end return IsPlayerAdmin(player) end feature_state.register_player_copy = function(obj) if feature_state.player_copy_registry[obj] then return end local target_num = obj.clearobjects_clone_target if target_num == nil then return end local copies = feature_state.player_copies_by_target[target_num] if not copies then copies = {} feature_state.player_copies_by_target[target_num] = copies end feature_state.player_copy_registry[obj] = true copies[#copies + 1] = obj end feature_state.for_each_player_copy = function(target_num, callback) local copies = feature_state.player_copies_by_target[target_num] if not copies then return end local write_index = 1 local emitted = 0 for _, copy in ipairs(copies) do if is_spawned_player_copy(copy) and copy.clearobjects_clone_target == target_num and not pending_removal_set[copy] then copies[write_index] = copy write_index = write_index + 1 if emitted < 16 then callback(copy) emitted = emitted + 1 end elseif copy then feature_state.player_copy_registry[copy] = nil end end for index = write_index, #copies do copies[index] = nil end if write_index == 1 then feature_state.player_copies_by_target[target_num] = nil end end feature_state.play_clone_skin_sound = function(obj, sound_slot) if not (obj and obj.valid and sound_slot ~= nil and obj.skin) then return end pcall(function() local skin = skins[obj.skin] local sound_id = skin and skin.soundsid and skin.soundsid[sound_slot] or nil if sound_id and sound_id > 0 then S_StartSound(obj, sound_id) end end) end feature_state.hurt_spawned_player_copy = function(obj, inflictor, source) if not is_spawned_player_copy(obj) then return false end obj.health = 1 obj.momx = 0 obj.momy = 0 obj.momz = 0 local pain_slot = rawget(_G, "SKSPLPAN1") if pain_slot ~= nil then feature_state.play_clone_skin_sound(obj, pain_slot + (leveltime % 4)) end return true end feature_state.get_clone_appearance = function(target_num, target_player, target_mo) local cache = feature_state.clone_appearance_cache[target_num] if not cache then cache = {generation = 0, tic = -1} feature_state.clone_appearance_cache[target_num] = cache end if cache.tic == leveltime then return cache end cache.tic = leveltime local vertical_flip = 0 local vertical_flip_flag = rawget(_G, "MFE_VERTICALFLIP") if vertical_flip_flag then vertical_flip = target_mo.eflags & vertical_flip_flag end local changed = cache.skin ~= target_mo.skin or cache.sprite ~= target_mo.sprite or cache.sprite2 ~= target_mo.sprite2 or cache.frame ~= target_mo.frame or cache.scale ~= target_mo.scale or cache.radius ~= target_mo.radius or cache.height ~= target_mo.height or cache.rollangle ~= target_mo.rollangle or cache.pitch ~= target_mo.pitch or cache.angle ~= target_mo.angle or cache.spritexscale ~= target_mo.spritexscale or cache.spriteyscale ~= target_mo.spriteyscale or cache.spritexoffset ~= target_mo.spritexoffset or cache.spriteyoffset ~= target_mo.spriteyoffset or cache.spriteroll ~= target_mo.spriteroll or cache.color ~= target_mo.color or cache.colorized ~= target_mo.colorized or cache.vertical_flip ~= vertical_flip or cache.name ~= target_player.name if changed then cache.skin = target_mo.skin cache.sprite = target_mo.sprite cache.sprite2 = target_mo.sprite2 cache.frame = target_mo.frame cache.scale = target_mo.scale cache.radius = target_mo.radius cache.height = target_mo.height cache.rollangle = target_mo.rollangle cache.pitch = target_mo.pitch cache.angle = target_mo.angle cache.spritexscale = target_mo.spritexscale cache.spriteyscale = target_mo.spriteyscale cache.spritexoffset = target_mo.spritexoffset cache.spriteyoffset = target_mo.spriteyoffset cache.spriteroll = target_mo.spriteroll cache.color = target_mo.color cache.colorized = target_mo.colorized cache.vertical_flip = vertical_flip cache.name = target_player.name cache.generation = cache.generation + 1 end return cache end addHook("MobjDamage", function(obj, inflictor, source) if not obj or obj.clearobjects_player_copy ~= true then return end if feature_state.hurt_spawned_player_copy(obj, inflictor, source) then return true end end, MT_PLAYER) addHook("MobjDeath", function(obj, inflictor, source) if not obj or obj.clearobjects_player_copy ~= true then return end if feature_state.hurt_spawned_player_copy(obj, inflictor, source) then return true end end, MT_PLAYER) addHook("MobjThinker", function(obj) if obj.player ~= nil or obj.clearobjects_player_copy ~= true then return end feature_state.register_player_copy(obj) if (obj.flags & MF_SOLID) ~= 0 then obj.flags = obj.flags & ~MF_SOLID end if obj.tics ~= -1 then obj.tics = -1 end local target_num = obj.clearobjects_clone_target local target_player = target_num ~= nil and players[target_num] or nil local target_mo = target_player and target_player.valid and target_player.mo or nil if not (target_mo and target_mo.valid) or target_player.spectator then queue_object_removal(obj) return true end if obj.momx ~= 0 then obj.momx = 0 end if obj.momy ~= 0 then obj.momy = 0 end if obj.momz ~= 0 then obj.momz = 0 end local appearance = feature_state.get_clone_appearance(target_num, target_player, target_mo) if feature_state.player_copy_generations[obj] ~= appearance.generation then local updated = pcall(function() if obj.skin ~= appearance.skin then obj.skin = appearance.skin end if obj.sprite ~= appearance.sprite then obj.sprite = appearance.sprite end if obj.sprite2 ~= appearance.sprite2 then obj.sprite2 = appearance.sprite2 end if obj.frame ~= appearance.frame then obj.frame = appearance.frame end if obj.scale ~= appearance.scale then obj.scale = appearance.scale end if obj.destscale ~= appearance.scale then obj.destscale = appearance.scale end if obj.radius ~= appearance.radius then obj.radius = appearance.radius end if obj.height ~= appearance.height then obj.height = appearance.height end if obj.rollangle ~= appearance.rollangle then obj.rollangle = appearance.rollangle end if obj.pitch ~= appearance.pitch then obj.pitch = appearance.pitch end if obj.angle ~= appearance.angle then obj.angle = appearance.angle end if obj.spritexscale ~= appearance.spritexscale then obj.spritexscale = appearance.spritexscale end if obj.spriteyscale ~= appearance.spriteyscale then obj.spriteyscale = appearance.spriteyscale end if obj.spritexoffset ~= appearance.spritexoffset then obj.spritexoffset = appearance.spritexoffset end if obj.spriteyoffset ~= appearance.spriteyoffset then obj.spriteyoffset = appearance.spriteyoffset end if obj.spriteroll ~= appearance.spriteroll then obj.spriteroll = appearance.spriteroll end if obj.clearobjects_clone_name ~= appearance.name then obj.clearobjects_clone_name = appearance.name end if not obj.clearobjects_forced_objectcolor then if obj.color ~= appearance.color then obj.color = appearance.color end if obj.colorized ~= appearance.colorized then obj.colorized = appearance.colorized end end local vertical_flip_flag = rawget(_G, "MFE_VERTICALFLIP") if vertical_flip_flag then local next_eflags = (obj.eflags & ~vertical_flip_flag) | appearance.vertical_flip if obj.eflags ~= next_eflags then obj.eflags = next_eflags end end end) if updated then feature_state.player_copy_generations[obj] = appearance.generation end end return true end, MT_PLAYER) -- Requests have no quantity/active-object cap. Process a finite amount of work -- per tick so ordinary synchronized map recovery can interrupt a huge request. -- Store only serializable job data: late joins and state reloads resume the -- same queue and indices on every peer, including clients with older engines. feature_state.spawn_requests = {} addHook("NetVars", function(net) feature_state.spawn_requests = net(feature_state.spawn_requests) end) addHook("MapChange", function() feature_state.spawn_requests = {} end) feature_state.spawn_request_one = function(request, target_player, mobj_type, item_number, item_total) if not (target_player and target_player.valid and target_player.mo and target_player.mo.valid) then return false end local target_mo = target_player.mo local sX, sY, sZ = calculate_spawn_coords(target_mo, item_number, item_total, request.shape_name, request.dist_option, request.is_tower) local spawned_ok, obj = pcall(P_SpawnMobj, sX, sY, sZ, mobj_type) if not spawned_ok then obj = nil end if not (obj and obj.valid) then return false end local player_copy = mobj_type == MT_PLAYER and obj.player == nil if player_copy then obj.clearobjects_player_copy = true obj.clearobjects_clone_target = #target_player obj.clearobjects_clone_name = target_player.name obj.flags = obj.flags & ~MF_SOLID obj.tics = -1 obj.health = 1 end initialize_spawned_ambient(obj, mobj_type) obj.angle = target_mo.angle pcall(function() obj.scale = target_mo.scale obj.destscale = target_mo.scale if player_copy then obj.skin = target_mo.skin obj.color = target_mo.color obj.colorized = target_mo.colorized obj.radius = target_mo.radius obj.height = target_mo.height obj.sprite = target_mo.sprite obj.sprite2 = target_mo.sprite2 obj.frame = target_mo.frame obj.spritexscale = target_mo.spritexscale obj.spriteyscale = target_mo.spriteyscale obj.spritexoffset = target_mo.spritexoffset obj.spriteyoffset = target_mo.spriteyoffset obj.spriteroll = target_mo.spriteroll end if request.objectcolor_mode ~= "none" then mark_forced_object_color(obj, request.objectcolor_mode, request.objectcolor_value, target_player) end end) pcall(function() obj.skin = target_mo.skin end) obj.orig_x = sX obj.orig_y = sY obj.orig_z = sZ obj.orig_angle = target_mo.angle obj.spawned_by = request.owner_number return true end addHook("PostThinkFrame", function() if gamestate ~= GS_LEVEL then return end local remaining_work = 1000 while remaining_work > 0 and #feature_state.spawn_requests > 0 do remaining_work = remaining_work - 1 local request = feature_state.spawn_requests[1] local owner = request.owner if not (owner and owner.valid) then table.remove(feature_state.spawn_requests, 1) else local target = request.targets[request.target_index] if target and target.valid and target.mo and target.mo.valid and not target.spectator then local mtype = request.mtype if request.emeralds then mtype = getMobjType("MT_EMERALD" .. (((request.item_index - 1) % 7) + 1)) end if mtype and feature_state.spawn_request_one(request, target, mtype, request.item_index, request.qty) then -- Saturate only the status counter, never the actual request. if request.spawned < 2147483647 then request.spawned = request.spawned + 1 end end if request.item_index == request.qty then request.item_index = 1 request.target_index = request.target_index + 1 else request.item_index = request.item_index + 1 end else request.item_index = 1 request.target_index = request.target_index + 1 end if request.target_index > #request.targets then CONS_Printf(owner, "Spawned " .. request.spawned .. request.description .. ".") table.remove(feature_state.spawn_requests, 1) end end end end) local spawnobjects_handler = function(player, name, count, shape, ...) if gamestate ~= GS_LEVEL then CONS_Printf(player, "This can only be used inside of a level.") return end if not player or not player.valid then return end if not can_use_spawnobjects(player) then if is_ringslinger_gametype() then CONS_Printf(player, "You need Level 3 permissions to use spawnobjects in Ringslinger modes.") else CONS_Printf(player, "You need administrator permissions to use spawnobjects.") end return end local all_args = {} if name then table.insert(all_args, name) end if count then table.insert(all_args, count) end if shape then table.insert(all_args, shape) end for _, extra in ipairs({...}) do table.insert(all_args, extra) end if #all_args == 0 then CONS_Printf(player, "Usage: spawnobjects [tower] [shape] [count] [target] [distance]") CONS_Printf(player, "Available shapes: straight, line, circle, square, triangle, tower, self") CONS_Printf(player, "You can combine tower with shapes: e.g. spawnobjects tower circle ring 50") CONS_Printf(player, "Available distances: short, medium, far") CONS_Printf(player, "Examples: spawnobjects straight ring 20") CONS_Printf(player, " spawnobjects tower ring 15") CONS_Printf(player, " spawnobjects tower circle ring 50 Jojo") return end local raw_object_name = nil local qty = 1 local qty_was_set = false local shape_name = nil local is_tower = false local dist_option = nil local target_spec = nil for _, a in ipairs(all_args) do local lower_a = string_lower(a) local num_a = tonumber(a) if lower_a == "tower" or lower_a == "stack" or lower_a == "vertical" then is_tower = true if not shape_name then shape_name = "tower" end elseif lower_a == "straight" or lower_a == "singleline" or lower_a == "1line" then shape_name = "straight" elseif lower_a == "circle" or lower_a == "square" or lower_a == "triangle" or lower_a == "line" or lower_a == "self" then shape_name = lower_a elseif lower_a == "short" or lower_a == "medium" or lower_a == "med" or lower_a == "far" then dist_option = lower_a elseif num_a ~= nil and not qty_was_set then qty = max(1, num_a) qty_was_set = true elseif raw_object_name == nil and (lower_a == "emerald" or lower_a == "mt_emerald" or getMobjType(a) ~= nil) then raw_object_name = a elseif target_spec == nil and (lower_a == "all" or lower_a == "me" or find_spawn_target_player(a) ~= nil) then target_spec = a elseif raw_object_name == nil then raw_object_name = a elseif target_spec == nil then target_spec = a else CONS_Printf(player, "Unrecognized argument: " .. a) return end end if not raw_object_name then CONS_Printf(player, "Please specify an object type to spawn.") return end local name_trimmed = raw_object_name:match("^%s*(.-)%s*$") local name_lower = string_lower(name_trimmed) if (name_lower == "emerald" or name_lower == "mt_emerald") and not qty_was_set then qty = 7 end local target_players = {} if target_spec and string_lower(target_spec) == "all" then for candidate in players.iterate do if candidate.mo and candidate.mo.valid and not candidate.spectator then table.insert(target_players, candidate) end end elseif target_spec and string_lower(target_spec) == "me" then table.insert(target_players, player) elseif target_spec then local selected, target_error = find_spawn_target_player(target_spec) if not selected then CONS_Printf(player, target_error) return end table.insert(target_players, selected) else local tracked_number = tracked_viewpoints[#player] local tracked_player = tracked_number ~= nil and players[tracked_number] or nil if tracked_player and tracked_player.valid then table.insert(target_players, tracked_player) else table.insert(target_players, player) end end local usable_targets = {} for _, target_player in ipairs(target_players) do if target_player and target_player.valid and target_player.mo and target_player.mo.valid and not target_player.spectator then table.insert(usable_targets, target_player) end end if #usable_targets == 0 then CONS_Printf(player, "The selected player target is dead, spectating, or has no character in-game.") return end local emeralds = name_lower == "emerald" or name_lower == "mt_emerald" local mType = not emeralds and getMobjType(name_trimmed) or nil if not emeralds then if not mType then CONS_Printf(player, "This object type doesn't exist: " .. name_trimmed) return end if is_unsafe_command_spawn_type(mType) and mType ~= MT_PLAYER then CONS_Printf(player, "That engine-owned object type cannot be spawned safely.") return end end local shape_desc = "" if is_tower and shape_name and shape_name ~= "tower" then shape_desc = " in a " .. shape_name .. " tower" elseif is_tower or shape_name == "tower" then shape_desc = " in a tower" elseif shape_name then shape_desc = " in a " .. shape_name end local target_label = " around " .. #usable_targets .. " player(s)" local object_label if name_lower == "emerald" or name_lower == "mt_emerald" then object_label = " emeralds" else object_label = " of " .. string_upper(name_trimmed) end local description = object_label .. shape_desc .. target_label table.insert(feature_state.spawn_requests, { owner = player, owner_number = #player, targets = usable_targets, qty = qty, item_index = 1, target_index = 1, spawned = 0, emeralds = emeralds, mtype = mType, shape_name = shape_name, dist_option = dist_option, is_tower = is_tower, objectcolor_mode = objectcolor_modes[#player] or "none", objectcolor_value = objectcolor_values[#player], description = description }) CONS_Printf(player, "Spawning " .. qty .. " per target" .. description .. ".") end register_clearobjects_command("spawnobjects", spawnobjects_handler) -- RALLYOBJECTS local rallyobjects_handler = function(player, arg1, ...) if gamestate ~= GS_LEVEL then CONS_Printf(player, "This can only be used inside of a level.") return end if not player or not player.valid then return end if not arg1 then CONS_Printf(player, "Usage: rallyobjects [shape/self] [player] [distance]") CONS_Printf(player, "Available shapes: circle, square, triangle, line, self") CONS_Printf(player, "Available distances: short (enlarged), medium (+100%), far (+200%). Omit distance for original distance.") CONS_Printf(player, "Examples: rallyobjects plushkimiko self, rallyobjects ring self Airfox, rallyobjects ring Airfox self") return end init_protected_types() local raw_args = {arg1, ...} local shape_name = nil local is_tower = false local dist_option = nil local remaining_args = {} for _, a in ipairs(raw_args) do local lower_a = string_lower(a) if lower_a == "tower" or lower_a == "stack" or lower_a == "vertical" then is_tower = true if not shape_name then shape_name = "tower" end elseif lower_a == "straight" or lower_a == "singleline" or lower_a == "1line" then shape_name = "straight" elseif lower_a == "circle" or lower_a == "square" or lower_a == "triangle" or lower_a == "line" or lower_a == "self" then shape_name = lower_a elseif lower_a == "short" or lower_a == "medium" or lower_a == "med" or lower_a == "far" then dist_option = lower_a else table.insert(remaining_args, a) end end local target_player = player local target_spec = nil local selector_args = {} for _, a in ipairs(remaining_args) do local lower_a = string_lower(a) local clean_a = string_upper(a:match("^%s*(.-)%s*$")):gsub("[^A-Z0-9_]", "") local candidate = find_spawn_target_player(a) local flag_value = getMobjFlag(a) local is_mode_word = lower_a == "all" or lower_a == "flags" or lower_a == "flag" or lower_a == "type" or lower_a == "types" or lower_a == "self" or lower_a == "other" or lower_a == "others" or lower_a == "everyone" local is_object_selector = is_mode_word or general_mappings[clean_a] ~= nil or flag_value ~= nil or getMobjType(a) ~= nil local numeric_player = tonumber(a) ~= nil and #remaining_args > 1 if target_spec == nil and candidate and (numeric_player or not is_object_selector) then target_spec = a target_player = candidate else selector_args[#selector_args + 1] = a end end remaining_args = selector_args local first_arg = remaining_args[1] local lowercase_first = first_arg and string_lower(first_arg) or "all" local rest_args = {} for i = 2, #remaining_args do table.insert(rest_args, remaining_args[i]) end local mode = "none" local parsed_flags = {} local parsed_types = {} if lowercase_first == "all" then mode = "all" elseif lowercase_first == "self" then mode = "self" elseif lowercase_first == "other" or lowercase_first == "others" then mode = "other" elseif lowercase_first == "everyone" then mode = "everyone" elseif lowercase_first == "flags" or lowercase_first == "flag" then mode = "flags" local flag_names = rest_args if #flag_names == 0 then CONS_Printf(player, "Usage: rallyobjects flags [shape] [distance]") return end for _, name in ipairs(flag_names) do local val, is_flags2 = getMobjFlag(name) if val ~= nil then table.insert(parsed_flags, {val = val, is_flags2 = is_flags2, name = name}) else CONS_Printf(player, "Unknown flag: " .. name) end end if #parsed_flags == 0 then return end elseif lowercase_first == "type" or lowercase_first == "types" then mode = "types" local type_names = rest_args if #type_names == 0 then CONS_Printf(player, "Usage: rallyobjects types [shape] [distance]") return end for _, name in ipairs(type_names) do local clean_name = string_upper(name:match("^%s*(.-)%s*$")):gsub("[^A-Z0-9_]", "") if general_mappings[clean_name] then for _, const_name in ipairs(general_mappings[clean_name]) do local val = safe_get_mt(const_name) if val ~= nil then table.insert(parsed_types, val) end end else local val = getMobjType(name) if val ~= nil then table.insert(parsed_types, val) else CONS_Printf(player, "This object type doesn't exist: " .. name) end end end if #parsed_types == 0 then return end else local flagVal, is_flags2 = getMobjFlag(first_arg) if flagVal ~= nil then mode = "flags" local flag_names = {first_arg} for _, name in ipairs(rest_args) do table.insert(flag_names, name) end for _, name in ipairs(flag_names) do local val, f2 = getMobjFlag(name) if val ~= nil then table.insert(parsed_flags, {val = val, is_flags2 = f2, name = name}) else CONS_Printf(player, "Unknown flag: " .. name) end end if #parsed_flags == 0 then return end else local clean_first = string_upper(first_arg:match("^%s*(.-)%s*$")):gsub("[^A-Z0-9_]", "") local is_type = false if general_mappings[clean_first] then is_type = true else local tVal = getMobjType(first_arg) if tVal ~= nil then is_type = true end end if is_type then mode = "types" local type_names = {first_arg} for _, name in ipairs(rest_args) do table.insert(type_names, name) end for _, name in ipairs(type_names) do local clean_name = string_upper(name:match("^%s*(.-)%s*$")):gsub("[^A-Z0-9_]", "") if general_mappings[clean_name] then for _, const_name in ipairs(general_mappings[clean_name]) do local val = safe_get_mt(const_name) if val ~= nil then table.insert(parsed_types, val) end end else local val = getMobjType(name) if val ~= nil then table.insert(parsed_types, val) else CONS_Printf(player, "This object type doesn't exist: " .. name) end end end if #parsed_types == 0 then return end else CONS_Printf(player, "Unknown argument: " .. first_arg) return end end end local mo = target_player.mo if not mo or not mo.valid then CONS_Printf(player, target_player.name .. " must be in-game to receive rallied objects.") return end local to_move = {} local parsed_type_set = {} for _, parsed_type in ipairs(parsed_types) do parsed_type_set[parsed_type] = true end local scan_context = build_object_scan_context() local player_num = #player local function is_protected_mobj(mobj) if not mobj or not mobj.valid then return true end if is_protected_player_mobj(mobj) then return true end local mobj_type = mobj.type local is_protected = false if mode == "types" then is_protected = always_protected[mobj_type] if conditionally_protected[mobj_type] and not parsed_type_set[mobj_type] then is_protected = true end else local is_bumper_or_balloon = mobj_type == scan_context.mt_bumper or mobj_type == scan_context.mt_balloon is_protected = always_protected[mobj_type] or (conditionally_protected[mobj_type] and not is_bumper_or_balloon and not is_banner_object(mobj, scan_context)) or is_linked_to_chain_anchor(mobj, scan_context) end if is_spawned_player_copy(mobj) then is_protected = false end if mode == "all" and is_hostile_mobj(mobj) then is_protected = always_protected[mobj_type] == true end local goal_is_explicit = mode == "types" and parsed_type_set[mobj_type] == true if scan_context.goal_types[mobj_type] and not goal_is_explicit then is_protected = true end if is_attached_to_player(mobj, scan_context) then is_protected = true end return is_protected end local function consider_mobj(mobj) if not mobj or not mobj.valid then return end local mobj_type = mobj.type local is_protected = is_protected_mobj(mobj) if not is_protected then local moveMe = false if mode == "all" then moveMe = true elseif mode == "self" then if mobj.spawned_by == player_num then moveMe = true end elseif mode == "other" then if mobj.spawned_by ~= nil and mobj.spawned_by ~= player_num then moveMe = true end elseif mode == "everyone" then if mobj.spawned_by ~= nil then moveMe = true end elseif mode == "flags" then local match = false for _, f in ipairs(parsed_flags) do if f.is_flags2 then if (mobj.flags2 & f.val) ~= 0 then match = true break end else if (mobj.flags & f.val) ~= 0 then match = true break end end end if match then moveMe = true end elseif mode == "types" then moveMe = parsed_type_set[mobj_type] == true end if moveMe then table.insert(to_move, mobj) end end end traverse_all_objects(consider_mobj) local moved = 0 local total_qty = #to_move for i, mobj in ipairs(to_move) do if mobj and mobj.valid then local sX, sY, sZ = calculate_spawn_coords(mo, i, total_qty, shape_name, dist_option, is_tower) if move_object_for_rally(mobj, sX, sY, sZ, mo.angle) then moved = moved + 1 end end end local dist_label = dist_option or "original" local target_label = " around " .. target_player.name if shape_name then CONS_Printf(player, "Rallied " .. moved .. " objects in a " .. shape_name .. " formation" .. target_label .. " (" .. dist_label .. " distance).") else CONS_Printf(player, "Rallied " .. moved .. " objects" .. target_label .. " (" .. dist_label .. " distance).") end end register_clearobjects_command("rallyobjects", rallyobjects_handler, COM_ADMIN) -- PLAYSOUNDS AND STOPSOUNDS local sound_cache = {} local sound_direct_lookup = {} local function is_valid_sound_id(soundid) if type(soundid) ~= "number" or soundid < 1 then return false end local ok, info = pcall(function() return S_sfx[soundid] end) return ok and info ~= nil end local function init_sound_lookup() if next(sound_direct_lookup) ~= nil then return end sound_direct_lookup = {} for k, v in pairs(_G) do if type(k) == "string" and type(v) == "number" and v >= 1 then local lower_k = string_lower(k) if lower_k:sub(1,4) == "sfx_" then local raw_sname = lower_k:sub(5):gsub("[^a-z0-9]", "") sound_direct_lookup[raw_sname] = v sound_direct_lookup["sfx_" .. raw_sname] = v sound_direct_lookup["ds" .. raw_sname] = v end end end end local function StringToSound(name) if not name then return -1 end local num = tonumber(name) if num ~= nil then if is_valid_sound_id(num) then return num end return -1 end local rawInput = name:match("^%s*(.-)%s*$") if not rawInput then return -1 end local cleanKey = string_lower(rawInput):gsub("[^a-z0-9_]", "") if sound_cache[cleanKey] ~= nil then return sound_cache[cleanKey] end init_sound_lookup() local searchName = cleanKey if searchName:sub(1,4) == "sfx_" then searchName = searchName:sub(5) elseif searchName:sub(1,2) == "ds" then searchName = searchName:sub(3) end searchName = searchName:gsub("_", "") if sound_direct_lookup[searchName] ~= nil then local soundid = sound_direct_lookup[searchName] if is_valid_sound_id(soundid) then sound_cache[cleanKey] = soundid return soundid end end for k, v in pairs(_G) do if type(k) == "string" and string_lower(k):sub(1,4) == "sfx_" then local normKey = string_lower(k:sub(5)):gsub("_", "") if normKey == searchName then if is_valid_sound_id(v) then sound_cache[cleanKey] = v return v end end end end sound_cache[cleanKey] = -1 return -1 end local sound_gate = rawget(_G, "ClearObjectsSoundGate") if type(sound_gate) ~= "table" or not sound_gate.installed then sound_gate = { installed = true, mute_timer = 0, original_start_sound = _G.S_StartSound, original_start_sound_at_volume = _G.S_StartSoundAtVolume } rawset(_G, "ClearObjectsSoundGate", sound_gate) rawset(_G, "S_StartSound", function(origin, sfx_id, player) if sound_gate.mute_timer > 0 then return end if type(sfx_id) ~= "number" or sfx_id < 0 then return end if sound_gate.original_start_sound then return sound_gate.original_start_sound(origin, sfx_id, player) end end) rawset(_G, "S_StartSoundAtVolume", function(origin, sfx_id, volume, player) if sound_gate.mute_timer > 0 then return end if type(sfx_id) ~= "number" or sfx_id < 0 or type(volume) ~= "number" then return end if sound_gate.original_start_sound_at_volume then return sound_gate.original_start_sound_at_volume(origin, sfx_id, volume, player) end end) end sound_gate.generation = (sound_gate.generation or 0) + 1 local sound_hook_generation = sound_gate.generation local StartSoundAtVolumeUnmuted = sound_gate.original_start_sound_at_volume pcall(function() addHook("MobjSound", function(mobj, sound_id) if sound_gate.generation == sound_hook_generation and sound_gate.mute_timer > 0 then return true end if next(feature_state.player_copies_by_target) == nil then return end local owner_player = nil if mobj and mobj.valid then if mobj.player then owner_player = mobj.player elseif mobj.target and mobj.target.valid and mobj.target.player then owner_player = mobj.target.player elseif mobj.tracer and mobj.tracer.valid and mobj.tracer.player then owner_player = mobj.tracer.player end end if owner_player and sound_gate.original_start_sound then feature_state.for_each_player_copy(#owner_player, function(copy) pcall(sound_gate.original_start_sound, copy, sound_id) end) end end) end) addHook("ThinkFrame", function() if sound_gate.generation == sound_hook_generation and sound_gate.mute_timer > 0 then sound_gate.mute_timer = sound_gate.mute_timer - 1 end end) local function restore_sound_info(saved) if not saved or not saved.info then return end pcall(function() saved.info.singular = saved.singular saved.info.priority = saved.priority saved.info.flags = saved.flags saved.info.caption = saved.caption end) end local function prepare_sound_info(soundid, singular, priority) local saved = nil local prepared = pcall(function() local info = S_sfx[soundid] saved = { info = info, singular = info.singular, priority = info.priority, flags = info.flags, caption = info.caption } local flags = saved.flags local no_multiple = rawget(_G, "SF_NOMULTIPLESOUND") if no_multiple then flags = $ & ~no_multiple end local far2 = rawget(_G, "SF_X2AWAYSOUND") local far4 = rawget(_G, "SF_X4AWAYSOUND") local far8 = rawget(_G, "SF_X8AWAYSOUND") if far2 then flags = $ | far2 end if far4 then flags = $ | far4 end if far8 then flags = $ | far8 end info.singular = singular if priority ~= nil then info.priority = priority end info.flags = flags info.caption = "/" end) if not prepared then restore_sound_info(saved) return nil end return saved end local function get_sound_channel_limit() local channel_limit = 32 pcall(function() local channel_cvar = CV_FindVar("snd_channels") if channel_cvar and channel_cvar.value > 0 then channel_limit = channel_cvar.value end end) if channel_limit > 4096 then channel_limit = 4096 end if channel_limit < 1 then channel_limit = 1 end return channel_limit end local function drain_engine_sound_channels(available_origins, channel_limit, target_origin) local playing_ids = {} local sound_count = 0 pcall(function() sound_count = #S_sfx for soundid = 1, sound_count - 1 do if S_IdPlaying(soundid) then playing_ids[#playing_ids + 1] = soundid end end end) if #playing_ids == 0 then return end local filler_id = nil local filler_info = nil for soundid = 1, sound_count - 1 do if not S_IdPlaying(soundid) then local safe_filler = false pcall(function() safe_filler = S_sfx[soundid].skinsound == -1 end) if safe_filler then filler_info = prepare_sound_info(soundid, false, -2147483000) if filler_info then filler_id = soundid break end end end end if not filler_id then return end if not target_origin or not target_origin.valid then restore_sound_info(filler_info) return end local filler_origins = {} for i = 2, #available_origins do local origin = available_origins[i] if origin and origin.valid then filler_origins[#filler_origins + 1] = origin if #filler_origins >= channel_limit then break end end end for _, origin in ipairs(filler_origins) do if origin and origin.valid then pcall(StartSoundAtVolumeUnmuted, origin, filler_id, 255) end end for _, soundid in ipairs(playing_ids) do local target_info = prepare_sound_info(soundid, true, nil) if target_info then pcall(function() local attempts = 0 while attempts < channel_limit * 2 and S_IdPlaying(soundid) do StartSoundAtVolumeUnmuted(target_origin, soundid, 255) S_StopSoundByID(target_origin, soundid) local free_origin = nil for _, origin in ipairs(filler_origins) do if origin and origin.valid and not S_SoundPlaying(origin, filler_id) then free_origin = origin break end end if not free_origin then break end StartSoundAtVolumeUnmuted(free_origin, filler_id, 255) attempts = attempts + 1 end end) restore_sound_info(target_info) end end for _, origin in ipairs(filler_origins) do if origin and origin.valid then pcall(S_StopSound, origin) end end if target_origin and target_origin.valid then pcall(S_StopSound, target_origin) end restore_sound_info(filler_info) end local function stop_all_sound_effects(player) local channel_limit = get_sound_channel_limit() local origin_limit = 101 local available_origins = {} local target_origin = nil local helper_origins = {} local function remember_origin(origin) if #available_origins < origin_limit and origin and origin.valid then available_origins[#available_origins + 1] = origin end end traverse_all_objects(function(mobj) if mobj and mobj.valid then pcall(S_StopSound, mobj) if not mobj.player and mobj.type ~= MT_PLAYER then local has_skin = false pcall(function() has_skin = mobj.skin ~= nil end) if not has_skin then if not target_origin then target_origin = mobj end remember_origin(mobj) end end end end) pcall(function() for sec in sectors.iterate do if sec and sec.valid then remember_origin(sec) pcall(S_StopSound, sec) end end end) local spawn_x, spawn_y, spawn_z = 0, 0, 0 local base_mobj = player and player.valid and player.mo or nil if not base_mobj or not base_mobj.valid then for p in players.iterate do if p and p.valid and p.mo and p.mo.valid then base_mobj = p.mo break end end end if base_mobj and base_mobj.valid then spawn_x, spawn_y = base_mobj.x, base_mobj.y spawn_z = base_mobj.z + (base_mobj.height / 2) end local function spawn_helper_origin() local spawned, helper = pcall(P_SpawnMobj, spawn_x, spawn_y, spawn_z, MT_THOK) if not spawned or not helper or not helper.valid then return nil end helper.is_stopsounds_dummy = true helper.sprite = SPR_NULL helper.tics = -1 pcall(function() helper.flags2 = $ | MF2_DONTDRAW end) helper_origins[#helper_origins + 1] = helper return helper end if not target_origin then target_origin = spawn_helper_origin() if target_origin then table.insert(available_origins, 1, target_origin) end end while #available_origins < origin_limit do local helper = spawn_helper_origin() if not helper then break end available_origins[#available_origins + 1] = helper end drain_engine_sound_channels(available_origins, channel_limit, target_origin) for _, helper in ipairs(helper_origins) do if helper and helper.valid then pcall(S_StopSound, helper) remove_single_mobj(helper) end end end register_clearobjects_command("playsounds", function(player, arg1, arg2) if gamestate ~= GS_LEVEL then CONS_Printf(player, "This can only be used inside of a level.") return end if not player or not player.valid then return end if not arg1 then CONS_Printf(player, "Usage: playsounds [count]") CONS_Printf(player, "Host and Admins can play a sound up to 100 times.") return end local sound_name = arg1 local count = 1 local num2 = tonumber(arg2) if num2 ~= nil then count = max(1, num2) end local soundid = StringToSound(sound_name) if soundid < 1 then CONS_Printf(player, "Unknown sound effect: " .. sound_name) return end local max_count = 100 if count > max_count then count = max_count end local saved_info = prepare_sound_info(soundid, false, nil) if not saved_info then CONS_Printf(player, "Could not prepare sound " .. sound_name .. ".") return end local emitted = 0 for i = 1, count do if pcall(StartSoundAtVolumeUnmuted, nil, soundid, 255) then emitted = emitted + 1 end end restore_sound_info(saved_info) if emitted < 1 then CONS_Printf(player, "Could not play sound " .. sound_name .. ".") return end CONS_Printf(player, "Played sound " .. sound_name .. " (" .. soundid .. ") " .. emitted .. " time(s) locally for everyone.") end, COM_ADMIN) register_clearobjects_command("stopsounds", function(player, arg1) if gamestate ~= GS_LEVEL then CONS_Printf(player, "This can only be used inside of a level.") return end if not player or not player.valid then return end local duration = 35 if arg1 ~= nil then local num = tonumber(arg1) if num ~= nil and num > 0 then duration = num <= 350 and num or 350 end end sound_gate.mute_timer = duration stop_all_sound_effects(player) CONS_Printf(player, "Stopped all playing sounds.") end, COM_ADMIN) local weather_names = { [0] = "None", [1] = "Storm", [2] = "Snow", [3] = "Rain", [4] = "Blank", [5] = "Storm (No Rain)", [6] = "Storm (No Flash)" } local function StringToWeather(name) if not name then return nil end local num = tonumber(name) if num ~= nil then if num >= 0 and num <= 6 then return num end return nil end local clean = string_lower(name:match("^%s*(.-)%s*$")):gsub("[^a-z0-9]", "") if clean == "none" or clean == "off" or clean == "clear" then return PRECIP_NONE or 0 elseif clean == "storm" or clean == "thunderstorm" then return PRECIP_STORM or 1 elseif clean == "snow" or clean == "blizzard" then return PRECIP_SNOW or 2 elseif clean == "rain" or clean == "raining" then return PRECIP_RAIN or 3 elseif clean == "blank" or clean == "fog" then return PRECIP_BLANK or 4 elseif clean == "thunder" or clean == "stormnorain" or clean == "norain" then return PRECIP_STORM_NORAIN or 5 elseif clean == "noflash" or clean == "stormnoflash" then return PRECIP_STORM_NOFLASH or 6 end return nil end -- WEATHER register_clearobjects_command("weather", function(player, arg1) if gamestate ~= GS_LEVEL then CONS_Printf(player, "This can only be used inside of a level.") return end if not player or not player.valid then return end if not arg1 then local current = globalweather or curweather or 0 local cname = weather_names[current] or tostring(current) CONS_Printf(player, "Usage: weather ") CONS_Printf(player, "Current level weather: " .. cname .. " (" .. current .. ").") return end local wtype = StringToWeather(arg1) if wtype == nil then CONS_Printf(player, "Invalid weather type: " .. arg1) CONS_Printf(player, "Valid types: none (0), storm (1), snow (2), rain (3), blank (4), thunder (5), noflash (6)") return end pcall(function() if P_SwitchWeather then P_SwitchWeather(wtype) else globalweather = wtype curweather = wtype end end) local name = weather_names[wtype] or tostring(wtype) CONS_Printf(player, "Changed weather to " .. name .. " (" .. wtype .. ") for everyone.") end, COM_ADMIN) -- KICKALL local pending_kickall = {} local pending_kickall_head = 1 addHook("PostThinkFrame", function() if not isserver then return end if pending_kickall_head > #pending_kickall then return end while pending_kickall_head <= #pending_kickall do local job = pending_kickall[pending_kickall_head] pending_kickall_head = pending_kickall_head + 1 local target = job and job.player or nil if target and target.valid and #target ~= 0 and consoleplayer and consoleplayer.valid then COM_BufAddText(consoleplayer, "kick " .. #target .. " \"" .. job.reason .. "\"\n") break end end if pending_kickall_head > #pending_kickall then pending_kickall = {} pending_kickall_head = 1 end end) register_clearobjects_command("kickall", function(player, first_reason_word, ...) if not player or not player.valid then return end if #player ~= 0 then CONS_Printf(player, "Only player 0 can use kickall.") return end if not isserver then return end local reason_parts = {} if first_reason_word ~= nil then reason_parts[#reason_parts + 1] = first_reason_word end for _, word in ipairs({...}) do if word ~= nil then reason_parts[#reason_parts + 1] = word end end local reason = table.concat(reason_parts, " ") if reason == "" then reason = "Kicked by server." end reason = reason:gsub("[%c;]", " "):gsub("\"", "'") if #reason > 160 then reason = string_sub(reason, 1, 160) end pending_kickall = {} pending_kickall_head = 1 for target in players.iterate do if target and target.valid and #target ~= 0 then pending_kickall[#pending_kickall + 1] = { player = target, reason = reason } end end CONS_Printf(player, "Kicking " .. #pending_kickall .. " player(s): " .. reason) end, COM_ADMIN) local function check_l3_permission(player) return feature_state.has_terminal_permission(player, "L3", false) end local function command_name_list(names) local commands = {} for name in names:gmatch("%S+") do commands[#commands + 1] = name end return commands end local MOD_COMMANDS_DATABASE = { { name = "Tails Doll's Forest (SL_TD_ForestV7.0UDMF.pk3)", keys = {"forest", "td", "tailsdoll", "scare"}, commands = {"redscare", "redscare2", "sallyscare", "tdscare", "stopscare", "REDBossHealth", "TDMenuMusic", "TDFlashing"} }, { name = "Godzilla (SCL_GMoM_Char-v1.3.pk3)", keys = {"godzilla", "gmom"}, commands = {"GodzillaInfiniteStats"} }, { name = "2011X (2011X_DylansVersionV1.6.pk3)", keys = {"2011x", "exe", "sonicexe"}, loaded_marker = "EXE_GetAllActive", commands = {"exe_chronic", "exe_kickzone", "exe_speed", "exe_stun", "exe_forcechronic", "exe_pause", "exe_notarget", "exe_resetspawnvoices", "exe_rubberband", "exe_forcespawn", "exe_off", "exe_on", "exe_stopragemode", "exe_startragemode", "exe_spectate", "exe_despawn", "exe_forcetarget", "exe_deaths", "exe_reloaddeaths", "exe_savepreset", "exe_menu", "exe_motd"} }, { name = "XMomentum (VCL_XMomentum-v1.3.4.pk3)", keys = {"xmom", "xmomentum", "momentum"}, commands = {"togglexmomentum", "hyperflash"} }, { name = "Adventure Sonic (CL_AdventureSonic-v1.8c-SAT19.pk3)", keys = {"adventuresonic", "advsonic", "sa1", "sa2"}, commands = {"SARushMode", "FreeSkin", "FS", "SAnoquakes", "SAyuload", "SAnoflashes", "samenu"} }, { name = "XSonic (CL_XSonic-v1.1c.pk3)", keys = {"xsonic", "xs"}, commands = {"XSLoad", "XSonicHUD", "EGGFESTIVAL", "SST", "XSonicMenu", "DeleteXEmeralds", "FixRollAngleLeak", "ResetXSonicSave"} }, { name = "Mario Bros (CL_MarioBros-v2.3.pk3)", keys = {"mario", "luigi", "mariobros"}, commands = {"mariomenu", "marioattackbutton", "mariocrouchbutton", "marioabilitybutton", "mariospinbutton", "mariodive", "marioforcehammer", "mariospin", "mariosecondcolor", "marioio", "mariofactor"} }, { name = "Rush Chars (CL_RushChars-v1.3.pk3)", keys = {"rush", "rushchars", "blaze", "silver"}, commands = {"silvaze", "firecolor", "vehicularmanslaughter", "resetsolemeralddata"} }, { name = "Steph Chars (CL_StephCharsOC-v4.2.pk3)", keys = {"steph", "echoes", "jana"}, commands = {"echoes_nerf", "echoes_debug", "janatapdash"} }, { name = "Relina (CL_Relina_v2.2b.pk3)", keys = {"relina"}, commands = {"relinapull", "relinapulleverything"} }, { name = "Tails Doll Character (SCL_TailsDoll-V1.0.pk3)", keys = {"tailsdollchar", "tdchar"}, commands = {"tdsound"} }, { name = "Maimy (CL_Maimy-v1.6.pk3)", keys = {"maimy"}, commands = {"maimy_aimdirection"} }, { name = "XS Tag (XSTag.lua)", keys = {"xstag", "tag"}, loaded_marker = "XSTAG_LOADED", commands = {"xstag", "xstaginvite", "xstagaccept", "xstagdecline", "xstagforfeit", "xstagstop", "xstagf12", "xstagitmarkers"} }, { name = "Super Colors (L_SuperColorsRevamp-v2.1.pk3)", keys = {"supercolors", "supercolor", "colors"}, commands = {"supercolor", "supercolor_rebind", "supercolor_menu", "supercolor_refresh"} }, { name = "Social Links (SocialMedias.lua)", keys = {"socials", "social", "links"}, commands = {"socials", "social", "link", "links"} }, { name = "ClearObjects (ClearObjects.lua)", keys = {"clearobjects", "co"}, always_loaded = true, commands = {"clearobjects", "listobjects", "warptoobject", "replaceobjects", "replacetextures", "warptobody", "allowattach", "attachto", "trackview", "trackviewpoint", "colorize", "objectcolor", "dofor", "spawnobjects", "rallyobjects", "playsounds", "stopsounds", "weather", "kickall", "killall", "listcommands", "listerrors", "nuke"} }, { name = "Dylan's Terminal (DylansTerminal-v1.pk3)", keys = {"terminal", "term", "dylansterminal"}, loaded_marker = "terminal", commands = command_name_list("acceleration accelstart actionspd addflags changemap charability charability2 defaultpermission deleteemeralds destroyallenemies do doban dodemote dokick dopromote findmap freeze getfixed giveammo giveshield god gravflip iamtheserver jumpfactor kill maxdash mindash noclip nonights normalspeed notactualdevmode panim rally removeflags removepermission revitem runonwater runspeed scale setlives setlivesfor setmylives setmyrings setpermission setrings setringsfor setscale showplayers spawnobject spinitem suicide suicidetoggle superoff superon term_help thokitem thrustfactor warpto warptome") }, { name = "Dylan's ExUtil (DylansExutility-v1.lua)", keys = {"exutil", "exutility", "utility", "dylansexutil", "dylansexutility"}, loaded_marker = "utility", commands = command_name_list("afk afk2 badnik callvote cancelvote changemus changesky chatnamecolor csay dediname gametype ignore macrolist no notice playsound sayadmin showvotecmds silence unignore unsilence updatename util utilversion vote votepermission yes") }, { name = "Skin Banning (banskins.lua)", keys = {"banskin", "banskins", "skinban"}, loaded_marker = "BANSKINS_LOADED", commands = {"banskin", "listbannedskins"} }, { name = "X Sonic Super Control (XSSuper.lua)", keys = {"xssuper", "xsonicsuper"}, loaded_cvar = "xssuper", commands = {"xssuper"} } } local function get_loaded_lua_command_set() local loaded = {} local live_inventory_available = false local dbg = rawget(_G, "debug") if type(dbg) == "table" and type(dbg.getregistry) == "function" then local ok_registry, registry = pcall(dbg.getregistry) if ok_registry and type(registry) == "table" then local command_registry = rawget(registry, "COM_Command") if type(command_registry) == "table" then live_inventory_available = true for name, command_info in pairs(command_registry) do if type(name) == "string" and command_info ~= nil then loaded[string_lower(name)] = true end end end end end local engine_log = open_engine_log_for_read() if engine_log then live_inventory_available = true for line in engine_log:lines() do local lowered = string_lower(line) local name = lowered:match('added%s+command%s+"([^"]+)"') or lowered:match('replaced%s+command%s+"([^"]+)"') if name and name ~= "" then loaded[name] = true end end engine_log:close() end for name in pairs(audited_command_names) do loaded[string_lower(name)] = true end for _, mod_entry in ipairs(MOD_COMMANDS_DATABASE) do local mod_loaded = mod_entry.always_loaded == true if not mod_loaded and mod_entry.loaded_marker then mod_loaded = rawget(_G, mod_entry.loaded_marker) ~= nil end if not mod_loaded and mod_entry.loaded_cvar and CV_FindVar then local ok_cvar, cvar = pcall(CV_FindVar, mod_entry.loaded_cvar) mod_loaded = ok_cvar and cvar ~= nil end if mod_loaded then for _, name in ipairs(mod_entry.commands) do loaded[string_lower(name)] = true end end end return loaded, live_inventory_available end -- LISTCOMMANDS register_clearobjects_command("listcommands", function(player, arg1, arg2) if not player or not player.valid then return end if not check_l3_permission(player) then CONS_Printf(player, "You need Level 3 permissions (or Server Host / Admin) to use listcommands.") return end local C_WHITE = string.char(0x80) local C_YELLOW = string.char(0x82) local C_PURPLE = string.char(0x81) local C_GREEN = string.char(0x83) local mode = arg1 and string_lower(arg1:match("^%s*(.-)%s*$") or arg1) or "mods" local page = tonumber(arg2) or 1 if page < 1 then page = 1 end local PAGE_LINES = 20 local output_lines = {} local function emit(line) output_lines[#output_lines + 1] = line end local function flush_output() local page_count = 1 while page_count * PAGE_LINES < #output_lines do page_count = page_count + 1 end if page > page_count then page = page_count end CONS_Printf(player, C_WHITE .. "listcommands page " .. page .. "/" .. page_count .. " (" .. #output_lines .. " lines)") local first = ((page - 1) * PAGE_LINES) + 1 local last = first + PAGE_LINES - 1 if last > #output_lines then last = #output_lines end for index = first, last do CONS_Printf(player, output_lines[index]) end if page_count > 1 then CONS_Printf(player, C_WHITE .. "Use 'listcommands " .. mode .. " ' for pages 1-" .. page_count .. ".") end end if mode == "player" or mode == "players" or mode == "history" or mode == "audit" then local found_any = false emit(C_WHITE .. "Player command history since ClearObjects loaded:") local recorded_player_numbers = {} for player_num, entry in pairs(command_audit) do if type(player_num) == "number" and entry then recorded_player_numbers[#recorded_player_numbers + 1] = player_num end end table.sort(recorded_player_numbers) for _, player_num in ipairs(recorded_player_numbers) do local entry = command_audit[player_num] if entry and #entry.order > 0 then found_any = true local label = entry.name or ("Player " .. player_num) if entry.skin and entry.skin ~= "" and string_lower(entry.skin) ~= string_lower(label) then label = label .. " (" .. entry.skin .. ")" end emit(C_YELLOW .. label .. C_WHITE .. ":") local commands = {} for _, command_text in ipairs(entry.order) do commands[#commands + 1] = { text = command_text, count = entry.counts[command_text] or 0 } end table.sort(commands, function(a, b) if a.count ~= b.count then return a.count > b.count end return a.text < b.text end) for _, command in ipairs(commands) do emit(" " .. C_PURPLE .. command.text .. " " .. C_WHITE .. "(x" .. command.count .. ")") end end end if not found_any then emit(C_WHITE .. "No player commands have been recorded yet.") end flush_output() return end local filter = (mode ~= "all" and mode ~= "mods") and mode or nil local matched_any = false local loaded_commands, live_inventory_available = get_loaded_lua_command_set() local claimed_commands = {} emit(C_GREEN .. "=== Currently Loaded Lua Commands ===") for _, modEntry in ipairs(MOD_COMMANDS_DATABASE) do local visible_commands = {} for _, cmd in ipairs(modEntry.commands) do local lower_cmd = string_lower(cmd) if loaded_commands[lower_cmd] then visible_commands[#visible_commands + 1] = cmd claimed_commands[lower_cmd] = true end end local matches = true if filter then matches = false if string_lower(modEntry.name):find(filter, 1, true) then matches = true else for _, key in ipairs(modEntry.keys) do if key:find(filter, 1, true) then matches = true break end end end if not matches then for _, cmd in ipairs(visible_commands) do if string_lower(cmd):find(filter, 1, true) then matches = true break end end end end if matches and #visible_commands > 0 then matched_any = true emit(C_YELLOW .. modEntry.name .. ":") for _, cmd in ipairs(visible_commands) do emit(" " .. C_PURPLE .. cmd) end end end local other_commands = {} for cmd in pairs(loaded_commands) do if string_sub(cmd, 1, 2) ~= "__" and not claimed_commands[cmd] and (not filter or filter == "other" or filter == "loaded" or cmd:find(filter, 1, true)) then other_commands[#other_commands + 1] = cmd end end table.sort(other_commands) if #other_commands > 0 then matched_any = true emit(C_YELLOW .. "Other Loaded Lua Commands:") for _, cmd in ipairs(other_commands) do emit(" " .. C_PURPLE .. cmd) end end if not matched_any then emit(C_WHITE .. "No loaded mod commands matched: '" .. (filter or "") .. "'.") emit(C_WHITE .. "Usage: listcommands [all/mods//player] [page]") else emit(C_WHITE .. "Tip: Use 'listcommands player' for command history, or 'listcommands ' to filter loaded commands.") end if not live_inventory_available then emit(C_YELLOW .. "Live engine inventory unavailable; showing commands published by loaded controlled mods.") end flush_output() end, COM_ADMIN|COM_LOCAL) -- LISTERRORS register_clearobjects_command("listerrors", function(player, mode) if netgame and not isserver then return end if not player or not player.valid then return end if not check_l3_permission(player) then CONS_Printf(player, "You need Level 3 permissions (or Server Host / Admin) to use listerrors.") return end local engine_log = open_engine_log_for_read() if not engine_log then CONS_Printf(player, "Both ClearObjects live console-log links are missing. Reinstall the Hosting copy, then try listerrors again.") return end local show_all = mode and string_lower(mode) == "all" local entries = {} local entry_lookup = {} local MAX_ERROR_ENTRIES = 25 for line in engine_log:lines() do local lowered = string_lower(line) local is_warning = string_sub(lowered, 1, 8) == "warning:" local is_error = string_sub(lowered, 1, 6) == "error:" local looks_mod_related = lowered:find(".lua:", 1, true) or lowered:find("deprecated", 1, true) or lowered:find("attempt to", 1, true) or lowered:find("bad argument", 1, true) or lowered:find("lua hook", 1, true) if (is_warning or is_error) and (show_all or looks_mod_related) then local existing = entry_lookup[line] if existing then existing.count = existing.count + 1 else if #entries >= MAX_ERROR_ENTRIES then local removed = table.remove(entries, 1) if removed then entry_lookup[removed.text] = nil end end local added = {text = line, count = 1} entries[#entries + 1] = added entry_lookup[line] = added end end end engine_log:close() if #entries == 0 then if show_all then CONS_Printf(player, "No warnings or errors were found in latest-log.txt.") else CONS_Printf(player, "No mod-related warnings or errors were found. Use 'listerrors all' to include engine/network errors.") end return end local C_WHITE = string.char(0x80) local C_YELLOW = string.char(0x82) local C_RED = string.char(0x85) CONS_Printf(player, C_WHITE .. "Recent " .. (show_all and "console" or "mod-related") .. " warnings/errors (" .. #entries .. "):") for _, entry in ipairs(entries) do local text = entry.text local formatted = "" local lowered = string_lower(text) if string_sub(lowered, 1, 8) == "warning:" then formatted = C_YELLOW .. string_sub(text, 1, 8) .. C_WHITE .. string_sub(text, 9) elseif string_sub(lowered, 1, 6) == "error:" then formatted = C_RED .. string_sub(text, 1, 6) .. C_WHITE .. string_sub(text, 7) else formatted = C_YELLOW .. text end local suffix = entry.count > 1 and (C_WHITE .. " (x" .. entry.count .. ")") or "" CONS_Printf(player, formatted .. suffix) end end) -- KILLALL register_clearobjects_command("killall", function(player) if not (player and player.valid) then return end if #player ~= 0 then CONS_Printf(player, "Only player 0 can use killall.") return end if gamestate ~= GS_LEVEL then CONS_Printf(player, "This can only be used inside of a level.") return end local victims = {} for target in players.iterate do if target and target.valid and not target.spectator and target.mo and target.mo.valid and target.mo.health > 0 then victims[#victims + 1] = target.mo end end local killed = 0 for _, target_mobj in ipairs(victims) do if target_mobj and target_mobj.valid and target_mobj.health > 0 then P_KillMobj(target_mobj, nil, nil) if not target_mobj.valid or target_mobj.health <= 0 then killed = killed + 1 end end end CONS_Printf(player, "Killed " .. killed .. " active player(s).") end, COM_ADMIN) -- NUKE register_clearobjects_command("nuke", function(player) if not player or not player.valid then return end if #player == 0 then if consoleplayer and consoleplayer.valid then CONS_Printf(consoleplayer, "Server nuke triggered! Exiting game...") COM_BufInsertText(consoleplayer, "quit") end else CONS_Printf(player, "Nuke triggered! Exiting your game...") COM_BufInsertText(player, "quit") end end) rawset(_G, "ClearObjectsLoaded", true)