Issue with region generation and packet sizing
Looked through a few sources to get region generation/construction going. I'm having issues with Packet 241 (ConstructMapRegion). I am currently on vencillio and I've got a little too much time invested to switch sources. The main difference I am noticing compared to other sources is that I have to declare the size server sided where others do not. I match the client side packet size to the server and I still am getting T1/T2 Errors. I'm not really sure if 20 is correct but its what I've seen on a few other really old posts.
Server Code:
Code:
StreamBuffer.OutBuffer out = StreamBuffer.newOutBuffer(20);
out.writeHeader(paramClient.getEncryptor(), 241);
out.writeShort(paramClient.getPlayer().getLocation().getRegionX() + 6);
out.writeShort(paramClient.getPlayer().getLocation().getRegionY() + 6);
out.setAccessType(StreamBuffer.AccessType.BIT_ACCESS);
for (int z = 0; z < 4; z++) {
for (int x = 0; x < 13; x++) {
for (int y = 0; y < 13; y++) {
Palette.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 ? 1 : 0;
out.writeBits(1, toWrite);
if (toWrite == 1) {
int val = tile.getX() << 14 | tile.getY() << 3 | tile.getZ() << 24 | tile.getRotation() << 1;
out.writeBits(26, val);
}
}
}
}
out.setAccessType(StreamBuffer.AccessType.BYTE_ACCESS);
paramClient.send(out.getBuffer());
Client Code: (I've cross referenced this code to about 3 other sources as well and it seems fairly consistent.)
Code:
case 73:
case 241:
int regionX = mapRegionsX;
int regionY = mapRegionsY;
if (pktType == 73) {
regionX = MapX = inStream.method435();
regionY = MapY = inStream.readUShort();
dynamicRegion = false;
}
if (pktType == 241) {
System.out.println("241 packet size: " + pktSize);
regionX = MapX = inStream.readUShort();
regionY = MapY = inStream.readUShort();
inStream.initBitAccess();
for (int j16 = 0; j16 < 4; j16++) {
for (int l20 = 0; l20 < 13; l20++) {
for (int j23 = 0; j23 < 13; j23++) {
int i26 = inStream.readBits(1);
if (i26 == 1) {
anIntArrayArrayArray1129[j16][l20][j23] = inStream.readBits(26);
} else {
anIntArrayArrayArray1129[j16][l20][j23] = -1;
}
}
}
}
inStream.finishBitAccess();
dynamicRegion = true;
}
if (pktType != 241 && mapRegionsX == regionX && mapRegionsY == regionY && loadingStage == 2) {
pktType = -1;
return true;
}
mapRegionsX = regionX;
mapRegionsY = regionY;
regionBaseX = (mapRegionsX - 6) * 8;
regionBaseY = (mapRegionsY - 6) * 8;
aBoolean1141 = (mapRegionsX / 8 == 48 || mapRegionsX / 8 == 49) && mapRegionsY / 8 == 48;
if (mapRegionsX / 8 == 48 && mapRegionsY / 8 == 148)
aBoolean1141 = true;
loadingStage = 1;
aLong824 = System.currentTimeMillis();
aRSImageProducer_1165.initDrawingArea();
drawLoadingMessages(1, "Loading - please wait.", null);
aRSImageProducer_1165.drawGraphics(frameMode == ScreenMode.FIXED ? 4 : 0, super.graphics,
frameMode == ScreenMode.FIXED ? 4 : 0);
if (pktType == 73) {
int k16 = 0;
for (int i21 = (mapRegionsX - 6) / 8; i21 <= (mapRegionsX + 6) / 8; i21++) {
for (int k23 = (mapRegionsY - 6) / 8; k23 <= (mapRegionsY + 6) / 8; k23++)
k16++;
}
aByteArrayArray1183 = new byte[k16][];
aByteArrayArray1247 = new byte[k16][];
mapCoordinates = new int[k16];
anIntArray1235 = new int[k16];
anIntArray1236 = new int[k16];
k16 = 0;
for (int l23 = (mapRegionsX - 6) / 8; l23 <= (mapRegionsX + 6) / 8; l23++) {
for (int j26 = (mapRegionsY - 6) / 8; j26 <= (mapRegionsY + 6) / 8; j26++) {
mapCoordinates[k16] = (l23 << 8) + j26;
if (aBoolean1141
&& (j26 == 49 || j26 == 149 || j26 == 147 || l23 == 50 || l23 == 49 && j26 == 47)) {
anIntArray1235[k16] = -1;
anIntArray1236[k16] = -1;
k16++;
} else {
int k28 = anIntArray1235[k16] = onDemandFetcher.method562(0, j26, l23);
if (k28 != -1)
onDemandFetcher.method558(3, k28);
int j30 = anIntArray1236[k16] = onDemandFetcher.method562(1, j26, l23);
if (j30 != -1)
onDemandFetcher.method558(3, j30);
k16++;
}
}
}
}
if (pktType == 241) {
int l16 = 0;
int ai[] = new int[676];
for (int i24 = 0; i24 < 4; i24++) {
for (int k26 = 0; k26 < 13; k26++) {
for (int l28 = 0; l28 < 13; l28++) {
int k30 = anIntArrayArrayArray1129[i24][k26][l28];
if (k30 != -1) {
int k31 = k30 >> 14 & 0x3ff;
int i32 = k30 >> 3 & 0x7ff;
int k32 = (k31 / 8 << 8) + i32 / 8;
for (int j33 = 0; j33 < l16; j33++) {
if (ai[j33] != k32)
continue;
k32 = -1;
}
if (k32 != -1)
ai[l16++] = k32;
}
}
}
}
aByteArrayArray1183 = new byte[l16][];
aByteArrayArray1247 = new byte[l16][];
mapCoordinates = new int[l16];
anIntArray1235 = new int[l16];
anIntArray1236 = new int[l16];
for (int l26 = 0; l26 < l16; l26++) {
int i29 = mapCoordinates[l26] = ai[l26];
int l30 = i29 >> 8 & 0xff;
int l31 = i29 & 0xff;
int j32 = anIntArray1235[l26] = onDemandFetcher.method562(0, l31, l30);
if (j32 != -1)
onDemandFetcher.method558(3, j32);
int i33 = anIntArray1236[l26] = onDemandFetcher.method562(1, l31, l30);
if (i33 != -1)
onDemandFetcher.method558(3, i33);
}
}
int i17 = regionBaseX - anInt1036;
int j21 = regionBaseY - anInt1037;
anInt1036 = regionBaseX;
anInt1037 = regionBaseY;
for (int j24 = 0; j24 < 16384; j24++) {
Npc npc = npcArray[j24];
if (npc != null) {
for (int j29 = 0; j29 < 10; j29++) {
npc.smallX[j29] -= i17;
npc.smallY[j29] -= j21;
}
npc.x -= i17 * 128;
npc.y -= j21 * 128;
}
}
for (int i27 = 0; i27 < maxPlayers; i27++) {
Player player = playerArray[i27];
if (player != null) {
for (int i31 = 0; i31 < 10; i31++) {
player.smallX[i31] -= i17;
player.smallY[i31] -= j21;
}
player.x -= i17 * 128;
player.y -= j21 * 128;
}
}
aBoolean1080 = true;
byte byte1 = 0;
byte byte2 = 104;
byte byte3 = 1;
if (i17 < 0) {
byte1 = 103;
byte2 = -1;
byte3 = -1;
}
byte byte4 = 0;
byte byte5 = 104;
byte byte6 = 1;
if (j21 < 0) {
byte4 = 103;
byte5 = -1;
byte6 = -1;
}
for (int k33 = byte1; k33 != byte2; k33 += byte3) {
for (int l33 = byte4; l33 != byte5; l33 += byte6) {
int i34 = k33 + i17;
int j34 = l33 + j21;
for (int k34 = 0; k34 < 4; k34++)
if (i34 >= 0 && j34 >= 0 && i34 < 104 && j34 < 104)
groundArray[k34][k33][l33] = groundArray[k34][i34][j34];
else
groundArray[k34][k33][l33] = null;
}
}
for (Class30_Sub1 class30_sub1_1 = (Class30_Sub1) aClass19_1179
.reverseGetFirst(); class30_sub1_1 != null; class30_sub1_1 = (Class30_Sub1) aClass19_1179
.reverseGetNext()) {
class30_sub1_1.anInt1297 -= i17;
class30_sub1_1.anInt1298 -= j21;
if (class30_sub1_1.anInt1297 < 0 || class30_sub1_1.anInt1298 < 0 || class30_sub1_1.anInt1297 >= 104
|| class30_sub1_1.anInt1298 >= 104)
class30_sub1_1.unlink();
}
if (destX != 0) {
destX -= i17;
destY -= j21;
}
aBoolean1160 = false;
pktType = -1;
return true;
Packet Size: (I've tried -1 and -2 to try to read it from the actual inStream but that fails as well - I either get 0, or 239 not 100% sure why either)
Code:
2, 19, 0, 0, 0, 0, 6, 0, 4, 3, // 240
The reason why its 19 (I've tried 20) is because a few of the other packets I have are 1 less in the packetSizes array than in the newOutBuffer(size) code.
Console: (Prints are pretty much every time it loops through)
Code:
PACKET IS : 241
About to check packets
241 packet size: 19
PACKET IS : 34
About to check packets
PACKET IS : 231
About to check packets
Error: T1 - Packet Type 231, Size0 - 34,241
PACKET IS : 56
About to check packets
Error: T1 - Packet Type 56, Size0 - 231,34
Thanks in advance,
Crazz