Esempio n. 1
0
        public static byte[] GenerateBFF2(byte[] palette, byte[] data, CGeneric.Compression compressionMethod, int sizeX, int sizeY, string bffName)
        {
            //generate header
            //--> determine GreenAlpha and palette size
            byte greenAlphaIndex = 0;

            if (palette.Length > 0)
            {
                greenAlphaIndex = CTextureManager.GetGreenAlphaValueIndex(palette, compressionMethod);
            }
            //make almost random compressed value.. (10)(because not enought information about it)
            //set displayedWidth equal pixel width (because not enought information about it)
            byte[] sizeXB   = CGeneric.ConvertIntToByteArray16bits(sizeX);
            byte[] sizeYB   = CGeneric.ConvertIntToByteArray16bits(sizeY);
            byte[] name     = CGeneric.ConvertStringToByteArray(bffName);
            byte[] nbColors = new byte[0];
            if (palette.Length > 0)
            {
                nbColors = CGeneric.ConvertIntToByteArray(palette.Length / CTextureManager.GetBytePerPixel(compressionMethod));
            }

            byte[] bff2header = SetHeader(compressionMethod, greenAlphaIndex, 0xE, sizeXB, sizeXB, sizeYB, name, nbColors);

            //concatenate header, palette and compressed data
            byte[] finalData = new byte[bff2header.Length + palette.Length + data.Length];
            Array.Copy(bff2header, 0, finalData, 0, bff2header.Length);
            if (palette.Length > 0)
            {
                Array.Copy(palette, 0, finalData, bff2header.Length, palette.Length);
            }

            Array.Copy(data, 0, finalData, bff2header.Length + palette.Length, data.Length);

            return(finalData);
        }
Esempio n. 2
0
        private int ChunkTextObject(byte[] data, int nbTextObject, int indexDataStart)
        {
            byte[] lengthHeader = new byte[4];
            byte[] lengthText   = new byte[4];
            int    lengthHeaderInt;
            int    lengthTextInt;
            int    totalSize = 0;

            for (int i = 0; i < nbTextObject; i++)
            {
                // get the length of the header text object
                Array.Copy(data, indexDataStart, lengthHeader, 0, lengthHeader.Length);
                lengthHeaderInt = CSBF1TextObject.GetHeaderLength(CGeneric.ConvertByteArrayToInt(lengthHeader));

                //grab the size of the text (add 4 for the header (size text) and determine length of text (multiply per 2))
                Array.Copy(data, indexDataStart + lengthHeaderInt, lengthText, 0, lengthText.Length);
                lengthTextInt = lengthText.Length + CGeneric.ConvertByteArrayToInt(lengthText) * 2;

                //store the new item
                byte[] dataTextObject = new byte[lengthHeaderInt + lengthTextInt];
                Array.Copy(data, indexDataStart, dataTextObject, 0, dataTextObject.Length);
                textObjectList.Add(new CSBF1TextObject(dataTextObject, lengthHeaderInt, lengthTextInt));

                //increment totalSize and indexStart
                indexDataStart += lengthHeaderInt + lengthTextInt;
                totalSize      += lengthHeaderInt + lengthTextInt;
            }
            return(totalSize);
        }
Esempio n. 3
0
        private static (byte[] palette, byte[] data) ConvertRGBAtoMax16Colors(byte[] texture)
        {
            //construct palette and use it.
            List <Color> colors = ExtractPaletteFromByteArray(texture);

            //first array for palette color
            byte[] palette = new byte[colors.Count * 4];

            //second array for palette data
            byte[] finalArray = new byte[texture.Length / 8];

            // write palette
            for (int i = 0; i < colors.Count(); i++)
            {
                palette[i * 4]     = colors[i].R;
                palette[i * 4 + 1] = colors[i].G;
                palette[i * 4 + 2] = colors[i].B;
                palette[i * 4 + 3] = colors[i].A;
            }

            int  index = 0;
            byte nibble1;
            byte nibble2;

            // write data with palette information
            for (int i = 0; i < texture.Length; i += 8)
            {
                nibble1           = GetIndexFromPalette(colors, Color.FromArgb(texture[i + 3], texture[i], texture[i + 1], texture[i + 2]));
                nibble2           = GetIndexFromPalette(colors, Color.FromArgb(texture[i + 7], texture[i + 4], texture[i + 5], texture[i + 6]));
                finalArray[index] = CGeneric.NibbleToByte(nibble1, nibble2);
                index++;
            }
            return(palette, finalArray);
        }
