#include "entity_config.h" #include "data.h" #include "manager.h" #include "texture_cache.h" #include #include #include #include constexpr std::string_view DOCUMENT_TAG = "#document"; constexpr std::string_view ENTITIES_VERSION = "5"; constexpr int BOSS_COLORS_VERSION_MAX = 1; constexpr char STRING_KEY_PREFIX = '#'; constexpr float SHADOW_SIZE_SCALE = 100; // Eden, whose children list the hairstyles it rolls, and the point boss portrait pivots are measured back from. constexpr int PLAYER_EDEN = 9; constexpr float BOSS_PORTRAIT_ORIGIN_X = 96; constexpr float BOSS_PORTRAIT_ORIGIN_Y = 132; // Types that share one id by variant, so a mod's clashing entity takes the next variant instead of the next type. constexpr int ENTITY_EFFECT = 1000; constexpr int ENTITY_TEXT = 9001; constexpr int ENTITY_FIRST_NPC = 10; // What tags and gibFlags read, each name standing for its index's bit. constexpr std::array ENTITY_TAG_NAMES = { "fly", "spider", "poop", "ghost", "noreroll", "cansacrifice", "explosive_soul", "homing_soul", "brimstone_soul", "nodelirium"}; constexpr std::array GIB_FLAG_NAMES = { "blood", "bone", "gut", "eye", "large", "poop", "worm", "rock", "rock_small", "sound_baby", "sound_bone", "chain", "dust", "huge"}; // The mod sprites a character takes its menus from, in PlayerSprite order, and the ones a tainted character takes. constexpr std::array PLAYER_SPRITE_SLOTS = { MOD_SPRITE_CHARACTER_MENU, MOD_SPRITE_CHARACTER_PORTRAITS, MOD_SPRITE_DEATH_SCREEN, MOD_SPRITE_COOP_MENU, MOD_SPRITE_CONTROLS}; constexpr std::array PLAYER_SPRITE_SLOTS_TAINTED = { MOD_SPRITE_CHARACTER_MENU_ALT, MOD_SPRITE_CHARACTER_PORTRAITS_ALT, MOD_SPRITE_DEATH_SCREEN_ALT, MOD_SPRITE_COOP_MENU_ALT, MOD_SPRITE_CONTROLS_ALT}; // 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]); // Which children of an element a walk visits: all, the ones of a tag, or every one from the first of a tag on. enum ChildWalk { CHILDREN_ALL, CHILDREN_TAGGED, CHILDREN_FROM_TAGGED }; // The roots entities2.xml gives every entity's paths, and whether the mod loading it brought its own portraits. struct EntityLoad { std::string anm2Root; bool isPortraitModded = false; }; // The roots players.xml gives every character's paths. struct PlayerLoad { std::string nameImageRoot; std::string portraitRoot; std::string skinRoot; }; // Attribute text as atoi and atof read it. Every attribute is NUL-terminated where simdjson keeps it. 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()); } // True for "true", "True" or a nonzero number, as the game reads its boolean attributes. static bool is_text_true(std::string_view text) { return text == "true" || text == "True" || text_int(text) != 0; } // The pieces between delimiters, as std::getline splits them: an empty last piece is dropped. static std::vector text_split(std::string_view text, char delimiter) { std::vector pieces; for (size_t start = 0; start < text.size();) { size_t end = std::min(text.find(delimiter, start), text.size()); pieces.emplace_back(text.substr(start, end - start)); start = end + 1; } return pieces; } // 00694680 The flags a space-separated list of names sets, each name standing for its index's bit. // An unknown name logs error. The original then sets a bit read from memory it never wrote, and this sets none. template static uint32_t flags_parse(std::string_view text, const std::array& names, const char* error) { uint32_t flags = 0; for (std::string& name : text_split(text, ' ')) { auto found = std::ranges::find(names, name); if (found == names.end()) log_printf(LOG_ASSERT, error, name.c_str()); else flags |= 1u << (found - names.begin()); } return flags; } // Calls visit with each attribute's name and text. template static void 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 the children walk picks, in document order. A leaf has no children array to walk at all. template static void children_walk(DataNode node, std::string_view tag, ChildWalk walk, Visit visit) { simdjson::dom::array children; bool isFound = walk == CHILDREN_ALL; if (node["children"].get(children) != simdjson::SUCCESS) return; for (DataNode child : children) { bool isTagged = node_tag(child) == tag; isFound = isFound || isTagged; if (walk == CHILDREN_TAGGED ? isTagged : isFound) visit(child); } } static std::optional child_find(DataNode node, std::string_view tag) { std::optional found; children_walk(node, tag, CHILDREN_TAGGED, [&](DataNode child) { if (!found) found = child; }); return found; } static std::optional attr_find(DataNode node, std::string_view name) { std::string_view value; if (node["attrs"][name].get(value) != simdjson::SUCCESS) return std::nullopt; return value; } // The document's root element of a tag, logging its absence. The original goes on to read the missing root and crashes. static std::optional root_find(Data& data, std::string_view tag, std::string_view path) { std::optional root = node_tag(data.root) == DOCUMENT_TAG ? child_find(data.root, tag) : node_tag(data.root) == tag ? std::optional(data.root) : std::nullopt; if (!root) log_printf(LOG_ASSERT, "Could not find root node '%.*s' in %.*s\n", (int)tag.size(), tag.data(), (int)path.size(), path.data()); return root; } // A name as the player reads it: a #key translated from the category's strings when they hold it. static std::string name_translate(std::string_view name, std::string_view category, int language) { StringTable& strings = g_manager->stringTable; bool isMissing = false; if (name.empty() || name[0] != STRING_KEY_PREFIX) return std::string(name); if (language == NAME_LANGUAGE_CURRENT) language = strings.language; std::string_view text = strings.get_string(category, language, name.substr(1), &isMissing); return std::string(isMissing ? name : text); } // Gives color preset number index, from 1, leaving it as it is for any other number. static void boss_color_preset_apply(ColorMod& 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); } // A bestiary transform, "x,y,scale". Any other number of pieces leaves the page as it was. static void bestiary_transform_read(EntityConfig_Entity& entity, std::string_view text) { std::vector pieces = text_split(text, ','); if (pieces.size() != 3) return; entity.bestiaryOffset = vector_make(text_float(pieces[0]), text_float(pieces[1])); entity.bestiaryScale = text_float(pieces[2]); } // One attribute of an . static void entity_attr_read(EntityConfig_Entity& entity, std::string_view name, std::string_view value, EntityLoad& load) { if (name == "id") entity.id = text_int(value); else if (name == "variant") entity.variant = text_int(value); else if (name == "subtype") entity.subtype = text_int(value); else if (name == "shadowSize") entity.shadowSize = (float)text_int(value) / SHADOW_SIZE_SCALE; else if (name == "name") entity.name = value; else if (name == "collisionDamage") entity.collisionDamage = text_float(value); else if (name == "boss") entity.isBoss = is_text_true(value); else if (name == "bossID") entity.bossID = text_int(value); else if (name == "champion") entity.isCanBeChampion = value == "1"; else if (name == "collisionRadius") entity.collisionRadius = text_float(value); else if (name == "collisionRadiusXMulti") entity.collisionRadiusMulti.x = text_float(value); else if (name == "collisionRadiusYMulti") entity.collisionRadiusMulti.y = text_float(value); else if (name == "collisionMass") entity.mass = text_float(value); else if (name == "numGridCollisionPoints") entity.gridCollisionPoints = text_int(value); else if (name == "friction") entity.friction = text_float(value); else if (name == "baseHP") entity.baseHP = text_float(value); else if (name == "stageHP") entity.stageHP = text_float(value); else if (name == "anm2path" && !value.empty()) entity.anm2Path = load.anm2Root + std::string(value); else if (name == "portrait") { entity.portrait = std::abs(text_int(value)); entity.isPortraitModded = text_int(value) >= 0 && load.isPortraitModded; } else if (name == "shutdoors") entity.isShutDoors = is_text_true(value); else if (name == "gridCollision") entity.gridCollisionClassString = value; else if (name == "reroll") entity.isReroll = is_text_true(value); else if (name == "hasFloorAlts") entity.isHasFloorAlts = is_text_true(value); else if (name == "collisionInterval") entity.collisionInterval = text_int(value); else if (name == "shieldStrength") entity.shieldStrength = text_float(value); else if (name == "shieldFrames") entity.shieldFrames = text_int(value); else if (name == "tags") entity.tags = flags_parse(value, ENTITY_TAG_NAMES, "invalid tag: %s\n"); else if (name == "bestiary") entity.isBestiary = is_text_true(value); else if (name == "bestiaryTransform") bestiary_transform_read(entity, value); else if (name == "bestiaryAnim") entity.bestiaryAnim = value; else if (name == "bestiaryOverlay") entity.bestiaryOverlay = value; else if (name == "gibAmount") entity.gibsAmount = text_int(value); else if (name == "gibFlags") entity.gibFlags |= flags_parse(value, GIB_FLAG_NAMES, "invalid gibflag entry: %s\n"); } // One attribute of an entity's . static void bestiary_attr_read(EntityConfig_Entity& entity, std::string_view name, std::string_view value, EntityLoad& load) { if (name == "transform") bestiary_transform_read(entity, value); else if (name == "parent") { std::vector parent = text_split(value, '.'); if (parent.size() > 0) entity.bestiaryParentType = text_int(parent[0]); if (parent.size() > 1) entity.bestiaryParentVariant = text_int(parent[1]); } else if (name == "anm2path") entity.bestiaryAnm2Path = load.anm2Root + std::string(value); else if (name == "anim") entity.bestiaryAnim = value; else if (name == "overlay") entity.bestiaryOverlay = value; else if (name == "alt") entity.bestiaryFloorAlt = value; } // An 's children: gibs, bestiary page, preloads, preloaded sounds and devolves. static void entity_children_read(EntityConfig_Entity& entity, DataNode node, EntityLoad& load) { if (auto gibs = child_find(node, "gibs")) attrs_walk(*gibs, [&](std::string_view name, std::string_view value) { auto flag = std::ranges::find(GIB_FLAG_NAMES, name); bool isFlagSet = flag != GIB_FLAG_NAMES.end() && value == "1"; if (name == "amount") entity.gibsAmount = text_int(value); else if (isFlagSet) entity.gibFlags |= 1u << (flag - GIB_FLAG_NAMES.begin()); }); if (auto bestiary = child_find(node, "bestiary")) { entity.isBestiary = true; attrs_walk(*bestiary, [&](std::string_view name, std::string_view value) { bestiary_attr_read(entity, name, value, load); }); } if (entity.bestiaryParentType != 0) entity.isBestiary = false; children_walk(node, "preload", CHILDREN_TAGGED, [&](DataNode child) { EntityConfig_Preload preload; preload.type = text_int(node_attr(child, "id")); preload.variant = text_int(node_attr(child, "variant")); preload.subtype = text_int(node_attr(child, "subtype")); preload.path = node_attr(child, "path"); entity.preloads.push_back(preload); }); children_walk(node, "preload-snd", CHILDREN_TAGGED, [&](DataNode child) { entity.preloadSounds.push_back(text_int(node_attr(child, "id"))); }); // A devolve's weight is read and dropped by the original, so every devolve weighs 1. children_walk(node, "devolve", CHILDREN_TAGGED, [&](DataNode child) { std::vector id = text_split(node_attr(child, "id"), '.'); Devolve devolve; if (id.size() == 3) devolve = {1, text_int(id[0]), (uint16_t)text_int(id[2]), (uint16_t)text_int(id[1])}; entity.devolve.push_back(devolve); }); } // The mod sprite in slot that has an animation named after the character, or null. static ANM2* mod_sprite_find(ModEntry& mod, ModContentSprite slot, std::string_view name) { ANM2& sprite = mod.contentSprites[slot]; return sprite.isLoaded && sprite.GetAnimationData(name) ? &sprite : nullptr; } // A modded character's menu sprites from its mod, a tainted one's own first, and whether its menu draws a background. static void player_sprites_load(EntityConfig_Player& player, ModEntry& mod) { std::string name = player.GetDisplayName(); ANM2* background = nullptr; if (!player.bSkinParentName.empty()) for (int i = 0; i < PLAYER_SPRITE_COUNT; i++) player.moddedSprites[i] = mod_sprite_find(mod, PLAYER_SPRITE_SLOTS_TAINTED[i], name); for (int i = 0; i < PLAYER_SPRITE_COUNT; i++) if (!player.moddedSprites[i]) player.moddedSprites[i] = mod_sprite_find(mod, PLAYER_SPRITE_SLOTS[i], name); background = player.moddedSprites[PLAYER_SPRITE_MENU_BACKGROUND]; if (!background) return; background->SetFrame(name, 0); LayerState* layer = background->GetLayer("Background"); if (!layer) return; const AnimationFrame* frame = background->animState.GetLayerFrame(layer->layerData ? layer->layerData->id : -1); player.isRenderCustomBackground = frame && frame->isVisible; } // One attribute of a . static void player_attr_read(EntityConfig_Player& player, std::string_view name, std::string_view value, PlayerLoad& load) { if (name == "id") player.id = text_int(value); else if (name == "name") player.name = value; else if (name == "skin") player.skinPath = load.skinRoot + std::string(value); else if (name == "nameimage") player.nameImagePath = load.nameImageRoot + std::string(value); else if (name == "portrait") player.portraitPath = load.portraitRoot + std::string(value); else if (name == "extraportrait") player.extraPortraitPath = load.portraitRoot + std::string(value); else if (name == "costume") player.costumeID = text_int(value); else if (name == "hp") player.heart = text_int(value); else if (name == "armor") player.armor = text_int(value); else if (name == "black") player.blackHeart = text_int(value); else if (name == "coins") player.coins = text_int(value); else if (name == "bombs") player.bombs = text_int(value); else if (name == "keys") player.keys = text_int(value); else if (name == "card") player.card = text_int(value); else if (name == "pill") player.pill = text_int(value); else if (name == "items") for (std::string& item : text_split(value, ',')) player.collectibles.push_back(text_int(item)); else if (name == "trinket") player.trinket = text_int(value); else if (name == "skinColor") player.skinColor = text_int(value); else if (name == "canShoot") player.isCanShoot = is_text_true(value); else if (name == "costumeSuffix") player.costumeSuffixName = value; else if (name == "achievement") player.achievement = text_int(value); else if (name == "broken") player.brokenHeart = text_int(value); else if (name == "pocketActive") player.pocketActiveID = text_int(value); else if (name == "birthright") player.birthrightDescription = value; else if (name == "bSkinParent") player.bSkinParentName = value; else if (name == "hidden") player.isHidden = is_text_true(value); } // 00694d20 The entity's name, translated from the "Entities" strings when it is a #key they hold. std::string EntityConfig_Entity::GetName(int language) { return name_translate(name, "Entities", language); } // 00694de0 The character's name, translated from the "Players" strings when it is a #key they hold. std::string EntityConfig_Player::GetDisplayName() { return name_translate(name, "Players", NAME_LANGUAGE_CURRENT); } // 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) { while (true) { auto found = entities.find(entity_key(id, variant, subtype)); if (found != entities.end()) return &found->second; if (subtype != 0) subtype = 0; else if (variant != 0) variant = 0; else return nullptr; } } // 00695030 The config whose bestiary page an entity shows: its own, or its bestiary parent's, followed to the end. EntityConfig_Entity* EntityConfig::GetBestiaryConfig(int id, int variant) { EntityConfig_Entity* entity = GetEntity(id, variant, 0); while (entity && entity->bestiaryParentType != 0) entity = GetEntity(entity->bestiaryParentType, entity->bestiaryParentVariant, 0); return entity; } // 0069bd10 A character's config, or null for an id players.xml did not fill. EntityConfig_Player* EntityConfig::GetPlayer(int id) { return id >= 0 && id < (int)players.size() ? &players[id] : nullptr; } // 00694f00 Copies of every config of an entity type, by variant and subtype. std::vector EntityConfig::entities_get(int type) { std::vector found; for (EntityConfig_Entity& entity : std::views::values(entities)) if (entity.id == type) found.push_back(entity); return found; } // 006950c0 Reads entities2.xml, or a mod's, filing each entity under its key and rerollable ones in the reroll pools. // A mod's entity that clashes with one already filed moves to the next free variant or type. False without the file. // The reroll pools are sorted stably by base health. The original's std::sort leaves equal entries in its own order. bool EntityConfig::LoadEntities(std::string_view path, ModEntry* mod) { Data data; EntityLoad load; data_load(data, path); if (!data.isLoaded) return false; std::optional root = root_find(data, "entities", path); if (!root) return false; std::string_view version = node_attr(*root, "version"); if (version != ENTITIES_VERSION) log_printf(LOG_ASSERT, "Invalid version %.*s for %.*s\n", (int)version.size(), version.data(), (int)path.size(), path.data()); load.anm2Root = node_attr(*root, "anm2root"); std::optional deathAnm2 = attr_find(*root, "deathanm2"); if (mod && deathAnm2) { mod->load_content_anm2(MOD_SPRITE_DEATH_ENEMIES, *deathAnm2); load.isPortraitModded = mod->contentSprites[MOD_SPRITE_DEATH_ENEMIES].isLoaded; } children_walk(*root, "entity", CHILDREN_FROM_TAGGED, [&](DataNode node) { EntityConfig_Entity entity; attrs_walk(node, [&](std::string_view name, std::string_view value) { entity_attr_read(entity, name, value, load); }); entity_children_read(entity, node, load); entity.modEntry = mod; while (mod && entities.contains(entity_key(entity.id, entity.variant, entity.subtype))) { int id = entity.id; if (id == ENTITY_EFFECT || id == ENTITY_TEXT || id < ENTITY_FIRST_NPC) entity.variant++; else entity.id += id + 1 == ENTITY_TEXT || id + 1 == ENTITY_EFFECT ? 2 : 1; } EntityConfig_Entity& filed = entities[entity_key(entity.id, entity.variant, entity.subtype)]; filed = std::move(entity); if (filed.isBoss || !filed.isReroll) return; bool isGround = filed.gridCollisionClassString == "ground" || (filed.gridCollisionClassString.empty() && filed.gridCollisionPoints > 0); (isGround ? groundRerolls : otherRerolls) .push_back({filed.baseHP, filed.stageHP, filed.id, filed.subtype, filed.variant}); }); std::ranges::stable_sort(otherRerolls, {}, &RerollEntry::baseHP); std::ranges::stable_sort(groundRerolls, {}, &RerollEntry::baseHP); return true; } // 006998d0 Reads players.xml into the 41 vanilla characters, or appends a mod's characters with their menu sprites, // then Eden's hairstyles. False without the file. // The original writes past the characters for a vanilla id of 41 or more. This grows them to fit. bool EntityConfig::LoadPlayers(std::string_view path, ModEntry* mod) { Data data; PlayerLoad load; if (!mod) players.assign(PLAYER_TYPE_COUNT, {}); data_load(data, path); if (!data.isLoaded) return false; std::optional root = root_find(data, "players", path); if (!root) return false; load.skinRoot = node_attr(*root, "root"); load.portraitRoot = node_attr(*root, "portraitroot"); load.nameImageRoot = node_attr(*root, "nameimageroot"); children_walk(*root, "player", CHILDREN_FROM_TAGGED, [&](DataNode node) { EntityConfig_Player player; attrs_walk(node, [&](std::string_view name, std::string_view value) { player_attr_read(player, name, value, load); }); player.modEntry = mod; if (mod) { player.id = player.moddedTaintedPlayerID = (int)players.size(); player_sprites_load(player, *mod); players.push_back(player); } else if (player.id >= 0) { player.moddedTaintedPlayerID = player.id; if (player.id >= (int)players.size()) players.resize(player.id + 1); players[player.id] = player; } // A without gfx crashes the original. This reads it as empty. if (player.id != PLAYER_EDEN) return; edenHair.clear(); children_walk(node, "hair", CHILDREN_FROM_TAGGED, [&](DataNode hair) { edenHair.push_back(load.skinRoot + std::string(node_attr(hair, "gfx"))); }); }); return true; } // 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. This returns. void EntityConfig::LoadBabies(std::string_view path) { Data data; EntityConfig_Baby filler; std::string root; babies.clear(); data_load(data, path); if (!data.isLoaded) return; std::optional rootNode = root_find(data, "babies", path); if (!rootNode) return; filler.achievementID = 0; root = node_attr(*rootNode, "root"); children_walk(*rootNode, "baby", CHILDREN_FROM_TAGGED, [&](DataNode node) { EntityConfig_Baby baby; attrs_walk(node, [&](std::string_view name, std::string_view value) { if (name == "id") baby.id = text_int(value); else if (name == "name") baby.name = value; else if (name == "skin") baby.gfx = root + std::string(value); else if (name == "achievement") baby.achievementID = text_int(value); }); if (baby.id < 0) return; if ((int)babies.size() < baby.id) babies.resize(baby.id, filler); babies.push_back(baby); }); } // 00698e80 Replaces the champion looks of each boss bosscolors.xml names. False without the file. // The original reads a boss without id or variant from memory it never wrote. This carries them over from the // boss before, from 0. bool EntityConfig::boss_colors_load(std::string_view path) { Data data; std::string anm2Root; std::string portraitRoot; int type = 0; int variant = 0; int version = 0; data_load(data, path); if (!data.isLoaded) return false; std::optional root = root_find(data, "bosscolors", path); if (!root) return false; std::string_view versionText = node_attr(*root, "version"); version = text_int(versionText); if (version < 0 || version > BOSS_COLORS_VERSION_MAX) log_printf(LOG_ASSERT, "Invalid version %.*s for %.*s\n", (int)versionText.size(), versionText.data(), (int)path.size(), path.data()); if (version > 0) { anm2Root = node_attr(*root, "anm2root"); portraitRoot = node_attr(*root, "portraitroot"); } children_walk(*root, "boss", CHILDREN_FROM_TAGGED, [&](DataNode bossNode) { 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_printf(LOG_INFO, "Cannot patch boss colors for Entity %d.%d\n", type, variant); return; } entity->bossColors.clear(); children_walk(bossNode, "color", CHILDREN_FROM_TAGGED, [&](DataNode colorNode) { EntityConfig_BossColor bossColor; 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") bossColor.suffix = value; else if (name == "anm2path" && version > 0) bossColor.anm2Path = anm2Root + std::string(value); else if (name == "portrait" && version > 0) bossColor.portraitPath = portraitRoot + std::string(value); else if (name == "scale") bossColor.scale = text_float(value); else if (name == "hp") bossColor.hpMultiplier = text_float(value); }); entity->bossColors.push_back(bossColor); }); }); return true; } // 0069c420 Reads bossportraits.xml into the 104 boss slots: each boss's name, portrait and per-stage portraits. // False without the file. A boss without id takes the one before, and an alt without stage the one before, from 0. // The original reads those from memory it never wrote, and writes the alts of an id out of range past the slots. // This skips them. bool EntityConfig::boss_portraits_load(std::string_view path) { Data data; std::string root; int altStage = 0; int bossId = 0; data_load(data, path); if (!data.isLoaded) return false; std::optional rootNode = root_find(data, "bosses", path); if (!rootNode) return false; root = node_attr(*rootNode, "root"); bosses.resize(BOSS_PORTRAIT_COUNT); children_walk(*rootNode, {}, CHILDREN_ALL, [&](DataNode node) { EntityConfig_Boss boss; boss.achievement = -1; attrs_walk(node, [&](std::string_view name, std::string_view value) { if (name == "id") bossId = text_int(value); else if (name == "name") boss.name = value; else if (name == "nameimage") boss.namePath = root + std::string(value); else if (name == "portrait") boss.portraitPath = root + std::string(value); else if (name == "pivotX") boss.pivot.x = BOSS_PORTRAIT_ORIGIN_X - text_float(value); else if (name == "pivotY") boss.pivot.y = BOSS_PORTRAIT_ORIGIN_Y - text_float(value); else if (name == "achievement") boss.achievement = text_int(value); }); if (bossId < 1 || bossId >= BOSS_PORTRAIT_COUNT) return; boss.bossID = bossId; bosses[bossId] = boss; children_walk(node, "alt", CHILDREN_TAGGED, [&](DataNode altNode) { EntityConfig_BossAlt alt; attrs_walk(altNode, [&](std::string_view name, std::string_view value) { if (name == "stage") altStage = text_int(value); else if (name == "portrait") alt.portraitPath = root + std::string(value); }); alt.stageId = altStage; bosses[bossId].alts.push_back(alt); }); }); return true; } // 0069d290 Points each visible modded character at its tainted twin: the visible modded one whose bSkinParent is the // first's display name. When names repeat, the first character of a name is the one linked. void EntityConfig::tainted_players_link() { std::map regulars; for (int i = PLAYER_TYPE_COUNT; i < (int)players.size(); i++) if (!players[i].isHidden && players[i].bSkinParentName.empty()) regulars.emplace(players[i].GetDisplayName(), i); for (int i = PLAYER_TYPE_COUNT; i < (int)players.size(); i++) { if (players[i].isHidden || players[i].bSkinParentName.empty()) continue; auto found = regulars.find(players[i].bSkinParentName); if (found != regulars.end()) players[found->second].moddedTaintedPlayerID = i; } } // 0069ba90 Loads an entity's sprite, sounds and images into their caches once, with every entity it preloads. // The original reads a null entity, as from a preload of an unknown entity, and crashes. This returns. void EntityConfig::PreloadResources(EntityConfig_Entity* entity) { if (!entity || entity->isPreloaded) return; // The db names the sound manager twice: SFXManager carries its methods and SoundEffects its fields. AnmCache::Preload(entity->anm2Path); for (int sound : entity->preloadSounds) if (sound != 0) g_manager->sfxManager.Preload(sound); for (EntityConfig_Preload& preload : entity->preloads) { if (!preload.path.empty()) TextureCache::Preload(preload.path); if (preload.type != 0) PreloadResources(GetEntity(preload.type, preload.variant, preload.subtype)); } entity->isPreloaded = true; } // 0069bbf0 Forgets every entity, character, baby, hairstyle and reroll. Boss portraits stay. void EntityConfig::clear() { entities.clear(); players = {}; babies.clear(); edenHair.clear(); groundRerolls.clear(); otherRerolls.clear(); }