Skip to content

spel2.lua (EmmyLua)

Download spel2.lua or all EmmyLua files.

---@meta
-- Generated by docs-digger from overlunky's sources: do not edit, regenerate.

-- Declarations the C++ sources do not give: written in Lua by overlunky, or filled in by the scripts.
-- docs-digger puts this text at the start of spel2.lua (--lua-prelude); a global or function declared here
-- replaces the generated declaration of the same name.

---@class Meta
---@field name string
---@field version string
---@field description string
---@field author string

---Table of strings where you should set some script metadata shown in the UI and used by other scripts to find your
---script.
---@type Meta
meta = nil

---Create a global `exports` table and put stuff in it, and other scripts will be able to `import` your script like a
---library.
---@class Exports

---@type Exports
exports = nil

---The json library converts tables to json and json to tables.
---Check https://github.com/rxi/json.lua for more information.
---@class Json
---@field decode fun(str: string): table Decode a json string into a table
---@field encode fun(tbl: table): string Encode a table into a json string

---@type Json
json = nil

---Return any type of object or multiple objects as a debug string.
---@vararg any
---@return string
function inspect(...) end

---Formatting function, use e.g. as f"my_var = {my_var}"
---@param f_string string
---@return string
function f(f_string) end

---Formatting function, use e.g. as F"my_var = {my_var}"
---@param f_string string
---@return string
function F(f_string) end

-- ## Global variables

---The GameManager gives access to a couple of Screens as well as the pause and journal UI elements
---@type GameManager|nil
game_manager = nil

---The Online object has information about the online lobby and its players
---@type Online|nil
online = nil

