Example #1
0
        private void LoadTableData()
        {
            DataGrid.Rows.Clear();
            DataGrid.Columns.Clear();

            data = new TableData();
            using (BinaryReader reader = new BinaryReader(File.Open(file.FullName, FileMode.Open)))
            {
                data.Deserialize(0, reader.BaseStream, Gibbed.IO.Endian.Little);
            }

            foreach (TableData.Column column in data.Columns)
            {
                MTableColumn newCol = new MTableColumn();
                newCol.NameHash   = column.NameHash;
                newCol.HeaderText = GetColumnName(newCol.NameHash);
                newCol.Unk2       = column.Unknown2;
                newCol.Unk3       = column.Unknown3;
                newCol.TypeM2     = column.Type;

                switch (newCol.TypeM2)
                {
                case TableData.ColumnType.Boolean:
                    newCol.CellTemplate = new DataGridViewCheckBoxCell();
                    break;

                case TableData.ColumnType.String16:
                case TableData.ColumnType.String32:
                case TableData.ColumnType.String64:
                    newCol.CellTemplate = new DataGridViewTextBoxCell();
                    break;

                default:
                    newCol.CellTemplate = new DataGridViewTextBoxCell();
                    break;
                }
                DataGrid.Columns.Add(newCol);
            }

            foreach (TableData.Row row in data.Rows)
            {
                DataGrid.Rows.Add(row.Values.ToArray());
            }

            Text          = Language.GetString("$TABLE_EDITOR_TITLE");
            bIsFileEdited = false;
        }
Example #2
0
        public ResourceEntry WriteTableEntry(ResourceEntry entry, XPathNodeIterator nodes, string sdsFolder, XmlNode descNode)
        {
            TableResource resource = new TableResource();

            //number of tables
            nodes.Current.MoveToNext();
            int count = nodes.Current.ValueAsInt;

            //read tables and add to resource.
            for (int i = 0; i != count; i++)
            {
                //goto next and read file name.
                nodes.Current.MoveToNext();
                string file = nodes.Current.Value;

                //create file data.
                TableData data = new TableData();

                //now read..
                using (BinaryReader reader = new BinaryReader(File.Open(sdsFolder + file, FileMode.Open)))
                {
                    data.Deserialize(1, reader.BaseStream, Endian);
                    data.Name     = file;
                    data.NameHash = FNV64.Hash(data.Name);
                }

                resource.Tables.Add(data);
            }

            //get version, always 1 Mafia II (2010) is 1, Mafia: DE (2020) is 2.
            nodes.Current.MoveToNext();
            entry.Version = Convert.ToUInt16(nodes.Current.Value);

            //create a temporary memory stream, merge all data and then fill entry data.
            using (MemoryStream stream = new MemoryStream())
            {
                resource.Serialize(entry.Version, stream, Endian.Little);
                entry.Data            = stream.ToArray();
                entry.SlotRamRequired = (uint)entry.Data.Length + 128;
            }

            //fin.
            return(entry);
        }
Example #3
0
        public void Initialise()
        {
            TableData data = new TableData();

            using (BinaryReader reader = new BinaryReader(File.Open(file.FullName, FileMode.Open)))
            {
                data.Deserialize(0, reader.BaseStream, Gibbed.IO.Endian.Little);
            }

            foreach (TableData.Column column in data.Columns)
            {
                DataGridViewColumn newCol = new DataGridViewColumn();
                newCol.HeaderText = column.NameHash.ToString("X8");

                switch (column.Type)
                {
                case TableData.ColumnType.Boolean:
                    newCol.CellTemplate = new DataGridViewCheckBoxCell();
                    break;

                case TableData.ColumnType.String16:
                case TableData.ColumnType.String32:
                case TableData.ColumnType.String64:
                    newCol.CellTemplate = new DataGridViewTextBoxCell();
                    break;

                default:
                    newCol.CellTemplate = new DataGridViewTextBoxCell();
                    break;
                }
                //newCol.CellTemplate = new DataGridViewTextBoxCell();
                DataGrid.Columns.Add(newCol);
            }

            foreach (TableData.Row row in data.Rows)
            {
                DataGrid.Rows.Add(row.Values.ToArray());
            }

            ShowDialog();
        }