Ejemplo n.º 1
0
        internal void Init(BigEndianReader reader)
        {
            reader.ReadSByte();
            MapVersion = reader.ReadSByte();
            Id         = (int)reader.ReadUInt();

            if (MapVersion >= 7)
            {
                Encrypted        = reader.ReadBoolean();
                EncryptedVersion = reader.ReadSByte();
                int count = reader.ReadInt();
                if (Encrypted)
                {
                    byte[] buffer  = CustomHex.ToArray(CustomHex.FromString("649ae451ca33ec53bbcbcc33becf15f4", false));
                    byte[] buffer2 = reader.ReadBytes(count);
                    for (int n = 0; n < buffer2.Length; n++)
                    {
                        buffer2[n] = Convert.ToByte((buffer2[n] ^ buffer[(n % buffer.Length)]));
                    }
                    reader = new BigEndianReader(buffer2);
                }
            }

            RelativeId            = (int)reader.ReadUInt();
            MapType               = reader.ReadSByte();
            SubAreaId             = reader.ReadInt();
            TopNeighbourId        = reader.ReadInt();
            BottomNeighbourId     = reader.ReadInt();
            LeftNeighbourId       = reader.ReadInt();
            RightNeighbourId      = reader.ReadInt();
            ShadowBonusOnEntities = (int)reader.ReadUInt();

            if (MapVersion >= 9)
            {
                int readColor = reader.ReadInt();
                BackgroundAlpha = (readColor & 4278190080) >> 32;
                BackgroundRed   = (readColor & 16711680) >> 16;
                BackgroundGreen = (readColor & 65280) >> 8;
                BackgroundBlue  = readColor & 255;
                uint readColor2 = reader.ReadUInt();
                GridAlpha = (readColor2 & 4278190080) >> 32;
                GridRed   = (readColor2 & 16711680) >> 16;
                GridGreen = (readColor2 & 65280) >> 8;
                GridBlue  = readColor2 & 255;
            }
            else if (MapVersion >= 3)
            {
                BackgroundRed   = reader.ReadSByte();
                BackgroundGreen = reader.ReadSByte();
                BackgroundBlue  = reader.ReadSByte();
            }
            if (MapVersion >= 4)
            {
                ZoomScale   = Convert.ToDouble(reader.ReadUShort()) / 100;
                ZoomOffsetX = reader.ReadShort();
                ZoomOffsetY = reader.ReadShort();
            }

            UseLowPassFilter = reader.ReadBoolean();
            UseReverb        = reader.ReadBoolean();
            if (UseReverb)
            {
                PresetId = reader.ReadInt();
            }
            BackgroundsCount = reader.ReadSByte();
            for (int i = 0; i < BackgroundsCount; i++)
            {
                Fixture item = new Fixture();
                item.Init(reader);
                BackgroundFixtures.Add(item);
            }
            ForegroundsCount = reader.ReadSByte();
            for (int i = 0; i < ForegroundsCount; i++)
            {
                Fixture fixture2 = new Fixture();
                fixture2.Init(reader);
                ForegroundFixtures.Add(fixture2);
            }
            CellsCount = 560;
            reader.ReadInt();
            GroundCRC   = reader.ReadInt().ToString();
            LayersCount = reader.ReadSByte();
            for (int i = 0; i < LayersCount; i++)
            {
                Layer layer = new Layer();
                layer.Init(reader, MapVersion);
                Layers.Add(layer);
            }
            uint oldMvtSys = 0;

            for (int i = 0; i < CellsCount; i++)
            {
                CellData data = new CellData();
                data.Init(reader, MapVersion);
                if (oldMvtSys == 0)
                {
                    oldMvtSys = data.MoveZone;
                }
                if (data.MoveZone != oldMvtSys)
                {
                    IsUsingNewMovementSystem = true;
                }
                cells.Add(data);
            }
        }
