Beispiel #1
0
        public static UserSettings CreateDefaults()
        {
            var settings = new UserSettings();
            settings.ResetToDefaults();

            return settings;
        }
Beispiel #2
0
        static void SaveUserSettings(string fileName, UserSettings settings)
        {
            if (fileName == null)
                throw new ArgumentNullException("fileName");

            if (settings == null)
                throw new ArgumentNullException("settings");

            try
            {
                var xml = new XDocument(
                    new XDeclaration("1.0", "utf-8", "yes"),
                    new XElement("Settings",
                        new XAttribute("FileVersion", App.SettingsFileVersion),
                        settings.Serialize()));

                // Save user settings to file
                xml.Save(fileName);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(string.Format("Unable to save user settings: {0}", ex.Message));
            }
        }
Beispiel #3
0
        public UserSettingsViewModel(UserSettings userSettings)
            : base(null, null)
        {
            if (userSettings == null)
                throw new ArgumentNullException("userSettings");

            this.userSettings = userSettings;
        }
Beispiel #4
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();
                }
            }
        }
Beispiel #5
0
        static ClientVersion DetectClientVersion(UserSettings settings, IEnumerable<ClientVersion> availableVersions)
        {
            if (settings.ShouldAutoDetectClientVersion)
            {
                // Auto-detect using the computed MD5 hash
                using (var md5 = MD5.Create())
                {
                    var hashString = md5.ComputeHashString(settings.ClientExecutablePath);

                    // Find the client version by hash
                    Debug.WriteLine(string.Format("ClientHash = {0}", hashString));
                    return availableVersions.FirstOrDefault(x => x.Hash.Equals(hashString, StringComparison.OrdinalIgnoreCase));
                }
            }
            else
            {
                return availableVersions.FirstOrDefault(x => x.Name.Equals(settings.ClientVersion, StringComparison.OrdinalIgnoreCase));
            }
        }
Beispiel #6
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
        }
Beispiel #7
0
        public MainViewModel(UserSettings userSettings, IEnumerable<ClientVersion> clientVersions, IDialogService dialogService)
            : base(App.ApplicationName, dialogService)
        {
            if (userSettings == null)
                throw new ArgumentNullException("userSettings");

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

            if (dialogService == null)
                throw new ArgumentNullException("dialogService");

            this.userSettings = userSettings;
            this.clientVersions = clientVersions;

            // Create user settings view model
            this.userSettingsViewModel = new UserSettingsViewModel(userSettings);

            // Create client version view model for each client settings object (via LINQ projection)
            var viewModels = from v in clientVersions
                             orderby v.VersionCode descending
                             select new ClientVersionViewModel(v);

            this.clientVersionViewModels = new ObservableCollection<ClientVersionViewModel>(viewModels);
        }