diff --git a/analysis/repentogon_coverage.tsv b/analysis/repentogon_coverage.tsv index 03d872d..ae3bc5b 100644 --- a/analysis/repentogon_coverage.tsv +++ b/analysis/repentogon_coverage.tsv @@ -2110,401 +2110,401 @@ constructor SourceQuad SourceQuad repentogon/LuaInterfaces/LuaRender.cpp:3213 r constructor Sprite Sprite repentogon/resources/scripts/main_ex.lua:2168 Sprite.md render and sprites done defined in Lua constructor Vector Vector repentogon/LuaInterfaces/LuaVector.cpp:152 misc review constructor WeightedOutcomePicker WeightedOutcomePicker repentogon/LuaInterfaces/LuaWeightedOutcomePicker.cpp:108 WeightedOutcomePicker.md items and pools todo -callback ModCallbacks MC_BOMB_GRID_COLLISION repentogon/resources/scripts/enums_ex.lua:170 enums/ModCallbacks.md tear and weapons todo id 1178 -callback ModCallbacks MC_CAN_SELECT_CHARACTER repentogon/resources/scripts/enums_ex.lua:291 enums/ModCallbacks.md misc todo id 1328 -callback ModCallbacks MC_COMPLETION_MARK_GET repentogon/resources/scripts/enums_ex.lua:49 enums/ModCallbacks.md persistent data and saves todo id 1047 +callback ModCallbacks MC_BOMB_GRID_COLLISION repentogon/resources/scripts/enums_ex.lua:170 enums/ModCallbacks.md tear and weapons done id 1178 +callback ModCallbacks MC_CAN_SELECT_CHARACTER repentogon/resources/scripts/enums_ex.lua:291 enums/ModCallbacks.md misc done id 1328 +callback ModCallbacks MC_COMPLETION_MARK_GET repentogon/resources/scripts/enums_ex.lua:49 enums/ModCallbacks.md persistent data and saves done id 1047 callback ModCallbacks MC_CONSOLE_AUTOCOMPLETE repentogon/resources/scripts/enums_ex.lua:122 enums/ModCallbacks.md console and debug todo id 1120 callback ModCallbacks MC_ENTITY_RESTORE repentogon/resources/scripts/enums_ex.lua:289 entities todo id 1315 -callback ModCallbacks MC_ENTITY_SAVE repentogon/resources/scripts/enums_ex.lua:288 persistent data and saves todo id 1314 +callback ModCallbacks MC_ENTITY_SAVE repentogon/resources/scripts/enums_ex.lua:288 persistent data and saves done id 1314 callback ModCallbacks MC_ENTITY_TAKE_DMG enums/ModCallbacks.md entities review id 11, vanilla callback REPENTOGON changes callback ModCallbacks MC_EVALUATE_CUSTOM_CACHE repentogon/resources/scripts/enums_ex.lua:199 enums/ModCallbacks.md items and pools todo id 1224 -callback ModCallbacks MC_EVALUATE_FAMILIAR_MULTIPLIER repentogon/resources/scripts/enums_ex.lua:200 enums/ModCallbacks.md familiar todo id 1225 +callback ModCallbacks MC_EVALUATE_FAMILIAR_MULTIPLIER repentogon/resources/scripts/enums_ex.lua:200 enums/ModCallbacks.md familiar done id 1225 callback ModCallbacks MC_EVALUATE_MULTI_SHOT_PARAMS repentogon/resources/scripts/enums_ex.lua:263 enums/ModCallbacks.md misc todo id 1289 -callback ModCallbacks MC_EVALUATE_STAT repentogon/resources/scripts/enums_ex.lua:201 enums/ModCallbacks.md hud and menus todo id 1226 -callback ModCallbacks MC_EVALUATE_TEAR_HIT_PARAMS repentogon/resources/scripts/enums_ex.lua:404 enums/ModCallbacks.md tear and weapons todo id 1490 -callback ModCallbacks MC_FAMILIAR_GRID_COLLISION repentogon/resources/scripts/enums_ex.lua:168 enums/ModCallbacks.md familiar todo id 1176 -callback ModCallbacks MC_GET_BOSS_THEMATIC_ITEM repentogon/resources/scripts/enums_ex.lua:407 enums/ModCallbacks.md npc todo id 1493 -callback ModCallbacks MC_GET_FOLLOWER_PRIORITY repentogon/resources/scripts/enums_ex.lua:65 enums/ModCallbacks.md misc todo id 1063 +callback ModCallbacks MC_EVALUATE_STAT repentogon/resources/scripts/enums_ex.lua:201 enums/ModCallbacks.md hud and menus done id 1226 +callback ModCallbacks MC_EVALUATE_TEAR_HIT_PARAMS repentogon/resources/scripts/enums_ex.lua:404 enums/ModCallbacks.md tear and weapons done id 1490 +callback ModCallbacks MC_FAMILIAR_GRID_COLLISION repentogon/resources/scripts/enums_ex.lua:168 enums/ModCallbacks.md familiar done id 1176 +callback ModCallbacks MC_GET_BOSS_THEMATIC_ITEM repentogon/resources/scripts/enums_ex.lua:407 enums/ModCallbacks.md npc done id 1493 +callback ModCallbacks MC_GET_FOLLOWER_PRIORITY repentogon/resources/scripts/enums_ex.lua:65 enums/ModCallbacks.md misc done id 1063 callback ModCallbacks MC_GET_PILL_EFFECT enums/ModCallbacks.md items and pools review id 65, vanilla callback REPENTOGON changes -callback ModCallbacks MC_GET_SHOP_ITEM_PRICE repentogon/resources/scripts/enums_ex.lua:68 enums/ModCallbacks.md items and pools todo id 1066 -callback ModCallbacks MC_GET_STATUS_EFFECT_TARGET repentogon/resources/scripts/enums_ex.lua:399 enums/ModCallbacks.md hud and menus todo id 1485 -callback ModCallbacks MC_GRID_HURT_DAMAGE repentogon/resources/scripts/enums_ex.lua:13 enums/ModCallbacks.md level and room todo id 1012 -callback ModCallbacks MC_HUD_POST_UPDATE repentogon/resources/scripts/enums_ex.lua:22 hud and menus todo id 1021 -callback ModCallbacks MC_HUD_RENDER repentogon/resources/scripts/enums_ex.lua:24 enums/ModCallbacks.md hud and menus todo id 1022 -callback ModCallbacks MC_HUD_UPDATE repentogon/resources/scripts/enums_ex.lua:21 enums/ModCallbacks.md hud and menus todo id 1020 -callback ModCallbacks MC_IS_PERSISTENT_ROOM_ENTITY repentogon/resources/scripts/enums_ex.lua:237 enums/ModCallbacks.md persistent data and saves todo id 1263 -callback ModCallbacks MC_MAIN_MENU_RENDER repentogon/resources/scripts/enums_ex.lua:25 enums/ModCallbacks.md hud and menus todo id 1023 -callback ModCallbacks MC_MENU_INPUT_ACTION repentogon/resources/scripts/enums_ex.lua:380 enums/ModCallbacks.md hud and menus todo id 1464 -callback ModCallbacks MC_NPC_GRID_COLLISION repentogon/resources/scripts/enums_ex.lua:176 enums/ModCallbacks.md npc todo id 1184 -callback ModCallbacks MC_NPC_PICK_TARGET repentogon/resources/scripts/enums_ex.lua:197 enums/ModCallbacks.md npc todo id 1222 -callback ModCallbacks MC_PICKUP_GET_COIN_VALUE repentogon/resources/scripts/enums_ex.lua:224 enums/ModCallbacks.md pickup todo id 1250 -callback ModCallbacks MC_PICKUP_GRID_COLLISION repentogon/resources/scripts/enums_ex.lua:172 enums/ModCallbacks.md pickup todo id 1180 -callback ModCallbacks MC_PLAYER_GET_ACTIVE_MAX_CHARGE repentogon/resources/scripts/enums_ex.lua:74 enums/ModCallbacks.md player todo id 1072 -callback ModCallbacks MC_PLAYER_GET_ACTIVE_MIN_USABLE_CHARGE repentogon/resources/scripts/enums_ex.lua:75 enums/ModCallbacks.md player todo id 1073 -callback ModCallbacks MC_PLAYER_GET_HEALTH_TYPE repentogon/resources/scripts/enums_ex.lua:69 enums/ModCallbacks.md player todo id 1067 -callback ModCallbacks MC_PLAYER_GET_HEART_LIMIT repentogon/resources/scripts/enums_ex.lua:76 enums/ModCallbacks.md player todo id 1074 -callback ModCallbacks MC_PLAYER_GRID_COLLISION repentogon/resources/scripts/enums_ex.lua:164 enums/ModCallbacks.md player todo id 1172 -callback ModCallbacks MC_PLAYER_HEALTH_TYPE_CHANGE repentogon/resources/scripts/enums_ex.lua:130 enums/ModCallbacks.md player todo id 1128 -callback ModCallbacks MC_PLAYER_INIT_POST_LEVEL_INIT_STATS repentogon/resources/scripts/enums_ex.lua:44 enums/ModCallbacks.md player todo id 1042 -callback ModCallbacks MC_PLAYER_INIT_PRE_LEVEL_INIT_STATS repentogon/resources/scripts/enums_ex.lua:129 enums/ModCallbacks.md player todo id 1127 -callback ModCallbacks MC_POST_ACHIEVEMENT_UNLOCK repentogon/resources/scripts/enums_ex.lua:390 enums/ModCallbacks.md persistent data and saves todo id 1476 -callback ModCallbacks MC_POST_ADD_COLLECTIBLE repentogon/resources/scripts/enums_ex.lua:5 enums/ModCallbacks.md items and pools todo id 1005 +callback ModCallbacks MC_GET_SHOP_ITEM_PRICE repentogon/resources/scripts/enums_ex.lua:68 enums/ModCallbacks.md items and pools done id 1066 +callback ModCallbacks MC_GET_STATUS_EFFECT_TARGET repentogon/resources/scripts/enums_ex.lua:399 enums/ModCallbacks.md hud and menus done id 1485 +callback ModCallbacks MC_GRID_HURT_DAMAGE repentogon/resources/scripts/enums_ex.lua:13 enums/ModCallbacks.md level and room done id 1012 +callback ModCallbacks MC_HUD_POST_UPDATE repentogon/resources/scripts/enums_ex.lua:22 hud and menus done id 1021 +callback ModCallbacks MC_HUD_RENDER repentogon/resources/scripts/enums_ex.lua:24 enums/ModCallbacks.md hud and menus done id 1022 +callback ModCallbacks MC_HUD_UPDATE repentogon/resources/scripts/enums_ex.lua:21 enums/ModCallbacks.md hud and menus done id 1020 +callback ModCallbacks MC_IS_PERSISTENT_ROOM_ENTITY repentogon/resources/scripts/enums_ex.lua:237 enums/ModCallbacks.md persistent data and saves done id 1263 +callback ModCallbacks MC_MAIN_MENU_RENDER repentogon/resources/scripts/enums_ex.lua:25 enums/ModCallbacks.md hud and menus done id 1023 +callback ModCallbacks MC_MENU_INPUT_ACTION repentogon/resources/scripts/enums_ex.lua:380 enums/ModCallbacks.md hud and menus done id 1464 +callback ModCallbacks MC_NPC_GRID_COLLISION repentogon/resources/scripts/enums_ex.lua:176 enums/ModCallbacks.md npc done id 1184 +callback ModCallbacks MC_NPC_PICK_TARGET repentogon/resources/scripts/enums_ex.lua:197 enums/ModCallbacks.md npc done id 1222 +callback ModCallbacks MC_PICKUP_GET_COIN_VALUE repentogon/resources/scripts/enums_ex.lua:224 enums/ModCallbacks.md pickup done id 1250 +callback ModCallbacks MC_PICKUP_GRID_COLLISION repentogon/resources/scripts/enums_ex.lua:172 enums/ModCallbacks.md pickup done id 1180 +callback ModCallbacks MC_PLAYER_GET_ACTIVE_MAX_CHARGE repentogon/resources/scripts/enums_ex.lua:74 enums/ModCallbacks.md player done id 1072 +callback ModCallbacks MC_PLAYER_GET_ACTIVE_MIN_USABLE_CHARGE repentogon/resources/scripts/enums_ex.lua:75 enums/ModCallbacks.md player done id 1073 +callback ModCallbacks MC_PLAYER_GET_HEALTH_TYPE repentogon/resources/scripts/enums_ex.lua:69 enums/ModCallbacks.md player done id 1067 +callback ModCallbacks MC_PLAYER_GET_HEART_LIMIT repentogon/resources/scripts/enums_ex.lua:76 enums/ModCallbacks.md player done id 1074 +callback ModCallbacks MC_PLAYER_GRID_COLLISION repentogon/resources/scripts/enums_ex.lua:164 enums/ModCallbacks.md player done id 1172 +callback ModCallbacks MC_PLAYER_HEALTH_TYPE_CHANGE repentogon/resources/scripts/enums_ex.lua:130 enums/ModCallbacks.md player done id 1128 +callback ModCallbacks MC_PLAYER_INIT_POST_LEVEL_INIT_STATS repentogon/resources/scripts/enums_ex.lua:44 enums/ModCallbacks.md player done id 1042 +callback ModCallbacks MC_PLAYER_INIT_PRE_LEVEL_INIT_STATS repentogon/resources/scripts/enums_ex.lua:129 enums/ModCallbacks.md player done id 1127 +callback ModCallbacks MC_POST_ACHIEVEMENT_UNLOCK repentogon/resources/scripts/enums_ex.lua:390 enums/ModCallbacks.md persistent data and saves done id 1476 +callback ModCallbacks MC_POST_ADD_COLLECTIBLE repentogon/resources/scripts/enums_ex.lua:5 enums/ModCallbacks.md items and pools done id 1005 callback ModCallbacks MC_POST_ADD_INNATE_COLLECTIBLE repentogon/resources/scripts/enums_ex.lua:56 enums/ModCallbacks.md items and pools todo id 1054 callback ModCallbacks MC_POST_ADD_INNATE_TRINKET repentogon/resources/scripts/enums_ex.lua:57 enums/ModCallbacks.md items and pools todo id 1055 -callback ModCallbacks MC_POST_ADD_TO_BAG_OF_CRAFTING repentogon/resources/scripts/enums_ex.lua:17 enums/ModCallbacks.md items and pools todo id 1016 -callback ModCallbacks MC_POST_APPLY_TEARFLAG_EFFECTS repentogon/resources/scripts/enums_ex.lua:252 enums/ModCallbacks.md tear and weapons todo id 1278 +callback ModCallbacks MC_POST_ADD_TO_BAG_OF_CRAFTING repentogon/resources/scripts/enums_ex.lua:17 enums/ModCallbacks.md items and pools done id 1016 +callback ModCallbacks MC_POST_APPLY_TEARFLAG_EFFECTS repentogon/resources/scripts/enums_ex.lua:252 enums/ModCallbacks.md tear and weapons done id 1278 callback ModCallbacks MC_POST_BACKDROP_CHANGE repentogon/resources/scripts/enums_ex.lua:144 enums/ModCallbacks.md level and room todo id 1142 -callback ModCallbacks MC_POST_BACKDROP_PRE_RENDER_WALLS repentogon/resources/scripts/enums_ex.lua:111 enums/ModCallbacks.md render and sprites todo id 1109 -callback ModCallbacks MC_POST_BACKWARDS_ROOM_RESTORE repentogon/resources/scripts/enums_ex.lua:282 enums/ModCallbacks.md level and room todo id 1308 -callback ModCallbacks MC_POST_BACKWARDS_ROOM_SAVE repentogon/resources/scripts/enums_ex.lua:281 enums/ModCallbacks.md persistent data and saves todo id 1307 -callback ModCallbacks MC_POST_BOMB_COLLISION repentogon/resources/scripts/enums_ex.lua:211 enums/ModCallbacks.md tear and weapons todo id 1237 -callback ModCallbacks MC_POST_BOMB_DAMAGE repentogon/resources/scripts/enums_ex.lua:249 enums/ModCallbacks.md tear and weapons todo id 1275 -callback ModCallbacks MC_POST_BOMB_TEARFLAG_EFFECTS repentogon/resources/scripts/enums_ex.lua:250 enums/ModCallbacks.md tear and weapons todo id 1276 -callback ModCallbacks MC_POST_BOSS_INTRO_SHOW repentogon/resources/scripts/enums_ex.lua:244 enums/ModCallbacks.md npc todo id 1270 -callback ModCallbacks MC_POST_BRIMSTONE_SNEEZE repentogon/resources/scripts/enums_ex.lua:39 enums/ModCallbacks.md tear and weapons todo id 1037 -callback ModCallbacks MC_POST_CHALLENGE_DONE repentogon/resources/scripts/enums_ex.lua:386 enums/ModCallbacks.md game todo id 1472 -callback ModCallbacks MC_POST_COMPLETION_EVENT repentogon/resources/scripts/enums_ex.lua:54 enums/ModCallbacks.md persistent data and saves todo id 1052 -callback ModCallbacks MC_POST_COMPLETION_MARKS_RENDER repentogon/resources/scripts/enums_ex.lua:192 enums/ModCallbacks.md persistent data and saves todo id 1217 -callback ModCallbacks MC_POST_COMPLETION_MARK_GET repentogon/resources/scripts/enums_ex.lua:50 enums/ModCallbacks.md persistent data and saves todo id 1048 -callback ModCallbacks MC_POST_DEVIL_CALCULATE repentogon/resources/scripts/enums_ex.lua:135 enums/ModCallbacks.md items and pools todo id 1133 -callback ModCallbacks MC_POST_DISCHARGE_ACTIVE_ITEM repentogon/resources/scripts/enums_ex.lua:142 enums/ModCallbacks.md items and pools todo id 1140 +callback ModCallbacks MC_POST_BACKDROP_PRE_RENDER_WALLS repentogon/resources/scripts/enums_ex.lua:111 enums/ModCallbacks.md render and sprites done id 1109 +callback ModCallbacks MC_POST_BACKWARDS_ROOM_RESTORE repentogon/resources/scripts/enums_ex.lua:282 enums/ModCallbacks.md level and room done id 1308 +callback ModCallbacks MC_POST_BACKWARDS_ROOM_SAVE repentogon/resources/scripts/enums_ex.lua:281 enums/ModCallbacks.md persistent data and saves done id 1307 +callback ModCallbacks MC_POST_BOMB_COLLISION repentogon/resources/scripts/enums_ex.lua:211 enums/ModCallbacks.md tear and weapons done id 1237 +callback ModCallbacks MC_POST_BOMB_DAMAGE repentogon/resources/scripts/enums_ex.lua:249 enums/ModCallbacks.md tear and weapons done id 1275 +callback ModCallbacks MC_POST_BOMB_TEARFLAG_EFFECTS repentogon/resources/scripts/enums_ex.lua:250 enums/ModCallbacks.md tear and weapons done id 1276 +callback ModCallbacks MC_POST_BOSS_INTRO_SHOW repentogon/resources/scripts/enums_ex.lua:244 enums/ModCallbacks.md npc done id 1270 +callback ModCallbacks MC_POST_BRIMSTONE_SNEEZE repentogon/resources/scripts/enums_ex.lua:39 enums/ModCallbacks.md tear and weapons done id 1037 +callback ModCallbacks MC_POST_CHALLENGE_DONE repentogon/resources/scripts/enums_ex.lua:386 enums/ModCallbacks.md game done id 1472 +callback ModCallbacks MC_POST_COMPLETION_EVENT repentogon/resources/scripts/enums_ex.lua:54 enums/ModCallbacks.md persistent data and saves done id 1052 +callback ModCallbacks MC_POST_COMPLETION_MARKS_RENDER repentogon/resources/scripts/enums_ex.lua:192 enums/ModCallbacks.md persistent data and saves done id 1217 +callback ModCallbacks MC_POST_COMPLETION_MARK_GET repentogon/resources/scripts/enums_ex.lua:50 enums/ModCallbacks.md persistent data and saves done id 1048 +callback ModCallbacks MC_POST_DEVIL_CALCULATE repentogon/resources/scripts/enums_ex.lua:135 enums/ModCallbacks.md items and pools done id 1133 +callback ModCallbacks MC_POST_DISCHARGE_ACTIVE_ITEM repentogon/resources/scripts/enums_ex.lua:142 enums/ModCallbacks.md items and pools done id 1140 callback ModCallbacks MC_POST_ENTITY_KILL enums/ModCallbacks.md entities review id 68, vanilla callback REPENTOGON changes -callback ModCallbacks MC_POST_ENTITY_SET_COLOR repentogon/resources/scripts/enums_ex.lua:401 enums/ModCallbacks.md render and sprites todo id 1487 -callback ModCallbacks MC_POST_ENTITY_TAKE_DMG repentogon/resources/scripts/enums_ex.lua:7 enums/ModCallbacks.md entities todo id 1006 -callback ModCallbacks MC_POST_ENTITY_THROW repentogon/resources/scripts/enums_ex.lua:43 enums/ModCallbacks.md entities todo id 1041 -callback ModCallbacks MC_POST_FAMILIAR_COLLISION repentogon/resources/scripts/enums_ex.lua:209 enums/ModCallbacks.md familiar todo id 1235 -callback ModCallbacks MC_POST_FAMILIAR_FIRE_BRIMSTONE repentogon/resources/scripts/enums_ex.lua:235 enums/ModCallbacks.md familiar todo id 1261 -callback ModCallbacks MC_POST_FAMILIAR_FIRE_PROJECTILE repentogon/resources/scripts/enums_ex.lua:226 enums/ModCallbacks.md familiar todo id 1252 -callback ModCallbacks MC_POST_FAMILIAR_FIRE_TECH_LASER repentogon/resources/scripts/enums_ex.lua:236 enums/ModCallbacks.md familiar todo id 1262 -callback ModCallbacks MC_POST_FIRE_BOMB repentogon/resources/scripts/enums_ex.lua:227 enums/ModCallbacks.md tear and weapons todo id 1253 -callback ModCallbacks MC_POST_FIRE_BONE_CLUB repentogon/resources/scripts/enums_ex.lua:228 enums/ModCallbacks.md tear and weapons todo id 1254 -callback ModCallbacks MC_POST_FIRE_BRIMSTONE repentogon/resources/scripts/enums_ex.lua:229 enums/ModCallbacks.md tear and weapons todo id 1255 -callback ModCallbacks MC_POST_FIRE_BRIMSTONE_BALL repentogon/resources/scripts/enums_ex.lua:230 enums/ModCallbacks.md tear and weapons todo id 1256 -callback ModCallbacks MC_POST_FIRE_KNIFE repentogon/resources/scripts/enums_ex.lua:231 enums/ModCallbacks.md tear and weapons todo id 1257 +callback ModCallbacks MC_POST_ENTITY_SET_COLOR repentogon/resources/scripts/enums_ex.lua:401 enums/ModCallbacks.md render and sprites done id 1487 +callback ModCallbacks MC_POST_ENTITY_TAKE_DMG repentogon/resources/scripts/enums_ex.lua:7 enums/ModCallbacks.md entities done id 1006 +callback ModCallbacks MC_POST_ENTITY_THROW repentogon/resources/scripts/enums_ex.lua:43 enums/ModCallbacks.md entities done id 1041 +callback ModCallbacks MC_POST_FAMILIAR_COLLISION repentogon/resources/scripts/enums_ex.lua:209 enums/ModCallbacks.md familiar done id 1235 +callback ModCallbacks MC_POST_FAMILIAR_FIRE_BRIMSTONE repentogon/resources/scripts/enums_ex.lua:235 enums/ModCallbacks.md familiar done id 1261 +callback ModCallbacks MC_POST_FAMILIAR_FIRE_PROJECTILE repentogon/resources/scripts/enums_ex.lua:226 enums/ModCallbacks.md familiar done id 1252 +callback ModCallbacks MC_POST_FAMILIAR_FIRE_TECH_LASER repentogon/resources/scripts/enums_ex.lua:236 enums/ModCallbacks.md familiar done id 1262 +callback ModCallbacks MC_POST_FIRE_BOMB repentogon/resources/scripts/enums_ex.lua:227 enums/ModCallbacks.md tear and weapons done id 1253 +callback ModCallbacks MC_POST_FIRE_BONE_CLUB repentogon/resources/scripts/enums_ex.lua:228 enums/ModCallbacks.md tear and weapons done id 1254 +callback ModCallbacks MC_POST_FIRE_BRIMSTONE repentogon/resources/scripts/enums_ex.lua:229 enums/ModCallbacks.md tear and weapons done id 1255 +callback ModCallbacks MC_POST_FIRE_BRIMSTONE_BALL repentogon/resources/scripts/enums_ex.lua:230 enums/ModCallbacks.md tear and weapons done id 1256 +callback ModCallbacks MC_POST_FIRE_KNIFE repentogon/resources/scripts/enums_ex.lua:231 enums/ModCallbacks.md tear and weapons done id 1257 callback ModCallbacks MC_POST_FIRE_SPLIT_TEAR repentogon/resources/scripts/enums_ex.lua:27 enums/ModCallbacks.md tear and weapons todo id 1025 -callback ModCallbacks MC_POST_FIRE_SWORD repentogon/resources/scripts/enums_ex.lua:232 enums/ModCallbacks.md tear and weapons todo id 1258 -callback ModCallbacks MC_POST_FIRE_TECH_LASER repentogon/resources/scripts/enums_ex.lua:233 enums/ModCallbacks.md tear and weapons todo id 1259 -callback ModCallbacks MC_POST_FIRE_TECH_X_LASER repentogon/resources/scripts/enums_ex.lua:234 enums/ModCallbacks.md tear and weapons todo id 1260 -callback ModCallbacks MC_POST_FORCE_ADD_PILL_EFFECT repentogon/resources/scripts/enums_ex.lua:131 enums/ModCallbacks.md items and pools todo id 1129 -callback ModCallbacks MC_POST_GAME_STATE_RESTORE repentogon/resources/scripts/enums_ex.lua:286 hud and menus todo id 1312 -callback ModCallbacks MC_POST_GAME_STATE_SAVE repentogon/resources/scripts/enums_ex.lua:284 persistent data and saves todo id 1310 -callback ModCallbacks MC_POST_GLOWING_HOURGLASS_LOAD repentogon/resources/scripts/enums_ex.lua:275 enums/ModCallbacks.md misc todo id 1301 -callback ModCallbacks MC_POST_GLOWING_HOURGLASS_SAVE repentogon/resources/scripts/enums_ex.lua:274 enums/ModCallbacks.md persistent data and saves todo id 1300 -callback ModCallbacks MC_POST_GRID_ENTITY_DECORATION_RENDER repentogon/resources/scripts/enums_ex.lua:361 enums/ModCallbacks.md render and sprites todo id 1445 -callback ModCallbacks MC_POST_GRID_ENTITY_DECORATION_UPDATE repentogon/resources/scripts/enums_ex.lua:318 enums/ModCallbacks.md level and room todo id 1401 -callback ModCallbacks MC_POST_GRID_ENTITY_DOOR_RENDER repentogon/resources/scripts/enums_ex.lua:363 enums/ModCallbacks.md render and sprites todo id 1447 -callback ModCallbacks MC_POST_GRID_ENTITY_DOOR_UPDATE repentogon/resources/scripts/enums_ex.lua:320 enums/ModCallbacks.md level and room todo id 1403 -callback ModCallbacks MC_POST_GRID_ENTITY_FIRE_RENDER repentogon/resources/scripts/enums_ex.lua:365 enums/ModCallbacks.md tear and weapons todo id 1449 -callback ModCallbacks MC_POST_GRID_ENTITY_FIRE_UPDATE repentogon/resources/scripts/enums_ex.lua:322 enums/ModCallbacks.md tear and weapons todo id 1405 -callback ModCallbacks MC_POST_GRID_ENTITY_GRAVITY_UPDATE repentogon/resources/scripts/enums_ex.lua:324 enums/ModCallbacks.md level and room todo id 1407 -callback ModCallbacks MC_POST_GRID_ENTITY_LOCK_RENDER repentogon/resources/scripts/enums_ex.lua:367 enums/ModCallbacks.md render and sprites todo id 1451 -callback ModCallbacks MC_POST_GRID_ENTITY_LOCK_UPDATE repentogon/resources/scripts/enums_ex.lua:326 enums/ModCallbacks.md level and room todo id 1409 -callback ModCallbacks MC_POST_GRID_ENTITY_PIT_RENDER repentogon/resources/scripts/enums_ex.lua:371 enums/ModCallbacks.md render and sprites todo id 1455 -callback ModCallbacks MC_POST_GRID_ENTITY_PIT_UPDATE repentogon/resources/scripts/enums_ex.lua:328 enums/ModCallbacks.md level and room todo id 1411 -callback ModCallbacks MC_POST_GRID_ENTITY_POOP_RENDER repentogon/resources/scripts/enums_ex.lua:373 enums/ModCallbacks.md render and sprites todo id 1457 -callback ModCallbacks MC_POST_GRID_ENTITY_POOP_UPDATE repentogon/resources/scripts/enums_ex.lua:330 enums/ModCallbacks.md level and room todo id 1413 -callback ModCallbacks MC_POST_GRID_ENTITY_PRESSUREPLATE_RENDER repentogon/resources/scripts/enums_ex.lua:377 enums/ModCallbacks.md render and sprites todo id 1461 -callback ModCallbacks MC_POST_GRID_ENTITY_PRESSUREPLATE_UPDATE repentogon/resources/scripts/enums_ex.lua:332 enums/ModCallbacks.md level and room todo id 1415 -callback ModCallbacks MC_POST_GRID_ENTITY_ROCK_RENDER repentogon/resources/scripts/enums_ex.lua:375 enums/ModCallbacks.md render and sprites todo id 1459 -callback ModCallbacks MC_POST_GRID_ENTITY_ROCK_UPDATE repentogon/resources/scripts/enums_ex.lua:334 enums/ModCallbacks.md level and room todo id 1417 -callback ModCallbacks MC_POST_GRID_ENTITY_SPAWN repentogon/resources/scripts/enums_ex.lua:103 enums/ModCallbacks.md level and room todo id 1101 -callback ModCallbacks MC_POST_GRID_ENTITY_SPIKES_RENDER repentogon/resources/scripts/enums_ex.lua:350 enums/ModCallbacks.md render and sprites todo id 1433 -callback ModCallbacks MC_POST_GRID_ENTITY_SPIKES_UPDATE repentogon/resources/scripts/enums_ex.lua:336 enums/ModCallbacks.md level and room todo id 1419 -callback ModCallbacks MC_POST_GRID_ENTITY_STAIRCASE_RENDER repentogon/resources/scripts/enums_ex.lua:358 enums/ModCallbacks.md render and sprites todo id 1441 -callback ModCallbacks MC_POST_GRID_ENTITY_STAIRCASE_UPDATE repentogon/resources/scripts/enums_ex.lua:338 enums/ModCallbacks.md level and room todo id 1421 -callback ModCallbacks MC_POST_GRID_ENTITY_STATUE_UPDATE repentogon/resources/scripts/enums_ex.lua:340 enums/ModCallbacks.md hud and menus todo id 1423 -callback ModCallbacks MC_POST_GRID_ENTITY_TELEPORTER_RENDER repentogon/resources/scripts/enums_ex.lua:369 enums/ModCallbacks.md render and sprites todo id 1453 -callback ModCallbacks MC_POST_GRID_ENTITY_TELEPORTER_UPDATE repentogon/resources/scripts/enums_ex.lua:342 enums/ModCallbacks.md level and room todo id 1425 -callback ModCallbacks MC_POST_GRID_ENTITY_TNT_RENDER repentogon/resources/scripts/enums_ex.lua:354 enums/ModCallbacks.md render and sprites todo id 1437 -callback ModCallbacks MC_POST_GRID_ENTITY_TNT_UPDATE repentogon/resources/scripts/enums_ex.lua:348 enums/ModCallbacks.md level and room todo id 1431 -callback ModCallbacks MC_POST_GRID_ENTITY_TRAPDOOR_RENDER repentogon/resources/scripts/enums_ex.lua:356 enums/ModCallbacks.md render and sprites todo id 1439 -callback ModCallbacks MC_POST_GRID_ENTITY_TRAPDOOR_UPDATE repentogon/resources/scripts/enums_ex.lua:344 enums/ModCallbacks.md level and room todo id 1427 -callback ModCallbacks MC_POST_GRID_ENTITY_WALL_RENDER repentogon/resources/scripts/enums_ex.lua:379 enums/ModCallbacks.md render and sprites todo id 1463 -callback ModCallbacks MC_POST_GRID_ENTITY_WEB_RENDER repentogon/resources/scripts/enums_ex.lua:352 enums/ModCallbacks.md render and sprites todo id 1435 -callback ModCallbacks MC_POST_GRID_ENTITY_WEB_UPDATE repentogon/resources/scripts/enums_ex.lua:346 enums/ModCallbacks.md level and room todo id 1429 -callback ModCallbacks MC_POST_GRID_HURT repentogon/resources/scripts/enums_ex.lua:19 enums/ModCallbacks.md level and room todo id 1018 -callback ModCallbacks MC_POST_GRID_HURT_DAMAGE repentogon/resources/scripts/enums_ex.lua:14 enums/ModCallbacks.md level and room todo id 1013 -callback ModCallbacks MC_POST_GRID_ROCK_DESTROY repentogon/resources/scripts/enums_ex.lua:12 enums/ModCallbacks.md level and room todo id 1011 -callback ModCallbacks MC_POST_HISTORYHUD_RECOMPUTE repentogon/resources/scripts/enums_ex.lua:31 enums/ModCallbacks.md hud and menus todo id 1029 -callback ModCallbacks MC_POST_HISTORYHUD_RENDER repentogon/resources/scripts/enums_ex.lua:30 enums/ModCallbacks.md hud and menus todo id 1028 -callback ModCallbacks MC_POST_HUD_RENDER repentogon/resources/scripts/enums_ex.lua:26 enums/ModCallbacks.md hud and menus todo id 1024 -callback ModCallbacks MC_POST_HUD_UPDATE repentogon/resources/scripts/enums_ex.lua:23 enums/ModCallbacks.md hud and menus todo id 1021 -callback ModCallbacks MC_POST_ITEM_OVERLAY_RENDER repentogon/resources/scripts/enums_ex.lua:141 enums/ModCallbacks.md hud and menus todo id 1139 -callback ModCallbacks MC_POST_ITEM_OVERLAY_SHOW repentogon/resources/scripts/enums_ex.lua:136 enums/ModCallbacks.md hud and menus todo id 1134 -callback ModCallbacks MC_POST_ITEM_OVERLAY_UPDATE repentogon/resources/scripts/enums_ex.lua:77 enums/ModCallbacks.md hud and menus todo id 1075 -callback ModCallbacks MC_POST_KNIFE_COLLISION repentogon/resources/scripts/enums_ex.lua:217 enums/ModCallbacks.md tear and weapons todo id 1243 -callback ModCallbacks MC_POST_LASER_COLLISION repentogon/resources/scripts/enums_ex.lua:223 enums/ModCallbacks.md tear and weapons todo id 1249 -callback ModCallbacks MC_POST_LEVEL_LAYOUT_GENERATED repentogon/resources/scripts/enums_ex.lua:101 enums/ModCallbacks.md level and room todo id 1099 -callback ModCallbacks MC_POST_MINIMAP_RENDER repentogon/resources/scripts/enums_ex.lua:394 hud and menus todo id 1480 -callback ModCallbacks MC_POST_MINIMAP_UPDATE repentogon/resources/scripts/enums_ex.lua:392 hud and menus todo id 1478 -callback ModCallbacks MC_POST_MODS_LOADED repentogon/resources/scripts/enums_ex.lua:185 enums/ModCallbacks.md misc todo id 1210 -callback ModCallbacks MC_POST_NIGHTMARE_SCENE_RENDER repentogon/resources/scripts/enums_ex.lua:104 enums/ModCallbacks.md hud and menus todo id 1102 -callback ModCallbacks MC_POST_NIGHTMARE_SCENE_SHOW repentogon/resources/scripts/enums_ex.lua:105 enums/ModCallbacks.md hud and menus todo id 1103 -callback ModCallbacks MC_POST_NPC_COLLISION repentogon/resources/scripts/enums_ex.lua:221 enums/ModCallbacks.md npc todo id 1247 -callback ModCallbacks MC_POST_NPC_DARK_RED_CHAMPION_REGEN repentogon/resources/scripts/enums_ex.lua:198 enums/ModCallbacks.md npc todo id 1223 +callback ModCallbacks MC_POST_FIRE_SWORD repentogon/resources/scripts/enums_ex.lua:232 enums/ModCallbacks.md tear and weapons done id 1258 +callback ModCallbacks MC_POST_FIRE_TECH_LASER repentogon/resources/scripts/enums_ex.lua:233 enums/ModCallbacks.md tear and weapons done id 1259 +callback ModCallbacks MC_POST_FIRE_TECH_X_LASER repentogon/resources/scripts/enums_ex.lua:234 enums/ModCallbacks.md tear and weapons done id 1260 +callback ModCallbacks MC_POST_FORCE_ADD_PILL_EFFECT repentogon/resources/scripts/enums_ex.lua:131 enums/ModCallbacks.md items and pools done id 1129 +callback ModCallbacks MC_POST_GAME_STATE_RESTORE repentogon/resources/scripts/enums_ex.lua:286 hud and menus done id 1312 +callback ModCallbacks MC_POST_GAME_STATE_SAVE repentogon/resources/scripts/enums_ex.lua:284 persistent data and saves done id 1310 +callback ModCallbacks MC_POST_GLOWING_HOURGLASS_LOAD repentogon/resources/scripts/enums_ex.lua:275 enums/ModCallbacks.md misc done id 1301 +callback ModCallbacks MC_POST_GLOWING_HOURGLASS_SAVE repentogon/resources/scripts/enums_ex.lua:274 enums/ModCallbacks.md persistent data and saves done id 1300 +callback ModCallbacks MC_POST_GRID_ENTITY_DECORATION_RENDER repentogon/resources/scripts/enums_ex.lua:361 enums/ModCallbacks.md render and sprites done id 1445 +callback ModCallbacks MC_POST_GRID_ENTITY_DECORATION_UPDATE repentogon/resources/scripts/enums_ex.lua:318 enums/ModCallbacks.md level and room done id 1401 +callback ModCallbacks MC_POST_GRID_ENTITY_DOOR_RENDER repentogon/resources/scripts/enums_ex.lua:363 enums/ModCallbacks.md render and sprites done id 1447 +callback ModCallbacks MC_POST_GRID_ENTITY_DOOR_UPDATE repentogon/resources/scripts/enums_ex.lua:320 enums/ModCallbacks.md level and room done id 1403 +callback ModCallbacks MC_POST_GRID_ENTITY_FIRE_RENDER repentogon/resources/scripts/enums_ex.lua:365 enums/ModCallbacks.md tear and weapons done id 1449 +callback ModCallbacks MC_POST_GRID_ENTITY_FIRE_UPDATE repentogon/resources/scripts/enums_ex.lua:322 enums/ModCallbacks.md tear and weapons done id 1405 +callback ModCallbacks MC_POST_GRID_ENTITY_GRAVITY_UPDATE repentogon/resources/scripts/enums_ex.lua:324 enums/ModCallbacks.md level and room done id 1407 +callback ModCallbacks MC_POST_GRID_ENTITY_LOCK_RENDER repentogon/resources/scripts/enums_ex.lua:367 enums/ModCallbacks.md render and sprites done id 1451 +callback ModCallbacks MC_POST_GRID_ENTITY_LOCK_UPDATE repentogon/resources/scripts/enums_ex.lua:326 enums/ModCallbacks.md level and room done id 1409 +callback ModCallbacks MC_POST_GRID_ENTITY_PIT_RENDER repentogon/resources/scripts/enums_ex.lua:371 enums/ModCallbacks.md render and sprites done id 1455 +callback ModCallbacks MC_POST_GRID_ENTITY_PIT_UPDATE repentogon/resources/scripts/enums_ex.lua:328 enums/ModCallbacks.md level and room done id 1411 +callback ModCallbacks MC_POST_GRID_ENTITY_POOP_RENDER repentogon/resources/scripts/enums_ex.lua:373 enums/ModCallbacks.md render and sprites done id 1457 +callback ModCallbacks MC_POST_GRID_ENTITY_POOP_UPDATE repentogon/resources/scripts/enums_ex.lua:330 enums/ModCallbacks.md level and room done id 1413 +callback ModCallbacks MC_POST_GRID_ENTITY_PRESSUREPLATE_RENDER repentogon/resources/scripts/enums_ex.lua:377 enums/ModCallbacks.md render and sprites done id 1461 +callback ModCallbacks MC_POST_GRID_ENTITY_PRESSUREPLATE_UPDATE repentogon/resources/scripts/enums_ex.lua:332 enums/ModCallbacks.md level and room done id 1415 +callback ModCallbacks MC_POST_GRID_ENTITY_ROCK_RENDER repentogon/resources/scripts/enums_ex.lua:375 enums/ModCallbacks.md render and sprites done id 1459 +callback ModCallbacks MC_POST_GRID_ENTITY_ROCK_UPDATE repentogon/resources/scripts/enums_ex.lua:334 enums/ModCallbacks.md level and room done id 1417 +callback ModCallbacks MC_POST_GRID_ENTITY_SPAWN repentogon/resources/scripts/enums_ex.lua:103 enums/ModCallbacks.md level and room done id 1101 +callback ModCallbacks MC_POST_GRID_ENTITY_SPIKES_RENDER repentogon/resources/scripts/enums_ex.lua:350 enums/ModCallbacks.md render and sprites done id 1433 +callback ModCallbacks MC_POST_GRID_ENTITY_SPIKES_UPDATE repentogon/resources/scripts/enums_ex.lua:336 enums/ModCallbacks.md level and room done id 1419 +callback ModCallbacks MC_POST_GRID_ENTITY_STAIRCASE_RENDER repentogon/resources/scripts/enums_ex.lua:358 enums/ModCallbacks.md render and sprites done id 1441 +callback ModCallbacks MC_POST_GRID_ENTITY_STAIRCASE_UPDATE repentogon/resources/scripts/enums_ex.lua:338 enums/ModCallbacks.md level and room done id 1421 +callback ModCallbacks MC_POST_GRID_ENTITY_STATUE_UPDATE repentogon/resources/scripts/enums_ex.lua:340 enums/ModCallbacks.md hud and menus done id 1423 +callback ModCallbacks MC_POST_GRID_ENTITY_TELEPORTER_RENDER repentogon/resources/scripts/enums_ex.lua:369 enums/ModCallbacks.md render and sprites done id 1453 +callback ModCallbacks MC_POST_GRID_ENTITY_TELEPORTER_UPDATE repentogon/resources/scripts/enums_ex.lua:342 enums/ModCallbacks.md level and room done id 1425 +callback ModCallbacks MC_POST_GRID_ENTITY_TNT_RENDER repentogon/resources/scripts/enums_ex.lua:354 enums/ModCallbacks.md render and sprites done id 1437 +callback ModCallbacks MC_POST_GRID_ENTITY_TNT_UPDATE repentogon/resources/scripts/enums_ex.lua:348 enums/ModCallbacks.md level and room done id 1431 +callback ModCallbacks MC_POST_GRID_ENTITY_TRAPDOOR_RENDER repentogon/resources/scripts/enums_ex.lua:356 enums/ModCallbacks.md render and sprites done id 1439 +callback ModCallbacks MC_POST_GRID_ENTITY_TRAPDOOR_UPDATE repentogon/resources/scripts/enums_ex.lua:344 enums/ModCallbacks.md level and room done id 1427 +callback ModCallbacks MC_POST_GRID_ENTITY_WALL_RENDER repentogon/resources/scripts/enums_ex.lua:379 enums/ModCallbacks.md render and sprites done id 1463 +callback ModCallbacks MC_POST_GRID_ENTITY_WEB_RENDER repentogon/resources/scripts/enums_ex.lua:352 enums/ModCallbacks.md render and sprites done id 1435 +callback ModCallbacks MC_POST_GRID_ENTITY_WEB_UPDATE repentogon/resources/scripts/enums_ex.lua:346 enums/ModCallbacks.md level and room done id 1429 +callback ModCallbacks MC_POST_GRID_HURT repentogon/resources/scripts/enums_ex.lua:19 enums/ModCallbacks.md level and room done id 1018 +callback ModCallbacks MC_POST_GRID_HURT_DAMAGE repentogon/resources/scripts/enums_ex.lua:14 enums/ModCallbacks.md level and room done id 1013 +callback ModCallbacks MC_POST_GRID_ROCK_DESTROY repentogon/resources/scripts/enums_ex.lua:12 enums/ModCallbacks.md level and room done id 1011 +callback ModCallbacks MC_POST_HISTORYHUD_RECOMPUTE repentogon/resources/scripts/enums_ex.lua:31 enums/ModCallbacks.md hud and menus done id 1029 +callback ModCallbacks MC_POST_HISTORYHUD_RENDER repentogon/resources/scripts/enums_ex.lua:30 enums/ModCallbacks.md hud and menus done id 1028 +callback ModCallbacks MC_POST_HUD_RENDER repentogon/resources/scripts/enums_ex.lua:26 enums/ModCallbacks.md hud and menus done id 1024 +callback ModCallbacks MC_POST_HUD_UPDATE repentogon/resources/scripts/enums_ex.lua:23 enums/ModCallbacks.md hud and menus done id 1021 +callback ModCallbacks MC_POST_ITEM_OVERLAY_RENDER repentogon/resources/scripts/enums_ex.lua:141 enums/ModCallbacks.md hud and menus done id 1139 +callback ModCallbacks MC_POST_ITEM_OVERLAY_SHOW repentogon/resources/scripts/enums_ex.lua:136 enums/ModCallbacks.md hud and menus done id 1134 +callback ModCallbacks MC_POST_ITEM_OVERLAY_UPDATE repentogon/resources/scripts/enums_ex.lua:77 enums/ModCallbacks.md hud and menus done id 1075 +callback ModCallbacks MC_POST_KNIFE_COLLISION repentogon/resources/scripts/enums_ex.lua:217 enums/ModCallbacks.md tear and weapons done id 1243 +callback ModCallbacks MC_POST_LASER_COLLISION repentogon/resources/scripts/enums_ex.lua:223 enums/ModCallbacks.md tear and weapons done id 1249 +callback ModCallbacks MC_POST_LEVEL_LAYOUT_GENERATED repentogon/resources/scripts/enums_ex.lua:101 enums/ModCallbacks.md level and room done id 1099 +callback ModCallbacks MC_POST_MINIMAP_RENDER repentogon/resources/scripts/enums_ex.lua:394 hud and menus done id 1480 +callback ModCallbacks MC_POST_MINIMAP_UPDATE repentogon/resources/scripts/enums_ex.lua:392 hud and menus done id 1478 +callback ModCallbacks MC_POST_MODS_LOADED repentogon/resources/scripts/enums_ex.lua:185 enums/ModCallbacks.md misc done id 1210 +callback ModCallbacks MC_POST_NIGHTMARE_SCENE_RENDER repentogon/resources/scripts/enums_ex.lua:104 enums/ModCallbacks.md hud and menus done id 1102 +callback ModCallbacks MC_POST_NIGHTMARE_SCENE_SHOW repentogon/resources/scripts/enums_ex.lua:105 enums/ModCallbacks.md hud and menus done id 1103 +callback ModCallbacks MC_POST_NPC_COLLISION repentogon/resources/scripts/enums_ex.lua:221 enums/ModCallbacks.md npc done id 1247 +callback ModCallbacks MC_POST_NPC_DARK_RED_CHAMPION_REGEN repentogon/resources/scripts/enums_ex.lua:198 enums/ModCallbacks.md npc done id 1223 callback ModCallbacks MC_POST_NPC_GET_LOOT_LIST repentogon/resources/scripts/enums_ex.lua:302 npc todo id 1339 -callback ModCallbacks MC_POST_NPC_MORPH repentogon/resources/scripts/enums_ex.lua:189 enums/ModCallbacks.md npc todo id 1214 -callback ModCallbacks MC_POST_OPEN_CHEST repentogon/resources/scripts/enums_ex.lua:406 enums/ModCallbacks.md misc todo id 1492 -callback ModCallbacks MC_POST_PAUSE_SCREEN_RENDER repentogon/resources/scripts/enums_ex.lua:194 enums/ModCallbacks.md hud and menus todo id 1219 -callback ModCallbacks MC_POST_PICKUP_COLLISION repentogon/resources/scripts/enums_ex.lua:213 enums/ModCallbacks.md pickup todo id 1239 +callback ModCallbacks MC_POST_NPC_MORPH repentogon/resources/scripts/enums_ex.lua:189 enums/ModCallbacks.md npc done id 1214 +callback ModCallbacks MC_POST_OPEN_CHEST repentogon/resources/scripts/enums_ex.lua:406 enums/ModCallbacks.md misc done id 1492 +callback ModCallbacks MC_POST_PAUSE_SCREEN_RENDER repentogon/resources/scripts/enums_ex.lua:194 enums/ModCallbacks.md hud and menus done id 1219 +callback ModCallbacks MC_POST_PICKUP_COLLISION repentogon/resources/scripts/enums_ex.lua:213 enums/ModCallbacks.md pickup done id 1239 callback ModCallbacks MC_POST_PICKUP_GET_LOOT_LIST repentogon/resources/scripts/enums_ex.lua:299 enums/ModCallbacks.md pickup todo id 1336 -callback ModCallbacks MC_POST_PICKUP_MORPH repentogon/resources/scripts/enums_ex.lua:190 enums/ModCallbacks.md pickup todo id 1215 +callback ModCallbacks MC_POST_PICKUP_MORPH repentogon/resources/scripts/enums_ex.lua:190 enums/ModCallbacks.md pickup done id 1215 callback ModCallbacks MC_POST_PICKUP_SELECTION enums/ModCallbacks.md pickup review id 37, vanilla callback REPENTOGON changes -callback ModCallbacks MC_POST_PICKUP_SHOP_PURCHASE repentogon/resources/scripts/enums_ex.lua:64 enums/ModCallbacks.md pickup todo id 1062 -callback ModCallbacks MC_POST_PLANETARIUM_CALCULATE repentogon/resources/scripts/enums_ex.lua:117 enums/ModCallbacks.md items and pools todo id 1115 -callback ModCallbacks MC_POST_PLAYERHUD_RENDER_ACTIVE_ITEM repentogon/resources/scripts/enums_ex.lua:81 enums/ModCallbacks.md player todo id 1079 -callback ModCallbacks MC_POST_PLAYERHUD_RENDER_CRAFTING_TABLE repentogon/resources/scripts/enums_ex.lua:272 enums/ModCallbacks.md player todo id 1298 -callback ModCallbacks MC_POST_PLAYERHUD_RENDER_HEARTS repentogon/resources/scripts/enums_ex.lua:93 enums/ModCallbacks.md player todo id 1091 -callback ModCallbacks MC_POST_PLAYERHUD_RENDER_INVENTORY repentogon/resources/scripts/enums_ex.lua:268 enums/ModCallbacks.md player todo id 1294 -callback ModCallbacks MC_POST_PLAYERHUD_RENDER_POOP_SPELL_QUEUE repentogon/resources/scripts/enums_ex.lua:270 enums/ModCallbacks.md player todo id 1296 -callback ModCallbacks MC_POST_PLAYER_ADD_CARD repentogon/resources/scripts/enums_ex.lua:305 enums/ModCallbacks.md player todo id 1351 -callback ModCallbacks MC_POST_PLAYER_ADD_COSTUME repentogon/resources/scripts/enums_ex.lua:257 enums/ModCallbacks.md player todo id 1283 -callback ModCallbacks MC_POST_PLAYER_ADD_EFFECT repentogon/resources/scripts/enums_ex.lua:247 enums/ModCallbacks.md player todo id 1273 -callback ModCallbacks MC_POST_PLAYER_ADD_HEARTS repentogon/resources/scripts/enums_ex.lua:11 enums/ModCallbacks.md player todo id 1010 -callback ModCallbacks MC_POST_PLAYER_ADD_PILL repentogon/resources/scripts/enums_ex.lua:307 enums/ModCallbacks.md player todo id 1353 -callback ModCallbacks MC_POST_PLAYER_COLLECT_CARD repentogon/resources/scripts/enums_ex.lua:311 enums/ModCallbacks.md player todo id 1357 -callback ModCallbacks MC_POST_PLAYER_COLLECT_PILL repentogon/resources/scripts/enums_ex.lua:313 enums/ModCallbacks.md player todo id 1359 -callback ModCallbacks MC_POST_PLAYER_COLLISION repentogon/resources/scripts/enums_ex.lua:205 enums/ModCallbacks.md player todo id 1231 -callback ModCallbacks MC_POST_PLAYER_DROP_CARD repentogon/resources/scripts/enums_ex.lua:314 enums/ModCallbacks.md player todo id 1360 -callback ModCallbacks MC_POST_PLAYER_DROP_PILL repentogon/resources/scripts/enums_ex.lua:315 enums/ModCallbacks.md player todo id 1361 -callback ModCallbacks MC_POST_PLAYER_DROP_TRINKET repentogon/resources/scripts/enums_ex.lua:146 enums/ModCallbacks.md player todo id 1144 +callback ModCallbacks MC_POST_PICKUP_SHOP_PURCHASE repentogon/resources/scripts/enums_ex.lua:64 enums/ModCallbacks.md pickup done id 1062 +callback ModCallbacks MC_POST_PLANETARIUM_CALCULATE repentogon/resources/scripts/enums_ex.lua:117 enums/ModCallbacks.md items and pools done id 1115 +callback ModCallbacks MC_POST_PLAYERHUD_RENDER_ACTIVE_ITEM repentogon/resources/scripts/enums_ex.lua:81 enums/ModCallbacks.md player done id 1079 +callback ModCallbacks MC_POST_PLAYERHUD_RENDER_CRAFTING_TABLE repentogon/resources/scripts/enums_ex.lua:272 enums/ModCallbacks.md player done id 1298 +callback ModCallbacks MC_POST_PLAYERHUD_RENDER_HEARTS repentogon/resources/scripts/enums_ex.lua:93 enums/ModCallbacks.md player done id 1091 +callback ModCallbacks MC_POST_PLAYERHUD_RENDER_INVENTORY repentogon/resources/scripts/enums_ex.lua:268 enums/ModCallbacks.md player done id 1294 +callback ModCallbacks MC_POST_PLAYERHUD_RENDER_POOP_SPELL_QUEUE repentogon/resources/scripts/enums_ex.lua:270 enums/ModCallbacks.md player done id 1296 +callback ModCallbacks MC_POST_PLAYER_ADD_CARD repentogon/resources/scripts/enums_ex.lua:305 enums/ModCallbacks.md player done id 1351 +callback ModCallbacks MC_POST_PLAYER_ADD_COSTUME repentogon/resources/scripts/enums_ex.lua:257 enums/ModCallbacks.md player done id 1283 +callback ModCallbacks MC_POST_PLAYER_ADD_EFFECT repentogon/resources/scripts/enums_ex.lua:247 enums/ModCallbacks.md player done id 1273 +callback ModCallbacks MC_POST_PLAYER_ADD_HEARTS repentogon/resources/scripts/enums_ex.lua:11 enums/ModCallbacks.md player done id 1010 +callback ModCallbacks MC_POST_PLAYER_ADD_PILL repentogon/resources/scripts/enums_ex.lua:307 enums/ModCallbacks.md player done id 1353 +callback ModCallbacks MC_POST_PLAYER_COLLECT_CARD repentogon/resources/scripts/enums_ex.lua:311 enums/ModCallbacks.md player done id 1357 +callback ModCallbacks MC_POST_PLAYER_COLLECT_PILL repentogon/resources/scripts/enums_ex.lua:313 enums/ModCallbacks.md player done id 1359 +callback ModCallbacks MC_POST_PLAYER_COLLISION repentogon/resources/scripts/enums_ex.lua:205 enums/ModCallbacks.md player done id 1231 +callback ModCallbacks MC_POST_PLAYER_DROP_CARD repentogon/resources/scripts/enums_ex.lua:314 enums/ModCallbacks.md player done id 1360 +callback ModCallbacks MC_POST_PLAYER_DROP_PILL repentogon/resources/scripts/enums_ex.lua:315 enums/ModCallbacks.md player done id 1361 +callback ModCallbacks MC_POST_PLAYER_DROP_TRINKET repentogon/resources/scripts/enums_ex.lua:146 enums/ModCallbacks.md player done id 1144 callback ModCallbacks MC_POST_PLAYER_GET_MULTI_SHOT_PARAMS repentogon/resources/scripts/enums_ex.lua:225 player todo id 1251 -callback ModCallbacks MC_POST_PLAYER_NEW_LEVEL repentogon/resources/scripts/enums_ex.lua:80 enums/ModCallbacks.md player todo id 1078 -callback ModCallbacks MC_POST_PLAYER_NEW_ROOM_TEMP_EFFECTS repentogon/resources/scripts/enums_ex.lua:79 enums/ModCallbacks.md player todo id 1077 -callback ModCallbacks MC_POST_PLAYER_REMOVE_CARD repentogon/resources/scripts/enums_ex.lua:308 enums/ModCallbacks.md player todo id 1354 -callback ModCallbacks MC_POST_PLAYER_REMOVE_COSTUME repentogon/resources/scripts/enums_ex.lua:258 enums/ModCallbacks.md player todo id 1284 -callback ModCallbacks MC_POST_PLAYER_REMOVE_PILL repentogon/resources/scripts/enums_ex.lua:309 enums/ModCallbacks.md player todo id 1355 -callback ModCallbacks MC_POST_PLAYER_REVIVE repentogon/resources/scripts/enums_ex.lua:396 enums/ModCallbacks.md player todo id 1482 -callback ModCallbacks MC_POST_PLAYER_TRIGGER_EFFECT_REMOVED repentogon/resources/scripts/enums_ex.lua:242 enums/ModCallbacks.md player todo id 1268 -callback ModCallbacks MC_POST_PLAYER_TRIGGER_ROOM_CLEAR repentogon/resources/scripts/enums_ex.lua:140 enums/ModCallbacks.md player todo id 1138 -callback ModCallbacks MC_POST_PLAYER_USE_BOMB repentogon/resources/scripts/enums_ex.lua:196 enums/ModCallbacks.md player todo id 1221 -callback ModCallbacks MC_POST_PROJECTILE_COLLISION repentogon/resources/scripts/enums_ex.lua:219 enums/ModCallbacks.md tear and weapons todo id 1245 -callback ModCallbacks MC_POST_PROJECTILE_DEATH repentogon/resources/scripts/enums_ex.lua:34 enums/ModCallbacks.md tear and weapons todo id 1032 +callback ModCallbacks MC_POST_PLAYER_NEW_LEVEL repentogon/resources/scripts/enums_ex.lua:80 enums/ModCallbacks.md player done id 1078 +callback ModCallbacks MC_POST_PLAYER_NEW_ROOM_TEMP_EFFECTS repentogon/resources/scripts/enums_ex.lua:79 enums/ModCallbacks.md player done id 1077 +callback ModCallbacks MC_POST_PLAYER_REMOVE_CARD repentogon/resources/scripts/enums_ex.lua:308 enums/ModCallbacks.md player done id 1354 +callback ModCallbacks MC_POST_PLAYER_REMOVE_COSTUME repentogon/resources/scripts/enums_ex.lua:258 enums/ModCallbacks.md player done id 1284 +callback ModCallbacks MC_POST_PLAYER_REMOVE_PILL repentogon/resources/scripts/enums_ex.lua:309 enums/ModCallbacks.md player done id 1355 +callback ModCallbacks MC_POST_PLAYER_REVIVE repentogon/resources/scripts/enums_ex.lua:396 enums/ModCallbacks.md player done id 1482 +callback ModCallbacks MC_POST_PLAYER_TRIGGER_EFFECT_REMOVED repentogon/resources/scripts/enums_ex.lua:242 enums/ModCallbacks.md player done id 1268 +callback ModCallbacks MC_POST_PLAYER_TRIGGER_ROOM_CLEAR repentogon/resources/scripts/enums_ex.lua:140 enums/ModCallbacks.md player done id 1138 +callback ModCallbacks MC_POST_PLAYER_USE_BOMB repentogon/resources/scripts/enums_ex.lua:196 enums/ModCallbacks.md player done id 1221 +callback ModCallbacks MC_POST_PROJECTILE_COLLISION repentogon/resources/scripts/enums_ex.lua:219 enums/ModCallbacks.md tear and weapons done id 1245 +callback ModCallbacks MC_POST_PROJECTILE_DEATH repentogon/resources/scripts/enums_ex.lua:34 enums/ModCallbacks.md tear and weapons done id 1032 callback ModCallbacks MC_POST_REMOVE_INNATE_COLLECTIBLE repentogon/resources/scripts/enums_ex.lua:58 enums/ModCallbacks.md items and pools todo id 1056 callback ModCallbacks MC_POST_REMOVE_INNATE_TRINKET repentogon/resources/scripts/enums_ex.lua:59 enums/ModCallbacks.md items and pools todo id 1057 -callback ModCallbacks MC_POST_RENDER_CHARACTER_SELECT_PAGE repentogon/resources/scripts/enums_ex.lua:293 enums/ModCallbacks.md render and sprites todo id 1330 -callback ModCallbacks MC_POST_RENDER_CHARACTER_SELECT_PORTRAIT repentogon/resources/scripts/enums_ex.lua:295 enums/ModCallbacks.md render and sprites todo id 1332 -callback ModCallbacks MC_POST_RENDER_PLAYER_BODY repentogon/resources/scripts/enums_ex.lua:48 player todo id 1046 -callback ModCallbacks MC_POST_RENDER_PLAYER_HEAD repentogon/resources/scripts/enums_ex.lua:47 player todo id 1045 -callback ModCallbacks MC_POST_REPLACE_SPRITESHEET repentogon/resources/scripts/enums_ex.lua:119 enums/ModCallbacks.md render and sprites todo id 1117 -callback ModCallbacks MC_POST_RESTOCK_SHOP repentogon/resources/scripts/enums_ex.lua:73 enums/ModCallbacks.md items and pools todo id 1071 -callback ModCallbacks MC_POST_ROOM_ADD_EFFECT repentogon/resources/scripts/enums_ex.lua:248 enums/ModCallbacks.md level and room todo id 1274 -callback ModCallbacks MC_POST_ROOM_RENDER_ENTITIES repentogon/resources/scripts/enums_ex.lua:46 enums/ModCallbacks.md render and sprites todo id 1044 -callback ModCallbacks MC_POST_ROOM_SAVE_STATE repentogon/resources/scripts/enums_ex.lua:278 enums/ModCallbacks.md persistent data and saves todo id 1304 -callback ModCallbacks MC_POST_ROOM_TRANSITION_RENDER repentogon/resources/scripts/enums_ex.lua:246 enums/ModCallbacks.md render and sprites todo id 1272 -callback ModCallbacks MC_POST_ROOM_TRANSITION_UPDATE repentogon/resources/scripts/enums_ex.lua:245 enums/ModCallbacks.md level and room todo id 1271 -callback ModCallbacks MC_POST_ROOM_TRIGGER_CLEAR repentogon/resources/scripts/enums_ex.lua:145 enums/ModCallbacks.md level and room todo id 1143 -callback ModCallbacks MC_POST_ROOM_TRIGGER_EFFECT_REMOVED repentogon/resources/scripts/enums_ex.lua:243 enums/ModCallbacks.md level and room todo id 1269 -callback ModCallbacks MC_POST_SAVESLOT_LOAD repentogon/resources/scripts/enums_ex.lua:384 enums/ModCallbacks.md persistent data and saves todo id 1470 -callback ModCallbacks MC_POST_SFX_PLAY repentogon/resources/scripts/enums_ex.lua:33 enums/ModCallbacks.md audio todo id 1031 -callback ModCallbacks MC_POST_SHUFFLE_COSTUMES repentogon/resources/scripts/enums_ex.lua:409 enums/ModCallbacks.md player todo id 1495 -callback ModCallbacks MC_POST_SLOT_COLLISION repentogon/resources/scripts/enums_ex.lua:215 enums/ModCallbacks.md pickup todo id 1241 -callback ModCallbacks MC_POST_SLOT_CREATE_EXPLOSION_DROPS repentogon/resources/scripts/enums_ex.lua:126 enums/ModCallbacks.md pickup todo id 1124 -callback ModCallbacks MC_POST_SLOT_INIT repentogon/resources/scripts/enums_ex.lua:123 enums/ModCallbacks.md pickup todo id 1121 -callback ModCallbacks MC_POST_SLOT_RENDER repentogon/resources/scripts/enums_ex.lua:92 enums/ModCallbacks.md pickup todo id 1090 -callback ModCallbacks MC_POST_SLOT_SET_PRIZE_COLLECTIBLE repentogon/resources/scripts/enums_ex.lua:128 enums/ModCallbacks.md pickup todo id 1126 -callback ModCallbacks MC_POST_SLOT_UPDATE repentogon/resources/scripts/enums_ex.lua:124 enums/ModCallbacks.md pickup todo id 1122 -callback ModCallbacks MC_POST_START_AMBUSH_WAVE repentogon/resources/scripts/enums_ex.lua:402 enums/ModCallbacks.md level and room todo id 1488 -callback ModCallbacks MC_POST_START_GREED_WAVE repentogon/resources/scripts/enums_ex.lua:403 enums/ModCallbacks.md level and room todo id 1489 -callback ModCallbacks MC_POST_STATUS_EFFECT_APPLY repentogon/resources/scripts/enums_ex.lua:382 enums/ModCallbacks.md hud and menus todo id 1466 -callback ModCallbacks MC_POST_SWAP_ROOMS repentogon/resources/scripts/enums_ex.lua:280 enums/ModCallbacks.md level and room todo id 1306 -callback ModCallbacks MC_POST_TAKE_DMG repentogon/resources/scripts/enums_ex.lua:6 entities todo id 1006 -callback ModCallbacks MC_POST_TEAR_COLLISION repentogon/resources/scripts/enums_ex.lua:207 enums/ModCallbacks.md tear and weapons todo id 1233 -callback ModCallbacks MC_POST_TEAR_DEATH repentogon/resources/scripts/enums_ex.lua:35 enums/ModCallbacks.md tear and weapons todo id 1033 +callback ModCallbacks MC_POST_RENDER_CHARACTER_SELECT_PAGE repentogon/resources/scripts/enums_ex.lua:293 enums/ModCallbacks.md render and sprites done id 1330 +callback ModCallbacks MC_POST_RENDER_CHARACTER_SELECT_PORTRAIT repentogon/resources/scripts/enums_ex.lua:295 enums/ModCallbacks.md render and sprites done id 1332 +callback ModCallbacks MC_POST_RENDER_PLAYER_BODY repentogon/resources/scripts/enums_ex.lua:48 player done id 1046 +callback ModCallbacks MC_POST_RENDER_PLAYER_HEAD repentogon/resources/scripts/enums_ex.lua:47 player done id 1045 +callback ModCallbacks MC_POST_REPLACE_SPRITESHEET repentogon/resources/scripts/enums_ex.lua:119 enums/ModCallbacks.md render and sprites done id 1117 +callback ModCallbacks MC_POST_RESTOCK_SHOP repentogon/resources/scripts/enums_ex.lua:73 enums/ModCallbacks.md items and pools done id 1071 +callback ModCallbacks MC_POST_ROOM_ADD_EFFECT repentogon/resources/scripts/enums_ex.lua:248 enums/ModCallbacks.md level and room done id 1274 +callback ModCallbacks MC_POST_ROOM_RENDER_ENTITIES repentogon/resources/scripts/enums_ex.lua:46 enums/ModCallbacks.md render and sprites done id 1044 +callback ModCallbacks MC_POST_ROOM_SAVE_STATE repentogon/resources/scripts/enums_ex.lua:278 enums/ModCallbacks.md persistent data and saves done id 1304 +callback ModCallbacks MC_POST_ROOM_TRANSITION_RENDER repentogon/resources/scripts/enums_ex.lua:246 enums/ModCallbacks.md render and sprites done id 1272 +callback ModCallbacks MC_POST_ROOM_TRANSITION_UPDATE repentogon/resources/scripts/enums_ex.lua:245 enums/ModCallbacks.md level and room done id 1271 +callback ModCallbacks MC_POST_ROOM_TRIGGER_CLEAR repentogon/resources/scripts/enums_ex.lua:145 enums/ModCallbacks.md level and room done id 1143 +callback ModCallbacks MC_POST_ROOM_TRIGGER_EFFECT_REMOVED repentogon/resources/scripts/enums_ex.lua:243 enums/ModCallbacks.md level and room done id 1269 +callback ModCallbacks MC_POST_SAVESLOT_LOAD repentogon/resources/scripts/enums_ex.lua:384 enums/ModCallbacks.md persistent data and saves done id 1470 +callback ModCallbacks MC_POST_SFX_PLAY repentogon/resources/scripts/enums_ex.lua:33 enums/ModCallbacks.md audio done id 1031 +callback ModCallbacks MC_POST_SHUFFLE_COSTUMES repentogon/resources/scripts/enums_ex.lua:409 enums/ModCallbacks.md player done id 1495 +callback ModCallbacks MC_POST_SLOT_COLLISION repentogon/resources/scripts/enums_ex.lua:215 enums/ModCallbacks.md pickup done id 1241 +callback ModCallbacks MC_POST_SLOT_CREATE_EXPLOSION_DROPS repentogon/resources/scripts/enums_ex.lua:126 enums/ModCallbacks.md pickup done id 1124 +callback ModCallbacks MC_POST_SLOT_INIT repentogon/resources/scripts/enums_ex.lua:123 enums/ModCallbacks.md pickup done id 1121 +callback ModCallbacks MC_POST_SLOT_RENDER repentogon/resources/scripts/enums_ex.lua:92 enums/ModCallbacks.md pickup done id 1090 +callback ModCallbacks MC_POST_SLOT_SET_PRIZE_COLLECTIBLE repentogon/resources/scripts/enums_ex.lua:128 enums/ModCallbacks.md pickup done id 1126 +callback ModCallbacks MC_POST_SLOT_UPDATE repentogon/resources/scripts/enums_ex.lua:124 enums/ModCallbacks.md pickup done id 1122 +callback ModCallbacks MC_POST_START_AMBUSH_WAVE repentogon/resources/scripts/enums_ex.lua:402 enums/ModCallbacks.md level and room done id 1488 +callback ModCallbacks MC_POST_START_GREED_WAVE repentogon/resources/scripts/enums_ex.lua:403 enums/ModCallbacks.md level and room done id 1489 +callback ModCallbacks MC_POST_STATUS_EFFECT_APPLY repentogon/resources/scripts/enums_ex.lua:382 enums/ModCallbacks.md hud and menus done id 1466 +callback ModCallbacks MC_POST_SWAP_ROOMS repentogon/resources/scripts/enums_ex.lua:280 enums/ModCallbacks.md level and room done id 1306 +callback ModCallbacks MC_POST_TAKE_DMG repentogon/resources/scripts/enums_ex.lua:6 entities done id 1006 +callback ModCallbacks MC_POST_TEAR_COLLISION repentogon/resources/scripts/enums_ex.lua:207 enums/ModCallbacks.md tear and weapons done id 1233 +callback ModCallbacks MC_POST_TEAR_DEATH repentogon/resources/scripts/enums_ex.lua:35 enums/ModCallbacks.md tear and weapons done id 1033 callback ModCallbacks MC_POST_TRIGGER_BED_SLEEP_EFFECT repentogon/resources/scripts/enums_ex.lua:260 enums/ModCallbacks.md misc todo id 1286 -callback ModCallbacks MC_POST_TRIGGER_COLLECTIBLE_ADDED repentogon/resources/scripts/enums_ex.lua:55 enums/ModCallbacks.md items and pools todo id 1053 -callback ModCallbacks MC_POST_TRIGGER_COLLECTIBLE_REMOVED repentogon/resources/scripts/enums_ex.lua:97 enums/ModCallbacks.md items and pools todo id 1095 -callback ModCallbacks MC_POST_TRIGGER_TRINKET_ADDED repentogon/resources/scripts/enums_ex.lua:98 enums/ModCallbacks.md items and pools todo id 1096 -callback ModCallbacks MC_POST_TRIGGER_TRINKET_REMOVED repentogon/resources/scripts/enums_ex.lua:99 enums/ModCallbacks.md items and pools todo id 1097 +callback ModCallbacks MC_POST_TRIGGER_COLLECTIBLE_ADDED repentogon/resources/scripts/enums_ex.lua:55 enums/ModCallbacks.md items and pools done id 1053 +callback ModCallbacks MC_POST_TRIGGER_COLLECTIBLE_REMOVED repentogon/resources/scripts/enums_ex.lua:97 enums/ModCallbacks.md items and pools done id 1095 +callback ModCallbacks MC_POST_TRIGGER_TRINKET_ADDED repentogon/resources/scripts/enums_ex.lua:98 enums/ModCallbacks.md items and pools done id 1096 +callback ModCallbacks MC_POST_TRIGGER_TRINKET_REMOVED repentogon/resources/scripts/enums_ex.lua:99 enums/ModCallbacks.md items and pools done id 1097 callback ModCallbacks MC_POST_TRIGGER_WEAPON_FIRED repentogon/resources/scripts/enums_ex.lua:100 enums/ModCallbacks.md tear and weapons todo id 1098 -callback ModCallbacks MC_POST_USE_ITEM repentogon/resources/scripts/enums_ex.lua:3 enums/ModCallbacks.md items and pools todo id 1003 +callback ModCallbacks MC_POST_USE_ITEM repentogon/resources/scripts/enums_ex.lua:3 enums/ModCallbacks.md items and pools done id 1003 callback ModCallbacks MC_POST_WEAPON_FIRE repentogon/resources/scripts/enums_ex.lua:107 enums/ModCallbacks.md tear and weapons todo id 1105 -callback ModCallbacks MC_PRE_ADD_COLLECTIBLE repentogon/resources/scripts/enums_ex.lua:4 enums/ModCallbacks.md items and pools todo id 1004 -callback ModCallbacks MC_PRE_ADD_TRINKET repentogon/resources/scripts/enums_ex.lua:15 enums/ModCallbacks.md items and pools todo id 1014 -callback ModCallbacks MC_PRE_APPLY_TEARFLAG_EFFECTS repentogon/resources/scripts/enums_ex.lua:251 enums/ModCallbacks.md tear and weapons todo id 1277 -callback ModCallbacks MC_PRE_BACKDROP_CHANGE repentogon/resources/scripts/enums_ex.lua:143 enums/ModCallbacks.md level and room todo id 1141 -callback ModCallbacks MC_PRE_BACKDROP_RENDER_FLOOR repentogon/resources/scripts/enums_ex.lua:109 enums/ModCallbacks.md render and sprites todo id 1107 -callback ModCallbacks MC_PRE_BACKDROP_RENDER_WALLS repentogon/resources/scripts/enums_ex.lua:108 enums/ModCallbacks.md render and sprites todo id 1106 -callback ModCallbacks MC_PRE_BACKDROP_RENDER_WATER repentogon/resources/scripts/enums_ex.lua:110 enums/ModCallbacks.md render and sprites todo id 1108 -callback ModCallbacks MC_PRE_BED_SLEEP repentogon/resources/scripts/enums_ex.lua:262 enums/ModCallbacks.md misc todo id 1288 +callback ModCallbacks MC_PRE_ADD_COLLECTIBLE repentogon/resources/scripts/enums_ex.lua:4 enums/ModCallbacks.md items and pools done id 1004 +callback ModCallbacks MC_PRE_ADD_TRINKET repentogon/resources/scripts/enums_ex.lua:15 enums/ModCallbacks.md items and pools done id 1014 +callback ModCallbacks MC_PRE_APPLY_TEARFLAG_EFFECTS repentogon/resources/scripts/enums_ex.lua:251 enums/ModCallbacks.md tear and weapons done id 1277 +callback ModCallbacks MC_PRE_BACKDROP_CHANGE repentogon/resources/scripts/enums_ex.lua:143 enums/ModCallbacks.md level and room done id 1141 +callback ModCallbacks MC_PRE_BACKDROP_RENDER_FLOOR repentogon/resources/scripts/enums_ex.lua:109 enums/ModCallbacks.md render and sprites done id 1107 +callback ModCallbacks MC_PRE_BACKDROP_RENDER_WALLS repentogon/resources/scripts/enums_ex.lua:108 enums/ModCallbacks.md render and sprites done id 1106 +callback ModCallbacks MC_PRE_BACKDROP_RENDER_WATER repentogon/resources/scripts/enums_ex.lua:110 enums/ModCallbacks.md render and sprites done id 1108 +callback ModCallbacks MC_PRE_BED_SLEEP repentogon/resources/scripts/enums_ex.lua:262 enums/ModCallbacks.md misc done id 1288 callback ModCallbacks MC_PRE_BOMB_COLLISION enums/ModCallbacks.md tear and weapons review id 60, vanilla callback REPENTOGON changes -callback ModCallbacks MC_PRE_BOMB_DAMAGE repentogon/resources/scripts/enums_ex.lua:265 enums/ModCallbacks.md tear and weapons todo id 1291 -callback ModCallbacks MC_PRE_BOMB_GRID_COLLISION repentogon/resources/scripts/enums_ex.lua:169 enums/ModCallbacks.md tear and weapons todo id 1177 -callback ModCallbacks MC_PRE_BOMB_RENDER repentogon/resources/scripts/enums_ex.lua:90 enums/ModCallbacks.md tear and weapons todo id 1088 -callback ModCallbacks MC_PRE_BOMB_TEARFLAG_EFFECTS repentogon/resources/scripts/enums_ex.lua:266 enums/ModCallbacks.md tear and weapons todo id 1292 -callback ModCallbacks MC_PRE_BOMB_UPDATE repentogon/resources/scripts/enums_ex.lua:155 enums/ModCallbacks.md tear and weapons todo id 1163 +callback ModCallbacks MC_PRE_BOMB_DAMAGE repentogon/resources/scripts/enums_ex.lua:265 enums/ModCallbacks.md tear and weapons done id 1291 +callback ModCallbacks MC_PRE_BOMB_GRID_COLLISION repentogon/resources/scripts/enums_ex.lua:169 enums/ModCallbacks.md tear and weapons done id 1177 +callback ModCallbacks MC_PRE_BOMB_RENDER repentogon/resources/scripts/enums_ex.lua:90 enums/ModCallbacks.md tear and weapons done id 1088 +callback ModCallbacks MC_PRE_BOMB_TEARFLAG_EFFECTS repentogon/resources/scripts/enums_ex.lua:266 enums/ModCallbacks.md tear and weapons done id 1292 +callback ModCallbacks MC_PRE_BOMB_UPDATE repentogon/resources/scripts/enums_ex.lua:155 enums/ModCallbacks.md tear and weapons done id 1163 callback ModCallbacks MC_PRE_BOSS_SELECT repentogon/resources/scripts/enums_ex.lua:254 enums/ModCallbacks.md npc todo id 1280 -callback ModCallbacks MC_PRE_BRIMSTONE_SNEEZE repentogon/resources/scripts/enums_ex.lua:38 enums/ModCallbacks.md tear and weapons todo id 1036 -callback ModCallbacks MC_PRE_CHALLENGE_DONE repentogon/resources/scripts/enums_ex.lua:385 enums/ModCallbacks.md game todo id 1471 -callback ModCallbacks MC_PRE_CHANGE_ROOM repentogon/resources/scripts/enums_ex.lua:63 enums/ModCallbacks.md level and room todo id 1061 -callback ModCallbacks MC_PRE_COMPLETION_EVENT repentogon/resources/scripts/enums_ex.lua:51 enums/ModCallbacks.md persistent data and saves todo id 1049 -callback ModCallbacks MC_PRE_COMPLETION_MARKS_RENDER repentogon/resources/scripts/enums_ex.lua:191 enums/ModCallbacks.md persistent data and saves todo id 1216 -callback ModCallbacks MC_PRE_DEVIL_APPLY_ITEMS repentogon/resources/scripts/enums_ex.lua:132 enums/ModCallbacks.md items and pools todo id 1130 -callback ModCallbacks MC_PRE_DEVIL_APPLY_SPECIAL_ITEMS repentogon/resources/scripts/enums_ex.lua:134 enums/ModCallbacks.md items and pools todo id 1132 -callback ModCallbacks MC_PRE_DEVIL_APPLY_STAGE_PENALTY repentogon/resources/scripts/enums_ex.lua:133 enums/ModCallbacks.md level and room todo id 1131 -callback ModCallbacks MC_PRE_EFFECT_RENDER repentogon/resources/scripts/enums_ex.lua:89 enums/ModCallbacks.md render and sprites todo id 1087 -callback ModCallbacks MC_PRE_EFFECT_UPDATE repentogon/resources/scripts/enums_ex.lua:160 enums/ModCallbacks.md game todo id 1168 -callback ModCallbacks MC_PRE_ENTITY_SET_COLOR repentogon/resources/scripts/enums_ex.lua:400 enums/ModCallbacks.md render and sprites todo id 1486 -callback ModCallbacks MC_PRE_ENTITY_THROW repentogon/resources/scripts/enums_ex.lua:42 enums/ModCallbacks.md entities todo id 1040 -callback ModCallbacks MC_PRE_FAMILIAR_CAN_CHARM repentogon/resources/scripts/enums_ex.lua:387 enums/ModCallbacks.md familiar todo id 1473 +callback ModCallbacks MC_PRE_BRIMSTONE_SNEEZE repentogon/resources/scripts/enums_ex.lua:38 enums/ModCallbacks.md tear and weapons done id 1036 +callback ModCallbacks MC_PRE_CHALLENGE_DONE repentogon/resources/scripts/enums_ex.lua:385 enums/ModCallbacks.md game done id 1471 +callback ModCallbacks MC_PRE_CHANGE_ROOM repentogon/resources/scripts/enums_ex.lua:63 enums/ModCallbacks.md level and room done id 1061 +callback ModCallbacks MC_PRE_COMPLETION_EVENT repentogon/resources/scripts/enums_ex.lua:51 enums/ModCallbacks.md persistent data and saves done id 1049 +callback ModCallbacks MC_PRE_COMPLETION_MARKS_RENDER repentogon/resources/scripts/enums_ex.lua:191 enums/ModCallbacks.md persistent data and saves done id 1216 +callback ModCallbacks MC_PRE_DEVIL_APPLY_ITEMS repentogon/resources/scripts/enums_ex.lua:132 enums/ModCallbacks.md items and pools done id 1130 +callback ModCallbacks MC_PRE_DEVIL_APPLY_SPECIAL_ITEMS repentogon/resources/scripts/enums_ex.lua:134 enums/ModCallbacks.md items and pools done id 1132 +callback ModCallbacks MC_PRE_DEVIL_APPLY_STAGE_PENALTY repentogon/resources/scripts/enums_ex.lua:133 enums/ModCallbacks.md level and room done id 1131 +callback ModCallbacks MC_PRE_EFFECT_RENDER repentogon/resources/scripts/enums_ex.lua:89 enums/ModCallbacks.md render and sprites done id 1087 +callback ModCallbacks MC_PRE_EFFECT_UPDATE repentogon/resources/scripts/enums_ex.lua:160 enums/ModCallbacks.md game done id 1168 +callback ModCallbacks MC_PRE_ENTITY_SET_COLOR repentogon/resources/scripts/enums_ex.lua:400 enums/ModCallbacks.md render and sprites done id 1486 +callback ModCallbacks MC_PRE_ENTITY_THROW repentogon/resources/scripts/enums_ex.lua:42 enums/ModCallbacks.md entities done id 1040 +callback ModCallbacks MC_PRE_FAMILIAR_CAN_CHARM repentogon/resources/scripts/enums_ex.lua:387 enums/ModCallbacks.md familiar done id 1473 callback ModCallbacks MC_PRE_FAMILIAR_COLLISION enums/ModCallbacks.md familiar review id 26, vanilla callback REPENTOGON changes -callback ModCallbacks MC_PRE_FAMILIAR_GRID_COLLISION repentogon/resources/scripts/enums_ex.lua:167 enums/ModCallbacks.md familiar todo id 1175 -callback ModCallbacks MC_PRE_FAMILIAR_RENDER repentogon/resources/scripts/enums_ex.lua:82 enums/ModCallbacks.md familiar todo id 1080 -callback ModCallbacks MC_PRE_FAMILIAR_UPDATE repentogon/resources/scripts/enums_ex.lua:154 enums/ModCallbacks.md familiar todo id 1162 -callback ModCallbacks MC_PRE_FORTUNE_DISPLAY repentogon/resources/scripts/enums_ex.lua:397 enums/ModCallbacks.md misc todo id 1483 -callback ModCallbacks MC_PRE_GAME_STATE_RESTORE repentogon/resources/scripts/enums_ex.lua:285 hud and menus todo id 1311 -callback ModCallbacks MC_PRE_GAME_STATE_SAVE repentogon/resources/scripts/enums_ex.lua:283 persistent data and saves todo id 1309 -callback ModCallbacks MC_PRE_GET_LIGHTING_ALPHA repentogon/resources/scripts/enums_ex.lua:148 enums/ModCallbacks.md render and sprites todo id 1150 -callback ModCallbacks MC_PRE_GET_RANDOM_ROOM_INDEX repentogon/resources/scripts/enums_ex.lua:264 enums/ModCallbacks.md level and room todo id 1290 -callback ModCallbacks MC_PRE_GLOWING_HOURGLASS_LOAD repentogon/resources/scripts/enums_ex.lua:277 enums/ModCallbacks.md misc todo id 1303 -callback ModCallbacks MC_PRE_GLOWING_HOURGLASS_SAVE repentogon/resources/scripts/enums_ex.lua:276 enums/ModCallbacks.md persistent data and saves todo id 1302 -callback ModCallbacks MC_PRE_GRID_ENTITY_DECORATION_RENDER repentogon/resources/scripts/enums_ex.lua:360 enums/ModCallbacks.md render and sprites todo id 1444 -callback ModCallbacks MC_PRE_GRID_ENTITY_DECORATION_UPDATE repentogon/resources/scripts/enums_ex.lua:317 enums/ModCallbacks.md level and room todo id 1400 -callback ModCallbacks MC_PRE_GRID_ENTITY_DOOR_RENDER repentogon/resources/scripts/enums_ex.lua:362 enums/ModCallbacks.md render and sprites todo id 1446 -callback ModCallbacks MC_PRE_GRID_ENTITY_DOOR_UPDATE repentogon/resources/scripts/enums_ex.lua:319 enums/ModCallbacks.md level and room todo id 1402 -callback ModCallbacks MC_PRE_GRID_ENTITY_FIRE_RENDER repentogon/resources/scripts/enums_ex.lua:364 enums/ModCallbacks.md tear and weapons todo id 1448 -callback ModCallbacks MC_PRE_GRID_ENTITY_FIRE_UPDATE repentogon/resources/scripts/enums_ex.lua:321 enums/ModCallbacks.md tear and weapons todo id 1404 -callback ModCallbacks MC_PRE_GRID_ENTITY_GRAVITY_UPDATE repentogon/resources/scripts/enums_ex.lua:323 enums/ModCallbacks.md level and room todo id 1406 -callback ModCallbacks MC_PRE_GRID_ENTITY_LOCK_RENDER repentogon/resources/scripts/enums_ex.lua:366 enums/ModCallbacks.md render and sprites todo id 1450 -callback ModCallbacks MC_PRE_GRID_ENTITY_LOCK_UPDATE repentogon/resources/scripts/enums_ex.lua:325 enums/ModCallbacks.md level and room todo id 1408 -callback ModCallbacks MC_PRE_GRID_ENTITY_PIT_RENDER repentogon/resources/scripts/enums_ex.lua:370 enums/ModCallbacks.md render and sprites todo id 1454 -callback ModCallbacks MC_PRE_GRID_ENTITY_PIT_UPDATE repentogon/resources/scripts/enums_ex.lua:327 enums/ModCallbacks.md level and room todo id 1410 -callback ModCallbacks MC_PRE_GRID_ENTITY_POOP_RENDER repentogon/resources/scripts/enums_ex.lua:372 enums/ModCallbacks.md render and sprites todo id 1456 -callback ModCallbacks MC_PRE_GRID_ENTITY_POOP_UPDATE repentogon/resources/scripts/enums_ex.lua:329 enums/ModCallbacks.md level and room todo id 1412 -callback ModCallbacks MC_PRE_GRID_ENTITY_PRESSUREPLATE_RENDER repentogon/resources/scripts/enums_ex.lua:376 enums/ModCallbacks.md render and sprites todo id 1460 -callback ModCallbacks MC_PRE_GRID_ENTITY_PRESSUREPLATE_UPDATE repentogon/resources/scripts/enums_ex.lua:331 enums/ModCallbacks.md level and room todo id 1414 -callback ModCallbacks MC_PRE_GRID_ENTITY_ROCK_RENDER repentogon/resources/scripts/enums_ex.lua:374 enums/ModCallbacks.md render and sprites todo id 1458 -callback ModCallbacks MC_PRE_GRID_ENTITY_ROCK_UPDATE repentogon/resources/scripts/enums_ex.lua:333 enums/ModCallbacks.md level and room todo id 1416 -callback ModCallbacks MC_PRE_GRID_ENTITY_SPAWN repentogon/resources/scripts/enums_ex.lua:102 enums/ModCallbacks.md level and room todo id 1100 -callback ModCallbacks MC_PRE_GRID_ENTITY_SPIKES_RENDER repentogon/resources/scripts/enums_ex.lua:349 enums/ModCallbacks.md render and sprites todo id 1432 -callback ModCallbacks MC_PRE_GRID_ENTITY_SPIKES_UPDATE repentogon/resources/scripts/enums_ex.lua:335 enums/ModCallbacks.md level and room todo id 1418 -callback ModCallbacks MC_PRE_GRID_ENTITY_STAIRCASE_RENDER repentogon/resources/scripts/enums_ex.lua:357 enums/ModCallbacks.md render and sprites todo id 1440 -callback ModCallbacks MC_PRE_GRID_ENTITY_STAIRCASE_UPDATE repentogon/resources/scripts/enums_ex.lua:337 enums/ModCallbacks.md level and room todo id 1420 -callback ModCallbacks MC_PRE_GRID_ENTITY_STATUE_UPDATE repentogon/resources/scripts/enums_ex.lua:339 enums/ModCallbacks.md hud and menus todo id 1422 -callback ModCallbacks MC_PRE_GRID_ENTITY_TELEPORTER_RENDER repentogon/resources/scripts/enums_ex.lua:368 enums/ModCallbacks.md render and sprites todo id 1452 -callback ModCallbacks MC_PRE_GRID_ENTITY_TELEPORTER_UPDATE repentogon/resources/scripts/enums_ex.lua:341 enums/ModCallbacks.md level and room todo id 1424 -callback ModCallbacks MC_PRE_GRID_ENTITY_TNT_RENDER repentogon/resources/scripts/enums_ex.lua:353 enums/ModCallbacks.md render and sprites todo id 1436 -callback ModCallbacks MC_PRE_GRID_ENTITY_TNT_UPDATE repentogon/resources/scripts/enums_ex.lua:347 enums/ModCallbacks.md level and room todo id 1430 -callback ModCallbacks MC_PRE_GRID_ENTITY_TRAPDOOR_RENDER repentogon/resources/scripts/enums_ex.lua:355 enums/ModCallbacks.md render and sprites todo id 1438 -callback ModCallbacks MC_PRE_GRID_ENTITY_TRAPDOOR_UPDATE repentogon/resources/scripts/enums_ex.lua:343 enums/ModCallbacks.md level and room todo id 1426 -callback ModCallbacks MC_PRE_GRID_ENTITY_WALL_RENDER repentogon/resources/scripts/enums_ex.lua:378 enums/ModCallbacks.md render and sprites todo id 1462 -callback ModCallbacks MC_PRE_GRID_ENTITY_WEB_RENDER repentogon/resources/scripts/enums_ex.lua:351 enums/ModCallbacks.md render and sprites todo id 1434 -callback ModCallbacks MC_PRE_GRID_ENTITY_WEB_UPDATE repentogon/resources/scripts/enums_ex.lua:345 enums/ModCallbacks.md level and room todo id 1428 -callback ModCallbacks MC_PRE_GRID_HURT repentogon/resources/scripts/enums_ex.lua:18 enums/ModCallbacks.md level and room todo id 1017 -callback ModCallbacks MC_PRE_HISTORYHUD_RENDER repentogon/resources/scripts/enums_ex.lua:29 enums/ModCallbacks.md hud and menus todo id 1027 -callback ModCallbacks MC_PRE_ITEM_OVERLAY_SHOW repentogon/resources/scripts/enums_ex.lua:78 enums/ModCallbacks.md hud and menus todo id 1076 -callback ModCallbacks MC_PRE_ITEM_TEXT_DISPLAY repentogon/resources/scripts/enums_ex.lua:398 enums/ModCallbacks.md items and pools todo id 1484 +callback ModCallbacks MC_PRE_FAMILIAR_GRID_COLLISION repentogon/resources/scripts/enums_ex.lua:167 enums/ModCallbacks.md familiar done id 1175 +callback ModCallbacks MC_PRE_FAMILIAR_RENDER repentogon/resources/scripts/enums_ex.lua:82 enums/ModCallbacks.md familiar done id 1080 +callback ModCallbacks MC_PRE_FAMILIAR_UPDATE repentogon/resources/scripts/enums_ex.lua:154 enums/ModCallbacks.md familiar done id 1162 +callback ModCallbacks MC_PRE_FORTUNE_DISPLAY repentogon/resources/scripts/enums_ex.lua:397 enums/ModCallbacks.md misc done id 1483 +callback ModCallbacks MC_PRE_GAME_STATE_RESTORE repentogon/resources/scripts/enums_ex.lua:285 hud and menus done id 1311 +callback ModCallbacks MC_PRE_GAME_STATE_SAVE repentogon/resources/scripts/enums_ex.lua:283 persistent data and saves done id 1309 +callback ModCallbacks MC_PRE_GET_LIGHTING_ALPHA repentogon/resources/scripts/enums_ex.lua:148 enums/ModCallbacks.md render and sprites done id 1150 +callback ModCallbacks MC_PRE_GET_RANDOM_ROOM_INDEX repentogon/resources/scripts/enums_ex.lua:264 enums/ModCallbacks.md level and room done id 1290 +callback ModCallbacks MC_PRE_GLOWING_HOURGLASS_LOAD repentogon/resources/scripts/enums_ex.lua:277 enums/ModCallbacks.md misc done id 1303 +callback ModCallbacks MC_PRE_GLOWING_HOURGLASS_SAVE repentogon/resources/scripts/enums_ex.lua:276 enums/ModCallbacks.md persistent data and saves done id 1302 +callback ModCallbacks MC_PRE_GRID_ENTITY_DECORATION_RENDER repentogon/resources/scripts/enums_ex.lua:360 enums/ModCallbacks.md render and sprites done id 1444 +callback ModCallbacks MC_PRE_GRID_ENTITY_DECORATION_UPDATE repentogon/resources/scripts/enums_ex.lua:317 enums/ModCallbacks.md level and room done id 1400 +callback ModCallbacks MC_PRE_GRID_ENTITY_DOOR_RENDER repentogon/resources/scripts/enums_ex.lua:362 enums/ModCallbacks.md render and sprites done id 1446 +callback ModCallbacks MC_PRE_GRID_ENTITY_DOOR_UPDATE repentogon/resources/scripts/enums_ex.lua:319 enums/ModCallbacks.md level and room done id 1402 +callback ModCallbacks MC_PRE_GRID_ENTITY_FIRE_RENDER repentogon/resources/scripts/enums_ex.lua:364 enums/ModCallbacks.md tear and weapons done id 1448 +callback ModCallbacks MC_PRE_GRID_ENTITY_FIRE_UPDATE repentogon/resources/scripts/enums_ex.lua:321 enums/ModCallbacks.md tear and weapons done id 1404 +callback ModCallbacks MC_PRE_GRID_ENTITY_GRAVITY_UPDATE repentogon/resources/scripts/enums_ex.lua:323 enums/ModCallbacks.md level and room done id 1406 +callback ModCallbacks MC_PRE_GRID_ENTITY_LOCK_RENDER repentogon/resources/scripts/enums_ex.lua:366 enums/ModCallbacks.md render and sprites done id 1450 +callback ModCallbacks MC_PRE_GRID_ENTITY_LOCK_UPDATE repentogon/resources/scripts/enums_ex.lua:325 enums/ModCallbacks.md level and room done id 1408 +callback ModCallbacks MC_PRE_GRID_ENTITY_PIT_RENDER repentogon/resources/scripts/enums_ex.lua:370 enums/ModCallbacks.md render and sprites done id 1454 +callback ModCallbacks MC_PRE_GRID_ENTITY_PIT_UPDATE repentogon/resources/scripts/enums_ex.lua:327 enums/ModCallbacks.md level and room done id 1410 +callback ModCallbacks MC_PRE_GRID_ENTITY_POOP_RENDER repentogon/resources/scripts/enums_ex.lua:372 enums/ModCallbacks.md render and sprites done id 1456 +callback ModCallbacks MC_PRE_GRID_ENTITY_POOP_UPDATE repentogon/resources/scripts/enums_ex.lua:329 enums/ModCallbacks.md level and room done id 1412 +callback ModCallbacks MC_PRE_GRID_ENTITY_PRESSUREPLATE_RENDER repentogon/resources/scripts/enums_ex.lua:376 enums/ModCallbacks.md render and sprites done id 1460 +callback ModCallbacks MC_PRE_GRID_ENTITY_PRESSUREPLATE_UPDATE repentogon/resources/scripts/enums_ex.lua:331 enums/ModCallbacks.md level and room done id 1414 +callback ModCallbacks MC_PRE_GRID_ENTITY_ROCK_RENDER repentogon/resources/scripts/enums_ex.lua:374 enums/ModCallbacks.md render and sprites done id 1458 +callback ModCallbacks MC_PRE_GRID_ENTITY_ROCK_UPDATE repentogon/resources/scripts/enums_ex.lua:333 enums/ModCallbacks.md level and room done id 1416 +callback ModCallbacks MC_PRE_GRID_ENTITY_SPAWN repentogon/resources/scripts/enums_ex.lua:102 enums/ModCallbacks.md level and room done id 1100 +callback ModCallbacks MC_PRE_GRID_ENTITY_SPIKES_RENDER repentogon/resources/scripts/enums_ex.lua:349 enums/ModCallbacks.md render and sprites done id 1432 +callback ModCallbacks MC_PRE_GRID_ENTITY_SPIKES_UPDATE repentogon/resources/scripts/enums_ex.lua:335 enums/ModCallbacks.md level and room done id 1418 +callback ModCallbacks MC_PRE_GRID_ENTITY_STAIRCASE_RENDER repentogon/resources/scripts/enums_ex.lua:357 enums/ModCallbacks.md render and sprites done id 1440 +callback ModCallbacks MC_PRE_GRID_ENTITY_STAIRCASE_UPDATE repentogon/resources/scripts/enums_ex.lua:337 enums/ModCallbacks.md level and room done id 1420 +callback ModCallbacks MC_PRE_GRID_ENTITY_STATUE_UPDATE repentogon/resources/scripts/enums_ex.lua:339 enums/ModCallbacks.md hud and menus done id 1422 +callback ModCallbacks MC_PRE_GRID_ENTITY_TELEPORTER_RENDER repentogon/resources/scripts/enums_ex.lua:368 enums/ModCallbacks.md render and sprites done id 1452 +callback ModCallbacks MC_PRE_GRID_ENTITY_TELEPORTER_UPDATE repentogon/resources/scripts/enums_ex.lua:341 enums/ModCallbacks.md level and room done id 1424 +callback ModCallbacks MC_PRE_GRID_ENTITY_TNT_RENDER repentogon/resources/scripts/enums_ex.lua:353 enums/ModCallbacks.md render and sprites done id 1436 +callback ModCallbacks MC_PRE_GRID_ENTITY_TNT_UPDATE repentogon/resources/scripts/enums_ex.lua:347 enums/ModCallbacks.md level and room done id 1430 +callback ModCallbacks MC_PRE_GRID_ENTITY_TRAPDOOR_RENDER repentogon/resources/scripts/enums_ex.lua:355 enums/ModCallbacks.md render and sprites done id 1438 +callback ModCallbacks MC_PRE_GRID_ENTITY_TRAPDOOR_UPDATE repentogon/resources/scripts/enums_ex.lua:343 enums/ModCallbacks.md level and room done id 1426 +callback ModCallbacks MC_PRE_GRID_ENTITY_WALL_RENDER repentogon/resources/scripts/enums_ex.lua:378 enums/ModCallbacks.md render and sprites done id 1462 +callback ModCallbacks MC_PRE_GRID_ENTITY_WEB_RENDER repentogon/resources/scripts/enums_ex.lua:351 enums/ModCallbacks.md render and sprites done id 1434 +callback ModCallbacks MC_PRE_GRID_ENTITY_WEB_UPDATE repentogon/resources/scripts/enums_ex.lua:345 enums/ModCallbacks.md level and room done id 1428 +callback ModCallbacks MC_PRE_GRID_HURT repentogon/resources/scripts/enums_ex.lua:18 enums/ModCallbacks.md level and room done id 1017 +callback ModCallbacks MC_PRE_HISTORYHUD_RENDER repentogon/resources/scripts/enums_ex.lua:29 enums/ModCallbacks.md hud and menus done id 1027 +callback ModCallbacks MC_PRE_ITEM_OVERLAY_SHOW repentogon/resources/scripts/enums_ex.lua:78 enums/ModCallbacks.md hud and menus done id 1076 +callback ModCallbacks MC_PRE_ITEM_TEXT_DISPLAY repentogon/resources/scripts/enums_ex.lua:398 enums/ModCallbacks.md items and pools done id 1484 callback ModCallbacks MC_PRE_KNIFE_COLLISION enums/ModCallbacks.md tear and weapons review id 53, vanilla callback REPENTOGON changes -callback ModCallbacks MC_PRE_KNIFE_RENDER repentogon/resources/scripts/enums_ex.lua:88 enums/ModCallbacks.md tear and weapons todo id 1086 -callback ModCallbacks MC_PRE_KNIFE_UPDATE repentogon/resources/scripts/enums_ex.lua:157 enums/ModCallbacks.md tear and weapons todo id 1165 -callback ModCallbacks MC_PRE_LASER_COLLISION repentogon/resources/scripts/enums_ex.lua:222 enums/ModCallbacks.md tear and weapons todo id 1248 -callback ModCallbacks MC_PRE_LASER_UPDATE repentogon/resources/scripts/enums_ex.lua:159 enums/ModCallbacks.md tear and weapons todo id 1167 -callback ModCallbacks MC_PRE_LEVEL_INIT repentogon/resources/scripts/enums_ex.lua:62 enums/ModCallbacks.md level and room todo id 1060 -callback ModCallbacks MC_PRE_LEVEL_PLACE_ROOM repentogon/resources/scripts/enums_ex.lua:139 enums/ModCallbacks.md level and room todo id 1137 -callback ModCallbacks MC_PRE_LEVEL_SELECT repentogon/resources/scripts/enums_ex.lua:106 enums/ModCallbacks.md level and room todo id 1104 -callback ModCallbacks MC_PRE_MEGA_SATAN_ENDING repentogon/resources/scripts/enums_ex.lua:183 enums/ModCallbacks.md misc todo id 1201 -callback ModCallbacks MC_PRE_MINIMAP_RENDER repentogon/resources/scripts/enums_ex.lua:393 hud and menus todo id 1479 -callback ModCallbacks MC_PRE_MINIMAP_UPDATE repentogon/resources/scripts/enums_ex.lua:391 hud and menus todo id 1477 -callback ModCallbacks MC_PRE_MOD_UNLOAD enums/ModCallbacks.md misc todo id 73, vanilla callback REPENTOGON changes -callback ModCallbacks MC_PRE_MUSIC_LAYER_TOGGLE repentogon/resources/scripts/enums_ex.lua:37 enums/ModCallbacks.md audio todo id 1035 -callback ModCallbacks MC_PRE_MUSIC_PLAY repentogon/resources/scripts/enums_ex.lua:36 enums/ModCallbacks.md audio todo id 1034 -callback ModCallbacks MC_PRE_MUSIC_PLAY_JINGLE repentogon/resources/scripts/enums_ex.lua:96 enums/ModCallbacks.md audio todo id 1094 -callback ModCallbacks MC_PRE_M_MORPH_ACTIVE repentogon/resources/scripts/enums_ex.lua:178 enums/ModCallbacks.md misc todo id 1190 -callback ModCallbacks MC_PRE_NEW_ROOM repentogon/resources/scripts/enums_ex.lua:182 enums/ModCallbacks.md level and room todo id 1200 +callback ModCallbacks MC_PRE_KNIFE_RENDER repentogon/resources/scripts/enums_ex.lua:88 enums/ModCallbacks.md tear and weapons done id 1086 +callback ModCallbacks MC_PRE_KNIFE_UPDATE repentogon/resources/scripts/enums_ex.lua:157 enums/ModCallbacks.md tear and weapons done id 1165 +callback ModCallbacks MC_PRE_LASER_COLLISION repentogon/resources/scripts/enums_ex.lua:222 enums/ModCallbacks.md tear and weapons done id 1248 +callback ModCallbacks MC_PRE_LASER_UPDATE repentogon/resources/scripts/enums_ex.lua:159 enums/ModCallbacks.md tear and weapons done id 1167 +callback ModCallbacks MC_PRE_LEVEL_INIT repentogon/resources/scripts/enums_ex.lua:62 enums/ModCallbacks.md level and room done id 1060 +callback ModCallbacks MC_PRE_LEVEL_PLACE_ROOM repentogon/resources/scripts/enums_ex.lua:139 enums/ModCallbacks.md level and room done id 1137 +callback ModCallbacks MC_PRE_LEVEL_SELECT repentogon/resources/scripts/enums_ex.lua:106 enums/ModCallbacks.md level and room done id 1104 +callback ModCallbacks MC_PRE_MEGA_SATAN_ENDING repentogon/resources/scripts/enums_ex.lua:183 enums/ModCallbacks.md misc done id 1201 +callback ModCallbacks MC_PRE_MINIMAP_RENDER repentogon/resources/scripts/enums_ex.lua:393 hud and menus done id 1479 +callback ModCallbacks MC_PRE_MINIMAP_UPDATE repentogon/resources/scripts/enums_ex.lua:391 hud and menus done id 1477 +callback ModCallbacks MC_PRE_MOD_UNLOAD enums/ModCallbacks.md misc review id 73, vanilla callback REPENTOGON changes +callback ModCallbacks MC_PRE_MUSIC_LAYER_TOGGLE repentogon/resources/scripts/enums_ex.lua:37 enums/ModCallbacks.md audio done id 1035 +callback ModCallbacks MC_PRE_MUSIC_PLAY repentogon/resources/scripts/enums_ex.lua:36 enums/ModCallbacks.md audio done id 1034 +callback ModCallbacks MC_PRE_MUSIC_PLAY_JINGLE repentogon/resources/scripts/enums_ex.lua:96 enums/ModCallbacks.md audio done id 1094 +callback ModCallbacks MC_PRE_M_MORPH_ACTIVE repentogon/resources/scripts/enums_ex.lua:178 enums/ModCallbacks.md misc done id 1190 +callback ModCallbacks MC_PRE_NEW_ROOM repentogon/resources/scripts/enums_ex.lua:182 enums/ModCallbacks.md level and room done id 1200 callback ModCallbacks MC_PRE_NPC_COLLISION enums/ModCallbacks.md npc review id 30, vanilla callback REPENTOGON changes callback ModCallbacks MC_PRE_NPC_GET_LOOT_LIST repentogon/resources/scripts/enums_ex.lua:300 npc todo id 1337 -callback ModCallbacks MC_PRE_NPC_GRID_COLLISION repentogon/resources/scripts/enums_ex.lua:175 enums/ModCallbacks.md npc todo id 1183 -callback ModCallbacks MC_PRE_NPC_MORPH repentogon/resources/scripts/enums_ex.lua:187 enums/ModCallbacks.md npc todo id 1212 -callback ModCallbacks MC_PRE_NPC_RENDER repentogon/resources/scripts/enums_ex.lua:83 enums/ModCallbacks.md npc todo id 1081 -callback ModCallbacks MC_PRE_NPC_SPLIT repentogon/resources/scripts/enums_ex.lua:179 enums/ModCallbacks.md npc todo id 1191 -callback ModCallbacks MC_PRE_NPC_UPDATE_GHOST_PICKUPS repentogon/resources/scripts/enums_ex.lua:301 npc todo id 1338 +callback ModCallbacks MC_PRE_NPC_GRID_COLLISION repentogon/resources/scripts/enums_ex.lua:175 enums/ModCallbacks.md npc done id 1183 +callback ModCallbacks MC_PRE_NPC_MORPH repentogon/resources/scripts/enums_ex.lua:187 enums/ModCallbacks.md npc done id 1212 +callback ModCallbacks MC_PRE_NPC_RENDER repentogon/resources/scripts/enums_ex.lua:83 enums/ModCallbacks.md npc done id 1081 +callback ModCallbacks MC_PRE_NPC_SPLIT repentogon/resources/scripts/enums_ex.lua:179 enums/ModCallbacks.md npc done id 1191 +callback ModCallbacks MC_PRE_NPC_UPDATE_GHOST_PICKUPS repentogon/resources/scripts/enums_ex.lua:301 npc done id 1338 callback ModCallbacks MC_PRE_OPENGL_RENDER repentogon/resources/scripts/enums_ex.lua:138 render and sprites todo id 1136 -callback ModCallbacks MC_PRE_OPEN_CHEST repentogon/resources/scripts/enums_ex.lua:405 enums/ModCallbacks.md misc todo id 1491 -callback ModCallbacks MC_PRE_PAUSE_SCREEN_RENDER repentogon/resources/scripts/enums_ex.lua:193 enums/ModCallbacks.md hud and menus todo id 1218 +callback ModCallbacks MC_PRE_OPEN_CHEST repentogon/resources/scripts/enums_ex.lua:405 enums/ModCallbacks.md misc done id 1491 +callback ModCallbacks MC_PRE_PAUSE_SCREEN_RENDER repentogon/resources/scripts/enums_ex.lua:193 enums/ModCallbacks.md hud and menus done id 1218 callback ModCallbacks MC_PRE_PICKUP_COLLISION enums/ModCallbacks.md pickup review id 38, vanilla callback REPENTOGON changes -callback ModCallbacks MC_PRE_PICKUP_COMPOSTED repentogon/resources/scripts/enums_ex.lua:241 enums/ModCallbacks.md pickup todo id 1267 +callback ModCallbacks MC_PRE_PICKUP_COMPOSTED repentogon/resources/scripts/enums_ex.lua:241 enums/ModCallbacks.md pickup done id 1267 callback ModCallbacks MC_PRE_PICKUP_GET_LOOT_LIST repentogon/resources/scripts/enums_ex.lua:297 enums/ModCallbacks.md pickup todo id 1334 -callback ModCallbacks MC_PRE_PICKUP_GRID_COLLISION repentogon/resources/scripts/enums_ex.lua:171 enums/ModCallbacks.md pickup todo id 1179 -callback ModCallbacks MC_PRE_PICKUP_MORPH repentogon/resources/scripts/enums_ex.lua:188 enums/ModCallbacks.md pickup todo id 1213 -callback ModCallbacks MC_PRE_PICKUP_RENDER repentogon/resources/scripts/enums_ex.lua:85 enums/ModCallbacks.md pickup todo id 1083 -callback ModCallbacks MC_PRE_PICKUP_UPDATE repentogon/resources/scripts/enums_ex.lua:156 enums/ModCallbacks.md pickup todo id 1164 -callback ModCallbacks MC_PRE_PICKUP_UPDATE_GHOST_PICKUPS repentogon/resources/scripts/enums_ex.lua:298 enums/ModCallbacks.md pickup todo id 1335 -callback ModCallbacks MC_PRE_PICKUP_VOIDED repentogon/resources/scripts/enums_ex.lua:239 enums/ModCallbacks.md pickup todo id 1265 -callback ModCallbacks MC_PRE_PICKUP_VOIDED_ABYSS repentogon/resources/scripts/enums_ex.lua:240 enums/ModCallbacks.md pickup todo id 1266 -callback ModCallbacks MC_PRE_PLANETARIUM_APPLY_ITEMS repentogon/resources/scripts/enums_ex.lua:115 enums/ModCallbacks.md items and pools todo id 1113 -callback ModCallbacks MC_PRE_PLANETARIUM_APPLY_PLANETARIUM_PENALTY repentogon/resources/scripts/enums_ex.lua:113 enums/ModCallbacks.md items and pools todo id 1111 -callback ModCallbacks MC_PRE_PLANETARIUM_APPLY_STAGE_PENALTY repentogon/resources/scripts/enums_ex.lua:112 enums/ModCallbacks.md level and room todo id 1110 -callback ModCallbacks MC_PRE_PLANETARIUM_APPLY_TELESCOPE_LENS repentogon/resources/scripts/enums_ex.lua:116 enums/ModCallbacks.md items and pools todo id 1114 -callback ModCallbacks MC_PRE_PLANETARIUM_APPLY_TREASURE_PENALTY repentogon/resources/scripts/enums_ex.lua:114 enums/ModCallbacks.md items and pools todo id 1112 -callback ModCallbacks MC_PRE_PLAYERHUD_RENDER_ACTIVE_ITEM repentogon/resources/scripts/enums_ex.lua:121 enums/ModCallbacks.md player todo id 1119 -callback ModCallbacks MC_PRE_PLAYERHUD_RENDER_CRAFTING_TABLE repentogon/resources/scripts/enums_ex.lua:271 enums/ModCallbacks.md player todo id 1297 -callback ModCallbacks MC_PRE_PLAYERHUD_RENDER_HEARTS repentogon/resources/scripts/enums_ex.lua:120 enums/ModCallbacks.md player todo id 1118 -callback ModCallbacks MC_PRE_PLAYERHUD_RENDER_INVENTORY repentogon/resources/scripts/enums_ex.lua:267 enums/ModCallbacks.md player todo id 1293 -callback ModCallbacks MC_PRE_PLAYERHUD_RENDER_POOP_SPELL_QUEUE repentogon/resources/scripts/enums_ex.lua:269 enums/ModCallbacks.md player todo id 1295 -callback ModCallbacks MC_PRE_PLAYERHUD_TRINKET_RENDER repentogon/resources/scripts/enums_ex.lua:238 enums/ModCallbacks.md player todo id 1264 -callback ModCallbacks MC_PRE_PLAYER_ADD_CARD repentogon/resources/scripts/enums_ex.lua:304 enums/ModCallbacks.md player todo id 1350 -callback ModCallbacks MC_PRE_PLAYER_ADD_COSTUME repentogon/resources/scripts/enums_ex.lua:255 enums/ModCallbacks.md player todo id 1281 -callback ModCallbacks MC_PRE_PLAYER_ADD_HEARTS repentogon/resources/scripts/enums_ex.lua:10 enums/ModCallbacks.md player todo id 1009 -callback ModCallbacks MC_PRE_PLAYER_ADD_PILL repentogon/resources/scripts/enums_ex.lua:306 enums/ModCallbacks.md player todo id 1352 -callback ModCallbacks MC_PRE_PLAYER_APPLY_INNATE_COLLECTIBLE_NUM repentogon/resources/scripts/enums_ex.lua:94 player todo id 1092 -callback ModCallbacks MC_PRE_PLAYER_COLLECT_CARD repentogon/resources/scripts/enums_ex.lua:310 enums/ModCallbacks.md player todo id 1356 -callback ModCallbacks MC_PRE_PLAYER_COLLECT_PILL repentogon/resources/scripts/enums_ex.lua:312 enums/ModCallbacks.md player todo id 1358 +callback ModCallbacks MC_PRE_PICKUP_GRID_COLLISION repentogon/resources/scripts/enums_ex.lua:171 enums/ModCallbacks.md pickup done id 1179 +callback ModCallbacks MC_PRE_PICKUP_MORPH repentogon/resources/scripts/enums_ex.lua:188 enums/ModCallbacks.md pickup done id 1213 +callback ModCallbacks MC_PRE_PICKUP_RENDER repentogon/resources/scripts/enums_ex.lua:85 enums/ModCallbacks.md pickup done id 1083 +callback ModCallbacks MC_PRE_PICKUP_UPDATE repentogon/resources/scripts/enums_ex.lua:156 enums/ModCallbacks.md pickup done id 1164 +callback ModCallbacks MC_PRE_PICKUP_UPDATE_GHOST_PICKUPS repentogon/resources/scripts/enums_ex.lua:298 enums/ModCallbacks.md pickup done id 1335 +callback ModCallbacks MC_PRE_PICKUP_VOIDED repentogon/resources/scripts/enums_ex.lua:239 enums/ModCallbacks.md pickup done id 1265 +callback ModCallbacks MC_PRE_PICKUP_VOIDED_ABYSS repentogon/resources/scripts/enums_ex.lua:240 enums/ModCallbacks.md pickup done id 1266 +callback ModCallbacks MC_PRE_PLANETARIUM_APPLY_ITEMS repentogon/resources/scripts/enums_ex.lua:115 enums/ModCallbacks.md items and pools done id 1113 +callback ModCallbacks MC_PRE_PLANETARIUM_APPLY_PLANETARIUM_PENALTY repentogon/resources/scripts/enums_ex.lua:113 enums/ModCallbacks.md items and pools done id 1111 +callback ModCallbacks MC_PRE_PLANETARIUM_APPLY_STAGE_PENALTY repentogon/resources/scripts/enums_ex.lua:112 enums/ModCallbacks.md level and room done id 1110 +callback ModCallbacks MC_PRE_PLANETARIUM_APPLY_TELESCOPE_LENS repentogon/resources/scripts/enums_ex.lua:116 enums/ModCallbacks.md items and pools done id 1114 +callback ModCallbacks MC_PRE_PLANETARIUM_APPLY_TREASURE_PENALTY repentogon/resources/scripts/enums_ex.lua:114 enums/ModCallbacks.md items and pools done id 1112 +callback ModCallbacks MC_PRE_PLAYERHUD_RENDER_ACTIVE_ITEM repentogon/resources/scripts/enums_ex.lua:121 enums/ModCallbacks.md player done id 1119 +callback ModCallbacks MC_PRE_PLAYERHUD_RENDER_CRAFTING_TABLE repentogon/resources/scripts/enums_ex.lua:271 enums/ModCallbacks.md player done id 1297 +callback ModCallbacks MC_PRE_PLAYERHUD_RENDER_HEARTS repentogon/resources/scripts/enums_ex.lua:120 enums/ModCallbacks.md player done id 1118 +callback ModCallbacks MC_PRE_PLAYERHUD_RENDER_INVENTORY repentogon/resources/scripts/enums_ex.lua:267 enums/ModCallbacks.md player done id 1293 +callback ModCallbacks MC_PRE_PLAYERHUD_RENDER_POOP_SPELL_QUEUE repentogon/resources/scripts/enums_ex.lua:269 enums/ModCallbacks.md player done id 1295 +callback ModCallbacks MC_PRE_PLAYERHUD_TRINKET_RENDER repentogon/resources/scripts/enums_ex.lua:238 enums/ModCallbacks.md player done id 1264 +callback ModCallbacks MC_PRE_PLAYER_ADD_CARD repentogon/resources/scripts/enums_ex.lua:304 enums/ModCallbacks.md player done id 1350 +callback ModCallbacks MC_PRE_PLAYER_ADD_COSTUME repentogon/resources/scripts/enums_ex.lua:255 enums/ModCallbacks.md player done id 1281 +callback ModCallbacks MC_PRE_PLAYER_ADD_HEARTS repentogon/resources/scripts/enums_ex.lua:10 enums/ModCallbacks.md player done id 1009 +callback ModCallbacks MC_PRE_PLAYER_ADD_PILL repentogon/resources/scripts/enums_ex.lua:306 enums/ModCallbacks.md player done id 1352 +callback ModCallbacks MC_PRE_PLAYER_APPLY_INNATE_COLLECTIBLE_NUM repentogon/resources/scripts/enums_ex.lua:94 player done id 1092 +callback ModCallbacks MC_PRE_PLAYER_COLLECT_CARD repentogon/resources/scripts/enums_ex.lua:310 enums/ModCallbacks.md player done id 1356 +callback ModCallbacks MC_PRE_PLAYER_COLLECT_PILL repentogon/resources/scripts/enums_ex.lua:312 enums/ModCallbacks.md player done id 1358 callback ModCallbacks MC_PRE_PLAYER_COLLISION enums/ModCallbacks.md player review id 33, vanilla callback REPENTOGON changes -callback ModCallbacks MC_PRE_PLAYER_GIVE_BIRTH_CAMBION repentogon/resources/scripts/enums_ex.lua:388 enums/ModCallbacks.md player todo id 1474 -callback ModCallbacks MC_PRE_PLAYER_GIVE_BIRTH_IMMACULATE repentogon/resources/scripts/enums_ex.lua:389 enums/ModCallbacks.md player todo id 1475 -callback ModCallbacks MC_PRE_PLAYER_GRID_COLLISION repentogon/resources/scripts/enums_ex.lua:163 enums/ModCallbacks.md player todo id 1171 -callback ModCallbacks MC_PRE_PLAYER_POCKET_ITEMS_SWAP repentogon/resources/scripts/enums_ex.lua:261 enums/ModCallbacks.md player todo id 1287 -callback ModCallbacks MC_PRE_PLAYER_REMOVE_COSTUME repentogon/resources/scripts/enums_ex.lua:256 enums/ModCallbacks.md player todo id 1282 -callback ModCallbacks MC_PRE_PLAYER_RENDER repentogon/resources/scripts/enums_ex.lua:84 enums/ModCallbacks.md player todo id 1082 -callback ModCallbacks MC_PRE_PLAYER_REVIVE repentogon/resources/scripts/enums_ex.lua:395 enums/ModCallbacks.md player todo id 1481 -callback ModCallbacks MC_PRE_PLAYER_TAKE_DMG repentogon/resources/scripts/enums_ex.lua:9 enums/ModCallbacks.md player todo id 1008 -callback ModCallbacks MC_PRE_PLAYER_TRIGGER_ROOM_CLEAR repentogon/resources/scripts/enums_ex.lua:71 enums/ModCallbacks.md player todo id 1069 -callback ModCallbacks MC_PRE_PLAYER_UPDATE repentogon/resources/scripts/enums_ex.lua:152 enums/ModCallbacks.md player todo id 1160 -callback ModCallbacks MC_PRE_PLAYER_USE_BOMB repentogon/resources/scripts/enums_ex.lua:195 enums/ModCallbacks.md player todo id 1220 +callback ModCallbacks MC_PRE_PLAYER_GIVE_BIRTH_CAMBION repentogon/resources/scripts/enums_ex.lua:388 enums/ModCallbacks.md player done id 1474 +callback ModCallbacks MC_PRE_PLAYER_GIVE_BIRTH_IMMACULATE repentogon/resources/scripts/enums_ex.lua:389 enums/ModCallbacks.md player done id 1475 +callback ModCallbacks MC_PRE_PLAYER_GRID_COLLISION repentogon/resources/scripts/enums_ex.lua:163 enums/ModCallbacks.md player done id 1171 +callback ModCallbacks MC_PRE_PLAYER_POCKET_ITEMS_SWAP repentogon/resources/scripts/enums_ex.lua:261 enums/ModCallbacks.md player done id 1287 +callback ModCallbacks MC_PRE_PLAYER_REMOVE_COSTUME repentogon/resources/scripts/enums_ex.lua:256 enums/ModCallbacks.md player done id 1282 +callback ModCallbacks MC_PRE_PLAYER_RENDER repentogon/resources/scripts/enums_ex.lua:84 enums/ModCallbacks.md player done id 1082 +callback ModCallbacks MC_PRE_PLAYER_REVIVE repentogon/resources/scripts/enums_ex.lua:395 enums/ModCallbacks.md player done id 1481 +callback ModCallbacks MC_PRE_PLAYER_TAKE_DMG repentogon/resources/scripts/enums_ex.lua:9 enums/ModCallbacks.md player done id 1008 +callback ModCallbacks MC_PRE_PLAYER_TRIGGER_ROOM_CLEAR repentogon/resources/scripts/enums_ex.lua:71 enums/ModCallbacks.md player done id 1069 +callback ModCallbacks MC_PRE_PLAYER_UPDATE repentogon/resources/scripts/enums_ex.lua:152 enums/ModCallbacks.md player done id 1160 +callback ModCallbacks MC_PRE_PLAYER_USE_BOMB repentogon/resources/scripts/enums_ex.lua:195 enums/ModCallbacks.md player done id 1220 callback ModCallbacks MC_PRE_PROJECTILE_COLLISION enums/ModCallbacks.md tear and weapons review id 46, vanilla callback REPENTOGON changes -callback ModCallbacks MC_PRE_PROJECTILE_GRID_COLLISION repentogon/resources/scripts/enums_ex.lua:173 enums/ModCallbacks.md tear and weapons todo id 1181 -callback ModCallbacks MC_PRE_PROJECTILE_RENDER repentogon/resources/scripts/enums_ex.lua:87 enums/ModCallbacks.md tear and weapons todo id 1085 -callback ModCallbacks MC_PRE_PROJECTILE_UPDATE repentogon/resources/scripts/enums_ex.lua:158 enums/ModCallbacks.md tear and weapons todo id 1166 -callback ModCallbacks MC_PRE_RENDER repentogon/resources/scripts/enums_ex.lua:137 enums/ModCallbacks.md render and sprites todo id 1135 -callback ModCallbacks MC_PRE_RENDER_CHARACTER_SELECT_PAGE repentogon/resources/scripts/enums_ex.lua:292 enums/ModCallbacks.md render and sprites todo id 1329 -callback ModCallbacks MC_PRE_RENDER_CHARACTER_SELECT_PORTRAIT repentogon/resources/scripts/enums_ex.lua:294 enums/ModCallbacks.md render and sprites todo id 1331 -callback ModCallbacks MC_PRE_RENDER_CUSTOM_CHARACTER_MENU repentogon/resources/scripts/enums_ex.lua:296 hud and menus todo id 1333 -callback ModCallbacks MC_PRE_RENDER_ENTITY_LIGHTING repentogon/resources/scripts/enums_ex.lua:150 enums/ModCallbacks.md render and sprites todo id 1152 -callback ModCallbacks MC_PRE_RENDER_GRID_LIGHTING repentogon/resources/scripts/enums_ex.lua:149 enums/ModCallbacks.md render and sprites todo id 1151 -callback ModCallbacks MC_PRE_RENDER_PLAYER_BODY repentogon/resources/scripts/enums_ex.lua:41 enums/ModCallbacks.md player todo id 1039 -callback ModCallbacks MC_PRE_RENDER_PLAYER_HEAD repentogon/resources/scripts/enums_ex.lua:40 enums/ModCallbacks.md player todo id 1038 -callback ModCallbacks MC_PRE_REPLACE_SPRITESHEET repentogon/resources/scripts/enums_ex.lua:118 enums/ModCallbacks.md render and sprites todo id 1116 -callback ModCallbacks MC_PRE_RESTOCK_SHOP repentogon/resources/scripts/enums_ex.lua:72 enums/ModCallbacks.md items and pools todo id 1070 -callback ModCallbacks MC_PRE_ROOM_COLLISION_PASS repentogon/resources/scripts/enums_ex.lua:202 enums/ModCallbacks.md level and room todo id 1227 -callback ModCallbacks MC_PRE_ROOM_EXIT repentogon/resources/scripts/enums_ex.lua:45 enums/ModCallbacks.md level and room todo id 1043 -callback ModCallbacks MC_PRE_ROOM_GRID_ENTITY_SPAWN repentogon/resources/scripts/enums_ex.lua:180 enums/ModCallbacks.md level and room todo id 1192 -callback ModCallbacks MC_PRE_ROOM_RESTORE_STATE repentogon/resources/scripts/enums_ex.lua:279 enums/ModCallbacks.md hud and menus todo id 1305 -callback ModCallbacks MC_PRE_ROOM_TRIGGER_CLEAR repentogon/resources/scripts/enums_ex.lua:70 enums/ModCallbacks.md level and room todo id 1068 -callback ModCallbacks MC_PRE_SELECT_AMBUSH_WAVE repentogon/resources/scripts/enums_ex.lua:60 level and room todo id 1058 -callback ModCallbacks MC_PRE_SELECT_GREED_WAVE repentogon/resources/scripts/enums_ex.lua:61 level and room todo id 1059 -callback ModCallbacks MC_PRE_SFX_PLAY repentogon/resources/scripts/enums_ex.lua:32 enums/ModCallbacks.md audio todo id 1030 -callback ModCallbacks MC_PRE_SHUFFLE_COSTUMES repentogon/resources/scripts/enums_ex.lua:408 enums/ModCallbacks.md player todo id 1494 -callback ModCallbacks MC_PRE_SLOT_COLLISION repentogon/resources/scripts/enums_ex.lua:214 enums/ModCallbacks.md pickup todo id 1240 -callback ModCallbacks MC_PRE_SLOT_CREATE_EXPLOSION_DROPS repentogon/resources/scripts/enums_ex.lua:125 enums/ModCallbacks.md pickup todo id 1123 -callback ModCallbacks MC_PRE_SLOT_RENDER repentogon/resources/scripts/enums_ex.lua:91 enums/ModCallbacks.md pickup todo id 1089 -callback ModCallbacks MC_PRE_SLOT_SET_PRIZE_COLLECTIBLE repentogon/resources/scripts/enums_ex.lua:127 enums/ModCallbacks.md pickup todo id 1125 -callback ModCallbacks MC_PRE_SLOT_UPDATE repentogon/resources/scripts/enums_ex.lua:161 enums/ModCallbacks.md pickup todo id 1169 -callback ModCallbacks MC_PRE_STATUS_EFFECT_APPLY repentogon/resources/scripts/enums_ex.lua:381 enums/ModCallbacks.md hud and menus todo id 1465 +callback ModCallbacks MC_PRE_PROJECTILE_GRID_COLLISION repentogon/resources/scripts/enums_ex.lua:173 enums/ModCallbacks.md tear and weapons done id 1181 +callback ModCallbacks MC_PRE_PROJECTILE_RENDER repentogon/resources/scripts/enums_ex.lua:87 enums/ModCallbacks.md tear and weapons done id 1085 +callback ModCallbacks MC_PRE_PROJECTILE_UPDATE repentogon/resources/scripts/enums_ex.lua:158 enums/ModCallbacks.md tear and weapons done id 1166 +callback ModCallbacks MC_PRE_RENDER repentogon/resources/scripts/enums_ex.lua:137 enums/ModCallbacks.md render and sprites done id 1135 +callback ModCallbacks MC_PRE_RENDER_CHARACTER_SELECT_PAGE repentogon/resources/scripts/enums_ex.lua:292 enums/ModCallbacks.md render and sprites done id 1329 +callback ModCallbacks MC_PRE_RENDER_CHARACTER_SELECT_PORTRAIT repentogon/resources/scripts/enums_ex.lua:294 enums/ModCallbacks.md render and sprites done id 1331 +callback ModCallbacks MC_PRE_RENDER_CUSTOM_CHARACTER_MENU repentogon/resources/scripts/enums_ex.lua:296 hud and menus done id 1333 +callback ModCallbacks MC_PRE_RENDER_ENTITY_LIGHTING repentogon/resources/scripts/enums_ex.lua:150 enums/ModCallbacks.md render and sprites done id 1152 +callback ModCallbacks MC_PRE_RENDER_GRID_LIGHTING repentogon/resources/scripts/enums_ex.lua:149 enums/ModCallbacks.md render and sprites done id 1151 +callback ModCallbacks MC_PRE_RENDER_PLAYER_BODY repentogon/resources/scripts/enums_ex.lua:41 enums/ModCallbacks.md player done id 1039 +callback ModCallbacks MC_PRE_RENDER_PLAYER_HEAD repentogon/resources/scripts/enums_ex.lua:40 enums/ModCallbacks.md player done id 1038 +callback ModCallbacks MC_PRE_REPLACE_SPRITESHEET repentogon/resources/scripts/enums_ex.lua:118 enums/ModCallbacks.md render and sprites done id 1116 +callback ModCallbacks MC_PRE_RESTOCK_SHOP repentogon/resources/scripts/enums_ex.lua:72 enums/ModCallbacks.md items and pools done id 1070 +callback ModCallbacks MC_PRE_ROOM_COLLISION_PASS repentogon/resources/scripts/enums_ex.lua:202 enums/ModCallbacks.md level and room done id 1227 +callback ModCallbacks MC_PRE_ROOM_EXIT repentogon/resources/scripts/enums_ex.lua:45 enums/ModCallbacks.md level and room done id 1043 +callback ModCallbacks MC_PRE_ROOM_GRID_ENTITY_SPAWN repentogon/resources/scripts/enums_ex.lua:180 enums/ModCallbacks.md level and room done id 1192 +callback ModCallbacks MC_PRE_ROOM_RESTORE_STATE repentogon/resources/scripts/enums_ex.lua:279 enums/ModCallbacks.md hud and menus done id 1305 +callback ModCallbacks MC_PRE_ROOM_TRIGGER_CLEAR repentogon/resources/scripts/enums_ex.lua:70 enums/ModCallbacks.md level and room done id 1068 +callback ModCallbacks MC_PRE_SELECT_AMBUSH_WAVE repentogon/resources/scripts/enums_ex.lua:60 level and room done id 1058 +callback ModCallbacks MC_PRE_SELECT_GREED_WAVE repentogon/resources/scripts/enums_ex.lua:61 level and room done id 1059 +callback ModCallbacks MC_PRE_SFX_PLAY repentogon/resources/scripts/enums_ex.lua:32 enums/ModCallbacks.md audio done id 1030 +callback ModCallbacks MC_PRE_SHUFFLE_COSTUMES repentogon/resources/scripts/enums_ex.lua:408 enums/ModCallbacks.md player done id 1494 +callback ModCallbacks MC_PRE_SLOT_COLLISION repentogon/resources/scripts/enums_ex.lua:214 enums/ModCallbacks.md pickup done id 1240 +callback ModCallbacks MC_PRE_SLOT_CREATE_EXPLOSION_DROPS repentogon/resources/scripts/enums_ex.lua:125 enums/ModCallbacks.md pickup done id 1123 +callback ModCallbacks MC_PRE_SLOT_RENDER repentogon/resources/scripts/enums_ex.lua:91 enums/ModCallbacks.md pickup done id 1089 +callback ModCallbacks MC_PRE_SLOT_SET_PRIZE_COLLECTIBLE repentogon/resources/scripts/enums_ex.lua:127 enums/ModCallbacks.md pickup done id 1125 +callback ModCallbacks MC_PRE_SLOT_UPDATE repentogon/resources/scripts/enums_ex.lua:161 enums/ModCallbacks.md pickup done id 1169 +callback ModCallbacks MC_PRE_STATUS_EFFECT_APPLY repentogon/resources/scripts/enums_ex.lua:381 enums/ModCallbacks.md hud and menus done id 1465 callback ModCallbacks MC_PRE_TEAR_COLLISION enums/ModCallbacks.md tear and weapons review id 42, vanilla callback REPENTOGON changes -callback ModCallbacks MC_PRE_TEAR_GRID_COLLISION repentogon/resources/scripts/enums_ex.lua:165 enums/ModCallbacks.md tear and weapons todo id 1173 -callback ModCallbacks MC_PRE_TEAR_RENDER repentogon/resources/scripts/enums_ex.lua:86 enums/ModCallbacks.md tear and weapons todo id 1084 -callback ModCallbacks MC_PRE_TEAR_UPDATE repentogon/resources/scripts/enums_ex.lua:153 enums/ModCallbacks.md tear and weapons todo id 1161 -callback ModCallbacks MC_PRE_TRIGGER_BED_SLEEP_EFFECT repentogon/resources/scripts/enums_ex.lua:259 enums/ModCallbacks.md misc todo id 1285 -callback ModCallbacks MC_PRE_TRIGGER_PLAYER_DEATH repentogon/resources/scripts/enums_ex.lua:52 enums/ModCallbacks.md player todo id 1050 -callback ModCallbacks MC_PRE_UPDATE repentogon/resources/scripts/enums_ex.lua:28 enums/ModCallbacks.md game todo id 1026 -callback ModCallbacks MC_PRE_USE_CARD repentogon/resources/scripts/enums_ex.lua:66 enums/ModCallbacks.md items and pools todo id 1064 +callback ModCallbacks MC_PRE_TEAR_GRID_COLLISION repentogon/resources/scripts/enums_ex.lua:165 enums/ModCallbacks.md tear and weapons done id 1173 +callback ModCallbacks MC_PRE_TEAR_RENDER repentogon/resources/scripts/enums_ex.lua:86 enums/ModCallbacks.md tear and weapons done id 1084 +callback ModCallbacks MC_PRE_TEAR_UPDATE repentogon/resources/scripts/enums_ex.lua:153 enums/ModCallbacks.md tear and weapons done id 1161 +callback ModCallbacks MC_PRE_TRIGGER_BED_SLEEP_EFFECT repentogon/resources/scripts/enums_ex.lua:259 enums/ModCallbacks.md misc done id 1285 +callback ModCallbacks MC_PRE_TRIGGER_PLAYER_DEATH repentogon/resources/scripts/enums_ex.lua:52 enums/ModCallbacks.md player done id 1050 +callback ModCallbacks MC_PRE_UPDATE repentogon/resources/scripts/enums_ex.lua:28 enums/ModCallbacks.md game done id 1026 +callback ModCallbacks MC_PRE_USE_CARD repentogon/resources/scripts/enums_ex.lua:66 enums/ModCallbacks.md items and pools done id 1064 callback ModCallbacks MC_PRE_USE_ITEM enums/ModCallbacks.md items and pools review id 23, vanilla callback REPENTOGON changes -callback ModCallbacks MC_PRE_USE_PILL repentogon/resources/scripts/enums_ex.lua:67 enums/ModCallbacks.md items and pools todo id 1065 -callback ModCallbacks MC_PROJECTILE_GRID_COLLISION repentogon/resources/scripts/enums_ex.lua:174 enums/ModCallbacks.md tear and weapons todo id 1182 -callback ModCallbacks MC_SHOULD_SAVE_ENTITY repentogon/resources/scripts/enums_ex.lua:287 persistent data and saves todo id 1313 -callback ModCallbacks MC_TEAR_GRID_COLLISION repentogon/resources/scripts/enums_ex.lua:166 enums/ModCallbacks.md tear and weapons todo id 1174 -callback ModCallbacks MC_TRIGGER_PLAYER_DEATH_POST_CHECK_REVIVES repentogon/resources/scripts/enums_ex.lua:53 enums/ModCallbacks.md player todo id 1051 -callback ModCallbacks MC_TRY_ADD_TO_BAG_OF_CRAFTING repentogon/resources/scripts/enums_ex.lua:16 enums/ModCallbacks.md items and pools todo id 1015 +callback ModCallbacks MC_PRE_USE_PILL repentogon/resources/scripts/enums_ex.lua:67 enums/ModCallbacks.md items and pools done id 1065 +callback ModCallbacks MC_PROJECTILE_GRID_COLLISION repentogon/resources/scripts/enums_ex.lua:174 enums/ModCallbacks.md tear and weapons done id 1182 +callback ModCallbacks MC_SHOULD_SAVE_ENTITY repentogon/resources/scripts/enums_ex.lua:287 persistent data and saves done id 1313 +callback ModCallbacks MC_TEAR_GRID_COLLISION repentogon/resources/scripts/enums_ex.lua:166 enums/ModCallbacks.md tear and weapons done id 1174 +callback ModCallbacks MC_TRIGGER_PLAYER_DEATH_POST_CHECK_REVIVES repentogon/resources/scripts/enums_ex.lua:53 enums/ModCallbacks.md player done id 1051 +callback ModCallbacks MC_TRY_ADD_TO_BAG_OF_CRAFTING repentogon/resources/scripts/enums_ex.lua:16 enums/ModCallbacks.md items and pools done id 1015 callback ModCallbacks MC_USE_PILL enums/ModCallbacks.md items and pools review id 10, vanilla callback REPENTOGON changes xml_attribute achievements.xml gfxback repentogon/Patches/AchievementsStuff.cpp:184 xml/achievements.md persistent data and saves todo File "achievements.xml": path of the png sprite to use as a background paper for the achievement xml_attribute achievements.xml hidden repentogon/Patches/XMLData.cpp:1479 xml/achievements.md persistent data and saves todo File "achievements.xml": any value other than 'false', preferably 'true', will make it not show the achievement popup on @@ -2767,13 +2767,13 @@ option internal SkipArchiveChecks repentogon/REPENTOGONOptions.h:67 misc done o option internal UnifontRenderMode repentogon/REPENTOGONOptions.h:63 console and debug done options.ini behaviour_patch Patches ASMPatches.cpp repentogon/Patches/ASMPatches.cpp:1 console and debug todo Applies every byte patch at startup: log and console routing, mod and save folders moved to REPENTOGON's data folder behaviour_patch Patches ASMPatches/ASMBagOfCrafting.cpp repentogon/Patches/ASMPatches/ASMBagOfCrafting.cpp:1 items and pools todo Bag of Crafting pickup adds: MC_TRY_ADD_TO_BAG_OF_CRAFTING and modded pickups -behaviour_patch Patches ASMPatches/ASMCallbacks.cpp repentogon/Patches/ASMPatches/ASMCallbacks.cpp:1 misc todo Inline patches firing the callbacks a hook cannot reach (pause, HUD messages, room placement, NPC removal and many more) +behaviour_patch Patches ASMPatches/ASMCallbacks.cpp repentogon/Patches/ASMPatches/ASMCallbacks.cpp:1 misc started Inline patches firing the callbacks a hook cannot reach (pause, HUD messages, room placement, NPC removal and many more) behaviour_patch Patches ASMPatches/ASMCamera.cpp repentogon/Patches/ASMPatches/ASMCamera.cpp:1 level and room todo Keeps the room's single Camera alive for Lua and restores it on destruction behaviour_patch Patches ASMPatches/ASMDelirium.cpp repentogon/Patches/ASMPatches/ASMDelirium.cpp:1 npc todo Delirium transformation callbacks (pre, transform, post) behaviour_patch Patches ASMPatches/ASMEntityKnife.cpp repentogon/Patches/ASMPatches/ASMEntityKnife.cpp:1 tear and weapons todo Melee knife hitbox initialisation behaviour_patch Patches ASMPatches/ASMEntityNPC.cpp repentogon/Patches/ASMPatches/ASMEntityNPC.cpp:1 npc todo NPC speed and active enemy checks driven by entity config behaviour_patch Patches ASMPatches/ASMFixes.cpp repentogon/Patches/ASMPatches/ASMFixes.cpp:1 misc todo Vanilla bug fixes: modded crafting quality, smelted trinkets, pill identification and effects, game state load, render target overflow, familiar pathing -behaviour_patch Patches ASMPatches/ASMGridEntityCollision.cpp repentogon/Patches/ASMPatches/ASMGridEntityCollision.cpp:1 level and room todo Grid collision callbacks, deduplicated per frame and grid index +behaviour_patch Patches ASMPatches/ASMGridEntityCollision.cpp repentogon/Patches/ASMPatches/ASMGridEntityCollision.cpp:1 level and room started Grid collision callbacks, deduplicated per frame and grid index behaviour_patch Patches ASMPatches/ASMGridEntitySpawn.cpp repentogon/Patches/ASMPatches/ASMGridEntitySpawn.cpp:1 level and room todo Routes inlined grid spawns through MC_PRE/POST_GRID_ENTITY_SPAWN behaviour_patch Patches ASMPatches/ASMGridEntitySpawn_Definitions.cpp repentogon/Patches/ASMPatches/ASMGridEntitySpawn_Definitions.cpp:1 level and room todo Signature table of the inlined grid spawn sites behaviour_patch Patches ASMPatches/ASMHud.cpp repentogon/Patches/ASMPatches/ASMHud.cpp:1 hud and menus todo HistoryHUD render and recompute callbacks, smelted item images @@ -2802,7 +2802,7 @@ behaviour_patch Patches EntityManager.cpp repentogon/Patches/EntityManager.cpp:1 behaviour_patch Patches EntityPlus.cpp repentogon/Patches/EntityPlus.cpp:1 entities todo Extra per entity data: water clip, flying override, init and remove behaviour_patch Patches EvaluateStats.cpp repentogon/Patches/EvaluateStats.cpp:1 items and pools todo XML item stats (tears, damage, range ...) applied at the vanilla steps of EvaluateItems behaviour_patch Patches ExtraDebugRender.cpp repentogon/Patches/ExtraDebugRender.cpp:1 console and debug todo Draws FindInRadius and capsule queries (debug option) -behaviour_patch Patches ExtraLives.cpp repentogon/Patches/ExtraLives.cpp:1 player todo Custom extra lives and revives, MC_PRE_TRIGGER_PLAYER_DEATH +behaviour_patch Patches ExtraLives.cpp repentogon/Patches/ExtraLives.cpp:1 player started Custom extra lives and revives, MC_PRE_TRIGGER_PLAYER_DEATH behaviour_patch Patches ExtraRenderSteps.cpp repentogon/Patches/ExtraRenderSteps.cpp:1 render and sprites todo Cursor initialised and rendered for the mouse control option behaviour_patch Patches FamiliarTags.cpp repentogon/Patches/FamiliarTags.cpp:1 familiar todo Familiar XML tags: damageable, blocks projectiles, charmable behaviour_patch Patches GetCoinValue.cpp repentogon/Patches/GetCoinValue.cpp:1 pickup todo Custom coin values, MC_PICKUP_GET_COIN_VALUE @@ -2824,7 +2824,7 @@ behaviour_patch Patches ModsMenuStuff.cpp repentogon/Patches/ModsMenuStuff.cpp:1 behaviour_patch Patches NullItemsAndCostumes.cpp repentogon/Patches/NullItemsAndCostumes.cpp:1 player todo Custom null items and their costumes behaviour_patch Patches PlayerFeatures.cpp repentogon/Patches/PlayerFeatures.cpp:1 player todo Modded character trinket handling, Greed donations, per save state behaviour_patch Patches PlayerTags.cpp repentogon/Patches/PlayerTags.cpp:1 player todo players.xml tags: no shake, no Metronome, no expansion pack, nightmare portraits -behaviour_patch Patches PocketItems.cpp repentogon/Patches/PocketItems.cpp:1 player todo Pocket item adds and removals with callbacks +behaviour_patch Patches PocketItems.cpp repentogon/Patches/PocketItems.cpp:1 player started Pocket item adds and removals with callbacks behaviour_patch Patches Quickstart.cpp repentogon/Patches/Quickstart.cpp:1 hud and menus todo Quickstart into the last save slot behaviour_patch Patches RoomConfigExtras.h repentogon/Patches/RoomConfigExtras.h:1 level and room todo Stage id mapping for Greed and alternate stages behaviour_patch Patches SaveImport.cpp repentogon/Patches/SaveImport.cpp:1 persistent data and saves todo Imports vanilla saves into REPENTOGON's save folder diff --git a/generated-src/classes.h b/generated-src/classes.h index 7acd03c..a62e2ed 100644 --- a/generated-src/classes.h +++ b/generated-src/classes.h @@ -123,6 +123,7 @@ struct AchievementOverlay_Entry; struct ActionGlyph; struct ActiveGain; struct ActiveItemDesc; +struct ActiveItemRender; struct ActiveUse; struct AfterImageFrame; struct AfterbirthPersistentGameData; @@ -162,6 +163,7 @@ struct BrimstoneShot; struct BufferedStream; struct ButterBeanFart; struct CLIENT_ID; +struct CallbackRun; struct Camera; struct CameraBounds; struct Capsule; @@ -171,9 +173,12 @@ struct ChainLightning; struct ChallengeParam; struct ChallengeParams; struct ChampionLook; +struct CharacterPage; struct Checksum; struct ClubSwing; struct CoPlayerState; +struct CollectibleAdd; +struct CollisionCallbacks; struct Color; struct ColorMod; struct ColorModState; @@ -203,6 +208,7 @@ struct CutsceneEntry; struct CutscenePart; struct DailyChallenge; struct DamageEvent; +struct DamageHit; struct DamageInfo; struct Data; struct DateTime; @@ -312,6 +318,7 @@ struct GlowingHourglassState; struct GlyphDraw; struct GlyphQuad; struct GraphicsWindow; +struct GridCollisionCallbacks; struct GridDestroy; struct GridEntity; struct GridEntityDesc; @@ -351,12 +358,16 @@ struct HWND__; struct HallucinationOverlay; struct Harness; struct HeartGain; +struct HeartsAdd; struct History; struct HistoryHUD; struct HistoryHUDItem; struct HistoryHUDPlayer; struct HistoryItem; struct HomingLaser; +struct HudActiveDraw; +struct HudElementScope; +struct HudHeartsDraw; struct IconResource; struct ImageBase; struct ImagePng; @@ -400,6 +411,7 @@ struct KAGE_ReferenceCount_EntitySaveState; struct KAGE_ReferenceCount_ImageBase; struct KColor; struct KerningPair; +struct KeyConfigRow; struct KeyConfigs; struct KilledNpc; struct KnifeHit; @@ -500,6 +512,7 @@ struct NetplayTextPopup; struct NetworkManager; struct NightmareScene; struct NpcHelper; +struct NpcMorph; struct NullFrame; struct OnlineChat; struct OnlineChatMessage; @@ -507,6 +520,8 @@ struct OnlineEmotes; struct OnlineStatsScreen; struct OnlineUserStats; struct OptionsConfig; +struct Overlay; +struct OverlaySuggestion; struct PMD; struct ParticleSpawn; struct PassiveShot; @@ -521,6 +536,8 @@ struct PersistentGameDataWriter; struct PersistentGameData_Bestiary; struct PickupChoice; struct PickupGhostData; +struct PickupMorph; +struct PickupMorphed; struct PillEffect; struct Platform; struct PlayerCostumeMap; @@ -574,6 +591,7 @@ struct ReferenceCountBase; struct RenderBatch; struct RenderConfig; struct RenderTarget; +struct RepentogonOptions; struct RerollEntry; struct RevivePlayerMenu; struct RichText; @@ -653,6 +671,8 @@ struct StringTable; struct StringTableCategory; struct SubtitleCue; struct TargetSearch; +struct TearFlagHit; +struct TearHitQuery; struct TearParams; struct TearSplash; struct TechLaserShot; @@ -665,6 +685,7 @@ struct TexturePtr; struct Thread; struct TrailFrame; struct TrailPoint; +struct TrinketAdd; struct TrinketPoolItem; struct TypeDescriptor; struct UmbilicalBabyData; diff --git a/scripts/source_tree.py b/scripts/source_tree.py index cfc418d..4d77975 100644 --- a/scripts/source_tree.py +++ b/scripts/source_tree.py @@ -442,10 +442,12 @@ def class_emit(cls, stack=()): srcDir = os.path.join(os.path.dirname(os.path.abspath(outDir)), 'src') NAMESPACE_BLOCK = re.compile(r'^namespace ([\w:]+)\s*\{(.*?)^\}$', re.M | re.S) # a src/ namespace closes with a lone } at column 0 +TEMPLATE_CLASS = re.compile(r'^\s*template\s*<[^\n]*>\s*\n\s*(?:struct|class) \w+', re.M) # src/'s own templates, no game class def curated_classes_load(): # src/ defines these itself: top-level classes, and A::B::Name for those in a namespace A::B block found = set() for root, _, names_ in os.walk(srcDir): - for text in [open(os.path.join(root, n), errors='replace').read() for n in names_ if n.endswith('.h')]: + for text in [TEMPLATE_CLASS.sub('', open(os.path.join(root, n), errors='replace').read()) + for n in names_ if n.endswith('.h')]: for namespace, body in NAMESPACE_BLOCK.findall(text): found |= {f'{namespace}::{m}' for m in re.findall(r'^\s*(?:struct|class) (\w+)\b[^;]*$', body, re.M)} found |= set(re.findall(r'^(?:struct|class) (\w+)\b[^;]*$', NAMESPACE_BLOCK.sub('', text), re.M)) diff --git a/src/engine/anm2.cpp b/src/engine/anm2.cpp index 5f64bf5..5bb91aa 100644 --- a/src/engine/anm2.cpp +++ b/src/engine/anm2.cpp @@ -16,6 +16,9 @@ #include #include #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/render.h" +#endif // 00a15640 A value's place between inMin and inMax carried between outMin and outMax, logging an empty range. float lerp_range(float value, const LerpRange& range) @@ -1353,6 +1356,9 @@ void ANM2::LoadGraphics() // 0040bf30 Points a layer at another spritesheet for the next LoadGraphics, false when the layer or path stays. bool ANM2::ReplaceSpritesheet(int layerId, std::string_view path) { +#ifdef ISAAC_REPENTOGON + if (std::optional isReplaced = spritesheet_replace_hook(*this, layerId, path)) return *isReplaced; +#endif if (layerId < 0 || layerId >= (int)layerStates.size() || layerStates[layerId].spriteSheetPath == path) return false; layerStates[layerId].spriteSheetPath = path; diff --git a/src/entity/boss/intro.cpp b/src/entity/boss/intro.cpp index b306542..9ea99a0 100644 --- a/src/entity/boss/intro.cpp +++ b/src/entity/boss/intro.cpp @@ -11,6 +11,9 @@ #include "level/stage_transition.h" #include "stb_image.h" #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/callbacks.h" +#endif constexpr std::string_view VERSUS_ANM2 = "gfx/ui/boss/versusscreen.anm2"; constexpr std::string_view VERSUS_DOGMA_ANM2 = "gfx/ui/boss/versusscreen_dogma.anm2"; @@ -258,4 +261,7 @@ void RoomTransition::StartBossIntro(uint32_t bossId1, uint32_t bossId2) } versus.Play(isDoubleTrouble ? "DoubleTrouble" : "Scene", PLAY_FORCED); mode = TRANSITION_OUT; +#ifdef ISAAC_REPENTOGON + unfiltered_notify("PostBossIntroShow", MC_POST_BOSS_INTRO_SHOW, bossId1, bossId2); +#endif } diff --git a/src/entity/collision.cpp b/src/entity/collision.cpp index 688afb1..626a08d 100644 --- a/src/entity/collision.cpp +++ b/src/entity/collision.cpp @@ -15,6 +15,9 @@ #include #include #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/collision.h" +#endif // What crushes rocks on contact: The Nail, Leo (worn or rolled by Zodiac), Thunder Thighs, Stompy and Mega Mush. // A transformation counts once the player holds this many of its items. @@ -327,8 +330,12 @@ void Entity::PlayerCollideWithGrid(GridCollisionMode mode) bool isWall = collision == COLLISION_WALL || (collision == COLLISION_SOLID && grid && grid->type == GRID_DOOR); bool isBlocked = collision != COLLISION_NONE && collision != COLLISION_WALL_EXCEPT_PLAYER; - if ((entityGridCollisionClass == GRIDCOLL_WALLS && isWall) || - (entityGridCollisionClass == GRIDCOLL_GROUND && isBlocked)) + bool isMet = (entityGridCollisionClass == GRIDCOLL_WALLS && isWall) || + (entityGridCollisionClass == GRIDCOLL_GROUND && isBlocked); +#ifdef ISAAC_REPENTOGON + isMet = isMet && (isSimulated || !entity_grid_collision_is_ignored(*player, gridIndex)); +#endif + if (isMet) { normal.x += point.x; normal.y += point.y; @@ -413,6 +420,9 @@ static void shot_grid_collide(Entity& shot, Room& room) GridEntity* grid = room.GetGridEntity(gridIndex); if (!grid || grid->type == GRID_PIT) return; +#ifdef ISAAC_REPENTOGON + if (entity_grid_collision_is_ignored(shot, gridIndex)) return; +#endif shot.isCollidesWithGrid = true; shot.gridCollisionVelocity = shot.velocity; } @@ -466,7 +476,11 @@ static Vector blocked_points_sum(Entity& entity, Room& room, int gridClass, bool int gridIndex = room.GetGridIndex(vector_make(entity.pos.x + point.x, entity.pos.y + point.y)); uint32_t collision = room.GetGridCollision(gridIndex); GridEntity* grid = room.GetGridEntity(gridIndex); - if (is_cell_blocked(gridClass, collision, grid)) + bool isBlocked = is_cell_blocked(gridClass, collision, grid); +#ifdef ISAAC_REPENTOGON + isBlocked = isBlocked && !entity_grid_collision_is_ignored(entity, gridIndex); +#endif + if (isBlocked) { sum.x += point.x; sum.y += point.y; diff --git a/src/entity/combat.cpp b/src/entity/combat.cpp index 1d4463a..6effbfc 100644 --- a/src/entity/combat.cpp +++ b/src/entity/combat.cpp @@ -26,6 +26,10 @@ #include #include #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/callbacks.h" +#include "repentogon/entities.h" +#endif constexpr float HALF_F = 0.5f; @@ -349,7 +353,11 @@ bool Entity::TakeDamage(float damage, uint64_t damageFlags, const EntityRef& sou if (HasEntityFlags(FLAG_WEAKNESS)) damage += damage; if (maxHitPoints <= 0) return false; +#ifdef ISAAC_REPENTOGON + if (!entity_damage_pre(*this, {source, damage, nullptr, countdown, damageFlags})) return false; +#else if (!lua_engine_get().EntityTakeDamage(this, damage, damageFlags, source, countdown)) return false; +#endif damageEvents.push_back({.source = source, .damage = damage, .damageFlags = damageFlags}); pendingDamageFlags |= damageFlags; pendingDamage += damage; @@ -357,6 +365,9 @@ bool Entity::TakeDamage(float damage, uint64_t damageFlags, const EntityRef& sou // The online stats screen also tallies the damage, which netplay being offline leaves out. Entity* attacker = source.entity ? source.entity->GetPlayerAncestor() : nullptr; if (attacker && is_enemy_type(type)) static_cast(attacker)->versus.damageDealt += (uint32_t)damage; +#ifdef ISAAC_REPENTOGON + entity_damage_post(*this, {source, damage, nullptr, countdown, damageFlags}); +#endif return true; } @@ -375,7 +386,11 @@ void Entity::Kill(const EntityRef& source) explosion_effects({.position = pos, .source = killer, .damage = BLACK_POWDER_DAMAGE}); } if (!IsBoss() && type != ENTITY_FAMILIAR) BloodExplode(); +#ifdef ISAAC_REPENTOGON + entity_kill_post(*this, source); +#else lua_engine_get().PostEntityKill(this); +#endif } // Part of 006b45c0: the burst's sound, by what its config says it is made of. @@ -1047,7 +1062,19 @@ static bool tear_flies_on(Entity_Tear& tear, Entity& collider) // familiars, friends, rockets, other tears) and once per entity unless it pierces, it deals its damage with its hit // flags, knocks flies along and applies its flags' effects, then dies there unless it flies on. An explosive tear // bursts on any hit. Whether the collision is ignored. +// REPENTOGON's collision callbacks run around it. bool Entity_Tear::HandleCollision(Entity* collider, bool isLow) +{ +#ifdef ISAAC_REPENTOGON + CollisionCallbacks callbacks = {"PreTearCollision", MC_PRE_TEAR_COLLISION, MC_POST_TEAR_COLLISION, (int)variant}; + return collision_callbacks_run(*this, collider, isLow, callbacks, &Entity_Tear::collision_react); +#else + return collision_react(collider, isLow); +#endif +} + +// HandleCollision's own code. +bool Entity_Tear::collision_react(Entity* collider, bool isLow) { LuaResult lua = lua_engine_get().PreTearCollision(this, collider, isLow); if (lua != LUA_RESULT_NIL) return lua == LUA_RESULT_TRUE; @@ -1311,7 +1338,19 @@ static void breath_of_life_burst(Entity_Player& player, Entity& collider) // 0078e1f0 Touches another entity, after a mod's MC_PRE_PLAYER_COLLISION: mid-suplex it passes enemies and shots, // it hurts a vulnerable enemy by its items' contact damage, poisons with The Virus or Serpent's Kiss, and a thrown // Tainted Forgotten slows on enemies. Tainted Forgotten's soul picks the body up. Whether the collision is ignored, which a pony's dash makes it. +// REPENTOGON's collision callbacks run around it. bool Entity_Player::HandleCollision(Entity* collider, bool isLow) +{ +#ifdef ISAAC_REPENTOGON + CollisionCallbacks callbacks = {"PrePlayerCollision", MC_PRE_PLAYER_COLLISION, MC_POST_PLAYER_COLLISION, variant}; + return collision_callbacks_run(*this, collider, isLow, callbacks, &Entity_Player::collision_react); +#else + return collision_react(collider, isLow); +#endif +} + +// HandleCollision's own code. +bool Entity_Player::collision_react(Entity* collider, bool isLow) { LuaResult lua = lua_engine_get().PrePlayerCollide(this, collider, isLow); if (lua == LUA_RESULT_TRUE) return true; diff --git a/src/entity/effect/boss.cpp b/src/entity/effect/boss.cpp index 9b25ba5..0c27c3f 100644 --- a/src/entity/effect/boss.cpp +++ b/src/entity/effect/boss.cpp @@ -10,6 +10,9 @@ #include "game/sfx_manager.h" #include #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/callbacks.h" +#endif // A beam of light from above (Crack the Sky, Isaac's and the Holy Eye's beams): a spotlight that strikes on its Hit // event, then hurts what stands in it every third frame its beam shows. Subtype 1 is the player's, which takes subtype @@ -323,9 +326,13 @@ constexpr int SIREN_STATE_IDLE = 216; constexpr int FAMILIAR_VARIANT_LAST_PLAIN = 900; // FUN_0060dae0 Whether the Siren may charm a familiar: not the ones that never follow her, the subtype 0 ones only -// as such, Incubus only away from Lilith, and two only in some states. +// as such, Incubus only away from Lilith, and two only in some states. A mod's MC_PRE_FAMILIAR_CAN_CHARM may refuse. bool is_familiar_charmable(Entity_Familiar& familiar) { +#ifdef ISAAC_REPENTOGON + CallbackRun run = {"PreFamiliarCanCharm", MC_PRE_FAMILIAR_CAN_CHARM, familiar.variant}; + if (!boolean_run(run, true, &familiar)) return false; +#endif int variant = familiar.variant; if (variant > FAMILIAR_VARIANT_LAST_PLAIN) return true; if (std::find(SIREN_IMMUNE_FAMILIARS.begin(), SIREN_IMMUNE_FAMILIARS.end(), variant) != diff --git a/src/entity/effect/effect.cpp b/src/entity/effect/effect.cpp index c1a3cad..82c94e0 100644 --- a/src/entity/effect/effect.cpp +++ b/src/entity/effect/effect.cpp @@ -24,6 +24,9 @@ #include #include #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/callbacks.h" +#endif // The creep variants the players leave (holy water trail, black, red, white, holy water, green, Lemon Mishap, Lemon // Party, 204, Black Powder, milk, Black Powder's pentagram). @@ -299,6 +302,9 @@ void Entity_Effect::Init(int entityType, int entityVariant, int entitySubType, u // while following it, then runs its variant and counts its timeout down to its death. void Entity_Effect::Update() { +#ifdef ISAAC_REPENTOGON + if (boolean_run({"PreEffectUpdate", MC_PRE_EFFECT_UPDATE, (int)variant}, false, this)) return Entity::Update(); +#endif speedMultiplier = g_game->room->GetTimeScale(this); if (variant == EFFECT_HUSH_LASER || variant == EFFECT_HUSH_LASER_UP) { @@ -364,8 +370,16 @@ void Entity_Effect::Interpolate() } // 00607620 Draws the effect at its place on screen through its variant, or its sprite. A light only lights the room. -void Entity_Effect::Render(const Vector& offset) +void Entity_Effect::Render(const Vector& renderOffset) { +#ifdef ISAAC_REPENTOGON + CallbackRun pre = {"MC_PRE_EFFECT_RENDER", MC_PRE_EFFECT_RENDER, (int)variant}; + std::optional moved = render_pre_run(pre, this, renderOffset); + if (!moved) return; + const Vector& offset = *moved; +#else + const Vector& offset = renderOffset; +#endif if (variant == EFFECT_LIGHT || !isVisible) return; Vector screen = render_position_get(vector_make(pos.x + posOffset.x, pos.y + posOffset.y), RENDER_SNAPPED); diff --git a/src/entity/entity.cpp b/src/entity/entity.cpp index 21a1146..07f4806 100644 --- a/src/entity/entity.cpp +++ b/src/entity/entity.cpp @@ -20,6 +20,10 @@ #include #include #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/callbacks.h" +#include "repentogon/entities.h" +#endif // classes.h declares the original's Lua imports, and its luaL_newstate differs from Lua's only in its return type. #define luaL_newstate lua_newstate_auxiliary @@ -321,9 +325,18 @@ Entity* Entity::GetLastSpawner() return last; } -// 006a89f0 The segment that holds the status effects of a body sharing them, or itself. +// 006a89f0 The segment that holds the status effects of a body sharing them, or itself. A mod may name another. Entity* Entity::GetStatusEffectTarget() { +#ifdef ISAAC_REPENTOGON + LuaEngine& engine = lua_engine_get(); + if (callback_run(engine, {"GetStatusEffectTarget", MC_GET_STATUS_EFFECT_TARGET, type}, this)) + { + Entity* target = (Entity*)lua_object_test(engine.state, -1, LUA_CLASS_ENTITY); + lua_pop(engine.state, 1); + if (target) return target; + } +#endif return DoesEntityShareStatus() ? GetLastParent() : this; } @@ -1211,6 +1224,9 @@ bool Entity::RenderShadowLayer(const Vector& offset) // the rest of its body. void Entity::SetColor(const ColorMod& newColor, int duration, int priority, bool isFadeout, bool isShared) { +#ifdef ISAAC_REPENTOGON + if (entity_color_hook(*this, {newColor, duration, priority, duration, isFadeout, isShared})) return; +#endif if (duration < 1) { color = newColor; diff --git a/src/entity/factory.cpp b/src/entity/factory.cpp index 556ba12..fca772c 100644 --- a/src/entity/factory.cpp +++ b/src/entity/factory.cpp @@ -23,6 +23,10 @@ #include "level/room.h" #include #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/callbacks.h" +#include "repentogon/level.h" +#endif // The seed of a pedestal's Flip item comes from its own with this shift. constexpr uint32_t FLIP_SEED_SHIFT_INDEX = 39; @@ -763,9 +767,13 @@ void room_trigger_output_cell_add(Room& room, int group, int column, int row) constexpr std::array PERSISTENT_ENTITIES = { ENTITY_STONEHEAD, 202, 203, 218, 235, 236, 804, 809, 852, 877, 893}; -// 007ed2a0 Room::IsPersistentRoomEntity: whether a cleared room still spawns the entity. +// 007ed2a0 Room::IsPersistentRoomEntity: whether a cleared room still spawns the entity. A mod may answer. bool room_entity_is_persistent(int type, int variant) { +#ifdef ISAAC_REPENTOGON + CallbackRun run = {"IsPersistentRoomEntity", MC_IS_PERSISTENT_ROOM_ENTITY, std::nullopt}; + if (std::optional isPersistent = callback_boolean_get(run, type, variant)) return *isPersistent; +#endif if (type == ENTITY_POKY) return variant != 0; return type == ENTITY_MINECART || std::find(PERSISTENT_ENTITIES.begin(), PERSISTENT_ENTITIES.end(), type) != PERSISTENT_ENTITIES.end(); @@ -939,6 +947,9 @@ static bool grid_entry_spawn(Room& room, RoomEntry& entry, int gridIndex, uint32 if (grid.variant >= 0) variant = grid.variant; } +#ifdef ISAAC_REPENTOGON + if (!room_grid_spawn_pre(gridType, variant, varData, gridIndex, seed)) return false; +#endif GridEntity* grid = CreateGridEntity(gridType, gridIndex); if (!grid) return false; room.gridEntities[gridIndex] = grid; diff --git a/src/entity/familiar/collision.cpp b/src/entity/familiar/collision.cpp index 830b9ca..cbdf0c5 100644 --- a/src/entity/familiar/collision.cpp +++ b/src/entity/familiar/collision.cpp @@ -17,6 +17,9 @@ #include "level/room_grid.h" #include "entity/weapon/weapon.h" #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/callbacks.h" +#endif // The enemies a contact familiar swats outright: the flies (a Pooter only of its first kinds). constexpr int SWATTED_TYPES[] = {13, 18, 80, 222, 256, 296, 281, 868}; @@ -623,7 +626,20 @@ static bool dip_touch(Entity_Familiar& dip, Entity& enemy, float damageMultiplie // Baby lets players by, the spiders curse, Sissy Longlegs charms, a dashing charger breaks fireplaces and poop, a // spinning orbital hits, Skatole and Beelzebub keep the flies off the player, a familiar with contact damage hurts // enemies (once per hit list) and a blocking one stops shots. Returns whether the touch is ignored. +// REPENTOGON's collision callbacks run around it. bool Entity_Familiar::HandleCollision(Entity* collider, bool isLow) +{ +#ifdef ISAAC_REPENTOGON + CollisionCallbacks callbacks = {"PreFamiliarCollision", MC_PRE_FAMILIAR_COLLISION, MC_POST_FAMILIAR_COLLISION, + variant}; + return collision_callbacks_run(*this, collider, isLow, callbacks, &Entity_Familiar::collision_react); +#else + return collision_react(collider, isLow); +#endif +} + +// HandleCollision's own code. +bool Entity_Familiar::collision_react(Entity* collider, bool isLow) { if (familiar_versus()) { diff --git a/src/entity/familiar/familiar.cpp b/src/entity/familiar/familiar.cpp index 21e02e6..ca553b9 100644 --- a/src/entity/familiar/familiar.cpp +++ b/src/entity/familiar/familiar.cpp @@ -21,6 +21,9 @@ #include "game/sfx_manager.h" #include #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/callbacks.h" +#endif // The familiars that join the following line, and the ones that trail the player's path instead (Init 0060de70). constexpr int FOLLOWER_VARIANTS[] = {1, 2, 4, 5, 6, 7, 9, 10, 11, 20, 21, 22, 23, 40, 41, 3, @@ -558,9 +561,12 @@ bool Entity_Familiar::update_appearing() // 0061da10 A familiar's frame: its size, the first frames' fixes (the delayed ones start on the player, a fourth // familiar in the innermost orbit pushes an orbiting fly out), the appearing poof, then its variant's behaviour and the -// shared tail. +// shared tail. A mod's MC_PRE_FAMILIAR_UPDATE may leave only Entity's update. void Entity_Familiar::Update() { +#ifdef ISAAC_REPENTOGON + if (boolean_run({"PreFamiliarUpdate", MC_PRE_FAMILIAR_UPDATE, variant}, false, this)) return Entity::Update(); +#endif if (variant != FORGOTTEN_BODY) { float scale = variant == ABYSS_LOCUST ? locust_scale_get(*this) : 1; @@ -1057,9 +1063,18 @@ void Entity_Familiar::Interpolate() // 00624e10 Draws a familiar with its charge bar. Isaac's body draws its parts, a detached head its player's head, Gello // its cord first, Samson's Chains and Gemini hang their links, a locust its shot sprites and an item wisp its item's -// icon. Tainted Lazarus's hologram draws them all faint and flickering. -void Entity_Familiar::Render(const Vector& offset) +// icon. Tainted Lazarus's hologram draws them all faint and flickering. A mod's MC_PRE_FAMILIAR_RENDER may skip it or +// move it. +void Entity_Familiar::Render(const Vector& renderOffset) { +#ifdef ISAAC_REPENTOGON + std::optional moved = render_pre_run({"PreFamiliarRender", MC_PRE_FAMILIAR_RENDER, variant}, this, + renderOffset); + if (!moved) return; + const Vector& offset = *moved; +#else + const Vector& offset = renderOffset; +#endif if (IsLilithBirthrightIncubus()) { Entity* whip = get_incubus_umbilical_whip(); diff --git a/src/entity/familiar/familiar.h b/src/entity/familiar/familiar.h index 7b75906..d77ed44 100644 --- a/src/entity/familiar/familiar.h +++ b/src/entity/familiar/familiar.h @@ -475,6 +475,10 @@ struct Entity_Familiar : Entity private: void blood_puppy_restore(float bodyHealth); + Entity_Laser* brimstone_fire(const Vector& aimDirection, BrimstoneLook look); + bool collision_react(Entity* collider, bool isLow); + Entity_Laser* robo_laser_fire(const Vector& direction); + Entity_Tear* tear_fire(const Vector& aimDirection, FireMode mode); bool collision_block(Entity& collider, bool isIgnored); bool collision_contact(Entity& collider, float damageMultiplier, float damage); void collision_hurt(Entity& collider, float damageMultiplier, float dealt); diff --git a/src/entity/familiar/follow.cpp b/src/entity/familiar/follow.cpp index 0e9742e..e0847ac 100644 --- a/src/entity/familiar/follow.cpp +++ b/src/entity/familiar/follow.cpp @@ -15,6 +15,9 @@ #include "level/room.h" #include "level/room_grid.h" #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/callbacks.h" +#endif // How far behind its leader a follower keeps, closer for Milk and on Child's Leash, and how hard it catches up. constexpr float FOLLOW_DISTANCE = 20; @@ -157,9 +160,13 @@ static bool is_wide_wisp(Entity_Familiar& familiar) } // 00612970 Its rank in the following line: the shooters first, then Mongo Baby and its peers, the Lils, Incubus, Milk -// and King Baby at the very front. Others do not follow. +// and King Baby at the very front. Others do not follow. A mod may answer. int Entity_Familiar::GetFollowerPriority() { +#ifdef ISAAC_REPENTOGON + CallbackRun run = {"GetFollowerPriority", MC_GET_FOLLOWER_PRIORITY, variant}; + if (std::optional priority = callback_integer_get(run, this)) return *priority; +#endif if (familiar_listed(PRIORITY_1_VARIANTS, variant)) return 1; if (familiar_listed(PRIORITY_2_VARIANTS, variant)) return 2; diff --git a/src/entity/familiar/shoot.cpp b/src/entity/familiar/shoot.cpp index 482d991..6467833 100644 --- a/src/entity/familiar/shoot.cpp +++ b/src/entity/familiar/shoot.cpp @@ -11,6 +11,9 @@ #include "entity/npc/ai.h" #include "level/room.h" #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/callbacks.h" +#endif // The items and trinkets the familiars' shots read. @@ -148,7 +151,8 @@ int familiar_lullaby_delay(Entity_Familiar& familiar, int fireDelay) // 0060dc40 How strong its attacks are: doubled by BFFS! (not for blue flies and spiders) or by Hive Mind (flies and // spiders), a quarter more per Child's Leash, three quarters for Tainted Bethany, a quarter for Tainted Lazarus's other -// form while it is behind. +// form while it is behind. A positive number from a mod's MC_EVALUATE_FAMILIAR_MULTIPLIER replaces it. REPENTOGON +// keeps that per familiar until a familiarmultiplier custom cache, the rebuild asks each time. float Entity_Familiar::GetMultiplier() { uint64_t tags = config->tags; @@ -167,6 +171,16 @@ float Entity_Familiar::GetMultiplier() if (player->isExists && isLazarusB && twin && twin != player && twin->playerIndex != -1 && twin->playerIndex < player->playerIndex) multiplier *= 0.25f; +#ifdef ISAAC_REPENTOGON + LuaEngine& engine = lua_engine_get(); + CallbackRun run = {"EvaluateFamiliarMultiplier", MC_EVALUATE_FAMILIAR_MULTIPLIER, variant}; + if (callback_run(engine, run, this, multiplier, player)) + { + float evaluated = lua_isnumber(engine.state, -1) ? (float)lua_tonumber(engine.state, -1) : 0; + lua_pop(engine.state, 1); + if (evaluated > 0) multiplier = evaluated; + } +#endif return multiplier; } @@ -556,8 +570,19 @@ static Entity_Tear* intruder_shots_fire(Entity_Familiar& intruder, FamiliarShot& // 00639750 Fires a familiar's tear: at ten speed, with the player's motion unless aimed at a mark (Intruder only the // part not against its aim), its damage and size scaled by BFFS!, and the variant's flags and look. Harlequin Baby -// fires two, Intruder four and the wisps their own way. +// fires two, Intruder four and the wisps their own way. MC_POST_FAMILIAR_FIRE_PROJECTILE follows a tear fired. Entity_Tear* Entity_Familiar::FireProjectile(const Vector& aimDirection, FireMode mode) +{ + Entity_Tear* tear = tear_fire(aimDirection, mode); +#ifdef ISAAC_REPENTOGON + CallbackRun run = {"PostFamiliarFireProjectile", MC_POST_FAMILIAR_FIRE_PROJECTILE, variant}; + if (tear) callback_notify(lua_engine_get(), run, tear); +#endif + return tear; +} + +// FireProjectile's own code. +Entity_Tear* Entity_Familiar::tear_fire(const Vector& aimDirection, FireMode mode) { FamiliarShot shot; shot.velocity = vector_scale(aimDirection, SHOT_SPEED); @@ -740,7 +765,19 @@ void Entity_Familiar::shot_owner_convert(Entity* shot) // 00613c20 Robo-Baby's laser (a wisp's too): a short thin beam from its eye, hitting once and staying where it was // fired, three and a half damage times BFFS!, drawn behind it when aimed up or left. Lil Delirium tints it, a hologram // fades it, Baby-Bender bends it and the Siren turns it on the player. None for a dead player. +// MC_POST_FAMILIAR_FIRE_TECH_LASER follows (REPENTOGON's Entity_Familiar::FireTechLaser). Entity_Laser* Entity_Familiar::fire_robo_baby_laser(const Vector& direction) +{ + Entity_Laser* laser = robo_laser_fire(direction); +#ifdef ISAAC_REPENTOGON + CallbackRun run = {"PostFamiliarFireTechLaser", MC_POST_FAMILIAR_FIRE_TECH_LASER, variant}; + callback_notify(lua_engine_get(), run, laser); +#endif + return laser; +} + +// fire_robo_baby_laser's own code. +Entity_Laser* Entity_Familiar::robo_laser_fire(const Vector& direction) { if (player->isDead) return nullptr; @@ -880,7 +917,19 @@ bool Entity_Familiar::apply_baby_bender(Entity_Laser& laser) // 00638c10 Fires a familiar's Brimstone beam along a direction (none for a dead player): a short thin beam from its // mouth, a third of Brimstone's damage times BFFS!, drawn behind it when aimed up. Its own beam is tinted for Lil // Delirium, bent by Baby-Bender, turned on the player by the Siren, linked to it and shown on its head. +// MC_POST_FAMILIAR_FIRE_BRIMSTONE follows. Entity_Laser* Entity_Familiar::FireBrimstone(const Vector& aimDirection, BrimstoneLook look) +{ + Entity_Laser* laser = brimstone_fire(aimDirection, look); +#ifdef ISAAC_REPENTOGON + CallbackRun run = {"PostFamiliarFireBrimstone", MC_POST_FAMILIAR_FIRE_BRIMSTONE, variant}; + callback_notify(lua_engine_get(), run, laser); +#endif + return laser; +} + +// FireBrimstone's own code. +Entity_Laser* Entity_Familiar::brimstone_fire(const Vector& aimDirection, BrimstoneLook look) { if (player->isDead) return nullptr; diff --git a/src/entity/familiar/wisp.cpp b/src/entity/familiar/wisp.cpp index c57d9f8..2e18b21 100644 --- a/src/entity/familiar/wisp.cpp +++ b/src/entity/familiar/wisp.cpp @@ -14,6 +14,9 @@ #include #include #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/items.h" +#endif constexpr int WISP_SHEET_WIDE = 128; constexpr int WISP_HEAD_FRAMES = 12; @@ -185,7 +188,7 @@ int Entity_Familiar::GetRandomWisp(RNG* rng) // 00436330 Sets a wisp up: an item wisp takes Lemegeton's (or Book of Virtues' Lemegeton) entry, Eden's Soul and // Mystery Gift wisps become a random wisp, the wisps with their own behaviour get ready, then its entry's health, -// sheets and colours. The item wisps are counted as held. +// sheets and colours. The item wisps are counted as held, and MC_POST_TRIGGER_COLLECTIBLE_ADDED runs for a new one. void Entity_Familiar::WispInit() { int item = subtype; @@ -214,6 +217,10 @@ void Entity_Familiar::WispInit() if (variant == ITEM_WISP) player->RecomputeWispCollectibles(this); g_game->UpdateVisibility(); +#ifdef ISAAC_REPENTOGON + if (!isFamiliarsRestoring && variant == ITEM_WISP && player && ItemConfig::IsValidCollectible(subtype)) + collectible_added_post(*player, subtype, false, true); +#endif } // 0043d7f0 Turns a wisp into another kind, keeping its health below the new kind's. @@ -603,6 +610,9 @@ void Entity_Player::RecomputeWispCollectibles(Entity_Familiar* joining) for (int id : removedIds) { ItemConfig_Item* item = items.GetCollectible(id); +#ifdef ISAAC_REPENTOGON + collectibleRemoval = REMOVAL_KIND_WISP; +#endif TriggerCollectibleRemoved(id); if (item && item->isAddCostumeOnPickup && !HasCollectible(id)) RemoveCostume(item); } diff --git a/src/entity/list.cpp b/src/entity/list.cpp index ec2d2be..eee57d8 100644 --- a/src/entity/list.cpp +++ b/src/entity/list.cpp @@ -14,6 +14,9 @@ #include #include #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/callbacks.h" +#endif constexpr const char* SHADOW_PNG = "gfx/shadow.png"; @@ -405,6 +408,10 @@ void EntityList::Update(UpdateMode mode) boss_bar_update(tally); enemyDamageInflicted = tally.damageInflicted; bool isBakedAway = surfaces_bake(renderEL); +#ifdef ISAAC_REPENTOGON + if (mode == UPDATE_NORMAL) + callback_notify(lua_engine_get(), {"PreRoomCollisionPass", MC_PRE_ROOM_COLLISION_PASS, std::nullopt}); +#endif if (tally.isAnyRemoved || isBakedAway) removed_drop(); if (mode == UPDATE_NORMAL) rebuild_sublists(); sort_by_render_z(); diff --git a/src/entity/list.h b/src/entity/list.h index a2fa97d..11fd1c1 100644 --- a/src/entity/list.h +++ b/src/entity/list.h @@ -167,6 +167,7 @@ struct EntityList void Update(UpdateMode mode); void rebuild_sublists(); void sort_by_render_z(); + void removed_drop(); void render_up_to(uint32_t maxDepth, const Vector& offset); void invalidate_type_cache(int type, int variant, int subType); int CountEntities(Entity* spawner, int type, int variant, int subType); @@ -177,6 +178,5 @@ private: void entities_update(UpdateMode mode, UpdateTally& tally); void players_update(UpdateMode mode); void boss_bar_update(const UpdateTally& tally); - void removed_drop(); void twins_push_apart(); }; diff --git a/src/entity/npc/champion.cpp b/src/entity/npc/champion.cpp index 9bf6851..073acfd 100644 --- a/src/entity/npc/champion.cpp +++ b/src/entity/npc/champion.cpp @@ -11,6 +11,9 @@ #include "game/sfx_manager.h" #include #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/callbacks.h" +#endif constexpr int SHRINK_PULSE_FRAMES = 60; @@ -505,6 +508,10 @@ static void dark_red_champion_update(Entity_NPC& npc) } npc.pathfinder.Reset(); npc.ResetColor(); +#ifdef ISAAC_REPENTOGON + CallbackRun regen = {"PostNPCDarkRedChampionRegen", MC_POST_NPC_DARK_RED_CHAMPION_REGEN, (int)npc.type}; + callback_notify(lua_engine_get(), regen, &npc); +#endif } } diff --git a/src/entity/npc/collision.cpp b/src/entity/npc/collision.cpp index 820fb00..7c50d95 100644 --- a/src/entity/npc/collision.cpp +++ b/src/entity/npc/collision.cpp @@ -15,6 +15,9 @@ #include #include #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/callbacks.h" +#endif // The variants and states some contacts depend on. constexpr int FIREPLACE_WHITE = 4; @@ -943,7 +946,19 @@ static void contact_impact(Entity_NPC& npc, Entity& other) // 006cd410 What it does on touching another entity, and whether that contact is ignored. The special contacts of // bosses and odd enemies come first, then the generic ones: a shrunk enemy is squished, friends and shots pass, a // touched player is hurt, kin pass each other, and a charmed enemy bumps others. +// REPENTOGON's collision callbacks run around it. bool Entity_NPC::HandleCollision(Entity* collider, bool isLow) +{ +#ifdef ISAAC_REPENTOGON + CollisionCallbacks callbacks = {"PreNPCCollision", MC_PRE_NPC_COLLISION, MC_POST_NPC_COLLISION, (int)type}; + return collision_callbacks_run(*this, collider, isLow, callbacks, &Entity_NPC::collision_react); +#else + return collision_react(collider, isLow); +#endif +} + +// HandleCollision's own code. +bool Entity_NPC::collision_react(Entity* collider, bool isLow) { LuaResult lua = lua_engine_get().PreNPCCollision(this, collider, isLow); if (lua == LUA_RESULT_TRUE) return true; diff --git a/src/entity/npc/npc.cpp b/src/entity/npc/npc.cpp index f210b17..e570260 100644 --- a/src/entity/npc/npc.cpp +++ b/src/entity/npc/npc.cpp @@ -36,6 +36,10 @@ #include #include #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/callbacks.h" +#include "repentogon/npc.h" +#endif // The frames of a controlled NPC's charge bar, empty to full. constexpr int CHARGE_BAR_FRAMES = 100; @@ -1124,6 +1128,9 @@ bool Entity_NPC::Redirect(int* entityType, int* entityVariant) // kept only where the new one can be one. An enemy the run erased leaves in a poof. void Entity_NPC::Morph(int entityType, int entityVariant, int entitySubType, int championId) { +#ifdef ISAAC_REPENTOGON + if (npc_morph_hook(*this, {entityType, entityVariant, entitySubType, championId})) return; +#endif bool isSame = entityType == type && entityVariant == variant && entitySubType == subtype && (championId < 0 || championId == championColorIdx); if (isSame) return; @@ -2432,6 +2439,9 @@ static Entity* dople_player_pick(Entity_NPC& npc) // the rest the nearest target player (Game::GetNearestTargetPlayer), else the first player. Entity* Entity_NPC::GetPlayerTarget() { +#ifdef ISAAC_REPENTOGON + if (std::optional picked = npc_target_hook(*this)) return *picked; +#endif if (type == ENTITY_DOPLE) return dople_player_pick(*this); bool isRetargeting = IsFrame(TARGET_REFRESH_FRAMES, (int)index) || !target; @@ -3032,7 +3042,7 @@ void Entity_NPC::hold_set(int countdown, const Vector& position) // configs. In a run a mod may answer first through MC_INPUT_ACTION. Netplay's remote devices are offline. float input_action_value_get(ButtonAction action, int controllerIndex, Entity* entity) { - if (g_manager->state == MANAGER_STATE_GAME && g_luaEngine) + if (is_input_hook_asked()) if (std::optional modValue = lua_engine_get().InputActionValue(entity, action)) return *modValue; KAGE::Input::Manager& input = KAGE::Input::manager; @@ -3629,7 +3639,11 @@ bool Entity_NPC::split(float damage, const EntityRef& source, bool isPlaySound) if (isDead || !isExists) return false; if (isPlaySound) npc_sound_play(SOUND_MEATY_DEATHS, 1, 2, 1); - bool isHurtOnly = scale < SPLIT_LEAST_SCALE || split_is_unsplittable(*this); + bool isBlacklisted = split_is_unsplittable(*this); +#ifdef ISAAC_REPENTOGON + isBlacklisted = boolean_run({"PreNPCSplit", MC_PRE_NPC_SPLIT, (int)type}, isBlacklisted, this, isBlacklisted); +#endif + bool isHurtOnly = scale < SPLIT_LEAST_SCALE || isBlacklisted; bool isChain = (type == ENTITY_VISAGE && variant == VISAGE_CHAIN) || (type == ENTITY_SCOURGE && variant == SCOURGE_CHAIN); if (isHurtOnly) TakeDamage(damage, 0, source, SPLIT_HURT_COUNTDOWN); else if (type == ENTITY_FALLEN && variant == 0 && spawnerType != ENTITY_FALLEN) @@ -3653,10 +3667,17 @@ bool Entity_NPC::split(float damage, const EntityRef& source, bool isPlaySound) // ghosts. Otherwise, or with nothing to drop, the ghosts shown before go. void Entity_NPC::UpdatePickupGhosts() { +#ifdef ISAAC_REPENTOGON + bool isShown = npc_ghosts_is_shown(*this); +#else bool isLootHolder = (type == ENTITY_FIREPLACE && health > 1) || (type == ENTITY_SHOPKEEPER && !isDead); - if (isLootHolder && g_game->playerManager.FirstCollectibleOwner(COLLECTIBLE_GUPPYS_EYE, LAZARUS_SHARE_CHECK)) + bool isShown = isLootHolder && g_game->playerManager.FirstCollectibleOwner(COLLECTIBLE_GUPPYS_EYE, LAZARUS_SHARE_CHECK); +#endif + if (isShown) { - LootList loot = type == ENTITY_FIREPLACE ? fireplace_get_loot(false) : LootList{shopkeeper_loot_get(*this, false)}; + LootList loot = type == ENTITY_FIREPLACE ? fireplace_get_loot(false) + : type == ENTITY_SHOPKEEPER ? LootList{shopkeeper_loot_get(*this, false)} + : LootList{}; if (!loot.entries.empty()) { pickupGhostsEntity = Entity_Effect::CreateLootPreview( diff --git a/src/entity/npc/npc.h b/src/entity/npc/npc.h index 7d7e4bd..2f546ba 100644 --- a/src/entity/npc/npc.h +++ b/src/entity/npc/npc.h @@ -285,6 +285,7 @@ struct Entity_NPC : Entity bool TryThrow(const EntityRef& source, const Vector& direction, float force) override; Vector GetForwardVector() override; bool HandleCollision(Entity* collider, bool isLow) override; + bool collision_react(Entity* collider, bool isLow); void ResetColor() override; void LoadEntityConfig() override; diff --git a/src/entity/npc/render.cpp b/src/entity/npc/render.cpp index 161542c..8d1ae28 100644 --- a/src/entity/npc/render.cpp +++ b/src/entity/npc/render.cpp @@ -16,6 +16,9 @@ #include #include #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/callbacks.h" +#endif constexpr float NPC_SCREEN_SCALE = 0.65f; constexpr int SPAWN_BAR_DELAY = 2; @@ -383,8 +386,15 @@ static bool npc_is_health_bar_shown(Entity_NPC& npc) // 006d2e50 Draws it: hidden in the wrong pass or tinted, on its minecart, with a special body for some bosses, the // size pulse, the Lamb's afterimages, and the links in front, then what it holds, its status effect, a health bar // and its controller's charge bar. -void Entity_NPC::Render(const Vector& offset) +void Entity_NPC::Render(const Vector& renderOffset) { +#ifdef ISAAC_REPENTOGON + std::optional moved = render_pre_run({"PreNPCRender", MC_PRE_NPC_RENDER, (int)type}, this, renderOffset); + if (!moved) return; + const Vector& offset = *moved; +#else + const Vector& offset = renderOffset; +#endif if (is_type(*this, ENTITY_MINECART, 0) && child) return; RenderMode renderMode = g_game->room->entityList.renderMode; diff --git a/src/entity/npc/ultra_greed.cpp b/src/entity/npc/ultra_greed.cpp index 7231256..b2bd96a 100644 --- a/src/entity/npc/ultra_greed.cpp +++ b/src/entity/npc/ultra_greed.cpp @@ -400,7 +400,7 @@ static UltraGreedRoom ultra_greed_room_read() int gapers = 0; for (Entity* coin : entity_query(ENTITY_PICKUP, PICKUP_COIN)) - if (auto* pickup = dynamic_cast(coin)) room.coinWorth += pickup->GetCoinValue(); + if (auto* pickup = dynamic_cast(coin)) room.coinWorth += pickup->coin_worth(); coins = (int)entity_query(ENTITY_ULTRA_COIN, -1).size(); gapers = (int)entity_query(ENTITY_GREED_GAPER, -1).size(); room.keepers = (int)entity_query(ENTITY_KEEPER, -1).size(); @@ -1101,7 +1101,7 @@ static Vector ultra_greed_walk_goal(Entity_NPC& npc, bool& isCoinGoal) { auto* pickup = dynamic_cast(coin); if (!pickup) continue; - float score = vector_length_squared(vector_sub(npc.pos, coin->pos)) / (float)pickup->GetCoinValue(); + float score = vector_length_squared(vector_sub(npc.pos, coin->pos)) / (float)pickup->coin_worth(); if (score >= best || pickup->entityCollisionClass == ENTCOLL_NONE || pickup->isDead) continue; isCoinGoal = true; goal = coin->pos; diff --git a/src/entity/pickup/chest.cpp b/src/entity/pickup/chest.cpp index 7224b67..8e85132 100644 --- a/src/entity/pickup/chest.cpp +++ b/src/entity/pickup/chest.cpp @@ -16,6 +16,9 @@ #include #include #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/callbacks.h" +#endif // The shift index of the RNG every outcome draw seeds (5, 9, 7), and the one a loot's spot angle comes from. constexpr int OUTCOME_SHIFT_INDEX = 35; @@ -655,8 +658,16 @@ static void chest_vanish(Entity_Pickup& chest) // 006e6e40 Opens the chest for a player (the nearest main one when none): it plays Open with its sounds and a faint poof, // gives its loot and stays open. An eternal chest that gives nothing closes again. An item turns the chest into its // pedestal, and a pickup or enemy coming out pushes a close player away. Whether a closed chest opened. +// A mod may keep it shut. bool Entity_Pickup::TryOpenChest(Entity_Player* player) { +#ifdef ISAAC_REPENTOGON + bool isOpenChest = IsChest(variant) && subtype == 0; + if (!isOpenChest && !boolean_run({"PreOpenChest", MC_PRE_OPEN_CHEST, variant}, true, this, player)) return false; + ScopeExit post{[=, this] { + if (!isOpenChest) callback_notify(lua_engine_get(), {"PostOpenChest", MC_POST_OPEN_CHEST, variant}, this, player); + }}; +#endif if (!player) player = main_player_nearest(pos); if (!player) player = g_game->GetPlayer(0); if (subtype == 0) return false; diff --git a/src/entity/pickup/item_overlay.cpp b/src/entity/pickup/item_overlay.cpp index 95048a6..649d486 100644 --- a/src/entity/pickup/item_overlay.cpp +++ b/src/entity/pickup/item_overlay.cpp @@ -8,6 +8,9 @@ #include "engine/render_passes.h" #include "level/room.h" #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/callbacks.h" +#endif constexpr int SLEEP_SOUL_HEARTS = 6; constexpr int EVENT_COUNTER_SLEEPS = 202; @@ -66,11 +69,15 @@ static void overlay_sound_play(int sound, int frameDelay, float pitch) } // Sleeping's healing: each player but Tainted Soul fills its red hearts, or takes three soul hearts without heart -// containers, with a power up sound unless finishing. The game counts the sleep. +// containers, with a power up sound unless finishing. The game counts the sleep. A mod may skip a player. static void sleep_heal(OverlayUpdate mode) { for (Entity_Player* player : g_game->playerManager.playerList) { +#ifdef ISAAC_REPENTOGON + if (boolean_run({"PreTriggerBedSleepEffect", MC_PRE_TRIGGER_BED_SLEEP_EFFECT, std::nullopt}, false, player)) + continue; +#endif if (player->playerType == PLAYER_THESOUL_B) continue; @@ -128,8 +135,23 @@ static void sleep_nightmare_update(ANM2& overlay, OverlayUpdate mode) // 009ad210 Shows a giant book: its .anm2 with the entry's spritesheet and recolored layers, playing its animation, at // once or after a delay. An entry without one (Mega Mush's) leaves the sprite empty. +// A mod may keep it hidden or show another. void ItemOverlay::Show(int overlayId, int showDelay, Entity_Player* shown) { +#ifdef ISAAC_REPENTOGON + LuaEngine& engine = lua_engine_get(); + if (callback_run(engine, {"PreItemOverlayShow", MC_PRE_ITEM_OVERLAY_SHOW, overlayId}, overlayId, showDelay, shown)) + { + bool isCancelled = lua_isboolean(engine.state, -1) && lua_toboolean(engine.state, -1); + if (lua_isnumber(engine.state, -1)) overlayId = (int)lua_tonumber(engine.state, -1); + lua_pop(engine.state, 1); + if (isCancelled) return; + } + ScopeExit post{[&] { + CallbackRun run = {"PostItemOverlayShow", MC_POST_ITEM_OVERLAY_SHOW, overlayId}; + callback_notify(engine, run, overlayId, showDelay, shown); + }}; +#endif if ((unsigned)overlayId >= GIANTBOOK_ENTRY_COUNT) return; @@ -163,6 +185,12 @@ void ItemOverlay::Show(int overlayId, int showDelay, Entity_Player* shown) // and the nightmare of the bed in Home. Finishing skips the animations to their end and the sounds. void ItemOverlay::Update(OverlayUpdate mode) { +#ifdef ISAAC_REPENTOGON + ScopeExit post{[&] { + CallbackRun run = {"PostItemOverlayUpdate", MC_POST_ITEM_OVERLAY_UPDATE, overlayID}; + callback_notify(lua_engine_get(), run, overlayID, mode == OVERLAY_UPDATE_FINISH); + }}; +#endif if (state == ITEM_OVERLAY_WAITING) { if (--delay < 1) @@ -237,4 +265,8 @@ void ItemOverlay::Render() } } graphics.shader_default_set(); +#ifdef ISAAC_REPENTOGON + if (sprite.isLoaded || overlayID == GIANTBOOK_MEGA_MUSH) + callback_notify(lua_engine_get(), {"PostItemOverlayRender", MC_POST_ITEM_OVERLAY_RENDER, overlayID}, overlayID); +#endif } diff --git a/src/entity/pickup/item_pool.cpp b/src/entity/pickup/item_pool.cpp index a9c46c0..b681be5 100644 --- a/src/entity/pickup/item_pool.cpp +++ b/src/entity/pickup/item_pool.cpp @@ -14,6 +14,10 @@ #include #include #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/callbacks.h" +#include "repentogon/items.h" +#endif // An outcome of a weighted draw and its weight, as WeightedOutcomePicker holds them. struct WeightedOutcome @@ -885,9 +889,19 @@ static int effect_swap(std::span> pairs, int effect) // 00734a80 The effect a pill color has for a player: PHD (Virgo, Lucky Foot) turns bad pills good unless False PHD // cancels it, and False PHD alone turns good pills bad. A pill the player cannot use falls back on a safe one. Lua's -// MC_GET_PILL_EFFECT may override it. +// MC_GET_PILL_EFFECT may override it, without vanilla parity after it all and seeing the player. // The original reads past the colors for a color above gold. Here that is no effect. int ItemPool::GetPillEffect(uint32_t pillColor, Entity_Player* player) +{ + int effect = pill_effect_pick(pillColor, player); +#ifdef ISAAC_REPENTOGON + if (!repentogonOptions.isVanillaParity) return pill_effect_post(effect, pillColor, player); +#endif + return effect; +} + +// GetPillEffect's own code. +int ItemPool::pill_effect_pick(uint32_t pillColor, Entity_Player* player) { int color = (int)(pillColor & PILL_COLOR_MASK); int effect = color < PILL_COLOR_SLOTS ? pillEffects[color] : PILLEFFECT_NULL; @@ -915,8 +929,20 @@ int ItemPool::GetPillEffect(uint32_t pillColor, Entity_Player* player) return overridden != -1 ? overridden : effect; } -// 00736ba0 The color with a pill effect, given to a random color first when none has it. +// 00736ba0 The color with a pill effect, given to a random color first when none has it. MC_POST_FORCE_ADD_PILL_EFFECT +// follows. int ItemPool::ForceAddPillEffect(int pillEffect) +{ + int color = pill_effect_force(pillEffect); +#ifdef ISAAC_REPENTOGON + CallbackRun run = {"PostForceAddPillEffect", MC_POST_FORCE_ADD_PILL_EFFECT, std::nullopt}; + callback_notify(lua_engine_get(), run, pillEffect, color); +#endif + return color; +} + +// ForceAddPillEffect's own code. +int ItemPool::pill_effect_force(int pillEffect) { for (int color = 1; color <= PILL_COLORS; color++) if (pillEffects[color] == pillEffect) return color; diff --git a/src/entity/pickup/item_pool.h b/src/entity/pickup/item_pool.h index 034f64e..904a486 100644 --- a/src/entity/pickup/item_pool.h +++ b/src/entity/pickup/item_pool.h @@ -215,7 +215,9 @@ public: static int GetPill(uint32_t drawSeed); int GetPillEffect(uint32_t pillColor, Entity_Player* player); + int pill_effect_pick(uint32_t pillColor, Entity_Player* player); int ForceAddPillEffect(int pillEffect); + int pill_effect_force(int pillEffect); void IdentifyPill(uint32_t pillColor); bool IsPillIdentified(uint32_t pillColor); int on_pill_used(int pillColor, uint32_t useSeed, uint32_t& rngState); diff --git a/src/entity/pickup/morph.cpp b/src/entity/pickup/morph.cpp index e7e6b87..a2aa38a 100644 --- a/src/entity/pickup/morph.cpp +++ b/src/entity/pickup/morph.cpp @@ -7,6 +7,9 @@ #include #include #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/items.h" +#endif constexpr int MORPH_RNG_SHIFT = 7; @@ -54,10 +57,15 @@ int Entity_Pickup::sacrifice_item_pick() // index, flags and timers kept, its price kept or dropped, an active's initial charge, and its pedestal. Entities // pointing at it forget it. A devil deal keeps a sacrifice item, a priced item rerolled to nothing gets a new ware of // its shop slot at its price, a Mega Chest's halves stay paired, and Flip's other item stays while the pickup keeps its -// kind. +// kind. Mods' MC_PRE_PICKUP_MORPH may cancel or change it, and MC_POST_PICKUP_MORPH follows. void Entity_Pickup::Morph(int entityType, int entityVariant, int entitySubType, bool isKeepPrice, bool isKeepSeed, bool isIgnoreModifiers) { +#ifdef ISAAC_REPENTOGON + std::optional morphed = + pickup_morph_pre(*this, {entityType, entityVariant, entitySubType, isKeepPrice, isKeepSeed, isIgnoreModifiers}); + if (!morphed) return; +#endif if (!isKeepSeed) { RNG rng = rng_make(initSeed, MORPH_RNG_SHIFT); @@ -153,4 +161,7 @@ void Entity_Pickup::Morph(int entityType, int entityVariant, int entitySubType, first->megaChestCollectible[1] = this; } if (flipOther && flipOther->type == type && flipOther->variant == variant) flipSaveState = flipOther; +#ifdef ISAAC_REPENTOGON + pickup_morph_post(*morphed); +#endif } diff --git a/src/entity/pickup/pickup.cpp b/src/entity/pickup/pickup.cpp index 857c4b1..231929d 100644 --- a/src/entity/pickup/pickup.cpp +++ b/src/entity/pickup/pickup.cpp @@ -31,6 +31,10 @@ #include #include #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/callbacks.h" +#include "repentogon/items.h" +#endif // The chest variants (chest, locked, red, bomb, eternal, spiked, mimic, mom's, old, wooden, mega, haunted). constexpr std::array CHESTS = {PICKUP_CHEST, PICKUP_LOCKEDCHEST, PICKUP_REDCHEST, PICKUP_BOMBCHEST, @@ -858,7 +862,11 @@ void Entity_Pickup::Init(int entityType, int entityVariant, int entitySubType, u choice.subType = COLLECTIBLE_BROKEN_SHOVEL_1; charge = g_manager->itemConfig.GetCollectible(COLLECTIBLE_BROKEN_SHOVEL_1)->maxCharges; } - lua_engine_get().PostPickupSelection(this, choice.variant, choice.subType); +#ifdef ISAAC_REPENTOGON + if (!repentogonOptions.isVanillaParity) pickup_selection_post(*this, choice, {entitySubType, entityVariant, seed}); + else +#endif + lua_engine_get().PostPickupSelection(this, choice.variant, choice.subType); bool isPoopBomb = choice.variant == PICKUP_BOMB && g_game->playerManager.are_all_players_tainted_blue_baby() && !is_listed({BOMB_SUBTYPE_TROLL, BOMB_SUBTYPE_SUPERTROLL, BOMB_SUBTYPE_GOLDENTROLL}, choice.subType); @@ -1004,11 +1012,16 @@ void Entity_Pickup::UpdateSprite(bool isIgnoreBlind) } // 006e17c0 Shows a closed chest's or a sack's contents to a holder of Guppy's Eye, while it is not timing out, and -// otherwise removes the preview. +// otherwise removes the preview. A mod's MC_PRE_PICKUP_UPDATE_GHOST_PICKUPS may decide whether it shows. void Entity_Pickup::UpdateLootPreview() { bool isLoot = (IsChest(variant) && subtype != 0) || (variant == PICKUP_GRAB_BAG && !isDead); - if (anyone_has_collectible(COLLECTIBLE_GUPPYS_EYE) && isLoot && timeout < 1) + bool isShown = anyone_has_collectible(COLLECTIBLE_GUPPYS_EYE) && isLoot && timeout < 1; +#ifdef ISAAC_REPENTOGON + CallbackRun run = {"PrePickupUpdateGhostPickups", MC_PRE_PICKUP_UPDATE_GHOST_PICKUPS, variant}; + isShown = callback_boolean_get(run, this).value_or(isShown); +#endif + if (isShown) { LootList loot = GetChestLoot(POOL_DRAW_PEEK, game_nearest_player(pos)); auto* ghost = static_cast(pickupGhost.get()); @@ -1026,9 +1039,17 @@ void Entity_Pickup::Interpolate() } // 006e69b0 Draws the pickup and its price, unless it is waiting to drop. The second item of a Mega Chest's pair is -// drawn by the first. -void Entity_Pickup::Render(const Vector& offset) +// drawn by the first. A mod's MC_PRE_PICKUP_RENDER may skip it or move it. +void Entity_Pickup::Render(const Vector& renderOffset) { +#ifdef ISAAC_REPENTOGON + std::optional moved = render_pre_run({"PrePickupRender", MC_PRE_PICKUP_RENDER, variant}, this, + renderOffset); + if (!moved) return; + const Vector& offset = *moved; +#else + const Vector& offset = renderOffset; +#endif if (!isExists || !isVisible || dropDelay >= 1) return; if (variant == PICKUP_COLLECTIBLE && megaChestCollectible[0]) return; @@ -1164,9 +1185,13 @@ static void rotten_heart_drip(Entity_Pickup& heart) // 006e3940 Runs the pickup for a frame: a thrown chest's flight, Keeper's hearts turning into flies, Sack Head's // sacks, troll bombs going off, holding its place where it must, a scared heart's flight, its motion and friction, // its appear animation and drop sound, the glitch it may appear with, its timeouts and the crawl space's gravity. -// Haunted, mega and mimic chests open or wake, rotten hearts drip, and the seeds slide and hide pickups. +// Haunted, mega and mimic chests open or wake, rotten hearts drip, and the seeds slide and hide pickups. A mod's +// MC_PRE_PICKUP_UPDATE may leave only Entity's update. void Entity_Pickup::Update() { +#ifdef ISAAC_REPENTOGON + if (boolean_run({"PrePickupUpdate", MC_PRE_PICKUP_UPDATE, variant}, false, this)) return Entity::Update(); +#endif if (dropDelay > 0) { if (entityCollisionClass == ENTCOLL_NONE) @@ -1818,7 +1843,7 @@ static bool throwable_bomb_lift(Entity_Pickup& pickup, Entity_Player& player) } // Part of 006e8ae0: a bed sends the players to sleep once, when one of them could use red hearts. Mom's bed always -// does, reviving the co-op ghosts, and at Home it brings the nightmare. +// does, reviving the co-op ghosts, and at Home it brings the nightmare. A mod may leave a player out of the check. static void bed_touch(Entity_Pickup& bed, Entity_Player& player) { constexpr int BED_MOM = 10; @@ -1829,6 +1854,9 @@ static void bed_touch(Entity_Pickup& bed, Entity_Player& player) for (Entity_Player* other : g_game->playerManager.playerList) { if (isUsed) break; +#ifdef ISAAC_REPENTOGON + if (boolean_run({"PreBedSleep", MC_PRE_BED_SLEEP, bed.subtype}, false, other, &bed)) continue; +#endif HealthType health = other->GetHealthType(); int hearts = health == HEALTH_SOUL || health == HEALTH_NO_HEALTH ? other->maxHearts : other->maxHearts + other->boneHearts * 2; @@ -1895,8 +1923,19 @@ static void store_credit_spend(Entity_Player& player, Entity_Pickup* dropped) // kinds. Whether the collision is solid: a priced or collected pickup and players' bombs pass through. // A priced pickup is bought with the player's coins or health, and chests open (entity_pickup_chest.cpp). Taking an // item, opening a chest or a sack starts a challenge room's fight, and a bed sends the players to sleep. A free ware -// spends a Store Credit. +// spends a Store Credit. REPENTOGON's collision callbacks run around it. bool Entity_Pickup::HandleCollision(Entity* collider, bool isLow) +{ +#ifdef ISAAC_REPENTOGON + CollisionCallbacks callbacks = {"PrePickupCollision", MC_PRE_PICKUP_COLLISION, MC_POST_PICKUP_COLLISION, variant}; + return collision_callbacks_run(*this, collider, isLow, callbacks, &Entity_Pickup::collision_react); +#else + return collision_react(collider, isLow); +#endif +} + +// HandleCollision's own code. +bool Entity_Pickup::collision_react(Entity* collider, bool isLow) { if (variant == PICKUP_COLLECTIBLE && megaChestCollectible[0] && g_forceCollideDepth == 0) return true; Entity* megaPartner = variant == PICKUP_COLLECTIBLE ? megaChestCollectible[1].get() : nullptr; @@ -2659,8 +2698,18 @@ void Entity_Pickup::PlayPickupSound() if (sound) pickup_sound_play(sound); } -// 006e8380 How many coins a coin is worth, 0 for anything else. +// 006e8380 How many coins a coin is worth, 0 for anything else. A mod's MC_PICKUP_GET_COIN_VALUE may set a coin's. int Entity_Pickup::GetCoinValue() +{ +#ifdef ISAAC_REPENTOGON + CallbackRun run = {"PickupGetCoinValue", MC_PICKUP_GET_COIN_VALUE, subtype}; + if (variant == PICKUP_COIN) return callback_integer_run(lua_engine_get(), run, coin_worth(), this); +#endif + return coin_worth(); +} + +// GetCoinValue without mods, as Ultra Greed's search for coins reads it. +int Entity_Pickup::coin_worth() { return variant == PICKUP_COIN && subtype >= COIN_PENNY && subtype <= COIN_GOLDEN ? COIN_VALUES[subtype] : 0; } diff --git a/src/entity/pickup/pickup.h b/src/entity/pickup/pickup.h index 1e975d6..cbd2c60 100644 --- a/src/entity/pickup/pickup.h +++ b/src/entity/pickup/pickup.h @@ -230,6 +230,7 @@ struct Entity_Pickup : Entity void PlayDropSound(); void PlayPickupSound(); int GetCoinValue(); + int coin_worth(); bool CanPickupShopItem(Entity_Player& player); void TriggerShopPurchase(Entity_Player& player, int spentMoney); uint8_t empty_pedestal(); @@ -248,6 +249,7 @@ struct Entity_Pickup : Entity static void load_collectible_gfx(ANM2& itemSprite, int layerId, int collectibleId, uint32_t seed, bool isBlind); private: + bool collision_react(Entity* collider, bool isLow); void appear_start(); bool keeper_flies_update(); void target_position_update(); diff --git a/src/entity/pickup/shop.cpp b/src/entity/pickup/shop.cpp index 3fd6b51..f4edeb8 100644 --- a/src/entity/pickup/shop.cpp +++ b/src/entity/pickup/shop.cpp @@ -13,6 +13,9 @@ #include "level/room_special.h" #include #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/callbacks.h" +#endif constexpr int COLLECTIBLE_KEEPERS_SACK = 716; constexpr int ACHIEVEMENT_SHOP_SPENDING = 582; @@ -334,9 +337,12 @@ static bool deal_health_pay(Entity_Player& player, int price) // 006e84d0 Pays for a bought ware (Entity_Pickup::TriggerShopPurchase): coins less the Coupon wisps, which burn, or // the deal's health, which counts as devil damage. A player without health takes the other deals away. A ware bought -// with Restock or in Greed mode restocks its shop slot. +// with Restock or in Greed mode restocks its shop slot. MC_POST_PICKUP_SHOP_PURCHASE follows. void Entity_Pickup::TriggerShopPurchase(Entity_Player& player, int spentMoney) { +#ifdef ISAAC_REPENTOGON + int askedMoney = spentMoney; +#endif if (spentMoney == 0) spentMoney = price; if (spentMoney != 0) { @@ -366,6 +372,10 @@ void Entity_Pickup::TriggerShopPurchase(Entity_Player& player, int spentMoney) g_game->playerManager.FirstCollectibleOwner(COLLECTIBLE_RESTOCK, LAZARUS_SHARE_CHECK) || g_game->IsGreedMode(); if (variant != PICKUP_COLLECTIBLE && spentMoney != 0 && isRestocked && room.roomType == ROOM_SHOP) room_restock_trigger(room, room.GetGridIndex(pos), shopItemId); +#ifdef ISAAC_REPENTOGON + CallbackRun run = {"PostPickupShopPurchase", MC_POST_PICKUP_SHOP_PURCHASE, variant}; + callback_notify(lua_engine_get(), run, this, &player, askedMoney); +#endif } // A player without health taking a devil deal: the room's other deals vanish in a poof, and on the Dark Room's start diff --git a/src/entity/pickup/slot.cpp b/src/entity/pickup/slot.cpp index add99ae..6c6f35c 100644 --- a/src/entity/pickup/slot.cpp +++ b/src/entity/pickup/slot.cpp @@ -22,6 +22,11 @@ #include "level/room_special.h" #include #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/callbacks.h" +#include "repentogon/items.h" +#include "repentogon/player.h" +#endif // The run's state flags of a broken or jammed donation machine, and of one blown up. // The tainted character Home's closet holds for each regular character. @@ -284,9 +289,14 @@ static Vector throw_velocity_get(const Vector& from, RNG* rng) // 00815ae0 (Room::ShopRestockFull) Restocks a shop or black market: forgets the bought-out slots, chooses its wares // again, takes away every ware still for sale and spawns each shop spot of the room's layout anew in a poof, pushing -// any pickup lying there aside. Elsewhere the first player rolls the room's pedestals with the D6. +// any pickup lying there aside. Elsewhere the first player rolls the room's pedestals with the D6. Mods' +// MC_PRE_RESTOCK_SHOP may cancel it, and MC_POST_RESTOCK_SHOP follows. void room_shop_restock_full() { +#ifdef ISAAC_REPENTOGON + if (!shop_restock_pre(RESTOCK_FULL)) return; + ScopeExit post{[] { shop_restock_post(RESTOCK_FULL); }}; +#endif Room& room = *g_game->room; if (room.roomType != ROOM_SHOP && room.roomType != ROOM_BLACK_MARKET) { @@ -540,6 +550,9 @@ void Entity_Slot::Init(int entityType, int entityVariant, int entitySubType, uin } entityGridCollisionClass = GRIDCOLL_NONE; timeout = 0; +#ifdef ISAAC_REPENTOGON + callback_notify(lua_engine_get(), {"PostSlotInit", MC_POST_SLOT_INIT, entityVariant}, (Entity*)this); +#endif } // 00665630 Shows the coins the Revive Machine still asks for on its two digit layers. @@ -560,19 +573,42 @@ void Entity_Slot::counter_show(int count) sprite.SetLayerFrame(3, count % DIGIT_BASE); } -// 00665370 Draws the slot, and a shell game's prize while it plays. -void Entity_Slot::Render(const Vector& offset) +// 00665370 Draws the slot, and a shell game's prize while it plays. Mods' MC_PRE_SLOT_RENDER may skip it or move it, +// and MC_POST_SLOT_RENDER follows. +void Entity_Slot::Render(const Vector& renderOffset) { +#ifdef ISAAC_REPENTOGON + std::optional moved = render_pre_run({"PreSlotRender", MC_PRE_SLOT_RENDER, variant}, this, renderOffset); + if (!moved) return; + const Vector& offset = *moved; +#else + const Vector& offset = renderOffset; +#endif Entity::Render(offset); bool isShellGame = variant == SLOT_SHELL_GAME || variant == SLOT_HELL_GAME; if (isShellGame && prizeAnm2.animState.animData && prizeAnm2.animState.isPlaying) prizeAnm2.Render(SpriteDraw{renderPosition, {}, {}}); +#ifdef ISAAC_REPENTOGON + callback_notify(lua_engine_get(), {"PostSlotRender", MC_POST_SLOT_RENDER, variant}, (Entity*)this, offset); +#endif } // 00665500 Sets the collectible a slot pays out, shown on the Hell Game's prize layer or the Crane Game's glass (a -// question mark under Curse of the Blind). +// question mark under Curse of the Blind). Mods' MC_PRE_SLOT_SET_PRIZE_COLLECTIBLE may cancel or change it, and +// MC_POST_SLOT_SET_PRIZE_COLLECTIBLE follows. void Entity_Slot::SetPrizeType(int collectibleId) { +#ifdef ISAAC_REPENTOGON + LuaEngine& engine = lua_engine_get(); + if (callback_run(engine, {"PreSlotSetPrize", MC_PRE_SLOT_SET_PRIZE_COLLECTIBLE, variant}, (Entity*)this, + collectibleId)) + { + bool isCancelled = lua_isboolean(engine.state, -1) && !lua_toboolean(engine.state, -1); + if (lua_isnumber(engine.state, -1)) collectibleId = (int)lua_tonumber(engine.state, -1); + lua_pop(engine.state, 1); + if (isCancelled) return; + } +#endif prizeCollectible = collectibleId; bool isBlind = g_game->GetCurses() & CURSE_OF_BLIND; if (variant == SLOT_HELL_GAME) @@ -585,6 +621,10 @@ void Entity_Slot::SetPrizeType(int collectibleId) Entity_Pickup::load_collectible_gfx(sprite, CRANE_GAME_PRIZE_LAYER, prizeCollectible, dropRNG._seed, isBlind); sprite.LoadGraphics(); } +#ifdef ISAAC_REPENTOGON + callback_notify(engine, {"PostSlotSetPrize", MC_POST_SLOT_SET_PRIZE_COLLECTIBLE, variant}, (Entity*)this, + collectibleId); +#endif } // 006657a0 (an overload Ghidra names Entity_Slot::HandleCollision) Throws pickups out of the slot, each at a velocity @@ -1697,7 +1737,20 @@ void Entity_Slot::closet_effects_update() // 0065d950 Runs a slot each frame: its appearance, its spot, a Rotten Beggar's first splat, a Bomb Bum's Troll Bombs, // the slot machine's roll once its spin ends, the Crane Game and Confessional prizes, and the payout once a payment's // animation is done. A shell game shuffles with a sound, and touches count while a player keeps touching it. +// Mods' MC_PRE_SLOT_UPDATE may leave only Entity's update, and MC_POST_SLOT_UPDATE follows the slot's own. void Entity_Slot::Update() +{ +#ifdef ISAAC_REPENTOGON + if (boolean_run({"PreSlotUpdate", MC_PRE_SLOT_UPDATE, variant}, false, (Entity*)this)) return Entity::Update(); + update_frame(); + callback_notify(lua_engine_get(), {"PostSlotUpdate", MC_POST_SLOT_UPDATE, variant}, (Entity*)this); +#else + update_frame(); +#endif +} + +// Update's own code. +void Entity_Slot::update_frame() { if (variant == SLOT_CRANE_GAME && state != SLOT_STATE_BROKEN && prizeCollectible == 0) SetPrizeType(g_game->itemPool.GetCollectible(POOL_CRANE_GAME, dropRNG._seed, 0, COLLECTIBLE_BUDDY_IN_A_BOX, 0)); @@ -2079,6 +2132,10 @@ static void beths_essence_wisp_add(Entity_Player& player, const Vector& position // behind the pair when it is to swap with another pair. The costumes are then rebuilt. static void costumes_shuffle(Entity_Player& player, uint32_t seed) { +#ifdef ISAAC_REPENTOGON + if (costumes_shuffle_is_cancelled(player, seed)) return; + ScopeExit shufflePost = {[&] { costumes_shuffle_post(player, seed); }}; +#endif constexpr uint32_t DRESSER_SHUFFLE_SHIFT = 19; std::vector& costumes = player.costumeSpriteDescs; int count = (int)costumes.size(); @@ -2138,8 +2195,19 @@ void Entity_Slot::dresser_open(Entity_Player& player) // 006627e0 A player touching an idle slot pays it, which makes it the slot's target, may give Beth's Essence a wisp // for a beggar, and starts the slot's payment. A player touching Mom's dresser opens it. Touches are counted while a -// player keeps touching. Enemies and bombs pass through a slot. -bool Entity_Slot::HandleCollision(Entity* collider, bool) +// player keeps touching. Enemies and bombs pass through a slot. REPENTOGON's collision callbacks run around it. +bool Entity_Slot::HandleCollision(Entity* collider, bool isLow) +{ +#ifdef ISAAC_REPENTOGON + CollisionCallbacks callbacks = {"PreSlotCollision", MC_PRE_SLOT_COLLISION, MC_POST_SLOT_COLLISION, variant, false}; + return collision_callbacks_run(*this, collider, isLow, callbacks, &Entity_Slot::collision_react); +#else + return collision_react(collider, isLow); +#endif +} + +// HandleCollision's own code. +bool Entity_Slot::collision_react(Entity* collider, bool) { bool isPlayer = collider->type == ENTITY_PLAYER; if (variant == SLOT_MOMS_DRESSER && isPlayer && collider->variant == PLAYER_VARIANT_PLAYER && @@ -2306,7 +2374,20 @@ bool Entity_Slot::TakeDamage(float, uint64_t damageFlags, const EntityRef& sourc // heart from a Rotten Beggar, coins from a restock machine, coins or hearts from the blood donation machine, Mom's // dresser's clothes or a rare item, a Revive Machine's hearts or bomb in a boss room, and from the rest a trinket or // pill, a rare chest, or coins, hearts, keys and bombs (Lucky Toe giving one more, drop trinkets a matching pickup). +// Mods' MC_PRE_SLOT_CREATE_EXPLOSION_DROPS may cancel them, and MC_POST_SLOT_CREATE_EXPLOSION_DROPS follows. void Entity_Slot::spawn_break_drops() +{ +#ifdef ISAAC_REPENTOGON + if (!boolean_run({"PreSlotDrops", MC_PRE_SLOT_CREATE_EXPLOSION_DROPS, variant}, true, (Entity*)this)) return; + break_drops_create(); + callback_notify(lua_engine_get(), {"PostSlotDrops", MC_POST_SLOT_CREATE_EXPLOSION_DROPS, variant}, (Entity*)this); +#else + break_drops_create(); +#endif +} + +// spawn_break_drops's own code. +void Entity_Slot::break_drops_create() { RNG* daemonsTail = nullptr; g_game->playerManager.RandomTrinketOwner(TRINKET_DAEMONS_TAIL, initSeed, &daemonsTail); diff --git a/src/entity/pickup/slot.h b/src/entity/pickup/slot.h index 68367a2..77e8ad7 100644 --- a/src/entity/pickup/slot.h +++ b/src/entity/pickup/slot.h @@ -79,6 +79,9 @@ struct Entity_Slot : Entity void SetPrizeType(int prizeType); private: + bool collision_react(Entity* collider, bool isLow); + void update_frame(); + void break_drops_create(); void counter_show(int count); void revive_counter_show(); void drops_spawn(const SlotDrop& drop); diff --git a/src/entity/player/actives.cpp b/src/entity/player/actives.cpp index f26ae6c..023043a 100644 --- a/src/entity/player/actives.cpp +++ b/src/entity/player/actives.cpp @@ -41,6 +41,11 @@ #include #include #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/callbacks.h" +#include "repentogon/items.h" +#include "repentogon/player.h" +#endif constexpr int ACHIEVEMENT_HALO = 27; constexpr int ACTIVE_PICKUP_HOLD_FRAMES = 30; @@ -224,10 +229,10 @@ static bool is_action_met(ButtonAction action, int controllerIndex, ActionTest t return false; } -// A mod's answer to an action test through MC_INPUT_ACTION, asked only in a run. +// A mod's answer to an action test through MC_INPUT_ACTION, asked only in a run (anywhere with REPENTOGON). static std::optional action_hook_run(Entity* entity, int hook, ButtonAction action) { - if (g_manager->state != MANAGER_STATE_GAME || !g_luaEngine) return std::nullopt; + if (!is_input_hook_asked()) return std::nullopt; return lua_engine_get().InputAction(entity, hook, action); } @@ -354,6 +359,9 @@ bool Entity_Player::HasTimedItem() // Necromancer's Necronomicon. int Entity_Player::GetCollectibleMaxCharge(int collectibleId, int varData) { +#ifdef ISAAC_REPENTOGON + if (std::optional charge = active_max_charge_hook(*this, collectibleId, varData)) return *charge; +#endif constexpr int VARDATA_CHARGED[] = {263, 286, 348, 510}; constexpr int D_INFINITY = 489; constexpr int SUMPTORIUM = 713; @@ -403,6 +411,9 @@ int Entity_Player::GetActiveMaxCharge(int slot) // 00791380 The charges an active slot needs before it can be used: one for the items that spend what they have. int Entity_Player::GetActiveMinUsableCharge(int slot) { +#ifdef ISAAC_REPENTOGON + if (std::optional charge = active_min_charge_hook(*this, slot)) return *charge; +#endif if (slot == ACTIVE_SLOT_POCKET2) return 0; if (slot == ACTIVE_SLOT_POCKET && activeItems[slot].item == COLLECTIBLE_RED_KEY && g_game->challenge == CHALLENGE_RED_REDEMPTION) @@ -497,6 +508,10 @@ void Entity_Player::SetActiveCharge(int charge, int slot) // A filled Broken Glass Cannon mends. The charge added, negative when taken. int Entity_Player::AddActiveCharge(int charge, int slot, bool isFlashHud, bool isOvercharge, bool isForce) { +#ifdef ISAAC_REPENTOGON + max_charge_cache_begin(); + ScopeExit cacheEnd = {max_charge_cache_end}; +#endif if (slot < 0) { int added = 0; @@ -752,9 +767,12 @@ static void esau_jr_swap(Entity_Player& player, uint32_t slot) // 007ac7e0 Spends an active slot's charge after a use, its battery charge becoming the charge. Bethany pays what was // missing in soul or blood charges, 9 Volt gives one back. Esau Jr. swaps with its stored player (making one first), -// Flip moves the item, the rest is the after use. +// Flip moves the item, the rest is the after use. MC_POST_DISCHARGE_ACTIVE_ITEM follows. void Entity_Player::DischargeActiveItem(uint32_t slot, bool isRemoved) { +#ifdef ISAAC_REPENTOGON + ScopeExit dischargedPost = {[=, this] { active_discharge_post(*this, slot, isRemoved); }}; +#endif if (slot >= (uint32_t)ACTIVE_SLOT_COUNT || activeItems[slot].item == 0) return; ActiveItemDesc& active = activeItems[slot]; @@ -831,7 +849,7 @@ static void trinket_active_use(Entity_Player& player, int item) } // M!: the spent active turns into another, weighed toward the low qualities (a glitched one with TMTRAINER), with more -// copies sometimes fully charged. +// copies sometimes fully charged. A mod may pick the new active or keep the old one. static void m_trinket_swap(Entity_Player& player) { constexpr int QUALITY_WEIGHTS[] = {5, 4, 3, 2, 1}; @@ -850,6 +868,16 @@ static void m_trinket_swap(Entity_Player& player) swapped = picker.PickOutcome(rng_make(rng.Next(), DEFAULT_SHIFT_INDEX)); } if (swapped == 0) return; +#ifdef ISAAC_REPENTOGON + LuaEngine& engine = lua_engine_get(); + if (callback_run(engine, {"PreMMorphActive", MC_PRE_M_MORPH_ACTIVE, std::nullopt}, &player, swapped)) + { + if (is_result_false(engine.state)) swapped = 0; + else if (lua_isinteger(engine.state, -1)) swapped = (int)lua_tointeger(engine.state, -1); + lua_pop(engine.state, 1); + } + if (swapped == 0) return; +#endif int copies = player.GetTrinketMultiplier(TRINKET_M); player.RemoveCollectible(player.activeItems[ACTIVE_SLOT_PRIMARY].item, false, ACTIVE_SLOT_PRIMARY, true); @@ -1999,15 +2027,28 @@ static void item_effect_run(ItemUse& use) // 005b39d0 Uses an active item: co-op babies copy the main player's first use since a discharge, the item is raised // with its sound, its own effect runs, mods see the use, its room effect and costume go on and the stats are reread. -// What its slot does next: discharge unless an item state holds the item, and remove it if a mod asks. +// What its slot does next: discharge unless an item state holds the item, and remove it if a mod asks. REPENTOGON's +// MC_PRE_USE_ITEM may also keep the charge, and its MC_POST_USE_ITEM follows a use that was not prevented. UseResult Entity_Player::UseActiveItem(const ActiveUse& request) { - UseResult result; - if (request.item == 0 || request.slot >= ACTIVE_SLOT_COUNT) return result; + if (request.item == 0 || request.slot >= ACTIVE_SLOT_COUNT) return {}; +#ifdef ISAAC_REPENTOGON + if (std::optional prevented = active_use_pre(*this, request)) return *prevented; + UseResult result = active_item_use(request); + active_use_post(*this, request, result); + return result; +#else LuaItemUse preUse = {.player = this, .rng = &GetCollectibleRNG(request.item), .activeSlot = request.slot, .collectibleType = request.item, .customVarData = request.varData, .useFlags = request.flags}; - if (lua_engine_get().PreUseItem(preUse)) return result; + if (lua_engine_get().PreUseItem(preUse)) return {}; + return active_item_use(request); +#endif +} +// UseActiveItem's own code once the mods let the use happen. +UseResult Entity_Player::active_item_use(const ActiveUse& request) +{ + UseResult result; if (variant == PLAYER_VARIANT_PLAYER && !isActiveUsed) for (Entity_Player* each : g_game->playerManager.playerList) if (each->variant == PLAYER_VARIANT_COOP_BABY) each->UseActiveItem({.item = request.item}); @@ -2776,6 +2817,10 @@ void Entity_Player::update_suplex() // keeps is never set. void Entity_Player::ControlActiveItem(int slot) { +#ifdef ISAAC_REPENTOGON + max_charge_cache_begin(); + ScopeExit cacheEnd = {max_charge_cache_end}; +#endif if (variant == PLAYER_VARIANT_COOP_BABY || isCoopGhost || IsHologram() || playerType == PLAYER_THESOUL_B) return; ButtonAction action = slot != ACTIVE_SLOT_PRIMARY ? ACTION_PILL_CARD : twin_button_action(*this, TWIN_BUTTON_ITEM); ItemButton button = {.isPressed = input_is_action_pressed(action, controllerIndex, this), diff --git a/src/entity/player/actives_afterbirth.cpp b/src/entity/player/actives_afterbirth.cpp index 15773bf..f4aaf51 100644 --- a/src/entity/player/actives_afterbirth.cpp +++ b/src/entity/player/actives_afterbirth.cpp @@ -24,6 +24,9 @@ #include #include #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/callbacks.h" +#endif // The achievement a character entry carries when nothing unlocks it at all. constexpr int PLAYER_NEVER_UNLOCKED = -2; @@ -175,7 +178,8 @@ static void void_item_absorb(Entity_Player& player, RNG& rng, const VoidedPassiv } // The Void: every active it ate fires again (Breath of Life as a blink of invincibility), then it eats the item held -// up and every free pedestal item (a co-op choice is put back rolled from the boss pool). Apollyon's Birthright may +// up and every free pedestal item (a co-op choice is put back rolled from the boss pool), unless a mod's +// MC_PRE_PICKUP_VOIDED spares it. Apollyon's Birthright may // first throw out a passive it ate. Book of Virtues adds a wisp per eaten active, and eating starts a challenge room. static void void_use(ItemUse& use) { @@ -188,8 +192,11 @@ static void void_use(ItemUse& use) { if (entity->type != ENTITY_PICKUP || entity->isDead) continue; auto* pickup = static_cast(entity); - if (pickup->CanReroll() && pickup->variant == PICKUP_COLLECTIBLE && !pickup->IsShopItem()) - pedestals.push_back(pickup); + if (!pickup->CanReroll() || pickup->variant != PICKUP_COLLECTIBLE || pickup->IsShopItem()) continue; +#ifdef ISAAC_REPENTOGON + if (!boolean_run({"PrePickupVoided", MC_PRE_PICKUP_VOIDED, pickup->variant}, true, pickup, false)) continue; +#endif + pedestals.push_back(pickup); } QueueItemData queued = player.queuedItem; bool isQueued = queued.item && queued.item->IsCollectible() && !queued.item->HasTags(TAG_QUEST); diff --git a/src/entity/player/actives_repentance.cpp b/src/entity/player/actives_repentance.cpp index e85e117..881fcaa 100644 --- a/src/entity/player/actives_repentance.cpp +++ b/src/entity/player/actives_repentance.cpp @@ -29,6 +29,9 @@ #include "level/room_grid.h" #include #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/callbacks.h" +#endif constexpr int ALABASTER_BOX_DELAY = 30; constexpr int ALABASTER_EXTRA_WISPS = 4; @@ -845,7 +848,8 @@ static void magic_skin_use(ItemUse& use) } // Compost: every blue fly and spider doubled (a random one of the two when there are none), and every free pickup of -// the room turned into one. Book of Virtues' wisp counts the pickups composted. +// the room turned into one, unless a mod's MC_PRE_PICKUP_COMPOSTED spares it. Book of Virtues' wisp counts the pickups +// composted. static void compost_use(ItemUse& use) { Entity_Player& player = use.player; @@ -876,6 +880,9 @@ static void compost_use(ItemUse& use) ? static_cast(entities[i]) : nullptr; if (!pickup || pickup->IsShopItem() || !pickup->CanReroll()) continue; +#ifdef ISAAC_REPENTOGON + if (!boolean_run({"PrePickupComposted", MC_PRE_PICKUP_COMPOSTED, pickup->variant}, true, pickup)) continue; +#endif pickup->Remove(); composted++; if (rng.RandomInt(2) == 0) player.AddBlueSpider(pickup->pos); diff --git a/src/entity/player/bombs.cpp b/src/entity/player/bombs.cpp index 12280a1..f36adfe 100644 --- a/src/entity/player/bombs.cpp +++ b/src/entity/player/bombs.cpp @@ -13,6 +13,10 @@ #include #include #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/callbacks.h" +#include "repentogon/player.h" +#endif // The items a player's bombs ask about (Lua's CollectibleType and TrinketType). constexpr int COLLECTIBLE_BOBBY_BOMB = 125; @@ -295,6 +299,9 @@ void Entity_Player::update_bomb_input() bool isGiga = numGigaBombs > 0; if (numBombs < 1 && !isFree && HasCollectible(COLLECTIBLE_BLOOD_BOMBS)) isFree = blood_bomb_pay(*this); if (numBombs < 1 && !isFree) return; +#ifdef ISAAC_REPENTOGON + if (player_bomb_use_is_cancelled(*this)) return; +#endif bombPlaceDelay = HasCollectible(COLLECTIBLE_FAST_BOMBS) ? BOMB_DELAY_FAST : BOMB_DELAY; DeathmatchManager& versus = g_game->deathmatchManager; @@ -340,6 +347,9 @@ void Entity_Player::update_bomb_input() } } bomb.Update(); +#ifdef ISAAC_REPENTOGON + player_bomb_post_use(*this, bomb); +#endif } } @@ -415,5 +425,8 @@ Entity_Bomb* Entity_Player::FireBomb(Vector position, Vector throwVelocity, Enti laser.spawnerEntity = this; } if (bomb.IsRocket()) bomb.Update(); +#ifdef ISAAC_REPENTOGON + unfiltered_notify("PostFireBomb", MC_POST_FIRE_BOMB, &bomb); +#endif return &bomb; } diff --git a/src/entity/player/cards.cpp b/src/entity/player/cards.cpp index 3d24a30..38624a0 100644 --- a/src/entity/player/cards.cpp +++ b/src/entity/player/cards.cpp @@ -28,6 +28,9 @@ #include #include #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/callbacks.h" +#endif // The room transition's flags Tarot Cloth's Hermit and Stars set. enum CardTransitionFlag : uint32_t @@ -1297,7 +1300,7 @@ static void black_rune_stats_raise(Entity_Player& player) // Black Rune: the item held up and every free pedestal item are eaten for stat ups (a co-op pedestal choice is put back // rerolled from the boss pool), every other free pickup turns into a blue fly, the Necronomicon hurts the room and a -// challenge room's waves start if anything was eaten. +// challenge room's waves start if anything was eaten. A mod's MC_PRE_PICKUP_VOIDED may spare a pickup. static PocketUseEnd black_rune_use(PocketUse& use) { Entity_Player& player = use.player; @@ -1317,6 +1320,9 @@ static PocketUseEnd black_rune_use(PocketUse& use) { auto* pickup = entity->type == ENTITY_PICKUP ? static_cast(entity) : nullptr; if (!pickup || pickup->IsShopItem() || pickup->isDead || !pickup->CanReroll()) continue; +#ifdef ISAAC_REPENTOGON + if (!boolean_run({"PrePickupVoided", MC_PRE_PICKUP_VOIDED, pickup->variant}, true, pickup, true)) continue; +#endif if (pickup->variant == PICKUP_COLLECTIBLE && pickup->subtype != 0 && pickup->timeout < 1) { isEaten = true; diff --git a/src/entity/player/characters.cpp b/src/entity/player/characters.cpp index 750c572..e6ef227 100644 --- a/src/entity/player/characters.cpp +++ b/src/entity/player/characters.cpp @@ -22,6 +22,9 @@ #include #include #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/player.h" +#endif constexpr uint64_t DEAD_BIRD_VERSUS_MS = 30001; constexpr int DEAD_BIRD_VERSUS_FRAMES = 450; @@ -625,6 +628,10 @@ void Entity_Player::RemoveSkinCostume() // Tainted Forgotten is dropped by its soul and gets its weapons back. The extra layer shows again. void Entity_Player::Revive() { +#ifdef ISAAC_REPENTOGON + if (player_revive_is_cancelled(*this)) return; + ScopeExit revivePost = {[this] { player_revive_post(*this); }}; +#endif if (!isDead) return; isDead = false; @@ -1298,6 +1305,9 @@ void cambion_conception_hit(Entity_Player& player) int sound = SOUND_CAMBION_CONCEPTION; seed_fart_sound_override(&sound); g_manager->sfxManager.Play(sound); +#ifdef ISAAC_REPENTOGON + if (player_birth_is_cancelled(player, flag, BIRTH_CAMBION)) break; +#endif player.conceptionFamiliarFlags |= flag; player.cacheFlags |= CACHE_FAMILIARS; player.EvaluateItems(); diff --git a/src/entity/player/collectibles.cpp b/src/entity/player/collectibles.cpp index 0e7d8c9..06234dc 100644 --- a/src/entity/player/collectibles.cpp +++ b/src/entity/player/collectibles.cpp @@ -17,6 +17,11 @@ #include "level/room_grid.h" #include #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/callbacks.h" +#include "repentogon/items.h" +#include "repentogon/player.h" +#endif // The collectibles and null items losing an item names (Lua's CollectibleType and NullItemID). enum RemovalItem : int @@ -140,11 +145,16 @@ static void pocket_excess_drop(Entity_Player& player) uint32_t seed = Random(); Vector spot = room_free_pickup_position_find({.position = player.pos, .step = REMOVED_DROP_STEP}); - g_game->Spawn({.position = spot, .spawner = &player, .subType = pocket.id, .type = ENTITY_PICKUP, - .variant = pocket.type == POCKET_CARD ? PICKUP_TAROTCARD : PICKUP_PILL, .seed = seed}); + int variant = pocket.type == POCKET_CARD ? PICKUP_TAROTCARD : PICKUP_PILL; + [[maybe_unused]] Entity* dropped = g_game->Spawn({.position = spot, .spawner = &player, .subType = pocket.id, + .type = ENTITY_PICKUP, .variant = variant, .seed = seed}); + [[maybe_unused]] PocketItem lost = pocket; std::move(player.pocketItems.begin() + slot + 1, player.pocketItems.end(), player.pocketItems.begin() + slot); player.pocketItems.back() = {}; excess--; +#ifdef ISAAC_REPENTOGON + pocket_post_drop(player, lost.type, lost.id, slot, dropped); +#endif } } @@ -207,9 +217,13 @@ static void collectible_last_removed(Entity_Player& player, int collectibleId) // 0078ff90 What losing a collectible undoes: Leo's and Magic Mushroom's count towards their form, Dead Cat's lives, and // Heartbreak's broken hearts. With the last copy gone, the item's own loss runs (see collectible_last_removed), and an -// effect that clears on removal ends. Netplay's stats are offline. +// effect that clears on removal ends. Netplay's stats are offline. MC_POST_TRIGGER_COLLECTIBLE_REMOVED follows. void Entity_Player::TriggerCollectibleRemoved(int collectibleId) { +#ifdef ISAAC_REPENTOGON + CollectibleRemoval removal = std::exchange(collectibleRemoval, REMOVAL_KIND_FORM); + ScopeExit removedPost = {[=, this] { collectible_removed_post(*this, collectibleId, removal); }}; +#endif if (collectibleId == REMOVAL_MAGIC_MUSHROOM || collectibleId == REMOVAL_LEO) IncrementPlayerFormCounter(PLAYER_FORM_STOMPY, -1); else if (collectibleId == REMOVAL_DEAD_CAT) @@ -499,8 +513,11 @@ static void null_effect_end(Entity_Player& player, int nullItem) // trinket's effect takes its costume off (Faded Polaroid's fading colour too). A collectible's doubled costumes come // off, Mega Mush shrinks back, its costume comes off unless the item keeps it, and its own end runs (see // collectible_effect_end). -void Entity_Player::trigger_collectible_effect_removed(ItemConfig_Item* item, int) +void Entity_Player::trigger_collectible_effect_removed(ItemConfig_Item* item, [[maybe_unused]] int count) { +#ifdef ISAAC_REPENTOGON + ScopeExit removedPost = {[&] { player_effect_post_remove(*this, item, count); }}; +#endif if (item->type == ITEM_NULL) return null_effect_end(*this, item->id); if (item->type == ITEM_TRINKET) { @@ -569,6 +586,9 @@ void Entity_Player::RemoveCollectible(int type, bool isIgnoreModifiers, int acti break; } +#ifdef ISAAC_REPENTOGON + collectibleRemoval = isRemoveFromForm ? REMOVAL_KIND_FORM : REMOVAL_KIND_KEEP_FORM; +#endif TriggerCollectibleRemoved(type); doubled_costume_remove(*this, type); if (type >= 0 && collectibleCounts[type] < 1) diff --git a/src/entity/player/crafting.cpp b/src/entity/player/crafting.cpp index 0ee64c6..0c58f3a 100644 --- a/src/entity/player/crafting.cpp +++ b/src/entity/player/crafting.cpp @@ -15,6 +15,9 @@ #include "engine/seeds.h" #include #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/items.h" +#endif // The pickups the bag holds (REPENTOGON's BagOfCraftingPickup), in recipes.xml's symbol order. enum BagPickup : uint8_t @@ -212,7 +215,8 @@ static std::optional> bag_ingredients_get(int variant, in // 007d5170 Takes a pickup the bag's swing touched into Tainted Cain's bag: its one or two bag pickups push out the // oldest when full, it poofs (black when Book of Belial turned a red heart black), dies into its "Collect" animation -// and is paid for, and a full bag works out what it crafts. Whether the bag took it. +// and is paid for, and a full bag works out what it crafts. Whether the bag took it. Mods' +// MC_TRY_ADD_TO_BAG_OF_CRAFTING may change its ingredients, and MC_POST_ADD_TO_BAG_OF_CRAFTING follows. bool Entity_Player::bag_of_crafting_collect(Entity_Pickup* pickup) { int variant = pickup->variant; @@ -228,10 +232,16 @@ bool Entity_Player::bag_of_crafting_collect(Entity_Pickup* pickup) isBlackened = true; } std::optional> ingredients = bag_ingredients_get(variant, subType); - if (!ingredients) return false; +#ifdef ISAAC_REPENTOGON + std::optional added = bag_ingredients_hook(*this, *pickup, ingredients); + if (!added) return false; +#else + std::optional>& added = ingredients; + if (!added) return false; +#endif size_t count = std::ranges::find(bagOfCraftingContent, BAG_NONE) - bagOfCraftingContent.begin(); - for (uint8_t ingredient : *ingredients) + for (uint8_t ingredient : *added) { if (ingredient == BAG_NONE) continue; if (count >= BAG_OF_CRAFTING_SIZE) @@ -265,6 +275,9 @@ bool Entity_Player::bag_of_crafting_collect(Entity_Pickup* pickup) bagOfCraftingOutput = output.output; bagOfCraftingPool = output.pool; g_game->hud.InvalidateCraftingItem(this); +#ifdef ISAAC_REPENTOGON + bag_add_post(*this, *pickup); +#endif return true; } diff --git a/src/entity/player/damage.cpp b/src/entity/player/damage.cpp index 726d20b..c2c0334 100644 --- a/src/entity/player/damage.cpp +++ b/src/entity/player/damage.cpp @@ -25,6 +25,10 @@ #include "level/room_grid.h" #include #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/entities.h" +#include "repentogon/player.h" +#endif #include constexpr int COLLECTIBLE_BINKY = 438; @@ -941,6 +945,11 @@ static void astral_projection_start(Entity_Player& player) // grunt and the Hit animation, starts the invincibility frames, and kills the player out of hearts. True when it hurt. bool Entity_Player::TakeDamage(float damage, uint64_t damageFlags, const EntityRef& source, int damageCountdown) { +#ifdef ISAAC_REPENTOGON + if (std::optional isHurt = player_damage_hook(*this, {source, damage, nullptr, damageCountdown, damageFlags})) + return *isHurt; + if (player_damage_is_cancelled(*this, damage, damageFlags, source, damageCountdown)) return false; +#endif Game& game = *g_game; Entity_Player* twin = twin_get(); @@ -1010,7 +1019,12 @@ bool Entity_Player::TakeDamage(float damage, uint64_t damageFlags, const EntityR AddEntityFlags(FLAG_NO_DAMAGE_BLINK); return false; } +#ifdef ISAAC_REPENTOGON + if (!entity_damage_pre(*this, {source, damage, &amount, damageCountdown, damageFlags})) return false; + isPenalized = !(damageFlags & DAMAGE_UNPENALIZED); +#else if (!lua_engine_get().EntityTakeDamage(this, (float)amount, damageFlags, source, damageCountdown)) return false; +#endif if (try_end_astral_projection()) return false; if (playerType == PLAYER_JACOB_B && source.type == ENTITY_DARK_ESAU) { diff --git a/src/entity/player/death.cpp b/src/entity/player/death.cpp index 1f5b1c3..53a3807 100644 --- a/src/entity/player/death.cpp +++ b/src/entity/player/death.cpp @@ -30,6 +30,10 @@ #include #include #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/callbacks.h" +#include "repentogon/player.h" +#endif constexpr float DEATH_FRICTION = 0.6f; @@ -570,8 +574,12 @@ static void soul_of_lazarus_revive(Entity_Player& holder, std::vector& players, int old // Missing Poster says so in a Sacrifice Room, where dying with it unlocks the Lost. bool Entity_Player::TriggerDeath(bool isCheckOnly) { +#ifdef ISAAC_REPENTOGON + if (!isCheckOnly) + if (std::optional isRevived = player_death_pre_trigger(*this)) return *isRevived; +#endif Game& game = *g_game; if (variant == PLAYER_VARIANT_COOP_BABY) @@ -740,6 +752,9 @@ bool Entity_Player::TriggerDeath(bool isCheckOnly) Revival revival = revival_find(*this, players); if (isCheckOnly) return revival.kind == REVIVAL_POSTER_LOCKED ? isSacrificeRoom : revival.kind != REVIVAL_NONE; revival_apply(revival, players); +#ifdef ISAAC_REPENTOGON + if (revival.kind == REVIVAL_NONE || revival.kind == REVIVAL_POSTER_LOCKED) player_death_post_check_revives(*this); +#endif for (Entity_Player* player : players) { @@ -961,6 +976,9 @@ void Entity_Player::death_update() // the longest walked, the after-images go, and a soul player of the Forgotten or Jacob leaves. void Entity_Player::room_exit(bool isKeepHolyMantle) { +#ifdef ISAAC_REPENTOGON + callback_notify(lua_engine_get(), {"PreRoomExit", MC_PRE_ROOM_EXIT, std::nullopt}, this, isKeepHolyMantle); +#endif ItemConfig& items = g_manager->itemConfig; Game& game = *g_game; diff --git a/src/entity/player/evaluate.cpp b/src/entity/player/evaluate.cpp index 61d5cd2..d44fe0f 100644 --- a/src/entity/player/evaluate.cpp +++ b/src/entity/player/evaluate.cpp @@ -13,6 +13,9 @@ #include #include #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/stats.h" +#endif // The stat evaluation's constants: the tears formula, the base stats and the clamps that end it. constexpr float TEARS_CURVE_SCALE = 1.3f; @@ -259,6 +262,9 @@ static void fire_delay_evaluate(Entity_Player& p, const StatBonuses& bonus) if (effects.HasCollectibleEffect(COLLECTIBLE_MEGA_MUSH)) tears = tears - 1.9f; if (p.HasPlayerForm(PLAYER_FORM_CONJOINED)) tears = tears - 0.3f; if (p.coopBabyBuffTimers[COOP_BUFF_TEARS] > 0) tears = tears + 1; +#ifdef ISAAC_REPENTOGON + tears = stat_evaluate(p, tears, STAT_STAGE_TEARS_UP); +#endif float curve = std::sqrt(std::max(tears * TEARS_CURVE_SCALE + 1, 0.0f)); float delay = std::max(TEARS_DELAY_BASE - curve * TEARS_DELAY_STEP - std::min(tears, 0.0f) * TEARS_DELAY_STEP, @@ -297,6 +303,9 @@ static void fire_delay_evaluate(Entity_Player& p, const StatBonuses& bonus) rate = glitched_stat_get(p, GLITCHED_TEARS) + rate; if (p.grantedCollectibleCountdown > 0) rate = rate + 1.5f; if (TemporaryEffect* camo = effects.GetNullEffect(NULLITEM_CAMO_BOOST)) rate = rate + (float)camo->count * 0.25f; +#ifdef ISAAC_REPENTOGON + rate = stat_evaluate(p, rate, STAT_STAGE_FLAT_TEARS); +#endif if (!has(245)) { @@ -461,6 +470,9 @@ static void damage_evaluate(Entity_Player& p, const StatBonuses& bonus) damage = (float)effects.GetNullEffectNum(NULLITEM_WAVY_CAP_1) * 0.2f + (float)e(COLLECTIBLE_WAVY_CAP) * 0.2f + damage; if (ChallengeParam* challenge = g_game->challenge != 0 ? &g_manager->GetChallengeParams(g_game->challenge) : nullptr) damage = challenge->addDamage + damage; +#ifdef ISAAC_REPENTOGON + damage = stat_evaluate(p, damage, STAT_STAGE_DAMAGE_UP); +#endif if (has(120) || effects.HasCollectibleEffect(120)) damage = damage * 0.9f - 0.4f; if (effects.HasCollectibleEffect(COLLECTIBLE_THE_NAIL)) damage = (float)(e(COLLECTIBLE_THE_NAIL) + e(COLLECTIBLE_THE_NAIL)) + damage; @@ -494,6 +506,9 @@ static void damage_evaluate(Entity_Player& p, const StatBonuses& bonus) : damage + 5; damage = damage * character_damage_scale_get(p); if (p.variant == PLAYER_VARIANT_COOP_BABY && p.babySkin == BABY_BONE) damage = damage * 1.5f; +#ifdef ISAAC_REPENTOGON + damage = stat_evaluate(p, damage, STAT_STAGE_PRE_FLAT_DAMAGE); +#endif damage = damage + character_damage_get(p); if (effects.HasNullEffect(NULLITEM_ESAU_JR)) damage = damage + 2; if (effects.HasCollectibleEffect(COLLECTIBLE_MEGA_MUSH)) damage = damage * 4; @@ -508,6 +523,9 @@ static void damage_evaluate(Entity_Player& p, const StatBonuses& bonus) if (has(513)) damage = damage + 0.1f; if (effects.HasNullEffect(NULLITEM_HUGE_GROWTH)) damage = damage + 7; if (p.HasWeaponType(WEAPON_BONE) && has(114)) damage = damage + 4; +#ifdef ISAAC_REPENTOGON + damage = stat_evaluate(p, damage, STAT_STAGE_FLAT_DAMAGE); +#endif if (has(COLLECTIBLE_CROWN_OF_LIGHT) && effects.HasCollectibleEffect(COLLECTIBLE_CROWN_OF_LIGHT)) damage = damage + damage; if (has(182)) damage = damage * 2.3f + 1; diff --git a/src/entity/player/forgotten.cpp b/src/entity/player/forgotten.cpp index 87bf740..0bc61f3 100644 --- a/src/entity/player/forgotten.cpp +++ b/src/entity/player/forgotten.cpp @@ -15,6 +15,9 @@ #include "level/room_transition.h" #include #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/player.h" +#endif constexpr int FORGOTTEN_SWAP_COOLDOWN = 15; constexpr int FORGOTTEN_SWAP_HOLD_COOLDOWN = 10; @@ -363,6 +366,10 @@ PocketItem& Entity_Player::GetPocketItem(int slot) // 007a4850 Removes the card or pill in a slot (-1 for the first), never a pocket active. void Entity_Player::RemovePocketItem(int slot) { +#ifdef ISAAC_REPENTOGON + PocketItem removed = GetPocketItem(slot); + ScopeExit removePost = {[this, removed, slot] { pocket_post_remove(*this, removed.type, removed.id, slot); }}; +#endif slot = pocket_slot_resolve(*this, slot); if (slot >= POCKET_SLOT_COUNT || pocketItems[slot].id == 0 || pocketItems[slot].type == POCKET_ACTIVE) return; pocket_slot_clear(*this, slot); @@ -375,12 +382,15 @@ void Entity_Player::DropPocketItem(int slot, Vector position) slot = pocket_slot_resolve(*this, slot); if (slot >= POCKET_SLOT_COUNT || pocketItems[slot].id == 0 || pocketItems[slot].type == POCKET_ACTIVE) return; - PocketItem& held = pocketItems[slot]; + PocketItem held = pocketItems[slot]; int variant = held.type == POCKET_CARD ? PICKUP_TAROTCARD : PICKUP_PILL; Entity* pickup = g_game->Spawn({.position = position, .spawner = this, .subType = held.id, .type = ENTITY_PICKUP, .variant = variant, .seed = Random()}); if (pickup) static_cast(pickup)->collisionCooldown = DROPPED_POCKET_COOLDOWN; pocket_slot_clear(*this, slot); +#ifdef ISAAC_REPENTOGON + pocket_post_drop(*this, held.type, held.id, slot, pickup); +#endif } // The drop button's turn of the pockets: each filled pocket moves one slot forward and the first goes last. @@ -482,7 +492,11 @@ void Entity_Player::pockets_rotate() if (forgottenSwapFormCooldown > 0) forgottenSwapFormCooldown--; if (input_is_action_triggered(ACTION_DROP, controllerIndex, this)) { - if (!SwapForgottenForm(false, false)) + bool isSwapped = !SwapForgottenForm(false, false); +#ifdef ISAAC_REPENTOGON + isSwapped = isSwapped && !pocket_swap_is_cancelled(*this); +#endif + if (isSwapped) { pocket_items_rotate(*this); if (itemState == 0) active_items_rotate(*this); diff --git a/src/entity/player/frame.cpp b/src/entity/player/frame.cpp index f4a6396..3ab90a5 100644 --- a/src/entity/player/frame.cpp +++ b/src/entity/player/frame.cpp @@ -35,6 +35,9 @@ #include #include #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/player.h" +#endif constexpr int DUCT_TAPE_MODES = 4; constexpr float BODY_TURN_RATE = 0.3f; @@ -1955,8 +1958,12 @@ static void hud_bubble_render(PlayerHUD& hud, Vector at) // in front or behind, then its overlays (the co-op indicator, charge bars, status effect and the Void's hallucination // of its past walk) in the room's pass. A player following a target shows only a marker. Netplay's shadows and colors // are offline. The dashes' after-images draw first, fading. -void Entity_Player::Render(const Vector& offset) +void Entity_Player::Render(const Vector& drawOffset) { + Vector offset = drawOffset; +#ifdef ISAAC_REPENTOGON + if (!render_pre_run({"PrePlayerRender", MC_PRE_PLAYER_RENDER, variant}, this, offset)) return; +#endif if (target) { FontSettings settings; @@ -2180,8 +2187,13 @@ void Entity_Player::render_back(const Vector& position) // 0078dde0 Draws the body layers, the costumes' where they cover them, and the blood gush of a headless player, raised // over Jupiter's and Mega Mush's bodies. Flying costumes cover the body only while flying. -void Entity_Player::RenderBody(const Vector& position) +void Entity_Player::RenderBody(const Vector& drawPosition) { + Vector position = drawPosition; +#ifdef ISAAC_REPENTOGON + if (!player_part_pre_render(*this, position, RENDER_PART_BODY)) return; + ScopeExit bodyPost = {[&] { player_part_post_render(*this, position, RENDER_PART_BODY); }}; +#endif if (!isVisible || IsFullSpriteRendering()) return; bool isBodyRendered = false; @@ -2218,8 +2230,13 @@ void Entity_Player::RenderBody(const Vector& position) // 0078dff0 Draws the head layers, the costumes' where they cover them, and the crowns of Dark Prince's Crown and Crown // of Light. -void Entity_Player::RenderHead(const Vector& position) +void Entity_Player::RenderHead(const Vector& drawPosition) { + Vector position = drawPosition; +#ifdef ISAAC_REPENTOGON + if (!player_part_pre_render(*this, position, RENDER_PART_HEAD)) return; + ScopeExit headPost = {[&] { player_part_post_render(*this, position, RENDER_PART_HEAD); }}; +#endif if (!isVisible || IsFullSpriteRendering()) return; for (int layer = PLAYER_LAYER_HEAD; layer < PLAYER_LAYER_TOP0; layer++) diff --git a/src/entity/player/health.cpp b/src/entity/player/health.cpp index bf1dcb5..b94149a 100644 --- a/src/entity/player/health.cpp +++ b/src/entity/player/health.cpp @@ -12,6 +12,9 @@ #include "game/sfx_manager.h" #include #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/player.h" +#endif constexpr int CONSUMABLE_MAX = 99; constexpr int DEEP_POCKETS_COIN_MAX = 999; @@ -62,8 +65,8 @@ Entity_Player* Entity_Player::health_owner() return player; } -// 007cafe0 How the character counts its health. -HealthType Entity_Player::GetHealthType() +// How a character counts its health. +static HealthType character_health_type(int playerType) { switch (playerType) { @@ -89,11 +92,24 @@ HealthType Entity_Player::GetHealthType() } } +// 007cafe0 How the character counts its health, which REPENTOGON's mods may change. +HealthType Entity_Player::GetHealthType() +{ +#ifdef ISAAC_REPENTOGON + return (HealthType)player_health_type_evaluate(*this, character_health_type(playerType)); +#else + return character_health_type(playerType); +#endif +} + // 007cae60 The most half hearts the player can hold: 24, 12 for The Forgotten and The Soul and co-op babies, more with // Magdalene's Birthright, Keeper's coin hearts from Greed's Gullet, less two per broken heart. With isKeeperBypass the // broken hearts and Keeper's own limits are ignored. Forgotten's and Esau's soul forms hold less. int Entity_Player::GetHeartLimit(bool isKeeperBypass) { +#ifdef ISAAC_REPENTOGON + if (std::optional limit = heart_limit_hook(*this, isKeeperBypass)) return *limit; +#endif if (g_game->deathmatchManager.is_active()) return HEART_LIMIT_DEATHMATCH; if (variant == PLAYER_VARIANT_PLAYER) { @@ -146,6 +162,10 @@ int Entity_Player::GetGreedsGulletHearts() // bone hearts. Past the limit the extra is lost, and soul and red hearts are clamped to what is left. void Entity_Player::AddMaxHearts(int amount, bool isIgnoreKeeper) { +#ifdef ISAAC_REPENTOGON + amount = hearts_pre_add(*this, {ADD_HEALTH_MAX, amount, isIgnoreKeeper}); + ScopeExit heartsPost = {[&, amount] { hearts_post_add(*this, {ADD_HEALTH_MAX, amount, isIgnoreKeeper}); }}; +#endif Entity_Player& owner = *health_owner(); HealthType health = owner.GetHealthType(); @@ -194,6 +214,10 @@ void Entity_Player::AddMaxHearts(int amount, bool isIgnoreKeeper) // nothing unless isUnknown is set. void Entity_Player::AddHearts(int hearts, bool isUnknown, bool isUnknown2) { +#ifdef ISAAC_REPENTOGON + hearts = hearts_pre_add(*this, {ADD_HEALTH_RED, hearts}); + ScopeExit heartsPost = {[&, hearts] { hearts_post_add(*this, {ADD_HEALTH_RED, hearts}); }}; +#endif Entity_Player* owner = this; while (true) { @@ -245,6 +269,10 @@ void Entity_Player::red_hearts_add(int hearts, bool isUnknown2) // charge, and characters without health a single soul heart when given any. void Entity_Player::AddSoulHearts(int amount, bool isUnknown) { +#ifdef ISAAC_REPENTOGON + amount = hearts_pre_add(*this, {ADD_HEALTH_SOUL, amount}); + ScopeExit heartsPost = {[&, amount] { hearts_post_add(*this, {ADD_HEALTH_SOUL, amount}); }}; +#endif Entity_Player* owner = this; Game& game = *g_game; @@ -377,6 +405,10 @@ void Entity_Player::SetFullHearts() // soul hearts black from the last one back instead. Golden hearts left without a heart to sit on break. void Entity_Player::AddBlackHearts(int amount) { +#ifdef ISAAC_REPENTOGON + amount = hearts_pre_add(*this, {ADD_HEALTH_BLACK, amount}); + ScopeExit heartsPost = {[&, amount] { hearts_post_add(*this, {ADD_HEALTH_BLACK, amount}); }}; +#endif Entity_Player* owner = health_owner(); while (owner->GetHealthType() != HEALTH_NO_HEALTH && owner->playerType == PLAYER_THEFORGOTTEN) { @@ -451,6 +483,10 @@ void Entity_Player::black_hearts_add(int amount) // Heartbreak's damage follows the count. void Entity_Player::AddBrokenHearts(int amount) { +#ifdef ISAAC_REPENTOGON + amount = hearts_pre_add(*this, {ADD_HEALTH_BROKEN, amount}); + ScopeExit heartsPost = {[&, amount] { hearts_post_add(*this, {ADD_HEALTH_BROKEN, amount}); }}; +#endif Entity_Player& owner = *health_owner(); owner.brokenHearts = std::min(std::max(0, owner.brokenHearts + amount), owner.GetHeartLimit(true) / 2); @@ -979,6 +1015,10 @@ void Entity_Player::eternal_heart_overlay_show() // revives instead, and characters without red health take none. The deathmatch adds a container at once. void Entity_Player::AddEternalHearts(int amount) { +#ifdef ISAAC_REPENTOGON + amount = hearts_pre_add(*this, {ADD_HEALTH_ETERNAL, amount}); + ScopeExit heartsPost = {[&, amount] { hearts_post_add(*this, {ADD_HEALTH_ETERNAL, amount}); }}; +#endif if (isCoopGhost) return RevivePlayerGhost(); HealthType health = GetHealthType(); if (health == HEALTH_COIN || health == HEALTH_NO_HEALTH) return; @@ -1025,6 +1065,9 @@ void Entity_Player::AddImmaculateConceptionCounter(int amount) uint32_t familiar = CONCEPTION_FAMILIAR_FLAGS[(roll % familiars + offset) % familiars]; if (conceptionFamiliarFlags & familiar) continue; sound_play(SOUND_IMMACULATE_CONCEPTION); +#ifdef ISAAC_REPENTOGON + if (player_birth_is_cancelled(*this, familiar, BIRTH_IMMACULATE)) break; +#endif conceptionFamiliarFlags |= familiar; cacheFlags |= CACHE_FAMILIARS; EvaluateItems(); @@ -1043,6 +1086,10 @@ void Entity_Player::AddImmaculateConceptionCounter(int amount) // break one at once. Tainted Forgotten's soul gives them to its twin. void Entity_Player::AddGoldenHearts(int amount, bool isSkipBreak) { +#ifdef ISAAC_REPENTOGON + amount = hearts_pre_add(*this, {ADD_HEALTH_GOLDEN, amount}); + ScopeExit heartsPost = {[&, amount] { hearts_post_add(*this, {ADD_HEALTH_GOLDEN, amount}); }}; +#endif Entity_Player& owner = *health_owner(); if (&owner != this) isSkipBreak = false; if (owner.playerType == PLAYER_THELOST || owner.playerType == PLAYER_THELOST_B || @@ -1080,6 +1127,10 @@ bool Entity_Player::CanPickGoldenHearts() // the soul hearts. Keeper gets flies, The Soul gives them to its body, characters without health take none. void Entity_Player::AddBoneHearts(int amount) { +#ifdef ISAAC_REPENTOGON + amount = hearts_pre_add(*this, {ADD_HEALTH_BONE, amount}); + ScopeExit heartsPost = {[&, amount] { hearts_post_add(*this, {ADD_HEALTH_BONE, amount}); }}; +#endif Entity_Player* owner = this; while (true) { @@ -1141,6 +1192,10 @@ bool Entity_Player::CanPickBoneHearts() // and Keeper gets flies. The Have a Heart challenge heals nothing unless isUnknown is set. void Entity_Player::AddRottenHearts(int amount, bool isUnknown) { +#ifdef ISAAC_REPENTOGON + amount = hearts_pre_add(*this, {ADD_HEALTH_ROTTEN, amount}); + ScopeExit heartsPost = {[&, amount] { hearts_post_add(*this, {ADD_HEALTH_ROTTEN, amount}); }}; +#endif Entity_Player* owner = this; while (true) { diff --git a/src/entity/player/hold.cpp b/src/entity/player/hold.cpp index fa244e1..41a5bf1 100644 --- a/src/entity/player/hold.cpp +++ b/src/entity/player/hold.cpp @@ -10,6 +10,9 @@ #include "entity/npc/ai.h" #include #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/entities.h" +#endif constexpr float THROW_HEIGHT = 7; constexpr float THROWN_BOMB_OFFSET_Y = -24; @@ -111,6 +114,9 @@ static Entity_Tear* lifted_grid_throw(Entity_Player& player, Entity_Effect& lift // hands, a lifted grid entity becomes a tear, a small rocket vanishes. Returns what was let go, or the grid's tear. Entity* Entity_Player::ThrowHeldEntity(Vector throwVelocity) { +#ifdef ISAAC_REPENTOGON + if (std::optional thrown = entity_throw_hook(*this, throwVelocity)) return *thrown; +#endif Entity* held = heldEntity; if (!held) return nullptr; diff --git a/src/entity/player/hud.cpp b/src/entity/player/hud.cpp index 3a6514c..1281f97 100644 --- a/src/entity/player/hud.cpp +++ b/src/entity/player/hud.cpp @@ -19,6 +19,10 @@ #include #include #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/player.h" +#include +#endif constexpr const char* HEARTS_PNG = "gfx/ui/ui_hearts.png"; constexpr const char* HEARTS_SMALL_PNG = "gfx/ui/ui_hearts_small.png"; @@ -733,6 +737,12 @@ void PlayerHUD::UpdateHearts(std::span slots, Entity_Player& sho // versus match a health bar. outExtent is how far the hearts reach. void PlayerHUD::RenderHearts(Vector& outExtent, ANM2& sprite, PlayerHudLayout layout, float heartScale, Vector at) { +#ifdef ISAAC_REPENTOGON + HudHeartsDraw heartsDraw = {outExtent, sprite, at, layout, heartScale}; + bool isFollowed = player && !player->isCoopGhost; + if (isFollowed && hud_hearts_pre_render(*this, heartsDraw)) return; + ScopeExit heartsPost = {[&] { if (isFollowed) hud_hearts_post_render(*this, heartsDraw); }}; +#endif Game& game = *g_game; if (game.currentRoomIdx == ROOM_DEATHMATCH_IDX) { @@ -1055,6 +1065,10 @@ static void glitched_icon_draw(int id, const SourceQuad& source, const KAGE::Gra static void active_item_draw(const PlayerHUDActiveItem& active, const SourceQuad& source, const KAGE::Graphics::ColorQuad& quad, const ColorMod& color) { +#ifdef ISAAC_REPENTOGON + bool isOutline = std::memcmp(&color, &ICON_OUTLINE, sizeof(ColorMod)) == 0; + if (activeItemRender.isItemHidden || (activeItemRender.isOutlineHidden && isOutline)) return; +#endif KAGE::Graphics::manager.shader_default_set(); if (active.id < 0) return glitched_icon_draw(active.id, source, quad, color); if (!active.itemImage) return; @@ -1161,8 +1175,17 @@ static void bar_fill_draw(const ChargeBar& bar, float fill, ColorMod color) // overlay on even frames. Hold shows the poop it holds. void PlayerHUD::RenderActiveItem(int activeSlot, Vector at, PlayerHudLayout layout, float itemScale, float alpha) { +#ifdef ISAAC_REPENTOGON + max_charge_cache_begin(); + ScopeExit cacheEnd = {max_charge_cache_end}; +#endif if (!player || player->isCoopGhost) return; +#ifdef ISAAC_REPENTOGON + HudActiveDraw activeDraw = {at, activeSlot, layout, alpha, itemScale}; + if (hud_active_item_pre_render(*this, activeDraw)) return; + ScopeExit activePost = {[&] { hud_active_item_post_render(*this, activeDraw); }}; +#endif KAGE::Graphics::Manager& graphics = KAGE::Graphics::manager; Entity_Player& shown = *player; @@ -1191,6 +1214,9 @@ void PlayerHUD::RenderActiveItem(int activeSlot, Vector at, PlayerHudLayout layo shown.GetTotalActiveCharge(activeSlot) >= shown.GetActiveMinUsableCharge(activeSlot) && alpha >= 1; active_icon_frame_set(icon, shown, activeSlot, charge); +#ifdef ISAAC_REPENTOGON + if (activeItemRender.isCropped) icon.frame = vector_make(activeItemRender.cropX, activeItemRender.cropY); +#endif if (item == COLLECTIBLE_HOLD && shown.activeItems[activeSlot].varData != 0) { ANM2& poops = hud->poopSpellsSprite; @@ -1232,7 +1258,11 @@ void PlayerHUD::RenderActiveItem(int activeSlot, Vector at, PlayerHudLayout layo icon_pass_draw(active, icon, iconSize, main); } - if (charge.max < 1) + bool isBarHidden = charge.max < 1; +#ifdef ISAAC_REPENTOGON + isBarHidden = isBarHidden || activeItemRender.isChargeBarHidden; +#endif + if (isBarHidden) { graphics.shader_default_set(); return; @@ -1294,13 +1324,11 @@ void PlayerHUD::RenderActiveItem(int activeSlot, Vector at, PlayerHudLayout layo graphics.shader_default_set(); } -// (0084bab0) Draws a trinket's icon at a position and size in a color: its 32 pixel frame, which for Monkey Paw is the -// one of the paw's fingers left. -void PlayerHUD::trinket_draw(const PlayerHUDTrinket& trinket, Vector at, const ColorMod& color, float trinketScale) +// (0084bab0) Draws a trinket's icon at a position and size in a color, from its 32 pixel frame at crop. +void PlayerHUD::trinket_draw(const PlayerHUDTrinket& trinket, Vector at, const ColorMod& color, float trinketScale, + Vector crop) { - float frameX = trinket.id == TRINKET_MONKEY_PAW ? (float)(MONKEY_PAW_FRAMES - player->monkeyPawCounter) * TRINKET_SIZE - : 0; - SourceQuad source = KAGE::Graphics::source_quad_rect(vector_make(frameX, 0), vector_make(TRINKET_SIZE, TRINKET_SIZE)); + SourceQuad source = KAGE::Graphics::source_quad_rect(crop, vector_make(TRINKET_SIZE, TRINKET_SIZE)); Vector size = vector_make(trinketScale * TRINKET_SIZE, trinketScale * TRINKET_SIZE); KAGE::Graphics::ColorQuad quad = KAGE::Graphics::color_quad_rect(at, size, kcolor_rgba(1, 1, 1, 1)); @@ -1310,11 +1338,18 @@ void PlayerHUD::trinket_draw(const PlayerHUDTrinket& trinket, Vector at, const C // 00846ff0 Draws a trinket slot's icon over its shadow, shaken with the screen and, when small, centered on its drawn // pixels: the error trinket reddened, a golden trinket shimmering in the gold shader, a Modeling Clay copy in clay. -// The original leaves the shaders it picks current. Here they are popped after. +// Monkey Paw shows the frame of the fingers it has left. The original leaves the shaders it picks current. Here they +// are popped after. void PlayerHUD::RenderTrinket(int trinketSlot, Vector at, float trinketScale, bool isSmall) { const PlayerHUDTrinket& trinket = trinkets[trinketSlot]; if (trinket.id == 0 || !trinket.image) return; + float frameX = trinket.id == TRINKET_MONKEY_PAW ? (float)(MONKEY_PAW_FRAMES - player->monkeyPawCounter) * TRINKET_SIZE + : 0; + Vector crop = vector_make(frameX, 0); +#ifdef ISAAC_REPENTOGON + if (!hud_trinket_pre_render(*this, trinketSlot, at, trinketScale, crop)) return; +#endif KAGE::Graphics::Manager& graphics = KAGE::Graphics::manager; Vector shake = g_game->screenShakeOffset; @@ -1324,7 +1359,7 @@ void PlayerHUD::RenderTrinket(int trinketSlot, Vector at, float trinketScale, bo int pushed = graphics.shader_push(COLOR_OFFSET_SHADER) ? 1 : 0; trinket_draw(trinket, vector_make(trinketScale + trinketScale + position.x, trinketScale + trinketScale + position.y), - TRINKET_SHADOW, trinketScale); + TRINKET_SHADOW, trinketScale, crop); ColorMod color = COLOR_DEFAULT; uint32_t held = player->trinkets[trinketSlot]; @@ -1337,7 +1372,7 @@ void PlayerHUD::RenderTrinket(int trinketSlot, Vector at, float trinketScale, bo } else if (trinket.clayItem != 0) for (int i = 0; i < 4; i++) color._colorize[i] = CLAY_COLORIZE[i]; - trinket_draw(trinket, position, color, trinketScale); + trinket_draw(trinket, position, color, trinketScale, crop); for (; pushed > 0; pushed--) graphics.shader_pop(); } @@ -1544,6 +1579,10 @@ static void inventory_icon_draw(const PlayerHUDIcon& icon, const KAGE::Graphics: // one the next item replaces. void PlayerHUD::render_inventory(Vector at, float inventoryScale) { +#ifdef ISAAC_REPENTOGON + HudElementScope elementScope(*this, HUD_ELEMENT_INVENTORY, at, inventoryScale); + if (!elementScope.isDrawn) return; +#endif ANM2& sprite = hud->inventorySprite; int slots = player->GetMaxInventorySize(); int columns = slots / 2; @@ -1654,6 +1693,10 @@ void PlayerHUD::render_card_table(Vector at, float tableScale) // challenge it draws the card table instead. void PlayerHUD::RenderCraftingTable(Vector at, float tableScale) { +#ifdef ISAAC_REPENTOGON + HudElementScope elementScope(*this, HUD_ELEMENT_CRAFTING_TABLE, at, tableScale); + if (!elementScope.isDrawn) return; +#endif ANM2& sprite = hud->craftingTableSprite; sprite.scale = vector_make(tableScale, tableScale); if (g_game->challenge == CHALLENGE_CANTRIPPED) diff --git a/src/entity/player/hud.h b/src/entity/player/hud.h index 532dc49..eae3a4e 100644 --- a/src/entity/player/hud.h +++ b/src/entity/player/hud.h @@ -138,7 +138,8 @@ private: void trinkets_update(bool& isChanged); void pockets_update(); void inventory_update(); - void trinket_draw(const PlayerHUDTrinket& trinket, Vector at, const ColorMod& color, float trinketScale); + void trinket_draw(const PlayerHUDTrinket& trinket, Vector at, const ColorMod& color, float trinketScale, + Vector crop); void card_icon_render(const PlayerHUDIcon& icon, Vector at, float size, float shadowShift); void render_card_table(Vector at, float tableScale); }; diff --git a/src/entity/player/items.cpp b/src/entity/player/items.cpp index 4574aec..8d26fd3 100644 --- a/src/entity/player/items.cpp +++ b/src/entity/player/items.cpp @@ -18,6 +18,11 @@ #include #include #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/callbacks.h" +#include "repentogon/items.h" +#include "repentogon/player.h" +#endif constexpr int ROOM_TRINKET_ROLL_SHIFT = 13; constexpr float PICKUP_SPAWN_STEP = 40; @@ -212,6 +217,9 @@ int Entity_Player::extra_collectible_count(int collectibleId) // The original reads a missing collectible's tags for co-op ghosts. Here a missing one counts as no quest item. int Entity_Player::GetCollectibleNum(int collectibleId, ItemCheck check) { +#ifdef ISAAC_REPENTOGON + if (std::optional count = collectible_num_hook(*this, collectibleId, check == ITEM_CHECK_OWNED)) return *count; +#endif if (collectibleId < 0 || collectibleId >= (int)collectibleCounts.size()) return 0; if (variant == PLAYER_VARIANT_COOP_BABY) if (Entity_Player* owner = GetMainPlayer()) return owner->GetCollectibleNum(collectibleId, check); @@ -528,6 +536,9 @@ int Entity_Player::GetZodiacEffect() // effects (entity_player_trinkets.cpp) in their places. A shield broken in the last room is taken away first. void Entity_Player::TriggerNewRoom_TemporaryEffects() { +#ifdef ISAAC_REPENTOGON + ScopeExit effectsPost = {[this] { player_room_effects_post_trigger(*this); }}; +#endif constexpr int CAMO_UNDIES = 497; ItemConfig& items = g_manager->itemConfig; ItemConfig_Item* mantle = items.GetCollectible(COLLECTIBLE_HOLY_MANTLE); @@ -1584,9 +1595,16 @@ static void collectible_late_effect_apply(Entity_Player& p, const CollectibleGai // own pickup effect runs, its cache flags are evaluated, transformations count it, and its costume goes on. An active // takes its slot, and Book of Virtues an empty first one. The history keeps the pool the item came from. Nothing is // given while Forget Me Now takes the floor away. Online, an item the versus rules allow joins the next match's pool. -// Procedural items stop the game. +// Procedural items stop the game. Mods' MC_PRE_ADD_COLLECTIBLE may cancel or change it, and +// MC_POST_TRIGGER_COLLECTIBLE_ADDED and MC_POST_ADD_COLLECTIBLE follow. void Entity_Player::AddCollectible(int type, int charge, bool isFirstTime, int activeSlot, int varData, int poolType) { +#ifdef ISAAC_REPENTOGON + if (!collectible_add_pre(*this, {type, charge, isFirstTime, activeSlot, varData})) return; + ScopeExit addPost = {[=, this]() mutable { + collectible_add_post(*this, {type, charge, isFirstTime, activeSlot, varData}); + }}; +#endif Game& game = *g_game; ItemConfig_Item* item = g_manager->itemConfig.GetCollectible(type); if (!item) return log_printf(LOG_INFO, "[warn] no config for collectible %d.\n", type); @@ -1722,6 +1740,10 @@ static ItemConfig_Item* costume_item_get(Entity_Player& player, ItemConfig_Item* void Entity_Player::AddCostume(ItemConfig_Item* item, bool isItemStateOnly) { if (variant == PLAYER_VARIANT_COOP_BABY || !item || isCoopGhost) return; +#ifdef ISAAC_REPENTOGON + if (costume_pre_add(*this, item, isItemStateOnly)) return; + ScopeExit costumePost = {[&, item] { costume_post_add(*this, item, isItemStateOnly); }}; +#endif item = costume_item_get(*this, item); if (!item) return; diff --git a/src/entity/player/player.cpp b/src/entity/player/player.cpp index ab9a47a..6192cb2 100644 --- a/src/entity/player/player.cpp +++ b/src/entity/player/player.cpp @@ -23,6 +23,9 @@ #include #include #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/player.h" +#endif constexpr float PLAYER_START_TEAR_HEIGHT = -23.75f; constexpr float PLAYER_START_TEAR_FALLING_SPEED = 0.2f; @@ -567,6 +570,9 @@ void Entity_Player::links_reset() // rolls, the challenge and the seeds add. Eden rolls its health, a pickup and its stat offsets from the init seed. void Entity_Player::InitPreLevelInitStats() { +#ifdef ISAAC_REPENTOGON + player_level_stats_pre_init(*this); +#endif Game& game = *g_game; EntityConfig_Player* playerConfig = g_manager->entityConfig.GetPlayer(playerType); RNG rng = rng_make(initSeed, PRE_LEVEL_RNG_SHIFT); @@ -806,6 +812,9 @@ void Entity_Player::starting_trinket_add(int id) // and starts the twins and companions. Straw Man's player only evaluates. Netplay's per-player save data is offline. void Entity_Player::InitPostLevelInitStats() { +#ifdef ISAAC_REPENTOGON + ScopeExit statsPost = {[this] { player_level_stats_post_init(*this); }}; +#endif Game& game = *g_game; EntityConfig_Player* playerConfig = g_manager->entityConfig.GetPlayer(playerType); RNG rng = rng_make(initSeed, PRE_LEVEL_RNG_SHIFT); @@ -960,6 +969,9 @@ void Entity_Player::jacobs_curse_add(const JacobsCurseDelay& delay) // spills blood at low health, ends the floor's effects, restores what the floor gives back and evaluates its stats. void Entity_Player::level_start(bool isForced) { +#ifdef ISAAC_REPENTOGON + ScopeExit levelPost = {[this, isForced] { player_level_post_start(*this, isForced); }}; +#endif delayedSfxId = 0; delayedSfxDelay = 0; moveToTarget = {}; @@ -1460,9 +1472,15 @@ bool Entity_Player::is_body_layer(int layer) } // 0075d850 Takes off an item's costume, from its Lazarus twin too when the item is shared, and redoes the costumes. -// Co-op babies wear none. +// Co-op babies wear none. Without vanilla parity a co-op ghost keeps its costumes, as REPENTOGON has it. void Entity_Player::RemoveCostume(ItemConfig_Item* item) { +#ifdef ISAAC_REPENTOGON + bool isFollowed = item && variant != PLAYER_VARIANT_COOP_BABY && !isCoopGhost; + if (isFollowed && costume_pre_remove(*this, item)) return; + if (isCoopGhost && !repentogonOptions.isVanillaParity) return; + ScopeExit costumePost = {[&] { if (isFollowed) costume_post_remove(*this, item); }}; +#endif if (!item || variant == PLAYER_VARIANT_COOP_BABY || item->costume.anm2Path.empty()) return; if (isValid && item->HasTags(TAG_LAZ_SHARED) && backupPlayer) backupPlayer->RemoveCostume(item); diff --git a/src/entity/player/player.h b/src/entity/player/player.h index 5c2f015..e249bae 100644 --- a/src/entity/player/player.h +++ b/src/entity/player/player.h @@ -1832,6 +1832,11 @@ public: bool isMarsDashReady = true; bool isPostLevelInitFinished = false; bool isUrethraBlocked = false; +#ifdef ISAAC_REPENTOGON + // REPENTOGON's health type tracking (EntityPlayerPlus): the last evaluated one, -1 before any change. + int previousHealthType = -1; + bool isEvaluatingHealthType = false; +#endif // Set while EvaluateItems spawns the players Found Soul and Strawman give, who start without pickups. static inline bool isSpawningHelperPlayers = false; @@ -1966,9 +1971,11 @@ public: void PlayCollectibleAnim(int collectible, bool isCheckBodyLayers, std::string_view animation, int frame); void PlayExtraAnimation(std::string_view animation, bool isUnknown); UseResult UseActiveItem(const ActiveUse& use); + UseResult active_item_use(const ActiveUse& request); void trigger_collectible_effect_removed(ItemConfig_Item* item, int count); private: + bool collision_react(Entity* collider, bool isLow); void stats_reset(); void tear_stats_reset(); void sprites_load(); diff --git a/src/entity/player/pockets.cpp b/src/entity/player/pockets.cpp index 0bd8753..5f8cecc 100644 --- a/src/entity/player/pockets.cpp +++ b/src/entity/player/pockets.cpp @@ -20,6 +20,11 @@ #include #include #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/callbacks.h" +#include "repentogon/items.h" +#include "repentogon/player.h" +#endif constexpr int CARD_ID_VANILLA_LAST = 97; // Endless Nameless' odds to copy a used card or pill, by its copies. @@ -111,6 +116,13 @@ RNG& Entity_Player::GetPillRNG(int pillEffect) // moving down. Full pockets drop their cards and pills first, and a helper player drops what it gets. void Entity_Player::AddPocketItem(int id, uint32_t pocketItemType) { +#ifdef ISAAC_REPENTOGON + int callbackSlot = pocketItems[0].type == POCKET_ACTIVE && pocketItems[0].id > 0 ? 1 : 0; + std::optional added = pocket_pre_add(*this, (int)pocketItemType, id, callbackSlot); + if (!added) return; + id = *added; + ScopeExit addPost = {[=, this] { pocket_post_add(*this, (int)pocketItemType, id, callbackSlot); }}; +#endif int maxPockets = (int)GetMaxPocketItems() + (pocketItemType == POCKET_ACTIVE ? 1 : 0); if (pocketItems[0].id != 0 && pocketItems[maxPockets - 1].id != 0) for (int slot = 0; slot < maxPockets; slot++) @@ -155,20 +167,34 @@ int Entity_Player::GetPill(int slot) return is_pocket_slot(slot) && pocketItems[slot].type == POCKET_PILL ? pocketItems[slot].id : 0; } -// 007a3cb0 Puts a card in a pocket slot, then updates the Red Key's door outlines. -void Entity_Player::SetCard(int slot, int card) +// Puts a card or pill in a pocket slot, then updates the Red Key's door outlines. +static void pocket_slot_set(Entity_Player& player, int slot, PocketItem pocket) { if (!is_pocket_slot(slot)) return; - pocketItems[slot] = {card, POCKET_CARD}; +#ifdef ISAAC_REPENTOGON + std::optional id = pocket_pre_add(player, pocket.type, pocket.id, slot); + if (!id) return; + pocket.id = *id; + PocketItem replaced = player.pocketItems[slot]; + ScopeExit setPost = {[&] { + pocket_post_remove(player, replaced.type, replaced.id, slot); + pocket_post_add(player, pocket.type, pocket.id, slot); + }}; +#endif + player.pocketItems[slot] = pocket; g_game->room->UpdateRedKey(); } -// 007a3cf0 Puts a pill in a pocket slot, then updates the Red Key's door outlines. +// 007a3cb0 Puts a card in a pocket slot. +void Entity_Player::SetCard(int slot, int card) +{ + pocket_slot_set(*this, slot, {card, POCKET_CARD}); +} + +// 007a3cf0 Puts a pill in a pocket slot. void Entity_Player::SetPill(int slot, int pillColor) { - if (!is_pocket_slot(slot)) return; - pocketItems[slot] = {pillColor, POCKET_PILL}; - g_game->room->UpdateRedKey(); + pocket_slot_set(*this, slot, {pillColor, POCKET_PILL}); } // 007717c0 How many trinkets the player holds: two with Mom's Purse or Belly Button. @@ -294,6 +320,11 @@ static std::string pocket_text(std::string_view text) bool pocket_item_collect(Entity_Pickup& pocket, Entity_Player& player) { if (player.IsHoldingItem()) return false; +#ifdef ISAAC_REPENTOGON + bool isPocketed = g_game->challenge != CHALLENGE_CANTRIPPED; + if (isPocketed && pocket_collect_is_cancelled(pocket, player)) return false; + ScopeExit collectPost = {[&] { if (isPocketed) pocket_collect_post(pocket, player); }}; +#endif if (g_game->challenge == CHALLENGE_CANTRIPPED) { uint32_t item = player.AddItemCard((uint32_t)pocket.subtype & ~CARD_ITEM_FLAG); @@ -331,9 +362,12 @@ bool pocket_item_collect(Entity_Pickup& pocket, Entity_Player& player) // 007b2230 Uses a card: its effect, the card held up unless hidden, the announcer naming it now and then, and the mods' // MC_USE_CARD. The random cards challenge swaps it for a random card. Tarot Cloth doubles a tarot card: the ones with -// a doubled effect run it, the others run once more as a car battery's second use. +// a doubled effect run it, the others run once more as a car battery's second use. A mod's MC_PRE_USE_CARD may cancel it. void Entity_Player::UseCard(int cardType, uint32_t useFlag) { +#ifdef ISAAC_REPENTOGON + if (card_use_is_cancelled(*this, cardType, useFlag)) return; +#endif ItemConfig_Card* card = cardType >= 0 ? g_manager->itemConfig.GetCard(cardType) : nullptr; if (!card) return; @@ -370,9 +404,14 @@ void tears_up_unlock_check(Entity_Player& player) // instead), its name shows and its use counts, its effect runs, the announcer names it now and then and the mods see // it. A horse pill doubles the count and swaps the thumbs' sounds for louder ones. False PHD turns a bad pill into a // black heart and some damage. The random pills challenge shows a random pill's name, and the seeds hide or scramble -// it. Netplay's remote players, whose pills the original keeps off the HUD, are offline. +// it. Netplay's remote players, whose pills the original keeps off the HUD, are offline. A mod's MC_PRE_USE_PILL may +// cancel it, and without vanilla parity MC_USE_PILL runs after it all, with the pill color too. void Entity_Player::UsePill(int pillEffect, int pillColor, uint32_t useFlags) { +#ifdef ISAAC_REPENTOGON + if (pill_use_is_cancelled(*this, pillEffect, pillColor, useFlags)) return; + ScopeExit usedPost = {[=, this] { pill_use_post(*this, pillEffect, pillColor, useFlags); }}; +#endif constexpr int FALSE_PHD_SHIFT = 72; constexpr int FALSE_PHD_PILLS[] = {PILLEFFECT_AMNESIA, PILLEFFECT_BAD_TRIP, PILLEFFECT_WIZARD, PILLEFFECT_PARALYSIS, PILLEFFECT_ADDICTED, PILLEFFECT_QUESTIONMARK, @@ -427,7 +466,10 @@ void Entity_Player::UsePill(int pillEffect, int pillColor, uint32_t useFlags) if (isAnnounced && pill && pill->announcerVoice != 0) announcer_queue(*this, isHorse ? pill->announcerVoiceSuper : pill->announcerVoice, pill->announcerDelay, frames); - lua_engine_get().UsePill(pillEffect, this, useFlags); +#ifdef ISAAC_REPENTOGON + if (repentogonOptions.isVanillaParity) +#endif + lua_engine_get().UsePill(pillEffect, this, useFlags); if (isHorse && sprite.IsPlaying("Happy")) { g_manager->sfxManager.Stop(SOUND_THUMBSUP); @@ -492,6 +534,9 @@ void Entity_Player::pocket_use_input() save.AddToCollection(COLLECTION_CARD); save.IncreaseEventCounter(EVENT_COUNTER_CARDS_USED, 1); pockets_shift(*this); +#ifdef ISAAC_REPENTOGON + pocket_post_remove(*this, POCKET_CARD, used.id, 0); +#endif TriggerEchoChamber(POCKET_CARD, used.id); UseCard(used.id, USE_OWNED); if (used.id != CARD_WILD && used.id != CARD_QUESTIONMARK) @@ -512,6 +557,9 @@ void Entity_Player::pocket_use_input() bool isGoldenKept = (used.id & PILL_COLOR_MASK) == PILL_COLOR_GOLD && GetCollectibleRNG(COLLECTIBLE_PHD).RandomInt(PERCENT) >= GOLDEN_PILL_KEEP_CHANCE; if (!isGoldenKept) pockets_shift(*this); +#ifdef ISAAC_REPENTOGON + pocket_post_remove(*this, POCKET_PILL, used.id, 0); +#endif TriggerEchoChamber(POCKET_PILL, used.id); UsePill(effect, used.id, 0); wildCardItemType = WILD_CARD_PILL; diff --git a/src/entity/player/poop_spells.cpp b/src/entity/player/poop_spells.cpp index 4918e68..c1a11a4 100644 --- a/src/entity/player/poop_spells.cpp +++ b/src/entity/player/poop_spells.cpp @@ -13,6 +13,9 @@ #include "entity/player/hud.h" #include #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/player.h" +#endif constexpr int POOP_SPELL_PICK_SHIFT = 35; constexpr int POOP_SPELL_RARE_END = 4; @@ -247,6 +250,10 @@ void blue_baby_poop_update(Entity_Player& player) // small, each lit while the poop covers it and faint otherwise. void PlayerHUD::RenderSpellQueue(Vector at, float queueScale) { +#ifdef ISAAC_REPENTOGON + HudElementScope elementScope(*this, HUD_ELEMENT_POOP_SPELL_QUEUE, at, queueScale); + if (!elementScope.isDrawn) return; +#endif ANM2& spells = hud->poopSpellsSprite; float inset = queueScale * SPELL_SLOT_INSET; spells.scale = vector_make(queueScale, queueScale); diff --git a/src/entity/player/tainted_characters.cpp b/src/entity/player/tainted_characters.cpp index f80fb3b..db45f0e 100644 --- a/src/entity/player/tainted_characters.cpp +++ b/src/entity/player/tainted_characters.cpp @@ -22,6 +22,9 @@ #include #include #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/callbacks.h" +#endif // Dark Esau is called when Jacob's curse has this many frames left (Anima Sola with nothing to chain sets it there). constexpr int DARK_ESAU_CALL_FRAMES = 10; @@ -171,6 +174,10 @@ void abyss_use(ItemUse& use) if (!pickup.CanReroll() || pickup.IsShopItem() || pickup.variant != PICKUP_COLLECTIBLE || pickup.subtype == 0 || pickup.timeout >= 1) continue; +#ifdef ISAAC_REPENTOGON + CallbackRun run = {"PrePickupVoidedAbyss", MC_PRE_PICKUP_VOIDED_ABYSS, pickup.variant}; + if (!boolean_run(run, true, &pickup)) continue; +#endif locust_spawn(player, pickup.subtype, pickup.pos); pickup.Remove(); diff --git a/src/entity/player/tears.cpp b/src/entity/player/tears.cpp index e7425ba..1b136fe 100644 --- a/src/entity/player/tears.cpp +++ b/src/entity/player/tears.cpp @@ -9,6 +9,9 @@ #include #include #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/weapons.h" +#endif // The tear's size from its damage: a root, the item scale (above one it grows by its log) and a little of the damage. constexpr float TEAR_SCALE_ROOT = 0.23f; @@ -915,6 +918,9 @@ TearParams Entity_Player::GetTearHitParams(WeaponType weaponType, float damageSc NetplayManager& netplay = g_manager->netplayManager; if (netplay.is_online() && !netplay.IsIdxLocalPlayer(controllerIndex) && !g_game->deathmatchManager.is_active()) params.tearColor._tint[TINT_ALPHA] *= (float)g_manager->optionsConfig.onlinePlayerOpacity * 0.09f + 0.1f; +#ifdef ISAAC_REPENTOGON + tear_hit_params_evaluate(*this, params, {weaponType, damageScale, displacement, source}); +#endif return params; } diff --git a/src/entity/player/temporary_effects.cpp b/src/entity/player/temporary_effects.cpp index 4149324..a3cd978 100644 --- a/src/entity/player/temporary_effects.cpp +++ b/src/entity/player/temporary_effects.cpp @@ -5,6 +5,10 @@ #include "level/room.h" #include "game/manager.h" #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/callbacks.h" +#include "repentogon/player.h" +#endif constexpr int BOOK_OF_SHADOWS_SOUND_END = 1027; @@ -54,6 +58,11 @@ void TemporaryEffects::AddEffect(const TemporaryEffect& effect, bool isAddCostum } cacheFlags |= effect.item->cacheFlags; isEvaluateCachePending = true; +#ifdef ISAAC_REPENTOGON + if (effect.item && g_game->room && this == &g_game->room->temporaryEffects) + item_callback_notify("PostRoomAddEffect", MC_POST_ROOM_ADD_EFFECT, effect.item, effect.item); + else if (player) player_effect_post_add(*player, effect, isAddCostume, count); +#endif } // 009302e0 Adds copies of a collectible's effect. diff --git a/src/entity/player/trinkets.cpp b/src/entity/player/trinkets.cpp index 6368717..7d725f1 100644 --- a/src/entity/player/trinkets.cpp +++ b/src/entity/player/trinkets.cpp @@ -25,6 +25,11 @@ #include #include #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/callbacks.h" +#include "repentogon/items.h" +#include "repentogon/player.h" +#endif // The trinkets' constants: Rosary Bead's Bible chance, the battery trinkets' achievement, Wooden Cross's mantles // counted in the high half of the mantle stacks, Mother's Kiss's hearts and Lil Clot's clots. @@ -203,13 +208,20 @@ Entity_Pickup* Entity_Player::DropTrinket(Vector position, bool isReplaceTick) else if (id == TRINKET_MOMS_TOENAIL && !(g_game->room->descriptor->flags & ROOM_DESCRIPTOR_FLAG_CLEAR) && pickup) moms_toenail_stomp(pickup->pos, stomps); if (cacheFlags) EvaluateItems(); +#ifdef ISAAC_REPENTOGON + player_trinket_post_drop(*this, position, isReplaceTick, pickup); +#endif return pickup; } // 00771d30 Puts a trinket in the first free slot (two with Mom's Purse or Belly Button), wearing its costume, then // sets off its pickup effect. Three battery items held unlock an achievement. A helper player drops it at once. +// Mods' MC_PRE_ADD_TRINKET may cancel or change it. void Entity_Player::AddTrinket(int type, bool isFirstTime) { +#ifdef ISAAC_REPENTOGON + if (!trinket_add_pre(*this, {type, isFirstTime})) return; +#endif ItemConfig_Item* trinket = g_manager->itemConfig.GetTrinket(type & TRINKET_ID_MASK); if (!trinket) return; @@ -251,9 +263,12 @@ static void trinket_cache_add(Entity_Player& player, uint32_t id) // 007ad860 What picking a trinket up changes at once: the Bible's chance, the transformations it counts for, Duct // Tape's mode, Wooden Cross's mantles, Mother's Kiss's hearts, Gilded Key's key, Lil Clot's clots and the versus -// trinkets. The trinket's stats are evaluated with the next frame. +// trinkets. The trinket's stats are evaluated with the next frame. MC_POST_TRIGGER_TRINKET_ADDED follows. void Entity_Player::TriggerTrinketAdded(uint32_t trinketId, bool isFirstTime) { +#ifdef ISAAC_REPENTOGON + ScopeExit addedPost = {[=, this] { trinket_added_post(*this, trinketId, isFirstTime); }}; +#endif Game& game = *g_game; if (variant != PLAYER_VARIANT_PLAYER) return; bool isGolden = trinketId & TRINKET_GOLDEN_FLAG; @@ -301,9 +316,12 @@ void Entity_Player::TriggerTrinketAdded(uint32_t trinketId, bool isFirstTime) // 007adb30 What losing a trinket changes at once, undoing its pickup: the Bible's chance, the transformations, Wooden // Cross's mantles, Modeling Clay's copied item and the versus trinkets' effects. The stats are evaluated with the next -// frame. +// frame. MC_POST_TRIGGER_TRINKET_REMOVED follows. void Entity_Player::TriggerTrinketRemoved(uint32_t trinketId) { +#ifdef ISAAC_REPENTOGON + ScopeExit removedPost = {[=, this] { trinket_removed_post(*this, trinketId); }}; +#endif Game& game = *g_game; if (variant != PLAYER_VARIANT_PLAYER) return; uint32_t id = trinketId & TRINKET_ID_MASK; diff --git a/src/entity/player/update.cpp b/src/entity/player/update.cpp index a9b7c34..7742aab 100644 --- a/src/entity/player/update.cpp +++ b/src/entity/player/update.cpp @@ -37,6 +37,9 @@ #include "entity/weapon/lasers.h" #include #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/callbacks.h" +#endif constexpr int SIREN_COPY_SPAWNER = 904; constexpr float LEADER_PUSH_REACH = 12; @@ -1233,6 +1236,9 @@ static void extra_player_update(Entity_Player& player) // The parts the plain path does not run yet stop the game until reached. void Entity_Player::Update() { +#ifdef ISAAC_REPENTOGON + if (update_pre_is_skipped({"PrePlayerUpdate", MC_PRE_PLAYER_UPDATE, variant}, this)) return Entity::Update(); +#endif Game& game = *g_game; DeathmatchManager& deathmatch = game.deathmatchManager; hud_update(*this); diff --git a/src/entity/player/weapons.cpp b/src/entity/player/weapons.cpp index 8bda152..231a76f 100644 --- a/src/entity/player/weapons.cpp +++ b/src/entity/player/weapons.cpp @@ -15,6 +15,9 @@ #include "level/room.h" #include #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/callbacks.h" +#endif // Stye's right eye tears float longer. constexpr float STYE_FALLING_ACCEL_SCALE = 0.5f; @@ -585,6 +588,9 @@ Entity_Laser* Entity_Player::FireTechLaser(const TechLaserShot& shot) : (aim.y <= -TECH_LASER_FACING || aim.x <= -TECH_LASER_FACING); laser->renderDepthOffset = isBehind ? TECH_LASER_BACK_DEPTH : TECH_LASER_FRONT_DEPTH; laser->isPlayerParams = true; +#ifdef ISAAC_REPENTOGON + unfiltered_notify("PostFireTechLaser", MC_POST_FIRE_TECH_LASER, laser); +#endif return laser; } @@ -636,6 +642,9 @@ Entity_Laser* Entity_Player::FireTechXLaser(const TechXShot& shot) laser->isPlayerParams = true; laser->mass *= params.massMultiplier; laser->damageMultiplier = shot.damageMultiplier; +#ifdef ISAAC_REPENTOGON + unfiltered_notify("PostFireTechXLaser", MC_POST_FIRE_TECH_X_LASER, laser); +#endif return laser; } @@ -656,6 +665,9 @@ Entity_Knife* Entity_Player::FireKnife(const KnifeShot& shot) knife->SetCollisionDamage(damage); static_cast(knife)->rotationOffset = normalize_angle_degrees(shot.rotationOffset); if (shot.isCantOverwrite) knife->AddEntityFlags(FLAG_DONT_OVERWRITE); +#ifdef ISAAC_REPENTOGON + unfiltered_notify("PostFireKnife", MC_POST_FIRE_KNIFE, static_cast(knife)); +#endif return static_cast(knife); } diff --git a/src/entity/status.cpp b/src/entity/status.cpp index ba1168b..4119dfc 100644 --- a/src/entity/status.cpp +++ b/src/entity/status.cpp @@ -12,6 +12,9 @@ #include "level/room.h" #include #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/status.h" +#endif // How long each status effect can add up to. constexpr int STATUS_MAX_FRAMES = 120; @@ -149,6 +152,10 @@ int Entity::apply_second_hand_duration(int duration, const EntityRef& source) // 006ad3c0 Freezes the entity (the head of a body sharing its status) unless a friend did it, tinted grey. void Entity::AddFreeze(const EntityRef& source, int duration, bool isIgnoreBossCooldown) { +#ifdef ISAAC_REPENTOGON + StatusApplyScope statusScope(STATUS_FREEZE, *this, source, duration, isIgnoreBossCooldown); + if (statusScope.isCancelled) return; +#endif if (IsDamageSourceFriendly(source)) return; duration = apply_second_hand_duration(duration, source); Entity& head = *GetStatusEffectTarget(); @@ -165,6 +172,10 @@ void Entity::AddFreeze(const EntityRef& source, int duration, bool isIgnoreBossC // (the source's player's melee damage without one). It turns greener the longer it lasts. void Entity::AddPoison(const EntityRef& source, int duration, float damage, bool isIgnoreBossCooldown) { +#ifdef ISAAC_REPENTOGON + StatusApplyScope statusScope(STATUS_POISON, *this, source, duration, damage, isIgnoreBossCooldown); + if (statusScope.isCancelled) return; +#endif if (IsDamageSourceFriendly(source) || is_evil_charmed(*this)) return; duration = apply_second_hand_duration(duration, source); damage = tick_damage_get(*this, source, damage); @@ -248,6 +259,10 @@ static void charm_permanent(Entity& entity, Entity& head, bool isCharmed, bool i // source, and an enemy just charmed finds a new path. void Entity::AddCharmed(const EntityRef& source, int duration, bool isIgnoreBossCooldown, bool isAddEnemyKillScore) { +#ifdef ISAAC_REPENTOGON + StatusApplyScope statusScope(STATUS_CHARMED, *this, source, duration, isIgnoreBossCooldown); + if (statusScope.isCancelled) return; +#endif if (HasEntityFlags(FLAG_FRIENDLY)) return; duration = apply_second_hand_duration(duration, source); Entity& head = *GetStatusEffectTarget(); @@ -270,6 +285,10 @@ void Entity::AddCharmed(const EntityRef& source, int duration, bool isIgnoreBoss // tinted grey. An enemy just confused finds a new path. void Entity::AddConfusion(const EntityRef& source, int duration, bool isIgnoreBossCooldown) { +#ifdef ISAAC_REPENTOGON + StatusApplyScope statusScope(STATUS_CONFUSION, *this, source, duration, isIgnoreBossCooldown); + if (statusScope.isCancelled) return; +#endif if (IsDamageSourceFriendly(source) || is_evil_charmed(*this)) return; duration = apply_second_hand_duration(duration, source); Entity& head = *GetStatusEffectTarget(); @@ -291,6 +310,10 @@ void Entity::AddConfusion(const EntityRef& source, int duration, bool isIgnoreBo // status effects while not frozen in ice. Heavy entities are pushed less and for less long, by the log of their mass. void Entity::AddKnockback(const EntityRef& source, Vector push, int duration, bool isImpactDamage) { +#ifdef ISAAC_REPENTOGON + StatusApplyScope statusScope(STATUS_KNOCKBACK, *this, source, duration, push, isImpactDamage); + if (statusScope.isCancelled) return; +#endif constexpr float KNOCKBACK_LIGHT_MASS = 10; if (IsDamageSourceFriendly(source)) return; Entity& head = *GetStatusEffectTarget(); @@ -313,6 +336,10 @@ void Entity::AddKnockback(const EntityRef& source, Vector push, int duration, bo // A poop turns golden instead. void Entity::AddMidasFreeze(const EntityRef& source, int duration, bool isIgnoreBossCooldown) { +#ifdef ISAAC_REPENTOGON + StatusApplyScope statusScope(STATUS_MIDAS_FREEZE, *this, source, duration, isIgnoreBossCooldown); + if (statusScope.isCancelled) return; +#endif if (IsDamageSourceFriendly(source)) return; duration = apply_second_hand_duration(duration, source); Entity& head = *GetStatusEffectTarget(); @@ -339,6 +366,10 @@ void Entity::AddMidasFreeze(const EntityRef& source, int duration, bool isIgnore // challenge a boss frightened by the player shrugs status off sooner. An enemy just frightened (or shrunk) flees anew. void Entity::AddFear(const EntityRef& source, int duration, bool isIgnoreBossCooldown) { +#ifdef ISAAC_REPENTOGON + StatusApplyScope statusScope(STATUS_FEAR, *this, source, duration, isIgnoreBossCooldown); + if (statusScope.isCancelled) return; +#endif if (IsDamageSourceFriendly(source) || is_evil_charmed(*this)) return; duration = apply_second_hand_duration(duration, source); Entity& head = *GetStatusEffectTarget(); @@ -362,6 +393,10 @@ void Entity::AddFear(const EntityRef& source, int duration, bool isIgnoreBossCoo // (the source's player's melee damage without one). Its flicker comes from Update. void Entity::AddBurn(const EntityRef& source, int duration, float damage, bool isIgnoreBossCooldown) { +#ifdef ISAAC_REPENTOGON + StatusApplyScope statusScope(STATUS_BURN, *this, source, duration, damage, isIgnoreBossCooldown); + if (statusScope.isCancelled) return; +#endif if (IsDamageSourceFriendly(source) || is_evil_charmed(*this)) return; duration = apply_second_hand_duration(duration, source); damage = tick_damage_get(*this, source, damage); @@ -380,6 +415,11 @@ void Entity::AddBurn(const EntityRef& source, int duration, float damage, bool i // and damage come from Update. void Entity::AddBleeding(const EntityRef& source, int duration) { +#ifdef ISAAC_REPENTOGON + bool isIgnoreBossCooldown = false; + StatusApplyScope statusScope(STATUS_BLEEDING, *this, source, duration, isIgnoreBossCooldown); + if (statusScope.isCancelled) return; +#endif if (IsDamageSourceFriendly(source)) return; duration = apply_second_hand_duration(duration, source); Entity& head = *GetStatusEffectTarget(); @@ -430,6 +470,10 @@ void Entity::RemoveStatusEffects() // status checks: its collision shrinks with its size, and an enemy just shrunk (or frightened) flees anew. void Entity::AddShrink(const EntityRef& source, int duration, bool isIgnoreBossCooldown, bool isForced) { +#ifdef ISAAC_REPENTOGON + StatusApplyScope statusScope(STATUS_SHRINK, *this, source, duration, isIgnoreBossCooldown); + if (statusScope.isCancelled) return; +#endif if ((!isForced && IsDamageSourceFriendly(source)) || IsBoss()) return; duration = apply_second_hand_duration(duration, source); Entity& head = *GetStatusEffectTarget(); @@ -452,6 +496,11 @@ void Entity::AddShrink(const EntityRef& source, int duration, bool isIgnoreBossC // whatever first spawned the source. void Entity::AddMagnetized(const EntityRef& source, int duration) { +#ifdef ISAAC_REPENTOGON + bool isIgnoreBossCooldown = false; + StatusApplyScope statusScope(STATUS_MAGNETIZED, *this, source, duration, isIgnoreBossCooldown); + if (statusScope.isCancelled) return; +#endif if (IsDamageSourceFriendly(source)) return; duration = apply_second_hand_duration(duration, source); Entity& head = *GetStatusEffectTarget(); @@ -476,6 +525,11 @@ void Entity::AddMagnetized(const EntityRef& source, int duration) // spawned the source. void Entity::AddBaited(const EntityRef& source, int duration) { +#ifdef ISAAC_REPENTOGON + bool isIgnoreBossCooldown = false; + StatusApplyScope statusScope(STATUS_BAITED, *this, source, duration, isIgnoreBossCooldown); + if (statusScope.isCancelled) return; +#endif if (IsDamageSourceFriendly(source)) return; duration = apply_second_hand_duration(duration, source); Entity& head = *GetStatusEffectTarget(); @@ -491,8 +545,13 @@ void Entity::AddBaited(const EntityRef& source, int duration) // 006b77d0 Weakens the entity unless a friend did it, tinted purple, whatever its status guards. // The original ignores the duration it is given and always weakens for three frames or more. -void Entity::AddWeakness(const EntityRef& source, int) +void Entity::AddWeakness(const EntityRef& source, int requestedDuration) { +#ifdef ISAAC_REPENTOGON + bool isIgnoreBossCooldown = false; + StatusApplyScope statusScope(STATUS_WEAKNESS, *this, source, requestedDuration, isIgnoreBossCooldown); + if (statusScope.isCancelled) return; +#endif if (IsDamageSourceFriendly(source)) return; int duration = apply_second_hand_duration(WEAKNESS_DURATION, source); Entity& head = *GetStatusEffectTarget(); @@ -507,6 +566,11 @@ void Entity::AddWeakness(const EntityRef& source, int) // 006b78d0 Marks the entity for Brimstone's bombs unless a friend did it, tinted red, whatever its status guards. void Entity::AddBrimstoneMark(const EntityRef& source, int duration) { +#ifdef ISAAC_REPENTOGON + bool isIgnoreBossCooldown = false; + StatusApplyScope statusScope(STATUS_BRIMSTONE_MARK, *this, source, duration, isIgnoreBossCooldown); + if (statusScope.isCancelled) return; +#endif if (IsDamageSourceFriendly(source)) return; duration = apply_second_hand_duration(duration, source); Entity& head = *GetStatusEffectTarget(); @@ -521,6 +585,11 @@ void Entity::AddBrimstoneMark(const EntityRef& source, int duration) // 006b79d0 Ices the entity (never a boss) unless a friend did it, so it freezes solid when it dies. void Entity::AddIce(const EntityRef& source, int duration) { +#ifdef ISAAC_REPENTOGON + bool isIgnoreBossCooldown = false; + StatusApplyScope statusScope(STATUS_ICE, *this, source, duration, isIgnoreBossCooldown); + if (statusScope.isCancelled) return; +#endif if (IsDamageSourceFriendly(source) || IsBoss()) return; duration = apply_second_hand_duration(duration, source); Entity& head = *GetStatusEffectTarget(); diff --git a/src/entity/weapon/bomb.cpp b/src/entity/weapon/bomb.cpp index 04464ef..22584bd 100644 --- a/src/entity/weapon/bomb.cpp +++ b/src/entity/weapon/bomb.cpp @@ -24,6 +24,9 @@ #include #include #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/callbacks.h" +#endif // A bomb's fuse and damage, and the brimstone and giga bombs' own. Troll bombs light a random part of a second longer. constexpr int FUSE_FRAMES = 45; @@ -483,6 +486,9 @@ void Entity_Bomb::pulse_update(Entity_Player* spawner) // sound plays. void Entity_Bomb::Update() { +#ifdef ISAAC_REPENTOGON + if (boolean_run({"PreBombUpdate", MC_PRE_BOMB_UPDATE, (int)variant}, false, this)) return Entity::Update(); +#endif if (isSkipNextUpdate) { isSkipNextUpdate = false; @@ -911,8 +917,16 @@ void Entity_Bomb::rocket_sprite_update(float shownAngle) // 006a5a60 Draws the bomb at its place: with costumes, the back costume, the bomb, then the others, each following the // bomb's first layer. // The original reads the first layer's frame without checking for one. Without one, the costumes are left out. -void Entity_Bomb::Render(const Vector& offset) +void Entity_Bomb::Render(const Vector& renderOffset) { +#ifdef ISAAC_REPENTOGON + std::optional moved = + render_pre_run({"PreBombRender", MC_PRE_BOMB_RENDER, (int)variant}, this, renderOffset); + if (!moved) return; + const Vector& offset = *moved; +#else + const Vector& offset = renderOffset; +#endif if (!isExists || !isVisible) return; if (isLoadCostumes) update_sparks(); @@ -989,7 +1003,19 @@ static void enemy_push(Entity_Bomb& bomb, Entity& collider) // 006a5f00 Meets another entity: falling bombs and rockets pass tears and bombs, bombs pass pickups and slots, players // nudge it, its hit damages enemies once, and something low slows both down. +// REPENTOGON's collision callbacks run around it. bool Entity_Bomb::HandleCollision(Entity* collider, bool isLow) +{ +#ifdef ISAAC_REPENTOGON + CollisionCallbacks callbacks = {"PreBombCollision", MC_PRE_BOMB_COLLISION, MC_POST_BOMB_COLLISION, (int)variant}; + return collision_callbacks_run(*this, collider, isLow, callbacks, &Entity_Bomb::collision_react); +#else + return collision_react(collider, isLow); +#endif +} + +// HandleCollision's own code. +bool Entity_Bomb::collision_react(Entity* collider, bool isLow) { LuaResult result = lua_engine_get().PreBombCollision(this, collider, isLow); if (result != LUA_RESULT_NIL) return result == LUA_RESULT_TRUE; diff --git a/src/entity/weapon/bomb.h b/src/entity/weapon/bomb.h index 81df69e..2569a32 100644 --- a/src/entity/weapon/bomb.h +++ b/src/entity/weapon/bomb.h @@ -96,6 +96,7 @@ struct Entity_Bomb : Entity void update_sparks(); private: + bool collision_react(Entity* collider, bool isLow); void fall_update(bool isBouncy); void pulse_update(Entity_Player* spawner); bool fuse_update(Entity_Player* spawner); diff --git a/src/entity/weapon/bomb_explosion.cpp b/src/entity/weapon/bomb_explosion.cpp index 409ff64..c1411a0 100644 --- a/src/entity/weapon/bomb_explosion.cpp +++ b/src/entity/weapon/bomb_explosion.cpp @@ -27,6 +27,9 @@ #include #include #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/weapons.h" +#endif // An explosion's reach by its damage, a giga bomb's, and the crater's size at the smallest reach. constexpr float RADIUS_SMALL = 75; @@ -326,6 +329,9 @@ static void explosion_grid_break(const Explosion& explosion) // shrink one no player set off. void explosion_damage(Explosion explosion) { +#ifdef ISAAC_REPENTOGON + if (explosion_damage_hook(explosion)) return; +#endif if (is_scissored(explosion.source)) { int scissors = g_game->playerManager.GetTrinketMultiplier(TRINKET_SAFETY_SCISSORS); @@ -770,6 +776,9 @@ static void giga_bomb_crater(const Explosion& explosion) // Bombs' eggs, Scatter Bombs' poison, Blood, Brimstone and Giga Bombs. void explosion_tear_flag_effects(const Explosion& explosion) { +#ifdef ISAAC_REPENTOGON + if (explosion_tear_flag_effects_hook(explosion)) return; +#endif const TearFlags& flags = explosion.tearFlags; Entity* source = explosion.source; if (flags[TEAR_BUTT_BOMB]) butt_bomb_spread(explosion); diff --git a/src/entity/weapon/knife.cpp b/src/entity/weapon/knife.cpp index 65fb0d2..64ee103 100644 --- a/src/entity/weapon/knife.cpp +++ b/src/entity/weapon/knife.cpp @@ -21,6 +21,9 @@ #include #include #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/callbacks.h" +#endif constexpr float KNIFE_DAMAGE_DEFAULT = 22; constexpr float KNIFE_MAX_DISTANCE_DEFAULT = 100; @@ -855,6 +858,9 @@ void Entity_Knife::sword_beam_fire(Entity_Player* player) // the hit list's refresh, the mods' update and the grid it cuts. A knife whose owner lost its weapon goes. void Entity_Knife::Update() { +#ifdef ISAAC_REPENTOGON + if (boolean_run({"PreKnifeUpdate", MC_PRE_KNIFE_UPDATE, (int)subtype}, false, this)) return Entity::Update(); +#endif if (!isInterpolating) friction *= KNIFE_FRICTION; Entity_Player* player = GetPlayer(); @@ -1606,8 +1612,16 @@ void Entity_Knife::render_orbit_trail(const Vector& offset) // 00965d30 Draws a visible knife (none of a player's during a floor change): an orbiting thrown knife's trail first, // then the knife, then Dead Eye's mark over a club while its player holds charges. -void Entity_Knife::Render(const Vector& offset) +void Entity_Knife::Render(const Vector& renderOffset) { +#ifdef ISAAC_REPENTOGON + std::optional moved = + render_pre_run({"PreKnifeRender", MC_PRE_KNIFE_RENDER, (int)variant}, this, renderOffset); + if (!moved) return; + const Vector& offset = *moved; +#else + const Vector& offset = renderOffset; +#endif if (!isVisible) return; Entity_Player* player = GetPlayer(); if (player && g_game->stageTransition.state != STAGE_TRANSITION_NONE) return; @@ -1645,7 +1659,19 @@ void Entity_Knife::Render(const Vector& offset) // thrown knife pushes bombs along; a vulnerable enemy (or fire, poop or TNT) not hit yet takes the knife's hit (a club's // scaled by its swing, Mom's Knife's by its charge and speed, with the player's tear effects one throw in six, or two // held) and its effects. A Lost Contact knife may destroy an enemy shot. +// REPENTOGON's collision callbacks run around it. bool Entity_Knife::HandleCollision(Entity* collider, bool isLow) +{ +#ifdef ISAAC_REPENTOGON + CollisionCallbacks callbacks = {"PreKnifeCollision", MC_PRE_KNIFE_COLLISION, MC_POST_KNIFE_COLLISION, (int)subtype}; + return collision_callbacks_run(*this, collider, isLow, callbacks, &Entity_Knife::collision_react); +#else + return collision_react(collider, isLow); +#endif +} + +// HandleCollision's own code. +bool Entity_Knife::collision_react(Entity* collider, bool isLow) { constexpr float BOMB_PUSH = 0.6f; constexpr float BOMB_DRAG = 0.8f; diff --git a/src/entity/weapon/knife.h b/src/entity/weapon/knife.h index 0149892..8ac13fa 100644 --- a/src/entity/weapon/knife.h +++ b/src/entity/weapon/knife.h @@ -130,6 +130,7 @@ struct Entity_Knife : Entity void apply_hit_effects(const KnifeHit& hit); private: + bool collision_react(Entity* collider, bool isLow); bool held_update(Entity_Player* player); void ludovico_update(); void path_update(); diff --git a/src/entity/weapon/knives.cpp b/src/entity/weapon/knives.cpp index 94214fc..adba25b 100644 --- a/src/entity/weapon/knives.cpp +++ b/src/entity/weapon/knives.cpp @@ -17,6 +17,9 @@ #include "entity/npc/basement.h" #include #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/callbacks.h" +#endif constexpr float KNIFE_CHARGE_DELAYS = 4; constexpr float KNIFE_CHARGE_MINIMUM = 0.001f; @@ -497,6 +500,9 @@ Entity_Knife* Weapon::fire_bone_club(Entity* clubParent, int clubVariant, bool i club.SetCollisionDamage(player->damage); club.rotationOffset = normalize_angle_degrees(rotationOffset); if (isCantOverwrite) club.AddEntityFlags(FLAG_DONT_OVERWRITE); +#ifdef ISAAC_REPENTOGON + unfiltered_notify("PostFireBoneClub", MC_POST_FIRE_BONE_CLUB, &club); +#endif club.spawnerEntity = owner; return &club; } @@ -731,24 +737,28 @@ Entity_Effect* Entity_Player::FireBrimstoneBall(const PosVel& shot, const Vector ball->timeout = BRIMSTONE_BALL_FRAMES; ball->lifespan = BRIMSTONE_BALL_FRAMES; ball->renderDepthOffset = TECH_LASER_FRONT_DEPTH; - if (!HasCollectible(COLLECTIBLE_TECH_X)) return ball; - - uint32_t ringSeed = Random(); - Entity_Laser* ring = static_cast(game_spawn({.position = ball->pos, - .spawner = this, - .subType = LASER_SUBTYPE_RING_FOLLOW_PARENT, - .type = ENTITY_LASER, - .variant = LASER_THIN_RED, - .seed = ringSeed}, - POOL_OVERWRITE)); - ring->SetColor(laserColor, -1, COLOR_PRIORITY_DEFAULT, false, true); - ring->posOffset = offset; - ring->parent = ball; - ring->renderDepthOffset = TECH_LASER_FRONT_DEPTH; - ring->tearFlags = tearFlags; - ring->SetCollisionDamage(params.tearDamage); - ring->radius = BRIMSTONE_BALL_RING_RADIUS; - ring->spawnerEntity = this; + if (HasCollectible(COLLECTIBLE_TECH_X)) + { + uint32_t ringSeed = Random(); + Entity_Laser* ring = static_cast(game_spawn({.position = ball->pos, + .spawner = this, + .subType = LASER_SUBTYPE_RING_FOLLOW_PARENT, + .type = ENTITY_LASER, + .variant = LASER_THIN_RED, + .seed = ringSeed}, + POOL_OVERWRITE)); + ring->SetColor(laserColor, -1, COLOR_PRIORITY_DEFAULT, false, true); + ring->posOffset = offset; + ring->parent = ball; + ring->renderDepthOffset = TECH_LASER_FRONT_DEPTH; + ring->tearFlags = tearFlags; + ring->SetCollisionDamage(params.tearDamage); + ring->radius = BRIMSTONE_BALL_RING_RADIUS; + ring->spawnerEntity = this; + } +#ifdef ISAAC_REPENTOGON + unfiltered_notify("PostFireBrimstoneBall", MC_POST_FIRE_BRIMSTONE_BALL, ball); +#endif return ball; } diff --git a/src/entity/weapon/laser.cpp b/src/entity/weapon/laser.cpp index ff3d1b4..6101671 100644 --- a/src/entity/weapon/laser.cpp +++ b/src/entity/weapon/laser.cpp @@ -19,6 +19,9 @@ #include "game/sfx_manager.h" #include #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/callbacks.h" +#endif constexpr float THIN_SCALE_THRESHOLDS[] = {1.15f, 2.2f, 4.2f}; constexpr float THIN_SCALE_DIVISORS[] = {1, 2, 4, 6}; @@ -1012,6 +1015,9 @@ void Entity_Laser::color_cycle_update() // loop). Its first update sets it up instead: a static beam for Dogma, the Cage's Vis's own sprite. void Entity_Laser::Update() { +#ifdef ISAAC_REPENTOGON + if (boolean_run({"PreLaserUpdate", MC_PRE_LASER_UPDATE, (int)variant}, false, this)) return Entity::Update(); +#endif if (tearFlags[TEAR_WAIT] && !IsCircleLaser() && timeout > 0) tear_wait_start(); Entity* swirl = tearWaitEffect; if (swirl && static_cast(swirl)->state == 0 && waitFrames < LASER_WAIT_FRAMES) diff --git a/src/entity/weapon/laser_hits.cpp b/src/entity/weapon/laser_hits.cpp index 4e78afb..a6ee38d 100644 --- a/src/entity/weapon/laser_hits.cpp +++ b/src/entity/weapon/laser_hits.cpp @@ -21,6 +21,9 @@ #include #include #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/callbacks.h" +#endif constexpr float LASER_KNOCKBACK = 1.8f; constexpr float ATTRACTOR_NEAREST_START = 1e6f; @@ -128,6 +131,10 @@ static void laser_push(Entity_Laser& laser, Entity& entity, Vector direction, fl // spared. A Brimstone-marked entity takes a thick beam's hit harder, and Black Hp drops are rolled from its seed. void Entity_Laser::DoDamage(Entity* entity, float damage) { +#ifdef ISAAC_REPENTOGON + CallbackRun post = {"PostLaserCollision", MC_POST_LASER_COLLISION, variant}; + ScopeExit postRun{[&] { callback_notify(lua_engine_get(), post, this, entity); }}; +#endif std::vector& hits = hit_list_get(); uint32_t hitIndex = entity->GetHitListIndex(); auto slot = std::lower_bound(hits.begin(), hits.end(), hitIndex); @@ -499,6 +506,9 @@ void Entity_Laser::update_line_hits(float damage) float across = std::abs(direction.y * relative.x - direction.x * relative.y); float reach = variant == LASER_PRIDE ? vector_length(relative) * RING_REACH_SCALE : entity->size + size; if (across >= reach || along <= 0 || along >= std::abs(posOffset.y) + laserLength) continue; +#ifdef ISAAC_REPENTOGON + if (boolean_run({"PreLaserCollision", MC_PRE_LASER_COLLISION, variant}, false, this, entity)) continue; +#endif DoDamage(entity, damage); if (is_knocked_back(*this, *entity)) laser_push(*this, *entity, direction, entity->mass); @@ -554,7 +564,12 @@ void Entity_Laser::update_line_hits(float damage) if (behindSquared < projection.distanceSquared) projection = {behindSquared, 0}; } float reach = entity->size + size; - if (reach * reach <= projection.distanceSquared) + bool isMissed = reach * reach <= projection.distanceSquared; +#ifdef ISAAC_REPENTOGON + CallbackRun pre = {"PreLaserCollision", MC_PRE_LASER_COLLISION, variant}; + isMissed = isMissed || boolean_run(pre, false, this, entity); +#endif + if (isMissed) { travelled += length; continue; diff --git a/src/entity/weapon/lasers.cpp b/src/entity/weapon/lasers.cpp index 09a7cdf..2ae3ee4 100644 --- a/src/entity/weapon/lasers.cpp +++ b/src/entity/weapon/lasers.cpp @@ -20,6 +20,9 @@ #include "game/sfx_manager.h" #include "entity/weapon/fetus.h" #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/callbacks.h" +#endif constexpr float LASER_INHERIT_SCALE = 0.4f; constexpr float FAMILIAR_EYE_SPREAD = 7; @@ -329,6 +332,9 @@ Entity_Laser* Weapon::FireBrimstone(const BrimstoneShot& shot) laser->isPlayerParams = true; laser->mass *= massMultiplier; laser->tearFlags = params.tearFlags; +#ifdef ISAAC_REPENTOGON + unfiltered_notify("PostFireBrimstone", MC_POST_FIRE_BRIMSTONE, laser); +#endif return laser; } @@ -1323,6 +1329,11 @@ static void sneeze_blast(const SneezeHit& hit, Vector tip) // params at one and a half times the damage scale, and every burst is shielded. Whether it hurt an enemy. bool Weapon_Brimstone::fire_hitscan(const Vector& direction, float damageScale) { +#ifdef ISAAC_REPENTOGON + auto sneeze = [&](const char* name, int callback) { unfiltered_notify(name, callback, owner, direction, damageScale); }; + sneeze("PreBrimstoneSneeze", MC_PRE_BRIMSTONE_SNEEZE); + ScopeExit post{[&] { sneeze("PostBrimstoneSneeze", MC_POST_BRIMSTONE_SNEEZE); }}; +#endif SneezeHit hit; hit.color = get_laser_color(); hit.owner = owner; diff --git a/src/entity/weapon/projectile.cpp b/src/entity/weapon/projectile.cpp index 38a35d3..be56546 100644 --- a/src/entity/weapon/projectile.cpp +++ b/src/entity/weapon/projectile.cpp @@ -24,6 +24,9 @@ #include #include #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/callbacks.h" +#endif // The shot a fresh projectile is: its height, slight random fall, homing, curving and change defaults. constexpr float HEIGHT_START = -23; @@ -743,6 +746,10 @@ static void fly_ball_update(Entity_Projectile& ball) // parent. void Entity_Projectile::Update() { +#ifdef ISAAC_REPENTOGON + if (boolean_run({"PreProjectileUpdate", MC_PRE_PROJECTILE_UPDATE, (int)variant}, false, this)) + return Entity::Update(); +#endif speedMultiplier = time_scale_get(); if (pauseTimer > 0) pauseTimer--; if (projectileFlags & GRID_PASS_FLAGS) isCollidesWithGrid = false; @@ -1300,6 +1307,9 @@ void Entity_Projectile::death_update() if (projectileFlags & PROJECTILE_LASER_SHOT) laser_shot_dot_spawn(); if (projectileFlags & PROJECTILE_SIDE_WAVE) side_wave_burst(); if (variant == PROJECTILE_HEAD) head_splash(); +#ifdef ISAAC_REPENTOGON + callback_notify(lua_engine_get(), {"PostProjectileDeath", MC_POST_PROJECTILE_DEATH, (int)variant}, this); +#endif Remove(); if (variant == PROJECTILE_FIRE && spawnerType == ENTITY_BEAST) npc_sound_play(SOUND_BEAST_FIRE_RING, 1, 2, 1); } @@ -2391,8 +2401,16 @@ void Entity_Projectile::Interpolate() // 0065cb60 Draws the shot, at the floor when it is rendered at the ground. A shot the Broken Modem froze draws // where it froze, scaled down and glitching. -void Entity_Projectile::Render(const Vector& offset) +void Entity_Projectile::Render(const Vector& renderOffset) { +#ifdef ISAAC_REPENTOGON + std::optional moved = + render_pre_run({"PreProjectileRender", MC_PRE_PROJECTILE_RENDER, (int)variant}, this, renderOffset); + if (!moved) return; + const Vector& offset = *moved; +#else + const Vector& offset = renderOffset; +#endif if (isRenderedAtGround) posOffset.y -= height; bool isModemFrozen = HasEntityFlags(FLAG_FREEZE) && !vector_is_zero(modemPosition); @@ -2458,7 +2476,20 @@ void Entity_Projectile::update_height_collision() // 0065b670 Hits what it touches: a player above its reach (unless a hat or Infamy blocks it), an enemy when it is // friendly, and the familiars that take hits. Singe's ball, frozen enemies and poop break it. Whether the collision // is ignored. The Beast's lava ball never stops a collision. +// REPENTOGON's collision callbacks run around it. bool Entity_Projectile::HandleCollision(Entity* collider, bool isLow) +{ +#ifdef ISAAC_REPENTOGON + CollisionCallbacks callbacks = {"PreProjectileCollision", MC_PRE_PROJECTILE_COLLISION, MC_POST_PROJECTILE_COLLISION, + (int)variant}; + return collision_callbacks_run(*this, collider, isLow, callbacks, &Entity_Projectile::collision_react); +#else + return collision_react(collider, isLow); +#endif +} + +// HandleCollision's own code. +bool Entity_Projectile::collision_react(Entity* collider, bool isLow) { LuaResult luaResult = lua_engine_get().PreProjectileCollision(this, collider, isLow); if (luaResult == LUA_RESULT_TRUE) return true; diff --git a/src/entity/weapon/projectile.h b/src/entity/weapon/projectile.h index dc46ba2..0fe13de 100644 --- a/src/entity/weapon/projectile.h +++ b/src/entity/weapon/projectile.h @@ -197,6 +197,7 @@ struct Entity_Projectile : Entity void update_height_collision(); private: + bool collision_react(Entity* collider, bool isLow); float time_scale_get(); bool modem_freeze_update(); void animation_update(); diff --git a/src/entity/weapon/spirit_sword.cpp b/src/entity/weapon/spirit_sword.cpp index ad8881f..600a5e8 100644 --- a/src/entity/weapon/spirit_sword.cpp +++ b/src/entity/weapon/spirit_sword.cpp @@ -13,6 +13,9 @@ #include "game/sfx_manager.h" #include #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/callbacks.h" +#endif constexpr float SWORD_LIFT = -10; constexpr float SWORD_CHARGE_DELAYS = 4; @@ -64,6 +67,9 @@ Entity_Knife* Weapon::FireSword(const KnifeShot& shot) } sword->rotationOffset = normalize_angle_degrees(shot.rotationOffset); if (shot.isCantOverwrite) sword->AddEntityFlags(FLAG_DONT_OVERWRITE); +#ifdef ISAAC_REPENTOGON + unfiltered_notify("PostFireSword", MC_POST_FIRE_SWORD, sword); +#endif return sword; } diff --git a/src/entity/weapon/tear.cpp b/src/entity/weapon/tear.cpp index 7b053b5..9d1123e 100644 --- a/src/entity/weapon/tear.cpp +++ b/src/entity/weapon/tear.cpp @@ -25,6 +25,12 @@ #include #include #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/callbacks.h" +#ifdef ISAAC_REPENTOGON +#include "repentogon/weapons.h" +#endif +#endif constexpr float TEAR_HEIGHT_START = -23; constexpr float TEAR_DAMAGE_DEFAULT = 3.5f; @@ -519,6 +525,9 @@ static void versus_circle_reflect(Entity_Tear& tear) // steer, grow, shrink, split, link and stick it. void Entity_Tear::Update() { +#ifdef ISAAC_REPENTOGON + if (boolean_run({"PreTearUpdate", MC_PRE_TEAR_UPDATE, (int)variant}, false, this)) return Entity::Update(); +#endif if (isFireSoundPending) { play_fire_sound(); @@ -1430,8 +1439,16 @@ void Entity_Tear::big_spiral_apply(float strength) } // 006790c0 Draws the tear with its halo, its tear effect behind or in front, and Dead Eye's glow. -void Entity_Tear::Render(const Vector& offset) +void Entity_Tear::Render(const Vector& renderOffset) { +#ifdef ISAAC_REPENTOGON + std::optional moved = + render_pre_run({"PreTearRender", MC_PRE_TEAR_RENDER, (int)variant}, this, renderOffset); + if (!moved) return; + const Vector& offset = *moved; +#else + const Vector& offset = renderOffset; +#endif if (!isExists || !isVisible) return; renderPosition = vector_add(render_position_get(vector_add(pos, posOffset), RENDER_SNAPPED), offset); @@ -2170,6 +2187,9 @@ void Entity_Tear::ApplyTearFlagEffects(Entity* entity, const Vector& position, c float damage) { if (!entity || (source && entity->IsDamageSourceFriendly(EntityRef(source)))) return; +#ifdef ISAAC_REPENTOGON + if (tear_flag_effects_hook({entity, position, flags, source, damage})) return; +#endif Vector direction = hit_direction_get(*entity, position, source); bool isActiveEnemy = entity->IsActiveEnemy(DEAD_EXCLUDED); diff --git a/src/entity/weapon/tear.h b/src/entity/weapon/tear.h index b0c1ae5..4a9f73c 100644 --- a/src/entity/weapon/tear.h +++ b/src/entity/weapon/tear.h @@ -369,6 +369,7 @@ struct Entity_Tear : Entity float damage); private: + bool collision_react(Entity* collider, bool isLow); float animation_update(); float spinning_animation_update(); float fetus_animation_update(); diff --git a/src/entity/weapon/tear_death.cpp b/src/entity/weapon/tear_death.cpp index 6a9455a..cb19d41 100644 --- a/src/entity/weapon/tear_death.cpp +++ b/src/entity/weapon/tear_death.cpp @@ -15,6 +15,9 @@ #include "game/sfx_manager.h" #include #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/callbacks.h" +#endif // The splash a dying tear leaves: the poof sizes by its scale, the volumes and pitches of the sounds, the particles // the hard tears break into, Bob's head's and Ipecac's explosion, and the stains the plain tears leave. @@ -462,7 +465,12 @@ void Entity_Tear::death_update() if (splash.effect) poof_spawn(splash, explosionScale); if (std::find(TEAR_STAINING_VARIANTS.begin(), TEAR_STAINING_VARIANTS.end(), variant) != TEAR_STAINING_VARIANTS.end()) blood_stains_spawn(); - if (isDead) Remove(); + if (!isDead) return; + +#ifdef ISAAC_REPENTOGON + callback_notify(lua_engine_get(), {"PostTearDeath", MC_POST_TEAR_DEATH, (int)variant}, this); +#endif + Remove(); } // Cricket's Body: four pieces at a random angle and its right angles, at the dying tear's speed (10 when it barely diff --git a/src/game/end.cpp b/src/game/end.cpp index 9f2aea0..eeed24c 100644 --- a/src/game/end.cpp +++ b/src/game/end.cpp @@ -14,6 +14,10 @@ #include #include #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/callbacks.h" +#include "repentogon/saves.h" +#endif // The cutscene each ending plays, none for a death. Mom's Heart's first eleven kills each play the next of the Womb's // endings (cutscenes 4 to 14), any later one the credits. @@ -181,9 +185,16 @@ static void completion_mark_unlock(int completion, int playerType, int difficult // 0095a7b0 Marks a completion for every main player (a twin once, the first of the pair), a risen Lazarus as Lazarus // II, then Mega Satan's and Mother's own unlocks. -// Netplay is offline, so the online players' queued marks are left out. +// Netplay is offline, so the online players' queued marks are left out. A mod may refuse or change the completion. void PlayerManager::unlock_completion_mark(int completionType) { +#ifdef ISAAC_REPENTOGON + if (!completion_event_pre(completionType)) return; + ScopeExit post{[&] { + CallbackRun run = {"PostCompletionEvent", MC_POST_COMPLETION_EVENT, completionType}; + callback_notify(lua_engine_get(), run, completionType); + }}; +#endif Game* game = g_game; if (!game) return; diff --git a/src/game/game.cpp b/src/game/game.cpp index f97351c..a04e895 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -23,6 +23,9 @@ extern "C" { #include "lua.h" } +#ifdef ISAAC_REPENTOGON +#include "repentogon/level.h" +#endif constexpr const char* STAGES_XML = "stages.xml"; constexpr const char* CURSES_XML = "curses.xml"; @@ -1106,6 +1109,9 @@ void Game::Render() // or the online stats screen. The original's netplay player-list checks are is_online, as the game is offline. bool Game::IsPaused() { +#ifdef ISAAC_REPENTOGON + if (isUpdateHeld) return true; +#endif bool isOffline = !g_manager->netplayManager.is_online(); if (console.state != CONSOLE_CLOSED && isOffline) return true; diff --git a/src/game/manager.cpp b/src/game/manager.cpp index 75f1891..d8f355f 100644 --- a/src/game/manager.cpp +++ b/src/game/manager.cpp @@ -13,7 +13,11 @@ #include "engine/kage_input.h" #include "engine/texture_cache.h" #ifdef ISAAC_REPENTOGON +#include "repentogon/callbacks.h" +#include "repentogon/collision.h" #include "repentogon/options.h" +#include "repentogon/repentogon.h" +#include "repentogon/saves.h" #endif #include #include @@ -607,6 +611,9 @@ void isaac_shutdown() data.Save(); } if (manager.state == MANAGER_STATE_GAME) Game::Exit(true); +#ifdef ISAAC_REPENTOGON + if (!repentogonOptions.isVanillaParity) mods_shutdown_notify(lua_engine_get()); +#endif log_printf(LOG_INFO, "Isaac has shut down successfully \n"); } @@ -1174,6 +1181,9 @@ void Manager::SetSaveSlot(uint32_t slot) } } currentSaveSlot = slot; +#ifdef ISAAC_REPENTOGON + save_slot_post(slot); +#endif } // 00958aa0 Queues a new run on a character, challenge, seeds and difficulty: no saved run, rerun, debug run or daily. @@ -1460,6 +1470,9 @@ static void run_update(Manager& manager) entity->isInterpolating = false; } game.Update(); +#ifdef ISAAC_REPENTOGON + grid_collision_cache_clear(); +#endif } else if (manager.optionsConfig.render.isInterpolationEnabled) game.interpolate_update(); @@ -1598,6 +1611,9 @@ static void cursor_render(Manager& manager) // The mods' Workshop update screen is offline with Steam, and netplay draws nothing offline. void Manager::Render() { +#ifdef ISAAC_REPENTOGON + callback_notify(lua_engine_get(), {"MC_PRE_RENDER", MC_PRE_RENDER, std::nullopt}); +#endif KAGE::Graphics::Manager& graphics = KAGE::Graphics::manager; using KAGE::Graphics::PRESENT_FLUSH; using KAGE::Graphics::TARGET_SCREEN_SIZE; diff --git a/src/game/mod_manager.cpp b/src/game/mod_manager.cpp index 071326e..69c969d 100644 --- a/src/game/mod_manager.cpp +++ b/src/game/mod_manager.cpp @@ -13,6 +13,10 @@ #include #include #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/callbacks.h" +#include "repentogon/render.h" +#endif // classes.h declares the original's Lua imports, and its luaL_newstate differs from Lua's only in its return type. #define luaL_newstate lua_newstate_auxiliary @@ -595,6 +599,9 @@ void ModManager::LoadModContent() g_manager->entityConfig.tainted_players_link(); modDefaultsSprite.Load(MOD_DEFAULTS_SPRITE, GRAPHICS_LOAD); +#ifdef ISAAC_REPENTOGON + unfiltered_notify("PostModsLoaded", MC_POST_MODS_LOADED); +#endif } // 008f46f0 Adds each loaded mod's itempools.xml to the game's item pools, once a game exists. @@ -766,9 +773,16 @@ void ModManager::RenderCustomCharacterMenu(int characterId, Vector& renderPos, A { EntityConfig_Player* player = g_manager->entityConfig.GetPlayer(characterId); ANM2* sprite = character_sprite_play(characterId, PLAYER_SPRITE_MENU_BACKGROUND); +#ifdef ISAAC_REPENTOGON + CharacterPage page = {sprite, defaultSprite, renderPos, characterId, sprite && player->isRenderCustomBackground}; + if (!character_page_pre(page)) return; +#endif if (!sprite || !player->isRenderCustomBackground) defaultSprite.RenderLayer(0, {renderPos}); if (sprite) sprite->Render({renderPos}); +#ifdef ISAAC_REPENTOGON + character_page_post(page); +#endif } // 008f8a60 Draws a modded character's game over sprite, when it brings one. diff --git a/src/game/music_manager.cpp b/src/game/music_manager.cpp index 3c19cd9..196072d 100644 --- a/src/game/music_manager.cpp +++ b/src/game/music_manager.cpp @@ -3,6 +3,9 @@ #include "game/game.h" #include "game/manager.h" #include "level/room.h" +#ifdef ISAAC_REPENTOGON +#include "repentogon/audio.h" +#endif #include #include #include @@ -455,6 +458,9 @@ void MusicManager::track_play(MusicChannel& channel, MusicTrack& track, float vo // 007e1d50 Plays a track from the start on the current channel at a volume, stopping both channels first. void MusicManager::Play(int musicId, float volume) { +#ifdef ISAAC_REPENTOGON + if (!music_play_pre(*this, musicId, volume, MUSIC_START_PLAY)) return; +#endif if (!is_music_id_valid(musicId)) { log_printf(LOG_ASSERT, "Music ID %d out of bounds.\n", musicId); @@ -482,6 +488,9 @@ void MusicManager::Play(int musicId, float volume) // other channel to the music volume. For the track already playing it only sets the target volume. void MusicManager::Crossfade(int musicId, float fadeRate) { +#ifdef ISAAC_REPENTOGON + if (!music_play_pre(*this, musicId, fadeRate, MUSIC_START_CROSSFADE)) return; +#endif if (!is_music_id_valid(musicId)) { log_printf(LOG_ASSERT, "Music ID %d out of bounds.\n", musicId); @@ -544,6 +553,9 @@ void MusicManager::Fadeout(float fadeRate) // The original's two unused arguments are dropped. void MusicManager::PlayJingle(int musicId) { +#ifdef ISAAC_REPENTOGON + if (!music_jingle_pre(musicId)) return; +#endif if (!is_music_id_valid(musicId) || currentMusicId == MUSIC_BOSS_OVER_TWISTED) return; if (currentMusicId == MUSIC_REVERSE_GENESIS || tracks[musicId].path.empty()) return; @@ -578,6 +590,9 @@ void MusicManager::Resume() // going silent at once in LAYER_MODE_REPLACE) with the channel updated right away. void MusicManager::EnableLayer(int layerId, LayerSwitch layerSwitch) { +#ifdef ISAAC_REPENTOGON + if (!music_layer_pre(layerId, LAYER_TOGGLE_ON)) return; +#endif if (layerId < 0 || layerId >= MUSIC_LAYER_COUNT) return; MusicChannel& channel = channels[currentChannel]; @@ -602,6 +617,9 @@ void MusicManager::EnableLayer(int layerId, LayerSwitch layerSwitch) // 007e2410 Turns a layer of the current track off, to fade out. void MusicManager::DisableLayer(int layerId) { +#ifdef ISAAC_REPENTOGON + if (!music_layer_pre(layerId, LAYER_TOGGLE_OFF)) return; +#endif if (layerId >= 0 && layerId < MUSIC_LAYER_COUNT) channels[currentChannel].enabledLayers.reset(layerId); } diff --git a/src/game/persistent_game_data.cpp b/src/game/persistent_game_data.cpp index 895a308..8359464 100644 --- a/src/game/persistent_game_data.cpp +++ b/src/game/persistent_game_data.cpp @@ -12,6 +12,11 @@ #include #include #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/callbacks.h" +#include "repentogon/level.h" +#include "repentogon/saves.h" +#endif constexpr int ACHIEVEMENT_NEVER = -2; constexpr int CUTSCENE_EPILOGUE = 3; @@ -1072,6 +1077,10 @@ bool PersistentGameData::TryUnlock(int achievementID) isChangesMade = true; check_challenge_unlocks(); check_collection_unlocks(); +#ifdef ISAAC_REPENTOGON + CallbackRun run = {"PostAchievementUnlock", MC_POST_ACHIEVEMENT_UNLOCK, achievementID}; + callback_notify(lua_engine_get(), run, achievementID); +#endif return true; } @@ -1085,9 +1094,12 @@ bool PersistentGameData::Unlocked(int achievementID) } // 00929b40 Adds to an event counter (which stops at 0) and checks every unlock counters and completion marks give. -// An id past the counters is ignored, where the game wrote past them. +// An id past the counters is ignored, where the game wrote past them. A mod may refuse a character's completion mark. void PersistentGameData::IncreaseEventCounter(int eventCounter, int num) { +#ifdef ISAAC_REPENTOGON + if (!is_hook_inner() && completion_mark_hook(*this, eventCounter, num)) return; +#endif if (isReadOnly || eventCounter < 0 || eventCounter >= EVENT_COUNTER_COUNT) return; int& counter = eventCounters[eventCounter]; @@ -1215,10 +1227,17 @@ void PersistentGameData::check_collection_unlocks() // 0092a7b0 Marks a challenge as won and unlocks its achievement. void PersistentGameData::AddChallenge(int challengeID) { - if (isReadOnly || challengeID < 0 || challengeID >= CHALLENGE_COUNT) return; - - challenges[challengeID] = true; - TryUnlock(CHALLENGE_WIN_ACHIEVEMENTS[challengeID]); +#ifdef ISAAC_REPENTOGON + if (!challenge_done_pre(challengeID)) return; +#endif + if (!isReadOnly && challengeID >= 0 && challengeID < CHALLENGE_COUNT) + { + challenges[challengeID] = true; + TryUnlock(CHALLENGE_WIN_ACHIEVEMENTS[challengeID]); + } +#ifdef ISAAC_REPENTOGON + callback_notify(lua_engine_get(), {"PostChallengeDone", MC_POST_CHALLENGE_DONE, challengeID}, challengeID); +#endif } // 0092b270 Stores the characters run with as a bit mask, unlocking an achievement once five have been. diff --git a/src/game/restore.cpp b/src/game/restore.cpp index e2c0c73..dec631f 100644 --- a/src/game/restore.cpp +++ b/src/game/restore.cpp @@ -15,6 +15,11 @@ #include #include #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/callbacks.h" +#include "repentogon/items.h" +#include "repentogon/saves.h" +#endif constexpr uint32_t ROOM_REF_STAGE_MASK = 0xffff; constexpr uint32_t ROOM_REF_HALF_MASK = 0xffff; @@ -107,6 +112,9 @@ static void ambush_resume(Ambush& ambush, int wave) // Netplay is offline. void Game::restore_game_state(GameState& state, GameRestore restore) { +#ifdef ISAAC_REPENTOGON + game_state_callbacks_run(state, MC_PRE_GAME_STATE_RESTORE, MC_PRE_GLOWING_HOURGLASS_LOAD); +#endif Manager& manager = *g_manager; uint64_t savedFlagsMask = (1ull << SAVED_GAME_STATE_FLAG_COUNT) - 1; @@ -184,6 +192,9 @@ void Game::restore_game_state(GameState& state, GameRestore restore) if (ambush.isActive) ambush_resume(ambush, state.ambushWave); scoreSheet.restore_state(state.scoreSheet); for (Entity_Player* player : playerManager.playerList) player->update_mini_mush_costume(); +#ifdef ISAAC_REPENTOGON + game_state_callbacks_run(state, MC_POST_GAME_STATE_RESTORE, MC_POST_GLOWING_HOURGLASS_LOAD); +#endif } // Part of 00706020: the familiars and friendly enemies leave the room's lists (the state brings them back), counting @@ -963,6 +974,10 @@ static void dark_esau_restore(Entity_Player& player) // the co-op ghost's entrance and a sub player the Soul of the Forgotten no longer needs. Its stats are evaluated again. void Entity_Player::RestoreGameState_PostLevelInit(GameStatePlayer& saved) { +#ifdef ISAAC_REPENTOGON + isFamiliarsRestoring = true; + ScopeExit restored = {[] { isFamiliarsRestoring = false; }}; +#endif for (const FamiliarData& familiar : saved.familiars) { Vector spot = vector_add(pos, vector_scale(random_direction(), FAMILIAR_RESTORE_SCATTER)); diff --git a/src/game/save.cpp b/src/game/save.cpp index 7c1b4ea..a4411e3 100644 --- a/src/game/save.cpp +++ b/src/game/save.cpp @@ -7,6 +7,10 @@ #include "game/manager.h" #include "engine/platform.h" #include "level/room.h" +#ifdef ISAAC_REPENTOGON +#include "repentogon/callbacks.h" +#include "repentogon/saves.h" +#endif constexpr int CHARGER_MY_SHADOW = 1; constexpr int FAMILIAR_UMBILICAL_BABY = 240; @@ -29,6 +33,9 @@ static void versus_store(DeathmatchManager& manager, GameState& state) // The saved flags are the first 53 of the run's state flags. void Game::store_game_state(GameState& state) { +#ifdef ISAAC_REPENTOGON + game_state_callbacks_run(state, MC_PRE_GAME_STATE_SAVE, MC_PRE_GLOWING_HOURGLASS_SAVE); +#endif state.Clear(); state.seeds = seedEffects; state.playerManagerSeed = playerManager.rng._seed; @@ -81,6 +88,9 @@ void Game::store_game_state(GameState& state) state.ambushWave = ambush.currentWave > 0 ? ambush.currentWave - 1 : ambush.currentWave; scoreSheet.store_state(state.scoreSheet); versus_store(deathmatchManager, state); +#ifdef ISAAC_REPENTOGON + game_state_callbacks_run(state, MC_POST_GAME_STATE_SAVE, MC_POST_GLOWING_HOURGLASS_SAVE); +#endif } // 00705ee0 Saves the run for the Glowing Hourglass as the players enter a room, by the door they leave it through. @@ -492,8 +502,12 @@ void Entity_Player::StoreGameState(GameStatePlayer* saveState, bool isSaveTempor { if (entity->type != ENTITY_FAMILIAR) continue; Entity_Familiar& familiar = *static_cast(entity); - if (familiar.player == this && is_familiar_saved(familiar, isSaveTemporaryFamiliars)) - familiar.store_backup(&state.familiars.emplace_back()); + if (familiar.player != this || !is_familiar_saved(familiar, isSaveTemporaryFamiliars)) continue; + + familiar.store_backup(&state.familiars.emplace_back()); +#ifdef ISAAC_REPENTOGON + unfiltered_notify("EntitySave", MC_ENTITY_SAVE, entity); +#endif } } state.levelEffectItems = levelEffectItems; @@ -511,4 +525,7 @@ void Entity_Player::StoreGameState(GameStatePlayer* saveState, bool isSaveTempor state.queuedItem = queuedItem; state.temporaryEffects = temporaryEffects.effects; state.strengthMaxHearts = strengthMaxHearts; +#ifdef ISAAC_REPENTOGON + unfiltered_notify("EntitySave", MC_ENTITY_SAVE, (Entity*)this); +#endif } diff --git a/src/game/sfx_manager.cpp b/src/game/sfx_manager.cpp index e13d12b..b9a88b5 100644 --- a/src/game/sfx_manager.cpp +++ b/src/game/sfx_manager.cpp @@ -2,6 +2,9 @@ #include "engine/data.h" #include "game/music_manager.h" #include "game/manager.h" +#ifdef ISAAC_REPENTOGON +#include "repentogon/audio.h" +#endif #include #include #include @@ -249,6 +252,9 @@ void SFXManager::Preload(int soundId) // Called without a pan (0092df00), it pans to the center. void SFXManager::Play(int soundId, SoundPlay play) { +#ifdef ISAAC_REPENTOGON + if (sfx_play_hook(*this, soundId, play)) return; +#endif SoundEffect* sound = sound_find(soundId); if (!sound) return; diff --git a/src/game/transition.cpp b/src/game/transition.cpp index 94e0087..4fb6f6a 100644 --- a/src/game/transition.cpp +++ b/src/game/transition.cpp @@ -13,6 +13,9 @@ #include #include #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/level.h" +#endif constexpr int ROOM_INDEX_MIN = -20; constexpr int ROOM_INDEX_MAX = LEVEL_GRID_CELLS - 1; @@ -372,6 +375,9 @@ static void enter_door_open(Level& level, int previousType) // dropped, a mineshaft entrance marks its descent, the new room loads and its entry door opens, then the map updates. void Level::ChangeRoom(int targetRoomIdx, int dimension) { +#ifdef ISAAC_REPENTOGON + change_room_pre(targetRoomIdx, dimension); +#endif Game& game = *g_game; PersistentGameData& persistent = g_manager->persistentGameData; int newRoomIdx = std::clamp(targetRoomIdx, ROOM_INDEX_MIN, ROOM_INDEX_MAX); diff --git a/src/game/update.cpp b/src/game/update.cpp index 2d70660..b9bb17b 100644 --- a/src/game/update.cpp +++ b/src/game/update.cpp @@ -13,6 +13,9 @@ #include #include #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/level.h" +#endif constexpr float TRAPDOOR_LOOP_FADE = 0.05f; constexpr float TRAPDOOR_HEARING_DISTANCE = 200; @@ -338,6 +341,9 @@ static void screen_effects_update(Game& game) // The online stats are not registered: Game's onlinePlayerStats stays a generated vector. void Game::Update() { +#ifdef ISAAC_REPENTOGON + isUpdateHeld = false; +#endif if (console.update_state()) return; trapdoor_loop_sfx_update(*this); @@ -389,6 +395,9 @@ void Game::Update() if (pauseScreen.is_pausing()) return; } if (isOffline && revivePlayerMenu.state != REVIVE_MENU_HIDDEN) return revivePlayerMenu.Update(); +#ifdef ISAAC_REPENTOGON + if (game_update_is_skipped()) return; +#endif timers_update(*this); room->Update(); diff --git a/src/level/ambush.cpp b/src/level/ambush.cpp index 7acc531..1d8ee73 100644 --- a/src/level/ambush.cpp +++ b/src/level/ambush.cpp @@ -21,6 +21,10 @@ #include #include #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/callbacks.h" +#include "repentogon/level.h" +#endif // A wave's difficulty by wave (one later on Hard), the room subtypes of normal and boss waves, how often a wave is // drawn again (the special rooms' stage the second time) before none is called, and the Death Certificate's @@ -132,6 +136,9 @@ static std::vector> wave_entries_pick(Ambush& ambush) .subtype = isBossWave ? WAVE_SUBTYPE_BOSS : WAVE_SUBTYPE_NORMAL, .type = ROOM_CHALLENGE}; RoomConfig_Room* wave = game.roomConfig.GetRandomRoom(ambush.waveRng.Next(), WEIGHT_REDUCE, query); +#ifdef ISAAC_REPENTOGON + wave = wave_room_select(wave, MC_PRE_SELECT_AMBUSH_WAVE, ambush.waveRng._seed); +#endif if (!wave) { if (stageId == STAGE_ID_SPECIAL_ROOMS) @@ -193,6 +200,9 @@ void Ambush::SpawnWave() spawned->spawnGridIndex = cell; } wave_summoned(); +#ifdef ISAAC_REPENTOGON + callback_notify(lua_engine_get(), {"PostStartAmbushWave", MC_POST_START_AMBUSH_WAVE, std::nullopt}, false); +#endif } // A boss's pentagram where it is to rise, from the next seed. @@ -277,6 +287,9 @@ void Ambush::SpawnBossrushWave() boss_rush_ground_clear(boss.type, spot); } wave_summoned(); +#ifdef ISAAC_REPENTOGON + callback_notify(lua_engine_get(), {"PostStartAmbushWave", MC_POST_START_AMBUSH_WAVE, std::nullopt}, true); +#endif } // 00834350 Runs the fight: 30 frames after a wave's enemies (the Boss Rush's bosses) are gone the next is called, the diff --git a/src/level/backdrop.cpp b/src/level/backdrop.cpp index 71ff960..b95c061 100644 --- a/src/level/backdrop.cpp +++ b/src/level/backdrop.cpp @@ -22,6 +22,9 @@ #include #include #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/callbacks.h" +#endif constexpr std::string_view DEFAULT_PROPS = "gfx/grid/props_01_basement.anm2"; constexpr std::string_view DEFAULT_ROCKS = "gfx/grid/rocks_basement.png"; @@ -359,6 +362,10 @@ bool Backdrop::LoadConfig(std::string_view path) // loads its graphics if asked. void Backdrop::Init(uint32_t id, bool isLoadGraphics) { +#ifdef ISAAC_REPENTOGON + CallbackRun run = {"PreBackdropChange", MC_PRE_BACKDROP_CHANGE, std::nullopt}; + id = (uint32_t)callback_integer_run(lua_engine_get(), run, (int)id, id); +#endif Room& room = *g_game->room; backdropId = (int)id < 0 || (int)id >= BACKDROP_COUNT ? 1 : id; @@ -577,6 +584,10 @@ void Backdrop::load_details() graphics.isCullOffscreen = false; render_ashpit_ash(); pre_render_walls(); +#ifdef ISAAC_REPENTOGON + callback_notify(lua_engine_get(), {"MC_POST_BACKDROP_PRE_RENDER_WALLS", MC_POST_BACKDROP_PRE_RENDER_WALLS, + std::nullopt}); +#endif graphics.isCullOffscreen = true; gfx.reset(); nlFloorGfx.reset(); @@ -1815,6 +1826,9 @@ void Backdrop::render_wall_detail(const WallDetail& detail) // blends its floor, the others draw it opaque. void Backdrop::RenderFloor(Vector renderOffset, ColorMod color) { +#ifdef ISAAC_REPENTOGON + callback_notify(lua_engine_get(), {"MC_PRE_BACKDROP_RENDER_FLOOR", MC_PRE_BACKDROP_RENDER_FLOOR, std::nullopt}, &color); +#endif KAGE::Graphics::Manager& graphics = KAGE::Graphics::manager; KAGE::Graphics::BlendMode savedBlend = graphics.blendMode; graphics.blend_set(backdropId == BACKDROP_GREED_SHOP ? KAGE::Graphics::BLEND_NORMAL : KAGE::Graphics::BLEND_OPAQUE); @@ -1961,6 +1975,9 @@ static void wall_surface_blit(KAGE::Graphics::ImageBase& surface, const SurfaceR // the wall surface's walls in the room's wall color, piece by piece around the floor. void Backdrop::RenderWalls(Vector renderOffset, ColorMod color) { +#ifdef ISAAC_REPENTOGON + callback_notify(lua_engine_get(), {"MC_PRE_BACKDROP_RENDER_WALLS", MC_PRE_BACKDROP_RENDER_WALLS, std::nullopt}, &color); +#endif KAGE::Graphics::Manager& graphics = KAGE::Graphics::manager; if (waterGfx) RenderWater(renderOffset); @@ -2172,6 +2189,9 @@ static std::span water_strips_get(int shape) // the top and bottom walls, scrolling with the frames (backward for a reversed sheet), each pushed behind the walls. void Backdrop::RenderWater(Vector renderOffset) { +#ifdef ISAAC_REPENTOGON + callback_notify(lua_engine_get(), {"MC_PRE_BACKDROP_RENDER_WATER", MC_PRE_BACKDROP_RENDER_WATER, std::nullopt}); +#endif KAGE::Graphics::Manager& graphics = KAGE::Graphics::manager; KAGE::Graphics::BlendMode savedBlend = graphics.blendMode; Room& room = *g_game->room; diff --git a/src/level/curses.cpp b/src/level/curses.cpp index c814b56..17cf1c9 100644 --- a/src/level/curses.cpp +++ b/src/level/curses.cpp @@ -6,6 +6,9 @@ #include "level/room.h" #include #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/callbacks.h" +#endif // The curses that shape the floor as it is laid out, which RemoveCurses leaves on. constexpr uint32_t FLOOR_SHAPING_CURSES = CURSE_OF_LABYRINTH | CURSE_OF_GIANT; @@ -181,5 +184,9 @@ bool Level::maze_swap_rooms(int roomIdx, int otherRoomIdx) if (grid._type == GRID_DOOR || otherGrid._type == GRID_DOOR) std::swap(grid, otherGrid); } +#ifdef ISAAC_REPENTOGON + CallbackRun run = {"PostSwapRooms", MC_POST_SWAP_ROOMS, std::nullopt}; + callback_notify(lua_engine_get(), run, GetRoomByIdx(roomIdx), GetRoomByIdx(otherRoomIdx)); +#endif return true; } diff --git a/src/level/generator.cpp b/src/level/generator.cpp index 79c1885..5b7c99b 100644 --- a/src/level/generator.cpp +++ b/src/level/generator.cpp @@ -4,6 +4,9 @@ #include #include #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/callbacks.h" +#endif // A spot a candidate room may take beside a door: its top left cell and shape. struct ShapeSpot @@ -157,6 +160,11 @@ void LevelGenerator::Generate(const GenerationSettings& settings, const LevelGen if (rooms[deadEnds[j]].distanceFromStart > rooms[deadEnds[farthest]].distanceFromStart) farthest = j; std::swap(deadEnds[i], deadEnds[farthest]); } +#ifdef ISAAC_REPENTOGON + constexpr int LAYOUT_GENERATED_PARAM = 12; + CallbackRun run = {"PostLevelLayoutGenerated", MC_POST_LEVEL_LAYOUT_GENERATED, LAYOUT_GENERATED_PARAM}; + callback_notify(lua_engine_get(), run, LuaOpaque{}); +#endif } // 009b04d0 Grows rooms breadth first from the start: each room taken from the queue offers its shuffled candidates, diff --git a/src/level/greed.cpp b/src/level/greed.cpp index 0879235..4c492ce 100644 --- a/src/level/greed.cpp +++ b/src/level/greed.cpp @@ -23,6 +23,10 @@ #include #include #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/callbacks.h" +#include "repentogon/level.h" +#endif // A room of a Greed floor's fixed layout: its cell, shape and type, and the cell and side it joins the layout through // (none for the start room). @@ -465,6 +469,11 @@ static void greedier_champion_make(Room& room, RNG& rng) // the wave (a boss room for the boss waves) by the wave's seed. Greedier makes one of them a champion. void Room::SpawnGreedModeWave() { +#ifdef ISAAC_REPENTOGON + ScopeExit post{[] { + callback_notify(lua_engine_get(), {"PostStartGreedWave", MC_POST_START_GREED_WAVE, std::nullopt}); + }}; +#endif Game& game = *g_game; int wavesBefore = game.greedModeWave; uint32_t wave = std::min((uint32_t)wavesBefore + 1, GREED_WAVE_LAST); @@ -513,6 +522,10 @@ void Room::SpawnGreedModeWave() .stageId = stageId, .type = wave < greed_boss_wave() ? ROOM_CHALLENGE : ROOM_BOSS}; RoomConfig_Room* waveRoom = game.roomConfig.GetRandomRoom(rng.Next(), WEIGHT_KEEP, query); +#ifdef ISAAC_REPENTOGON + uint32_t waveSeed = game.greedWaveSeeds[std::min(wave, GREED_WAVE_SEED_COUNT - 1)]; + waveRoom = wave_room_select(waveRoom, MC_PRE_SELECT_GREED_WAVE, waveSeed); +#endif if (!waveRoom) { @@ -712,8 +725,12 @@ constexpr ColorMod GOLD_GRID_COLOR = {{1, 1, 1, 1}, {3, 1.8f, 0, 0.8f}, {0, 0, 0 // 007ebd50 Room::SpawnGridEntityDesc: a grid entity spawned on a free cell (a flat one where nothing collides, any // other where the path is not blocked) from a saved description, replacing what stood there. -static bool room_grid_desc_spawn(Room& room, int gridIndex, const GridEntityDesc& desc) +bool room_grid_desc_spawn(Room& room, int gridIndex, const GridEntityDesc& gridDesc) { + GridEntityDesc desc = gridDesc; +#ifdef ISAAC_REPENTOGON + if (std::optional isSpawned = grid_desc_spawn_pre(room, gridIndex, desc)) return *isSpawned; +#endif if ((uint32_t)gridIndex >= ROOM_GRID_CELLS) { log_printf(LOG_ASSERT, "SpawnGridEntity: Grid index invalid\n"); diff --git a/src/level/grid/decoration.cpp b/src/level/grid/decoration.cpp index 01434a5..691444a 100644 --- a/src/level/grid/decoration.cpp +++ b/src/level/grid/decoration.cpp @@ -9,6 +9,9 @@ #include #include #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/callbacks.h" +#endif // The G FUEL seed's props: on the second and later floors, every fifth seed, and always on these stages. constexpr int GFUEL_STAGES[] = {3, 4, 11}; @@ -92,6 +95,10 @@ void GridEntity_Decoration::subclass_init() // its color under the player. void GridEntity_Decoration::Update() { +#ifdef ISAAC_REPENTOGON + GridUpdateScope scope(*this, MC_PRE_GRID_ENTITY_DECORATION_UPDATE, MC_POST_GRID_ENTITY_DECORATION_UPDATE); + if (scope.isSkipped) return; +#endif if (variant == DECORATION_HIDDEN || !sprite.isLoaded) return; diff --git a/src/level/grid/door.cpp b/src/level/grid/door.cpp index bd4ffda..8228336 100644 --- a/src/level/grid/door.cpp +++ b/src/level/grid/door.cpp @@ -9,6 +9,9 @@ #include "level/room.h" #include "engine/seeds.h" #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/callbacks.h" +#endif // The rooms a door can lead to off the map: the Downpour's mirror and the Mines' shaft. constexpr int DOOR_TARGET_MIRROR = -100; @@ -829,6 +832,10 @@ static bool is_reopen_ready(GridEntity_Door& door) // hidden room's door for the Shiny Rock. void GridEntity_Door::Update() { +#ifdef ISAAC_REPENTOGON + GridUpdateScope scope(*this, MC_PRE_GRID_ENTITY_DOOR_UPDATE, MC_POST_GRID_ENTITY_DOOR_UPDATE); + if (scope.isSkipped) return; +#endif Room& room = *g_game->room; updateCount++; if (variant == DOOR_LOCKED_KEYFAMILIAR && (g_game->gameStateFlags & (1ull << GAME_STATE_MEGA_SATAN_DOOR_OPENED))) diff --git a/src/level/grid/fire.cpp b/src/level/grid/fire.cpp index c831334..162e456 100644 --- a/src/level/grid/fire.cpp +++ b/src/level/grid/fire.cpp @@ -12,6 +12,9 @@ #include "entity/player/stats.h" #include "level/room.h" #include "engine/seeds.h" +#ifdef ISAAC_REPENTOGON +#include "repentogon/callbacks.h" +#endif // A grid fire's grid path while it stands, the odds a fresh one burns red, and its red tints. constexpr int GRID_FIRE_PATH = 1400; @@ -76,6 +79,10 @@ void GridEntity_Fire::subclass_init() // the nearest player in sight. Embers drift up from it, wavering, until their time is up. void GridEntity_Fire::Update() { +#ifdef ISAAC_REPENTOGON + GridUpdateScope scope(*this, MC_PRE_GRID_ENTITY_FIRE_UPDATE, MC_POST_GRID_ENTITY_FIRE_UPDATE); + if (scope.isSkipped) return; +#endif Game& game = *g_game; Room& room = *game.room; diff --git a/src/level/grid/gravity.cpp b/src/level/grid/gravity.cpp index 79429b5..90f28a7 100644 --- a/src/level/grid/gravity.cpp +++ b/src/level/grid/gravity.cpp @@ -4,6 +4,9 @@ #include "game/game.h" #include "level/room.h" #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/callbacks.h" +#endif // A ledge cell shows one of the dungeon's floor tiles: Rotgut's at a random frame of its Floor, the others one of // three Floor animations. @@ -45,6 +48,10 @@ void GridEntity_Gravity::PostInit() // 0099b980 The players standing in it fall, and its tile animates. void GridEntity_Gravity::Update() { +#ifdef ISAAC_REPENTOGON + GridUpdateScope scope(*this, MC_PRE_GRID_ENTITY_GRAVITY_UPDATE, MC_POST_GRID_ENTITY_GRAVITY_UPDATE); + if (scope.isSkipped) return; +#endif Room& room = *g_game->room; for (Entity_Player* player : g_game->playerManager.playerList) if (room.GetGridIndex(player->pos) == gridIndex) player->AddEntityFlags(FLAG_APPLY_GRAVITY); diff --git a/src/level/grid/grid_entity.cpp b/src/level/grid/grid_entity.cpp index a24f70a..4fb3747 100644 --- a/src/level/grid/grid_entity.cpp +++ b/src/level/grid/grid_entity.cpp @@ -37,6 +37,9 @@ #include #include #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/callbacks.h" +#endif // TNT still standing before its output trigger blows it up. constexpr int TNT_STATE_STANDING_LAST = 3; @@ -165,6 +168,9 @@ void GridEntity::Init(uint32_t seed) spawnCount++; isInitialized = true; spawnFrame = g_game->frameCount; +#ifdef ISAAC_REPENTOGON + callback_notify(lua_engine_get(), {"PostGridEntitySpawn", MC_POST_GRID_ENTITY_SPAWN, (int)type}, this); +#endif } // The entity as the room saves its cell. @@ -528,6 +534,15 @@ static void sacrifice_reward(GridEntity& spikes, Entity& victim) // What it hurts is pushed away, fire hisses, and spikes pay out a spike offer or a sacrifice. void GridEntity::hurt_func(Entity& entity, const GridHurt& hurt) { +#ifdef ISAAC_REPENTOGON + int gridType = type; + auto run = [&](int callback) { + return callback_boolean_get({"GridHurtDamage", callback, gridType}, this, &entity, hurt.playerDamage, + hurt.damageFlags, hurt.damage, hurt.isIgnoreGridCollisionClass); + }; + if (run(MC_GRID_HURT_DAMAGE)) return; + ScopeExit post{[&] { run(MC_POST_GRID_HURT_DAMAGE); }}; +#endif if (is_spared(entity, hurt)) return; EntityRef source; diff --git a/src/level/grid/lock.cpp b/src/level/grid/lock.cpp index b94dc1f..e045ae9 100644 --- a/src/level/grid/lock.cpp +++ b/src/level/grid/lock.cpp @@ -2,6 +2,9 @@ #include "entity/pickup/pickup.h" #include "game/game.h" #include "level/room.h" +#ifdef ISAAC_REPENTOGON +#include "repentogon/callbacks.h" +#endif // The grid path a standing block claims, and how near a player must come to open it. constexpr int GRID_PATH_LOCK = 4000; @@ -31,6 +34,10 @@ void GridEntity_Lock::subclass_init() // 00711950 Frees the cell once the breaking animation breaks, and lets the players near a standing block open it. void GridEntity_Lock::Update() { +#ifdef ISAAC_REPENTOGON + GridUpdateScope scope(*this, MC_PRE_GRID_ENTITY_LOCK_UPDATE, MC_POST_GRID_ENTITY_LOCK_UPDATE); + if (scope.isSkipped) return; +#endif if (sprite.animState.animData && sprite.IsEventTriggered("Break")) { collisionClass = COLLISION_NONE; diff --git a/src/level/grid/pit.cpp b/src/level/grid/pit.cpp index f32ebee..2efae50 100644 --- a/src/level/grid/pit.cpp +++ b/src/level/grid/pit.cpp @@ -10,6 +10,9 @@ #include "engine/seeds.h" #include #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/callbacks.h" +#endif // The grid path a pit claims, and a spiked bridge's. constexpr int GRID_PATH_SPIKED_BRIDGE = 999; @@ -227,6 +230,10 @@ static void lava_ember_spawn(const Vector& position) // life: the escaping mineshaft's dust, the Mines' lava embers and the Dank Depths' tar bubbles. void GridEntity_Pit::Update() { +#ifdef ISAAC_REPENTOGON + GridUpdateScope scope(*this, MC_PRE_GRID_ENTITY_PIT_UPDATE, MC_POST_GRID_ENTITY_PIT_UPDATE); + if (scope.isSkipped) return; +#endif Game& game = *g_game; Room& room = *game.room; RoomDescriptor* current = game.GetRoomByIdx(game.currentRoomIdx, game.currentDimensionIdx); diff --git a/src/level/grid/poop.cpp b/src/level/grid/poop.cpp index 3164cdd..fc7c284 100644 --- a/src/level/grid/poop.cpp +++ b/src/level/grid/poop.cpp @@ -20,6 +20,10 @@ #include #include #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/callbacks.h" +#include "repentogon/level.h" +#endif // How much of its state a hit breaks of a poop, a golden poop (50 to 124), a white poop and a giant poop, the giant // poop's state per reward, and the stages a state shows. @@ -391,6 +395,10 @@ static void hallowed_ground_update(GridEntity_Poop& poop) // grows red poop back, burns and pulses while red, walks the players over it and keeps the white poop's aura. void GridEntity_Poop::Update() { +#ifdef ISAAC_REPENTOGON + GridUpdateScope scope(*this, MC_PRE_GRID_ENTITY_POOP_UPDATE, MC_POST_GRID_ENTITY_POOP_UPDATE); + if (scope.isSkipped) return; +#endif if (is_giga(variant)) for (int part = POOP_GIGA_TOP_LEFT; part <= POOP_GIGA_BOTTOM_RIGHT; part++) { @@ -458,6 +466,16 @@ void GridEntity_Poop::Render(const Vector& offset) // stages broken, gibs now and then and, once it breaks, its effects and drops. A red poop starts growing back. // The online co-op stat of a broken poop (Player_stats_add 00425ac0) is left to the online stats. bool GridEntity_Poop::Hurt(int damage, const EntityRef& source) +{ +#ifdef ISAAC_REPENTOGON + return grid_hurt_run(*this, damage, source, state != POOP_STATE_BROKEN, &GridEntity_Poop::hurt_apply); +#else + return hurt_apply(damage, source); +#endif +} + +// The hurt itself, which REPENTOGON's MC_PRE_GRID_HURT and MC_POST_GRID_HURT surround. +bool GridEntity_Poop::hurt_apply(int damage, const EntityRef& source) { if (is_giga(variant) && variant != POOP_GIGA_BOTTOM_LEFT) { diff --git a/src/level/grid/poop.h b/src/level/grid/poop.h index 91f7066..ad398da 100644 --- a/src/level/grid/poop.h +++ b/src/level/grid/poop.h @@ -62,6 +62,7 @@ struct GridEntity_Poop : GridEntity bool Hurt(int damage, const EntityRef& source) override; WaterClipInfo GetWaterClipInfo() override; + bool hurt_apply(int damage, const EntityRef& source); void RespawnRedPoop(); Vector center_get(); GridEntity_Poop* get_giga_part(int partVariant, bool isCreate); diff --git a/src/level/grid/pressure_plate.cpp b/src/level/grid/pressure_plate.cpp index 37e2340..3458727 100644 --- a/src/level/grid/pressure_plate.cpp +++ b/src/level/grid/pressure_plate.cpp @@ -16,6 +16,9 @@ #include #include #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/callbacks.h" +#endif // Who presses a plate, and how close: the entities a query finds around it, within reach of its center. constexpr float PLATE_QUERY_RADIUS = 60; @@ -187,6 +190,10 @@ void GridEntity_PressurePlate::subclass_init() // 00983330 Animates the plate, runs Greed's button or the press, and claims the cell's path while unpressed. void GridEntity_PressurePlate::Update() { +#ifdef ISAAC_REPENTOGON + GridUpdateScope scope(*this, MC_PRE_GRID_ENTITY_PRESSUREPLATE_UPDATE, MC_POST_GRID_ENTITY_PRESSUREPLATE_UPDATE); + if (scope.isSkipped) return; +#endif sprite.Update(); if (variant == PLATE_GREED) update_greed_button(); else update_press(); diff --git a/src/level/grid/rock.cpp b/src/level/grid/rock.cpp index d3ee084..8fce67a 100644 --- a/src/level/grid/rock.cpp +++ b/src/level/grid/rock.cpp @@ -22,6 +22,9 @@ #include #include #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/callbacks.h" +#endif // A big rock's last frame. constexpr int BIG_ROCK_LAST_FRAME = 7; @@ -501,6 +504,10 @@ static void rock_spider_release(GridEntity_Rock& rock, Entity_Player& owner) // spiked rock until a plate or the Flat File retracts its spikes. void GridEntity_Rock::Update() { +#ifdef ISAAC_REPENTOGON + GridUpdateScope scope(*this, MC_PRE_GRID_ENTITY_ROCK_UPDATE, MC_POST_GRID_ENTITY_ROCK_UPDATE); + if (scope.isSkipped) return; +#endif Room& room = *g_game->room; bool isGlinting = type == GRID_ROCKT || type == GRID_ROCK_SS; if (!isGlinting) @@ -612,6 +619,17 @@ void GridEntity_Rock::RenderTop(const Vector& offset) // rocks around it fall apart, and it leaves its drops and maybe a ladder. // The original reads the rock's cell after a ladder may have replaced it. Here the cell is kept from before. bool GridEntity_Rock::Destroy(bool isImmediate, const EntityRef& source) +{ + bool isDestroyed = destroy_apply(isImmediate, source); +#ifdef ISAAC_REPENTOGON + CallbackRun run = {"PostGridRockDestroy", MC_POST_GRID_ROCK_DESTROY, (int)type}; + if (isDestroyed) callback_notify(lua_engine_get(), run, this, (int)type, isImmediate, &source); +#endif + return isDestroyed; +} + +// The break itself, which REPENTOGON's MC_POST_GRID_ROCK_DESTROY follows. +bool GridEntity_Rock::destroy_apply(bool isImmediate, const EntityRef& source) { Vector position = Position(); if (state == ROCK_STATE_STANDING) diff --git a/src/level/grid/rock.h b/src/level/grid/rock.h index 821c75b..4cec111 100644 --- a/src/level/grid/rock.h +++ b/src/level/grid/rock.h @@ -66,6 +66,7 @@ struct GridEntity_Rock : GridEntity bool Destroy(bool isImmediate, const EntityRef& source) override; WaterClipInfo GetWaterClipInfo() override; + bool destroy_apply(bool isImmediate, const EntityRef& source); void update_collision(); void RenderTop(const Vector& position); void SetBigRockFrame(int frame); diff --git a/src/level/grid/spikes.cpp b/src/level/grid/spikes.cpp index 0ce3f90..05434c8 100644 --- a/src/level/grid/spikes.cpp +++ b/src/level/grid/spikes.cpp @@ -7,6 +7,9 @@ #include #include #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/callbacks.h" +#endif // The grid path spikes claim standing and lowered, and the countdowns of timed spikes (per variant step, and between // switches). @@ -116,6 +119,10 @@ void GridEntity_Spikes::subclass_init() // spike), switches timed spikes every 60 frames with their animation five frames ahead, and lowers kept-down spikes. void GridEntity_Spikes::Update() { +#ifdef ISAAC_REPENTOGON + GridUpdateScope scope(*this, MC_PRE_GRID_ENTITY_SPIKES_UPDATE, MC_POST_GRID_ENTITY_SPIKES_UPDATE); + if (scope.isSkipped) return; +#endif if (state != 0) path_set(GRID_PATH_SPIKES_DOWN); else { diff --git a/src/level/grid/stairs.cpp b/src/level/grid/stairs.cpp index 3a1518f..7faceed 100644 --- a/src/level/grid/stairs.cpp +++ b/src/level/grid/stairs.cpp @@ -8,6 +8,9 @@ #include "level/room_transition.h" #include #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/callbacks.h" +#endif constexpr std::string_view STAIRS_ANIM_CLOSED = "Closed"; constexpr std::string_view STAIRS_ANIM_OPENING = "Open Animation"; @@ -38,6 +41,10 @@ void GridEntity_Stairs::subclass_init() // onto the open stairs goes down, the way back kept: the room and the stairs, or from a negative room its last one. void GridEntity_Stairs::Update() { +#ifdef ISAAC_REPENTOGON + GridUpdateScope scope(*this, MC_PRE_GRID_ENTITY_STAIRCASE_UPDATE, MC_POST_GRID_ENTITY_STAIRCASE_UPDATE); + if (scope.isSkipped) return; +#endif Game& game = *g_game; Room& room = *game.room; bool isCleared = room.descriptor->flags & ROOM_DESCRIPTOR_FLAG_CLEAR; diff --git a/src/level/grid/statue.cpp b/src/level/grid/statue.cpp index b4df064..27a8ba0 100644 --- a/src/level/grid/statue.cpp +++ b/src/level/grid/statue.cpp @@ -7,6 +7,9 @@ #include "game/manager.h" #include "game/music_manager.h" #include "level/room.h" +#ifdef ISAAC_REPENTOGON +#include "repentogon/callbacks.h" +#endif // The statue kinds. constexpr int STATUE_DEVIL = 0; @@ -35,6 +38,10 @@ void GridEntity_Statue::subclass_init() // 00838520 Animates the statue, solid while it stands. void GridEntity_Statue::Update() { +#ifdef ISAAC_REPENTOGON + GridUpdateScope scope(*this, MC_PRE_GRID_ENTITY_STATUE_UPDATE, MC_POST_GRID_ENTITY_STATUE_UPDATE); + if (scope.isSkipped) return; +#endif sprite.Update(); if (state == STATUE_STATE_STANDING) collisionClass = COLLISION_SOLID; diff --git a/src/level/grid/teleporter.cpp b/src/level/grid/teleporter.cpp index 8578b53..82dd4c4 100644 --- a/src/level/grid/teleporter.cpp +++ b/src/level/grid/teleporter.cpp @@ -6,6 +6,9 @@ #include "level/room_config.h" #include #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/callbacks.h" +#endif // The pads' looks: seven variants, Gehenna's own. constexpr int TELEPORTER_VARIANT_LAST = 6; @@ -84,6 +87,10 @@ static void teleporter_use(GridEntity_Teleporter& pad, Entity_Player& player) // turned off. Else it shows on and sends a player standing on it away. The pad's cell stays out of the walkers' paths. void GridEntity_Teleporter::Update() { +#ifdef ISAAC_REPENTOGON + GridUpdateScope scope(*this, MC_PRE_GRID_ENTITY_TELEPORTER_UPDATE, MC_POST_GRID_ENTITY_TELEPORTER_UPDATE); + if (scope.isSkipped) return; +#endif if (state == TELEPORTER_STATE_ON) { if (!teleporter_player_find(*this)) state = 0; diff --git a/src/level/grid/tnt.cpp b/src/level/grid/tnt.cpp index 9e6a6ef..077237d 100644 --- a/src/level/grid/tnt.cpp +++ b/src/level/grid/tnt.cpp @@ -10,6 +10,10 @@ #include "level/room.h" #include "engine/seeds.h" #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/callbacks.h" +#include "repentogon/level.h" +#endif // The barrel's fuse once it is ready to blow, its blast, and the wood its pieces show. constexpr int TNT_FUSE = 3; @@ -66,6 +70,10 @@ void GridEntity_TNT::subclass_init() // damage, the wooden pieces and maybe a trinket. void GridEntity_TNT::Update() { +#ifdef ISAAC_REPENTOGON + GridUpdateScope scope(*this, MC_PRE_GRID_ENTITY_TNT_UPDATE, MC_POST_GRID_ENTITY_TNT_UPDATE); + if (scope.isSkipped) return; +#endif collisionClass = state > TNT_STATE_READY ? COLLISION_NONE : COLLISION_OBJECT; if (state == 0 || state == 1) return sprite.Play("Idle"); if (state == 2) return sprite.Play("IdleMedium"); @@ -92,7 +100,17 @@ void GridEntity_TNT::Update() } // 0071f250 Damages the barrel a stage or more, one time in three a stage more. -bool GridEntity_TNT::Hurt(int damage, const EntityRef&) +bool GridEntity_TNT::Hurt(int damage, const EntityRef& source) +{ +#ifdef ISAAC_REPENTOGON + return grid_hurt_run(*this, damage, source, state < TNT_STATE_BLOWN, &GridEntity_TNT::hurt_apply); +#else + return hurt_apply(damage, source); +#endif +} + +// The hurt itself, which REPENTOGON's MC_PRE_GRID_HURT and MC_POST_GRID_HURT surround. +bool GridEntity_TNT::hurt_apply(int damage, const EntityRef&) { int stages = Random() % 3 == 0 ? std::min(damage + 1, TNT_STATE_BLOWN) : damage; if (stages < 1 || state > TNT_STATE_READY) return false; @@ -102,8 +120,11 @@ bool GridEntity_TNT::Hurt(int damage, const EntityRef&) } // 0071f2b0 Blows the barrel at once into its pieces, without a blast. Not at once, it is hurt as by a bomb. -bool GridEntity_TNT::Destroy(bool isImmediate, const EntityRef&) +bool GridEntity_TNT::Destroy(bool isImmediate, const EntityRef& source) { +#ifdef ISAAC_REPENTOGON + if (!isImmediate) return Hurt(4, source); +#endif if (!isImmediate) return Hurt(4, EntityRef()); if (state > TNT_STATE_READY) return false; diff --git a/src/level/grid/tnt.h b/src/level/grid/tnt.h index d8a53bb..91bfef8 100644 --- a/src/level/grid/tnt.h +++ b/src/level/grid/tnt.h @@ -19,4 +19,6 @@ struct GridEntity_TNT : GridEntity void Update() override; bool Hurt(int damage, const EntityRef& source) override; bool Destroy(bool isImmediate, const EntityRef& source) override; + + bool hurt_apply(int damage, const EntityRef& source); }; diff --git a/src/level/grid/trap_door.cpp b/src/level/grid/trap_door.cpp index 9d30d3d..721b822 100644 --- a/src/level/grid/trap_door.cpp +++ b/src/level/grid/trap_door.cpp @@ -15,6 +15,9 @@ #include "level/stage_transition.h" #include #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/callbacks.h" +#endif constexpr const char* TRAPDOOR_ANM2 = "gfx/grid/Door_11_TrapDoor.anm2"; constexpr const char* VOID_ANM2 = "gfx/grid/VoidTrapdoor.anm2"; @@ -316,6 +319,10 @@ static void void_portal_ripple(GridEntity_TrapDoor& trapDoor) // The original also opened it for a netplay boss room's late joiners, which the offline game never has. void GridEntity_TrapDoor::Update() { +#ifdef ISAAC_REPENTOGON + GridUpdateScope scope(*this, MC_PRE_GRID_ENTITY_TRAPDOOR_UPDATE, MC_POST_GRID_ENTITY_TRAPDOOR_UPDATE); + if (scope.isSkipped) return; +#endif Game& game = *g_game; Room& room = *game.room; Vector position = Position(); diff --git a/src/level/grid/web.cpp b/src/level/grid/web.cpp index ca3c7c3..9c087b9 100644 --- a/src/level/grid/web.cpp +++ b/src/level/grid/web.cpp @@ -3,6 +3,9 @@ #include "game/game.h" #include #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/callbacks.h" +#endif // How often a web slows the players in it, how near they must be, and how much and how long it slows them, tinted // blue. A web turns in quarter turns. @@ -38,6 +41,10 @@ void GridEntity_Web::subclass_init() // 00721780 Every fourth frame slows the walking players in a standing web (but not with Evil Charm), tinted blue. void GridEntity_Web::Update() { +#ifdef ISAAC_REPENTOGON + GridUpdateScope scope(*this, MC_PRE_GRID_ENTITY_WEB_UPDATE, MC_POST_GRID_ENTITY_WEB_UPDATE); + if (scope.isSkipped) return; +#endif if (state == WEB_STATE_STANDING && g_game->frameCount % WEB_CHECK_FRAMES == 0) { Vector position = Position(); diff --git a/src/level/level.cpp b/src/level/level.cpp index 556fe4c..31a49c5 100644 --- a/src/level/level.cpp +++ b/src/level/level.cpp @@ -32,6 +32,12 @@ #include #include #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/callbacks.h" +#include "repentogon/items.h" +#include "repentogon/level.h" +#include "repentogon/saves.h" +#endif // Where GetEnterPosition puts the players: a crawlspace's ladder down and its ladder back up, the Black Market's // stairs, and the spots of the secret shop and the two off-map rooms between it and the Black Market. @@ -498,6 +504,9 @@ static void ascent_voiceover_start(uint32_t voiceStage) // the layout the floor calls for, then enters the start room (or the boss room on the Ascent) and starts the floor. void Level::Init(bool isResetLilPortalRoom) { +#ifdef ISAAC_REPENTOGON + callback_notify(lua_engine_get(), {"PreLevelInit", MC_PRE_LEVEL_INIT, std::nullopt}); +#endif Game& game = *g_game; bool isMyosotis = game.playerManager.AnyoneHasTrinket(TRINKET_MYOSOTIS); bool isHard = game.difficulty == DIFFICULTY_HARD; @@ -869,6 +878,9 @@ void Level::generate_dungeon(RNG& curseRng) // backdrop 1 in 5 times. bool Level::place_room(const LevelGenerator_Room& slot, RoomConfig_Room* data, uint32_t seed, RoomDescriptor** outDesc) { +#ifdef ISAAC_REPENTOGON + data = place_room_pre(slot, data, seed); +#endif if (!data) log_printf(LOG_ASSERT, "Level::place_room data is NULL!\n"); if (nbRooms >= ROOM_MAP_CELLS) { @@ -1056,12 +1068,18 @@ void Game::SaveBackwardsStage(int stage) game.backwardsStages[stage].bossRooms.clear(); game.backwardsStages[stage].treasureRooms.clear(); } +#ifdef ISAAC_REPENTOGON + backwards_rooms_post(stage, saved); +#endif } // 007466d0 Moves to a stage and type (clamped to the game's), recording the stage left for the Ascent, the stage for // the nightmare scenes, and Boss Rush's par time (longer on the alternate path's first six stages). void Level::SetStage(int stageId, int alt) { +#ifdef ISAAC_REPENTOGON + level_select_pre(stageId, alt); +#endif uint32_t newStage = (uint32_t)std::clamp(stageId, 0, (int)STAGE_HOME); uint32_t newType = (uint32_t)std::clamp(alt, 0, (int)STAGETYPE_REPENTANCE_B); @@ -2382,15 +2400,27 @@ bool Level::IsStageWithinEnd(int levelStage, bool isAltPath) return params.pathType != PATH_TYPE_HOME && levelStage <= endStage; } +static float planetarium_chance_get(Level& level); + // 0074dbd0 The chance the floor has a planetarium: none past Sheol, past the Depths without Telescope Lens or past the // Womb without a golden one or Mom's Box. Before the first planetarium it grows by a fifth per treasure room skipped // (sure with Crystal Ball), with Magic 8 Ball, Crystal Ball, Sausage and the Lens adding to it. After, only the Lens -// does. Kept between 0.01 and 1. Lua's Game:GetPlanetariumChance. +// does. Kept between 0.01 and 1. Lua's Game:GetPlanetariumChance. REPENTOGON's mods may reshape it. float Level::GetPlanetariumChance() +{ +#ifdef ISAAC_REPENTOGON + return planetarium_chance_hook(*this, planetarium_chance_get(*this)); +#else + return planetarium_chance_get(*this); +#endif +} + +// GetPlanetariumChance's own code. +static float planetarium_chance_get(Level& level) { Game& game = *g_game; PlayerManager& players = game.playerManager; - int effectiveStage = (int)stage + (IsAltPath() ? 1 : 0); + int effectiveStage = level.stage + (level.IsAltPath() ? 1 : 0); Entity_Player* lensOwner = players.FirstTrinketOwner(TRINKET_TELESCOPE_LENS); bool isLens = lensOwner && lensOwner->HasTrinket(TRINKET_TELESCOPE_LENS); bool isGoldenLens = lensOwner && lensOwner->HasGoldenTrinket(TRINKET_TELESCOPE_LENS); @@ -2400,8 +2430,8 @@ float Level::GetPlanetariumChance() }; float chance = PLANETARIUM_CHANCE_MIN; - if (stage > STAGE_SHEOL || (stage > STAGE_DEPTHS_II && !isLens) || - (stage > STAGE_WOMB_II && !isGoldenLens && !isMomsBox)) + if (level.stage > STAGE_SHEOL || (level.stage > STAGE_DEPTHS_II && !isLens) || + (level.stage > STAGE_WOMB_II && !isGoldenLens && !isMomsBox)) return 0; if (game.planetariumsVisited == 0) { @@ -3123,6 +3153,9 @@ static bool backwards_boss_rooms_place(Level& level, LevelGenerator& generator, generator.block_unused_door_cells(*room, config->doors); level.lastBossRoomListIdx = level.nbRooms - 1; previous = room->generationIndex; +#ifdef ISAAC_REPENTOGON + backwards_room_restore_post(saved, desc, "boss", (int)(&bossRoom - saved.bossRooms.data())); +#endif } return true; } @@ -3154,6 +3187,10 @@ bool Level::place_rooms_backwards(LevelGenerator& generator, BackwardsStageDesc& if (!room) return false; place_room(*room, config, generationRNG.Next(), nullptr); backwards_room_restore(roomList[nbRooms - 1], treasure.desc); +#ifdef ISAAC_REPENTOGON + int treasureIndex = (int)(&treasure - saved.treasureRooms.data()); + backwards_room_restore_post(saved, roomList[nbRooms - 1], "treasure", treasureIndex); +#endif } for (LevelGenerator_Room* room : generator.get_all_rooms()) { @@ -3853,8 +3890,12 @@ int Level::GetRandomRoomIndex(bool isErrorRoom, uint32_t seed) if (desc.dimension == currentDimensionIdx && (desc.group == -1 || desc.group == current.group)) candidates.push_back(cell); } - if (candidates.empty()) return currentRoomIdx; - return candidates[rng.Next() % candidates.size()]; + int index = candidates.empty() ? currentRoomIdx : candidates[rng.Next() % candidates.size()]; +#ifdef ISAAC_REPENTOGON + CallbackRun run = {"PreGetRandomRoomIndex", MC_PRE_GET_RANDOM_ROOM_INDEX, std::nullopt}; + index = callback_integer_run(lua_engine_get(), run, index, index, isErrorRoom, seed); +#endif + return index; } // 00740a60 The safe grid index of a room not cleared yet in the current dimension and room group, the first plain one diff --git a/src/level/minimap.cpp b/src/level/minimap.cpp index 92024c8..5b42ca5 100644 --- a/src/level/minimap.cpp +++ b/src/level/minimap.cpp @@ -14,6 +14,9 @@ #include #include #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/callbacks.h" +#endif constexpr const char* SMALL_MAP_ANM2 = "gfx/ui/minimap1.anm2"; constexpr const char* LARGE_MAP_ANM2 = "gfx/ui/minimap2.anm2"; @@ -755,6 +758,10 @@ void Minimap::Refresh() // Netplay is offline, so every player reads its own controller. void Minimap::Update() { +#ifdef ISAAC_REPENTOGON + unfiltered_notify("PreMinimapUpdate", MC_PRE_MINIMAP_UPDATE); + ScopeExit post{[] { unfiltered_notify("PostMinimapUpdate", MC_POST_MINIMAP_UPDATE); }}; +#endif std::vector& players = g_game->playerManager.playerList; if (players.empty()) KAGE_LogMessage(LOG_ASSERT, (uint8_t*)NO_PLAYERS); @@ -837,6 +844,10 @@ Vector Minimap::GetDisplayedSize() // only the time and score, and only in a daily run. void Minimap::Render() { +#ifdef ISAAC_REPENTOGON + unfiltered_notify("PreMinimapRender", MC_PRE_MINIMAP_RENDER); + ScopeExit post{[] { unfiltered_notify("PostMinimapRender", MC_POST_MINIMAP_RENDER); }}; +#endif Game& game = *g_game; if (!game.hud.isVisible || game.seedEffects.HasSeedEffect(SEED_NO_HUD)) return; diff --git a/src/level/room.cpp b/src/level/room.cpp index f74b15a..7855d83 100644 --- a/src/level/room.cpp +++ b/src/level/room.cpp @@ -35,6 +35,11 @@ extern "C" { #include "lua.h" } +#ifdef ISAAC_REPENTOGON +#include "repentogon/callbacks.h" +#include "repentogon/items.h" +#include "repentogon/level.h" +#endif // REPENTOGON's LRoomTileDesc table at 00c35b80, by shape. constexpr LRoomTileDesc SHAPE_TILES[ROOMSHAPE_ANY] = { @@ -396,6 +401,9 @@ static void boss_fireplaces_bind(Room& room, bool isHeretic) // flags say, decorates a first visit, and sets the camera on it. void Room::Init(RoomConfig_Room& config, RoomDescriptor& roomDescriptor) { +#ifdef ISAAC_REPENTOGON + callback_notify(lua_engine_get(), {"PreNewRoom", MC_PRE_NEW_ROOM, std::nullopt}, this, &roomDescriptor); +#endif temporaryEffects.ClearEffects(false); killedNpcs.clear(); for (int group = 0; group < OUTPUT_GROUP_COUNT; group++) @@ -946,6 +954,10 @@ void Room::init_dungeon_rock() // others. False when it is not or the type has no grid entity. bool Room::SpawnGridEntity(int gridIndex, GridEntityType type, int variant, uint32_t seed, int varData) { +#ifdef ISAAC_REPENTOGON + std::optional isSpawned = grid_spawn_pre(*this, gridIndex, type, variant, seed, varData); + if (isSpawned) return *isSpawned; +#endif if (gridIndex < 0 || gridIndex >= ROOM_GRID_CELLS) KAGE_LogMessage(LOG_ASSERT, (uint8_t*)"SpawnGridEntity: Grid index invalid\n"); if ((uint32_t)gridIndex >= ROOM_GRID_CELLS) return false; @@ -1915,6 +1927,11 @@ float Room::time_scale_update() // Pause lets every enemy and effect (and the players, in versus mode) move again. void Room::TriggerEffectRemoved(ItemConfig_Item* item) { +#ifdef ISAAC_REPENTOGON + ScopeExit post{[item] { + item_callback_notify("PostRoomTriggerEffectRemoved", MC_POST_ROOM_TRIGGER_EFFECT_REMOVED, item, item); + }}; +#endif if (item->type != ITEM_PASSIVE && item->type != ITEM_ACTIVE && item->type != ITEM_FAMILIAR) return; if (item->id == COLLECTIBLE_HOURGLASS || item->id == COLLECTIBLE_ASTRAL_PROJECTION) @@ -2140,7 +2157,8 @@ static int deal_stage_get() // 007f92b0 The chance the floor's last boss room opens a deal door: a base chance raised by the deal items and // trinkets, the Satanic Bible's wisps, a bum killed and a shopkeeper killed, more without red heart damage on the // floor (or in its boss room) unless Act of Contrition forgives it, cut after a recent deal. None once disabled, -// certain with Goat Head, Eucharist, Greed's later waves and the surprise miniboss daily. +// certain with Goat Head, Eucharist, Greed's later waves and the surprise miniboss daily. REPENTOGON's mods may reshape +// it. float Room::GetDevilRoomChance() { Game& game = *g_game; @@ -2190,6 +2208,9 @@ float Room::GetDevilRoomChance() if (is_owned(COLLECTIBLE_EUCHARIST)) chance = 1; uint32_t greedDealWave = GREED_DEAL_WAVE + (game.difficulty == DIFFICULTY_GREEDIER ? 1 : 0); if (is_greed()) chance = (uint32_t)game.greedModeWave < greedDealWave ? 0 : 1; +#ifdef ISAAC_REPENTOGON + chance = devil_chance_hook(*this, chance); +#endif return chance; } static bool is_narrow_room(Room& room) diff --git a/src/level/room.h b/src/level/room.h index 6ae2b3c..d647999 100644 --- a/src/level/room.h +++ b/src/level/room.h @@ -428,3 +428,4 @@ public: int room_shape_get_door_grid_index(int doorSlot, int width, int height, int shape); Vector random_position_away_from_players(Vector center, float clearance); bool is_npc_type(int type); +bool room_grid_desc_spawn(Room& room, int gridIndex, const GridEntityDesc& desc); diff --git a/src/level/room_clear.cpp b/src/level/room_clear.cpp index 0fbfb91..9f2e5a3 100644 --- a/src/level/room_clear.cpp +++ b/src/level/room_clear.cpp @@ -30,6 +30,13 @@ #include #include #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/callbacks.h" +#include "repentogon/player.h" +#ifdef ISAAC_REPENTOGON +#include "repentogon/npc.h" +#endif +#endif constexpr int COLLECTIBLE_GUPPYS_TAIL = 134; constexpr int COLLECTIBLE_CONTRACT_FROM_BELOW = 241; @@ -746,6 +753,9 @@ static void boss_items_spawn(Room& room, ClearAward& award) int specialItem = 0; int specialTrinket = 0; bool isSpecial = special_award_pick(room, award.rng, specialItem, specialTrinket); +#ifdef ISAAC_REPENTOGON + isSpecial = boss_thematic_item_get(isSpecial, specialItem, specialTrinket); +#endif float row = award.reward.y + AWARD_ITEM_DROP; Vector center = vector_make(award.reward.x, award.itemRow); Vector left = vector_make(award.reward.x - AWARD_ITEM_SPACING, row); @@ -1206,6 +1216,7 @@ static void void_award_spawn(Room& room, ClearAward& award, bool isContinuing) // Mega Satan: the kill counts and marks. Unless the challenge is to beat him, the run ends at once with his ending, or // where it goes on to the Void a big chest and a Void portal come. A Mega Satan challenge's end leaves a trophy. +// A mod may hold the ending off. static void mega_satan_award_spawn(Room& room, ClearAward& award, bool isContinuing) { Game& game = *g_game; @@ -1213,7 +1224,10 @@ static void mega_satan_award_spawn(Room& room, ClearAward& award, bool isContinu g_manager->persistentGameData.AddBoss(BOSS_MEGA_SATAN); PlayerManager::unlock_completion_mark(COMPLETION_MEGA_SATAN); if (game.GetChallengeParams().isMegaSatan) return (void)final_chest_spawn(room, award, false); - if (!isContinuing || !is_void_reachable()) return game_end(ENDING_MEGA_SATAN); +#ifdef ISAAC_REPENTOGON + if (!boolean_run({"PreMegaSatanEnding", MC_PRE_MEGA_SATAN_ENDING, std::nullopt}, false)) +#endif + if (!isContinuing || !is_void_reachable()) return game_end(ENDING_MEGA_SATAN); g_manager->achievementOverlay.isPopupBlocked = true; game.Spawn({.position = award.reward, .type = ENTITY_PICKUP, .variant = PICKUP_BIGCHEST, .seed = award.rng.Next()}); @@ -1442,6 +1456,10 @@ static void shovel_quest_check(Room& room) // spawns the award (unless the room gives none), revives Greed's co-op ghosts and saves the rewind state. void room_clear_trigger(Room& room, ClearSound sound) { +#ifdef ISAAC_REPENTOGON + bool isSilent = sound == CLEAR_SOUND_SILENT; + callback_notify(lua_engine_get(), {"PreRoomTriggerClear", MC_PRE_ROOM_TRIGGER_CLEAR, std::nullopt}, isSilent); +#endif Game& game = *g_game; RoomDescriptor& descriptor = *room.descriptor; descriptor.flags |= ROOM_DESCRIPTOR_FLAG_CLEAR; @@ -1486,6 +1504,9 @@ void room_clear_trigger(Room& room, ClearSound sound) game.playerManager.IsCoopPlay()) game.playerManager.revive_player_ghosts(); game.save_rewind_state(-1); +#ifdef ISAAC_REPENTOGON + callback_notify(lua_engine_get(), {"PostRoomTriggerClear", MC_POST_ROOM_TRIGGER_CLEAR, std::nullopt}, isSilent); +#endif } // 009bb840 Every player's room clear effects, then every familiar's in the room. The familiars are gathered first, @@ -1716,6 +1737,10 @@ static void crystal_key_door_open(Entity_Player& player) // Azazel's Stump, and the wisps waiting for a clear. void Entity_Player::TriggerRoomClear() { +#ifdef ISAAC_REPENTOGON + if (player_room_clear_is_cancelled(*this)) return; + ScopeExit clearPost = {[this] { player_room_clear_post(*this); }}; +#endif if (!HasTrinket(TRINKET_OLD_CAPACITOR) && !HasCollectible(COLLECTIBLE_4_5_VOLT)) for (int slot = 0; slot < ACTIVE_SLOT_COUNT; slot++) active_clear_charge(*this, slot); if (HasTrinket(TRINKET_ISAACS_FORK)) isaacs_fork_heal(*this); diff --git a/src/level/room_lighting.cpp b/src/level/room_lighting.cpp index 48b4185..287100d 100644 --- a/src/level/room_lighting.cpp +++ b/src/level/room_lighting.cpp @@ -16,6 +16,9 @@ #include "engine/seeds.h" #include #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/render.h" +#endif // The flicker of entity lights: its RNG's shifts, the seed it takes for a zero one, and RandomVector's angle. constexpr uint32_t FLICKER_SHIFTS[] = {5, 27, 25}; @@ -936,6 +939,9 @@ static void npc_light_render(LightPass& pass) // the cart's null. void entity_light_render(Room& room, Entity& entity, Vector offset) { +#ifdef ISAAC_REPENTOGON + if (!entity_light_render_pre(entity, offset)) return; +#endif uint32_t seed = (uint32_t)g_game->frameCount + entity.initSeed; LightPass pass = {room, entity, diff --git a/src/level/room_render.cpp b/src/level/room_render.cpp index 212788e..a0728b6 100644 --- a/src/level/room_render.cpp +++ b/src/level/room_render.cpp @@ -21,6 +21,10 @@ #include #include #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/callbacks.h" +#include "repentogon/render.h" +#endif // The debug grid views: half a cell's outline on screen, where a cell's text starts, and their faint yellow. constexpr float DEBUG_CELL_HALF = 13; @@ -440,7 +444,12 @@ static bool is_grid_type(const GridEntity* grid, GridEntityType type) template static void grids_render(Room& room, Vector offset, Filter isDrawn) { for (int i = 0; i < room.gridWidth * room.gridHeight; i++) - if (room.gridEntities[i] && isDrawn(*room.gridEntities[i])) room.gridEntities[i]->Render(offset); + if (room.gridEntities[i] && isDrawn(*room.gridEntities[i])) +#ifdef ISAAC_REPENTOGON + grid_entity_render(*room.gridEntities[i], offset); +#else + room.gridEntities[i]->Render(offset); +#endif } // Pits, trapdoors, stairs and destroyed poop: the grid entities flat on the floor, drawn with the walls. @@ -742,7 +751,11 @@ static void mines_pits_render(Room& room, Vector offset) if (!is_grid_type(pit, GRID_PIT)) continue; pit->sprite.GetLayer(0)->isVisible = false; +#ifdef ISAAC_REPENTOGON + grid_entity_render(*pit, offset); +#else pit->Render(offset); +#endif pit->sprite.GetLayer(0)->isVisible = true; } } @@ -1110,6 +1123,9 @@ static void depth_render(Room& room, bool isWaterShown) } if (isWaterShown) list.renderMode = RENDER_NORMAL; list.render_up_to(UINT_MAX, scroll); +#ifdef ISAAC_REPENTOGON + callback_notify(lua_engine_get(), {"MC_POST_ROOM_RENDER_ENTITIES", MC_POST_ROOM_RENDER_ENTITIES, std::nullopt}); +#endif entities_post_render(list); list.renderMode = RENDER_NULL; } @@ -1697,6 +1713,9 @@ static void trapdoor_light_render(Room& room, GridEntity& trapdoor, Vector offse // sprite's light null. static void grid_light_render(Room& room, GridEntity& grid, Vector offset) { +#ifdef ISAAC_REPENTOGON + if (!grid_light_render_pre(grid, offset)) return; +#endif Vector position = grid.Position(); switch (grid.type) @@ -1766,6 +1785,9 @@ static KColor room_light_color(Room& room, KColor shadow) // fully dark there and light from 300 away. float Room::GetLightingAlpha() { +#ifdef ISAAC_REPENTOGON + if (std::optional alpha = lighting_alpha_hook(*this)) return *alpha; +#endif Game& game = *g_game; PlayerManager& players = game.playerManager; diff --git a/src/level/room_special.cpp b/src/level/room_special.cpp index 3c5b6c6..948d24b 100644 --- a/src/level/room_special.cpp +++ b/src/level/room_special.cpp @@ -16,6 +16,10 @@ #include #include #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/callbacks.h" +#include "repentogon/items.h" +#endif constexpr int TRINKET_KEEPERS_BARGAIN = 171; constexpr int TRINKET_ADOPTION_PAPERS = 184; @@ -357,10 +361,24 @@ static int secret_shop_price(Room& room, const ShopOffer& offer, bool isFleshDea return (int)rng.RandomInt(maxPrice - SECRET_SHOP_ITEM_MIN + 1) + SECRET_SHOP_ITEM_MIN; } +static int shop_item_price_base(Room& room, const ShopOffer& offer, Entity_Player* player); + // 008151e0 A ware's price before discounts, for the players (or one player): in shops coins by kind (an item its // config's price, an angel room's items by their devil price), in devil deals red hearts by the item's devil price, -// spikes for spike offers, and coins for Keepers. Pound of Flesh turns coin prices into hearts and spikes. +// spikes for spike offers, and coins for Keepers. Pound of Flesh turns coin prices into hearts and spikes. An integer +// from a mod's MC_GET_SHOP_ITEM_PRICE replaces it. int room_shop_item_price(Room& room, const ShopOffer& offer, Entity_Player* player) +{ + int price = shop_item_price_base(room, offer, player); +#ifdef ISAAC_REPENTOGON + CallbackRun run = {"GetShopItemPrice", MC_GET_SHOP_ITEM_PRICE, offer.variant}; + price = callback_integer_run(lua_engine_get(), run, price, offer.variant, offer.subType, offer.shopItemId, price); +#endif + return price; +} + +// room_shop_item_price's own code. +static int shop_item_price_base(Room& room, const ShopOffer& offer, Entity_Player* player) { PlayerManager& players = g_game->playerManager; uint32_t seed = (uint32_t)(offer.subType + offer.variant) | (room.descriptor->decorationSeed & PRICE_SEED_MASK); @@ -577,9 +595,14 @@ void room_restock_trigger(Room& room, int gridIndex, int shopItemId) } // 008158a0 Restocks every queued shop slot with a new ware in a poof, each slot's restock raising its price, the -// spawns seeded from the room's spawn seed. Only shops restock. +// spawns seeded from the room's spawn seed. Only shops restock. Mods' MC_PRE_RESTOCK_SHOP may cancel it, and +// MC_POST_RESTOCK_SHOP follows. void room_restock_partial(Room& room) { +#ifdef ISAAC_REPENTOGON + if (!shop_restock_pre(RESTOCK_PARTIAL)) return; + ScopeExit post{[] { shop_restock_post(RESTOCK_PARTIAL); }}; +#endif if (room.roomType != ROOM_SHOP) { log_printf(LOG_INFO, "[warn] restock disabled for room type %d.\n", room.roomType); diff --git a/src/level/room_state.cpp b/src/level/room_state.cpp index 16799d4..02b432f 100644 --- a/src/level/room_state.cpp +++ b/src/level/room_state.cpp @@ -16,6 +16,10 @@ #include #include #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/callbacks.h" +#include "repentogon/saves.h" +#endif // The last frames of a clear's delay that leaving the room still counts the clear in. constexpr int ROOM_CLEAR_DELAY_PENDING = 8; @@ -146,12 +150,21 @@ static bool effect_state_save(Entity_Effect& effect, EntitySaveState& state) // 007eeeb0 Saves an entity the room keeps when the players leave (Entity_Pickup::CanFlip in the dump), or refuses a // dead, persistent or unkept one: its kind, place, seeds and spawner, then what its class keeps. +// A mod may decide whether its kind is kept. bool entity_state_save(Room& room, Entity& entity, EntitySaveState& state, MinecartCheck check) { +#ifdef ISAAC_REPENTOGON + if (!is_hook_inner() && lua_engine_get().is_callback_enabled(MC_ENTITY_SAVE)) + return entity_save_hook(room, entity, state, check); +#endif if (entity.isDead || entity.HasEntityFlags(FLAG_PERSISTENT)) return false; if (entity.minecart && check == MINECART_REFUSED) return false; - if (!entity_type_is_saved(entity.type, entity.variant, (uint32_t)entity.subtype, entity.spawnerType, room.IsClear())) - return false; + bool isSaved = + entity_type_is_saved(entity.type, entity.variant, (uint32_t)entity.subtype, entity.spawnerType, room.IsClear()); +#ifdef ISAAC_REPENTOGON + isSaved = boolean_run({"ShouldSaveEntity", MC_SHOULD_SAVE_ENTITY, std::nullopt}, isSaved, &entity, room.IsClear()); +#endif + if (!isSaved) return false; state.type = entity.type; state.variant = entity.variant; @@ -356,6 +369,9 @@ void entity_state_restore(Room& room, Entity& entity, const EntitySaveState& sta // once visited, its grid cells and the entities it keeps are saved, a minecart only with its rider, saved after it. void Room::on_leave() { +#ifdef ISAAC_REPENTOGON + ScopeExit post{[this] { unfiltered_notify("PostRoomSaveState", MC_POST_ROOM_SAVE_STATE, this, descriptor); }}; +#endif Game& game = *g_game; if (shopRestockTimer > 0) @@ -431,6 +447,9 @@ void Room::RestoreState() std::vector& saved = descriptor->savedEntities; g_pickupIgnoreModifiers++; +#ifdef ISAAC_REPENTOGON + unfiltered_notify("PreRoomRestoreState", MC_PRE_ROOM_RESTORE_STATE, this, descriptor); +#endif for (size_t i = 0; i < saved.size(); i++) { const EntitySaveState& cart = saved[i]; diff --git a/src/level/room_transition.cpp b/src/level/room_transition.cpp index 5c4ff86..ca8d5c7 100644 --- a/src/level/room_transition.cpp +++ b/src/level/room_transition.cpp @@ -19,6 +19,9 @@ #include #include #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/callbacks.h" +#endif constexpr const char* VERSUS_SCREEN_ANM2 = "gfx/ui/boss/versusscreen.anm2"; constexpr const char* OLD_ROOM_SURFACE = "Old Room Surface"; @@ -631,6 +634,11 @@ void RoomTransition::landing_update() // the frame. void RoomTransition::Update() { +#ifdef ISAAC_REPENTOGON + ScopeExit post{[this] { + callback_notify(lua_engine_get(), {"PostRoomTransitionUpdate", MC_POST_ROOM_TRANSITION_UPDATE, (int)mode}); + }}; +#endif Game& game = *g_game; Entity* cart = minecart.get(); Entity_NPC* minecartNpc = cart && cart->type == ENTITY_MINECART && cart->variant == MINECART_RIDDEN @@ -703,6 +711,11 @@ static void versus_screen_render(RoomTransition& transition) // a mirror). void RoomTransition::Render() { +#ifdef ISAAC_REPENTOGON + ScopeExit post{[this] { + callback_notify(lua_engine_get(), {"MC_POST_ROOM_TRANSITION_RENDER", MC_POST_ROOM_TRANSITION_RENDER, (int)mode}); + }}; +#endif KAGE::Graphics::Manager& graphics = KAGE::Graphics::manager; Vector screen = vector_make(g_screenWidth, g_screenHeight); if (mode != TRANSITION_OUT && mode != TRANSITION_IN) return; diff --git a/src/lua/api.cpp b/src/lua/api.cpp index 53af9b9..5ef3ea7 100644 --- a/src/lua/api.cpp +++ b/src/lua/api.cpp @@ -91,14 +91,14 @@ void lua_object_push(lua_State* state, void* object, LuaClass luaClass) lua_setmetatable(state, -2); } -// (0085c590, 0085c3e0) The object argument index holds when it is of the class or one derived from it. Raises an -// argument error if not. -void* lua_object_check(lua_State* state, int index, LuaClass luaClass) +// The object index holds when it is of the class or one derived from it, else nullptr. +void* lua_object_test(lua_State* state, int index, LuaClass luaClass) { void** block = lua_type(state, index) == LUA_TUSERDATA ? (void**)lua_touserdata(state, index) : nullptr; - const char* actual = luaL_typename(state, index); + if (!block || !lua_getmetatable(state, index)) return nullptr; + lua_rawgetp(state, LUA_REGISTRYINDEX, lua_class_key(luaClass)); - if (!block || !lua_getmetatable(state, index)) lua_pushnil(state); + lua_insert(state, -2); while (!lua_isnil(state, -1)) { if (lua_rawequal(state, -1, -2)) @@ -109,8 +109,19 @@ void* lua_object_check(lua_State* state, int index, LuaClass luaClass) field_raw_get(state, -1, "__parent"); lua_remove(state, -2); } + lua_pop(state, 2); + return nullptr; +} - field_raw_get(state, -2, "__name"); +// (0085c590, 0085c3e0) The object argument index holds when it is of the class or one derived from it. Raises an +// argument error if not. +void* lua_object_check(lua_State* state, int index, LuaClass luaClass) +{ + if (void* object = lua_object_test(state, index, luaClass)) return object; + + const char* actual = luaL_typename(state, index); + lua_rawgetp(state, LUA_REGISTRYINDEX, lua_class_key(luaClass)); + field_raw_get(state, -1, "__name"); const char* expected = lua_pushfstring(state, "%s expected, got %s", lua_tostring(state, -1), actual); luaL_argerror(state, index, expected); return nullptr; diff --git a/src/lua/api.h b/src/lua/api.h index b8acf6e..182fdbc 100644 --- a/src/lua/api.h +++ b/src/lua/api.h @@ -246,6 +246,7 @@ template constexpr bool IS_LUA_STRING = std::is_same_v || std::is_same_v; void lua_object_push(lua_State* state, void* object, LuaClass luaClass); +void* lua_object_test(lua_State* state, int index, LuaClass luaClass); void* lua_object_check(lua_State* state, int index, LuaClass luaClass); void lua_class_begin(lua_State* state, const char* name, LuaClass luaClass, LuaClass parent = LUA_CLASS_COUNT); void lua_namespace_begin(lua_State* state, const char* name); diff --git a/src/lua/api_grid_entity.cpp b/src/lua/api_grid_entity.cpp index d7ec0fa..aceddbf 100644 --- a/src/lua/api_grid_entity.cpp +++ b/src/lua/api_grid_entity.cpp @@ -8,6 +8,9 @@ #include "level/grid/spikes.h" #include "level/grid/tnt.h" #include "lua/api.h" +#ifdef ISAAC_REPENTOGON +#include "repentogon/render.h" +#endif // Adds a To method casting a grid entity to a subclass, nil when it is not one. template @@ -46,7 +49,11 @@ static void grid_entity_base_register(lua_State* state) lua_method(state, "GetSaveState", [](GridEntity& grid) { return grid.desc_save(); }); lua_method(state, "Init", [](GridEntity& grid, uint32_t seed) { grid.Init(seed); }); lua_method(state, "Update", [](GridEntity& grid) { grid.Update(); }); +#ifdef ISAAC_REPENTOGON + lua_method(state, "Render", [](GridEntity& grid, Vector offset) { grid_entity_render(grid, offset); }); +#else lua_method(state, "Render", [](GridEntity& grid, Vector offset) { grid.Render(offset); }); +#endif lua_method(state, "PostInit", [](GridEntity& grid) { grid.PostInit(); }); lua_method(state, "Hurt", [](GridEntity& grid, int damage) { return grid.Hurt(damage, EntityRef()); }); lua_method(state, "HurtWithSource", diff --git a/src/lua/callback_run.h b/src/lua/callback_run.h index 504a282..791e4c0 100644 --- a/src/lua/callback_run.h +++ b/src/lua/callback_run.h @@ -4,17 +4,19 @@ #include // One run of a callback: the name its errors log, its id, and the parameter mods filter it by, nil when it has none. +// A parameter is as wide as a Lua integer, for REPENTOGON's object hashes, or a string, which replaces the first. // A REPENTOGON callback may filter by a second parameter, which runs it through _RunCallbackWithTwoParams. struct CallbackRun { const char* name; int id; - std::optional param = CALLBACK_PARAM_NONE; - std::optional secondParam; + std::optional param = CALLBACK_PARAM_NONE; + std::optional secondParam; + const char* stringParam = nullptr; }; // Pushes a filter parameter, nil when there is none. -inline void param_push(lua_State* state, std::optional param) +inline void param_push(lua_State* state, std::optional param) { if (param) lua_pushinteger(state, *param); else lua_pushnil(state); @@ -53,7 +55,8 @@ bool callback_run(LuaEngine& engine, CallbackRun run, Args... args) lua_rawgeti(state, LUA_REGISTRYINDEX, isTwoParams ? engine.runCallbackTwoParamsRef : engine.runCallbackRef); lua_pushinteger(state, run.id); - param_push(state, run.param); + if (run.stringParam) lua_pushstring(state, run.stringParam); + else param_push(state, run.param); if (isTwoParams) param_push(state, run.secondParam); (lua_push(state, args), ...); if (lua_pcall(state, sizeof...(Args) + 2 + isTwoParams, 1, 0) == LUA_OK) return true; @@ -93,7 +96,8 @@ bool callback_boolean_run(LuaEngine& engine, CallbackRun run, bool fallback, Arg return result; } -// Runs a Pre*Collision callback for an entity and what it hits, and reads its result as true, false or nothing. +// Runs a Pre*Collision callback for an entity and what it hits, and reads its result as true, false or nothing, +// which the engine keeps for REPENTOGON's collision callbacks. template LuaResult collision_run(LuaEngine& engine, CallbackRun run, T* entity, Entity* collider, bool isLow) { @@ -103,6 +107,7 @@ LuaResult collision_run(LuaEngine& engine, CallbackRun run, T* entity, Entity* c : lua_toboolean(engine.state, -1) ? LUA_RESULT_TRUE : LUA_RESULT_FALSE; lua_pop(engine.state, 1); + engine.collisionResult = result; return result; } @@ -115,14 +120,31 @@ inline void field_read(lua_State* state, const char* key, bool& value) } // Sets value to an element of the table on top of the stack, when the element is not nil. Whether it was not. -// The original aborts on an element that is not an integer. This keeps the value instead. +// The original aborts on an element that is not of the value's type (an integer, number, boolean or string). This keeps +// the value instead. template bool element_read(lua_State* state, int key, T& value) { - int isInteger = 0; + int isOfType = 0; bool isSet = lua_geti(state, -1, key) != LUA_TNIL; - lua_Integer element = lua_tointegerx(state, -1, &isInteger); - if (isInteger) value = (T)element; + if constexpr (std::is_same_v) + { + if (lua_isboolean(state, -1)) value = lua_toboolean(state, -1); + } + else if constexpr (std::is_floating_point_v) + { + lua_Number element = lua_tonumberx(state, -1, &isOfType); + if (isOfType) value = (T)element; + } + else if constexpr (std::is_same_v) + { + if (lua_type(state, -1) == LUA_TSTRING) value = lua_tostring(state, -1); + } + else + { + lua_Integer element = lua_tointegerx(state, -1, &isOfType); + if (isOfType) value = (T)element; + } lua_pop(state, 1); return isSet; } diff --git a/src/lua/callbacks.cpp b/src/lua/callbacks.cpp index a223e5e..4fe06ea 100644 --- a/src/lua/callbacks.cpp +++ b/src/lua/callbacks.cpp @@ -12,61 +12,97 @@ #include "entity/weapon/tear.h" #include "game/game.h" #include "level/room_config.h" +#include "game/manager.h" +#ifdef ISAAC_REPENTOGON +#include "repentogon/callbacks.h" +#endif constexpr int PILL_EFFECT_UNCHANGED = -1; -// 00862250 Runs MC_PRE_BOMB_COLLISION, filtered by the bomb's variant. +// 00862250 Runs MC_PRE_BOMB_COLLISION, filtered by the bomb's variant. Without vanilla parity REPENTOGON runs +// it around the bomb's collision instead. LuaResult LuaEngine::PreBombCollision(Entity_Bomb* bomb, Entity* collider, bool isLow) { +#ifdef ISAAC_REPENTOGON + if (!repentogonOptions.isVanillaParity) return LUA_RESULT_NIL; +#endif 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. +// 008610d0 Runs MC_PRE_FAMILIAR_COLLISION, filtered by the familiar's variant. Without vanilla parity REPENTOGON runs +// it around the familiar's collision instead. LuaResult LuaEngine::PreFamiliarCollision(Entity_Familiar* familiar, Entity* collider, bool isLow) { +#ifdef ISAAC_REPENTOGON + if (!repentogonOptions.isVanillaParity) return LUA_RESULT_NIL; +#endif 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. +// 00861c40 Runs MC_PRE_KNIFE_COLLISION, filtered by the knife's subtype. Without vanilla parity REPENTOGON runs +// it around the knife's collision instead. LuaResult LuaEngine::PreKnifeCollision(Entity_Knife* knife, Entity* collider, bool isLow) { +#ifdef ISAAC_REPENTOGON + if (!repentogonOptions.isVanillaParity) return LUA_RESULT_NIL; +#endif 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. +// 00860d70 Runs MC_PRE_NPC_COLLISION, filtered by the NPC's type. Without vanilla parity REPENTOGON runs +// it around the NPC's collision instead. LuaResult LuaEngine::PreNPCCollision(Entity_NPC* npc, Entity* collider, bool isLow) { +#ifdef ISAAC_REPENTOGON + if (!repentogonOptions.isVanillaParity) return LUA_RESULT_NIL; +#endif 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. +// 008631b0 Runs MC_PRE_PICKUP_COLLISION, filtered by the pickup's variant. Without vanilla parity REPENTOGON runs it +// around the pickup's collision instead. LuaResult LuaEngine::PrePickupCollision(Entity_Pickup* pickup, Entity* collider, bool isLow) { +#ifdef ISAAC_REPENTOGON + if (!repentogonOptions.isVanillaParity) return LUA_RESULT_NIL; +#endif 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. +// 00864300 Runs MC_PRE_PLAYER_COLLISION, filtered by the player's variant. Without vanilla parity REPENTOGON runs it +// around the player's collision instead. LuaResult LuaEngine::PrePlayerCollide(Entity_Player* player, Entity* collider, bool isLow) { +#ifdef ISAAC_REPENTOGON + if (!repentogonOptions.isVanillaParity) return LUA_RESULT_NIL; +#endif 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. +// 00862760 Runs MC_PRE_PROJECTILE_COLLISION, filtered by the projectile's variant. Without vanilla parity REPENTOGON +// runs it around the projectile's collision instead. LuaResult LuaEngine::PreProjectileCollision(Entity_Projectile* projectile, Entity* collider, bool isLow) { +#ifdef ISAAC_REPENTOGON + if (!repentogonOptions.isVanillaParity) return LUA_RESULT_NIL; +#endif 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. +// 00862d70 Runs MC_PRE_TEAR_COLLISION, filtered by the tear's variant. Without vanilla parity REPENTOGON runs +// it around the tear's collision instead. LuaResult LuaEngine::PreTearCollision(Entity_Tear* tear, Entity* collider, bool isLow) { +#ifdef ISAAC_REPENTOGON + if (!repentogonOptions.isVanillaParity) return LUA_RESULT_NIL; +#endif CallbackRun run = {"PreTearCollision", MC_PRE_TEAR_COLLISION, (int)tear->variant}; return collision_run(*this, run, tear, collider, isLow); } @@ -85,9 +121,13 @@ 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. +// 00865ad0 Runs MC_GET_PILL_EFFECT for the effect a pill color got. The effect a mod chose, -1 to keep it. Without +// vanilla parity REPENTOGON runs it after ItemPool::GetPillEffect instead. int LuaEngine::GetPillEffect(int pillEffect, int pillColor) { +#ifdef ISAAC_REPENTOGON + if (!repentogonOptions.isVanillaParity) return PILL_EFFECT_UNCHANGED; +#endif CallbackRun run = {"GetPillEffect", MC_GET_PILL_EFFECT}; return callback_integer_run(*this, run, PILL_EFFECT_UNCHANGED, pillEffect, pillColor); } @@ -99,11 +139,31 @@ int LuaEngine::GetTrinket(int trinket, const RNG& rng) return callback_integer_run(*this, {"GetTrinket", MC_GET_TRINKET}, 0, trinket, rng); } +// Whether the game asks mods about input: in a run, or with REPENTOGON (ASMPatchInputAction) anywhere, as +// MC_MENU_INPUT_ACTION outside a run. +bool is_input_hook_asked() +{ +#ifdef ISAAC_REPENTOGON + return g_luaEngine; +#else + return g_manager->state == MANAGER_STATE_GAME && g_luaEngine; +#endif +} + +// The callback input hooks run: MC_INPUT_ACTION, or with REPENTOGON outside a run its MC_MENU_INPUT_ACTION. +static int input_action_callback() +{ +#ifdef ISAAC_REPENTOGON + if (g_manager->state != MANAGER_STATE_GAME || !g_game) return MC_MENU_INPUT_ACTION; +#endif + return MC_INPUT_ACTION; +} + // 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}; + CallbackRun run = {"PreActionHookB", input_action_callback(), hook}; if (!callback_run(*this, run, entity, hook, action)) return std::nullopt; std::optional value; @@ -115,7 +175,7 @@ std::optional LuaEngine::InputAction(Entity* entity, int hook, int action) // 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}; + CallbackRun run = {"PreActionHookF", input_action_callback(), INPUT_HOOK_VALUE}; if (!callback_run(*this, run, entity, INPUT_HOOK_VALUE, action)) return std::nullopt; std::optional value; diff --git a/src/lua/engine.h b/src/lua/engine.h index ce90f1b..246e21b 100644 --- a/src/lua/engine.h +++ b/src/lua/engine.h @@ -148,6 +148,7 @@ struct LuaEngine std::string scriptPath; lua_State* state = nullptr; LuaMode mode = LUA_MODE_NORMAL; + LuaResult collisionResult = LUA_RESULT_NIL; int gcCooldown = 0; int gcFrame = 0; int gcLastMemory = -1; @@ -250,6 +251,7 @@ extern void* g_luaEngine; const void* lua_class_key(LuaClass luaClass); void lua_error_log(lua_State* state, const char* name); +bool is_input_hook_asked(); // The game's Lua engine, which Manager creates at startup. inline LuaEngine& lua_engine_get() diff --git a/src/repentogon/audio.cpp b/src/repentogon/audio.cpp new file mode 100644 index 0000000..22c2fd2 --- /dev/null +++ b/src/repentogon/audio.cpp @@ -0,0 +1,95 @@ +#include "repentogon/audio.h" +#include "game/music_manager.h" +#include "game/sfx_manager.h" +#include "repentogon/callbacks.h" + +constexpr int SFX_PLAY_ARGUMENTS = 6; +constexpr int MUSIC_PLAY_ARGUMENTS = 2; + +// Runs MC_PRE_SFX_PLAY and MC_POST_SFX_PLAY around SFXManager::Play, filtered by the sound. A PRE table of all six +// arguments replaces them, false keeps the sound silent and skips POST. Whether it ran Play itself. +bool sfx_play_hook(SFXManager& sfx, int soundId, SoundPlay play) +{ + LuaEngine& engine = lua_engine_get(); + if (is_hook_inner() || (!engine.is_callback_enabled(MC_PRE_SFX_PLAY) && !engine.is_callback_enabled(MC_POST_SFX_PLAY))) + return false; + + lua_State* state = engine.state; + bool isLoop = play.loop == SOUND_LOOP; + if (callback_run(engine, {"MC_PRE_SFX_PLAY", MC_PRE_SFX_PLAY, soundId}, soundId, play.volume, play.frameDelay, + isLoop, play.pitch, play.pan)) + { + if (is_result_false(state)) + { + lua_pop(state, 1); + return true; + } + bool isReplaced = lua_istable(state, -1) && lua_rawlen(state, -1) == SFX_PLAY_ARGUMENTS; + if (isReplaced) elements_pop(state, soundId, play.volume, play.frameDelay, isLoop, play.pitch, play.pan); + else lua_pop(state, 1); + play.loop = isLoop ? SOUND_LOOP : SOUND_ONCE; + } + + hook_inner_call([&] { sfx.Play(soundId, play); }); + callback_notify(engine, {"MC_POST_SFX_PLAY", MC_POST_SFX_PLAY, soundId}, soundId, play.volume, play.frameDelay, + isLoop, play.pitch, play.pan); + return true; +} + +// Runs MC_PRE_MUSIC_PLAY before a track plays or crossfades in, filtered by the track. A table of an id and a volume (or +// fade rate) replaces both, an id replaces the track (which Play then skips when it already plays), false keeps the +// music as it is. Whether the track starts. +bool music_play_pre(MusicManager& music, int& musicId, float& value, MusicStart start) +{ + LuaEngine& engine = lua_engine_get(); + lua_State* state = engine.state; + if (!callback_run(engine, {"MC_PRE_MUSIC_PLAY", MC_PRE_MUSIC_PLAY, musicId}, musicId, value, + start == MUSIC_START_CROSSFADE)) + return true; + + bool isStarted = true; + if (lua_istable(state, -1) && lua_rawlen(state, -1) == MUSIC_PLAY_ARGUMENTS) + { + elements_pop(state, musicId, value); + return true; + } + if (lua_isinteger(state, -1)) + { + musicId = (int)lua_tointeger(state, -1); + isStarted = start == MUSIC_START_CROSSFADE || music.currentMusicId != musicId; + } + else isStarted = !is_result_false(state); + lua_pop(state, 1); + return isStarted; +} + +// Runs MC_PRE_MUSIC_LAYER_TOGGLE before a layer turns on or off, filtered by the layer. An id replaces the layer, the +// boolean opposite of the toggle keeps it as it is. Whether the layer toggles. +bool music_layer_pre(int& layerId, LayerToggle toggle) +{ + LuaEngine& engine = lua_engine_get(); + lua_State* state = engine.state; + bool isOn = toggle == LAYER_TOGGLE_ON; + if (!callback_run(engine, {"MC_PRE_MUSIC_LAYER_TOGGLE", MC_PRE_MUSIC_LAYER_TOGGLE, layerId}, layerId, isOn)) + return true; + + bool isToggled = true; + if (lua_isinteger(state, -1)) layerId = (int)lua_tointeger(state, -1); + else if (lua_isboolean(state, -1)) isToggled = lua_toboolean(state, -1) == isOn; + lua_pop(state, 1); + return isToggled; +} + +// Runs MC_PRE_MUSIC_PLAY_JINGLE before a jingle plays, filtered by its track. An id replaces it, false skips it. +// Whether it plays. +bool music_jingle_pre(int& musicId) +{ + LuaEngine& engine = lua_engine_get(); + lua_State* state = engine.state; + if (!callback_run(engine, {"MC_PRE_MUSIC_PLAY_JINGLE", MC_PRE_MUSIC_PLAY_JINGLE, musicId}, musicId)) return true; + + bool isPlayed = !is_result_false(state); + if (lua_isinteger(state, -1)) musicId = (int)lua_tointeger(state, -1); + lua_pop(state, 1); + return isPlayed; +} diff --git a/src/repentogon/audio.h b/src/repentogon/audio.h new file mode 100644 index 0000000..88bd4e1 --- /dev/null +++ b/src/repentogon/audio.h @@ -0,0 +1,24 @@ +#pragma once + +class MusicManager; +class SFXManager; +struct SoundPlay; + +// How a track starts, which MC_PRE_MUSIC_PLAY passes as whether it fades in. +enum MusicStart +{ + MUSIC_START_PLAY, + MUSIC_START_CROSSFADE +}; + +// Which way a music layer turns, which MC_PRE_MUSIC_LAYER_TOGGLE passes as whether it turns on. +enum LayerToggle +{ + LAYER_TOGGLE_OFF, + LAYER_TOGGLE_ON +}; + +bool sfx_play_hook(SFXManager& sfx, int soundId, SoundPlay play); +bool music_play_pre(MusicManager& music, int& musicId, float& value, MusicStart start); +bool music_layer_pre(int& layerId, LayerToggle toggle); +bool music_jingle_pre(int& musicId); diff --git a/src/repentogon/callbacks.h b/src/repentogon/callbacks.h new file mode 100644 index 0000000..ea46f0d --- /dev/null +++ b/src/repentogon/callbacks.h @@ -0,0 +1,658 @@ +#pragma once + +#include "lua/callback_run.h" +#include "repentogon/options.h" +#include + +// REPENTOGON's callback ids (enums_ex.lua's ModCallbacks), aliases included. +enum RepentogonCallback : int +{ + MC_POST_USE_ITEM = 1003, + MC_PRE_ADD_COLLECTIBLE = 1004, + MC_POST_ADD_COLLECTIBLE = 1005, + MC_POST_TAKE_DMG = 1006, + MC_POST_ENTITY_TAKE_DMG = 1006, + MC_PRE_PLAYER_TAKE_DMG = 1008, + MC_PRE_PLAYER_ADD_HEARTS = 1009, + MC_POST_PLAYER_ADD_HEARTS = 1010, + MC_POST_GRID_ROCK_DESTROY = 1011, + MC_GRID_HURT_DAMAGE = 1012, + MC_POST_GRID_HURT_DAMAGE = 1013, + MC_PRE_ADD_TRINKET = 1014, + MC_TRY_ADD_TO_BAG_OF_CRAFTING = 1015, + MC_POST_ADD_TO_BAG_OF_CRAFTING = 1016, + MC_PRE_GRID_HURT = 1017, + MC_POST_GRID_HURT = 1018, + MC_HUD_UPDATE = 1020, + MC_HUD_POST_UPDATE = 1021, + MC_POST_HUD_UPDATE = 1021, + MC_HUD_RENDER = 1022, + MC_MAIN_MENU_RENDER = 1023, + MC_POST_HUD_RENDER = 1024, + MC_POST_FIRE_SPLIT_TEAR = 1025, + MC_PRE_UPDATE = 1026, + MC_PRE_HISTORYHUD_RENDER = 1027, + MC_POST_HISTORYHUD_RENDER = 1028, + MC_POST_HISTORYHUD_RECOMPUTE = 1029, + MC_PRE_SFX_PLAY = 1030, + MC_POST_SFX_PLAY = 1031, + MC_POST_PROJECTILE_DEATH = 1032, + MC_POST_TEAR_DEATH = 1033, + MC_PRE_MUSIC_PLAY = 1034, + MC_PRE_MUSIC_LAYER_TOGGLE = 1035, + MC_PRE_BRIMSTONE_SNEEZE = 1036, + MC_POST_BRIMSTONE_SNEEZE = 1037, + MC_PRE_RENDER_PLAYER_HEAD = 1038, + MC_PRE_RENDER_PLAYER_BODY = 1039, + MC_PRE_ENTITY_THROW = 1040, + MC_POST_ENTITY_THROW = 1041, + MC_PLAYER_INIT_POST_LEVEL_INIT_STATS = 1042, + MC_PRE_ROOM_EXIT = 1043, + MC_POST_ROOM_RENDER_ENTITIES = 1044, + MC_POST_RENDER_PLAYER_HEAD = 1045, + MC_POST_RENDER_PLAYER_BODY = 1046, + MC_COMPLETION_MARK_GET = 1047, + MC_POST_COMPLETION_MARK_GET = 1048, + MC_PRE_COMPLETION_EVENT = 1049, + MC_PRE_TRIGGER_PLAYER_DEATH = 1050, + MC_TRIGGER_PLAYER_DEATH_POST_CHECK_REVIVES = 1051, + MC_POST_COMPLETION_EVENT = 1052, + MC_POST_TRIGGER_COLLECTIBLE_ADDED = 1053, + MC_POST_ADD_INNATE_COLLECTIBLE = 1054, + MC_POST_ADD_INNATE_TRINKET = 1055, + MC_POST_REMOVE_INNATE_COLLECTIBLE = 1056, + MC_POST_REMOVE_INNATE_TRINKET = 1057, + MC_PRE_SELECT_AMBUSH_WAVE = 1058, + MC_PRE_SELECT_GREED_WAVE = 1059, + MC_PRE_LEVEL_INIT = 1060, + MC_PRE_CHANGE_ROOM = 1061, + MC_POST_PICKUP_SHOP_PURCHASE = 1062, + MC_GET_FOLLOWER_PRIORITY = 1063, + MC_PRE_USE_CARD = 1064, + MC_PRE_USE_PILL = 1065, + MC_GET_SHOP_ITEM_PRICE = 1066, + MC_PLAYER_GET_HEALTH_TYPE = 1067, + MC_PRE_ROOM_TRIGGER_CLEAR = 1068, + MC_PRE_PLAYER_TRIGGER_ROOM_CLEAR = 1069, + MC_PRE_RESTOCK_SHOP = 1070, + MC_POST_RESTOCK_SHOP = 1071, + MC_PLAYER_GET_ACTIVE_MAX_CHARGE = 1072, + MC_PLAYER_GET_ACTIVE_MIN_USABLE_CHARGE = 1073, + MC_PLAYER_GET_HEART_LIMIT = 1074, + MC_POST_ITEM_OVERLAY_UPDATE = 1075, + MC_PRE_ITEM_OVERLAY_SHOW = 1076, + MC_POST_PLAYER_NEW_ROOM_TEMP_EFFECTS = 1077, + MC_POST_PLAYER_NEW_LEVEL = 1078, + MC_POST_PLAYERHUD_RENDER_ACTIVE_ITEM = 1079, + MC_PRE_FAMILIAR_RENDER = 1080, + MC_PRE_NPC_RENDER = 1081, + MC_PRE_PLAYER_RENDER = 1082, + MC_PRE_PICKUP_RENDER = 1083, + MC_PRE_TEAR_RENDER = 1084, + MC_PRE_PROJECTILE_RENDER = 1085, + MC_PRE_KNIFE_RENDER = 1086, + MC_PRE_EFFECT_RENDER = 1087, + MC_PRE_BOMB_RENDER = 1088, + MC_PRE_SLOT_RENDER = 1089, + MC_POST_SLOT_RENDER = 1090, + MC_POST_PLAYERHUD_RENDER_HEARTS = 1091, + MC_PRE_PLAYER_APPLY_INNATE_COLLECTIBLE_NUM = 1092, + MC_PRE_MUSIC_PLAY_JINGLE = 1094, + MC_POST_TRIGGER_COLLECTIBLE_REMOVED = 1095, + MC_POST_TRIGGER_TRINKET_ADDED = 1096, + MC_POST_TRIGGER_TRINKET_REMOVED = 1097, + MC_POST_TRIGGER_WEAPON_FIRED = 1098, + MC_POST_LEVEL_LAYOUT_GENERATED = 1099, + MC_PRE_GRID_ENTITY_SPAWN = 1100, + MC_POST_GRID_ENTITY_SPAWN = 1101, + MC_POST_NIGHTMARE_SCENE_RENDER = 1102, + MC_POST_NIGHTMARE_SCENE_SHOW = 1103, + MC_PRE_LEVEL_SELECT = 1104, + MC_POST_WEAPON_FIRE = 1105, + MC_PRE_BACKDROP_RENDER_WALLS = 1106, + MC_PRE_BACKDROP_RENDER_FLOOR = 1107, + MC_PRE_BACKDROP_RENDER_WATER = 1108, + MC_POST_BACKDROP_PRE_RENDER_WALLS = 1109, + MC_PRE_PLANETARIUM_APPLY_STAGE_PENALTY = 1110, + MC_PRE_PLANETARIUM_APPLY_PLANETARIUM_PENALTY = 1111, + MC_PRE_PLANETARIUM_APPLY_TREASURE_PENALTY = 1112, + MC_PRE_PLANETARIUM_APPLY_ITEMS = 1113, + MC_PRE_PLANETARIUM_APPLY_TELESCOPE_LENS = 1114, + MC_POST_PLANETARIUM_CALCULATE = 1115, + MC_PRE_REPLACE_SPRITESHEET = 1116, + MC_POST_REPLACE_SPRITESHEET = 1117, + MC_PRE_PLAYERHUD_RENDER_HEARTS = 1118, + MC_PRE_PLAYERHUD_RENDER_ACTIVE_ITEM = 1119, + MC_CONSOLE_AUTOCOMPLETE = 1120, + MC_POST_SLOT_INIT = 1121, + MC_POST_SLOT_UPDATE = 1122, + MC_PRE_SLOT_CREATE_EXPLOSION_DROPS = 1123, + MC_POST_SLOT_CREATE_EXPLOSION_DROPS = 1124, + MC_PRE_SLOT_SET_PRIZE_COLLECTIBLE = 1125, + MC_POST_SLOT_SET_PRIZE_COLLECTIBLE = 1126, + MC_PLAYER_INIT_PRE_LEVEL_INIT_STATS = 1127, + MC_PLAYER_HEALTH_TYPE_CHANGE = 1128, + MC_POST_FORCE_ADD_PILL_EFFECT = 1129, + MC_PRE_DEVIL_APPLY_ITEMS = 1130, + MC_PRE_DEVIL_APPLY_STAGE_PENALTY = 1131, + MC_PRE_DEVIL_APPLY_SPECIAL_ITEMS = 1132, + MC_POST_DEVIL_CALCULATE = 1133, + MC_POST_ITEM_OVERLAY_SHOW = 1134, + MC_PRE_RENDER = 1135, + MC_PRE_OPENGL_RENDER = 1136, + MC_PRE_LEVEL_PLACE_ROOM = 1137, + MC_POST_PLAYER_TRIGGER_ROOM_CLEAR = 1138, + MC_POST_ITEM_OVERLAY_RENDER = 1139, + MC_POST_DISCHARGE_ACTIVE_ITEM = 1140, + MC_PRE_BACKDROP_CHANGE = 1141, + MC_POST_BACKDROP_CHANGE = 1142, + MC_POST_ROOM_TRIGGER_CLEAR = 1143, + MC_POST_PLAYER_DROP_TRINKET = 1144, + MC_PRE_GET_LIGHTING_ALPHA = 1150, + MC_PRE_RENDER_GRID_LIGHTING = 1151, + MC_PRE_RENDER_ENTITY_LIGHTING = 1152, + MC_PRE_PLAYER_UPDATE = 1160, + MC_PRE_TEAR_UPDATE = 1161, + MC_PRE_FAMILIAR_UPDATE = 1162, + MC_PRE_BOMB_UPDATE = 1163, + MC_PRE_PICKUP_UPDATE = 1164, + MC_PRE_KNIFE_UPDATE = 1165, + MC_PRE_PROJECTILE_UPDATE = 1166, + MC_PRE_LASER_UPDATE = 1167, + MC_PRE_EFFECT_UPDATE = 1168, + MC_PRE_SLOT_UPDATE = 1169, + MC_PRE_PLAYER_GRID_COLLISION = 1171, + MC_PLAYER_GRID_COLLISION = 1172, + MC_PRE_TEAR_GRID_COLLISION = 1173, + MC_TEAR_GRID_COLLISION = 1174, + MC_PRE_FAMILIAR_GRID_COLLISION = 1175, + MC_FAMILIAR_GRID_COLLISION = 1176, + MC_PRE_BOMB_GRID_COLLISION = 1177, + MC_BOMB_GRID_COLLISION = 1178, + MC_PRE_PICKUP_GRID_COLLISION = 1179, + MC_PICKUP_GRID_COLLISION = 1180, + MC_PRE_PROJECTILE_GRID_COLLISION = 1181, + MC_PROJECTILE_GRID_COLLISION = 1182, + MC_PRE_NPC_GRID_COLLISION = 1183, + MC_NPC_GRID_COLLISION = 1184, + MC_PRE_M_MORPH_ACTIVE = 1190, + MC_PRE_NPC_SPLIT = 1191, + MC_PRE_ROOM_GRID_ENTITY_SPAWN = 1192, + MC_PRE_NEW_ROOM = 1200, + MC_PRE_MEGA_SATAN_ENDING = 1201, + MC_POST_MODS_LOADED = 1210, + MC_PRE_NPC_MORPH = 1212, + MC_PRE_PICKUP_MORPH = 1213, + MC_POST_NPC_MORPH = 1214, + MC_POST_PICKUP_MORPH = 1215, + MC_PRE_COMPLETION_MARKS_RENDER = 1216, + MC_POST_COMPLETION_MARKS_RENDER = 1217, + MC_PRE_PAUSE_SCREEN_RENDER = 1218, + MC_POST_PAUSE_SCREEN_RENDER = 1219, + MC_PRE_PLAYER_USE_BOMB = 1220, + MC_POST_PLAYER_USE_BOMB = 1221, + MC_NPC_PICK_TARGET = 1222, + MC_POST_NPC_DARK_RED_CHAMPION_REGEN = 1223, + MC_EVALUATE_CUSTOM_CACHE = 1224, + MC_EVALUATE_FAMILIAR_MULTIPLIER = 1225, + MC_EVALUATE_STAT = 1226, + MC_PRE_ROOM_COLLISION_PASS = 1227, + MC_POST_PLAYER_COLLISION = 1231, + MC_POST_TEAR_COLLISION = 1233, + MC_POST_FAMILIAR_COLLISION = 1235, + MC_POST_BOMB_COLLISION = 1237, + MC_POST_PICKUP_COLLISION = 1239, + MC_PRE_SLOT_COLLISION = 1240, + MC_POST_SLOT_COLLISION = 1241, + MC_POST_KNIFE_COLLISION = 1243, + MC_POST_PROJECTILE_COLLISION = 1245, + MC_POST_NPC_COLLISION = 1247, + MC_PRE_LASER_COLLISION = 1248, + MC_POST_LASER_COLLISION = 1249, + MC_PICKUP_GET_COIN_VALUE = 1250, + MC_POST_PLAYER_GET_MULTI_SHOT_PARAMS = 1251, + MC_POST_FAMILIAR_FIRE_PROJECTILE = 1252, + MC_POST_FIRE_BOMB = 1253, + MC_POST_FIRE_BONE_CLUB = 1254, + MC_POST_FIRE_BRIMSTONE = 1255, + MC_POST_FIRE_BRIMSTONE_BALL = 1256, + MC_POST_FIRE_KNIFE = 1257, + MC_POST_FIRE_SWORD = 1258, + MC_POST_FIRE_TECH_LASER = 1259, + MC_POST_FIRE_TECH_X_LASER = 1260, + MC_POST_FAMILIAR_FIRE_BRIMSTONE = 1261, + MC_POST_FAMILIAR_FIRE_TECH_LASER = 1262, + MC_IS_PERSISTENT_ROOM_ENTITY = 1263, + MC_PRE_PLAYERHUD_TRINKET_RENDER = 1264, + MC_PRE_PICKUP_VOIDED = 1265, + MC_PRE_PICKUP_VOIDED_ABYSS = 1266, + MC_PRE_PICKUP_COMPOSTED = 1267, + MC_POST_PLAYER_TRIGGER_EFFECT_REMOVED = 1268, + MC_POST_ROOM_TRIGGER_EFFECT_REMOVED = 1269, + MC_POST_BOSS_INTRO_SHOW = 1270, + MC_POST_ROOM_TRANSITION_UPDATE = 1271, + MC_POST_ROOM_TRANSITION_RENDER = 1272, + MC_POST_PLAYER_ADD_EFFECT = 1273, + MC_POST_ROOM_ADD_EFFECT = 1274, + MC_POST_BOMB_DAMAGE = 1275, + MC_POST_BOMB_TEARFLAG_EFFECTS = 1276, + MC_PRE_APPLY_TEARFLAG_EFFECTS = 1277, + MC_POST_APPLY_TEARFLAG_EFFECTS = 1278, + MC_PRE_BOSS_SELECT = 1280, + MC_PRE_PLAYER_ADD_COSTUME = 1281, + MC_PRE_PLAYER_REMOVE_COSTUME = 1282, + MC_POST_PLAYER_ADD_COSTUME = 1283, + MC_POST_PLAYER_REMOVE_COSTUME = 1284, + MC_PRE_TRIGGER_BED_SLEEP_EFFECT = 1285, + MC_POST_TRIGGER_BED_SLEEP_EFFECT = 1286, + MC_PRE_PLAYER_POCKET_ITEMS_SWAP = 1287, + MC_PRE_BED_SLEEP = 1288, + MC_EVALUATE_MULTI_SHOT_PARAMS = 1289, + MC_PRE_GET_RANDOM_ROOM_INDEX = 1290, + MC_PRE_BOMB_DAMAGE = 1291, + MC_PRE_BOMB_TEARFLAG_EFFECTS = 1292, + MC_PRE_PLAYERHUD_RENDER_INVENTORY = 1293, + MC_POST_PLAYERHUD_RENDER_INVENTORY = 1294, + MC_PRE_PLAYERHUD_RENDER_POOP_SPELL_QUEUE = 1295, + MC_POST_PLAYERHUD_RENDER_POOP_SPELL_QUEUE = 1296, + MC_PRE_PLAYERHUD_RENDER_CRAFTING_TABLE = 1297, + MC_POST_PLAYERHUD_RENDER_CRAFTING_TABLE = 1298, + MC_POST_GLOWING_HOURGLASS_SAVE = 1300, + MC_POST_GLOWING_HOURGLASS_LOAD = 1301, + MC_PRE_GLOWING_HOURGLASS_SAVE = 1302, + MC_PRE_GLOWING_HOURGLASS_LOAD = 1303, + MC_POST_ROOM_SAVE_STATE = 1304, + MC_PRE_ROOM_RESTORE_STATE = 1305, + MC_POST_SWAP_ROOMS = 1306, + MC_POST_BACKWARDS_ROOM_SAVE = 1307, + MC_POST_BACKWARDS_ROOM_RESTORE = 1308, + MC_PRE_GAME_STATE_SAVE = 1309, + MC_POST_GAME_STATE_SAVE = 1310, + MC_PRE_GAME_STATE_RESTORE = 1311, + MC_POST_GAME_STATE_RESTORE = 1312, + MC_SHOULD_SAVE_ENTITY = 1313, + MC_ENTITY_SAVE = 1314, + MC_ENTITY_RESTORE = 1315, + MC_CAN_SELECT_CHARACTER = 1328, + MC_PRE_RENDER_CHARACTER_SELECT_PAGE = 1329, + MC_POST_RENDER_CHARACTER_SELECT_PAGE = 1330, + MC_PRE_RENDER_CHARACTER_SELECT_PORTRAIT = 1331, + MC_POST_RENDER_CHARACTER_SELECT_PORTRAIT = 1332, + MC_PRE_RENDER_CUSTOM_CHARACTER_MENU = 1333, + MC_PRE_PICKUP_GET_LOOT_LIST = 1334, + MC_PRE_PICKUP_UPDATE_GHOST_PICKUPS = 1335, + MC_POST_PICKUP_GET_LOOT_LIST = 1336, + MC_PRE_NPC_GET_LOOT_LIST = 1337, + MC_PRE_NPC_UPDATE_GHOST_PICKUPS = 1338, + MC_POST_NPC_GET_LOOT_LIST = 1339, + MC_PRE_PLAYER_ADD_CARD = 1350, + MC_POST_PLAYER_ADD_CARD = 1351, + MC_PRE_PLAYER_ADD_PILL = 1352, + MC_POST_PLAYER_ADD_PILL = 1353, + MC_POST_PLAYER_REMOVE_CARD = 1354, + MC_POST_PLAYER_REMOVE_PILL = 1355, + MC_PRE_PLAYER_COLLECT_CARD = 1356, + MC_POST_PLAYER_COLLECT_CARD = 1357, + MC_PRE_PLAYER_COLLECT_PILL = 1358, + MC_POST_PLAYER_COLLECT_PILL = 1359, + MC_POST_PLAYER_DROP_CARD = 1360, + MC_POST_PLAYER_DROP_PILL = 1361, + MC_PRE_GRID_ENTITY_DECORATION_UPDATE = 1400, + MC_POST_GRID_ENTITY_DECORATION_UPDATE = 1401, + MC_PRE_GRID_ENTITY_DOOR_UPDATE = 1402, + MC_POST_GRID_ENTITY_DOOR_UPDATE = 1403, + MC_PRE_GRID_ENTITY_FIRE_UPDATE = 1404, + MC_POST_GRID_ENTITY_FIRE_UPDATE = 1405, + MC_PRE_GRID_ENTITY_GRAVITY_UPDATE = 1406, + MC_POST_GRID_ENTITY_GRAVITY_UPDATE = 1407, + MC_PRE_GRID_ENTITY_LOCK_UPDATE = 1408, + MC_POST_GRID_ENTITY_LOCK_UPDATE = 1409, + MC_PRE_GRID_ENTITY_PIT_UPDATE = 1410, + MC_POST_GRID_ENTITY_PIT_UPDATE = 1411, + MC_PRE_GRID_ENTITY_POOP_UPDATE = 1412, + MC_POST_GRID_ENTITY_POOP_UPDATE = 1413, + MC_PRE_GRID_ENTITY_PRESSUREPLATE_UPDATE = 1414, + MC_POST_GRID_ENTITY_PRESSUREPLATE_UPDATE = 1415, + MC_PRE_GRID_ENTITY_ROCK_UPDATE = 1416, + MC_POST_GRID_ENTITY_ROCK_UPDATE = 1417, + MC_PRE_GRID_ENTITY_SPIKES_UPDATE = 1418, + MC_POST_GRID_ENTITY_SPIKES_UPDATE = 1419, + MC_PRE_GRID_ENTITY_STAIRCASE_UPDATE = 1420, + MC_POST_GRID_ENTITY_STAIRCASE_UPDATE = 1421, + MC_PRE_GRID_ENTITY_STATUE_UPDATE = 1422, + MC_POST_GRID_ENTITY_STATUE_UPDATE = 1423, + MC_PRE_GRID_ENTITY_TELEPORTER_UPDATE = 1424, + MC_POST_GRID_ENTITY_TELEPORTER_UPDATE = 1425, + MC_PRE_GRID_ENTITY_TRAPDOOR_UPDATE = 1426, + MC_POST_GRID_ENTITY_TRAPDOOR_UPDATE = 1427, + MC_PRE_GRID_ENTITY_WEB_UPDATE = 1428, + MC_POST_GRID_ENTITY_WEB_UPDATE = 1429, + MC_PRE_GRID_ENTITY_TNT_UPDATE = 1430, + MC_POST_GRID_ENTITY_TNT_UPDATE = 1431, + MC_PRE_GRID_ENTITY_SPIKES_RENDER = 1432, + MC_POST_GRID_ENTITY_SPIKES_RENDER = 1433, + MC_PRE_GRID_ENTITY_WEB_RENDER = 1434, + MC_POST_GRID_ENTITY_WEB_RENDER = 1435, + MC_PRE_GRID_ENTITY_TNT_RENDER = 1436, + MC_POST_GRID_ENTITY_TNT_RENDER = 1437, + MC_PRE_GRID_ENTITY_TRAPDOOR_RENDER = 1438, + MC_POST_GRID_ENTITY_TRAPDOOR_RENDER = 1439, + MC_PRE_GRID_ENTITY_STAIRCASE_RENDER = 1440, + MC_POST_GRID_ENTITY_STAIRCASE_RENDER = 1441, + MC_PRE_GRID_ENTITY_DECORATION_RENDER = 1444, + MC_POST_GRID_ENTITY_DECORATION_RENDER = 1445, + MC_PRE_GRID_ENTITY_DOOR_RENDER = 1446, + MC_POST_GRID_ENTITY_DOOR_RENDER = 1447, + MC_PRE_GRID_ENTITY_FIRE_RENDER = 1448, + MC_POST_GRID_ENTITY_FIRE_RENDER = 1449, + MC_PRE_GRID_ENTITY_LOCK_RENDER = 1450, + MC_POST_GRID_ENTITY_LOCK_RENDER = 1451, + MC_PRE_GRID_ENTITY_TELEPORTER_RENDER = 1452, + MC_POST_GRID_ENTITY_TELEPORTER_RENDER = 1453, + MC_PRE_GRID_ENTITY_PIT_RENDER = 1454, + MC_POST_GRID_ENTITY_PIT_RENDER = 1455, + MC_PRE_GRID_ENTITY_POOP_RENDER = 1456, + MC_POST_GRID_ENTITY_POOP_RENDER = 1457, + MC_PRE_GRID_ENTITY_ROCK_RENDER = 1458, + MC_POST_GRID_ENTITY_ROCK_RENDER = 1459, + MC_PRE_GRID_ENTITY_PRESSUREPLATE_RENDER = 1460, + MC_POST_GRID_ENTITY_PRESSUREPLATE_RENDER = 1461, + MC_PRE_GRID_ENTITY_WALL_RENDER = 1462, + MC_POST_GRID_ENTITY_WALL_RENDER = 1463, + MC_MENU_INPUT_ACTION = 1464, + MC_PRE_STATUS_EFFECT_APPLY = 1465, + MC_POST_STATUS_EFFECT_APPLY = 1466, + MC_POST_SAVESLOT_LOAD = 1470, + MC_PRE_CHALLENGE_DONE = 1471, + MC_POST_CHALLENGE_DONE = 1472, + MC_PRE_FAMILIAR_CAN_CHARM = 1473, + MC_PRE_PLAYER_GIVE_BIRTH_CAMBION = 1474, + MC_PRE_PLAYER_GIVE_BIRTH_IMMACULATE = 1475, + MC_POST_ACHIEVEMENT_UNLOCK = 1476, + MC_PRE_MINIMAP_UPDATE = 1477, + MC_POST_MINIMAP_UPDATE = 1478, + MC_PRE_MINIMAP_RENDER = 1479, + MC_POST_MINIMAP_RENDER = 1480, + MC_PRE_PLAYER_REVIVE = 1481, + MC_POST_PLAYER_REVIVE = 1482, + MC_PRE_FORTUNE_DISPLAY = 1483, + MC_PRE_ITEM_TEXT_DISPLAY = 1484, + MC_GET_STATUS_EFFECT_TARGET = 1485, + MC_PRE_ENTITY_SET_COLOR = 1486, + MC_POST_ENTITY_SET_COLOR = 1487, + MC_POST_START_AMBUSH_WAVE = 1488, + MC_POST_START_GREED_WAVE = 1489, + MC_EVALUATE_TEAR_HIT_PARAMS = 1490, + MC_PRE_OPEN_CHEST = 1491, + MC_POST_OPEN_CHEST = 1492, + MC_GET_BOSS_THEMATIC_ITEM = 1493, + MC_PRE_SHUFFLE_COSTUMES = 1494, + MC_POST_SHUFFLE_COSTUMES = 1495 +}; + +// An entity as REPENTOGON's callbacks pass it: as its own class, or as an Entity when the API has none for it (slots). +template +auto* callback_entity(T* entity) +{ + if constexpr (IS_LUA_CLASS) return entity; + else return (Entity*)entity; +} + +// Runs a callback whose result counts only when it is a boolean: that boolean, else fallback. +template +bool boolean_run(CallbackRun run, bool fallback, Args... args) +{ + LuaEngine& engine = lua_engine_get(); + if (!callback_run(engine, run, args...)) return fallback; + + bool result = lua_isboolean(engine.state, -1) ? lua_toboolean(engine.state, -1) : fallback; + lua_pop(engine.state, 1); + return result; +} + +// A field of the table on top of the stack when it is a boolean. +inline std::optional boolean_field_get(lua_State* state, const char* key) +{ + std::optional value; + lua_getfield(state, -1, key); + if (lua_isboolean(state, -1)) value = lua_toboolean(state, -1); + lua_pop(state, 1); + return value; +} + +// Runs a PRE_X_RENDER callback for an entity drawn at offset. Where to draw it, nothing when a mod cancels the render. +// A Vector result moves it (main_ex.lua adds each mod's to the offset). +template +std::optional render_pre_run(CallbackRun run, T* entity, const Vector& offset) +{ + LuaEngine& engine = lua_engine_get(); + if (!callback_run(engine, run, callback_entity(entity), offset)) return offset; + + std::optional result = offset; + if (lua_isboolean(engine.state, -1) && !lua_toboolean(engine.state, -1)) result.reset(); + else if (auto* moved = (Vector*)lua_object_test(engine.state, -1, LUA_CLASS_VECTOR)) result = *moved; + lua_pop(engine.state, 1); + return result; +} + +// The callbacks REPENTOGON runs around an entity's collision code: its PRE (the game's own Pre*Collision for most +// entities, which isVanillaPre marks) and POST_X_COLLISION, and the parameter both filter by. +struct CollisionCallbacks +{ + const char* name; + int pre; + int post; + int param; + bool isVanillaPre = true; +}; + +// Runs REPENTOGON's collision callbacks around react, an entity's own collision code. Whether the touch is ignored. +// A PRE result of true or false skips react and is the answer, a table sets SkipCollisionEffects and Collide. +// POST runs only after react ran. With vanilla parity the game's own Pre*Collision keeps its place inside react, and +// whether it skipped react is read back from the engine. +template +bool collision_callbacks_run(T& entity, Entity* collider, bool isLow, CollisionCallbacks callbacks, + bool (T::*react)(Entity*, bool)) +{ + LuaEngine& engine = lua_engine_get(); + lua_State* state = engine.state; + auto* pushed = callback_entity(&entity); + std::optional isIgnored; + bool isSkipped = false; + bool isVanillaHook = callbacks.isVanillaPre && repentogonOptions.isVanillaParity; + + if (!isVanillaHook && callback_run(engine, {callbacks.name, callbacks.pre, callbacks.param}, pushed, collider, isLow)) + { + if (lua_isboolean(state, -1)) + { + isSkipped = true; + isIgnored = lua_toboolean(state, -1); + } + else if (lua_istable(state, -1)) + { + isSkipped = boolean_field_get(state, "SkipCollisionEffects").value_or(false); + if (std::optional isCollide = boolean_field_get(state, "Collide")) isIgnored = !*isCollide; + } + lua_pop(state, 1); + } + if (isSkipped) return isIgnored.value_or(false); + + LuaResult outer = engine.collisionResult; + engine.collisionResult = LUA_RESULT_NIL; + bool isResult = (entity.*react)(collider, isLow); + bool isReacted = !isVanillaHook || engine.collisionResult == LUA_RESULT_NIL; + engine.collisionResult = outer; + if (isReacted) callback_notify(engine, {callbacks.name, callbacks.post, callbacks.param}, pushed, collider, isLow); + return isIgnored.value_or(isResult); +} + +// Sets value to the class value on top of the stack when it is one, as REPENTOGON reads a returned Vector or TearParams. +// The rebuild ignores a userdata of another class, which REPENTOGON raises an error for. +template +void object_read(lua_State* state, V& value) +{ + if (V* object = (V*)lua_object_test(state, -1, LUA_CLASS_OF)) value = *object; +} + +// Runs a callback without a filter parameter whose result the game ignores. +template +void unfiltered_notify(const char* name, int id, Args... args) +{ + callback_notify(lua_engine_get(), {name, id, std::nullopt}, args...); +} + +// Runs a callback. Its result as a boolean, nothing when no function ran or it returned no boolean. +template +std::optional callback_boolean_get(CallbackRun run, Args... args) +{ + LuaEngine& engine = lua_engine_get(); + if (!callback_run(engine, run, args...)) return std::nullopt; + + std::optional result; + if (lua_isboolean(engine.state, -1)) result = lua_toboolean(engine.state, -1); + lua_pop(engine.state, 1); + return result; +} + +// Runs a callback. Its result as an integer, nothing when no function ran or it returned no integer. +template +std::optional callback_integer_get(CallbackRun run, Args... args) +{ + LuaEngine& engine = lua_engine_get(); + if (!callback_run(engine, run, args...)) return std::nullopt; + + std::optional result; + if (lua_isinteger(engine.state, -1)) result = (int)lua_tointeger(engine.state, -1); + lua_pop(engine.state, 1); + return result; +} + +// Runs a PRE_*_UPDATE callback. Whether a mod returned true, which skips the entity's own update for Entity::Update. +template +bool update_pre_is_skipped(CallbackRun run, T* entity) +{ + return boolean_run(run, false, entity); +} + +// Runs a PRE_*_RENDER callback with a render offset the caller owns. False when a mod returned false to skip the +// render, else a Vector a mod returned replaces offset. +template +bool render_pre_run(CallbackRun run, T* entity, Vector& offset) +{ + std::optional moved = render_pre_run(run, entity, std::as_const(offset)); + if (moved) offset = *moved; + return moved.has_value(); +} + +// Calls function as the scope it is made in ends: a POST callback after every return of the function it guards. +template +struct ScopeExit +{ + F function; + + ~ScopeExit() { function(); } +}; + +// A grid entity as REPENTOGON's callbacks pass it: as its own class, or as a GridEntity when the API has none for it. +template +auto* callback_grid(T* grid) +{ + if constexpr (IS_LUA_CLASS) return grid; + else return (GridEntity*)grid; +} + +// Runs a grid entity's PRE_GRID_ENTITY_X_UPDATE callback, filtered by its type, as its update starts, and POST as the +// update ends. Any boolean a mod returns to PRE skips the update, and POST with it. +template +struct GridUpdateScope +{ + T& grid; + int postCallback; + bool isSkipped; + + GridUpdateScope(T& grid, int preCallback, int postCallback) + : grid(grid), postCallback(postCallback), + isSkipped(callback_boolean_get({"PreGridEntityUpdate", preCallback, (int)grid.type}, callback_grid(&grid)) + .has_value()) + {} + + ~GridUpdateScope() + { + if (isSkipped) return; + callback_notify(lua_engine_get(), {"PostGridEntityUpdate", postCallback, (int)grid.type}, callback_grid(&grid)); + } +}; + +// Runs a callback filtered by an item config entry, which REPENTOGON passes as the parameter itself (main_ex.lua +// filters by its GetPtrHash), whose result the game ignores. +template +void item_callback_notify(const char* name, int callback, ItemConfig_Item* item, Args... args) +{ + LuaEngine& engine = lua_engine_get(); + if (!engine.is_callback_enabled(callback)) return; + + lua_State* state = engine.state; + lua_rawgeti(state, LUA_REGISTRYINDEX, engine.runCallbackRef); + lua_pushinteger(state, callback); + lua_push(state, item); + (lua_push(state, args), ...); + if (lua_pcall(state, sizeof...(Args) + 2, 1, 0) == LUA_OK) lua_pop(state, 1); + else lua_error_log(state, name); +} + +// Whether the hooked function called next runs its own code, as its hook's call of it. That function takes the flag +// first thing, so calls it makes run their hooks again. +inline bool isHookInner = false; + +// Whether a hooked function was called by its own hook, taking the flag. +inline bool is_hook_inner() +{ + return std::exchange(isHookInner, false); +} + +// Calls a hooked function's own code from its hook, REPENTOGON's super. +template +auto hook_inner_call(F call) +{ + isHookInner = true; + return call(); +} + +// Whether a callback's result on top of the stack is false, which cancels what REPENTOGON's PRE callbacks run before. +inline bool is_result_false(lua_State* state) +{ + return lua_isboolean(state, -1) && !lua_toboolean(state, -1); +} + +// The callbacks REPENTOGON runs as an entity meets a grid cell: PRE_X_GRID_COLLISION, X_GRID_COLLISION and the +// parameter both filter by. +struct GridCollisionCallbacks +{ + const char* name; + int pre; + int post; + int param; +}; + +std::optional grid_collision_cached(Entity* entity, int gridIndex); +void grid_collision_cache(Entity* entity, int gridIndex, bool isIgnored); +GridEntity* grid_collision_grid_get(int gridIndex); + +// (RunGridCollisionCallbacks) An entity's PRE_X_GRID_COLLISION and X_GRID_COLLISION for a grid cell it meets, with the +// cell's index and grid entity, once per entity and cell each game update. Whether a mod returned true to PRE, which +// ignores the cell. X_GRID_COLLISION runs when none did. +template +bool grid_collision_is_ignored(T& entity, int gridIndex, GridCollisionCallbacks callbacks) +{ + LuaEngine& engine = lua_engine_get(); + if (!engine.is_callback_enabled(callbacks.pre) && !engine.is_callback_enabled(callbacks.post)) return false; + if (std::optional isCached = grid_collision_cached(&entity, gridIndex)) return *isCached; + + GridEntity* grid = grid_collision_grid_get(gridIndex); + bool isIgnored = boolean_run({callbacks.name, callbacks.pre, callbacks.param}, false, &entity, gridIndex, grid); + if (!isIgnored) + callback_notify(engine, {callbacks.name, callbacks.post, callbacks.param}, &entity, gridIndex, grid); + grid_collision_cache(&entity, gridIndex, isIgnored); + return isIgnored; +} + diff --git a/src/repentogon/collision.cpp b/src/repentogon/collision.cpp new file mode 100644 index 0000000..dd43c0a --- /dev/null +++ b/src/repentogon/collision.cpp @@ -0,0 +1,84 @@ +#include "repentogon/collision.h" +#include "entity/familiar/familiar.h" +#include "entity/npc/npc.h" +#include "entity/pickup/pickup.h" +#include "entity/player/player.h" +#include "entity/weapon/bomb.h" +#include "entity/weapon/projectile.h" +#include "entity/weapon/tear.h" +#include "game/game.h" +#include "level/room.h" +#include "repentogon/callbacks.h" +#include + +// What the grid collision callbacks answered for each entity and cell this game update (cachedGridCollisionResult). +static std::unordered_map> gridCollisionCache; + +std::optional grid_collision_cached(Entity* entity, int gridIndex) +{ + auto cells = gridCollisionCache.find(entity); + if (cells == gridCollisionCache.end()) return std::nullopt; + + auto cell = cells->second.find(gridIndex); + return cell == cells->second.end() ? std::nullopt : std::optional(cell->second); +} + +void grid_collision_cache(Entity* entity, int gridIndex, bool isIgnored) +{ + gridCollisionCache[entity][gridIndex] = isIgnored; +} + +GridEntity* grid_collision_grid_get(int gridIndex) +{ + return g_game->room->GetGridEntity(gridIndex); +} + +// Forgets the answers as a game update ends. +void grid_collision_cache_clear() +{ + if (!gridCollisionCache.empty()) gridCollisionCache.clear(); +} + +// (TriggerGridCollisionCallbacks) The grid collision callbacks of an entity meeting a grid cell, by its kind (an NPC's +// filtered by its type, the rest by their variant). Whether a mod returned true, which ignores the cell. +bool entity_grid_collision_is_ignored(Entity& entity, int gridIndex) +{ + int variant = entity.variant; + switch (entity.type) + { + case ENTITY_PLAYER: + return grid_collision_is_ignored(static_cast(entity), gridIndex, + {"PlayerGridCollision", MC_PRE_PLAYER_GRID_COLLISION, + MC_PLAYER_GRID_COLLISION, variant}); + case ENTITY_TEAR: + return grid_collision_is_ignored(static_cast(entity), gridIndex, + {"TearGridCollision", MC_PRE_TEAR_GRID_COLLISION, MC_TEAR_GRID_COLLISION, + variant}); + case ENTITY_FAMILIAR: + return grid_collision_is_ignored(static_cast(entity), gridIndex, + {"FamiliarGridCollision", MC_PRE_FAMILIAR_GRID_COLLISION, + MC_FAMILIAR_GRID_COLLISION, variant}); + case ENTITY_BOMB: + return grid_collision_is_ignored(static_cast(entity), gridIndex, + {"BombGridCollision", MC_PRE_BOMB_GRID_COLLISION, MC_BOMB_GRID_COLLISION, + variant}); + case ENTITY_PICKUP: + return grid_collision_is_ignored(static_cast(entity), gridIndex, + {"PickupGridCollision", MC_PRE_PICKUP_GRID_COLLISION, + MC_PICKUP_GRID_COLLISION, variant}); + case ENTITY_PROJECTILE: + return grid_collision_is_ignored(static_cast(entity), gridIndex, + {"ProjectileGridCollision", MC_PRE_PROJECTILE_GRID_COLLISION, + MC_PROJECTILE_GRID_COLLISION, variant}); + default: + break; + } + LuaEngine& engine = lua_engine_get(); + bool isHooked = + engine.is_callback_enabled(MC_PRE_NPC_GRID_COLLISION) || engine.is_callback_enabled(MC_NPC_GRID_COLLISION); + auto* npc = isHooked ? dynamic_cast(&entity) : nullptr; + if (!npc) return false; + + return grid_collision_is_ignored(*npc, gridIndex, + {"NPCGridCollision", MC_PRE_NPC_GRID_COLLISION, MC_NPC_GRID_COLLISION, npc->type}); +} diff --git a/src/repentogon/collision.h b/src/repentogon/collision.h new file mode 100644 index 0000000..f0150c1 --- /dev/null +++ b/src/repentogon/collision.h @@ -0,0 +1,6 @@ +#pragma once + +struct Entity; + +bool entity_grid_collision_is_ignored(Entity& entity, int gridIndex); +void grid_collision_cache_clear(); diff --git a/src/repentogon/entities.cpp b/src/repentogon/entities.cpp new file mode 100644 index 0000000..ac8d561 --- /dev/null +++ b/src/repentogon/entities.cpp @@ -0,0 +1,186 @@ +#include "repentogon/entities.h" +#include "entity/player/player.h" +#include "repentogon/callbacks.h" +#include + +constexpr int FIRE_DAMAGE_COOLDOWN = 10; +constexpr int WHITE_FIREPLACE_VARIANT = 4; + +// A hit's values once MC_ENTITY_TAKE_DMG settled them, which MC_POST_ENTITY_TAKE_DMG passes for a player: the damage +// (the hearts it cost), countdown and flags. +struct SettledHit +{ + Entity* entity; + float damage; + int countdown; + uint64_t damageFlags; +}; + +// The hit of the innermost Entity_Player::TakeDamage that player_damage_hook runs, null outside one. +static SettledHit* settledHit = nullptr; + +// Reads REPENTOGON's table result of MC_ENTITY_TAKE_DMG into the hit: Damage (not below 0, rounded into a player's +// hearts), DamageFlags and DamageCountdown. Flags it adds count as the game counts them before the callback: a fake +// hit costs no hearts, and for others a fire or countdown hit under its cooldown misses, else starts it. +// Whether the hit still lands. +static bool damage_table_read(lua_State* state, Entity& entity, DamageHit& hit) +{ + uint64_t original = hit.damageFlags; + lua_getfield(state, -1, "Damage"); + if (lua_isnumber(state, -1)) + { + hit.damage = std::max((float)lua_tonumber(state, -1), 0.0f); + if (hit.hearts) *hit.hearts = (int)std::round(hit.damage); + } + lua_getfield(state, -2, "DamageFlags"); + if (lua_isinteger(state, -1)) hit.damageFlags = lua_tointeger(state, -1); + lua_getfield(state, -3, "DamageCountdown"); + if (lua_isnumber(state, -1)) hit.countdown = (int)lua_tonumber(state, -1); + lua_pop(state, 3); + + uint64_t added = hit.damageFlags & ~original; + if (hit.hearts) + { + if (added & DAMAGE_FAKE) *hit.hearts = 0; + return true; + } + if (added & DAMAGE_FIRE) + { + if (entity.fireDamageCountdown > 0) return false; + entity.fireDamageCountdown = FIRE_DAMAGE_COOLDOWN; + } + if ((added & DAMAGE_COUNTDOWN) && entity.damageCountdown > 0) return false; + if (hit.damageFlags & DAMAGE_COUNTDOWN) entity.damageCountdown = hit.countdown; + return true; +} + +// REPENTOGON's MC_ENTITY_TAKE_DMG, filtered by the entity's type: a player's hit passes its hearts as the damage, and +// an ExtraSource follows the countdown (nil until the damage dealers pass theirs). A boolean decides the hit, a table +// changes it. Whether the hit lands. +static bool damage_callback_run(Entity& entity, DamageHit& hit) +{ + LuaEngine& engine = lua_engine_get(); + lua_State* state = engine.state; + CallbackRun run = {"PreEntityTakeDamage", MC_ENTITY_TAKE_DMG, entity.type}; + auto damage_run = [&](auto damage) { + return callback_run(engine, run, &entity, damage, hit.damageFlags, &hit.source, hit.countdown, + (EntityRef*)nullptr); + }; + if (!(hit.hearts ? damage_run(*hit.hearts) : damage_run(hit.damage))) return true; + + bool isLanded = true; + if (lua_isboolean(state, -1)) isLanded = lua_toboolean(state, -1); + else if (lua_istable(state, -1)) isLanded = damage_table_read(state, entity, hit); + lua_pop(state, 1); + return isLanded; +} + +// Runs MC_ENTITY_TAKE_DMG where the game does: as the game does with vanilla parity, else as REPENTOGON rewrote it, +// which turns a player's damage into the hearts it costs. Keeps a player's settled hit for MC_POST_ENTITY_TAKE_DMG. +// Whether the hit lands. +bool entity_damage_pre(Entity& entity, DamageHit hit) +{ + bool isLanded = true; + if (repentogonOptions.isVanillaParity) + { + float damage = hit.hearts ? (float)*hit.hearts : hit.damage; + isLanded = lua_engine_get().EntityTakeDamage(&entity, damage, hit.damageFlags, hit.source, hit.countdown); + } + else + { + isLanded = damage_callback_run(entity, hit); + if (hit.hearts) hit.damage = (float)*hit.hearts; + } + + if (settledHit && settledHit->entity == &entity && hit.hearts) + *settledHit = {&entity, (float)*hit.hearts, hit.countdown, hit.damageFlags}; + return isLanded; +} + +// Runs MC_POST_ENTITY_TAKE_DMG after a hit landed, filtered by the entity's type, with the hit as the game settled it. +void entity_damage_post(Entity& entity, DamageHit hit) +{ + callback_notify(lua_engine_get(), {"MC_POST_ENTITY_TAKE_DMG", MC_POST_ENTITY_TAKE_DMG, entity.type}, &entity, + hit.damage, hit.damageFlags, &hit.source, hit.countdown, (EntityRef*)nullptr); +} + +// Runs Entity_Player::TakeDamage and after it MC_POST_ENTITY_TAKE_DMG when it hurt, but for the white fireplace's hit, +// which hurts no hearts. The damage passed is the hearts it cost, as MC_ENTITY_TAKE_DMG settled it. +// Whether it hurt, nothing when no mod added a function or this is the hook's own call. +std::optional player_damage_hook(Entity_Player& player, DamageHit hit) +{ + if (is_hook_inner() || !lua_engine_get().is_callback_enabled(MC_POST_ENTITY_TAKE_DMG)) return std::nullopt; + + SettledHit settled = {&player, hit.damage, hit.countdown, hit.damageFlags}; + SettledHit* outer = std::exchange(settledHit, &settled); + bool isHurt = hook_inner_call([&] { return player.TakeDamage(hit.damage, hit.damageFlags, hit.source, hit.countdown); }); + settledHit = outer; + + bool isWhiteFire = hit.source.type == ENTITY_FIREPLACE && hit.source.variant == WHITE_FIREPLACE_VARIANT; + if (!isHurt || isWhiteFire) return isHurt; + + callback_notify(lua_engine_get(), {"MC_POST_ENTITY_TAKE_DMG", MC_POST_ENTITY_TAKE_DMG, player.type}, (Entity*)&player, + (int)std::round(settled.damage), settled.damageFlags, &hit.source, settled.countdown, + (EntityRef*)nullptr); + return isHurt; +} + +// Runs MC_POST_ENTITY_KILL, filtered by the entity's type, with the kill's source after it unless vanilla parity is on. +void entity_kill_post(Entity& entity, const EntityRef& source) +{ + LuaEngine& engine = lua_engine_get(); + if (repentogonOptions.isVanillaParity) return engine.PostEntityKill(&entity); + callback_notify(engine, {"PostEntityKill", MC_POST_ENTITY_KILL, entity.type}, &entity, &source); +} + +// Runs MC_PRE_ENTITY_THROW and MC_POST_ENTITY_THROW around Entity_Player::ThrowHeldEntity. A PRE Vector replaces the +// velocity. POST passes what was thrown, and is skipped after a PRE error. +// What was thrown, nothing when no mod added a function or this is the hook's own call. +std::optional entity_throw_hook(Entity_Player& player, Vector velocity) +{ + LuaEngine& engine = lua_engine_get(); + bool isPre = engine.is_callback_enabled(MC_PRE_ENTITY_THROW); + if (is_hook_inner() || (!isPre && !engine.is_callback_enabled(MC_POST_ENTITY_THROW))) return std::nullopt; + + bool isPostRun = true; + if (isPre) + { + CallbackRun pre = {"MC_PRE_ENTITY_THROW", MC_PRE_ENTITY_THROW, std::nullopt}; + isPostRun = callback_run(engine, pre, &player, player.heldEntity, velocity); + if (isPostRun) object_read(engine.state, velocity); + if (isPostRun) lua_pop(engine.state, 1); + } + + Entity* thrown = hook_inner_call([&] { return player.ThrowHeldEntity(velocity); }); + if (isPostRun) + callback_notify(engine, {"MC_POST_ENTITY_THROW", MC_POST_ENTITY_THROW, std::nullopt}, &player, thrown, velocity); + return thrown; +} + +// Runs MC_PRE_ENTITY_SET_COLOR and MC_POST_ENTITY_SET_COLOR around Entity::SetColor, filtered by the entity's type. +// PRE false skips the color and POST, a Color replaces it. Mods may also change the passed Color in place. +// Whether it ran SetColor itself. +bool entity_color_hook(Entity& entity, const ColorParams& params) +{ + LuaEngine& engine = lua_engine_get(); + bool isPre = engine.is_callback_enabled(MC_PRE_ENTITY_SET_COLOR); + if (is_hook_inner() || (!isPre && !engine.is_callback_enabled(MC_POST_ENTITY_SET_COLOR))) return false; + + lua_State* state = engine.state; + ColorMod color = params.color; + auto color_run = [&](CallbackRun run) { + return callback_run(engine, run, &entity, &color, params.duration, params.priority, params.isFadeout, + params.isShared); + }; + if (color_run({"MC_PRE_ENTITY_SET_COLOR", MC_PRE_ENTITY_SET_COLOR, entity.type})) + { + bool isCancelled = is_result_false(state); + object_read(state, color); + lua_pop(state, 1); + if (isCancelled) return true; + } + + hook_inner_call([&] { entity.SetColor(color, params.duration, params.priority, params.isFadeout, params.isShared); }); + if (color_run({"MC_POST_ENTITY_SET_COLOR", MC_POST_ENTITY_SET_COLOR, entity.type})) lua_pop(state, 1); + return true; +} diff --git a/src/repentogon/entities.h b/src/repentogon/entities.h new file mode 100644 index 0000000..6b6d95f --- /dev/null +++ b/src/repentogon/entities.h @@ -0,0 +1,28 @@ +#pragma once + +#include +#include + +struct Entity; +struct Entity_Player; +struct ColorParams; +struct EntityRef; +struct Vector; + +// A hit as Entity::TakeDamage and Entity_Player::TakeDamage hold it where MC_ENTITY_TAKE_DMG runs, which mods may +// change: its source, damage, the hearts it costs a player (none for others), countdown and flags. +struct DamageHit +{ + const EntityRef& source; + float& damage; + int* hearts; + int& countdown; + uint64_t& damageFlags; +}; + +bool entity_damage_pre(Entity& entity, DamageHit hit); +void entity_damage_post(Entity& entity, DamageHit hit); +std::optional player_damage_hook(Entity_Player& player, DamageHit hit); +void entity_kill_post(Entity& entity, const EntityRef& source); +std::optional entity_throw_hook(Entity_Player& player, Vector velocity); +bool entity_color_hook(Entity& entity, const ColorParams& params); diff --git a/src/repentogon/hud.cpp b/src/repentogon/hud.cpp new file mode 100644 index 0000000..3ef91e1 --- /dev/null +++ b/src/repentogon/hud.cpp @@ -0,0 +1,59 @@ +#include "repentogon/hud.h" +#include "entity/player/player.h" +#include "repentogon/callbacks.h" +#include + +// The recent items MC_PRE_HISTORYHUD_RENDER hides this render, by id without the golden trinket flag. +static std::set hiddenCollectibles; +static std::set hiddenTrinkets; + +// Adds the integer keys of a table field of the result on top of the stack to ids. +static void hidden_ids_read(lua_State* state, const char* key, std::set& ids) +{ + lua_getfield(state, -1, key); + if (lua_istable(state, -1)) + for (lua_pushnil(state); lua_next(state, -2); lua_pop(state, 1)) + if (lua_isinteger(state, -2)) ids.insert((int)lua_tointeger(state, -2)); + lua_pop(state, 1); +} + +// (ASMHud.cpp) Runs MC_PRE_HISTORYHUD_RENDER before the recent items draw. False skips them and POST, a table's +// HideCollectibles and HideTrinkets keys hide those items. Whether they draw. +bool history_render_pre(Vector at, bool isMini) +{ + LuaEngine& engine = lua_engine_get(); + lua_State* state = engine.state; + hiddenCollectibles.clear(); + hiddenTrinkets.clear(); + if (!callback_run(engine, {"PreHistoryHudRender", MC_PRE_HISTORYHUD_RENDER, std::nullopt}, LuaOpaque{}, at, isMini)) + return true; + + bool isDrawn = !is_result_false(state); + if (lua_istable(state, -1)) + { + hidden_ids_read(state, "HideCollectibles", hiddenCollectibles); + hidden_ids_read(state, "HideTrinkets", hiddenTrinkets); + } + lua_pop(state, 1); + return isDrawn; +} + +// Runs MC_POST_HISTORYHUD_RENDER after the recent items drew. +void history_render_post(Vector at, bool isMini) +{ + unfiltered_notify("PostHistoryHudRender", MC_POST_HISTORYHUD_RENDER, LuaOpaque{}, at, isMini); +} + +// Whether MC_PRE_HISTORYHUD_RENDER hid a recent item this render. +bool is_history_icon_hidden(const HistoryHUDItem& icon) +{ + return (icon.isTrinket ? hiddenTrinkets : hiddenCollectibles).contains(icon.historyId & TRINKET_ID_MASK); +} + +// Runs MC_POST_HISTORYHUD_RECOMPUTE, filtered by the slot, after a slot's items were rebuilt at once. +void history_recompute_post(int playerIndex, HistoryRebuild rebuild) +{ + if (rebuild != HISTORY_REBUILD_ICONS || playerIndex < 0 || playerIndex >= HISTORY_PLAYER_COUNT) return; + callback_notify(lua_engine_get(), {"PostHistoryHudRecompute", MC_POST_HISTORYHUD_RECOMPUTE, playerIndex}, + LuaOpaque{}, playerIndex); +} diff --git a/src/repentogon/hud.h b/src/repentogon/hud.h new file mode 100644 index 0000000..ef8266a --- /dev/null +++ b/src/repentogon/hud.h @@ -0,0 +1,8 @@ +#pragma once + +#include "ui/hud.h" + +bool history_render_pre(Vector at, bool isMini); +void history_render_post(Vector at, bool isMini); +bool is_history_icon_hidden(const HistoryHUDItem& icon); +void history_recompute_post(int playerIndex, HistoryRebuild rebuild); diff --git a/src/repentogon/items.cpp b/src/repentogon/items.cpp new file mode 100644 index 0000000..d5aa2d4 --- /dev/null +++ b/src/repentogon/items.cpp @@ -0,0 +1,496 @@ +#include "repentogon/items.h" +#include "entity/pickup/pickup.h" +#include "entity/player/active_items.h" +#include "entity/player/player.h" +#include "game/game.h" +#include "game/manager.h" +#include "level/level.h" +#include "level/room.h" +#include "repentogon/callbacks.h" +#include +#include + +constexpr int MORPH_KIND_SIZE = 3; +constexpr int MORPH_FULL_SIZE = 6; +constexpr int SELECTION_RNG_SHIFT = 3; +constexpr int COLLECTIBLE_ADD_SIZE = 5; +constexpr int PILL_EFFECT_KEPT = -1; +constexpr int BAG_INGREDIENT_LIMIT = 30; +constexpr int BAG_CALLBACK_ARGUMENTS = 5; + +// REPENTOGON's reimplementation of the deal and planetarium chances, its own numbers. +constexpr int COLLECTIBLE_MAGIC_8_BALL = 194; +constexpr int TRINKET_TELESCOPE_LENS = 152; +constexpr float DEAL_BASE = 0.01f; +constexpr float DEAL_PENTAGRAM = 0.1f; +constexpr float DEAL_SECOND_PENTAGRAM = 0.05f; +constexpr float DEAL_BLACK_CANDLE = 0.15f; +constexpr float DEAL_BELIAL = 0.125f; +constexpr float DEAL_REVELATIONS = 0.175f; +constexpr float DEAL_BUM_KILLED = 0.35f; +constexpr float DEAL_CONTRITION_BOSS = 0.15f; +constexpr float DEAL_UNHURT_BOSS = 0.35f; +constexpr float DEAL_CONTRITION_FLOOR = 0.4f; +constexpr float DEAL_UNHURT_FLOOR = 0.99f; +constexpr float DEAL_SHOPKEEPER_KILLED = 0.1f; +constexpr float DEAL_NUMBER_MAGNET = 0.1f; +constexpr float DEAL_SAUSAGE = 0.069f; +constexpr float DEAL_PER_WISP = 0.1f; +constexpr float DEAL_LAST_SCALE = 0.5f; +constexpr float DEAL_RECENT_SCALE = 0.25f; +constexpr float DEAL_GOAT_HEAD = 66.6f; +constexpr int DEAL_GREED_WAVE = 11; +constexpr float PLANETARIUM_BASE = 0.01f; +constexpr float PLANETARIUM_SKIPPED = 0.2f; +constexpr float PLANETARIUM_ITEM = 0.15f; +constexpr float PLANETARIUM_SAUSAGE = 0.069f; +constexpr float PLANETARIUM_LENS = 0.09f; + +// Runs MC_PRE_PICKUP_MORPH before a pickup morphs. A table of three replaces the kind, one of six the keep flags too. +// What MC_POST_PICKUP_MORPH gets after, nothing when a mod returned false to cancel the morph. +std::optional pickup_morph_pre(Entity_Pickup& pickup, PickupMorph morph) +{ + PickupMorphed morphed = {&pickup, pickup.type, pickup.variant, pickup.subtype, + morph.isKeepPrice, morph.isKeepSeed, morph.isIgnoreModifiers}; + LuaEngine& engine = lua_engine_get(); + lua_State* state = engine.state; + if (!callback_run(engine, {"PrePickupMorph", MC_PRE_PICKUP_MORPH, std::nullopt}, &pickup, morph.type, morph.variant, + morph.subType, morph.isKeepPrice, morph.isKeepSeed, morph.isIgnoreModifiers)) + return morphed; + + bool isCancelled = lua_isboolean(state, -1) && !lua_toboolean(state, -1); + size_t size = lua_istable(state, -1) ? lua_rawlen(state, -1) : 0; + if (size == MORPH_KIND_SIZE || size == MORPH_FULL_SIZE) + { + int key = 1; + for (int* kind : {&morph.type, &morph.variant, &morph.subType}) + { + lua_rawgeti(state, -1, key++); + *kind = (int)lua_tointeger(state, -1); + lua_pop(state, 1); + } + for (bool* flag : {&morph.isKeepPrice, &morph.isKeepSeed, &morph.isIgnoreModifiers}) + { + if (size == MORPH_KIND_SIZE) break; + lua_rawgeti(state, -1, key++); + *flag = lua_toboolean(state, -1); + lua_pop(state, 1); + } + } + lua_pop(state, 1); + if (isCancelled) return std::nullopt; + return morphed; +} + +// Runs MC_POST_PICKUP_MORPH once a pickup morphed. +void pickup_morph_post(const PickupMorphed& morphed) +{ + callback_notify(lua_engine_get(), {"PostPickupMorph", MC_POST_PICKUP_MORPH, std::nullopt}, morphed.pickup, + morphed.type, morphed.variant, morphed.subType, morphed.isKeepPrice, morphed.isKeepSeed, + morphed.isIgnoreModifiers); +} + +// REPENTOGON's MC_POST_PICKUP_SELECTION for the kind a pickup was given: also the kind Init asked for and an RNG of +// its seed. A table result replaces the variant and subtype, in that order, with each element that is not nil. +void pickup_selection_post(Entity_Pickup& pickup, PickupChoice& choice, const PickupChoice& requested) +{ + LuaEngine& engine = lua_engine_get(); + RNG rng = rng_make(requested.seed, SELECTION_RNG_SHIFT); + if (callback_run(engine, {"PostPickupSelection", MC_POST_PICKUP_SELECTION, std::nullopt}, &pickup, choice.variant, + choice.subType, requested.variant, requested.subType, &rng)) + elements_pop(engine.state, choice.variant, choice.subType); +} + +// Runs MC_PRE_RESTOCK_SHOP. Whether the shop restocks, false when a mod returned false. +bool shop_restock_pre(RestockKind kind) +{ + return boolean_run({"PreRestockShop", MC_PRE_RESTOCK_SHOP, std::nullopt}, true, kind == RESTOCK_PARTIAL); +} + +// Runs MC_POST_RESTOCK_SHOP once a shop restocked. +void shop_restock_post(RestockKind kind) +{ + callback_notify(lua_engine_get(), {"PostRestockShop", MC_POST_RESTOCK_SHOP, std::nullopt}, kind == RESTOCK_PARTIAL); +} + +// Runs MC_PRE_ADD_COLLECTIBLE before a player gets a collectible. An integer replaces it, a table each argument it +// holds a fitting value for, in AddCollectible's order. Whether the player still gets it, false when a mod returned +// false. +bool collectible_add_pre(Entity_Player& player, CollectibleAdd add) +{ + LuaEngine& engine = lua_engine_get(); + lua_State* state = engine.state; + if (!callback_run(engine, {"PreAddCollectible", MC_PRE_ADD_COLLECTIBLE, add.type}, add.type, add.charge, + add.isFirstTime, add.activeSlot, add.varData, &player)) + return true; + + bool isAdded = !(lua_isboolean(state, -1) && !lua_toboolean(state, -1)); + if (lua_isinteger(state, -1)) add.type = (int)lua_tointeger(state, -1); + else if (lua_istable(state, -1)) + { + std::array values = {&add.type, &add.charge, nullptr, &add.activeSlot, &add.varData}; + for (int key = 1; key <= COLLECTIBLE_ADD_SIZE; key++) + { + lua_rawgeti(state, -1, key); + if (!values[key - 1] && lua_isboolean(state, -1)) add.isFirstTime = lua_toboolean(state, -1); + else if (values[key - 1] && lua_isinteger(state, -1)) *values[key - 1] = (int)lua_tointeger(state, -1); + lua_pop(state, 1); + } + } + lua_pop(state, 1); + return isAdded; +} + +// Runs MC_POST_TRIGGER_COLLECTIBLE_ADDED, then MC_POST_ADD_COLLECTIBLE, once a player got a collectible. +void collectible_add_post(Entity_Player& player, CollectibleAdd add) +{ + collectible_added_post(player, add.type, add.isFirstTime, false); + callback_notify(lua_engine_get(), {"PostAddCollectible", MC_POST_ADD_COLLECTIBLE, add.type}, add.type, add.charge, + add.isFirstTime, add.activeSlot, add.varData, &player); +} + +// Runs MC_POST_TRIGGER_COLLECTIBLE_ADDED for a collectible a player got, or an item wisp lends it. +void collectible_added_post(Entity_Player& player, int type, bool isFirstTime, bool isWisp) +{ + CallbackRun run = {"PostTriggerCollectibleAdded", MC_POST_TRIGGER_COLLECTIBLE_ADDED, type}; + callback_notify(lua_engine_get(), run, &player, type, isFirstTime, isWisp); +} + +// Runs MC_POST_TRIGGER_COLLECTIBLE_REMOVED once a collectible's loss ran. +void collectible_removed_post(Entity_Player& player, int type, CollectibleRemoval removal) +{ + CallbackRun run = {"PostTriggerCollectibleRemoved", MC_POST_TRIGGER_COLLECTIBLE_REMOVED, type}; + callback_notify(lua_engine_get(), run, &player, type, removal == REMOVAL_KIND_FORM, removal == REMOVAL_KIND_WISP); +} + +// Runs MC_PRE_ADD_TRINKET before a player gets a trinket that exists. An integer replaces it, a table its type and +// isFirstTime. Whether the player still gets it, false when a mod returned false. +bool trinket_add_pre(Entity_Player& player, TrinketAdd add) +{ + LuaEngine& engine = lua_engine_get(); + lua_State* state = engine.state; + if (!g_manager->itemConfig.GetTrinket(add.type & TRINKET_ID_MASK)) return true; + if (!callback_run(engine, {"PreAddTrinket", MC_PRE_ADD_TRINKET, add.type}, &player, add.type, add.isFirstTime)) + return true; + + bool isAdded = !(lua_isboolean(state, -1) && !lua_toboolean(state, -1)); + if (lua_isinteger(state, -1)) add.type = (int)lua_tointeger(state, -1); + else if (lua_istable(state, -1)) + { + lua_rawgeti(state, -1, 1); + if (lua_isinteger(state, -1)) add.type = (int)lua_tointeger(state, -1); + lua_rawgeti(state, -2, 2); + if (lua_isboolean(state, -1)) add.isFirstTime = lua_toboolean(state, -1); + lua_pop(state, 2); + } + lua_pop(state, 1); + return isAdded; +} + +// Runs MC_POST_TRIGGER_TRINKET_ADDED once a trinket's pickup changes ran. REPENTOGON's innate trinkets are not ported. +void trinket_added_post(Entity_Player& player, uint32_t type, bool isFirstTime) +{ + CallbackRun run = {"PostTriggerTrinketAdded", MC_POST_TRIGGER_TRINKET_ADDED, (int)type}; + callback_notify(lua_engine_get(), run, &player, type, isFirstTime, false); +} + +// Runs MC_POST_TRIGGER_TRINKET_REMOVED once a trinket's loss ran. +void trinket_removed_post(Entity_Player& player, uint32_t type) +{ + CallbackRun run = {"PostTriggerTrinketRemoved", MC_POST_TRIGGER_TRINKET_REMOVED, (int)type}; + callback_notify(lua_engine_get(), run, &player, type, false); +} + +// MC_PRE_USE_ITEM before an active item is used: the game's own with vanilla parity, else REPENTOGON's, which a true +// prevents and a table prevents too, keeping the charge when its Discharge is false. What the use then does, nothing +// when it goes ahead. +std::optional active_use_pre(Entity_Player& player, const ActiveUse& request) +{ + LuaEngine& engine = lua_engine_get(); + lua_State* state = engine.state; + RNG* rng = &player.GetCollectibleRNG(request.item); + if (repentogonOptions.isVanillaParity) + { + LuaItemUse use = {.player = &player, .rng = rng, .activeSlot = request.slot, .collectibleType = request.item, + .customVarData = request.varData, .useFlags = request.flags}; + if (engine.PreUseItem(use)) return UseResult{}; + return std::nullopt; + } + if (!callback_run(engine, {"PreUseItem", MC_PRE_USE_ITEM, request.item}, request.item, rng, &player, request.flags, + request.slot, request.varData)) + return std::nullopt; + + std::optional prevented; + if (lua_isboolean(state, -1) && lua_toboolean(state, -1)) prevented = UseResult{}; + else if (lua_istable(state, -1)) + prevented = UseResult{.isDischarge = boolean_field_get(state, "Discharge").value_or(true)}; + lua_pop(state, 1); + return prevented; +} + +// Runs MC_POST_USE_ITEM once an active item was used, with whether its charge goes and whether it is removed. +void active_use_post(Entity_Player& player, const ActiveUse& request, UseResult result) +{ + CallbackRun run = {"PostUseItem", MC_POST_USE_ITEM, request.item}; + callback_notify(lua_engine_get(), run, request.item, &player.GetCollectibleRNG(request.item), &player, request.flags, + request.slot, request.varData, result.isDischarge, result.isRemove); +} + +// Runs MC_POST_DISCHARGE_ACTIVE_ITEM once a slot was discharged, filtered by the item it holds now. +void active_discharge_post(Entity_Player& player, uint32_t slot, bool isRemoved) +{ + if (slot >= (uint32_t)ACTIVE_SLOT_COUNT) return; + + int item = player.activeItems[slot].item; + CallbackRun run = {"PostDischargeActiveItem", MC_POST_DISCHARGE_ACTIVE_ITEM, item}; + callback_notify(lua_engine_get(), run, item, isRemoved, &player, slot); +} + +// Runs MC_PRE_USE_CARD. Whether a mod cancelled the use: any boolean does, as REPENTOGON's hook reads it. +bool card_use_is_cancelled(Entity_Player& player, int card, uint32_t useFlags) +{ + LuaEngine& engine = lua_engine_get(); + if (!callback_run(engine, {"PreUseCard", MC_PRE_USE_CARD, card}, card, &player, useFlags)) return false; + + bool isCancelled = lua_isboolean(engine.state, -1); + lua_pop(engine.state, 1); + return isCancelled; +} + +// Runs MC_PRE_USE_PILL. Whether a mod cancelled the use with true. +bool pill_use_is_cancelled(Entity_Player& player, int pillEffect, int pillColor, uint32_t useFlags) +{ + CallbackRun run = {"PreUsePill", MC_PRE_USE_PILL, pillEffect}; + return boolean_run(run, false, pillEffect, pillColor, &player, useFlags); +} + +// REPENTOGON's MC_USE_PILL, without vanilla parity, once a pill was used: also its color. +void pill_use_post(Entity_Player& player, int pillEffect, int pillColor, uint32_t useFlags) +{ + if (repentogonOptions.isVanillaParity) return; + + CallbackRun run = {"PostUsePillEffect", MC_USE_PILL, pillEffect}; + callback_notify(lua_engine_get(), run, pillEffect, &player, useFlags, pillColor); +} + +// REPENTOGON's MC_GET_PILL_EFFECT, without vanilla parity, once a pill color's effect was picked: also the player. The +// effect a mod chose, other than -1, or the picked one. +int pill_effect_post(int pillEffect, uint32_t pillColor, Entity_Player* player) +{ + CallbackRun run = {"GetPillEffect", MC_GET_PILL_EFFECT, pillEffect}; + int chosen = callback_integer_run(lua_engine_get(), run, PILL_EFFECT_KEPT, pillEffect, (int)(pillColor & PILL_COLOR_MASK), + player); + return chosen != PILL_EFFECT_KEPT ? chosen : pillEffect; +} + +// Runs a chance step's callback, whose number replaces the chance. +static float chance_step_run(const char* name, int callback, float chance) +{ + LuaEngine& engine = lua_engine_get(); + if (!callback_run(engine, {name, callback, std::nullopt}, chance)) return chance; + + chance = (float)lua_tonumber(engine.state, -1); + lua_pop(engine.state, 1); + return chance; +} + +// Runs a chance step's callback, whose result replaces the chance when it is a number. +static float numeric_step_run(const char* name, int callback, float chance) +{ + LuaEngine& engine = lua_engine_get(); + if (!callback_run(engine, {name, callback, std::nullopt}, chance)) return chance; + + if (lua_isnumber(engine.state, -1)) chance = (float)lua_tonumber(engine.state, -1); + lua_pop(engine.state, 1); + return chance; +} + +// Whether any of the callbacks from first to last runs. +static bool is_any_enabled(int first, int last) +{ + for (int callback = first; callback <= last; callback++) + if (lua_engine_get().is_callback_enabled(callback)) return true; + return false; +} + +// REPENTOGON's deal chance once a mod changes it: its reimplementation of the chance in steps, MC_PRE_DEVIL_APPLY_ITEMS +// after the base, MC_PRE_DEVIL_APPLY_STAGE_PENALTY deciding the recent deal's cut, MC_PRE_DEVIL_APPLY_SPECIAL_ITEMS +// before Goat Head and Eucharist and MC_POST_DEVIL_CALCULATE before Greed's waves. The game's own chance without +// those callbacks and in dailies. +float devil_chance_hook(Room& room, float chance) +{ + Game& game = *g_game; + if (game.dailyChallenge.id || !is_any_enabled(MC_PRE_DEVIL_APPLY_ITEMS, MC_POST_DEVIL_CALCULATE)) return chance; + + PlayerManager& players = game.playerManager; + auto is_owned = [&](int collectible) { return players.FirstCollectibleOwner(collectible, LAZARUS_SHARE_CHECK); }; + auto is_flagged = [&](int flag) { return (game.levelStateFlags >> flag & 1) != 0; }; + bool isContrition = is_owned(COLLECTIBLE_ACT_OF_CONTRITION); + RoomDescriptor* descriptor = game.GetRoomByIdx(game.currentRoomIdx); + chance = 0; + if (!game.isDevilRoomDisabled) + { + chance = chance_step_run("PreDevilApplyItems", MC_PRE_DEVIL_APPLY_ITEMS, chance + DEAL_BASE); + if (is_owned(COLLECTIBLE_PENTAGRAM)) chance += DEAL_PENTAGRAM; + if (players.GetNumCollectibles(COLLECTIBLE_PENTAGRAM) > 1) chance += DEAL_SECOND_PENTAGRAM; + if (is_owned(COLLECTIBLE_BLACK_CANDLE)) chance += DEAL_BLACK_CANDLE; + if (is_owned(COLLECTIBLE_BOOK_OF_BELIAL) || is_owned(COLLECTIBLE_BOOK_OF_BELIAL_PASSIVE)) chance += DEAL_BELIAL; + if (is_owned(COLLECTIBLE_BOOK_OF_REVELATIONS)) chance += DEAL_REVELATIONS; + if (is_flagged(LEVEL_STATE_BUM_KILLED)) chance += DEAL_BUM_KILLED; + if (descriptor && descriptor->listIndex == game.lastBossRoomListIdx && game.room->isRedHeartDamaged) + chance += isContrition ? DEAL_CONTRITION_BOSS : 0; + else chance += DEAL_UNHURT_BOSS; + if (is_flagged(LEVEL_STATE_REDHEART_DAMAGED)) chance += isContrition ? DEAL_CONTRITION_FLOOR : 0; + else chance += DEAL_UNHURT_FLOOR; + if (is_flagged(LEVEL_STATE_SHOPKEEPER_KILLED)) chance += DEAL_SHOPKEEPER_KILLED; + if (players.AnyoneHasTrinket(TRINKET_NUMBER_MAGNET)) chance += DEAL_NUMBER_MAGNET; + if (is_owned(COLLECTIBLE_SAUSAGE)) chance += DEAL_SAUSAGE; + chance += DEAL_PER_WISP * (float)std::ranges::count_if(game.room->entityList.wispEL, [](Entity* wisp) { + return wisp->subtype == COLLECTIBLE_SATANIC_BIBLE; + }); + + CallbackRun penalty = {"PreDevilApplyStagePenalty", MC_PRE_DEVIL_APPLY_STAGE_PENALTY, std::nullopt}; + bool isPenalized = callback_boolean_get(penalty).value_or(true); + if (game.lastDevilRoomStage != 0 && isPenalized) + { + bool isAltStage = game.stageType == STAGETYPE_REPENTANCE || game.stageType == STAGETYPE_REPENTANCE_B; + uint32_t sinceDeal = (uint32_t)game.stage + (isAltStage ? 1 : 0) - (uint32_t)game.lastDevilRoomStage; + if (sinceDeal == 0 || sinceDeal == 1) chance *= DEAL_RECENT_SCALE; + else if (sinceDeal == 2) chance *= DEAL_LAST_SCALE; + } + } + chance = chance_step_run("PreDevilApplySpecialItems", MC_PRE_DEVIL_APPLY_SPECIAL_ITEMS, chance); + if (is_owned(COLLECTIBLE_GOAT_HEAD) || room.temporaryEffects.HasCollectibleEffect(COLLECTIBLE_GOAT_HEAD)) + chance = DEAL_GOAT_HEAD; + if (is_owned(COLLECTIBLE_EUCHARIST)) chance = 1; + chance = chance_step_run("PostDevilCalculate", MC_POST_DEVIL_CALCULATE, chance); + if (game.IsGreedMode()) + chance = game.greedModeWave < DEAL_GREED_WAVE + (game.difficulty == DIFFICULTY_GREEDIER ? 1 : 0) ? 0 : 1; + return chance; +} + +// REPENTOGON's planetarium chance: without vanilla parity none when Telescope Lens is locked or the challenge has no +// treasure rooms. Once a mod changes it, its reimplementation of the chance in steps: MC_PRE_PLANETARIUM_APPLY_ +// STAGE_PENALTY, PLANETARIUM_PENALTY and TREASURE_PENALTY deciding the cuts, ITEMS before the items, TELESCOPE_LENS +// before the lens and MC_POST_PLANETARIUM_CALCULATE last. The game's own chance in dailies. +float planetarium_chance_hook(Level& level, float chance) +{ + Game& game = *g_game; + if (game.dailyChallenge.id) return chance; + if (!repentogonOptions.isVanillaParity) + { + if (!g_manager->itemConfig.GetTrinket(TRINKET_TELESCOPE_LENS)->IsAvailable(UNLOCK_CHECKED)) return 0; + if (game.challenge != 0 && game.GetChallengeParams().roomset.contains(ROOM_TREASURE)) return 0; + } + if (!is_any_enabled(MC_PRE_PLANETARIUM_APPLY_STAGE_PENALTY, MC_POST_PLANETARIUM_CALCULATE)) return chance; + + PlayerManager& players = game.playerManager; + auto is_owned = [&](int collectible) { return players.FirstCollectibleOwner(collectible, LAZARUS_SHARE_CHECK); }; + bool isLens = players.AnyoneHasTrinket(TRINKET_TELESCOPE_LENS); + bool isAltStage = level.stageType == STAGETYPE_REPENTANCE || level.stageType == STAGETYPE_REPENTANCE_B; + int stage = (int)level.stage + (isAltStage ? 1 : 0); + chance = PLANETARIUM_BASE; + + CallbackRun stagePenalty = {"PrePlanetariumApplyStagePenalty", MC_PRE_PLANETARIUM_APPLY_STAGE_PENALTY, std::nullopt}; + bool isStagePenalized = callback_boolean_get(stagePenalty).value_or(true); + if (isStagePenalized && ((stage > STAGE_DEPTHS_II && !isLens) || stage > STAGE_WOMB_II)) return 0; + + CallbackRun visitPenalty = {"PrePlanetariumApplyPlanetariumPenalty", MC_PRE_PLANETARIUM_APPLY_PLANETARIUM_PENALTY, + std::nullopt}; + bool isVisitBypassed = !callback_boolean_get(visitPenalty).value_or(true); + if (game.planetariumsVisited == 0 || isVisitBypassed) + { + LuaEngine& engine = lua_engine_get(); + int treasureVisited = game.treasureRoomsVisited; + bool isTreasureBypassed = false; + CallbackRun treasurePenalty = {"PrePlanetariumApplyTreasurePenalty", MC_PRE_PLANETARIUM_APPLY_TREASURE_PENALTY, + std::nullopt}; + if (callback_run(engine, treasurePenalty, treasureVisited)) + { + if (lua_isinteger(engine.state, -1)) treasureVisited = (int)lua_tointeger(engine.state, -1); + else if (lua_isboolean(engine.state, -1) && !lua_toboolean(engine.state, -1)) + { + isTreasureBypassed = true; + treasureVisited = 0; + } + lua_pop(engine.state, 1); + } + if (treasureVisited < stage - 1 || isTreasureBypassed) + { + chance += (float)(stage - treasureVisited - 1) * PLANETARIUM_SKIPPED; + if (is_owned(COLLECTIBLE_CRYSTAL_BALL)) chance += 1; + } + + chance = numeric_step_run("PrePlanetariumApplyItems", MC_PRE_PLANETARIUM_APPLY_ITEMS, chance); + if (is_owned(COLLECTIBLE_MAGIC_8_BALL)) chance += PLANETARIUM_ITEM; + if (is_owned(COLLECTIBLE_CRYSTAL_BALL)) chance += PLANETARIUM_ITEM; + if (is_owned(COLLECTIBLE_SAUSAGE)) chance += PLANETARIUM_SAUSAGE; + if (isLens) chance += PLANETARIUM_ITEM; + } + chance = numeric_step_run("PrePlanetariumApplyTelescopeLens", MC_PRE_PLANETARIUM_APPLY_TELESCOPE_LENS, chance); + if (isLens) chance += PLANETARIUM_LENS; + chance = numeric_step_run("PostPlanetariumCalculate", MC_POST_PLANETARIUM_CALCULATE, chance); + return std::min(chance, 1.0f); +} + +// Runs MC_TRY_ADD_TO_BAG_OF_CRAFTING once the bag chose a pickup's ingredients (none for one it cannot take). A table +// of up to eight replaces them up to its first one out of range, false refuses the pickup. What goes in the bag, +// nothing when it does not take the pickup. +std::optional bag_ingredients_hook(Entity_Player& player, Entity_Pickup& pickup, + std::optional> ingredients) +{ + BagIngredients chosen{}; + int count = 0; + for (uint8_t ingredient : ingredients.value_or(std::array{})) + { + if (ingredient == 0) break; + chosen[count++] = ingredient; + } + + LuaEngine& engine = lua_engine_get(); + lua_State* state = engine.state; + if (engine.is_callback_enabled(MC_TRY_ADD_TO_BAG_OF_CRAFTING)) + { + lua_rawgeti(state, LUA_REGISTRYINDEX, engine.runCallbackRef); + lua_pushinteger(state, MC_TRY_ADD_TO_BAG_OF_CRAFTING); + lua_pushinteger(state, pickup.variant); + lua_push(state, &player); + lua_push(state, &pickup); + lua_createtable(state, count, 0); + for (int i = 0; i < count; i++) + { + lua_pushinteger(state, chosen[i]); + lua_rawseti(state, -2, i + 1); + } + bool isRun = lua_pcall(state, BAG_CALLBACK_ARGUMENTS, 1, 0) == LUA_OK; + if (!isRun) lua_error_log(state, "TryAddToBagOfCrafting"); + else + { + bool isRefused = lua_isboolean(state, -1) && !lua_toboolean(state, -1); + if (lua_istable(state, -1)) + { + chosen = {}; + int size = (int)lua_rawlen(state, -1); + for (int i = 0; i < (int)chosen.size() && i < size; i++) + { + lua_rawgeti(state, -1, i + 1); + int value = (int)lua_tointeger(state, -1); + lua_pop(state, 1); + if (value <= 0 || value >= BAG_INGREDIENT_LIMIT) break; + chosen[i] = (uint8_t)value; + } + } + lua_pop(state, 1); + if (isRefused) return std::nullopt; + } + } + if (chosen[0] == 0) return std::nullopt; + return chosen; +} + +// Runs MC_POST_ADD_TO_BAG_OF_CRAFTING once the bag took a pickup. +void bag_add_post(Entity_Player& player, Entity_Pickup& pickup) +{ + CallbackRun run = {"PostAddToBagOfCrafting", MC_POST_ADD_TO_BAG_OF_CRAFTING, pickup.variant}; + callback_notify(lua_engine_get(), run, &player, &pickup); +} diff --git a/src/repentogon/items.h b/src/repentogon/items.h new file mode 100644 index 0000000..9b4eb62 --- /dev/null +++ b/src/repentogon/items.h @@ -0,0 +1,103 @@ +#pragma once + +#include +#include +#include + +struct Entity_Pickup; +struct Entity_Player; +struct PickupChoice; +struct ActiveUse; +struct UseResult; +class Level; +class Room; + +// How a collectible left for MC_POST_TRIGGER_COLLECTIBLE_REMOVED: taken counting towards its form or not (Entity_Player:: +// RemoveCollectible's choice), or its item wisp gone. +enum CollectibleRemoval +{ + REMOVAL_KIND_FORM, + REMOVAL_KIND_KEEP_FORM, + REMOVAL_KIND_WISP +}; + +// The removal TriggerCollectibleRemoved reports next, which it puts back to a removal from the form. +inline CollectibleRemoval collectibleRemoval = REMOVAL_KIND_FORM; + +// Whether the familiars a continued run saved are coming back, whose item wisps were added before. +inline bool isFamiliarsRestoring = false; + +// A collectible being given as MC_PRE_ADD_COLLECTIBLE may change it: Entity_Player::AddCollectible's arguments. +struct CollectibleAdd +{ + int& type; + int& charge; + bool& isFirstTime; + int& activeSlot; + int& varData; +}; + +// A trinket being given as MC_PRE_ADD_TRINKET may change it: Entity_Player::AddTrinket's arguments. +struct TrinketAdd +{ + int& type; + bool& isFirstTime; +}; + +// The ingredients a pickup puts in the bag of crafting, REPENTOGON's up to eight, none past the first 0. +using BagIngredients = std::array; + +// Which restock MC_PRE and MC_POST_RESTOCK_SHOP see: Restock's after a purchase, or a full one. +enum RestockKind +{ + RESTOCK_FULL, + RESTOCK_PARTIAL +}; + +// A pickup morph as MC_PRE_PICKUP_MORPH may change it: Entity_Pickup::Morph's arguments. +struct PickupMorph +{ + int& type; + int& variant; + int& subType; + bool& isKeepPrice; + bool& isKeepSeed; + bool& isIgnoreModifiers; +}; + +// What MC_POST_PICKUP_MORPH gets: the pickup, its kind before the morph and the keep flags it was asked with. +struct PickupMorphed +{ + Entity_Pickup* pickup; + int type; + int variant; + int subType; + bool isKeepPrice; + bool isKeepSeed; + bool isIgnoreModifiers; +}; + +std::optional active_use_pre(Entity_Player& player, const ActiveUse& request); +void active_use_post(Entity_Player& player, const ActiveUse& request, UseResult result); +void active_discharge_post(Entity_Player& player, uint32_t slot, bool isRemoved); +bool card_use_is_cancelled(Entity_Player& player, int card, uint32_t useFlags); +bool pill_use_is_cancelled(Entity_Player& player, int pillEffect, int pillColor, uint32_t useFlags); +std::optional bag_ingredients_hook(Entity_Player& player, Entity_Pickup& pickup, + std::optional> ingredients); +void bag_add_post(Entity_Player& player, Entity_Pickup& pickup); +float devil_chance_hook(Room& room, float chance); +float planetarium_chance_hook(Level& level, float chance); +int pill_effect_post(int pillEffect, uint32_t pillColor, Entity_Player* player); +void pill_use_post(Entity_Player& player, int pillEffect, int pillColor, uint32_t useFlags); +bool collectible_add_pre(Entity_Player& player, CollectibleAdd add); +void collectible_add_post(Entity_Player& player, CollectibleAdd add); +void collectible_added_post(Entity_Player& player, int type, bool isFirstTime, bool isWisp); +void collectible_removed_post(Entity_Player& player, int type, CollectibleRemoval removal); +bool trinket_add_pre(Entity_Player& player, TrinketAdd add); +void trinket_added_post(Entity_Player& player, uint32_t type, bool isFirstTime); +void trinket_removed_post(Entity_Player& player, uint32_t type); +std::optional pickup_morph_pre(Entity_Pickup& pickup, PickupMorph morph); +void pickup_morph_post(const PickupMorphed& morphed); +bool shop_restock_pre(RestockKind kind); +void shop_restock_post(RestockKind kind); +void pickup_selection_post(Entity_Pickup& pickup, PickupChoice& choice, const PickupChoice& requested); diff --git a/src/repentogon/level.cpp b/src/repentogon/level.cpp new file mode 100644 index 0000000..1a34a49 --- /dev/null +++ b/src/repentogon/level.cpp @@ -0,0 +1,281 @@ +#include "repentogon/level.h" +#include "classes.h" +#include "engine/platform.h" +#include "game/game.h" +#include "level/generator.h" +#include "level/grid/grid_entity.h" +#include "level/room.h" +#include "level/room_config.h" +#include "repentogon/callbacks.h" + +constexpr int LEVEL_STAGE_LAST = 14; +constexpr int GREED_STAGE_LAST = 7; +constexpr int STAGE_TYPE_REMOVED = 3; +constexpr int STAGE_TYPE_LAST = 5; + +bool isUpdateHeld = false; + +// Whether a grid entity spawn runs inside another's override, which skips its MC_PRE_GRID_ENTITY_SPAWN. +static bool isGridSpawnNested = false; + +// Reads the integer elements 1 up of the table on top of the stack into values, each as lua_tointeger does (0 for +// what is not a number), and pops it. +template +static void integers_pop(lua_State* state, T&... values) +{ + int key = 1; + ((lua_rawgeti(state, -1, key++), values = (T)lua_tointeger(state, -1), lua_pop(state, 1)), ...); + lua_pop(state, 1); +} + +// The table on top of the stack's elements 1 up that are integers, set into values. Others keep theirs. +template +static void integers_read(lua_State* state, T&... values) +{ + int key = 1; + ((lua_rawgeti(state, -1, key++), lua_isinteger(state, -1) ? (void)(values = (T)lua_tointeger(state, -1)) : (void)0, + lua_pop(state, 1)), + ...); +} + +// Runs MC_PRE_UPDATE before the run's timers, rooms and players update. Whether a mod skipped the update. A skipped +// update still drops the entities that stopped existing, sorts the draw order and updates the HUD, and the run reads +// as paused until the next. +bool game_update_is_skipped() +{ + Game& game = *g_game; + isUpdateHeld = true; + bool isSkipped = callback_boolean_get({"PreUpdate", MC_PRE_UPDATE, std::nullopt}).value_or(false); + if (isSkipped) + { + game.room->entityList.removed_drop(); + game.room->entityList.sort_by_render_z(); + game.hud.PostUpdate(); + } + isUpdateHeld = isSkipped; + return isSkipped; +} + +// Runs MC_PRE_CHALLENGE_DONE with the first player. Whether the challenge still counts as won, false when a mod +// returned false. +// REPENTOGON passes the save data as the player, which no script can use. This passes the first player. +bool challenge_done_pre(int challenge) +{ + Entity_Player* player = g_game ? g_game->playerManager.GetPlayer(0) : nullptr; + return boolean_run({"PreChallengeDone", MC_PRE_CHALLENGE_DONE, challenge}, true, challenge, player); +} + +// Runs MC_PRE_CHANGE_ROOM. A table of two integers sends the players to that room and dimension instead when it +// exists, and the door they leave by is forgotten. +void change_room_pre(int& roomIdx, int& dimension) +{ + LuaEngine& engine = lua_engine_get(); + lua_State* state = engine.state; + if (!callback_run(engine, {"PreChangeRoom", MC_PRE_CHANGE_ROOM, std::nullopt}, roomIdx, dimension)) return; + if (!lua_istable(state, -1) || lua_rawlen(state, -1) != 2) return lua_pop(state, 1); + + int changedIdx = 0; + int changedDimension = 0; + integers_pop(state, changedIdx, changedDimension); + RoomDescriptor* desc = g_game->GetRoomByIdx(changedIdx, changedDimension); + if (!desc || !desc->data) + { + log_printf(LOG_INFO, "MC_PRE_CHANGE_ROOM: Tried to switch to room with Idx %d and dimension %d, but it doesn't " + "exist\n", changedIdx, changedDimension); + return; + } + g_game->leaveDoor = -1; + roomIdx = changedIdx; + dimension = changedDimension; +} + +// Runs MC_PRE_LEVEL_SELECT. A table of a stage and a stage type in range (1 to 7 in Greed, 1 to 14 otherwise, a type +// of 0 to 5 but 3) replaces the stage the floor moves to. Another table is logged and ignored, anything else ignored. +void level_select_pre(int& stage, int& stageType) +{ + LuaEngine& engine = lua_engine_get(); + lua_State* state = engine.state; + if (!callback_run(engine, {"PreLevelSelect", MC_PRE_LEVEL_SELECT, std::nullopt}, stage, stageType)) return; + if (!lua_istable(state, -1)) return lua_pop(state, 1); + lua_len(state, -1); + int length = (int)lua_tointeger(state, -1); + lua_pop(state, 1); + if (length != 2) + { + log_printf(LOG_INFO, "MC_PRE_LEVEL_SELECT: Invalid return value, table contains %d elements, expected 2\n", + length); + return lua_pop(state, 1); + } + + int selectedStage = 0; + int selectedType = 0; + integers_pop(state, selectedStage, selectedType); + bool isGreed = g_game->difficulty == DIFFICULTY_GREED || g_game->difficulty == DIFFICULTY_GREEDIER; + int lastStage = isGreed ? GREED_STAGE_LAST : LEVEL_STAGE_LAST; + if (selectedStage < 1 || selectedStage > lastStage) + return log_printf(LOG_INFO, "MC_PRE_LEVEL_SELECT: Invalid level stage, received %d, should be in range " + "[1; %d]\n", selectedStage, lastStage); + if (selectedType < 0 || selectedType == STAGE_TYPE_REMOVED || selectedType > STAGE_TYPE_LAST) + return log_printf(LOG_INFO, "MC_PRE_LEVEL_SELECT: Invalid stage type, received value %d, expected 0, 1, 2, 4 " + "or 5\n", selectedType); + stage = selectedStage; + stageType = selectedType; +} + +// Runs MC_PRE_LEVEL_PLACE_ROOM for a layout slot about to get a room. A room config a mod returned replaces the room +// when its shape matches and it has every door the slot needs. The API has no LevelGeneratorRoom yet, so the slot is +// passed as an opaque userdata. +RoomConfig_Room* place_room_pre(const LevelGenerator_Room& slot, RoomConfig_Room* config, uint32_t seed) +{ + LuaEngine& engine = lua_engine_get(); + lua_State* state = engine.state; + CallbackRun run = {"PreLevelPlaceRoom", MC_PRE_LEVEL_PLACE_ROOM, std::nullopt}; + if (!callback_run(engine, run, LuaOpaque{}, config, seed)) return config; + + auto* other = (RoomConfig_Room*)lua_object_test(state, -1, LUA_CLASS_ROOM_CONFIG_ROOM); + if (lua_isuserdata(state, -1) && !other) + log_printf(LOG_WARN, "Invalid userdata returned in MC_PRE_LEVEL_PLACE_ROOM\n"); + lua_pop(state, 1); + if (!other || !config) return config; + + bool isFit = other->shape == config->shape; + if (!isFit) + log_printf(LOG_WARN, "MC_PRE_LEVEL_PLACE_ROOM: Shape mismatch. Original = %d, override = %d\n", config->shape, + other->shape); + for (int i = 0; i < DOOR_SLOT_COUNT; i++) + { + if (!(slot.doors & 1u << i) || (other->doors & 1u << i)) continue; + log_printf(LOG_WARN, "MC_PRE_LEVEL_PLACE_ROOM: Required doors mismatch. Slot %d (mask = %d) required\n", i, + 1 << i); + isFit = false; + } + return isFit ? other : config; +} + +// Runs MC_PRE_SELECT_AMBUSH_WAVE or MC_PRE_SELECT_GREED_WAVE for the room a wave was drawn from. A room config of the +// same shape a mod returned replaces it. +RoomConfig_Room* wave_room_select(RoomConfig_Room* room, int callback, uint32_t seed) +{ + LuaEngine& engine = lua_engine_get(); + lua_State* state = engine.state; + const char* name = callback == MC_PRE_SELECT_GREED_WAVE ? "MC_PRE_SELECT_GREED_WAVE" : "MC_PRE_SELECT_AMBUSH_WAVE"; + if (!callback_run(engine, {name, callback, std::nullopt}, room, seed)) return room; + + auto* other = (RoomConfig_Room*)lua_object_test(state, -1, LUA_CLASS_ROOM_CONFIG_ROOM); + if (lua_isuserdata(state, -1) && !other) log_printf(LOG_WARN, "Invalid userdata returned in %s\n", name); + lua_pop(state, 1); + if (!other || other == room || !room) return room; + if (other->shape == room->shape) return other; + + log_printf(LOG_WARN, "%s: Shape mismatch. Original = %d, override = %d\n", name, room->shape, other->shape); + return room; +} + +// Runs MC_POST_BACKWARDS_ROOM_RESTORE for a room of the Ascent restored from its stage's save, named by its slot as +// MC_POST_BACKWARDS_ROOM_SAVE names it ("boss_0", "treasure_1" ...). +void backwards_room_restore_post(const BackwardsStageDesc& saved, RoomDescriptor& desc, const char* key, int index) +{ + int stage = (int)(&saved - g_game->backwardsStages.data()) + 1; + std::string slot = std::string(key) + "_" + std::to_string(index); + CallbackRun run = {"PostBackwardsRoomRestore", MC_POST_BACKWARDS_ROOM_RESTORE, std::nullopt}; + callback_notify(lua_engine_get(), run, stage, &desc, slot); +} + +// Runs MC_PRE_GRID_ENTITY_SPAWN for a grid entity about to spawn. A table result changes its type, variant, varData +// and seed (each that is an integer), a GridEntityDesc spawns that instead, and false cancels it. The spawn's result +// when it no longer goes on as asked. +std::optional grid_spawn_pre(Room& room, int gridIndex, GridEntityType& type, int& variant, uint32_t& seed, + int& varData) +{ + bool isNested = std::exchange(isGridSpawnNested, false); + LuaEngine& engine = lua_engine_get(); + lua_State* state = engine.state; + CallbackRun run = {"PreGridEntitySpawn", MC_PRE_GRID_ENTITY_SPAWN, (int)type}; + if (isNested || !callback_run(engine, run, (int)type, variant, varData, gridIndex, seed, (GridEntityDesc*)nullptr)) + return std::nullopt; + + std::optional result; + int changedType = type; + if (lua_istable(state, -1)) integers_read(state, changedType, variant, varData, seed); + else if (auto* desc = (GridEntityDesc*)lua_object_test(state, -1, LUA_CLASS_GRID_ENTITY_DESC)) + { + isGridSpawnNested = true; + GridEntityDesc copy = *desc; + lua_pop(state, 1); + return room_grid_desc_spawn(room, gridIndex, copy); + } + else if (lua_isboolean(state, -1) && !lua_toboolean(state, -1)) result = false; + type = (GridEntityType)changedType; + lua_pop(state, 1); + return result; +} + +// Runs MC_PRE_GRID_ENTITY_SPAWN for a grid entity about to spawn from a description, passed as the last argument. A +// GridEntityDesc result replaces it, a table spawns by type, variant, varData and seed instead, and false cancels it. +// The spawn's result when it no longer goes on as asked. +std::optional grid_desc_spawn_pre(Room& room, int gridIndex, GridEntityDesc& desc) +{ + bool isNested = std::exchange(isGridSpawnNested, false); + LuaEngine& engine = lua_engine_get(); + lua_State* state = engine.state; + CallbackRun run = {"PreGridEntitySpawn", MC_PRE_GRID_ENTITY_SPAWN, desc._type}; + if (isNested || + !callback_run(engine, run, desc._type, desc._variant, desc._varData, gridIndex, desc._spawnSeed, &desc)) + return std::nullopt; + + std::optional result; + if (auto* changed = (GridEntityDesc*)lua_object_test(state, -1, LUA_CLASS_GRID_ENTITY_DESC)) desc = *changed; + else if (lua_istable(state, -1)) + { + int type = desc._type; + int variant = desc._variant; + int varData = desc._varData; + uint32_t seed = desc._spawnSeed; + integers_read(state, type, variant, varData, seed); + isGridSpawnNested = true; + result = room.SpawnGridEntity(gridIndex, (GridEntityType)type, variant, seed, varData); + } + else if (lua_isboolean(state, -1) && !lua_toboolean(state, -1)) result = false; + lua_pop(state, 1); + return result; +} + +// Runs MC_PRE_ROOM_GRID_ENTITY_SPAWN for a room layout's grid entity about to spawn. A table result replaces its type, +// variant, varData and seed. Whether it still spawns, false when a mod returned false. +bool room_grid_spawn_pre(GridEntityType& type, int& variant, int& varData, int gridIndex, uint32_t& seed) +{ + LuaEngine& engine = lua_engine_get(); + lua_State* state = engine.state; + CallbackRun run = {"PreRoomGridEntitySpawn", MC_PRE_ROOM_GRID_ENTITY_SPAWN, (int)type}; + if (!callback_run(engine, run, (int)type, variant, varData, gridIndex, seed)) return true; + + bool isSpawned = !lua_isboolean(state, -1) || lua_toboolean(state, -1); + if (!lua_istable(state, -1)) lua_pop(state, 1); + else + { + int changedType = 0; + integers_pop(state, changedType, variant, varData, seed); + type = (GridEntityType)changedType; + } + return isSpawned; +} + +// Runs MC_PRE_GRID_HURT, filtered by the grid entity's type. An integer of 0 or more replaces the damage. Whether the +// hurt goes on, false when a mod returned false. +bool grid_hurt_pre(GridEntity& grid, int& damage, const EntityRef& source) +{ + LuaEngine& engine = lua_engine_get(); + lua_State* state = engine.state; + if (!callback_run(engine, {"PreGridHurt", MC_PRE_GRID_HURT, (int)grid.type}, &grid, damage, &source)) return true; + + bool isHurt = !lua_isboolean(state, -1) || lua_toboolean(state, -1); + if (lua_isinteger(state, -1) && lua_tointeger(state, -1) >= 0) damage = (int)lua_tointeger(state, -1); + lua_pop(state, 1); + return isHurt; +} + +// Runs MC_POST_GRID_HURT, filtered by the grid entity's type. +void grid_hurt_post(GridEntity& grid, int damage, const EntityRef& source) +{ + callback_notify(lua_engine_get(), {"PostGridHurt", MC_POST_GRID_HURT, (int)grid.type}, &grid, damage, &source); +} diff --git a/src/repentogon/level.h b/src/repentogon/level.h new file mode 100644 index 0000000..4b5a37a --- /dev/null +++ b/src/repentogon/level.h @@ -0,0 +1,45 @@ +#pragma once + +#include +#include + +class Room; +struct BackwardsStageDesc; +struct EntityRef; +struct GridEntity; +struct GridEntityDesc; +struct LevelGenerator_Room; +struct RoomConfig_Room; +struct RoomDescriptor; +enum GridEntityType : int; + +// Whether MC_PRE_UPDATE holds the run: while it runs, and until the next update once a mod skipped one. The game +// reads it as paused. +extern bool isUpdateHeld; + +bool game_update_is_skipped(); +bool challenge_done_pre(int challenge); +void change_room_pre(int& roomIdx, int& dimension); +void level_select_pre(int& stage, int& stageType); +RoomConfig_Room* place_room_pre(const LevelGenerator_Room& slot, RoomConfig_Room* config, uint32_t seed); +RoomConfig_Room* wave_room_select(RoomConfig_Room* room, int callback, uint32_t seed); +void backwards_room_restore_post(const BackwardsStageDesc& saved, RoomDescriptor& desc, const char* key, int index); +std::optional grid_spawn_pre(Room& room, int gridIndex, GridEntityType& type, int& variant, uint32_t& seed, + int& varData); +std::optional grid_desc_spawn_pre(Room& room, int gridIndex, GridEntityDesc& desc); +bool room_grid_spawn_pre(GridEntityType& type, int& variant, int& varData, int gridIndex, uint32_t& seed); +bool grid_hurt_pre(GridEntity& grid, int& damage, const EntityRef& source); +void grid_hurt_post(GridEntity& grid, int damage, const EntityRef& source); + +// Runs MC_PRE_GRID_HURT, which may change the damage or cancel the hurt, then hurt, then MC_POST_GRID_HURT once it +// hurt. Only a grid entity that can still be hurt runs them. +template +bool grid_hurt_run(T& grid, int damage, const EntityRef& source, bool isHurtable, + bool (T::*hurt)(int, const EntityRef&)) +{ + if (isHurtable && !grid_hurt_pre(grid, damage, source)) return false; + + bool isHurt = (grid.*hurt)(damage, source); + if (isHurtable && isHurt) grid_hurt_post(grid, damage, source); + return isHurt; +} diff --git a/src/repentogon/npc.cpp b/src/repentogon/npc.cpp new file mode 100644 index 0000000..b2fb23f --- /dev/null +++ b/src/repentogon/npc.cpp @@ -0,0 +1,110 @@ +#include "repentogon/npc.h" +#include "entity/npc/npc.h" +#include "entity/pickup/item_config.h" +#include "entity/player/player.h" +#include "game/game.h" +#include "game/manager.h" +#include "repentogon/callbacks.h" + +constexpr float FIREPLACE_GHOSTS_HEALTH_MIN = 1; + +// (Entity_NPC::GetPlayerTarget hook) MC_NPC_PICK_TARGET, filtered by the NPC's type, with the target it picked. An +// entity a mod returned is the target instead. Nothing when no mod added a function. +std::optional npc_target_hook(Entity_NPC& npc) +{ + LuaEngine& engine = lua_engine_get(); + if (is_hook_inner() || !engine.is_callback_enabled(MC_NPC_PICK_TARGET)) return std::nullopt; + + Entity* target = hook_inner_call([&] { return npc.GetPlayerTarget(); }); + if (!callback_run(engine, {"NPCPickTarget", MC_NPC_PICK_TARGET, (int)npc.type}, &npc, target)) return target; + + if (auto* picked = (Entity*)lua_object_test(engine.state, -1, LUA_CLASS_ENTITY)) target = picked; + lua_pop(engine.state, 1); + return target; +} + +// (Entity_NPC::Morph hook) MC_PRE_NPC_MORPH, unfiltered, cancels the morph with false, or changes it with a table of +// the type, variant, subtype and optionally the champion. MC_POST_NPC_MORPH follows with the NPC's former type, +// variant and subtype. Whether the hook ran the morph. +bool npc_morph_hook(Entity_NPC& npc, NpcMorph morph) +{ + LuaEngine& engine = lua_engine_get(); + bool isHooked = engine.is_callback_enabled(MC_PRE_NPC_MORPH) || engine.is_callback_enabled(MC_POST_NPC_MORPH); + if (is_hook_inner() || !isHooked) return false; + + CallbackRun pre = {"PreNPCMorph", MC_PRE_NPC_MORPH, std::nullopt}; + if (callback_run(engine, pre, &npc, morph.type, morph.variant, morph.subType, morph.championId)) + { + lua_State* state = engine.state; + bool isCancelled = is_result_false(state); + size_t length = lua_istable(state, -1) ? lua_rawlen(state, -1) : 0; + if (length == 3 || length == 4) + { + element_read(state, 1, morph.type); + element_read(state, 2, morph.variant); + element_read(state, 3, morph.subType); + if (length == 4) element_read(state, 4, morph.championId); + } + lua_pop(state, 1); + if (isCancelled) return true; + } + + int formerType = npc.type; + int formerVariant = npc.variant; + int formerSubType = npc.subtype; + hook_inner_call([&] { npc.Morph(morph.type, morph.variant, morph.subType, morph.championId); }); + CallbackRun post = {"PostNPCMorph", MC_POST_NPC_MORPH, std::nullopt}; + callback_notify(engine, post, &npc, formerType, formerVariant, formerSubType); + return true; +} + +// (Entity_NPC::UpdatePickupGhosts patch) Whether an NPC shows the loot it would drop as ghosts: never a fireplace at 1 +// health or less or another dead NPC, else what a mod's MC_PRE_NPC_UPDATE_GHOST_PICKUPS answered, filtered by its type, +// else while a player holds Guppy's Eye. +bool npc_ghosts_is_shown(Entity_NPC& npc) +{ + if (npc.type == ENTITY_FIREPLACE ? npc.health <= FIREPLACE_GHOSTS_HEALTH_MIN : npc.isDead) return false; + + CallbackRun run = {"PreNPCUpdateGhostPickups", MC_PRE_NPC_UPDATE_GHOST_PICKUPS, (int)npc.type}; + if (std::optional isShown = callback_boolean_get(run, &npc)) return *isShown; + return g_game->playerManager.FirstCollectibleOwner(COLLECTIBLE_GUPPYS_EYE, LAZARUS_SHARE_CHECK); +} + +// Sets value to an integer field of the table on top of the stack. Whether it was one. +static bool integer_field_read(lua_State* state, const char* key, int& value) +{ + lua_getfield(state, -1, key); + bool isInteger = lua_isinteger(state, -1); + if (isInteger) value = (int)lua_tointeger(state, -1); + lua_pop(state, 1); + return isInteger; +} + +// (Room::GetBossThematicItem hook) MC_GET_BOSS_THEMATIC_ITEM, unfiltered, with whether a boss kill's rare award was +// picked and its collectible and trinket. A table's Collectible or Trinket the item config has replaces the award, and +// true cancels it. Whether there is one. +bool boss_thematic_item_get(bool isPicked, int& item, int& trinket) +{ + LuaEngine& engine = lua_engine_get(); + CallbackRun run = {"GetBossThematicItem", MC_GET_BOSS_THEMATIC_ITEM, std::nullopt}; + if (!callback_run(engine, run, isPicked, item, trinket)) return isPicked; + + lua_State* state = engine.state; + bool isCancelled = lua_isboolean(state, -1) && lua_toboolean(state, -1); + int chosen = 0; + bool isTable = lua_istable(state, -1); + if (isTable && integer_field_read(state, "Collectible", chosen) && g_manager->itemConfig.GetCollectible(chosen)) + { + item = chosen; + trinket = 0; + isPicked = true; + } + if (isTable && integer_field_read(state, "Trinket", chosen) && g_manager->itemConfig.GetTrinket(chosen)) + { + trinket = chosen; + item = 0; + isPicked = true; + } + lua_pop(state, 1); + return isPicked && !isCancelled; +} diff --git a/src/repentogon/npc.h b/src/repentogon/npc.h new file mode 100644 index 0000000..c1f0a75 --- /dev/null +++ b/src/repentogon/npc.h @@ -0,0 +1,20 @@ +#pragma once + +#include + +struct Entity; +struct Entity_NPC; + +// The entity an NPC turns into, as Entity_NPC::Morph takes it. +struct NpcMorph +{ + int type; + int variant; + int subType; + int championId; +}; + +std::optional npc_target_hook(Entity_NPC& npc); +bool npc_morph_hook(Entity_NPC& npc, NpcMorph morph); +bool npc_ghosts_is_shown(Entity_NPC& npc); +bool boss_thematic_item_get(bool isPicked, int& item, int& trinket); diff --git a/src/repentogon/player.cpp b/src/repentogon/player.cpp new file mode 100644 index 0000000..88abe51 --- /dev/null +++ b/src/repentogon/player.cpp @@ -0,0 +1,720 @@ +#include "repentogon/player.h" +#include "entity/pickup/pickup.h" +#include "entity/player/hud.h" +#include "entity/player/player.h" +#include "entity/weapon/bomb.h" +#include "game/game.h" +#include "repentogon/callbacks.h" +#include +#include +#include + +// REPENTOGON's player callbacks (LuaInterfaces/CustomCallbacks.cpp, Patches/ASMPatches/ASMCallbacks.cpp, +// Patches/PocketItems.cpp, Patches/ExtraLives.cpp, Patches/ASMPatches/ASMGridEntityCollision.cpp), fired from the +// vanilla functions they hook. + +constexpr int HEALTH_TYPE_COUNT = 5; +constexpr int HEALTH_TYPE_UNSET = -1; +constexpr int COIN_HEARTS_MIN = 2; +// Where PRE and POST_PLAYERHUD_RENDER_ACTIVE_ITEM say the charge bar is, from the item's position, in item sizes. +constexpr float BAR_SHIFT_X = 34; +constexpr float BAR_SHIFT_X_SECOND = -2; +constexpr float BAR_SHIFT_X_ESAU_SECOND = 38; +constexpr float BAR_SHIFT_Y = 17; +constexpr float BOOK_ITEM_RISE = 4; +constexpr float BOOK_BAR_DROP = 3; +constexpr float SECOND_SLOT_SCALE = 0.5f; +constexpr int ESAU_HUD_INDEX = 4; +// The compact layout draws Esau's hearts lower than the position RenderHearts gets. +constexpr float ESAU_COMPACT_HEARTS_DROP = 34; + +ActiveItemRender activeItemRender; + +static bool isMaxChargeCached = false; +static std::unordered_map maxChargeCache; + +// Whether a hook takes this call: never its own call of the vanilla body, and only while a mod added a function for +// its callback. +static bool hook_is_taken(int callback) +{ + return !is_hook_inner() && lua_engine_get().is_callback_enabled(callback); +} + +// Runs a callback. Its result when it is an integer, nothing otherwise. +template +static std::optional integer_get(CallbackRun run, Args... args) +{ + LuaEngine& engine = lua_engine_get(); + if (!callback_run(engine, run, args...)) return std::nullopt; + + std::optional result; + if (lua_isinteger(engine.state, -1)) result = (int)lua_tointeger(engine.state, -1); + lua_pop(engine.state, 1); + return result; +} + +// Runs a callback whose result the game ignores. +template +static void notify(CallbackRun run, Args... args) +{ + callback_notify(lua_engine_get(), run, args...); +} + +// Runs a callback. Whether a mod returned answer. +template +static bool answer_is(bool answer, CallbackRun run, Args... args) +{ + return callback_boolean_get(run, args...) == answer; +} + +// The filter parameter an item config entry stands for: its GetPtrHash, as main_ex.lua converts an Item parameter. +static lua_Integer item_param(ItemConfig_Item* item) +{ + return (lua_Integer)((uintptr_t)item ^ lua_engine_get().pointerMask); +} + +// 007729d0's MC_PRE_PLAYER_TAKE_DMG, before Holy Mantle and every other ward. Whether a mod returned false. +bool player_damage_is_cancelled(Entity_Player& player, float damage, uint64_t damageFlags, const EntityRef& source, + int countdown) +{ + CallbackRun run = {"PrePlayerTakeDmg", MC_PRE_PLAYER_TAKE_DMG, player.variant}; + return answer_is(false, run, &player, damage, damageFlags, &source, countdown); +} + +// MC_PRE_PLAYER_ADD_HEARTS for hearts about to be added. The amount to add: an integer a mod returned, or theirs. +int hearts_pre_add(Entity_Player& player, const HeartsAdd& add) +{ + CallbackRun run = {"PrePlayerAddHearts", MC_PRE_PLAYER_ADD_HEARTS, add.type}; + if (add.isIgnoreKeeper) + return integer_get(run, &player, add.amount, (int)add.type, *add.isIgnoreKeeper).value_or(add.amount); + return integer_get(run, &player, add.amount, (int)add.type).value_or(add.amount); +} + +// MC_POST_PLAYER_ADD_HEARTS after hearts were added. +void hearts_post_add(Entity_Player& player, const HeartsAdd& add) +{ + CallbackRun run = {"PostPlayerAddHearts", MC_POST_PLAYER_ADD_HEARTS, add.type}; + if (add.isIgnoreKeeper) notify(run, &player, add.amount, (int)add.type, *add.isIgnoreKeeper); + else notify(run, &player, add.amount, (int)add.type); +} + +// 007bbbd0's MC_PLAYER_INIT_PRE_LEVEL_INIT_STATS, before the character gets its starting health and pickups. +void player_level_stats_pre_init(Entity_Player& player) +{ + notify({"PlayerInitPreLevelInitStats", MC_PLAYER_INIT_PRE_LEVEL_INIT_STATS, player.playerType}, &player); +} + +// 007bc740's MC_PLAYER_INIT_POST_LEVEL_INIT_STATS, after the character got its starting items. +void player_level_stats_post_init(Entity_Player& player) +{ + notify({"PlayerInitPostLevelInitStats", MC_PLAYER_INIT_POST_LEVEL_INIT_STATS, player.playerType}, &player); +} + +// Without vanilla parity, REPENTOGON's conversion of the hearts a new health type cannot hold: soul characters turn +// heart containers into soul hearts, coin characters keep whole coins, bone characters turn them into bone hearts. +static void health_type_convert(Entity_Player& player, int healthType) +{ + if (healthType == HEALTH_SOUL) + { + player.redHearts = 0; + player.rottenHearts = 0; + if (player.maxHearts > 0) + { + int oldMaxHearts = player.maxHearts; + player.trigger_max_hearts_removed(oldMaxHearts); + player.maxHearts = 0; + player.soulHearts += oldMaxHearts; + player.blackHearts <<= oldMaxHearts / 2; + player.boneHeartsMask <<= oldMaxHearts / 2; + } + } + else if (healthType == HEALTH_NO_HEALTH) + { + player.rottenHearts = 0; + player.boneHeartsMask = 0; + player.boneHearts = 0; + player.eternalHearts = 0; + player.redHearts = 0; + player.blackHearts = 0; + player.soulHearts = 1; + if (player.maxHearts > 0) player.trigger_max_hearts_removed(player.maxHearts); + player.maxHearts = 0; + } + else if (healthType == HEALTH_COIN) + { + player.rottenHearts = 0; + player.boneHeartsMask = 0; + player.boneHearts = 0; + player.soulHearts = 0; + player.blackHearts = 0; + if (player.maxHearts == 0) player.maxHearts = COIN_HEARTS_MIN; + if (player.redHearts < COIN_HEARTS_MIN) player.redHearts = COIN_HEARTS_MIN; + else if (player.redHearts % 2 != 0) player.redHearts++; + } + else if (healthType == HEALTH_BONE && player.maxHearts > 0) + { + for (int i = 0; i < player.maxHearts / 2; i++) + { + player.boneHeartsMask = (player.boneHeartsMask << 1) + 1; + player.boneHearts++; + } + player.maxHearts = 0; + player.redHearts = std::min(player.redHearts, player.boneHearts * 2); + } + player.UpdateBlackHeartMask(); + player.update_greeds_gullet(); + player.UpdateHeartDependentEffects(); + player.update_bone_hearts(); +} + +// 007cafe0's MC_PLAYER_GET_HEALTH_TYPE and MC_PLAYER_HEALTH_TYPE_CHANGE. The health type a mod chose (0 to 4), or the +// character's. A change from the last one runs the change callback, and without vanilla parity converts the hearts. +int player_health_type_evaluate(Entity_Player& player, int healthType) +{ + if (player.isEvaluatingHealthType) + return player.previousHealthType != HEALTH_TYPE_UNSET ? player.previousHealthType : healthType; + + player.isEvaluatingHealthType = true; + int previous = player.previousHealthType != HEALTH_TYPE_UNSET ? player.previousHealthType : healthType; + int evaluated = healthType; + CallbackRun run = {"PlayerGetHealthType", MC_PLAYER_GET_HEALTH_TYPE, player.playerType}; + if (std::optional chosen = integer_get(run, &player, previous, healthType); + chosen && *chosen >= 0 && *chosen < HEALTH_TYPE_COUNT) + evaluated = *chosen; + + if (evaluated != previous) + { + player.previousHealthType = evaluated; + notify({"PlayerHealthTypeChange", MC_PLAYER_HEALTH_TYPE_CHANGE, player.playerType}, &player, evaluated, + previous, healthType); + if (!repentogonOptions.isVanillaParity) health_type_convert(player, evaluated); + } + player.isEvaluatingHealthType = false; + return evaluated; +} + +// Marks the vanilla functions that ask for a max charge many times over (ControlActiveItem, AddActiveCharge and +// PlayerHUD::RenderActiveItem): while they run, MC_PLAYER_GET_ACTIVE_MAX_CHARGE answers once per item. +void max_charge_cache_begin() +{ + isMaxChargeCached = true; + maxChargeCache.clear(); +} + +void max_charge_cache_end() +{ + isMaxChargeCached = false; + maxChargeCache.clear(); +} + +// 007911f0's MC_PLAYER_GET_ACTIVE_MAX_CHARGE: the charges an item needs, a mod's integer (at least 0) replacing them. +std::optional active_max_charge_hook(Entity_Player& player, int collectibleId, int varData) +{ + if (!hook_is_taken(MC_PLAYER_GET_ACTIVE_MAX_CHARGE)) return std::nullopt; + + int charge = hook_inner_call([&] { return player.GetCollectibleMaxCharge(collectibleId, varData); }); + if (collectibleId == 0) return charge; + if (isMaxChargeCached && maxChargeCache.contains(collectibleId)) return maxChargeCache[collectibleId]; + + CallbackRun run = {"PlayerGetActiveMaxCharge", MC_PLAYER_GET_ACTIVE_MAX_CHARGE, collectibleId}; + std::optional chosen = integer_get(run, collectibleId, &player, varData, charge); + if (!chosen) return charge; + if (isMaxChargeCached) maxChargeCache[collectibleId] = std::max(*chosen, 0); + return std::max(*chosen, 0); +} + +// 00791380's MC_PLAYER_GET_ACTIVE_MIN_USABLE_CHARGE for a slot holding an item: a mod's integer (at least 0). +std::optional active_min_charge_hook(Entity_Player& player, int slot) +{ + if (!hook_is_taken(MC_PLAYER_GET_ACTIVE_MIN_USABLE_CHARGE)) return std::nullopt; + + int charge = hook_inner_call([&] { return player.GetActiveMinUsableCharge(slot); }); + int item = player.activeItems[slot].item; + if (item == 0) return charge; + CallbackRun run = {"PlayerGetActiveMinUsableCharge", MC_PLAYER_GET_ACTIVE_MIN_USABLE_CHARGE, item}; + return std::max(integer_get(run, slot, &player, charge).value_or(charge), 0); +} + +// 007cae60's MC_PLAYER_GET_HEART_LIMIT: the half hearts the player holds, a mod's integer replacing them. +std::optional heart_limit_hook(Entity_Player& player, bool isKeeperBypass) +{ + if (!hook_is_taken(MC_PLAYER_GET_HEART_LIMIT)) return std::nullopt; + + int limit = hook_inner_call([&] { return player.GetHeartLimit(isKeeperBypass); }); + CallbackRun run = {"PlayerGetHeartLimit", MC_PLAYER_GET_HEART_LIMIT, player.playerType}; + return integer_get(run, &player, limit, isKeeperBypass).value_or(limit); +} + +// 00770ca0's MC_PRE_PLAYER_APPLY_INNATE_COLLECTIBLE_NUM: the copies of a collectible the player has, plus a mod's. +std::optional collectible_num_hook(Entity_Player& player, int collectibleId, bool isOnlyTrueItems) +{ + if (!hook_is_taken(MC_PRE_PLAYER_APPLY_INNATE_COLLECTIBLE_NUM)) return std::nullopt; + + ItemCheck check = isOnlyTrueItems ? ITEM_CHECK_OWNED : ITEM_CHECK_MODIFIED; + int count = hook_inner_call([&] { return player.GetCollectibleNum(collectibleId, check); }); + CallbackRun run = {"PrePlayerApplyInnateCollectibleNum", MC_PRE_PLAYER_APPLY_INNATE_COLLECTIBLE_NUM, std::nullopt}; + return count + integer_get(run, 0, &player, collectibleId, isOnlyTrueItems).value_or(0); +} + +// MC_POST_PLAYER_NEW_ROOM_TEMP_EFFECTS, after a room's entry set up the player's temporary effects. +void player_room_effects_post_trigger(Entity_Player& player) +{ + notify({"PostPlayerNewRoomTempEffects", MC_POST_PLAYER_NEW_ROOM_TEMP_EFFECTS, player.playerType}, &player); +} + +// 007a4ba0's MC_POST_PLAYER_NEW_LEVEL, after the player was readied for a new floor. +void player_level_post_start(Entity_Player& player, bool isForced) +{ + CallbackRun run = {"PostPlayerNewLevel", MC_POST_PLAYER_NEW_LEVEL, player.playerType}; + notify(run, &player, isForced, player.isPostLevelInitFinished); +} + +// MC_PRE_RENDER_PLAYER_HEAD or BODY. Whether the part is drawn: false when a mod returned false, a Vector it returned +// moving it. +bool player_part_pre_render(Entity_Player& player, Vector& position, PlayerRenderPart part) +{ + int callback = part == RENDER_PART_HEAD ? MC_PRE_RENDER_PLAYER_HEAD : MC_PRE_RENDER_PLAYER_BODY; + CallbackRun run = {"PreRenderPlayerPart", callback, player.playerType}; + return render_pre_run(run, &player, position); +} + +// MC_POST_RENDER_PLAYER_HEAD or BODY, at the position the part was drawn at. +void player_part_post_render(Entity_Player& player, const Vector& position, PlayerRenderPart part) +{ + int callback = part == RENDER_PART_HEAD ? MC_POST_RENDER_PLAYER_HEAD : MC_POST_RENDER_PLAYER_BODY; + CallbackRun run = {"PostRenderPlayerPart", callback, player.playerType}; + notify(run, &player, position); +} + +// 007a8fd0's MC_PRE_PLAYER_TRIGGER_ROOM_CLEAR. Whether a mod returned false, which skips the clear's effects. +bool player_room_clear_is_cancelled(Entity_Player& player) +{ + return answer_is(false, {"PrePlayerTriggerRoomClear", MC_PRE_PLAYER_TRIGGER_ROOM_CLEAR, player.variant}, &player); +} + +// MC_POST_PLAYER_TRIGGER_ROOM_CLEAR, after the clear's effects. +void player_room_clear_post(Entity_Player& player) +{ + notify({"PostPlayerTriggerRoomClear", MC_POST_PLAYER_TRIGGER_ROOM_CLEAR, player.variant}, &player); +} + +// 00771800's MC_POST_PLAYER_DROP_TRINKET for the pickup a trinket dropped as, filtered by its id without the golden +// flag. +void player_trinket_post_drop(Entity_Player& player, const Vector& position, bool isReplaceTick, Entity_Pickup* pickup) +{ + if (!pickup) return; + + int trinket = pickup->subtype & TRINKET_ID_MASK; + bool isGolden = (pickup->subtype & TRINKET_GOLDEN_FLAG) != 0; + CallbackRun run = {"PostPlayerDropTrinket", MC_POST_PLAYER_DROP_TRINKET, trinket}; + notify(run, trinket, position, &player, isGolden, isReplaceTick, pickup); +} + +// 00793970's MC_POST_PLAYER_TRIGGER_EFFECT_REMOVED, after an item's temporary effect left the player. +void player_effect_post_remove(Entity_Player& player, ItemConfig_Item* item, int count) +{ + CallbackRun run = {"PostPlayerTriggerEffectRemoved", MC_POST_PLAYER_TRIGGER_EFFECT_REMOVED, item_param(item)}; + notify(run, &player, item, count); +} + +// 00930220's MC_POST_PLAYER_ADD_EFFECT, after copies of an item's effect were added to a player. +void player_effect_post_add(Entity_Player& player, const TemporaryEffect& effect, bool isAddCostume, int count) +{ + if (!effect.item) return; + CallbackRun run = {"PostPlayerAddEffect", MC_POST_PLAYER_ADD_EFFECT, item_param(effect.item)}; + notify(run, &player, effect.item, isAddCostume, count); +} + +// 0075d1d0's MC_PRE_PLAYER_ADD_COSTUME. Whether a mod returned true, which keeps the costume off. An Item it returned +// is worn instead. +bool costume_pre_add(Entity_Player& player, ItemConfig_Item*& item, bool isItemStateOnly) +{ + LuaEngine& engine = lua_engine_get(); + if (!callback_run(engine, {"PrePlayerAddCostume", MC_PRE_PLAYER_ADD_COSTUME, item_param(item)}, item, &player, + isItemStateOnly)) + return false; + + bool isCancelled = lua_isboolean(engine.state, -1) && lua_toboolean(engine.state, -1); + if (auto* chosen = (ItemConfig_Item*)lua_object_test(engine.state, -1, LUA_CLASS_ITEM_CONFIG_ITEM)) item = chosen; + lua_pop(engine.state, 1); + return isCancelled; +} + +// MC_POST_PLAYER_ADD_COSTUME, after the costume was put on. +void costume_post_add(Entity_Player& player, ItemConfig_Item* item, bool isItemStateOnly) +{ + CallbackRun run = {"PostPlayerAddCostume", MC_POST_PLAYER_ADD_COSTUME, item_param(item)}; + notify(run, item, &player, isItemStateOnly); +} + +// 0075d850's MC_PRE_PLAYER_REMOVE_COSTUME. Whether a mod returned true, which keeps the costume on. +bool costume_pre_remove(Entity_Player& player, ItemConfig_Item* item) +{ + CallbackRun run = {"PrePlayerRemoveCostume", MC_PRE_PLAYER_REMOVE_COSTUME, item_param(item)}; + return answer_is(true, run, item, &player); +} + +// MC_POST_PLAYER_REMOVE_COSTUME, after the costume came off. +void costume_post_remove(Entity_Player& player, ItemConfig_Item* item) +{ + notify({"PostPlayerRemoveCostume", MC_POST_PLAYER_REMOVE_COSTUME, item_param(item)}, item, &player); +} + +// 007a2220's MC_PRE_PLAYER_REVIVE. Whether a mod returned false, which keeps the player dead. +bool player_revive_is_cancelled(Entity_Player& player) +{ + return answer_is(false, {"PrePlayerRevive", MC_PRE_PLAYER_REVIVE, player.playerType}, &player); +} + +// MC_POST_PLAYER_REVIVE. Without vanilla parity REPENTOGON first gives The Forgotten an empty bone heart for the half +// soul heart he cannot hold, and Keeper a whole coin heart for half of one. +void player_revive_post(Entity_Player& player) +{ + if (!repentogonOptions.isVanillaParity) + { + if (player.playerType == PLAYER_THEFORGOTTEN) + { + player.soulHearts = 0; + if (player.boneHearts < 1) + { + player.boneHearts = 1; + player.boneHeartsMask = 1; + } + } + if (player.GetHealthType() == HEALTH_COIN && player.redHearts == 1) player.redHearts = 2; + } + notify({"PostPlayerRevive", MC_POST_PLAYER_REVIVE, player.playerType}, &player); +} + +// 0075d9f0's MC_PRE_SHUFFLE_COSTUMES. Whether a mod returned false, which keeps the costumes in place. +bool costumes_shuffle_is_cancelled(Entity_Player& player, uint32_t seed) +{ + return answer_is(false, {"PreShuffleCostumes", MC_PRE_SHUFFLE_COSTUMES, player.playerType}, &player, seed); +} + +// MC_POST_SHUFFLE_COSTUMES. REPENTOGON runs MC_PRE_SHUFFLE_COSTUMES's id here by mistake: this runs the POST one. +void costumes_shuffle_post(Entity_Player& player, uint32_t seed) +{ + notify({"PostShuffleCostumes", MC_POST_SHUFFLE_COSTUMES, player.playerType}, &player, seed); +} + +// The twins revived together after a mod's revival, sharing the longer invincibility, and shown again outside a room +// transition. +static void revive_checks_post(Entity_Player& player) +{ + Entity_Player* twin = player.twin_get(); + if (twin) + { + int damageCooldown = std::max(player.damageCooldown, twin->damageCooldown); + if (twin->isDead) twin->Revive(); + player.damageCooldown = damageCooldown; + twin->damageCooldown = damageCooldown; + } + if (g_game->roomTransition.is_active()) return; + player.isVisible = true; + if (twin) twin->isVisible = true; +} + +// MC_PRE_TRIGGER_PLAYER_DEATH or MC_TRIGGER_PLAYER_DEATH_POST_CHECK_REVIVES for a dying player. A mod revives it by +// returning false (keeping a longer invincibility it set) or by reviving it itself. Whether it was revived. +static bool death_callback_run(Entity_Player& player, int callback) +{ + LuaEngine& engine = lua_engine_get(); + if (!player.isExists || !callback_run(engine, {"TriggerPlayerDeath", callback, std::nullopt}, &player)) + return false; + + bool isFalse = lua_isboolean(engine.state, -1) && !lua_toboolean(engine.state, -1); + lua_pop(engine.state, 1); + if (!player.isExists) return false; + if (isFalse && player.isDead) + { + int damageCooldown = player.damageCooldown; + player.Revive(); + player.damageCooldown = std::max(player.damageCooldown, damageCooldown); + } + if (player.isDead) return false; + revive_checks_post(player); + return true; +} + +// 007a1090's MC_PRE_TRIGGER_PLAYER_DEATH, before any revival is looked for. The death's result when the callback +// settles it: revived by a mod, or gone. Without vanilla parity REPENTOGON first sets the invincibility to one frame. +std::optional player_death_pre_trigger(Entity_Player& player) +{ + if (!repentogonOptions.isVanillaParity) player.damageCooldown = 1; + bool isRun = lua_engine_get().is_callback_enabled(MC_PRE_TRIGGER_PLAYER_DEATH); + if (death_callback_run(player, MC_PRE_TRIGGER_PLAYER_DEATH)) return true; + if (!player.isExists && (isRun || !repentogonOptions.isVanillaParity)) return false; + return std::nullopt; +} + +// MC_TRIGGER_PLAYER_DEATH_POST_CHECK_REVIVES, when no revival saved the player. Without vanilla parity REPENTOGON then +// revives a twin whose partner lives, and lets the other twin die first to look for its revivals. +void player_death_post_check_revives(Entity_Player& player) +{ + death_callback_run(player, MC_TRIGGER_PLAYER_DEATH_POST_CHECK_REVIVES); + Entity_Player* twin = player.twin_get(); + if (repentogonOptions.isVanillaParity || !player.isExists || !player.isDead || !twin || !twin->isExists) return; + + if (!twin->isDead) + { + player.Revive(); + revive_checks_post(player); + } + else if (player.playerIndex < twin->playerIndex) + { + twin->TriggerDeath(false); + if (!player.isDead) revive_checks_post(player); + } +} + +// 00780f40's MC_PRE_PLAYER_USE_BOMB, as a placed bomb is about to be paid for. Whether a mod returned false. +bool player_bomb_use_is_cancelled(Entity_Player& player) +{ + return answer_is(false, {"PrePlayerUseBomb", MC_PRE_PLAYER_USE_BOMB, player.variant}, &player); +} + +// MC_POST_PLAYER_USE_BOMB for each bomb placed. +void player_bomb_post_use(Entity_Player& player, Entity_Bomb& bomb) +{ + notify({"PostPlayerUseBomb", MC_POST_PLAYER_USE_BOMB, player.variant}, &player, &bomb); +} + +// MC_PRE_PLAYER_GIVE_BIRTH_CAMBION or IMMACULATE for the familiar a conception is about to give. Whether a mod +// returned false, which gives none. +bool player_birth_is_cancelled(Entity_Player& player, uint32_t familiarFlag, ConceptionBirth birth) +{ + int callback = birth == BIRTH_CAMBION ? MC_PRE_PLAYER_GIVE_BIRTH_CAMBION : MC_PRE_PLAYER_GIVE_BIRTH_IMMACULATE; + return answer_is(false, {"PrePlayerGiveBirth", callback, familiarFlag}, &player, familiarFlag); +} + +// 007a42b0's MC_PRE_PLAYER_POCKET_ITEMS_SWAP. Whether a mod returned true, which keeps the pockets and actives still. +bool pocket_swap_is_cancelled(Entity_Player& player) +{ + return answer_is(true, {"PrePlayerPocketItemsSwap", MC_PRE_PLAYER_POCKET_ITEMS_SWAP, std::nullopt}, &player); +} + +// Whether a pocket item is a card or a pill, the kinds the pocket callbacks follow. +static bool is_pocket_followed(int pocketItemType, int id) +{ + return id > 0 && (pocketItemType == POCKET_CARD || pocketItemType == POCKET_PILL); +} + +// MC_PRE_PLAYER_ADD_CARD or PILL for a card or pill about to go into a pocket slot. The id to add: a positive integer a +// mod returned, or its own. Nothing when a mod returned false, which keeps it out. +std::optional pocket_pre_add(Entity_Player& player, int pocketItemType, int id, int slot) +{ + if (!is_pocket_followed(pocketItemType, id)) return id; + + LuaEngine& engine = lua_engine_get(); + int callback = pocketItemType == POCKET_CARD ? MC_PRE_PLAYER_ADD_CARD : MC_PRE_PLAYER_ADD_PILL; + if (!callback_run(engine, {"PrePlayerAddPocketItem", callback, id}, &player, id, slot)) return id; + + std::optional result = id; + if (lua_isboolean(engine.state, -1) && !lua_toboolean(engine.state, -1)) result.reset(); + else if (lua_isinteger(engine.state, -1) && lua_tointeger(engine.state, -1) > 0) + result = (int)lua_tointeger(engine.state, -1); + lua_pop(engine.state, 1); + return result; +} + +// MC_POST_PLAYER_ADD_CARD or PILL after a card or pill went into a pocket slot. +void pocket_post_add(Entity_Player& player, int pocketItemType, int id, int slot) +{ + if (!is_pocket_followed(pocketItemType, id)) return; + int callback = pocketItemType == POCKET_CARD ? MC_POST_PLAYER_ADD_CARD : MC_POST_PLAYER_ADD_PILL; + notify({"PostPlayerAddPocketItem", callback, id}, &player, id, slot); +} + +// MC_POST_PLAYER_REMOVE_CARD or PILL after a card or pill left a pocket slot. +void pocket_post_remove(Entity_Player& player, int pocketItemType, int id, int slot) +{ + if (!is_pocket_followed(pocketItemType, id)) return; + int callback = pocketItemType == POCKET_CARD ? MC_POST_PLAYER_REMOVE_CARD : MC_POST_PLAYER_REMOVE_PILL; + notify({"PostPlayerRemovePocketItem", callback, id}, &player, id, slot); +} + +// Whether an entity is a card or pill pickup holding one. +static bool is_pocket_pickup(Entity* pickup) +{ + return pickup && pickup->type == ENTITY_PICKUP && + (pickup->variant == PICKUP_TAROTCARD || pickup->variant == PICKUP_PILL); +} + +// MC_POST_PLAYER_REMOVE_CARD or PILL for a card or pill dropped from a pocket slot, then MC_POST_PLAYER_DROP_CARD or +// PILL for the pickup it dropped as. +void pocket_post_drop(Entity_Player& player, int pocketItemType, int id, int slot, Entity* pickup) +{ + if (!is_pocket_followed(pocketItemType, id)) return; + + pocket_post_remove(player, pocketItemType, id, slot); + if (!is_pocket_pickup(pickup)) return; + int callback = pickup->variant == PICKUP_TAROTCARD ? MC_POST_PLAYER_DROP_CARD : MC_POST_PLAYER_DROP_PILL; + notify({"PostPlayerDropPocketItem", callback, pickup->subtype}, &player, static_cast(pickup), slot); +} + +// MC_PRE_PLAYER_COLLECT_CARD or PILL as a player touches a card or pill it can take. Whether the pickup stays: a mod +// returned false, or changed it into something else. +bool pocket_collect_is_cancelled(Entity_Pickup& pocket, Entity_Player& player) +{ + bool isCard = pocket.variant == PICKUP_TAROTCARD; + CallbackRun run = {"PrePlayerCollectPocketItem", isCard ? MC_PRE_PLAYER_COLLECT_CARD : MC_PRE_PLAYER_COLLECT_PILL, + pocket.subtype}; + if (answer_is(false, run, &player, &pocket)) return true; + return !is_pocket_pickup(&pocket) || (pocket.variant == PICKUP_TAROTCARD) != isCard || pocket.subtype == 0; +} + +// MC_POST_PLAYER_COLLECT_CARD or PILL after a player took a card or pill. +void pocket_collect_post(Entity_Pickup& pocket, Entity_Player& player) +{ + if (!is_pocket_pickup(&pocket)) return; + bool isCard = pocket.variant == PICKUP_TAROTCARD; + CallbackRun run = {"PostPlayerCollectPocketItem", + isCard ? MC_POST_PLAYER_COLLECT_CARD : MC_POST_PLAYER_COLLECT_PILL, pocket.subtype}; + notify(run, &player, &pocket); +} + +// Where RenderHearts' callbacks say the hearts are: lower for Esau's in the compact twin layout. +static Vector hearts_position_get(PlayerHUD& hud, const HudHeartsDraw& draw) +{ + Vector sent = draw.position; + if (hud.playerHudIndex >= MAIN_PLAYER_HUD_COUNT && draw.layout == HUD_LAYOUT_JACOB_ESAU_COMPACT) + sent.y += ESAU_COMPACT_HEARTS_DROP; + return sent; +} + +// 00843df0's MC_PRE_PLAYERHUD_RENDER_HEARTS for a living player's hearts. Whether a mod returned true to skip them. +bool hud_hearts_pre_render(PlayerHUD& hud, const HudHeartsDraw& draw) +{ + CallbackRun run = {"PrePlayerHUDRenderHearts", MC_PRE_PLAYERHUD_RENDER_HEARTS, std::nullopt}; + return answer_is(true, run, &draw.extent, &draw.sprite, hearts_position_get(hud, draw), draw.scale, hud.player); +} + +// MC_POST_PLAYERHUD_RENDER_HEARTS after a living player's hearts were drawn. +void hud_hearts_post_render(PlayerHUD& hud, const HudHeartsDraw& draw) +{ + CallbackRun run = {"PostPlayerHUDRenderHearts", MC_POST_PLAYERHUD_RENDER_HEARTS, std::nullopt}; + notify(run, &draw.extent, &draw.sprite, hearts_position_get(hud, draw), draw.scale, hud.player); +} + +// The PRE and POST callbacks of the HUD elements drawn from just a position and a scale. +static constexpr std::array, 3> HUD_ELEMENT_CALLBACKS = {{ + {MC_PRE_PLAYERHUD_RENDER_INVENTORY, MC_POST_PLAYERHUD_RENDER_INVENTORY}, + {MC_PRE_PLAYERHUD_RENDER_POOP_SPELL_QUEUE, MC_POST_PLAYERHUD_RENDER_POOP_SPELL_QUEUE}, + {MC_PRE_PLAYERHUD_RENDER_CRAFTING_TABLE, MC_POST_PLAYERHUD_RENDER_CRAFTING_TABLE}, +}}; + +// A HUD element's PRE callback (Tainted Isaac's inventory, Tainted ???'s poop spells, Tainted Cain's crafting table) +// as it is about to be drawn: false skips it, a Vector moves it. Its POST callback runs as the drawing ends. +HudElementScope::HudElementScope(PlayerHUD& hud, HudElement element, Vector& position, float scale) + : hud(hud), element(element), scale(scale) +{ + LuaEngine& engine = lua_engine_get(); + CallbackRun run = {"PrePlayerHUDRenderElement", HUD_ELEMENT_CALLBACKS[element][0], std::nullopt}; + if (callback_run(engine, run, hud.player, position, scale)) + { + isDrawn = !lua_isboolean(engine.state, -1) || lua_toboolean(engine.state, -1); + object_read(engine.state, position); + lua_pop(engine.state, 1); + } + this->position = position; +} + +HudElementScope::~HudElementScope() +{ + if (!isDrawn) return; + notify({"PostPlayerHUDRenderElement", HUD_ELEMENT_CALLBACKS[element][1], std::nullopt}, hud.player, position, + scale); +} + +// The item and charge bar positions PRE and POST_PLAYERHUD_RENDER_ACTIVE_ITEM pass, where the game draws them, and +// the slot's size. +struct ActiveItemPositions +{ + Vector item; + Vector bar; + float scale; +}; + +static ActiveItemPositions active_item_positions_get(PlayerHUD& hud, const HudActiveDraw& draw) +{ + bool isSecond = draw.slot == ACTIVE_SLOT_SECONDARY; + float size = isSecond ? draw.scale * SECOND_SLOT_SCALE : draw.scale; + ActiveItemPositions positions = {draw.position, draw.position, size}; + bool isEsauFirst = hud.playerHudIndex == ESAU_HUD_INDEX && draw.layout == HUD_LAYOUT_JACOB_ESAU; + if (!isEsauFirst) positions.bar.x += (isSecond ? BAR_SHIFT_X_SECOND : BAR_SHIFT_X) * size; + else if (isSecond) positions.bar.x += BAR_SHIFT_X_ESAU_SECOND * size; + positions.bar.y += BAR_SHIFT_Y * size; + if (hud.activeItems[draw.slot].bookImage) + { + positions.item.y -= BOOK_ITEM_RISE; + positions.bar.y += BOOK_BAR_DROP; + } + return positions; +} + +// 008453c0's MC_PRE_PLAYERHUD_RENDER_ACTIVE_ITEM, filtered by the slot's item. Whether a mod returned true, which skips +// the slot. A table hides the item, its outline or its charge bar, or crops a modded item's icon. +bool hud_active_item_pre_render(PlayerHUD& hud, const HudActiveDraw& draw) +{ + activeItemRender = {}; + LuaEngine& engine = lua_engine_get(); + lua_State* state = engine.state; + ActiveItemPositions positions = active_item_positions_get(hud, draw); + CallbackRun run = {"PrePlayerHUDRenderActiveItem", MC_PRE_PLAYERHUD_RENDER_ACTIVE_ITEM, + hud.player->activeItems[draw.slot].item}; + if (!callback_run(engine, run, hud.player, draw.slot, positions.item, draw.alpha, positions.scale, positions.bar)) + return false; + + bool isSkipped = lua_isboolean(state, -1) && lua_toboolean(state, -1); + if (lua_istable(state, -1)) + { + activeItemRender.isItemHidden = boolean_field_get(state, "HideItem").value_or(false); + activeItemRender.isOutlineHidden = boolean_field_get(state, "HideOutline").value_or(false); + activeItemRender.isChargeBarHidden = boolean_field_get(state, "HideChargeBar").value_or(false); + Vector crop{}; + lua_getfield(state, -1, "CropOffset"); + object_read(state, crop); + lua_pop(state, 1); + activeItemRender.isCropped = hud.activeItems[draw.slot].id >= COLLECTIBLE_VANILLA_COUNT; + activeItemRender.cropX = crop.x; + activeItemRender.cropY = crop.y; + } + lua_pop(state, 1); + return isSkipped; +} + +// MC_POST_PLAYERHUD_RENDER_ACTIVE_ITEM, after the slot was drawn. +void hud_active_item_post_render(PlayerHUD& hud, const HudActiveDraw& draw) +{ + activeItemRender = {}; + ActiveItemPositions positions = active_item_positions_get(hud, draw); + CallbackRun run = {"PostPlayerHUDRenderActiveItem", MC_POST_PLAYERHUD_RENDER_ACTIVE_ITEM, + hud.player->activeItems[draw.slot].item}; + notify(run, hud.player, draw.slot, positions.item, draw.alpha, positions.scale, positions.bar); +} + +// 00846ff0's MC_PRE_PLAYERHUD_TRINKET_RENDER, filtered by the slot. Whether the trinket is drawn: false when a mod +// returned true. A table moves it, scales it or crops its icon elsewhere. +bool hud_trinket_pre_render(PlayerHUD& hud, int slot, Vector& position, float& scale, Vector& cropOffset) +{ + LuaEngine& engine = lua_engine_get(); + lua_State* state = engine.state; + CallbackRun run = {"PrePlayerHUDTrinketRender", MC_PRE_PLAYERHUD_TRINKET_RENDER, slot}; + if (!hud.player || !callback_run(engine, run, slot, position, scale, hud.player, cropOffset)) return true; + + bool isDrawn = !(lua_isboolean(state, -1) && lua_toboolean(state, -1)); + if (lua_istable(state, -1)) + { + lua_getfield(state, -1, "Position"); + object_read(state, position); + lua_getfield(state, -2, "CropOffset"); + object_read(state, cropOffset); + lua_pop(state, 2); + lua_getfield(state, -1, "Scale"); + if (lua_isnumber(state, -1)) scale = (float)lua_tonumber(state, -1); + lua_pop(state, 1); + } + lua_pop(state, 1); + return isDrawn; +} diff --git a/src/repentogon/player.h b/src/repentogon/player.h new file mode 100644 index 0000000..4f8cc9a --- /dev/null +++ b/src/repentogon/player.h @@ -0,0 +1,155 @@ +#pragma once + +#include "classes.h" +#include "repentogon/callbacks.h" +#include +#include + +struct ANM2; +struct Entity; +struct Entity_Bomb; +struct Entity_Pickup; +struct Entity_Player; +struct EntityRef; +struct ItemConfig_Item; +struct PlayerHUD; +struct TemporaryEffect; + +// The hearts MC_PRE and MC_POST_PLAYER_ADD_HEARTS tell apart (Lua's AddHealthType), as their filter bits. +enum AddHealthType : int +{ + ADD_HEALTH_RED = 1 << 0, + ADD_HEALTH_MAX = 1 << 1, + ADD_HEALTH_SOUL = 1 << 2, + ADD_HEALTH_BLACK = 1 << 3, + ADD_HEALTH_ETERNAL = 1 << 4, + ADD_HEALTH_GOLDEN = 1 << 5, + ADD_HEALTH_BONE = 1 << 6, + ADD_HEALTH_ROTTEN = 1 << 7, + ADD_HEALTH_BROKEN = 1 << 8 +}; + +// Which conception gives birth to a familiar: Cambion Conception from hits, Immaculate Conception from hearts. +enum ConceptionBirth +{ + BIRTH_CAMBION, + BIRTH_IMMACULATE +}; + +// The HUD elements REPENTOGON's PRE and POST_PLAYERHUD_RENDER callbacks wrap with only a position and a scale. +enum HudElement +{ + HUD_ELEMENT_INVENTORY, + HUD_ELEMENT_POOP_SPELL_QUEUE, + HUD_ELEMENT_CRAFTING_TABLE +}; + +// The parts of a player PRE and POST_RENDER_PLAYER_HEAD and BODY run around. +enum PlayerRenderPart +{ + RENDER_PART_HEAD, + RENDER_PART_BODY +}; + +// Hearts about to be added, as the hearts callbacks see them: their kind, the amount and AddMaxHearts' ignoreKeeper. +struct HeartsAdd +{ + AddHealthType type; + int amount; + std::optional isIgnoreKeeper; +}; + +// A player's hearts as the HUD draws them, for PRE and POST_PLAYERHUD_RENDER_HEARTS: the extent they reach, their +// sprite, their position, layout and scale. +struct HudHeartsDraw +{ + Vector& extent; + ANM2& sprite; + Vector position; + int layout; + float scale; +}; + +// An active slot as the HUD draws it, for PRE and POST_PLAYERHUD_RENDER_ACTIVE_ITEM. +struct HudActiveDraw +{ + Vector position; + int slot; + int layout; + float alpha; + float scale; +}; + +// A HUD element drawn from just a position and a scale, between its PRE and POST_PLAYERHUD_RENDER callbacks. +struct HudElementScope +{ + PlayerHUD& hud; + Vector position; + HudElement element; + float scale; + bool isDrawn = true; + + HudElementScope(PlayerHUD& hud, HudElement element, Vector& position, float scale); + ~HudElementScope(); +}; + +// What PRE_PLAYERHUD_RENDER_ACTIVE_ITEM asked of an active slot's drawing, which ends with the slot. +struct ActiveItemRender +{ + float cropX = 0; + float cropY = 0; + bool isChargeBarHidden = false; + bool isCropped = false; + bool isItemHidden = false; + bool isOutlineHidden = false; +}; + +extern ActiveItemRender activeItemRender; + +bool player_damage_is_cancelled(Entity_Player& player, float damage, uint64_t damageFlags, const EntityRef& source, + int countdown); +int hearts_pre_add(Entity_Player& player, const HeartsAdd& add); +void hearts_post_add(Entity_Player& player, const HeartsAdd& add); +void player_level_stats_pre_init(Entity_Player& player); +void player_level_stats_post_init(Entity_Player& player); +int player_health_type_evaluate(Entity_Player& player, int healthType); +std::optional active_max_charge_hook(Entity_Player& player, int collectibleId, int varData); +std::optional active_min_charge_hook(Entity_Player& player, int slot); +std::optional heart_limit_hook(Entity_Player& player, bool isKeeperBypass); +std::optional collectible_num_hook(Entity_Player& player, int collectibleId, bool isOnlyTrueItems); +void max_charge_cache_begin(); +void max_charge_cache_end(); +void player_room_effects_post_trigger(Entity_Player& player); +void player_level_post_start(Entity_Player& player, bool isForced); +bool player_part_pre_render(Entity_Player& player, Vector& position, PlayerRenderPart part); +void player_part_post_render(Entity_Player& player, const Vector& position, PlayerRenderPart part); +bool player_room_clear_is_cancelled(Entity_Player& player); +void player_room_clear_post(Entity_Player& player); +void player_trinket_post_drop(Entity_Player& player, const Vector& position, bool isReplaceTick, Entity_Pickup* pickup); +void player_effect_post_remove(Entity_Player& player, ItemConfig_Item* item, int count); +void player_effect_post_add(Entity_Player& player, const TemporaryEffect& effect, bool isAddCostume, int count); +bool costume_pre_add(Entity_Player& player, ItemConfig_Item*& item, bool isItemStateOnly); +void costume_post_add(Entity_Player& player, ItemConfig_Item* item, bool isItemStateOnly); +bool costume_pre_remove(Entity_Player& player, ItemConfig_Item* item); +void costume_post_remove(Entity_Player& player, ItemConfig_Item* item); +bool player_revive_is_cancelled(Entity_Player& player); +void player_revive_post(Entity_Player& player); +bool costumes_shuffle_is_cancelled(Entity_Player& player, uint32_t seed); +void costumes_shuffle_post(Entity_Player& player, uint32_t seed); +std::optional player_death_pre_trigger(Entity_Player& player); +void player_death_post_check_revives(Entity_Player& player); +bool player_bomb_use_is_cancelled(Entity_Player& player); +void player_bomb_post_use(Entity_Player& player, Entity_Bomb& bomb); +bool player_birth_is_cancelled(Entity_Player& player, uint32_t familiarFlag, ConceptionBirth birth); +bool pocket_swap_is_cancelled(Entity_Player& player); +std::optional pocket_pre_add(Entity_Player& player, int pocketItemType, int id, int slot); +void pocket_post_add(Entity_Player& player, int pocketItemType, int id, int slot); +void pocket_post_remove(Entity_Player& player, int pocketItemType, int id, int slot); +void pocket_post_drop(Entity_Player& player, int pocketItemType, int id, int slot, Entity* pickup); +bool pocket_collect_is_cancelled(Entity_Pickup& pocket, Entity_Player& player); +void pocket_collect_post(Entity_Pickup& pocket, Entity_Player& player); +bool hud_hearts_pre_render(PlayerHUD& hud, const HudHeartsDraw& draw); +void hud_hearts_post_render(PlayerHUD& hud, const HudHeartsDraw& draw); +bool hud_active_item_pre_render(PlayerHUD& hud, const HudActiveDraw& draw); +void hud_active_item_post_render(PlayerHUD& hud, const HudActiveDraw& draw); +bool hud_trinket_pre_render(PlayerHUD& hud, int slot, Vector& position, float& scale, Vector& cropOffset); diff --git a/src/repentogon/render.cpp b/src/repentogon/render.cpp new file mode 100644 index 0000000..f6e78e7 --- /dev/null +++ b/src/repentogon/render.cpp @@ -0,0 +1,227 @@ +#include "repentogon/render.h" +#include "entity/player/player.h" +#include "level/grid/door.h" +#include "level/grid/pit.h" +#include "level/grid/poop.h" +#include "level/grid/pressure_plate.h" +#include "level/grid/rock.h" +#include "level/grid/spikes.h" +#include "level/grid/tnt.h" +#include "level/room.h" +#include "repentogon/callbacks.h" + +// The game's own player types, whose pages and portraits run the character menu's callbacks as REPENTOGON's patches +// of the game's drawing do. Modded ones beyond them run them from their mods' drawing. +constexpr int GAME_PLAYER_TYPE_COUNT = PLAYER_THESOUL_B + 1; + +// REPENTOGON's PRE and POST render callbacks of a grid entity's kind, which its class's Render runs, none for a kind +// whose Render it does not hook (gravity, statues, the alternate spikes). +static std::pair grid_render_callbacks(GridEntityType type) +{ + switch (type) + { + case GRID_DECORATION: return {MC_PRE_GRID_ENTITY_DECORATION_RENDER, MC_POST_GRID_ENTITY_DECORATION_RENDER}; + case GRID_ROCK: + case GRID_ROCKB: + case GRID_ROCKT: + case GRID_ROCK_BOMB: + case GRID_ROCK_ALT: + case GRID_ROCK_SS: + case GRID_PILLAR: + case GRID_ROCK_SPIKED: + case GRID_ROCK_ALT2: + case GRID_ROCK_GOLD: return {MC_PRE_GRID_ENTITY_ROCK_RENDER, MC_POST_GRID_ENTITY_ROCK_RENDER}; + case GRID_PIT: return {MC_PRE_GRID_ENTITY_PIT_RENDER, MC_POST_GRID_ENTITY_PIT_RENDER}; + case GRID_SPIKES: + case GRID_SPIKES_ONOFF: return {MC_PRE_GRID_ENTITY_SPIKES_RENDER, MC_POST_GRID_ENTITY_SPIKES_RENDER}; + case GRID_SPIDERWEB: return {MC_PRE_GRID_ENTITY_WEB_RENDER, MC_POST_GRID_ENTITY_WEB_RENDER}; + case GRID_LOCK: return {MC_PRE_GRID_ENTITY_LOCK_RENDER, MC_POST_GRID_ENTITY_LOCK_RENDER}; + case GRID_TNT: return {MC_PRE_GRID_ENTITY_TNT_RENDER, MC_POST_GRID_ENTITY_TNT_RENDER}; + case GRID_FIREPLACE: return {MC_PRE_GRID_ENTITY_FIRE_RENDER, MC_POST_GRID_ENTITY_FIRE_RENDER}; + case GRID_POOP: return {MC_PRE_GRID_ENTITY_POOP_RENDER, MC_POST_GRID_ENTITY_POOP_RENDER}; + case GRID_WALL: return {MC_PRE_GRID_ENTITY_WALL_RENDER, MC_POST_GRID_ENTITY_WALL_RENDER}; + case GRID_DOOR: return {MC_PRE_GRID_ENTITY_DOOR_RENDER, MC_POST_GRID_ENTITY_DOOR_RENDER}; + case GRID_TRAPDOOR: return {MC_PRE_GRID_ENTITY_TRAPDOOR_RENDER, MC_POST_GRID_ENTITY_TRAPDOOR_RENDER}; + case GRID_STAIRS: return {MC_PRE_GRID_ENTITY_STAIRCASE_RENDER, MC_POST_GRID_ENTITY_STAIRCASE_RENDER}; + case GRID_PRESSURE_PLATE: + return {MC_PRE_GRID_ENTITY_PRESSUREPLATE_RENDER, MC_POST_GRID_ENTITY_PRESSUREPLATE_RENDER}; + case GRID_TELEPORTER: return {MC_PRE_GRID_ENTITY_TELEPORTER_RENDER, MC_POST_GRID_ENTITY_TELEPORTER_RENDER}; + default: return {}; + } +} + +// Runs a grid render callback, filtered by the grid entity's kind, with it as the class the API has for its kind (a +// GridEntity for the kinds it has none for yet). Whether it ran, leaving its result. +template +static bool grid_callback_run(int callback, GridEntity& grid, Args... args) +{ + LuaEngine& engine = lua_engine_get(); + CallbackRun run = {"GridEntityRender", callback, grid.type}; + auto grid_run = [&](auto* pushed) { return callback_run(engine, run, pushed, args...); }; + switch (grid_render_callbacks(grid.type).first) + { + case MC_PRE_GRID_ENTITY_ROCK_RENDER: return grid_run(static_cast(&grid)); + case MC_PRE_GRID_ENTITY_PIT_RENDER: return grid_run(static_cast(&grid)); + case MC_PRE_GRID_ENTITY_SPIKES_RENDER: return grid_run(static_cast(&grid)); + case MC_PRE_GRID_ENTITY_TNT_RENDER: return grid_run(static_cast(&grid)); + case MC_PRE_GRID_ENTITY_POOP_RENDER: return grid_run(static_cast(&grid)); + case MC_PRE_GRID_ENTITY_DOOR_RENDER: return grid_run(static_cast(&grid)); + case MC_PRE_GRID_ENTITY_PRESSUREPLATE_RENDER: return grid_run(static_cast(&grid)); + default: return grid_run(&grid); + } +} + +// Draws a grid entity through its Render inside the PRE and POST render callbacks of its kind. Any PRE boolean skips +// the render and POST, a Vector replaces the offset. +void grid_entity_render(GridEntity& grid, const Vector& offset) +{ + lua_State* state = lua_engine_get().state; + auto [pre, post] = grid_render_callbacks(grid.type); + Vector moved = offset; + if (pre && grid_callback_run(pre, grid, offset)) + { + bool isSkipped = lua_isboolean(state, -1); + object_read(state, moved); + lua_pop(state, 1); + if (isSkipped) return; + } + + grid.Render(moved); + if (post && grid_callback_run(post, grid)) lua_pop(state, 1); +} + +// Runs a PRE lighting callback for what lights the room at offset. False skips the light, a Vector moves it. +// Whether it lights. +template +static bool light_render_pre(CallbackRun run, T* lit, Vector& offset) +{ + LuaEngine& engine = lua_engine_get(); + if (!callback_run(engine, run, lit, offset)) return true; + + bool isLit = !is_result_false(engine.state); + Vector moved = {}; + object_read(engine.state, moved); + offset = vector_add(offset, moved); + lua_pop(engine.state, 1); + return isLit; +} + +// Runs MC_PRE_RENDER_GRID_LIGHTING before a grid entity's light, filtered by its type. Whether it lights. +bool grid_light_render_pre(GridEntity& grid, Vector& offset) +{ + return light_render_pre({"MC_PRE_RENDER_GRID_LIGHTING", MC_PRE_RENDER_GRID_LIGHTING, grid.type}, &grid, offset); +} + +// Runs MC_PRE_RENDER_ENTITY_LIGHTING before an entity's light, filtered by its type, with sprites drawing as lights +// while it runs. Whether it lights. +bool entity_light_render_pre(Entity& entity, Vector& offset) +{ + DAT_00c7977e = 1; + bool isLit = light_render_pre({"MC_PRE_RENDER_ENTITY_LIGHTING", MC_PRE_RENDER_ENTITY_LIGHTING, entity.type}, + &entity, offset); + DAT_00c7977e = 0; + return isLit; +} + +// Runs MC_PRE_GET_LIGHTING_ALPHA with the room's shadow alpha, which a number replaces. +// The alpha, nothing when no mod added a function or this is the hook's own call. +std::optional lighting_alpha_hook(Room& room) +{ + LuaEngine& engine = lua_engine_get(); + if (is_hook_inner() || !engine.is_callback_enabled(MC_PRE_GET_LIGHTING_ALPHA)) return std::nullopt; + + float alpha = hook_inner_call([&] { return room.GetLightingAlpha(); }); + if (!callback_run(engine, {"MC_PRE_GET_LIGHTING_ALPHA", MC_PRE_GET_LIGHTING_ALPHA, std::nullopt}, alpha)) + return alpha; + if (lua_isnumber(engine.state, -1)) alpha = (float)lua_tonumber(engine.state, -1); + lua_pop(engine.state, 1); + return alpha; +} + +// Runs MC_PRE_REPLACE_SPRITESHEET and MC_POST_REPLACE_SPRITESHEET around ANM2::ReplaceSpritesheet, filtered by the +// sprite's file. A PRE table of a layer and a path replaces both. +// Whether the layer took the path, nothing when no mod added a function or this is the hook's own call. +std::optional spritesheet_replace_hook(ANM2& sprite, int layerId, std::string_view path) +{ + LuaEngine& engine = lua_engine_get(); + bool isPre = engine.is_callback_enabled(MC_PRE_REPLACE_SPRITESHEET); + if (is_hook_inner() || (!isPre && !engine.is_callback_enabled(MC_POST_REPLACE_SPRITESHEET))) return std::nullopt; + + std::string sheet(path); + std::string file = sprite.filename; + CallbackRun run = {.name = "MC_PRE_REPLACE_SPRITESHEET", .id = MC_PRE_REPLACE_SPRITESHEET, + .stringParam = file.c_str()}; + if (callback_run(engine, run, file, layerId, sheet)) + { + if (lua_istable(engine.state, -1)) elements_pop(engine.state, layerId, sheet); + else lua_pop(engine.state, 1); + } + + bool isReplaced = hook_inner_call([&] { return sprite.ReplaceSpritesheet(layerId, sheet); }); + run.name = "MC_POST_REPLACE_SPRITESHEET"; + run.id = MC_POST_REPLACE_SPRITESHEET; + callback_notify(engine, run, file, layerId, sheet); + return isReplaced; +} + +// Draws a portrait of the character wheel inside MC_PRE_RENDER_CHARACTER_SELECT_PORTRAIT and +// MC_POST_RENDER_CHARACTER_SELECT_PORTRAIT, filtered by the player type, which pass copies of its scale and color. +// PRE false skips it and POST, a Vector moves it. Whether it drew it itself. +bool character_portrait_hook(ANM2& sprite, Vector position, int playerType) +{ + LuaEngine& engine = lua_engine_get(); + bool isPre = engine.is_callback_enabled(MC_PRE_RENDER_CHARACTER_SELECT_PORTRAIT); + bool isPost = engine.is_callback_enabled(MC_POST_RENDER_CHARACTER_SELECT_PORTRAIT); + if ((!isPre && !isPost) || playerType >= GAME_PLAYER_TYPE_COUNT) return false; + + Vector scale = sprite.scale; + ColorMod color = sprite.color; + auto portrait_run = [&](CallbackRun run) { + return callback_run(engine, run, playerType, &sprite, position, &scale, &color); + }; + if (portrait_run({"MC_PRE_RENDER_CHARACTER_SELECT_PORTRAIT", MC_PRE_RENDER_CHARACTER_SELECT_PORTRAIT, playerType})) + { + bool isSkipped = is_result_false(engine.state); + object_read(engine.state, position); + lua_pop(engine.state, 1); + if (isSkipped) return true; + } + + sprite.Render({position}); + CallbackRun post = {"MC_POST_RENDER_CHARACTER_SELECT_PORTRAIT", MC_POST_RENDER_CHARACTER_SELECT_PORTRAIT, playerType}; + if (portrait_run(post)) lua_pop(engine.state, 1); + return true; +} + +// Runs MC_PRE_RENDER_CHARACTER_SELECT_PAGE before a character's page, filtered by the player type. Whether it draws. +bool character_page_pre(CharacterPage page) +{ + CallbackRun run = {"MC_PRE_RENDER_CHARACTER_SELECT_PAGE", MC_PRE_RENDER_CHARACTER_SELECT_PAGE, page.playerType}; + return callback_boolean_get(run, page.playerType, page.position, &page.vanillaSprite, page.customSprite, + page.isCustomBackground) + .value_or(true); +} + +// Runs MC_POST_RENDER_CHARACTER_SELECT_PAGE after a character's page, filtered by the player type, a modded +// character's after the older MC_PRE_RENDER_CUSTOM_CHARACTER_MENU, which also ran after the page. +void character_page_post(CharacterPage page) +{ + LuaEngine& engine = lua_engine_get(); + if (page.playerType >= GAME_PLAYER_TYPE_COUNT) + callback_notify(engine, {"MC_PRE_RENDER_CUSTOM_CHARACTER_MENU", MC_PRE_RENDER_CUSTOM_CHARACTER_MENU, page.playerType}, + page.playerType, page.position, &page.vanillaSprite); + callback_notify(engine, {"MC_POST_RENDER_CHARACTER_SELECT_PAGE", MC_POST_RENDER_CHARACTER_SELECT_PAGE, page.playerType}, + page.playerType, page.position, &page.vanillaSprite, page.customSprite, page.isCustomBackground); +} + +// Draws the game's page of a character inside the page callbacks. Whether it drew, false when a mod skipped it, which +// also hides Eden's token count. +bool character_page_render(ANM2& sprite, Vector position, int playerType) +{ + CharacterPage page = {nullptr, sprite, position, playerType, false}; + if (playerType < GAME_PLAYER_TYPE_COUNT && !character_page_pre(page)) return false; + + sprite.Render({position}); + if (playerType < GAME_PLAYER_TYPE_COUNT) character_page_post(page); + return true; +} diff --git a/src/repentogon/render.h b/src/repentogon/render.h new file mode 100644 index 0000000..d2fd82c --- /dev/null +++ b/src/repentogon/render.h @@ -0,0 +1,31 @@ +#pragma once + +#include +#include + +class Room; +struct ANM2; +struct Entity; +struct GridEntity; +struct Vector; + +// A character's page as the character menu draws it: a modded character's own sprite (none for the game's), the +// game's page sprite, where, the player type, and whether the modded sprite brings its own background. +struct CharacterPage +{ + ANM2* customSprite; + ANM2& vanillaSprite; + Vector& position; + int playerType; + bool isCustomBackground; +}; + +void grid_entity_render(GridEntity& grid, const Vector& offset); +bool grid_light_render_pre(GridEntity& grid, Vector& offset); +bool entity_light_render_pre(Entity& entity, Vector& offset); +std::optional lighting_alpha_hook(Room& room); +std::optional spritesheet_replace_hook(ANM2& sprite, int layerId, std::string_view path); +bool character_portrait_hook(ANM2& sprite, Vector position, int playerType); +bool character_page_pre(CharacterPage page); +void character_page_post(CharacterPage page); +bool character_page_render(ANM2& sprite, Vector position, int playerType); diff --git a/src/repentogon/repentogon.cpp b/src/repentogon/repentogon.cpp index 283b207..5596722 100644 --- a/src/repentogon/repentogon.cpp +++ b/src/repentogon/repentogon.cpp @@ -2,6 +2,8 @@ #include "engine/data.h" #include "engine/platform.h" #include "lua/api.h" +#include "lua/callbacks.h" +#include "lua/engine.h" #include "repentogon/options.h" constexpr const char* SCRIPTS_FOLDER = "repentogon/scripts/"; @@ -86,3 +88,22 @@ void repentogon_scripts_run(LuaEngine& engine) lua_pushnil(state); lua_setglobal(state, GLOBAL); } + +// (ASMCallbacks.cpp) Runs MC_PRE_MOD_UNLOAD for every mod as the game shuts down, after the run saved, with its +// shutting down argument true. The rebuild leaves the engine to the process's exit, so no unload runs it later. +void mods_shutdown_notify(LuaEngine& engine) +{ + if (!engine.is_callback_enabled(MC_PRE_MOD_UNLOAD)) return; + + lua_State* state = engine.state; + for (LuaMod& mod : engine.mods) + { + lua_rawgeti(state, LUA_REGISTRYINDEX, engine.runCallbackRef); + lua_pushinteger(state, MC_PRE_MOD_UNLOAD); + lua_pushnil(state); + lua_rawgeti(state, LUA_REGISTRYINDEX, mod.tableRef); + lua_pushboolean(state, true); + if (lua_pcall(state, 4, 1, 0) == LUA_OK) lua_pop(state, 1); + else lua_error_log(state, "PreModUnload"); + } +} diff --git a/src/repentogon/repentogon.h b/src/repentogon/repentogon.h index 934bb11..9cd54cc 100644 --- a/src/repentogon/repentogon.h +++ b/src/repentogon/repentogon.h @@ -10,3 +10,4 @@ constexpr bool IS_REPENTOGON_EXPOSED = false; std::string repentogon_script_path(std::string_view path); void repentogon_scripts_run(LuaEngine& engine); +void mods_shutdown_notify(LuaEngine& engine); diff --git a/src/repentogon/saves.cpp b/src/repentogon/saves.cpp new file mode 100644 index 0000000..5fd7a94 --- /dev/null +++ b/src/repentogon/saves.cpp @@ -0,0 +1,150 @@ +#include "repentogon/saves.h" +#include "game/game.h" +#include "game/manager.h" +#include "repentogon/callbacks.h" +#include + +// (GameStateManagement.cpp) Runs a callback around a save or restore of a game state the game keeps, the save file's +// or a Glowing Hourglass slot's, then for a slot its hourglass callback with the slot. +void game_state_callbacks_run(GameState& state, int callback, int hourglassCallback) +{ + std::array& slots = g_game->glowingHourglassStates; + auto slot = std::ranges::find_if(slots, [&](GlowingHourglassState& kept) { return &kept.gameState == &state; }); + bool isHourglass = slot != slots.end(); + if (!isHourglass && &state != &g_manager->gamestate) return; + + unfiltered_notify("GameState", callback); + if (isHourglass) unfiltered_notify("GlowingHourglass", hourglassCallback, (int)(slot - slots.begin())); +} + +// A rider saved for its minecart, which MC_ENTITY_SAVE reports once the minecart saved too. +static Entity* savedRider = nullptr; + +// (EntitySaveStateManagement.cpp) Runs MC_ENTITY_SAVE for an entity the room saved, a minecart's rider first. Whether +// it saved. +bool entity_save_hook(Room& room, Entity& entity, EntitySaveState& state, MinecartCheck check) +{ + Entity* rider = std::exchange(savedRider, nullptr); + if (!hook_inner_call([&] { return entity_state_save(room, entity, state, check); })) return false; + if (check == MINECART_IGNORED) + { + savedRider = &entity; + return true; + } + + if (rider) unfiltered_notify("EntitySave", MC_ENTITY_SAVE, rider); + unfiltered_notify("EntitySave", MC_ENTITY_SAVE, &entity); + return true; +} + +// Runs MC_POST_BACKWARDS_ROOM_SAVE after a stage's rooms were kept for the Ascent, for each of the floor's rooms kept, +// with the stage and the key the Ascent loads it by (boss_0, treasure_1...). +void backwards_rooms_post(int stage, BackwardsStageDesc& saved) +{ + if (!lua_engine_get().is_callback_enabled(MC_POST_BACKWARDS_ROOM_SAVE)) return; + + for (auto [rooms, key] : {std::pair{&saved.bossRooms, "boss"}, {&saved.treasureRooms, "treasure"}}) + for (size_t i = 0; i < rooms->size(); i++) + { + RoomDescriptor* desc = &g_game->roomList[(*rooms)[i].desc.listIndex]; + std::string name = std::format("{}_{}", key, i); + unfiltered_notify("PostBackwardsRoomSave", MC_POST_BACKWARDS_ROOM_SAVE, stage, desc, name); + } +} + +// A completion mark's character and kind by the event counter holding it, as REPENTOGON's CompletionTracker maps +// them: the highest player type sharing a counter, and Ultra Greedier over Ultra Greed. No character for other +// counters. +struct MarkOwner +{ + int completion = 0; + int playerType = -1; +}; + +static std::array mark_owners_make() +{ + std::array owners{}; + for (int playerType = 0; playerType < COMPLETION_PLAYER_TYPE_COUNT; playerType++) + for (int completion = 0; completion < COMPLETION_TAINTED; completion++) + { + int counter = COMPLETION_MARKS[playerType][completion].counter; + if (counter && completion != COMPLETION_GREED_DONATION && completion != COMPLETION_HARD) + owners[counter] = {completion, playerType}; + } + return owners; +} + +// The mark counter a hard run raised last, its normal bit, and whether MC_COMPLETION_MARK_GET refused it. +static int lastMarkCounter = -1; +static bool isMarkRefused = false; + +// (CompletionTracker.cpp) Runs MC_COMPLETION_MARK_GET before a character's completion mark counter rises, filtered by +// the character, and MC_POST_COMPLETION_MARK_GET after. False refuses the mark. A hard run raises the normal bit only +// once a mark, as the refusal holds for it. Whether it ran the counter's own rise. +bool completion_mark_hook(PersistentGameData& data, int counter, int num) +{ + static std::array owners = mark_owners_make(); + LuaEngine& engine = lua_engine_get(); + bool isEnabled = engine.is_callback_enabled(MC_COMPLETION_MARK_GET) || + engine.is_callback_enabled(MC_POST_COMPLETION_MARK_GET); + if (!isEnabled || num <= 0 || counter < 0 || counter >= EVENT_COUNTER_COUNT || owners[counter].playerType < 0) + return false; + + MarkOwner owner = owners[counter]; + Difficulty difficulty = g_game ? g_game->difficulty : DIFFICULTY_NORMAL; + bool isHardFirst = (difficulty == DIFFICULTY_HARD || difficulty == DIFFICULTY_GREEDIER) && num == 1; + auto increase = [&] { hook_inner_call([&] { data.IncreaseEventCounter(counter, num); }); }; + if (isHardFirst && lastMarkCounter == counter) + { + if (!std::exchange(isMarkRefused, false)) increase(); + return true; + } + + CallbackRun pre = {"CompletionMarkGet", MC_COMPLETION_MARK_GET, owner.playerType}; + if (!boolean_run(pre, true, owner.completion, owner.playerType)) + { + if (!isHardFirst) return true; + lastMarkCounter = counter; + isMarkRefused = true; + return true; + } + increase(); + CallbackRun post = {"PostCompletionMarkGet", MC_POST_COMPLETION_MARK_GET, owner.playerType}; + callback_notify(engine, post, owner.completion, owner.playerType); + if (isHardFirst) lastMarkCounter = counter; + return true; +} + +// (CustomCallbacks.cpp) Runs MC_PRE_COMPLETION_EVENT before the players earn a completion mark, filtered by the +// completion. False refuses it, a completion from 0 to 17 replaces it, and any other integer refuses it. Whether the +// players earn one. +bool completion_event_pre(int& completion) +{ + LuaEngine& engine = lua_engine_get(); + if (!callback_run(engine, {"PreCompletionEvent", MC_PRE_COMPLETION_EVENT, completion}, completion)) return true; + + lua_State* state = engine.state; + bool isEarned = !is_result_false(state); + if (lua_isinteger(state, -1)) + { + int replaced = (int)lua_tointeger(state, -1); + isEarned = replaced >= 0 && replaced < COMPLETION_TYPE_COUNT; + if (isEarned) completion = replaced; + } + lua_pop(state, 1); + return isEarned; +} + +// Whether a save file was picked since the game started on none, which MC_POST_SAVESLOT_LOAD passes. +static bool isSlotPicked = false; +static bool isSlotNoneSet = false; + +// (CustomCallbacks.cpp) Runs MC_POST_SAVESLOT_LOAD after a save file became the current one, filtered by the file (1 +// for none), with whether one was picked after none and the file itself. +void save_slot_post(uint32_t slot) +{ + if (slot > 0) isSlotPicked |= isSlotNoneSet; + else isSlotNoneSet = true; + int shown = slot > 0 ? (int)slot : 1; + callback_notify(lua_engine_get(), {"PostSaveslotLoad", MC_POST_SAVESLOT_LOAD, shown}, shown, isSlotPicked, slot); +} diff --git a/src/repentogon/saves.h b/src/repentogon/saves.h new file mode 100644 index 0000000..02cdde7 --- /dev/null +++ b/src/repentogon/saves.h @@ -0,0 +1,15 @@ +#pragma once + +#include "level/room_state.h" +#include + +class PersistentGameData; +struct BackwardsStageDesc; +struct GameState; + +void game_state_callbacks_run(GameState& state, int callback, int hourglassCallback); +bool entity_save_hook(Room& room, Entity& entity, EntitySaveState& state, MinecartCheck check); +void backwards_rooms_post(int stage, BackwardsStageDesc& saved); +bool completion_mark_hook(PersistentGameData& data, int counter, int num); +bool completion_event_pre(int& completion); +void save_slot_post(uint32_t slot); diff --git a/src/repentogon/stats.cpp b/src/repentogon/stats.cpp new file mode 100644 index 0000000..ca15234 --- /dev/null +++ b/src/repentogon/stats.cpp @@ -0,0 +1,15 @@ +#include "repentogon/stats.h" +#include "entity/player/player.h" +#include "repentogon/callbacks.h" + +// (EvaluateStats.cpp) Runs MC_EVALUATE_STAT, filtered by the stage, with a stat's value there. A number replaces it, +// at the flat tears stage only a positive one. +float stat_evaluate(Entity_Player& player, float value, EvaluateStatStage stage) +{ + LuaEngine& engine = lua_engine_get(); + if (!callback_run(engine, {"EvaluateStat", MC_EVALUATE_STAT, stage}, &player, (int)stage, value)) return value; + + float result = lua_isnumber(engine.state, -1) ? (float)lua_tonumber(engine.state, -1) : value; + lua_pop(engine.state, 1); + return stage != STAT_STAGE_FLAT_TEARS || result > 0 ? result : value; +} diff --git a/src/repentogon/stats.h b/src/repentogon/stats.h new file mode 100644 index 0000000..4a3948c --- /dev/null +++ b/src/repentogon/stats.h @@ -0,0 +1,15 @@ +#pragma once + +struct Entity_Player; + +// REPENTOGON's EvaluateStatStage: the points of a player's tears and damage evaluation where MC_EVALUATE_STAT runs. +enum EvaluateStatStage +{ + STAT_STAGE_TEARS_UP, + STAT_STAGE_FLAT_TEARS, + STAT_STAGE_DAMAGE_UP, + STAT_STAGE_FLAT_DAMAGE, + STAT_STAGE_PRE_FLAT_DAMAGE +}; + +float stat_evaluate(Entity_Player& player, float value, EvaluateStatStage stage); diff --git a/src/repentogon/status.cpp b/src/repentogon/status.cpp new file mode 100644 index 0000000..3573c0e --- /dev/null +++ b/src/repentogon/status.cpp @@ -0,0 +1,58 @@ +#include "repentogon/status.h" +#include "entity/entity.h" +#include "repentogon/callbacks.h" + +// A status argument as the callbacks pass it: a class value (the knockback's push) by pointer, which a mod may change. +template +auto status_argument(T& value) +{ + if constexpr (IS_LUA_CLASS) return &value; + else return value; +} + +// (CustomCallbacks.cpp) Runs MC_PRE_STATUS_EFFECT_APPLY. False cancels the status, an integer replaces the duration, +// a table the values in order. +template +StatusApplyScope::StatusApplyScope(int status, Entity& entity, const EntityRef& source, Values&... values) + : status(status), entity(entity), source(source), values(values...) +{ + lua_State* state = lua_engine_get().state; + if (!run(MC_PRE_STATUS_EFFECT_APPLY)) return; + + int key = 1; + auto read = [&](auto& value) { + if constexpr (IS_LUA_CLASS>) + { + lua_geti(state, -1, key++); + object_read(state, value); + lua_pop(state, 1); + } + else element_read(state, key++, value); + }; + isCancelled = is_result_false(state); + if (lua_isinteger(state, -1)) std::get<0>(this->values) = (int)lua_tointeger(state, -1); + if (lua_istable(state, -1)) std::apply([&](auto&... each) { (read(each), ...); }, this->values); + lua_pop(state, 1); +} + +// Runs MC_POST_STATUS_EFFECT_APPLY with the values the status was added with. +template +StatusApplyScope::~StatusApplyScope() +{ + if (!isCancelled && run(MC_POST_STATUS_EFFECT_APPLY)) lua_pop(lua_engine_get().state, 1); +} + +// Runs a status callback, leaving its result. Whether it ran. +template +bool StatusApplyScope::run(int callback) +{ + CallbackRun callbackRun = {"StatusEffectApply", callback, status}; + auto run_with = [&](auto&... each) { + return callback_run(lua_engine_get(), callbackRun, status, &entity, &source, status_argument(each)...); + }; + return std::apply(run_with, values); +} + +template struct StatusApplyScope; +template struct StatusApplyScope; +template struct StatusApplyScope; diff --git a/src/repentogon/status.h b/src/repentogon/status.h new file mode 100644 index 0000000..4826b1b --- /dev/null +++ b/src/repentogon/status.h @@ -0,0 +1,44 @@ +#pragma once + +#include + +struct Entity; +struct EntityRef; + +// REPENTOGON's StatusEffect ids, which its status callbacks are filtered by. Slowing runs none. +enum StatusEffect +{ + STATUS_BAITED, + STATUS_BLEEDING, + STATUS_BRIMSTONE_MARK, + STATUS_BURN, + STATUS_CHARMED, + STATUS_CONFUSION, + STATUS_FEAR, + STATUS_FREEZE, + STATUS_ICE, + STATUS_KNOCKBACK, + STATUS_MAGNETIZED, + STATUS_MIDAS_FREEZE, + STATUS_POISON, + STATUS_SHRINK, + STATUS_SLOWING, + STATUS_WEAKNESS +}; + +// Runs MC_PRE_STATUS_EFFECT_APPLY as a status effect is added to an entity, filtered by the status, with its source and +// values (the duration first), and MC_POST_STATUS_EFFECT_APPLY with them as the scope ends, unless cancelled. +// Defined for the value lists the status functions pass. +template +struct StatusApplyScope +{ + int status; + Entity& entity; + const EntityRef& source; + std::tuple values; + bool isCancelled = false; + + StatusApplyScope(int status, Entity& entity, const EntityRef& source, Values&... values); + ~StatusApplyScope(); + bool run(int callback); +}; diff --git a/src/repentogon/weapons.cpp b/src/repentogon/weapons.cpp new file mode 100644 index 0000000..92b487a --- /dev/null +++ b/src/repentogon/weapons.cpp @@ -0,0 +1,169 @@ +#include "repentogon/weapons.h" +#include "entity/npc/npc.h" +#include "entity/player/player.h" +#include "entity/weapon/bomb.h" +#include "entity/weapon/tear.h" +#include "repentogon/callbacks.h" +#include +#include +#include + +// The players and weapon types whose MC_EVALUATE_TEAR_HIT_PARAMS runs, which a nested GetTearHitParams skips. +static std::vector> tearHitEvaluations; + +// Sets value to a number field of the table on top of the stack, not below 0, when it is a number. +static void number_field_read(lua_State* state, const char* key, float& value) +{ + lua_getfield(state, -1, key); + if (lua_isnumber(state, -1)) value = std::max((float)lua_tonumber(state, -1), 0.0f); + lua_pop(state, 1); +} + +// Sets value to a class value field of the table on top of the stack, when it is one. +template +static void object_field_read(lua_State* state, const char* key, V& value) +{ + lua_getfield(state, -1, key); + object_read(state, value); + lua_pop(state, 1); +} + +// The filter parameter of the explosion and tear effect callbacks: the source's type, nil without one. +static std::optional source_param(Entity* source) +{ + return source ? std::optional(source->type) : std::nullopt; +} + +// (Game::BombDamage hook) MC_PRE_BOMB_DAMAGE, filtered by the source's type, cancels the explosion's damage with false, +// or changes it with a table's Radius, Damage, TearFlags, DamageFlags and Position. MC_POST_BOMB_DAMAGE follows. +// Whether the hook dealt it. +bool explosion_damage_hook(const Explosion& original) +{ + LuaEngine& engine = lua_engine_get(); + bool isHooked = engine.is_callback_enabled(MC_PRE_BOMB_DAMAGE) || engine.is_callback_enabled(MC_POST_BOMB_DAMAGE); + if (is_hook_inner() || !isHooked) return false; + + Explosion explosion = original; + std::optional param = source_param(explosion.source); + auto run = [&](CallbackRun callback) + { + return callback_run(engine, callback, explosion.position, explosion.damage, explosion.radius, + explosion.isLineCheck, explosion.source, &explosion.tearFlags, explosion.damageFlags, + explosion.isDamageSource); + }; + if (run({"PreBombDamage", MC_PRE_BOMB_DAMAGE, param})) + { + lua_State* state = engine.state; + bool isCancelled = is_result_false(state); + if (lua_istable(state, -1)) + { + number_field_read(state, "Radius", explosion.radius); + number_field_read(state, "Damage", explosion.damage); + object_field_read(state, "TearFlags", explosion.tearFlags); + object_field_read(state, "Position", explosion.position); + lua_getfield(state, -1, "DamageFlags"); + if (lua_isnumber(state, -1)) explosion.damageFlags = (uint64_t)std::max(0.0, lua_tonumber(state, -1)); + lua_pop(state, 1); + } + lua_pop(state, 1); + if (isCancelled) return true; + } + + hook_inner_call([&] { explosion_damage(explosion); }); + if (run({"PostBombDamage", MC_POST_BOMB_DAMAGE, param})) lua_pop(engine.state, 1); + return true; +} + +// (Game::BombTearflagEffects hook) MC_PRE_BOMB_TEARFLAG_EFFECTS, filtered by the source's type, cancels the effects an +// explosion spreads with false, or changes them with a table's Radius, RadiusMult, TearFlags and Position. +// MC_POST_BOMB_TEARFLAG_EFFECTS follows. Whether the hook spread them. +bool explosion_tear_flag_effects_hook(const Explosion& original) +{ + LuaEngine& engine = lua_engine_get(); + bool isHooked = engine.is_callback_enabled(MC_PRE_BOMB_TEARFLAG_EFFECTS) || + engine.is_callback_enabled(MC_POST_BOMB_TEARFLAG_EFFECTS); + if (is_hook_inner() || !isHooked) return false; + + Explosion explosion = original; + std::optional param = source_param(explosion.source); + auto run = [&](CallbackRun callback) + { + return callback_run(engine, callback, explosion.position, explosion.radius, &explosion.tearFlags, + explosion.source, explosion.radiusMultiplier); + }; + if (run({"PreBombTearflagEffects", MC_PRE_BOMB_TEARFLAG_EFFECTS, param})) + { + lua_State* state = engine.state; + bool isCancelled = is_result_false(state); + if (lua_istable(state, -1)) + { + number_field_read(state, "Radius", explosion.radius); + number_field_read(state, "RadiusMult", explosion.radiusMultiplier); + object_field_read(state, "TearFlags", explosion.tearFlags); + object_field_read(state, "Position", explosion.position); + } + lua_pop(state, 1); + if (isCancelled) return true; + } + + hook_inner_call([&] { explosion_tear_flag_effects(explosion); }); + if (run({"PostBombTearflagEffects", MC_POST_BOMB_TEARFLAG_EFFECTS, param})) lua_pop(engine.state, 1); + return true; +} + +// (Entity_Tear::ApplyTearFlagEffects hook) For an NPC, MC_PRE_APPLY_TEARFLAG_EFFECTS, filtered by the source's type, +// cancels a hit's tear effects with false, or changes them with a table's Damage, TearFlags and Position. +// MC_POST_APPLY_TEARFLAG_EFFECTS follows. Whether the hook applied them. +bool tear_flag_effects_hook(TearFlagHit hit) +{ + LuaEngine& engine = lua_engine_get(); + bool isHooked = engine.is_callback_enabled(MC_PRE_APPLY_TEARFLAG_EFFECTS) || + engine.is_callback_enabled(MC_POST_APPLY_TEARFLAG_EFFECTS); + auto* npc = !is_hook_inner() && isHooked ? dynamic_cast(hit.entity) : nullptr; + if (!npc) return false; + + Vector position = hit.position; + TearFlags flags = hit.flags; + float damage = hit.damage; + std::optional param = source_param(hit.source); + auto run = [&](CallbackRun callback) + { return callback_run(engine, callback, npc, position, &flags, hit.source, damage); }; + if (run({"PreApplyTearflagEffects", MC_PRE_APPLY_TEARFLAG_EFFECTS, param})) + { + lua_State* state = engine.state; + bool isCancelled = is_result_false(state); + if (lua_istable(state, -1)) + { + number_field_read(state, "Damage", damage); + object_field_read(state, "TearFlags", flags); + object_field_read(state, "Position", position); + } + lua_pop(state, 1); + if (isCancelled) return true; + } + + hook_inner_call([&] { Entity_Tear::ApplyTearFlagEffects(npc, position, flags, hit.source, damage); }); + if (run({"PostApplyTearflagEffects", MC_POST_APPLY_TEARFLAG_EFFECTS, param})) lua_pop(engine.state, 1); + return true; +} + +// MC_EVALUATE_TEAR_HIT_PARAMS, filtered by the player's character, with the hit params a player's weapon fires with, +// which mods change in place or replace with a TearParams. Skipped inside its own run for the same player and weapon. +void tear_hit_params_evaluate(Entity_Player& player, TearParams& params, TearHitQuery query) +{ + std::pair evaluation = {&player, query.weaponType}; + LuaEngine& engine = lua_engine_get(); + if (!engine.is_callback_enabled(MC_EVALUATE_TEAR_HIT_PARAMS) || + std::ranges::find(tearHitEvaluations, evaluation) != tearHitEvaluations.end()) + return; + + tearHitEvaluations.push_back(evaluation); + CallbackRun run = {"EvaluateTearHitParams", MC_EVALUATE_TEAR_HIT_PARAMS, player.playerType}; + if (callback_run(engine, run, &player, ¶ms, query.weaponType, query.damageScale, query.displacement, + query.source)) + { + object_read(engine.state, params); + lua_pop(engine.state, 1); + } + std::erase(tearHitEvaluations, evaluation); +} diff --git a/src/repentogon/weapons.h b/src/repentogon/weapons.h new file mode 100644 index 0000000..1d1d559 --- /dev/null +++ b/src/repentogon/weapons.h @@ -0,0 +1,33 @@ +#pragma once + +#include + +struct Entity; +struct Entity_Player; +struct Explosion; +struct TearParams; +struct Vector; + +// A hit's tear effects as Entity_Tear::ApplyTearFlagEffects takes them. +struct TearFlagHit +{ + Entity* entity; + const Vector& position; + const std::bitset<128>& flags; + Entity* source; + float damage; +}; + +// What Entity_Player::GetTearHitParams was asked for besides the player. +struct TearHitQuery +{ + int weaponType; + float damageScale; + int displacement; + Entity* source; +}; + +bool explosion_damage_hook(const Explosion& explosion); +bool explosion_tear_flag_effects_hook(const Explosion& explosion); +bool tear_flag_effects_hook(TearFlagHit hit); +void tear_hit_params_evaluate(Entity_Player& player, TearParams& params, TearHitQuery query); diff --git a/src/ui/console.cpp b/src/ui/console.cpp index 36d9532..461c537 100644 --- a/src/ui/console.cpp +++ b/src/ui/console.cpp @@ -139,11 +139,12 @@ static bool is_key(int key, ActionTest test) (test == ACTION_TRIGGERED ? keyboard->is_button_triggered(key) : keyboard->is_button_pressed(key)); } -// Whether the console key was pressed: in a game a mod's input callback for it may decide, else the ` key does. +// Whether the console key was pressed: a mod's input callback for it may decide (in a game, or anywhere with +// REPENTOGON), else the ` key does. static bool is_open_pressed() { std::optional isModPressed; - if (g_manager->state == MANAGER_STATE_GAME && g_luaEngine) + if (is_input_hook_asked()) isModPressed = lua_engine_get().InputAction(nullptr, INPUT_HOOK_TRIGGERED, ACTION_CONSOLE); return isModPressed ? *isModPressed : is_key(KEY_GRAVE_ACCENT, ACTION_TRIGGERED); diff --git a/src/ui/cutscene.cpp b/src/ui/cutscene.cpp index b84e072..33f120d 100644 --- a/src/ui/cutscene.cpp +++ b/src/ui/cutscene.cpp @@ -625,8 +625,7 @@ static void part_start(CutscenePart& part) static bool skip_action_get(ButtonAction action) { std::optional isModTriggered; - if (g_manager->state == MANAGER_STATE_GAME && g_luaEngine) - isModTriggered = lua_engine_get().InputAction(nullptr, INPUT_HOOK_TRIGGERED, action); + if (is_input_hook_asked()) isModTriggered = lua_engine_get().InputAction(nullptr, INPUT_HOOK_TRIGGERED, action); return isModTriggered ? *isModTriggered : is_action(action, ACTION_TRIGGERED); } diff --git a/src/ui/hud.cpp b/src/ui/hud.cpp index bb2e89d..379eb17 100644 --- a/src/ui/hud.cpp +++ b/src/ui/hud.cpp @@ -21,6 +21,10 @@ #include #include #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/callbacks.h" +#include "repentogon/hud.h" +#endif constexpr const char* MPLUS_FONT = "font/MPlus_12b.fnt"; constexpr const char* KOREAN_FONT = "font/KR_Font14.fnt"; @@ -279,9 +283,14 @@ void HUD_Message::set_text_line(std::u16string_view line, int lineIndex) } // 00840b00 Shows a title, and a subtitle when given (else the last one stays), playing out the banner shown first. -// An auto hiding banner plays "Text" through, a sticky one stops on "TextStay" until text_out. +// An auto hiding banner plays "Text" through, a sticky one stops on "TextStay" until text_out. A mod's +// MC_PRE_ITEM_TEXT_DISPLAY may keep it from showing. void HUD_Message::Show(const char* title, const char* subtitle, bool isAutoHideOn, bool isCurse) { +#ifdef ISAAC_REPENTOGON + CallbackRun run = {"PreItemTextDisplay", MC_PRE_ITEM_TEXT_DISPLAY, std::nullopt}; + if (!boolean_run(run, true, title, subtitle, !isAutoHideOn, isCurse)) return; +#endif if (!title) return log_printf(LOG_ERROR, "HUD_Message::Show() recieved NULL messageText (This will have no effect) \n"); @@ -490,8 +499,13 @@ void HistoryHUD::clear() // trinkets shimmer, the error trinket shows red, Modeling Clay its copied item in clay, Monkey Paw its fingers left and // a glitched item its own icon. // The original leaves the shaders it picks current. Here they are popped after each icon. +// A mod may skip them or hide some. void HistoryHUD::Render(Vector at, bool isMini) { +#ifdef ISAAC_REPENTOGON + if (!history_render_pre(at, isMini)) return; + ScopeExit post{[=] { history_render_post(at, isMini); }}; +#endif KAGE::Graphics::Manager& graphics = KAGE::Graphics::manager; float iconSize = isMini ? HISTORY_MINI_ICON : HISTORY_ICON; int columns = isMini ? HISTORY_MINI_COLUMNS : HISTORY_COLUMNS; @@ -521,6 +535,9 @@ void HistoryHUD::Render(Vector at, bool isMini) HistoryHUDItem& icon = slot.items[i]; Vector position = vector_make((float)(i % columns) * iconSize + at.x, (float)(i / columns) * iconSize + at.y); if (position.y >= bottom) break; +#ifdef ISAAC_REPENTOGON + if (is_history_icon_hidden(icon)) continue; +#endif bool isGolden = icon.key > 0 && (icon.key & HISTORY_GOLDEN_KEY) == HISTORY_GOLDEN_KEY; ColorMod color = COLOR_DEFAULT; @@ -583,6 +600,9 @@ int HistoryHUD::player_slot_get(Entity_Player* player) // kept by key across the rebuild, each reused once, and loaded otherwise. A glitched item has no icon of its own. void HistoryHUD::Recompute(int playerIndex, HistoryRebuild rebuild) { +#ifdef ISAAC_REPENTOGON + ScopeExit post{[=] { history_recompute_post(playerIndex, rebuild); }}; +#endif if (playerIndex < 0 || playerIndex >= HISTORY_PLAYER_COUNT || !players[playerIndex].player) return; HistoryHUDPlayer& slot = players[playerIndex]; @@ -776,6 +796,9 @@ void HUD::unload_graphics() // paper sound as it slides in and out), then updates the item info panel. void HUD::Update() { +#ifdef ISAAC_REPENTOGON + unfiltered_notify("HudUpdate", MC_HUD_UPDATE); +#endif if (isRefreshTick) { hudRefreshCountdown--; @@ -809,6 +832,9 @@ void HUD::Update() // then the stats. void HUD::PostUpdate() { +#ifdef ISAAC_REPENTOGON + unfiltered_notify("HudPostUpdate", MC_HUD_POST_UPDATE); +#endif for (PlayerHUD& hud : playerHUD) if (hud.player) hud.Update(); @@ -995,8 +1021,12 @@ void HUD::show_fortune_text_impl(const char* text) // 009a3ac0 Writes a fortune's lines centred into the fortune surface in black, at half size when they are too wide or // too many, and plays the paper that fits them (Text, Text2 or Text3). No lines leave the plain paper, empty. +// A mod may keep the paper from showing. void HUD::render_fortune_text(const std::vector& lines) { +#ifdef ISAAC_REPENTOGON + if (!boolean_run({"PreFortuneDisplay", MC_PRE_FORTUNE_DISPLAY, std::nullopt}, true)) return; +#endif KAGE::Graphics::Manager& graphics = KAGE::Graphics::manager; Font& font = fortune_font(*this); float textScale = 1; @@ -1072,6 +1102,10 @@ void fortune_show(std::string_view category) // the co-op join carousel and the boss bar. Every corner forgets the box it covered first. void HUD::Render() { +#ifdef ISAAC_REPENTOGON + unfiltered_notify("HudRender", MC_HUD_RENDER); + ScopeExit post{[] { unfiltered_notify("PostHudRender", MC_POST_HUD_RENDER); }}; +#endif for (PlayerHUD& hud : playerHUD) hud.bounds_reset(); if (!isVisible) return; diff --git a/src/ui/menu/character.cpp b/src/ui/menu/character.cpp index 9cf1eef..1f616b8 100644 --- a/src/ui/menu/character.cpp +++ b/src/ui/menu/character.cpp @@ -13,6 +13,10 @@ #include #include #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/callbacks.h" +#include "repentogon/render.h" +#endif // Each menu's sheets: its pages, its portraits, and the face its background shows. struct MenuSheets @@ -340,11 +344,19 @@ void CompletionWidget::Update() } } -// 004252f0 Draws the widget at a scale. +// 004252f0 Draws the widget at a scale. A mod may skip it. void CompletionWidget::Render(Vector widgetPosition, Vector scale) { +#ifdef ISAAC_REPENTOGON + CallbackRun pre = {"PreCompletionMarksRender", MC_PRE_COMPLETION_MARKS_RENDER, std::nullopt}; + if (callback_boolean_get(pre, &anm2, &widgetPosition, &scale, characterId)) return; +#endif anm2.scale = scale; anm2.Render({widgetPosition}); +#ifdef ISAAC_REPENTOGON + unfiltered_notify("PostCompletionMarksRender", MC_POST_COMPLETION_MARKS_RENDER, &anm2, &widgetPosition, &scale, + characterId); +#endif } // 00947470 Loads every sprite of the menu on the first menu's sheets, the completion widget, and the snapshot the page @@ -744,10 +756,26 @@ void Menu_Character::random_spin_step() bigCharPageSprite.Play(CHARACTER_ENTRIES[characterMenuShown][selectedCharacterID].animationName); } +#ifdef ISAAC_REPENTOGON +// Whether MC_CAN_SELECT_CHARACTER asks about a character for a run starting with it or for another check. +enum CharacterSelect +{ + CHARACTER_SELECT_CHECK, + CHARACTER_SELECT_START +}; + +// (ASMCallbacks.cpp) Runs MC_CAN_SELECT_CHARACTER, filtered by the character. False refuses it. +static bool is_character_selectable(int playerType, CharacterSelect select) +{ + CallbackRun run = {"CanSelectCharacter", MC_CAN_SELECT_CHARACTER, playerType}; + return boolean_run(run, true, playerType, select == CHARACTER_SELECT_START); +} +#endif + // 0094de50 Picks the random character among the available ones and the modded ones, and winds the spin up to land on // it after three turns of the wheel. // The original reads before its table with nothing to pick, which cannot happen as Isaac is always there. Random's -// own slot is picked then. +// own slot is picked then. A mod may leave characters out, and buzz when none is left. void Menu_Character::SelectRandomChar() { std::vector candidates; @@ -755,6 +783,17 @@ void Menu_Character::SelectRandomChar() for (int i = 1; i < CHARACTER_ENTRY_COUNT; i++) if (CHARACTER_ENTRIES[characterMenuShown][i].IsCharacterAvailable()) candidates.push_back(i); for (int i = 0; i < (int)modCharacters.size(); i++) candidates.push_back(CHARACTER_ENTRY_COUNT + i); +#ifdef ISAAC_REPENTOGON + std::erase_if(candidates, [this](int menuId) { + return !is_character_selectable(GetPlayerTypeFromMenuID(menuId, characterMenuShown), CHARACTER_SELECT_CHECK); + }); + if (candidates.empty()) + { + menu_sound_play(SOUND_ERROR_BUZZ, 0); + status = CHARACTER_STATUS_SELECT; + return; + } +#endif int chosen = candidates.empty() ? MENU_ID_RANDOM : candidates[Random() % (uint32_t)candidates.size()]; chosenRandomCharacter = chosen; @@ -785,6 +824,7 @@ void Menu_Character::handle_input() // The selection's input: confirm spins for Random, starts the run on an unlocked character or buzzes; up and down // change the difficulty; left and right turn the wheel (repeating while held, once the wheel stopped); back leaves. +// A mod may refuse the character. void Menu_Character::select_input() { MenuManager& menus = *g_menuManager; @@ -803,6 +843,11 @@ void Menu_Character::select_input() input_poll_active_device(); } else if (!isCharacterUnlocked) menu_sound_play(SOUND_ERROR_BUZZ, SOUND_DELAY); +#ifdef ISAAC_REPENTOGON + else if (!is_character_selectable(GetPlayerTypeFromMenuID(selectedCharacterID, characterMenuShown), + CHARACTER_SELECT_START)) + menu_sound_play(SOUND_ERROR_BUZZ, SOUND_DELAY); +#endif else { g_manager->selectedDifficulty = difficulty; @@ -1145,12 +1190,19 @@ void Menu_Character::render_seed_unlock() // token count, and the blood stain of the hard difficulties fading in or out. void Menu_Character::render_wheel(Vector wheelPosition, WheelPortraits portraits) { + bool isPageShown = true; +#ifdef ISAAC_REPENTOGON + if (selectedCharacterID < CHARACTER_ENTRY_COUNT) + isPageShown = character_page_render(bigCharPageSprite, wheelPosition, + GetPlayerTypeFromMenuID(selectedCharacterID, characterMenuShown)); +#else if (selectedCharacterID < CHARACTER_ENTRY_COUNT) bigCharPageSprite.Render({wheelPosition}); +#endif else ModManager::RenderCustomCharacterMenu(GetPlayerTypeFromMenuID(selectedCharacterID, characterMenuShown), wheelPosition, bigCharPageSprite); if (portraits == WHEEL_WITH_PORTRAITS) render_portraits(wheelPosition, vector_make(0, 0), vector_make(1, 1)); - if (selectedCharacterID == MENU_ID_EDEN) + if (selectedCharacterID == MENU_ID_EDEN && isPageShown) { std::string_view format = string_table_translate(g_manager->stringTable, EDEN_TOKENS_KEY); std::array text{}; @@ -1225,7 +1277,11 @@ void Menu_Character::render_portraits(Vector wheelPosition, Vector offset, Vecto characterPortraitsSprite.SetFrame(entry.IsCharacterAvailable() ? 0.0f : 1.0f); characterPortraitsSprite.scale = portraitScale; characterPortraitsSprite.color = color; - characterPortraitsSprite.Render( - {vector_make(scale.x * portrait.position.x + wheelPosition.x + offset.x, portraitY)}); + Vector position = vector_make(scale.x * portrait.position.x + wheelPosition.x + offset.x, portraitY); +#ifdef ISAAC_REPENTOGON + int playerType = GetPlayerTypeFromMenuID(portrait.menuId, characterMenuShown); + if (character_portrait_hook(characterPortraitsSprite, position, playerType)) continue; +#endif + characterPortraitsSprite.Render({position}); } } diff --git a/src/ui/menu/manager.cpp b/src/ui/menu/manager.cpp index 4cd506a..9dc5523 100644 --- a/src/ui/menu/manager.cpp +++ b/src/ui/menu/manager.cpp @@ -7,6 +7,9 @@ #include "engine/render_passes.h" #include #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/callbacks.h" +#endif constexpr const char* EMPTY_SCREEN_PNG = "gfx/ui/main menu/EmptyScreen.png"; constexpr const char* MENU_OVERLAY_PNG = "gfx/ui/main menu/MenuOverlay.png"; @@ -496,6 +499,9 @@ void MenuManager::Render() flySprite.Render(menu_draw_get(vector_make(scrollInterpolationX, scrollInterpolationY))); popup_buttons_place(); +#ifdef ISAAC_REPENTOGON + unfiltered_notify("MainMenuRender", MC_MAIN_MENU_RENDER); +#endif vignette_update(); overlay_render(); if (isColorModifierEnabled) color_mod_render(); diff --git a/src/ui/nightmare_scene.cpp b/src/ui/nightmare_scene.cpp index ea68a53..a85b046 100644 --- a/src/ui/nightmare_scene.cpp +++ b/src/ui/nightmare_scene.cpp @@ -23,6 +23,9 @@ #include #include #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/callbacks.h" +#endif constexpr std::string_view BACKGROUND_DEFAULT = "nightmare_bg.anm2"; constexpr std::string_view SCENE_ANIM = "Scene"; @@ -280,6 +283,9 @@ static void dream_catcher_pages_get(NightmareScene& scene) // offline. void NightmareScene::Show(bool isSameStageShown) { +#ifdef ISAAC_REPENTOGON + ScopeExit post{[=] { unfiltered_notify("PostNightmareSceneShow", MC_POST_NIGHTMARE_SCENE_SHOW, isSameStageShown); }}; +#endif Game& game = *g_game; Entity_Player* player = game.GetPlayer(0); // The original indexed an empty nightmare list. This shows no scene. @@ -570,6 +576,9 @@ void NightmareScene::Render() if (isDreamCatcher) diary_render(*this); else if (bubbleSprite.isLoaded) bubbleSprite.Render({}); if (!isDogma) stage_bar_render(*this); +#ifdef ISAAC_REPENTOGON + unfiltered_notify("PostNightmareSceneRender", MC_POST_NIGHTMARE_SCENE_RENDER); +#endif if (fadeAlpha <= 0) return; graphics.blendMode.SetMode(KAGE::Graphics::BLEND_NORMAL); diff --git a/src/ui/pause_screen.cpp b/src/ui/pause_screen.cpp index ca47591..99e235a 100644 --- a/src/ui/pause_screen.cpp +++ b/src/ui/pause_screen.cpp @@ -18,6 +18,9 @@ #include "engine/platform.h" #include "level/room.h" #include +#ifdef ISAAC_REPENTOGON +#include "repentogon/callbacks.h" +#endif constexpr const char* PAUSE_ANM2 = "gfx/ui/PauseScreen_small.anm2"; constexpr const char* MY_STUFF_ANM2 = "gfx/ui/PauseScreen_MyStuff.anm2"; @@ -1039,8 +1042,18 @@ void PauseScreen::animation_update() // 009b7190 Draws the open page outside a boss intro: the paper at the bottom right with its seed and completion marks // (outside the no HUD seed, once marks are earned, in a run that can unlock), the options or My Stuff, then the prompt. +// A mod may skip it. void PauseScreen::Render() { +#ifdef ISAAC_REPENTOGON + // The stats paper's sprite REPENTOGON passes, which the rebuild leaves out: an empty one stands in. + static ANM2 statsSprite; + CallbackRun pre = {"PrePauseScreenRender", MC_PRE_PAUSE_SCREEN_RENDER, std::nullopt}; + if (callback_boolean_get(pre, &menuSprite, &statsSprite)) return; + ScopeExit post{[this] { + unfiltered_notify("PostPauseScreenRender", MC_POST_PAUSE_SCREEN_RENDER, &menuSprite, &statsSprite); + }}; +#endif Game& game = *g_game; if (game.roomTransition.mode != 0 && game.roomTransition.bossIntroBossId != 0) return;