Ejemplo n.º 1
0
 //
 protected void onReadyCallback(GameControllerEventArgs e)
 {
     if (null != this.GameControllerEvents)
     {
         this.GameControllerEvents(this, e);
     }
 }
Ejemplo n.º 2
0
        private void Controllers_Installed(object sender, GameControllerEventArgs args)
        {
            var game = args.Controller.Game;

            logger.Info($"Game {game.Name} installed after {args.EllapsedTime} seconds.");

            var dbGame = database.GetGame(game.Id);

            dbGame.State.Installing = false;
            dbGame.State.Installed  = true;
            dbGame.InstallDirectory = args.Controller.Game.InstallDirectory;

            if (dbGame.PlayTask == null)
            {
                dbGame.PlayTask = args.Controller.Game.PlayTask;
            }

            if (dbGame.OtherTasks == null)
            {
                dbGame.OtherTasks = args.Controller.Game.OtherTasks;
            }

            database.UpdateGameInDatabase(dbGame);
            Controllers.RemoveController(args.Controller);
        }
Ejemplo n.º 3
0
        private void Controllers_Installed(object sender, GameControllerEventArgs args)
        {
            var game = args.Controller.Game;

            logger.Info($"Game {game.Name} installed after {args.EllapsedTime} seconds.");

            var dbGame = database.Games.Get(game.Id);

            dbGame.IsInstalling     = false;
            dbGame.IsInstalled      = true;
            dbGame.InstallDirectory = args.Controller.Game.InstallDirectory;

            if (dbGame.PlayAction == null)
            {
                dbGame.PlayAction = args.Controller.Game.PlayAction;
            }

            if (dbGame.OtherActions == null)
            {
                dbGame.OtherActions = args.Controller.Game.OtherActions;
            }

            database.Games.Update(dbGame);
            controllers.RemoveController(args.Controller);
        }
Ejemplo n.º 4
0
        private void Controllers_Stopped(object sender, GameControllerEventArgs args)
        {
            var game = args.Controller.Game;

            logger.Info($"Game {game.Name} stopped after {args.EllapsedTime} seconds.");

            var dbGame = Database.Games.Get(game.Id);

            dbGame.IsRunning   = false;
            dbGame.IsLaunching = false;
            dbGame.Playtime   += args.EllapsedTime;
            Database.Games.Update(dbGame);
            controllers.RemoveController(args.Controller);
            if (application.Mode == ApplicationMode.Desktop)
            {
                if (appSettings.AfterGameClose == AfterGameCloseOptions.Restore)
                {
                    application.Restore();
                }
            }
            else
            {
                application.Restore();
            }
        }
Ejemplo n.º 5
0
        private void Controllers_Started(object sender, GameControllerEventArgs args)
        {
            var game = args.Controller.Game;

            logger.Info($"Started {game.Name} game.");
            UpdateGameState(game.Id, null, true, null, null, false);
            if (Application.Mode == ApplicationMode.Desktop)
            {
                if (AppSettings.AfterLaunch == AfterLaunchOptions.Close)
                {
                    Application.Quit();
                }
                else if (AppSettings.AfterLaunch == AfterLaunchOptions.Minimize)
                {
                    Application.Minimize();
                }
            }
            else
            {
                if (AppSettings.AfterLaunch == AfterLaunchOptions.Close)
                {
                    Application.Quit();
                }
                else
                {
                    Application.Minimize();
                }
            }
        }
Ejemplo n.º 6
0
 void OnBeginFire(object sender, GameControllerEventArgs e)
 {
     if (currentGunMan != null)
     {
         currentGunMan.AboutFire(GameController.Instrance.StopWatch);
     }
 }
Ejemplo n.º 7
0
 private void GameControllerEventHandler(object sender, GameControllerEventArgs args)
 {
     foreach (var controllerEvent in args.ControllerEvents)
     {
         var controllerEventViewModel = ControllerEventList.FirstOrDefault(ce => ce.EventType == controllerEvent.Key.EventType && ce.EventCode == controllerEvent.Key.EventCode);
         if (0.1F < Math.Abs(controllerEvent.Value))
         {
             if (controllerEventViewModel != null)
             {
                 controllerEventViewModel.Value = controllerEvent.Value;
             }
             else
             {
                 ControllerEventList.Add(new GameControllerEventViewModel(controllerEvent.Key.EventType, controllerEvent.Key.EventCode, controllerEvent.Value));
             }
         }
         else
         {
             if (controllerEventViewModel != null)
             {
                 ControllerEventList.Remove(controllerEventViewModel);
             }
         }
     }
 }
