Advertisement
secXsQuared

JAVASTUFF

Oct 13th, 2016
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.15 KB | None | 0 0
  1. import java.io.IOException;
  2. import java.nio.file.Files;
  3. import java.nio.file.Path;
  4. import java.nio.file.Paths;
  5.  
  6. public class ItemSet
  7. {
  8.     private final static int FIRST_KEY_ITEM_ID = 1227;
  9.     private final static int OFFSET_ITEMS_END = 0x2EE7;
  10.     private final static int OFFSET_ITEMS_START = 0x10;
  11.     private final static int OFFSET_ITEMS_SIZE = 0x8;
  12.  
  13.  
  14.     private static int byte_to_uint(byte b)
  15.     {
  16.         return (int)(b) & 0xFF;
  17.     }
  18.  
  19.     private static int byte_to_uint16_le(byte[] ref, int offset)
  20.     {
  21.         if(ref.length < offset + 2)
  22.             throw new RuntimeException("Buffer overflowed - Offset " + offset);
  23.         return byte_to_uint(ref[offset]) | (byte_to_uint(ref[offset + 1]) << 8);
  24.     }
  25.  
  26.     private static void write_uint16_le(byte[] ref, int offset, int val)
  27.     {
  28.         if(ref.length < offset + 2)
  29.             throw new RuntimeException("Buffer overflowed - Offset " + offset);
  30.         ref[offset] = (byte)(val % 256);
  31.         ref[offset+1] = (byte)(val / 256);
  32.     }
  33.  
  34.     public static void main(String[] args) throws IOException
  35.     {
  36.         byte[] buffer;
  37.         if (args.length == 1)
  38.         {
  39.             final Path path = Paths.get(args[0]);
  40.             final Path output = Paths.get(args[0] + ".hacked");
  41.             buffer = Files.readAllBytes(path);
  42.             System.out.print("Read file size: " + buffer.length + " bytes.\n");
  43.  
  44.             for (int i = OFFSET_ITEMS_START; i < OFFSET_ITEMS_END; i += OFFSET_ITEMS_SIZE)
  45.             {
  46.                 final int item_id = byte_to_uint16_le(buffer, i);
  47.                 final int item_count = byte_to_uint16_le(buffer, i+2);
  48.  
  49.                 if (item_id == FIRST_KEY_ITEM_ID)
  50.                 {
  51.                     break;
  52.                 }
  53.                 if (item_id != 0)
  54.                 {
  55.                     System.out.print("Setting item id " + item_id + " from " + item_count + " to 999.\n");
  56.                     write_uint16_le(buffer, i+2, 999);
  57.                 }
  58.             }
  59.  
  60.             Files.write(output, buffer);
  61.         }
  62.         else
  63.         {
  64.             System.err.println("Incorret arguments.");
  65.         }
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement