Ejemplo n.º 1
0
        /// <summary>
        /// Attempts to unlock the provided cheat.
        /// </summary>
        /// <param name="cheat">The cheat to unlock</param>
        private void UnlockCheat(Cheat cheat)
        {
            if (!this.LockedCheatList.Contains(cheat))
            {
                throw new Exception("Cheat must be a locked cheat");
            }

            AccessTokens accessTokens = SettingsViewModel.GetInstance().AccessTokens;

            // We need the unlocked cheat, since the locked one does not include the payload
            try
            {
                UnlockedCheat unlockedCheat = SqualrApi.UnlockCheat(accessTokens.AccessToken, cheat.CheatId);

                BrowseViewModel.GetInstance().SetCoinAmount(unlockedCheat.RemainingCoins);

                this.LockedCheatList.Remove(cheat);
                this.UnlockedCheatList.Insert(0, unlockedCheat.Cheat);
                LibraryViewModel.GetInstance().OnUnlock(unlockedCheat.Cheat);
            }
            catch (Exception ex)
            {
                OutputViewModel.GetInstance().Log(OutputViewModel.LogLevel.Error, "Error unlocking cheat", ex);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Selects a specific game for which to view the store.
        /// </summary>
        /// <param name="game">The selected game.</param>
        public void SelectGame(Game game)
        {
            // Deselect current game
            this.IsCheatListLoading = true;
            this.LockedCheatList    = null;
            this.UnlockedCheatList  = null;

            Task.Run(() =>
            {
                try
                {
                    // Select new game
                    AccessTokens accessTokens = SettingsViewModel.GetInstance().AccessTokens;
                    StoreCheats storeCheats   = SqualrApi.GetStoreCheats(accessTokens.AccessToken, game.GameId);
                    this.LockedCheatList      = new FullyObservableCollection <Cheat>(storeCheats.LockedCheats);
                    this.UnlockedCheatList    = new FullyObservableCollection <Cheat>(storeCheats.UnlockedCheats);
                }
                catch (Exception ex)
                {
                    OutputViewModel.GetInstance().Log(OutputViewModel.LogLevel.Error, "Error loading cheats", ex);
                    BrowseViewModel.GetInstance().NavigateBack();
                }
                finally
                {
                    this.IsCheatListLoading = false;
                }
            });
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets the twitch oauth access tokens using the provided code.
        /// </summary>
        /// <param name="code">The one time use exchange code to receive the access tokens.</param>
        private void PerformLogin(String code)
        {
            try
            {
                AccessTokens accessTokens = SqualrApi.GetAccessTokens(code);
                User         user         = SqualrApi.GetTwitchUser(accessTokens.AccessToken);
                SqualrApi.Connect(accessTokens.AccessToken);

                SettingsViewModel.GetInstance().AccessTokens = accessTokens;
                BrowseViewModel.GetInstance().ActiveUser     = user;

                BrowseViewModel.GetInstance().IsLoggedIn = true;
            }
            catch (Exception ex)
            {
                OutputViewModel.GetInstance().Log(OutputViewModel.LogLevel.Fatal, "Error authorizing Twitch", ex);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Selects a specific game for which to view the store.
        /// </summary>
        /// <param name="library">The selected library.</param>
        private void SelectLibrary(Library library)
        {
            BrowseViewModel.GetInstance().Navigate(NavigationPage.LibraryEdit);

            Task.Run(() =>
            {
                try
                {
                    this.IsLibraryLoading = true;

                    // Deselect current library
                    this.ActiveLibrary   = null;
                    this.CheatsAvailable = null;
                    this.CheatsInLibrary = null;
                    this.RaisePropertyChanged(nameof(this.CheatsAvailable));
                    this.RaisePropertyChanged(nameof(this.CheatsInLibrary));

                    // Select library
                    AccessTokens accessTokens   = SettingsViewModel.GetInstance().AccessTokens;
                    LibraryCheats libraryCheats = SqualrApi.GetCheats(accessTokens.AccessToken, library.LibraryId);
                    SqualrApi.SetActiveLibrary(accessTokens.AccessToken, library.LibraryId);

                    this.ActiveLibrary   = library;
                    this.CheatsAvailable = new ObservableCollection <Cheat>(libraryCheats.CheatsAvailable);
                    this.CheatsInLibrary = new ObservableCollection <Cheat>(libraryCheats.CheatsInLibrary);
                    this.RaisePropertyChanged(nameof(this.CheatsAvailable));
                    this.RaisePropertyChanged(nameof(this.CheatsInLibrary));
                }
                catch (Exception ex)
                {
                    OutputViewModel.GetInstance().Log(OutputViewModel.LogLevel.Error, "Error loading cheats", ex);
                }
                finally
                {
                    this.IsLibraryLoading = false;
                }
            });
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Selects a specific game for which to view the store.
        /// </summary>
        /// <param name="game">The selected game.</param>
        private void SelectGame(Game game)
        {
            // Deselect current game
            this.SelectedGame         = null;
            this.Libraries            = null;
            this.IsLibraryListLoading = true;
            this.ActiveLibrary        = null;
            this.RaisePropertyChanged(nameof(this.Libraries));

            BrowseViewModel.GetInstance().Navigate(NavigationPage.LibrarySelect);

            Task.Run(() =>
            {
                try
                {
                    StoreViewModel.GetInstance().SelectGame(game);

                    // Select new game
                    AccessTokens accessTokens       = SettingsViewModel.GetInstance().AccessTokens;
                    IEnumerable <Library> libraries = SqualrApi.GetLibraries(accessTokens.AccessToken, game.GameId);

                    this.Libraries = new ObservableCollection <Library>(libraries);
                    this.RaisePropertyChanged(nameof(this.Libraries));

                    this.SelectedGame = game;
                }
                catch (Exception ex)
                {
                    OutputViewModel.GetInstance().Log(OutputViewModel.LogLevel.Error, "Error loading libraries", ex);
                    BrowseViewModel.GetInstance().Navigate(NavigationPage.GameSelect);
                }
                finally
                {
                    this.IsLibraryListLoading = false;
                }
            });
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Loads the list of games from the API.
        /// </summary>
        private void LoadGameList()
        {
            this.IsGameListLoading = true;
            this.GameList          = null;

            Task.Run(() =>
            {
                try
                {
                    AccessTokens accessTokens = SettingsViewModel.GetInstance().AccessTokens;
                    this.GameList             = SqualrApi.GetOwnedGameList(accessTokens.AccessToken);
                }
                catch (Exception ex)
                {
                    OutputViewModel.GetInstance().Log(OutputViewModel.LogLevel.Error, "Error fetching game list", ex);

                    BrowseViewModel.GetInstance().NavigateBack();
                }
                finally
                {
                    this.IsGameListLoading = false;
                }
            });
        }
Ejemplo n.º 7
0
 public BrowseView()
 {
     InitializeComponent();
     BindingContext = BrowseViewModel.GetInstance();
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Event fired when the stream commands need to be update.
        /// </summary>
        private void OnUpdate()
        {
            if (!this.IsConnected)
            {
                return;
            }

            try
            {
                lock (this.VoteLock)
                {
                    if (!this.IsConnected || !BrowseViewModel.GetInstance().IsLoggedIn)
                    {
                        return;
                    }

                    AccessTokens             accessTokens    = SettingsViewModel.GetInstance().AccessTokens;
                    IEnumerable <CheatVotes> cheatVotes      = SqualrApi.GetStreamActivationIds(accessTokens.AccessToken);
                    IEnumerable <Cheat>      candidateCheats = LibraryViewModel.GetInstance().CheatsInLibrary;

                    if (candidateCheats == null || this.PreviousCheatVotes == null || cheatVotes == null || this.PreviousCheatVotes.Count() != cheatVotes.Count())
                    {
                        this.PreviousCheatVotes = cheatVotes;
                        return;
                    }

                    // Get cheat IDs to activate based on increased vote counts
                    IEnumerable <Int32> cheatIdsToActivate = cheatVotes
                                                             .Join(
                        this.PreviousCheatVotes,
                        currentVote => currentVote.CheatId,
                        previousVote => previousVote.CheatId,
                        (currentVote, previousVote) => new { cheatId = currentVote.CheatId, currentCount = currentVote.VoteCount, previousCount = previousVote.VoteCount })
                                                             .Where(combinedVote => combinedVote.currentCount != combinedVote.previousCount)
                                                             .Select(combinedVote => combinedVote.cheatId);

                    // Add in new votes with no previous vote count
                    cheatIdsToActivate = cheatVotes
                                         .Select(vote => vote.CheatId)
                                         .Except(this.PreviousCheatVotes.Select(vote => vote.CheatId))
                                         .Concat(cheatIdsToActivate)
                                         .Distinct();

                    IEnumerable <Cheat> projectItemsToActivate = cheatIdsToActivate
                                                                 .Join(
                        candidateCheats,
                        cheatId => cheatId,
                        projectItem => projectItem?.CheatId,
                        (cheatId, projectItem) => projectItem);

                    IEnumerable <Cheat> projectItemsToDeactivate = cheatVotes
                                                                   .Join(
                        candidateCheats,
                        cheatVote => cheatVote.CheatId,
                        projectItem => projectItem?.CheatId,
                        (cheatId, projectItem) => projectItem)
                                                                   .Except(projectItemsToActivate);

                    // Handle activations
                    projectItemsToActivate.ForEach(item =>
                    {
                        item.IsActivated = true;

                        // Reset duration always
                        item.Duration = 0.0f;
                    });

                    // Notify which project items were activated such that Squalr can update the stream overlay
                    if (projectItemsToActivate.Count() > 0)
                    {
                        Task.Run(() =>
                        {
                            IEnumerable <Cheat> activatedProjectItems = candidateCheats
                                                                        .Select(item => item)
                                                                        .Where(item => !item.IsStreamDisabled)
                                                                        .Where(item => item.IsActivated);

                            IEnumerable <OverlayMeta> overlayMeta = activatedProjectItems
                                                                    .Select(item => new OverlayMeta(item.CheatId, item.Cooldown, item.Duration));

                            if (overlayMeta.Count() > 0)
                            {
                                try
                                {
                                    SqualrApi.UpdateOverlayMeta(accessTokens.AccessToken, overlayMeta.ToArray());
                                }
                                catch (Exception ex)
                                {
                                    OutputViewModel.GetInstance().Log(OutputViewModel.LogLevel.Error, "Error updating overlay cooldowns and durations", ex);
                                }
                            }
                        });
                    }

                    this.PreviousCheatVotes = cheatVotes;
                }
            }
            catch (Exception ex)
            {
                OutputViewModel.GetInstance().Log(OutputViewModel.LogLevel.Warn, "Error fetching activated cheats", ex);
            }
        }