Esempio n. 4
0
        private void WriteListHeader <T>(ref FileStream fs, ref int indexData, List <T> listOfressource) where T : AbsRessource
        {
            for (int index = 0; index < listOfressource.Count(); index++)
            {
                //write size
                fs.Write(CGeneric.ConvertIntToByteArray(listOfressource[index].GetRawData().Length), 0, 4);

                // write index start
                fs.Write(CGeneric.ConvertIntToByteArray(indexData), 0, 4);

                //write name of FIB (BIF Name)
                byte[] nameBIF = System.Text.Encoding.UTF8.GetBytes(listOfressource[index].GetRessourceName());
                fs.Write(nameBIF, 0, nameBIF.Length);

                //fill free space (of name) by 0
                for (int freeSpace = 0; freeSpace < 16 - nameBIF.Length; freeSpace++)
                {
                    fs.WriteByte(0);
                }

                //if data is not pair, add a FF for to be sure it's pair... (because !)
                if (listOfressource[index].GetRawData().Length % 2 == 1)
                {
                    indexData++;
                }

                indexData += listOfressource[index].GetRawData().Length;
            }
        }
Esempio n. 5
0
        public void AddNewTextObject(bool sameScene)
        {
            //get the last element
            if (textObjectList.Count > 0)
            {
                var LastText = textObjectList[textObjectList.Count - 1];

                //add one to ID and take his group
                int textId    = LastText.id + 1;
                int groupText = LastText.group;

                //if the text is independant
                if (!sameScene)
                {
                    textId    += 0x64;
                    groupText += 1;
                }
                //create the new text object
                textObjectList.Add(new CSBF1TextObject(CGeneric.ConvertIntToByteArray(textId), groupText));
            }
            else
            {
                textObjectList.Add(new CSBF1TextObject(CGeneric.ConvertIntToByteArray(0), 0));
            }
        }
Esempio n. 6
0
        private static byte GetByteForCompression(int qtReaded, int qtRepeated)
        {
            byte nib1 = 0;

            switch (qtReaded)
            {
            case 1: nib1 = 0x8; break;

            case int n when(n == 2 || n == 3): nib1 = 0xC; break;

            case int n when(n == 4 || n == 5): nib1 = 0xD; break;

            case int n when(n == 6 || n == 7): nib1 = 0xE; break;

            case int n when(n == 8 || n == 9): nib1 = 0xF; break;
            }
            byte nib2 = (byte)(qtRepeated - 2);

            if (qtReaded % 2 == 1 && nib1 != 0x8)
            {
                nib2 += 8;
            }

            return(CGeneric.NibbleToByte(nib1, nib2));
        }
Esempio n. 7
0
        private int ChunkDynamicObject(byte[] data, int nbDynamicObject, int indexDataStart)
        {
            byte[] lengthData = new byte[4];
            int    lengthDataInt;
            int    totalSize = 0;

            for (int i = 0; i < nbDynamicObject; i++)
            {
                // get the length of the dynamic object
                Array.Copy(data, indexDataStart, lengthData, 0, lengthData.Length);
                lengthDataInt = CSBF1DynamicObject.GetHeaderLength(CGeneric.ConvertByteArrayToInt(lengthData));

                //create the array to add the object
                byte[] dataDynamicObject = new byte[lengthDataInt];

                //create the new dynamicObject item
                Array.Copy(data, indexDataStart, dataDynamicObject, 0, dataDynamicObject.Length);
                dynamicObjectList.Add(new CSBF1DynamicObject(dataDynamicObject));

                //increment totalSize and indexStart
                indexDataStart += lengthDataInt;
                totalSize      += lengthDataInt;
            }
            return(totalSize);
        }
