Curation round 3: Lua engine, Manager, sound, menus, cutscenes, rooms, item pools, saves; boots past LuaEngine::Init
Seven agents took over LuaEngine (the mod API registration deferred), the rest of Manager (LoadConfigs, fonts, render surfaces, Update/Render), MusicManager/SFXManager, MenuManager with the title/save/game menus, Cutscene/NightmareScene/ Backdrop, RoomConfig (src/rooms ported and retired) with ItemPool, and PersistentGameData (the original binary save format) with InfoDisplay. An integration pass moved call sites to the new APIs, declared the taken-over free functions, fixed two data.cpp crashes (an empty children array, null attribute strings), and made the generator keep a header's own name where a prototype names another address. Clean build (0 warnings with -Wall -Wextra). build/isaac runs the game's Lua scripts (without the mod API yet) and stops at reload_resource_paths. 901 functions taken over, boot path 204/615. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a7061306fa
commit
ddf913f304
137 files changed
+12684
-50687
No files matched your search
@@ -0,0 +1,362 @@
|
||||
#include "info_display.h"
|
||||
#include "persistent_game_data.h"
|
||||
#include "manager.h"
|
||||
#include "data.h"
|
||||
#include <algorithm>
|
||||
#include <cstdlib>
|
||||
#include <optional>
|
||||
|
||||
constexpr std::string_view DOCUMENT_TAG = "#document";
|
||||
constexpr uint32_t TRINKET_GOLDEN_FLAG = 0x8000;
|
||||
constexpr uint32_t PILL_HORSE_FLAG = 0x800;
|
||||
constexpr int DIFFICULTY_GREED = 2;
|
||||
constexpr int DIFFICULTY_GREEDIER = 3;
|
||||
constexpr int RED_HEARTS_ALL = 24;
|
||||
|
||||
// The ids load_xml lists from the item config before reading info_display.xml.
|
||||
constexpr int DEFAULT_COLLECTIBLE_COUNT = 733;
|
||||
constexpr int DEFAULT_TRINKET_COUNT = 190;
|
||||
constexpr int DEFAULT_CARD_COUNT = 98;
|
||||
constexpr int DEFAULT_PILL_COUNT = 50;
|
||||
|
||||
// Necromancer's items, which count toward it without a tag.
|
||||
constexpr int PLAYER_FORM_NECROMANCER = 15;
|
||||
constexpr int COLLECTIBLE_NECRONOMICON = 35;
|
||||
constexpr int COLLECTIBLE_MISSING_PAGE_2 = 262;
|
||||
constexpr int TRINKET_MISSING_PAGE = 48;
|
||||
|
||||
// A group of info_display.xml: its element names and the kind of entry it fills.
|
||||
struct InfoDisplayGroup
|
||||
{
|
||||
std::string_view groupTag;
|
||||
std::string_view itemTag;
|
||||
InfoDisplayType type;
|
||||
};
|
||||
|
||||
constexpr InfoDisplayGroup INFO_DISPLAY_GROUPS[] = {{"collectibles", "collectible", INFO_DISPLAY_COLLECTIBLE},
|
||||
{"trinkets", "trinket", INFO_DISPLAY_TRINKET},
|
||||
{"pills", "pill", INFO_DISPLAY_PILL},
|
||||
{"cards", "card", INFO_DISPLAY_CARD}};
|
||||
|
||||
// Whether a list holds a value.
|
||||
static bool is_listed(std::vector<int>& list, int value)
|
||||
{
|
||||
return std::ranges::find(list, value) != list.end();
|
||||
}
|
||||
|
||||
// An attribute read as atoi reads it, 0 when it is missing.
|
||||
static int attr_int(DataNode node, std::string_view name)
|
||||
{
|
||||
return std::atoi(std::string(node_attr(node, name)).c_str());
|
||||
}
|
||||
|
||||
// A comma-separated attribute read as numbers, splitting as std::getline does (no token after a final comma).
|
||||
static std::vector<int> attr_list(DataNode node, std::string_view name)
|
||||
{
|
||||
std::string text(node_attr(node, name));
|
||||
std::vector<int> values;
|
||||
|
||||
for (size_t start = 0; start < text.size();)
|
||||
{
|
||||
size_t end = std::min(text.find(',', start), text.size());
|
||||
values.push_back(std::atoi(text.substr(start, end - start).c_str()));
|
||||
start = end + 1;
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
// A top-level element of a document by tag, as rapidxml's first_node finds it on the document.
|
||||
static std::optional<DataNode> group_find(DataNode root, std::string_view tag)
|
||||
{
|
||||
if (node_tag(root) != DOCUMENT_TAG) return node_tag(root) == tag ? std::optional(root) : std::nullopt;
|
||||
for (DataNode child : node_children(root))
|
||||
if (node_tag(child) == tag) return child;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
// A line that always applies.
|
||||
static InfoDisplayText line_make(std::string text)
|
||||
{
|
||||
InfoDisplayText line;
|
||||
line.text = std::move(text);
|
||||
return line;
|
||||
}
|
||||
|
||||
// An entry with no lines yet.
|
||||
static InfoDisplayEntry entry_make(InfoDisplayType type, int id, std::string name)
|
||||
{
|
||||
InfoDisplayEntry entry;
|
||||
entry.name = std::move(name);
|
||||
entry.type = type;
|
||||
entry.id = id;
|
||||
return entry;
|
||||
}
|
||||
|
||||
// Reads an <info> element into a line.
|
||||
static InfoDisplayText line_read(DataNode node)
|
||||
{
|
||||
InfoDisplayText line;
|
||||
|
||||
line.text = node_attr(node, "text");
|
||||
line.players = attr_list(node, "player");
|
||||
line.notPlayers = attr_list(node, "notplayer");
|
||||
line.collectibles = attr_list(node, "collectible");
|
||||
line.notCollectibles = attr_list(node, "notcollectible");
|
||||
line.trinkets = attr_list(node, "trinket");
|
||||
line.notTrinkets = attr_list(node, "nottrinket");
|
||||
line.achievement = attr_int(node, "achievement");
|
||||
line.tag = (InfoDisplayTag)attr_int(node, "tag");
|
||||
return line;
|
||||
}
|
||||
|
||||
// Names or describes a new entry from the item config, false when the config has no such item.
|
||||
static bool entry_describe(InfoDisplayEntry& entry)
|
||||
{
|
||||
ItemConfig& config = g_manager->itemConfig;
|
||||
|
||||
switch (entry.type)
|
||||
{
|
||||
case INFO_DISPLAY_COLLECTIBLE:
|
||||
case INFO_DISPLAY_TRINKET:
|
||||
{
|
||||
ItemConfig_Item* item = entry.type == INFO_DISPLAY_TRINKET ? config.GetTrinket(entry.id)
|
||||
: config.GetCollectible(entry.id);
|
||||
if (!item) return false;
|
||||
InfoDisplay::describe_pickup_stats(*item, entry);
|
||||
return true;
|
||||
}
|
||||
case INFO_DISPLAY_PILL:
|
||||
case INFO_DISPLAY_CARD:
|
||||
{
|
||||
PocketItemConfig* pocketItem = nullptr;
|
||||
if (entry.type == INFO_DISPLAY_PILL)
|
||||
pocketItem = config.GetPillEffect(entry.id);
|
||||
else
|
||||
pocketItem = config.GetCard(entry.id);
|
||||
if (!pocketItem) return false;
|
||||
entry.name = pocketItem->GetName();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// (00850480, 00851b20, 00853180, 00854940) Reads a group of info_display.xml: a fresh entry per element, dropped
|
||||
// when the item config lacks its item, with its <info> lines after the item config's.
|
||||
// A mod's collectible and trinket ids go through its collectible id map, the trinkets' included, as the game does.
|
||||
// Like rapidxml's sibling walk, every element after the first of a tag is read whatever its own tag.
|
||||
static void group_load(DataNode group, InfoDisplayGroup kind, std::map<int, InfoDisplayEntry>& entries, ModEntry* mod)
|
||||
{
|
||||
bool isItemStarted = false;
|
||||
|
||||
for (DataNode node : node_children(group))
|
||||
{
|
||||
isItemStarted |= node_tag(node) == kind.itemTag;
|
||||
if (!isItemStarted) continue;
|
||||
|
||||
int id = attr_int(node, "id");
|
||||
if (mod && (kind.type == INFO_DISPLAY_COLLECTIBLE || kind.type == INFO_DISPLAY_TRINKET))
|
||||
{
|
||||
auto found = mod->collectibleIdMap.find(id);
|
||||
if (found == mod->collectibleIdMap.end()) continue;
|
||||
id = found->second;
|
||||
}
|
||||
if (kind.type == INFO_DISPLAY_TRINKET) id &= ~TRINKET_GOLDEN_FLAG;
|
||||
if (kind.type == INFO_DISPLAY_PILL) id &= ~PILL_HORSE_FLAG;
|
||||
|
||||
InfoDisplayEntry& entry = entries[id] = entry_make(kind.type, id, "");
|
||||
if (!entry_describe(entry))
|
||||
{
|
||||
entries.erase(id);
|
||||
continue;
|
||||
}
|
||||
|
||||
bool isInfoStarted = false;
|
||||
for (DataNode info : node_children(node))
|
||||
{
|
||||
isInfoStarted |= node_tag(info) == "info";
|
||||
if (isInfoStarted) entry.lines.push_back(line_read(info));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 0084eba0 Loads info_display.xml. The game's own load first lists every vanilla item, trinket, card and pill effect
|
||||
// from the item config, then the file adds to and replaces those.
|
||||
void InfoDisplay::load_xml(std::string_view path, ModEntry* mod)
|
||||
{
|
||||
ItemConfig& config = g_manager->itemConfig;
|
||||
Data data;
|
||||
|
||||
if (!mod)
|
||||
{
|
||||
collectibles.clear();
|
||||
trinkets.clear();
|
||||
cards.clear();
|
||||
pills.clear();
|
||||
for (int id = 0; id < DEFAULT_COLLECTIBLE_COUNT; id++)
|
||||
if (ItemConfig_Item* item = config.GetCollectible(id)) add_item_entry(*item, DESCRIPTION_NONE);
|
||||
for (int id = 0; id < DEFAULT_TRINKET_COUNT; id++)
|
||||
if (ItemConfig_Item* item = config.GetTrinket(id)) add_item_entry(*item, DESCRIPTION_NONE);
|
||||
for (int id = 0; id < DEFAULT_CARD_COUNT; id++)
|
||||
if (ItemConfig_Card* card = config.GetCard(id)) add_card_entry(*card, DESCRIPTION_NONE);
|
||||
for (int id = 0; id < DEFAULT_PILL_COUNT; id++)
|
||||
if (ItemConfig_Pill* pill = config.GetPillEffect(id)) add_pill_entry(*pill, DESCRIPTION_NONE);
|
||||
}
|
||||
|
||||
data_load(data, path);
|
||||
if (!data.isLoaded) return;
|
||||
for (InfoDisplayGroup kind : INFO_DISPLAY_GROUPS)
|
||||
{
|
||||
std::map<int, InfoDisplayEntry>& entries = kind.type == INFO_DISPLAY_COLLECTIBLE ? collectibles
|
||||
: kind.type == INFO_DISPLAY_TRINKET ? trinkets
|
||||
: kind.type == INFO_DISPLAY_PILL ? pills
|
||||
: cards;
|
||||
if (std::optional<DataNode> group = group_find(data.root, kind.groupTag))
|
||||
group_load(*group, kind, entries, mod);
|
||||
}
|
||||
}
|
||||
|
||||
// 0084f0a0 Lists a collectible or trinket with its stat lines, and its own description if asked.
|
||||
void InfoDisplay::add_item_entry(ItemConfig_Item& item, DescriptionMode mode)
|
||||
{
|
||||
bool isTrinket = item.type == ITEM_TRINKET;
|
||||
InfoDisplayEntry entry = entry_make(isTrinket ? INFO_DISPLAY_TRINKET : INFO_DISPLAY_COLLECTIBLE, item.id, "");
|
||||
|
||||
describe_pickup_stats(item, entry);
|
||||
if (mode == DESCRIPTION_ADD && !item.desc.empty()) entry.lines.push_back(line_make(item.desc));
|
||||
(isTrinket ? trinkets : collectibles)[item.id] = std::move(entry);
|
||||
}
|
||||
|
||||
// 0084f380 Lists a card under its raw name, with its description if asked. It is filed as a collectible.
|
||||
void InfoDisplay::add_card_entry(PocketItemConfig& card, DescriptionMode mode)
|
||||
{
|
||||
InfoDisplayEntry entry = entry_make(INFO_DISPLAY_COLLECTIBLE, card.id, card.name);
|
||||
|
||||
if (mode == DESCRIPTION_ADD && !card.desc.empty()) entry.lines.push_back(line_make(card.desc));
|
||||
cards[card.id] = std::move(entry);
|
||||
}
|
||||
|
||||
// 0084f4e0 Lists a pill effect under its raw name, with its description if asked.
|
||||
void InfoDisplay::add_pill_entry(PocketItemConfig& pill, DescriptionMode mode)
|
||||
{
|
||||
InfoDisplayEntry entry = entry_make(INFO_DISPLAY_PILL, pill.id, pill.name);
|
||||
|
||||
if (mode == DESCRIPTION_ADD && !pill.desc.empty()) entry.lines.push_back(line_make(pill.desc));
|
||||
pills[pill.id] = std::move(entry);
|
||||
}
|
||||
|
||||
// An entry of a map, or the empty default.
|
||||
static InfoDisplayEntry& entry_get(std::map<int, InfoDisplayEntry>& entries, int id, InfoDisplayEntry& fallback)
|
||||
{
|
||||
auto found = entries.find(id);
|
||||
return found == entries.end() ? fallback : found->second;
|
||||
}
|
||||
|
||||
// 0084f640 A collectible's entry.
|
||||
InfoDisplayEntry& InfoDisplay::get_collectible(int id)
|
||||
{
|
||||
return entry_get(collectibles, id, defaultEntry);
|
||||
}
|
||||
|
||||
// 0084f680 A trinket's entry, golden or not.
|
||||
InfoDisplayEntry& InfoDisplay::get_trinket(uint32_t trinketType)
|
||||
{
|
||||
return entry_get(trinkets, (int)(trinketType & ~TRINKET_GOLDEN_FLAG), defaultEntry);
|
||||
}
|
||||
|
||||
// 0084f6e0 A pill effect's entry, horse pill or not.
|
||||
InfoDisplayEntry& InfoDisplay::get_pill(uint32_t pillEffect)
|
||||
{
|
||||
return entry_get(pills, (int)(pillEffect & ~PILL_HORSE_FLAG), defaultEntry);
|
||||
}
|
||||
|
||||
// 0084f740 A card's entry.
|
||||
InfoDisplayEntry& InfoDisplay::get_card(int id)
|
||||
{
|
||||
return entry_get(cards, id, defaultEntry);
|
||||
}
|
||||
|
||||
// 0084f780 Names an entry after its item and replaces its lines with what the item gives on pickup: health,
|
||||
// hearts, bombs, keys and coins.
|
||||
void InfoDisplay::describe_pickup_stats(ItemConfig_Item& item, InfoDisplayEntry& entry)
|
||||
{
|
||||
int maxHearts = item.addMaxHearts >> 1;
|
||||
auto line_add = [&](int count, std::string_view noun, bool isPlural)
|
||||
{ entry.lines.push_back(line_make("+" + std::to_string(count) + std::string(noun) + (isPlural ? "s" : ""))); };
|
||||
|
||||
entry.lines.clear();
|
||||
entry.name = item.GetLocalizedName();
|
||||
if (maxHearts > 0)
|
||||
line_add(maxHearts, item.addHearts < item.addMaxHearts ? " empty red health" : " health", false);
|
||||
|
||||
if (item.addHearts >= RED_HEARTS_ALL)
|
||||
entry.lines.push_back(line_make("Heals all red hearts"));
|
||||
else if (int hearts = (item.addHearts >> 1) - maxHearts; item.addHearts > 0 && hearts >= 1)
|
||||
entry.lines.push_back(line_make("Heals " + std::to_string(hearts) + " red heart" + (hearts != 1 ? "s" : "")));
|
||||
|
||||
if (item.addSoulHearts > 0) line_add(item.addSoulHearts / 2, " soul heart", item.addSoulHearts != 2);
|
||||
if (item.addBlackHearts > 0) line_add(item.addBlackHearts / 2, " black heart", item.addBlackHearts != 2);
|
||||
if (item.addBombs > 0) line_add(item.addBombs, " bomb", item.addBombs > 1);
|
||||
if (item.addKeys > 0) line_add(item.addKeys, " key", item.addKeys > 1);
|
||||
if (item.addCoins > 0) line_add(item.addCoins, " coin", item.addCoins > 1);
|
||||
}
|
||||
|
||||
// 0084e5b0 Whether a line applies: to this player's character, with the collectibles and trinkets it names held or
|
||||
// not, its achievement unlocked, and for a tagged line the pickup's variant (subtype's golden or horse bit, or greed
|
||||
// mode for cards). Every line of an entry with id 0 applies.
|
||||
bool InfoDisplayEntry::is_line_visible(size_t lineIndex, Entity_Player& player, uint32_t subtype)
|
||||
{
|
||||
if (lineIndex >= lines.size()) return false;
|
||||
if (id == 0) return true;
|
||||
|
||||
InfoDisplayText& line = lines[lineIndex];
|
||||
auto isOwned = [&](int collectible) { return player.HasCollectible(collectible, 0) != 0; };
|
||||
auto isHeld = [&](int trinket) { return player.HasTrinket((uint32_t)trinket, 0) != 0; };
|
||||
if (!line.players.empty() && !is_listed(line.players, player._playerType)) return false;
|
||||
if (is_listed(line.notPlayers, player._playerType)) return false;
|
||||
if (!std::ranges::all_of(line.collectibles, isOwned) || std::ranges::any_of(line.notCollectibles, isOwned))
|
||||
return false;
|
||||
if (!std::ranges::all_of(line.trinkets, isHeld) || std::ranges::any_of(line.notTrinkets, isHeld)) return false;
|
||||
if (!g_manager->persistentGameData.Unlocked(line.achievement)) return false;
|
||||
if (line.tag == INFO_DISPLAY_TAG_ANY) return true;
|
||||
|
||||
bool isSpecial = false;
|
||||
switch (type)
|
||||
{
|
||||
case INFO_DISPLAY_TRINKET: isSpecial = subtype & TRINKET_GOLDEN_FLAG; break;
|
||||
case INFO_DISPLAY_PILL: isSpecial = subtype & PILL_HORSE_FLAG; break;
|
||||
case INFO_DISPLAY_CARD:
|
||||
// The game reads the difficulty without checking for a game. Here no game means no greed mode.
|
||||
if (line.tag != INFO_DISPLAY_TAG_SPECIAL) return true;
|
||||
return g_game && (g_game->_difficulty == DIFFICULTY_GREED || g_game->_difficulty == DIFFICULTY_GREEDIER);
|
||||
default: return true;
|
||||
}
|
||||
if (line.tag == INFO_DISPLAY_TAG_SPECIAL) return isSpecial;
|
||||
return line.tag == INFO_DISPLAY_TAG_PLAIN ? !isSpecial : true;
|
||||
}
|
||||
|
||||
// 0084e820 How many lines the panel shows: one per transformation the item counts toward, then the visible lines.
|
||||
// An entry with id 0 shows all its lines.
|
||||
int InfoDisplayEntry::count_lines(Entity_Player& player, uint32_t subtype)
|
||||
{
|
||||
if (id == 0) return (int)lines.size();
|
||||
|
||||
int count = 0;
|
||||
for (std::unique_ptr<ItemConfig_PlayerForm>& form : g_manager->itemConfig.playerForms)
|
||||
{
|
||||
if (!form) continue;
|
||||
if (form->tags == 0)
|
||||
{
|
||||
bool isNecromancerCollectible = id == COLLECTIBLE_NECRONOMICON || id == COLLECTIBLE_MISSING_PAGE_2;
|
||||
bool isNecromancerItem = (type == INFO_DISPLAY_COLLECTIBLE && isNecromancerCollectible) ||
|
||||
(type == INFO_DISPLAY_TRINKET && id == TRINKET_MISSING_PAGE);
|
||||
count += form->id == PLAYER_FORM_NECROMANCER && isNecromancerItem;
|
||||
continue;
|
||||
}
|
||||
count += (type == INFO_DISPLAY_COLLECTIBLE && ItemConfig::is_collectible_tagged(id, form->tags)) ||
|
||||
(type == INFO_DISPLAY_TRINKET && ItemConfig::is_trinket_tagged(id, form->tags));
|
||||
}
|
||||
|
||||
for (size_t index = 0; index < lines.size(); index++) count += is_line_visible(index, player, subtype);
|
||||
return count;
|
||||
}
|
||||
Reference in new issue
Block a user