Exemple #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());
        }
Exemple #2
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);
                }
            }
        }
        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());
        }
Exemple #4
0
        public static void SerializeLegacy(ThingType thingType, Net.OutputMessage binaryWriter, int startPhase, int phasesLimit)
        {
            binaryWriter.AddU8(1);
            binaryWriter.AddS32(thingType.HasAttribute(AttributesUniform.AnimateAlways) || thingType.Category == ThingCategory.Item ? 0 : 1);
            binaryWriter.AddU8(0);

            int duration;

            if (thingType.Category == ThingCategory.Effect)
            {
                duration = 75;
            }
            else
            {
                duration = phasesLimit > 0 ? 1000 / phasesLimit : 40;
            }

            for (int i = 0; i < phasesLimit; i++)
            {
                binaryWriter.AddS32(duration); // force legacy animation
                binaryWriter.AddS32(duration);
            }
        }
Exemple #5
0
        public void Serialize(Net.OutputMessage binaryWriter, int startPhase, int phasesLimit)
        {
            binaryWriter.AddU8(Async ? (byte)1 : (byte)0);
            binaryWriter.AddS32(LoopCount);

            int minPhase = startPhase;
            int maxPhase = startPhase = phasesLimit;

            if (StartPhase > 0 && (StartPhase < minPhase || StartPhase > maxPhase))
            {
                binaryWriter.AddS8((sbyte)minPhase);
            }
            else
            {
                binaryWriter.AddS8(StartPhase);
            }

            for (int i = 0; i < phasesLimit; i++)
            {
                var frameGroupDuration = FrameGroupDurations[startPhase + i];
                binaryWriter.AddS32(frameGroupDuration.Minimum);
                binaryWriter.AddS32(frameGroupDuration.Maximum);
            }
        }