Example #1
0
    public async Task GeneratePasswordAsync()
    {
        // Correct the data in case it's out of range
        CorrectData();

        // Create a save
        var save = new PS1Password.SaveData
        {
            LivesCount = (byte)LivesCount,
            Continues  = (byte)ContinuesCount
        };

        // Set level states
        for (int i = 0; i < Levels.Length; i++)
        {
            save.WorldInfo[i].IsUnlocked  = Levels[i].IsUnlocked;
            save.WorldInfo[i].HasAllCages = Levels[i].HasAllCages;
        }

        // Set boss flags
        foreach (var lev in Levels.Where(x => x.HasBoss))
        {
            save.FinBossLevel = save.FinBossLevel.SetFlag(lev.BossFlag, lev.BeatBoss);
        }

        // Set flags
        save.FinBossLevel = save.FinBossLevel.SetFlag(FinBossLevel.HelpedMusician, HasHelpedTheMusician);

        // Validate the password
        var error = save.Validate();

        if (error != null)
        {
            Logger.Warn("Invalid R1 password: {0}", error);
            await Services.MessageUI.DisplayMessageAsync(Resources.R1Passwords_InvalidData, MessageType.Error);

            return;
        }

        // Get the password
        var password = new PS1Password(save, ModeSelection.SelectedValue);

        Password = password.ToString().ToUpper();
    }
Example #2
0
    public async Task LoadPasswordAsync()
    {
        var validationRule = new Utility_R1PasswordGenerator_PasswordValidationRule().Validate(Password, CultureInfo.CurrentCulture);

        if (!validationRule.IsValid)
        {
            return;
        }

        var password = new PS1Password(Password, ModeSelection.SelectedValue);
        var save     = password.Decode();

        if (save == null)
        {
            await Services.MessageUI.DisplayMessageAsync(Resources.R1Passwords_Invalid, MessageType.Error);

            return;
        }

        LivesCount     = save.LivesCount;
        ContinuesCount = save.Continues;

        // Set level states
        for (int i = 0; i < Levels.Length; i++)
        {
            Levels[i].IsUnlocked  = save.WorldInfo[i].IsUnlocked;
            Levels[i].HasAllCages = save.WorldInfo[i].HasAllCages;
        }

        // Set boss flags
        foreach (var lev in Levels.Where(x => x.HasBoss))
        {
            lev.BeatBoss = save.FinBossLevel.HasFlag(lev.BossFlag);
        }

        // Set flags
        HasHelpedTheMusician = save.FinBossLevel.HasFlag(FinBossLevel.HelpedMusician);
    }
    public override ValidationResult Validate(object value, CultureInfo cultureInfo)
    {
        var supportedChars = PS1Password.GetSupportedCharacters();

        if (value is not string s)
        {
            return(new ValidationResult(false, Resources.R1Passwords_Invalid));
        }

        if (s.Length != 10)
        {
            return(new ValidationResult(false, Resources.R1Passwords_InvalidLength));
        }

        char?invalidChar = s.Select(x => (char?)x).
                           FirstOrDefault(x => !supportedChars.Any(c => c.ToString().Equals(x.ToString(), StringComparison.InvariantCultureIgnoreCase)));

        if (invalidChar != null)
        {
            return(new ValidationResult(false, String.Format(Resources.R1Passwords_InvalidChar, invalidChar)));
        }

        return(ValidationResult.ValidResult);
    }