public LevelDMAFileInfo(LevelDMAFile dma)
     : base(dma)
 {
     _dma = dma;
 }
Esempio n. 2
0
        private bool BytesToDMATable(byte[] data, Endianness RomEndianness)
        {
            //Using the DMA Table offset, break up the file into its constituent DMA blocks.
            if (DMATableOffset == 0x0)
            {
                return false;
            }

            IsCompressed = false;

            DMATable.Clear();
            _levelDMAs.Clear();
            _headerDMA = null;
            _dmaTableDMA = null;
            _referenceDMA = null;

            int CurrentPos = (int)DMATableOffset;

            try
            {
                while (CurrentPos < data.Length - 16)
                {
                    uint VStart = ByteHelper.ReadUInt(data, CurrentPos, RomEndianness);
                    uint PStart = ByteHelper.ReadUInt(data, CurrentPos + 4, RomEndianness);
                    uint PEnd = ByteHelper.ReadUInt(data, CurrentPos + 8, RomEndianness);
                    uint CompFlag = ByteHelper.ReadUInt(data, CurrentPos + 12, RomEndianness);

                    //End of the DMA Header
                    if ((PStart == 0x00) && (PEnd == 0x00)) break;

                    //Create the actual data
                    byte[] dmaBytes = new byte[PEnd - PStart];
                    Array.Copy(data, PStart, dmaBytes, 0, dmaBytes.Length);

                    DMAFile entry;
                    switch(DMATable.Count) //Should act as an index for the current dma file
                    {
                        case 0: //Header DMA
                            entry = new HeaderDMAFile(dmaBytes, DMATable.Count);
                            _headerDMA = (HeaderDMAFile)entry;
                            break;
                        case 1: //Reference DMA
                            entry = new ReferenceDMAFile(dmaBytes, DMATable.Count);
                            _referenceDMA = (ReferenceDMAFile)entry;
                            break;
                        case 2: //DMA Table DMA
                            entry = new DMATableDMAFile(dmaBytes, DMATable.Count);
                            _dmaTableDMA = (DMATableDMAFile)entry;
                            break;
                        case 54: //Dialogue DMA
                            entry = new DialogueDMAFile(dmaBytes, DMATable.Count);
                            _dialogueDMA = (DialogueDMAFile)entry;
                            break;
                        //case 12: Appears broken right now, the Game Object table is set up differently than the other files. Possibly a prototype setup?
                        case 18:
                        case 19:
                        case 20:
                        case 26:
                        case 27:
                        case 28:
                        case 29:
                        case 30:
                        case 31:
                        case 33:
                        case 34:
                        case 35:
                        case 36:
                        case 37:
                        case 38:
                        case 39:
                        case 47:
                        case 53:
                            entry = new LevelDMAFile(dmaBytes, DMATable.Count, (int)_referenceDMA.LevelHeaderOffsets[StarFoxRomInfo.DMATableToLevelIndex(DMATable.Count)], 
                                (int)_referenceDMA.LevelInfoOffsets[StarFoxRomInfo.DMATableToLevelIndex(DMATable.Count)]);
                            _levelDMAs.Add(entry as LevelDMAFile);
                            break;
                        default: //Others
                            entry = new DMAFile(dmaBytes, DMATable.Count);
                            break;
                    }

                    DMATable.Add(entry);

                    CurrentPos += 16;
                }

                //Now set the DMA Headers
                if (_dmaTableDMA != null)
                {
                    for (int i = 0; i < DMATable.Count; i++)
                    {
                        DMATable[i].DMAInfo = _dmaTableDMA.DMATableEntries[i];

                        if (DMATable[i].DMAInfo.CFlag == 1)
                            IsCompressed = true;
                    }
                }

                if (_referenceDMA != null && _levelDMAs.Count > 0)
                {
                    //Parse out the F3DEX info
                    //LoadROMResources();
                }
            }
            catch
            {
                //Error log entry?
                return false;
            }

            return true;

            ////Automatically decompress on loading?
            //if (IsCompressed)
            //{
            //    if (DecompressDMA())
            //    {
            //        FixCRC();
            //    }
            //}
        }