Search in sources :

Example 1 with WalkMessage

use of org.apollo.game.message.impl.WalkMessage in project apollo by apollo-rsps.

the class WalkMessageDecoder method decode.

@Override
public WalkMessage decode(GamePacket packet) {
    GamePacketReader reader = new GamePacketReader(packet);
    int length = packet.getLength();
    if (packet.getOpcode() == 213) {
        // strip off anti-cheat data
        length -= 14;
    }
    int steps = (length - 5) / 2;
    int[][] path = new int[steps][2];
    int x = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD);
    boolean run = reader.getUnsigned(DataType.BYTE) == 1;
    int y = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD);
    for (int i = 0; i < steps; i++) {
        path[i][0] = (int) reader.getSigned(DataType.BYTE);
        path[i][1] = (int) reader.getSigned(DataType.BYTE, DataTransformation.SUBTRACT);
    }
    Position[] positions = new Position[steps + 1];
    positions[0] = new Position(x, y);
    for (int i = 0; i < steps; i++) {
        positions[i + 1] = new Position(path[i][0] + x, path[i][1] + y);
    }
    return new WalkMessage(positions, run);
}
Also used : WalkMessage(org.apollo.game.message.impl.WalkMessage) GamePacketReader(org.apollo.net.codec.game.GamePacketReader) Position(org.apollo.game.model.Position)

Example 2 with WalkMessage

use of org.apollo.game.message.impl.WalkMessage in project apollo by apollo-rsps.

the class WalkMessageDecoder method decode.

@Override
public WalkMessage decode(GamePacket packet) {
    GamePacketReader reader = new GamePacketReader(packet);
    int length = packet.getLength();
    if (packet.getOpcode() == 248) {
        // strip off anti-cheat data
        length -= 14;
    }
    int steps = (length - 5) / 2;
    int[][] path = new int[steps][2];
    int x = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD);
    for (int i = 0; i < steps; i++) {
        path[i][0] = (int) reader.getSigned(DataType.BYTE);
        path[i][1] = (int) reader.getSigned(DataType.BYTE);
    }
    int y = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE);
    boolean run = reader.getUnsigned(DataType.BYTE, DataTransformation.NEGATE) == 1;
    Position[] positions = new Position[steps + 1];
    positions[0] = new Position(x, y);
    for (int i = 0; i < steps; i++) {
        positions[i + 1] = new Position(path[i][0] + x, path[i][1] + y);
    }
    return new WalkMessage(positions, run);
}
Also used : WalkMessage(org.apollo.game.message.impl.WalkMessage) GamePacketReader(org.apollo.net.codec.game.GamePacketReader) Position(org.apollo.game.model.Position)

Aggregations

WalkMessage (org.apollo.game.message.impl.WalkMessage)2 Position (org.apollo.game.model.Position)2 GamePacketReader (org.apollo.net.codec.game.GamePacketReader)2