Ejemplo n.º 8
0
        private void GuildWars2GameController_Stopped(object sender, GameControllerEventArgs controller)
        {
            var accountData = this.settings.GuildWars2Accounts.FirstOrDefault(a => a.InternalId.ToString() == this.Game.GameId);

            string appData         = Path.Combine(GetFolderPath(SpecialFolder.ApplicationData), "Guild Wars 2");
            string localDat        = Path.Combine(appData, "Local.dat");
            string sourceDat       = Path.Combine(appData, $"Local.dat.{accountData.Id}");
            string sourceDatBackup = Path.Combine(appData, $"Local.dat.{accountData.Id}._bak");

            if (File.Exists(sourceDatBackup))
            {
                File.Delete(sourceDatBackup);
            }
            if (File.Exists(sourceDat))
            {
                File.Move(sourceDat, sourceDatBackup);
            }
            File.Copy(localDat, sourceDat);
            if (File.Exists(sourceDatBackup))
            {
                File.Delete(sourceDatBackup);
            }

            this.Stopped -= this.GuildWars2GameController_Stopped;
        }
Ejemplo n.º 9
0
        private void Controllers_Stopped(object sender, GameControllerEventArgs args)
        {
            var game = args.Controller.Game;

            logger.Info($"Game {game.Name} stopped after {args.EllapsedTime} seconds.");

            var dbGame = database.GetGame(game.Id);

            dbGame.State.Running = false;
            dbGame.Playtime     += args.EllapsedTime;
            database.UpdateGameInDatabase(dbGame);
            Controllers.RemoveController(args.Controller);
        }
Ejemplo n.º 10
0
        private void Controllers_Uninstalled(object sender, GameControllerEventArgs args)
        {
            var game = args.Controller.Game;

            logger.Info($"Game {game.Name} uninstalled after {args.EllapsedTime} seconds.");

            var dbGame = Database.Games.Get(game.Id);

            dbGame.IsUninstalling   = false;
            dbGame.IsInstalled      = false;
            dbGame.InstallDirectory = string.Empty;
            Database.Games.Update(dbGame);
            controllers.RemoveController(args.Controller);
        }
Ejemplo n.º 11
0
        private void Controllers_Started(object sender, GameControllerEventArgs args)
        {
            var game = args.Controller.Game;

            logger.Info($"Started {game.Name} game.");
            UpdateGameState(game.Id, null, true, null, null, false);

            if (appSettings.AfterLaunch == AfterLaunchOptions.Close)
            {
                App.CurrentApp.Quit();
            }
            else if (appSettings.AfterLaunch == AfterLaunchOptions.Minimize)
            {
                Application.Current.MainWindow.WindowState = WindowState.Minimized;
            }
        }
Ejemplo n.º 12
0
        private void Controllers_Stopped(object sender, GameControllerEventArgs args)
        {
            var game = args.Controller.Game;

            logger.Info($"Game {game.Name} stopped after {args.EllapsedTime} seconds.");

            var dbGame = database.GetGame(game.Id);

            dbGame.State.Running = false;
            dbGame.Playtime     += args.EllapsedTime;
            database.UpdateGameInDatabase(dbGame);
            controllers.RemoveController(args.Controller);

            if (appSettings.AfterGameClose == AfterGameCloseOptions.Restore)
            {
                App.CurrentApp.MainViewWindow.RestoreWindow();
            }
        }
Ejemplo n.º 13
0
 private void Controller_Uninstalled(object sender, GameControllerEventArgs e)
 {
     Uninstalled?.Invoke(this, e);
 }
Ejemplo n.º 14
0
 private void Controller_Started(object sender, GameControllerEventArgs e)
 {
     Started?.Invoke(this, e);
 }