Ejemplo n.º 2
0
        internal void Init(BigEndianReader reader)
        {
            byte header = reader.ReadByte();

            if (header != 77)
            {
                throw new Exception("Header cannot be different than 77");
            }
            MapVersion = reader.ReadSByte();
            Id         = reader.ReadUInt();
            if (MapVersion >= 7)
            {
                Encrypted        = reader.ReadBoolean();
                EncryptedVersion = reader.ReadSByte();
                int dataLen = reader.ReadInt();
                if (Encrypted)
                {
                    byte[] key           = Encoding.UTF8.GetBytes("649ae451ca33ec53bbcbcc33becf15f4");
                    var    encryptedData = reader.ReadBytes(dataLen);
                    System.IO.MemoryStream decryptedData = new System.IO.MemoryStream();
                    for (int i = 0; i < dataLen; i++)
                    {
                        decryptedData.WriteByte((byte)(encryptedData[i] ^ (key[i % key.Length])));
                    }

                    reader = new BigEndianReader(decryptedData.ToArray());
                }
            }

            RelativeId            = reader.ReadUInt();
            MapType               = reader.ReadSByte();
            SubAreaId             = reader.ReadInt();
            TopNeighbourId        = reader.ReadInt();
            BottomNeighbourId     = reader.ReadInt();
            LeftNeighbourId       = reader.ReadInt();
            RightNeighbourId      = reader.ReadInt();
            ShadowBonusOnEntities = reader.ReadInt();

            if (MapVersion >= 9)
            {
                int color = reader.ReadInt();
                BackgroundAlpha = (color & 4278190080) >> 32;
                BackgroundRed   = (color & 16711680) >> 16;
                BackgroundGreen = (color & 65280) >> 8;
                BackgroundBlue  = (color & 255);
                uint gridColor = reader.ReadUInt();
                GridAlpha = (gridColor & 4278190080) >> 32;
                GridRed   = (gridColor & 16711680) >> 16;
                GridGreen = (gridColor & 65280) >> 8;
                GridBlue  = (gridColor & 255);
                GridColor = (GridAlpha & 255) << 32 | (GridRed & 255) << 16 | (GridGreen & 255) << 8 | (GridBlue & 255);
            }
            else if (MapVersion >= 3)
            {
                BackgroundRed   = reader.ReadSByte();
                BackgroundGreen = reader.ReadSByte();
                BackgroundBlue  = reader.ReadSByte();
            }
            BackgroundColor = (BackgroundRed & 255) << 16 | (BackgroundGreen & 255) << 8 | (BackgroundBlue & 255);
            if (MapVersion >= 4)
            {
                ZoomScale   = Convert.ToDouble(reader.ReadUShort() / 100);
                ZoomOffsetX = Convert.ToInt32(reader.ReadShort());
                ZoomOffsetY = Convert.ToInt32(reader.ReadShort());
                if (ZoomScale < 1)
                {
                    ZoomScale   = 1;
                    ZoomOffsetX = 0;
                    ZoomOffsetY = 0;
                }
            }
            if (MapVersion > 10)
            {
                TacticalModeTempladeId = reader.ReadInt();
            }
            UseLowPassFilter = reader.ReadBoolean();
            UseReverb        = reader.ReadBoolean();
            if (UseReverb)
            {
                PresetId = reader.ReadInt();
            }
            else
            {
                PresetId = -1;
            }

            BackgroundsCount = reader.ReadSByte();
            for (var i = 0; i < BackgroundsCount; i++)
            {
                var fixture = new Fixture();
                fixture.Init(reader);
                BackgroundFixtures.Add(fixture);
            }
            ForegroundsCount = reader.ReadSByte();
            for (var i = 0; i < ForegroundsCount; i++)
            {
                var fixture = new Fixture();
                fixture.Init(reader);
                ForegroundFixtures.Add(fixture);
            }
            reader.ReadInt();
            GroundCRC   = reader.ReadInt().ToString();
            LayersCount = reader.ReadSByte();
            for (int i = 0; i < LayersCount; i++)
            {
                var layer = new Layer();
                layer.Init(reader, MapVersion);
                Layers.Add(layer);
            }
            CellsCount = 560;
            for (int i = 0; i < CellsCount; i++)
            {
                CellData cd = new CellData();
                cd.Init(reader, MapVersion, i, this);
                Cells.Add(cd);
            }
        }
