示例#1
0
        public DlmMap ReadMap()
        {
            m_reader.Seek(0, SeekOrigin.Begin);
            int header = m_reader.ReadByte();

            if (header != 77)
            {
                try
                {
                    m_reader.Seek(0, SeekOrigin.Begin);
                    var output = new MemoryStream();
                    ZipHelper.Deflate(new MemoryStream(m_reader.ReadBytes((int)m_reader.BytesAvailable)), output);

                    var uncompress = output.ToArray();

                    m_reader.Dispose();
                    m_reader = new FastBigEndianReader(uncompress);

                    header = m_reader.ReadByte();

                    if (header != 77)
                    {
                        throw new FileLoadException("Wrong header file");
                    }
                }
                catch (Exception ex)
                {
                    throw new FileLoadException("Wrong header file");
                }
            }

            var map = DlmMap.ReadFromStream(m_reader, this);

            return(map);
        }
示例#2
0
        public Map(int id, string decryptionKey)
        {
            // decryption key not used ? oO
            m_map = DataProvider.Instance.Get<DlmMap>(id, GenericDecryptionKey);
            IEnumerable<Cell> cells = m_map.Cells.Select(entry => new Cell(this, entry));

            Cells = new CellList(cells.ToArray());
        }
示例#3
0
        public static DlmLayer ReadFromStream(DlmMap map, IDataReader reader)
        {
            var layer = new DlmLayer(map);

            layer.LayerId = reader.ReadInt();
            layer.Cells = new DlmCell[reader.ReadShort()];
            for (int i = 0; i < layer.Cells.Length; i++)
            {
                layer.Cells[i] = DlmCell.ReadFromStream(layer, reader);
            }

            return layer;
        }
示例#4
0
        public static DlmLayer ReadFromStream(DlmMap map, IDataReader reader)
        {
            var layer = new DlmLayer(map);

            layer.LayerId = reader.ReadInt();
            layer.Cells   = new DlmCell[reader.ReadShort()];
            for (int i = 0; i < layer.Cells.Length; i++)
            {
                layer.Cells[i] = DlmCell.ReadFromStream(layer, reader);
            }

            return(layer);
        }
示例#5
0
        public static DlmFixture ReadFromStream(DlmMap map, IDataReader reader)
        {
            var fixture = new DlmFixture(map);

            fixture.FixtureId = reader.ReadInt();
            fixture.Offset    = new System.Drawing.Point(reader.ReadShort(), reader.ReadShort());
            fixture.Rotation  = reader.ReadShort();
            fixture.ScaleX    = reader.ReadShort();
            fixture.ScaleY    = reader.ReadShort();
            fixture.Hue       = reader.ReadByte() << 16 | reader.ReadByte() << 8 | reader.ReadByte();
            fixture.Alpha     = reader.ReadByte();

            return(fixture);
        }
示例#6
0
        public static DlmFixture ReadFromStream(DlmMap map, BigEndianReader reader)
        {
            var fixture = new DlmFixture(map);

            fixture.FixtureId = reader.ReadInt();
            fixture.Offset = new System.Drawing.Point(reader.ReadShort(), reader.ReadShort());
            fixture.Rotation = reader.ReadShort();
            fixture.ScaleX = reader.ReadShort();
            fixture.ScaleY = reader.ReadShort();
            fixture.Hue = reader.ReadByte() << 16 | reader.ReadByte() << 8 | reader.ReadByte();
            fixture.Alpha = reader.ReadByte();

            return fixture;
        }
示例#7
0
        public static DlmCellData ReadFromStream(DlmMap map, short id, BigEndianReader reader)
        {
            var cell = new DlmCellData(map, id);

            cell.Floor = (short)(reader.ReadByte() * 10);

            if (cell.Floor == -1280)
            {
                return(cell);
            }

            cell.LosMov        = reader.ReadByte();
            cell.Speed         = reader.ReadByte();
            cell.MapChangeData = reader.ReadByte();

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

            return(cell);
        }
示例#8
0
        public MapData(DlmMap map, MapPosition position = null)
        {
            Id= map.Id;
            Version = map.Version;
            Encrypted = map.Encrypted;
            EncryptionVersion = map.EncryptionVersion;
            RelativeId = map.RelativeId;
            MapType = map.MapType;
            SubAreaId = map.SubAreaId;
            BottomNeighbourId = map.BottomNeighbourId;
            LeftNeighbourId = map.LeftNeighbourId;
            RightNeighbourId = map.RightNeighbourId;
            TopNeighbourId = map.TopNeighbourId;
            Cells = new CellDataList(map.Cells.Select(x => new CellData(x)).ToArray());
            if (position != null)
            {
                X = position.posX;
                Y = position.posY;
                WorldMap = position.worldMap;
                Outdoor = position.outdoor;
            }
            else
            {
                X = ( Id & 0x3FE00 ) >> 9; // 9 higher bits
                Y = Id & 0x01FF; // 9 lower bits
                WorldMap = Id & 0x3FFC0000 >> 18;

                if ((X & 0x100) == 0x100) // 9th bit is the sign. 1 means it's minus
                {
                    X = -( X & 0xFF ); // just take the 8 first bits and take the opposite number
                }
                if (( Y & 0x100 ) == 0x100) // 9th bit is the sign. 1 means it's minus
                {
                    Y = -( Y & 0xFF ); // just take the 8 first bits and take the opposite number
                }
            }
        }
示例#9
0
        public static DlmCellData ReadFromStream(DlmMap map, short id, BigEndianReader reader)
        {
            var cell = new DlmCellData(map, id);

            cell.Floor = (short) (reader.ReadByte()*10);

            if (cell.Floor == -1280)
            {
                return cell;
            }

            cell.LosMov = reader.ReadByte();
            cell.Speed = reader.ReadByte();
            cell.MapChangeData = reader.ReadByte();

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

            return cell;
        }