Ejemplo n.º 15
0
 //
 protected void onReadyCallback(GameControllerEventArgs e)
 {
     if (null != this.GameControllerEvents)
     {
         this.GameControllerEvents(this, e);
     }
 }
Ejemplo n.º 16
0
        private void Controllers_Started(object sender, GameControllerEventArgs args)
        {
            var game = args.Controller.Game;

            logger.Info($"Started {game.Name} game.");
            UpdateGameState(game.Id, null, true, null, null, false);
            gameStartups.TryAdd(game.Id, DateTime.Now);

            if (!AppSettings.GameStartedScript.IsNullOrWhiteSpace() && game.UseGlobalGameStartedScript)
            {
                try
                {
                    var expanded = game.ExpandVariables(AppSettings.GameStartedScript);
                    ExecuteScriptAction(AppSettings.ActionsScriptLanguage, expanded, game);
                }
                catch (Exception exc) when(!PlayniteEnvironment.ThrowAllErrors)
                {
                    var message = exc.Message;

                    if (exc is ScriptRuntimeException err)
                    {
                        message = err.Message + "\n\n" + err.ScriptStackTrace;
                    }

                    logger.Error(exc, "Failed to execute global game-started action.");
                    logger.Error(AppSettings.GameStartedScript);
                    Dialogs.ShowMessage(
                        message,
                        resources.GetString("LOCErrorGlobalScriptAction"),
                        MessageBoxButton.OK,
                        MessageBoxImage.Error);
                }
            }

            if (!game.GameStartedScript.IsNullOrWhiteSpace())
            {
                try
                {
                    var expanded = game.ExpandVariables(game.GameStartedScript);
                    ExecuteScriptAction(game.ActionsScriptLanguage, expanded, game);
                }
                catch (Exception exc) when(!PlayniteEnvironment.ThrowAllErrors)
                {
                    var message = exc.Message;

                    if (exc is ScriptRuntimeException err)
                    {
                        message = err.Message + "\n\n" + err.ScriptStackTrace;
                    }

                    logger.Error(exc, "Failed to execute game's game-started action.");
                    logger.Error(game.GameStartedScript);
                    Dialogs.ShowMessage(
                        message,
                        resources.GetString("LOCErrorGameScriptAction"),
                        MessageBoxButton.OK,
                        MessageBoxImage.Error);
                }
            }

            if (Application.Mode == ApplicationMode.Desktop)
            {
                if (AppSettings.AfterLaunch == AfterLaunchOptions.Close)
                {
                    Application.Quit();
                }
                else if (AppSettings.AfterLaunch == AfterLaunchOptions.Minimize)
                {
                    Application.Minimize();
                }
            }
            else
            {
                if (AppSettings.AfterLaunch == AfterLaunchOptions.Close)
                {
                    Application.Quit();
                }
                else
                {
                    Application.Minimize();
                }
            }

            if (AppSettings.DiscordPresenceEnabled)
            {
                Application.Discord?.SetPresence(game.Name);
            }
        }
Ejemplo n.º 17
0
 void OnWin(object sender, GameControllerEventArgs e)
 {
     GameUIPanel panel = currentPanel as GameUIPanel;
     panel.ShowWin();
 }
Ejemplo n.º 18
0
 public virtual void OnStarting(object sender, GameControllerEventArgs args)
 {
     execContext.Post((a) => Starting?.Invoke(sender, args), null);
 }
