Beispiel #1
0
        public Format Read2(sFile file)
        {
            string ext = "";
            if (file.size >= 4)
            {
                using (BinaryReader br = new BinaryReader(File.OpenRead(file.path)))
                {
                    ext = new String(Encoding.ASCII.GetChars(br.ReadBytes(4)));
                    br.Close();
                }
            }

            // Palette
            if (file.name.ToUpper().EndsWith(".NTFP") || file.name.ToUpper().EndsWith(".PLT"))
            {
                RawPalette palette = new RawPalette(file.path, file.id, true, 0, -1, file.name);
                pluginHost.Set_Palette(palette);
                return Format.Palette;
            }
            else if (ext == "RLCN")
            {
                PaletteBase palette = new NCLR(file.path, file.id, file.name);
                pluginHost.Set_Palette(palette);
                return Format.Palette;
            }
            else if (ext == "NCCL")
            {
                NCCL palette = new NCCL(file.path, file.id, file.name);
                pluginHost.Set_Palette(palette);
                return Format.Palette;
            }
            else if (file.name.ToUpper().EndsWith(".NBFP"))
            {
                RawPalette palette = new RawPalette(file.path, file.id, true, 0, -1, file.name);
                pluginHost.Set_Palette(palette);
                return Format.Palette;
            }
            else if (file.name.ToUpper().EndsWith(".NCL.L") && ext[0] != '\x10')
            {
                RawPalette palette = new RawPalette(file.path, file.id, true, 0, -1, file.name);
                pluginHost.Set_Palette(palette);
                return Format.Palette;
            }

            // Tile
            ColorFormat depth = ColorFormat.colors256;
            if (pluginHost.Get_Palette().Loaded)
                depth = pluginHost.Get_Palette().Depth;

            if (file.name.ToUpper().EndsWith(".NTFT"))
            {

                RawImage image = new RawImage(file.path, file.id, TileForm.Lineal, depth, true, 0, -1, file.name);
                pluginHost.Set_Image(image);
                return Format.Tile;
            }
            else if (ext == "RGCN" || ext == "RBCN")
            {
                NCGR ncgr = new NCGR(file.path, file.id, file.name);
                pluginHost.Set_Image(ncgr);
                return Format.Tile;
            }
            else if (ext == "NCCG")
            {
                NCCG image = new NCCG(file.path, file.id, file.name);
                pluginHost.Set_Image(image);
                return Format.Tile;
            }
            else if (file.name.ToUpper().EndsWith(".NBFC") || file.name.ToUpper().EndsWith(".CHAR"))
            {
                RawImage image = new RawImage(file.path, file.id, TileForm.Horizontal, depth, true, 0, -1, file.name);
                pluginHost.Set_Image(image);
                return Format.Tile;
            }
            else if (file.name.ToUpper().EndsWith(".NCG.L") && ext[0] != '\x10')
            {
                RawImage image = new RawImage(file.path, file.id, TileForm.Horizontal, depth, true, 0, -1, file.name);
                pluginHost.Set_Image(image);
                return Format.Tile;
            }

            // Map
            if (file.name.ToUpper().EndsWith(".NBFS"))
            {
                RawMap map = new RawMap(file.path, file.id, 0, -1, true, file.name);
                pluginHost.Set_Map(map);
                return Format.Map;
            }
            else if (ext == "RCSN")
            {
                NSCR nscr = new NSCR(file.path, file.id, file.name);
                pluginHost.Set_Map(nscr);
                return Format.Map;
            }
            else if (ext == "NCSC")
            {
                NCSC map = new NCSC(file.path, file.id, file.name);
                pluginHost.Set_Map(map);
                return Format.Map;
            }
            else if (file.name.ToUpper().EndsWith(".NSC.L") && ext[0] != '\x10')
            {
                RawMap map = new RawMap(file.path, file.id, 0, -1, true, file.name);
                pluginHost.Set_Map(map);
                return Format.Map;
            }

            // Sprite
            if (ext == "NCOB")
            {
                NCOB sprite = new NCOB(file.path, file.id, file.name);
                pluginHost.Set_Sprite(sprite);
                pluginHost.Set_Image(sprite.Image);
                return Format.Cell;
            }
            else if (ext == "RECN")
            {
                NCER ncer = new NCER(file.path, file.id, file.name);
                pluginHost.Set_Sprite(ncer);
                return Format.Cell;
            }

            // Animation
            if (ext == "RNAN")
            {
                nanr = new NANR(pluginHost, file.path, file.id);
                return Format.Animation;
            }

            return Format.Unknown;
        }
