Advertisement
secXsQuared

Java All Items

Oct 15th, 2016
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.10 KB | None | 0 0
  1. import java.io.*;
  2. import java.nio.file.Files;
  3. import java.nio.file.Path;
  4. import java.nio.file.Paths;
  5. import java.util.ArrayList;
  6. import java.util.List;
  7.  
  8. public class ItemSet
  9. {
  10.     private final static String MAPPING_FILE_NAME = "idmap.txt";
  11.     private final static List<Integer> item_offsets = new ArrayList<>();
  12.     private final static List<Integer> item_ids = new ArrayList<>();
  13.     private final static List<String> item_names = new ArrayList<>();
  14.  
  15.     private static int byte_to_uint(byte b)
  16.     {
  17.         return (int) (b) & 0xFF;
  18.     }
  19.  
  20.     private static int byte_to_uint16_le(byte[] ref, int offset)
  21.     {
  22.         if (ref.length < offset + 2)
  23.             throw new RuntimeException("Buffer overflowed - Offset " + offset);
  24.         return byte_to_uint(ref[offset]) | (byte_to_uint(ref[offset + 1]) << 8);
  25.     }
  26.  
  27.     private static void write_uint16_le(byte[] ref, int offset, int val)
  28.     {
  29.         if (ref.length < offset + 2)
  30.             throw new RuntimeException("Buffer overflowed - Offset " + offset);
  31.         ref[offset] = (byte) (val % 256);
  32.         ref[offset + 1] = (byte) (val / 256);
  33.     }
  34.  
  35.     private static void read_mapping() throws IOException
  36.     {
  37.         final BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(MAPPING_FILE_NAME), "UTF-16"));
  38.         String line = null;
  39.         int line_num = 0;
  40.         while((line = in.readLine()) != null)
  41.         {
  42.             line_num++;
  43.             final String[] each_line = line.split("\\t");
  44.             if(each_line.length != 3)
  45.             {
  46.                 throw new RuntimeException("Mapping file line #" + line_num + " \"" + line + "\" is corrupted.\n");
  47.             }
  48.             item_offsets.add(Integer.parseInt(each_line[0], 16));
  49.             item_ids.add(Integer.parseInt(each_line[1], 16));
  50.             item_names.add(each_line[2]);
  51.         }
  52.         in.close();
  53.     }
  54.  
  55.     public static void main(String[] args) throws IOException
  56.     {
  57.         if (args.length == 1)
  58.         {
  59.             read_mapping();
  60.             System.out.print("Read mapping file \"" + MAPPING_FILE_NAME + "\". Records: "+ item_offsets.size() + ".\n");
  61.             final byte[] buffer;
  62.             final Path path = Paths.get(args[0]);
  63.             final Path output = Paths.get(args[0] + ".hacked");
  64.  
  65.             buffer = Files.readAllBytes(path);
  66.             System.out.print("Read save file \"" + args[0] + "\". Size: " + buffer.length + " bytes.\n");
  67.             for(int i = 0; i < item_offsets.size(); i++)
  68.             {
  69.                 write_uint16_le(buffer, item_offsets.get(i), item_ids.get(i));
  70.                 write_uint16_le(buffer, item_offsets.get(i) + 2, 999);
  71.                 System.out.print("Giving 999 " + item_names.get(i) + ". ID: 0x" +
  72.                         Integer.toHexString(item_ids.get(i)) +
  73.                         " Offset: 0x" + Integer.toHexString(item_offsets.get(i)) + "\n");
  74.             }
  75.             Files.write(output, buffer);
  76.             System.out.print("Completed.\n");
  77.         } else
  78.         {
  79.             System.err.println("Incorret arguments.");
  80.         }
  81.     }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement