public void Unserialize(Net.InputMessage binaryReader, int clientVersion) { Width = binaryReader.GetU8(); Height = binaryReader.GetU8(); if (Width > 1 || Height > 1) { ExactSize = binaryReader.GetU8(); } else { ExactSize = 32; } Layers = binaryReader.GetU8(); PatternWidth = binaryReader.GetU8(); PatternHeight = binaryReader.GetU8(); PatternDepth = clientVersion >= 755 ? binaryReader.GetU8() : (byte)1; Phases = binaryReader.GetU8(); if (Phases > 1 && clientVersion >= 1050) { Animator = new FrameGroupAnimator(); Animator.Unserialize(Phases, binaryReader); } int totalSprites = Width * Height * Layers * PatternWidth * PatternHeight * PatternDepth * Phases; for (int j = 0; j < totalSprites; j++) { Sprites.Add(clientVersion >= 960 ? binaryReader.GetU32() : binaryReader.GetU16()); } }
public static FrameGroup Serialize(ThingCategory category, ref Net.InputMessage binaryReader) { FrameGroup frameGroup = new FrameGroup(); frameGroup.Width = binaryReader.GetU8(); frameGroup.Height = binaryReader.GetU8(); if (frameGroup.Width > 1 || frameGroup.Height > 1) { frameGroup.ExactSize = binaryReader.GetU8(); } else { frameGroup.ExactSize = 32; } frameGroup.Layers = binaryReader.GetU8(); frameGroup.PatternWidth = binaryReader.GetU8(); frameGroup.PatternHeight = binaryReader.GetU8(); frameGroup.PatternDepth = binaryReader.GetU8(); frameGroup.Phases = binaryReader.GetU8(); if (frameGroup.Phases > 1) { frameGroup.Animator = FrameGroupAnimator.Serialize(frameGroup.Phases, ref binaryReader); } int totalSprites = frameGroup.Width * frameGroup.Height * frameGroup.Layers * frameGroup.PatternWidth * frameGroup.PatternHeight * frameGroup.PatternDepth * frameGroup.Phases; for (int j = 0; j < totalSprites; j++) { frameGroup.Sprites.Add(binaryReader.GetU32()); } return(frameGroup); }
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 static FrameGroupAnimator Serialize(byte animationPhases, ref Net.InputMessage binaryReader) { FrameGroupAnimator frameGroupAnimator = new FrameGroupAnimator(); frameGroupAnimator.AnimationPhases = animationPhases; frameGroupAnimator.Async = binaryReader.GetU8() == 0; frameGroupAnimator.LoopCount = binaryReader.GetS32(); frameGroupAnimator.StartPhase = binaryReader.GetS8(); for (int i = 0; i < animationPhases; i++) { FrameGroupDuration duration = new FrameGroupDuration(); duration.Minimum = (int)binaryReader.GetU32(); duration.Maximum = (int)binaryReader.GetU32(); frameGroupAnimator.FrameGroupDurations.Add(duration); } return(frameGroupAnimator); }