From 451241bc002efc99f628e399a63bf1b6c29b19c8 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Sun, 28 Feb 2021 16:01:34 -0500 Subject: Added option to override palette in tileset_dumper Useful because the hallucination version of Mixolydia's house is not a separate map, it's just a special palette (which you can dump from the game while it's running in an emulator). --- tools/sprite_dumper/common.h | 2 ++ tools/sprite_dumper/tileset_dumper.cpp | 61 +++++++++++++++++++++++++++------- 2 files changed, 51 insertions(+), 12 deletions(-) (limited to 'tools') diff --git a/tools/sprite_dumper/common.h b/tools/sprite_dumper/common.h index d9fb5da..0c7eefe 100644 --- a/tools/sprite_dumper/common.h +++ b/tools/sprite_dumper/common.h @@ -154,6 +154,8 @@ public: } } + explicit Palette(std::vector colors) : colors_(colors) {} + const std::vector& Colors() const { return colors_; } private: diff --git a/tools/sprite_dumper/tileset_dumper.cpp b/tools/sprite_dumper/tileset_dumper.cpp index 4ca0785..c6816ff 100644 --- a/tools/sprite_dumper/tileset_dumper.cpp +++ b/tools/sprite_dumper/tileset_dumper.cpp @@ -121,12 +121,13 @@ public: BufferView m3, int roomNum, RoomInfo roomInfo, - RoomGfxPal roomGfxPal) + std::vector palettes, + std::vector> tilesets) : roomNum_(roomNum), width_(roomInfo.width), height_(roomInfo.height), - palettes_(roomGfxPal.GetPalettes(m3)), - tilesets_(roomGfxPal.GetTilesets(m3)), + palettes_(palettes), + tilesets_(tilesets), mapTiles_(GetMapTiles(m3, roomNum)), mapLayers_(GetMapLayers(m3, roomNum)) { @@ -149,12 +150,6 @@ public: itemised_.push_back(std::move(newLayer)); } - - // Debug info - std::cout << width_ << "," << height_ << std::endl; - std::cout << roomGfxPal.paletteId; - for (int i=0;i<12;i++) std::cout << "," << roomGfxPal.tilesetId[i]; - std::cout << std::endl; } Magick::Image renderTile(size_t metatile_id, bool tflipx, bool tflipy) const { @@ -297,20 +292,62 @@ using globaltile_id = globaltile_identifier::id_type; int main(int argc, char** argv) { if (argc < 3) { - std::cout << "Usage: ./tileset_dumper [path to rom] {map ID}" << std::endl; + std::cout << "Usage: ./tileset_dumper [path to rom] [--palette=path to override palette in ACT format] {map ID}" << std::endl; return -1; } Magick::InitializeMagick(nullptr); + int mapArgStart = 2; + + bool shouldOverridePalette = false; + std::vector overridePalettes; + if (std::string(argv[2]).substr(0, 10) == "--palette=") { + mapArgStart++; + shouldOverridePalette = true; + + std::string filename = std::string(argv[2]).substr(10); + std::ifstream palfile(filename, std::ios::binary); + if (!palfile.is_open()) { + throw std::invalid_argument("Could not find palette file: " + filename); + } + + palfile.seekg(0, palfile.end); + int length = palfile.tellg(); + palfile.seekg(0, palfile.beg); + std::vector paletteData(length, 0); + palfile.read(paletteData.data(), length); + + BufferView palbuf(paletteData); + for (int i=0; i<12; i++) { + std::vector colors; + + for (int j=0; j<16; j++) { + unsigned char r = palbuf.ReadNextByte(); + unsigned char g = palbuf.ReadNextByte(); + unsigned char b = palbuf.ReadNextByte(); + colors.push_back(Magick::ColorRGB(r/256.0, g/256.0, b/256.0)); + } + + overridePalettes.emplace_back(std::move(colors)); + } + } + Rom m3(argv[1]); auto roomInfos = RoomInfo::ReadFromRom(m3.buffer()); auto roomGfxPals = RoomGfxPal::ReadFromRom(m3.buffer()); std::list maps; - for (int i=2; i