Esempio n. 8
0
        public CSBF1(Byte[] rawData, Byte[] ressourceName) : base(rawData, ressourceName)
        {
            //grab nb ressources used in scene
            int nbTextureScene = CGeneric.ConvertByteArrayToInt(CGeneric.GiveMeArray(rawData, 4, 4));

            //grab names of texture used (bif list)
            bifList = new List <byte[]>();

            for (int i = 0; i < nbTextureScene; i++)
            {
                byte[] tmpArray = new byte[16];
                Array.Copy(rawData, 8 + i * 16, tmpArray, 0, tmpArray.Length);
                bifList.Add(tmpArray);
            }

            //grab index number of scene
            int headerSize = 12 + bifList.Count * 0x10;
            int nbScene    = CGeneric.ConvertByteArrayToInt(CGeneric.GiveMeArray(rawData, headerSize - 4, 4));

            //send the data without SBF header for chuncking data..
            byte[] dataWithoutHeader = new byte[rawData.Length - headerSize];
            Array.Copy(rawData, headerSize, dataWithoutHeader, 0, dataWithoutHeader.Length);

            SetChunk(dataWithoutHeader, nbScene);
        }
        public CSBF1TextureManagement(int id, int index)
        {
            byte[] newTexture = new byte[28];
            Array.Copy(CGeneric.ConvertIntToByteArray(id), 0, newTexture, 16, 4);
            Array.Copy(CGeneric.ConvertIntToByteArray(-1), 0, newTexture, 20, 4);
            Array.Copy(CGeneric.ConvertIntToByteArray(index), 0, newTexture, 24, 4);

            rawData = newTexture;
            decomposeHeader();
        }
Esempio n. 10
0
        public List <string> GetBifList()
        {
            var list = new List <String>();

            foreach (byte[] element in bifList)
            {
                list.Add(CGeneric.ConvertByteArrayToString(element));
            }
            return(list);
        }
Esempio n. 11
0
        public void Init()
        {
            //init header...

            // take 2 byte : for the fist byte keep only 4 last bit and for the second keep only the 4 first..
            byte b1 = rawData[17];
            byte b2 = rawData[18];

            b1  %= 16;
            b1 <<= 4;
            b2  /= 16;
            b1  += b2;
            headerBFF2.transparencyPixelIndex = b1;

            headerBFF2.displayLength = rawData[8];
            // check if the data is compressed and if data had indexed color
            headerBFF2.isCompressedTexture = (rawData[18] % 16 > 7) ? true : false;

            //copy basic informations..
            headerBFF2.textureType = rawData[19];
            headerBFF2.nameLength  = rawData[35];

            headerBFF2.isIndexedColor = (headerBFF2.textureType == 0x32 || headerBFF2.textureType == 0x33) ? true : false;
            headerBFF2.textureWidth   = new byte[2];
            headerBFF2.textureHeight  = new byte[2];
            headerBFF2.name           = new byte[headerBFF2.nameLength];

            headerBFF2.bytePerPixel = (byte)CTextureManager.GetBytePerPixel((CGeneric.Compression)headerBFF2.textureType);

            Array.Copy(rawData, 22, headerBFF2.textureWidth, 0, 2);
            Array.Copy(rawData, 26, headerBFF2.textureHeight, 0, 2);
            Array.Copy(rawData, 36, headerBFF2.name, 0, headerBFF2.nameLength);

            //remove last not necessary character
            if (headerBFF2.name[headerBFF2.nameLength - 1] == 0)
            {
                headerBFF2.name = new byte[headerBFF2.nameLength - 1];
                Array.Copy(rawData, 36, headerBFF2.name, 0, headerBFF2.nameLength - 1);
            }

            headerBFF2.sizeX = CGeneric.ConvertByteArrayToInt(headerBFF2.textureWidth);
            headerBFF2.sizeY = CGeneric.ConvertByteArrayToInt(headerBFF2.textureHeight);

            //extract palette
            int startingData = 0x24 + headerBFF2.nameLength;

            if (headerBFF2.isIndexedColor)
            {
                ExtractPalette(startingData);
                startingData += headerBFF2.palette.Length + headerBFF2.paletteSize.Length;
            }

            headerBFF2.dataCompressed = new Byte[rawData.Length - startingData];
            Array.Copy(rawData, startingData, headerBFF2.dataCompressed, 0, headerBFF2.dataCompressed.Length);
        }
Esempio n. 12
0
        private void ExtractPalette(int indexPalette)
        {
            //get palette size
            headerBFF2.paletteSize = new Byte[4];
            Array.Copy(rawData, indexPalette, headerBFF2.paletteSize, 0, headerBFF2.paletteSize.Length);

            //fill palette data
            int paletteSize1 = CGeneric.ConvertByteArrayToInt(headerBFF2.paletteSize);

            headerBFF2.palette = new Byte[paletteSize1 * headerBFF2.bytePerPixel];
            Array.Copy(rawData, indexPalette + headerBFF2.paletteSize.Length, headerBFF2.palette, 0, headerBFF2.palette.Length);
        }
