use of org.apollo.net.codec.game.GamePacketReader 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);
}
use of org.apollo.net.codec.game.GamePacketReader in project apollo by apollo-rsps.
the class MagicOnItemMessageDecoder method decode.
@Override
public MagicOnItemMessage decode(GamePacket packet) {
GamePacketReader reader = new GamePacketReader(packet);
int spell = (int) reader.getUnsigned(DataType.SHORT);
int interfaceId = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD);
int slot = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD);
int id = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD);
return new MagicOnItemMessage(interfaceId, id, slot, spell);
}
use of org.apollo.net.codec.game.GamePacketReader in project apollo by apollo-rsps.
the class ReportAbuseMessageDecoder method decode.
@Override
public ReportAbuseMessage decode(GamePacket packet) {
GamePacketReader reader = new GamePacketReader(packet);
String name = NameUtil.decodeBase37(reader.getSigned(DataType.LONG));
int rule = (int) reader.getUnsigned(DataType.BYTE);
boolean mute = reader.getUnsigned(DataType.BYTE) == 1;
return new ReportAbuseMessage(name, rule, mute);
}
use of org.apollo.net.codec.game.GamePacketReader in project apollo by apollo-rsps.
the class PlayerDesignMessageDecoder method decode.
@Override
public PlayerDesignMessage decode(GamePacket packet) {
GamePacketReader reader = new GamePacketReader(packet);
int genderIntValue = (int) reader.getUnsigned(DataType.BYTE);
int[] style = new int[7];
for (int i = 0; i < style.length; i++) {
style[i] = (int) reader.getUnsigned(DataType.BYTE);
}
int[] color = new int[5];
for (int i = 0; i < color.length; i++) {
color[i] = (int) reader.getUnsigned(DataType.BYTE);
}
Gender gender = genderIntValue == Gender.MALE.toInteger() ? Gender.MALE : Gender.FEMALE;
return new PlayerDesignMessage(new Appearance(gender, style, color));
}
use of org.apollo.net.codec.game.GamePacketReader in project apollo by apollo-rsps.
the class PublicChatMessageDecoder method decode.
@Override
public PublicChatMessage decode(GamePacket packet) {
GamePacketReader reader = new GamePacketReader(packet);
int color = (int) reader.getUnsigned(DataType.BYTE, DataTransformation.NEGATE);
int effects = (int) reader.getUnsigned(DataType.BYTE, DataTransformation.ADD);
int length = packet.getLength() - 2;
byte[] originalCompressed = new byte[length];
reader.getBytes(originalCompressed);
String uncompressed = TextUtil.decompress(originalCompressed, length);
uncompressed = TextUtil.filterInvalidCharacters(uncompressed);
uncompressed = TextUtil.capitalize(uncompressed);
byte[] recompressed = new byte[length];
// in case invalid data gets sent, this effectively verifies it
TextUtil.compress(uncompressed, recompressed);
return new PublicChatMessage(uncompressed, recompressed, color, effects);
}
Aggregations