Example #1
0
        public override void OnGameStarted(OnGameStartedEventArgs args)
        {
            var game = args.Game;

            if (game.Features == null || game.Features.Count == 0)
            {
                return;
            }

            if (settings.Settings.ChangeResOnlyGamesNotRunning && IsAnyOtherGameRunning(game))
            {
                logger.Debug("Another game was detected as running during game start");
                return;
            }

            foreach (var feature in game.Features)
            {
                var resMatch = Regex.Match(feature.Name, @"^\[RC\] (\d+)x(\d+)$", RegexOptions.IgnoreCase);
                if (resMatch.Success)
                {
                    var width           = int.Parse(resMatch.Groups[1].Value);
                    var height          = int.Parse(resMatch.Groups[2].Value);
                    var resChangeResult = ChangeResolution(width, height);
                    if (resChangeResult)
                    {
                        resolutionChanged = true;
                    }

                    break;
                }
            }
        }
        public override void OnGameStarted(OnGameStartedEventArgs args)
        {
            var game = args.Game;

            if (game.IsInstalled == false)
            {
                return;
            }

            if (BuiltinExtensions.GetExtensionFromId(game.PluginId) != BuiltinExtension.SteamLibrary)
            {
                return;
            }

            string modeFeatureName = GetModeFeatureName();

            if (game.Features != null)
            {
                var matchingFeature = game.Features.Where(f => f.Name == modeFeatureName);
                if (settings.Settings.LaunchMode == 0 && matchingFeature.Count() > 0)
                {
                    logger.Info(String.Format("Stopped execution in game \"{0}\". Global mode and game has \"{1}\" feature", game.Name, modeFeatureName));
                    return;
                }
                else if (settings.Settings.LaunchMode == 1 && matchingFeature.Count() == 0)
                {
                    logger.Info(String.Format("Stopped execution in game \"{0}\". Selective mode and game doesn't have \"{1}\" feature", game.Name, modeFeatureName));
                    return;
                }
            }

            LaunchSteam();
        }
Example #3
0
 public override void OnGameStarted(OnGameStartedEventArgs args)
 {
     if (SupportedEvents.Contains(ApplicationEvent.OnGameStarted))
     {
         InvokeFunction(ApplicationEvent.OnGameStarted.ToString(), new List <object> {
             args
         });
     }
 }
 public override void OnGameStarted(OnGameStartedEventArgs args)
 {
     // Add code to be executed when game is started running.
 }
Example #5
0
 public override void OnGameStarted(OnGameStartedEventArgs args)
 {
     logger.Info($"TestPluginDev OnGameStarted {args.Game.Name}");
     logger.Warn(PlayniteApi.ApplicationSettings.CompletionStatus.PlayedStatus.ToString());
 }
 public override void OnGameStarted(OnGameStartedEventArgs args)
 {
     // Add code to be executed when game is started running.
     //needs to be sync or it won't speak out full text
 }
 // Add code to be executed when game is started running.
 public override void OnGameStarted(OnGameStartedEventArgs args)
 {
 }
Example #8
0
 /// <summary>
 /// Called when game has started.
 /// </summary>
 public virtual void OnGameStarted(OnGameStartedEventArgs args)
 {
 }
        public override void OnGameStarted(OnGameStartedEventArgs args)
        {
            if (isSuspended)
            {
                SwitchGameState();
            }

            var game = args.Game;

            if (game.Features != null && game.Features.Any(a => a.Name.Equals("[PlayState] Blacklist", StringComparison.OrdinalIgnoreCase)))
            {
                logger.Info($"{game.Name} is in PlayState blacklist. Extension execution stopped");
                return;
            }

            suspendPlaytimeOnly = false;
            if (settings.Settings.SubstractSuspendedPlaytimeOnStopped &&
                (settings.Settings.GlobalOnlySuspendPlaytime ||
                 game.Features != null && game.Features.Any(a => a.Name.Equals("[PlayState] Suspend Playtime only", StringComparison.OrdinalIgnoreCase))))
            {
                suspendPlaytimeOnly            = true;
                currentGame                    = game;
                splashWindowViewModel.GameName = currentGame.Name;
                gameProcesses                  = null;
                CreateGameStopwatchTuple(game);
                return;
            }

            Task.Run(async() =>
            {
                currentGame = game;
                splashWindowViewModel.GameName = currentGame.Name;
                gameProcesses = null;
                isSuspended   = false;
                logger.Debug($"Changed game to {currentGame.Name} game processes");
                var sourceAction = args.SourceAction;
                if (sourceAction?.Type == GameActionType.Emulator)
                {
                    var emulatorProfileId = sourceAction.EmulatorProfileId;
                    if (emulatorProfileId.StartsWith("#builtin_"))
                    {
                        //Currently it isn't possible to obtain the emulator path
                        //for emulators using Builtin profiles
                        return;
                    }

                    var emulator = PlayniteApi.Database.Emulators[sourceAction.EmulatorId];
                    var profile  = emulator?.CustomProfiles.FirstOrDefault(p => p.Id == emulatorProfileId);
                    if (profile != null)
                    {
                        gameProcesses = GetProcessesWmiQuery(false, profile.Executable.ToLower());
                        if (gameProcesses.Count > 0)
                        {
                            CreateGameStopwatchTuple(game);
                        }
                    }
                    return;
                }

                if (string.IsNullOrEmpty(game.InstallDirectory))
                {
                    return;
                }
                gameInstallDir = game.InstallDirectory.ToLower();

                // Fix for some games that take longer to start, even when already detected as running
                await Task.Delay(15000);
                if (CurrentGameChanged(game))
                {
                    return;
                }

                gameProcesses = GetProcessesWmiQuery(true);
                if (gameProcesses.Count > 0)
                {
                    logger.Debug($"Found {gameProcesses.Count} game processes");
                    CreateGameStopwatchTuple(game);
                    return;
                }

                // Waiting is useful for games that use a startup launcher, since
                // it can take some time before the user launches the game from it
                await Task.Delay(40000);
                var filterPaths = true;
                for (int i = 0; i < 10; i++)
                {
                    // This is done to stop execution in case a new game was launched
                    // or the launched game was closed
                    if (CurrentGameChanged(game))
                    {
                        return;
                    }

                    // Try a few times with filters.
                    // If nothing is found, try without filters. This helps in cases
                    // where the active process is being filtered out by filters
                    if (i == 5)
                    {
                        filterPaths = false;
                    }
                    gameProcesses = GetProcessesWmiQuery(filterPaths);
                    if (gameProcesses.Count > 0)
                    {
                        logger.Debug($"Found {gameProcesses.Count} game processes");
                        CreateGameStopwatchTuple(game);
                        return;
                    }
                    else
                    {
                        await Task.Delay(15000);
                    }
                }

                logger.Debug("Couldn't find any game process");
            });
        }