Esempio n. 13
0
        public void Add3FIB(string name)
        {
            //set name and header initial data
            byte[] byteName = CGeneric.ConvertStringToByteArray(name);
            byte[] rawData  = new byte[] { 0x33, 0x46, 0x49, 0x42, 8, 1, 0, 0, 0xFF, 0xFF, 0xFF, 0xFF, 0, 0, 0, 0, (byte)byteName.Length, 0, 0, 0 };
            rawData = rawData.Concat(byteName).ToArray();

            //add .fib to the end, and init the 3fib.
            C3FIB new3Fib = new C3FIB(rawData, byteName.Concat(new Byte[] { 0x2E, 0x42, 0x49, 0x46 }).ToArray());

            new3Fib.Init();
            fibList.Add(new3Fib);
        }
Esempio n. 14
0
        public byte[] GetRawData()
        {
            int flags = CGeneric.ConvertByteArrayToInt(CGeneric.GiveMeArray(rawData, 0, 4));

            //set unknown bit values
            //CGeneric.SetBitInInt(ref flags, 1, true);

            //Array.Copy(CGeneric.ConvertIntToByteArray(flags), 0, rawData, 0, 4);



            return(rawData);
        }
        public byte[] GetRawData()
        {
            int newHeaderDataSize = 28;

            if (this.transparencybit)
            {
                newHeaderDataSize += 4;
            }
            if (this.extra2)
            {
                newHeaderDataSize += 8;
            }

            byte[] newHeaderData = new byte[newHeaderDataSize];

            int flags = 0;

            //set extra bit value
            CGeneric.SetBitInInt(ref flags, 22, this.transparencybit);
            CGeneric.SetBitInInt(ref flags, 26, this.extra2);

            //set unknown bit values
            CGeneric.SetBitInInt(ref flags, 19, this.bit19);
            CGeneric.SetBitInInt(ref flags, 20, this.bit20);
            CGeneric.SetBitInInt(ref flags, 21, this.bit21);
            CGeneric.SetBitInInt(ref flags, 23, this.bit23);
            CGeneric.SetBitInInt(ref flags, 24, this.bit24);
            CGeneric.SetBitInInt(ref flags, 25, this.bit25);
            CGeneric.SetBitInInt(ref flags, 27, this.bit27);
            CGeneric.SetBitInInt(ref flags, 28, this.bit28);
            CGeneric.SetBitInInt(ref flags, 29, this.bit29);
            CGeneric.SetBitInInt(ref flags, 30, this.bit30);
            CGeneric.SetBitInInt(ref flags, 31, this.bit31);
            CGeneric.SetBitInInt(ref flags, 32, this.bit32);

            Array.Copy(CGeneric.ConvertIntToByteArray(flags), 0, newHeaderData, 0, 4);
            Array.Copy(CGeneric.ConvertIntToByteArray(posX), 0, newHeaderData, 4, 4);
            Array.Copy(CGeneric.ConvertIntToByteArray(posY), 0, newHeaderData, 8, 4);

            //copy unknown data
            Array.Copy(rawData, 12, newHeaderData, 12, 16);

            newHeaderData[27] = this.textureIndex;
            if (transparencybit)
            {
                newHeaderData[31] = transparency;
            }
            return(newHeaderData);
        }
Esempio n. 16
0
        public byte[] GetRawData()
        {
            //init
            byte[] res = new byte[0];

            //add the 4 unknown bytes...
            res = res.Concat(CGeneric.GiveMeArray(rawData, 0, 4)).ToArray();

            //title scene length
            res = res.Concat(CGeneric.ConvertIntToByteArray(this.sceneName.Length)).ToArray();

            //scene name
            res = res.Concat(sceneName).ToArray();

            //size dynamicObject
            res = res.Concat(CGeneric.ConvertIntToByteArray(dynamicObjectList.Count)).ToArray();

            //dynamic objectData
            foreach (CSBF1DynamicObject dynObj in dynamicObjectList)
            {
                res = res.Concat(dynObj.GetRawData()).ToArray();
            }

            //size TextObject
            res = res.Concat(CGeneric.ConvertIntToByteArray(textObjectList.Count)).ToArray();

            //TextObject
            foreach (CSBF1TextObject TexObj in textObjectList)
            {
                res = res.Concat(TexObj.GetRawData()).ToArray();
            }

            //Size textureManagement
            res = res.Concat(CGeneric.ConvertIntToByteArray(textureManagementObjectList.Count)).ToArray();

            //TextureManagement
            foreach (CSBF1TextureManagement texManObj in textureManagementObjectList)
            {
                res = res.Concat(texManObj.GetRawData()).ToArray();
            }

            //dont renember why.. but needed
            byte[] test = new byte[] { 0x00, 0x00, 0x00, 0x00 };
            res = res.Concat(test).ToArray();

            return(res);
        }
