Exemplo n.º 1
0
        private void ParseBac()
        {
            int offset = BitConverter.ToInt32(rawBytes, 16);
            int count  = BitConverter.ToInt32(rawBytes, 8);

            bacFile.I_20       = BitConverter_Ex.ToInt32Array(rawBytes, 20, 3);
            bacFile.F_32       = BitConverter_Ex.ToFloat32Array(rawBytes, 32, 12);
            bacFile.I_80       = BitConverter_Ex.ToInt32Array(rawBytes, 80, 4);
            bacFile.BacEntries = AsyncObservableCollection <BAC_Entry> .Create();

            for (int i = 0; i < count; i++)
            {
                int typeListOffset = BitConverter.ToInt32(rawBytes, offset + 8);
                int typeListCount  = BitConverter.ToInt16(rawBytes, offset + 4);

                bacFile.BacEntries.Add(new BAC_Entry()
                {
                    Flag  = (BAC_Entry.Flags)BitConverter.ToUInt32(rawBytes, offset + 0),
                    Index = i.ToString()
                });

                for (int a = 0; a < typeListCount; a++)
                {
                    int thisType       = BitConverter.ToInt16(rawBytes, typeListOffset + 0);
                    int thisTypeCount  = BitConverter.ToInt16(rawBytes, typeListOffset + 2);
                    int thisTypeOffset = BitConverter.ToInt32(rawBytes, typeListOffset + 8);


                    if (thisTypeOffset != 0)
                    {
                        switch (thisType)
                        {
                        case 0:
                            bacFile.BacEntries[i].Type0 = BAC_Type0.Read(rawBytes, bytes, thisTypeOffset, thisTypeCount);
                            break;

                        case 1:
                            bacFile.BacEntries[i].Type1 = BAC_Type1.Read(rawBytes, bytes, thisTypeOffset, thisTypeCount);
                            break;

                        case 2:
                            bacFile.BacEntries[i].Type2 = BAC_Type2.Read(rawBytes, bytes, thisTypeOffset, thisTypeCount);
                            break;

                        case 3:
                            bacFile.BacEntries[i].Type3 = BAC_Type3.Read(rawBytes, bytes, thisTypeOffset, thisTypeCount);
                            break;

                        case 4:
                            bacFile.BacEntries[i].Type4 = BAC_Type4.Read(rawBytes, bytes, thisTypeOffset, thisTypeCount);
                            break;

                        case 5:
                            bacFile.BacEntries[i].Type5 = BAC_Type5.Read(rawBytes, bytes, thisTypeOffset, thisTypeCount);
                            break;

                        case 6:
                            bacFile.BacEntries[i].Type6 = BAC_Type6.Read(rawBytes, bytes, thisTypeOffset, thisTypeCount);
                            break;

                        case 7:
                            bacFile.BacEntries[i].Type7 = BAC_Type7.Read(rawBytes, bytes, thisTypeOffset, thisTypeCount);
                            break;

                        case 8:
                            bacFile.BacEntries[i].Type8 = BAC_Type8.Read(rawBytes, bytes, thisTypeOffset, thisTypeCount);
                            break;

                        case 9:
                            bacFile.BacEntries[i].Type9 = BAC_Type9.Read(rawBytes, bytes, thisTypeOffset, thisTypeCount);
                            break;

                        case 10:
                            bacFile.BacEntries[i].Type10 = BAC_Type10.Read(rawBytes, bytes, thisTypeOffset, thisTypeCount);
                            break;

                        case 11:
                            bacFile.BacEntries[i].Type11 = BAC_Type11.Read(rawBytes, bytes, thisTypeOffset, thisTypeCount);
                            break;

                        case 12:
                            bacFile.BacEntries[i].Type12 = BAC_Type12.Read(rawBytes, bytes, thisTypeOffset, thisTypeCount);
                            break;

                        case 13:
                            bacFile.BacEntries[i].Type13 = BAC_Type13.Read(rawBytes, bytes, thisTypeOffset, thisTypeCount);
                            break;

                        case 14:
                            bacFile.BacEntries[i].Type14 = BAC_Type14.Read(rawBytes, bytes, thisTypeOffset, thisTypeCount);
                            break;

                        case 15:
                            bacFile.BacEntries[i].Type15 = BAC_Type15.Read(rawBytes, bytes, thisTypeOffset, thisTypeCount);
                            break;

                        case 16:
                            bacFile.BacEntries[i].Type16 = BAC_Type16.Read(rawBytes, bytes, thisTypeOffset, thisTypeCount);
                            break;

                        case 17:
                            bacFile.BacEntries[i].Type17 = BAC_Type17.Read(rawBytes, bytes, thisTypeOffset, thisTypeCount, IsType17Small(thisTypeOffset, thisTypeCount, i));
                            break;

                        case 18:
                            bacFile.BacEntries[i].Type18 = BAC_Type18.Read(rawBytes, bytes, thisTypeOffset, thisTypeCount);
                            break;

                        case 19:
                            bacFile.BacEntries[i].Type19 = BAC_Type19.Read(rawBytes, bytes, thisTypeOffset, thisTypeCount);
                            break;

                        case 20:
                            bacFile.BacEntries[i].Type20 = BAC_Type20.Read(rawBytes, bytes, thisTypeOffset, thisTypeCount);
                            break;

                        case 21:
                            bacFile.BacEntries[i].Type21 = BAC_Type21.Read(rawBytes, bytes, thisTypeOffset, thisTypeCount);
                            break;

                        case 22:
                            bacFile.BacEntries[i].Type22 = BAC_Type22.Read(rawBytes, bytes, thisTypeOffset, thisTypeCount);
                            break;

                        case 23:
                            bacFile.BacEntries[i].Type23 = BAC_Type23.Read(rawBytes, bytes, thisTypeOffset, thisTypeCount);
                            break;

                        case 24:
                            bacFile.BacEntries[i].Type24 = BAC_Type24.Read(rawBytes, bytes, thisTypeOffset, thisTypeCount);
                            break;

                        case 25:
                            bacFile.BacEntries[i].Type25 = BAC_Type25.Read(rawBytes, bytes, thisTypeOffset, thisTypeCount);
                            break;

                        case 26:
                            bacFile.BacEntries[i].Type26 = BAC_Type26.Read(rawBytes, bytes, thisTypeOffset, thisTypeCount);
                            break;

                        case 27:
                            bacFile.BacEntries[i].Type27 = BAC_Type27.Read(rawBytes, bytes, thisTypeOffset, thisTypeCount);
                            break;

                        default:
                            throw new InvalidDataException(String.Format("Parse failed. Unknown BacType encountered ({0})\nOffset: {1}\nCount: {2}.", thisType, thisTypeOffset, thisTypeCount));
                        }
                    }
                    else
                    {
                        if (bacFile.BacEntries[i].TypeDummy == null)
                        {
                            bacFile.BacEntries[i].TypeDummy = new List <int>();
                        }
                        bacFile.BacEntries[i].TypeDummy.Add(thisType);
                    }


                    typeListOffset += 16;
                }


                offset += 16;
            }
        }
