Beispiel #1
0
    public static byte[][] Change_ImageCell(Cell cell, uint blockSize, NCGR.NCGR_s newTiles, NCGR.NCGR_s oldImage)
    {
        uint          num3;
        int           num4;
        List <byte[]> list       = new List <byte[]>();
        List <byte[]> collection = new List <byte[]>();
        List <byte>   list3      = new List <byte>();

        for (int i = 0; i < 0x200; i++)
        {
            for (int j = 0; j < 0x200; j++)
            {
                if (((i >= (0x100 + cell.obj0.yOffset)) && (i < ((0x100 + cell.obj0.yOffset) + cell.height))) && ((j >= (0x100 + cell.obj1.xOffset)) && (j < ((0x100 + cell.obj1.xOffset) + cell.width))))
                {
                    list3.Add(newTiles.rahc.tileData.tiles[0][j + (i * 0x200)]);
                }
            }
        }
        if (oldImage.order == NCGR.TileOrder.Horizontal)
        {
            collection.AddRange(Convertir.BytesToTiles_NoChanged(list3.ToArray(), cell.width / 8, cell.height / 8));
        }
        else
        {
            collection.Add(list3.ToArray());
        }
        list3.Clear();
        if (oldImage.order == NCGR.TileOrder.Horizontal)
        {
            num3  = (oldImage.rahc.depth == ColorDepth.Depth4Bit) ? (cell.obj2.tileOffset * 2) : cell.obj2.tileOffset;
            num3 *= (blockSize != 0) ? blockSize : 1;
            for (num4 = 0; num4 < num3; num4++)
            {
                list.Add(oldImage.rahc.tileData.tiles[num4]);
            }
            list.AddRange(collection);
            for (num4 = ((int)num3) + ((cell.width * cell.height) / 0x40); num4 < oldImage.rahc.tileData.tiles.Length; num4++)
            {
                list.Add(oldImage.rahc.tileData.tiles[num4]);
            }
        }
        else if (oldImage.order == NCGR.TileOrder.NoTiled)
        {
            num3  = ((oldImage.rahc.depth == ColorDepth.Depth4Bit) ? (cell.obj2.tileOffset * 2) : cell.obj2.tileOffset) * 0x40;
            num3 *= (blockSize != 0) ? blockSize : 1;
            for (num4 = 0; num4 < num3; num4++)
            {
                list3.Add(oldImage.rahc.tileData.tiles[0][num4]);
            }
            list3.AddRange(collection[0]);
            for (num4 = ((int)num3) + (cell.width * cell.height); num4 < oldImage.rahc.tileData.tiles[0].Length; num4++)
            {
                list3.Add(oldImage.rahc.tileData.tiles[0][num4]);
            }
            list.Add(list3.ToArray());
        }
        return(list.ToArray());
    }