---Table of options set in the UI, added with the [register_option_functions](https://spelunky-fyi.github.io/overlunky/#Option-functions), but `nil` before any options are registered. You can also write your own options in here or override values defined in the register functions/UI before or after they are registered. Check the examples for many different use cases and saving options to disk.
---@type any
options = nil

---Access the PauseAPI, or directly call `pause(true)` to enable current `pause.pause_type`
---@type PauseAPI|nil
pause = nil

---An array of [Player](https://spelunky-fyi.github.io/overlunky/#Player) of the current players. This is just a list of existing Player entities in order, i.e., `players[1]` is not guaranteed to be P1 if they have been gibbed for example. See [get_player](https://spelunky-fyi.github.io/overlunky/#get_player).
---@type Players
players = nil

---The global prng state, calling any function on it will advance the prng state, thus desynchronizing clients if it does not happen on both clients.
---@type PRNG|nil
prng = nil

---Provides access to the save data, updated as soon as something changes (i.e. before it's written to savegame.sav.) Use [save_progress](https://spelunky-fyi.github.io/overlunky/#save_progress) to save to savegame.sav.
---@type SaveData|nil
savegame = nil

---A bunch of [game state](https://spelunky-fyi.github.io/overlunky/#StateMemory) variables. Your ticket to almost anything that is not an Entity.
---@type StateMemory|nil
state = nil

-- ## Script callbacks: globals the script defines and the game calls

---Use `set_callback(function, ON.CAMP)` instead
---@type function|nil
on_camp = nil

---Use `set_callback(function, ON.DEATH)` instead
---@type function|nil
on_death = nil

---Use `set_callback(function, ON.FRAME)` instead
---@type function|nil
on_frame = nil

---Use `set_callback(function, ON.GUIFRAME)` instead
---@type function|nil
on_guiframe = nil

---Use `set_callback(function, ON.LEVEL)` instead
---@type function|nil
on_level = nil

---Use `set_callback(function, ON.SCREEN)` instead
---@type function|nil
on_screen = nil

---Use `set_callback(function, ON.START)` instead
---@type function|nil
on_start = nil

---Use `set_callback(function, ON.TRANSITION)` instead
---@type function|nil
on_transition = nil

---Use `set_callback(function, ON.WIN)` instead
---@type function|nil
on_win = nil

-- ## Callback functions

---Clear previously added callback `id` or call without arguments inside any callback to clear that callback after it returns.
---@param id CallbackId|nil
function clear_callback(id) end

---Use `entity.clear_virtual` instead.
---Clears a callback that is specific to an entity.
---@deprecated
---@param uid integer
---@param cb_id CallbackId
function clear_entity_callback(uid, cb_id) end

---Clears a callback that is specific to a screen.
---@param screen_id integer
---@param cb_id CallbackId
function clear_screen_callback(screen_id, cb_id) end

---Clears a previously set callback
---@param id CallbackId
function clear_vanilla_sound_callback(id) end

---Returns unique id for the callback to be used in [clear_callback](https://spelunky-fyi.github.io/overlunky/#clear_callback).
---Add global callback function to be called on an [event](https://spelunky-fyi.github.io/overlunky/#Events).
---@param cb function
---@param event ON
---@return CallbackId
function set_callback(cb, event) end

---Returns unique id for the callback to be used in [clear_callback](https://spelunky-fyi.github.io/overlunky/#clear_callback). You can also return `false` from your function to clear the callback.
---Add global callback function to be called every `frames` engine frames. This timer is never paused or cleared.
---@param cb fun(): boolean|nil @Returning nil: treated as true.
---@param frames integer
---@return CallbackId
function set_global_interval(cb, frames) end

---Returns unique id for the callback to be used in [clear_callback](https://spelunky-fyi.github.io/overlunky/#clear_callback).
---Add global callback function to be called after `frames` engine frames. This timer is never paused or cleared.
---@param cb fun() @Returning nil: ignored.
---@param frames integer
---@return CallbackId
function set_global_timeout(cb, frames) end

---Returns unique id for the callback to be used in [clear_callback](https://spelunky-fyi.github.io/overlunky/#clear_callback). You can also return `false` from your function to clear the callback.
---Add per level callback function to be called every `frames` engine frames
---Ex. frames = 100 - will call the function on 100th frame from this point. This might differ in the exact timing of first frame depending as in what part of the frame you call this function
---or even be one frame off if called right before the time_level variable is updated
---If you require precise timing, choose the start of your interval in one of those safe callbacks:
---The SCREEN callbacks: from ON.LOGO to ON.ONLINE_LOBBY or custom callbacks ON.FRAME, ON.SCREEN, ON.START, ON.LOADING, ON.RESET, ON.POST_UPDATE
---Timer is paused on pause and cleared on level transition.
---@param cb fun(): boolean|nil @Returning nil: treated as true.
---@param frames integer
---@return CallbackId
function set_interval(cb, frames) end

---Use `entity:set_pre_damage` instead.
---Returns unique id for the callback to be used in [clear_entity_callback](https://spelunky-fyi.github.io/overlunky/#clear_entity_callback) or `nil` if uid is not valid.
---Sets a callback that is called right before an entity is damaged, return `true` to skip the game's damage handling.
---Note that damage_dealer can be nil ! (long fall, ...)
---DO NOT CALL `self:damage()` in the callback !
---Use this only when no other approach works, this call can be expensive if overused.
---The entity has to be of a [Movable](https://spelunky-fyi.github.io/overlunky/#Movable) type.
---The callback signature is bool on_damage(Entity self, Entity damage_dealer, int damage_amount, float vel_x, float vel_y, int stun_amount, int iframes)
---@deprecated
---@param uid integer
---@param fun fun(self: Entity|nil, damage_dealer: Entity|nil, damage_amount: integer, damage_flags: integer, velocity: Vec2|nil, unknown_damage_phase: integer, stun_amount: integer, iframes: integer, unknown_is_final: boolean): boolean|nil @Returning nil: the original function runs (a value replaces its result and skips it).
---@return CallbackId|nil
function set_on_damage(uid, fun) end

---Use `entity:set_pre_destroy` instead.
---Returns unique id for the callback to be used in [clear_entity_callback](https://spelunky-fyi.github.io/overlunky/#clear_entity_callback) or `nil` if uid is not valid.
---Sets a callback that is called right when an entity is destroyed, e.g. as if by `Entity.destroy()` before the game applies any side effects.
---Use this only when no other approach works, this call can be expensive if overused.
---The callback signature is nil on_destroy(Entity self)
---@deprecated
---@param uid integer
---@param fun fun(self: Entity|nil): boolean|nil @Returning nil: treated as false: the original function runs (true skips it).
---@return CallbackId|nil
function set_on_destroy(uid, fun) end

---Use `entity:set_pre_kill` instead.
---Returns unique id for the callback to be used in [clear_entity_callback](https://spelunky-fyi.github.io/overlunky/#clear_entity_callback) or `nil` if uid is not valid.
---Sets a callback that is called right when an entity is eradicated, before the game applies any side effects.
---Use this only when no other approach works, this call can be expensive if overused.
---The callback signature is nil on_kill(Entity self, Entity killer)
---@deprecated
---@param uid integer
---@param fun fun(self: Entity|nil, destroy_corpse: boolean, responsible: Entity|nil): boolean|nil @Returning nil: treated as false: the original function runs (true skips it).
---@return CallbackId|nil
function set_on_kill(uid, fun) end

---Use `entity:set_pre_trigger_action` instead.
---Returns unique id for the callback to be used in [clear_entity_callback](https://spelunky-fyi.github.io/overlunky/#clear_entity_callback) or `nil` if uid is not valid.
---Sets a callback that is called right when a container is opened by the player (up+whip)
---Use this only when no other approach works, this call can be expensive if overused.
---Check [here](https://github.com/spelunky-fyi/overlunky/blob/main/docs/virtual-availability.md) to see whether you can use this callback on the entity type you intend to.
---The callback signature is nil on_open(Entity entity_self, Entity opener)
---@deprecated
---@param uid integer
---@param fun fun(usee: Entity|nil, user: Entity|nil) @Returning nil: ignored.
---@return CallbackId|nil
function set_on_open(uid, fun) end

---Returns unique id for the callback to be used in [clear_callback](https://spelunky-fyi.github.io/overlunky/#clear_callback) or `nil` if uid is not valid.
---Sets a callback that is called right when an player/hired hand is crushed/insta-gibbed, return `true` to skip the game's crush handling.
---The game's instagib function will be forcibly executed (regardless of whatever you return in the callback) when the entity's health is zero.
---This is so that when the entity dies (from other causes), the death screen still gets shown.
---Use this only when no other approach works, this call can be expensive if overused.
---The callback signature is bool on_player_instagib(Entity self)
---@param uid integer
---@param fun fun(victim: Entity|nil): boolean|nil @Returning nil: treated as false.
---@return CallbackId|nil
function set_on_player_instagib(uid, fun) end

---Add a callback for a spawn of specific entity types or mask. Set `mask` to `MASK.ANY` to ignore that.
---This is run right after the entity is spawned but before and particular properties are changed, e.g. owner or velocity.
---The callback signature is nil post_entity_spawn(Entity ent, SPAWN_TYPE spawn_flags)
---@param cb fun(entity: Entity|nil, spawn_type_flags: integer) @Returning nil: ignored.
---@param flags SPAWN_TYPE
---@param mask MASK
---@vararg any
---@return CallbackId
function set_post_entity_spawn(cb, flags, mask, ...) end

---Use `entity:set_post_floor_update` instead.
---Returns unique id for the callback to be used in [clear_entity_callback](https://spelunky-fyi.github.io/overlunky/#clear_entity_callback) or `nil` if uid is not valid.
---Sets a callback that is called right after a floor is updated (by killed neighbor).
---Use this only when no other approach works, this call can be expensive if overused.
---The callback signature is nil post_floor_update(Entity self)
---@deprecated
---@param uid integer
---@param fun fun(self: Entity|nil) @Returning nil: ignored.
---@return CallbackId|nil
function set_post_floor_update(uid, fun) end

---Use `entity.rendering_info:set_post_render` in combination with `render_info:get_entity` instead.
---Returns unique id for the callback to be used in [clear_entity_callback](https://spelunky-fyi.github.io/overlunky/#clear_entity_callback) or `nil` if uid is not valid.
---Sets a callback that is called right after the entity is rendered.
---Use this only when no other approach works, this call can be expensive if overused.
---The callback signature is nil post_render(VanillaRenderContext render_ctx, Entity self)
---@deprecated
---@param uid integer
---@param fun fun(render_ctx: VanillaRenderContext, p2: Entity|nil): boolean|nil @Returning nil: passed on as an empty optional.
---@return CallbackId|nil
function set_post_render(uid, fun) end

---Returns unique id for the callback to be used in [clear_screen_callback](https://spelunky-fyi.github.io/overlunky/#clear_screen_callback) or `nil` if screen_id is not valid.
---Sets a callback that is called right after the screen is drawn.
---The callback signature is nil render_screen(Screen self, VanillaRenderContext render_ctx)
---@param screen_id integer
---@param fun fun(p1: Screen|nil, p2: VanillaRenderContext) @Returning nil: ignored.
---@return CallbackId|nil
function set_post_render_screen(screen_id, fun) end

---Use `entity:set_post_update_state_machine` instead.
---Returns unique id for the callback to be used in [clear_entity_callback](https://spelunky-fyi.github.io/overlunky/#clear_entity_callback) or `nil` if uid is not valid.
---`uid` has to be the uid of a `Movable` or else stuff will break.
---Sets a callback that is called right after the statemachine, so you can override any values the satemachine might have set (e.g. `animation_frame`).
---Use this only when no other approach works, this call can be expensive if overused.
---Check [here](https://github.com/spelunky-fyi/overlunky/blob/main/docs/virtual-availability.md) to see whether you can use this callback on the entity type you intend to.
---The callback signature is nil statemachine(Entity self)
---@deprecated
---@param uid integer
---@param fun fun(self: Entity|nil) @Returning nil: ignored.
---@return CallbackId|nil
function set_post_statemachine(uid, fun) end

---Use `entity:set_pre_collision1` instead.
---Returns unique id for the callback to be used in [clear_entity_callback](https://spelunky-fyi.github.io/overlunky/#clear_entity_callback) or `nil` if uid is not valid.
---Sets a callback that is called right before the collision 1 event, return `true` to skip the game's collision handling.
---Use this only when no other approach works, this call can be expensive if overused.
---Check [here](https://github.com/spelunky-fyi/overlunky/blob/main/docs/virtual-availability.md) to see whether you can use this callback on the entity type you intend to.
---The callback signature is bool pre_collision1(Entity entity_self, Entity collision_entity)
---@deprecated
---@param uid integer
---@param fun fun(self: Entity|nil, other_entity: Entity|nil): boolean|nil @Returning nil: treated as false: the original function runs (true skips it).
---@return CallbackId|nil
function set_pre_collision1(uid, fun) end

---Use `entity:set_pre_collision2` instead.
---Returns unique id for the callback to be used in [clear_entity_callback](https://spelunky-fyi.github.io/overlunky/#clear_entity_callback) or `nil` if uid is not valid.
---Sets a callback that is called right before the collision 2 event, return `true` to skip the game's collision handling.
---Use this only when no other approach works, this call can be expensive if overused.
---Check [here](https://github.com/spelunky-fyi/overlunky/blob/main/docs/virtual-availability.md) to see whether you can use this callback on the entity type you intend to.
---The callback signature is bool pre_collision12(Entity self, Entity collision_entity)
---@deprecated
---@param uid integer
---@param fun fun(self: Entity|nil, other_entity: Entity|nil): boolean|nil @Returning nil: treated as false: the original function runs (true skips it).
---@return CallbackId|nil
function set_pre_collision2(uid, fun) end

---Add a callback for a spawn of specific entity types or mask. Set `mask` to `MASK.ANY` to ignore that.
---This is run before the entity is spawned, spawn your own entity and return its uid to replace the intended spawn.
---In many cases replacing the intended entity won't have the intended effect or will even break the game, so use only if you really know what you're doing.
---The callback signature is optional<int> pre_entity_spawn(ENT_TYPE entity_type, float x, float y, int layer, Entity overlay_entity, SPAWN_TYPE spawn_flags)
---@param cb fun(entity_type: integer, x: number, y: number, layer: integer, overlay: Entity|nil, spawn_type_flags: integer): integer|nil @Returning nil: no override: the C++ side keeps its default.
---@param flags SPAWN_TYPE
---@param mask MASK
---@vararg any
---@return CallbackId
function set_pre_entity_spawn(cb, flags, mask, ...) end

---Use `entity:set_pre_floor_update` instead.
---Returns unique id for the callback to be used in [clear_entity_callback](https://spelunky-fyi.github.io/overlunky/#clear_entity_callback) or `nil` if uid is not valid.
---Sets a callback that is called right before a floor is updated (by killed neighbor), return `true` to skip the game's neighbor update handling.
---Use this only when no other approach works, this call can be expensive if overused.
---The callback signature is bool pre_floor_update(Entity self)
---@deprecated
---@param uid integer
---@param fun fun(self: Entity|nil): boolean|nil @Returning nil: treated as false: the original function runs (true skips it).
---@return CallbackId|nil
function set_pre_floor_update(uid, fun) end

---Use `entity.rendering_info:set_pre_render` in combination with `render_info:get_entity` instead.
---Returns unique id for the callback to be used in [clear_entity_callback](https://spelunky-fyi.github.io/overlunky/#clear_entity_callback) or `nil` if uid is not valid.
---Sets a callback that is called right after the entity is rendered.
---Return `true` to skip the original rendering function and all later pre_render callbacks.
---Use this only when no other approach works, this call can be expensive if overused.
---The callback signature is bool render(VanillaRenderContext render_ctx, Entity self)
---@deprecated
---@param uid integer
---@param fun fun(render_ctx: VanillaRenderContext, p2: Entity|nil): boolean|nil @Returning nil: passed on as an empty optional.
---@return CallbackId|nil
function set_pre_render(uid, fun) end

---Returns unique id for the callback to be used in [clear_screen_callback](https://spelunky-fyi.github.io/overlunky/#clear_screen_callback) or `nil` if screen_id is not valid.
---Sets a callback that is called right before the screen is drawn, return `true` to skip the default rendering.
---The callback signature is bool render_screen(Screen self, VanillaRenderContext render_ctx)
---@param screen_id integer
---@param fun fun(p1: Screen|nil, p2: VanillaRenderContext): boolean|nil @Returning nil: treated as false.
---@return CallbackId|nil
function set_pre_render_screen(screen_id, fun) end

---Use `entity:set_pre_update_state_machine` instead.
---Returns unique id for the callback to be used in [clear_entity_callback](https://spelunky-fyi.github.io/overlunky/#clear_entity_callback) or `nil` if uid is not valid.
---`uid` has to be the uid of a `Movable` or else stuff will break.
---Sets a callback that is called right before the statemachine, return `true` to skip the statemachine update.
---Use this only when no other approach works, this call can be expensive if overused.
---Check [here](https://github.com/spelunky-fyi/overlunky/blob/main/docs/virtual-availability.md) to see whether you can use this callback on the entity type you intend to.
---The callback signature is bool statemachine(Entity self)
---@deprecated
---@param uid integer
---@param fun fun(self: Entity|nil): boolean|nil @Returning nil: treated as false: the original function runs (true skips it).
---@return CallbackId|nil
function set_pre_statemachine(uid, fun) end

---Returns unique id for the callback to be used in [clear_callback](https://spelunky-fyi.github.io/overlunky/#clear_callback).
---Add per level callback function to be called after `frames` engine frames. Timer is paused on pause and cleared on level transition.
---@param cb fun() @Returning nil: ignored.
---@param frames integer
---@return CallbackId
function set_timeout(cb, frames) end

---Returns unique id for the callback to be used in [clear_vanilla_sound_callback](https://spelunky-fyi.github.io/overlunky/#clear_vanilla_sound_callback).
---Sets a callback for a vanilla sound which lets you hook creation or playing events of that sound
---Callbacks are executed on another thread, so avoid touching any global state, only the local Lua state is protected
---If you set such a callback and then play the same sound yourself you have to wait until receiving the STARTED event before changing any properties on the sound. Otherwise you may cause a deadlock.
---The callback signature is nil on_vanilla_sound(PlayingSound sound)
---@param name VANILLA_SOUND
---@param types VANILLA_SOUND_CALLBACK_TYPE
---@param cb fun(p1: PlayingSound, p2: PlayingSound) @Returning nil: ignored.
---@return CallbackId
function set_vanilla_sound_callback(name, types, cb) end

-- ## Debug functions

---Dump the object (table, container, class) as a recursive table, for pretty printing in console. Don't use this for anything except debug printing. Unsafe.
---@param object any
---@param depth integer|nil
---@return table
function dump(object, depth) end

---Hook the sendto and recvfrom functions and start dumping network data to terminal for debug purposes
function dump_network() end

---Get memory address from a lua object
---@param o any|nil
---@return string
function get_address(o) end

---Get the rva for a pattern name, used for debugging.
---@param address_name string
---@return string
function get_rva(address_name) end

---Get the rva for a vtable offset and index, used for debugging.
---@param offset integer
---@param index integer
---@return string
function get_virtual_rva(offset, index) end

---Raise a signal and probably crash the game
---@param _Signal integer
---@return integer
function raise(_Signal) end

-- ## Entity functions

---Attach liquid collision to entity by uid (this is what the push blocks use)
---Collision is based on the entity's hitbox, collision is removed when the entity is destroyed (bodies of killed entities will still have the collision)
---Use only for entities that can move around, (for static prefer [update_liquid_collision_at](https://spelunky-fyi.github.io/overlunky/#update_liquid_collision_at) )
---If entity is in back layer and liquid in the front, there will be no collision created, also collision is not destroyed when entity changes layers, so you have to handle that yourself
---@param uid integer
---@param add boolean
function add_entity_to_liquid_collision(uid, add) end

---Apply changes made in [get_type](https://spelunky-fyi.github.io/overlunky/#get_type)() to entity instance by uid.
---@param uid integer
function apply_entity_db(uid) end

---Spawns and attaches ball and chain to `uid`, the initial position of the ball is at the entity position plus `off_x`, `off_y`
---@param uid integer
---@param off_x number
---@param off_y number
---@return integer
function attach_ball_and_chain(uid, off_x, off_y) end

---Attaches `attachee` to `overlay`, similar to setting `get_entity(attachee).overlay = get_entity(overlay)`.
---However this function offsets `attachee` (so you don't have to) and inserts it into `overlay`'s inventory.
---@param overlay_uid integer
---@param attachee_uid integer
function attach_entity(overlay_uid, attachee_uid) end

---Make `mount_uid` carry `rider_uid` on their back. Only use this with actual mounts and living things.
---@param mount_uid integer
---@param rider_uid integer
function carry(mount_uid, rider_uid) end

---Drop held entity, `what_uid` optional, if set, it will check if entity is holding that entity first before dropping it
---@param who_uid integer
---@param what_uid integer|nil
function drop(who_uid, what_uid) end

---Calls the enter door function, position doesn't matter, can also enter closed doors (like COG, EW) without unlocking them
---@param player_uid integer
---@param door_uid integer
function enter_door(player_uid, door_uid) end

---Gets uids of entities attached to given entity uid. Use `entity_type` and `mask` ([MASK](https://spelunky-fyi.github.io/overlunky/#MASK)) to filter, set them to 0 to return all attached entities.
---@param uid integer
---@param entity_type ENT_TYPE
---@param mask MASK
---@return integer[]
---@overload fun(uid: integer, entity_types: ENT_TYPE[], mask: MASK): integer[]
function entity_get_items_by(uid, entity_type, mask) end

---Check if the entity `uid` has some ENT_TYPE `entity_type` in their inventory, can also use table of entity_types
---@param uid integer
---@param entity_type ENT_TYPE
---@return boolean
---@overload fun(uid: integer, entity_types: ENT_TYPE[]): boolean
function entity_has_item_type(uid, entity_type) end

---Check if the entity `uid` has some specific `item_uid` by uid in their inventory
---@param uid integer
---@param item_uid integer
---@return boolean
function entity_has_item_uid(uid, item_uid) end

---Remove item by uid from entity. `check_autokill` defaults to true, checks if entity should be killed when missing overlay and kills it if so (can help with avoiding crashes)
---@param uid integer
---@param item_uid integer
---@param check_autokill boolean|nil
function entity_remove_item(uid, item_uid, check_autokill) end

---Returns a list of all uids in `entities` for which `predicate(get_entity(uid))` returns true
---@param entities integer[]
---@param predicate fun(p1: any): boolean|nil @Returning nil: treated as false.
---@return integer[]
function filter_entities(entities, predicate) end

---Use `Entity:flip` instead
---@deprecated
---@param uid integer
function flip_entity(uid) end

---Get door target `world`, `level`, `theme`
---@param uid integer
---@return integer
---@return integer
---@return integer
function get_door_target(uid) end

---Use `get_entities_by(0, MASK.ANY, LAYER.BOTH)` instead
---@deprecated
---@return integer[]
function get_entities() end

---Get uids of matching entities inside some radius ([ENT_TYPE](https://spelunky-fyi.github.io/overlunky/#ENT_TYPE), [MASK](https://spelunky-fyi.github.io/overlunky/#MASK)). Set `entity_type` or `mask` to `0` to ignore that, can also use table of entity_types
---Recommended to always set the mask, even if you look for one entity type
---@param entity_type ENT_TYPE
---@param mask MASK
---@param x number
---@param y number
---@param layer LAYER
---@param radius number
---@return integer[]
---@overload fun(entity_types: ENT_TYPE[], mask: MASK, x: number, y: number, layer: LAYER, radius: number): integer[]
function get_entities_at(entity_type, mask, x, y, layer, radius) end

---Get uids of entities by some conditions ([ENT_TYPE](https://spelunky-fyi.github.io/overlunky/#ENT_TYPE), [MASK](https://spelunky-fyi.github.io/overlunky/#MASK)). Set `entity_type` or `mask` to `0` to ignore that, can also use table of entity_types.
---Recommended to always set the mask, even if you look for one entity type
---@param entity_type ENT_TYPE
---@param mask MASK
---@param layer LAYER
---@return integer[]
---@overload fun(entity_types: ENT_TYPE[], mask: MASK, layer: LAYER): integer[]
function get_entities_by(entity_type, mask, layer) end

---Get uids of entities by draw_depth. Can also use table of draw_depths.
---You can later use [filter_entities](https://spelunky-fyi.github.io/overlunky/#filter_entities) if you want specific entity
---@param draw_depth integer
---@param l LAYER
---@return integer[]
---@overload fun(draw_depths: integer[], l: LAYER): integer[]
function get_entities_by_draw_depth(draw_depth, l) end

---Use `get_entities_by(0, MASK.ANY, layer)` instead
---@deprecated
---@param layer LAYER
---@return integer[]
function get_entities_by_layer(layer) end

---Use `get_entities_by(0, mask, LAYER.BOTH)` instead
---@deprecated
---@param mask MASK
---@return integer[]
function get_entities_by_mask(mask) end

---Get uids of entities matching id. This function is variadic, meaning it accepts any number of id's.
---You can even pass a table!
---This function can be slower than the [get_entities_by](https://spelunky-fyi.github.io/overlunky/#get_entities_by) with the mask parameter filled
---@vararg any
---@return integer[]
function get_entities_by_type(...) end

---Use `get_entities_overlapping_hitbox` instead
---@deprecated
---@param entity_type ENT_TYPE
---@param mask MASK
---@param sx number
---@param sy number
---@param sx2 number
---@param sy2 number
---@param layer LAYER
---@return integer[]
---@overload fun(entity_types: ENT_TYPE[], mask: MASK, sx: number, sy: number, sx2: number, sy2: number, layer: LAYER): integer[]
function get_entities_overlapping(entity_type, mask, sx, sy, sx2, sy2, layer) end

---Get uids of static entities overlapping this grid position (decorations, backgrounds etc.)
---@param x number
---@param y number
---@param layer LAYER
---@return integer[]
function get_entities_overlapping_grid(x, y, layer) end

---Get uids of matching entities overlapping with the given hitbox. Set `entity_type` or `mask` to `0` to ignore that, can also use table of entity_types
---@param entity_type ENT_TYPE
---@param mask MASK
---@param hitbox AABB
---@param layer LAYER
---@return integer[]
---@overload fun(entity_types: ENT_TYPE[], mask: MASK, hitbox: AABB, layer: LAYER): integer[]
function get_entities_overlapping_hitbox(entity_type, mask, hitbox, layer) end

---Get the Entity behind an uid, converted to the correct type. To see what type you will get, consult the [entity hierarchy list](https://github.com/spelunky-fyi/overlunky/blob/main/docs/entities-hierarchy.md)
---@param uid integer
---@return Entity
function get_entity(uid) end

---As the name is misleading. use Movable.`move_state` field instead
---@deprecated
---@param uid integer
---@return integer
function get_entity_ai_state(uid) end

---Get localized name of an entity from the journal, pass `fallback_strategy` as `true` to fall back to the `ENT_TYPE.*` enum name
---if the entity has no localized name
---@param type ENT_TYPE
---@param fallback_strategy boolean|nil
---@return string
function get_entity_name(type, fallback_strategy) end

---Get the ENT_TYPE... of the entity by uid
---@param uid integer
---@return ENT_TYPE
function get_entity_type(uid) end

---Gets a grid entity, such as floor or spikes, at the given position and layer.
---@param x number
---@param y number
---@param layer LAYER
---@return integer
function get_grid_entity_at(x, y, layer) end

---Get the thread-local version of players
---@return Player[]
function get_local_players() end

---Returns Player (or PlayerGhost if `get_player(1, true)`) with this player slot
---@param slot integer
---@param or_ghost boolean|nil
---@return Player|PlayerGhost
function get_player(slot, or_ghost) end

---Returns PlayerGhost with this player slot 1..4
---@param slot integer
---@return PlayerGhost|nil
function get_playerghost(slot) end

---Get the [EntityDB](https://spelunky-fyi.github.io/overlunky/#EntityDB) behind an ENT_TYPE...
---@param id ENT_TYPE
---@return EntityDB|nil
function get_type(id) end

---Kills an entity by uid. `destroy_corpse` defaults to `true`, if you are killing for example a caveman and want the corpse to stay make sure to pass `false`.
---@param uid integer
---@param destroy_corpse boolean|nil
function kill_entity(uid, destroy_corpse) end

---use `Door:unlock` instead
---@deprecated
---@param x number
---@param y number
function lock_door_at(x, y) end

---Teleport entity to coordinates with optional velocity
---@param uid integer
---@param x number
---@param y number
---@param vx number
---@param vy number
---@overload fun(uid: integer, x: number, y: number, vx: number, vy: number, layer: LAYER)
function move_entity(uid, x, y, vx, vy) end

---Teleport grid entity, the destination should be whole number, this ensures that the collisions will work properly
---@param uid integer
---@param x number
---@param y number
---@param layer LAYER
function move_grid_entity(uid, x, y, layer) end

---Pick up another entity by uid. Make sure you're not already holding something, or weird stuff will happen.
---@param who_uid integer
---@param what_uid integer
function pick_up(who_uid, what_uid) end

---Poisons entity, to cure poison set [Movable](https://spelunky-fyi.github.io/overlunky/#Movable).`poison_tick_timer` to -1
---@param entity_uid integer
function poison_entity(entity_uid) end

---This function never worked properly as too many places in the game individually check for vlads cape and calculate the blood multiplication
---`default_multiplier` doesn't do anything due to some changes in last game updates, `vladscape_multiplier` only changes the multiplier to some entities death's blood spit
---@deprecated
---@param p1 integer
---@param vladscape_multiplier integer
function set_blood_multiplication(p1, vladscape_multiplier) end

---Set the contents of [Coffin](https://spelunky-fyi.github.io/overlunky/#Coffin), [Present](https://spelunky-fyi.github.io/overlunky/#Present), [Pot](https://spelunky-fyi.github.io/overlunky/#Pot), [Container](https://spelunky-fyi.github.io/overlunky/#Container)
---Check the [entity hierarchy list](https://github.com/spelunky-fyi/overlunky/blob/main/docs/entities-hierarchy.md) for what the exact ENT_TYPE's can this function affect
---@param uid integer
---@param item_entity_type ENT_TYPE
function set_contents(uid, item_entity_type) end

---Short for [set_door_target](https://spelunky-fyi.github.io/overlunky/#set_door_target).
---@param uid integer
---@param w integer
---@param l integer
---@param t integer
function set_door(uid, w, l, t) end

---Make an ENT_TYPE.FLOOR_DOOR_EXIT go to world `w`, level `l`, theme `t`
---@param uid integer
---@param w integer
---@param l integer
---@param t integer
function set_door_target(uid, w, l, t) end

---Unequips the currently worn backitem
---@param who_uid integer
function unequip_backitem(who_uid) end

---use `Door:unlock` instead
---@deprecated
---@param x number
---@param y number
function unlock_door_at(x, y) end

---Returns how many of a specific entity type Waddler has stored
---@param entity_type ENT_TYPE
---@return integer
function waddler_count_entity(entity_type) end

---Gets the entity type of the item in the provided slot
---@param slot integer
---@return integer
function waddler_entity_type_in_slot(slot) end

---Gets the 16-bit meta-value associated with the entity type in the associated slot
---@param slot integer
---@return integer
function waddler_get_entity_meta(slot) end

---Removes an entity type from Waddler's storage. Second param determines how many of the item to remove (default = remove all)
---@param entity_type ENT_TYPE
---@param amount_to_remove integer
function waddler_remove_entity(entity_type, amount_to_remove) end

---Sets the 16-bit meta-value associated with the entity type in the associated slot
---@param slot integer
---@param meta integer
function waddler_set_entity_meta(slot, meta) end

---Store an entity type in Waddler's storage. Returns the slot number the item was stored in or -1 when storage is full and the item couldn't be stored.
---@param entity_type ENT_TYPE
---@return integer
function waddler_store_entity(entity_type) end

---Returns the uid of the currently worn backitem, or -1 if wearing nothing
---@param who_uid integer
---@return integer
function worn_backitem(who_uid) end

-- ## Feat functions

---Helper function to set the title and description strings for a FEAT with change_string, as well as the hidden state.
---@param feat FEAT
---@param hidden boolean
---@param name string
---@param description string
function change_feat(feat, hidden, name, description) end

---Check if the user has performed a feat (Real Steam achievement or a hooked one). Returns: `bool unlocked, bool hidden, string name, string description`
---@param feat FEAT
---@return boolean
---@return boolean
---@return string
---@return string
function get_feat(feat) end

---Get the visibility of a feat
---@param feat FEAT
---@return boolean
function get_feat_hidden(feat) end

---Set the visibility of a feat
---@param feat FEAT
---@param hidden boolean
function set_feat_hidden(feat, hidden) end

-- ## Flag functions

---Clears the nth bit in a number. This doesn't actually change the variable you pass, it just returns the new value you can use.
---@param flags Flags
---@param bit integer
---@return Flags
function clr_flag(flags, bit) end

---Clears a bitmask in a number. This doesn't actually change the variable you pass, it just returns the new value you can use.
---@param flags Flags
---@param mask Flags
---@return Flags
function clr_mask(flags, mask) end

---@deprecated
---@param flags Flags
---@param bit integer
---@return Flags
function clrflag(flags, bit) end

---Flips the nth bit in a number. This doesn't actually change the variable you pass, it just returns the new value you can use.
---@param flags Flags
---@param bit integer
---@return Flags
function flip_flag(flags, bit) end

---Flips the nth bit in a number. This doesn't actually change the variable you pass, it just returns the new value you can use.
---@param flags Flags
---@param mask Flags
---@return Flags
function flip_mask(flags, mask) end

---Get the `flags` field from entity by uid
---@param uid integer
---@return ENT_FLAG
function get_entity_flags(uid) end

---Get the `more_flags` field from entity by uid
---@param uid integer
---@return ENT_MORE_FLAG
function get_entity_flags2(uid) end

---Get `state.level_flags`
---@return integer
function get_level_flags() end

---Set the `flags` field from entity by uid
---@param uid integer
---@param flags ENT_FLAG
function set_entity_flags(uid, flags) end

---Set the `more_flags` field from entity by uid
---@param uid integer
---@param flags ENT_MORE_FLAG
function set_entity_flags2(uid, flags) end

---Set the nth bit in a number. This doesn't actually change the variable you pass, it just returns the new value you can use.
---@param flags Flags
---@param bit integer
---@return Flags
function set_flag(flags, bit) end

---Set `state.level_flags`
---@param flags integer
function set_level_flags(flags) end

---Set a bitmask in a number. This doesn't actually change the variable you pass, it just returns the new value you can use.
---@param flags Flags
---@param mask Flags
---@return Flags
function set_mask(flags, mask) end

---@deprecated
---@param flags Flags
---@param bit integer
---@return Flags
function setflag(flags, bit) end

---Returns true if the nth bit is set in the number.
---@param flags Flags
---@param bit integer
---@return boolean
function test_flag(flags, bit) end

---Returns true if a bitmask is set in the number.
---@param flags Flags
---@param mask Flags
---@return boolean
function test_mask(flags, mask) end

---@deprecated
---@param flags Flags
---@param bit integer
---@return boolean
function testflag(flags, bit) end

-- ## Game patching functions

---Activate custom variables for speed and y coordinate limit for crushing elevator
---note: because those variables are custom and game does not initiate them, you need to do it yourself for each CrushElevator entity, recommending set_post_entity_spawn
---default game values are: speed = 0.0125, y_limit = 98.5
---@param activate boolean
function activate_crush_elevator_hack(activate) end

---Activate custom variables for y coordinate limit for hundun and spawn of it's heads
---note: because those variables are custom and game does not initiate them, you need to do it yourself for each Hundun entity, recommending set_post_entity_spawn
---default game value are: y_limit = 98.5, rising_speed_x = 0, rising_speed_y = 0.0125, bird_head_spawn_y = 55, snake_head_spawn_y = 71
---@param activate boolean
function activate_hundun_hack(activate) end

---Activate custom variables for speed and distance in the `ITEM_SPARK`
---note: because those the variables are custom and game does not initiate them, you need to do it yourself for each spark, recommending `set_post_entity_spawn`
---default game values are: speed = -0.015, distance = 3.0
---@param activate boolean
function activate_sparktraps_hack(activate) end

---Activate custom variables for position used for detecting the player (normally hardcoded)
---note: because those variables are custom and game does not initiate them, you need to do it yourself for each Tiamat entity, recommending set_post_entity_spawn
---default game values are: attack_x = 17.5 attack_y = 62.5
---@param activate boolean
function activate_tiamat_position_hack(activate) end

---Change ENT_TYPE's spawned when you damage the altar, by default there are 6:
---{MONS_BAT, MONS_BEE, MONS_SPIDER, MONS_JIANGSHI, MONS_FEMALE_JIANGSHI, MONS_VAMPIRE}
---Max 255 types.
---Use empty table as argument to reset to the game default
---@param ent_types ENT_TYPE[]
function change_altar_damage_spawns(ent_types) end

---Change ENT_TYPE's spawned in dice shops (Madame Tusk as well), by default there are 25:
---{ITEM_PICKUP_BOMBBAG, ITEM_PICKUP_BOMBBOX, ITEM_PICKUP_ROPEPILE, ITEM_PICKUP_COMPASS, ITEM_PICKUP_PASTE, ITEM_PICKUP_PARACHUTE, ITEM_PURCHASABLE_CAPE, ITEM_PICKUP_SPECTACLES, ITEM_PICKUP_CLIMBINGGLOVES, ITEM_PICKUP_PITCHERSMITT,
---ENT_TYPE_ITEM_PICKUP_SPIKESHOES, ENT_TYPE_ITEM_PICKUP_SPRINGSHOES, ITEM_MACHETE, ITEM_BOOMERANG, ITEM_CROSSBOW, ITEM_SHOTGUN, ITEM_FREEZERAY, ITEM_WEBGUN, ITEM_CAMERA, ITEM_MATTOCK, ITEM_PURCHASABLE_JETPACK, ITEM_PURCHASABLE_HOVERPACK,
---ITEM_TELEPORTER, ITEM_PURCHASABLE_TELEPORTER_BACKPACK, ITEM_PURCHASABLE_POWERPACK}
---Min 6, Max 255, if you want less then 6 you need to write some of them more then once (they will have higher "spawn chance").
---If you use this function in the level with dice shop in it, you have to update `item_ids` in the [ITEM_DICE_PRIZE_DISPENSER](https://spelunky-fyi.github.io/overlunky/#PrizeDispenser).
---Use empty table as argument to reset to the game default
---@param ent_types ENT_TYPE[]
function change_diceshop_prizes(ent_types) end

---Change the amount of frames after the damage from poison is applied
---@param frames integer
function change_poison_timer(frames) end

---Change ENT_TYPE's spawned by `FLOOR_SUNCHALLENGE_GENERATOR`, by default there are 4:
---{MONS_WITCHDOCTOR, MONS_VAMPIRE, MONS_SORCERESS, MONS_NECROMANCER}
---Use empty table as argument to reset to the game default
---@param ent_types ENT_TYPE[]
function change_sunchallenge_spawns(ent_types) end

---Change ENT_TYPE's spawned when Waddler dies, by default there are 3:
---{ITEM_PICKUP_COMPASS, ITEM_CHEST, ITEM_KEY}
---Max 255 types.
---Use empty table as argument to reset to the game default
---@param ent_types ENT_TYPE[]
function change_waddler_drop(ent_types) end

---Disable all crust item spawns, returns whether they were already disabled before the call
---@param disable boolean
---@return boolean
function disable_floor_embeds(disable) end

---Forces Olmec to stay on phase 0 (stomping)
---@param b boolean
function force_olmec_phase_0(b) end

---Change how much health the ankh gives you after death, with every beat (the heart beat effect) it will add `beat_add_health` to your health,
---`beat_add_health` has to be divisor of `health` and can't be 0, otherwise the function does nothing. Set `health` to 0 to return to the game defaults
---If you set `health` above the game max health it will be forced down to the game max
---@param max_health integer
---@param beat_add_health integer
function modify_ankh_health_gain(max_health, beat_add_health) end

---Changes characteristics of (all) sparktraps: speed, rotation direction and distance from center
---Speed: expressed as the amount that should be added to the angle every frame (use a negative number to go in the other direction)
---Distance from center: if you go above 3.0 the game might crash because a spark may go out of bounds!
---@param angle_increment number
---@param distance number
function modify_sparktraps(angle_increment, distance) end

---Changes a particular drop, e.g. what Van Horsing throws at you (use e.g. replace_drop(DROP.VAN_HORSING_DIAMOND, ENT_TYPE.ITEM_PLASMACANNON))
---Use `0` as type to reset this drop to default, use `-1` as drop_id to reset all to default
---Check all the available drops [here](https://github.com/spelunky-fyi/overlunky/blob/main/src/game_api/drops.cpp)
---@param drop_id DROP
---@param new_drop_entity_type ENT_TYPE
function replace_drop(drop_id, new_drop_entity_type) end

---Allows you to disable the control over the door for Hundun and Tiamat
---This will also prevent game crashing when there is no exit door when they are in level
---@param enable boolean
function set_boss_door_control_enabled(enable) end

---This disables the `state.camera_layer` to be forced to the `(leader player).layer` and setting of the `state.layer_transition_timer` & `state.transition_to_layer` when player enters layer door.
---Letting you control those manually.
---Look at the example on how to mimic game layer switching behavior
---@param enable boolean
function set_camera_layer_control_enabled(enable) end

---Enables or disables the default position based camp camera bounds, to set them manually yourself
---@param b boolean
function set_camp_camera_bounds_enabled(b) end

---Determines whether the ghost appears when breaking the ghost pot
---@param enable boolean
function set_cursepot_ghost_enabled(enable) end

---Alters the drop chance for the provided monster-item combination (use e.g. set_drop_chance(DROPCHANCE.MOLE_MATTOCK, 10) for a 1 in 10 chance)
---Use `-1` as dropchance_id to reset all to default
---@param dropchance_id DROPCHANCE
---@param new_drop_chance integer
function set_drop_chance(dropchance_id, new_drop_chance) end

---Force the character unlocked in either ending to ENT_TYPE. Set to 0 to reset to the default guys. Does not affect the texture of the actual savior. (See example)
---@param type ENT_TYPE
function set_ending_unlock(type) end

---Sets which entities are affected by a bomb explosion. Default = MASK.PLAYER | MASK.MOUNT | MASK.MONSTER | MASK.ITEM | MASK.ACTIVEFLOOR | MASK.FLOOR
---@param mask integer
function set_explosion_mask(mask) end

---Determines when the ghost appears, either when the player is cursed or not
---@param normal integer
---@param cursed integer
function set_ghost_spawn_times(normal, cursed) end

---Sets the amount of blood drops in the Kapala needed to trigger a health increase (default = 7).
---@param threshold integer
function set_kapala_blood_threshold(threshold) end

---Sets the hud icon for the Kapala (0-6 ; -1 for default behaviour).
---If you set a Kapala treshold greater than 7, make sure to set the hud icon in the range 0-6, or other icons will appear in the hud!
---@param icon_index integer
function set_kapala_hud_icon(icon_index) end

---Setting to false disables all player logic in SCREEN.LEVEL, mainly the death screen from popping up if all players are dead or missing, but also shop camera zoom and some other small things.
---@param enable boolean
function set_level_logic_enabled(enable) end

---Change layer at which the liquid spawns in, THIS FUNCTION NEEDS TO BE CALLED BEFORE THE LEVEL IS BUILD, otherwise collisions and other stuff will be wrong for the newly spawned liquid
---This sadly also makes lavamanders extinct, since the logic for their spawn is hardcoded to front layer with bunch of other unrelated stuff (you can still spawn them with script or place them directly in level files)
---Everything should be working more or less correctly (report on community discord if you find something unusual)
---@param l LAYER
function set_liquid_layer(l) end

---Sets the maximum length of a thrown rope (anchor segment not included). Unfortunately, setting this higher than default (6) creates visual glitches in the rope, even though it is fully functional.
---@param length integer
function set_max_rope_length(length) end

---Olmec cutscene moves Olmec and destroys the four floor tiles, so those things never happen if the cutscene is disabled, and Olmec will spawn on even ground. More useful for level gen mods, where the cutscene doesn't make sense. You can also set olmec_cutscene.timer to the last frame (809) to skip to the end, with Olmec in the hole.
---@param enable boolean
function set_olmec_cutscene_enabled(enable) end

---Sets the Y-level at which Olmec changes phases
---@param phase integer
---@param y number
function set_olmec_phase_y_level(phase, y) end

---Setting to true will stop the state update from unpausing after a screen load, leaving you with state.pause == PAUSE.FADE on the first frame to do what you want.
---@param enable boolean
function set_start_level_paused(enable) end

---Set layer to search for storage items on
---@param layer LAYER
function set_storage_layer(layer) end

---Tiamat cutscene is also responsible for locking the exit door, so you may need to close it yourself if you still want Tiamat kill to be required
---@param enable boolean
function set_tiamat_cutscene_enabled(enable) end

---Determines whether the time ghost appears, including the showing of the ghost toast
---@param b boolean
function set_time_ghost_enabled(b) end

---Determines whether the time jelly appears in cosmic ocean
---@param b boolean
function set_time_jelly_enabled(b) end

-- ## Generic functions

---@return integer
function __load() end

---@return integer
function __loadfile() end

---@param path string
---@param func string
---@return any
function __loadlib(path, func) end

---@param path string
---@return any
function __require(path) end

---Adds new custom type (group of ENT_TYPE) that can be later used in functions like get_entities_by or set_(pre/post)_entity_spawn
---Use empty array or no parameter to get new unique ENT_TYPE that can be used for custom EntityDB
---@param types ENT_TYPE[]
---@return ENT_TYPE
---@overload fun(): ENT_TYPE
function add_custom_type(types) end

---Adds money to the state.money_shop_total and displays the effect on the HUD for money change
---Can be negative, default display_time = 60 (about 2s). Returns the current money after the transaction
---@param amount integer
---@param display_time integer|nil
---@return integer
function add_money(amount, display_time) end

---Adds money to the state.items.player_inventory[player_slot].money and displays the effect on the HUD for money change
---Can be negative, default display_time = 60 (about 2s). Returns the current money after the transaction
---@param amount integer
---@param player_slot integer
---@param display_time integer|nil
---@return integer
function add_money_slot(amount, player_slot, display_time) end

---Clear cache for a file path or the whole directory
---@overload fun(path: string)
function clear_cache() end

---Clear save state from slot 1..4.
---@param slot integer
function clear_state(slot) end

---Creates an `FMODguidMap` by parsing a GUIDs.txt exported from FMOD Studio from disk relative to this script. This is useful
---if you want to use a human readable FMOD event path to create a `CustomEventDescription` instead of using an FMOD GUID string.
---@param path string
---@return FMODguidMap|nil
function create_fmod_guid_map(path) end

---Create image from file. Returns a tuple containing id, width and height.
---Depending on the image size, this can take a moment, preferably don't create them dynamically, rather create all you need in global scope so it will load them as soon as the game starts
---@param path string
---@return IMAGE
---@return integer
---@return integer
function create_image(path) end

---Create image from file, cropped to the geometry provided. Returns a tuple containing id, width and height.
---Depending on the image size, this can take a moment, preferably don't create them dynamically, rather create all you need in global scope so it will load them as soon as the game starts
---@param path string
---@param x integer
---@param y integer
---@param w integer
---@param h integer
---@return IMAGE
---@return integer
---@return integer
function create_image_crop(path, x, y, w, h) end

---Initializes an empty layer that doesn't currently exist.
---@param layer integer
function create_layer(layer) end

---Initializes an empty front and back layer that don't currently exist. Does nothing(?) if layers already exist.
function create_level() end

---Destroy the grid entity (by uid or position), and its item entities, removing them from the grid without dropping particles or gold.
---Will also destroy monsters or items that are standing on a linked activefloor or chain, though excludes MASK.PLAYER to prevent crashes
---@param uid integer
---@overload fun(x: number, y: number, layer: LAYER)
function destroy_grid(uid) end

---Destroys a layer and all entities in it.
---@param layer integer
function destroy_layer(layer) end

---Destroys all layers and all entities in the level. Usually a bad idea, unless you also call create_level and spawn the player back in.
function destroy_level() end

---@return integer
function dofile() end

---Use [GuiDrawContext](https://spelunky-fyi.github.io/overlunky/#GuiDrawContext)`.draw_circle` instead
---@deprecated
---@param x number
---@param y number
---@param radius number
---@param thickness number
---@param color uColor
function draw_circle(x, y, radius, thickness, color) end

---Use [GuiDrawContext](https://spelunky-fyi.github.io/overlunky/#GuiDrawContext)`.draw_circle_filled` instead
---@deprecated
---@param x number
---@param y number
---@param radius number
---@param color uColor
function draw_circle_filled(x, y, radius, color) end

---Use [GuiDrawContext](https://spelunky-fyi.github.io/overlunky/#GuiDrawContext)`.draw_image` instead
---@deprecated
---@param image IMAGE
---@param x1 number
---@param y1 number
---@param x2 number
---@param y2 number
---@param uvx1 number
---@param uvy1 number
---@param uvx2 number
---@param uvy2 number
---@param color uColor
function draw_image(image, x1, y1, x2, y2, uvx1, uvy1, uvx2, uvy2, color) end

---Use [GuiDrawContext](https://spelunky-fyi.github.io/overlunky/#GuiDrawContext)`.draw_image_rotated` instead
---@deprecated
---@param image IMAGE
---@param x1 number
---@param y1 number
---@param x2 number
---@param y2 number
---@param uvx1 number
---@param uvy1 number
---@param uvx2 number
---@param uvy2 number
---@param color uColor
---@param angle number
---@param px number
---@param py number
function draw_image_rotated(image, x1, y1, x2, y2, uvx1, uvy1, uvx2, uvy2, color, angle, px, py) end

---Use [GuiDrawContext](https://spelunky-fyi.github.io/overlunky/#GuiDrawContext)`.draw_line` instead
---@deprecated
---@param x1 number
---@param y1 number
---@param x2 number
---@param y2 number
---@param thickness number
---@param color uColor
function draw_line(x1, y1, x2, y2, thickness, color) end

---Use [GuiDrawContext](https://spelunky-fyi.github.io/overlunky/#GuiDrawContext)`.draw_rect` instead
---@deprecated
---@param x1 number
---@param y1 number
---@param x2 number
---@param y2 number
---@param thickness number
---@param rounding number
---@param color uColor
function draw_rect(x1, y1, x2, y2, thickness, rounding, color) end

---Use [GuiDrawContext](https://spelunky-fyi.github.io/overlunky/#GuiDrawContext)`.draw_rect_filled` instead
---@deprecated
---@param x1 number
---@param y1 number
---@param x2 number
---@param y2 number
---@param rounding number
---@param color uColor
function draw_rect_filled(x1, y1, x2, y2, rounding, color) end

---Use [GuiDrawContext](https://spelunky-fyi.github.io/overlunky/#GuiDrawContext)`.draw_text` instead
---@deprecated
---@param x number
---@param y number
---@param size number
---@param text string
---@param color uColor
function draw_text(x, y, size, text, color) end

---Set level flag 18 on post room generation instead, to properly force every level to dark
---@deprecated
---@param g boolean
function force_dark_level(g) end

---Force the journal to open on a chapter and entry# when pressing the journal button. Only use even entry numbers. Set chapter to `JOURNALUI_PAGE_SHOWN.JOURNAL` to reset. (This forces the journal toggle to always read from `game_manager.save_related.journal_popup_ui.entry_to_show` etc.)
---@param chapter integer
---@param entry integer
function force_journal(chapter, entry) end

---Get the current adventure seed pair, or optionally what it was at the start of this run, because it changes every level.
---@param run_start boolean|nil
---@return integer
---@return integer
function get_adventure_seed(run_start) end

---Gets an existing loaded bank if a file at the same path was already loaded
---@param path string
---@return CustomBank|nil
function get_bank(path) end

---Returns the Bucket of data stored in shared memory between Overlunky and Playlunky
---@return Bucket
function get_bucket() end

---Same as `Player.get_heart_color`
---@param type_id ENT_TYPE
---@return Color
function get_character_heart_color(type_id) end

---Convert a string to a color, you can use the HTML color names, or even HTML color codes, just prefix them with '#' symbol
---You can also convert hex string into a color, prefix it with '0x', but use it only if you need to since lua allows for hex values directly too.
---Default alpha value will be 0xFF, unless it's specified
---Format: [name], #RRGGBB, #RRGGBBAA, 0xBBGGRR, 0xAABBGGRR
---@param color_name string
---@param alpha integer|nil
---@return uColor
function get_color(color_name, alpha) end

---Just convenient way of getting the current amount of money
---short for state->money_shop_total + loop[inventory.money + inventory.collected_money_total]
---@return integer
function get_current_money() end

---Gets a `CustomEventDescription` if the event description is loaded using an FMOD GUID string. The string representation
---must be formatted as 32 digits seperated by hyphens and enclosed in braces: {00000000-0000-0000-0000-000000000000}.
---@param guid_string string
---@return CustomEventDescription|nil
function get_event_by_id(guid_string) end

---Get the current frame count since the game was started*. You can use this to make some timers yourself, the engine runs at 60fps. This counter is paused if the pause is set with flags PAUSE.FADE or PAUSE.ANKH.
---@return integer
function get_frame() end

---Get engine target frametime (1/framerate, default 1/60).
---@return number
function get_frametime() end

---Get engine target frametime when game is unfocused (1/framerate, default 1/33).
---@return number
function get_frametime_unfocused() end

---Get the current global frame count since the game was started. You can use this to make some timers yourself, the engine runs at 60fps. This counter keeps incrementing with game loop. Never stops.
---@return integer
function get_global_frame() end

---Get the HudData the game draws the vanilla HUD from.
---@return HudData|nil
function get_hud() end

---Get your sanitized script id to be used in import.
---@return string
function get_id() end

---Gets the value for the specified config
---@param config LEVEL_CONFIG
---@return integer
function get_level_config(config) end

---Get the current layer that the liquid is spawn in. Related function [set_liquid_layer](https://spelunky-fyi.github.io/overlunky/#set_liquid_layer)
---@return integer
function get_liquid_layer() end

---Optimized function to check for the amount of liquids at a certain position, by accessing a 2d array of liquids by third of a tile. Try the `liquids.lua` example to know better how it works.
---Returns a pair of water and lava, in that order.
---Water blobs increase the number by 2 on the grid, while lava blobs increase it by 3. The maximum is usually 6.
---Coarse water increase the number by 3, coarse and stagnant lava by 6. Combinations of both normal and coarse can make the number higher than 6.
---@param x number
---@param y number
---@param layer LAYER
---@return integer
---@return integer
function get_liquids_at(x, y, layer) end

---Get the thread-local version of prng
---@return PRNG|nil
function get_local_prng() end

---Get the thread-local version of state
---@return StateMemory|nil
function get_local_state() end

---Get the current timestamp in milliseconds since the Unix Epoch.
---@return integer
function get_ms() end

---Retrieves the current value of the performance counter, which is a high resolution (<1us) time stamp that can be used for time-interval measurements.
---@return integer
function get_performance_counter() end

---Retrieves the frequency of the performance counter. The frequency of the performance counter is fixed at system boot and is consistent across all processors. Therefore, the frequency need only be queried upon application initialization, and the result can be cached.
---@return integer
function get_performance_frequency() end

---Get StateMemory from a save_state slot.
---@param slot integer
---@return StateMemory|nil
function get_save_state(slot) end

---Gets the specified setting, values might need to be interpreted differently per setting
---@param setting GAME_SETTING
---@return integer|nil
function get_setting(setting) end

---Get the current speedhack multiplier
---@return number
function get_speedhack() end

---Returns true if the level pause hack is enabled
---@return boolean
function get_start_level_paused() end

---Enable/disable godmode for players.
---@param g boolean
function god(g) end

---Enable/disable godmode for companions.
---@param g boolean
function god_companions(g) end

---Grow chains from `ENT_TYPE_FLOOR_CHAIN_CEILING` and chain with blocks on it from `ENT_TYPE_FLOOR_CHAINANDBLOCKS_CEILING`, it starts looking for the ceilings from the top left corner of a level.
---To limit it use the parameters, so x = 10 will only grow chains from ceilings with x < 10, with y = 10 it's ceilings that have y > (level bound top - 10)
---@param x integer
---@param y integer
---@return boolean
---@overload fun(): boolean
function grow_chainandblocks(x, y) end

---Grow pole from `GROWABLE_CLIMBING_POLE` entities in a level, `area` default is whole level, `destroy_broken` default is false
---@param l LAYER
---@param max_length integer
---@overload fun(l: LAYER, max_length: integer, area: AABB, destroy_broken: boolean)
function grow_poles(l, max_length) end

---Grow vines from `GROWABLE_VINE` and `VINE_TREE_TOP` entities in a level, `area` default is whole level, `destroy_broken` default is false
---@param l LAYER
---@param max_length integer
---@overload fun(l: LAYER, max_length: integer, area: AABB, destroy_broken: boolean)
function grow_vines(l, max_length) end

---Load another script by id "author/name" and import its `exports` table. Enables the imported
---script if it isn't already, except when it is unsafe and yours is not, since enabling a script
---runs it and only the user gets to make that call for an unsafe one. Returns:
---
---- `table` if the script has exports
---- `nil` if the script was found but has no exports
---- `false` if the script was not found, or is unsafe and not enabled, but optional is set to true
---- an error if the script was not found, or is unsafe and not enabled, and the optional argument was not set
---@param id string
---@param version string|nil
---@param optional boolean|nil
---@return table
function import(id, version, optional) end

---Converts INPUTS to (x, y, BUTTON)
---@param inputs INPUTS
---@return number
---@return number
---@return BUTTON
function inputs_to_buttons(inputs) end

---Find intersection point of two lines [A, B] and [C, D], returns INFINITY if the lines don't intersect each other [parallel]
---@param A Vec2
---@param B Vec2
---@param C Vec2
---@param D Vec2
---@return Vec2
function intersection(A, B, C, D) end

---Same as `Player.is_female`
---@param type_id ENT_TYPE
---@return boolean
function is_character_female(type_id) end

---List all char_*.png files recursively from Mods/Packs. Returns table of file paths.
---@return any
function list_char_mods() end

---List files in directory relative to the mods data directory (Mods/Data/...). Returns table of file/directory names or nil if not found.
---@param dir string|nil
---@return any
function list_data_dir(dir) end

---List files in directory relative to the script root. Returns table of file/directory names or nil if not found.
---@param dir string|nil
---@return any
function list_dir(dir) end

---A chunk loaded by the stock load/loadfile/dofile gets the real _G as its _ENV, so these have to give the chunk the calling script's environment instead.
---@return integer
function load() end

---Loads a bank from disk relative to this script, ownership might be shared with other code that loads the same file.
---Returns nil if the file can't be found. Loading a bank file will load the banks metadata, but not non-streaming
---sample data. Once a bank has finished loading, all metadata can be accessed meaning that event descriptions can
---be found with `get_event_by_id()` or using `create_fmod_guid_map()` and calling `FMODguidMap:get_event()`.
---The banks loading state can be queried using `CustomBank:get_loading_state()` which will return an `FMOD_LOADING_STATE`.
---@param path string
---@param flags integer
---@return CustomBank|nil
function load_bank(path, flags) end

---Immediately ends the run with the death screen, also calls the [save_progress](https://spelunky-fyi.github.io/overlunky/#save_progress)
function load_death_screen() end

---Immediately load a screen based on [state](https://spelunky-fyi.github.io/overlunky/#state).screen_next and stuff
function load_screen() end

---Same as import().
---@deprecated
---@param id string
---@return any
---@overload fun(id: string, version: string): any
---@overload fun(id: string, version: string, optional: boolean): any
---@overload fun(id: string, optional: boolean): any
function load_script(id) end

---Load level state from slot 1..4, if a save_state was made in this level.
---@param slot integer
function load_state(slot) end

---@return integer
function loadfile() end

---Some random hash function
---@param x integer
---@return integer
function lowbias32(x) end

---Reverse of some random hash function
---@param x integer
---@return integer
function lowbias32_r(x) end

---Initializes some adventure run related values and loads the character select screen, as if starting a new adventure run from the Play menu. Character select can be skipped by changing `state.screen_next` right after calling this function, maybe with `warp()`. If player isn't already selected, make sure to set `state.items.player_select` and `state.items.player_count` appropriately too.
function play_adventure() end

---Initializes some seeded run related values and loads the character select screen, as if starting a new seeded run after entering the seed.
---@param seed integer|nil
function play_seeded(seed) end

---Read the game prng state. Use [prng](https://spelunky-fyi.github.io/overlunky/#PRNG):get_pair() instead.
---@deprecated
---@return integer[]
function read_prng() end

---Adds a command that can be used in the console.
---@param name string
---@param cmd function
function register_console_command(name, cmd) end

---Custom implementation to trick Lua into allowing to `require 'lib.module'` more than once given it was called from a different source
---@param path string
---@return any
function require(path) end

---Converts a color to int to be used in drawing functions. Use values from `0..255`.
---@param r integer
---@param g integer
---@param b integer
---@param a integer
---@return uColor
function rgba(r, g, b, a) end

---Saves the game to savegame.sav, unless game saves are blocked in the settings. Also runs the ON.SAVE callback. Fails and returns false, if you're trying to save too often (2s).
---@return boolean
function save_progress() end

---Runs the ON.SAVE callback. Fails and returns false, if you're trying to save too often (2s).
---@return boolean
function save_script() end

---Save current level state to slot 1..4. These save states are invalid and cleared after you exit the current level, but can be used to rollback to an earlier state in the same level. You probably definitely shouldn't use save state functions during an update, and sync them to the same event outside an update (i.e. GUIFRAME, POST_UPDATE). These slots are already allocated by the game, actually used for online rollback, and use no additional memory. Also see SaveState if you need more.
---@param slot integer
function save_state(slot) end

---Check if another script is enabled by id "author/name". You should probably check this after all the other scripts have had a chance to load.
---@param id string
---@param version string|nil
---@return boolean
function script_enabled(id, version) end

---Seed the game prng.
---@param seed integer
function seed_prng(seed) end

---Set the current adventure seed pair. Use just before resetting a run to recreate an adventure run.
---@param first integer
---@param second integer
function set_adventure_seed(first, second) end

---Use [replace_drop](https://spelunky-fyi.github.io/overlunky/#replace_drop)(DROP.ARROWTRAP_WOODENARROW, new_arrow_type) and [replace_drop](https://spelunky-fyi.github.io/overlunky/#replace_drop)(DROP.POISONEDARROWTRAP_WOODENARROW, new_arrow_type) instead
---@deprecated
---@param regular_entity_type ENT_TYPE
---@param poison_entity_type ENT_TYPE
function set_arrowtrap_projectile(regular_entity_type, poison_entity_type) end

---Same as `Player.set_heart_color`
---@param type_id ENT_TYPE
---@param color Color
function set_character_heart_color(type_id, color) end

---Set engine target frametime (1/framerate, default 1/60). Always capped by your GPU max FPS / VSync. To run the engine faster than rendered FPS, try update_state. Set to 0 to go as fast as possible. Call without arguments to reset. Also see set_speedhack
---@param frametime number|nil
function set_frametime(frametime) end

---Set engine target frametime when game is unfocused (1/framerate, default 1/33). Always capped by the engine frametime. Set to 0 to go as fast as possible. Call without arguments to reset.
---@param frametime number|nil
function set_frametime_unfocused(frametime) end

---Returns unique id >= 0 for the callback to be used in [clear_callback](https://spelunky-fyi.github.io/overlunky/#clear_callback) or -1 if the key could not be registered.
---Add callback function to be called on a hotkey, using Windows hotkey api. These hotkeys will override all game and UI input and can work even when the game is unfocused. They are by design very intrusive and won't let anything else use the same key combo. Can't detect if input is active in another instance, use ImGuiIO if you need Playlunky hotkeys to react to Overlunky input state. Key is a KEY combo (e.g. `KEY.OL_MOD_CTRL | KEY.X`), possibly returned by GuiDrawContext:key_picker. Doesn't work with mouse buttons.
---The callback signature is nil on_hotkey(KEY key)
---@param cb function
---@param key KEY
---@param flags HOTKEY_TYPE|nil
---@return CallbackId
function set_hotkey(cb, key, flags) end

---Disable the Infinite Loop Detection of 420 million instructions per frame, if you know what you're doing and need to perform some serious calculations that hang the game updates for several seconds.
---@param enable boolean
function set_infinite_loop_detection_enabled(enable) end

---Enables or disables the journal
---@param b boolean
function set_journal_enabled(b) end

---Set the value for the specified config
---@param config LEVEL_CONFIG
---@param value integer
function set_level_config(config, value) end

---Set seed and reset run.
---@param seed integer
function set_seed(seed) end

---Sets the specified setting temporarily. These values are not saved and might reset to the users real settings if they visit the options menu. (Check example.) All settings are available in unsafe mode and only a smaller subset SAFE_SETTING by default for Hud and other visuals. Returns false, if setting failed.
---@param setting GAME_SETTING
---@param value integer
---@return boolean
function set_setting(setting, value) end

---Set multiplier (default 1.0) for a QueryPerformanceCounter hook based speedhack, similar to the one in Cheat Engine. Call without arguments to reset. Also see [set_frametime](https://spelunky-fyi.github.io/overlunky/#set_frametime)
---@param multiplier number|nil
function set_speedhack(multiplier) end

---Open the journal on a chapter and page. The main Journal spread is pages 0..1, so most chapters start at 2. Use even page numbers only.
---@param chapter JOURNALUI_PAGE_SHOWN
---@param page integer
function show_journal(chapter, page) end

---Open or close the journal as if pressing the journal button. Will respect visible journal popups and [force_journal](https://spelunky-fyi.github.io/overlunky/#force_journal).
function toggle_journal() end

---Measures angle between two lines with one common point
---@param A Vec2
---@param common Vec2
---@param B Vec2
---@return number
---@overload fun(line1_A: Vec2, line1_B: Vec2, line2_A: Vec2, line2_B: Vec2): number
function two_lines_angle(A, common, B) end

---Updates the floor collisions used by the liquids, set add to false to remove tile of collision, set to true to add one
---optional `layer` parameter to be used when liquid was moved to back layer using [set_liquid_layer](https://spelunky-fyi.github.io/overlunky/#set_liquid_layer)
---@param x number
---@param y number
---@param add boolean
---@param layer LAYER|nil
function update_liquid_collision_at(x, y, add, layer) end

---Run state update manually, i.e. simulate one logic frame. Use in e.g. POST_UPDATE, but be mindful of infinite loops, this will cause another POST_UPDATE. Can even be called thousands of times to simulate minutes of gameplay in a few seconds.
function update_state() end

---Warp to a level immediately.
---@param world integer
---@param level integer
---@param theme integer
function warp(world, level, theme) end

---Use [GuiDrawContext](https://spelunky-fyi.github.io/overlunky/#GuiDrawContext)`.win_button` instead
---@deprecated
---@param text string
---@return boolean
function win_button(text) end

---Use [GuiDrawContext](https://spelunky-fyi.github.io/overlunky/#GuiDrawContext)`.win_check` instead
---@deprecated
---@param label string
---@param value boolean
---@return boolean
function win_check(label, value) end

---Use [GuiDrawContext](https://spelunky-fyi.github.io/overlunky/#GuiDrawContext)`.win_combo` instead
---@deprecated
---@param label string
---@param selected integer
---@param opts string
---@return integer
function win_combo(label, selected, opts) end

---Use [GuiDrawContext](https://spelunky-fyi.github.io/overlunky/#GuiDrawContext)`.win_drag_float` instead
---@deprecated
---@param label string
---@param value number
---@param min number
---@param max number
---@return number
function win_drag_float(label, value, min, max) end

---Use [GuiDrawContext](https://spelunky-fyi.github.io/overlunky/#GuiDrawContext)`.win_drag_int` instead
---@deprecated
---@param label string
---@param value integer
---@param min integer
---@param max integer
---@return integer
function win_drag_int(label, value, min, max) end

---Use [GuiDrawContext](https://spelunky-fyi.github.io/overlunky/#GuiDrawContext)`.win_image` instead
---@deprecated
---@param image IMAGE
---@param width number
---@param height number
function win_image(image, width, height) end

---Use [GuiDrawContext](https://spelunky-fyi.github.io/overlunky/#GuiDrawContext)`.win_inline` instead
---@deprecated
function win_inline() end

---Use [GuiDrawContext](https://spelunky-fyi.github.io/overlunky/#GuiDrawContext)`.win_popid` instead
---@deprecated
function win_popid() end

---Use [GuiDrawContext](https://spelunky-fyi.github.io/overlunky/#GuiDrawContext)`.win_pushid` instead
---@deprecated
---@param id integer
function win_pushid(id) end

---Use [GuiDrawContext](https://spelunky-fyi.github.io/overlunky/#GuiDrawContext)`.win_sameline` instead
---@deprecated
---@param offset number
---@param spacing number
function win_sameline(offset, spacing) end

---Use [GuiDrawContext](https://spelunky-fyi.github.io/overlunky/#GuiDrawContext)`.win_separator` instead
---@deprecated
function win_separator() end

---Use [GuiDrawContext](https://spelunky-fyi.github.io/overlunky/#GuiDrawContext)`.win_slider_float` instead
---@deprecated
---@param label string
---@param value number
---@param min number
---@param max number
---@return number
function win_slider_float(label, value, min, max) end

---Use [GuiDrawContext](https://spelunky-fyi.github.io/overlunky/#GuiDrawContext)`.win_slider_int` instead
---@deprecated
---@param label string
---@param value integer
---@param min integer
---@param max integer
---@return integer
function win_slider_int(label, value, min, max) end

---Use [GuiDrawContext](https://spelunky-fyi.github.io/overlunky/#GuiDrawContext)`.win_text` instead
---@deprecated
---@param text string
function win_text(text) end

---Use [GuiDrawContext](https://spelunky-fyi.github.io/overlunky/#GuiDrawContext)`.window` instead
---@deprecated
---@param title string
---@param x number
---@param y number
---@param w number
---@param h number
---@param movable boolean
---@param callback fun(p1: GuiDrawContext|nil, p2: Vec2, p3: Vec2) @Returning nil: ignored.
function window(title, x, y, w, h, movable, callback) end

-- ## Input functions

---Converts (x, y, BUTTON) to INPUTS
---@param x number
---@param y number
---@param buttons BUTTON
---@return INPUTS
function buttons_to_inputs(x, y, buttons) end

---Returns: [ImGuiIO](https://spelunky-fyi.github.io/overlunky/#ImGuiIO) for raw keyboard, mouse and xinput gamepad stuff.
---@return ImGuiIO
function get_io() end

---Returns RawInput, a game structure for raw keyboard and controller state
---@return RawInput|nil
function get_raw_input() end

---Current mouse cursor position in screen coordinates.
---@return number
---@return number
function mouse_position() end

---Use `players[1].input.buttons_gameplay` for only the inputs during the game, or `.buttons` for all the inputs, even during the pause menu
---Of course, you can get the Player by other mean, it doesn't need to be the `players` table
---You can only read inputs from actual players, HH don't have any inputs
---@deprecated
---@param uid integer
---@return INPUTS
function read_input(uid) end

---Read input that has been previously stolen with [steal_input](https://spelunky-fyi.github.io/overlunky/#steal_input)
---Use `state.player_inputs.player_slots[player_slot].buttons_gameplay` for only the inputs during the game, or `.buttons` for all the inputs, even during the pause menu
---@deprecated
---@param uid integer
---@return INPUTS
function read_stolen_input(uid) end

---Return input previously stolen with [steal_input](https://spelunky-fyi.github.io/overlunky/#steal_input)
---@deprecated
---@param uid integer
function return_input(uid) end

---Send input to entity, has to be previously stolen with [steal_input](https://spelunky-fyi.github.io/overlunky/#steal_input)
---@deprecated
---@param uid integer
---@param buttons INPUTS
function send_input(uid, buttons) end

---Deprecated because it's a weird old hack that crashes the game. You can modify inputs in many other ways, like editing `state.player_inputs.player_slot_1.buttons_gameplay` in PRE_UPDATE or a `set_pre_process_input` hook. Steal input from a Player, HiredHand or PlayerGhost.
---@deprecated
---@param uid integer
function steal_input(uid) end

---Use [GuiDrawContext](https://spelunky-fyi.github.io/overlunky/#GuiDrawContext)`.win_input_float` instead
---@deprecated
---@param label string
---@param value number
---@return number
function win_input_float(label, value) end

---Use [GuiDrawContext](https://spelunky-fyi.github.io/overlunky/#GuiDrawContext)`.win_input_int` instead
---@deprecated
---@param label string
---@param value integer
---@return integer
function win_input_int(label, value) end

---Use [GuiDrawContext](https://spelunky-fyi.github.io/overlunky/#GuiDrawContext)`.win_input_text` instead
---@deprecated
---@param label string
---@param value string
---@return string
function win_input_text(label, value) end

-- ## Lighting functions

---Creates a new Illumination. Don't forget to continuously call [refresh_illumination](https://spelunky-fyi.github.io/overlunky/#refresh_illumination), otherwise your light emitter fades out! Check out the [illumination.lua](https://github.com/spelunky-fyi/overlunky/blob/main/examples/illumination.lua) script for an example.
---Warning: this is only valid for current level!
---@param color Color
---@param size number
---@param x number
---@param y number
---@return Illumination|nil
---@overload fun(color: Color, size: number, uid: integer): Illumination|nil
---@overload fun(pos: Vec2, color: Color, type: LIGHT_TYPE, size: number, flags: integer, uid: integer, layer: LAYER): Illumination|nil
function create_illumination(color, size, x, y) end

---Refreshes an Illumination, keeps it from fading out, short for `illumination.timer = get_frame()`
---@param illumination Illumination|nil
function refresh_illumination(illumination) end

-- ## Message functions

---Hide the speech bubble currently on screen, if any, by expiring its timer.
function cancel_speechbubble() end

---Hide the toast message currently on screen, if any, by expiring its timer.
function cancel_toast() end

---Prinspect to in-game console.
---@vararg any
function console_prinspect(...) end

---Print a log message to in-game console with a comment identifying the script that sent it.
---@param message string
function console_print(message) end

---Log to spelunky.log
---@param message string
function log_print(message) end

---Standard lua print function, prints directly to the terminal but not to the game
---@param message string
function lua_print(message) end

---Same as `print`
---@param message string
function message(message) end

---Same as `prinspect`
---@vararg any
function messpect(...) end

---Prints any type of object by first funneling it through `inspect`, no need for a manual `tostring` or `inspect`.
---@vararg any
function prinspect(...) end

---Print a log message on screen.
---@param message string
function print(message) end

---Short for print(string.format(...))
function printf(...) end

---Show a message coming from an entity
---@param entity_uid integer
---@param message string
---@param sound_type integer
---@param top boolean
function say(entity_uid, message, sound_type, top) end

---Returns true while a speech bubble is on screen.
---@return boolean
function speechbubble_visible() end

---Show a message that looks like a level feeling.
---@param message string
function toast(message) end

---Returns true while a toast message is on screen.
---@return boolean
function toast_visible() end

-- ## Movable Behavior functions

---Make a `CustomMovableBehavior`, if `base_behavior` is `nil` you will have to set all of the
---behavior functions. If a behavior with `behavior_name` already exists for your script it will
---be returned instead.
---@param behavior_name string
---@param state_id integer
---@param base_behavior VanillaMovableBehavior|nil
---@return CustomMovableBehavior|nil
function make_custom_behavior(behavior_name, state_id, base_behavior) end

-- ## Network functions

---Send a synchronous HTTP GET request and return response as a string or nil on an error. Requires unsafe mode.
---@param url string
---@return string|nil
function http_get(url) end

---Send an asynchronous HTTP GET request and run the callback when done. If there is an error, response will be nil and vice versa.
---The callback signature is nil on_data(string response, string error). Requires unsafe mode.
---@param url string
---@param on_data fun(p1: string|nil, p2: string|nil) @Returning nil: ignored.
function http_get_async(url, on_data) end

---Use the `new` operator on [UdpServer](https://spelunky-fyi.github.io/overlunky/#UdpServer) instead
---The server will be closed lazily by garbage collection once the handle is released. Requires unsafe mode.
---The callback signature is optional<string> on_message(string msg, string src)
---@deprecated
---@param host string
---@param port integer
---@param cb function
---@return any
function udp_listen(host, port, cb) end

---Send data to specified UDP address. Requires unsafe mode.
---@param host string
---@param port integer
---@param msg string
---@return integer
---@overload fun(address: string, msg: string): integer
function udp_send(host, port, msg) end

-- ## Option functions

---Add a boolean option that the user can change in the UI. Read with `options.name`, `value` is the default.
---@param name string
---@param desc string
---@param long_desc string
---@param value boolean
function register_option_bool(name, desc, long_desc, value) end

---Add a button that the user can click in the UI. Sets the timestamp of last click on value and runs the callback function.
---@param name string
---@param desc string
---@param long_desc string
---@param on_click function
function register_option_button(name, desc, long_desc, on_click) end

---Add custom options using the window drawing functions. Everything drawn in the callback will be rendered in the options window and the return value saved to `options[name]` or overwriting the whole `options` table if using and empty name.
---`value` is the default value, and pretty important because anything defined in the callback function will only be defined after the options are rendered. See the example for details.
---The callback signature is optional<any> on_render(GuiDrawContext draw_ctx)
---@param name string
---@param value any
---@param on_render fun(draw_ctx: GuiDrawContext): any|nil @Returning nil: no override: the C++ side keeps its default.
function register_option_callback(name, value, on_render) end

---Add a combobox option that the user can change in the UI. Read the int index of the selection with `options.name`. Separate `opts` with `\0`,
---with a double `\0\0` at the end. `value` is the default index 1..n.
---@param name string
---@param desc string
---@param long_desc string
---@param opts string
---@param value integer
function register_option_combo(name, desc, long_desc, opts, value) end

---Add a float option that the user can change in the UI. Read with `options.name`, `value` is the default. Keep in mind these are just soft
---limits, you can override them in the UI with double click.
---@param name string
---@param desc string
---@param long_desc string
---@param value number
---@param min number
---@param max number
function register_option_float(name, desc, long_desc, value, min, max) end

---Add an integer option that the user can change in the UI. Read with `options.name`, `value` is the default. Keep in mind these are just soft
---limits, you can override them in the UI with double click.
---@param name string
---@param desc string
---@param long_desc string
---@param value integer
---@param min integer
---@param max integer
function register_option_int(name, desc, long_desc, value, min, max) end

---Add a string option that the user can change in the UI. Read with `options.name`, `value` is the default.
---@param name string
---@param desc string
---@param long_desc string
---@param value string
function register_option_string(name, desc, long_desc, value) end

---Removes an option by name. To make complicated conditionally visible options you should probably just use register_option_callback though.
---@param name string
function unregister_option(name) end

-- ## Particle functions

---Advances the state of the screen particle emitter (simulates the next positions, ... of all the particles in the emitter). Only used with screen particle emitters. See the `particles.lua` example script for more details.
---@param particle_emitter ParticleEmitterInfo|nil
function advance_screen_particles(particle_emitter) end

---Extinguish a particle emitter (use the return value of `generate_world_particles` or `generate_screen_particles` as the parameter in this function)
---@param particle_emitter ParticleEmitterInfo|nil
function extinguish_particles(particle_emitter) end

---Use `generate_world_particles`
---@deprecated
---@param particle_emitter_id PARTICLEEMITTER
---@param uid integer
---@return ParticleEmitterInfo|nil
function generate_particles(particle_emitter_id, uid) end

---Generate particles of the specified type at a certain screen coordinate (use e.g. `local emitter = generate_screen_particles(PARTICLEEMITTER.CHARSELECTOR_TORCHFLAME_FLAMES, 0.0, 0.0)`). See the `particles.lua` example script for more details.
---@param particle_emitter_id PARTICLEEMITTER
---@param x number
---@param y number
---@return ParticleEmitterInfo|nil
function generate_screen_particles(particle_emitter_id, x, y) end

---Generate particles of the specified type around the specified entity uid (use e.g. `local emitter = generate_world_particles(PARTICLEEMITTER.PETTING_PET, players[1].uid)`). You can then decouple the emitter from the entity with `emitter.entity_uid = -1` and freely move it around. See the `particles.lua` example script for more details.
---@param particle_emitter_id PARTICLEEMITTER
---@param uid integer
---@return ParticleEmitterInfo|nil
function generate_world_particles(particle_emitter_id, uid) end

---Get the [ParticleDB](https://spelunky-fyi.github.io/overlunky/#ParticleDB) details of the specified ID
---@param id PARTICLEEMITTER
---@return ParticleDB|nil
function get_particle_type(id) end

---Renders the particles to the screen. Only used with screen particle emitters. See the `particles.lua` example script for more details.
---@param particle_emitter ParticleEmitterInfo|nil
function render_screen_particles(particle_emitter) end

-- ## Position functions

---Calculate the tile distance of two entities by uid
---@param uid_a integer
---@param uid_b integer
---@return number
function distance(uid_a, uid_b) end

---Calculate the bounding box of text, so you can center it etc. Returns `width`, `height` in screen distance.
---@param size number
---@param text string
---@return number
---@return number
function draw_text_size(size, text) end

---Removes all liquid that is about to go out of bounds, this would normally crash the game, but playlunky/overlunky patch this bug.
---The patch however does not destroy the liquids that fall pass the level bounds,
---so you may still want to use this function if you spawn a lot of liquid that may fall out of the level
function fix_liquid_out_of_bounds() end

---Get the game coordinates at the screen position (`x`, `y`)
---@param x number
---@param y number
---@return number
---@return number
function game_position(x, y) end

---Same as [get_bounds](https://spelunky-fyi.github.io/overlunky/#get_bounds) but returns AABB struct instead of loose floats
---@return AABB
function get_aabb_bounds() end

---Basically gets the absolute coordinates of the area inside the unbreakable bedrock walls, from wall to wall. Every solid entity should be
---inside these boundaries. The order is: left x, top y, right x, bottom y
---@return number
---@return number
---@return number
---@return number
function get_bounds() end

---Gets the current camera position in the level
---@return number
---@return number
function get_camera_position() end

---Gets the hitbox of an entity, use `extrude` to make the hitbox bigger/smaller in all directions and `offset` to offset the hitbox in a given direction
---@param uid integer
---@param extrude number|nil
---@param offsetx number|nil
---@param offsety number|nil
---@return AABB
function get_hitbox(uid, extrude, offsetx, offsety) end

---Approximate bounding box of the player hud element for player index 1..4 based on user settings and player count
---@param index integer
---@return AABB
function get_hud_position(index) end

---Get image size from file. Returns a tuple containing width and height.
---@param path string
---@return integer
---@return integer
function get_image_size(path) end

---Get position `x, y, layer` of entity by uid. Use this, don't use `Entity.x/y` because those are sometimes just the offset to the entity
---you're standing on, not real level coordinates.
---@param uid integer
---@return number
---@return number
---@return integer
function get_position(uid) end

---Same as `get_hitbox` but based on `get_render_position`
---@param uid integer
---@param extrude number|nil
---@param offsetx number|nil
---@param offsety number|nil
---@return AABB
function get_render_hitbox(uid, extrude, offsetx, offsety) end

---Get interpolated render position `x, y, layer` of entity by uid. This gives smooth hitboxes for 144Hz master race etc...
---@param uid integer
---@return number
---@return number
---@return integer
function get_render_position(uid) end

---Get velocity `vx, vy` of an entity by uid. Use this to get velocity relative to the game world, (the `Entity.velocityx/velocityy` are relative to `Entity.overlay`). Only works for movable or liquid entities
---@param uid integer
---@return number
---@return number
function get_velocity(uid) end

---Gets the resolution (width and height) of the screen
---@return integer
---@return integer
function get_window_size() end

---Get the current set zoom level
---@return number
function get_zoom_level() end

---Check if position satisfies the given POS_TYPE flags, to be used in a custom is_valid function procedural for spawns.
---@param x number
---@param y number
---@param layer LAYER
---@param flags POS_TYPE
---@return boolean
function position_is_valid(x, y, layer, flags) end

---Convert an `AABB` to a screen `AABB` that can be directly passed to draw functions
---@param box AABB
---@return AABB
function screen_aabb(box) end

---Translate a distance of `x` tiles to screen distance to be be used in drawing functions
---@param x number
---@return number
function screen_distance(x) end

---Translate an entity position to screen position to be used in drawing functions
---@param x number
---@param y number
---@return number
---@return number
function screen_position(x, y) end

---Sets the absolute current camera position without rubberbanding animation. Ignores camera bounds or currently focused uid, but doesn't clear them. Best used in ON.RENDER_PRE_GAME or similar. See Camera for proper camera handling with bounds and rubberbanding.
---@param cx number
---@param cy number
function set_camera_position(cx, cy) end

---Updates the camera focus according to the params set in Camera, i.e. to apply normal camera movement when paused etc.
function update_camera_position() end

---Set the zoom level used in levels and shops. 13.5 is the default, or 12.5 for shops. See zoom_reset.
---@param level number
function zoom(level) end

---Reset the default zoom levels for all areas and sets current zoom level to 13.5.
function zoom_reset() end

-- ## Room functions

---Define a new room template to use with `set_room_template`
---@param room_template string
---@param type ROOM_TEMPLATE_TYPE
---@return integer
function define_room_template(room_template, type) end

---Transform a position to a room index to be used in `get_room_template` and `PostRoomGenerationContext.set_room_template`
---@param x number
---@param y number
---@return integer
---@return integer
function get_room_index(x, y) end

---Transform a room index into the top left corner position in the room
---@param x integer
---@param y integer
---@return number
---@return number
function get_room_pos(x, y) end

---Get the room template given a certain index, returns `nil` if coordinates are out of bounds
---@param x integer
---@param y integer
---@param layer LAYER
---@return integer|nil
function get_room_template(x, y, layer) end

---For debugging only, get the name of a room template, returns `'invalid'` if room template is not defined
---@param room_template integer
---@return string
function get_room_template_name(room_template) end

---Get whether a room is the origin of a machine room
---@param x integer
---@param y integer
---@return boolean
function is_machine_room_origin(x, y) end

---Get whether a room is flipped at the given index, returns `false` if coordinates are out of bounds
---@param x integer
---@param y integer
---@return boolean
function is_room_flipped(x, y) end

---Set the size of room template in tiles, the template must be of type `ROOM_TEMPLATE_TYPE.MACHINE_ROOM`.
---@param room_template integer
---@param width integer
---@param height integer
---@return boolean
function set_room_template_size(room_template, width, height) end

---Spawn a RoomOwner (or a few other like [CavemanShopkeeper](https://spelunky-fyi.github.io/overlunky/#CavemanShopkeeper)) in the coordinates and make them own the room, optionally changing the room template. Returns the RoomOwner uid.
---@param owner_type ENT_TYPE
---@param x number
---@param y number
---@param layer LAYER
---@param room_template ROOM_TEMPLATE|nil
---@return integer
function spawn_roomowner(owner_type, x, y, layer, room_template) end

-- ## Shop functions

---Adds entity as shop item, has to be of [Purchasable](https://spelunky-fyi.github.io/overlunky/#Purchasable) type, check the [entity hierarchy list](https://github.com/spelunky-fyi/overlunky/blob/main/docs/entities-hierarchy.md) to find all the Purchasable entity types.
---Adding other entities will result in not obtainable items or game crash, if item already is in StateMemory.room_owners.owned_items then it will just re-parent it
---@param item_uid integer
---@param shop_owner_uid integer
function add_item_to_shop(item_uid, shop_owner_uid) end

---Checks whether a coordinate is inside a room containing an active shop. This function checks whether the shopkeeper is still alive.
---@param x number
---@param y number
---@param layer LAYER
---@return boolean
function is_inside_active_shop_room(x, y, layer) end

---Checks whether a coordinate is inside a shop zone, the rectangle where the camera zooms in a bit. Does not check if the shop is still active!
---@param x number
---@param y number
---@param layer LAYER
---@return boolean
function is_inside_shop_zone(x, y, layer) end

---Spawn a Shopkeeper in the coordinates and make the room their shop. Returns the Shopkeeper uid. Also see [spawn_roomowner](https://spelunky-fyi.github.io/overlunky/#spawn_roomowner).
---@param x number
---@param y number
---@param layer LAYER
---@param room_template ROOM_TEMPLATE|nil
---@return integer
function spawn_shopkeeper(x, y, layer, room_template) end

-- ## Sound functions

---@param id SOUNDID
---@return VANILLA_SOUND
---@overload fun(sound: VANILLA_SOUND): SOUNDID
function convert_sound_id(id) end

---Loads a sound from disk relative to this script, ownership might be shared with other code that loads the same file. Returns nil if file can't be found
---@param path string
---@return CustomSound|nil
function create_sound(path) end

---Gets an existing sound, either if a file at the same path was already loaded or if it is already loaded by the game
---@param path_or_vanilla_sound string
---@return CustomSound|nil
function get_sound(path_or_vanilla_sound) end

---Use source_uid to make the sound be played at the location of that entity, set it -1 to just play it "everywhere"
---Returns SoundMeta, beware that the sound can't be stopped (`start_over` and `playing` are unavailable). Should only be used for sfx.
---@param sound_id SOUNDID
---@param source_uid integer
---@return SoundMeta|nil
---@overload fun(sound: VANILLA_SOUND, source_uid: integer): SoundMeta|nil
function play_sound(sound_id, source_uid) end

-- ## Spawn functions

---Default function in spawn definitions to check whether a spawn is valid or not
---@param x number
---@param y number
---@param layer LAYER
---@return boolean
function default_spawn_is_valid(x, y, layer) end

---Define a new extra spawn, these are semi-guaranteed level gen spawns with a fixed upper bound.
---The function `nil do_spawn(float x, float y, LAYER layer)` contains your code to spawn the thing, whatever it is.
---The function `bool is_valid(float x, float y, LAYER layer)` determines whether the spawn is legal in the given position and layer.
---Use for example when you can spawn only on the ceiling, under water or inside a shop.
---Set `is_valid` to `nil` in order to use the default rule (aka. on top of floor and not obstructed).
---To change the number of spawns use `PostRoomGenerationContext:set_num_extra_spawns` during `ON.POST_ROOM_GENERATION`
---No name is attached to the extra spawn since it is not modified from level files, instead every call to this function will return a new unique id.
---@param do_spawn fun(p1: number, p2: number, p3: integer) @Returning nil: ignored.
---@param is_valid fun(p1: number, p2: number, p3: integer): boolean|nil @Returning nil: treated as false.
---@param num_spawns_frontlayer integer
---@param num_spawns_backlayer integer
---@return integer
function define_extra_spawn(do_spawn, is_valid, num_spawns_frontlayer, num_spawns_backlayer) end

---Define a new procedural spawn, the function `nil do_spawn(float x, float y, LAYER layer)` contains your code to spawn the thing, whatever it is.
---The function `bool is_valid(float x, float y, LAYER layer)` determines whether the spawn is legal in the given position and layer.
---Use for example when you can spawn only on the ceiling, under water or inside a shop.
---Set `is_valid` to `nil` in order to use the default rule (aka. on top of floor and not obstructed).
---If a user disables your script but still uses your level mod nothing will be spawned in place of your procedural spawn.
---@param procedural_spawn string
---@param do_spawn fun(p1: number, p2: number, p3: integer) @Returning nil: ignored.
---@param is_valid fun(p1: number, p2: number, p3: integer): boolean|nil @Returning nil: treated as false.
---@return PROCEDURAL_CHANCE
function define_procedural_spawn(procedural_spawn, do_spawn, is_valid) end

---Short for [spawn_door](https://spelunky-fyi.github.io/overlunky/#spawn_door).
---@param x number
---@param y number
---@param layer LAYER
---@param w integer
---@param l integer
---@param t integer
---@return integer
function door(x, y, layer, w, l, t) end

---Use to query whether any of the requested spawns could not be made, usually because there were not enough valid spaces in the level.
---Returns missing spawns in the front layer and missing spawns in the back layer in that order.
---The value only makes sense after level generation is complete, aka after `ON.POST_LEVEL_GENERATION` has run.
---@param extra_spawn_chance_id integer
---@return integer
---@return integer
function get_missing_extra_spawns(extra_spawn_chance_id) end

---Get the inverse chance of a procedural spawn for the current level.
---A return value of 0 does not mean the chance is infinite, it means the chance is zero.
---@param chance_id PROCEDURAL_CHANCE
---@return integer
function get_procedural_spawn_chance(chance_id) end

---Short for [spawn_layer_door](https://spelunky-fyi.github.io/overlunky/#spawn_layer_door).
---@param x number
---@param y number
function layer_door(x, y) end

---Short for [spawn_entity](https://spelunky-fyi.github.io/overlunky/#spawn_entity).
---@param entity_type ENT_TYPE
---@param x number
---@param y number
---@param layer LAYER
---@param vx number
---@param vy number
---@return integer
function spawn(entity_type, x, y, layer, vx, vy) end

---Spawns apep with the choice if it going left or right, if you want the game to choose use regular spawn functions with `ENT_TYPE.MONS_APEP_HEAD`
---@param x number
---@param y number
---@param layer LAYER
---@param right boolean
---@return integer
function spawn_apep(x, y, layer, right) end

---Spawn a companion (hired hand, player character, eggplant child)
---@param companion_type ENT_TYPE
---@param x number
---@param y number
---@param layer LAYER
---@return integer
function spawn_companion(companion_type, x, y, layer) end

---Short for [spawn_entity_nonreplaceable](https://spelunky-fyi.github.io/overlunky/#spawn_entity_nonreplaceable).
---@param entity_type ENT_TYPE
---@param x number
---@param y number
---@param layer LAYER
---@param vx number
---@param vy number
---@return integer
function spawn_critical(entity_type, x, y, layer, vx, vy) end

---Spawn a door to another world, level and theme and return the uid of spawned entity.
---Uses level coordinates with LAYER.FRONT and LAYER.BACK, but player-relative coordinates with LAYER.PLAYERn
---@param x number
---@param y number
---@param layer LAYER
---@param w integer
---@param l integer
---@param t integer
---@return integer
function spawn_door(x, y, layer, w, l, t) end

---Spawn an entity in position with some velocity and return the uid of spawned entity.
---Uses level coordinates with [LAYER.FRONT](https://spelunky-fyi.github.io/overlunky/#LAYER) and LAYER.BACK, but player-relative coordinates with LAYER.PLAYER(n), where (n) is a player number (1-4).
---@param entity_type ENT_TYPE
---@param x number
---@param y number
---@param layer LAYER
---@param vx number
---@param vy number
---@return integer
function spawn_entity(entity_type, x, y, layer, vx, vy) end

---Same as `spawn_entity` but does not trigger any pre-entity-spawn callbacks, so it will not be replaced by another script
---@param entity_type ENT_TYPE
---@param x number
---@param y number
---@param layer LAYER
---@param vx number
---@param vy number
---@return integer
function spawn_entity_nonreplaceable(entity_type, x, y, layer, vx, vy) end

---Spawn an entity of `entity_type` attached to some other entity `over_uid`, in offset `x`, `y`
---@param entity_type ENT_TYPE
---@param over_uid integer
---@param x number
---@param y number
---@return integer
function spawn_entity_over(entity_type, over_uid, x, y) end

---Spawns an entity directly on the floor below the tile at the given position.
---Use this to avoid the little fall that some entities do when spawned during level gen callbacks.
---@param entity_type ENT_TYPE
---@param x number
---@param y number
---@param layer LAYER
---@return integer
function spawn_entity_snapped_to_floor(entity_type, x, y, layer) end

---Spawn a grid entity, such as floor or traps, that snaps to the grid.
---@param entity_type ENT_TYPE
---@param x number
---@param y number
---@param layer LAYER
---@return integer
function spawn_grid_entity(entity_type, x, y, layer) end

---Spawn a door to backlayer.
---@param x number
---@param y number
function spawn_layer_door(x, y) end

---Spawn liquids, always spawns in the front layer, will have fun effects if `entity_type` is not a liquid (only the short version, without velocity etc.).
---Don't overuse this, you are still restricted by the liquid pool sizes and thus might crash the game.
---`liquid_flags` - not much known about, 2 - will probably crash the game, 3 - pause_physics, 6-12 is probably agitation, surface_tension etc. set to 0 to ignore
---`amount` - it will spawn amount x amount (so 1 = 1, 2 = 4, 3 = 6 etc.), `blobs_separation` is optional
---@param entity_type ENT_TYPE
---@param x number
---@param y number
---@overload fun(entity_type: ENT_TYPE, x: number, y: number, velocityx: number, velocityy: number, liquid_flags: integer, amount: integer)
---@overload fun(entity_type: ENT_TYPE, x: number, y: number, velocityx: number, velocityy: number, liquid_flags: integer, amount: integer, blobs_separation: number)
function spawn_liquid(entity_type, x, y) end

---Spawns and grows mushroom, height relates to the trunk, without it, it will roll the game default 3-5 height
---Regardless, if there is not enough space, it will spawn shorter one or if there is no space even for the smallest one, it will just not spawn at all
---Returns uid of the base or -1 if it wasn't able to spawn
---@param x number
---@param y number
---@param l LAYER
---@return integer
---@overload fun(x: number, y: number, l: LAYER, height: integer): integer
function spawn_mushroom(x, y, l) end

---Short for [spawn_entity_snapped_to_floor](https://spelunky-fyi.github.io/overlunky/#spawn_entity_snapped_to_floor).
---@param entity_type ENT_TYPE
---@param x number
---@param y number
---@param layer LAYER
---@return integer
function spawn_on_floor(entity_type, x, y, layer) end

---Short for [spawn_entity_over](https://spelunky-fyi.github.io/overlunky/#spawn_entity_over)
---@param entity_type ENT_TYPE
---@param over_uid integer
---@param x number
---@param y number
---@return integer
function spawn_over(entity_type, over_uid, x, y) end

---Spawn a player in given location, if player of that slot already exist it will spawn clone, the game may crash as this is very unexpected situation
---If you want to respawn a player that is a ghost, set in his Inventory `health` to above 0, and `time_of_death` to 0 and call this function, the ghost entity will be removed automatically
---@param player_slot integer
---@param x number|nil
---@param y number|nil
---@param layer LAYER|nil
---@return integer
function spawn_player(player_slot, x, y, layer) end

---Spawn the PlayerGhost entity, it will not move and not be connected to any player, you can then use [steal_input](https://spelunky-fyi.github.io/overlunky/#steal_input) and send_input to control it
---or change it's `player_inputs` to the `input` of real player so he can control it directly
---@param char_type ENT_TYPE
---@param x number
---@param y number
---@param layer LAYER
---@return integer
function spawn_playerghost(char_type, x, y, layer) end

---Spawns and grows a tree
---@param x number
---@param y number
---@param layer LAYER
---@return integer
---@overload fun(x: number, y: number, layer: LAYER, height: integer): integer
function spawn_tree(x, y, layer) end

---Spawns an already unrolled rope as if created by player
---@param x number
---@param y number
---@param layer LAYER
---@param texture TEXTURE
---@return integer
---@overload fun(x: number, y: number, layer: LAYER, texture: TEXTURE, max_length: integer): integer
function spawn_unrolled_player_rope(x, y, layer, texture) end

-- ## String functions

---Adds custom name to the item by uid used in the shops
---This is better alternative to `add_string` but instead of changing the name for entity type, it changes it for this particular entity
---@param uid integer
---@param name string
function add_custom_name(uid, name) end

---Add custom string, currently can only be used for names of shop items (EntityDB->description)
---Returns STRINGID of the new string
---@param str string
---@return STRINGID
function add_string(str) end

---Change string at the given id (**don't use stringid directly for vanilla string**, use [hash_to_stringid](https://spelunky-fyi.github.io/overlunky/#hash_to_stringid) first)
---This edits custom string and in game strings but changing the language in settings will reset game strings
---@param id STRINGID
---@param str string
function change_string(id, str) end

---Clears the name set with [add_custom_name](https://spelunky-fyi.github.io/overlunky/#add_custom_name)
---@param uid integer
function clear_custom_name(uid) end

---Return the matching names for a bitmask in an enum table of masks
---@param enum table
---@param value integer
---@return table<string>
function enum_get_mask_names(enum, value) end

---Return the name of the first matching number in an enum table
---@param enum table
---@param value integer
---@return string
function enum_get_name(enum, value) end

---Return all the names of a number in an enum table
---@param enum table
---@param value integer
---@return table<string>
function enum_get_names(enum, value) end

---Same as `Player.get_name`
---@param type_id ENT_TYPE
---@return string
function get_character_name(type_id) end

---Same as `Player.get_short_name`
---@param type_id ENT_TYPE
---@return string
function get_character_short_name(type_id) end

---Get string behind STRINGID, **don't use stringid directly for vanilla string**, use [hash_to_stringid](https://spelunky-fyi.github.io/overlunky/#hash_to_stringid) first
---Will return the string of currently choosen language
---@param string_id STRINGID
---@return string
function get_string(string_id) end

---Convert the hash to stringid
---Check [strings00_hashed.str](https://github.com/spelunky-fyi/overlunky/blob/main/docs/game_data/strings00_hashed.str) for the hash values, or extract assets with modlunky and check those.
---@param hash integer
---@return STRINGID
function hash_to_stringid(hash) end

---Returns human readable string from KEY chord (e.g. "Ctrl+X", "Unknown" or "None")
---@return string
function key_name() end

---Set the level number shown in the hud and journal to any string. This is reset to the default "%d-%d" automatically just before PRE_LOAD_SCREEN to a level or main menu, so use in PRE_LOAD_SCREEN, POST_LEVEL_GENERATION or similar for each level.
---Use "%d-%d" to reset to default manually. Does not affect the "...COMPLETED!" message in transitions or lines in "Dear Journal", you need to edit them separately with [change_string](https://spelunky-fyi.github.io/overlunky/#change_string).
---@param str string
function set_level_string(str) end

-- ## Texture functions

---Defines a new texture that can be used in Entity::set_texture
---If a texture with the same definition already exists the texture will be reloaded from disk.
---@param texture_data TextureDefinition
---@return TEXTURE
function define_texture(texture_data) end

---Gets a texture with the same definition as the given, if none exists returns `nil`
---@param texture_data TextureDefinition
---@return TEXTURE|nil
function get_texture(texture_data) end

---Gets a `TextureDefinition` for equivalent to the one used to define the texture with `id`
---@param texture_id TEXTURE
---@return TextureDefinition
function get_texture_definition(texture_id) end

---Reloads a texture from disk, use this only as a development tool for example in the console
---Note that [define_texture](https://spelunky-fyi.github.io/overlunky/#define_texture) will also reload the texture if it already exists
---@param texture_path string
function reload_texture(texture_path) end

---Replace a vanilla texture definition with a custom texture definition and reload the texture.
---@param vanilla_id TEXTURE
---@param custom_id TEXTURE
---@return boolean
function replace_texture(vanilla_id, custom_id) end

---Replace a vanilla texture definition with a custom texture definition and reload the texture. Set corresponding character heart color to the pixel in the center of the player indicator arrow in that texture. (448,1472)
---@param vanilla_id TEXTURE
---@param custom_id TEXTURE
---@return boolean
function replace_texture_and_heart_color(vanilla_id, custom_id) end

---Same as `set_lut(nil, layer)`
---@param layer LAYER
function reset_lut(layer) end

---Reset a replaced vanilla texture to the original and reload the texture.
---@param vanilla_id TEXTURE
function reset_texture(vanilla_id) end

---Force the LUT texture for the given layer (or both) until it is reset.
---Pass `nil` in the first parameter to reset
---@param texture_id TEXTURE|nil
---@param layer LAYER
function set_lut(texture_id, layer) end

-- ## Theme functions

---Forces the theme of the next cosmic ocean level(s) (use e.g. `force_co_subtheme(COSUBTHEME.JUNGLE)`. Use COSUBTHEME.RESET to reset to default random behaviour)
---@param subtheme COSUBTHEME
function force_co_subtheme(subtheme) end

---Force current subtheme used in the CO theme. You can pass a CustomTheme, ThemeInfo or THEME. Not to be confused with force_co_subtheme.
---@param customtheme CustomTheme|ThemeInfo|THEME
function force_custom_subtheme(customtheme) end

---Force a theme in PRE_LOAD_LEVEL_FILES, POST_ROOM_GENERATION or PRE_LEVEL_GENERATION to change different aspects of the levelgen. You can pass a CustomTheme, ThemeInfo or THEME.
---@param customtheme CustomTheme|ThemeInfo|THEME
function force_custom_theme(customtheme) end

---Gets the sub theme of the current cosmic ocean level, returns COSUBTHEME.NONE if the current level is not a CO level.
---@return COSUBTHEME
function get_co_subtheme() end

-- ## Tile code functions

---Define a new tile code, to make this tile code do anything you have to use either [set_pre_tile_code_callback](https://spelunky-fyi.github.io/overlunky/#set_pre_tile_code_callback) or [set_post_tile_code_callback](https://spelunky-fyi.github.io/overlunky/#set_post_tile_code_callback).
---If a user disables your script but still uses your level mod nothing will be spawned in place of your tile code.
---@param tile_code string
---@return TILE_CODE
function define_tile_code(tile_code) end

---Gets a short tile code based on definition, returns `nil` if it can't be found
---@param short_tile_code_def ShortTileCodeDef
---@return integer|nil
function get_short_tile_code(short_tile_code_def) end

---Gets the definition of a short tile code (if available), will vary depending on which file is loaded
---@param short_tile_code SHORT_TILE_CODE
---@return ShortTileCodeDef|nil
function get_short_tile_code_definition(short_tile_code) end

---Add a callback for a specific tile code that is called after the game handles the tile code.
---Use this to affect what the game or other scripts spawned in this position.
---This is received even if a previous pre-tile-code-callback has returned true
---The callback signature is nil post_tile_code(float x, float y, int layer, ROOM_TEMPLATE room_template)
---@param cb fun(x: number, y: number, layer: integer, room_template: integer) @Returning nil: ignored.
---@param tile_code string
---@return CallbackId
function set_post_tile_code_callback(cb, tile_code) end

---Add a callback for a specific tile code that is called before the game handles the tile code.
---Return true in order to stop the game or scripts loaded after this script from handling this tile code.
---For example, when returning true in this callback set for `"floor"` then no floor will spawn in the game (unless you spawn it yourself)
---The callback signature is bool pre_tile_code(float x, float y, int layer, ROOM_TEMPLATE room_template)
---@param cb fun(x: number, y: number, layer: integer, room_template: integer): boolean|nil @Returning nil: treated as false.
---@param tile_code string
---@return CallbackId
function set_pre_tile_code_callback(cb, tile_code) end

-- ## io

---@param filename string
---@param mode string|nil
---@return any
function io.open_data(filename, mode) end

---@param filename string
---@param mode string|nil
---@return any
function io.open_mod(filename, mode) end

function io.type(...) end

-- ## os

function os.clock(...) end

function os.date(...) end

function os.difftime(...) end

---@param filename string
---@return any
function os.remove_data(filename) end

---@param filename string
---@return any
function os.remove_mod(filename) end

function os.time(...) end

-- ## package

---@param path string
---@param func string
---@return any
function package.loadlib(path, func) end

-- ## Aliases

---@alias BucketItem boolean|integer|number|string
---@alias CallbackId integer
---@alias Flags integer
---@alias IMAGE integer
---@alias SHORT_TILE_CODE integer
---@alias SOUNDID integer
---@alias STRINGID integer
---@alias uColor integer

-- ## Lua libraries

-- dump_api: math, base, string, table, coroutine, package, debug
-- load_libraries: math, base, string, table, coroutine, package
-- load_unsafe_libraries: io, os, ffi, debug