@@ -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
0 commit comments