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
@@ -12,6 +12,9 @@
|
||||
#include "level/room_transition.h"
|
||||
#include "engine/kage_input.h"
|
||||
#include "engine/texture_cache.h"
|
||||
#ifdef ISAAC_REPENTOGON
|
||||
#include "repentogon/options.h"
|
||||
#endif
|
||||
#include <SDL3/SDL_mouse.h>
|
||||
#include <SDL3/SDL_video.h>
|
||||
#include <algorithm>
|
||||
@@ -522,7 +525,7 @@ static void daily_challenge_clear(DailyChallenge& daily)
|
||||
// lobby from the command line are offline.
|
||||
// The import tool's resources/ replaces the packed archives, their mount points and their load timing.
|
||||
// Lua uses the system allocator, so --luaheapsize is ignored. LuaEngine's inlined construction is its own, run by new
|
||||
// once taken over.
|
||||
// once taken over. REPENTOGON's options load first, as its scripts read them.
|
||||
void IsaacStartup(int argc, uint8_t** argv)
|
||||
{
|
||||
StartupArguments arguments;
|
||||
@@ -533,6 +536,9 @@ void IsaacStartup(int argc, uint8_t** argv)
|
||||
if (argument == LUA_DEBUG_FLAG) arguments.luaMode = LUA_MODE_DEBUG;
|
||||
else if (argument == NETWORK_TEST_FLAG) isNetworkTestRequested = true;
|
||||
}
|
||||
#ifdef ISAAC_REPENTOGON
|
||||
repentogonOptions.load();
|
||||
#endif
|
||||
LuaEngine* luaEngine = new LuaEngine();
|
||||
g_luaEngine = luaEngine;
|
||||
luaEngine->Init(arguments.luaMode);
|
||||
|
||||
+14
-9
@@ -18,6 +18,9 @@
|
||||
#include "engine/platform.h"
|
||||
#include "level/room.h"
|
||||
#include "level/room_grid.h"
|
||||
#ifdef ISAAC_REPENTOGON
|
||||
#include "repentogon/repentogon.h"
|
||||
#endif
|
||||
#include <SDL3/SDL_mouse.h>
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
@@ -286,8 +289,8 @@ static int mod_data_remove(lua_State* state)
|
||||
}
|
||||
|
||||
// 0085f0f0 The file a module name is in: dots become folders and .lua is added, searched in resources/scripts/, the
|
||||
// running script's folder, and that folder under the mods folder. The name is lowercased, as the import tool lowercases
|
||||
// every path a mod ships. Empty when none exists, with tried listing them.
|
||||
// running script's folder, and that folder under the mods folder, with REPENTOGON's scripts folder first. The name is
|
||||
// lowercased, as the import tool lowercases every path a mod ships. Empty when none exists, with tried listing them.
|
||||
static std::string module_path_find(std::string_view name, std::string& tried)
|
||||
{
|
||||
std::string module(name);
|
||||
@@ -299,7 +302,11 @@ static std::string module_path_find(std::string_view name, std::string& tried)
|
||||
|
||||
std::string scriptPath = lua_engine_get().scriptPath;
|
||||
std::string local = scriptPath.substr(0, scriptPath.find_last_of(PATH_SEPARATORS)) + "/" + module;
|
||||
for (const std::string& path : {resource_path(SCRIPTS_FOLDER + module), local, platform.modsDirectory + local})
|
||||
for (const std::string& path : {
|
||||
#ifdef ISAAC_REPENTOGON
|
||||
repentogon_script_path(module),
|
||||
#endif
|
||||
resource_path(SCRIPTS_FOLDER + module), local, platform.modsDirectory + local})
|
||||
{
|
||||
std::error_code error;
|
||||
if (std::filesystem::exists(path, error)) return path;
|
||||
@@ -500,12 +507,10 @@ static void isaac_register(lua_State* state)
|
||||
EntityList& list = g_game->room->entityList;
|
||||
return std::max(list.bossCount + list.pendingBossCount, 0);
|
||||
});
|
||||
lua_method(state, "SetBuiltInCallbackState", [](int callback, bool isEnabled) {
|
||||
if ((uint32_t)callback < LUA_CALLBACK_COUNT) lua_engine_get().enabledCallbacks[callback] = isEnabled;
|
||||
});
|
||||
lua_method(state, "GetBuiltInCallbackState", [](int callback) {
|
||||
return (uint32_t)callback < LUA_CALLBACK_COUNT && lua_engine_get().enabledCallbacks[callback];
|
||||
});
|
||||
lua_method(state, "SetBuiltInCallbackState",
|
||||
[](int callback, bool isEnabled) { lua_engine_get().callback_state_set(callback, isEnabled); });
|
||||
lua_method(state, "GetBuiltInCallbackState",
|
||||
[](int callback) { return lua_engine_get().is_callback_enabled(callback); });
|
||||
|
||||
lua_method(state, "WorldToScreen", [](Vector position) {
|
||||
if (!g_game) return position;
|
||||
|
||||
@@ -0,0 +1,139 @@
|
||||
#pragma once
|
||||
|
||||
#include "lua/api.h"
|
||||
#include <optional>
|
||||
|
||||
// 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 REPENTOGON callback may filter by a second parameter, which runs it through _RunCallbackWithTwoParams.
|
||||
struct CallbackRun
|
||||
{
|
||||
const char* name;
|
||||
int id;
|
||||
std::optional<int> param = CALLBACK_PARAM_NONE;
|
||||
std::optional<int> secondParam;
|
||||
};
|
||||
|
||||
// Pushes a filter parameter, nil when there is none.
|
||||
inline void param_push(lua_State* state, std::optional<int> param)
|
||||
{
|
||||
if (param) lua_pushinteger(state, *param);
|
||||
else lua_pushnil(state);
|
||||
}
|
||||
|
||||
// Calls _RunCallback (_RunCallbackWithTwoParams for two filter parameters) with a callback's id, its filter parameters
|
||||
// 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>
|
||||
bool callback_run(LuaEngine& engine, CallbackRun run, Args... args)
|
||||
{
|
||||
if (!engine.is_callback_enabled(run.id)) return false;
|
||||
lua_State* state = engine.state;
|
||||
bool isTwoParams = run.secondParam.has_value();
|
||||
|
||||
lua_rawgeti(state, LUA_REGISTRYINDEX, isTwoParams ? engine.runCallbackTwoParamsRef : engine.runCallbackRef);
|
||||
lua_pushinteger(state, run.id);
|
||||
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;
|
||||
|
||||
lua_error_log(state, run.name);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Runs a callback whose result the game ignores.
|
||||
template <typename... Args>
|
||||
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>
|
||||
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>
|
||||
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>
|
||||
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.
|
||||
inline 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>
|
||||
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>
|
||||
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;
|
||||
}
|
||||
+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)
|
||||
{
|
||||
|
||||
+32
-4
@@ -5,6 +5,9 @@
|
||||
#include "game/game.h"
|
||||
#include "game/manager.h"
|
||||
#include "engine/platform.h"
|
||||
#ifdef ISAAC_REPENTOGON
|
||||
#include "repentogon/repentogon.h"
|
||||
#endif
|
||||
#include <algorithm>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
@@ -169,6 +172,9 @@ void LuaEngine::Init(LuaMode luaMode)
|
||||
RegisterAPI();
|
||||
RunScript(resource_path(ENUMS_SCRIPT));
|
||||
RunScript(resource_path(MAIN_SCRIPT));
|
||||
#ifdef ISAAC_REPENTOGON
|
||||
repentogon_scripts_run(*this);
|
||||
#endif
|
||||
runCallbackRef = global_take(state, RUN_CALLBACK);
|
||||
unloadModRef = global_take(state, UNLOAD_MOD);
|
||||
}
|
||||
@@ -193,10 +199,11 @@ void LuaEngine::destroy()
|
||||
for (LuaMod& mod : mods) mod_unload(*this, mod);
|
||||
mods.clear();
|
||||
|
||||
luaL_unref(state, LUA_REGISTRYINDEX, runCallbackRef);
|
||||
luaL_unref(state, LUA_REGISTRYINDEX, unloadModRef);
|
||||
runCallbackRef = LUA_REF_NONE;
|
||||
unloadModRef = LUA_REF_NONE;
|
||||
for (int* ref : {&runCallbackRef, &runCallbackTwoParamsRef, &unloadModRef})
|
||||
{
|
||||
luaL_unref(state, LUA_REGISTRYINDEX, *ref);
|
||||
*ref = LUA_REF_NONE;
|
||||
}
|
||||
lua_close(state);
|
||||
state = nullptr;
|
||||
}
|
||||
@@ -296,6 +303,27 @@ void LuaEngine::gc_update()
|
||||
lua_gc(state, LUA_GCSTEP, gcStepSize);
|
||||
}
|
||||
|
||||
// Whether a mod added a function for a callback, by its id: the original's, or with REPENTOGON one of its own.
|
||||
bool LuaEngine::is_callback_enabled(int callback)
|
||||
{
|
||||
if ((uint32_t)callback < LUA_CALLBACK_COUNT) return enabledCallbacks[callback];
|
||||
#ifdef ISAAC_REPENTOGON
|
||||
uint32_t index = (uint32_t)(callback - REPENTOGON_CALLBACK_FIRST);
|
||||
if (index < REPENTOGON_CALLBACK_COUNT) return enabledRepentogonCallbacks[index];
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
// Sets whether a callback runs, for the API's SetBuiltInCallbackState. Any other id is ignored.
|
||||
void LuaEngine::callback_state_set(int callback, bool isEnabled)
|
||||
{
|
||||
if ((uint32_t)callback < LUA_CALLBACK_COUNT) enabledCallbacks[callback] = isEnabled;
|
||||
#ifdef ISAAC_REPENTOGON
|
||||
uint32_t index = (uint32_t)(callback - REPENTOGON_CALLBACK_FIRST);
|
||||
if (index < REPENTOGON_CALLBACK_COUNT) enabledRepentogonCallbacks[index] = isEnabled;
|
||||
#endif
|
||||
}
|
||||
|
||||
// 0086f640 A collectible's id by its name, -1 for none. The original searches a copy of the name map.
|
||||
int LuaEngine::Isaac_GetItemIdByName(std::string_view name)
|
||||
{
|
||||
|
||||
+9
-1
@@ -34,6 +34,9 @@ constexpr int LUA_MEMORY_HISTORY_SIZE = 128;
|
||||
constexpr int LUA_REF_NONE = -2;
|
||||
// A callback registered for every parameter.
|
||||
constexpr int CALLBACK_PARAM_NONE = -1;
|
||||
// REPENTOGON's callback ids, from 1000 up (enums_ex.lua's ModCallbacks), with room for as many as it tracks.
|
||||
constexpr int REPENTOGON_CALLBACK_FIRST = 1000;
|
||||
constexpr int REPENTOGON_CALLBACK_COUNT = 500;
|
||||
|
||||
// The input hooks of MC_INPUT_ACTION (Lua's InputHook).
|
||||
enum InputHook : int
|
||||
@@ -132,13 +135,15 @@ struct LuaMod
|
||||
|
||||
// The mod scripting host: the Lua 5.3 state, the game's scripts in resources/scripts/, the mods scripts register, and
|
||||
// the entry points that run mods' callbacks. A callback runs only while enabledCallbacks has its id, which the API's
|
||||
// SetBuiltInCallbackState sets once a mod adds a function for it. Lua errors are logged, never fatal.
|
||||
// SetBuiltInCallbackState sets once a mod adds a function for it, REPENTOGON's ids from 1000 up in a set of their own.
|
||||
// Lua errors are logged, never fatal.
|
||||
// Construction is inlined in IsaacStartup, and the original never destroys the engine.
|
||||
struct LuaEngine
|
||||
{
|
||||
std::array<int, LUA_MEMORY_HISTORY_SIZE> memoryHistory{};
|
||||
std::array<int, LUA_GC_HISTORY_SIZE> gcGrowth{};
|
||||
std::bitset<LUA_CALLBACK_COUNT> enabledCallbacks;
|
||||
std::bitset<REPENTOGON_CALLBACK_COUNT> enabledRepentogonCallbacks;
|
||||
std::list<LuaMod> mods;
|
||||
std::string scriptPath;
|
||||
lua_State* state = nullptr;
|
||||
@@ -151,6 +156,7 @@ struct LuaEngine
|
||||
int memoryHistoryIndex = 0;
|
||||
int memoryHistoryTimer = 0;
|
||||
int runCallbackRef = LUA_REF_NONE;
|
||||
int runCallbackTwoParamsRef = LUA_REF_NONE;
|
||||
int scriptApiVersion = -1;
|
||||
int unloadModRef = LUA_REF_NONE;
|
||||
uint32_t pointerMask = 0;
|
||||
@@ -161,6 +167,8 @@ struct LuaEngine
|
||||
bool RunScript(std::string_view path);
|
||||
bool LuamodCMD(std::string_view modName);
|
||||
void gc_update();
|
||||
bool is_callback_enabled(int callback);
|
||||
void callback_state_set(int callback, bool isEnabled);
|
||||
static int Isaac_GetItemIdByName(std::string_view name);
|
||||
|
||||
LuaResult PreBombCollision(Entity_Bomb* bomb, Entity* collider, bool isLow);
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
#include "repentogon/options.h"
|
||||
#include "engine/platform.h"
|
||||
#include <SDL3/SDL_filesystem.h>
|
||||
#include <SDL3/SDL_stdinc.h>
|
||||
#include <algorithm>
|
||||
#include <charconv>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
|
||||
constexpr const char* OPTIONS_FILE = "Repentogon/options.ini";
|
||||
constexpr std::string_view WHITESPACE = " \t\r";
|
||||
constexpr int FONT_SIZES[] = {13, 16, 14, 8, 8};
|
||||
constexpr int FONT_SIZE_DEFAULT = 8;
|
||||
|
||||
// The keys a new options.ini gets besides the options, which REPENTOGON writes but no longer reads.
|
||||
constexpr const char* UNREAD_KEYS[][3] = {{"VanillaTweaks", "FastLasers", "0"},
|
||||
{"internal", "DidModReset", "0"},
|
||||
{"internal", "EnableUnifont", "1"},
|
||||
{"internal", "UnifontRenderMode", "0"}};
|
||||
|
||||
RepentogonOptions repentogonOptions;
|
||||
|
||||
// The text without the whitespace around it.
|
||||
static std::string_view text_trim(std::string_view text)
|
||||
{
|
||||
size_t start = text.find_first_not_of(WHITESPACE);
|
||||
if (start == text.npos) return {};
|
||||
|
||||
return text.substr(start, text.find_last_not_of(WHITESPACE) + 1 - start);
|
||||
}
|
||||
|
||||
// Sets value to a key's leading digits, kept when the key is missing or has none, as REPENTOGON's defstoi reads it.
|
||||
template <typename T> static void value_read(RepentogonOptions& options, const char* section, const char* key, T& value)
|
||||
{
|
||||
auto keys = options.ini.find(section);
|
||||
if (keys == options.ini.end() || !keys->second.contains(key)) return;
|
||||
|
||||
std::string& text = keys->second[key];
|
||||
int number = 0;
|
||||
if (std::from_chars(text.data(), text.data() + text.size(), number).ec == std::errc()) value = (T)number;
|
||||
}
|
||||
|
||||
// Reads options.ini's sections, writing a new one with the defaults when there is none, then every option it holds.
|
||||
// FontSize defaults by the old UnifontRenderMode, and the Mars double tap window is clamped.
|
||||
void RepentogonOptions::load()
|
||||
{
|
||||
char* folder = SDL_GetPrefPath("", SAVE_FOLDER.data());
|
||||
path = std::string(folder ? folder : "") + OPTIONS_FILE;
|
||||
SDL_free(folder);
|
||||
|
||||
std::ifstream file(path);
|
||||
std::string section;
|
||||
for (std::string line; std::getline(file, line);)
|
||||
{
|
||||
std::string_view text = text_trim(line);
|
||||
size_t equals = text.find('=');
|
||||
|
||||
if (text.starts_with('[') && text.ends_with(']')) section = text.substr(1, text.size() - 2);
|
||||
else if (equals != text.npos && !text.starts_with(';'))
|
||||
ini[section][std::string(text_trim(text.substr(0, equals)))] = text_trim(text.substr(equals + 1));
|
||||
}
|
||||
bool isNew = !file.is_open();
|
||||
if (isNew)
|
||||
for (auto [fileSection, key, value] : UNREAD_KEYS) ini[fileSection][key] = value;
|
||||
|
||||
int renderMode = -1;
|
||||
value_read(*this, "internal", "UnifontRenderMode", renderMode);
|
||||
fontSize = (uint32_t)renderMode < std::size(FONT_SIZES) ? FONT_SIZES[renderMode] : FONT_SIZE_DEFAULT;
|
||||
repentogon_options_visit(*this, [&](const char* fileSection, const char* key, auto& value) {
|
||||
value_read(*this, fileSection, key, value);
|
||||
});
|
||||
marsDoubleTapWindow = std::clamp(marsDoubleTapWindow, MARS_DOUBLE_TAP_WINDOW_MIN, MARS_DOUBLE_TAP_WINDOW_MAX);
|
||||
if (isNew) save();
|
||||
}
|
||||
|
||||
// Writes every option into its section of options.ini, with the keys it read but does not know.
|
||||
void RepentogonOptions::save()
|
||||
{
|
||||
repentogon_options_visit(*this, [&](const char* section, const char* key, auto value) {
|
||||
ini[section][key] = std::to_string((int)value);
|
||||
});
|
||||
|
||||
std::error_code error;
|
||||
std::filesystem::create_directories(std::filesystem::path(path).parent_path(), error);
|
||||
std::ofstream file(path);
|
||||
for (auto& [section, keys] : ini)
|
||||
{
|
||||
file << '[' << section << "]\n";
|
||||
for (auto& [key, value] : keys) file << key << '=' << value << '\n';
|
||||
file << '\n';
|
||||
}
|
||||
if (!file) log_printf(LOG_INFO, "[warn] could not write %s\n", path.c_str());
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
constexpr int MARS_DOUBLE_TAP_WINDOW_MIN = 2;
|
||||
constexpr int MARS_DOUBLE_TAP_WINDOW_MAX = 20;
|
||||
|
||||
// REPENTOGON's own options (REPENTOGONOptions), kept by section in Repentogon/options.ini in the save folder, with its
|
||||
// defaults, plus the rebuild's vanilla parity switch, which keeps the game's behaviour exactly the original's.
|
||||
// Keys it does not know are kept as read. Only the parity switch changes anything yet: the callback dispatch.
|
||||
struct RepentogonOptions
|
||||
{
|
||||
std::map<std::string, std::map<std::string, std::string>> ini;
|
||||
std::string path;
|
||||
|
||||
int consoleAutofillLimit = 10;
|
||||
int consoleKeyMode = 0;
|
||||
int consoleKeyScancode = 41;
|
||||
int consoleKeyVK = 192;
|
||||
int fontRenderStyle = 0;
|
||||
int fontSize = 8;
|
||||
int imGuiScale = 0;
|
||||
int lastSaveFile = 0;
|
||||
int marsDoubleTapWindow = 10;
|
||||
|
||||
bool isBetterVoidGeneration = false;
|
||||
bool isBlockUnknownDevices = false;
|
||||
bool isDidInputConfigsImport = false;
|
||||
bool isDisableExitPrompt = false;
|
||||
bool isEcoMode = false;
|
||||
bool isEnableDocking = true;
|
||||
bool isEnableImGuiMultiView = false;
|
||||
bool isFileMap = true;
|
||||
bool isHushLaserSpeedFix = true;
|
||||
bool isInterpolV2 = false;
|
||||
bool isPreventModUpdates = false;
|
||||
bool isQuickRoomClear = false;
|
||||
bool isRenderDebugFindInRadius = false;
|
||||
bool isSkipArchiveChecks = false;
|
||||
bool isSkipIntro = false;
|
||||
bool isStatHudPlanetarium = true;
|
||||
bool isSyncModsEnabled = true;
|
||||
bool isSyncVanillaOptions = true;
|
||||
bool isVanillaParity = true;
|
||||
|
||||
void load();
|
||||
void save();
|
||||
};
|
||||
|
||||
// Calls visit with each option's section, key and value, in the order REPENTOGON saves them, the parity switch first.
|
||||
template <typename Visit> void repentogon_options_visit(RepentogonOptions& options, Visit visit)
|
||||
{
|
||||
visit("Rebuild", "VanillaParity", options.isVanillaParity);
|
||||
visit("OptionsSyncing", "SyncVanillaOptions", options.isSyncVanillaOptions);
|
||||
visit("OptionsSyncing", "SyncModsEnabled", options.isSyncModsEnabled);
|
||||
visit("VanillaTweaks", "BetterVoidGeneration", options.isBetterVoidGeneration);
|
||||
visit("VanillaTweaks", "HushLaserSpeedFix", options.isHushLaserSpeedFix);
|
||||
visit("VanillaTweaks", "QuickRoomClear", options.isQuickRoomClear);
|
||||
visit("VanillaTweaks", "PreventModUpdates", options.isPreventModUpdates);
|
||||
visit("VanillaTweaks", "StatHUDPlanetarium", options.isStatHudPlanetarium);
|
||||
visit("VanillaTweaks", "SkipIntro", options.isSkipIntro);
|
||||
visit("VanillaTweaks", "InterpolV2", options.isInterpolV2);
|
||||
visit("VanillaTweaks", "MarsDoubleTapWindow", options.marsDoubleTapWindow);
|
||||
visit("VanillaTweaks", "ConsoleAutofillLimit", options.consoleAutofillLimit);
|
||||
visit("VanillaTweaks", "ConsoleKeyMode", options.consoleKeyMode);
|
||||
visit("VanillaTweaks", "ConsoleKeyVK", options.consoleKeyVK);
|
||||
visit("VanillaTweaks", "ConsoleKeyScancode", options.consoleKeyScancode);
|
||||
visit("VanillaTweaks", "EcoMode", options.isEcoMode);
|
||||
visit("VanillaTweaks", "DisableExitPrompt", options.isDisableExitPrompt);
|
||||
visit("VanillaTweaks", "BlockUnknownDevices", options.isBlockUnknownDevices);
|
||||
visit("internal", "LastSaveFile", options.lastSaveFile);
|
||||
visit("internal", "FileMap", options.isFileMap);
|
||||
visit("internal", "ImGuiScale", options.imGuiScale);
|
||||
visit("internal", "RenderDebugFindInRadius", options.isRenderDebugFindInRadius);
|
||||
visit("internal", "SkipArchiveChecks", options.isSkipArchiveChecks);
|
||||
visit("internal", "DidInputConfigsImport", options.isDidInputConfigsImport);
|
||||
visit("internal", "FontSize", options.fontSize);
|
||||
visit("internal", "FontRenderStyle", options.fontRenderStyle);
|
||||
visit("internal", "EnableImGuiMultiView", options.isEnableImGuiMultiView);
|
||||
visit("internal", "EnableDocking", options.isEnableDocking);
|
||||
}
|
||||
|
||||
extern RepentogonOptions repentogonOptions;
|
||||
@@ -0,0 +1,88 @@
|
||||
#include "repentogon/repentogon.h"
|
||||
#include "engine/data.h"
|
||||
#include "engine/platform.h"
|
||||
#include "lua/api.h"
|
||||
#include "repentogon/options.h"
|
||||
|
||||
constexpr const char* SCRIPTS_FOLDER = "repentogon/scripts/";
|
||||
constexpr const char* ENUMS_SCRIPT = "enums_ex.lua";
|
||||
constexpr const char* MAIN_SCRIPT = "main_ex.lua";
|
||||
constexpr const char* BINDINGS = "_CBindings";
|
||||
constexpr const char* GLOBAL = "REPENTOGON";
|
||||
constexpr const char* RUN_CALLBACK_TWO_PARAMS = "_RunCallbackWithTwoParams";
|
||||
|
||||
// Logs that a mod's callback failed, where REPENTOGON raises its error display.
|
||||
static int mod_error_raise(lua_State* state)
|
||||
{
|
||||
log_printf(LOG_INFO, "%s is causing errors!\n", luaL_checkstring(state, 1));
|
||||
return 0;
|
||||
}
|
||||
|
||||
// The main.lua path of the mod a table was registered for, nil for none.
|
||||
static int mod_id_get(lua_State* state)
|
||||
{
|
||||
luaL_checktype(state, 1, LUA_TTABLE);
|
||||
for (LuaMod& mod : lua_engine_get().mods)
|
||||
{
|
||||
lua_rawgeti(state, LUA_REGISTRYINDEX, mod.tableRef);
|
||||
bool isMod = lua_rawequal(state, 1, -1);
|
||||
lua_pop(state, 1);
|
||||
if (!isMod) continue;
|
||||
|
||||
lua_pushstring(state, mod.scriptPath.c_str());
|
||||
return 1;
|
||||
}
|
||||
lua_pushnil(state);
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Whether the vanilla parity option is on, read at each callback run.
|
||||
static int vanilla_parity_get(lua_State* state)
|
||||
{
|
||||
lua_pushboolean(state, repentogonOptions.isVanillaParity);
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Where one of REPENTOGON's scripts lives: under assets/repentogon/scripts/.
|
||||
std::string repentogon_script_path(std::string_view path)
|
||||
{
|
||||
return asset_path(SCRIPTS_FOLDER + std::string(path));
|
||||
}
|
||||
|
||||
// Runs REPENTOGON's enums_ex.lua and main_ex.lua after the game's own scripts, as its LuaEngine::Init hook does.
|
||||
// debug opens again for them (main.lua closed it), os too unless vanilla parity is on, and _CBindings holds the
|
||||
// internals main_ex.lua takes, cleared after. main_ex.lua replaces _RunCallback and _UnloadMod, which Init then takes,
|
||||
// and adds _RunCallbackWithTwoParams. The REPENTOGON global is cleared while it is not exposed.
|
||||
void repentogon_scripts_run(LuaEngine& engine)
|
||||
{
|
||||
lua_State* state = engine.state;
|
||||
for (luaL_Reg library : {luaL_Reg{LUA_DBLIBNAME, luaopen_debug}, {LUA_OSLIBNAME, luaopen_os}})
|
||||
{
|
||||
if (library.func == luaopen_os && repentogonOptions.isVanillaParity) continue;
|
||||
luaL_requiref(state, library.name, library.func, 1);
|
||||
lua_pop(state, 1);
|
||||
}
|
||||
|
||||
lua_newtable(state);
|
||||
for (auto [name, function] : {std::pair{"RaiseModError", mod_error_raise}, {"GetModId", mod_id_get},
|
||||
{"IsVanillaParity", vanilla_parity_get}})
|
||||
{
|
||||
lua_pushcfunction(state, function);
|
||||
lua_table_set(state, -2, name);
|
||||
}
|
||||
lua_pushboolean(state, IS_REPENTOGON_EXPOSED);
|
||||
lua_table_set(state, -2, "IsExposed");
|
||||
lua_setglobal(state, BINDINGS);
|
||||
|
||||
engine.RunScript(repentogon_script_path(ENUMS_SCRIPT));
|
||||
engine.RunScript(repentogon_script_path(MAIN_SCRIPT));
|
||||
lua_pushnil(state);
|
||||
lua_setglobal(state, BINDINGS);
|
||||
|
||||
lua_getglobal(state, RUN_CALLBACK_TWO_PARAMS);
|
||||
engine.runCallbackTwoParamsRef = luaL_ref(state, LUA_REGISTRYINDEX);
|
||||
if (IS_REPENTOGON_EXPOSED) return;
|
||||
|
||||
lua_pushnil(state);
|
||||
lua_setglobal(state, GLOBAL);
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
struct LuaEngine;
|
||||
|
||||
// Whether mods see the REPENTOGON global and its version. It stays off until the whole API is ported, which flips it.
|
||||
constexpr bool IS_REPENTOGON_EXPOSED = false;
|
||||
|
||||
std::string repentogon_script_path(std::string_view path);
|
||||
void repentogon_scripts_run(LuaEngine& engine);
|
||||
@@ -5,6 +5,9 @@
|
||||
#include "game/options_config.h"
|
||||
#include "game/sfx_manager.h"
|
||||
#include "game/string_table.h"
|
||||
#ifdef ISAAC_REPENTOGON
|
||||
#include "repentogon/options.h"
|
||||
#endif
|
||||
#include "ui/hud.h"
|
||||
#include "ui/menu/key_config.h"
|
||||
#include <imgui.h>
|
||||
@@ -24,11 +27,18 @@ enum OptionsTab
|
||||
OPTIONS_TAB_CONSOLE,
|
||||
OPTIONS_TAB_ONLINE,
|
||||
OPTIONS_TAB_SYSTEM,
|
||||
#ifdef ISAAC_REPENTOGON
|
||||
OPTIONS_TAB_REPENTOGON,
|
||||
#endif
|
||||
OPTIONS_TAB_COUNT
|
||||
};
|
||||
|
||||
constexpr const char* OPTIONS_TAB_NAMES[OPTIONS_TAB_COUNT] = {"Audio", "Video", "HUD", "Gameplay",
|
||||
"Console", "Online", "System"};
|
||||
constexpr const char* OPTIONS_TAB_NAMES[OPTIONS_TAB_COUNT] = {"Audio", "Video", "HUD", "Gameplay",
|
||||
"Console", "Online", "System",
|
||||
#ifdef ISAAC_REPENTOGON
|
||||
"REPENTOGON"
|
||||
#endif
|
||||
};
|
||||
|
||||
// Where an options.ini setting sits: its tab and label, the range of a number (a slider when it has one, else typed),
|
||||
// and for a choice its labels, each standing for min plus its index.
|
||||
@@ -93,7 +103,39 @@ constexpr OptionSpec OPTION_SPECS[] = {
|
||||
{"SteamCloud", "Steam Cloud", OPTIONS_TAB_SYSTEM},
|
||||
{"TryImportSave", "Import save", OPTIONS_TAB_SYSTEM},
|
||||
{"AcceptedPublicBeta_v1.9.7.17", "Public beta accepted", OPTIONS_TAB_SYSTEM},
|
||||
{"AcceptedDataCollectionDisclaimer", "Data collection accepted", OPTIONS_TAB_SYSTEM}};
|
||||
{"AcceptedDataCollectionDisclaimer", "Data collection accepted", OPTIONS_TAB_SYSTEM},
|
||||
#ifdef ISAAC_REPENTOGON
|
||||
{"VanillaParity", "Vanilla parity", OPTIONS_TAB_REPENTOGON},
|
||||
{"SyncVanillaOptions", "Sync vanilla options", OPTIONS_TAB_REPENTOGON},
|
||||
{"SyncModsEnabled", "Sync enabled mods", OPTIONS_TAB_REPENTOGON},
|
||||
{"BetterVoidGeneration", "Better Void generation", OPTIONS_TAB_REPENTOGON},
|
||||
{"HushLaserSpeedFix", "Hush laser speed fix", OPTIONS_TAB_REPENTOGON},
|
||||
{"QuickRoomClear", "Quick room clear", OPTIONS_TAB_REPENTOGON},
|
||||
{"PreventModUpdates", "Prevent mod updates", OPTIONS_TAB_REPENTOGON},
|
||||
{"StatHUDPlanetarium", "Planetarium chance on stat HUD", OPTIONS_TAB_REPENTOGON},
|
||||
{"SkipIntro", "Skip intro", OPTIONS_TAB_REPENTOGON},
|
||||
{"InterpolV2", "Interpolation v2", OPTIONS_TAB_REPENTOGON},
|
||||
{"MarsDoubleTapWindow", "Mars double tap window", OPTIONS_TAB_REPENTOGON, MARS_DOUBLE_TAP_WINDOW_MIN,
|
||||
MARS_DOUBLE_TAP_WINDOW_MAX},
|
||||
{"ConsoleAutofillLimit", "Console autofill limit", OPTIONS_TAB_REPENTOGON},
|
||||
{"ConsoleKeyMode", "Console key mode", OPTIONS_TAB_REPENTOGON, 0, 1, "Virtual key\0Scancode\0"},
|
||||
{"ConsoleKeyVK", "Console virtual key", OPTIONS_TAB_REPENTOGON},
|
||||
{"ConsoleKeyScancode", "Console scancode", OPTIONS_TAB_REPENTOGON},
|
||||
{"EcoMode", "Eco mode", OPTIONS_TAB_REPENTOGON},
|
||||
{"DisableExitPrompt", "Disable exit prompt", OPTIONS_TAB_REPENTOGON},
|
||||
{"BlockUnknownDevices", "Block unknown devices", OPTIONS_TAB_REPENTOGON},
|
||||
{"LastSaveFile", "Last save file", OPTIONS_TAB_REPENTOGON},
|
||||
{"FileMap", "File map", OPTIONS_TAB_REPENTOGON},
|
||||
{"ImGuiScale", "ImGui scale", OPTIONS_TAB_REPENTOGON},
|
||||
{"RenderDebugFindInRadius", "Draw FindInRadius", OPTIONS_TAB_REPENTOGON},
|
||||
{"SkipArchiveChecks", "Skip archive checks", OPTIONS_TAB_REPENTOGON},
|
||||
{"DidInputConfigsImport", "Input configs imported", OPTIONS_TAB_REPENTOGON},
|
||||
{"FontSize", "Font size", OPTIONS_TAB_REPENTOGON},
|
||||
{"FontRenderStyle", "Font render style", OPTIONS_TAB_REPENTOGON},
|
||||
{"EnableImGuiMultiView", "ImGui multi-viewport", OPTIONS_TAB_REPENTOGON},
|
||||
{"EnableDocking", "ImGui docking", OPTIONS_TAB_REPENTOGON},
|
||||
#endif
|
||||
};
|
||||
|
||||
static const OptionSpec* spec_find(std::string_view key)
|
||||
{
|
||||
@@ -146,8 +188,8 @@ template <typename T> static bool is_option_edited(const OptionSpec& spec, T& va
|
||||
}
|
||||
}
|
||||
|
||||
// Every setting options.ini holds, a tab each by subject, then the key bindings. A change applies at once and is saved
|
||||
// to options.ini as the game saves it, once no widget is held.
|
||||
// Every setting options.ini holds, a tab each by subject, REPENTOGON's own options in theirs, then the key bindings.
|
||||
// A change applies at once and is saved as the game saves it, once no widget is held.
|
||||
void Overlay::options_render()
|
||||
{
|
||||
OptionsConfig& config = g_manager->optionsConfig;
|
||||
@@ -173,7 +215,7 @@ void Overlay::options_render()
|
||||
ImGui::TextDisabled("Language: %s (read only)", language.c_str());
|
||||
}
|
||||
|
||||
options_visit(config, [&](const char* key, auto& value) {
|
||||
auto optionRender = [&](const char* file, const char* key, auto& value) {
|
||||
const OptionSpec* spec = spec_find(key);
|
||||
if (!spec || spec->tab != tab) return;
|
||||
|
||||
@@ -183,11 +225,22 @@ void Overlay::options_render()
|
||||
option_apply(key);
|
||||
isOptionsSavePending = true;
|
||||
}
|
||||
ImGui::SetItemTooltip("options.ini: %s", key);
|
||||
ImGui::SetItemTooltip("%s: %s", file, key);
|
||||
ImGui::PopID();
|
||||
});
|
||||
};
|
||||
options_visit(config, [&](const char* key, auto& value) { optionRender("options.ini", key, value); });
|
||||
if (tab == OPTIONS_TAB_CONSOLE)
|
||||
ImGui::TextDisabled("**The overlay's console works whatever these say. They drive the original's.");
|
||||
#ifdef ISAAC_REPENTOGON
|
||||
if (tab == OPTIONS_TAB_REPENTOGON)
|
||||
{
|
||||
ImGui::TextDisabled("**Only vanilla parity does anything yet. On, the original's callbacks run as the "
|
||||
"original runs them.");
|
||||
repentogon_options_visit(repentogonOptions, [&](const char* section, const char* key, auto& value) {
|
||||
optionRender(section, key, value);
|
||||
});
|
||||
}
|
||||
#endif
|
||||
ImGui::PopItemWidth();
|
||||
ImGui::EndTabItem();
|
||||
}
|
||||
@@ -200,6 +253,9 @@ void Overlay::options_render()
|
||||
|
||||
if (!isOptionsSavePending || ImGui::IsAnyItemActive()) return;
|
||||
config.Save();
|
||||
#ifdef ISAAC_REPENTOGON
|
||||
repentogonOptions.save();
|
||||
#endif
|
||||
isOptionsSavePending = false;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user