private int parseAttributesPack(ref Attribute[] attList, int maxGroups, ref byte[] data, int offset) { for (int i = 0; i < maxGroups; i++) { byte groupIndicator = BufferHandler.readByte(ref data, ref offset); int basePos = i * 7; //Output.WriteLine("Parsing group:"+i); //Output.WriteLine("Group indicator:"+(int)groupIndicator); for (int j = 0; j < 7; j++) { if ((groupIndicator & (1 << j)) == 1) // Attribute is being updated //Output.WriteLine("Updating: "+attList[basePos+j].getName()); { } else { //Output.WriteLine("Not Updating: "+attList[basePos+j].getName()); } } if (groupIndicator < 0x80) // More groups flag is OFF { break; } if (groupIndicator == 0x00) { break; } } return(offset); }
public int parseAutoView(ref byte[] buffer, int _offset) { int offset = _offset; byte subview = BufferHandler.readByte(ref buffer, ref offset); switch (subview) { case 0x01: //Self view Attributes only offset = parseAttributes(ref buffer, offset); break; case 0x02: offset = parseAttributes2(ref buffer, offset); break; default: //TODO: put something here break; } return(offset); }
private void parseRpc() { int length = BufferHandler.readByte(ref buffer, ref offset); if (length >= 0x80) //2 bytes as size { length = (length - 0x80) << 8; length = length + (int)BufferHandler.readByte(ref buffer, ref offset); } int header = BufferHandler.readByte(ref buffer, ref offset); length--; //discount 1 byte for the header if (header >= 0x80) //2 bytes as size { header = (header - 0x80) << 8; header = header + (int)BufferHandler.readByte(ref buffer, ref offset); length--; // discount another byte for the header (2nd byte) } byte[] rpcValues = BufferHandler.readBytes(ref buffer, ref offset, length); #if DEBUG Output.WriteLine("RPC (Header " + header + " | Content:" + StringUtils.bytesToString(rpcValues)); #endif rpcManager.HandleRpc(header, ref rpcValues); }
public int parse(int _offset, ref byte[] packetData) { offset = _offset; buffer = packetData; int viewId = (int)BufferHandler.readByte(ref packetData, ref offset); viewId += (int)(BufferHandler.readByte(ref packetData, ref offset) << 8); while (viewId != 0x00 && offset < packetData.Length) { if (viewId == 0x02) { Output.WriteLine("[MPM] Parsing selfview"); offset = Store.currentClient.playerInstance.parseAutoView(ref packetData, offset); } //Keep reading viewId = (int)BufferHandler.readByte(ref packetData, ref offset); // Prevent the crash issue if (offset < packetData.Length) { viewId += (int)(BufferHandler.readByte(ref packetData, ref offset) << 8); //Output.WriteLine("[MPM] Parsing view: " + viewId); } } return(offset); }
private void parseRpcBlock() { // Read current Client RPC Counter BufferHandler.readBytes(ref buffer, ref offset, 2); int rpcInside = (int)BufferHandler.readByte(ref buffer, ref offset); for (int i = 0; i < rpcInside; i++) { parseRpc(); } }
public int parse(int _offset, ref byte[] packetData) { buffer = packetData; offset = _offset; // See what we are dealing with: int rpcBlocks = (int)BufferHandler.readByte(ref buffer, ref offset); for (int i = 0; i < rpcBlocks; i++) { parseRpcBlock(); } return(offset); }
public int parseAttributes(ref byte[] buffer, int _offset) { int offset = _offset; byte flag = 0x00; flag = BufferHandler.readByte(ref buffer, ref offset); byte[] stateData = new byte[buffer.Length - offset + 2]; ArrayUtils.copy(buffer, offset - 2, stateData, 0, buffer.Length - offset + 2); //Flag Bits{0,0,0,0,Vector3f Position Update, Yaw Update,Animation Update, AttributesPacked Update?} switch (flag) { case 0x02: Action.setValue(BufferHandler.readBytes(ref buffer, ref offset, Action.getSize())); break; case 0x04: YawInterval.setValue(BufferHandler.readBytes(ref buffer, ref offset, YawInterval.getSize())); break; case 0x08: double x = (double)NumericalUtils.byteArrayToFloat(BufferHandler.readBytes(ref buffer, ref offset, 4), 1); double y = (double)NumericalUtils.byteArrayToFloat(BufferHandler.readBytes(ref buffer, ref offset, 4), 1); double z = (double)NumericalUtils.byteArrayToFloat(BufferHandler.readBytes(ref buffer, ref offset, 4), 1); Position.setValue(NumericalUtils.doublesToLtVector3d(x, y, z)); break; case 0x0e: // UInt16 unknown + LtVector3f UInt16 unknown = NumericalUtils.ByteArrayToUint16(BufferHandler.readBytes(ref buffer, ref offset, 2), 1); float xPos = NumericalUtils.byteArrayToFloat(BufferHandler.readBytes(ref buffer, ref offset, 4), 1); float yPos = NumericalUtils.byteArrayToFloat(BufferHandler.readBytes(ref buffer, ref offset, 4), 1); float zPos = NumericalUtils.byteArrayToFloat(BufferHandler.readBytes(ref buffer, ref offset, 4), 1); Position.setValue(NumericalUtils.doublesToLtVector3d((double)xPos, (double)yPos, (double)zPos)); break; } // TODO: update player attribute packets someday (announce it to my spawners) Store.world.sendViewPacketToAllPlayers(stateData, Store.currentClient.playerData.getCharID(), NumericalUtils.ByteArrayToUint16(Store.currentClient.playerInstance.GetGoid(), 1), Store.currentClient.playerData.getEntityId()); return(offset); }
public int parseAttributes2(ref byte[] buffer, int _offset) { int offset = _offset; byte flag = 0x00; flag = BufferHandler.readByte(ref buffer, ref offset); if ((flag & 0x60) != 0) { byte lastnameLength = BufferHandler.readByte(ref buffer, ref offset); RealLastName.setValue(BufferHandler.readBytes(ref buffer, ref offset, lastnameLength)); byte firstnameLength = BufferHandler.readByte(ref buffer, ref offset); RealFirstName.setValue(BufferHandler.readBytes(ref buffer, ref offset, firstnameLength)); //Store.currentClient.messageQueue.addObjectMessage(StringUtils.hexStringToBytes("0200028080808080101100")); } return(offset); }
private static void ParseContent(ref byte[] packetData) { buffer = null; buffer = packetData; offset = 0; //initialize to initial byte byte temp; temp = BufferHandler.readByte(ref packetData, ref offset); // Convert to Ack Flags BitArray AckFlags = NumericalUtils.byteToBitArray(temp); /* Flag Field * 1 - unknown / nothing * 2 - isAck (should always be ) * 3 - unknown currently * 4 - unknown currently * 5 - SERVERFLAGS_RESETRCC * 6 - CLIENTFLAGS_RESETDONE (so its done) * 7 - SERVERFLAG_SIMTIME (aka 0x82, 0xc2) */ if (AckFlags.Get(1) == false) { Output.WriteDebugLog("[WARNING] Packet has acked not set and is encrypted"); } if (AckFlags.Get(7) == true) { byte[] simTime = BufferHandler.readBytes(ref packetData, ref offset, 4); Store.currentClient.playerData.setClientSimTime(NumericalUtils.byteArrayToFloat(simTime, 1)); } if (AckFlags.Get(6) == true) { Output.WriteDebugLog("[CLIENT]CLIENTFLAGS_RESETDONE found - we can init new RCC Comm "); // Reset comm Store.currentClient.playerData.setCseq(0); Store.currentClient.playerData.setSseq(0); Store.currentClient.playerData.setPss(0x00); Store.currentClient.playerData.setOnWorld(false); Store.currentClient.playerData.setRPCShutDown(false); Store.currentClient.playerData.setRPCCounter(0); PlayerHandler handler = new PlayerHandler(); handler.processAttributes(); handler.processPlayerSetup(); } if (packetData.Length > 1 && AckFlags.Get(1) == true) //Not just ACK nor Resetting { if (packetData[offset] == 0x05) { offset = offset + 4; Output.writeToLogForConsole("Its a 05 Packet"); Store.currentClient.messageQueue.ackOnlyCount = Store.currentClient.messageQueue.ackOnlyCount + 1; Store.currentClient.flushQueue(); // We dont need a handler for 05 Packets (as there is only one as i see lol) } if (packetData[offset] == 0x03) // Is a 03 packet { offset++; offset = man03.parse(offset, ref buffer); } if (offset < packetData.Length) // There is no more info if we'r out of offset { if (packetData[offset] == 0x04) // Is a 04 packet { offset++; offset = man04.parse(offset, ref buffer); } } if (Store.currentClient.messageQueue.ObjectMessagesQueue.Count == 0 && Store.currentClient.messageQueue.RPCMessagesQueue.Count == 0) { // nothing to send ? we should really ack something then Store.currentClient.messageQueue.ackOnlyCount = Store.currentClient.messageQueue.ackOnlyCount + 1; Store.currentClient.flushQueue(); } } }
public int parseAttributes(ref byte[] buffer, int _offset) { _offset++; byte flag = 0x00; flag = BufferHandler.readByte(ref buffer, ref _offset); byte[] stateData = new byte[buffer.Length - _offset + 2]; ArrayUtils.copy(buffer, _offset - 2, stateData, 0, buffer.Length - _offset + 2); //Flag Bits{0,0,0,0,Vector3f Position Update, Yaw Update,Animation Update, AttributesPacked Update?} double x = 0; double y = 0; double z = 0; switch (flag) { case 0x02: Action.setValue(BufferHandler.readBytes(ref buffer, ref _offset, Action.getSize())); break; case 0x04: YawInterval.setValue(BufferHandler.readBytes(ref buffer, ref _offset, YawInterval.getSize())); break; case 0x08: x = (double)NumericalUtils.byteArrayToFloat(BufferHandler.readBytes(ref buffer, ref _offset, 4), 1); y = (double)NumericalUtils.byteArrayToFloat(BufferHandler.readBytes(ref buffer, ref _offset, 4), 1); z = (double)NumericalUtils.byteArrayToFloat(BufferHandler.readBytes(ref buffer, ref _offset, 4), 1); Position.setValue(NumericalUtils.doublesToLtVector3d(x, y, z)); break; case 0x0a: YawInterval.setValue(BufferHandler.readByte(ref buffer, ref _offset)); x = (double)NumericalUtils.byteArrayToFloat(BufferHandler.readBytes(ref buffer, ref _offset, 4), 1); y = (double)NumericalUtils.byteArrayToFloat(BufferHandler.readBytes(ref buffer, ref _offset, 4), 1); z = (double)NumericalUtils.byteArrayToFloat(BufferHandler.readBytes(ref buffer, ref _offset, 4), 1); Position.setValue(NumericalUtils.doublesToLtVector3d(x, y, z)); break; case 0x0e: // UInt16 unknown + LtVector3f UInt16 unknown = NumericalUtils.ByteArrayToUint16(BufferHandler.readBytes(ref buffer, ref _offset, 2), 1); x = NumericalUtils.byteArrayToFloat(BufferHandler.readBytes(ref buffer, ref _offset, 4), 1); y = NumericalUtils.byteArrayToFloat(BufferHandler.readBytes(ref buffer, ref _offset, 4), 1); z = NumericalUtils.byteArrayToFloat(BufferHandler.readBytes(ref buffer, ref _offset, 4), 1); Position.setValue(NumericalUtils.doublesToLtVector3d(x, y, z)); break; default: // ToDo: we need a proper way to proove if there is a 00 00 04 somewhere (and if set the offset to it) // If this doesnt match we need to write this somewhere... string message = "RPCMAIN : Unknown Client 03 Request Packet \r\n" + "Flag: " + flag + "\r\n " + "Content: \n" + StringUtils.bytesToString(stateData) + "\r\n"; Output.WriteClientViewRequestLog(message); // ...and we dont want to crash so we just say "offset is full packet" _offset = buffer.Length - 1; break; } // TODO: update player attribute packets someday (announce it to my spawners) Store.world.sendViewPacketToAllPlayers(stateData, Store.currentClient.playerData.getCharID(), NumericalUtils.ByteArrayToUint16(Store.currentClient.playerInstance.GetGoid(), 1), Store.currentClient.playerData.getEntityId()); return(_offset); }