Beispiel #1
0
        public async Task <IZGameProcess> CreateSingleAsync(ZSingleParams args)
        {
            ZConnectionHelper.MakeSureConnection();

            var installedGames = await _installedGamesService.GetInstalledGamesAsync();

            if (installedGames == null)
            {
                throw new Exception("Installed games not received. Check your ZClient connection.");
            }

            var architecture = args.PreferredArchitecture ??
                               (installedGames.IsX64 ? ZGameArchitecture.x64 : ZGameArchitecture.x32);
            var compatibleGames = installedGames.InstalledGames
                                  .Where(insGame => insGame.EnumGame == args.Game)
                                  .ToArray();
            var targetGame = compatibleGames.Length > 1
                ? compatibleGames.FirstOrDefault(insGame => insGame.RunnableName.EndsWith(architecture.ToString()))
                : compatibleGames.FirstOrDefault();

            if (targetGame == null)
            {
                throw new InvalidOperationException($"The target game {args.Game} not found.");
            }

            var commandRun = __runStrings[_SingleKey].ToObject <string>();

            commandRun = commandRun.Replace(_personaRefReplaceable, __userContext.UserId.ToString());

            var runGame = _createRunGame(targetGame, commandRun, args.Game, architecture);

            return(runGame);
        }
Beispiel #2
0
        /// <inheritdoc />
        public IZServersListService CreateServersListService(ZGame game)
        {
            ZConnectionHelper.MakeSureConnection();

            if (_config == null)
            {
                throw new InvalidOperationException("You cannot create a service until the api is configured.");
            }

            if (game == ZGame.None)
            {
                throw new InvalidEnumArgumentException(nameof(game), (int)game, typeof(ZGame));
            }

            if (_lastCreatedServerListInstance != null && _lastCreatedServerListInstance.CanUse)
            {
                _lastCreatedServerListInstance.StopReceiving();
            }

            var service = _BuildServerListService(game);

            _lastCreatedServerListInstance = service;

            return(service);
        }
Beispiel #3
0
        public async Task <IZGameProcess> CreateCoOpAsync(ZCoopParams args)
        {
            ZConnectionHelper.MakeSureConnection();

            if (args.Mode != ZPlayMode.CooperativeHost && args.Mode != ZPlayMode.CooperativeClient)
            {
                throw new ArgumentException("Mode contains wrong value. Allowed values is CooperativeHost or CooperativeClient.");
            }

            if (ZPlayMode.CooperativeClient == args.Mode && args.FriendId == null)
            {
                throw new ArgumentException($"For this {args.Mode} mode need to specify {nameof(args.FriendId)} value.");
            }
            else if (ZPlayMode.CooperativeHost == args.Mode && (args.Difficulty == null || args.Level == null))
            {
                throw new ArgumentException($"For this {args.Mode} mode need to specify {nameof(args.Difficulty)}, {nameof(args.Level)} value.");
            }

            var installedGames = await _installedGamesService.GetInstalledGamesAsync();

            if (installedGames == null)
            {
                throw new Exception("Installed games not received. Check your ZClient connection.");
            }

            var architecture = args.PreferredArchitecture ??
                               (installedGames.IsX64 ? ZGameArchitecture.x64 : ZGameArchitecture.x32);
            var compatibleGames = installedGames.InstalledGames
                                  .Where(insGame => insGame.EnumGame == ZGame.BF3)
                                  .ToArray();
            var targetGame = compatibleGames.Length > 1
                ? compatibleGames.FirstOrDefault(insGame => insGame.RunnableName.EndsWith(architecture.ToString()))
                : compatibleGames.FirstOrDefault();

            if (targetGame == null)
            {
                throw new InvalidOperationException($"The target game {ZGame.BF3} not found.");
            }

            string commandRun;

            if (args.Mode == ZPlayMode.CooperativeHost)
            {
                commandRun = __runStrings[_CoopHostKey].ToObject <string>();
                commandRun = commandRun.Replace(_levelReplaceable, args.Level.ToString().ToUpper());
                commandRun = commandRun.Replace(_difficultyReplaceable, args.Difficulty.ToString().ToUpper());
                commandRun = commandRun.Replace(_personaRefReplaceable, __userContext.UserId.ToString());
            }
            else
            {
                commandRun = __runStrings[_CoopJoinKey].ToObject <string>();
                commandRun = commandRun.Replace(_friendIdReplaceable, args.FriendId.ToString());
                commandRun = commandRun.Replace(_personaRefReplaceable, __userContext.UserId.ToString());
            }

            var runGame = _createRunGame(targetGame, commandRun, ZGame.BF3, architecture);

            return(runGame);
        }
