Skip to content

Commit ad033e8

Browse files
committed
Merge pull request #5 from meir000/master
A PlayOnlineViewer installation folder was set.
2 parents 8f866ab + 0d04349 commit ad033e8

File tree

4 files changed

+103
-28
lines changed

4 files changed

+103
-28
lines changed

xiloader/defines.h

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ This file is part of DarkStar-server source code.
4848
#define POLFUNC_INET_MUTEX 0x032F
4949
#define POLFUNC_REGISTRY_LANG 0x03C5
5050
#define POLFUNC_FFXI_LANG 0x01A4
51-
#define POLFUNC_INTERFACE_LANG 0x016F
51+
#define POLFUNC_REGISTRY_KEY 0x016F
52+
#define POLFUNC_INSTALL_FOLDER 0x007D
5253

5354
namespace xiloader
5455
{
@@ -72,14 +73,6 @@ namespace xiloader
7273
const CLSID CLSID_FFXiEntry = { 0x989D790D, 0x6236, 0x11D4, { 0x80, 0xE9, 0x00, 0x10, 0x5A, 0x81, 0xE8, 0x90 } };
7374
const IID IID_IFFXiEntry = { 0x989D790C, 0x6236, 0x11D4, { 0x80, 0xE9, 0x00, 0x10, 0x5A, 0x81, 0xE8, 0x90 } };
7475

75-
/* PlayOnline Registry Keys */
76-
const char RegistryKeys[3][255] =
77-
{
78-
{ "SOFTWARE\\PlayOnline" },
79-
{ "SOFTWARE\\PlayOnlineUS" },
80-
{ "SOFTWARE\\PlayOnlineEU" }
81-
};
82-
8376
/* PlayOnline Language Enumeration */
8477
enum Language
8578
{

xiloader/functions.cpp

Lines changed: 77 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -67,36 +67,97 @@ namespace xiloader
6767
return 0;
6868
}
6969

70+
/**
71+
* @brief Obtains the PlayOnline registry key.
72+
* "SOFTWARE\PlayOnlineXX"
73+
*
74+
* @param lang The language id the loader was started with.
75+
*
76+
* @return registry pathname.
77+
*/
78+
const char* functions::GetRegistryPlayOnlineKey(int lang)
79+
{
80+
static const char* RegistryKeys[3] =
81+
{
82+
"SOFTWARE\\PlayOnline", // xiloader::Japanese
83+
"SOFTWARE\\PlayOnlineUS", // xiloader::English
84+
"SOFTWARE\\PlayOnlineEU" // xiloader::European
85+
};
86+
87+
if(lang < 0)
88+
lang = 0;
89+
if(lang > 2)
90+
lang = 2;
91+
92+
return RegistryKeys[lang];
93+
}
94+
7095
/**
7196
* @brief Obtains the PlayOnline language id from the system registry.
7297
*
7398
* @param lang The language id the loader was started with.
7499
*
75100
* @return The language id from the registry, 1 otherwise.
76101
*/
77-
unsigned int functions::GetRegistryLanguage(int lang)
102+
int functions::GetRegistryPlayOnlineLanguage(int lang)
103+
{
104+
const char* SquareEnix = (lang == 0 /*xiloader::Japanese*/) ? "Square" : "SquareEnix";
105+
106+
char szRegistryPath[MAX_PATH];
107+
sprintf_s(szRegistryPath, MAX_PATH, "%s\\%s\\PlayOnlineViewer\\Settings", functions::GetRegistryPlayOnlineKey(lang), SquareEnix);
108+
109+
HKEY hKey = NULL;
110+
DWORD dwRegValue = 0;
111+
DWORD dwRegSize = sizeof(DWORD);
112+
DWORD dwRegType = REG_DWORD;
113+
114+
if (::RegOpenKeyExA(HKEY_LOCAL_MACHINE, szRegistryPath, 0, KEY_QUERY_VALUE | KEY_WOW64_32KEY, &hKey) == ERROR_SUCCESS)
115+
{
116+
if (::RegQueryValueExA(hKey, "Language", NULL, &dwRegType, (LPBYTE)&dwRegValue, &dwRegSize) == ERROR_SUCCESS)
117+
{
118+
if (dwRegType == REG_DWORD && dwRegSize == sizeof(DWORD))
119+
lang = (int) dwRegValue;
120+
}
121+
::RegCloseKey(hKey);
122+
}
123+
124+
return lang;
125+
}
126+
127+
/**
128+
* @brief Obtains the PlayOnlineViewer folder from the system registry.
129+
* "C:\Program Files\PlayOnline\PlayOnlineViewer"
130+
*
131+
* @param lang The language id the loader was started with.
132+
*
133+
* @return installation folder path.
134+
*/
135+
const char* functions::GetRegistryPlayOnlineInstallFolder(int lang)
78136
{
79-
const char szLanguageTags[4][255] = { { "" }, { "US" }, { "EU" }, { "EU" } };
80-
const char szLanguageTags2[4][255] = { { "" }, { "Enix" }, { "Enix" }, { "Enix" } };
81-
char szRegistryPath[MAX_PATH] = { 0 };
137+
static char InstallFolder[MAX_PATH] = {0};
82138

83-
HKEY hKey = NULL;
139+
char szRegistryPath[MAX_PATH];
140+
sprintf_s(szRegistryPath, MAX_PATH, "%s\\InstallFolder", functions::GetRegistryPlayOnlineKey(lang));
84141

85-
sprintf_s(szRegistryPath, MAX_PATH, "SOFTWARE\\PlayOnline%s\\Square%s\\PlayOnlineViewer\\Settings", szLanguageTags[lang], szLanguageTags2[lang]);
86-
if (!(::RegOpenKeyExA(HKEY_LOCAL_MACHINE, szRegistryPath, 0, KEY_QUERY_VALUE | KEY_WOW64_32KEY, &hKey) == ERROR_SUCCESS))
87-
return 1;
142+
HKEY hKey = NULL;
143+
DWORD dwRegSize = sizeof(InstallFolder);
144+
DWORD dwRegType = REG_SZ;
145+
bool found = false;
88146

89-
DWORD dwEntrySize = MAX_PATH;
90-
DWORD dwEntryType = REG_DWORD;
91-
DWORD dwLanguage = 0;
92-
if (!(::RegQueryValueExA(hKey, "Language", NULL, &dwEntryType, (LPBYTE)&dwLanguage, &dwEntrySize) == ERROR_SUCCESS))
147+
if (::RegOpenKeyExA( HKEY_LOCAL_MACHINE, szRegistryPath, 0, KEY_QUERY_VALUE | KEY_WOW64_32KEY, &hKey) == ERROR_SUCCESS)
93148
{
149+
if (::RegQueryValueExA(hKey, "1000", NULL, &dwRegType, (LPBYTE)InstallFolder, &dwRegSize) == ERROR_SUCCESS)
150+
{
151+
if (dwRegType == REG_SZ && dwRegSize > 0 && dwRegSize < sizeof(InstallFolder))
152+
found = true;
153+
}
94154
::RegCloseKey(hKey);
95-
return 1;
96155
}
97156

98-
::RegCloseKey(hKey);
99-
return dwLanguage;
157+
if (found == false)
158+
InstallFolder[0] = '\0';
159+
160+
return InstallFolder;
100161
}
101-
162+
102163
}; // namespace xiloader

