# PokEditor-Core **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](https://github.com/turtleisaac/PokEditor), 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. ## Dependencies [Nds4j](https://github.com/turtleisaac/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=` pointing at your own **legally obtained** HeartGold and Platinum ROMs. ## Usage 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. ```java // create a NintendoDsRom object using something like NintendoDsRom.fromFile() 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: ```java byte[] file = rom.getFileByName(GameFiles.PERSONAL.getPath()); Narc personalNarc = new Narc(file); Map narcMap = new HashMap<>(); narcMap.put(GameFiles.PERSONAL, personalNarc); MainCodeFile arm9 = rom.loadArm9(); Map codeBinaries = Collections.singletonMap(GameCodeBinaries.ARM9, arm9); PersonalParser parser = new PersonalParser(); List 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); ``` ## Troubleshooting 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=`; 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.