public ConfigStatus ParseToParameters(IDictionary <string, string> queryParams, LaunchParams parameters) { ConfigStatus status = AssignValues(parameters, queryParams); return(status.Merge(ParseParamsCustomParameters(parameters, queryParams))); }
ConfigStatus ParseParamsCmd(LaunchParams parameters, IDictionary <string, string> queryParams) { if (!queryParams.ContainsKey(QueryParamMapping.Cmd)) { return(ConfigStatus.OkStatus()); } string queryParamsCmd = queryParams[QueryParamMapping.Cmd]; if (string.IsNullOrWhiteSpace(parameters.Cmd)) { parameters.Cmd = queryParamsCmd; return(ConfigStatus.OkStatus()); } // The cmd is valid only if the binary name is the same as in // the project output. string settingsBinaryName = parameters.Cmd.Split(' ').First(s => !string.IsNullOrEmpty(s)); string queryBinaryName = queryParamsCmd.Split(' ').FirstOrDefault(s => !string.IsNullOrEmpty(s)); if (queryBinaryName != settingsBinaryName) { return(ConfigStatus.ErrorStatus( ErrorStrings.InvalidBinaryName(settingsBinaryName, queryBinaryName))); } parameters.Cmd = queryParamsCmd; return(ConfigStatus.OkStatus()); }
ConfigStatus ParseLaunchRequestVulkanDriverVariant(LaunchGameRequest launchRequest, IDictionary <string, string> queryParams) { ConfigStatus status = ConfigStatus.OkStatus(); if (queryParams.ContainsKey(QueryParamMapping.VulkanDriverVariant)) { string driverVariant = "GGP_DEV_VK_DRIVER_VARIANT"; if (!launchRequest.EnvironmentVariablePairs.ContainsKey(driverVariant)) { var allowedValues = new[] { "opt", "optprintasserts", "dbgtrapasserts" }; if (!allowedValues.Contains(queryParams[QueryParamMapping.VulkanDriverVariant] .ToLower())) { status.AppendWarning(ErrorStrings.InvalidEnumValue( QueryParamMapping.VulkanDriverVariant, queryParams[QueryParamMapping.VulkanDriverVariant], allowedValues)); } else { launchRequest.EnvironmentVariablePairs.Add( driverVariant, queryParams[QueryParamMapping.VulkanDriverVariant].ToLower()); } } } return(status); }
ConfigStatus ParseParamsCustomParameters(LaunchParams parameters, IDictionary <string, string> queryParams) { ConfigStatus status = ParseParamsCmd(parameters, queryParams); return(status.Merge(ParseParamsVars(parameters, queryParams))); }
ConfigStatus SetEnumProperty <T>( T assignObject, PropertyInfo property, string paramName, string value) { Type propertyType = property.PropertyType; var expectedValues = new List <string>(); foreach (string fieldName in Enum.GetNames(propertyType)) { FieldInfo fieldInfo = propertyType.GetField(fieldName); var attr = (MapValueAttribute)fieldInfo .GetCustomAttributes(typeof(MapValueAttribute), false).SingleOrDefault(); if (attr == null) { continue; } if (value.ToLower() == attr.QueryParameterValue.ToLower()) { property.SetValue(assignObject, Enum.Parse(propertyType, fieldName)); return(ConfigStatus.OkStatus()); } expectedValues.Add(attr.QueryParameterValue); } return(ConfigStatus.WarningStatus( ErrorStrings.InvalidEnumValue(paramName, value, expectedValues))); }
ConfigStatus AddBoolEnvironmentVariable(LaunchGameRequest launchRequest, IDictionary <string, string> queryParams, string variableName, string queryParamName) { if (!queryParams.ContainsKey(queryParamName) || launchRequest.EnvironmentVariablePairs.ContainsKey(variableName)) { return(ConfigStatus.OkStatus()); } if (!bool.TryParse(queryParams[queryParamName], out bool isTrue)) { if (!int.TryParse(queryParams[queryParamName], out int intVal) || intVal < 0 || intVal > 1) { return(ConfigStatus.WarningStatus(ErrorStrings.InvalidQueryParameterType( queryParamName, queryParams[queryParamName], typeof(bool)))); } isTrue = intVal == 1; } if (isTrue) { launchRequest.EnvironmentVariablePairs.Add(variableName, "1"); } return(ConfigStatus.OkStatus()); }
ConfigStatus SetStringArrayProperty <T>( T assignObject, PropertyInfo property, string paramName, string value) { property.SetValue(assignObject, value.Split(',') .Where(s => !string.IsNullOrWhiteSpace(s)).ToArray()); return(ConfigStatus.OkStatus()); }
public ConfigStatus ParseToLaunchRequest( IDictionary <string, string> queryParams, LaunchGameRequest launchRequest) { ConfigStatus status = AssignValues(launchRequest, queryParams); return(status.Merge(ParseLaunchRequestCustomParameters(launchRequest, queryParams))); }
public ConfigStatus Merge(ConfigStatus otherStatus) => new ConfigStatus { _errorMessages = _errorMessages.Concat(otherStatus._errorMessages).ToList(), _warningMessages = _warningMessages.Concat(otherStatus._warningMessages).ToList() };
public ConfigStatus ParametersToDictionary( string queryString, out IDictionary <string, string> queryParams) { ConfigStatus status = ToQueryParams(queryString, out queryParams); return(status); }
ConfigStatus SetIntProperty <T>( T assignObject, PropertyInfo property, string paramName, string value) { if (!int.TryParse(value, out int intValue)) { return(ConfigStatus.WarningStatus( ErrorStrings.InvalidQueryParameterType(paramName, value, typeof(int)))); } property.SetValue(assignObject, intValue); return(ConfigStatus.OkStatus()); }
ConfigStatus ParseParamsVars(LaunchParams parameters, IDictionary <string, string> queryParams) { if (queryParams.ContainsKey(QueryParamMapping.Vars)) { // The last occurrence of the an environment variable wins. parameters.GameletEnvironmentVars = parameters.GameletEnvironmentVars + ";" + queryParams[QueryParamMapping.Vars]; } return(ConfigStatus.OkStatus()); }
ConfigStatus SetUlongProperty <T>( T assignObject, PropertyInfo property, string paramName, string value) { if (!ulong.TryParse(value, out ulong ulongValue)) { return(ConfigStatus.WarningStatus( ErrorStrings.InvalidQueryParameterType(paramName, value, typeof(ulong)))); } property.SetValue(assignObject, ulongValue); return(ConfigStatus.OkStatus()); }
public ConfigStatus ToLaunchGameRequest( LaunchParams parameters, out LaunchGameRequest request) { ConfigStatus status = _queryParametersParser.ParametersToDictionary( parameters.QueryParams, out IDictionary <string, string> parametersDict); status = status.Merge( _queryParametersParser.ParseToParameters(parametersDict, parameters)); ISdkConfig sdkConfig = _sdkConfigFactory.LoadGgpSdkConfigOrDefault(); status = status.Merge( EnvironmentVariables(parameters, out IDictionary <string, string> envVariables)); status = status.Merge(CommandLineArguments(parameters, out string[] cmdArgs)); if ((parameters.Endpoint == StadiaEndpoint.PlayerEndpoint || parameters.Endpoint == StadiaEndpoint.AnyEndpoint) && !string.IsNullOrEmpty(parameters.TestAccount)) { status.AppendWarning( ErrorStrings.TestAccountsNotSupported(parameters.TestAccountGamerName)); parameters.TestAccount = null; } request = new LaunchGameRequest { Parent = Parent(sdkConfig, parameters), GameletName = parameters.GameletName, ApplicationName = parameters.ApplicationName, ExecutablePath = ExecutablePath(parameters), CommandLineArguments = cmdArgs, EnvironmentVariablePairs = envVariables, SurfaceEnforcementMode = parameters.SurfaceEnforcementMode, Debug = parameters.Debug, EnableDeveloperResumeOffer = parameters.Endpoint == StadiaEndpoint.AnyEndpoint }; status = status.Merge( _queryParametersParser.ParseToLaunchRequest(parametersDict, request)); status = status.Merge( _queryParametersParser.GetFinalQueryString(parametersDict, out string queryString)); parameters.QueryParams = queryString; if ((parameters.Endpoint == StadiaEndpoint.PlayerEndpoint || parameters.Endpoint == StadiaEndpoint.AnyEndpoint) && !string.IsNullOrEmpty(queryString)) { status.AppendWarning(ErrorStrings.QueryParamsNotSupported(queryString)); } return(status); }
ConfigStatus CommandLineArguments(LaunchParams parameters, out string[] args) { args = new string[0]; if (string.IsNullOrWhiteSpace(parameters.Cmd)) { return(ConfigStatus.OkStatus()); } args = parameters.Cmd.Trim().Split(' ').Where(s => !string.IsNullOrEmpty(s)).Skip(1) .ToArray(); return(ConfigStatus.OkStatus()); }
ConfigStatus AddFlagsEnvironmentVariables( LaunchParams parameters, IDictionary <string, string> variables) { ConfigStatus status = ConfigStatus.OkStatus(); var flagEnvironmentVariables = new Dictionary <string, string>(); if (!string.IsNullOrWhiteSpace(parameters.VulkanDriverVariant)) { flagEnvironmentVariables.Add("GGP_DEV_VK_DRIVER_VARIANT", parameters.VulkanDriverVariant); } if (parameters.RenderDoc) { flagEnvironmentVariables.Add("ENABLE_VULKAN_RENDERDOC_CAPTURE", "1"); flagEnvironmentVariables.Add("RENDERDOC_TEMP", "/mnt/developer/ggp"); flagEnvironmentVariables.Add("RENDERDOC_DEBUG_LOG_FILE", "/var/game/RDDebug.log"); } if (parameters.Rgp) { flagEnvironmentVariables.Add("GGP_INTERNAL_LOAD_RGP", "1"); flagEnvironmentVariables.Add("RGP_DEBUG_LOG_FILE", "/var/game/RGPDebug.log"); } foreach (string key in flagEnvironmentVariables.Keys) { if (variables.ContainsKey(key)) { status.AppendWarning(ErrorStrings.EnvironmentVariableOverride(key)); continue; } variables.Add(key, flagEnvironmentVariables[key]); } if (parameters.Rgp) { if (!variables.ContainsKey("LD_PRELOAD")) { variables.Add("LD_PRELOAD", string.Empty); } variables["LD_PRELOAD"] += (string.IsNullOrEmpty(variables["LD_PRELOAD"]) ? string.Empty : ":") + "librgpserver.so"; } return(status); }
ConfigStatus SetBoolProperty <T>( T assignObject, PropertyInfo property, string paramName, string value) { value = value.ToLower(); if (!bool.TryParse(value, out bool boolValue)) { if (!int.TryParse(value, out int intVal) || intVal < 0 || intVal > 1) { return(ConfigStatus.WarningStatus( ErrorStrings.InvalidQueryParameterType(paramName, value, typeof(bool)))); } boolValue = intVal == 1; } property.SetValue(assignObject, boolValue); return(ConfigStatus.OkStatus()); }
/// <summary> /// Sets environment variables from query parameters. /// Environment variables are prioritized in the following way: /// <list type="number"> /// <item> /// <description> /// Query parameter 'vars' value. /// </description> /// </item> /// <item> /// <description> /// 'Stadia Environment Variables' setting. /// </description> /// </item> /// <item> /// <description> /// Other VSI settings(Rgp, RenderDoc, ...). /// </description> /// </item> /// <item> /// <description> /// Other Query parameters(color_tools, enable_llpc_in_amdvlk, ...). /// </description> /// </item> /// </list> /// 3d and 4th points don't overlap, so they are actually together on the 3d place. /// </summary> /// <param name="launchRequest"></param> /// <param name="queryParams"></param> /// <returns></returns> ConfigStatus ParseLaunchRequestCustomParameters(LaunchGameRequest launchRequest, IDictionary <string, string> queryParams) { ConfigStatus status = AddBoolEnvironmentVariable( launchRequest, queryParams, "ENABLE_VK_LAYER_VULKAN_COLOR_TOOLS", QueryParamMapping.ColorTools); status = status.Merge( ParseLaunchRequestVulkanDriverVariant(launchRequest, queryParams)); status = status.Merge(AddBoolEnvironmentVariable( launchRequest, queryParams, "GGP_VK_AMDVLK_USE_LLPC", QueryParamMapping.EnableLlpcInAmdvlk)); status = status.Merge(AddBoolEnvironmentVariable( launchRequest, queryParams, "ENABLE_GOOGLE_PIPELINE_DATA_EXPORT_LAYER", QueryParamMapping.EnablePipelineCacheSourceLayer)); return(status); }
/// <summary> /// Parses the query string to a dictionary. /// Values in the dictionary contain decoded special characters. /// For example: the value 'value%3D%C3%BC' in the query string will be 'value=ü' /// in the resulting dictionary. /// </summary> ConfigStatus ToQueryParams(string queryString, out IDictionary <string, string> queryParams) { queryParams = new Dictionary <string, string>(); if (string.IsNullOrEmpty(queryString)) { return(ConfigStatus.OkStatus()); } try { NameValueCollection nameValueCollection; try { // May throw an exception when maximum number of keys is exceeded. nameValueCollection = HttpUtility.ParseQueryString(queryString); } catch (Exception e) { throw new ApplicationException(e.Message); } foreach (string key in nameValueCollection.AllKeys) { if (string.IsNullOrWhiteSpace(key)) { throw new ApplicationException("Parameter 'Key' can not be empty."); } queryParams.Add(key, nameValueCollection.Get(key)); } LogQueryString(queryString, queryParams); return(ConfigStatus.OkStatus()); } catch (ApplicationException e) { Trace.TraceWarning($"Error happened while parsing query string. {e.Message}"); queryParams = new Dictionary <string, string>(); return(ConfigStatus.WarningStatus( ErrorStrings.QueryParametersWrongFormat)); } }
ConfigStatus AssignValues <T>(T assignObject, IDictionary <string, string> queryParams) { var status = ConfigStatus.OkStatus(); Dictionary <string, QueryParamMapping> paramsToMap = _queryParamsMappings .Where(p => p.SetRequestParam && p.MapType == typeof(T)) .ToDictionary(p => p.ParamName, p => p); foreach (KeyValuePair <string, string> queryParam in queryParams) { if (!paramsToMap.ContainsKey(queryParam.Key)) { continue; } status = status.Merge(AssignValue(assignObject, paramsToMap[queryParam.Key], queryParam.Key, queryParam.Value)); } return(status); }
ConfigStatus EnvironmentVariables(LaunchParams parameters, out IDictionary <string, string> envVariables) { ConfigStatus status = ConfigStatus.OkStatus(); string variablesString = parameters.GameletEnvironmentVars ?? string.Empty; envVariables = variablesString.Split(';') .Select(v => v.Trim()) .Where(v => !string.IsNullOrWhiteSpace(v)).Select(v => { List <string> parts = v.Split('=').ToList(); if (string.IsNullOrWhiteSpace(parts[0])) { status.AppendWarning(ErrorStrings.InvalidEnvironmentVariable(v)); return(Tuple.Create(string.Empty, string.Empty)); } return(Tuple.Create(parts[0], string.Join("=", parts.Skip(1)))); }).Where(t => !string.IsNullOrEmpty(t.Item1)).GroupBy(tuple => tuple.Item1).Select( tuple => { if (tuple.Count() > 1) { status.AppendWarning( ErrorStrings.MultipleEnvironmentVariableKeys(tuple.Key)); } return(tuple); }).ToDictionary(t => t.Key, t => t.Last().Item2); status = status.Merge(AddFlagsEnvironmentVariables(parameters, envVariables)); if (!status.IsOk) { status.AppendWarning(ErrorStrings.EditEnvironmentVariables); } return(status); }
public ConfigStatus GetFinalQueryString( IDictionary <string, string> queryParams, out string queryString) { var status = ConfigStatus.OkStatus(); List <string> ignoredParameters = _queryParamsMappings .Where(p => p.IsIgnored && queryParams.ContainsKey(p.ParamName)) .Select(p => p.ParamName).ToList(); if (ignoredParameters.Any()) { status.AppendWarning(ErrorStrings.QueryParametersIgnored(ignoredParameters)); } Dictionary <string, QueryParamMapping> queryParamsMappingsDict = _queryParamsMappings.ToDictionary( p => p.ParamName, p => p); IEnumerable <KeyValuePair <string, string> > paramsToStayInQuery = queryParams.Where( p => !queryParamsMappingsDict.ContainsKey(p.Key) || queryParamsMappingsDict[p.Key].PassAsUrlParam); queryString = string.Join("&", paramsToStayInQuery.Select( p => $"{Uri.EscapeDataString(p.Key)}={Uri.EscapeDataString(p.Value)}")); return(status); }
ConfigStatus SetStringProperty <T>( T assignObject, PropertyInfo property, string value) { property.SetValue(assignObject, value); return(ConfigStatus.OkStatus()); }