Vencillio ConstructMap packet
So I have decided to add construction to my game and I ran into a problem, The outgoing packet ConstructMap.java is not finished.
it looks like this:
Code:
package com.vencillio.rs2.entity.player.net.out.impl;
import com.vencillio.rs2.entity.Palette;
import com.vencillio.rs2.entity.player.net.Client;
import com.vencillio.rs2.entity.player.net.out.OutgoingPacket;
/**
* Created with Eclipse. Date: 19/08/2013 Time: 20:34:44
*
* @author Sebastian <[email protected]>
* @see java.lang.Object
*/
public final class ConstructMap extends OutgoingPacket {
private Palette palette;
public ConstructMap(final Palette palette) {
this.palette = palette;
}
@Override
public void execute(Client client) {
/*
* StreamBuffer.OutBuffer out = StreamBuffer.newOutBuffer(20);
* out.writeHeader(client.getEncryptor(), 241);
* bldr.writeShort(player.getLocation().getRegionY() + 6);
* bldr.startBitAccess(); for (int z = 0; z < 4; z++) { for (int x = 0;
* x < 13; x++) { for (int y = 0; y < 13; y++) { PaletteTile tile =
* palette.getTile(x, y, z); bldr.putBits(1, tile != null ? 1 : 0); if
* (tile != null) { bldr.putBits(26, tile.getX() << 14 | tile.getY() <<
* 3 | tile.getZ() << 24 | tile.getRotation() << 1); } } } }
* bldr.finishBitAccess();
* bldr.putShort(player.getLocation().getRegionX() + 6);
* player.write(bldr.toPacket());
*/
}
@Override
public int getOpcode() {
return 241;
}
public Palette getPalette() {
return palette;
}
}
I tried to write it myself and this is what I came up with:
Code:
package com.vencillio.rs2.entity.player.net.out.impl;
import com.vencillio.core.network.StreamBuffer;
import com.vencillio.core.network.StreamBuffer.ValueType;
import com.vencillio.rs2.content.skill.construction.Palette;
import com.vencillio.rs2.content.skill.construction.Palette.PaletteTile;
import com.vencillio.rs2.entity.player.Player;
import com.vencillio.rs2.entity.player.net.Client;
import com.vencillio.rs2.entity.player.net.out.OutgoingPacket;
public final class ConstructMap extends OutgoingPacket {
private Palette palette;
private Player player;
public ConstructMap(final Palette palette, final Player player) {
this.palette = palette;
this.player = player;
}
@Override
public void execute(Client client) {
StreamBuffer.OutBuffer out = StreamBuffer.newOutBuffer(20);
out.writeShort(player.getLocation().getRegionY() + 6, ValueType.A);
for (int z = 0; z < 4; z++) {
for (int x = 0; x < 13; x++) {
for (int y = 0; y < 13; y++) {
PaletteTile tile = palette.getTile(x, y, z);
boolean b = false;
if (x < 2 || x > 10 || y < 2 || y > 10)
b = true;
int toWrite = !b && tile != null ? 5 : 0;
out.writeByte(toWrite);
if(toWrite == 5) {
int val = tile.getX() << 14 | tile.getY() << 3 | tile.getZ() << 24 | tile.getRotation() << 1;
out.writeString(""+val+"");
}
}
}
}
out.writeShort(player.getLocation().getRegionX() + 6);
client.send(out.getBuffer());
}
@Override
public int getOpcode() {
return 241;
}
public Palette getPalette() {
return palette;
}
}
But it looks like there is something wrong, as when I call the packet I get this error:
Code:
[2017-07-17 22:25:23] java.lang.ArrayIndexOutOfBoundsException: 20
[2017-07-17 22:25:23] at org.jboss.netty.buffer.HeapChannelBuffer.setByte(HeapChannelBuffer.java:120)
[2017-07-17 22:25:23] at org.jboss.netty.buffer.AbstractChannelBuffer.writeByte(AbstractChannelBuffer.java:408)
[2017-07-17 22:25:23] at com.vencillio.core.network.StreamBuffer$OutBuffer.writeByte(StreamBuffer.java:701)
[2017-07-17 22:25:23] at com.vencillio.core.network.StreamBuffer$OutBuffer.writeByte(StreamBuffer.java:673)
[2017-07-17 22:25:23] at com.vencillio.rs2.entity.player.net.out.impl.ConstructMap.execute(ConstructMap.java:43)
[2017-07-17 22:25:23] at com.vencillio.rs2.entity.player.net.Client.processOutgoingPackets(Client.java:268)
[2017-07-17 22:25:23] at com.vencillio.core.NetworkThread.cycle(NetworkThread.java:58)
[2017-07-17 22:25:23] at com.vencillio.core.NetworkThread.run(NetworkThread.java:98)
Does anyone have this script or does anyone know what I did wrong?
I changed the code to this:
Code:
StreamBuffer.OutBuffer out = StreamBuffer.newOutBuffer(20);
out.writeHeader(client.getEncryptor(), 241);
out.writeShort(player.getLocation().getRegionY() + 6);
out.setAccessType(AccessType.BIT_ACCESS);
for (int z = 0; z < 4; z++) {
for (int x = 0; x < 13; x++) {
for (int y = 0; y < 13; y++) {
PaletteTile tile = palette.getTile(x, y, z);
out.writeBits(1, tile != null ? 1 : 0);
if(tile != null) {
out.writeBits(26, tile.getX() << 14 | tile.getY() <<3 | tile.getZ() << 24 | tile.getRotation() << 1);
}
}
}
}
out.setAccessType(AccessType.BYTE_ACCESS);
out.writeShort(player.getLocation().getRegionX() + 6);
client.send(out.getBuffer());
And it works server side, but now I am just getting a buch of client side errors.
Code:
Error: T1 - 140,0 - 241,97
Error: T1 - 130,0 - 140,241
Error: T1 - 152,0 - 85,130
Error: T1 - 157,0 - 152,85
Error: T1 - 111,0 - 157,152
Error: T1 - 207,0 - 125,111
Error: T1 - 100,0 - 207,125
Error: T1 - 31,0 - 87,100
Error: T1 - 232,0 - 31,87
Error: T1 - 144,0 - 114,232
Error: T1 - 88,0 - 144,114
Error: T1 - 25,0 - 88,144
Error: T1 - 250,0 - 74,125
Error: T1 - 59,0 - 250,74
Error: T1 - 37,0 - 61,156
Error: T1 - 7,0 - 37,61
Error: T1 - 58,0 - 7,37
java.lang.ArrayIndexOutOfBoundsException: 5000
Error: T2 - 53,217,106 - 1,1884,5755 - 0,
at Stream.readString(Stream.java:176)
at Client.parsePacket(Client.java:12467)
at Client.mainGameProcessor(Client.java:3562)
at Client.processGameLoop(Client.java:2830)
at ClientEngine.run(ClientEngine.java:293)
at Client.run(Client.java:5366)
at java.lang.Thread.run(Unknown Source)
java.lang.NullPointerException
at Client.parsePacket(Client.java:13419)
at Client.mainGameProcessor(Client.java:3562)
at Client.processGameLoop(Client.java:2830)
at ClientEngine.run(ClientEngine.java:293)
at Client.run(Client.java:5366)
at java.lang.Thread.run(Unknown Source)
Exception in thread "Thread-3" java.lang.ArrayIndexOutOfBoundsException: 165
at Client.drawChannelButtons(Client.java:489)
at Client.drawChatArea(Client.java:554)
at Client.drawGameScreen(Client.java:9182)
at Client.processDrawing(Client.java:10344)
at ClientEngine.run(ClientEngine.java:301)
at Client.run(Client.java:5366)
at java.lang.Thread.run(Unknown Source)