From 3fb3b200d21311b9fd8b8e2756f6838706c6b526 Mon Sep 17 00:00:00 2001 From: skeletor Date: Tue, 21 Jan 2020 06:26:44 -0500 Subject: [PATCH] fixed byte-overflow in UpdateStackHeightComposer --- .../com/eu/habbo/habbohotel/rooms/Room.java | 4 ++-- .../rooms/items/SetStackHelperHeightEvent.java | 2 +- .../rooms/UpdateStackHeightComposer.java | 17 ++++++++++++----- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java b/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java index 174cad24..480f5f4c 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java @@ -547,7 +547,7 @@ public class Room implements Comparable, ISerialize, Runnable { tile.setState(this.calculateTileState(tile)); } - this.sendComposer(new UpdateStackHeightComposer(tiles).compose()); + this.sendComposer(new UpdateStackHeightComposer(this, tiles).compose()); } private RoomTileState calculateTileState(RoomTile tile) { @@ -655,7 +655,7 @@ public class Room implements Comparable, ISerialize, Runnable { } } } - this.sendComposer(new UpdateStackHeightComposer(updatedTiles).compose()); + this.sendComposer(new UpdateStackHeightComposer(this, updatedTiles).compose()); this.updateTiles(updatedTiles); for (RoomTile tile : updatedTiles) { this.updateHabbosAt(tile.x, tile.y); diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/SetStackHelperHeightEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/SetStackHelperHeightEvent.java index 4986e685..a46bb7d2 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/SetStackHelperHeightEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/SetStackHelperHeightEvent.java @@ -51,7 +51,7 @@ public class SetStackHelperHeightEvent extends MessageHandler { item.needsUpdate(true); this.client.getHabbo().getHabboInfo().getCurrentRoom().updateItem(item); this.client.getHabbo().getHabboInfo().getCurrentRoom().updateTiles(tiles); - this.client.getHabbo().getHabboInfo().getCurrentRoom().sendComposer(new UpdateStackHeightComposer(tiles).compose()); + this.client.getHabbo().getHabboInfo().getCurrentRoom().sendComposer(new UpdateStackHeightComposer(room, tiles).compose()); this.client.getHabbo().getHabboInfo().getCurrentRoom().sendComposer(new UpdateStackHeightTileHeightComposer(item, (int) ((height) * 100)).compose()); } } diff --git a/src/main/java/com/eu/habbo/messages/outgoing/rooms/UpdateStackHeightComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/rooms/UpdateStackHeightComposer.java index e43084b1..b01a6369 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/rooms/UpdateStackHeightComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/rooms/UpdateStackHeightComposer.java @@ -1,5 +1,6 @@ package com.eu.habbo.messages.outgoing.rooms; +import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomTile; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.outgoing.MessageComposer; @@ -12,6 +13,7 @@ public class UpdateStackHeightComposer extends MessageComposer { private double height; private THashSet updateTiles; + private Room room; public UpdateStackHeightComposer(int x, int y, double height) { this.x = x; @@ -19,24 +21,29 @@ public class UpdateStackHeightComposer extends MessageComposer { this.height = height; } - public UpdateStackHeightComposer(THashSet updateTiles) { + public UpdateStackHeightComposer(Room room, THashSet updateTiles) { this.updateTiles = updateTiles; + this.room = room; } @Override public ServerMessage compose() { - //TODO: THIS IS A TEMP FIX. THERE IS AN ISSUE WITH BAD PACKET STRUCTURE HERE CAUSING ISSUES WITH MOVING LARGE FURNITURE + //TODO: maybe do this another way? doesn't seem to be very clean but gets the job done this.response.init(Outgoing.UpdateStackHeightComposer); if (this.updateTiles != null) { - if(this.updateTiles.size() > 4) { + // prevent overflow. Byte max value is 127 + if(this.updateTiles.size() > 127) { RoomTile[] tiles = this.updateTiles.toArray(new RoomTile[updateTiles.size()]); - this.response.appendByte(4); - for(int i = 0; i < 4; i++) { + this.response.appendByte(127); + for(int i = 0; i < 127; i++) { RoomTile t = tiles[i]; + updateTiles.remove(t); // remove it from the set this.response.appendByte((int) t.x); this.response.appendByte((int) t.y); this.response.appendShort(t.relativeHeight()); } + //send the remaining tiles in a new message + this.room.sendComposer(new UpdateStackHeightComposer(this.room, updateTiles).compose()); return this.response; }