diff --git a/Source/Core/DiscIO/Src/BannerLoader.cpp b/Source/Core/DiscIO/Src/BannerLoader.cpp index 02242d5b29..8a1931db1e 100644 --- a/Source/Core/DiscIO/Src/BannerLoader.cpp +++ b/Source/Core/DiscIO/Src/BannerLoader.cpp @@ -94,31 +94,44 @@ bool IBannerLoader::CopyToStringAndCheck(std::string& _rDestination, const char* return(bResult); } -bool IBannerLoader::CopyUnicodeToString( std::string& _rDestination, const u16* _src ) +bool IBannerLoader::CopyBeUnicodeToString( std::string& _rDestination, const u16* _src, int length ) { + + bool returnCode = false; #ifdef WIN32 if (_src) { - u32 ansiNameSize = WideCharToMultiByte(CP_ACP, 0, - (LPCWSTR)_src, (int)wcslen((const wchar_t*)_src), - NULL, NULL, NULL, NULL); - if (ansiNameSize > 0) + u16* buffer = new u16[length]; + if (buffer) { - char* pAnsiStrBuffer = new char[ansiNameSize + 1]; - if (pAnsiStrBuffer) + memcpy(buffer, _src, sizeof(u16)*length); + for (int i = 0; i < length; i++) { - memset(pAnsiStrBuffer, 0, (ansiNameSize + 1) * sizeof(char)); - if (WideCharToMultiByte(CP_ACP, 0, - (LPCWSTR)_src, (int)wcslen((const wchar_t*)_src), - pAnsiStrBuffer, ansiNameSize, NULL, NULL)) - { - _rDestination = pAnsiStrBuffer; - returnCode = true; - } - delete pAnsiStrBuffer; + buffer[i] = swap16(buffer[i]); } - } + + u32 ansiNameSize = WideCharToMultiByte(CP_ACP, 0, + (LPCWSTR)buffer, (int)wcslen((const wchar_t*)buffer), + NULL, NULL, NULL, NULL); + if (ansiNameSize > 0) + { + char* pAnsiStrBuffer = new char[ansiNameSize + 1]; + if (pAnsiStrBuffer) + { + memset(pAnsiStrBuffer, 0, (ansiNameSize + 1) * sizeof(char)); + if (WideCharToMultiByte(CP_ACP, 0, + (LPCWSTR)buffer, (int)wcslen((const wchar_t*)buffer), + pAnsiStrBuffer, ansiNameSize, NULL, NULL)) + { + _rDestination = pAnsiStrBuffer; + returnCode = true; + } + delete pAnsiStrBuffer; + } + } + delete buffer; + } } #else // FIXME: Horribly broke on non win32 diff --git a/Source/Core/DiscIO/Src/BannerLoader.h b/Source/Core/DiscIO/Src/BannerLoader.h index 1a455c7a86..0da8ee3358 100644 --- a/Source/Core/DiscIO/Src/BannerLoader.h +++ b/Source/Core/DiscIO/Src/BannerLoader.h @@ -49,7 +49,12 @@ class IBannerLoader bool CopyToStringAndCheck(std::string& _rDestination, const char* _src); - bool CopyUnicodeToString(std::string& _rDestination, const u16* _src); + bool CopyBeUnicodeToString(std::string& _rDestination, const u16* _src, int length); + private: + u16 swap16(u16 data) + { + return ((data & 0xff00) >> 8) | ((data & 0xff) << 8); + } }; IBannerLoader* CreateBannerLoader(DiscIO::IFileSystem& _rFileSystem); diff --git a/Source/Core/DiscIO/Src/BannerLoaderWii.cpp b/Source/Core/DiscIO/Src/BannerLoaderWii.cpp index 12b7ba2e3e..cffffe2648 100644 --- a/Source/Core/DiscIO/Src/BannerLoaderWii.cpp +++ b/Source/Core/DiscIO/Src/BannerLoaderWii.cpp @@ -96,24 +96,6 @@ CBannerLoaderWii::GetBanner(u32* _pBannerImage) return true; } -std::string -CBannerLoaderWii::StupidWideCharToString(u16* _pSrc, size_t _max) -{ - std::string temp; - - u32 offset = 0; - while (_pSrc[offset] != 0x0000) - { - temp += (char)(_pSrc[offset] >> 8); - offset ++; - - if (offset >= _max) - break; - } - - return temp; -} - bool CBannerLoaderWii::GetName(std::string* _rName) { @@ -131,7 +113,7 @@ CBannerLoaderWii::GetName(std::string* _rName) SWiiBanner* pBanner = (SWiiBanner*)m_pBannerFile; std::string name; - if (CopyUnicodeToString(name, pBanner->m_Comment[0])) + if (CopyBeUnicodeToString(name, pBanner->m_Comment[0], WII_BANNER_COMMENT_SIZE)) { for (int i = 0; i < 6; i++) { @@ -168,7 +150,7 @@ CBannerLoaderWii::GetDescription(std::string* _rDescription) SWiiBanner* pBanner = (SWiiBanner*)m_pBannerFile; std::string description; - if (CopyUnicodeToString(description, pBanner->m_Comment[1])) + if (CopyBeUnicodeToString(description, pBanner->m_Comment[1], WII_BANNER_COMMENT_SIZE)) { for (int i = 0; i< 6; i++) { diff --git a/Source/Core/DiscIO/Src/BannerLoaderWii.h b/Source/Core/DiscIO/Src/BannerLoaderWii.h index 80a1ab4636..539bf71754 100644 --- a/Source/Core/DiscIO/Src/BannerLoaderWii.h +++ b/Source/Core/DiscIO/Src/BannerLoaderWii.h @@ -73,8 +73,6 @@ class CBannerLoaderWii void InitLUTTable(); u32 decode5A3(u16 val); void decode5A3image(u32* dst, u16* src, int width, int height); - - std::string StupidWideCharToString(u16* _pSrc, size_t _max); }; } // namespace diff --git a/Source/Core/DolphinWX/Src/ISOFile.cpp b/Source/Core/DolphinWX/Src/ISOFile.cpp index e0d7a01c00..48672b684a 100644 --- a/Source/Core/DolphinWX/Src/ISOFile.cpp +++ b/Source/Core/DolphinWX/Src/ISOFile.cpp @@ -32,7 +32,7 @@ #include "ChunkFile.h" #include "../resources/no_banner.cpp" -#define CACHE_REVISION 0x106 +#define CACHE_REVISION 0x107 #define DVD_BANNER_WIDTH 96 #define DVD_BANNER_HEIGHT 32