Exemplo n.º 1
0
        public async void StartRunningWatcher()
        {
            if (Origin.GetGameUsesEasyAntiCheat(Game))
            {
                // Games with EasyAntiCheat take longer to be re-executed by Origin
                await Task.Delay(12000);
            }
            else if (Origin.GetGameRequiresOrigin(Game))
            {
                // Solves issues with game process being started/shutdown multiple times during startup via Origin
                await Task.Delay(5000);
            }

            procMon.WatchDirectoryProcesses(Game.InstallDirectory, false);
        }
Exemplo n.º 2
0
        public Dictionary <string, GameInfo> GetInstalledGames(bool useDataCache = false)
        {
            var contentPath = Path.Combine(Origin.DataPath, "LocalContent");
            var games       = new Dictionary <string, GameInfo>();

            if (Directory.Exists(contentPath))
            {
                var packages = Directory.GetFiles(contentPath, "*.mfst", SearchOption.AllDirectories);
                foreach (var package in packages)
                {
                    try
                    {
                        var gameId = Path.GetFileNameWithoutExtension(package);
                        if (!gameId.StartsWith("Origin"))
                        {
                            // Get game id by fixing file via adding : before integer part of the name
                            // for example OFB-EAST52017 converts to OFB-EAST:52017
                            var match = Regex.Match(gameId, @"^(.*?)(\d+)$");
                            if (!match.Success)
                            {
                                logger.Warn("Failed to get game id from file " + package);
                                continue;
                            }

                            gameId = match.Groups[1].Value + ":" + match.Groups[2].Value;
                        }

                        var newGame = new GameInfo()
                        {
                            Source      = "Origin",
                            GameId      = gameId,
                            IsInstalled = true
                        };

                        GameLocalDataResponse localData = null;

                        try
                        {
                            localData = GetLocalManifest(gameId, package, useDataCache);
                        }
                        catch (Exception e) when(!Environment.IsDebugBuild)
                        {
                            logger.Error(e, $"Failed to get Origin manifest for a {gameId}, {package}");
                            continue;
                        }

                        if (localData.offerType != "Base Game" && localData.offerType != "DEMO")
                        {
                            continue;
                        }

                        newGame.Name = StringExtensions.NormalizeGameName(localData.localizableAttributes.displayName);
                        var platform = localData.publishing.softwareList.software.FirstOrDefault(a => a.softwarePlatform == "PCWIN");

                        if (platform == null)
                        {
                            logger.Warn(gameId + " game doesn't have windows platform, skipping install import.");
                            continue;
                        }

                        var installPath = GetPathFromPlatformPath(platform.fulfillmentAttributes.installCheckOverride);
                        if (string.IsNullOrEmpty(installPath) || !File.Exists(installPath))
                        {
                            continue;
                        }

                        newGame.PlayAction = GetGamePlayTask(localData);
                        if (newGame.PlayAction?.Type == GameActionType.File)
                        {
                            newGame.InstallDirectory      = newGame.PlayAction.WorkingDir;
                            newGame.PlayAction.WorkingDir = newGame.PlayAction.WorkingDir.Replace(newGame.InstallDirectory, ExpandableVariables.InstallationDirectory);
                            newGame.PlayAction.Path       = newGame.PlayAction.Path.Replace(newGame.InstallDirectory, "").Trim(new char[] { '\\', '/' });
                        }
                        else
                        {
                            newGame.InstallDirectory = Path.GetDirectoryName(installPath);
                        }

                        // If game uses EasyAntiCheat then use executable referenced by it
                        if (Origin.GetGameUsesEasyAntiCheat(newGame.InstallDirectory))
                        {
                            var eac = EasyAntiCheat.GetLauncherSettings(newGame.InstallDirectory);
                            if (newGame.PlayAction == null)
                            {
                                newGame.PlayAction = new GameAction {
                                    Type = GameActionType.File
                                };
                            }

                            newGame.PlayAction.Path = eac.Executable;
                            if (!string.IsNullOrEmpty(eac.Parameters) && eac.UseCmdlineParameters == "1")
                            {
                                newGame.PlayAction.Arguments = eac.Parameters;
                            }

                            if (!string.IsNullOrEmpty(eac.WorkingDirectory))
                            {
                                newGame.PlayAction.WorkingDir = Path.Combine(ExpandableVariables.InstallationDirectory, eac.WorkingDirectory);
                            }
                            else
                            {
                                newGame.PlayAction.WorkingDir = ExpandableVariables.InstallationDirectory;
                            }
                        }

                        games.Add(newGame.GameId, newGame);
                    }
                    catch (Exception e) when(!Environment.IsDebugBuild)
                    {
                        logger.Error(e, $"Failed to import installed Origin game {package}.");
                    }
                }
            }

            return(games);
        }