From a73ad3554c8a33762d97dacd52bf38e888ab8d43 Mon Sep 17 00:00:00 2001
From: LPFaint99 <lpfaint99@gmail.com>
Date: Sun, 18 Dec 2011 21:42:20 -0800
Subject: [PATCH] add the function to read all unicode gamenames from a wad
 file

---
 Source/Core/DiscIO/Src/Volume.h      |  1 +
 Source/Core/DiscIO/Src/VolumeWad.cpp | 45 +++++++++++++++++++++++++++-
 Source/Core/DiscIO/Src/VolumeWad.h   |  1 +
 3 files changed, 46 insertions(+), 1 deletion(-)

diff --git a/Source/Core/DiscIO/Src/Volume.h b/Source/Core/DiscIO/Src/Volume.h
index f1bb5d3773..ec20e47b6c 100644
--- a/Source/Core/DiscIO/Src/Volume.h
+++ b/Source/Core/DiscIO/Src/Volume.h
@@ -38,6 +38,7 @@ public:
 	virtual std::string GetUniqueID() const = 0;
 	virtual std::string GetMakerID() const = 0;
 	virtual std::string GetName() const = 0;
+	virtual bool GetWName(std::vector<std::wstring>& _rwNames) const {return false;};
 	virtual u32 GetFSTSize() const = 0;
 	virtual std::string GetApploaderDate() const = 0;
 
diff --git a/Source/Core/DiscIO/Src/VolumeWad.cpp b/Source/Core/DiscIO/Src/VolumeWad.cpp
index 5fd81cca8b..0cdfc85925 100644
--- a/Source/Core/DiscIO/Src/VolumeWad.cpp
+++ b/Source/Core/DiscIO/Src/VolumeWad.cpp
@@ -107,6 +107,45 @@ bool CVolumeWAD::GetTitleID(u8* _pBuffer) const
 	return true;
 }
 
+bool CVolumeWAD::GetWName(std::vector<std::wstring>& _rwNames) const
+{
+	u32 footer_size;
+
+	if (!Read(0x1C, 4, (u8*)&footer_size))
+	{
+		return false;
+	}
+	//Japanese, English, German, French, Spanish, Italian, Dutch, unknown, unknown, Korean
+
+	// Offset to the english title
+	for (int i = 0; i < 10; i++)
+	{
+		u16 temp[42];
+		std::wstring out_temp;
+
+		if (!Read(0x9C + (i*84) + OpeningBnrOffset, 84, (u8*)&temp) || Common::swap32(footer_size) < 0xF1
+			|| !temp[0])
+		{
+			_rwNames.push_back(L"");
+			continue;
+		}
+		for (int i = 0; i < 42; ++i)
+		{
+			u16 t = Common::swap16(temp[i]);
+			if (t == 0 && i > 0)
+			{
+				if (out_temp.at(out_temp.size()-1) != ' ')
+					out_temp.push_back(' ');			
+			}
+			else
+				out_temp.push_back(t);
+		}
+
+		_rwNames.push_back(out_temp);
+	}
+	return true;
+}
+
 std::string CVolumeWAD::GetName() const
 {
 	u32 footer_size;
@@ -114,9 +153,13 @@ std::string CVolumeWAD::GetName() const
 	if (!Read(0x1C, 4, (u8*)&footer_size))
 		return "";
 
+
+	//Japanese, English, German, French, Spanish, Italian, Dutch, unknown, unknown, Korean
+
 	// Offset to the english title
 	char temp[84];
-	if (!Read(0xF1 + OpeningBnrOffset, 84, (u8*)&temp) || Common::swap32(footer_size) < 0xF1)
+	if (!Read(0xF1 + OpeningBnrOffset, 84, (u8*)&temp) || Common::swap32(footer_size) < 0xF1 ||
+		!Common::swap16(temp[0]))
 		return "";
 
 	// Remove the null bytes due to 16bit char length
diff --git a/Source/Core/DiscIO/Src/VolumeWad.h b/Source/Core/DiscIO/Src/VolumeWad.h
index 06bd772699..956844acd1 100644
--- a/Source/Core/DiscIO/Src/VolumeWad.h
+++ b/Source/Core/DiscIO/Src/VolumeWad.h
@@ -39,6 +39,7 @@ public:
 	std::string GetUniqueID() const;
 	std::string GetMakerID() const;
 	std::string GetName() const;
+	bool GetWName(std::vector<std::wstring>& _rwNames) const;
 	u32 GetFSTSize() const					{ return 0; }
 	std::string GetApploaderDate() const	{ return "0"; }	
 	ECountry GetCountry() const;