示例#1
0
        static void PatchClient(UserSettings settings, SuspendedProcess process, ClientVersion clientVersion, IPAddress serverIPAddress, int serverPort)
        {
            if (settings.ShouldRedirectClient && serverIPAddress == null)
            {
                throw new ArgumentNullException("serverIPAddress", "Server IP address must be specified when redirecting the client");
            }

            if (settings.ShouldRedirectClient && serverPort <= 0)
            {
                throw new ArgumentOutOfRangeException("Server port number must be greater than zero when redirecting the client");
            }

            using (var stream = new ProcessMemoryStream(process.ProcessId))
                using (var patcher = new RuntimePatcher(clientVersion, stream, leaveOpen: true))
                {
                    // Apply server hostname/port patch
                    if (settings.ShouldRedirectClient && clientVersion.ServerHostnamePatchAddress > 0 && clientVersion.ServerPortPatchAddress > 0)
                    {
                        Debug.WriteLine("Applying server redirect patch...");
                        patcher.ApplyServerHostnamePatch(serverIPAddress);
                        patcher.ApplyServerPortPatch(serverPort);
                    }

                    // Apply intro video patch
                    if (settings.ShouldSkipIntro && clientVersion.IntroVideoPatchAddress > 0)
                    {
                        Debug.WriteLine("Applying intro video patch...");
                        patcher.ApplySkipIntroVideoPatch();
                    }

                    // Apply multiple instances patch
                    if (settings.ShouldAllowMultipleInstances && clientVersion.MultipleInstancePatchAddress > 0)
                    {
                        Debug.WriteLine("Applying multiple instance patch...");
                        patcher.ApplyMultipleInstancesPatch();
                    }

                    // Apply hide walls patch
                    if (settings.ShouldHideWalls && clientVersion.HideWallsPatchAddress > 0)
                    {
                        Debug.WriteLine("Applying hide walls patch...");
                        patcher.ApplyHideWallsPatch();
                    }
                }
        }
示例#2
0
        void LaunchClientWithSettings(UserSettings settings, IEnumerable <ClientVersion> clientVersions)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            if (clientVersions == null)
            {
                throw new ArgumentNullException("clientVersions");
            }

            IPAddress     serverIPAddress = null;
            int           serverPort      = settings.ServerPort;
            ClientVersion clientVersion   = null;

            #region Validate Client Executable Path
            if (!File.Exists(settings.ClientExecutablePath))
            {
                Debug.WriteLine("ClientExecutableNotFound: {0}", settings.ClientExecutablePath);

                this.DialogService.ShowOKDialog("File Not Found",
                                                "Unable to locate the client executable.",
                                                string.Format("Ensure the file exists at the following location:\n{0}", settings.ClientExecutablePath));

                return;
            }
            #endregion

            #region Determine Client Version

            try
            {
                // Detect client version
                clientVersion = DetectClientVersion(settings, clientVersions);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(string.Format("UnableToDetectClient: {0}", ex.Message));

                this.DialogService.ShowOKDialog("Unable to Detect Version",
                                                "Unable to detect the client version.",
                                                ex.Message);

                return;
            }

            // Check that a client version was determined
            if (clientVersion == null)
            {
                Debug.WriteLine("ClientVersionNotFound: Auto-Detect={0}, VersionName={1}", settings.ShouldAutoDetectClientVersion, settings.ClientVersion);

                this.DialogService.ShowOKDialog("Unknown Client Version",
                                                "Unable to determine the client version.",
                                                "You may manually select a client version by disabling auto-detection.");

                return;
            }
            #endregion

            #region Lookup Hostname for Redirect
            if (settings.ShouldRedirectClient)
            {
                try
                {
                    // Resolve the hostname via DNS
                    serverIPAddress = ResolveHostname(settings.ServerHostname);
                    Debug.WriteLine(string.Format("Resolved '{0}' -> {1}", settings.ServerHostname, serverIPAddress));

                    // An error occured when trying to resolve the hostname to an IPv4 address
                    if (serverIPAddress == null)
                    {
                        Debug.WriteLine(string.Format("NoIPv4AddressFoundForHost: {0}", settings.ServerHostname));

                        this.DialogService.ShowOKDialog("Unable to Resolve Hostname",
                                                        "Unable to resolve the server hostname to an IPv4 address.",
                                                        "Check your network connection and try again.");

                        return;
                    }
                }
                catch (Exception ex)
                {
                    // An error occured when trying to resolve the hostname
                    Debug.WriteLine(string.Format("UnableToResolveHostname: {0}", ex.Message));

                    this.DialogService.ShowOKDialog("Unable to Resolve Hostname",
                                                    "Unable to resolve the server hostname.",
                                                    "Check your network connection and try again.");

                    return;
                }
            }
            #endregion

            #region Launch and Patch Client
            try
            {
                Debug.WriteLine(string.Format("ClientVersion = {0}", clientVersion.Name));

                // Try to launch the client
                using (var process = SuspendedProcess.Start(settings.ClientExecutablePath))
                {
                    try
                    {
                        PatchClient(settings, process, clientVersion, serverIPAddress, serverPort);
                    }
                    catch (Exception ex)
                    {
                        // An error occured trying to patch the client
                        Debug.WriteLine(string.Format("UnableToPatchClient: {0}", ex.Message));

                        this.DialogService.ShowOKDialog("Failed to Patch",
                                                        "Unable to patch the client executable.",
                                                        ex.Message);
                    }
                }
            }
            catch (Exception ex)
            {
                // An error occured trying to launch the client
                Debug.WriteLine(string.Format("UnableToLaunchClient: {0}", ex.Message));

                this.DialogService.ShowOKDialog("Failed to Launch",
                                                "Unable to launch the client executable.",
                                                ex.Message);
            }
            #endregion
        }