private static void PutAnimationBlock(AnimationBlock block, MessageFrameBuilder builder) { var animation = block.Animation; builder.Put(MessageType.Short, DataOrder.Little, animation.Id); builder.Put(MessageType.Byte, DataTransformation.Negate, animation.Delay); }
protected override void Encode(IChannelHandlerContext context, ProtoMessage message, List <object> output) { var protoMessageCodec = _protoMessageCodecHandler.EncoderCodecs[message.Opcode]; var messageCodec = protoMessageCodec.MessageCodec; var fieldCodecs = protoMessageCodec.FieldCodec; Serilog.Log.Logger.Debug("Encoder Sent: {0} - {1} to {2}", message.Message, message.Message.Descriptor.ClrType.Name, message.Player.Username); var frameType = messageCodec.SizeType.GetFrameType(); var bldr = new MessageFrameBuilder(context.Allocator, message.Opcode, frameType); foreach (var field in fieldCodecs) { var isString = field.FieldCodec.Type == Models.FieldType.String; MessageType?messageType = isString ? null : field.FieldCodec.Type.GetMessageType(); var dataTransform = field.FieldCodec.Transform.GetDataTransformation(); var dataOrder = field.FieldCodec.Order.GetDataOrder(); object value = field.FieldDescriptor.Accessor.GetValue(message.Message); if (!isString) { long unboxedInt = field.ToUnboxedNumber(value); bldr.Put(messageType.Value, dataOrder, dataTransform, unboxedInt); } else { bldr.PutString((string)value); } } output.Add(bldr.ToMessageFrame()); }
public MessageFrame ToMessage(IByteBufferAllocator alloc) { var messageFrameBuilder = new MessageFrameBuilder(alloc, 238, FrameType.VariableShort); messageFrameBuilder.Put(MessageType.Int, Player.PingCount++ > 0xF42400 ? Player.PingCount = 1 : Player.PingCount); return(messageFrameBuilder.ToMessageFrame()); }
public override MessageFrame ToMessage(IByteBufferAllocator alloc) { var bldr = new MessageFrameBuilder(alloc, 101); bldr.Put(MessageType.Byte, DataTransformation.Negate, _type << 2 | _orientation); bldr.Put(MessageType.Byte, _positionOffset); return(bldr.ToMessageFrame()); }
private void PutAppearanceBlock(AppearanceBlock block, MessageFrameBuilder builder) { Appearance appearance = block.Appearance; var playerProperties = new MessageFrameBuilder(builder.Alloc); playerProperties.Put(MessageType.Byte, (int)appearance.Gender); playerProperties.Put(MessageType.Byte, 0); playerProperties.Put(MessageType.Byte, 0); if (block.NpcId > 0) { playerProperties.Put(MessageType.Byte, 255); playerProperties.Put(MessageType.Byte, 255); playerProperties.Put(MessageType.Short, block.NpcId); } else { //Inventory equipment = block.getEquipment(); int[] style = appearance.Style; //Item item, chest, helm; for (int slot = 0; slot < 4; slot++) { playerProperties.Put(MessageType.Byte, 0); } playerProperties.Put(MessageType.Short, 0x100 + style[2]); //Chest playerProperties.Put(MessageType.Byte, 0); //Shield playerProperties.Put(MessageType.Short, 0x100 + style[3]); //Arms playerProperties.Put(MessageType.Short, 0x100 + style[5]); //Legs playerProperties.Put(MessageType.Short, 0x100 + style[0]); //Helm playerProperties.Put(MessageType.Short, 0x100 + style[4]); //Hands playerProperties.Put(MessageType.Short, 0x100 + style[6]); //Feet playerProperties.Put(MessageType.Short, 0x100 + style[1]); //Beard } int[] colors = appearance.Colors; foreach (int color in colors) { playerProperties.Put(MessageType.Byte, color); } playerProperties.Put(MessageType.Short, 0x328); // stand playerProperties.Put(MessageType.Short, 0x337); // stand turn playerProperties.Put(MessageType.Short, 0x333); // walk playerProperties.Put(MessageType.Short, 0x334); // turn 180 playerProperties.Put(MessageType.Short, 0x335); // turn 90 cw playerProperties.Put(MessageType.Short, 0x336); // turn 90 ccw playerProperties.Put(MessageType.Short, 0x338); // run playerProperties.Put(MessageType.Long, block.Name); playerProperties.Put(MessageType.Byte, block.Combat); playerProperties.Put(MessageType.Short, block.Skill); builder.Put(MessageType.Byte, DataTransformation.Add, playerProperties.GetLength()); builder.PutRawBuilder(playerProperties); }
public override MessageFrame ToMessage(IByteBufferAllocator alloc) { MessageFrameBuilder builder = new MessageFrameBuilder(alloc, 151); builder.Put(MessageType.Byte, DataTransformation.Add, _positionOffset); builder.Put(MessageType.Short, DataOrder.Little, _id); builder.Put(MessageType.Byte, DataTransformation.Subtract, _type << 2 | _orientation); return(builder.ToMessageFrame()); }
private void PutAddPlayerUpdate(AddPlayerSegment seg, MessageFrameBuilder builder) { var updateRequired = seg.BlockSet.Size() > 0; Position player = Position; Position other = seg.Position; builder.PutBits(11, seg.Index); builder.PutBits(1, updateRequired ? 1 : 0); builder.PutBits(1, 1); // discard walking queue? builder.PutBits(5, other.Y - player.Y); builder.PutBits(5, other.X - player.X); }
public MessageFrame ToMessage(IByteBufferAllocator alloc) { MessageFrameBuilder bldr = new MessageFrameBuilder(alloc, 60, FrameType.VariableShort); Position basePos = _lastKnownRegion; bldr.Put(MessageType.Byte, _update.GetLocalY(basePos)); bldr.Put(MessageType.Byte, DataTransformation.Negate, _update.GetLocalX(basePos)); foreach (RegionUpdateMessage update in _messages) { var frame = update.ToMessage(alloc); bldr.Put(MessageType.Byte, frame.Id); bldr.PutBytes(frame.Payload); } return(bldr.ToMessageFrame()); }
private void PutMovementUpdate(SynchronizationSegment seg, MessageFrameBuilder builder) { bool updateRequired = seg.BlockSet.Size() > 0; if (seg.Type == SegmentType.Teleport) { var teleportSeg = ((TeleportSegment)seg); Position position = teleportSeg.Destination; builder.PutBits(1, 1); builder.PutBits(2, 3); builder.PutBits(1, RegionChanged ? 0 : 1); builder.PutBits(1, updateRequired ? 1 : 0); builder.PutBits(7, position.GetLocalX(LastKnownRegion)); builder.PutBits(2, position.Height); builder.PutBits(7, position.GetLocalY(LastKnownRegion)); } else if (seg.Type == SegmentType.Run) { Direction[] directions = ((MovementSegment)seg).Directions; builder.PutBits(1, 1); builder.PutBits(2, 2); builder.PutBits(3, directions[0].IntValue); builder.PutBits(3, directions[1].IntValue); builder.PutBits(1, updateRequired ? 1 : 0); } else if (seg.Type == SegmentType.Walk) { Direction[] directions = ((MovementSegment)seg).Directions; builder.PutBits(1, 1); builder.PutBits(2, 1); builder.PutBits(3, directions[0].IntValue); builder.PutBits(1, updateRequired ? 1 : 0); } else { if (updateRequired) { builder.PutBits(1, 1); builder.PutBits(2, 0); } else { builder.PutBits(1, 0); } } }
public MessageFrame ToMessage(IByteBufferAllocator alloc) { var bldr = new MessageFrameBuilder(alloc, 150, FrameType.VariableShort); bldr.SwitchToBitAccess(); var blockBuilder = new MessageFrameBuilder(alloc); PutMovementUpdate(Segment, bldr); PutBlocks(Segment, blockBuilder); bldr.PutBits(8, LocalPlayers); foreach (SynchronizationSegment segment in Segments) { SegmentType type = segment.Type; if (type == SegmentType.Remove_Mob) { PutRemovePlayerUpdate(bldr); } else if (type == SegmentType.Add_Mob) { PutAddPlayerUpdate((AddPlayerSegment)segment, bldr); PutBlocks(segment, blockBuilder); } else { PutMovementUpdate(segment, bldr); PutBlocks(segment, blockBuilder); } } if (blockBuilder.GetLength() > 0) { bldr.PutBits(11, 2047); bldr.SwitchToByteAccess(); bldr.PutRawBuilder(blockBuilder); } else { bldr.SwitchToByteAccess(); } return(bldr.ToMessageFrame()); }
public MessageFrame ToMessage(IByteBufferAllocator alloc) { var messageFrameBuilder = new MessageFrameBuilder(alloc, 61, FrameType.VariableShort); var playerPos = Player.Position; var clearRegion = false; var regionX = playerPos.RegionX; var regionY = playerPos.RegionY; var absoluteRegionX = (regionX + 6) / 8; var absoluteRegionY = (regionY + 6) / 8; if ( ((absoluteRegionX == 48 || absoluteRegionX == 49) && absoluteRegionY == 48) || (absoluteRegionX == 48 && absoluteRegionY == 148) ) { clearRegion = true; } messageFrameBuilder.Put(MessageType.Short, DataOrder.Little, DataTransformation.Add, playerPos.LocalY); messageFrameBuilder.Put(MessageType.Byte, playerPos.Height); messageFrameBuilder.Put(MessageType.Short, regionX + 6); for (int xCalc = regionX / 8; xCalc <= (regionX + 12) / 8; xCalc++) { for (int yCalc = regionY / 8; yCalc <= (regionY + 12) / 8; yCalc++) { int regionId = yCalc + (xCalc << 8); // 1786653352 if (clearRegion || yCalc != 49 && yCalc != 149 && yCalc != 147 && xCalc != 50 && (xCalc != 49 || yCalc != 47)) { messageFrameBuilder.Put(MessageType.Int, DataOrder.Little, 0); messageFrameBuilder.Put(MessageType.Int, DataOrder.Little, 0); messageFrameBuilder.Put(MessageType.Int, DataOrder.Little, 0); messageFrameBuilder.Put(MessageType.Int, DataOrder.Little, 0); } } } messageFrameBuilder.Put(MessageType.Short, DataOrder.Big, DataTransformation.Add, playerPos.LocalX); messageFrameBuilder.Put(MessageType.Short, regionY + 6); return(messageFrameBuilder.ToMessageFrame()); }
private void PutBlocks(SynchronizationSegment segment, MessageFrameBuilder builder) { var blockSet = segment.BlockSet; if (blockSet.Size() > 0) { int mask = 0; if (blockSet.Contains <AnimationBlock>()) { mask |= 0x8; } if (blockSet.Contains <AppearanceBlock>()) { mask |= 0x10; } if (mask >= 0x100) { mask |= 0x20; builder.Put(MessageType.Byte, (mask & 0xFF)); builder.Put(MessageType.Byte, (mask >> 8)); } else { builder.Put(MessageType.Byte, mask); } if (blockSet.Contains <AnimationBlock>()) { PutAnimationBlock(blockSet.Get <AnimationBlock>(), builder); } if (blockSet.Contains <AppearanceBlock>()) { PutAppearanceBlock(blockSet.Get <AppearanceBlock>(), builder); } } }
private void PutRemovePlayerUpdate(MessageFrameBuilder builder) { builder.PutBits(1, 1); builder.PutBits(2, 3); }