Esempio n. 17
0
        private void MakeBFF2Chunks(Byte[] bffsData, int bffCount)
        {
            //store position and size of all BFF2
            List <int> indexBFF2 = new List <int>();
            List <int> sizeBFF2  = new List <int>();

            int tmpPositionBFF2;

            //search all bff2 present in the 3FIB and grab index

            do
            {
                tmpPositionBFF2 = CGeneric.SearchBytesInArray(bffsData, CGeneric.patternBFF2, indexBFF2.Count()) - 12;

                if (tmpPositionBFF2 != -13)
                {
                    //add index
                    indexBFF2.Add(tmpPositionBFF2);
                    //calculate size of previous BFF2 (if not the last)
                    if (tmpPositionBFF2 != 0)
                    {
                        sizeBFF2.Add(indexBFF2[indexBFF2.Count() - 1] - indexBFF2[indexBFF2.Count() - 2]);
                    }
                }
                else
                {
                    //calculate size of last BFF2
                    try
                    {
                        sizeBFF2.Add(bffsData.Length - indexBFF2[indexBFF2.Count() - 1]);
                    } catch { } //can occur only when modified rom doesn't have any BFF2
                }
            } while (tmpPositionBFF2 != -13);

            //add bff2 list in the bff2Childs
            for (int i = 0; i < indexBFF2.Count(); i++)
            {
                Byte[] tmpByteBFF2 = new byte[sizeBFF2[i]];
                Array.Copy(bffsData, indexBFF2[i], tmpByteBFF2, 0, sizeBFF2[i]);
                bff2Childs.Add(new CBFF2(tmpByteBFF2));
                bff2Childs[bff2Childs.Count - 1].Init();
            }
        }
Esempio n. 18
0
        private void ChunkDataToRessources(Byte[] ressourceData)
        {
            int generalIndex = 0;

            // check all the ressources list...
            for (int i = 0; i < ressourcesList.Count(); i++)
            {
                //grab only one item by one
                int    sizeElement      = CGeneric.ConvertByteArrayToInt(ressourcesList[i].ressourceSize);
                Byte[] tmpContainerData = new byte[sizeElement];
                Array.Copy(ressourceData, generalIndex, tmpContainerData, 0, tmpContainerData.Length);

                //determine the type of data and fill in the apropriated list
                Byte[] dataPattern = new byte[4];
                Array.Copy(tmpContainerData, 0, dataPattern, 0, dataPattern.Length);

                switch (CGeneric.ConvertByteArrayToInt(dataPattern))
                {
                case (int)CGeneric.RessourceType.FIB:
                    fibList.Add(new C3FIB(tmpContainerData, ressourcesList[i].ressourceName));
                    fibList[fibList.Count - 1].Init();
                    break;

                case (int)CGeneric.RessourceType.HVQM:
                    hvqmList.Add(new CHVQM(tmpContainerData, ressourcesList[i].ressourceName));
                    break;

                case (int)CGeneric.RessourceType.SBF:
                    sbfList.Add(new CSBF1(tmpContainerData, ressourcesList[i].ressourceName));
                    break;

                default:
                    rdfList.Add(new CRDF(tmpContainerData, ressourcesList[i].ressourceName));
                    break;
                }
                generalIndex += sizeElement;
                if (sizeElement % 2 == 1)
                {
                    generalIndex += 1;
                }
            }
        }
Esempio n. 19
0
        public int Get3FIBIndexWithFIBName(string name)
        {
            int increm = 0;
            var b      = name.ToUpper().Replace("\0", "");

            for (int z = 0; z < ressourcesList.Count(); z++)
            {
                var a = CGeneric.ConvertByteArrayToString(ressourcesList[z].ressourceName).ToUpper().Replace("\0", "");
                if (a == b)
                {
                    return(increm);
                }

                if (a.EndsWith(".BIF"))
                {
                    increm++;
                }
            }
            return(-1);
        }
