diff options
author | tom-overton <tom.overton@outlook.com> | 2022-08-08 15:32:14 -0700 |
---|---|---|
committer | rafa_99 <raroma09@gmail.com> | 2022-09-03 13:39:52 +0100 |
commit | b798550825e998935da91c242acee373e7b6240f (patch) | |
tree | bae4dab379551c3b99f99bc50b7eeda7d2fe8efa /src/com/sneed/pkrandom/romhandlers | |
parent | 730711471fdaf344eed45de9a5eff60a52d3de1c (diff) |
Gen 6/7: Add support for Random Starter Held Item
Diffstat (limited to 'src/com/sneed/pkrandom/romhandlers')
-rw-r--r-- | src/com/sneed/pkrandom/romhandlers/Gen6RomHandler.java | 67 | ||||
-rw-r--r-- | src/com/sneed/pkrandom/romhandlers/Gen7RomHandler.java | 29 |
2 files changed, 77 insertions, 19 deletions
diff --git a/src/com/sneed/pkrandom/romhandlers/Gen6RomHandler.java b/src/com/sneed/pkrandom/romhandlers/Gen6RomHandler.java index 6a388bf..03ab7cc 100644 --- a/src/com/sneed/pkrandom/romhandlers/Gen6RomHandler.java +++ b/src/com/sneed/pkrandom/romhandlers/Gen6RomHandler.java @@ -1071,11 +1071,6 @@ public class Gen6RomHandler extends Abstract3DSRomHandler { se.pkmn = pokemon; se.forme = forme; se.level = staticCRO[offset+i*size + 5]; - int heldItem = FileFunctions.readFullInt(staticCRO,offset+i*size + 12); - if (heldItem < 0) { - heldItem = 0; - } - se.heldItem = heldItem; starters.add(se); } } catch (IOException e) { @@ -1123,11 +1118,6 @@ public class Gen6RomHandler extends Abstract3DSRomHandler { writeWord(staticCRO,offset+i*size,newStatic.pkmn.number); staticCRO[offset+i*size + 4] = (byte)newStatic.forme; // staticCRO[offset+i*size + 5] = (byte)newStatic.level; - if (newStatic.heldItem == 0) { - writeWord(staticCRO,offset+i*size + 12,-1); - } else { - writeWord(staticCRO,offset+i*size + 12,newStatic.heldItem); - } writeWord(displayCRO,displayOffset+displayIndex*0x54,newStatic.pkmn.number); displayCRO[displayOffset+displayIndex*0x54+2] = (byte)newStatic.forme; if (displayIndex < 3) { @@ -1171,13 +1161,60 @@ public class Gen6RomHandler extends Abstract3DSRomHandler { @Override public List<Integer> getStarterHeldItems() { - // do nothing - return new ArrayList<>(); + List<Integer> starterHeldItems = new ArrayList<>(); + try { + byte[] staticCRO = readFile(romEntry.getFile("StaticPokemon")); + + List<Integer> starterIndices = + Arrays.stream(romEntry.arrayEntries.get("StarterIndices")).boxed().collect(Collectors.toList()); + + // Gift Pokemon + int count = Gen6Constants.getGiftPokemonCount(romEntry.romType); + int size = Gen6Constants.getGiftPokemonSize(romEntry.romType); + int offset = romEntry.getInt("GiftPokemonOffset"); + for (int i = 0; i < count; i++) { + if (!starterIndices.contains(i)) continue; + int heldItem = FileFunctions.readFullInt(staticCRO,offset+i*size + 12); + if (heldItem < 0) { + heldItem = 0; + } + starterHeldItems.add(heldItem); + } + } catch (IOException e) { + throw new RandomizerIOException(e); + } + + return starterHeldItems; } @Override public void setStarterHeldItems(List<Integer> items) { - // do nothing + try { + byte[] staticCRO = readFile(romEntry.getFile("StaticPokemon")); + + List<Integer> starterIndices = + Arrays.stream(romEntry.arrayEntries.get("StarterIndices")).boxed().collect(Collectors.toList()); + + // Gift Pokemon + int count = Gen6Constants.getGiftPokemonCount(romEntry.romType); + int size = Gen6Constants.getGiftPokemonSize(romEntry.romType); + int offset = romEntry.getInt("GiftPokemonOffset"); + + Iterator<Integer> itemsIter = items.iterator(); + + for (int i = 0; i < count; i++) { + if (!starterIndices.contains(i)) continue; + int item = itemsIter.next(); + if (item == 0) { + FileFunctions.writeFullInt(staticCRO,offset+i*size + 12,-1); + } else { + FileFunctions.writeFullInt(staticCRO,offset+i*size + 12,item); + } + } + writeFile(romEntry.getFile("StaticPokemon"),staticCRO); + } catch (IOException e) { + throw new RandomizerIOException(e); + } } @Override @@ -2341,9 +2378,9 @@ public class Gen6RomHandler extends Abstract3DSRomHandler { staticCRO[offset+i*size + 4] = (byte)se.forme; staticCRO[offset+i*size + 5] = (byte)se.level; if (se.heldItem == 0) { - writeWord(staticCRO,offset+i*size + 12,-1); + FileFunctions.writeFullInt(staticCRO,offset+i*size + 12,-1); } else { - writeWord(staticCRO,offset+i*size + 12,se.heldItem); + FileFunctions.writeFullInt(staticCRO,offset+i*size + 12,se.heldItem); } } writeFile(romEntry.getFile("StaticPokemon"),staticCRO); diff --git a/src/com/sneed/pkrandom/romhandlers/Gen7RomHandler.java b/src/com/sneed/pkrandom/romhandlers/Gen7RomHandler.java index e99843c..c8a8457 100644 --- a/src/com/sneed/pkrandom/romhandlers/Gen7RomHandler.java +++ b/src/com/sneed/pkrandom/romhandlers/Gen7RomHandler.java @@ -1141,7 +1141,6 @@ public class Gen7RomHandler extends Abstract3DSRomHandler { se.pkmn = pokemon; se.forme = forme; se.level = giftsFile[offset + 3]; - se.heldItem = FileFunctions.read2ByteInt(giftsFile, offset + 8); starters.add(se); } } catch (IOException e) { @@ -1254,13 +1253,35 @@ public class Gen7RomHandler extends Abstract3DSRomHandler { @Override public List<Integer> getStarterHeldItems() { - // do nothing - return new ArrayList<>(); + List<Integer> starterHeldItems = new ArrayList<>(); + try { + GARCArchive staticGarc = readGARC(romEntry.getFile("StaticPokemon"), true); + byte[] giftsFile = staticGarc.files.get(0).get(0); + for (int i = 0; i < 3; i++) { + int offset = i * 0x14; + int item = FileFunctions.read2ByteInt(giftsFile, offset + 8); + starterHeldItems.add(item); + } + } catch (IOException e) { + throw new RandomizerIOException(e); + } + return starterHeldItems; } @Override public void setStarterHeldItems(List<Integer> items) { - // do nothing + try { + GARCArchive staticGarc = readGARC(romEntry.getFile("StaticPokemon"), true); + byte[] giftsFile = staticGarc.files.get(0).get(0); + for (int i = 0; i < 3; i++) { + int offset = i * 0x14; + int item = items.get(i); + FileFunctions.write2ByteInt(giftsFile, offset + 8, item); + } + writeGARC(romEntry.getFile("StaticPokemon"), staticGarc); + } catch (IOException e) { + throw new RandomizerIOException(e); + } } @Override |