private bool LoadUserGameStatsSchema() { string path; try { path = API.Steam.GetInstallPath(); path = Path.Combine(path, "appcache"); path = Path.Combine(path, "stats"); path = Path.Combine(path, string.Format( CultureInfo.InvariantCulture, "UserGameStatsSchema_{0}.bin", this._GameId)); if (File.Exists(path) == false) { return(false); } } catch { return(false); } var kv = KeyValue.LoadAsBinary(path); if (kv == null) { return(false); } var currentLanguage = this._SteamClient.SteamApps008.GetCurrentGameLanguage(); //var currentLanguage = "german"; this._AchievementDefinitions.Clear(); this._StatDefinitions.Clear(); var stats = kv[this._GameId.ToString(CultureInfo.InvariantCulture)]["stats"]; if (stats.Valid == false || stats.Children == null) { return(false); } foreach (var stat in stats.Children) { if (stat.Valid == false) { continue; } var rawType = stat["type_int"].Valid ? stat["type_int"].AsInteger(0) : stat["type"].AsInteger(0); var type = (APITypes.UserStatType)rawType; switch (type) { case APITypes.UserStatType.Invalid: { break; } case APITypes.UserStatType.Integer: { var id = stat["name"].AsString(""); string name = GetLocalizedString(stat["display"]["name"], currentLanguage, id); this._StatDefinitions.Add(new Stats.IntegerStatDefinition() { Id = stat["name"].AsString(""), DisplayName = name, MinValue = stat["min"].AsInteger(int.MinValue), MaxValue = stat["max"].AsInteger(int.MaxValue), MaxChange = stat["maxchange"].AsInteger(0), IncrementOnly = stat["incrementonly"].AsBoolean(false), DefaultValue = stat["default"].AsInteger(0), Permission = stat["permission"].AsInteger(0), }); break; } case APITypes.UserStatType.Float: case APITypes.UserStatType.AverageRate: { var id = stat["name"].AsString(""); string name = GetLocalizedString(stat["display"]["name"], currentLanguage, id); this._StatDefinitions.Add(new Stats.FloatStatDefinition() { Id = stat["name"].AsString(""), DisplayName = name, MinValue = stat["min"].AsFloat(float.MinValue), MaxValue = stat["max"].AsFloat(float.MaxValue), MaxChange = stat["maxchange"].AsFloat(0.0f), IncrementOnly = stat["incrementonly"].AsBoolean(false), DefaultValue = stat["default"].AsFloat(0.0f), Permission = stat["permission"].AsInteger(0), }); break; } case APITypes.UserStatType.Achievements: case APITypes.UserStatType.GroupAchievements: { if (stat.Children != null) { foreach (var bits in stat.Children.Where( b => string.Compare(b.Name, "bits", StringComparison.InvariantCultureIgnoreCase) == 0)) { if (bits.Valid == false || bits.Children == null) { continue; } foreach (var bit in bits.Children) { string id = bit["name"].AsString(""); string name = GetLocalizedString(bit["display"]["name"], currentLanguage, id); string desc = GetLocalizedString(bit["display"]["desc"], currentLanguage, ""); this._AchievementDefinitions.Add(new Stats.AchievementDefinition() { Id = id, Name = name, Description = desc, IconNormal = bit["display"]["icon"].AsString(""), IconLocked = bit["display"]["icon_gray"].AsString(""), IsHidden = bit["display"]["hidden"].AsBoolean(false), Permission = bit["permission"].AsInteger(0), }); } } } break; } default: { throw new InvalidOperationException("invalid stat type"); } } } return(true); }
public bool ReadAsBinary(Stream input) { this.Children = new List <KeyValue>(); try { while (true) { var type = (KeyValueType)input.ReadValueU8(); if (type == KeyValueType.End) { break; } var current = new KeyValue { Type = type, Name = input.ReadStringUnicode(), }; switch (type) { case KeyValueType.None: { current.ReadAsBinary(input); break; } case KeyValueType.String: { current.Valid = true; current.Value = input.ReadStringUnicode(); break; } case KeyValueType.WideString: { throw new FormatException("wstring is unsupported"); } case KeyValueType.Int32: { current.Valid = true; current.Value = input.ReadValueS32(); break; } case KeyValueType.UInt64: { current.Valid = true; current.Value = input.ReadValueU64(); break; } case KeyValueType.Float32: { current.Valid = true; current.Value = input.ReadValueF32(); break; } case KeyValueType.Color: { current.Valid = true; current.Value = input.ReadValueU32(); break; } case KeyValueType.Pointer: { current.Valid = true; current.Value = input.ReadValueU32(); break; } default: { throw new FormatException(); } } if (input.Position >= input.Length) { throw new FormatException(); } this.Children.Add(current); } this.Valid = true; return(input.Position == input.Length); } catch (Exception) { return(false); } }