Esempio n. 20
0
        public void WriteAllData(FileStream fs)
        {
            fs.Position = indexRessourcesStart;

            // write the number of elements
            fs.Write(CGeneric.ConvertIntToByteArray(fibList.Count() + GetHVQMCount() + GetSBFCount() + GetRTFCount()), 0, 4);

            // index of data (for writing header)
            int indexData = (fibList.Count() + GetHVQMCount() + GetSBFCount() + GetRTFCount()) * 24 + 4;

            //write list header (FIB,HVQM,SBF1,RDF1)
            WriteListHeader(ref fs, ref indexData, fibList);
            WriteListHeader(ref fs, ref indexData, hvqmList);
            WriteListHeader(ref fs, ref indexData, sbfList);
            WriteListHeader(ref fs, ref indexData, rdfList);

            //write data associated
            WriteRessourceData(ref fs, fibList);
            WriteRessourceData(ref fs, hvqmList);
            WriteRessourceData(ref fs, sbfList);
            WriteRessourceData(ref fs, rdfList);
        }
Esempio n. 21
0
        private int ChunkTextureManagementObject(byte[] data, int nbTextureManagementObject, int indexDataStart)
        {
            byte[] lengthData = new byte[4];
            int    lengthDataInt;

            int totalSize = 0;

            for (int i = 0; i < nbTextureManagementObject; i++)
            {
                // get the length of the texture management object
                Array.Copy(data, indexDataStart, lengthData, 0, lengthData.Length);
                lengthDataInt = CSBF1TextureManagement.GetHeaderLength(CGeneric.ConvertByteArrayToInt(lengthData));

                //create the new texture management item
                byte[] dataTextureManagementObject = new byte[lengthDataInt];
                Array.Copy(data, indexDataStart, dataTextureManagementObject, 0, dataTextureManagementObject.Length);
                textureManagementObjectList.Add(new CSBF1TextureManagement(dataTextureManagementObject));

                indexDataStart += lengthDataInt;
                totalSize      += lengthDataInt;
            }
            return(totalSize);
        }
Esempio n. 22
0
        public override byte[] GetRawData()
        {
            //return rawData;
            byte[] res = new byte[12 + (bifList.Count * 0x10)];
            Array.Copy(CGeneric.patternSBF1, 0, res, 0, CGeneric.patternSBF1.Length);
            Array.Copy(CGeneric.ConvertIntToByteArray(bifList.Count), 0, res, 4, 4);

            for (int i = 0; i < bifList.Count; i++)
            {
                Array.Copy(bifList[i], 0, res, 8 + i * bifList[0].Length, bifList[0].Length);
            }

            Array.Copy(CGeneric.ConvertIntToByteArray(scenesList.Count), 0, res, res.Length - 4, 4);

            //add each csbf1 scene
            foreach (CSBF1Scene scene in scenesList)
            {
                res = res.Concat(scene.GetRawData()).ToArray();
            }

            this.rawData = res;
            return(res);
        }