Ejemplo n.º 19
0
        private void Controllers_Stopped(object sender, GameControllerEventArgs args)
        {
            var game = args.Controller.Game;

            logger.Info($"Game {game.Name} stopped after {args.EllapsedTime} seconds.");

            var dbGame = Database.Games.Get(game.Id);

            dbGame.IsRunning   = false;
            dbGame.IsLaunching = false;
            dbGame.Playtime   += args.EllapsedTime;
            Database.Games.Update(dbGame);
            controllers.RemoveController(args.Controller);
            if (Application.Mode == ApplicationMode.Desktop)
            {
                if (AppSettings.AfterGameClose == AfterGameCloseOptions.Restore)
                {
                    Application.Restore();
                }
            }
            else
            {
                // The delay should hopefully fix rare cases where Fullscreen mode doesn't get proper focus after restore.
                // https://www.reddit.com/r/playnite/comments/f6d73l/bug_full_screen_ui_wont_respond_to_left_stick/
                Task.Delay(TimeSpan.FromSeconds(2)).ContinueWith(a => Application.Restore());
            }

            if (!game.PostScript.IsNullOrWhiteSpace())
            {
                try
                {
                    var expanded = game.ExpandVariables(game.PostScript);
                    ExecuteScriptAction(game.ActionsScriptLanguage, expanded, game);
                }
                catch (Exception exc) when(!PlayniteEnvironment.ThrowAllErrors)
                {
                    var message = exc.Message;

                    if (exc is ScriptRuntimeException err)
                    {
                        message = err.Message + "\n\n" + err.ScriptStackTrace;
                    }

                    logger.Error(exc, "Failed to execute game's post-script action.");
                    logger.Error(game.PostScript);
                    Dialogs.ShowMessage(
                        message,
                        resources.GetString("LOCErrorGameScriptAction"),
                        MessageBoxButton.OK,
                        MessageBoxImage.Error);
                }
            }

            if (!AppSettings.PostScript.IsNullOrWhiteSpace())
            {
                try
                {
                    var expanded = game.ExpandVariables(AppSettings.PostScript);
                    ExecuteScriptAction(AppSettings.ActionsScriptLanguage, expanded, game);
                }
                catch (Exception exc) when(!PlayniteEnvironment.ThrowAllErrors)
                {
                    var message = exc.Message;

                    if (exc is ScriptRuntimeException err)
                    {
                        message = err.Message + "\n\n" + err.ScriptStackTrace;
                    }

                    logger.Error(exc, "Failed to execute global post-script action.");
                    logger.Error(AppSettings.PostScript);
                    Dialogs.ShowMessage(
                        message,
                        resources.GetString("LOCErrorGlobalScriptAction"),
                        MessageBoxButton.OK,
                        MessageBoxImage.Error);
                }
            }

            if (AppSettings.ClientAutoShutdown.ShutdownClients && !game.IsCustomGame)
            {
                if (args.EllapsedTime <= AppSettings.ClientAutoShutdown.MinimalSessionTime)
                {
                    logger.Debug("Game session was too short for client to be shutdown.");
                }
                else
                {
                    var plugin = Extensions.GetLibraryPlugin(game.PluginId);
                    if (plugin?.Capabilities?.CanShutdownClient == true &&
                        AppSettings.ClientAutoShutdown.ShutdownPlugins.Contains(plugin.Id))
                    {
                        if (shutdownJobs.TryGetValue(game.PluginId, out var existingJob))
                        {
                            existingJob.CancelToken.Cancel();
                            shutdownJobs.TryRemove(game.PluginId, out var _);
                        }

                        var newJob = new ClientShutdownJob
                        {
                            PluginId    = plugin.Id,
                            CancelToken = new CancellationTokenSource()
                        };

                        var task = new Task(async() =>
                        {
                            var ct        = newJob.CancelToken;
                            var libPlugin = plugin;
                            var timeout   = AppSettings.ClientAutoShutdown.GraceTimeout;
                            var curTime   = 0;
                            logger.Info($"Scheduled {libPlugin.Name} to be closed after {timeout} seconds.");

                            while (curTime < timeout)
                            {
                                if (ct.IsCancellationRequested)
                                {
                                    logger.Debug($"Client {libPlugin.Name} shutdown canceled.");
                                    return;
                                }

                                await Task.Delay(1000);
                                curTime++;
                            }

                            if (curTime >= timeout)
                            {
                                try
                                {
                                    shutdownJobs.TryRemove(libPlugin.Id, out var _);
                                    libPlugin.Client.Shutdown();
                                }
                                catch (Exception e) when(!PlayniteEnvironment.ThrowAllErrors)
                                {
                                    logger.Error(e, $"Failed to shutdown {libPlugin.Name} client.");
                                }
                            }
                        });

                        newJob.CancelTask = task;
                        shutdownJobs.TryAdd(plugin.Id, newJob);
                        newJob.CancelTask.Start();
                    }
                }
            }
        }