Beispiel #2
0
    public static NCGR_s BitmapToTile(string bitmap, TileOrder tileOrder)
    {
        int          num7;
        int          num8;
        int          num9;
        int          num10;
        NCGR_s       _s     = new NCGR_s();
        BinaryReader reader = new BinaryReader(File.OpenRead(bitmap));

        if (new string(reader.ReadChars(2)) != "BM")
        {
            _s.header.id = "RGCN".ToCharArray();
        }
        _s.header.endianess        = 0xfeff;
        _s.header.constant         = 1;
        _s.header.header_size      = 0x10;
        _s.header.nSection         = 1;
        reader.BaseStream.Position = 10L;
        uint   num        = reader.ReadUInt32();
        Stream baseStream = reader.BaseStream;

        baseStream.Position += 4L;
        uint num2 = reader.ReadUInt32();
        uint num3 = reader.ReadUInt32();

        _s.rahc.nTilesX = (ushort)num2;
        _s.rahc.nTilesY = (ushort)num3;
        if (tileOrder == TileOrder.Horizontal)
        {
            _s.rahc.nTilesX = (ushort)(_s.rahc.nTilesX / 8);
            _s.rahc.nTilesY = (ushort)(_s.rahc.nTilesY / 8);
        }
        _s.rahc.nTiles = (ushort)(_s.rahc.nTilesX * _s.rahc.nTilesY);
        Stream stream2 = reader.BaseStream;

        stream2.Position += 2L;
        switch (reader.ReadUInt16())
        {
        case 4:
            _s.rahc.depth = ColorDepth.Depth4Bit;
            break;

        case 8:
            _s.rahc.depth = ColorDepth.Depth8Bit;
            break;
        }
        uint num5 = reader.ReadUInt32();
        uint num6 = reader.ReadUInt32();

        _s.rahc.tileData.tiles = new byte[1][];
        ColorDepth depth = _s.rahc.depth;

        if (depth == ColorDepth.Depth4Bit)
        {
            _s.rahc.tileData.tiles[0] = new byte[(num2 * num3) * 2];
            _s.rahc.tileData.nPalette = new byte[(num2 * num3) * 2];
            num7 = (int)(num2 / 2);
            if ((num2 % 4) != 0)
            {
                Math.DivRem((int)(num2 / 2), 4, out num8);
                num7 = ((int)(num2 / 2)) + (4 - num8);
            }
            reader.BaseStream.Position = num;
            for (num9 = ((int)num3) - 1; num9 >= 0; num9--)
            {
                num10 = 0;
                while (num10 < num2)
                {
                    string str = string.Format("{0:X}", reader.ReadByte());
                    if (str.Length == 1)
                    {
                        str = '0' + str;
                    }
                    char ch = str[0];
                    _s.rahc.tileData.tiles[0][(int)((IntPtr)(num10 + (num9 * num2)))] = Convert.ToByte(ch.ToString(), 0x10);
                    _s.rahc.tileData.nPalette[(int)((IntPtr)(num10 + (num9 * num2)))] = 0;
                    if ((num10 + 1) != num2)
                    {
                        _s.rahc.tileData.tiles[0][(int)((IntPtr)((num10 + 1) + (num9 * num2)))] = Convert.ToByte(str[1].ToString(), 0x10);
                        _s.rahc.tileData.nPalette[(int)((IntPtr)((num10 + 1) + (num9 * num2)))] = 0;
                    }
                    num10 += 2;
                }
                reader.ReadBytes(num7 - ((int)(((float)num2) / 2f)));
            }
        }
        else if (depth == ColorDepth.Depth8Bit)
        {
            _s.rahc.tileData.tiles[0] = new byte[num2 * num3];
            _s.rahc.tileData.nPalette = new byte[num2 * num3];
            num7 = (int)num2;
            if ((num2 % 4) != 0)
            {
                Math.DivRem((int)num2, 4, out num8);
                num7 = ((int)num2) + (4 - num8);
            }
            reader.BaseStream.Position = num;
            for (num9 = ((int)num3) - 1; num9 >= 0; num9--)
            {
                for (num10 = 0; num10 < num2; num10++)
                {
                    _s.rahc.tileData.tiles[0][(int)((IntPtr)(num10 + (num9 * num2)))] = reader.ReadByte();
                    _s.rahc.tileData.nPalette[(int)((IntPtr)(num10 + (num9 * num2)))] = 0;
                }
                reader.ReadBytes(num7 - ((int)num2));
            }
        }
        if (tileOrder == TileOrder.Horizontal)
        {
            _s.rahc.tileData.tiles = Convertir.BytesToTiles_NoChanged(_s.rahc.tileData.tiles[0], _s.rahc.nTilesX, _s.rahc.nTilesY);
        }
        _s.rahc.id            = "RAHC".ToCharArray();
        _s.rahc.size_tiledata = (uint)_s.rahc.tileData.nPalette.Length;
        _s.rahc.tiledFlag     = (uint)((tileOrder == TileOrder.NoTiled) ? 1 : 0);
        _s.rahc.unknown1      = 0;
        _s.rahc.unknown2      = 0;
        _s.rahc.unknown3      = 0x18;
        _s.rahc.size_section  = _s.rahc.size_tiledata + 0x20;
        _s.header.file_size   = _s.rahc.size_section + _s.header.header_size;
        _s.order = tileOrder;
        reader.Close();
        return(_s);
    }