示例#10
0
 public DlmFixture(DlmMap map)
 {
     Map = map;
 }
示例#11
0
 public DlmFixture(DlmMap map)
 {
     Map = map;
 }
示例#12
0
        public static DlmMap ReadFromStream(IDataReader givenReader, DlmReader dlmReader)
        {
            var reader = givenReader;
            var map    = new DlmMap();

            map.Version = reader.ReadByte();
            map.Id      = reader.ReadInt();

            if (map.Version >= 7)
            {
                map.Encrypted         = reader.ReadBoolean();
                map.EncryptionVersion = reader.ReadByte();

                var len = reader.ReadInt();

                if (map.Encrypted)
                {
                    var 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));
                    }

                    var data       = reader.ReadBytes(len);
                    var encodedKey = Encoding.Default.GetBytes(key);

                    if (key.Length > 0)
                    {
                        for (int i = 0; i < data.Length; i++)
                        {
                            data[i] = (byte)(data[i] ^ encodedKey[i % key.Length]);
                        }

                        reader = new FastBigEndianReader(data);
                    }
                }
            }

            map.RelativeId = reader.ReadUInt();
            map.MapType    = reader.ReadByte();

            // temp, just to know if the result is coherent
            if (map.MapType < 0 || map.MapType > 1)
            {
                throw new Exception("Invalid decryption key");
            }

            map.SubAreaId             = reader.ReadInt();
            map.TopNeighbourId        = reader.ReadInt();
            map.BottomNeighbourId     = reader.ReadInt();
            map.LeftNeighbourId       = reader.ReadInt();
            map.RightNeighbourId      = reader.ReadInt();
            map.ShadowBonusOnEntities = reader.ReadInt();

            if (map.Version >= 3)
            {
                map.BackgroundColor = Color.FromArgb(reader.ReadByte(), reader.ReadByte(), 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();
            }
            {
                map.PresetId = -1;
            }

            map.BackgroudFixtures = new DlmFixture[reader.ReadByte()];
            for (int i = 0; i < map.BackgroudFixtures.Length; i++)
            {
                map.BackgroudFixtures[i] = DlmFixture.ReadFromStream(map, reader);
            }

            map.ForegroundFixtures = new DlmFixture[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[reader.ReadByte()];
            for (int i = 0; i < map.Layers.Length; i++)
            {
                map.Layers[i] = DlmLayer.ReadFromStream(map, reader);
            }

            map.Cells = new DlmCellData[CellCount];
            int?lastMoveZone = null;

            for (short i = 0; i < map.Cells.Length; i++)
            {
                map.Cells[i] = DlmCellData.ReadFromStream(i, map.Version, reader);
                if (!lastMoveZone.HasValue)
                {
                    lastMoveZone = map.Cells[i].MoveZone;
                }
                else if (lastMoveZone != map.Cells[i].MoveZone) // if a cell is different the new system is used
                {
                    map.UsingNewMovementSystem = true;
                }
            }

            return(map);
        }
示例#13
0
 public DlmCellData(DlmMap map, short id)
 {
     Map    = map;
     Id     = id;
     LosMov = 3;
 }
示例#14
0
        public static DlmMap ReadFromStream(BigEndianReader givenReader, DlmReader dlmReader)
        {
            var reader = givenReader;
            var map = new DlmMap();

            map.Version = reader.ReadByte();
            map.Id = reader.ReadInt();

            if (map.Version >= 7)
            {
                map.Encrypted = reader.ReadBoolean();
                map.EncryptionVersion = reader.ReadByte();

                var len = reader.ReadInt();

                if (map.Encrypted)
                {
                    var 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));
                    }

                    var data = reader.ReadBytes(len);
                    var encodedKey = Encoding.Default.GetBytes(key);

                    if (key.Length > 0)
                    {
                        for (int i = 0; i < data.Length; i++)
                        {
                            data[i] = (byte)( 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 = reader.ReadInt();

            if (map.Version >= 3)
            {
                map.BackgroundColor = Color.FromArgb(reader.ReadByte(), reader.ReadByte(), 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();
            }
            {
                map.PresetId = -1;
            }

            map.BackgroudFixtures = new DlmFixture[reader.ReadByte()];
            for (int i = 0; i < map.BackgroudFixtures.Length; i++)
            {
                map.BackgroudFixtures[i] = DlmFixture.ReadFromStream(map, reader);
            }

            map.ForegroundFixtures = new DlmFixture[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[reader.ReadByte()];
            for (int i = 0; i < map.Layers.Length; i++)
            {
                map.Layers[i] = DlmLayer.ReadFromStream(map, reader);
            }

            map.Cells = new DlmCellData[CellCount];
            int? lastMoveZone = null;
            for (short i = 0; i < map.Cells.Length; i++)
            {
                map.Cells[i] = DlmCellData.ReadFromStream(map, i, reader);
                if (!lastMoveZone.HasValue)
                    lastMoveZone = map.Cells[i].MoveZone;
                else if (lastMoveZone != map.Cells[i].MoveZone) // if a cell is different the new system is used
                    map.UsingNewMovementSystem = true;
            }

            return map;
        }
示例#15
0
 public DlmLayer(DlmMap map)
 {
     Map = map;
 }
示例#16
0
 public DlmLayer(DlmMap map)
 {
     Map = map;
 }
示例#17
0
 public DlmCellData(DlmMap map, short id)
 {
     Map = map;
     Id = id;
     LosMov = 3;
 }