Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.nio.file.Files;
- import java.nio.file.Path;
- import java.nio.file.Paths;
- import java.util.ArrayList;
- import java.util.List;
- public class ItemSet
- {
- private final static String MAPPING_FILE_NAME = "idmap.txt";
- private final static List<Integer> item_offsets = new ArrayList<>();
- private final static List<Integer> item_ids = new ArrayList<>();
- private final static List<String> item_names = new ArrayList<>();
- 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);
- }
- private static void read_mapping() throws IOException
- {
- final BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(MAPPING_FILE_NAME), "UTF-16"));
- String line = null;
- int line_num = 0;
- while((line = in.readLine()) != null)
- {
- line_num++;
- final String[] each_line = line.split("\\t");
- if(each_line.length != 3)
- {
- throw new RuntimeException("Mapping file line #" + line_num + " \"" + line + "\" is corrupted.\n");
- }
- item_offsets.add(Integer.parseInt(each_line[0], 16));
- item_ids.add(Integer.parseInt(each_line[1], 16));
- item_names.add(each_line[2]);
- }
- in.close();
- }
- public static void main(String[] args) throws IOException
- {
- if (args.length == 1)
- {
- read_mapping();
- System.out.print("Read mapping file \"" + MAPPING_FILE_NAME + "\". Records: "+ item_offsets.size() + ".\n");
- final byte[] buffer;
- final Path path = Paths.get(args[0]);
- final Path output = Paths.get(args[0] + ".hacked");
- buffer = Files.readAllBytes(path);
- System.out.print("Read save file \"" + args[0] + "\". Size: " + buffer.length + " bytes.\n");
- for(int i = 0; i < item_offsets.size(); i++)
- {
- write_uint16_le(buffer, item_offsets.get(i), item_ids.get(i));
- write_uint16_le(buffer, item_offsets.get(i) + 2, 999);
- System.out.print("Giving 999 " + item_names.get(i) + ". ID: 0x" +
- Integer.toHexString(item_ids.get(i)) +
- " Offset: 0x" + Integer.toHexString(item_offsets.get(i)) + "\n");
- }
- Files.write(output, buffer);
- System.out.print("Completed.\n");
- } else
- {
- System.err.println("Incorret arguments.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement