// Copyright 2009 Dolphin Emulator Project // Licensed under GPLv2+ // Refer to the license.txt file included. #include "DiscIO/Volume.h" #include #include #include #include #include #include #include #include "Common/ColorUtil.h" #include "Common/CommonTypes.h" #include "Common/FileUtil.h" #include "Common/NandPaths.h" #include "Common/StringUtil.h" #include "Common/Swap.h" #include "DiscIO/Blob.h" #include "DiscIO/Enums.h" #include "DiscIO/VolumeDirectory.h" #include "DiscIO/VolumeGC.h" #include "DiscIO/VolumeWad.h" #include "DiscIO/VolumeWii.h" namespace DiscIO { static const unsigned int WII_BANNER_WIDTH = 192; static const unsigned int WII_BANNER_HEIGHT = 64; static const unsigned int WII_BANNER_SIZE = WII_BANNER_WIDTH * WII_BANNER_HEIGHT * 2; static const unsigned int WII_BANNER_OFFSET = 0xA0; const IOS::ES::TicketReader Volume::INVALID_TICKET{}; const IOS::ES::TMDReader Volume::INVALID_TMD{}; std::vector Volume::GetWiiBanner(int* width, int* height, u64 title_id) { *width = 0; *height = 0; const std::string file_name = Common::GetTitleDataPath(title_id, Common::FROM_CONFIGURED_ROOT) + "banner.bin"; if (!File::Exists(file_name)) return std::vector(); if (File::GetSize(file_name) < WII_BANNER_OFFSET + WII_BANNER_SIZE) return std::vector(); File::IOFile file(file_name, "rb"); if (!file.Seek(WII_BANNER_OFFSET, SEEK_SET)) return std::vector(); std::vector banner_file(WII_BANNER_SIZE); if (!file.ReadBytes(banner_file.data(), banner_file.size())) return std::vector(); std::vector image_buffer(WII_BANNER_WIDTH * WII_BANNER_HEIGHT); ColorUtil::decode5A3image(image_buffer.data(), (u16*)banner_file.data(), WII_BANNER_WIDTH, WII_BANNER_HEIGHT); *width = WII_BANNER_WIDTH; *height = WII_BANNER_HEIGHT; return image_buffer; } std::map Volume::ReadWiiNames(const std::vector& data) { std::map names; for (size_t i = 0; i < NUMBER_OF_LANGUAGES; ++i) { size_t name_start = NAME_BYTES_LENGTH * i; size_t name_end = name_start + NAME_BYTES_LENGTH; if (data.size() >= name_end) { u16* temp = (u16*)(data.data() + name_start); std::wstring out_temp(NAME_STRING_LENGTH, '\0'); std::transform(temp, temp + out_temp.size(), out_temp.begin(), (u16(&)(u16))Common::swap16); out_temp.erase(std::find(out_temp.begin(), out_temp.end(), 0x00), out_temp.end()); std::string name = UTF16ToUTF8(out_temp); if (!name.empty()) names[static_cast(i)] = name; } } return names; } std::unique_ptr CreateVolumeFromFilename(const std::string& filename) { std::unique_ptr reader(CreateBlobReader(filename)); if (reader == nullptr) return nullptr; // Check for Wii const std::optional wii_magic = reader->ReadSwapped(0x18); if (wii_magic == u32(0x5D1C9EA3)) return std::make_unique(std::move(reader)); // Check for WAD // 0x206962 for boot2 wads const std::optional wad_magic = reader->ReadSwapped(0x02); if (wad_magic == u32(0x00204973) || wad_magic == u32(0x00206962)) return std::make_unique(std::move(reader)); // Check for GC const std::optional gc_magic = reader->ReadSwapped(0x1C); if (gc_magic == u32(0xC2339F3D)) return std::make_unique(std::move(reader)); // No known magic words found return nullptr; } std::unique_ptr CreateVolumeFromDirectory(const std::string& directory, bool is_wii, const std::string& apploader, const std::string& dol) { if (VolumeDirectory::IsValidDirectory(directory)) return std::make_unique(directory, is_wii, apploader, dol); return nullptr; } } // namespace