using MissionStatsStar; using System; using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; using System.Diagnostics; using System.Globalization; using System.IO; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Xml; using System.Xml.Serialization; namespace MissionStatsStar { /// [Serializable()] [XmlType(AnonymousType = true, TypeName = "CategoryPermutation")] public partial class CategoryPermutation : ModelBase { /// [XmlTextAttribute()] public string Value { get { return m_value; } set { m_value = value; NotifyPropertyChanged("Value"); } } private string m_value; } /// [Serializable()] [XmlType(AnonymousType = true, TypeName = "Leaderboard")] public partial class Leaderboard : ModelBase { public override string ToString() { return Name + " (" + Id + ")"; } /// [XmlArray(Form = System.Xml.Schema.XmlSchemaForm.Unqualified, ElementName = "CategoryPermutations")] [XmlArrayItem("CategoryPermutation", Form = System.Xml.Schema.XmlSchemaForm.Unqualified)] public ObservableCollection CategoryPermutations { get { return m_categoryPermutations; } set { m_categoryPermutations = value; NotifyPropertyChanged("CategoryPermutations"); } } /// [XmlArray(Form = System.Xml.Schema.XmlSchemaForm.Unqualified, ElementName = "Columns")] [XmlArrayItem("Column", Form = System.Xml.Schema.XmlSchemaForm.Unqualified, IsNullable = false)] public ObservableCollection Columns { get { return m_columns; } set { m_columns = value; NotifyPropertyChanged("Columns"); } } /// [XmlAttribute(AttributeName = "id")] public string Id { get { return m_id; } set { m_id = value; NotifyPropertyChanged("Id"); } } /// [XmlAttribute(AttributeName = "name")] public string Name { get { return m_name; } set { m_name = value; NotifyPropertyChanged("Name"); } } /// [XmlAttribute(AttributeName = "entryExpiration")] public string EntryExpiration { get { return m_entryExpiration; } set { m_entryExpiration = value; NotifyPropertyChanged("EntryExpiration"); } } /// [XmlAttribute(AttributeName = "resetType")] public string ResetType { get { return m_resetType; } set { m_resetType = value; NotifyPropertyChanged("ResetType"); } } private ObservableCollection m_categoryPermutations; private ObservableCollection m_columns; private string m_id; private string m_name; private string m_entryExpiration; private string m_resetType; } /// [Serializable()] [XmlType(AnonymousType = true, TypeName = "GameInput")] public partial class GameInput : ModelBase { /// [XmlAttribute(AttributeName = "inputId")] public string InputId { get { return m_inputId; } set { m_inputId = value; NotifyPropertyChanged("InputId"); } } private string m_inputId; } /// [Serializable()] [XmlType(AnonymousType = true, TypeName = "ColumnInput")] public partial class ColumnInput : ModelBase { /// [XmlAttribute(AttributeName = "ordinal")] public string Ordinal { get { return m_ordinal; } set { m_ordinal = value; NotifyPropertyChanged("Ordinal"); } } /// [XmlAttribute(AttributeName = "columnId")] public string ColumnId { get { return m_columnId; } set { m_columnId = value; NotifyPropertyChanged("ColumnId"); } } private string m_ordinal; private string m_columnId; } /// [Serializable()] [XmlType(AnonymousType = true, TypeName = "Aggregation")] public partial class Aggregation : ModelBase { /// [XmlElement("ColumnInput", Form = System.Xml.Schema.XmlSchemaForm.Unqualified)] public ObservableCollection ColumnInput { get { return m_columnInput; } set { m_columnInput = value; NotifyPropertyChanged("ColumnInput"); } } /// [XmlElement("GameInput", Form = System.Xml.Schema.XmlSchemaForm.Unqualified)] public GameInput GameInput { get { return m_gameInput; } set { m_gameInput = value; NotifyPropertyChanged("GameInput"); } } /// [XmlAttribute(AttributeName = "type")] public string Type { get { return m_type; } set { m_type = value; NotifyPropertyChanged("Type"); } } /// [XmlAttribute(AttributeName = "conditionalOnColumnId")] public string ConditionalOnColumnId { get { return m_conditionalOnColumnId; } set { m_conditionalOnColumnId = value; NotifyPropertyChanged("ConditionalOnColumnId"); } } private ObservableCollection m_columnInput; private GameInput m_gameInput; private string m_type; private string m_conditionalOnColumnId; } /// [Serializable()] [XmlType(AnonymousType = true, TypeName = "Column")] public partial class Column : ModelBase { public override string ToString() { return Name + " (" + Id + ")"; } /// [XmlElement(Form = System.Xml.Schema.XmlSchemaForm.Unqualified, ElementName = "Aggregation")] public Aggregation Aggregation { get { return m_aggregation; } set { m_aggregation = value; NotifyPropertyChanged("Aggregation"); } } /// [XmlAttribute(AttributeName = "id")] public string Id { get { return m_id; } set { m_id = value; NotifyPropertyChanged("Id"); } } /// [XmlAttribute(AttributeName = "name")] public string Name { get { return m_name; } set { m_name = value; NotifyPropertyChanged("Name"); } } /// [XmlAttribute(AttributeName = "ordinal")] public string Ordinal { get { return m_ordinal; } set { m_ordinal = value; NotifyPropertyChanged("Ordinal"); } } /// [XmlAttribute(AttributeName = "isRankingColumn")] public string IsRankingColumn { get { return m_isRankingColumn; } set { m_isRankingColumn = value; NotifyPropertyChanged("IsRankingColumn"); } } private Aggregation m_aggregation; private string m_id; private string m_name; private string m_ordinal; private string m_isRankingColumn; public MishStatStar.StatCategory statCategoryLastBoundTo; } /// [Serializable()] [XmlType(AnonymousType = true, TypeName = "Category")] public partial class Category : ModelBase { /// [XmlAttribute(AttributeName = "name")] public string Name { get { return m_name; } set { m_name = value; NotifyPropertyChanged("Name"); } } private string m_name; } /// [Serializable()] [XmlType(AnonymousType = true, TypeName = "Input")] public partial class Input : ModelBase { /// [XmlAttribute(AttributeName = "id")] public string Id { get { return m_id; } set { m_id = value; NotifyPropertyChanged("Id"); } } /// [XmlAttribute(AttributeName = "name")] public string Name { get { return m_name; } set { m_name = value; NotifyPropertyChanged("Name"); } } /// [XmlAttribute(AttributeName = "dataType")] public string DataType { get { return m_dataType; } set { m_dataType = value; NotifyPropertyChanged("DataType"); } } private string m_id; private string m_name; private string m_dataType; } /// [Serializable()] [XmlType(AnonymousType = true, TypeName = "LeaderboardsConfiguration")] public partial class LeaderboardsConfiguration : ModelBase { /// [XmlArray(Form = System.Xml.Schema.XmlSchemaForm.Unqualified, ElementName = "Inputs")] [XmlArrayItem("Input", Form = System.Xml.Schema.XmlSchemaForm.Unqualified, IsNullable = false)] public ObservableCollection Inputs { get { return m_inputs; } set { m_inputs = value; NotifyPropertyChanged("Inputs"); } } /// [XmlArray(Form = System.Xml.Schema.XmlSchemaForm.Unqualified, ElementName = "Categories")] [XmlArrayItem("Category", Form = System.Xml.Schema.XmlSchemaForm.Unqualified, IsNullable = false)] public ObservableCollection Categories { get { return m_categories; } set { m_categories = value; NotifyPropertyChanged("Categories"); } } /// [XmlArray(Form = System.Xml.Schema.XmlSchemaForm.Unqualified, ElementName = "Leaderboards")] [XmlArrayItem("Leaderboard", Form = System.Xml.Schema.XmlSchemaForm.Unqualified, IsNullable = false)] public ObservableCollection Leaderboards { get { return m_leaderboards; } set { m_leaderboards = value; NotifyPropertyChanged("Leaderboards"); } } private ObservableCollection m_inputs; private ObservableCollection m_categories; private ObservableCollection m_leaderboards; } /// /// The base class of objects in the Model namespace. The Model namespace CONTAINS NO LOGIC. /// Marked as Serializable for Copy/Paste to/from the system clipboard. AllAttributes /// and AllElements are used to preserve unrecognized XML nodes. /// [Serializable()] public class ModelBase : INotifyPropertyChanged { #region INotifyPropertyChanged public event PropertyChangedEventHandler PropertyChanged; protected void NotifyPropertyChanged(string propertyName) { if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); } } #endregion public XmlAttribute[] AllAttributes { get { return m_allAttributes; } set { m_allAttributes = value; NotifyPropertyChanged("AllAttributes"); } } public XmlElement[] AllElements { get { return m_allElements; } set { m_allElements = value; NotifyPropertyChanged("AllElements"); } } private XmlAttribute[] m_allAttributes; private XmlElement[] m_allElements; } /// [Serializable()] [XmlType(AnonymousType = true, TypeName = "RockstarScsGameConfiguration")] [XmlRootAttribute(Namespace = "", ElementName = "RockstarScsGameConfiguration", IsNullable = false)] public partial class ScsGameConfiguration : ModelBase { /// [XmlElement(Form = System.Xml.Schema.XmlSchemaForm.Unqualified, ElementName = "LeaderboardsConfiguration")] public LeaderboardsConfiguration LeaderboardsConfiguration { get { return m_leaderboardsConfiguration; } set { m_leaderboardsConfiguration = value; NotifyPropertyChanged("LeaderboardsConfiguration"); } } /// [XmlAttribute("gameTitle")] public string GameTitle { get { return m_gameTitle; } set { m_gameTitle = value; NotifyPropertyChanged("GameTitle"); } } /// [XmlAttribute("configVersion")] public string ConfigVersion { get { return m_configVersion; } set { m_configVersion = value; NotifyPropertyChanged("ConfigVersion"); } } /// [XmlAttribute("fileVersion")] public int FileVersion { get { return m_fileVersion; } set { m_fileVersion = value; NotifyPropertyChanged("FileVersion"); } } private LeaderboardsConfiguration m_leaderboardsConfiguration; private string m_gameTitle; private string m_configVersion; private int m_fileVersion; } /////////////////////// /////////////////////// /////////////////////// /////////////////////// /////////////////////// /////////////////////// class ScsGameConfigObject { public readonly static ScsGameConfigObject Instance = new ScsGameConfigObject(); /// /// This is used to add the [XmlAnyAttribute()] and [XmlAnyElement()] attributes to the /// AllAttributes and AllElements properties on ModelBase, respectively. If these attributes /// are added in code (compile time) then XmlUnknownAttribute and XmlUnknownElement exceptions /// are never thrown during load, making it impossible to output debug messages for those /// errors. /// private static XmlAttributeOverrides GetSerializationOverrides() { XmlAttributes anyAttAttributes = new XmlAttributes(); XmlAnyAttributeAttribute anyAtt = new XmlAnyAttributeAttribute(); anyAttAttributes.XmlAnyAttribute = anyAtt; XmlAttributes anyElemAttributes = new XmlAttributes(); XmlAnyElementAttribute anyElem = new XmlAnyElementAttribute(); anyElemAttributes.XmlAnyElements.Add(anyElem); XmlAttributeOverrides overrides = new XmlAttributeOverrides(); overrides.Add(typeof(ModelBase), "AllAttributes", anyAttAttributes); overrides.Add(typeof(ModelBase), "AllElements", anyElemAttributes); return overrides; } public void LoadConfigFromFile(string fileName) { using (StreamReader reader = new StreamReader(fileName)) { XmlSerializer serializer = new XmlSerializer(typeof(ScsGameConfiguration), GetSerializationOverrides()); m_config = serializer.Deserialize(reader) as ScsGameConfiguration; //DebugOutput.WriteLine("Successfully loading config from " + fileName); ///DebugOutput.WriteLine("Inputs: " + m_config.LeaderboardsConfiguration.Inputs.Count); //DebugOutput.WriteLine("Leaderboards: " + m_config.LeaderboardsConfiguration.Leaderboards.Count); //DebugOutput.WriteLine("Categories: " + m_config.LeaderboardsConfiguration.Categories.Count); } } public ScsGameConfiguration GetConfig() { return m_config; } public Input GetInputById(int inputId) { foreach (Input inpt in m_config.LeaderboardsConfiguration.Inputs) { int id = Convert.ToInt32(inpt.Id); if (id == inputId) { return inpt; } } return null; } public Column GetColumnByIdOnLeaderboard(Leaderboard lb, int id) { foreach (Column col in lb.Columns) { int colId = Convert.ToInt32(col.Id); if (colId == id) { return col; } } return null; } public Input[] GetInputsOnLeaderboard(Leaderboard lb) { List inputList = new List(); foreach (Column col in lb.Columns) { if (col.Aggregation.GameInput != null) { int inputID = Convert.ToInt32(col.Aggregation.GameInput.InputId); if (inputID > 0) { //Find the input with this ID. Input lbInput = GetInputById(inputID); if (lbInput != null) { inputList.Add(lbInput); } } } } return inputList.ToArray(); } public ScsGameConfiguration m_config; } }