Ejemplo n.º 3
0
        internal void Init(BigEndianReader reader)
        {
            char b = (char)reader.ReadByte();

            MapVersion = reader.ReadByte();
            Id         = (int)reader.ReadUInt();
            if (MapVersion >= 7)
            {
                Encrypted        = reader.ReadBoolean();
                EncryptedVersion = reader.ReadByte();
                int count = reader.ReadInt();
                if (Encrypted)
                {
                    byte[] buffer  = CustomHex.ToArray(CustomHex.FromString("649ae451ca33ec53bbcbcc33becf15f4", false));
                    byte[] buffer2 = reader.ReadBytes(count);
                    int    num7    = (buffer2.Length - 1);
                    int    n       = 0;
                    while (n <= num7)
                    {
                        buffer2[n] = Convert.ToByte((buffer2[n] ^ buffer[(n % buffer.Length)]));
                        n         += 1;
                    }
                    reader = new BigEndianReader(buffer2);
                }
            }
            RelativeId            = (int)reader.ReadUInt();
            MapType               = reader.ReadByte();
            SubAreaId             = reader.ReadInt();
            TopNeighbourId        = reader.ReadInt();
            BottomNeighbourId     = reader.ReadInt();
            LeftNeighbourId       = reader.ReadInt();
            RightNeighbourId      = reader.ReadInt();
            ShadowBonusOnEntities = reader.ReadUInt();
            if (MapVersion >= 9)
            {
                int readColor = reader.ReadInt();
                BackGroundAlpha = (readColor & 4278190080) >> 32;
                BackgroundRed   = (readColor & 16711680) >> 16;
                BackgroundGreen = (readColor & 65280) >> 8;
                BackgroundBlue  = readColor & 255;
                var gridColor = reader.ReadUInt();
                var gridAlpha = (gridColor & 4278190080) >> 32;
                var gridRed   = (gridColor & 16711680) >> 16;
                var gridGreen = (gridColor & 65280) >> 8;
                var gridBlue  = gridColor & 255;
                GridColor = (gridAlpha & 255) << 32 | (gridRed & 255) << 16 | (gridGreen & 255) << 8 | gridBlue & 255;
            }
            else if (MapVersion >= 3)
            {
                BackgroundRed   = reader.ReadByte();
                BackgroundGreen = reader.ReadByte();
                BackgroundBlue  = reader.ReadByte();
            }
            BackGroundColor = (BackgroundRed & 255) << 16 | (BackgroundGreen & 255) << 8 | BackgroundBlue & 255;
            if (MapVersion >= 4)
            {
                ZoomScale   = (Convert.ToDouble(reader.ReadUShort()) / 100);
                ZoomOffsetX = reader.ReadShort();
                ZoomOffsetY = reader.ReadShort();
                if (ZoomScale < 1)
                {
                    ZoomScale   = 1;
                    ZoomOffsetX = 0;
                    ZoomOffsetY = 0;
                }
            }
            UseLowPassFilter = reader.ReadBoolean();
            UseReverb        = reader.ReadBoolean();
            if (UseReverb)
            {
                PresetId = reader.ReadInt();
            }
            else
            {
                PresetId = -1;
            }
            BackgroundsCount = reader.ReadByte();
            int backgroundsCount = BackgroundsCount;
            int i = 1;

            while (i <= backgroundsCount)
            {
                Fixture item = new Fixture();
                item.Init(reader);
                BackgroundFixtures.Add(item);
                i += 1;
            }
            ForegroundsCount = reader.ReadByte();
            int foregroundsCount = ForegroundsCount;
            int j = 1;

            while (j <= foregroundsCount)
            {
                Fixture fixture2 = new Fixture();
                fixture2.Init(reader);
                ForegroundFixtures.Add(fixture2);
                j += 1;
            }
            CellsCount = 560;
            reader.ReadInt();
            GroundCRC   = reader.ReadInt().ToString();
            LayersCount = reader.ReadByte();
            int layersCount = LayersCount;
            int k           = 1;

            while (k <= layersCount)
            {
                Layer layer = new Layer();
                layer.Init(reader, MapVersion);
                Layers.Add(layer);
                k += 1;
            }
            int  cellsCount = CellsCount;
            int  m          = 1;
            uint oldMvtSys  = 0;

            TopArrowCells    = new List <int>();
            BottomArrowCells = new List <int>();
            RightArrowCells  = new List <int>();
            LeftArrowCells   = new List <int>();
            while (m <= cellsCount)
            {
                CellData data = new CellData(m);
                data.Init(reader, MapVersion, this);
                if (oldMvtSys == 0)
                {
                    oldMvtSys = (uint)data.MoveZone;
                }
                if (data.MoveZone != oldMvtSys)
                {
                    IsUsingNewMovementSystem = true;
                }
                Cells.Add(data);
                m += 1;
            }
        }