summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortom-overton <tom.overton@outlook.com>2022-05-28 18:00:03 -0700
committerrafa_99 <raroma09@gmail.com>2022-05-29 22:01:48 +0100
commit520bc996f2286a1cc5f2eea2f8f0e98da2de057b (patch)
tree06be5348f5962975585392dab8d60f1a12668e19 /src
parente3b45c8a01a3c09a5c2dd5c0e08d7065512a0510 (diff)
BW2: Add support for reading/writing PWT trainer names/classes
Diffstat (limited to 'src')
-rwxr-xr-xsrc/com/sneed/pkrandom/config/gen5_offsets.ini4
-rw-r--r--src/com/sneed/pkrandom/constants/Gen5Constants.java5
-rwxr-xr-xsrc/com/sneed/pkrandom/romhandlers/Gen5RomHandler.java54
3 files changed, 55 insertions, 8 deletions
diff --git a/src/com/sneed/pkrandom/config/gen5_offsets.ini b/src/com/sneed/pkrandom/config/gen5_offsets.ini
index 5574c4b..246aba5 100755
--- a/src/com/sneed/pkrandom/config/gen5_offsets.ini
+++ b/src/com/sneed/pkrandom/config/gen5_offsets.ini
@@ -215,9 +215,11 @@ StarterCryTablePrefix=080A070000080000
PokedexGivenFileOffset=854
MoveTutorDataOffset=0x51538
PokemonNamesTextOffset=90
+TrainerMugshotsTextOffset=368
TrainerNamesTextOffset=382
TrainerClassesTextOffset=383
-TrainerMugshotsTextOffset=368
+PWTTrainerNamesTextOffset=409
+PWTTrainerClassesTextOffset=410
EliteFourIndices=[38, 39, 40, 41, 341]
ChallengeModeEliteFourIndices=[772,773,774,775,776]
MoveDescriptionsTextOffset=402
diff --git a/src/com/sneed/pkrandom/constants/Gen5Constants.java b/src/com/sneed/pkrandom/constants/Gen5Constants.java
index e7630e4..2af3df5 100644
--- a/src/com/sneed/pkrandom/constants/Gen5Constants.java
+++ b/src/com/sneed/pkrandom/constants/Gen5Constants.java
@@ -258,6 +258,11 @@ public class Gen5Constants {
766, 767, 768, 769, 770, 771, 772, 773, 774, 775, 776, 786, 787, 788,
789, 797, 798, 799, 800, 801, 802, 803, 804, 805, 806,
807, 808, 809, 810, 811, 812);
+
+ public static final List<Integer> bw2DriftveilTrainerOffsets = Arrays.asList(56, 57, 0, 1, 2, 3, 4, 68, 69, 70,
+ 71, 72, 73, 74, 75, 76, 77);
+
+ public static final int normalTrainerNameLength = 813, normalTrainerClassLength = 236;
// public static final Map<Integer, String> bw1ShopIndex = new HashMap<Integer, String>() {1:"Check"};
diff --git a/src/com/sneed/pkrandom/romhandlers/Gen5RomHandler.java b/src/com/sneed/pkrandom/romhandlers/Gen5RomHandler.java
index c08700b..6c86e30 100755
--- a/src/com/sneed/pkrandom/romhandlers/Gen5RomHandler.java
+++ b/src/com/sneed/pkrandom/romhandlers/Gen5RomHandler.java
@@ -1466,7 +1466,8 @@ public class Gen5RomHandler extends AbstractDSRomHandler {
for (int trno = 0; trno < 17; trno++) {
Trainer tr = new Trainer();
tr.poketype = 3; // have held items and custom moves
- tr.offset = 0;
+ int nameAndClassIndex = Gen5Constants.bw2DriftveilTrainerOffsets.get(trno);
+ tr.fullDisplayName = tclasses.get(Gen5Constants.normalTrainerClassLength + nameAndClassIndex) + " " + tnames.get(Gen5Constants.normalTrainerNameLength + nameAndClassIndex);
int pokemonNum = 6;
if (trno < 2) {
pokemonNum = 3;
@@ -3280,6 +3281,10 @@ public class Gen5RomHandler extends AbstractDSRomHandler {
public List<String> getTrainerNames() {
List<String> tnames = getStrings(false, romEntry.getInt("TrainerNamesTextOffset"));
tnames.remove(0); // blank one
+ if (romEntry.romType == Gen5Constants.Type_BW2) {
+ List<String> pwtNames = getStrings(false, romEntry.getInt("PWTTrainerNamesTextOffset"));
+ tnames.addAll(pwtNames);
+ }
// Tack the mugshot names on the end
List<String> mnames = getStrings(false, romEntry.getInt("TrainerMugshotsTextOffset"));
for (String mname : mnames) {
@@ -3314,10 +3319,25 @@ public class Gen5RomHandler extends AbstractDSRomHandler {
setStrings(false, romEntry.getInt("TrainerMugshotsTextOffset"), mnames);
// Now save the rest of trainer names
- List<String> newTNames = new ArrayList<>(trainerNames);
- newTNames.add(0, tnames.get(0)); // the 0-entry, preserve it
- setStrings(false, romEntry.getInt("TrainerNamesTextOffset"), newTNames);
-
+ if (romEntry.romType == Gen5Constants.Type_BW2) {
+ List<String> pwtNames = getStrings(false, romEntry.getInt("PWTTrainerNamesTextOffset"));
+ List<String> newTNames = new ArrayList<>();
+ List<String> newPWTNames = new ArrayList<>();
+ newTNames.add(0, tnames.get(0)); // the 0-entry, preserve it
+ for (int i = 1; i < tnames.size() + pwtNames.size(); i++) {
+ if (i < tnames.size()) {
+ newTNames.add(trainerNames.get(i - 1));
+ } else {
+ newPWTNames.add(trainerNames.get(i - 1));
+ }
+ }
+ setStrings(false, romEntry.getInt("TrainerNamesTextOffset"), newTNames);
+ setStrings(false, romEntry.getInt("PWTTrainerNamesTextOffset"), newPWTNames);
+ } else {
+ List<String> newTNames = new ArrayList<>(trainerNames);
+ newTNames.add(0, tnames.get(0)); // the 0-entry, preserve it
+ setStrings(false, romEntry.getInt("TrainerNamesTextOffset"), newTNames);
+ }
}
@Override
@@ -3333,12 +3353,32 @@ public class Gen5RomHandler extends AbstractDSRomHandler {
@Override
public List<String> getTrainerClassNames() {
- return getStrings(false, romEntry.getInt("TrainerClassesTextOffset"));
+ List<String> classNames = getStrings(false, romEntry.getInt("TrainerClassesTextOffset"));
+ if (romEntry.romType == Gen5Constants.Type_BW2) {
+ classNames.addAll(getStrings(false, romEntry.getInt("PWTTrainerClassesTextOffset")));
+ }
+ return classNames;
}
@Override
public void setTrainerClassNames(List<String> trainerClassNames) {
- setStrings(false, romEntry.getInt("TrainerClassesTextOffset"), trainerClassNames);
+ if (romEntry.romType == Gen5Constants.Type_BW2) {
+ List<String> newTClasses = new ArrayList<>();
+ List<String> newPWTClasses = new ArrayList<>();
+ List<String> classNames = getStrings(false, romEntry.getInt("TrainerClassesTextOffset"));
+ List<String> pwtClassNames = getStrings(false, romEntry.getInt("PWTTrainerClassesTextOffset"));
+ for (int i = 0; i < classNames.size() + pwtClassNames.size(); i++) {
+ if (i < classNames.size()) {
+ newTClasses.add(trainerClassNames.get(i));
+ } else {
+ newPWTClasses.add(trainerClassNames.get(i));
+ }
+ }
+ setStrings(false, romEntry.getInt("TrainerClassesTextOffset"), newTClasses);
+ setStrings(false, romEntry.getInt("PWTTrainerClassesTextOffset"), newPWTClasses);
+ } else {
+ setStrings(false, romEntry.getInt("TrainerClassesTextOffset"), trainerClassNames);
+ }
}
@Override