summaryrefslogtreecommitdiff
path: root/Source/Core/DiscIO/Src/BannerLoaderGC.cpp
blob: 58b79d12db636420c6f0f03d2e1419ca5d1a5ace (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
// Copyright 2013 Dolphin Emulator Project
// Licensed under GPLv2
// Refer to the license.txt file included.

// HyperIris: need clean code
#include "../../Core/Src/ConfigManager.h"

#include "ColorUtil.h"
#include "BannerLoaderGC.h"

namespace DiscIO
{
CBannerLoaderGC::CBannerLoaderGC(DiscIO::IFileSystem& _rFileSystem, DiscIO::IVolume* volume)
	: m_pBannerFile(NULL)
	, m_IsValid(false)
	, m_country(volume->GetCountry())
{
	// load the opening.bnr
	size_t FileSize = (size_t) _rFileSystem.GetFileSize("opening.bnr");
	if (FileSize == BNR1_SIZE || FileSize == BNR2_SIZE)
	{
		m_pBannerFile = new u8[FileSize];
		if (m_pBannerFile)
		{
			_rFileSystem.ReadFile("opening.bnr", m_pBannerFile, FileSize);
			m_BNRType = getBannerType();
			if (m_BNRType == BANNER_UNKNOWN)
				PanicAlertT("Invalid opening.bnr found in gcm:\n%s\n You may need to redump this game.",
					_rFileSystem.GetVolume()->GetName().c_str());
			else m_IsValid = true;
		}
	}
	else WARN_LOG(DISCIO, "Invalid opening.bnr size: %0lx",
		(unsigned long)FileSize);
}


CBannerLoaderGC::~CBannerLoaderGC()
{
	if (m_pBannerFile)
	{
		delete [] m_pBannerFile;
		m_pBannerFile = NULL;
	}
}


bool CBannerLoaderGC::IsValid()
{
	return m_IsValid;
}

bool CBannerLoaderGC::GetBanner(u32* _pBannerImage)
{
	if (!IsValid())
	{
		return false;
	}

	auto const pBanner = (DVDBanner*)m_pBannerFile;
	decode5A3image(_pBannerImage, pBanner->image, DVD_BANNER_WIDTH, DVD_BANNER_HEIGHT);

	return true;
}


std::vector<std::string> CBannerLoaderGC::GetNames()
{
	std::vector<std::string> names;

	if (!IsValid())
	{
		return names;
	}

	u32 name_count = 0;

	// find Banner type
	switch (m_BNRType)
	{
	case CBannerLoaderGC::BANNER_BNR1:
		name_count = 1;
		break;

	case CBannerLoaderGC::BANNER_BNR2:
		name_count = 6;
		break;

	default:
		break;
	}

	auto const banner = reinterpret_cast<const DVDBanner*>(m_pBannerFile);

	for (u32 i = 0; i != name_count; ++i)
	{
		auto& comment = banner->comment[i];

		if (comment.longTitle[0])
		{
			auto& data = comment.longTitle;
			names.push_back(GetDecodedString(data));
		}
		else
		{
			auto& data = comment.shortTitle;
			names.push_back(GetDecodedString(data));
		}
	}
	
	return names;
}


std::string CBannerLoaderGC::GetCompany()
{
	std::string company;

	if (IsValid())
	{
		auto const pBanner = (DVDBanner*)m_pBannerFile;
		auto& data = pBanner->comment[0].shortMaker;
		company = GetDecodedString(data);
	}

	return company;
}


std::vector<std::string> CBannerLoaderGC::GetDescriptions()
{
	std::vector<std::string> descriptions;

	if (!IsValid())
	{
		return descriptions;
	}

	u32 desc_count = 0;

	// find Banner type
	switch (m_BNRType)
	{
	case CBannerLoaderGC::BANNER_BNR1:
		desc_count = 1;
		break;

	// English, German, French, Spanish, Italian, Dutch
	case CBannerLoaderGC::BANNER_BNR2:
		desc_count = 6;
		break;

	default:
		break;
	}

	auto banner = reinterpret_cast<const DVDBanner*>(m_pBannerFile);

	for (u32 i = 0; i != desc_count; ++i)
	{
		auto& data = banner->comment[i].comment;
		descriptions.push_back(GetDecodedString(data));
	}

	return descriptions;
}


void CBannerLoaderGC::decode5A3image(u32* dst, u16* src, int width, int height)
{
	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++)
				{
					u32 RGBA = ColorUtil::Decode5A3(Common::swap16(src[ix]));
					dst[(y + iy) * width + (x + ix)] = RGBA;
				}
			}
		}
	}
}

CBannerLoaderGC::BANNER_TYPE CBannerLoaderGC::getBannerType()
{
	u32 bannerSignature = *(u32*)m_pBannerFile;
	CBannerLoaderGC::BANNER_TYPE type = CBannerLoaderGC::BANNER_UNKNOWN;
	switch (bannerSignature)
	{
	// "BNR1"
	case 0x31524e42:
		type = CBannerLoaderGC::BANNER_BNR1;
		break;

	// "BNR2"
	case 0x32524e42:
		type = CBannerLoaderGC::BANNER_BNR2;
		break;
	}
	return type;
}

} // namespace