| 
									
										
										
										
											2009-07-28 21:32:10 +00:00
										 |  |  | // Copyright (C) 2003 Dolphin Project.
 | 
					
						
							| 
									
										
										
										
											2008-12-08 05:30:24 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | // This program is free software: you can redistribute it and/or modify
 | 
					
						
							|  |  |  | // it under the terms of the GNU General Public License as published by
 | 
					
						
							|  |  |  | // the Free Software Foundation, version 2.0.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // This program is distributed in the hope that it will be useful,
 | 
					
						
							|  |  |  | // but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					
						
							|  |  |  | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					
						
							|  |  |  | // GNU General Public License 2.0 for more details.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // A copy of the GPL 2.0 should have been included with the program.
 | 
					
						
							|  |  |  | // If not, see http://www.gnu.org/licenses/
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Official SVN repository and contact information can be found at
 | 
					
						
							|  |  |  | // http://code.google.com/p/dolphin-emu/
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-22 07:42:17 +00:00
										 |  |  | // HyperIris: need clean code
 | 
					
						
							|  |  |  | #include "../../Core/Src/ConfigManager.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-02-22 12:43:25 +00:00
										 |  |  | #include "ColorUtil.h"
 | 
					
						
							| 
									
										
										
										
											2008-12-08 05:30:24 +00:00
										 |  |  | #include "BannerLoaderGC.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace DiscIO | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | CBannerLoaderGC::CBannerLoaderGC(DiscIO::IFileSystem& _rFileSystem) | 
					
						
							|  |  |  | 	: m_pBannerFile(NULL), | 
					
						
							|  |  |  | 	m_IsValid(false) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	// load the opening.bnr
 | 
					
						
							| 
									
										
										
										
											2008-12-20 18:46:49 +00:00
										 |  |  | 	size_t FileSize = (size_t) _rFileSystem.GetFileSize("opening.bnr"); | 
					
						
							| 
									
										
										
										
											2010-01-11 05:07:56 +00:00
										 |  |  | 	if (FileSize == sizeof(DVDBanner) || FileSize == sizeof(DVDBanner2)) | 
					
						
							| 
									
										
										
										
											2008-12-08 05:30:24 +00:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		m_pBannerFile = new u8[FileSize]; | 
					
						
							| 
									
										
										
										
											2009-01-21 16:31:44 +00:00
										 |  |  | 		if (m_pBannerFile) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			_rFileSystem.ReadFile("opening.bnr", m_pBannerFile, FileSize); | 
					
						
							| 
									
										
										
										
											2010-01-11 05:07:56 +00:00
										 |  |  | 			m_BNRType = getBannerType(); | 
					
						
							|  |  |  | 			if (m_BNRType == BANNER_UNKNOWN) | 
					
						
							| 
									
										
										
										
											2011-01-13 02:05:58 +00:00
										 |  |  | 				PanicAlertT("Invalid opening.bnr found in gcm:\n%s\n You may need to redump this game.", | 
					
						
							| 
									
										
										
										
											2010-01-11 05:07:56 +00:00
										 |  |  | 					_rFileSystem.GetVolume()->GetName().c_str()); | 
					
						
							|  |  |  | 			else m_IsValid = true; | 
					
						
							| 
									
										
										
										
											2009-01-21 16:31:44 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2008-12-08 05:30:24 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-12-05 18:22:41 +00:00
										 |  |  | 	else WARN_LOG(DISCIO, "Invalid opening.bnr size: %0lx", | 
					
						
							|  |  |  | 		(unsigned long)FileSize); | 
					
						
							| 
									
										
										
										
											2008-12-08 05:30:24 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | CBannerLoaderGC::~CBannerLoaderGC() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2009-01-21 16:31:44 +00:00
										 |  |  | 	if (m_pBannerFile) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		delete [] m_pBannerFile; | 
					
						
							|  |  |  | 		m_pBannerFile = NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-12-08 05:30:24 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-11 05:07:56 +00:00
										 |  |  | bool CBannerLoaderGC::IsValid() | 
					
						
							| 
									
										
										
										
											2008-12-08 05:30:24 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-07-28 23:38:49 +00:00
										 |  |  | 	return m_IsValid; | 
					
						
							| 
									
										
										
										
											2008-12-08 05:30:24 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-11 05:07:56 +00:00
										 |  |  | bool CBannerLoaderGC::GetBanner(u32* _pBannerImage) | 
					
						
							| 
									
										
										
										
											2008-12-08 05:30:24 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	if (!IsValid()) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2009-07-28 23:38:49 +00:00
										 |  |  | 		return false; | 
					
						
							| 
									
										
										
										
											2008-12-08 05:30:24 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	DVDBanner2* pBanner = (DVDBanner2*)m_pBannerFile; | 
					
						
							|  |  |  | 	decode5A3image(_pBannerImage, pBanner->image, DVD_BANNER_WIDTH, DVD_BANNER_HEIGHT); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-28 23:38:49 +00:00
										 |  |  | 	return true; | 
					
						
							| 
									
										
										
										
											2008-12-08 05:30:24 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-11 05:07:56 +00:00
										 |  |  | bool CBannerLoaderGC::GetName(std::string _rName[]) | 
					
						
							| 
									
										
										
										
											2008-12-08 05:30:24 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-01-21 16:31:44 +00:00
										 |  |  | 	bool returnCode = false; | 
					
						
							| 
									
										
										
										
											2008-12-08 05:30:24 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (!IsValid()) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2009-07-28 23:38:49 +00:00
										 |  |  | 		return false; | 
					
						
							| 
									
										
										
										
											2008-12-08 05:30:24 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-21 16:31:44 +00:00
										 |  |  | 	// find Banner type
 | 
					
						
							| 
									
										
										
										
											2010-01-11 05:07:56 +00:00
										 |  |  | 	switch (m_BNRType) | 
					
						
							| 
									
										
										
										
											2009-01-21 16:31:44 +00:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2009-01-22 07:42:17 +00:00
										 |  |  | 	case CBannerLoaderGC::BANNER_BNR1: | 
					
						
							| 
									
										
										
										
											2009-01-21 16:31:44 +00:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2009-01-22 07:42:17 +00:00
										 |  |  | 			DVDBanner* pBanner = (DVDBanner*)m_pBannerFile; | 
					
						
							| 
									
										
										
										
											2009-02-09 15:41:28 +00:00
										 |  |  | 			char tempBuffer[65] = {0}; | 
					
						
							|  |  |  | 			if (pBanner->comment.longTitle[0]) | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				memcpy(tempBuffer, pBanner->comment.longTitle, 64); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			else | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				memcpy(tempBuffer, pBanner->comment.shortTitle, 32); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2009-02-12 13:03:39 +00:00
										 |  |  | 			for (int i = 0; i < 6; i++) | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				CopyToStringAndCheck(_rName[i], tempBuffer); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2009-02-03 15:03:34 +00:00
										 |  |  | 			returnCode = true; | 
					
						
							| 
									
										
										
										
											2009-01-21 16:31:44 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-01-22 07:42:17 +00:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	case CBannerLoaderGC::BANNER_BNR2: | 
					
						
							| 
									
										
										
										
											2009-01-21 16:31:44 +00:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2009-01-22 07:42:17 +00:00
										 |  |  | 			DVDBanner2* pBanner = (DVDBanner2*)m_pBannerFile; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-02-03 15:03:34 +00:00
										 |  |  | 			for (int i = 0; i < 6; i++) | 
					
						
							| 
									
										
										
										
											2009-01-22 07:42:17 +00:00
										 |  |  | 			{ | 
					
						
							| 
									
										
										
										
											2009-02-09 15:41:28 +00:00
										 |  |  | 				char tempBuffer[65] = {0}; | 
					
						
							|  |  |  | 				if (pBanner->comment[i].longTitle[0]) | 
					
						
							|  |  |  | 				{ | 
					
						
							|  |  |  | 					memcpy(tempBuffer, pBanner->comment[i].longTitle, 64); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				else | 
					
						
							|  |  |  | 				{ | 
					
						
							|  |  |  | 					memcpy(tempBuffer, pBanner->comment[i].shortTitle, 32); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				CopyToStringAndCheck(_rName[i], tempBuffer); | 
					
						
							| 
									
										
										
										
											2009-01-22 07:42:17 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2009-02-03 15:03:34 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			returnCode = true; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-21 16:31:44 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-01-22 07:42:17 +00:00
										 |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2009-03-07 08:07:11 +00:00
										 |  |  | 	default: | 
					
						
							|  |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2009-01-21 16:31:44 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-01-22 07:42:17 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2009-01-21 16:31:44 +00:00
										 |  |  | 	return returnCode; | 
					
						
							| 
									
										
										
										
											2008-12-08 05:30:24 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-11 05:07:56 +00:00
										 |  |  | bool CBannerLoaderGC::GetCompany(std::string& _rCompany) | 
					
						
							| 
									
										
										
										
											2008-12-08 05:30:24 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-02-07 17:31:35 +00:00
										 |  |  | 	_rCompany = "N/A"; | 
					
						
							| 
									
										
										
										
											2008-12-08 05:30:24 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (!IsValid()) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		return(false); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	DVDBanner2* pBanner = (DVDBanner2*)m_pBannerFile; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-28 23:38:49 +00:00
										 |  |  | 	CopyToStringAndCheck(_rCompany, pBanner->comment[0].shortMaker); | 
					
						
							| 
									
										
										
										
											2008-12-08 05:30:24 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-28 23:38:49 +00:00
										 |  |  | 	return true; | 
					
						
							| 
									
										
										
										
											2008-12-08 05:30:24 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-11 05:07:56 +00:00
										 |  |  | bool CBannerLoaderGC::GetDescription(std::string* _rDescription) | 
					
						
							| 
									
										
										
										
											2008-12-08 05:30:24 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-01-21 16:31:44 +00:00
										 |  |  | 	bool returnCode = false; | 
					
						
							| 
									
										
										
										
											2008-12-08 05:30:24 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (!IsValid()) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2009-07-28 23:38:49 +00:00
										 |  |  | 		return false; | 
					
						
							| 
									
										
										
										
											2008-12-08 05:30:24 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-21 16:31:44 +00:00
										 |  |  | 	// find Banner type
 | 
					
						
							| 
									
										
										
										
											2010-01-11 05:07:56 +00:00
										 |  |  | 	switch (m_BNRType) | 
					
						
							| 
									
										
										
										
											2008-12-08 05:30:24 +00:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2009-01-22 07:42:17 +00:00
										 |  |  | 	case CBannerLoaderGC::BANNER_BNR1: | 
					
						
							| 
									
										
										
										
											2009-01-21 16:31:44 +00:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2009-01-22 07:42:17 +00:00
										 |  |  | 			DVDBanner* pBanner = (DVDBanner*)m_pBannerFile; | 
					
						
							| 
									
										
										
										
											2009-02-03 15:03:34 +00:00
										 |  |  | 			char tempBuffer[129] = {0}; | 
					
						
							|  |  |  | 			memcpy(tempBuffer, pBanner->comment.comment, 128); | 
					
						
							| 
									
										
										
										
											2009-02-12 13:03:39 +00:00
										 |  |  | 			for (int i = 0; i < 6; i++) | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				CopyToStringAndCheck(_rDescription[i], tempBuffer); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2009-02-03 15:03:34 +00:00
										 |  |  | 			returnCode = true; | 
					
						
							| 
									
										
										
										
											2009-01-21 16:31:44 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-01-22 07:42:17 +00:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	case CBannerLoaderGC::BANNER_BNR2: | 
					
						
							| 
									
										
										
										
											2009-01-21 16:31:44 +00:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2009-01-22 07:42:17 +00:00
										 |  |  | 			DVDBanner2* pBanner = (DVDBanner2*)m_pBannerFile; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-02-03 15:03:34 +00:00
										 |  |  | 			for (int i = 0; i< 6; i++) | 
					
						
							| 
									
										
										
										
											2009-01-22 07:42:17 +00:00
										 |  |  | 			{ | 
					
						
							| 
									
										
										
										
											2009-02-03 15:03:34 +00:00
										 |  |  | 				char tempBuffer[129] = {0}; | 
					
						
							|  |  |  | 				memcpy(tempBuffer, pBanner->comment[i].comment, 128); | 
					
						
							| 
									
										
										
										
											2009-02-09 15:41:28 +00:00
										 |  |  | 				CopyToStringAndCheck(_rDescription[i], tempBuffer); | 
					
						
							| 
									
										
										
										
											2009-01-22 07:42:17 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2009-02-03 15:03:34 +00:00
										 |  |  | 			returnCode = true; | 
					
						
							| 
									
										
										
										
											2009-01-21 16:31:44 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-01-22 07:42:17 +00:00
										 |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2009-03-07 08:07:11 +00:00
										 |  |  | 	default: | 
					
						
							|  |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2009-01-21 16:31:44 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	return returnCode; | 
					
						
							| 
									
										
										
										
											2008-12-08 05:30:24 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-11 05:07:56 +00:00
										 |  |  | void CBannerLoaderGC::decode5A3image(u32* dst, u16* src, int width, int height) | 
					
						
							| 
									
										
										
										
											2008-12-08 05:30:24 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	for (int y = 0; y < height; y += 4) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		for (int x = 0; x < width; x += 4) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			for (int iy = 0; iy < 4; iy++, src += 4) | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				for (int ix = 0; ix < 4; ix++) | 
					
						
							|  |  |  | 				{ | 
					
						
							| 
									
										
										
										
											2009-02-22 12:43:25 +00:00
										 |  |  | 					u32 RGBA = ColorUtil::Decode5A3(Common::swap16(src[ix])); | 
					
						
							| 
									
										
										
										
											2008-12-08 05:30:24 +00:00
										 |  |  | 					dst[(y + iy) * width + (x + ix)] = RGBA; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2009-01-22 07:42:17 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | CBannerLoaderGC::BANNER_TYPE CBannerLoaderGC::getBannerType() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	u32 bannerSignature = *(u32*)m_pBannerFile; | 
					
						
							|  |  |  | 	CBannerLoaderGC::BANNER_TYPE type = CBannerLoaderGC::BANNER_UNKNOWN; | 
					
						
							|  |  |  | 	switch (bannerSignature) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 	case 0x31524e42: | 
					
						
							|  |  |  | 		type = CBannerLoaderGC::BANNER_BNR1; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case 0x32524e42: | 
					
						
							|  |  |  | 		type = CBannerLoaderGC::BANNER_BNR2; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return type; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2008-12-08 05:30:24 +00:00
										 |  |  | } // namespace
 |