Esempio n. 1
0
        public void OnStarted()
        {
            if (_injectionService.IsProxyLoaded(_game.FilePath, _plugins.Proxy))
            {
                return;
            }

            var gameProfile = _game.Profiles.SingleOrDefault(profile => profile.Id == _game.ProfileId);

            if (gameProfile == null)
            {
                _logger.Log(LogLevel.Error, $"game profile could not be found for: {FilePath}");
                return;
            }

            var tokenReplacer = new TokenReplacer(new ApplicationFilePathTokenReplacingPolicy(() => _game.FilePath));
            var component     = _assembler.Assemble(gameProfile, new AssemblingContext(FormType.None, tokenReplacer));

            component.Tokenize();

            if (!component.IsValid)
            {
                _logger.Log(LogLevel.Error, $"game profile for: {FilePath} are not valid; skipping...");
                return;
            }

            try
            {
                foreach (var directoryPath in component.AllProperties
                         .OfType <IGenericProperty <string> >()
                         .Where(property => property.Configuration.IsDirectoryPath)
                         .Select(property => property.Value))
                {
                    _logger.Log(LogLevel.Information, $"demanding access to: {directoryPath}...");
                    _directoryRepository.DemandAccess(directoryPath);
                }
            }
            catch (SecurityException)
            {
                _logger.Log(LogLevel.Error, $"insufficient permissions to: {FilePath}");
                return;
            }
            catch (UnauthorizedAccessException)
            {
                _logger.Log(LogLevel.Error, $"insufficient permissions to: {FilePath}");
                return;
            }

            var settings = new InjectableProxySettings
            {
                CommunicationAddress = _communicationAddress,
                CommunicationPort    = _communicationPort,
                Direct3D11PluginPath = _plugins.Direct3D11,
                GameFilePath         = _game.FilePath,
                GameName             = _game.Name,
                GameProfile          = gameProfile
            };

            Inject(settings).Wait();
        }
Esempio n. 2
0
        private async Task Inject(InjectableProxySettings injectProxySettings)
        {
            _logger.Log(LogLevel.Information, $"injection started for: {FilePath}...");
            await new SynchronizationContextRemover();

            var directory = await _directoryRepository.LoadAsync(injectProxySettings.GameProfile.ProxyDirectoryPath);

            directory.AddFile(_plugins.ProxySettingsFileName, injectProxySettings.Serialize());

            _logger.Log(LogLevel.Information, $"creating proxy settings file at: {FilePath}...");
            await _directoryRepository.SaveAsync(directory);

            _logger.Log(LogLevel.Information, $"attempting to inject proxy dll into: {FilePath}...");
            var status = _injectionService.Inject(_game.FilePath, _plugins.Proxy);

            if (status?.Status == 0)
            {
                _logger.Log(LogLevel.Information, $"proxy dll injected into: {FilePath}");
            }
            else
            {
                _logger.Log(LogLevel.Error, $"proxy dll could not be injected into: {FilePath}; failed with status: {status}");
            }
        }