Beispiel #2
0
        public void Read(string file)
        {
            BinaryReader br = new BinaryReader(File.OpenRead(file));

            // Header
            uint paletaOffset = br.ReadUInt32() * 4;
            uint tileOffset = br.ReadUInt32() * 4;
            uint mapOffset = br.ReadUInt32() * 4;
            ColorFormat depth;
            br.BaseStream.Position = mapOffset;
            if (br.ReadUInt32() == 0x01)
                depth = ColorFormat.colors256;
            else
                depth = ColorFormat.colors16;

            // Palette
            Color[][] colors;
            if (paletaOffset == 0x00) // No palette
            {
                depth = ColorFormat.colors16;
                colors = new Color[defaultPaletteData.Length / 0x20][];

                for (int i = 0; i < colors.Length; i++)
                {
                    Byte[] data = new Byte[0x20];
                    Array.Copy(defaultPaletteData, i * 0x20, data, 0, 0x20);
                    colors[i] = Actions.BGR555ToColor(data);
                }
                goto Tile;
            }

            br.BaseStream.Position = paletaOffset;
            uint pCabeceraSize = br.ReadUInt32() * 4;
            uint pSize = br.ReadUInt32() * 4;
            if (pSize - 0x08 == 0x0200)
                depth = ColorFormat.colors256;
            else if (pSize - 0x08 == 0x20)
                depth = ColorFormat.colors16;

            colors = new Color[depth == ColorFormat.colors16 ? (pSize - 0x08) / 0x20 : 1][];
            uint pal_length = (depth == ColorFormat.colors16) ? 0x20 : pSize - 0x08;
            for (int i = 0; i < colors.Length; i++)
                colors[i] = Actions.BGR555ToColor(br.ReadBytes((int)pal_length));

            // Tile data
            Tile:
            br.BaseStream.Position = tileOffset;
            uint tCabeceraSize = br.ReadUInt32() * 4;
            uint tSize = br.ReadUInt32() * 4;
            byte[] tiles = br.ReadBytes((int)(tSize - 0x08));
            image = new RawImage(tiles, TileForm.Horizontal, depth, 0x40, tiles.Length / 0x40, false, fileName);

            // Map
            if (mapOffset == 0x00)
            {
                hasMap = false;
                goto End;
            }

            hasMap = true;
            br.BaseStream.Position = mapOffset;
            uint mCabeceraSize = br.ReadUInt32() * 4;
            uint[] mSize = new uint[(int)mCabeceraSize / 4];
            for (int i = 0; i < mSize.Length; i++)
                mSize[i] = (br.ReadUInt32() * 4) - mCabeceraSize - 4;

            maps = new MapBase[mSize.Length];
            for (int i = 0; i < maps.Length; i++)
            {
                ushort width = (ushort)(br.ReadUInt16() * 8);
                ushort height = (ushort)(br.ReadUInt16() * 8);

                NTFS[] map;
                if (i != 0)
                    map = new NTFS[((mSize[i] - mSize[i - 1]) - 4) / 2];
                else
                    map = new NTFS[(mSize[i] - 4) / 2];

                for (int j = 0; j < map.Length; j++)
                    map[j] = Actions.MapInfo(br.ReadUInt16());

                maps[i] = new RawMap(map, width, height, false, fileName);
            }

            End:
            br.Close();

            palette = new RawPalette(colors, false, depth, fileName);
        }
Beispiel #3
0
        private System.Windows.Forms.Control ShowImage(sFile file)
        {
            #region Palette
            BinaryReader br = new BinaryReader(File.OpenRead(file.path));
            br.ReadUInt32(); // 4 Bytes Stupid
            uint num_colors = 256;
            byte[] pal = br.ReadBytes((int)num_colors * 2);
            Color[] colors = Actions.BGR555ToColor(pal);
            PaletteBase palette = new RawPalette(colors, false, ColorFormat.colors256, file.name);
            br.ReadUInt32(); // 4 Bytes Stupid
            #endregion

            #region Map
            NTFS[] map_info = new NTFS[1024];
            for (int i = 0; i < 1024; i++)
            {
                ushort value = br.ReadUInt16();
                map_info[i] = Actions.MapInfo(value);
            }
            MapBase map = new RawMap(map_info, 256, 192, false, file.name);
            #endregion

            #region Tiles
            uint size_section = (uint)(br.ReadUInt32() * 64);
            Console.WriteLine("Size section: " + size_section.ToString("x"));
            byte[] readsize = br.ReadBytes((int)size_section);
            ImageBase image = new RawImage(readsize, TileForm.Horizontal, ColorFormat.colors256, 256, 192, false, file.name);
            #endregion

            br.Close();

            pluginHost.Set_Palette(palette);
            pluginHost.Set_Image(image);
            pluginHost.Set_Map(map);

            return new ImageControl(pluginHost, image, palette, map);
        }