Exemplo n.º 1
0
        private bool DecompressDMA()
        {
            if(!IsROMLoaded)
            {
                return false;
            }

            for (int i = 0; i < DMATable.Count; i++)
            {
                DMAFile dma = DMATable[i];
                if(dma.DMAInfo.CFlag == 0x1)
                {
                    //compressed

                    //Decompress here
                    byte[] newDMAData;
                    if(StarFoxRomInfo.DecompressMIO0(dma.GetAsBytes(), out newDMAData))
                    {
                        dma.LoadFromBytes(newDMAData);

                        dma.DMAInfo.PEnd = dma.DMAInfo.VStart + (uint)newDMAData.Length;
                        dma.DMAInfo.PStart = dma.DMAInfo.VStart;
                        dma.DMAInfo.CFlag = 0x0;

                        _dmaTableDMA.DMATableEntries[i].CFlag = dma.DMAInfo.CFlag;
                    }
                    else
                    {
                        //Catastrophic failure, just quit out
                        return false;
                    }

                }
                else
                {
                    //uncompressed
                    dma.DMAInfo.PEnd = dma.DMAInfo.VStart + (dma.DMAInfo.PEnd - dma.DMAInfo.PStart);
                    dma.DMAInfo.PStart = dma.DMAInfo.VStart;
                }
            }

            Size = DMATable.Last().DMAInfo.PEnd;
            FixDMATable();

            return true;
        }
Exemplo n.º 2
0
        public byte[] GetAsBytes()
        {
            if (!IsROMLoaded)
                return null;

            uint fullLength = DMATable.Last().DMAInfo.PEnd;

            //Rom length must be multiple of 0x400000
            if(fullLength % 0x400000 != 0)
                fullLength = (uint)Math.Ceiling((double)fullLength / 0x400000) * 0x400000;

            //Size = fullLength;

            byte[] newRomData = new byte[fullLength];

            foreach (DMAFile dma in DMATable)
            {
                Array.Copy(dma.GetAsBytes(), 0, newRomData, dma.DMAInfo.PStart, dma.DMAInfo.PEnd - dma.DMAInfo.PStart);
            }

            return newRomData;
        }