6#include "absl/strings/str_format.h"
22 std::vector<DungeonMap> dungeon_maps;
23 std::vector<std::array<uint8_t, kNumRooms>> current_floor_rooms_d;
24 std::vector<std::array<uint8_t, kNumRooms>> current_floor_gfx_d;
27 uint8_t nbr_basement_d;
30 current_floor_rooms_d.clear();
31 current_floor_gfx_d.clear();
43 nbr_basement_d &= 0x0F;
47 nbr_floor_d = nbr_floor_d >> 4;
49 total_floors_d = nbr_basement_d + nbr_floor_d;
52 for (
int i = 0; i < total_floors_d; i++) {
53 dungeon_map_labels[d].emplace_back();
55 std::array<uint8_t, kNumRooms> rdata;
56 std::array<uint8_t, kNumRooms> gdata;
63 gdata[j] = rdata[j] == 0x0F ? 0xFF : rom.
data()[pc_ptr_gfx++];
66 dungeon_map_labels[d][i][j] = label;
69 current_floor_gfx_d.push_back(gdata);
70 current_floor_rooms_d.push_back(rdata);
73 dungeon_maps.emplace_back(boss_room_d, nbr_floor_d, nbr_basement_d,
74 current_floor_rooms_d, current_floor_gfx_d);
84 if (d >=
static_cast<int>(dungeon_maps.size())) {
88 auto& map = dungeon_maps[d];
89 const int total_floors = map.nbr_of_floor + map.nbr_of_basement;
91 uint16_t floors = (map.nbr_of_floor << 4) | map.nbr_of_basement;
96 const bool has_boss = map.boss_room != 0x000F && map.boss_room != 0xFFFF;
97 bool search_boss = has_boss;
105 bool restart =
false;
106 for (
int f = 0; f < total_floors; f++) {
108 if (search_boss && map.floor_rooms[f][r] == map.boss_room) {
133 for (
int f = 0; f < total_floors; f++) {
135 if (map.floor_rooms[f][r] != 0x0F) {
154 return absl::OutOfRangeError(
"Dungeon map data exceeds reserved space");
163 return absl::NotFoundError(
164 absl::StrFormat(
"Boss room not found for dungeon %d", d));
168 return absl::OkStatus();
173 const std::vector<uint8_t>& gfx_data,
176 tile16_blockset.
map_size = {186, 186};
178 std::vector<uint8_t>(256 * 192, 0x00));
198 int sheet_offset = 212;
202 ComposeTile16(tile16_blockset, gfx_data, t1, t2, t3, t4, sheet_offset);
212 &tile16_blockset.
atlas);
214 return absl::OkStatus();
241 return absl::OkStatus();
246 std::array<gfx::Bitmap, 4>& sheets,
247 std::vector<uint8_t>& gfx_bin_data) {
249 if (bin_file.empty()) {
250 return absl::InternalError(
"No file selected");
253 std::ifstream file(bin_file, std::ios::binary);
254 if (!file.is_open()) {
255 return absl::InternalError(
"Failed to open file");
259 std::vector<uint8_t> bin_data((std::istreambuf_iterator<char>(file)),
260 std::istreambuf_iterator<char>());
262 gfx_bin_data = converted_bin;
265 std::vector<std::vector<uint8_t>> gfx_sheets;
266 for (
int i = 0; i < 4; i++) {
267 gfx_sheets.emplace_back(converted_bin.begin() + (i * 0x1000),
268 converted_bin.begin() + ((i + 1) * 0x1000));
269 sheets[i] =
gfx::Bitmap(128, 32, 8, gfx_sheets[i]);
271 sheets[i].SetPalette(
282 return absl::OkStatus();
The Rom class is used to load, save, and modify Rom data. This is a generic SNES ROM container and do...
absl::Status WriteByte(int addr, uint8_t value)
absl::StatusOr< uint16_t > ReadWord(int offset)
absl::StatusOr< uint8_t > ReadByte(int offset)
absl::Status WriteWord(int addr, uint16_t value)
void QueueTextureCommand(TextureCommandType type, Bitmap *bitmap)
Represents a bitmap image optimized for SNES ROM hacking.
void Create(int width, int height, int depth, std::span< uint8_t > data)
Create a bitmap with the given dimensions and data.
void SetPalette(const SnesPalette &palette)
Set the palette for the bitmap using SNES palette format.
SNES 16-bit tile metadata container.
static std::string ShowOpenFileDialog()
ShowOpenFileDialog opens a file dialog and returns the selected filepath. Uses global feature flag to...
#define ASSIGN_OR_RETURN(type_variable_name, expression)
uint16_t TileInfoToWord(TileInfo tile_info)
std::vector< uint8_t > SnesTo8bppSheet(std::span< uint8_t > sheet, int bpp, int num_sheets)
TileInfo WordToTileInfo(uint16_t word)
std::string HexByte(uint8_t byte, HexStringParams params)
Zelda 3 specific classes and functions.
absl::Status LoadDungeonMapTile16(gfx::Tilemap &tile16_blockset, Rom &rom, GameData *game_data, const std::vector< uint8_t > &gfx_data, bool bin_mode)
Load the dungeon map tile16 from the ROM.
constexpr int kDungeonMapDataStart
constexpr int kDungeonMapExpCheck
constexpr int kDungeonMapBossFloors
constexpr int kDungeonMapDataReservedEnd
constexpr int kDungeonMapFloors
constexpr int kDungeonMapTile16
constexpr int kDungeonMapTile16Expanded
absl::Status SaveDungeonMapTile16(gfx::Tilemap &tile16_blockset, Rom &rom)
Save the dungeon map tile16 to the ROM.
constexpr int kDungeonMapDataReservedStart
absl::Status LoadDungeonMapGfxFromBinary(Rom &rom, GameData *game_data, gfx::Tilemap &tile16_blockset, std::array< gfx::Bitmap, 4 > &sheets, std::vector< uint8_t > &gfx_bin_data)
Load the dungeon map gfx from binary.
constexpr int kDungeonMapDataLimit
constexpr int kDungeonMapBossRooms
constexpr int kDungeonMapRoomsPtr
constexpr int kNumDungeonMapTile16
constexpr int kNumDungeons
std::array< std::vector< std::array< std::string, kNumRooms > >, kNumDungeons > DungeonMapLabels
absl::StatusOr< std::vector< DungeonMap > > LoadDungeonMaps(Rom &rom, DungeonMapLabels &dungeon_map_labels)
Load the dungeon maps from the ROM.
constexpr int kDungeonMapGfxPtr
absl::Status SaveDungeonMaps(Rom &rom, std::vector< DungeonMap > &dungeon_maps)
Save the dungeon maps to the ROM.
uint32_t PcToSnes(uint32_t addr)
uint32_t SnesToPc(uint32_t addr) noexcept
#define RETURN_IF_ERROR(expr)
PaletteGroup dungeon_main
auto mutable_palette(int i)
Tilemap structure for SNES tile-based graphics management.
Pair tile_size
Size of individual tiles (8x8 or 16x16)
Pair map_size
Size of tilemap in tiles.
Bitmap atlas
Master bitmap containing all tiles.
std::vector< std::array< gfx::TileInfo, 4 > > tile_info
Tile metadata (4 tiles per 16x16)
gfx::PaletteGroupMap palette_groups