Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.IOException;
- import java.nio.file.Files;
- import java.nio.file.Path;
- import java.nio.file.Paths;
- public class ItemSet
- {
- private final static int FIRST_KEY_ITEM_ID = 1227;
- private final static int OFFSET_ITEMS_END = 0x2EE7;
- private final static int OFFSET_ITEMS_START = 0x10;
- private final static int OFFSET_ITEMS_SIZE = 0x8;
- private static int byte_to_uint(byte b)
- {
- return (int)(b) & 0xFF;
- }
- private static int byte_to_uint16_le(byte[] ref, int offset)
- {
- if(ref.length < offset + 2)
- throw new RuntimeException("Buffer overflowed - Offset " + offset);
- return byte_to_uint(ref[offset]) | (byte_to_uint(ref[offset + 1]) << 8);
- }
- private static void write_uint16_le(byte[] ref, int offset, int val)
- {
- if(ref.length < offset + 2)
- throw new RuntimeException("Buffer overflowed - Offset " + offset);
- ref[offset] = (byte)(val % 256);
- ref[offset+1] = (byte)(val / 256);
- }
- public static void main(String[] args) throws IOException
- {
- byte[] buffer;
- if (args.length == 1)
- {
- final Path path = Paths.get(args[0]);
- final Path output = Paths.get(args[0] + ".hacked");
- buffer = Files.readAllBytes(path);
- System.out.print("Read file size: " + buffer.length + " bytes.\n");
- for (int i = OFFSET_ITEMS_START; i < OFFSET_ITEMS_END; i += OFFSET_ITEMS_SIZE)
- {
- final int item_id = byte_to_uint16_le(buffer, i);
- final int item_count = byte_to_uint16_le(buffer, i+2);
- if (item_id == FIRST_KEY_ITEM_ID)
- {
- break;
- }
- if (item_id != 0)
- {
- System.out.print("Setting item id " + item_id + " from " + item_count + " to 999.\n");
- write_uint16_le(buffer, i+2, 999);
- }
- }
- Files.write(output, buffer);
- }
- else
- {
- System.err.println("Incorret arguments.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement