| 
									
										
										
										
											2013-04-17 23:09:55 -04:00
										 |  |  | // Copyright 2013 Dolphin Emulator Project
 | 
					
						
							|  |  |  | // Licensed under GPLv2
 | 
					
						
							|  |  |  | // Refer to the license.txt file included.
 | 
					
						
							| 
									
										
										
										
											2009-07-03 22:51:21 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-10 23:18:41 +02:00
										 |  |  | #include <algorithm>
 | 
					
						
							| 
									
										
										
										
											2015-04-09 17:44:53 +02:00
										 |  |  | #include <map>
 | 
					
						
							| 
									
										
										
										
											2014-02-21 01:47:53 +01:00
										 |  |  | #include <string>
 | 
					
						
							| 
									
										
										
										
											2015-04-10 22:10:49 +02:00
										 |  |  | #include <utility>
 | 
					
						
							| 
									
										
										
										
											2014-02-21 01:47:53 +01:00
										 |  |  | #include <vector>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-10 22:10:49 +02:00
										 |  |  | #include "Common/ColorUtil.h"
 | 
					
						
							|  |  |  | #include "Common/CommonFuncs.h"
 | 
					
						
							| 
									
										
										
										
											2014-09-07 20:06:58 -05:00
										 |  |  | #include "Common/CommonTypes.h"
 | 
					
						
							| 
									
										
										
										
											2015-04-10 22:10:49 +02:00
										 |  |  | #include "Common/FileUtil.h"
 | 
					
						
							|  |  |  | #include "Common/StringUtil.h"
 | 
					
						
							| 
									
										
										
										
											2014-09-18 23:17:41 -05:00
										 |  |  | #include "Common/Logging/Log.h"
 | 
					
						
							| 
									
										
										
										
											2014-02-17 05:18:15 -05:00
										 |  |  | #include "DiscIO/Volume.h"
 | 
					
						
							| 
									
										
										
										
											2009-07-03 22:51:21 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace DiscIO | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2015-04-10 22:10:49 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 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; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | std::vector<u32> IVolume::GetBanner(int* width, int* height) const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	*width = 0; | 
					
						
							|  |  |  | 	*height = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	u64 TitleID = 0; | 
					
						
							|  |  |  | 	GetTitleID((u8*)&TitleID); | 
					
						
							|  |  |  | 	TitleID = Common::swap64(TitleID); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	std::string file_name = StringFromFormat("%stitle/%08x/%08x/data/banner.bin", | 
					
						
							|  |  |  | 		File::GetUserPath(D_WIIUSER_IDX).c_str(), (u32)(TitleID >> 32), (u32)TitleID); | 
					
						
							|  |  |  | 	if (!File::Exists(file_name)) | 
					
						
							|  |  |  | 		return std::vector<u32>(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (File::GetSize(file_name) < WII_BANNER_OFFSET + WII_BANNER_SIZE) | 
					
						
							|  |  |  | 		return std::vector<u32>(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	File::IOFile file(file_name, "rb"); | 
					
						
							|  |  |  | 	if (!file.Seek(WII_BANNER_OFFSET, SEEK_SET)) | 
					
						
							|  |  |  | 		return std::vector<u32>(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	std::vector<u8> banner_file(WII_BANNER_SIZE); | 
					
						
							|  |  |  | 	if (!file.ReadBytes(banner_file.data(), banner_file.size())) | 
					
						
							|  |  |  | 		return std::vector<u32>(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	std::vector<u32> 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; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-10 23:18:41 +02:00
										 |  |  | std::map<IVolume::ELanguage, std::string> IVolume::ReadWiiNames(std::vector<u8>& data) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	std::map<IVolume::ELanguage, std::string> 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[(IVolume::ELanguage)i] = name; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return names; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-10 22:10:49 +02:00
										 |  |  | // Increment CACHE_REVISION if the code below is modified (ISOFile.cpp & GameFile.cpp)
 | 
					
						
							| 
									
										
										
										
											2015-02-23 20:43:29 -05:00
										 |  |  | IVolume::ECountry CountrySwitch(u8 country_code) | 
					
						
							| 
									
										
										
										
											2009-07-03 22:51:21 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-02-23 20:43:29 -05:00
										 |  |  | 	switch (country_code) | 
					
						
							| 
									
										
										
										
											2009-07-03 22:51:21 +00:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2014-10-30 10:35:46 -04:00
										 |  |  | 		// Region free - Uses European flag as placeholder
 | 
					
						
							| 
									
										
										
										
											2010-05-30 16:33:01 +00:00
										 |  |  | 		case 'A': | 
					
						
							| 
									
										
										
										
											2015-02-17 18:17:34 -06:00
										 |  |  | 			return IVolume::COUNTRY_WORLD; | 
					
						
							| 
									
										
										
										
											2013-10-29 01:23:17 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-05-30 17:16:06 +00:00
										 |  |  | 		// PAL
 | 
					
						
							| 
									
										
										
										
											2014-10-30 10:35:46 -04:00
										 |  |  | 		case 'D': | 
					
						
							| 
									
										
										
										
											2013-01-09 22:53:04 -06:00
										 |  |  | 			return IVolume::COUNTRY_GERMANY; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-22 00:48:59 +00:00
										 |  |  | 		case 'X': // Used by a couple PAL games
 | 
					
						
							| 
									
										
										
										
											2014-10-30 10:35:46 -04:00
										 |  |  | 		case 'Y': // German, French
 | 
					
						
							| 
									
										
										
										
											2010-05-30 17:16:06 +00:00
										 |  |  | 		case 'L': // Japanese import to PAL regions
 | 
					
						
							|  |  |  | 		case 'M': // Japanese import to PAL regions
 | 
					
						
							| 
									
										
										
										
											2009-07-03 22:51:21 +00:00
										 |  |  | 		case 'P': | 
					
						
							|  |  |  | 			return IVolume::COUNTRY_EUROPE; | 
					
						
							| 
									
										
										
										
											2013-10-29 01:23:17 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-30 10:35:46 -04:00
										 |  |  | 		case 'U': | 
					
						
							| 
									
										
										
										
											2014-10-26 17:47:07 -04:00
										 |  |  | 			return IVolume::COUNTRY_AUSTRALIA; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-03 22:51:21 +00:00
										 |  |  | 		case 'F': | 
					
						
							|  |  |  | 			return IVolume::COUNTRY_FRANCE; | 
					
						
							| 
									
										
										
										
											2013-10-29 01:23:17 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-03 22:51:21 +00:00
										 |  |  | 		case 'I': | 
					
						
							|  |  |  | 			return IVolume::COUNTRY_ITALY; | 
					
						
							| 
									
										
										
										
											2013-10-29 01:23:17 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-30 10:35:46 -04:00
										 |  |  | 		case 'H': | 
					
						
							|  |  |  | 			return IVolume::COUNTRY_NETHERLANDS; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-03 06:10:14 +00:00
										 |  |  | 		case 'R': | 
					
						
							|  |  |  | 			return IVolume::COUNTRY_RUSSIA; | 
					
						
							| 
									
										
										
										
											2009-07-03 22:51:21 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-30 10:35:46 -04:00
										 |  |  | 		case 'S': | 
					
						
							|  |  |  | 			return IVolume::COUNTRY_SPAIN; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-03 22:51:21 +00:00
										 |  |  | 		// NTSC
 | 
					
						
							|  |  |  | 		case 'E': | 
					
						
							| 
									
										
										
										
											2010-05-30 17:31:52 +00:00
										 |  |  | 		case 'N': // Japanese import to USA and other NTSC regions
 | 
					
						
							| 
									
										
										
										
											2015-01-12 22:28:12 -05:00
										 |  |  | 		case 'Z': // Prince of Persia - The Forgotten Sands (Wii)
 | 
					
						
							| 
									
										
										
										
											2014-12-30 19:57:14 -05:00
										 |  |  | 		case 'B': // Ufouria: The Saga (Virtual Console)
 | 
					
						
							| 
									
										
										
										
											2009-07-03 22:51:21 +00:00
										 |  |  | 			return IVolume::COUNTRY_USA; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		case 'J': | 
					
						
							|  |  |  | 			return IVolume::COUNTRY_JAPAN; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		case 'K': | 
					
						
							| 
									
										
										
										
											2010-05-30 17:16:06 +00:00
										 |  |  | 		case 'Q': // Korea with Japanese language
 | 
					
						
							| 
									
										
										
										
											2014-10-30 10:35:46 -04:00
										 |  |  | 		case 'T': // Korea with English language
 | 
					
						
							| 
									
										
										
										
											2009-07-03 22:51:21 +00:00
										 |  |  | 			return IVolume::COUNTRY_KOREA; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		case 'W': | 
					
						
							|  |  |  | 			return IVolume::COUNTRY_TAIWAN; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		default: | 
					
						
							| 
									
										
										
										
											2015-02-23 20:43:29 -05:00
										 |  |  | 			if (country_code > 'A') // Silently ignore IOS wads
 | 
					
						
							|  |  |  | 				WARN_LOG(DISCIO, "Unknown Country Code! %c", country_code); | 
					
						
							| 
									
										
										
										
											2009-07-03 22:51:21 +00:00
										 |  |  | 			return IVolume::COUNTRY_UNKNOWN; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2010-12-16 07:36:26 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | u8 GetSysMenuRegion(u16 _TitleVersion) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-03-11 00:30:55 +13:00
										 |  |  | 	switch (_TitleVersion) | 
					
						
							| 
									
										
										
										
											2010-12-16 07:36:26 +00:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2014-02-16 15:30:18 -05:00
										 |  |  | 	case 128: case 192: case 224: case 256: | 
					
						
							|  |  |  | 	case 288: case 352: case 384: case 416: | 
					
						
							|  |  |  | 	case 448: case 480: case 512: | 
					
						
							| 
									
										
										
										
											2010-12-16 07:36:26 +00:00
										 |  |  | 		return 'J'; | 
					
						
							| 
									
										
										
										
											2014-02-16 15:30:18 -05:00
										 |  |  | 	case 97:  case 193: case 225: case 257: | 
					
						
							|  |  |  | 	case 289: case 353: case 385: case 417: | 
					
						
							|  |  |  | 	case 449: case 481: case 513: | 
					
						
							| 
									
										
										
										
											2010-12-16 07:36:26 +00:00
										 |  |  | 		return 'E'; | 
					
						
							| 
									
										
										
										
											2014-02-16 15:30:18 -05:00
										 |  |  | 	case 130: case 162: case 194: case 226: | 
					
						
							|  |  |  | 	case 258: case 290: case 354: case 386: | 
					
						
							|  |  |  | 	case 418: case 450: case 482: case 514: | 
					
						
							| 
									
										
										
										
											2010-12-16 07:36:26 +00:00
										 |  |  | 		return 'P'; | 
					
						
							| 
									
										
										
										
											2014-02-16 15:30:18 -05:00
										 |  |  | 	case 326: case 390: case 454: case 486: | 
					
						
							| 
									
										
										
										
											2010-12-16 07:36:26 +00:00
										 |  |  | 	case 518: | 
					
						
							|  |  |  | 		return 'K'; | 
					
						
							|  |  |  | 	default: | 
					
						
							|  |  |  | 		return 'A'; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-02 19:46:55 -06:00
										 |  |  | } |