Risiko94

Format.java

Oct 19th, 2021 (edited)
522
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package main;
  2.  
  3. import DataTypes.*;
  4.  
  5.  
  6. public final class Format {
  7.     public static boolean showDecompressinginfo;
  8.     public static boolean showServerdetails;
  9.     public static boolean showPlayers;
  10.     public static boolean showChat;
  11.     public static boolean showKills;
  12.     public static boolean showRevives;
  13.     public static boolean onlyDecompress;
  14.     public static boolean verbose;
  15.     public static boolean cleanverbose;
  16.  
  17.  
  18.     public static String automatic(Message message) {
  19.         if (cleanverbose) verbose = true;
  20.         switch (message.getType().getType()){
  21.  
  22.         case 0x00:
  23.             if(showServerdetails) return serverdetails(message) + "\n";
  24.             if (verbose) return message.toStringNoData() + "\n" + serverdetails(message) + "\n";
  25.             return "";
  26.  
  27.         case 0x50:
  28.             if (showKills) return kill(message) + "\n";
  29.             if (verbose) return message.toStringNoData() + "\n" + kill(message) + "\n";
  30.             return "";
  31.         case (byte) 0xA0:
  32.             if (showRevives) return revive(message) + "\n";
  33.         if (verbose) return message.toStringNoData() + "\n" + revive(message) + "\n";
  34.         return "";
  35.  
  36.  
  37.         case 0x51:
  38.             if(showChat) return chat(message) + "\n";
  39.             if (verbose) return message.toStringNoData() + "\n" + chat(message) + "\n";
  40.             return "";
  41.  
  42.         case 0x11:
  43.             if (showPlayers)return player_add(message);
  44.             if (verbose) return message.toStringNoData() + "\n" + player_add(message) + "\n";
  45.             player_add(message);    //needs to happen to properly add a player to the playerlist
  46.             return "";         
  47.         case 0x12:
  48.             if (showPlayers) return player_remove(message) + "\n";
  49.             if (verbose) return message.toStringNoData() + "\n" + player_remove(message) + "\n";
  50.             player_remove(message);     //needs to happen to properly remove a player from the playerlist
  51.             return "";
  52.  
  53.         case 0x10:  //tick
  54.             if (cleanverbose) return "";
  55.             //$FALL-THROUGH$
  56.         case (byte) 0xF1:   //playerupdate
  57.             if (cleanverbose) return "";
  58.         //$FALL-THROUGH$
  59.         case 0x20:  //vehicleupdate
  60.             if (cleanverbose) return "";
  61.             //$FALL-THROUGH$
  62.         case (byte) 0x90:   //PROJECTILE_UPDATE
  63.             if (cleanverbose) return "";
  64.         //$FALL-THROUGH$
  65.         case (byte) 0x91:   //PROJECTILE_ADD
  66.             if (cleanverbose) return "";
  67.         //$FALL-THROUGH$
  68.         case (byte) 0x92:   //PROJECTILE_REMOVE
  69.             if (cleanverbose) return "";
  70.         //$FALL-THROUGH$
  71.  
  72.         default:
  73.             if(verbose)return message.toString() + "\n";
  74.             return "";
  75.         }
  76.     }
  77.  
  78.  
  79.  
  80.     //MESSAGETYPE_SERVERDETAILS 0x00
  81.     public static String serverdetails (Message message) {
  82.         byte[] data = message.getData();
  83.         String output = "";
  84.         int i;
  85.         output += ("Version: " + DemoUtils.ByteToInt(data, 0));
  86.         output += (" TimePerTick: " + DemoUtils.ByteToFloat(data, 4));
  87.         output += (" IP: " + new String(DemoUtils.getBytesBeforeZeroByte(data, 8)));
  88.         i = DemoUtils.findZeroByte(data, 8) + 1;
  89.         output += (" Servername: " + new String (DemoUtils.getBytesBeforeZeroByte(data, i)));
  90.         i = DemoUtils.findZeroByte(data, i) + 1;
  91.         output += (" MaxPlayers: " + data[i]);
  92.         i++;
  93.         output += (" Roundlength: " + (DemoUtils.ByteToShort(data[i], data[i+1])/60) + "min");
  94.         i +=2;
  95.         output += (" Briefingtime: " + (DemoUtils.ByteToShort(data[i], data[i+1])/60) + "min");
  96.         i +=2;
  97.         output += (" Mapname: " + new String(DemoUtils.getBytesBeforeZeroByte(data, i)));
  98.         i = DemoUtils.findZeroByte(data, i) + 1;
  99.         output += (" Gamemmode: " + new String(DemoUtils.getBytesBeforeZeroByte(data, i)));
  100.         i = DemoUtils.findZeroByte(data, i) + 1;
  101.         output += (" Maplayer: ");
  102.         switch (data[i] & 0xFF) {
  103.         case 16: output += "inf"; break;
  104.         case 32: output += "alt"; break;
  105.         case 64: output += "std"; break;
  106.         case 128: output += "lrg"; break;
  107.         default: output += "ERROR: UNRECOGNIZED GAMEMODE ID";
  108.         }
  109.         i++;
  110.         output += (" Opfor: " + new String(DemoUtils.getBytesBeforeZeroByte(data, i)));
  111.         i = DemoUtils.findZeroByte(data, i) + 1;
  112.         output += (" Blufor: " + new String(DemoUtils.getBytesBeforeZeroByte(data, i)));
  113.         i = DemoUtils.findZeroByte(data, i) + 1;
  114.         /*
  115.          * TO DO: Need to convert epoch into human readable time
  116.          */
  117.         output += (" Gamestart(epoch): " + DemoUtils.ByteToInt(data, i));
  118.         i +=4;
  119.         output += (" OpforTickets: " + DemoUtils.ByteToShort(data[i], data[i+1]));
  120.         i +=2;
  121.         output += (" BluforTickets: " + DemoUtils.ByteToShort(data[i], data[i+1]));
  122.         i +=2;
  123.         output += (" Mapsize: " + DemoUtils.ByteToFloat(data, i));
  124.         return output;
  125.     }
  126.  
  127.     //MESSAGETYPE_PLAYER_ADD 0x11
  128.     public static String player_add (Message message) {
  129.         byte[] data = message.getData();
  130.         String output = "";
  131.         Player player;
  132.         byte id;
  133.         String clantag;
  134.         String name;
  135.         String hash;
  136.         String ip;
  137.         //Format is
  138.         //id ZEROBYTE clantag SPACE name ZEROBYTE hash ZEROBYTE ip ZEROBYTE
  139.         //clantag can be nonexistant, ip is always nonexistant and hash is nonexistant for bots
  140.         //spaces and zerobytes will exist regardles
  141.         //zerobyte is 0x00, space is 0x20
  142.         //Playeradd has atleast 1 player, maybe more.
  143.         for (int counter = 0;counter < data.length;counter++) {
  144.             id = data[counter++];          
  145.  
  146.             clantag = new String (DemoUtils.getBytes(data, counter, (byte) 0x20));
  147.             counter = DemoUtils.findByte(data, counter, (byte) 0x20) +1;
  148.  
  149.             name = DemoUtils.getStringBeforeZeroByte(data, counter);
  150.             counter = DemoUtils.findZeroByte(data, counter) + 1;
  151.  
  152.             hash = DemoUtils.getStringBeforeZeroByte(data, counter);
  153.             counter = DemoUtils.findZeroByte(data, counter) + 1;
  154.  
  155.             ip = DemoUtils.getStringBeforeZeroByte(data, counter);
  156.  
  157.             player = new Player(id,clantag, name, hash, ip);
  158.             Playerlist.playerlist.add(player);
  159.  
  160.             output += ("Player joined: " + player + "\n");
  161.         }
  162.         return output;
  163.     }
  164.  
  165.     //MESSAGETYPE_PLAYER_REMOVE 0x12
  166.     //this is always just a single player, unlike PLAYER_ADD
  167.     public static String player_remove (Message message) { 
  168.         byte[] data = message.getData();
  169.         String output = "";
  170.         output += ("Player left: " + Playerlist.removeId(data[0]));
  171.         return output;
  172.     }
  173.  
  174.     //MESSAGETYPE_KILL 0x50
  175.     public static String kill (Message message) {  
  176.         byte[] data = message.getData();
  177.         String output = "";
  178.         output += Playerlist.getPlayerFromId(data[0]).getClanAndName()
  179.                 + " killed "
  180.                 + Playerlist.getPlayerFromId(data[1]).getClanAndName()
  181.                 + " with "
  182.                 + new String(DemoUtils.getBytesBeforeZeroByte(data, 2));
  183.         return output;
  184.     }
  185.     //MESSAGETYPE_REVIVE 0xA0
  186.     public static String revive (Message message) {
  187.         byte[] data = message.getData();
  188.         String output = "";
  189.         output += Playerlist.getPlayerFromId(data[0]).getClanAndName()
  190.                 + " revived "
  191.                 + Playerlist.getPlayerFromId(data[1]).getClanAndName();
  192.         return output;
  193.     }
  194.  
  195.     //MESSAGETYPE_CHAT 0x51
  196.     public static String chat(Message message) {
  197.         byte[] data = message.getData();
  198.         String output = "";
  199.         output += (Playerlist.getPlayerFromId(data[1]).getClanAndName() + " (Channel: " + DemoUtils.ByteToLongHex(data[0]) + "): " + new String(data, 2,data.length-3));
  200.         return output;
  201.     }
  202. }
  203.  
  204.  
  205.  
  206.  
  207.  
  208.  
RAW Paste Data