Exemplo n.º 2
0
        private void WriteBac()
        {
            SortEntries();

            int                count           = (bacFile.BacEntries != null) ? bacFile.BacEntries.Count() : 0;
            List <int>         BacEntryOffsets = new List <int>();
            List <List <int> > TypeOffsets     = new List <List <int> >();

            //Header
            bytes.AddRange(BitConverter.GetBytes(count));
            bytes.AddRange(new byte[4]);
            bytes.AddRange(BitConverter.GetBytes(96));
            bytes.AddRange(BitConverter_Ex.GetBytes(bacFile.I_20));
            bytes.AddRange(BitConverter_Ex.GetBytes(bacFile.F_32));
            bytes.AddRange(BitConverter_Ex.GetBytes(bacFile.I_80));

            //Bac_Entries
            for (int i = 0; i < count; i++)
            {
                if (bacFile.BacEntries[i].TypeDummy == null)
                {
                    bacFile.BacEntries[i].TypeDummy = new List <int>();
                }

                bytes.AddRange(BitConverter.GetBytes((uint)bacFile.BacEntries[i].Flag));
                bytes.AddRange(BitConverter.GetBytes((short)GetSubEntryCount(bacFile.BacEntries[i])));
                bytes.AddRange(BitConverter.GetBytes((short)0));
                BacEntryOffsets.Add(bytes.Count());
                bytes.AddRange(new byte[8]);
            }

            //Bac_SubEntries
            for (int i = 0; i < count; i++)
            {
                TypeOffsets.Add(new List <int>());
                int   subEntryCount = GetSubEntryCount(bacFile.BacEntries[i]);
                int[] types         = GetSubEntryTypes(bacFile.BacEntries[i]);

                if (subEntryCount > 0)
                {
                    bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(bytes.Count()), BacEntryOffsets[i]);

                    for (int a = 0; a < subEntryCount; a++)
                    {
                        bytes.AddRange(BitConverter.GetBytes((short)types[a]));
                        bytes.AddRange(BitConverter.GetBytes((short)GetTypeCount(bacFile.BacEntries[i], types[a])));
                        bytes.AddRange(new byte[4]);
                        TypeOffsets[i].Add(bytes.Count());
                        bytes.AddRange(new byte[8]);
                    }
                }
            }

            //Bac Types
            for (int i = 0; i < count; i++)
            {
                int   subEntryCount = GetSubEntryCount(bacFile.BacEntries[i]);
                int[] types         = GetSubEntryTypes(bacFile.BacEntries[i]);

                for (int a = 0; a < subEntryCount; a++)
                {
                    if (bacFile.BacEntries[i].TypeDummy.IndexOf(types[a]) == -1)
                    {
                        bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(bytes.Count()), TypeOffsets[i][a]);

                        switch (types[a])
                        {
                        case 0:
                            bytes.AddRange(BAC_Type0.Write(bacFile.BacEntries[i].Type0));
                            break;

                        case 1:
                            bytes.AddRange(BAC_Type1.Write(bacFile.BacEntries[i].Type1));
                            break;

                        case 2:
                            bytes.AddRange(BAC_Type2.Write(bacFile.BacEntries[i].Type2));
                            break;

                        case 3:
                            bytes.AddRange(BAC_Type3.Write(bacFile.BacEntries[i].Type3));
                            break;

                        case 4:
                            bytes.AddRange(BAC_Type4.Write(bacFile.BacEntries[i].Type4));
                            break;

                        case 5:
                            bytes.AddRange(BAC_Type5.Write(bacFile.BacEntries[i].Type5));
                            break;

                        case 6:
                            bytes.AddRange(BAC_Type6.Write(bacFile.BacEntries[i].Type6));
                            break;

                        case 7:
                            bytes.AddRange(BAC_Type7.Write(bacFile.BacEntries[i].Type7));
                            break;

                        case 8:
                            bytes.AddRange(BAC_Type8.Write(bacFile.BacEntries[i].Type8));
                            break;

                        case 9:
                            bytes.AddRange(BAC_Type9.Write(bacFile.BacEntries[i].Type9));
                            break;

                        case 10:
                            bytes.AddRange(BAC_Type10.Write(bacFile.BacEntries[i].Type10));
                            break;

                        case 11:
                            bytes.AddRange(BAC_Type11.Write(bacFile.BacEntries[i].Type11));
                            break;

                        case 12:
                            bytes.AddRange(BAC_Type12.Write(bacFile.BacEntries[i].Type12));
                            break;

                        case 13:
                            bytes.AddRange(BAC_Type13.Write(bacFile.BacEntries[i].Type13));
                            break;

                        case 14:
                            bytes.AddRange(BAC_Type14.Write(bacFile.BacEntries[i].Type14));
                            break;

                        case 15:
                            bytes.AddRange(BAC_Type15.Write(bacFile.BacEntries[i].Type15));
                            break;

                        case 16:
                            bytes.AddRange(BAC_Type16.Write(bacFile.BacEntries[i].Type16));
                            break;

                        case 17:
                            bytes.AddRange(BAC_Type17.Write(bacFile.BacEntries[i].Type17));
                            break;

                        case 18:
                            bytes.AddRange(BAC_Type18.Write(bacFile.BacEntries[i].Type18));
                            break;

                        case 19:
                            bytes.AddRange(BAC_Type19.Write(bacFile.BacEntries[i].Type19));
                            break;

                        case 20:
                            bytes.AddRange(BAC_Type20.Write(bacFile.BacEntries[i].Type20));
                            break;

                        case 21:
                            bytes.AddRange(BAC_Type21.Write(bacFile.BacEntries[i].Type21));
                            break;

                        case 22:
                            bytes.AddRange(BAC_Type22.Write(bacFile.BacEntries[i].Type22));
                            break;

                        case 23:
                            bytes.AddRange(BAC_Type23.Write(bacFile.BacEntries[i].Type23));
                            break;

                        case 24:
                            bytes.AddRange(BAC_Type24.Write(bacFile.BacEntries[i].Type24));
                            break;

                        case 25:
                            bytes.AddRange(BAC_Type25.Write(bacFile.BacEntries[i].Type25));
                            break;

                        case 26:
                            bytes.AddRange(BAC_Type26.Write(bacFile.BacEntries[i].Type26));
                            break;

                        case 27:
                            bytes.AddRange(BAC_Type27.Write(bacFile.BacEntries[i].Type27));
                            break;
                        }
                    }
                }
            }
        }