REPENTOGON phase 0 (e2c5aec, GPL-2): ISAAC_REPENTOGON option (on), src/repentogon/ with the hidden REPENTOGON global switch, callback ids 1000-1499 with REPENTOGON's enable state and dispatch (priorities, optional and two-parameter filters, isolated errors), its scripts loaded from assets/repentogon/scripts, its options store and a vanilla-parity switch (on) in the overlay, scripts/repentogon_coverage.py and analysis/repentogon_coverage.tsv (2,834 rows)
This commit is contained in:
1 parent
78cb0775b0
commit
2cc082f6ee
31 files changed
+12955
-149
No files matched your search
+1
-125
@@ -1,4 +1,4 @@
|
||||
#include "lua/engine.h"
|
||||
#include "lua/callback_run.h"
|
||||
#include "classes.h"
|
||||
#include "entity/weapon/bomb.h"
|
||||
#include "entity/effect/effect.h"
|
||||
@@ -11,134 +11,10 @@
|
||||
#include "entity/weapon/projectile.h"
|
||||
#include "entity/weapon/tear.h"
|
||||
#include "game/game.h"
|
||||
#include "lua/api.h"
|
||||
#include "level/room_config.h"
|
||||
|
||||
constexpr int PILL_EFFECT_UNCHANGED = -1;
|
||||
|
||||
// One run of a callback: the name its errors log, its id, and the parameter mods filter it by.
|
||||
struct CallbackRun
|
||||
{
|
||||
const char* name;
|
||||
LuaCallback id;
|
||||
int param = CALLBACK_PARAM_NONE;
|
||||
};
|
||||
|
||||
// Calls _RunCallback with a callback's id, its filter parameter and its arguments when a mod added a function for it,
|
||||
// leaving its one result on the stack. Whether it ran, false without a function or on an error, which is logged.
|
||||
// The callers, result readers and error throws the original instantiates per callback are this and its readers
|
||||
// (00872980, 00872c60, 00873470, 00873980, 00873d00, 00873fc0, 00874120, 00874210, 00874310, 00874a10, 00874f60)
|
||||
// (0085c080, 008727d0, 0086130e, 00861225, 00861d96, 00861e7f, 008623a6, 0086248f, 008628b6, 0086299f, 00864453)
|
||||
// (0086453c, 00865bbc, 00872a20, 00872b10, 00872ff0, 008730e0, 00873890, 00873ac0, 00873bb0, 00873e40, 008746b0)
|
||||
// (00874860, 00874910, 00874ac0, 00874d20, 00874dd0, 00874e90, 00865a04, 0085bfd0, 0085bff0, 0085c270, 00873f40)
|
||||
// (00872da0, 00872e90, 00873230, 00873320, 00873560, 00873650, 00873740, 00874400, 00874550, 00875050, 008663b6)
|
||||
// (00872820, 00872860, 00872910, 00861c23, 00862233, 00862d53, 00865aad, 00865c61, 00866474, 00872a0c, 00872af1)
|
||||
// (00872c43, 00872d80, 00872e71, 00872fc3, 008730c1, 00873213, 00873301, 00873453, 00873541, 00873631, 00873721)
|
||||
// (00873873, 00873961, 00873aa0, 00873b91, 00873ce3, 00873e20, 00873f26, 00874103, 008741f1, 008742f7, 008743eb)
|
||||
// (00874533, 0087469a, 00874846, 008748f6, 008749f7, 00874aa8, 00874bbb, 00874d0a, 00874db6, 00874e7e, 00874f4a)
|
||||
// (00861bda, 008621ea, 00862d0a, 0085c250, 0085c2d0, 0085c300, 0085c340, 0085bf50, 0085c1d0, 0085c200, 0085c210)
|
||||
// (0085da70)
|
||||
// and their catches log through lua_error_log
|
||||
// (00860ea3, 008611da, 0086191f, 00861d4b, 0086235b, 0086286b, 00862ea4, 008632e1)
|
||||
// (00863706, 00863b6a, 00863e31, 00863f1e, 008640de, 00864408, 00864f6e, 00865b69, 008661cc, 00860826, 0086090e)
|
||||
// (00860a70, 00860b4b, 00860c36, 00860d1e, 008613bf, 0086149f, 00861587, 00862a4c, 00862b2f, 00862cb8, 00862f8c)
|
||||
// (0086306c, 00863154, 0086354b, 00863fff, 00864a6a, 00864bb8, 00864d16, 00865209, 008652e9, 00865424, 008659a7)
|
||||
// (00865d53, 00865e99, 00865fe8, 008660ec)
|
||||
// (00860f8b, 00861076, 0086166f, 0086174f, 00861837, 008619ff, 00861b88, 00861f2f, 0086200f, 00862198, 0086253f)
|
||||
// (0086261f, 00862707, 0086362b, 00863879, 00863c6e, 00863d4e, 008641bb, 008642a4, 00864682, 00864e6d, 0086504e)
|
||||
// (0086512e, 008655b7, 00866364, 0086675e, 008668e0).
|
||||
template <typename... Args>
|
||||
static bool callback_run(LuaEngine& engine, CallbackRun run, Args... args)
|
||||
{
|
||||
if (!engine.enabledCallbacks[run.id]) return false;
|
||||
lua_State* state = engine.state;
|
||||
|
||||
lua_rawgeti(state, LUA_REGISTRYINDEX, engine.runCallbackRef);
|
||||
lua_push(state, (int)run.id);
|
||||
lua_push(state, run.param);
|
||||
(lua_push(state, args), ...);
|
||||
if (lua_pcall(state, sizeof...(Args) + 2, 1, 0) == LUA_OK) return true;
|
||||
|
||||
lua_error_log(state, run.name);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Runs a callback whose result the game ignores.
|
||||
template <typename... Args>
|
||||
static void callback_notify(LuaEngine& engine, CallbackRun run, Args... args)
|
||||
{
|
||||
if (callback_run(engine, run, args...)) lua_pop(engine.state, 1);
|
||||
}
|
||||
|
||||
// Runs a callback whose result is an integer that replaces fallback.
|
||||
// The original aborts on a result that is neither nil nor an integer. This keeps fallback instead.
|
||||
template <typename... Args>
|
||||
static int callback_integer_run(LuaEngine& engine, CallbackRun run, int fallback, Args... args)
|
||||
{
|
||||
if (!callback_run(engine, run, args...)) return fallback;
|
||||
|
||||
int isInteger = 0;
|
||||
lua_Integer result = lua_tointegerx(engine.state, -1, &isInteger);
|
||||
lua_pop(engine.state, 1);
|
||||
return isInteger ? (int)result : fallback;
|
||||
}
|
||||
|
||||
// Runs a callback whose result, when not nil, is a boolean that replaces fallback.
|
||||
template <typename... Args>
|
||||
static bool callback_boolean_run(LuaEngine& engine, CallbackRun run, bool fallback, Args... args)
|
||||
{
|
||||
if (!callback_run(engine, run, args...)) return fallback;
|
||||
|
||||
bool result = lua_isnil(engine.state, -1) ? fallback : lua_toboolean(engine.state, -1);
|
||||
lua_pop(engine.state, 1);
|
||||
return result;
|
||||
}
|
||||
|
||||
// Runs a Pre*Collision callback for an entity and what it hits, and reads its result as true, false or nothing.
|
||||
template <typename T>
|
||||
static LuaResult collision_run(LuaEngine& engine, CallbackRun run, T* entity, Entity* collider, bool isLow)
|
||||
{
|
||||
if (!callback_run(engine, run, entity, collider, isLow)) return LUA_RESULT_NIL;
|
||||
|
||||
LuaResult result = lua_isnil(engine.state, -1) ? LUA_RESULT_NIL
|
||||
: lua_toboolean(engine.state, -1) ? LUA_RESULT_TRUE
|
||||
: LUA_RESULT_FALSE;
|
||||
lua_pop(engine.state, 1);
|
||||
return result;
|
||||
}
|
||||
|
||||
// Sets value to a field of the table on top of the stack, when the field is not nil.
|
||||
static void field_read(lua_State* state, const char* key, bool& value)
|
||||
{
|
||||
lua_getfield(state, -1, key);
|
||||
if (!lua_isnil(state, -1)) value = lua_toboolean(state, -1);
|
||||
lua_pop(state, 1);
|
||||
}
|
||||
|
||||
// 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.
|
||||
template <typename T>
|
||||
static bool element_read(lua_State* state, int key, T& value)
|
||||
{
|
||||
int isInteger = 0;
|
||||
bool isSet = lua_geti(state, -1, key) != LUA_TNIL;
|
||||
lua_Integer element = lua_tointegerx(state, -1, &isInteger);
|
||||
if (isInteger) value = (T)element;
|
||||
lua_pop(state, 1);
|
||||
return isSet;
|
||||
}
|
||||
|
||||
// Pops a callback's result, and when it is a table sets values in order to its elements 1, 2 ... Whether any was set.
|
||||
template <typename... T>
|
||||
static bool elements_pop(lua_State* state, T&... values)
|
||||
{
|
||||
int key = 1;
|
||||
bool isChanged = false;
|
||||
if (lua_istable(state, -1)) ((isChanged |= element_read(state, key++, values)), ...);
|
||||
lua_pop(state, 1);
|
||||
return isChanged;
|
||||
}
|
||||
|
||||
// 00862250 Runs MC_PRE_BOMB_COLLISION, filtered by the bomb's variant.
|
||||
LuaResult LuaEngine::PreBombCollision(Entity_Bomb* bomb, Entity* collider, bool isLow)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user