From 4849cb5479e12100b6b7830c36bfbcfdef39db3a Mon Sep 17 00:00:00 2001 From: sirjonasxx <36828922+sirjonasxx@users.noreply.github.com> Date: Tue, 29 Dec 2020 19:19:25 +0100 Subject: [PATCH] packets stuff --- .../proxy/unity/UnityCommunicator.java | 19 ++++++++++++++----- .../unity/UnityPacketHandler.java | 4 ++-- .../uilogger/UiLoggerController.java | 2 +- .../unity_tools/js_code/unity_code.js | 10 +++++----- 4 files changed, 22 insertions(+), 13 deletions(-) diff --git a/G-Earth/src/main/java/gearth/protocol/connection/proxy/unity/UnityCommunicator.java b/G-Earth/src/main/java/gearth/protocol/connection/proxy/unity/UnityCommunicator.java index 17af595..8ee90bf 100644 --- a/G-Earth/src/main/java/gearth/protocol/connection/proxy/unity/UnityCommunicator.java +++ b/G-Earth/src/main/java/gearth/protocol/connection/proxy/unity/UnityCommunicator.java @@ -35,11 +35,13 @@ public class UnityCommunicator { @OnOpen public void onOpen(Session session) throws IOException { - session.setMaxBinaryMessageBufferSize(1024 * 1024 * 100); + session.setMaxBinaryMessageBufferSize(1024 * 1024 * 10); } + private int lastType = 2; // 0 = incoming, 1 = outgoing, 2 = expect new + @OnMessage - public void onMessage(byte[] b, Session session) throws IOException { + public void onMessage(byte[] b, boolean isLast, Session session) throws IOException { if (allowedSession != null && !session.getId().equals(allowedSession)) { return; } @@ -47,10 +49,15 @@ public class UnityCommunicator { if (revision == null) { revision = new String(b, StandardCharsets.ISO_8859_1); allowedSession = session.getId(); + if (!isLast) { + System.out.println("this is bad"); + } return; } - byte[] packet = Arrays.copyOfRange(b, 1, b.length); + + + byte[] packet = lastType == 2 ? Arrays.copyOfRange(b, 1, b.length) : b; if (hProxy == null && b[0] == 1) { HPacket maybe = new HPacket(packet); @@ -67,11 +74,13 @@ public class UnityCommunicator { } - if (hProxy != null && b[0] == 0) { + if (hProxy != null && ((lastType == 2 && b[0] == 0) || lastType == 0)) { hProxy.getInHandler().act(packet); + lastType = isLast ? 2 : 0; } - else if (hProxy != null && b[0] == 1) { + else if (hProxy != null && ((lastType == 2 && b[0] == 1) || lastType == 1)) { hProxy.getOutHandler().act(packet); + lastType = isLast ? 2 : 1; } else { proxyProvider.abort(); diff --git a/G-Earth/src/main/java/gearth/protocol/packethandler/unity/UnityPacketHandler.java b/G-Earth/src/main/java/gearth/protocol/packethandler/unity/UnityPacketHandler.java index bc2383a..266fb80 100644 --- a/G-Earth/src/main/java/gearth/protocol/packethandler/unity/UnityPacketHandler.java +++ b/G-Earth/src/main/java/gearth/protocol/packethandler/unity/UnityPacketHandler.java @@ -25,12 +25,12 @@ public class UnityPacketHandler extends PacketHandler { @Override public void sendToStream(byte[] buffer) { -// synchronized (session) { + synchronized (session) { byte[] prefix = new byte[]{(direction == HMessage.Direction.TOCLIENT ? ((byte)0) : ((byte)1))}; byte[] combined = ByteArrayUtils.combineByteArrays(prefix, buffer); session.getAsyncRemote().sendBinary(ByteBuffer.wrap(combined)); -// } + } } @Override diff --git a/G-Earth/src/main/java/gearth/ui/logger/loggerdisplays/uilogger/UiLoggerController.java b/G-Earth/src/main/java/gearth/ui/logger/loggerdisplays/uilogger/UiLoggerController.java index 6f1ad87..d8d69b5 100644 --- a/G-Earth/src/main/java/gearth/ui/logger/loggerdisplays/uilogger/UiLoggerController.java +++ b/G-Earth/src/main/java/gearth/ui/logger/loggerdisplays/uilogger/UiLoggerController.java @@ -125,7 +125,7 @@ public class UiLoggerController implements Initializable { elements.add(new Element("]", "incoming")); elements.add(new Element(" <- ", "")); - if (skiphugepackets && packet.length() > 8000) { + if (skiphugepackets && packet.length() > 4000) { elements.add(new Element("", "skipped")); } else { diff --git a/G-Earth/src/main/resources/gearth/services/unity_tools/js_code/unity_code.js b/G-Earth/src/main/resources/gearth/services/unity_tools/js_code/unity_code.js index e47b2a6..b7a8e6e 100644 --- a/G-Earth/src/main/resources/gearth/services/unity_tools/js_code/unity_code.js +++ b/G-Earth/src/main/resources/gearth/services/unity_tools/js_code/unity_code.js @@ -87,6 +87,11 @@ let _g_packet_split = 600; function inject_out(packet) { + if (chachas.length > 1) { + packet[5] = _gearth_returnbyte_copy(chachas[0], packet[5], chachaClass); + packet[4] = _gearth_returnbyte_copy(chachas[0], packet[4], chachaClass); + } + let i = 0; while (i < packet.length) { let inject_amount = Math.min(_g_packet_split, packet.length - i); @@ -97,11 +102,6 @@ function inject_out(packet) { unityInstance.Module.HEAPU8.set(writeLittleEndian(inject_amount), packet_location + 12); unityInstance.Module.HEAPU8.set(packet.slice(i, i + inject_amount), packet_location + 16); - if (i === 0 && chachas.length > 1) { - unityInstance.Module.HEAPU8[packet_location + 16 + 5] = _gearth_returnbyte_copy(chachas[0], unityInstance.Module.HEAPU8[packet_location + 16 + 5], chachaClass); - unityInstance.Module.HEAPU8[packet_location + 16 + 4] = _gearth_returnbyte_copy(chachas[0], unityInstance.Module.HEAPU8[packet_location + 16 + 4], chachaClass); - } - _gearth_outgoing_copy(out_send_param1, packet_location, out_send_param3); _free(packet_location);