Test round 2 fixes (wrong behaviour against the decompile: stats, combat, odds, level generation, visuals, the Lua API and 45 real mods): Blue Womb's last boss room is the start room (0074a500), Font:GetCharacterWidth takes a string and FontRenderSettings' wrap and truncation take a width, the original's callback error names, mod paths under --mods, SetStateFlag with a negative flag, the run timer hidden by default, popup and transformation text keys, room loads premultiply through a lookup table (about 3x faster, traces identical), --screenshot-every for windowed runs

This commit is contained in:
shweet committed 2026-11-23 22:17:09 -05:00
1 parent 7d407d5c19
commit ee965dad25
19 files changed
+112 -51

No files matched your search

+3
View File
@@ -95,11 +95,14 @@ Flags on the game binary (`src/engine/harness.cpp`), deterministic: the same inp
--frames N quit after N frames --frames N quit after N frames
--trace F [--trace-every N] [--trace-detail] hashes (or the fields) of the RNGs, players and entities --trace F [--trace-every N] [--trace-detail] hashes (or the fields) of the RNGs, players and entities
--mods DIR a private mods folder --mods DIR a private mods folder
--screenshot-every N a windowed run saves every Nth frame (as Isaac.GetFrameCount() counts) to screenshots/
``` ```
`tools/harness/run.sh SAVE WORK [flags]` runs on a fresh copy of a save folder with a private `XDG_DATA_HOME`; `tools/harness/run.sh SAVE WORK [flags]` runs on a fresh copy of a save folder with a private `XDG_DATA_HOME`;
`tools/harness/menu.py` writes the boot-to-run menu input; `tools/harness/compare.py A B` prints the first frame `tools/harness/menu.py` writes the boot-to-run menu input; `tools/harness/compare.py A B` prints the first frame
and field where two traces differ; `tools/harness/bot/` is a Lua mod that plays through `MC_INPUT_ACTION`. and field where two traces differ; `tools/harness/bot/` is a Lua mod that plays through `MC_INPUT_ACTION`.
`tools/harness/goldens/check.sh` replays about 40 recorded runs (every character, the main and alternate floors,
bosses, Greed, challenges, saving and continuing) and names each trace that changed; `--record` re-records them.
## Quick use ## Quick use
-2
View File
@@ -5572,7 +5572,6 @@ void FUN_004d7130(); // 004d7130
void FUN_004d7190(uint32_t *param_1); // 004d7190 void FUN_004d7190(uint32_t *param_1); // 004d7190
void FUN_004d71f0(); // 004d71f0 void FUN_004d71f0(); // 004d71f0
void FUN_004d7250(uint32_t *param_1); // 004d7250 void FUN_004d7250(uint32_t *param_1); // 004d7250
void FUN_004d72b0(uint32_t param_1, char param_2); // 004d72b0
void FUN_004d7310(void *param_1, void *param_2); // 004d7310 void FUN_004d7310(void *param_1, void *param_2); // 004d7310
void FUN_004d73e0(void *param_1, void *param_2, EntitySaveState *param_3); // 004d73e0 void FUN_004d73e0(void *param_1, void *param_2, EntitySaveState *param_3); // 004d73e0
void FUN_004d7450(void *param_1, int param_2); // 004d7450 void FUN_004d7450(void *param_1, int param_2); // 004d7450
@@ -7325,7 +7324,6 @@ uint32_t FUN_008a8c80(void *param_1); // 008a8c80
uint32_t FUN_008a8ce0(void *param_1); // 008a8ce0 uint32_t FUN_008a8ce0(void *param_1); // 008a8ce0
uint32_t FUN_008a8d80(void *param_1); // 008a8d80 uint32_t FUN_008a8d80(void *param_1); // 008a8d80
uint32_t FUN_008a8dd0(void *param_1); // 008a8dd0 uint32_t FUN_008a8dd0(void *param_1); // 008a8dd0
uint32_t FUN_008a8e40(void *param_1); // 008a8e40
uint32_t FUN_008a8ec0(void *param_1); // 008a8ec0 uint32_t FUN_008a8ec0(void *param_1); // 008a8ec0
uint32_t FUN_008a8f60(void *param_1); // 008a8f60 uint32_t FUN_008a8f60(void *param_1); // 008a8f60
uint32_t FUN_008a8fc0(void *param_1); // 008a8fc0 uint32_t FUN_008a8fc0(void *param_1); // 008a8fc0
-2
View File
@@ -9661,7 +9661,6 @@ void FUN_004d7130() { generated_stub("FUN_004d7130 004d7130"); }
void FUN_004d7190(uint32_t *param_1) { generated_stub("FUN_004d7190 004d7190"); } void FUN_004d7190(uint32_t *param_1) { generated_stub("FUN_004d7190 004d7190"); }
void FUN_004d71f0() { generated_stub("FUN_004d71f0 004d71f0"); } void FUN_004d71f0() { generated_stub("FUN_004d71f0 004d71f0"); }
void FUN_004d7250(uint32_t *param_1) { generated_stub("FUN_004d7250 004d7250"); } void FUN_004d7250(uint32_t *param_1) { generated_stub("FUN_004d7250 004d7250"); }
void FUN_004d72b0(uint32_t param_1, char param_2) { generated_stub("FUN_004d72b0 004d72b0"); }
void FUN_004d7310(void *param_1, void *param_2) { generated_stub("FUN_004d7310 004d7310"); } void FUN_004d7310(void *param_1, void *param_2) { generated_stub("FUN_004d7310 004d7310"); }
void FUN_004d73e0(void *param_1, void *param_2, EntitySaveState *param_3) { generated_stub("FUN_004d73e0 004d73e0"); } void FUN_004d73e0(void *param_1, void *param_2, EntitySaveState *param_3) { generated_stub("FUN_004d73e0 004d73e0"); }
void FUN_004d7450(void *param_1, int param_2) { generated_stub("FUN_004d7450 004d7450"); } void FUN_004d7450(void *param_1, int param_2) { generated_stub("FUN_004d7450 004d7450"); }
@@ -11419,7 +11418,6 @@ uint32_t FUN_008a8c80(void *param_1) { generated_stub("FUN_008a8c80 008a8c80");
uint32_t FUN_008a8ce0(void *param_1) { generated_stub("FUN_008a8ce0 008a8ce0"); } uint32_t FUN_008a8ce0(void *param_1) { generated_stub("FUN_008a8ce0 008a8ce0"); }
uint32_t FUN_008a8d80(void *param_1) { generated_stub("FUN_008a8d80 008a8d80"); } uint32_t FUN_008a8d80(void *param_1) { generated_stub("FUN_008a8d80 008a8d80"); }
uint32_t FUN_008a8dd0(void *param_1) { generated_stub("FUN_008a8dd0 008a8dd0"); } uint32_t FUN_008a8dd0(void *param_1) { generated_stub("FUN_008a8dd0 008a8dd0"); }
uint32_t FUN_008a8e40(void *param_1) { generated_stub("FUN_008a8e40 008a8e40"); }
uint32_t FUN_008a8ec0(void *param_1) { generated_stub("FUN_008a8ec0 008a8ec0"); } uint32_t FUN_008a8ec0(void *param_1) { generated_stub("FUN_008a8ec0 008a8ec0"); }
uint32_t FUN_008a8f60(void *param_1) { generated_stub("FUN_008a8f60 008a8f60"); } uint32_t FUN_008a8f60(void *param_1) { generated_stub("FUN_008a8f60 008a8f60"); }
uint32_t FUN_008a8fc0(void *param_1) { generated_stub("FUN_008a8fc0 008a8fc0"); } uint32_t FUN_008a8fc0(void *param_1) { generated_stub("FUN_008a8fc0 008a8fc0"); }
+8 -2
View File
@@ -19,12 +19,18 @@ std::string dataDirectory = "resources/";
std::string languageDirectory; std::string languageDirectory;
// A game path lowercased with forward slashes, as the game normalizes every path before a lookup. A path already under // A game path lowercased with forward slashes, as the game normalizes every path before a lookup. A path already under
// the resources, which mods build from their script's path as the original's absolute ones, stays there. // the resources or the mods folder, which mods build from their script's path as the original's absolute ones, stays
// there.
static std::string path_normalize(std::string_view path) static std::string path_normalize(std::string_view path)
{ {
std::string_view mods = platform.modsDirectory;
bool isModsPath = !mods.empty() && path.starts_with(mods);
if (isModsPath) path.remove_prefix(mods.size());
std::string normalized(path); std::string normalized(path);
for (char& letter : normalized) letter = letter == '\\' ? '/' : (char)std::tolower((unsigned char)letter); for (char& letter : normalized) letter = letter == '\\' ? '/' : (char)std::tolower((unsigned char)letter);
if (normalized.starts_with(MODS_FROM_RESOURCES)) normalized.erase(0, PARENT_FOLDER.size()); if (isModsPath) normalized.insert(0, MODS_FOLDER);
else if (normalized.starts_with(MODS_FROM_RESOURCES)) normalized.erase(0, PARENT_FOLDER.size());
else if (normalized.starts_with(dataDirectory)) normalized.erase(0, dataDirectory.size()); else if (normalized.starts_with(dataDirectory)) normalized.erase(0, dataDirectory.size());
return normalized; return normalized;
} }
+15
View File
@@ -3,6 +3,7 @@
#include "engine/kage_input.h" #include "engine/kage_input.h"
#include "engine/kage_sound.h" #include "engine/kage_sound.h"
#include "engine/platform.h" #include "engine/platform.h"
#include "engine/screenshot.h"
#include "engine/seeds.h" #include "engine/seeds.h"
#include "entity/effect/effect.h" #include "entity/effect/effect.h"
#include "entity/familiar/familiar.h" #include "entity/familiar/familiar.h"
@@ -42,6 +43,7 @@ struct HarnessFlag
constexpr HarnessFlag HARNESS_FLAGS[] = { constexpr HarnessFlag HARNESS_FLAGS[] = {
{"--headless", false}, {"--record", true}, {"--replay", true}, {"--frames", true}, {"--trace", true}, {"--headless", false}, {"--record", true}, {"--replay", true}, {"--frames", true}, {"--trace", true},
{"--trace-every", true}, {"--trace-detail", false}, {"--mods", true}, {"--mute", false}, {"--trace-every", true}, {"--trace-detail", false}, {"--mods", true}, {"--mute", false},
{"--screenshot-every", true},
}; };
Harness harness; Harness harness;
@@ -97,6 +99,7 @@ void Harness::arguments_load(int argc, char** argv)
else if (argument == "--trace-every") traceEvery = std::max(std::atoi(value), 1); else if (argument == "--trace-every") traceEvery = std::max(std::atoi(value), 1);
else if (argument == "--trace-detail") traceMode = TRACE_DETAIL; else if (argument == "--trace-detail") traceMode = TRACE_DETAIL;
else if (argument == "--mods") modsDirectory = std::string(value) + '/'; else if (argument == "--mods") modsDirectory = std::string(value) + '/';
else if (argument == "--screenshot-every") screenshotEvery = std::max(std::atoi(value), 0);
} }
std::vector<std::string> mods; std::vector<std::string> mods;
@@ -241,6 +244,18 @@ void Harness::frame_end()
if (frameLimit ? frame >= frameLimit : isReplayOver) platform.isQuitRequested = true; if (frameLimit ? frame >= frameLimit : isReplayOver) platform.isQuitRequested = true;
} }
// Saves the finished frame as screenshots/harness-<frame>.png under the user folder on every screenshotEvery-th frame,
// counted as Isaac.GetFrameCount() counts them so a mod can tell which frames it gets.
void Harness::screenshot_save()
{
uint64_t count = g_manager ? (uint64_t)g_manager->framecount : frame;
if (!screenshotEvery || isHeadless || count % screenshotEvery != 0) return;
std::error_code error;
std::filesystem::create_directories(platform.userDataDirectory + SCREENSHOTS_FOLDER, error);
save_screenshot(std::string(SCREENSHOTS_FOLDER) + "/harness-" + std::to_string(count));
}
// Closes the recording with the frame it ended on, and the trace. // Closes the recording with the frame it ended on, and the trace.
void Harness::shutdown() void Harness::shutdown()
{ {
+2
View File
@@ -56,6 +56,7 @@ public:
size_t replayNext = 0; size_t replayNext = 0;
SDL_MouseButtonFlags mouseButtons = 0; SDL_MouseButtonFlags mouseButtons = 0;
TraceMode traceMode = TRACE_HASH; TraceMode traceMode = TRACE_HASH;
int screenshotEvery = 0;
int traceEvery = 30; int traceEvery = 30;
int traceRoom = -1; int traceRoom = -1;
int traceStage = -1; int traceStage = -1;
@@ -69,6 +70,7 @@ public:
void text_add(uint32_t character); void text_add(uint32_t character);
SDL_MouseButtonFlags mouse_get(float* x, float* y); SDL_MouseButtonFlags mouse_get(float* x, float* y);
void frame_end(); void frame_end();
void screenshot_save();
void shutdown(); void shutdown();
private: private:
+43 -16
View File
@@ -27,6 +27,8 @@ constexpr int RGBA_HEADER_SIZE = 4;
constexpr int QUAD_INDICES = 6; constexpr int QUAD_INDICES = 6;
constexpr int QUAD_INDEX_ORDER[QUAD_INDICES] = {0, 2, 1, 1, 2, 3}; constexpr int QUAD_INDEX_ORDER[QUAD_INDICES] = {0, 2, 1, 1, 2, 3};
constexpr double SRGB_GAMMA = 2.2; constexpr double SRGB_GAMMA = 2.2;
constexpr int PREMULTIPLY_ALPHA_SHIFT = 8;
using PremultiplyTable = std::array<uint8_t, 1 << PREMULTIPLY_ALPHA_SHIFT * 2>;
// The color draw calls take to mean "the quad's own colors". // The color draw calls take to mean "the quad's own colors".
constexpr float COLOR_UNSET = -1; constexpr float COLOR_UNSET = -1;
constexpr GLenum FRAMEBUFFER_INCOMPLETE_DIMENSIONS = 0x8cd9; constexpr GLenum FRAMEBUFFER_INCOMPLETE_DIMENSIONS = 0x8cd9;
@@ -978,10 +980,11 @@ bool Manager::shader_create(std::string_view shaderName, std::span<const VertexA
// Reads a whole file, false when it cannot be opened. // Reads a whole file, false when it cannot be opened.
static bool file_read(const std::string& path, std::string& text) static bool file_read(const std::string& path, std::string& text)
{ {
std::ifstream file(path, std::ios::binary); std::ifstream file(path, std::ios::binary | std::ios::ate);
if (!file) return false; if (!file) return false;
text.assign(std::istreambuf_iterator<char>(file), {}); text.resize((size_t)file.tellg());
return true; file.seekg(0);
return (bool)file.read(text.data(), (std::streamsize)text.size());
} }
// 00a147e0 Builds a shader from its two GLSL files, given as the paths in files, and caches it. // 00a147e0 Builds a shader from its two GLSL files, given as the paths in files, and caches it.
@@ -1054,22 +1057,42 @@ static int format_bytes(ImageFormat format)
return format == IMAGE_RGB ? 3 : format == IMAGE_RGBA ? COLOR_CHANNELS : 1; return format == IMAGE_RGB ? 3 : format == IMAGE_RGBA ? COLOR_CHANNELS : 1;
} }
// 00a663c0 Premultiplies RGBA texels by their alpha through the game's rounding, in gamma 2.2 for sRGB. // The exe's premultiply tables (00c23640 straight, 00c13640 in gamma 2.2 for sRGB), indexed by alpha << 8 | color.
static void texels_premultiply(std::vector<uint8_t>& texels) // Built on first use from the formulas every entry of both matches.
static const PremultiplyTable& premultiply_table_get()
{ {
auto build = [](auto premultiply)
{
PremultiplyTable table{};
for (int alpha = 0; alpha <= UINT8_MAX; alpha++)
for (int color = 0; color <= UINT8_MAX; color++)
table[alpha << PREMULTIPLY_ALPHA_SHIFT | color] = (uint8_t)premultiply(color, alpha);
return table;
};
if (manager.isSrgb)
{
static PremultiplyTable srgb = build([](int color, int alpha) {
double linear = std::pow(color / (double)UINT8_MAX, SRGB_GAMMA) * alpha / UINT8_MAX;
return (int)std::floor(UINT8_MAX * std::pow(linear, 1 / SRGB_GAMMA) + 0.5);
});
return srgb;
}
static PremultiplyTable straight =
build([](int color, int alpha) { return (color * alpha + UINT8_MAX / 2) / UINT8_MAX; });
return straight;
}
// 00a663c0 Premultiplies RGBA texels by their alpha through the game's table. A clear texel turns black.
static void texels_premultiply(std::span<uint8_t> texels)
{
const PremultiplyTable& table = premultiply_table_get();
for (size_t i = 0; i + COLOR_CHANNELS <= texels.size(); i += COLOR_CHANNELS) for (size_t i = 0; i + COLOR_CHANNELS <= texels.size(); i += COLOR_CHANNELS)
{ {
int alpha = texels[i + 3]; int alpha = texels[i + 3];
if (alpha == UINT8_MAX) continue; if (alpha == UINT8_MAX) continue;
for (int channel = 0; channel < 3; channel++) for (int channel = 0; channel < 3; channel++)
{ texels[i + channel] = alpha ? table[alpha << PREMULTIPLY_ALPHA_SHIFT | texels[i + channel]] : 0;
int color = alpha ? texels[i + channel] : 0;
double linear = std::pow(color / (double)UINT8_MAX, SRGB_GAMMA) * alpha / UINT8_MAX;
double gamma = std::floor(UINT8_MAX * std::pow(linear, 1 / SRGB_GAMMA) + 0.5);
int premultiplied = (color * alpha + UINT8_MAX / 2) / UINT8_MAX;
texels[i + channel] = (uint8_t)(manager.isSrgb ? (int)gamma : premultiplied);
}
if (!alpha) texels[i + 3] = 0;
} }
} }
@@ -1083,12 +1106,16 @@ static bool image_fill(ImageBase& image, const uint8_t* pixels, int pixelWidth,
} }
int bytes = format_bytes(format); int bytes = format_bytes(format);
size_t rowSize = (size_t)pixelWidth * bytes;
bool isPremultiplied = manager.isPremultipliedAlpha && format == IMAGE_RGBA;
std::vector<uint8_t> texels((size_t)image.textureWidth * image.textureHeight * bytes); std::vector<uint8_t> texels((size_t)image.textureWidth * image.textureHeight * bytes);
for (int row = 0; row < pixelHeight; row++) for (int row = 0; row < pixelHeight; row++)
std::copy_n(pixels + (size_t)row * pixelWidth * bytes, (size_t)pixelWidth * bytes, {
texels.begin() + (size_t)row * image.textureWidth * bytes); uint8_t* destination = texels.data() + (size_t)row * image.textureWidth * bytes;
std::copy_n(pixels + row * rowSize, rowSize, destination);
if (isPremultiplied) texels_premultiply({destination, rowSize});
}
image.format = format; image.format = format;
if (manager.isPremultipliedAlpha && format == IMAGE_RGBA) texels_premultiply(texels);
return image.texels_load(texels); return image.texels_load(texels);
} }
+2 -1
View File
@@ -292,9 +292,10 @@ bool Platform::window_open()
return true; return true;
} }
// Shows the finished frame, as glfwSwapBuffers. // Shows the finished frame, as glfwSwapBuffers, after the harness's screenshot of it.
void Platform::window_swap() void Platform::window_swap()
{ {
harness.screenshot_save();
SDL_GL_SwapWindow(window); SDL_GL_SwapWindow(window);
} }
+2
View File
@@ -2,4 +2,6 @@
#include <string_view> #include <string_view>
constexpr const char* SCREENSHOTS_FOLDER = "screenshots";
void save_screenshot(std::string_view name); void save_screenshot(std::string_view name);
+1 -1
View File
@@ -95,7 +95,7 @@ void coop_awards_load(std::array<CoopAward, COOP_AWARD_COUNT>& awards)
const CoopAwardRule& rule = COOP_AWARD_RULES[i]; const CoopAwardRule& rule = COOP_AWARD_RULES[i];
CoopAward& award = awards[i]; CoopAward& award = awards[i];
award.name = g_manager->stringTable.translate(COOP_AWARD_KEYS[i]); award.name = string_table_translate(g_manager->stringTable, COOP_AWARD_KEYS[i]);
award.statId = rule.statId; award.statId = rule.statId;
award.isTieShared = rule.isTieShared; award.isTieShared = rule.isTieShared;
award.isMostWins = rule.isMostWins; award.isMostWins = rule.isMostWins;
-1
View File
@@ -192,7 +192,6 @@ constexpr int UPDATE_FRAME_PERIOD = 2;
constexpr int CURSOR_VISIBLE_FRAMES = 300; constexpr int CURSOR_VISIBLE_FRAMES = 300;
constexpr const char* CURSOR_CLICKED_ANIMATION = "Clicked"; constexpr const char* CURSOR_CLICKED_ANIMATION = "Clicked";
constexpr int SCREENSHOT_KEY = 298; constexpr int SCREENSHOT_KEY = 298;
constexpr const char* SCREENSHOTS_FOLDER = "screenshots";
constexpr const char* MANUAL_SCREENSHOT = "screenshots/ManualScreenshot"; constexpr const char* MANUAL_SCREENSHOT = "screenshots/ManualScreenshot";
// The stage bar's icon for a stage not reached. // The stage bar's icon for a stage not reached.
constexpr int STAGE_ICON_EMPTY = 17; constexpr int STAGE_ICON_EMPTY = 17;
+4 -4
View File
@@ -3211,9 +3211,9 @@ constexpr std::array<BlueWombRoom, 5> BLUE_WOMB_ROOMS = {{
{{6, 4}, ROOMSHAPE_2x2, {6, 5}, DIRECTION_UP, ROOM_BOSS}, {{6, 4}, ROOMSHAPE_2x2, {6, 5}, DIRECTION_UP, ROOM_BOSS},
}}; }};
// 0074a500 Lays out the Blue Womb by hand from its own rooms, Tainted Keeper's shop when he plays. Then the rooms off // 0074a500 Lays out the Blue Womb by hand from its own rooms, Tainted Keeper's shop when he plays, the start room
// the map, all drawn from the generation RNG: the error room, black market, crawl space, Mega Satan's, the Void's // counted the last boss room as in Greed. Then the rooms off the map, all drawn from the generation RNG: the error
// entrance, the Member Card's shop and the angel shop. // room, black market, crawl space, Mega Satan's, the Void's entrance, the Member Card's shop and the angel shop.
void Level::generate_blue_womb() void Level::generate_blue_womb()
{ {
RoomConfig& roomConfig = g_game->roomConfig; RoomConfig& roomConfig = g_game->roomConfig;
@@ -3246,7 +3246,7 @@ void Level::generate_blue_womb()
nbRooms = 0; nbRooms = 0;
for (size_t i = 0; i < BLUE_WOMB_ROOMS.size(); i++) for (size_t i = 0; i < BLUE_WOMB_ROOMS.size(); i++)
place_room(generator.rooms[i], configs[i], generationRNG.Next(), nullptr); place_room(generator.rooms[i], configs[i], generationRNG.Next(), nullptr);
lastBossRoomListIdx = generator.rooms.back().generationIndex; lastBossRoomListIdx = generator.rooms[0].generationIndex;
RoomQuery voidQuery = room_query(STAGE_ID_BLUE_WOMB, ROOM_DEFAULT, 1); RoomQuery voidQuery = room_query(STAGE_ID_BLUE_WOMB, ROOM_DEFAULT, 1);
+4 -3
View File
@@ -832,8 +832,9 @@ Vector Minimap::GetDisplayedSize()
return vector_make(map.boundsMax.x - map.boundsMin.x, map.boundsMax.y - map.boundsMin.y); return vector_make(map.boundsMax.x - map.boundsMin.x, map.boundsMax.y - map.boundsMin.y);
} }
// 0098e4d0 Draws the maps as far as they show through the room transition's HUD fade, then the time and score, // 0098e4d0 Draws the maps as far as they show through the room transition's HUD fade, then the time and score as far
// outside the no HUD seed. Home's dungeon shows only the time and score, and only in a daily run. // as the large map shows (at least half shown under the extra HUD), outside the no HUD seed. Home's dungeon shows
// only the time and score, and only in a daily run.
void Minimap::Render() void Minimap::Render()
{ {
Game& game = *g_game; Game& game = *g_game;
@@ -854,7 +855,7 @@ void Minimap::Render()
if (largeAlpha > 0) render_large(largeAlpha, isLost); if (largeAlpha > 0) render_large(largeAlpha, isLost);
bool isHistoryShown = g_manager->optionsConfig.historyHudMode == HISTORY_HUD_ON; bool isHistoryShown = g_manager->optionsConfig.historyHudMode == HISTORY_HUD_ON;
float scoreAlpha = isHistoryShown ? std::max(SCORE_HISTORY_ALPHA, hudAlpha) : hudAlpha; float scoreAlpha = isHistoryShown ? std::max(SCORE_HISTORY_ALPHA, largeAlpha) : largeAlpha;
if (scoreAlpha > 0) render_score_time(scoreAlpha); if (scoreAlpha > 0) render_score_time(scoreAlpha);
} }
+3 -1
View File
@@ -251,8 +251,10 @@ static void game_register(lua_State* state)
lua_method(state, "IsPaused", [](Game& game) { return game.IsPaused(); }); lua_method(state, "IsPaused", [](Game& game) { return game.IsPaused(); });
lua_method(state, "IsGreedMode", [](Game& game) { return game.IsGreedMode(); }); lua_method(state, "IsGreedMode", [](Game& game) { return game.IsGreedMode(); });
lua_method(state, "GetStateFlag", [](Game& game, GameStateFlag flag) { return game.GetStateFlag(flag); }); lua_method(state, "GetStateFlag", [](Game& game, GameStateFlag flag) { return game.GetStateFlag(flag); });
// 004d72b0 A negative flag is flag 0.
lua_method(state, "SetStateFlag", [](Game& game, int flag, bool isSet) { lua_method(state, "SetStateFlag", [](Game& game, int flag, bool isSet) {
game.gameStateFlags = isSet ? game.gameStateFlags | 1ull << flag : game.gameStateFlags & ~(1ull << flag); uint64_t mask = 1ull << std::max(flag, 0);
game.gameStateFlags = isSet ? game.gameStateFlags | mask : game.gameStateFlags & ~mask;
}); });
lua_method(state, "ShakeScreen", [](Game&, int timeout) { game_shake_screen(timeout); }); lua_method(state, "ShakeScreen", [](Game&, int timeout) { game_shake_screen(timeout); });
lua_method(state, "Spawn", [](Game& game, int type, int variant, Vector position, Vector velocity, Entity* spawner, lua_method(state, "Spawn", [](Game& game, int type, int variant, Vector position, Vector velocity, Entity* spawner,
+13 -6
View File
@@ -104,12 +104,17 @@ static void font_register(lua_State* state)
lua_method(state, "SetMaxCharacters", lua_method(state, "SetMaxCharacters",
[](FontSettings& settings, int16_t count) { settings.maxCharacters = count; }); [](FontSettings& settings, int16_t count) { settings.maxCharacters = count; });
lua_method(state, "GetMaxCharacters", [](FontSettings& settings) { return settings.maxCharacters; }); lua_method(state, "GetMaxCharacters", [](FontSettings& settings) { return settings.maxCharacters; });
lua_method(state, "EnableAutoWrap", [](FontSettings& settings, bool isOn) { // 0085e450 Wraps lines at a width, resetting the line height modifier.
settings.wrapMode = isOn ? FONT_WRAP_WORDS : FONT_WRAP_NONE; lua_method(state, "EnableAutoWrap", [](FontSettings& settings, uint16_t width) {
settings.wrapMode = FONT_WRAP_WORDS;
settings.maxLineWidth = width;
settings.lineHeightModifier = 1;
}); });
lua_method(state, "IsAutoWrapEnabled", [](FontSettings& settings) { return settings.wrapMode == FONT_WRAP_WORDS; }); lua_method(state, "IsAutoWrapEnabled", [](FontSettings& settings) { return settings.wrapMode == FONT_WRAP_WORDS; });
lua_method(state, "EnableTruncation", [](FontSettings& settings, bool isOn) { // 00a1a600 Truncates lines at a width.
settings.wrapMode = isOn ? FONT_WRAP_TRUNCATE : FONT_WRAP_NONE; lua_method(state, "EnableTruncation", [](FontSettings& settings, uint16_t width) {
settings.wrapMode = FONT_WRAP_TRUNCATE;
settings.maxLineWidth = width;
}); });
lua_method(state, "IsTruncationEnabled", lua_method(state, "IsTruncationEnabled",
[](FontSettings& settings) { return settings.wrapMode == FONT_WRAP_TRUNCATE; }); [](FontSettings& settings) { return settings.wrapMode == FONT_WRAP_TRUNCATE; });
@@ -128,8 +133,10 @@ static void font_register(lua_State* state)
lua_method(state, "Load", [](Font& font, std::string_view path) { return font.Load(path); }); lua_method(state, "Load", [](Font& font, std::string_view path) { return font.Load(path); });
lua_method(state, "Unload", [](Font& font) { font.Unload(); }); lua_method(state, "Unload", [](Font& font) { font.Unload(); });
lua_method(state, "IsLoaded", [](Font& font) { return font.isLoaded; }); lua_method(state, "IsLoaded", [](Font& font) { return font.isLoaded; });
lua_method(state, "GetCharacterWidth", // 008a8e40 GetCharacterWidth takes a string and measures its first byte.
[](Font& font, uint32_t character) { return font.GetCharacterWidth(character); }); lua_method(state, "GetCharacterWidth", [](Font& font, std::string_view text) {
return font.GetCharacterWidth(text.empty() ? 0 : (uint8_t)text[0]);
});
lua_method(state, "GetStringWidth", [](Font& font, std::string_view text) { return font.GetStringWidth(text); }); lua_method(state, "GetStringWidth", [](Font& font, std::string_view text) { return font.GetStringWidth(text); });
lua_method(state, "GetLineHeight", [](Font& font) { return font.GetLineHeight(); }); lua_method(state, "GetLineHeight", [](Font& font) { return font.GetLineHeight(); });
lua_method(state, "GetBaselineHeight", [](Font& font) { return font.GetBaselineHeight(); }); lua_method(state, "GetBaselineHeight", [](Font& font) { return font.GetBaselineHeight(); });
+5 -5
View File
@@ -273,7 +273,7 @@ int LuaEngine::PreGetCollectible(const LuaCollectibleDraw& draw)
bool LuaEngine::EntityTakeDamage(Entity* entity, float damage, uint64_t damageFlags, const EntityRef& source, bool LuaEngine::EntityTakeDamage(Entity* entity, float damage, uint64_t damageFlags, const EntityRef& source,
int countdown) int countdown)
{ {
CallbackRun run = {"EntityTakeDamage", MC_ENTITY_TAKE_DMG, entity->type}; CallbackRun run = {"PreEntityTakeDamage", MC_ENTITY_TAKE_DMG, entity->type};
return callback_boolean_run(*this, run, true, entity, damage, damageFlags, &source, countdown); return callback_boolean_run(*this, run, true, entity, damage, damageFlags, &source, countdown);
} }
@@ -287,7 +287,7 @@ bool LuaEngine::PreEntityDevolve(Entity* entity)
// The original throws past its callers on a Lua error. This logs it and spawns the award. // The original throws past its callers on a Lua error. This logs it and spawns the award.
bool LuaEngine::PreSpawnCleanAward(const RNG& rng, const Vector& position) bool LuaEngine::PreSpawnCleanAward(const RNG& rng, const Vector& position)
{ {
return callback_boolean_run(*this, {"PreSpawnCleanAward", MC_PRE_SPAWN_CLEAN_AWARD}, false, rng, position); return callback_boolean_run(*this, {"PreRoomRewardSpawn", MC_PRE_SPAWN_CLEAN_AWARD}, false, rng, position);
} }
// 00863760 Runs MC_PRE_USE_ITEM for an active item, filtered by its type. Whether a mod skips the use. // 00863760 Runs MC_PRE_USE_ITEM for an active item, filtered by its type. Whether a mod skips the use.
@@ -370,13 +370,13 @@ void LuaEngine::EvaluateItems(Entity_Player* player, int cacheFlag)
// 008635a0 Runs MC_FAMILIAR_INIT, filtered by the familiar's variant. // 008635a0 Runs MC_FAMILIAR_INIT, filtered by the familiar's variant.
void LuaEngine::FamiliarInit(Entity_Familiar* familiar) void LuaEngine::FamiliarInit(Entity_Familiar* familiar)
{ {
callback_notify(*this, {"FamiliarInit", MC_FAMILIAR_INIT, familiar->variant}, familiar); callback_notify(*this, {"PostFamiliarInit", MC_FAMILIAR_INIT, familiar->variant}, familiar);
} }
// 00860f00 Runs MC_FAMILIAR_UPDATE, filtered by the familiar's variant. // 00860f00 Runs MC_FAMILIAR_UPDATE, filtered by the familiar's variant.
void LuaEngine::FamiliarUpdate(Entity_Familiar* familiar) void LuaEngine::FamiliarUpdate(Entity_Familiar* familiar)
{ {
callback_notify(*this, {"FamiliarUpdate", MC_FAMILIAR_UPDATE, familiar->variant}, familiar); callback_notify(*this, {"PostFamiliarUpdate", MC_FAMILIAR_UPDATE, familiar->variant}, familiar);
} }
// 00860fe0 Runs MC_POST_FAMILIAR_RENDER with the render offset, filtered by the familiar's variant. // 00860fe0 Runs MC_POST_FAMILIAR_RENDER with the render offset, filtered by the familiar's variant.
@@ -561,7 +561,7 @@ void LuaEngine::PostPlayerInit(Entity_Player* player)
// 00863be0 Runs MC_POST_PEFFECT_UPDATE, filtered by the player's character. // 00863be0 Runs MC_POST_PEFFECT_UPDATE, filtered by the player's character.
void LuaEngine::PostPEffectUpdate(Entity_Player* player) void LuaEngine::PostPEffectUpdate(Entity_Player* player)
{ {
callback_notify(*this, {"PostPEffectUpdate", MC_POST_PEFFECT_UPDATE, player->playerType}, player); callback_notify(*this, {"PostPlayerEffectUpdate", MC_POST_PEFFECT_UPDATE, player->playerType}, player);
} }
// 00864130 Runs MC_POST_PLAYER_UPDATE, filtered by the player's variant. // 00864130 Runs MC_POST_PLAYER_UPDATE, filtered by the player's variant.
+1 -1
View File
@@ -372,7 +372,7 @@ int form_progress_get(const ItemConfig_PlayerForm& form, const Entity_Player* pl
// A transformation's line in a panel: its name and a count of the items it takes. // A transformation's line in a panel: its name and a count of the items it takes.
std::string form_line_get(const ItemConfig_PlayerForm& form, int progress) std::string form_line_get(const ItemConfig_PlayerForm& form, int progress)
{ {
std::string name(g_manager->stringTable.translate(form.name)); std::string name(string_table_translate(g_manager->stringTable, form.name));
return name + FORM_SEPARATOR + std::to_string(progress) + "/" + std::to_string(FORM_GOAL); return name + FORM_SEPARATOR + std::to_string(progress) + "/" + std::to_string(FORM_GOAL);
} }
+3 -3
View File
@@ -105,8 +105,8 @@ void MenuManager::online_awards_render()
if (award > 0 && award % AWARD_ROWS == 0) label = vector_make(label.x + COLUMN_WIDTH, start.y); if (award > 0 && award % AWARD_ROWS == 0) label = vector_make(label.x + COLUMN_WIDTH, start.y);
FontSettings labelSettings; FontSettings labelSettings;
font.DrawString(isWon ? g_manager->stringTable.translate(COOP_AWARD_KEYS[award]) : UNKNOWN_TEXT, label, scale, std::string_view name = string_table_translate(g_manager->stringTable, COOP_AWARD_KEYS[award]);
color, labelSettings); font.DrawString(isWon ? name : UNKNOWN_TEXT, label, scale, color, labelSettings);
FontSettings countSettings(ALIGN_TOP_RIGHT); FontSettings countSettings(ALIGN_TOP_RIGHT);
font.DrawString(std::to_string(count), vector_make(label.x + COUNT_OFFSET_X, label.y), scale, color, font.DrawString(std::to_string(count), vector_make(label.x + COUNT_OFFSET_X, label.y), scale, color,
countSettings); countSettings);
@@ -116,7 +116,7 @@ void MenuManager::online_awards_render()
FontSettings descriptionSettings(ALIGN_TOP_CENTER); FontSettings descriptionSettings(ALIGN_TOP_CENTER);
descriptionSettings.EnableAutoWrap(DESCRIPTION_WIDTH); descriptionSettings.EnableAutoWrap(DESCRIPTION_WIDTH);
std::string key = std::string(COOP_AWARD_KEYS[award]) + DESCRIPTION_SUFFIX; std::string key = std::string(COOP_AWARD_KEYS[award]) + DESCRIPTION_SUFFIX;
font.DrawString(isWon ? g_manager->stringTable.translate(key) : UNKNOWN_TEXT, font.DrawString(isWon ? string_table_translate(g_manager->stringTable, key) : UNKNOWN_TEXT,
vector_add(draw.position, description->pos), scale, TEXT_COLOR, descriptionSettings); vector_add(draw.position, description->pos), scale, TEXT_COLOR, descriptionSettings);
} }
} }
+3 -3
View File
@@ -411,13 +411,13 @@ void Popup::select_move(int step)
} while (desc.lines[selectedLine].id == POPUP_LINE_TEXT); } while (desc.lines[selectedLine].id == POPUP_LINE_TEXT);
} }
// A line's text, looked up in the string tables when it starts with ##GAME## or ##PLATFORM##. // A line's text, the #key after ##GAME## or ##PLATFORM## translated by the matching string table.
static std::string_view line_text_translate(std::string_view text) static std::string_view line_text_translate(std::string_view text)
{ {
if (text.starts_with(GAME_STRING_PREFIX)) if (text.starts_with(GAME_STRING_PREFIX))
return g_manager->stringTable.translate(text.substr(GAME_STRING_PREFIX.size())); return string_table_translate(g_manager->stringTable, text.substr(GAME_STRING_PREFIX.size()));
if (text.starts_with(PLATFORM_STRING_PREFIX)) if (text.starts_with(PLATFORM_STRING_PREFIX))
return g_manager->stringTablePc.translate(text.substr(PLATFORM_STRING_PREFIX.size())); return string_table_translate(g_manager->stringTablePc, text.substr(PLATFORM_STRING_PREFIX.size()));
return text; return text;
} }