Exemple #1
0
        public DlmMap ReadMap()
        {
            int header = (int)this.m_reader.ReadByte();

            if (header != 77)
            {
                try
                {
                    this.m_reader.Seek(0, SeekOrigin.Begin);
                    MemoryStream output = new MemoryStream();
                    ZipHelper.Deflate(new MemoryStream(this.m_reader.ReadBytes((int)this.m_reader.BytesAvailable)), output);
                    byte[] uncompress = output.ToArray();
                    this.ChangeStream(new MemoryStream(uncompress));
                    header = (int)this.m_reader.ReadByte();
                    if (header != 77)
                    {
                        throw new FileLoadException("Wrong header file");
                    }
                }
                catch (Exception)
                {
                    throw new FileLoadException("Wrong header file");
                }
            }
            return(DlmMap.ReadFromStream(this.m_reader, this));
        }
 public static DlmFixture ReadFromStream(DlmMap map, BigEndianReader reader)
 {
     return(new DlmFixture(map)
     {
         FixtureId = reader.ReadInt(),
         Offset = new System.Drawing.Point(reader.ReadShort(), reader.ReadShort()),
         Rotation = reader.ReadShort(),
         ScaleX = reader.ReadShort(),
         ScaleY = reader.ReadShort(),
         Hue = reader.ReadByte() << 16 | reader.ReadByte() << 8 | reader.ReadByte(),
             Alpha = (byte)reader.ReadSByte(),
     });
 }
Exemple #3
0
        public static DlmLayer ReadFromStream(DlmMap map, BigEndianReader reader)
        {
            DlmLayer layer = new DlmLayer(map);

            if (map.Version >= 9)
            {
                layer.LayerId = reader.ReadByte();
            }
            else
            {
                layer.LayerId = reader.ReadInt();
            }

            layer.Cells = new DlmCell[(int)reader.ReadShort()];
            for (int i = 0; i < layer.Cells.Length; i++)
            {
                layer.Cells[i] = DlmCell.ReadFromStream(layer, reader);
            }
            return(layer);
        }
        public static DlmCellData ReadFromStream(DlmMap map, short id, BigEndianReader reader)
        {
            DlmCellData cell = new DlmCellData(map, id);

            cell.Floor = (short)(reader.ReadByte() * 10);
            if (cell.Floor == -1280)
            {
                return(cell);
            }
            if (map.Version >= 9)
            {
                cell.LosMov = reader.ReadShort();
                cell.Mov    = (cell.LosMov & 1) == 0;
                cell.NonWalkableDuringFight = (cell.LosMov & 2) != 0;
                cell.NonWalkableDuringRP    = (cell.LosMov & 4) != 0;
                cell.Los      = (cell.LosMov & 8) == 0;
                cell.Blue     = (cell.LosMov & 16) != 0;
                cell.Red      = (cell.LosMov & 32) != 0;
                cell.Visible  = (cell.LosMov & 64) != 0;
                cell.FarmCell = (cell.LosMov & 128) != 0;

                bool topArrow;
                bool bottomArrow;
                bool rightArrow;
                bool leftArrow;
                if (map.Version >= 10)
                {
                    cell.HavenbagCell = (cell.LosMov & 256) != 0;
                    topArrow          = (cell.LosMov & 512) != 0;
                    bottomArrow       = (cell.LosMov & 1024) != 0;
                    rightArrow        = (cell.LosMov & 2048) != 0;
                    leftArrow         = (cell.LosMov & 4096) != 0;
                }
                else
                {
                    topArrow    = (cell.LosMov & 256) != 0;
                    bottomArrow = (cell.LosMov & 512) != 0;
                    rightArrow  = (cell.LosMov & 1024) != 0;
                    leftArrow   = (cell.LosMov & 2048) != 0;
                }
                if (topArrow)
                {
                    map.TopArrowCells.Add(cell.Id);
                }
                if (bottomArrow)
                {
                    map.BottomArrowCells.Add(cell.Id);
                }
                if (rightArrow)
                {
                    map.RightArrowCells.Add(cell.Id);
                }
                if (leftArrow)
                {
                    map.LeftArrowCells.Add(cell.Id);
                }
            }
            else
            {
                cell.LosMov                 = (byte)reader.ReadSByte();
                cell.Los                    = (cell.LosMov & 2) >> 1 == 1;
                cell.Mov                    = (cell.LosMov & 1) == 1;
                cell.Visible                = (cell.LosMov & 64) >> 6 == 1;
                cell.FarmCell               = (cell.LosMov & 32) >> 5 == 1;
                cell.Blue                   = (cell.LosMov & 16) >> 4 == 1;
                cell.Red                    = (cell.LosMov & 8) >> 3 == 1;
                cell.NonWalkableDuringRP    = (cell.LosMov & 128) >> 7 == 1;
                cell.NonWalkableDuringFight = (cell.LosMov & 4) >> 2 == 1;
            }

            cell.Speed = reader.ReadByte();

            cell.MapChangeData = reader.ReadByte();

            if (map.Version > 5)
            {
                cell.MoveZone = (byte)reader.ReadSByte();
            }

            if (map.Version > 7 && map.Version < 9)
            {
                var tmpBits = reader.ReadByte();
                cell.Arrow = 15 & tmpBits;
                //if(cell.use)
                //{
                //   map.topArrowCell.push(id);
                //}
                //if(useBottomArrow)
                //{
                //   map.bottomArrowCell.push(id);
                //}
                //if(useLeftArrow)
                //{
                //   map.leftArrowCell.push(id);
                //}
                //if(useRightArrow)
                //{
                //   map.rightArrowCell.push(id);
                //}
            }
            return(cell);
        }
 public DlmCellData(DlmMap map, short id)
 {
     this.Map    = map;
     this.Id     = id;
     this.LosMov = 3;
 }
