public void parse() { String fileName = "npcinfo_" + sessionName + ".txt"; try { BufferedWriter out = new BufferedWriter(new FileWriter(fileName)); for (DataPacket packet : packets) { String name = packet.getName(); if ("SM_NPC_INFO".equals(name)) { List<ValuePart> valuePartList = packet.getValuePartList(); NpcInfo npc = new NpcInfo(); for (ValuePart valuePart : valuePartList) { String partName = valuePart.getModelPart().getName(); if ("npcId".equals(partName)) { npc.npcId = Integer.parseInt(valuePart.readValue()); } else if ("titleId".equals(partName)) { npc.titleId = Integer.parseInt(valuePart.readValue()); } else if ("nameId".equals(partName)) { npc.nameId = Integer.parseInt(valuePart.readValue()); } else if ("npcMaxHP".equals(partName)) { npc.npcMaxHp = Integer.parseInt(valuePart.readValue()); } else if ("npclevel".equals(partName)) { npc.npcLevel = Byte.parseByte(valuePart.readValue()); } else if ("npcTemplateHeight".equals(partName)) { npc.npcTemplateHeight = Float.parseFloat(valuePart.readValue()); } } npcInfoList.add(npc); } } out.write("npcId\ttitleId\tnameId\tnpcMaxHp\tnpcLevel\tnpcTemplateHeight\n"); for (NpcInfo npc : npcInfoList) { StringBuilder sb = new StringBuilder(); sb.append(npc.npcId); sb.append("\t"); sb.append(npc.titleId); sb.append("\t"); sb.append(npc.nameId); sb.append("\t"); sb.append(npc.npcMaxHp); sb.append("\t"); sb.append(npc.npcLevel); sb.append("\t"); sb.append(npc.npcTemplateHeight); sb.append("\t"); sb.append("\n"); out.write(sb.toString()); } out.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } PacketSamurai.getUserInterface().log("The npc infos have been written"); }
public void updateCurrentPacket(boolean forced) { if (!forced && _currentSelectedPacket == _packetTable.getSelectedRow()) return; /*try { DataStructure gp = _gameSessionViewer.getPacket(_currentSelectedPacket); if(gp!= null) gp.setViewed(false); } catch (IndexOutOfBoundsException e) { }*/ _currentSelectedPacket = _packetTable.getSelectedRow(); // reset the selected part as we selected another packet _currentSelectedPart = null; DataPacket gp = _gameSessionViewer.getPacket(_currentSelectedPacket); // gp.setViewed(true); // System.out.println("Selected row/packet: "+_table.getSelectedRow()); _hexDumpArea.setText(""); if (gp.getPacketFormat() != null && gp.isValid()) { _packetFormat.setText(gp.getPacketFormat().getPartsStr()); // colorfull hex dump :P // opcode if (gp.getPacketId() != null) { for (IdPart part : gp.getPacketId().getParts()) { int bytes = part.getType().getTypeByteNumber(); for (int i2 = 0; i2 < bytes; i2++) { addStyledText( Util.zeropad(Long.toHexString(part.getValue() << (8 * i2) & 0xff), 2).toUpperCase(), "op"); if (i2 < bytes - 1) addStyledText(" ", "op"); } addStyledText(" ", "base"); } } // chksum if (gp.getProtocol().getChecksumSize() > 0) { int size = gp.getProtocol().getChecksumSize(); for (int i = 1; i < size + 1; i++) { addStyledText( Util.zeropad(Integer.toHexString(gp.getIdData()[i] & 0xff), 2).toUpperCase(), "chk"); if (i < size) addStyledText(" ", "chk"); } addStyledText(" ", "base"); } // parsed packet parts for (ValuePart part : gp.getValuePartList()) { addStyledText(Util.rawHexDump(part.getBytes()), part.getType().getName(), true); addStyledText(" ", "base"); } // unparsed data (if any) addStyledText(Util.rawHexDump(gp.getUnparsedData()), "base"); this.addLineBreaksToHexDump(gp.getIdData(), gp.getByteBuffer().array()); int opSize = 0; for (PartType pt : gp.getPacketFormat().getIdParts()) { opSize += pt.getTypeByteNumber() * 3; } DataPartNode root = new DataPartNode(gp.getRootNode(), opSize + gp.getProtocol().getChecksumSize() * 3); _packetViewTableModel.setRoot(root); _packetViewTable.revalidate(); _packetViewTable.expandAll(); } else { // clear the format _packetFormat.setText(""); // dump everything _hexDumpArea.setText(""); // if we know the opcode but the format was invalid still show the opcode if (gp.getFormat() != null) { for (IdPart part : gp.getPacketId().getParts()) { int bytes = part.getType().getTypeByteNumber(); for (int i2 = 0; i2 < bytes; i2++) { addStyledText( Util.zeropad(Long.toHexString(part.getValue() << (8 * i2) & 0xff), 2).toUpperCase(), "op"); if (i2 < bytes - 1) addStyledText(" ", "op"); } addStyledText(" ", "base"); } } ViewPane.this.addStyledText(Util.rawHexDump(gp.getData()), "base"); this.addLineBreaksToHexDump(gp.getIdData(), gp.getByteBuffer().array()); // no part for u _packetViewTableModel.setRoot(null); } }