xiloader/functions.h

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,34 @@ namespace xiloader
6767
*/
6868
static DWORD FindPattern(const char* moduleName, const unsigned char* lpPattern, const char* pszMask);
6969

70+
/**
71+
* @brief Obtains the PlayOnline registry key.
72+
* "SOFTWARE\PlayOnlineXX"
73+
*
74+
* @param lang The language id the loader was started with.
75+
*
76+
* @return registry pathname.
77+
*/
78+
static const char* GetRegistryPlayOnlineKey(int lang);
79+
7080
/**
7181
* @brief Obtains the PlayOnline language id from the system registry.
7282
*
7383
* @param lang The language id the loader was started with.
7484
*
7585
* @return The language id from the registry, 1 otherwise.
7686
*/
77-
static unsigned int GetRegistryLanguage(int lang);
87+
static int GetRegistryPlayOnlineLanguage(int lang);
88+
89+
/**
90+
* @brief Obtains the PlayOnlineViewer folder from the system registry.
91+
* "C:\Program Files\PlayOnline\PlayOnlineViewer"
92+
*
93+
* @param lang The language id the loader was started with.
94+
*
95+
* @return installation folder path.
96+
*/
97+
static const char* GetRegistryPlayOnlineInstallFolder(int lang);
7898
};
7999

80100
}; // namespace xiloader

xiloader/main.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,8 +354,9 @@ int __cdecl main(int argc, char* argv[])
354354

355355
/* Invoke the setup functions for polcore.. */
356356
lpCommandTable[POLFUNC_REGISTRY_LANG](g_Language);
357-
lpCommandTable[POLFUNC_FFXI_LANG](xiloader::functions::GetRegistryLanguage(g_Language));
358-
lpCommandTable[POLFUNC_INTERFACE_LANG](xiloader::RegistryKeys[g_Language]);
357+
lpCommandTable[POLFUNC_FFXI_LANG](xiloader::functions::GetRegistryPlayOnlineLanguage(g_Language));
358+
lpCommandTable[POLFUNC_REGISTRY_KEY](xiloader::functions::GetRegistryPlayOnlineKey(g_Language));
359+
lpCommandTable[POLFUNC_INSTALL_FOLDER](xiloader::functions::GetRegistryPlayOnlineInstallFolder(g_Language));
359360
lpCommandTable[POLFUNC_INET_MUTEX]();
360361

361362
/* Attempt to create FFXi instance..*/

0 commit comments

Comments
 (0)