Author: Turtleisaac
This library provides functionality for reading and writing various forms of game data for the Gen 4 Pokémon games and serves as the backend for PokEditor v3, my Gen 4 hacking tool.
Feel free to use this library for your own projects relating to the Gen 4 Pokémon games, given that you provide credit to me.
Nds4j, my library for interacting with, reading, editing, and writing the general proprietary Nintendo DS file formats, is required.
PokEditor-Core builds without a ROM. Some tests exercise round-tripping against real game data and are skipped when none is available; to run them, pass -Drom.dir=<directory> pointing at your own legally obtained HeartGold and Platinum ROMs.
As this is a library, there is nothing for you to run in terms of a JAR file or Main method. You need to write all the code to make use of my library yourself.
When you go to use PokEditor-Core, the first thing your program needs to do is define which game you are using, so it knows which set of file paths it needs to use.
// create a NintendoDsRom object using something like NintendoDsRom.fromFile(<path to rom>)
NintendoDsRom rom = NintendoDsRom.fromFile("path to rom");
// parseBaseRom returns the game together with its region, rather than storing the
// region on the Game enum constant where every ROM in the process would share it
Game.BaseRomInfo baseRomInfo = Game.parseBaseRom(rom.getGameCode());
Game game = baseRomInfo.game();
GameFiles.initialize(game);
TextFiles.initialize(game);
GameCodeBinaries.initialize(game);
Tables.initialize(game, baseRomInfo.region());Once you have ran the four initialize methods, your code can make use of the library without much further pain. Here is an example which works with species personal data:
byte[] file = rom.getFileByName(GameFiles.PERSONAL.getPath());
Narc personalNarc = new Narc(file);
Map<GameFiles, Narc> narcMap = new HashMap<>();
narcMap.put(GameFiles.PERSONAL, personalNarc);
MainCodeFile arm9 = rom.loadArm9();
Map<GameCodeBinaries, CodeBinary> codeBinaries = Collections.singletonMap(GameCodeBinaries.ARM9, arm9);
PersonalParser parser = new PersonalParser();
List<PersonalData> data = parser.generateDataList(narcMap, codeBinaries);
PersonalData turtwig = data.get(493);
turtwig.setAtk(255); // turtwig will now have a base attack stat of 255
narcMap = parser.processDataList(data, codeBinaries);
personalNarc = narcMap.get(GameFiles.PERSONAL);
rom.setFileByName(GameFiles.PERSONAL.getPath(), personalNarc.save());
// save the modified ROM to disk
rom.saveToFile("output rom path", false);PokEditor-Core builds and its test suite passes without any ROM present — the tests that need one are skipped rather than failed. To run those too, point the build at a directory holding your own legally obtained ROMs with -Drom.dir=<directory>; the file names default to HeartGold.nds and Platinum.nds and can be overridden with -Drom.heartgold and -Drom.platinum.
Additionally, there are some sources which need to be generated by maven/antlr4 which don't always get generated and compiled for some reason, so try running mvn generate-sources in the terminal/command-line from within the repo root to get those to appear.
You may need to mark the directory src/main/generated-sources as a generated sources root afterwards.