diff --git a/src/app/core/constants.h b/src/app/core/constants.h index e77af32f..fec967c5 100644 --- a/src/app/core/constants.h +++ b/src/app/core/constants.h @@ -279,8 +279,8 @@ constexpr int characters_width = 0x74ADF; // Dungeon Entrances Related Variables //=========================================================================================== constexpr int entrance_room = 0x14813; // 0x14577 //word value for each room -constexpr int entrance_scrolledge = - 0x1491D; // 0x14681 //8 bytes per room, HU, FU, HD, FD, HL, FL, HR, FR +// 8 bytes per room, HU, FU, HD, FD, HL, FL, HR, FR +constexpr int entrance_scrolledge = 0x1491D; // 0x14681 constexpr int entrance_yscroll = 0x14D45; // 0x14AA9 //2bytes each room constexpr int entrance_xscroll = 0x14E4F; // 0x14BB3 //2bytes constexpr int entrance_yposition = 0x14F59; // 0x14CBD 2bytes @@ -293,17 +293,17 @@ constexpr int entrance_blockset = 0x15381; // 0x150E5 1byte constexpr int entrance_floor = 0x15406; // 0x1516A 1byte constexpr int entrance_dungeon = 0x1548B; // 0x151EF 1byte (dungeon id) constexpr int entrance_door = 0x15510; // 0x15274 1byte -constexpr int entrance_ladderbg = - 0x15595; // 0x152F9 //1 byte, ---b ---a b = bg2, a = need to check -_- +// 1 byte, ---b ---a b = bg2, a = need to check -_- +constexpr int entrance_ladderbg = 0x15595; // 0x152F9 constexpr int entrance_scrolling = 0x1561A; // 0x1537E //1byte --h- --v- constexpr int entrance_scrollquadrant = 0x1569F; // 0x15403 1byte constexpr int entrance_exit = 0x15724; // 0x15488 //2byte word constexpr int entrance_music = 0x1582E; // 0x15592 -constexpr int startingentrance_room = - 0x15B6E; // 0x158D2 //word value for each room -constexpr int startingentrance_scrolledge = - 0x15B7C; // 0x158E0 //8 bytes per room, HU, FU, HD, FD, HL, FL, HR, FR +// word value for each room +constexpr int startingentrance_room = 0x15B6E; // 0x158D2 +// 8 bytes per room, HU, FU, HD, FD, HL, FL, HR, FR +constexpr int startingentrance_scrolledge = 0x15B7C; // 0x158E0 constexpr int startingentrance_yscroll = 0x15BB4; // 0x14AA9 //2bytes each room constexpr int startingentrance_xscroll = 0x15BC2; // 0x14BB3 //2bytes constexpr int startingentrance_yposition = 0x15BD0; // 0x14CBD 2bytes @@ -317,10 +317,10 @@ constexpr int startingentrance_dungeon = 0x15C16; // 0x151EF 1byte (dungeon id) constexpr int startingentrance_door = 0x15C2B; // 0x15274 1byte -constexpr int startingentrance_ladderbg = - 0x15C1D; // 0x152F9 //1 byte, ---b ---a b = bg2, a = need to check -_- -constexpr int startingentrance_scrolling = - 0x15C24; // 0x1537E //1byte --h- --v- +// 1 byte, ---b ---a b = bg2, a = need to check -_- +constexpr int startingentrance_ladderbg = 0x15C1D; // 0x152F9 +// 1byte --h- --v- +constexpr int startingentrance_scrolling = 0x15C24; // 0x1537E constexpr int startingentrance_scrollquadrant = 0x15C2B; // 0x15403 1byte constexpr int startingentrance_exit = 0x15C32; // 0x15488 //2byte word constexpr int startingentrance_music = 0x15C4E; // 0x15592 @@ -331,8 +331,8 @@ constexpr int items_data_end = 0xE6B2; // save purpose constexpr int initial_equipement = 0x271A6; constexpr int messages_id_dungeon = 0x3F61D; -constexpr int chests_backupitems = - 0x3B528; // item id you get instead if you already have that item +// item id you get instead if you already have that item +constexpr int chests_backupitems = 0x3B528; constexpr int chests_yoffset = 0x4836C; constexpr int chests_xoffset = 0x4836C + (76 * 1); constexpr int chests_itemsgfx = 0x4836C + (76 * 2); @@ -351,12 +351,12 @@ constexpr int dungeons_bossrooms = 0x10954; // short value constexpr int bedPositionX = 0x039A37; // short value constexpr int bedPositionY = 0x039A32; // short value -constexpr int bedPositionResetXLow = - 0x02DE53; // short value(on 2 different bytes) +// short value (on 2 different bytes) +constexpr int bedPositionResetXLow = 0x02DE53; constexpr int bedPositionResetXHigh = 0x02DE58; //^^^^^^ -constexpr int bedPositionResetYLow = - 0x02DE5D; // short value(on 2 different bytes) +// short value (on 2 different bytes) +constexpr int bedPositionResetYLow = 0x02DE5D; constexpr int bedPositionResetYHigh = 0x02DE62; //^^^^^^ constexpr int bedSheetPositionX = 0x0480BD; // short value @@ -386,8 +386,8 @@ constexpr int overworldPaletteAuxialiary = 0xDE86C; constexpr int overworldPaletteAnimated = 0xDE604; constexpr int globalSpritePalettesLW = 0xDD218; constexpr int globalSpritePalettesDW = 0xDD290; -constexpr int armorPalettes = - 0xDD308; // Green, Blue, Red, Bunny, Electrocuted (15 colors each) +// Green, Blue, Red, Bunny, Electrocuted (15 colors each) +constexpr int armorPalettes = 0xDD308; constexpr int spritePalettesAux1 = 0xDD39E; // 7 colors each constexpr int spritePalettesAux2 = 0xDD446; // 7 colors each constexpr int spritePalettesAux3 = 0xDD4E0; // 7 colors each @@ -397,8 +397,8 @@ constexpr int hudPalettes = 0xDD660; constexpr int dungeonMapPalettes = 0xDD70A; // 21 colors constexpr int dungeonMainPalettes = 0xDD734; //(15*6) colors each - 20 entries constexpr int dungeonMapBgPalettes = 0xDE544; // 16*6 -constexpr int hardcodedGrassLW = - 0x5FEA9; // Mirrored Value at 0x75645 : 0x75625 +// Mirrored Value at 0x75645 : 0x75625 +constexpr int hardcodedGrassLW = 0x5FEA9; constexpr int hardcodedGrassDW = 0x05FEB3; // 0x7564F constexpr int hardcodedGrassSpecial = 0x75640; @@ -409,16 +409,14 @@ constexpr int dungeonMap_rooms_ptr = 0x57605; // 14 pointers of map data constexpr int dungeonMap_floors = 0x575D9; // 14 words values constexpr int dungeonMap_gfx_ptr = 0x57BE4; // 14 pointers of gfx data -constexpr int dungeonMap_datastart = - 0x57039; // data start for floors/gfx MUST skip 575D9 to 57621 (pointers) - -constexpr int dungeonMap_expCheck = - 0x56652; // IF Byte = 0xB9 dungeon maps are not expanded +// data start for floors/gfx MUST skip 575D9 to 57621 (pointers) +constexpr int dungeonMap_datastart = 0x57039; +// IF Byte = 0xB9 dungeon maps are not expanded +constexpr int dungeonMap_expCheck = 0x56652; constexpr int dungeonMap_tile16 = 0x57009; constexpr int dungeonMap_tile16Exp = 0x109010; -constexpr int dungeonMap_bossrooms = 0x56807; // 14 words values 0x000F = no - // boss - +// 14 words values 0x000F = no boss +constexpr int dungeonMap_bossrooms = 0x56807; constexpr int triforceVertices = 0x04FFD2; // group of 3, X, Y ,Z constexpr int TriforceFaces = 0x04FFE4; // group of 5 diff --git a/src/app/editor/editor.cc b/src/app/editor/editor.cc index cc093a15..78887710 100644 --- a/src/app/editor/editor.cc +++ b/src/app/editor/editor.cc @@ -138,7 +138,6 @@ void Editor::DrawYazeMenu() { std::string filePathName = ImGuiFileDialog::Instance()->GetFilePathName(); std::string filePath = ImGuiFileDialog::Instance()->GetCurrentPath(); rom_.LoadFromFile(filePathName); - rom_data_ = (void *)rom_.data(); overworld_editor_.SetupROM(rom_); } ImGuiFileDialog::Instance()->Close(); @@ -217,7 +216,7 @@ void Editor::DrawViewMenu() { if (show_memory_editor) { static MemoryEditor mem_edit; - mem_edit.DrawWindow("Memory Editor", rom_data_, rom_.getSize()); + mem_edit.DrawWindow("Memory Editor", (void *)rom_.data(), rom_.getSize()); } if (show_imgui_demo) { @@ -294,14 +293,14 @@ void Editor::DrawGraphicsSheet(int offset) { surface->format->palette->colors[i].b = current_palette_[i].z * 255; } - unsigned int snesAddr = 0; - unsigned int pcAddr = 0; - snesAddr = (unsigned int)((((rom_.data()[0x4F80 + offset]) << 16) | + unsigned int snes_addr = 0; + unsigned int pc_addr = 0; + snes_addr = (unsigned int)((((rom_.data()[0x4F80 + offset]) << 16) | ((rom_.data()[0x505F + offset]) << 8) | ((rom_.data()[0x513E + offset])))); - pcAddr = core::SnesToPc(snesAddr); + pc_addr = core::SnesToPc(snes_addr); std::cout << "Decompressing..." << std::endl; - char *decomp = rom_.Decompress(pcAddr); + char *decomp = rom_.Decompress(pc_addr); std::cout << "Converting to 8bpp sheet..." << std::endl; sheet_buffer = rom_.SNES3bppTo8bppSheet((uchar *)decomp); std::cout << "Assigning pixel data..." << std::endl; @@ -360,10 +359,9 @@ void Editor::DrawProjectEditor() { static bool opt_enable_context_menu = true; static bool opt_enable_grid = true; ImVec2 canvas_p0 = ImGui::GetCursorScreenPos(); - // ImVec2 canvas_sz = ImGui::GetContentRegionAvail(); - ImVec2 canvas_sz = ImVec2( + auto canvas_sz = ImVec2( 512 + 1, ImGui::GetContentRegionAvail().y + (tilesheet_offset * 256)); - ImVec2 canvas_p1 = + auto canvas_p1 = ImVec2(canvas_p0.x + canvas_sz.x, canvas_p0.y + canvas_sz.y); // Draw border and background color @@ -376,7 +374,6 @@ void Editor::DrawProjectEditor() { ImGui::InvisibleButton( "canvas", canvas_sz, ImGuiButtonFlags_MouseButtonLeft | ImGuiButtonFlags_MouseButtonRight); - const bool is_hovered = ImGui::IsItemHovered(); // Hovered const bool is_active = ImGui::IsItemActive(); // Held const ImVec2 origin(canvas_p0.x + scrolling.x, canvas_p0.y + scrolling.y); // Lock scrolled origin diff --git a/src/app/editor/editor.h b/src/app/editor/editor.h index a352bb29..c4125e7a 100644 --- a/src/app/editor/editor.h +++ b/src/app/editor/editor.h @@ -42,7 +42,6 @@ class Editor { void DrawScreenEditor(); void DrawHUDEditor(); - void *rom_data_; bool is_loaded_ = true; app::rom::ROM rom_; diff --git a/src/app/editor/overworld_editor.cc b/src/app/editor/overworld_editor.cc index 3f782c24..0f274a9c 100644 --- a/src/app/editor/overworld_editor.cc +++ b/src/app/editor/overworld_editor.cc @@ -10,11 +10,6 @@ #include "app/zelda3/overworld.h" #include "gui/icons.h" -// first step would be to decompress all gfx data from the game -// (in alttp that's easy they're all located in the same location all the -// same sheet size 128x32) have a code that convert PC address to SNES and -// vice-versa - // 1) find the gfx pointers (you could use ZS constant file) // 2) decompress all the gfx with your lz2 decompressor // 3) convert the 3bpp snes data into PC 4bpp (probably the hardest part) @@ -132,7 +127,6 @@ void OverworldEditor::DrawToolset() { ImGui::TableNextColumn(); if (ImGui::Button(ICON_MD_UPDATE)) { overworld_.Load(rom_, allGfx16Ptr); - LoadBlockset(); } ImGui::EndTable(); @@ -280,6 +274,16 @@ void OverworldEditor::DrawOverworldCanvas() { } void OverworldEditor::DrawTileSelector() { + ImGui::Text("Palette:"); + for (int i = 0; i < 8; i++) { + std::string id = "##PaletteColor" + std::to_string(i); + ImGui::SameLine(); + ImGui::ColorEdit4(id.c_str(), ¤t_palette_[i].x, + ImGuiColorEditFlags_NoInputs | + ImGuiColorEditFlags_DisplayRGB | + ImGuiColorEditFlags_DisplayHex); + } + if (ImGui::BeginTabBar("##TabBar", ImGuiTabBarFlags_FittingPolicyScroll)) { if (ImGui::BeginTabItem("Tile16")) { bool child_is_visible = @@ -399,8 +403,7 @@ void OverworldEditor::DrawTile8Selector() { if (key >= 1) { top_left_y = canvas_p0.y + 64 * key; } - draw_list->AddImage((void *)value, - ImVec2(canvas_p0.x + 2, top_left_y), + draw_list->AddImage((void *)value, ImVec2(canvas_p0.x + 2, top_left_y), ImVec2(canvas_p0.x + 256, canvas_p0.y + offset)); } } @@ -433,41 +436,6 @@ void OverworldEditor::DrawChangelist() { ImGui::End(); } -void OverworldEditor::LoadBlockset() { - rom_.CreateAllGraphicsData(allGfx16Ptr); - - for (int i = 0; i < 16; i++) { - staticgfx[i] = i; - } - - // Update gfx to be on selected map - auto currentmapgfx8Data = current_gfx_ptr_; - auto allgfxData = allGfx16Ptr; - for (int i = 0; i < 16; i++) { - for (int j = 0; j < 2048; j++) { - auto mapByte = allgfxData[j + (staticgfx[i] * 2048)]; - switch (i) { - case 0: - case 3: - case 4: - case 5: - mapByte += 0x88; - break; - } - - currentmapgfx8Data[(i * 2048) + j] = mapByte; // Upload used gfx data - } - } - - auto tiles = overworld_.GetTiles16(); - app::gfx::BuildTiles16Gfx(tile16_blockset_ptr_, current_gfx_ptr_, tiles); - current_gfx_bmp_.Create(128, 512, 64, current_gfx_ptr_); - current_gfx_bmp_.CreateTexture(rom_.Renderer()); - tile16_blockset_bmp_.Create(128, 8192, 8, tile16_blockset_ptr_); - tile16_blockset_bmp_.CreateTexture(rom_.Renderer()); - map_blockset_loaded_ = true; -} - void OverworldEditor::LoadGraphics() { for (int i = 0; i < kNumSheetsToLoad; i++) { all_texture_sheet_[i] = rom_.DrawGraphicsSheet(i); @@ -475,5 +443,5 @@ void OverworldEditor::LoadGraphics() { } } // namespace editor -} // namespace gui +} // namespace app } // namespace yaze \ No newline at end of file diff --git a/src/app/editor/overworld_editor.h b/src/app/editor/overworld_editor.h index 61139a02..4de31c88 100644 --- a/src/app/editor/overworld_editor.h +++ b/src/app/editor/overworld_editor.h @@ -66,6 +66,8 @@ class OverworldEditor { bool all_gfx_loaded_ = false; bool map_blockset_loaded_ = false; + ImVec4 current_palette_[8]; + constexpr static int kByteSize = 3; constexpr static int kMessageIdSize = 5; constexpr static int kNumSheetsToLoad = 100; diff --git a/src/app/gfx/bitmap.cc b/src/app/gfx/bitmap.cc index f742ce61..ec5be1bb 100644 --- a/src/app/gfx/bitmap.cc +++ b/src/app/gfx/bitmap.cc @@ -38,6 +38,21 @@ void Bitmap::Create(int width, int height, int depth, uchar *data) { surface_->pixels = pixel_data_; } +void Bitmap::Create(int width, int height, int depth, int size) { + width_ = width; + height_ = height; + depth_ = depth; + surface_ = SDL_CreateRGBSurfaceWithFormat(0, width, height, depth, + SDL_PIXELFORMAT_INDEX8); + // Default grayscale palette + for (int i = 0; i < 8; i++) { + surface_->format->palette->colors[i].r = i * 31; + surface_->format->palette->colors[i].g = i * 31; + surface_->format->palette->colors[i].b = i * 31; + } + surface_->pixels = pixel_data_; +} + void Bitmap::CreateTexture(std::shared_ptr renderer) { texture_ = SDL_CreateTextureFromSurface(renderer.get(), surface_); } diff --git a/src/app/gfx/bitmap.h b/src/app/gfx/bitmap.h index 35705d07..7130ef74 100644 --- a/src/app/gfx/bitmap.h +++ b/src/app/gfx/bitmap.h @@ -16,15 +16,17 @@ class Bitmap { Bitmap(int width, int height, int depth, uchar *data); void Create(int width, int height, int depth, uchar *data); + void Create(int width, int height, int depth, int data_size); int GetWidth() const { return width_; } int GetHeight() const { return height_; } void CreateTexture(std::shared_ptr renderer); - inline SDL_Texture *GetTexture() const { return texture_; } + SDL_Texture *GetTexture() const { return texture_; } private: int width_; int height_; int depth_; + int data_size_; uchar *pixel_data_; SDL_Surface *surface_; SDL_Texture *texture_; diff --git a/src/app/gfx/snes_palette.cc b/src/app/gfx/snes_palette.cc index d82580ec..12d29da5 100644 --- a/src/app/gfx/snes_palette.cc +++ b/src/app/gfx/snes_palette.cc @@ -82,13 +82,13 @@ SNESPalette::SNESPalette(const std::vector & cols) { } char* SNESPalette::encode() { - auto data = std::make_shared(size_ * 2); + auto data = new char[size_ * 2]; for (unsigned int i = 0; i < size_; i++) { std::cout << colors[i].snes << std::endl; data[i * 2] = (char)(colors[i].snes & 0xFF); data[i * 2 + 1] = (char)(colors[i].snes >> 8); } - return data.get(); + return data; } SDL_Palette* SNESPalette::GetSDL_Palette() { diff --git a/src/app/rom.cc b/src/app/rom.cc index 9931d2fc..5df64e7f 100644 --- a/src/app/rom.cc +++ b/src/app/rom.cc @@ -20,11 +20,8 @@ namespace app { namespace rom { void ROM::Close() { - if (loaded) { + if (is_loaded_) { delete[] current_rom_; - for (auto &each : decompressed_graphic_sheets_) { - free(each); - } for (auto &each : converted_graphic_sheets_) { free(each); } @@ -52,7 +49,7 @@ void ROM::LoadFromFile(const std::string &path) { file.close(); memcpy(title, current_rom_ + 32704, 21); version_ = current_rom_[27]; - loaded = true; + is_loaded_ = true; } char *ROM::Decompress(int pos, int size, bool reversed) { @@ -224,13 +221,13 @@ SDL_Texture *ROM::DrawGraphicsSheet(int offset) { } int ROM::GetPCGfxAddress(uint8_t id) { - int gfxPtr1 = + auto gfxPtr1 = core::SnesToPc((current_rom_[core::constants::gfx_1_pointer + 1] << 8) + (current_rom_[core::constants::gfx_1_pointer])); - int gfxPtr2 = + auto gfxPtr2 = core::SnesToPc((current_rom_[core::constants::gfx_2_pointer + 1] << 8) + (current_rom_[core::constants::gfx_2_pointer])); - int gfxPtr3 = + auto gfxPtr3 = core::SnesToPc((current_rom_[core::constants::gfx_3_pointer + 1] << 8) + (current_rom_[core::constants::gfx_3_pointer])); diff --git a/src/app/rom.h b/src/app/rom.h index 1326eda4..d20612cd 100644 --- a/src/app/rom.h +++ b/src/app/rom.h @@ -41,10 +41,10 @@ class ROM { const uchar* getTitle() const { return title; } long getSize() const { return size_; } char getVersion() const { return version_; } - bool isLoaded() const { return loaded; } + bool isLoaded() const { return is_loaded_; } private: - bool loaded = false; + bool is_loaded_ = false; bool has_header_ = false; long size_; uint compressed_size_;