Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int lastProcessedIndex;
- int accumulatedTimeOffset;
- int recordedMovements;
- int i;
- int rawY;
- int rawX;
- int deltaX;
- int deltaY;
- int timeDelta;
- synchronized (class399.mouseRecorder.lock) {
- if (!socketError) {
- class399.mouseRecorder.index = 0;
- } else if (MouseInput.mouseLastButton != 0 || class399.mouseRecorder.index >= 40) {
- mousePacket = null;
- packetStartOffset = 0;
- lastProcessedIndex = 0;
- accumulatedTimeOffset = 0;
- recordedMovements = 0;
- for (i = 0; i < class399.mouseRecorder.index && (mousePacket == null || mousePacket.packetBuffer.offset - packetStartOffset < 246); ++i) {
- lastProcessedIndex = i;
- rawY = class399.mouseRecorder.ys[i];
- if (rawY < -1) {
- rawY = -1;
- } else if (rawY > 65534) {
- rawY = 65534;
- }
- rawX = class399.mouseRecorder.xs[i];
- if (rawX < -1) {
- rawX = -1;
- } else if (rawX > 65534) {
- rawX = 65534;
- }
- if (lastX != rawX || lastY != rawY) {
- if (mousePacket == null) {
- mousePacket = class151.getTcpConnectionMessage_3250(ClientProt.MOUSE_MOVE, serverConnection.isaac);
- mousePacket.packetBuffer.putByte(0);
- packetStartOffset = mousePacket.packetBuffer.offset;
- mousePacket.packetBuffer.offset += 2;
- accumulatedTimeOffset = 0;
- recordedMovements = 0;
- }
- if (lastTimeStamp != -1L) {
- deltaX = rawX - lastX;
- deltaY = rawY - lastY;
- timeDelta = (int) ((class399.mouseRecorder.millis[i] - lastTimeStamp) / 20L);
- accumulatedTimeOffset = (int) ((class399.mouseRecorder.millis[i] - lastTimeStamp) % 20L + (long) accumulatedTimeOffset);
- } else {
- deltaX = rawX;
- deltaY = rawY;
- timeDelta = Integer.MAX_VALUE;
- }
- lastX = rawX;
- lastY = rawY;
- if (timeDelta < 8 && deltaX >= -32 && deltaX <= 31 && deltaY >= -32 && deltaY <= 31) {
- deltaX += 32;
- deltaY += 32;
- mousePacket.packetBuffer.putShort((deltaX << 6) + (timeDelta << 12) + deltaY);
- } else if (timeDelta < 32 && deltaX >= -128 && deltaX <= 127 && deltaY >= -128 && deltaY <= 127) {
- deltaX += 128;
- deltaY += 128;
- mousePacket.packetBuffer.putByte(timeDelta + 128);
- mousePacket.packetBuffer.putShort((deltaX << 8) + deltaY);
- } else if (timeDelta < 32) {
- mousePacket.packetBuffer.putByte(timeDelta + 192);
- if (rawX != -1 && rawY != -1) {
- mousePacket.packetBuffer.putInt(rawX | rawY << 16);
- } else {
- mousePacket.packetBuffer.putInt(Integer.MIN_VALUE);
- }
- } else {
- mousePacket.packetBuffer.putShort((timeDelta & 8191) + '\ue000');
- if (rawX != -1 && rawY != -1) {
- mousePacket.packetBuffer.putInt(rawX | rawY << 16);
- } else {
- mousePacket.packetBuffer.putInt(Integer.MIN_VALUE);
- }
- }
- ++recordedMovements;
- lastTimeStamp = class399.mouseRecorder.millis[i];
- }
- }
- if (mousePacket != null) {
- mousePacket.packetBuffer.putByteSize(mousePacket.packetBuffer.offset - packetStartOffset);
- i = mousePacket.packetBuffer.offset;
- mousePacket.packetBuffer.offset = packetStartOffset;
- mousePacket.packetBuffer.putByte(accumulatedTimeOffset / recordedMovements);
- mousePacket.packetBuffer.putByte(accumulatedTimeOffset % recordedMovements);
- mousePacket.packetBuffer.offset = i;
- serverConnection.write(mousePacket);
- }
- if (lastProcessedIndex >= class399.mouseRecorder.index) {
- class399.mouseRecorder.index = 0;
- } else {
- MouseRecorder recorder = class399.mouseRecorder;
- recorder.index -= lastProcessedIndex;
- System.arraycopy(class399.mouseRecorder.xs, lastProcessedIndex, class399.mouseRecorder.xs, 0, class399.mouseRecorder.index);
- System.arraycopy(class399.mouseRecorder.ys, lastProcessedIndex, class399.mouseRecorder.ys, 0, class399.mouseRecorder.index);
- System.arraycopy(class399.mouseRecorder.millis, lastProcessedIndex, class399.mouseRecorder.millis, 0, class399.mouseRecorder.index);
- }
- }
- }
Advertisement