Exemple #6
0
        public static DlmMap ReadFromStream(BigEndianReader givenReader, DlmReader dlmReader)
        {
            BigEndianReader reader = givenReader;
            DlmMap          map    = new DlmMap();

            map.Version = reader.ReadByte();
            map.Id      = reader.ReadInt();
            if (map.Version >= 7)
            {
                map.Encrypted         = reader.ReadBoolean();
                map.EncryptionVersion = reader.ReadByte();
                int len = reader.ReadInt();
                if (map.Encrypted)
                {
                    string key = dlmReader.DecryptionKey;
                    if (key == null && dlmReader.DecryptionKeyProvider != null)
                    {
                        key = dlmReader.DecryptionKeyProvider(map.Id);
                    }
                    if (key == null)
                    {
                        throw new InvalidOperationException(string.Format("Cannot decrypt the map {0} without decryption key", map.Id));
                    }
                    byte[] data       = reader.ReadBytes(len);
                    byte[] encodedKey = Encoding.Default.GetBytes(key);
                    if (key.Length > 0)
                    {
                        for (int i = 0; i < data.Length; i++)
                        {
                            data[i] ^= encodedKey[i % key.Length];
                        }
                        reader = new BigEndianReader(new MemoryStream(data));
                    }
                }
            }
            map.RelativeId            = reader.ReadUInt();
            map.MapType               = reader.ReadByte();
            map.SubAreaId             = reader.ReadInt();
            map.TopNeighbourId        = reader.ReadInt();
            map.BottomNeighbourId     = reader.ReadInt();
            map.LeftNeighbourId       = reader.ReadInt();
            map.RightNeighbourId      = reader.ReadInt();
            map.ShadowBonusOnEntities = (int)reader.ReadUInt();

            if (map.Version >= 9)
            {
                var readColor       = reader.ReadInt();
                var backgroundAlpha = (readColor & 4278190080) >> 32;
                var backgroundRed   = (readColor & 16711680) >> 16;
                var backgroundGreen = (readColor & 65280) >> 8;
                var backgroundBlue  = readColor & 255;
                readColor = (int)reader.ReadUInt();
                var gridAlpha = (readColor & 4278190080) >> 32;
                var gridRed   = (readColor & 16711680) >> 16;
                var gridGreen = (readColor & 65280) >> 8;
                var gridBlue  = readColor & 255;
                var gridColor = (gridAlpha & 255) << 32 | (gridRed & 255) << 16 | (gridGreen & 255) << 8 | gridBlue & 255;
            }
            else if (map.Version >= 3)
            {
                map.BackgroundColor = Color.FromArgb((int)reader.ReadByte(), (int)reader.ReadByte(), (int)reader.ReadByte());
            }
            if (map.Version >= 4)
            {
                map.ZoomScale   = reader.ReadUShort();
                map.ZoomOffsetX = reader.ReadShort();
                map.ZoomOffsetY = reader.ReadShort();
            }
            map.UseLowPassFilter = (reader.ReadByte() == 1);
            map.UseReverb        = (reader.ReadByte() == 1);
            if (map.UseReverb)
            {
                map.PresetId = reader.ReadInt();
            }
            else
            {
                map.PresetId = -1;
            }

            map.BackgroudFixtures = new DlmFixture[(int)reader.ReadByte()];
            for (int i = 0; i < map.BackgroudFixtures.Length; i++)
            {
                map.BackgroudFixtures[i] = DlmFixture.ReadFromStream(map, reader);
            }
            map.ForegroundFixtures = new DlmFixture[(int)reader.ReadByte()];
            for (int i = 0; i < map.ForegroundFixtures.Length; i++)
            {
                map.ForegroundFixtures[i] = DlmFixture.ReadFromStream(map, reader);
            }
            reader.ReadInt();
            map.GroundCRC = reader.ReadInt();
            map.Layers    = new DlmLayer[(int)reader.ReadByte()];
            for (int i = 0; i < map.Layers.Length; i++)
            {
                map.Layers[i] = DlmLayer.ReadFromStream(map, reader);
            }
            map.Cells = new DlmCellData[560];
            short j = 0;

            while ((int)j < map.Cells.Length)
            {
                map.Cells[(int)j] = DlmCellData.ReadFromStream(map, j, reader);
                j += 1;
            }
            return(map);
        }
Exemple #7
0
 public DlmLayer(DlmMap map)
 {
     this.Map = map;
 }
 public DlmFixture(DlmMap map)
 {
     this.Map = map;
 }