diff options
author | Aaron Freytag <aaroncfreytag@gmail.com> | 2021-03-02 14:03:23 -0800 |
---|---|---|
committer | Aaron Freytag <aaroncfreytag@gmail.com> | 2021-03-02 14:03:23 -0800 |
commit | 47ec521bf0ed95c35eed36186904a6a00134986e (patch) | |
tree | fa30c43d01ee712e996b8ec908ed8285aa2b4754 /src | |
parent | 92b070df2c1e4876d6b18933e56659f99d741c9f (diff) | |
parent | c739e957e264e330a24e62af383e9f46623e13a5 (diff) |
Merge branch 'master' of https://github.com/Ajarmar/universal-pokemon-randomizer-zx into tm-tutor-follow-evolutions
Diffstat (limited to 'src')
3 files changed, 147 insertions, 2 deletions
diff --git a/src/com/dabomstew/pkrandom/config/gen6_offsets.ini b/src/com/dabomstew/pkrandom/config/gen6_offsets.ini index 24d9ef5..4dbf879 100644 --- a/src/com/dabomstew/pkrandom/config/gen6_offsets.ini +++ b/src/com/dabomstew/pkrandom/config/gen6_offsets.ini @@ -81,6 +81,7 @@ Acronym=OR PokemonStats=a/1/9/5 MoveData=a/1/8/9 WildPokemon=a/0/1/3 +PokedexAreaData=a/1/8/1 TextStringsJaKana=a/0/7/1 TextStringsJaKanji=a/0/7/2 TextStrings=a/0/7/3 diff --git a/src/com/dabomstew/pkrandom/constants/Gen6Constants.java b/src/com/dabomstew/pkrandom/constants/Gen6Constants.java index 0f9f178..c7a877b 100644 --- a/src/com/dabomstew/pkrandom/constants/Gen6Constants.java +++ b/src/com/dabomstew/pkrandom/constants/Gen6Constants.java @@ -219,7 +219,7 @@ public class Gen6Constants { rustlingBushEncounterOffset = 0xF40CC, rustlingBushEncounterCount = 7; public static final Map<Integer, String> fallingEncounterNameMap = constructFallingEncounterNameMap(); public static final Map<Integer, String> rustlingBushEncounterNameMap = constructRustlingBushEncounterNameMap(); - public static final int perPokemonAreaDataLengthXY = 0xE8; + public static final int perPokemonAreaDataLengthXY = 0xE8, perPokemonAreaDataLengthORAS = 0x2A0; private static final String saveLoadFormeReversionPrefixXY = "09EB000094E5141094E54A0B80E2", saveLoadFormeReversionPrefixORAS = "09EB000094E5141094E5120A80E2"; public static final String afterBattleFormeReversionPrefix = "E4FFFFEA0000000000000000"; @@ -1809,4 +1809,86 @@ public class Gen6Constants { 26, 26, 26, // Route 6 (rustling bush) 38, 38, 38, 38 // Route 18 (rustling bush) }; + + public static final int[] orasMapNumToPokedexIndex = { + 2, // Dewford Town + 6, // Pacifidlog Town + 7, // Petalburg City + 8, // Slateport City + 12, // Lilycove City + 13, // Mossdeep City + 14, // Sootopolis City + 15, // Ever Grande City + 17, // Route 101 + 18, // Route 102 + 19, // Route 103 + 20, // Route 104 (North Section) + 21, // Route 104 (South Section) + 22, // Route 105 + 23, // Route 106 + 24, // Route 107 + 26, // Route 108 + 27, // Route 109 + 28, // Route 110 + 30, // Route 111 (Desert) + 32, // Route 111 (South Section) + 33, // Route 112 (North Section) + 34, // Route 112 (South Section) + 35, // Route 113 + 36, // Route 114 + 37, // Route 115 + 38, // Route 116 + 39, // Route 117 + 40, // Route 118 + 41, 41, // Route 119 + 43, 43, // Route 120 + 45, // Route 121 + 46, // Route 122 + 47, // Route 123 + 48, // Route 124 + 50, // Route 125 + 51, // Route 126 + 53, // Route 127 + 55, // Route 128 + 57, // Route 129 + 59, // Route 130 + 61, // Route 131 + 62, // Route 132 + 63, // Route 133 + 64, // Route 134 + 25, // Route 107 (Underwater) + 49, // Route 124 (Underwater) + 52, // Route 126 (Underwater) + 56, // Route 128 (Underwater) + 58, // Route 129 (Underwater) + 60, // Route 130 (Underwater) + 69, 69, 69, 69, // Meteor Falls + 73, // Rusturf Tunnel + 74, 74, 74, // Granite Cave + 78, // Petalburg Woods + 80, // Jagged Pass + 81, // Fiery Path + 82, 82, 82, 82, 82, 82, // Mt. Pyre + -1, // Team Aqua Hideout + 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, // Seafloor Cavern + 102, 102, 102, 102, 102, // Cave of Origin + 114, 114, 114, 114, // Victory Road + 119, 119, 119, 119, 119, 119, 119, // Shoal Cave + 130, // New Mauville + 136, 136, 136, 136, // Sea Mauville + -1, // Sealed Chamber + -1, -1, -1, -1, // Scorched Slab + -1, // Team Magma Hideout + 150, // Sky Pillar + -1, -1, -1, -1, -1, -1, -1, -1, // Mirage Forest + -1, -1, -1, -1, -1, -1, -1, -1, // Mirage Island + -1, // Mirage Mountain + 159, // Battle Resort + 65, 65, 65, 65, // Safari Zone + 102, // Cave of Origin + -1, -1, -1, -1, -1, -1, -1, // Mirage Mountain + -1, -1, -1, -1, -1, -1, -1, -1, // Mirage Cave + -1, // Mt. Pyre (unused) + -1 // Sootopolis City (unused) + }; } diff --git a/src/com/dabomstew/pkrandom/romhandlers/Gen6RomHandler.java b/src/com/dabomstew/pkrandom/romhandlers/Gen6RomHandler.java index e0ddb0f..edb78cb 100644 --- a/src/com/dabomstew/pkrandom/romhandlers/Gen6RomHandler.java +++ b/src/com/dabomstew/pkrandom/romhandlers/Gen6RomHandler.java @@ -258,6 +258,14 @@ public class Gen6RomHandler extends Abstract3DSRomHandler { try { stringsGarc = readGARC(romEntry.getString("TextStrings"),true); + GARCArchive encounterGarc = readGARC(romEntry.getString("WildPokemon"), false); + byte[] boxLegendaryRoomData = encounterGarc.getFile(227); + AMX localScript = new AMX(boxLegendaryRoomData, 1); + byte[] data = localScript.decData; + File output = new File("C:\\Users\\Tom\\Desktop\\1.amx"); + try (FileOutputStream outputStream = new FileOutputStream(output)) { + outputStream.write(data); + } } catch (IOException e) { throw new RandomizerIOException(e); } @@ -1493,6 +1501,8 @@ public class Gen6RomHandler extends Abstract3DSRomHandler { // Save writeGARC(encountersFile, encounterGarc); + + this.updatePokedexAreaDataORAS(encounterGarc); } private void updatePokedexAreaDataXY(GARCArchive encounterGarc, byte[] fieldCRO) throws IOException { @@ -1566,13 +1576,65 @@ public class Gen6RomHandler extends Abstract3DSRomHandler { writeGARC(romEntry.getString("PokedexAreaData"), pokedexAreaGarc); } + private void updatePokedexAreaDataORAS(GARCArchive encounterGarc) throws IOException { + byte[] pokedexAreaData = new byte[(Gen6Constants.pokemonCount + 1) * Gen6Constants.perPokemonAreaDataLengthORAS]; + int currentMapNum = 0; + for (int i = 0; i < encounterGarc.files.size() - 2; i++) { + byte[] b = encounterGarc.files.get(i).get(0); + int offset = FileFunctions.readFullIntLittleEndian(b, 0x10) + 0xE; + int offset2 = FileFunctions.readFullIntLittleEndian(b, 0x14); + int length = offset2 - offset; + if (length < 0xF6) { // No encounters in this map + continue; + } + int areaIndex = Gen6Constants.orasMapNumToPokedexIndex[currentMapNum]; + if (areaIndex == -1) { // Current encounters are not taken into account for the Pokedex + currentMapNum++; + continue; + } + byte[] encounterData = new byte[0xF6]; + System.arraycopy(b, offset, encounterData, 0, 0xF6); + + EncounterSet grassEncounters = readEncounter(encounterData, 0, 12); + updatePokedexAreaDataFromEncounterSet(grassEncounters, pokedexAreaData, areaIndex, 0x1); + EncounterSet longGrassEncounters = readEncounter(encounterData, 48, 12); + updatePokedexAreaDataFromEncounterSet(longGrassEncounters, pokedexAreaData, areaIndex, 0x2); + int foreignEncounterType = grassEncounters.encounters.size() > 0 ? 0x04 : 0x08; + EncounterSet dexNavForeignEncounters = readEncounter(encounterData, 96, 3); + updatePokedexAreaDataFromEncounterSet(dexNavForeignEncounters, pokedexAreaData, areaIndex, foreignEncounterType); + EncounterSet surfEncounters = readEncounter(encounterData, 108, 5); + updatePokedexAreaDataFromEncounterSet(surfEncounters, pokedexAreaData, areaIndex, 0x10); + EncounterSet rockSmashEncounters = readEncounter(encounterData, 128, 5); + updatePokedexAreaDataFromEncounterSet(rockSmashEncounters, pokedexAreaData, areaIndex, 0x20); + EncounterSet oldRodEncounters = readEncounter(encounterData, 148, 3); + updatePokedexAreaDataFromEncounterSet(oldRodEncounters, pokedexAreaData, areaIndex, 0x40); + EncounterSet goodRodEncounters = readEncounter(encounterData, 160, 3); + updatePokedexAreaDataFromEncounterSet(goodRodEncounters, pokedexAreaData, areaIndex, 0x80); + EncounterSet superRodEncounters = readEncounter(encounterData, 172, 3); + updatePokedexAreaDataFromEncounterSet(superRodEncounters, pokedexAreaData, areaIndex, 0x100); + EncounterSet hordeCommonEncounters = readEncounter(encounterData, 184, 5); + updatePokedexAreaDataFromEncounterSet(hordeCommonEncounters, pokedexAreaData, areaIndex, 0x200); + EncounterSet hordeUncommonEncounters = readEncounter(encounterData, 204, 5); + updatePokedexAreaDataFromEncounterSet(hordeUncommonEncounters, pokedexAreaData, areaIndex, 0x200); + EncounterSet hordeRareEncounters = readEncounter(encounterData, 224, 5); + updatePokedexAreaDataFromEncounterSet(hordeRareEncounters, pokedexAreaData, areaIndex, 0x200); + currentMapNum++; + } + + GARCArchive pokedexAreaGarc = readGARC(romEntry.getString("PokedexAreaData"), true); + pokedexAreaGarc.setFile(0, pokedexAreaData); + writeGARC(romEntry.getString("PokedexAreaData"), pokedexAreaGarc); + } + private void updatePokedexAreaDataFromEncounterSet(EncounterSet es, byte[] pokedexAreaData, int areaIndex, int encounterType) { for (Encounter enc : es.encounters) { Pokemon pkmn = enc.pokemon; while (pkmn.baseForme != null) { // Failsafe if we need to write encounters without modifying species pkmn = pkmn.baseForme; } - int offset = pkmn.number * Gen6Constants.perPokemonAreaDataLengthXY + areaIndex * 4; + int perPokemonAreaDataLength = romEntry.romType == Gen6Constants.Type_XY ? + Gen6Constants.perPokemonAreaDataLengthXY : Gen6Constants.perPokemonAreaDataLengthORAS; + int offset = pkmn.number * perPokemonAreaDataLength + areaIndex * 4; int value = FileFunctions.readFullIntLittleEndian(pokedexAreaData, offset); value |= encounterType; FileFunctions.writeFullIntLittleEndian(pokedexAreaData, offset, value); |