| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | #include <stdio.h> |
| 6 | #include <algorithm> |
| 7 | |
| 8 | #include "Common.h" |
| 9 | #include "ColorUtil.h" |
| 10 | #include "BannerLoaderWii.h" |
| 11 | #include "VolumeCreator.h" |
| 12 | #include "FileUtil.h" |
| 13 | #include "FileHandlerARC.h" |
| 14 | |
| 15 | namespace DiscIO |
| 16 | { |
| 17 | |
| 18 | CBannerLoaderWii::CBannerLoaderWii(DiscIO::IVolume *pVolume) |
| 19 | : m_pBannerFile(NULL__null) |
| 20 | , m_IsValid(false) |
| 21 | { |
| 22 | char Filename[260]; |
| 23 | u64 TitleID; |
| 1 | 'TitleID' declared without an initial value | |
|
| 24 | |
| 25 | pVolume->GetTitleID((u8*)&TitleID); |
| 26 | |
| 27 | TitleID = Common::swap64(TitleID); |
| 2 | | Function call argument is an uninitialized value |
|
| 28 | |
| 29 | sprintf(Filename, "%stitle/%08x/%08x/data/banner.bin", |
| 30 | File::GetUserPath(D_WIIUSER_IDX).c_str(), (u32)(TitleID>>32), (u32)TitleID); |
| 31 | |
| 32 | if (!File::Exists(Filename)) |
| 33 | { |
| 34 | |
| 35 | |
| 36 | |
| 37 | #if 0 |
| 38 | char bnrFilename[260], titleFolder[260]; |
| 39 | |
| 40 | |
| 41 | sprintf(titleFolder, "%stitle/%08x/%08x/data/", |
| 42 | File::GetUserPath(D_WIIUSER_IDX).c_str(), (u32)(TitleID>>32), (u32)TitleID); |
| 43 | if(!File::Exists(titleFolder)) |
| 44 | File::CreateFullPath(titleFolder); |
| 45 | |
| 46 | |
| 47 | sprintf(bnrFilename, "%stitle/%08x/%08x/data/opening.bnr", |
| 48 | File::GetUserPath(D_WIIUSER_IDX).c_str(), (u32)(TitleID>>32), (u32)TitleID); |
| 49 | |
| 50 | if(!_rFileSystem.ExportFile("opening.bnr", bnrFilename)) { |
| 51 | m_IsValid = false; |
| 52 | return; |
| 53 | } |
| 54 | |
| 55 | CARCFile bnrArc (bnrFilename, 0x600); |
| 56 | |
| 57 | if(!bnrArc.ExportFile("meta/banner.bin", Filename)) { |
| 58 | m_IsValid = false; |
| 59 | return; |
| 60 | } |
| 61 | |
| 62 | |
| 63 | |
| 64 | |
| 65 | File::Delete(bnrFilename); |
| 66 | #else |
| 67 | m_IsValid = false; |
| 68 | return; |
| 69 | #endif |
| 70 | } |
| 71 | |
| 72 | |
| 73 | size_t FileSize = (size_t) File::GetSize(Filename); |
| 74 | |
| 75 | if (FileSize > 0) |
| 76 | { |
| 77 | m_pBannerFile = new u8[FileSize]; |
| 78 | File::IOFile pFile(Filename, "rb"); |
| 79 | if (pFile) |
| 80 | { |
| 81 | pFile.ReadBytes(m_pBannerFile, FileSize); |
| 82 | m_IsValid = true; |
| 83 | } |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | CBannerLoaderWii::~CBannerLoaderWii() |
| 88 | { |
| 89 | if (m_pBannerFile) |
| 90 | { |
| 91 | delete [] m_pBannerFile; |
| 92 | m_pBannerFile = NULL__null; |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | bool CBannerLoaderWii::IsValid() |
| 97 | { |
| 98 | return m_IsValid; |
| 99 | } |
| 100 | |
| 101 | std::vector<u32> CBannerLoaderWii::GetBanner(int* pWidth, int* pHeight) |
| 102 | { |
| 103 | SWiiBanner* pBanner = (SWiiBanner*)m_pBannerFile; |
| 104 | std::vector<u32> Buffer; |
| 105 | Buffer.resize(192 * 64); |
| 106 | decode5A3image(&Buffer[0], (u16*)pBanner->m_BannerTexture, 192, 64); |
| 107 | *pWidth = 192; |
| 108 | *pHeight = 64; |
| 109 | return Buffer; |
| 110 | } |
| 111 | |
| 112 | bool CBannerLoaderWii::GetStringFromComments(const CommentIndex index, std::string& result) |
| 113 | { |
| 114 | if (IsValid()) |
| 115 | { |
| 116 | auto const banner = reinterpret_cast<const SWiiBanner*>(m_pBannerFile); |
| 117 | auto const src_ptr = banner->m_Comment[index]; |
| 118 | |
| 119 | |
| 120 | auto const length = std::find(src_ptr, src_ptr + COMMENT_SIZE, 0x0) - src_ptr; |
| 121 | |
| 122 | std::wstring src; |
| 123 | src.resize(length); |
| 124 | std::transform(src_ptr, src_ptr + src.size(), src.begin(), (u16(&)(u16))Common::swap16); |
| 125 | result = UTF16ToUTF8(src); |
| 126 | |
| 127 | return true; |
| 128 | } |
| 129 | |
| 130 | return false; |
| 131 | } |
| 132 | |
| 133 | std::vector<std::string> CBannerLoaderWii::GetNames() |
| 134 | { |
| 135 | std::vector<std::string> ret(1); |
| 136 | |
| 137 | if (!GetStringFromComments(NAME_IDX, ret[0])) |
| 138 | ret.clear(); |
| 139 | |
| 140 | return ret; |
| 141 | } |
| 142 | |
| 143 | std::string CBannerLoaderWii::GetCompany() |
| 144 | { |
| 145 | return ""; |
| 146 | } |
| 147 | |
| 148 | std::vector<std::string> CBannerLoaderWii::GetDescriptions() |
| 149 | { |
| 150 | std::vector<std::string> result(1); |
| 151 | if (!GetStringFromComments(DESC_IDX, result[0])) |
| 152 | result.clear(); |
| 153 | return result; |
| 154 | } |
| 155 | |
| 156 | void CBannerLoaderWii::decode5A3image(u32* dst, u16* src, int width, int height) |
| 157 | { |
| 158 | for (int y = 0; y < height; y += 4) |
| 159 | { |
| 160 | for (int x = 0; x < width; x += 4) |
| 161 | { |
| 162 | for (int iy = 0; iy < 4; iy++, src += 4) |
| 163 | { |
| 164 | for (int ix = 0; ix < 4; ix++) |
| 165 | { |
| 166 | u32 RGBA = ColorUtil::Decode5A3(Common::swap16(src[ix])); |
| 167 | dst[(y + iy) * width + (x + ix)] = RGBA; |
| 168 | } |
| 169 | } |
| 170 | } |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | } |