Ejemplo n.º 1
0
        public byte[] ConvertTo(int newVersion)
        {
            var binaryWriter = new Net.OutputMessage();

            binaryWriter.AddU32(ClientVersionToDatSignature(newVersion));

            int[] counts = new int[(int)ThingCategory.LastCategory];
            for (int category = 0; category < (int)ThingCategory.LastCategory; category++)
            {
                int toWrite = ThingTypeDictionaries[category].Count;
                if (category == (int)ThingCategory.Item)
                {
                    toWrite += 99;
                }

                counts[category] = toWrite + 1;
                binaryWriter.AddU16((ushort)toWrite);
            }

            for (int category = 0; category < (int)ThingCategory.LastCategory; category++)
            {
                ushort firstId = 1;
                if (category == (int)ThingCategory.Item)
                {
                    firstId = 100;
                }

                for (ushort id = firstId; id < counts[category]; id++)
                {
                    ThingTypeDictionaries[category][id].Serialize(binaryWriter, m_ClientVersion, newVersion);
                }
            }

            return(binaryWriter.GetBufferArray());
        }
        public byte[] ConvertTo(int newVersion)
        {
            var binaryWriter = new Net.OutputMessage();

            binaryWriter.AddU32(ClientVersionToSprSignature(newVersion));

            int padding = 0;

            if (newVersion >= 960)
            {
                binaryWriter.AddU32(SpritesCount);
                padding = m_ClientVersion < 960 ? 2 : 0;
            }
            else
            {
                binaryWriter.AddU16((ushort)SpritesCount);
                padding = m_ClientVersion >= 960 ? -2 : 0;
            }

            m_BinaryReader.Seek(SpritesOffset);
            for (uint i = 0; i < SpritesCount; i++)
            {
                var spriteAddress = m_BinaryReader.GetU32();
                if (spriteAddress == 0)
                {
                    binaryWriter.AddU32(0);
                }
                else
                {
                    binaryWriter.AddU32((uint)(spriteAddress + padding));
                }
            }

            var pixels = m_BinaryReader.GetUnreadBuffer();

            binaryWriter.AddBytes(pixels);

            return(binaryWriter.GetBufferArray());
        }