Esempio n. 23
0
        public CSBF1Scene(byte[] rawData)
        {
            this.rawData = rawData;
            //read sceneNameLength
            byte[] sceneNameLength = new byte[4];
            Array.Copy(rawData, 4, sceneNameLength, 0, sceneNameLength.Length);
            int sceneLength = CGeneric.ConvertByteArrayToInt(sceneNameLength);

            //extract sceneName
            this.sceneName = new byte[sceneLength];
            Array.Copy(rawData, 8, sceneName, 0, sceneLength);

            //decompose scene in 3 parts.
            byte[] dataWithoutHeader = new Byte[rawData.Length - 8 - sceneLength];
            Array.Copy(rawData, 8 + sceneLength, dataWithoutHeader, 0, dataWithoutHeader.Length);

            this.sceneNameDebug = CGeneric.ConvertByteArrayToString(sceneName);
            //decompose data of scene
            ChunkScene(dataWithoutHeader, 8 + sceneLength);

            //for text, decompose groups of text
            GroupTextData();
        }
        private void decomposeHeader()
        {
            //data grabbed from 4 first bytes (converted to bits)
            int dataInitial = CGeneric.ConvertByteArrayToInt(CGeneric.GiveMeArray(rawData, 0, 4));

            //set flags
            transparencybit = CGeneric.GetBitStateFromInt(dataInitial, 22);
            extra2          = CGeneric.GetBitStateFromInt(dataInitial, 26);

            //set unknown flags
            bit19 = CGeneric.GetBitStateFromInt(dataInitial, 19);
            bit20 = CGeneric.GetBitStateFromInt(dataInitial, 20);
            bit21 = CGeneric.GetBitStateFromInt(dataInitial, 21);
            bit23 = CGeneric.GetBitStateFromInt(dataInitial, 23);
            bit24 = CGeneric.GetBitStateFromInt(dataInitial, 24);
            bit25 = CGeneric.GetBitStateFromInt(dataInitial, 25);
            bit27 = CGeneric.GetBitStateFromInt(dataInitial, 27);
            bit28 = CGeneric.GetBitStateFromInt(dataInitial, 28);
            bit29 = CGeneric.GetBitStateFromInt(dataInitial, 29);
            bit30 = CGeneric.GetBitStateFromInt(dataInitial, 30);
            bit31 = CGeneric.GetBitStateFromInt(dataInitial, 31);
            bit32 = CGeneric.GetBitStateFromInt(dataInitial, 32);

            if (transparencybit)
            {
                this.transparency = rawData[31];
            }

            if (rawData[3] != 8)
            {
                this.isCompressedTexture = true;
            }
            this.textureIndex = rawData[27];
            this.posX         = CGeneric.ConvertByteArrayToInt(CGeneric.GiveMeArray(rawData, 4, 4));
            this.posY         = CGeneric.ConvertByteArrayToInt(CGeneric.GiveMeArray(rawData, 8, 4));
        }
Esempio n. 25
0
        private void ChunkScene(byte[] data, int headerSize)
        {
            //separate 3 types of data -> dynamicObject, text and textureManagment
            int generalIndex = 0;

            //get the number of dynamic object
            byte[] nbDynamicArray = new byte[4];
            Array.Copy(data, generalIndex, nbDynamicArray, 0, nbDynamicArray.Length);
            //increment the global index with 4 (the size of nbDynamicArray.Length)
            generalIndex += nbDynamicArray.Length;

            //fill dynamic objects
            this.dynamicObjectList = new List <CSBF1DynamicObject>();
            generalIndex          += ChunkDynamicObject(data, CGeneric.ConvertByteArrayToInt(nbDynamicArray), generalIndex);

            //get the number of text object
            byte[] nbTextArray = new byte[4];
            Array.Copy(data, generalIndex, nbTextArray, 0, nbTextArray.Length);
            //increment the global index with 4 (the size of nbDynamicArray.Length)
            generalIndex += nbTextArray.Length;

            //fill text objects
            this.textObjectList = new List <CSBF1TextObject>();
            generalIndex       += ChunkTextObject(data, CGeneric.ConvertByteArrayToInt(nbTextArray), generalIndex);

            //get the number of texture management object
            byte[] nbTextureArray = new byte[4];
            Array.Copy(data, generalIndex, nbTextureArray, 0, nbTextureArray.Length);
            //increment the global index with 4 (the size of nbDynamicArray.Length)
            generalIndex += nbTextureArray.Length;

            //fill texture management object
            this.textureManagementObjectList = new List <CSBF1TextureManagement>();
            generalIndex += ChunkTextureManagementObject(data, CGeneric.ConvertByteArrayToInt(nbTextureArray), generalIndex);

            //add 4 because 0x00000000 at the end of each scene..
            //add specific value for ISO file (the 4th hidden thing in sbf...
            var hidden4thData = CGeneric.ConvertByteArrayToInt(CGeneric.GiveMeArray(data, generalIndex, 4));

            generalIndex += 4;
            if (hidden4thData != 0)
            {
                for (int i = 0; i < hidden4thData; i++)
                {
                    var code4thData = CGeneric.ConvertByteArrayToInt(CGeneric.GiveMeArray(data, generalIndex, 4));
                    switch (code4thData)
                    {
                    case 0x1E:
                    case 0x9E:
                        generalIndex += 0x20;
                        break;

                    case 0x1F:
                        generalIndex += 0x24;
                        break;

                    default:
                        throw new NotImplementedException();
                    }
                }
            }
            var a = sceneNameDebug;

            //with the datasize determinated set the new rawData array
            byte[] newArrayRawData = new byte[generalIndex + headerSize];
            Array.Copy(this.rawData, 0, newArrayRawData, 0, newArrayRawData.Length);
            this.rawData = newArrayRawData;
        }
