#include "lua/callback_run.h" #include "classes.h" #include "entity/weapon/bomb.h" #include "entity/effect/effect.h" #include "entity/familiar/familiar.h" #include "entity/weapon/knife.h" #include "entity/weapon/laser.h" #include "entity/npc/npc.h" #include "entity/pickup/pickup.h" #include "entity/player/player.h" #include "entity/weapon/projectile.h" #include "entity/weapon/tear.h" #include "game/game.h" #include "level/room_config.h" constexpr int PILL_EFFECT_UNCHANGED = -1; // 00862250 Runs MC_PRE_BOMB_COLLISION, filtered by the bomb's variant. LuaResult LuaEngine::PreBombCollision(Entity_Bomb* bomb, Entity* collider, bool isLow) { CallbackRun run = {"PreBombCollision", MC_PRE_BOMB_COLLISION, (int)bomb->variant}; return collision_run(*this, run, bomb, collider, isLow); } // 008610d0 Runs MC_PRE_FAMILIAR_COLLISION, filtered by the familiar's variant. LuaResult LuaEngine::PreFamiliarCollision(Entity_Familiar* familiar, Entity* collider, bool isLow) { CallbackRun run = {"PreFamiliarCollision", MC_PRE_FAMILIAR_COLLISION, (int)familiar->variant}; return collision_run(*this, run, familiar, collider, isLow); } // 00861c40 Runs MC_PRE_KNIFE_COLLISION, filtered by the knife's subtype. LuaResult LuaEngine::PreKnifeCollision(Entity_Knife* knife, Entity* collider, bool isLow) { CallbackRun run = {"PreKnifeCollision", MC_PRE_KNIFE_COLLISION, (int)knife->subtype}; return collision_run(*this, run, knife, collider, isLow); } // 00860d70 Runs MC_PRE_NPC_COLLISION, filtered by the NPC's type. LuaResult LuaEngine::PreNPCCollision(Entity_NPC* npc, Entity* collider, bool isLow) { CallbackRun run = {"PreNPCCollision", MC_PRE_NPC_COLLISION, (int)npc->type}; return collision_run(*this, run, npc, collider, isLow); } // 008631b0 Runs MC_PRE_PICKUP_COLLISION, filtered by the pickup's variant. LuaResult LuaEngine::PrePickupCollision(Entity_Pickup* pickup, Entity* collider, bool isLow) { CallbackRun run = {"PrePickupCollision", MC_PRE_PICKUP_COLLISION, (int)pickup->variant}; return collision_run(*this, run, pickup, collider, isLow); } // 00864300 Runs MC_PRE_PLAYER_COLLISION, filtered by the player's variant. LuaResult LuaEngine::PrePlayerCollide(Entity_Player* player, Entity* collider, bool isLow) { CallbackRun run = {"PrePlayerCollision", MC_PRE_PLAYER_COLLISION, (int)player->variant}; return collision_run(*this, run, player, collider, isLow); } // 00862760 Runs MC_PRE_PROJECTILE_COLLISION, filtered by the projectile's variant. LuaResult LuaEngine::PreProjectileCollision(Entity_Projectile* projectile, Entity* collider, bool isLow) { CallbackRun run = {"PreProjectileCollision", MC_PRE_PROJECTILE_COLLISION, (int)projectile->variant}; return collision_run(*this, run, projectile, collider, isLow); } // 00862d70 Runs MC_PRE_TEAR_COLLISION, filtered by the tear's variant. LuaResult LuaEngine::PreTearCollision(Entity_Tear* tear, Entity* collider, bool isLow) { CallbackRun run = {"PreTearCollision", MC_PRE_TEAR_COLLISION, (int)tear->variant}; return collision_run(*this, run, tear, collider, isLow); } // 00865340 Runs MC_GET_CARD for a card the pools drew. The card a mod chose, or the drawn one. int LuaEngine::GetCard(const LuaCardDraw& draw) { return callback_integer_run(*this, {"GetCard", MC_GET_CARD}, draw.card, draw.rng, draw.card, draw.isPlaying, draw.isRunes, draw.isOnlyRunes); } // 00865c80 Runs MC_GET_PILL_COLOR for a pill drawn from seed. The color a mod chose, 0 to keep the drawn one. // The original's first argument is an unused 9, and Lua gets only the seed, not the drawn color. int LuaEngine::GetPillColor(uint32_t seed) { return callback_integer_run(*this, {"GetPill", MC_GET_PILL_COLOR}, 0, seed); } // 00865ad0 Runs MC_GET_PILL_EFFECT for the effect a pill color got. The effect a mod chose, -1 to keep it. int LuaEngine::GetPillEffect(int pillEffect, int pillColor) { CallbackRun run = {"GetPillEffect", MC_GET_PILL_EFFECT}; return callback_integer_run(*this, run, PILL_EFFECT_UNCHANGED, pillEffect, pillColor); } // 008658c0 Runs MC_GET_TRINKET for a trinket the pool drew, with a copy of the pool's RNG. The trinket a mod chose, 0 // to keep the drawn one. int LuaEngine::GetTrinket(int trinket, const RNG& rng) { return callback_integer_run(*this, {"GetTrinket", MC_GET_TRINKET}, 0, trinket, rng); } // 00864c30 Runs MC_INPUT_ACTION for a boolean input hook, filtered by the hook. What a mod answered, nothing when no // mod did. std::optional LuaEngine::InputAction(Entity* entity, int hook, int action) { CallbackRun run = {"PreActionHookB", MC_INPUT_ACTION, hook}; if (!callback_run(*this, run, entity, hook, action)) return std::nullopt; std::optional value; if (!lua_isnil(state, -1)) value = lua_toboolean(state, -1); lua_pop(state, 1); return value; } // 00864d80 Runs MC_INPUT_ACTION for the action value hook. The value a mod answered, nothing when no mod did. std::optional LuaEngine::InputActionValue(Entity* entity, int action) { CallbackRun run = {"PreActionHookF", MC_INPUT_ACTION, INPUT_HOOK_VALUE}; if (!callback_run(*this, run, entity, INPUT_HOOK_VALUE, action)) return std::nullopt; std::optional value; if (!lua_isnil(state, -1)) value = (float)luaL_checknumber(state, -1); lua_pop(state, 1); return value; } // 00864ae0 Runs MC_POST_CURSE_EVAL for the curses a floor got. The curses a mod chose, or those. int LuaEngine::PostCurseEval(int curses) { return callback_integer_run(*this, {"PostCurseEval", MC_POST_CURSE_EVAL}, curses, curses); } // 00865f10 Runs MC_POST_GET_COLLECTIBLE for the collectible a pool gave. The collectible a mod chose, 0 to keep it. int LuaEngine::PostGetCollectible(const LuaCollectibleDraw& draw) { CallbackRun run = {"PostGetCollectible", MC_POST_GET_COLLECTIBLE}; return callback_integer_run(*this, run, 0, draw.collectible, draw.poolType, draw.isDecrease, draw.seed); } // 00865dc0 Runs MC_PRE_GET_COLLECTIBLE before a pool draws. The collectible a mod chose, 0 to draw as usual. int LuaEngine::PreGetCollectible(const LuaCollectibleDraw& draw) { CallbackRun run = {"PreGetCollectible", MC_PRE_GET_COLLECTIBLE}; return callback_integer_run(*this, run, 0, draw.poolType, draw.isDecrease, draw.seed); } // 00864560 Runs MC_ENTITY_TAKE_DMG for a hit, filtered by the entity's type. Whether the hit lands, false only when a // mod returned false. bool LuaEngine::EntityTakeDamage(Entity* entity, float damage, uint64_t damageFlags, const EntityRef& source, int countdown) { CallbackRun run = {"PreEntityTakeDamage", MC_ENTITY_TAKE_DMG, entity->type}; return callback_boolean_run(*this, run, true, entity, damage, damageFlags, &source, countdown); } // 008667d0 Runs MC_PRE_ENTITY_DEVOLVE, filtered by the entity's type. Whether a mod skips the devolve. bool LuaEngine::PreEntityDevolve(Entity* entity) { return callback_boolean_run(*this, {"PreEntityDevolve", MC_PRE_ENTITY_DEVOLVE, entity->type}, false, entity); } // 00866220 Runs MC_PRE_SPAWN_CLEAN_AWARD with copies of the award RNG and position. Whether a mod skips the award. // The original throws past its callers on a Lua error. This logs it and spawns the award. bool LuaEngine::PreSpawnCleanAward(const RNG& rng, const Vector& position) { return callback_boolean_run(*this, {"PreRoomRewardSpawn", MC_PRE_SPAWN_CLEAN_AWARD}, false, rng, position); } // 00863760 Runs MC_PRE_USE_ITEM for an active item, filtered by its type. Whether a mod skips the use. bool LuaEngine::PreUseItem(const LuaItemUse& use) { CallbackRun run = {"PreUseItem", MC_PRE_USE_ITEM, use.collectibleType}; return callback_boolean_run(*this, run, false, use.collectibleType, use.rng, use.player, use.useFlags, use.activeSlot, use.customVarData); } // 00860960 Runs MC_PRE_NPC_UPDATE, filtered by the NPC's type. Whether a mod skips the NPC's AI this frame. bool LuaEngine::PreNPCUpdate(Entity_NPC* npc) { CallbackRun run = {"PreNPCUpdate", MC_PRE_NPC_UPDATE, (int)npc->type}; if (!callback_run(*this, run, npc)) return false; bool isSkipped = lua_toboolean(state, -1); lua_pop(state, 1); return isSkipped; } // 008646e0 Runs MC_PRE_ENTITY_SPAWN for a spawn. A table result replaces its type, variant, subtype and seed, in that // order, with each element that is not nil. void LuaEngine::Callback_PreEntitySpawn(EntitySpawn& spawn) { if (!callback_run(*this, {"PreEntitySpawn", MC_PRE_ENTITY_SPAWN}, spawn.type, spawn.variant, spawn.subType, spawn.position, spawn.velocity, spawn.spawner, spawn.seed)) return; elements_pop(state, spawn.type, spawn.variant, spawn.subType, spawn.seed); } // 00866490 Runs MC_PRE_ROOM_ENTITY_SPAWN for a layout entry about to spawn, filtered by its subtype as the original // passes it. A table result replaces its type, variant and subtype, in that order, with each element that is not nil. // Whether any was replaced. bool LuaEngine::PreRoomEntitySpawn(RoomEntry& entry, int gridIndex, uint32_t seed) { CallbackRun run = {"PreRoomEntitySpawn", MC_PRE_ROOM_ENTITY_SPAWN, entry.subtype}; if (!callback_run(*this, run, (int)entry.type, (int)entry.variant, (int)entry.subtype, gridIndex, seed)) return false; return elements_pop(state, entry.type, entry.variant, entry.subtype); } // 00863340 Runs MC_POST_PICKUP_SELECTION for the kind a pickup was given. A table result replaces its variant and // subtype, in that order, with each element that is not nil. void LuaEngine::PostPickupSelection(Entity_Pickup* pickup, int& variant, int& subType) { CallbackRun run = {"PostPickupSelection", MC_POST_PICKUP_SELECTION}; if (callback_run(*this, run, pickup, variant, subType)) elements_pop(state, variant, subType); } // 008638d0 Runs MC_USE_ITEM for an active item, filtered by its type. A table result sets Discharge, Remove and // ShowAnim, any other result ShowAnim alone. Whether to show the use animation, false without a result. bool LuaEngine::UseItem(LuaItemUse& use) { CallbackRun run = {"PostUseItem", MC_USE_ITEM, use.collectibleType}; if (!callback_run(*this, run, use.collectibleType, use.rng, use.player, use.useFlags, use.activeSlot, use.customVarData)) return false; bool isShowAnimation = false; if (!lua_istable(state, -1)) isShowAnimation = lua_toboolean(state, -1); else { field_read(state, "Discharge", use.isDischarge); field_read(state, "Remove", use.isRemove); field_read(state, "ShowAnim", isShowAnimation); } lua_pop(state, 1); return isShowAnimation; } // 00863e90 Runs MC_EVALUATE_CACHE for a player's stat, filtered by the cache flag. void LuaEngine::EvaluateItems(Entity_Player* player, int cacheFlag) { callback_notify(*this, {"PostEvaluateItems", MC_EVALUATE_CACHE, cacheFlag}, player, cacheFlag); } // 008635a0 Runs MC_FAMILIAR_INIT, filtered by the familiar's variant. void LuaEngine::FamiliarInit(Entity_Familiar* familiar) { callback_notify(*this, {"PostFamiliarInit", MC_FAMILIAR_INIT, familiar->variant}, familiar); } // 00860f00 Runs MC_FAMILIAR_UPDATE, filtered by the familiar's variant. void LuaEngine::FamiliarUpdate(Entity_Familiar* familiar) { callback_notify(*this, {"PostFamiliarUpdate", MC_FAMILIAR_UPDATE, familiar->variant}, familiar); } // 00860fe0 Runs MC_POST_FAMILIAR_RENDER with the render offset, filtered by the familiar's variant. void LuaEngine::PostFamiliarRender(Entity_Familiar* familiar, const Vector& offset) { callback_notify(*this, {"PostFamiliarRender", MC_POST_FAMILIAR_RENDER, familiar->variant}, familiar, offset); } // 00861ea0 Runs MC_POST_BOMB_INIT, filtered by the bomb's variant. void LuaEngine::PostBombInit(Entity_Bomb* bomb) { callback_notify(*this, {"PostBombInit", MC_POST_BOMB_INIT, bomb->variant}, bomb); } // 00861f80 Runs MC_POST_BOMB_UPDATE, filtered by the bomb's variant. void LuaEngine::PostBombUpdate(Entity_Bomb* bomb) { callback_notify(*this, {"PostBombUpdate", MC_POST_BOMB_UPDATE, bomb->variant}, bomb); } // 00862060 Runs MC_POST_BOMB_RENDER with the render offset, filtered by the bomb's variant. void LuaEngine::PostBombRender(Entity_Bomb* bomb, const Vector& offset) { callback_notify(*this, {"PostBombRender", MC_POST_BOMB_RENDER, bomb->variant}, bomb, offset); } // 00861330 Runs MC_POST_EFFECT_INIT, filtered by the effect's variant. void LuaEngine::PostEffectInit(Entity_Effect* effect) { callback_notify(*this, {"PostEffectInit", MC_POST_EFFECT_INIT, (int)effect->variant}, effect); } // 008614f0 Runs MC_POST_EFFECT_RENDER with the render offset, filtered by the effect's variant. void LuaEngine::PostEffectRender(Entity_Effect* effect, const Vector& offset) { callback_notify(*this, {"PostEffectRender", MC_POST_EFFECT_RENDER, (int)effect->variant}, effect, offset); } // 00861410 Runs MC_POST_EFFECT_UPDATE, filtered by the effect's variant. void LuaEngine::PostEffectUpdate(Entity_Effect* effect) { callback_notify(*this, {"PostEffectUpdate", MC_POST_EFFECT_UPDATE, (int)effect->variant}, effect); } // 00866140 Runs MC_POST_ENTITY_KILL, filtered by the entity's type. void LuaEngine::PostEntityKill(Entity* entity) { callback_notify(*this, {"PostEntityKill", MC_POST_ENTITY_KILL, (int)entity->type}, entity); } // Runs MC_POST_ENTITY_REMOVE for Entity::ReleaseLuaRef, filtered by the entity's type. void LuaEngine::PostEntityRemove(Entity* entity) { callback_notify(*this, {"PostEntityRemove", MC_POST_ENTITY_REMOVE, (int)entity->type}, entity); } // 00863f70 Runs MC_POST_FIRE_TEAR for a tear a player fired. void LuaEngine::PostFireTear(Entity_Tear* tear) { callback_notify(*this, {"PostFireTear", MC_POST_FIRE_TEAR}, tear); } // 00864fc0 Runs MC_POST_GAME_END with whether the run ended in a game over. void LuaEngine::PostGameEnd(bool isGameOver) { callback_notify(*this, {"PostGameEnd", MC_POST_GAME_END}, isGameOver); } // 00864ee0 Runs MC_POST_GAME_STARTED with whether the run continues a saved one. void LuaEngine::PostGameStart(bool isContinued) { callback_notify(*this, {"PostGameStart", MC_POST_GAME_STARTED}, isContinued); } // 00861890 Runs MC_POST_KNIFE_INIT, filtered by the knife's subtype. void LuaEngine::PostKnifeInit(Entity_Knife* knife) { callback_notify(*this, {"PostKnifeInit", MC_POST_KNIFE_INIT, (int)knife->subtype}, knife); } // 00861970 Runs MC_POST_KNIFE_UPDATE, filtered by the knife's subtype. void LuaEngine::PostKnifeUpdate(Entity_Knife* knife) { callback_notify(*this, {"PostKnifeUpdate", MC_POST_KNIFE_UPDATE, knife->subtype}, knife); } // 00861a50 Runs MC_POST_KNIFE_RENDER with the render offset, filtered by the knife's subtype. void LuaEngine::PostKnifeRender(Entity_Knife* knife, const Vector& offset) { callback_notify(*this, {"PostKnifeRender", MC_POST_KNIFE_RENDER, knife->subtype}, knife, offset); } // 008615e0 Runs MC_POST_LASER_INIT, filtered by the laser's variant. void LuaEngine::PostLaserInit(Entity_Laser* laser) { callback_notify(*this, {"PostLaserInit", MC_POST_LASER_INIT, laser->variant}, laser); } // 008616c0 Runs MC_POST_LASER_UPDATE, filtered by the laser's variant. void LuaEngine::PostLaserUpdate(Entity_Laser* laser) { callback_notify(*this, {"PostLaserUpdate", MC_POST_LASER_UPDATE, laser->variant}, laser); } // 008617a0 Runs MC_POST_LASER_RENDER with the render offset, filtered by the laser's variant. void LuaEngine::PostLaserRender(Entity_Laser* laser, const Vector& offset) { callback_notify(*this, {"PostLaserRender", MC_POST_LASER_RENDER, laser->variant}, laser, offset); } // 00865260 Runs MC_POST_NEW_LEVEL once a floor is generated and its first room entered. void LuaEngine::PostNewLevel() { callback_notify(*this, {"PostLevelLoad", MC_POST_NEW_LEVEL}); } // 00865180 Runs MC_POST_NEW_ROOM once a room is loaded. void LuaEngine::PostNewRoom() { callback_notify(*this, {"PostRoomLoad", MC_POST_NEW_ROOM}); } // 00860c90 Runs MC_POST_NPC_DEATH, filtered by the NPC's type. void LuaEngine::PostNPCDeath(Entity_NPC* npc) { callback_notify(*this, {"PostNPCDeath", MC_POST_NPC_DEATH, (int)npc->type}, npc); } // 00860880 Runs MC_POST_NPC_INIT, filtered by the NPC's type. void LuaEngine::PostNPCInit(Entity_NPC* npc) { callback_notify(*this, {"PostNPCInit", MC_POST_NPC_INIT, (int)npc->type}, npc); } // 00860ba0 Runs MC_POST_NPC_RENDER with the render offset, filtered by the NPC's type. void LuaEngine::PostNPCRender(Entity_NPC* npc, const Vector& offset) { callback_notify(*this, {"PostNPCRender", MC_POST_NPC_RENDER, (int)npc->type}, npc, offset); } // 00860ac0 Runs MC_NPC_UPDATE after an NPC's AI, filtered by the NPC's type. void LuaEngine::PostNPCUpdate(Entity_NPC* npc) { callback_notify(*this, {"PostNPCUpdate", MC_NPC_UPDATE, (int)npc->type}, npc); } // 00862f00 Runs MC_POST_PICKUP_INIT, filtered by the pickup's variant. void LuaEngine::PostPickupInit(Entity_Pickup* pickup) { callback_notify(*this, {"PostPickupInit", MC_POST_PICKUP_INIT, (int)pickup->variant}, pickup); } // 008630c0 Runs MC_POST_PICKUP_RENDER with the render offset, filtered by the pickup's variant. void LuaEngine::PostPickupRender(Entity_Pickup* pickup, const Vector& offset) { callback_notify(*this, {"PostPickupRender", MC_POST_PICKUP_RENDER, (int)pickup->variant}, pickup, offset); } // 00862fe0 Runs MC_POST_PICKUP_UPDATE, filtered by the pickup's variant. void LuaEngine::PostPickupUpdate(Entity_Pickup* pickup) { callback_notify(*this, {"PostPickupUpdate", MC_POST_PICKUP_UPDATE, (int)pickup->variant}, pickup); } // 00864050 Runs MC_POST_PLAYER_INIT, filtered by the player's variant. void LuaEngine::PostPlayerInit(Entity_Player* player) { callback_notify(*this, {"PostPlayerInit", MC_POST_PLAYER_INIT, (int)player->variant}, player); } // 00863be0 Runs MC_POST_PEFFECT_UPDATE, filtered by the player's character. void LuaEngine::PostPEffectUpdate(Entity_Player* player) { callback_notify(*this, {"PostPlayerEffectUpdate", MC_POST_PEFFECT_UPDATE, player->playerType}, player); } // 00864130 Runs MC_POST_PLAYER_UPDATE, filtered by the player's variant. void LuaEngine::PostPlayerUpdate(Entity_Player* player) { callback_notify(*this, {"PostPlayerUpdate", MC_POST_PLAYER_UPDATE, player->variant}, player); } // 00864210 Runs MC_POST_PLAYER_RENDER with the render offset, filtered by the player's variant. void LuaEngine::PostPlayerRender(Entity_Player* player, const Vector& offset) { callback_notify(*this, {"PostPlayerRender", MC_POST_PLAYER_RENDER, player->variant}, player, offset); } // 008624b0 Runs MC_POST_PROJECTILE_INIT, filtered by the projectile's variant. void LuaEngine::PostProjectileInit(Entity_Projectile* projectile) { callback_notify(*this, {"PostProjectileInit", MC_POST_PROJECTILE_INIT, projectile->variant}, projectile); } // 00862590 Runs MC_POST_PROJECTILE_UPDATE, filtered by the projectile's variant. void LuaEngine::PostProjectileUpdate(Entity_Projectile* projectile) { callback_notify(*this, {"PostProjectileUpdate", MC_POST_PROJECTILE_UPDATE, projectile->variant}, projectile); } // 00862670 Runs MC_POST_PROJECTILE_RENDER with the render offset, filtered by the projectile's variant. void LuaEngine::PostProjectileRender(Entity_Projectile* projectile, const Vector& offset) { callback_notify(*this, {"PostProjectileRender", MC_POST_PROJECTILE_RENDER, projectile->variant}, projectile, offset); } // 00863680 Runs MC_POST_RENDER after the game renders. void LuaEngine::PostRender() { callback_notify(*this, {"PostRender", MC_POST_RENDER}); } // 008629c0 Runs MC_POST_TEAR_INIT, filtered by the tear's variant. void LuaEngine::PostTearInit(Entity_Tear* tear) { callback_notify(*this, {"PostTearInit", MC_POST_TEAR_INIT, (int)tear->variant}, tear); } // 00862b80 Runs MC_POST_TEAR_RENDER with the render offset, filtered by the tear's variant. void LuaEngine::PostTearRender(Entity_Tear* tear, const Vector& offset) { callback_notify(*this, {"PostTearRender", MC_POST_TEAR_RENDER, (int)tear->variant}, tear, offset); } // 00862aa0 Runs MC_POST_TEAR_UPDATE, filtered by the tear's variant. void LuaEngine::PostTearUpdate(Entity_Tear* tear) { callback_notify(*this, {"PostTearUpdate", MC_POST_TEAR_UPDATE, (int)tear->variant}, tear); } // 008607a0 Runs MC_POST_UPDATE after the game updates. void LuaEngine::PostUpdate() { callback_notify(*this, {"PostUpdate", MC_POST_UPDATE}); } // 008650a0 Runs MC_PRE_GAME_EXIT with whether the run is saved (its error handler 0086512e). void LuaEngine::PreGameExit(bool isSaving) { callback_notify(*this, {"PreGameExit", MC_PRE_GAME_EXIT}, isSaving); } // 00863cc0 Runs MC_USE_CARD for a card a player used, filtered by the card. void LuaEngine::UseCard(int card, Entity_Player* player, unsigned int useFlags) { callback_notify(*this, {"PostUseCard", MC_USE_CARD, card}, card, player, useFlags); } // 00863da0 Runs MC_USE_PILL for a pill effect, filtered by it. void LuaEngine::UsePill(int pillEffect, Entity_Player* player, unsigned int useFlags) { callback_notify(*this, {"PostUsePillEffect", MC_USE_PILL, pillEffect}, pillEffect, player, useFlags); }