Ejemplo n.º 20
0
 public virtual void OnStopped(object sender, GameControllerEventArgs args)
 {
     IsGameRunning = false;
     Stopped?.Invoke(sender, args);
 }
Ejemplo n.º 21
0
 public virtual void OnStarting(object sender, GameControllerEventArgs args)
 {
     Starting?.Invoke(sender, args);
 }
Ejemplo n.º 22
0
        private void Controllers_Stopped(object sender, GameControllerEventArgs args)
        {
            var game = args.Controller.Game;

            logger.Info($"Game {game.Name} stopped after {args.EllapsedTime} seconds.");

            var dbGame = Database.Games.Get(game.Id);

            dbGame.IsRunning   = false;
            dbGame.IsLaunching = false;
            dbGame.Playtime   += args.EllapsedTime;
            Database.Games.Update(dbGame);
            controllers.RemoveController(args.Controller);
            if (Application.Mode == ApplicationMode.Desktop)
            {
                if (AppSettings.AfterGameClose == AfterGameCloseOptions.Restore)
                {
                    Application.Restore();
                }
            }
            else
            {
                Application.Restore();
            }

            if (!game.PostScript.IsNullOrWhiteSpace())
            {
                try
                {
                    ExecuteScriptAction(game.ActionsScriptLanguage, game.PostScript, game);
                }
                catch (Exception exc) when(!PlayniteEnvironment.ThrowAllErrors)
                {
                    logger.Error(exc, "Failed to execute game's post-script action.");
                    logger.Error(game.PostScript);
                    Dialogs.ShowMessage(
                        string.Format(resources.GetString("LOCErrorGameScriptAction"), exc.Message),
                        resources.GetString("LOCGameError"),
                        MessageBoxButton.OK,
                        MessageBoxImage.Error);
                }
            }

            if (!AppSettings.PostScript.IsNullOrWhiteSpace())
            {
                try
                {
                    ExecuteScriptAction(AppSettings.ActionsScriptLanguage, AppSettings.PostScript, game);
                }
                catch (Exception exc) when(!PlayniteEnvironment.ThrowAllErrors)
                {
                    logger.Error(exc, "Failed to execute global post-script action.");
                    logger.Error(AppSettings.PostScript);
                    Dialogs.ShowMessage(
                        string.Format(resources.GetString("LOCErrorGlobalScriptAction"), exc.Message),
                        resources.GetString("LOCGameError"),
                        MessageBoxButton.OK,
                        MessageBoxImage.Error);
                }
            }
        }
Ejemplo n.º 23
0
 public virtual void OnInstalled(object sender, GameControllerEventArgs args)
 {
     execContext.Post((a) => Installed?.Invoke(sender, args), null);
 }
Ejemplo n.º 24
0
 public virtual void OnStopped(object sender, GameControllerEventArgs args)
 {
     IsGameRunning = false;
     execContext.Post((a) => Stopped?.Invoke(sender, args), null);
 }
Ejemplo n.º 25
0
 void gc_ControllerDisconnected(object sender, GameControllerEventArgs args)
 {
     OnControllerDisconnected(args.ControllerNum);
 }
Ejemplo n.º 26
0
 void gc_ControllerDisconnected(object sender, GameControllerEventArgs args)
 {
     if (ShowOutput)
     {
         SetLeftTriggerValue(string.Empty);
         SetRightTriggerValue(string.Empty);
         SetLeftStickValue(string.Empty);
         SetRightStickValue(string.Empty);
         ClearButtonOutput();
     }
 }
Ejemplo n.º 27
0
 public virtual void OnUninstalled(object sender, GameControllerEventArgs args)
 {
     Uninstalled?.Invoke(sender, args);
 }
Ejemplo n.º 28
0
 void OnBeginFire(object sender, GameControllerEventArgs e)
 {
     GameUIPanel panel = currentPanel as GameUIPanel;
     panel.ShowFire();
 }
Ejemplo n.º 29
0
 public virtual void OnStarted(object sender, GameControllerEventArgs args)
 {
     IsGameRunning = true;
     execContext.Send((a) => Started?.Invoke(sender, args), null);
 }