Esempio n. 26
0
        //public void AddTexture(int indexScene, string bifName)
        //{
        //    //if the texture is already in the sbf, just add the texture to the scene
        //    for(int i = 0; i < bifList.Count; i++)
        //    {
        //        if(bifName == CGeneric.ConvertByteArrayToString(bifList[i]).ToUpper())
        //        {
        //            scenesList[indexScene].AddNewTextureObject(i);
        //            return;
        //        }
        //    }
        //    //else add before the texture and after add it to the scene
        //    //store the name in lower just because it will be more pretty in the rom :)
        //    bifList.Add(CGeneric.ConvertStringToByteArray(bifName.ToLower()));
        //    scenesList[indexScene].AddNewTextureObject(bifList.Count - 1);
        //}

        public string GetBifName(int index)
        {
            return(CGeneric.ConvertByteArrayToString(bifList[index]));
        }
Esempio n. 27
0
 public void ReplaceTexture(int indexBif, string bifName)
 {
     bifList[indexBif] = CGeneric.ConvertStringToByteArray(bifName.ToLower());
 }
Esempio n. 28
0
        public void SetSBF1(byte[] scene, int index)
        {
            var name = CGeneric.ConvertStringToByteArray(sbfList[index].GetRessourceName());

            sbfList[index] = new CSBF1(scene, name);
        }
Esempio n. 29
0
 private void AddTexture(int location, int sizeX, int sizeY, int bpp, string text, int paletteLocation = 0, int paletteSize = 0)
 {
     graphicsRom.Add(new UncompressedRomTextureData(CGeneric.GiveMeArray(rawData, location, sizeX * sizeY * (bpp / 8)), location, sizeX, sizeY, bpp, text, CGeneric.GiveMeArray(rawData, paletteLocation, paletteSize), paletteLocation));
 }
        public static int GetHeaderLength(int headerValue)
        {
            var result = 28;

            if (CGeneric.GetBitStateFromInt(headerValue, 22))
            {
                result += 4;
            }
            if (CGeneric.GetBitStateFromInt(headerValue, 26))
            {
                result += 8;
            }

            return(result);

            //unknown data for now
            //switch (headerValue)
            //{
            //    case 0x00000000: return 0x1C;
            //    case 0x00000002: return 0x1C; //tested
            //    case 0x00000004: return 0x1C; //tested
            //    case 0x00000006: return 0x1C;
            //    case 0x00000008: return 0x1C; //tested
            //    case 0x0000000C: return 0x1C;
            //    case 0x00000040: return 0x24; //tested
            //    case 0x00000044: return 0x24; //tested
            //    case 0x00000080: return 0x1C; //tested
            //    case 0x00000082: return 0x1C;
            //    case 0x00000084: return 0x1C; //tested
            //    case 0x00000200: return 0x1C;
            //    case 0x00000400: return 0x20; //tested
            //    case 0x00000402: return 0x20;
            //    case 0x00000404: return 0x20;
            //    case 0x00000406: return 0x20; //tested
            //    case 0x00000482: return 0x20;
            //    case 0x00002000: return 0x1C;
            //    case 0x00002006: return 0x1C; //tested
            //    case 0x00002040: return 0x24;
            //    case 0x00002406: return 0x20; //tested

            //    //test cas ISO only
            //    case 0x00000664: return 0x28;//old vavlue 1C
            //    case 0x00000764: return 0x28;
            //    case 0x00000C02: return 0x20;
            //    //case 0x000000D2: return 0x1C; //not exists
            //    //case 0x000000D3: return 0x1C; //not exists
            //    case 0x00000091: return 0x1C;
            //    case 0x0000008C: return 0x1C;
            //    case 0x00000010: return 0x1C;
            //    case 0x00000210: return 0x1C;
            //    case 0x00000204: return 0x1C;
            //    case 0x00000104: return 0x1C;

            //    case 0x00001000: return 0x1C;
            //    case 0x00000001: return 0x1C;//tested
            //    case 0x00000502: return 0x20;
            //    case 0x00000202: return 0x1C;
            //    //case 0x00000020: return 0x18;//not exist
            //    default: throw new NotImplementedException();
            //}
        }