Beispiel #4
0
        /// <inheritdoc />
        public Task <ZStatsBase> GetStatsAsync(ZGame game)
        {
            ZConnectionHelper.MakeSureConnection();
            if (game == ZGame.BFH)
            {
                throw new NotSupportedException("Stats not implemented for Battlefield Hardline.");
            }

            return(_GetStatsImpl(game));
        }
Beispiel #5
0
        private ZApi()
        {
            // creating a client services
            _connection   = new ZConnection();
            _statsService = new ZStatsService();
            _gameFactory  = new ZGameFactory(_connection);
            _injector     = new ZInjectorService();

            // initializing the static helpers
            ZConnectionHelper.Initialize(_connection);
        }
Beispiel #6
0
        public async Task <IZGameProcess> CreateMultiAsync(ZMultiParams args)
        {
            ZConnectionHelper.MakeSureConnection();

            if ((args.Game == ZGame.BF3 || args.Game == ZGame.BFH) && args.Role == ZRole.Spectator)
            {
                throw new ArgumentException("BF3\\BFH is not support Spectator mode.");
            }

            var installedGames = await _installedGamesService.GetInstalledGamesAsync();

            if (installedGames == null)
            {
                throw new Exception("Installed games not received. Check your ZClient connection.");
            }

            var architecture = args.PreferredArchitecture ??
                               (installedGames.IsX64 ? ZGameArchitecture.x64 : ZGameArchitecture.x32);
            var compatibleGames = installedGames.InstalledGames
                                  .Where(insGame => insGame.EnumGame == args.Game)
                                  .ToArray();
            var targetGame = compatibleGames.Length > 1
                ? compatibleGames.FirstOrDefault(insGame => insGame.RunnableName.EndsWith(architecture.ToString()))
                : compatibleGames.FirstOrDefault();

            if (targetGame == null)
            {
                throw new Exception($"The target game {args.Game} not found.");
            }

            var commandRun = __runStrings[_MultiKey].ToObject <string>();

            commandRun = commandRun.Replace(_gameIdReplaceable, args.ServerId.ToString());
            commandRun = commandRun.Replace(_personaRefReplaceable, __userContext.UserId.ToString());

            if (args.Role != ZRole.Spectator)
            {
                commandRun = commandRun.Replace(_roleReplaceable, args.Role.ToString().ToLower());
                commandRun = commandRun.Replace(_isSpectatorReplaceable, string.Empty);
            }
            else
            {
                commandRun = commandRun.Replace(_roleReplaceable, ZRole.Soldier.ToString().ToLower());
                commandRun = commandRun.Replace(_isSpectatorReplaceable, _spectatorValue);
            }

            var runGame = _createRunGame(targetGame, commandRun, args.Game, architecture);

            return(runGame);
        }
Beispiel #7
0
        public async Task <IZGameProcess> CreateTestRangeAsync(ZTestRangeParams args)
        {
            ZConnectionHelper.MakeSureConnection();

            if (args.Game == ZGame.BF3)
            {
                throw new NotSupportedException("Battlefield 3 TestRange play mode not supported.");
            }

            if (args.Game == ZGame.BFH)
            {
                throw new NotImplementedException("Battlefield Hardline TestRange not implemented in ZLOEmu.");
            }

            var installedGames = await _installedGamesService.GetInstalledGamesAsync();

            if (installedGames == null)
            {
                throw new Exception("Installed games not received. Check your ZClient connection.");
            }

            var architecture = args.PreferredArchitecture ??
                               (installedGames.IsX64 ? ZGameArchitecture.x64 : ZGameArchitecture.x32);
            var compatibleGames = installedGames.InstalledGames
                                  .Where(insGame => insGame.EnumGame == args.Game)
                                  .ToArray();
            var targetGame = compatibleGames.Length > 1
                ? compatibleGames.FirstOrDefault(insGame => insGame.RunnableName.EndsWith(architecture.ToString()))
                : compatibleGames.FirstOrDefault();

            if (targetGame == null)
            {
                throw new Exception($"The target game {args.Game} not found.");
            }

            var commandRun = __runStrings[_TestRangeKey].ToObject <string>();

            commandRun = commandRun.Replace(_personaRefReplaceable, __userContext.UserId.ToString());

            var runGame = _createRunGame(targetGame, commandRun, args.Game, architecture);

            return(runGame);
        }
Beispiel #8
0
        /// <inheritdoc />
        public void InjectDll(ZGame game, IEnumerable <string> paths)
        {
            ZConnectionHelper.MakeSureConnection();

            _injector.Inject(game, paths);
        }