Curation round 1: 66 boot-path functions rewritten in src/; the game links into a Linux executable

Six agents took over ANM2/AnimationState/LayerState, ItemConfig, EntityConfig, StringTable/Font/FormattedText/RichText,
OptionsConfig/ChallengeParams and ModManager/ModEntry functions (FormattedText::parse checked against a transliteration
of its assembly on 200,000 random inputs). 174 field rows and 32 names from the round are merged into db/.
source_tree.py: a struct or class src/*.h defines is no longer emitted in classes.h (class takeover) and gets no stubs;
data labels get stub definitions. build/isaac links (64-bit ELF) and stops at the first function not reconstructed:
IsaacMain. Boot path 64/615 functions curated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shweetandClaude Opus 5.5 committed 2026-11-19 22:13:25 -05:00
1 parent 8c31c98a81
commit 837aa06518
63 files changed
+10557 -12054

No files matched your search

+511
View File
@@ -0,0 +1,511 @@
#include "entity_config.h"
#include "data.h"
#include "log.h"
#include <algorithm>
#include <array>
#include <cstdarg>
#include <new>
#include <span>
#include <string>
// An MSVC string keeps up to 15 characters in its own buffer, and a pointer to the heap there past that.
constexpr uint32_t STRING_INLINE_CAPACITY = 15;
constexpr char STRING_KEY_PREFIX = '#';
constexpr size_t LOG_MESSAGE_SIZE = 1024;
constexpr int DEFAULT_COLLISION_INTERVAL = 7;
constexpr int DEFAULT_SHIELD_FRAMES = 120;
// The bosscolors.xml versions the game reads. Version 1 adds the anm2 and portrait paths.
constexpr int BOSS_COLORS_VERSION_MAX = 1;
// The preset champion looks a bosscolors.xml idx picks, from 1. Each is a tint and an offset, at full alpha.
struct BossColorPreset
{
float tint[3];
float offset[3] = {};
};
constexpr BossColorPreset BOSS_COLOR_PRESETS[] = {
{{1, 0.6f, 0.6f}}, {{0.6f, 0.6f, 0.6f}}, {{0.6f, 1, 0.6f}}, {{0.6f, 1, 1}},
{{0.5f, 0.7f, 0.5f}}, {{1, 0.7f, 0.5f}}, {{0.5f, 0.7f, 1}}, {{0.5f, 0.7f, 0.7f}},
{{1, 0.7f, 0.5f}}, {{0, 1.7f, 1.1f}}, {{0.6f, 0.7f, 0.6f}}, {{1, 1, 0.5f}},
{{0.3f, 0.7f, 0.6f}}, {{1, 0.6f, 0.6f}}, {{0.5f, 0.5f, 0.6f}}, {{0.44f, 0.44f, 0.44f}},
{{0.5f, 0.5f, 0.5f}, {0.2f, 0.2f, 0.2f}}, {{0.24f, 0.24f, 0.24f}}, {{1.2f, 0.7f, 0.7f}},
{{2.5f, 1.2f, 1.5f}}, {{1, 1, 1}, {0.08f, -0.2f, -0.87f}}, {{1.5f, 1, 1.15f}}, {{0.7f, 0.5f, 0.3f}},
};
constexpr int BOSS_COLOR_PRESET_COUNT = sizeof(BOSS_COLOR_PRESETS) / sizeof(BOSS_COLOR_PRESETS[0]);
// Gives color preset number index, from 1, leaving it as it is for any other number.
static void boss_color_preset_apply(Color& color, int index)
{
if (index < 1 || index > BOSS_COLOR_PRESET_COUNT) return;
std::ranges::copy(BOSS_COLOR_PRESETS[index - 1].tint, color._tint);
std::ranges::copy(BOSS_COLOR_PRESETS[index - 1].offset, color._offset);
}
// Formats a message for KAGE_LogMessage, whose declaration takes nothing to format with.
[[gnu::format(printf, 2, 3)]] static void log_print(LogLevel level, const char* format, ...)
{
char message[LOG_MESSAGE_SIZE];
va_list args;
va_start(args, format);
vsnprintf(message, sizeof(message), format, args);
va_end(args);
KAGE_LogMessage(level, (uint8_t*)message);
}
// Attribute text as atoi and atof read it. simdjson keeps every string NUL-terminated.
static int text_int(std::string_view text)
{
return text.empty() ? 0 : atoi(text.data());
}
static float text_float(std::string_view text)
{
return text.empty() ? 0 : (float)atof(text.data());
}
// Calls visit with each attribute's name and text in document order, as the original walked a rapidxml node's.
template <class Visit> static void node_attrs_walk(DataNode node, Visit visit)
{
simdjson::dom::object attrs;
if (node["attrs"].get(attrs) != simdjson::SUCCESS) return;
for (auto [name, value] : attrs) visit(name, value.get_string().value_unsafe());
}
// Calls visit with node's children from the first one named tag on, as first_node(tag) then next_sibling() walked them.
template <class Visit> static void node_children_walk(DataNode node, std::string_view tag, Visit visit)
{
simdjson::dom::array children;
bool isFound = false;
if (node["children"].get(children) != simdjson::SUCCESS) return;
for (DataNode child : children)
{
isFound = isFound || node_tag(child) == tag;
if (isFound) visit(child);
}
}
static char* string_text(std_string& text)
{
return text._capacity > STRING_INLINE_CAPACITY ? *(char**)text._buf : text._buf;
}
static void string_init(std_string& text)
{
text._buf[0] = '\0';
text._size = 0;
text._capacity = STRING_INLINE_CAPACITY;
}
static void string_set(std_string& text, std::string_view value)
{
((msvc::string*)&text)->assign((uint8_t*)value.data(), (uint32_t)value.size());
}
static void string_free(std_string& text)
{
((msvc::string*)&text)->_Tidy_deallocate();
}
// Makes text, whatever it held, a new string with source's characters.
static void string_copy(std_string& text, std_string& source)
{
string_init(text);
string_set(text, {string_text(source), source._size});
}
static EntityConfig_BossColor record_copy(EntityConfig_BossColor& source)
{
EntityConfig_BossColor color = source;
string_copy(color.suffix, source.suffix);
string_copy(color.anm2Path, source.anm2Path);
string_copy(color.portraitPath, source.portraitPath);
return color;
}
static EntityConfig_Preload record_copy(EntityConfig_Preload& source)
{
EntityConfig_Preload preload = source;
string_copy(preload.path, source.path);
return preload;
}
template <class T> static T record_copy(T& source)
{
return source;
}
static void record_free(EntityConfig_BossColor& color)
{
string_free(color.portraitPath);
string_free(color.anm2Path);
string_free(color.suffix);
}
static void record_free(EntityConfig_Preload& preload)
{
string_free(preload.path);
}
static void record_free(EntityConfig_Baby& baby)
{
string_free(baby.gfx);
string_free(baby.name);
}
template <class T> static void record_free(T&)
{
}
template <class T> static std::span<T> vector_items(std_vector& items)
{
return {(T*)items._begin, (T*)items._end};
}
// Moves the records into new storage of capacity records, freeing the old.
template <class T> static void vector_reserve(std_vector& items, size_t capacity)
{
std::span<T> records = vector_items<T>(items);
auto begin = (T*)msvc::_Allocate((uint32_t)(capacity * sizeof(T)));
if (!records.empty()) std::memcpy((void*)begin, records.data(), records.size_bytes());
FID_conflict__Tidy(&items);
items = {begin, begin + records.size(), begin + capacity};
}
// Appends record, taking over the strings it owns. A full vector grows by half, as MSVC's does.
template <class T> static void vector_push(std_vector& items, T& record)
{
size_t capacity = (T*)items._capacity - (T*)items._begin;
if (items._end == items._capacity) vector_reserve<T>(items, std::max(capacity + capacity / 2, capacity + 1));
std::memcpy(items._end, (void*)&record, sizeof(T));
items._end = (T*)items._end + 1;
}
// Makes items, whatever it held, a new vector of copies of source's records.
template <class T> static void vector_copy(std_vector& items, std_vector& source)
{
std::span<T> records = vector_items<T>(source);
items = {};
if (records.empty()) return;
vector_reserve<T>(items, records.size());
for (T& record : records)
{
T copy = record_copy(record);
vector_push(items, copy);
}
}
template <class T> static void vector_clear(std_vector& items)
{
for (T& record : vector_items<T>(items)) record_free(record);
items._end = items._begin;
}
// Frees the records and their storage, with the allocator's own release, sized for any record a multiple of 4 bytes.
template <class T> static void vector_free(std_vector& items)
{
vector_clear<T>(items);
FID_conflict__Tidy(&items);
}
static auto entity_strings(EntityConfig_Entity& entity)
{
return std::array{&entity.name, &entity.anm2Path, &entity.gridCollisionClassString, &entity.bestiaryAnm2Path,
&entity.bestiaryAnim, &entity.bestiaryOverlay, &entity.bestiaryFloorAlt};
}
static auto player_strings(EntityConfig_Player& player)
{
return std::array{&player._name, &player._skinPath, &player._nameImagePath, &player._portraitPath,
&player._unkString, &player._extraPortraitPath, &player._costumeSuffixName,
&player._birthrightDescription, &player._bSkinParentName};
}
static void player_free(EntityConfig_Player& player)
{
for (std_string* text : player_strings(player)) string_free(*text);
vector_free<int>(player._collectibles);
}
static EntityConfig_Baby baby_make(int id, int achievementID)
{
EntityConfig_Baby baby;
baby.id = id;
string_init(baby.name);
string_init(baby.gfx);
baby.achievementID = achievementID;
return baby;
}
// The node filed under key, or the map's head when there is none.
static EntityConfig_EntityNode* entity_find(EntityConfig_EntityNode* head, uint32_t key)
{
EntityConfig_EntityNode* bound = head;
for (EntityConfig_EntityNode* node = head->parent; !node->isNil;)
{
if (node->key < key) node = node->right;
else
{
bound = node;
node = node->left;
}
}
return !bound->isNil && bound->key == key ? bound : head;
}
// 00694230 An empty entity config: one-unit collision, shutting doors, no portrait.
EntityConfig_Entity::EntityConfig_Entity()
{
std::memset((void*)this, 0, sizeof(*this));
for (std_string* text : entity_strings(*this)) string_init(*text);
collisionRadius = 1;
collisionRadiusMulti = g_vectorOne;
shutDoors = true;
portrait = -1;
collisionInterval = DEFAULT_COLLISION_INTERVAL;
shieldFrames = DEFAULT_SHIELD_FRAMES;
bestiaryOffset = g_vectorZero;
bestiaryScale = 1;
}
// 00698ab0 Frees the config's strings and lists.
EntityConfig_Entity::~EntityConfig_Entity()
{
for (std_string* text : entity_strings(*this)) string_free(*text);
vector_free<EntityConfig_BossColor>(_bossColors);
vector_free<EntityConfig_Preload>(_preloads);
vector_free<int>(preloadSounds);
vector_free<Devolve>(devolve);
}
// 0069f560 A copy of another entity config, which is what its int* points to.
EntityConfig_Entity::EntityConfig_Entity(int* param_2)
{
auto& other = *(EntityConfig_Entity*)param_2;
auto strings = entity_strings(*this);
auto sources = entity_strings(other);
std::memcpy((void*)this, &other, sizeof(*this));
for (size_t i = 0; i < strings.size(); i++) string_copy(*strings[i], *sources[i]);
vector_copy<EntityConfig_BossColor>(_bossColors, other._bossColors);
vector_copy<EntityConfig_Preload>(_preloads, other._preloads);
vector_copy<int>(preloadSounds, other.preloadSounds);
vector_copy<Devolve>(devolve, other.devolve);
}
// 00698b40 Copies another entity config over this one.
EntityConfig_Entity* EntityConfig_Entity::operator_assign(EntityConfig_Entity* other)
{
if (other == this) return this;
this->~EntityConfig_Entity();
return new (this) EntityConfig_Entity((int*)other);
}
// 006a15c0 Takes over another entity config's strings and lists, leaving it empty ones.
EntityConfig_Entity* EntityConfig_Entity::move_constructor(EntityConfig_Entity* other)
{
std::memcpy((void*)this, other, sizeof(*this));
for (std_string* text : entity_strings(*other)) string_init(*text);
for (std_vector* items : {&other->_bossColors, &other->_preloads, &other->preloadSounds, &other->devolve}) *items = {};
return this;
}
// 00694490 An empty player config that can shoot, with no costume, achievement or tainted twin.
EntityConfig_Player::EntityConfig_Player()
{
std::memset((void*)this, 0, sizeof(*this));
for (std_string* text : player_strings(*this)) string_init(*text);
_id = -1;
_costumeID = -1;
_canShoot = true;
_achievement = -1;
_moddedTaintedPlayerID = -1;
}
// 0069e6c0 Makes dst a copy of src.
void EntityConfig_Player::copy_constructor(EntityConfig_Player* dst, EntityConfig_Player* src)
{
auto strings = player_strings(*dst);
auto sources = player_strings(*src);
std::memcpy((void*)dst, src, sizeof(*dst));
for (size_t i = 0; i < strings.size(); i++) string_copy(*strings[i], *sources[i]);
vector_copy<int>(dst->_collectibles, src->_collectibles);
}
// 0069b810 Copies another player config over this one.
EntityConfig_Player* EntityConfig_Player::operator_assign(EntityConfig_Player* other)
{
if (other == this) return this;
player_free(*this);
copy_constructor(this, other);
return this;
}
// 00694de0 The player's name, translated from the "Players" strings when it is a #key they hold.
std_string* EntityConfig_Player::GetDisplayName(std_string* outName, [[maybe_unused]] void* unused)
{
char* text = string_text(_name);
StringTable& strings = g_manager->_stringTable;
if (text[0] == STRING_KEY_PREFIX)
{
uint8_t isMissing = false;
auto translated = (char*)strings.get_string((uint8_t*)"Players", strings._language, (uint8_t*)text + 1, &isMissing);
if (!isMissing) text = translated;
}
string_init(*outName);
string_set(*outName, text);
return outName;
}
// 00694fb0 The config of an entity, falling back to subtype 0, then to variant 0, or null without one.
EntityConfig_Entity* EntityConfig::GetEntity(int id, int variant, int subtype)
{
auto head = (EntityConfig_EntityNode*)_entities._head;
while (true)
{
EntityConfig_EntityNode* node = entity_find(head, entity_key(id, variant, subtype));
if (node != head) return &node->entity;
if (subtype != 0) subtype = 0;
else if (variant != 0) variant = 0;
else return nullptr;
}
}
// 0069bd50 Reads babies.xml into _babies, padding with unnamed babies so each sits at its id when they come in order.
// The original crashes on a missing babies root or root attribute. This returns, and reads a missing root as empty.
void EntityConfig::LoadBabies(uint8_t* xmlpath)
{
Data data;
std::string root;
vector_clear<EntityConfig_Baby>(_babies);
data_load(data, (char*)xmlpath);
if (!data.isLoaded) return;
if (node_tag(data.root) != "babies")
{
log_print(LOG_ASSERT, "Could not find root node 'babies' in %s\n", (char*)xmlpath);
return;
}
root = node_attr(data.root, "root");
node_children_walk(data.root, "baby", [&](DataNode node) {
EntityConfig_Baby baby = baby_make(-1, -1);
node_attrs_walk(node, [&](std::string_view name, std::string_view value) {
if (name == "id") baby.id = text_int(value);
else if (name == "name") string_set(baby.name, value);
else if (name == "skin") string_set(baby.gfx, root + std::string(value));
else if (name == "achievement") baby.achievementID = text_int(value);
});
if (baby.id < 0)
{
record_free(baby);
return;
}
while ((int)vector_items<EntityConfig_Baby>(_babies).size() < baby.id)
{
EntityConfig_Baby filler = baby_make(-1, 0);
vector_push(_babies, filler);
}
vector_push(_babies, baby);
});
}
// 00698e80 Replaces the champion looks of each boss bosscolors.xml names. False when the file is missing.
// The original crashes on a missing bosscolors root or version and reads a boss without id or variant from garbage.
// This returns false, reads a missing version as 0 and carries id and variant over from the boss before, from 0.
uint8_t EntityConfig::load_boss_colors(uint8_t* path)
{
Data data;
int version = 0;
int type = 0;
int variant = 0;
std::string anm2Root;
std::string portraitRoot;
data_load(data, (char*)path);
if (!data.isLoaded) return false;
if (node_tag(data.root) != "bosscolors")
{
log_print(LOG_ASSERT, "Could not find root node 'bosscolors' in %s\n", (char*)path);
return false;
}
std::string_view versionText = node_attr(data.root, "version");
version = text_int(versionText);
if (version < 0 || version > BOSS_COLORS_VERSION_MAX)
log_print(LOG_ASSERT, "Invalid version %.*s for %s\n", (int)versionText.size(), versionText.data(), (char*)path);
if (version > 0)
{
anm2Root = node_attr(data.root, "anm2root");
portraitRoot = node_attr(data.root, "portraitroot");
}
node_children_walk(data.root, "boss", [&](DataNode bossNode) {
node_attrs_walk(bossNode, [&](std::string_view name, std::string_view value) {
if (name == "id") type = text_int(value);
else if (name == "variant") variant = text_int(value);
});
EntityConfig_Entity* entity = GetEntity(type, variant, 0);
if (!entity || entity->variant != variant)
{
log_print(LOG_INFO, "Cannot patch boss colors for Entity %d.%d\n", type, variant);
return;
}
vector_clear<EntityConfig_BossColor>(entity->_bossColors);
node_children_walk(bossNode, "color", [&](DataNode colorNode) {
EntityConfig_BossColor bossColor;
string_init(bossColor.suffix);
string_init(bossColor.anm2Path);
string_init(bossColor.portraitPath);
bossColor.scale = 1;
bossColor.hpMultiplier = 1;
node_attrs_walk(colorNode, [&](std::string_view name, std::string_view value) {
if (name == "idx") boss_color_preset_apply(bossColor.color, text_int(value));
else if (name == "suffix") string_set(bossColor.suffix, value);
else if (name == "anm2path" && version > 0) string_set(bossColor.anm2Path, anm2Root + std::string(value));
else if (name == "portrait" && version > 0) string_set(bossColor.portraitPath, portraitRoot + std::string(value));
else if (name == "scale") bossColor.scale = text_float(value);
else if (name == "hp") bossColor.hpMultiplier = text_float(value);
});
vector_push(entity->_bossColors, bossColor);
});
});
return true;
}