예제 #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());
        }
예제 #3
0
        public void Serialize(ThingType thingType, Net.OutputMessage binaryWriter, int fromVersion, int newVersion, sbyte startPhase, byte phasesLimit)
        {
            binaryWriter.AddU8(Width);
            binaryWriter.AddU8(Height);
            if (Width > 1 || Height > 1)
            {
                binaryWriter.AddU8(ExactSize);
            }

            binaryWriter.AddU8(Layers);
            binaryWriter.AddU8(PatternWidth);
            binaryWriter.AddU8(PatternHeight);
            if (newVersion >= 755)
            {
                binaryWriter.AddU8(PatternDepth);
            }

            binaryWriter.AddU8(phasesLimit);

            if (fromVersion < 1050)
            {
                if (phasesLimit > 1 && newVersion >= 1050)
                {
                    FrameGroupAnimator.SerializeLegacy(thingType, binaryWriter, startPhase, phasesLimit);
                }
            }
            else
            {
                if (phasesLimit > 1 && newVersion >= 1050)
                {
                    Animator.Serialize(binaryWriter, startPhase, phasesLimit);
                }
            }

            int spritesPerPhase = Width * Height * Layers * PatternWidth * PatternHeight * PatternDepth;
            int totalSprites    = phasesLimit * spritesPerPhase;
            int offset          = startPhase * spritesPerPhase;

            for (int j = 0; j < totalSprites; j++)
            {
                uint spriteId = Sprites[offset + j];
                if (newVersion >= 960)
                {
                    binaryWriter.AddU32(spriteId);
                }
                else
                {
                    binaryWriter.AddU16((ushort)spriteId);
                }
            }
        }