Skip to content

Commit

Permalink
Merge pull request #5 from meir000/master
Browse files Browse the repository at this point in the history
A PlayOnlineViewer installation folder was set.
  • Loading branch information
teschnei committed Feb 23, 2016
2 parents 8f866ab + 0d04349 commit ad033e8
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 28 deletions.
11 changes: 2 additions & 9 deletions xiloader/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ This file is part of DarkStar-server source code.
#define POLFUNC_INET_MUTEX 0x032F
#define POLFUNC_REGISTRY_LANG 0x03C5
#define POLFUNC_FFXI_LANG 0x01A4
#define POLFUNC_INTERFACE_LANG 0x016F
#define POLFUNC_REGISTRY_KEY 0x016F
#define POLFUNC_INSTALL_FOLDER 0x007D

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

/* PlayOnline Registry Keys */
const char RegistryKeys[3][255] =
{
{ "SOFTWARE\\PlayOnline" },
{ "SOFTWARE\\PlayOnlineUS" },
{ "SOFTWARE\\PlayOnlineEU" }
};

/* PlayOnline Language Enumeration */
enum Language
{
Expand Down
93 changes: 77 additions & 16 deletions xiloader/functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,36 +67,97 @@ namespace xiloader
return 0;
}

/**
* @brief Obtains the PlayOnline registry key.
* "SOFTWARE\PlayOnlineXX"
*
* @param lang The language id the loader was started with.
*
* @return registry pathname.
*/
const char* functions::GetRegistryPlayOnlineKey(int lang)
{
static const char* RegistryKeys[3] =
{
"SOFTWARE\\PlayOnline", // xiloader::Japanese
"SOFTWARE\\PlayOnlineUS", // xiloader::English
"SOFTWARE\\PlayOnlineEU" // xiloader::European
};

if(lang < 0)
lang = 0;
if(lang > 2)
lang = 2;

return RegistryKeys[lang];
}

/**
* @brief Obtains the PlayOnline language id from the system registry.
*
* @param lang The language id the loader was started with.
*
* @return The language id from the registry, 1 otherwise.
*/
unsigned int functions::GetRegistryLanguage(int lang)
int functions::GetRegistryPlayOnlineLanguage(int lang)
{
const char* SquareEnix = (lang == 0 /*xiloader::Japanese*/) ? "Square" : "SquareEnix";

char szRegistryPath[MAX_PATH];
sprintf_s(szRegistryPath, MAX_PATH, "%s\\%s\\PlayOnlineViewer\\Settings", functions::GetRegistryPlayOnlineKey(lang), SquareEnix);

HKEY hKey = NULL;
DWORD dwRegValue = 0;
DWORD dwRegSize = sizeof(DWORD);
DWORD dwRegType = REG_DWORD;

if (::RegOpenKeyExA(HKEY_LOCAL_MACHINE, szRegistryPath, 0, KEY_QUERY_VALUE | KEY_WOW64_32KEY, &hKey) == ERROR_SUCCESS)
{
if (::RegQueryValueExA(hKey, "Language", NULL, &dwRegType, (LPBYTE)&dwRegValue, &dwRegSize) == ERROR_SUCCESS)
{
if (dwRegType == REG_DWORD && dwRegSize == sizeof(DWORD))
lang = (int) dwRegValue;
}
::RegCloseKey(hKey);
}

return lang;
}

/**
* @brief Obtains the PlayOnlineViewer folder from the system registry.
* "C:\Program Files\PlayOnline\PlayOnlineViewer"
*
* @param lang The language id the loader was started with.
*
* @return installation folder path.
*/
const char* functions::GetRegistryPlayOnlineInstallFolder(int lang)
{
const char szLanguageTags[4][255] = { { "" }, { "US" }, { "EU" }, { "EU" } };
const char szLanguageTags2[4][255] = { { "" }, { "Enix" }, { "Enix" }, { "Enix" } };
char szRegistryPath[MAX_PATH] = { 0 };
static char InstallFolder[MAX_PATH] = {0};

HKEY hKey = NULL;
char szRegistryPath[MAX_PATH];
sprintf_s(szRegistryPath, MAX_PATH, "%s\\InstallFolder", functions::GetRegistryPlayOnlineKey(lang));

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

DWORD dwEntrySize = MAX_PATH;
DWORD dwEntryType = REG_DWORD;
DWORD dwLanguage = 0;
if (!(::RegQueryValueExA(hKey, "Language", NULL, &dwEntryType, (LPBYTE)&dwLanguage, &dwEntrySize) == ERROR_SUCCESS))
if (::RegOpenKeyExA( HKEY_LOCAL_MACHINE, szRegistryPath, 0, KEY_QUERY_VALUE | KEY_WOW64_32KEY, &hKey) == ERROR_SUCCESS)
{
if (::RegQueryValueExA(hKey, "1000", NULL, &dwRegType, (LPBYTE)InstallFolder, &dwRegSize) == ERROR_SUCCESS)
{
if (dwRegType == REG_SZ && dwRegSize > 0 && dwRegSize < sizeof(InstallFolder))
found = true;
}
::RegCloseKey(hKey);
return 1;
}

::RegCloseKey(hKey);
return dwLanguage;
if (found == false)
InstallFolder[0] = '\0';

return InstallFolder;
}

}; // namespace xiloader
22 changes: 21 additions & 1 deletion xiloader/functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,34 @@ namespace xiloader
*/
static DWORD FindPattern(const char* moduleName, const unsigned char* lpPattern, const char* pszMask);

/**
* @brief Obtains the PlayOnline registry key.
* "SOFTWARE\PlayOnlineXX"
*
* @param lang The language id the loader was started with.
*
* @return registry pathname.
*/
static const char* GetRegistryPlayOnlineKey(int lang);

/**
* @brief Obtains the PlayOnline language id from the system registry.
*
* @param lang The language id the loader was started with.
*
* @return The language id from the registry, 1 otherwise.
*/
static unsigned int GetRegistryLanguage(int lang);
static int GetRegistryPlayOnlineLanguage(int lang);

/**
* @brief Obtains the PlayOnlineViewer folder from the system registry.
* "C:\Program Files\PlayOnline\PlayOnlineViewer"
*
* @param lang The language id the loader was started with.
*
* @return installation folder path.
*/
static const char* GetRegistryPlayOnlineInstallFolder(int lang);
};

}; // namespace xiloader
Expand Down
5 changes: 3 additions & 2 deletions xiloader/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,9 @@ int __cdecl main(int argc, char* argv[])

/* Invoke the setup functions for polcore.. */
lpCommandTable[POLFUNC_REGISTRY_LANG](g_Language);
lpCommandTable[POLFUNC_FFXI_LANG](xiloader::functions::GetRegistryLanguage(g_Language));
lpCommandTable[POLFUNC_INTERFACE_LANG](xiloader::RegistryKeys[g_Language]);
lpCommandTable[POLFUNC_FFXI_LANG](xiloader::functions::GetRegistryPlayOnlineLanguage(g_Language));
lpCommandTable[POLFUNC_REGISTRY_KEY](xiloader::functions::GetRegistryPlayOnlineKey(g_Language));
lpCommandTable[POLFUNC_INSTALL_FOLDER](xiloader::functions::GetRegistryPlayOnlineInstallFolder(g_Language));
lpCommandTable[POLFUNC_INET_MUTEX]();

/* Attempt to create FFXi instance..*/
Expand Down

0 comments on commit ad033e8

Please sign in to comment.