Beispiel #1
0
        internal static bool IsTranslationOutdated(Language language)
        {
            string selectedTranslationIniPath = Path.Combine(language.Path, Strings.IniName.Translation);

            if (!LoadPatcherIni(out IniFile translationIni, selectedTranslationIniPath))
            {
                return(true);
            }
            IniSection translationPatcherSection = translationIni.Sections[Strings.IniName.Patcher.Section];
            IniSection translationVerSection     = translationIni.Sections[Strings.IniName.Ver.Section];

            string clientIniPath = Path.Combine(UserSettings.GamePath, Strings.IniName.ClientVer);

            if (!LoadVerIni(out IniFile clientIni, clientIniPath))
            {
                throw new Exception(StringLoader.GetText("exception_generic_read_error", clientIniPath));
            }
            IniSection clientVerSection = clientIni.Sections[Strings.IniName.Ver.Section];

            string translationVer = translationVerSection.Keys[Strings.IniName.Ver.Key].Value;
            string clientVer      = clientVerSection.Keys[Strings.IniName.Ver.Key].Value;

            if (clientVer != translationVer)
            {
                return(true);
            }

            return(false);
        }
Beispiel #2
0
        internal static void CheckRunningProcesses(string regionId)
        {
            string[] processes = Methods.GetRunningGameProcesses(regionId).Union(Methods.GetRunningUpdaterProcesses()).ToArray();

            if (processes.Length > 0)
            {
                throw new Exception(StringLoader.GetText("exception_game_already_open", String.Join("/", processes)));
            }
        }
Beispiel #3
0
        internal static void CheckRunningUpdaters()
        {
            string[] processes = Methods.GetRunningUpdaterProcesses();

            if (processes.Length > 0)
            {
                throw new Exception(StringLoader.GetText("exception_game_already_open", string.Join("/", processes)));
            }
        }
Beispiel #4
0
        internal static void PatchExeFile(byte[] exeFileBytes, string gameExePatchedPath, string patchInstructionFilePath)
        {
            Logger.Debug(Methods.MethodFullName(MethodBase.GetCurrentMethod(), exeFileBytes.Length.ToString(), gameExePatchedPath, patchInstructionFilePath));

            using (var client = new WebClient())
            {
                string hexResult        = BitConverter.ToString(exeFileBytes).Replace("-", "");
                string patchedHexResult = String.Copy(hexResult);

                byte[] fileBytes = client.DownloadData(patchInstructionFilePath);
                var    ini       = new IniFile();
                using (var ms = new MemoryStream(fileBytes))
                {
                    ini.Load(ms);
                }

                foreach (IniSection section in ini.Sections)
                {
                    string original = section.Keys[Strings.IniName.PatchBytes.KeyOriginal].Value;
                    string patch    = section.Keys[Strings.IniName.PatchBytes.KeyPatch].Value;

                    patchedHexResult = patchedHexResult.Replace(original, patch);

                    if (hexResult == patchedHexResult)
                    {
                        Logger.Info($"Failed .exe patch=[{section.Name}]");
                        MsgBox.Error(StringLoader.GetText("error_exe_patch_fail", section.Name));

                        if (File.Exists(gameExePatchedPath))
                        {
                            File.Delete(gameExePatchedPath);
                        }

                        UserSettings.WantToPatchExe = false;

                        return;
                    }
                }

                int    charCount   = hexResult.Length;
                byte[] resultBytes = new byte[charCount / 2];

                for (int i = 0; i < charCount; i += 2)
                {
                    resultBytes[i / 2] = Convert.ToByte(patchedHexResult.Substring(i, 2), 16);
                }

                File.WriteAllBytes(gameExePatchedPath, resultBytes);
            }
        }
Beispiel #5
0
        internal static string GetGameExeName(string regionId)
        {
            switch (regionId)
            {
            case "jp":
            case "gjp":
                return(Strings.FileName.GameExeJP);

            case "kr":
            case "nkr":
                return(Strings.FileName.GameExeKR);

            case "gf":
                return(Strings.FileName.GameExeGF);

            default:
                throw new Exception(StringLoader.GetText("exception_region_unknown", regionId));
            }
        }
Beispiel #6
0
        internal static void EnsureDirectoryRights(string folderPath)
        {
            if (!Directory.Exists(folderPath))
            {
                throw new DirectoryNotFoundException(StringLoader.GetText("exception_directory_not_exist", folderPath));
            }

            FileSystemRights rights = FileSystemRights.Modify;

            if (!DirectoryHasRights(folderPath, rights))
            {
                string securityExePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, Strings.FileName.SecurityExe);

                var startInfo = new ProcessStartInfo
                {
                    UseShellExecute = true,
                    Verb            = "runas",
                    Arguments       = $"\"{folderPath}\" \"{rights}\"",
                    FileName        = securityExePath
                };

                var process = Process.Start(startInfo);
                process.WaitForExit();

                int exitCode = process.ExitCode;

                if (exitCode != 0)
                {
                    if (exitCode == -2)
                    {
                        throw new DirectoryNotFoundException(StringLoader.GetText("exception_directory_not_exist", folderPath));
                    }
                    else
                    {
                        throw new Exception(StringLoader.GetText("exception_directory_rights", folderPath));
                    }
                }
            }
        }
Beispiel #7
0
        internal static IniFile GetJPServerIni()
        {
            using (var client = new WebClient())
            {
                try
                {
                    byte[] iniBytes = client.DownloadData(Urls.SoulworkerSettingsHome + Strings.IniName.ServerVer);

                    var ini = new IniFile();
                    using (var ms = new MemoryStream(iniBytes))
                    {
                        ini.Load(ms);
                    }

                    return(ini);
                }
                catch (WebException e)
                {
                    if (e.InnerException is SocketException innerException)
                    {
                        if (innerException.SocketErrorCode == SocketError.ConnectionRefused)
                        {
                            throw new Exception(StringLoader.GetText("exception_server_refused_connection"));
                        }
                        else
                        {
                            throw;
                        }
                    }
                    else
                    {
                        throw;
                    }
                }
            }
        }
Beispiel #8
0
 internal static void RegionDoesNotSupportExePatch()
 {
     UserSettings.WantToPatchExe = false;
     throw new Exception(StringLoader.GetText("error_exe_region_not_supported"));
 }
Beispiel #9
0
 internal static void RegionDoesNotSupportLogin()
 {
     UserSettings.WantToLogin = false;
     throw new Exception(StringLoader.GetText("exception_login_option_not_supported"));
 }