Files
isaac-port/src/rooms/rooms.hpp
T
shweetandClaude Opus 5.5 ad8f933086 Salvage Repentance+ 1.9.7.17 decompilation toolkit, notes and name database
Ghidra 12.2 project and full dump of isaac-ng.exe v1.9.7.17, query scripts, notes
indexed by entity, anm2/rooms reimplementations, and db/ (names + fields) that
build.sh re-applies. Fixes awk numeric address comparison in find.sh/decompile.sh.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-24 13:08:19 -04:00

110 lines
6.0 KiB
C++

// RoomConfig: stage table (stages.xml), lazy .stb loading + mod merge, room selection, spawn picking.
// Reverse-engineered from isaac-ng.exe v1.9.7.17; addresses refer to that build.
#pragma once
#include "stb.hpp"
#include <array>
#include <functional>
#include <set>
namespace rooms {
// ---------------------------------------------------------------------------------------------
// RNG (0x7e8fe0 SetSeed, 0x7e90f0 Next, 0x7e9020 RandomInt, 0x7e9080 RandomFloat)
// xorshift32 with one of 81 shift triplets (table @0xb1f4c8).
// ---------------------------------------------------------------------------------------------
struct RNG {
uint32_t seed = 0, s1 = 0, s2 = 0, s3 = 0;
RNG() = default;
RNG(uint32_t seed, unsigned shiftIdx) { SetSeed(seed, shiftIdx); }
void SetSeed(uint32_t seed, unsigned shiftIdx);
uint32_t Next(); // ORIGINAL: seed == 0 logs "RNG Seed is zero!" and hits int3
uint32_t RandomInt(uint32_t n) { uint32_t x = Next(); return n ? x % n : 0; }
float RandomFloat() { return ToFloat(Next()); }
static float ToFloat(uint32_t x); // (float)(double)x * 2.3283062e-10f
};
extern const uint8_t kRngShifts[81][3];
// ---------------------------------------------------------------------------------------------
// Stage table
// ---------------------------------------------------------------------------------------------
constexpr int kNumStages = 37;
struct RoomConfigStage { // 0xc4, ctor 0x828f00
int id = 0; // +0x00
std::string name; // +0x04 "#BASEMENT_NAME" ('#' -> localised via "Stages")
std::string playerSpot; // +0x1c bossgfxroot + playerspot
std::string bossSpot; // +0x34 bossgfxroot + bossspot
std::string suffix; // +0x4c
RoomConfigMode modes[2]; // +0x64 [0] normal/hard, [1] greed/greedier
int music = 0; // +0xbc
int backdrop = 0; // +0xc0
};
// Resolves a game-relative path ("rooms/01.Basement.stb") to a readable file, or "" if absent.
// The game uses ModManager::ResolveContentPath (0x8f5ad0): enabled mods' resources-dlc3/<rel>,
// resources/<rel>, then the vanilla packed files.
using PathResolver = std::function<std::string(const std::string& rel)>;
// Returns the candidate mod room files for a rel path, in mod-list order (for each enabled mod:
// <mod>/content-dlc3/<rel> if it exists, else <mod>/content/<rel>) - see Mod::GetContentPath 0x8f99c0.
using ModRoomFiles = std::function<std::vector<std::string>(const std::string& rel)>;
struct RoomQuery { // GetRandomRoom / CollectRooms parameters
int type = 1;
int shape = 13; // 13 (ROOMSHAPE_NUM) = any
uint32_t minVariant = 0, maxVariant = 0xFFFFFFFFu; // unsigned compare
int minDifficulty = 0, maxDifficulty = 0; // signed compare
uint32_t requiredDoors = 0; // room must have ALL of these (superset ok)
int subtype = -1; // -1 = any
int mode = -1; // -1 = greed difficulty ? 1 : 0
};
struct GameState { // the bits of global Game state room selection reads
int levelStage = 1; // g+0 (12 = The Void)
int difficulty = 0; // g+0x269c8 (2/3 = greed/greedier)
bool seedEffect79 = false; // seed effect 79 active -> rooms flagged 0x80 (have 4500.0) excluded
bool curseOfTheGiant = false; // curse bit 0x80 -> 50% split-room path (NOT reimplemented)
};
class RoomConfig {
public:
std::array<RoomConfigStage, kNumStages> stages;
GameState* game = nullptr;
PathResolver resolve;
ModRoomFiles modRoomFiles;
bool LoadStagesXml(const std::string& path); // 0x82b2f0
bool LoadStageBinary(int stageId, int mode); // 0x82aa40 (+ ModManager::LoadModRooms 0x8f8040)
void ResetStageWeights(int stageId, int mode); // 0x82a9c0
Room* GetRoomByStageTypeAndVariant(int stageId, int type, int variant, int mode = -1); // 0x82c720
std::vector<Room*> CollectRooms(int stageId, const RoomQuery& q); // 0x82ce40
Room* GetRandomRoom(uint32_t seed, bool reduceWeight, int stageId, const RoomQuery& q); // 0x82c7d0
// 0x82cdd0: GetRandomRoom on stageId, retried on fallbackStageId if it returned NULL.
Room* GetRandomRoomWithFallback(uint32_t seed, bool reduceWeight, int stageId, int fallbackStageId, RoomQuery q);
int ResolveMode(int mode) const;
RoomConfigMode* Mode(int stageId, int mode); // resolves mode and lazily loads
};
// GetStageID 0x82d030: (LevelStage, StageType, mode) -> stb stage id.
int GetStageID(int levelStage, int stageType, int mode, int difficulty);
// ---------------------------------------------------------------------------------------------
// Spawns (Room::Init 0x7f2800, Spawn::PickEntry 0x82d290)
// ---------------------------------------------------------------------------------------------
const Entry* PickEntry(const Spawn& s, float r);
struct PlannedSpawn {
int gridIndex; // (x+1) + (y+1)*gridWidth
float worldX, worldY; // (idx % w)*40 + 40, (idx / w)*40 + 120
const Entry* entry;
uint32_t seed; // the RNG output used for the pick; passed on as the spawn seed
bool isGrid; // type >= 1000 -> grid entity, else Game::Spawn (970 spawns nothing)
};
// The real pass of Room::Init. gridWidth is the runtime room width INCLUDING walls (cfg width + 2).
// `skip` = RoomDescriptor+0x80 set of grid indices that must not be spawned (meaning unconfirmed).
std::vector<PlannedSpawn> PlanSpawns(const Room& cfg, uint32_t spawnSeed, int gridWidth,
const std::set<int>& skip = {});
} // namespace rooms