├── .settings ├── org.eclipse.core.resources.prefs └── org.eclipse.jdt.ui.prefs ├── settings ├── balanced.rnqs ├── classic.rnqs ├── trainers_only.rnqs ├── randomizer_race.rnqs └── super_randomizer_race.rnqs ├── src ├── com │ └── dabomstew │ │ └── pkrandom │ │ ├── gui │ │ ├── loading.gif │ │ ├── emptyIcon.png │ │ ├── QSFileFilter.java │ │ ├── PresetFileFilter.java │ │ ├── ROMFilter.java │ │ ├── UpdateCheckThread.java │ │ ├── OperationDialog.form │ │ ├── OperationDialog.java │ │ └── UpdateFoundDialog.form │ │ ├── patches │ │ ├── gs_en_bwxp.ips │ │ ├── rb_en_bwxp.ips │ │ ├── b1_instant_text.ips │ │ ├── b2_instant_text.ips │ │ ├── crystal_en_bwxp.ips │ │ ├── rb_en_critrate.ips │ │ ├── rb_en_xaccnerf.ips │ │ ├── w1_instant_text.ips │ │ ├── w2_instant_text.ips │ │ ├── yellow_en_bwxp.ips │ │ ├── hgss_instant_text.ips │ │ ├── plat_instant_text.ips │ │ ├── yellow_en_critrate.ips │ │ └── yellow_en_xaccnerf.ips │ │ ├── config │ │ ├── customnames.rncn │ │ ├── vietcrystal.tbl │ │ ├── green_translation.tbl │ │ ├── Generation5.tbl │ │ ├── rby_english.tbl │ │ ├── gsc_english.tbl │ │ ├── rby_freger.tbl │ │ ├── gsc_freger.tbl │ │ ├── rby_espita.tbl │ │ ├── gsc_espita.tbl │ │ ├── gba_english.tbl │ │ ├── gameboy_jap.tbl │ │ ├── realistic_gen1_english.tbl │ │ └── gba_jap.tbl │ │ ├── exceptions │ │ ├── RandomizationException.java │ │ ├── RandomizerIOException.java │ │ └── InvalidSupplementFilesException.java │ │ ├── pokemon │ │ ├── IngameTrade.java │ │ ├── ExpCurve.java │ │ ├── MoveCategory.java │ │ ├── MoveLearnt.java │ │ ├── ItemList.java │ │ ├── Encounter.java │ │ ├── TrainerPokemon.java │ │ ├── EncounterSet.java │ │ ├── Move.java │ │ ├── EvolutionType.java │ │ ├── GenRestrictions.java │ │ ├── Type.java │ │ ├── Evolution.java │ │ └── Trainer.java │ │ ├── constants │ │ ├── GBConstants.java │ │ └── GlobalConstants.java │ │ ├── SysConstants.java │ │ ├── newnds │ │ ├── CRC16.java │ │ ├── NDSFile.java │ │ ├── NDSY9Entry.java │ │ └── NARCArchive.java │ │ ├── MiscTweak.java │ │ ├── RandomSource.java │ │ ├── GFXFunctions.java │ │ ├── romhandlers │ │ ├── AbstractGBRomHandler.java │ │ └── AbstractGBCRomHandler.java │ │ ├── Utils.java │ │ └── CustomNamesSet.java ├── thenewpoketext │ ├── UnicodeParser.java │ ├── PokeTextData.java │ └── TextToPoke.java └── compressors │ ├── Gen2Decmp.java │ └── DSDecmp.java ├── codetweaks └── bwexp │ ├── gsc │ ├── gen2_expyieldstable.bin │ ├── gen2_bwxp_dividehook.asm │ ├── gen2_bwxp_bootstrap.asm │ ├── gs_bw_xp_instructions_new.txt │ ├── gen2_bwxp_expadder.asm │ ├── gold_bwxp_constants.asm │ └── crystal_bwxp_constants.asm │ └── rby │ ├── y_bw_xp_instructions_new.txt │ ├── rb_bwxp_constants.asm │ └── y_bwxp_constants.asm ├── .classpath ├── .project ├── .gitignore ├── README.md └── readme.txt /.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding/=UTF-8 3 | -------------------------------------------------------------------------------- /settings/balanced.rnqs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dabomstew/universal-pokemon-randomizer/HEAD/settings/balanced.rnqs -------------------------------------------------------------------------------- /settings/classic.rnqs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dabomstew/universal-pokemon-randomizer/HEAD/settings/classic.rnqs -------------------------------------------------------------------------------- /settings/trainers_only.rnqs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dabomstew/universal-pokemon-randomizer/HEAD/settings/trainers_only.rnqs -------------------------------------------------------------------------------- /settings/randomizer_race.rnqs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dabomstew/universal-pokemon-randomizer/HEAD/settings/randomizer_race.rnqs -------------------------------------------------------------------------------- /settings/super_randomizer_race.rnqs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dabomstew/universal-pokemon-randomizer/HEAD/settings/super_randomizer_race.rnqs -------------------------------------------------------------------------------- /src/com/dabomstew/pkrandom/gui/loading.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dabomstew/universal-pokemon-randomizer/HEAD/src/com/dabomstew/pkrandom/gui/loading.gif -------------------------------------------------------------------------------- /codetweaks/bwexp/gsc/gen2_expyieldstable.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dabomstew/universal-pokemon-randomizer/HEAD/codetweaks/bwexp/gsc/gen2_expyieldstable.bin -------------------------------------------------------------------------------- /src/com/dabomstew/pkrandom/gui/emptyIcon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dabomstew/universal-pokemon-randomizer/HEAD/src/com/dabomstew/pkrandom/gui/emptyIcon.png -------------------------------------------------------------------------------- /src/com/dabomstew/pkrandom/patches/gs_en_bwxp.ips: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dabomstew/universal-pokemon-randomizer/HEAD/src/com/dabomstew/pkrandom/patches/gs_en_bwxp.ips -------------------------------------------------------------------------------- /src/com/dabomstew/pkrandom/patches/rb_en_bwxp.ips: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dabomstew/universal-pokemon-randomizer/HEAD/src/com/dabomstew/pkrandom/patches/rb_en_bwxp.ips -------------------------------------------------------------------------------- /src/com/dabomstew/pkrandom/config/customnames.rncn: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dabomstew/universal-pokemon-randomizer/HEAD/src/com/dabomstew/pkrandom/config/customnames.rncn -------------------------------------------------------------------------------- /src/com/dabomstew/pkrandom/patches/b1_instant_text.ips: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dabomstew/universal-pokemon-randomizer/HEAD/src/com/dabomstew/pkrandom/patches/b1_instant_text.ips -------------------------------------------------------------------------------- /src/com/dabomstew/pkrandom/patches/b2_instant_text.ips: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dabomstew/universal-pokemon-randomizer/HEAD/src/com/dabomstew/pkrandom/patches/b2_instant_text.ips -------------------------------------------------------------------------------- /src/com/dabomstew/pkrandom/patches/crystal_en_bwxp.ips: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dabomstew/universal-pokemon-randomizer/HEAD/src/com/dabomstew/pkrandom/patches/crystal_en_bwxp.ips -------------------------------------------------------------------------------- /src/com/dabomstew/pkrandom/patches/rb_en_critrate.ips: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dabomstew/universal-pokemon-randomizer/HEAD/src/com/dabomstew/pkrandom/patches/rb_en_critrate.ips -------------------------------------------------------------------------------- /src/com/dabomstew/pkrandom/patches/rb_en_xaccnerf.ips: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dabomstew/universal-pokemon-randomizer/HEAD/src/com/dabomstew/pkrandom/patches/rb_en_xaccnerf.ips -------------------------------------------------------------------------------- /src/com/dabomstew/pkrandom/patches/w1_instant_text.ips: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dabomstew/universal-pokemon-randomizer/HEAD/src/com/dabomstew/pkrandom/patches/w1_instant_text.ips -------------------------------------------------------------------------------- /src/com/dabomstew/pkrandom/patches/w2_instant_text.ips: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dabomstew/universal-pokemon-randomizer/HEAD/src/com/dabomstew/pkrandom/patches/w2_instant_text.ips -------------------------------------------------------------------------------- /src/com/dabomstew/pkrandom/patches/yellow_en_bwxp.ips: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dabomstew/universal-pokemon-randomizer/HEAD/src/com/dabomstew/pkrandom/patches/yellow_en_bwxp.ips -------------------------------------------------------------------------------- /src/com/dabomstew/pkrandom/patches/hgss_instant_text.ips: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dabomstew/universal-pokemon-randomizer/HEAD/src/com/dabomstew/pkrandom/patches/hgss_instant_text.ips -------------------------------------------------------------------------------- /src/com/dabomstew/pkrandom/patches/plat_instant_text.ips: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dabomstew/universal-pokemon-randomizer/HEAD/src/com/dabomstew/pkrandom/patches/plat_instant_text.ips -------------------------------------------------------------------------------- /src/com/dabomstew/pkrandom/patches/yellow_en_critrate.ips: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dabomstew/universal-pokemon-randomizer/HEAD/src/com/dabomstew/pkrandom/patches/yellow_en_critrate.ips -------------------------------------------------------------------------------- /src/com/dabomstew/pkrandom/patches/yellow_en_xaccnerf.ips: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dabomstew/universal-pokemon-randomizer/HEAD/src/com/dabomstew/pkrandom/patches/yellow_en_xaccnerf.ips -------------------------------------------------------------------------------- /codetweaks/bwexp/gsc/gen2_bwxp_dividehook.asm: -------------------------------------------------------------------------------- 1 | BWXP_DivideExpDataHook:: 2 | ld [BWXP_SCRATCH1B], a 3 | cp $2 4 | ret c 5 | ld [BWXP_NUM_PARTICIPANTS], a 6 | jp BWXP_DIVIDEEXP_RETURN_POINT -------------------------------------------------------------------------------- /codetweaks/bwexp/gsc/gen2_bwxp_bootstrap.asm: -------------------------------------------------------------------------------- 1 | BWXP_Bootstrap:: 2 | push hl 3 | push bc 4 | ld hl, BWXP_EXPCalculation 5 | ld a, BANK(BWXP_EXPCalculation) 6 | rst $08 7 | pop bc 8 | pop hl 9 | jp BWXP_MAIN_RETURN_POINT -------------------------------------------------------------------------------- /.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /codetweaks/bwexp/rby/y_bw_xp_instructions_new.txt: -------------------------------------------------------------------------------- 1 | Yellow B/W-style XP patch 2 | 552B0 : C3 00 6B (jumps to the new code) 3 | 5548C : C3 44 70 (jumps to the participants hook) 4 | 9FAD9 : EC CF 38 (shows CFEC with 3 bytes big endian & max 8 digits) 5 | 9FAE1 : E7 58 (cuts the message down to X EXP! so it fits with >4 digits) 6 | 7 | 56B00-5704F: copy 0x550 bytes raw -------------------------------------------------------------------------------- /src/com/dabomstew/pkrandom/exceptions/RandomizationException.java: -------------------------------------------------------------------------------- 1 | package com.dabomstew.pkrandom.exceptions; 2 | 3 | public class RandomizationException extends RuntimeException { 4 | public RandomizationException(String text) { 5 | super(text); 6 | } 7 | 8 | private static final long serialVersionUID = -771695719222719664L; 9 | 10 | } 11 | -------------------------------------------------------------------------------- /src/com/dabomstew/pkrandom/pokemon/IngameTrade.java: -------------------------------------------------------------------------------- 1 | package com.dabomstew.pkrandom.pokemon; 2 | 3 | public class IngameTrade { 4 | 5 | public int id; 6 | 7 | public Pokemon requestedPokemon, givenPokemon; 8 | 9 | public String nickname, otName; 10 | 11 | public int otId; 12 | 13 | public int[] ivs = new int[0]; 14 | 15 | public int item = 0; 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/com/dabomstew/pkrandom/exceptions/RandomizerIOException.java: -------------------------------------------------------------------------------- 1 | package com.dabomstew.pkrandom.exceptions; 2 | 3 | public class RandomizerIOException extends RuntimeException { 4 | public RandomizerIOException(Exception e) { 5 | super(e); 6 | } 7 | 8 | public RandomizerIOException(String text) { 9 | super(text); 10 | } 11 | 12 | private static final long serialVersionUID = -8174099615381353972L; 13 | } 14 | -------------------------------------------------------------------------------- /codetweaks/bwexp/gsc/gs_bw_xp_instructions_new.txt: -------------------------------------------------------------------------------- 1 | Gold/Silver B/W-style XP patch (new) 2 | 3ECE1 : C3 00 7F (bootstrap) 3 | 3ED44 : C3 19 7F (jump for XP adding) 4 | 3EF0D : C3 0D 7F (jumps for participants copy) 5 | 191E29 & 191E3F : F1 D0 38 (shows D0F1 with 3 bytes big endian & max 8 digits) 6 | 191E31 & 191E47 : E7 58 (cuts the message down to X EXP! so it fits with >4 digits) 7 | 8 | 3FF00 - 3FF4D: copy 0x4E bytes raw 9 | 16AB00 - 16B060: copy 0x561 bytes raw 10 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | universal-pokemon-randomizer 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.jdt.core.javanature 16 | 17 | 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.NDS 2 | *.nds 3 | *.GB 4 | *.gb 5 | *.GBC 6 | *.gbc 7 | *.GBA 8 | *.gba 9 | *.RNDP 10 | *.rndp 11 | tmp_* 12 | *.sgm 13 | *.sav 14 | *.rtc 15 | *.sgb 16 | *.sn* 17 | *.rar 18 | *.zip 19 | config.ini 20 | *.pkm 21 | error_*.txt 22 | src/com/dabomstew/pkrandom/localtests 23 | bin 24 | *.log 25 | *.bin 26 | nbproject 27 | build.xml 28 | manifest.mf 29 | /nicknames.txt 30 | /trainerclasses.txt 31 | /trainernames.txt 32 | /build/ 33 | *.dsm 34 | *.dsv 35 | build_eclipse.xml 36 | /customnames.rncn 37 | -------------------------------------------------------------------------------- /src/com/dabomstew/pkrandom/config/vietcrystal.tbl: -------------------------------------------------------------------------------- 1 | 7F= 2 | 80=! 3 | 81=" 4 | 82=% 5 | 83=& 6 | 84=' 7 | 85=( 8 | 86=) 9 | 87=+ 10 | 88=, 11 | 89=- 12 | 8A=. 13 | 8B=/ 14 | 8C=0 15 | 8D=1 16 | 8E=2 17 | 8F=3 18 | 90=4 19 | 91=5 20 | 92=6 21 | 93=7 22 | 94=8 23 | 95=9 24 | 96=: 25 | 97=; 26 | 98== 27 | 99=> 28 | 9A=? 29 | 9B=A 30 | 9C=B 31 | 9D=C 32 | 9E=D 33 | 9F=E 34 | A0=F 35 | A1=G 36 | A2=H 37 | A3=I 38 | A4=J 39 | A5=K 40 | A6=L 41 | A7=M 42 | A8=N 43 | A9=O 44 | AA=P 45 | AB=Q 46 | AC=R 47 | AD=S 48 | AE=T 49 | AF=U 50 | B0=V 51 | B1=W 52 | B2=X 53 | B3=Y 54 | B4=Z 55 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Universal Pokemon Randomizer 2 | 3 | By Dabomstew 4 | 5 | Homepage: http://pokehacks.dabomstew.com/randomizer/ 6 | 7 | This is the original version of the randomizer, which ceased active development in 2016. This repository has now been archived to reflect this. 8 | 9 | ## Replacements ## 10 | 11 | If you're looking for a regularly updated UPR fork with support for Gen6/7 games and many other added features, check out the Universal Pokemon Randomizer ZX by Ajarmar: https://github.com/Ajarmar/universal-pokemon-randomizer-zx 12 | 13 | If you're a speedrunner looking for the randomizer to randomize Speedchoice roms, that now lives at https://github.com/Dabomstew/UPR-Speedchoice 14 | -------------------------------------------------------------------------------- /src/com/dabomstew/pkrandom/config/green_translation.tbl: -------------------------------------------------------------------------------- 1 | 7F= 2 | 87=' 3 | 8D=- 4 | 90=0 5 | 91=1 6 | 92=2 7 | 93=3 8 | 94=4 9 | 95=5 10 | 96=6 11 | 97=7 12 | 98=8 13 | 99=9 14 | 9F=? 15 | A1=A 16 | A2=B 17 | A3=C 18 | A4=D 19 | A5=E 20 | A6=F 21 | A7=G 22 | A8=H 23 | A9=I 24 | AA=J 25 | AB=K 26 | AC=L 27 | AD=M 28 | AE=N 29 | AF=O 30 | B0=P 31 | B1=Q 32 | B2=R 33 | B3=S 34 | B4=T 35 | B5=U 36 | B6=V 37 | B7=W 38 | B8=X 39 | B9=Y 40 | BA=Z 41 | C1=a 42 | C2=b 43 | C3=c 44 | C4=d 45 | C5=e 46 | C6=f 47 | C7=g 48 | C8=h 49 | C9=i 50 | CA=j 51 | CB=k 52 | CC=l 53 | CD=m 54 | CE=n 55 | CF=o 56 | D0=p 57 | D1=q 58 | D2=r 59 | D3=s 60 | D4=t 61 | D5=u 62 | D6=v 63 | D7=w 64 | D8=x 65 | D9=y 66 | DA=z -------------------------------------------------------------------------------- /src/com/dabomstew/pkrandom/config/Generation5.tbl: -------------------------------------------------------------------------------- 1 | 2467=× 2 | 2468=÷ 3 | 246C=… 4 | 246D=♂ 5 | 246E=♀ 6 | 246F=♠ 7 | 2470=♣ 8 | 2471=♥ 9 | 2472=♦ 10 | 2473=★ 11 | 2474=◎ 12 | 2475=○ 13 | 2476=□ 14 | 2477=△ 15 | 2478=◇ 16 | 2479=♪ 17 | 247A=☀ 18 | 247B=☁ 19 | 247D=☂ 20 | 21D2=\[angry] 21 | 21D4=\[turnup] 22 | 2200=\[turndown] 23 | 2203=\[zzz] 24 | 2227=\[=)] 25 | 2228=\[=D] 26 | 2460=\[:)] 27 | 2461=\[:D] 28 | 2462=\[>:O] 29 | 2463=\[:(] 30 | 2464=\[turnup2] 31 | 2465=\[turndown2] 32 | 2466=\[zzz2] 33 | 2469=\[er] 34 | 246A=\[re] 35 | 246B=\[corner] 36 | 247E=\[:)s] 37 | 247F=\[:Ds] 38 | 2480=\[>:Os] 39 | 2481=\[:(s] 40 | 2482=\[turnups] 41 | 2483=\[turndowns] 42 | 2484=\[zzzs] 43 | 2485=\[e] 44 | 2486=\[PK] 45 | 2487=\[MN] 46 | FFE2=\[>:O2] 47 | -------------------------------------------------------------------------------- /src/com/dabomstew/pkrandom/constants/GBConstants.java: -------------------------------------------------------------------------------- 1 | package com.dabomstew.pkrandom.constants; 2 | 3 | public class GBConstants { 4 | 5 | public static final int minRomSize = 0x80000, maxRomSize = 0x200000; 6 | 7 | public static final int jpFlagOffset = 0x14A, versionOffset = 0x14C, crcOffset = 0x14E, romSigOffset = 0x134, 8 | isGBCOffset = 0x143, romCodeOffset = 0x13F; 9 | 10 | public static final int stringTerminator = 0x50, stringPrintedTextEnd = 0x57, stringPrintedTextPromptEnd = 0x58; 11 | 12 | public static final int bankSize = 0x4000; 13 | 14 | public static final byte gbZ80Jump = (byte) 0xC3, gbZ80Nop = 0x00, gbZ80XorA = (byte) 0xAF, gbZ80LdA = 0x3E, 15 | gbZ80LdAToFar = (byte) 0xEA, gbZ80Ret = (byte) 0xC9, gbZ80JumpRelative = (byte) 0x18; 16 | 17 | } 18 | -------------------------------------------------------------------------------- /codetweaks/bwexp/rby/rb_bwxp_constants.asm: -------------------------------------------------------------------------------- 1 | BWXP_ENEMY_LEVEL EQU $CFF3 2 | BWXP_ENEMY_SPECIES EQU $CFE5 3 | BWXP_MAX_LEVEL EQU 100 4 | BWXP_BATTLE_TYPE EQU $D057 5 | BWXP_MULTIPLICAND EQU $FF95 6 | BWXP_MULTIPLIER EQU $FF99 7 | BWXP_DIVIDEND EQU BWXP_MULTIPLICAND 8 | BWXP_DIVISOR EQU BWXP_MULTIPLIER 9 | BWXP_INBUILT_MULTIPLY EQU $38AC ; $38AC = Multiply 10 | BWXP_INBUILT_DIVIDE EQU $38B9 ; $38B9 = Divide 11 | BWXP_INBUILT_ISITEMINBAG EQU $3493 12 | BWXP_NUM_PARTICIPANTS EQU $D11E 13 | BWXP_SCRATCH5B_1 EQU $CFED 14 | BWXP_SCRATCH5B_2 EQU $CFF4 15 | BWXP_SCRATCH1B EQU $CFFE 16 | BWXP_MULTIPLIER_STOR EQU $FF9B 17 | BWXP_BIG_MULTIPLICAND EQU $FF94 18 | BWXP_BIG_DIVIDEND EQU BWXP_BIG_MULTIPLICAND 19 | BWXP_LEVEL_OFFSET_IN_PARTYMON EQU $0007 20 | BWXP_TID_OFFSET_IN_PARTYMON EQU $FFF2 21 | BWXP_PLAYER_TID EQU $D359 22 | BWXP_BOOSTED_EXP_FLAG EQU $CF4D 23 | BWXP_RETURN_POINT EQU $52F9 24 | BWXP_DIVIDEEXP_RETURN_POINT EQU $5483 25 | -------------------------------------------------------------------------------- /codetweaks/bwexp/rby/y_bwxp_constants.asm: -------------------------------------------------------------------------------- 1 | BWXP_ENEMY_LEVEL EQU $CFF2 2 | BWXP_ENEMY_SPECIES EQU $CFE4 3 | BWXP_MAX_LEVEL EQU 100 4 | BWXP_BATTLE_TYPE EQU $D056 5 | BWXP_MULTIPLICAND EQU $FF95 6 | BWXP_MULTIPLIER EQU $FF99 7 | BWXP_DIVIDEND EQU BWXP_MULTIPLICAND 8 | BWXP_DIVISOR EQU BWXP_MULTIPLIER 9 | BWXP_INBUILT_MULTIPLY EQU $38A5 ; $38AC = Multiply 10 | BWXP_INBUILT_DIVIDE EQU $38B2 ; $38B9 = Divide 11 | BWXP_INBUILT_ISITEMINBAG EQU $3422 12 | BWXP_NUM_PARTICIPANTS EQU $D11D 13 | BWXP_SCRATCH5B_1 EQU $CFEC 14 | BWXP_SCRATCH5B_2 EQU $CFF3 15 | BWXP_SCRATCH1B EQU $CFFD 16 | BWXP_MULTIPLIER_STOR EQU $FF9B 17 | BWXP_BIG_MULTIPLICAND EQU $FF94 18 | BWXP_BIG_DIVIDEND EQU BWXP_BIG_MULTIPLICAND 19 | BWXP_LEVEL_OFFSET_IN_PARTYMON EQU $0007 20 | BWXP_TID_OFFSET_IN_PARTYMON EQU $FFF2 21 | BWXP_PLAYER_TID EQU $D358 22 | BWXP_BOOSTED_EXP_FLAG EQU $CF4C 23 | BWXP_RETURN_POINT EQU $5308 24 | BWXP_DIVIDEEXP_RETURN_POINT EQU $5492 25 | -------------------------------------------------------------------------------- /src/com/dabomstew/pkrandom/config/rby_english.tbl: -------------------------------------------------------------------------------- 1 | 4A=[pk] 2 | 54=[POKé] 3 | 74=№ 4 | 75=… 5 | 7F= 6 | 79=┌ 7 | 7A=─ 8 | 7B=┐ 9 | 7C=│ 10 | 7D=└ 11 | 7E=┘ 12 | 80=A 13 | 81=B 14 | 82=C 15 | 83=D 16 | 84=E 17 | 85=F 18 | 86=G 19 | 87=H 20 | 88=I 21 | 89=J 22 | 8A=K 23 | 8B=L 24 | 8C=M 25 | 8D=N 26 | 8E=O 27 | 8F=P 28 | 90=Q 29 | 91=R 30 | 92=S 31 | 93=T 32 | 94=U 33 | 95=V 34 | 96=W 35 | 97=X 36 | 98=Y 37 | 99=Z 38 | 9A=( 39 | 9B=) 40 | 9C=: 41 | 9D=; 42 | 9E=[ 43 | 9F=] 44 | A0=a 45 | A1=b 46 | A2=c 47 | A3=d 48 | A4=e 49 | A5=f 50 | A6=g 51 | A7=h 52 | A8=i 53 | A9=j 54 | AA=k 55 | AB=l 56 | AC=m 57 | AD=n 58 | AE=o 59 | AF=p 60 | B0=q 61 | B1=r 62 | B2=s 63 | B3=t 64 | B4=u 65 | B5=v 66 | B6=w 67 | B7=x 68 | B8=y 69 | B9=z 70 | BA=é 71 | BB='d 72 | BC='l 73 | BD='s 74 | BE='t 75 | BF='v 76 | E0=' 77 | E1=[PK] 78 | E2=[MN] 79 | E3=- 80 | E4='r 81 | E5='m 82 | E6=? 83 | E7=! 84 | E8=. 85 | F0=$ 86 | F2=[.] 87 | F4=, -------------------------------------------------------------------------------- /src/com/dabomstew/pkrandom/config/gsc_english.tbl: -------------------------------------------------------------------------------- 1 | 4A=[pk] 2 | 54=[POKé] 3 | 74=№ 4 | 75=… 5 | 7F= 6 | 79=┌ 7 | 7A=─ 8 | 7B=┐ 9 | 7C=│ 10 | 7D=└ 11 | 7E=┘ 12 | 80=A 13 | 81=B 14 | 82=C 15 | 83=D 16 | 84=E 17 | 85=F 18 | 86=G 19 | 87=H 20 | 88=I 21 | 89=J 22 | 8A=K 23 | 8B=L 24 | 8C=M 25 | 8D=N 26 | 8E=O 27 | 8F=P 28 | 90=Q 29 | 91=R 30 | 92=S 31 | 93=T 32 | 94=U 33 | 95=V 34 | 96=W 35 | 97=X 36 | 98=Y 37 | 99=Z 38 | 9A=( 39 | 9B=) 40 | 9C=: 41 | 9D=; 42 | 9E=[ 43 | 9F=] 44 | A0=a 45 | A1=b 46 | A2=c 47 | A3=d 48 | A4=e 49 | A5=f 50 | A6=g 51 | A7=h 52 | A8=i 53 | A9=j 54 | AA=k 55 | AB=l 56 | AC=m 57 | AD=n 58 | AE=o 59 | AF=p 60 | B0=q 61 | B1=r 62 | B2=s 63 | B3=t 64 | B4=u 65 | B5=v 66 | B6=w 67 | B7=x 68 | B8=y 69 | B9=z 70 | C0=Ä 71 | C1=Ö 72 | C2=Ü 73 | C3=ä 74 | C4=ö 75 | C5=ü 76 | D0='d 77 | D1='l 78 | D2='m 79 | D3='r 80 | D4='s 81 | D5='t 82 | D6='v 83 | E0=' 84 | E1=[PK] 85 | E2=[MN] 86 | E3=- 87 | E6=? 88 | E7=! 89 | E8=. 90 | E9=& 91 | EA=é 92 | EB=→ 93 | F0=$ 94 | F2=[.] 95 | F4=, -------------------------------------------------------------------------------- /src/com/dabomstew/pkrandom/pokemon/ExpCurve.java: -------------------------------------------------------------------------------- 1 | package com.dabomstew.pkrandom.pokemon; 2 | 3 | public enum ExpCurve { 4 | 5 | SLOW, MEDIUM_SLOW, MEDIUM_FAST, FAST, ERRATIC, FLUCTUATING; 6 | 7 | public static ExpCurve fromByte(byte curve) { 8 | switch (curve) { 9 | case 0: 10 | return MEDIUM_FAST; 11 | case 1: 12 | return ERRATIC; 13 | case 2: 14 | return FLUCTUATING; 15 | case 3: 16 | return MEDIUM_SLOW; 17 | case 4: 18 | return FAST; 19 | case 5: 20 | return SLOW; 21 | } 22 | return null; 23 | } 24 | 25 | public byte toByte() { 26 | switch (this) { 27 | case SLOW: 28 | return 5; 29 | case MEDIUM_SLOW: 30 | return 3; 31 | case MEDIUM_FAST: 32 | return 0; 33 | case FAST: 34 | return 4; 35 | case ERRATIC: 36 | return 1; 37 | case FLUCTUATING: 38 | return 2; 39 | } 40 | return 0; // default 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /codetweaks/bwexp/gsc/gen2_bwxp_expadder.asm: -------------------------------------------------------------------------------- 1 | BWXP_EXPAdderHook:: 2 | ; copy back yield to multiplier fields 3 | ld a, [BWXP_SCRATCH5B_1 + 2] 4 | ld [BWXP_MULTIPLICAND + 3], a 5 | ld a, [BWXP_SCRATCH5B_1 + 1] 6 | ld [BWXP_MULTIPLICAND + 2], a 7 | ld a, [BWXP_SCRATCH5B_1] 8 | ld [BWXP_MULTIPLICAND + 1], a 9 | 10 | ; unknown functions from original code, call them as is 11 | pop bc 12 | call BWXP_UNKNOWNFUNC1 13 | push bc 14 | call BWXP_UNKNOWNFUNC2 15 | pop bc 16 | ; set hl = 3rd byte of party mon exp value (+10 from current bc) 17 | ld hl, $a 18 | add hl, bc 19 | ; add new exp 20 | ld d, [hl] 21 | ld a, [BWXP_MULTIPLICAND + 3] 22 | add d 23 | ld [hld], a 24 | 25 | ld d, [hl] 26 | ld a, [BWXP_MULTIPLICAND + 2] 27 | adc d 28 | ld [hld], a 29 | 30 | ld d, [hl] 31 | ld a, [BWXP_MULTIPLICAND + 1] 32 | adc d 33 | ld [hl], a 34 | jr nc, .done 35 | ; maxed exp, set it to FFFFFF 36 | ld a, $ff 37 | ld [hli], a 38 | ld [hli], a 39 | ld [hl], a 40 | 41 | .done 42 | jp BWXP_EXPADDER_RETURN_POINT 43 | -------------------------------------------------------------------------------- /codetweaks/bwexp/gsc/gold_bwxp_constants.asm: -------------------------------------------------------------------------------- 1 | BWXP_ENEMY_LEVEL EQU $D0FC 2 | BWXP_ENEMY_SPECIES EQU $D0EF 3 | BWXP_MAX_LEVEL EQU 100 4 | BWXP_BATTLE_TYPE EQU $D116 5 | BWXP_MULTIPLICAND EQU $FFB5 6 | BWXP_MULTIPLIER EQU $FFB9 7 | BWXP_DIVIDEND EQU BWXP_MULTIPLICAND 8 | BWXP_DIVISOR EQU BWXP_MULTIPLIER 9 | BWXP_INBUILT_MULTIPLY EQU $31BE 10 | BWXP_INBUILT_DIVIDE EQU $31C9 11 | BWXP_INBUILT_PARTYPARAMLOC EQU $3B3A 12 | BWXP_PARTYPARAM_LEVEL EQU $1F 13 | BWXP_PARTYPARAM_TID EQU $06 14 | BWXP_PARTYPARAM_HELDITEM EQU $01 15 | BWXP_PARTYPARAM_HP EQU $02 16 | BWXP_NUM_PARTICIPANTS EQU $D151 17 | BWXP_SCRATCH5B_1 EQU $D0F1 18 | BWXP_SCRATCH5B_2 EQU $D0F6 19 | BWXP_SCRATCH1B EQU $D0FB 20 | BWXP_MULTIPLIER_STOR EQU $FFBB 21 | BWXP_BIG_MULTIPLICAND EQU $FFB4 22 | BWXP_BIG_DIVIDEND EQU BWXP_BIG_MULTIPLICAND 23 | BWXP_PLAYER_TID EQU $D1A1 24 | BWXP_BOOSTED_EXP_FLAG EQU $CF80 25 | BWXP_DIVIDEEXP_RETURN_POINT EQU $6F13 26 | BWXP_PARTYCOUNT EQU $DA22 27 | BWXP_PARTYMON1 EQU $DA2A 28 | BWXP_PARTYMON2 EQU $DA5A 29 | BWXP_MAIN_RETURN_POINT EQU $6D35 30 | BWXP_EXPADDER_RETURN_POINT EQU $6D69 31 | BWXP_UNKNOWNFUNC1 EQU $6F5F 32 | BWXP_UNKNOWNFUNC2 EQU $3158 -------------------------------------------------------------------------------- /codetweaks/bwexp/gsc/crystal_bwxp_constants.asm: -------------------------------------------------------------------------------- 1 | BWXP_ENEMY_LEVEL EQU $D213 2 | BWXP_ENEMY_SPECIES EQU $D206 3 | BWXP_MAX_LEVEL EQU 100 4 | BWXP_BATTLE_TYPE EQU $D22D 5 | BWXP_MULTIPLICAND EQU $FFB3 6 | BWXP_MULTIPLIER EQU $FFB7 7 | BWXP_DIVIDEND EQU BWXP_MULTIPLICAND 8 | BWXP_DIVISOR EQU BWXP_MULTIPLIER 9 | BWXP_INBUILT_MULTIPLY EQU $3119 10 | BWXP_INBUILT_DIVIDE EQU $3124 11 | BWXP_INBUILT_PARTYPARAMLOC EQU $3917 ; $3917 = GetPartyParamLocation 12 | BWXP_PARTYPARAM_LEVEL EQU $1F 13 | BWXP_PARTYPARAM_TID EQU $06 14 | BWXP_PARTYPARAM_HELDITEM EQU $01 15 | BWXP_PARTYPARAM_HP EQU $02 16 | BWXP_NUM_PARTICIPANTS EQU $D265 17 | BWXP_SCRATCH5B_1 EQU $D208 18 | BWXP_SCRATCH5B_2 EQU $D20D 19 | BWXP_SCRATCH1B EQU $D212 20 | BWXP_MULTIPLIER_STOR EQU $FFB9 21 | BWXP_BIG_MULTIPLICAND EQU $FFB2 22 | BWXP_BIG_DIVIDEND EQU BWXP_BIG_MULTIPLICAND 23 | BWXP_PLAYER_TID EQU $D47B 24 | BWXP_BOOSTED_EXP_FLAG EQU $D088 25 | BWXP_DIVIDEEXP_RETURN_POINT EQU $70EA 26 | BWXP_PARTYCOUNT EQU $DCD7 27 | BWXP_PARTYMON1 EQU $DCDF 28 | BWXP_PARTYMON2 EQU $DD0F 29 | BWXP_MAIN_RETURN_POINT EQU $6F02 30 | BWXP_EXPADDER_RETURN_POINT EQU $6F3D 31 | BWXP_UNKNOWNFUNC1 EQU $7136 32 | BWXP_UNKNOWNFUNC2 EQU $309D -------------------------------------------------------------------------------- /src/com/dabomstew/pkrandom/config/rby_freger.tbl: -------------------------------------------------------------------------------- 1 | 4A=[pk] 2 | 54=[POKé] 3 | 74=№ 4 | 75=… 5 | 7F= 6 | 79=┌ 7 | 7A=─ 8 | 7B=┐ 9 | 7C=│ 10 | 7D=└ 11 | 7E=┘ 12 | 80=A 13 | 81=B 14 | 82=C 15 | 83=D 16 | 84=E 17 | 85=F 18 | 86=G 19 | 87=H 20 | 88=I 21 | 89=J 22 | 8A=K 23 | 8B=L 24 | 8C=M 25 | 8D=N 26 | 8E=O 27 | 8F=P 28 | 90=Q 29 | 91=R 30 | 92=S 31 | 93=T 32 | 94=U 33 | 95=V 34 | 96=W 35 | 97=X 36 | 98=Y 37 | 99=Z 38 | 9A=( 39 | 9B=) 40 | 9C=: 41 | 9D=; 42 | 9E=[ 43 | 9F=] 44 | A0=a 45 | A1=b 46 | A2=c 47 | A3=d 48 | A4=e 49 | A5=f 50 | A6=g 51 | A7=h 52 | A8=i 53 | A9=j 54 | AA=k 55 | AB=l 56 | AC=m 57 | AD=n 58 | AE=o 59 | AF=p 60 | B0=q 61 | B1=r 62 | B2=s 63 | B3=t 64 | B4=u 65 | B5=v 66 | B6=w 67 | B7=x 68 | B8=y 69 | B9=z 70 | BA=à 71 | BB=è 72 | BC=é 73 | BD=ù 74 | BE=ß 75 | BF=ç 76 | C0=Ä 77 | C1=Ö 78 | C2=Ü 79 | C3=ä 80 | C4=ö 81 | C5=ü 82 | C6=ë 83 | C7=ï 84 | C8=â 85 | C9=ô 86 | CA=û 87 | CB=ê 88 | CC=î 89 | D4=c' 90 | D5=d' 91 | D6=j' 92 | D7=l' 93 | D8=m' 94 | D9=n' 95 | DA=p' 96 | DB=s' 97 | DC='s 98 | DD=t' 99 | DE=u' 100 | DF=y' 101 | E0=' 102 | E1=[PK] 103 | E2=[MN] 104 | E3=- 105 | E4=+ 106 | E6=? 107 | E7=! 108 | E8=. 109 | F0=$ 110 | F2=[.] 111 | F4=, -------------------------------------------------------------------------------- /src/com/dabomstew/pkrandom/config/gsc_freger.tbl: -------------------------------------------------------------------------------- 1 | 4A=[pk] 2 | 54=[POKé] 3 | 74=№ 4 | 75=… 5 | 7F= 6 | 79=┌ 7 | 7A=─ 8 | 7B=┐ 9 | 7C=│ 10 | 7D=└ 11 | 7E=┘ 12 | 80=A 13 | 81=B 14 | 82=C 15 | 83=D 16 | 84=E 17 | 85=F 18 | 86=G 19 | 87=H 20 | 88=I 21 | 89=J 22 | 8A=K 23 | 8B=L 24 | 8C=M 25 | 8D=N 26 | 8E=O 27 | 8F=P 28 | 90=Q 29 | 91=R 30 | 92=S 31 | 93=T 32 | 94=U 33 | 95=V 34 | 96=W 35 | 97=X 36 | 98=Y 37 | 99=Z 38 | 9A=( 39 | 9B=) 40 | 9C=: 41 | 9D=; 42 | 9E=[ 43 | 9F=] 44 | A0=a 45 | A1=b 46 | A2=c 47 | A3=d 48 | A4=e 49 | A5=f 50 | A6=g 51 | A7=h 52 | A8=i 53 | A9=j 54 | AA=k 55 | AB=l 56 | AC=m 57 | AD=n 58 | AE=o 59 | AF=p 60 | B0=q 61 | B1=r 62 | B2=s 63 | B3=t 64 | B4=u 65 | B5=v 66 | B6=w 67 | B7=x 68 | B8=y 69 | B9=z 70 | BA=à 71 | BB=è 72 | BC=é 73 | BD=ù 74 | BE=ß 75 | BF=ç 76 | C0=Ä 77 | C1=Ö 78 | C2=Ü 79 | C3=ä 80 | C4=ö 81 | C5=ü 82 | C6=ë 83 | C7=ï 84 | C8=â 85 | C9=ô 86 | CA=û 87 | CB=ê 88 | CC=î 89 | D4=c' 90 | D5=d' 91 | D6=j' 92 | D7=l' 93 | D8=m' 94 | D9=n' 95 | DA=p' 96 | DB=s' 97 | DC='s 98 | DD=t' 99 | DE=u' 100 | DF=y' 101 | E0=' 102 | E1=[PK] 103 | E2=[MN] 104 | E3=- 105 | E4=+ 106 | E6=? 107 | E7=! 108 | E8=. 109 | E9=& 110 | EA=é 111 | EB=→ 112 | F0=$ 113 | F2=[.] 114 | F4=, -------------------------------------------------------------------------------- /src/com/dabomstew/pkrandom/config/rby_espita.tbl: -------------------------------------------------------------------------------- 1 | 4A=[pk] 2 | 54=[POKé] 3 | 74=№ 4 | 75=… 5 | 7F= 6 | 79=┌ 7 | 7A=─ 8 | 7B=┐ 9 | 7C=│ 10 | 7D=└ 11 | 7E=┘ 12 | 80=A 13 | 81=B 14 | 82=C 15 | 83=D 16 | 84=E 17 | 85=F 18 | 86=G 19 | 87=H 20 | 88=I 21 | 89=J 22 | 8A=K 23 | 8B=L 24 | 8C=M 25 | 8D=N 26 | 8E=O 27 | 8F=P 28 | 90=Q 29 | 91=R 30 | 92=S 31 | 93=T 32 | 94=U 33 | 95=V 34 | 96=W 35 | 97=X 36 | 98=Y 37 | 99=Z 38 | 9A=( 39 | 9B=) 40 | 9C=: 41 | 9D=; 42 | 9E=[ 43 | 9F=] 44 | A0=a 45 | A1=b 46 | A2=c 47 | A3=d 48 | A4=e 49 | A5=f 50 | A6=g 51 | A7=h 52 | A8=i 53 | A9=j 54 | AA=k 55 | AB=l 56 | AC=m 57 | AD=n 58 | AE=o 59 | AF=p 60 | B0=q 61 | B1=r 62 | B2=s 63 | B3=t 64 | B4=u 65 | B5=v 66 | B6=w 67 | B7=x 68 | B8=y 69 | B9=z 70 | BA=à 71 | BB=è 72 | BC=é 73 | BD=ù 74 | BE=À 75 | BF=Á 76 | C0=Ä 77 | C1=Ö 78 | C2=Ü 79 | C3=ä 80 | C4=ö 81 | C5=ü 82 | C6=È 83 | C7=É 84 | C8=Ì 85 | C9=Í 86 | CA=Ñ 87 | CB=Ò 88 | CC=Ó 89 | CD=Ù 90 | CE=Ú 91 | CF=á 92 | D0=ì 93 | D1=í 94 | D2=ñ 95 | D3=ò 96 | D4=ó 97 | D5=ú 98 | D6=° 99 | D7=& 100 | D8='d 101 | D9='l 102 | DA='m 103 | DB='r 104 | DC='s 105 | DD='t 106 | DE='v 107 | E0=' 108 | E1=[PK] 109 | E2=[MN] 110 | E3=- 111 | E4=¿ 112 | E5=¡ 113 | E6=? 114 | E7=! 115 | E8=. 116 | F0=$ 117 | F2=[.] 118 | F4=, -------------------------------------------------------------------------------- /src/com/dabomstew/pkrandom/config/gsc_espita.tbl: -------------------------------------------------------------------------------- 1 | 4A=[pk] 2 | 54=[POKé] 3 | 74=№ 4 | 75=… 5 | 7F= 6 | 79=┌ 7 | 7A=─ 8 | 7B=┐ 9 | 7C=│ 10 | 7D=└ 11 | 7E=┘ 12 | 80=A 13 | 81=B 14 | 82=C 15 | 83=D 16 | 84=E 17 | 85=F 18 | 86=G 19 | 87=H 20 | 88=I 21 | 89=J 22 | 8A=K 23 | 8B=L 24 | 8C=M 25 | 8D=N 26 | 8E=O 27 | 8F=P 28 | 90=Q 29 | 91=R 30 | 92=S 31 | 93=T 32 | 94=U 33 | 95=V 34 | 96=W 35 | 97=X 36 | 98=Y 37 | 99=Z 38 | 9A=( 39 | 9B=) 40 | 9C=: 41 | 9D=; 42 | 9E=[ 43 | 9F=] 44 | A0=a 45 | A1=b 46 | A2=c 47 | A3=d 48 | A4=e 49 | A5=f 50 | A6=g 51 | A7=h 52 | A8=i 53 | A9=j 54 | AA=k 55 | AB=l 56 | AC=m 57 | AD=n 58 | AE=o 59 | AF=p 60 | B0=q 61 | B1=r 62 | B2=s 63 | B3=t 64 | B4=u 65 | B5=v 66 | B6=w 67 | B7=x 68 | B8=y 69 | B9=z 70 | BA=à 71 | BB=è 72 | BC=é 73 | BD=ù 74 | BE=À 75 | BF=Á 76 | C0=Ä 77 | C1=Ö 78 | C2=Ü 79 | C3=ä 80 | C4=ö 81 | C5=ü 82 | C6=È 83 | C7=É 84 | C8=Ì 85 | C9=Í 86 | CA=Ñ 87 | CB=Ò 88 | CC=Ó 89 | CD=Ù 90 | CE=Ú 91 | CF=á 92 | D0=ì 93 | D1=í 94 | D2=ñ 95 | D3=ò 96 | D4=ó 97 | D5=ú 98 | D6=° 99 | D7=& 100 | D8='d 101 | D9='l 102 | DA='m 103 | DB='r 104 | DC='s 105 | DD='t 106 | DE='v 107 | E0=' 108 | E1=[PK] 109 | E2=[MN] 110 | E3=- 111 | E4=¿ 112 | E5=¡ 113 | E6=? 114 | E7=! 115 | E8=. 116 | E9=& 117 | EA=é 118 | EB=→ 119 | F0=$ 120 | F2=[.] 121 | F4=, -------------------------------------------------------------------------------- /src/thenewpoketext/UnicodeParser.java: -------------------------------------------------------------------------------- 1 | package thenewpoketext; 2 | 3 | /*----------------------------------------------------------------------------*/ 4 | /*-- UnicodeParser.java - maintains the poke<->unicode text table --*/ 5 | /*-- Code loosely derived from "thenewpoketext", copyright (C) loadingNOW --*/ 6 | /*-- Ported to Java and customized by Dabomstew --*/ 7 | /*----------------------------------------------------------------------------*/ 8 | 9 | import java.io.FileNotFoundException; 10 | import java.util.HashMap; 11 | import java.util.Map; 12 | import java.util.Scanner; 13 | 14 | import com.dabomstew.pkrandom.FileFunctions; 15 | 16 | public class UnicodeParser { 17 | 18 | public static String[] tb = new String[65536]; 19 | public static Map d = new HashMap(); 20 | 21 | static { 22 | try { 23 | Scanner sc = new Scanner(FileFunctions.openConfig("Generation4.tbl"), "UTF-8"); 24 | while (sc.hasNextLine()) { 25 | String q = sc.nextLine(); 26 | if (!q.trim().isEmpty()) { 27 | String[] r = q.split("=", 2); 28 | if (r[1].endsWith("\r\n")) { 29 | r[1] = r[1].substring(0, r[1].length() - 2); 30 | } 31 | tb[Integer.parseInt(r[0], 16)] = r[1]; 32 | d.put(r[1], Integer.parseInt(r[0], 16)); 33 | } 34 | } 35 | sc.close(); 36 | } catch (FileNotFoundException e) { 37 | } 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/com/dabomstew/pkrandom/config/gba_english.tbl: -------------------------------------------------------------------------------- 1 | 00= 2 | 01=À 3 | 02=Á 4 | 03=Â 5 | 04=Ç 6 | 05=È 7 | 06=É 8 | 07=Ê 9 | 08=Ë 10 | 09=Ì 11 | 0B=Î 12 | 0C=Ï 13 | 0D=Ò 14 | 0E=Ó 15 | 0F=Ô 16 | 10=Æ 17 | 11=Ù 18 | 12=Ú 19 | 13=Û 20 | 14=Ñ 21 | 15=ß 22 | 16=à 23 | 17=á 24 | 19=ç 25 | 1A=è 26 | 1B=é 27 | 1C=ê 28 | 1D=ë 29 | 1E=ì 30 | 20=î 31 | 21=ï 32 | 22=ò 33 | 23=ó 34 | 24=ô 35 | 25=æ 36 | 26=ù 37 | 27=ú 38 | 28=û 39 | 29=ñ 40 | 2A=º 41 | 2B=ª 42 | 2C=· 43 | 2D=& 44 | 2E=+ 45 | 34=[Lv] 46 | 35== 47 | 36=; 48 | 51=¿ 49 | 52=¡ 50 | 53=[PK] 51 | 54=[MN] 52 | 55=[PO] 53 | 56=[Ke] 54 | 57=[BL] 55 | 58=[OC] 56 | 59=[K] 57 | 5A=Í 58 | 5B=% 59 | 5C=( 60 | 5D=) 61 | 68=â 62 | 6F=í 63 | 79=[U] 64 | 7A=[D] 65 | 7B=[L] 66 | 7C=[R] 67 | A1=0 68 | A2=1 69 | A3=2 70 | A4=3 71 | A5=4 72 | A6=5 73 | A7=6 74 | A8=7 75 | A9=8 76 | AA=9 77 | AB=! 78 | AC=? 79 | AD=. 80 | AE=- 81 | AF=· 82 | B0=… 83 | B1=“ 84 | B2=” 85 | B3=‘ 86 | B4=’ 87 | B5=♂ 88 | B6=♀ 89 | B7=$ 90 | B8=, 91 | B9=[x] 92 | BA=/ 93 | BB=A 94 | BC=B 95 | BD=C 96 | BE=D 97 | BF=E 98 | C0=F 99 | C1=G 100 | C2=H 101 | C3=I 102 | C4=J 103 | C5=K 104 | C6=L 105 | C7=M 106 | C8=N 107 | C9=O 108 | CA=P 109 | CB=Q 110 | CC=R 111 | CD=S 112 | CE=T 113 | CF=U 114 | D0=V 115 | D1=W 116 | D2=X 117 | D3=Y 118 | D4=Z 119 | D5=a 120 | D6=b 121 | D7=c 122 | D8=d 123 | D9=e 124 | DA=f 125 | DB=g 126 | DC=h 127 | DD=i 128 | DE=j 129 | DF=k 130 | E0=l 131 | E1=m 132 | E2=n 133 | E3=o 134 | E4=p 135 | E5=q 136 | E6=r 137 | E7=s 138 | E8=t 139 | E9=u 140 | EA=v 141 | EB=w 142 | EC=x 143 | ED=y 144 | EE=z 145 | EF=[>] 146 | F0=: 147 | F1=Ä 148 | F2=Ö 149 | F3=Ü 150 | F4=ä 151 | F5=ö 152 | F6=ü 153 | F7=[u] 154 | F8=[d] 155 | F9=[l] 156 | FA=\l 157 | FB=\p 158 | FC=\c 159 | FE=\n 160 | -------------------------------------------------------------------------------- /src/com/dabomstew/pkrandom/pokemon/MoveCategory.java: -------------------------------------------------------------------------------- 1 | package com.dabomstew.pkrandom.pokemon; 2 | 3 | /*----------------------------------------------------------------------------*/ 4 | /*-- DamageType.java - represents a move's Physical/Special split value. --*/ 5 | /*-- --*/ 6 | /*-- Part of "Universal Pokemon Randomizer" by Dabomstew --*/ 7 | /*-- Pokemon and any associated names and the like are --*/ 8 | /*-- trademark and (C) Nintendo 1996-2012. --*/ 9 | /*-- --*/ 10 | /*-- The custom code written here is licensed under the terms of the GPL: --*/ 11 | /*-- --*/ 12 | /*-- This program is free software: you can redistribute it and/or modify --*/ 13 | /*-- it under the terms of the GNU General Public License as published by --*/ 14 | /*-- the Free Software Foundation, either version 3 of the License, or --*/ 15 | /*-- (at your option) any later version. --*/ 16 | /*-- --*/ 17 | /*-- This program is distributed in the hope that it will be useful, --*/ 18 | /*-- but WITHOUT ANY WARRANTY; without even the implied warranty of --*/ 19 | /*-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the --*/ 20 | /*-- GNU General Public License for more details. --*/ 21 | /*-- --*/ 22 | /*-- You should have received a copy of the GNU General Public License --*/ 23 | /*-- along with this program. If not, see . --*/ 24 | /*----------------------------------------------------------------------------*/ 25 | 26 | public enum MoveCategory { 27 | PHYSICAL, SPECIAL, STATUS; 28 | } 29 | -------------------------------------------------------------------------------- /src/com/dabomstew/pkrandom/config/gameboy_jap.tbl: -------------------------------------------------------------------------------- 1 | 05=ガ 2 | 06=ギ 3 | 07=グ 4 | 08=ゲ 5 | 09=ゴ 6 | 0A=ザ 7 | 0B=ジ 8 | 0C=ズ 9 | 0D=ゼ 10 | 0E=ゾ 11 | 0F=ダ 12 | 10=ヂ 13 | 11=ヅ 14 | 12=デ 15 | 13=ド 16 | 19=バ 17 | 1A=ビ 18 | 1B=ブ 19 | 1C=ボ 20 | 26=が 21 | 27=ぎ 22 | 28=ぐ 23 | 29=げ 24 | 2A=ご 25 | 2B=ざ 26 | 2C=じ 27 | 2D=ず 28 | 2E=ぜ 29 | 2F=ぞ 30 | 30=だ 31 | 31=ぢ 32 | 32=づ 33 | 33=で 34 | 34=ど 35 | 3A=ば 36 | 3B=び 37 | 3C=ぶ 38 | 3D=べ 39 | 3E=ぼ 40 | 40=パ 41 | 41=ピ 42 | 42=プ 43 | 43=ポ 44 | 44=ぱ 45 | 45=ぴ 46 | 46=ぷ 47 | 47=ぺ 48 | 48=ぽ 49 | 54=ポケモン 50 | 7F= 51 | 80=ア 52 | 81=イ 53 | 82=ウ 54 | 83=エ 55 | 84=ォ 56 | 85=カ 57 | 86=キ 58 | 87=ク 59 | 88=ケ 60 | 89=コ 61 | 8A=サ 62 | 8B=シ 63 | 8C=ス 64 | 8D=セ 65 | 8E=ソ 66 | 8F=タ 67 | 90=チ 68 | 91=ツ 69 | 92=テ 70 | 93=ト 71 | 94=ナ 72 | 95=ニ 73 | 96=ヌ 74 | 97=ネ 75 | 98=ノ 76 | 99=ハ 77 | 9A=ヒ 78 | 9B=フ 79 | 9C=ホ 80 | 9D=マ 81 | 9E=ミ 82 | 9F=ム 83 | A0=メ 84 | A1=モ 85 | A2=ヤ 86 | A3=ユ 87 | A4=ヨ 88 | A5=ラ 89 | A6=ル 90 | A7=レ 91 | A8=ロ 92 | A9=ワ 93 | AA=ヲ 94 | AB=ン 95 | AC=ッ 96 | AD=ャ 97 | AE=ュ 98 | AF=ョ 99 | B0=ィ 100 | B1=あ 101 | B2=い 102 | B3=う 103 | B4=え 104 | B5=お 105 | B6=か 106 | B7=き 107 | B8=く 108 | B9=け 109 | BA=こ 110 | BB=さ 111 | BC=し 112 | BD=す 113 | BE=せ 114 | BF=そ 115 | C0=た 116 | C1=ち 117 | C2=つ 118 | C3=て 119 | C4=と 120 | C5=な 121 | C6=に 122 | C7=ぬ 123 | C8=ね 124 | C9=の 125 | CA=は 126 | CB=ひ 127 | CC=ふ 128 | CD=へ 129 | CE=ほ 130 | CF=ま 131 | D0=み 132 | D1=む 133 | D2=め 134 | D3=も 135 | D4=や 136 | D5=ゆ 137 | D6=よ 138 | D7=ら 139 | D8=り 140 | D9=る 141 | DA=れ 142 | DB=ろ 143 | DC=わ 144 | DD=を 145 | DE=ん 146 | DF=っ 147 | E0=ゃ 148 | E1=ゅ 149 | E2=ょ 150 | E3=ー 151 | E4=。 152 | E4=゚ 153 | E5=゙​ 154 | E6=? 155 | E7=! 156 | E8=。 157 | E9=ァ 158 | EB=ェ 159 | EF=♂ 160 | F0=円 161 | F1=× 162 | F2=[.] 163 | F3=/ 164 | F4=ォ 165 | F5=♀ 166 | F6=0 167 | F7=1 168 | F8=2 169 | F9=3 170 | FA=4 171 | FB=5 172 | FC=6 173 | FD=7 174 | FE=8 175 | FF=9 176 | 4F=\n 177 | 51=\p 178 | 55=\l 179 | 57=\e 180 | 58=\r -------------------------------------------------------------------------------- /src/com/dabomstew/pkrandom/pokemon/MoveLearnt.java: -------------------------------------------------------------------------------- 1 | package com.dabomstew.pkrandom.pokemon; 2 | 3 | /*----------------------------------------------------------------------------*/ 4 | /*-- MoveLearnt.java - represents a move learnt by a Pokemon at a level. --*/ 5 | /*-- --*/ 6 | /*-- Part of "Universal Pokemon Randomizer" by Dabomstew --*/ 7 | /*-- Pokemon and any associated names and the like are --*/ 8 | /*-- trademark and (C) Nintendo 1996-2012. --*/ 9 | /*-- --*/ 10 | /*-- The custom code written here is licensed under the terms of the GPL: --*/ 11 | /*-- --*/ 12 | /*-- This program is free software: you can redistribute it and/or modify --*/ 13 | /*-- it under the terms of the GNU General Public License as published by --*/ 14 | /*-- the Free Software Foundation, either version 3 of the License, or --*/ 15 | /*-- (at your option) any later version. --*/ 16 | /*-- --*/ 17 | /*-- This program is distributed in the hope that it will be useful, --*/ 18 | /*-- but WITHOUT ANY WARRANTY; without even the implied warranty of --*/ 19 | /*-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the --*/ 20 | /*-- GNU General Public License for more details. --*/ 21 | /*-- --*/ 22 | /*-- You should have received a copy of the GNU General Public License --*/ 23 | /*-- along with this program. If not, see . --*/ 24 | /*----------------------------------------------------------------------------*/ 25 | 26 | public class MoveLearnt { 27 | 28 | public int move; 29 | public int level; 30 | 31 | public String toString() { 32 | return "move " + move + " at level " + level; 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/com/dabomstew/pkrandom/pokemon/ItemList.java: -------------------------------------------------------------------------------- 1 | package com.dabomstew.pkrandom.pokemon; 2 | 3 | import java.util.Random; 4 | 5 | public class ItemList { 6 | 7 | private boolean[] items; 8 | private boolean[] tms; 9 | 10 | public ItemList(int highestIndex) { 11 | items = new boolean[highestIndex + 1]; 12 | tms = new boolean[highestIndex + 1]; 13 | for (int i = 1; i <= highestIndex; i++) { 14 | items[i] = true; 15 | } 16 | } 17 | 18 | public boolean isTM(int index) { 19 | if (index < 0 || index >= tms.length) { 20 | return false; 21 | } 22 | return tms[index]; 23 | } 24 | 25 | public boolean isAllowed(int index) { 26 | if (index < 0 || index >= tms.length) { 27 | return false; 28 | } 29 | return items[index]; 30 | } 31 | 32 | public void banSingles(int... indexes) { 33 | for (int index : indexes) { 34 | items[index] = false; 35 | } 36 | } 37 | 38 | public void banRange(int startIndex, int length) { 39 | for (int i = 0; i < length; i++) { 40 | items[i + startIndex] = false; 41 | } 42 | } 43 | 44 | public void tmRange(int startIndex, int length) { 45 | for (int i = 0; i < length; i++) { 46 | tms[i + startIndex] = true; 47 | } 48 | } 49 | 50 | public int randomItem(Random random) { 51 | int chosen = 0; 52 | while (!items[chosen]) { 53 | chosen = random.nextInt(items.length); 54 | } 55 | return chosen; 56 | } 57 | 58 | public int randomNonTM(Random random) { 59 | int chosen = 0; 60 | while (!items[chosen] || tms[chosen]) { 61 | chosen = random.nextInt(items.length); 62 | } 63 | return chosen; 64 | } 65 | 66 | public int randomTM(Random random) { 67 | int chosen = 0; 68 | while (!tms[chosen]) { 69 | chosen = random.nextInt(items.length); 70 | } 71 | return chosen; 72 | } 73 | 74 | public ItemList copy() { 75 | ItemList other = new ItemList(items.length - 1); 76 | System.arraycopy(items, 0, other.items, 0, items.length); 77 | System.arraycopy(tms, 0, other.tms, 0, tms.length); 78 | return other; 79 | } 80 | 81 | } 82 | -------------------------------------------------------------------------------- /src/com/dabomstew/pkrandom/pokemon/Encounter.java: -------------------------------------------------------------------------------- 1 | package com.dabomstew.pkrandom.pokemon; 2 | 3 | /*----------------------------------------------------------------------------*/ 4 | /*-- Encounter.java - contains one wild Pokemon slot --*/ 5 | /*-- --*/ 6 | /*-- Part of "Universal Pokemon Randomizer" by Dabomstew --*/ 7 | /*-- Pokemon and any associated names and the like are --*/ 8 | /*-- trademark and (C) Nintendo 1996-2012. --*/ 9 | /*-- --*/ 10 | /*-- The custom code written here is licensed under the terms of the GPL: --*/ 11 | /*-- --*/ 12 | /*-- This program is free software: you can redistribute it and/or modify --*/ 13 | /*-- it under the terms of the GNU General Public License as published by --*/ 14 | /*-- the Free Software Foundation, either version 3 of the License, or --*/ 15 | /*-- (at your option) any later version. --*/ 16 | /*-- --*/ 17 | /*-- This program is distributed in the hope that it will be useful, --*/ 18 | /*-- but WITHOUT ANY WARRANTY; without even the implied warranty of --*/ 19 | /*-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the --*/ 20 | /*-- GNU General Public License for more details. --*/ 21 | /*-- --*/ 22 | /*-- You should have received a copy of the GNU General Public License --*/ 23 | /*-- along with this program. If not, see . --*/ 24 | /*----------------------------------------------------------------------------*/ 25 | 26 | public class Encounter { 27 | 28 | public int level; 29 | public int maxLevel; 30 | public Pokemon pokemon; 31 | 32 | public String toString() { 33 | if (pokemon == null) { 34 | return "ERROR"; 35 | } 36 | if (maxLevel == 0) { 37 | return pokemon.name + " Lv" + level; 38 | } else { 39 | return pokemon.name + " Lvs " + level + "-" + maxLevel; 40 | } 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/com/dabomstew/pkrandom/pokemon/TrainerPokemon.java: -------------------------------------------------------------------------------- 1 | package com.dabomstew.pkrandom.pokemon; 2 | 3 | /*----------------------------------------------------------------------------*/ 4 | /*-- TrainerPokemon.java - represents a Pokemon owned by a trainer. --*/ 5 | /*-- --*/ 6 | /*-- Part of "Universal Pokemon Randomizer" by Dabomstew --*/ 7 | /*-- Pokemon and any associated names and the like are --*/ 8 | /*-- trademark and (C) Nintendo 1996-2012. --*/ 9 | /*-- --*/ 10 | /*-- The custom code written here is licensed under the terms of the GPL: --*/ 11 | /*-- --*/ 12 | /*-- This program is free software: you can redistribute it and/or modify --*/ 13 | /*-- it under the terms of the GNU General Public License as published by --*/ 14 | /*-- the Free Software Foundation, either version 3 of the License, or --*/ 15 | /*-- (at your option) any later version. --*/ 16 | /*-- --*/ 17 | /*-- This program is distributed in the hope that it will be useful, --*/ 18 | /*-- but WITHOUT ANY WARRANTY; without even the implied warranty of --*/ 19 | /*-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the --*/ 20 | /*-- GNU General Public License for more details. --*/ 21 | /*-- --*/ 22 | /*-- You should have received a copy of the GNU General Public License --*/ 23 | /*-- along with this program. If not, see . --*/ 24 | /*----------------------------------------------------------------------------*/ 25 | 26 | public class TrainerPokemon { 27 | 28 | public Pokemon pokemon; 29 | public int level; 30 | 31 | public int move1; 32 | public int move2; 33 | public int move3; 34 | public int move4; 35 | 36 | public int AILevel; 37 | public int heldItem; 38 | public int ability; 39 | 40 | public boolean resetMoves = false; 41 | 42 | public String toString() { 43 | return pokemon.name + " Lv" + level; 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/com/dabomstew/pkrandom/pokemon/EncounterSet.java: -------------------------------------------------------------------------------- 1 | package com.dabomstew.pkrandom.pokemon; 2 | 3 | /*----------------------------------------------------------------------------*/ 4 | /*-- EncounterSet.java - contains a group of wild Pokemon --*/ 5 | /*-- --*/ 6 | /*-- Part of "Universal Pokemon Randomizer" by Dabomstew --*/ 7 | /*-- Pokemon and any associated names and the like are --*/ 8 | /*-- trademark and (C) Nintendo 1996-2012. --*/ 9 | /*-- --*/ 10 | /*-- The custom code written here is licensed under the terms of the GPL: --*/ 11 | /*-- --*/ 12 | /*-- This program is free software: you can redistribute it and/or modify --*/ 13 | /*-- it under the terms of the GNU General Public License as published by --*/ 14 | /*-- the Free Software Foundation, either version 3 of the License, or --*/ 15 | /*-- (at your option) any later version. --*/ 16 | /*-- --*/ 17 | /*-- This program is distributed in the hope that it will be useful, --*/ 18 | /*-- but WITHOUT ANY WARRANTY; without even the implied warranty of --*/ 19 | /*-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the --*/ 20 | /*-- GNU General Public License for more details. --*/ 21 | /*-- --*/ 22 | /*-- You should have received a copy of the GNU General Public License --*/ 23 | /*-- along with this program. If not, see . --*/ 24 | /*----------------------------------------------------------------------------*/ 25 | 26 | import java.util.ArrayList; 27 | import java.util.HashSet; 28 | import java.util.List; 29 | import java.util.Set; 30 | 31 | public class EncounterSet { 32 | 33 | public int rate; 34 | public List encounters = new ArrayList(); 35 | public Set bannedPokemon = new HashSet(); 36 | public String displayName; 37 | public int offset; 38 | 39 | public String toString() { 40 | return "Encounter [Rate = " + rate + ", Encounters = " + encounters + "]"; 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/com/dabomstew/pkrandom/pokemon/Move.java: -------------------------------------------------------------------------------- 1 | package com.dabomstew.pkrandom.pokemon; 2 | 3 | /*----------------------------------------------------------------------------*/ 4 | /*-- Move.java - represents a move usable by Pokemon. --*/ 5 | /*-- --*/ 6 | /*-- Part of "Universal Pokemon Randomizer" by Dabomstew --*/ 7 | /*-- Pokemon and any associated names and the like are --*/ 8 | /*-- trademark and (C) Nintendo 1996-2012. --*/ 9 | /*-- --*/ 10 | /*-- The custom code written here is licensed under the terms of the GPL: --*/ 11 | /*-- --*/ 12 | /*-- This program is free software: you can redistribute it and/or modify --*/ 13 | /*-- it under the terms of the GNU General Public License as published by --*/ 14 | /*-- the Free Software Foundation, either version 3 of the License, or --*/ 15 | /*-- (at your option) any later version. --*/ 16 | /*-- --*/ 17 | /*-- This program is distributed in the hope that it will be useful, --*/ 18 | /*-- but WITHOUT ANY WARRANTY; without even the implied warranty of --*/ 19 | /*-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the --*/ 20 | /*-- GNU General Public License for more details. --*/ 21 | /*-- --*/ 22 | /*-- You should have received a copy of the GNU General Public License --*/ 23 | /*-- along with this program. If not, see . --*/ 24 | /*----------------------------------------------------------------------------*/ 25 | 26 | public class Move { 27 | 28 | public String name; 29 | public int number; 30 | public int internalId; 31 | public int power; 32 | public int pp; 33 | public double hitratio; 34 | public Type type; 35 | public int effectIndex; 36 | public MoveCategory category; 37 | public double hitCount = 1; // not saved, only used in randomized move powers. 38 | 39 | public String toString() { 40 | return "#" + number + " " + name + " - Power: " + power + ", Base PP: " + pp + ", Type: " + type + ", Hit%: " 41 | + (hitratio) + ", Effect: " + effectIndex; 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/com/dabomstew/pkrandom/pokemon/EvolutionType.java: -------------------------------------------------------------------------------- 1 | package com.dabomstew.pkrandom.pokemon; 2 | 3 | public enum EvolutionType { 4 | /* @formatter:off */ 5 | LEVEL(1, 1, 4, 4, 4), 6 | STONE(2, 2, 7, 7, 8), 7 | TRADE(3, 3, 5, 5, 5), 8 | TRADE_ITEM(-1, 3, 6, 6, 6), 9 | HAPPINESS(-1, 4, 1, 1, 1), 10 | HAPPINESS_DAY(-1, 4, 2, 2, 2), 11 | HAPPINESS_NIGHT(-1, 4, 3, 3, 3), 12 | LEVEL_ATTACK_HIGHER(-1, 5, 8, 8, 9), 13 | LEVEL_DEFENSE_HIGHER(-1, 5, 10, 10, 11), 14 | LEVEL_ATK_DEF_SAME(-1, 5, 9, 9, 10), 15 | LEVEL_LOW_PV(-1, -1, 11, 11, 12), 16 | LEVEL_HIGH_PV(-1, -1, 12, 12, 13), 17 | LEVEL_CREATE_EXTRA(-1, -1, 13, 13, 14), 18 | LEVEL_IS_EXTRA(-1, -1, 14, 14, 15), 19 | LEVEL_HIGH_BEAUTY(-1, -1, 15, 15, 16), 20 | STONE_MALE_ONLY(-1, -1, -1, 16, 17), 21 | STONE_FEMALE_ONLY(-1, -1, -1, 17, 18), 22 | LEVEL_ITEM_DAY(-1, -1, -1, 18, 19), 23 | LEVEL_ITEM_NIGHT(-1, -1, -1, 19, 20), 24 | LEVEL_WITH_MOVE(-1, -1, -1, 20, 21), 25 | LEVEL_WITH_OTHER(-1, -1, -1, 21, 22), 26 | LEVEL_MALE_ONLY(-1, -1, -1, 22, 23), 27 | LEVEL_FEMALE_ONLY(-1, -1, -1, 23, 24), 28 | LEVEL_ELECTRIFIED_AREA(-1, -1, -1, 24, 25), 29 | LEVEL_MOSS_ROCK(-1, -1, -1, 25, 26), 30 | LEVEL_ICY_ROCK(-1, -1, -1, 26, 27), 31 | TRADE_SPECIAL(-1, -1, -1, -1, 7), 32 | NONE(-1, -1, -1, -1, -1); 33 | /* @formatter:on */ 34 | 35 | private int[] indexNumbers; 36 | private static EvolutionType[][] reverseIndexes = new EvolutionType[5][30]; 37 | 38 | static { 39 | for (EvolutionType et : EvolutionType.values()) { 40 | for (int i = 0; i < et.indexNumbers.length; i++) { 41 | if (et.indexNumbers[i] > 0 && reverseIndexes[i][et.indexNumbers[i]] == null) { 42 | reverseIndexes[i][et.indexNumbers[i]] = et; 43 | } 44 | } 45 | } 46 | } 47 | 48 | private EvolutionType(int... indexes) { 49 | this.indexNumbers = indexes; 50 | } 51 | 52 | public int toIndex(int generation) { 53 | return indexNumbers[generation - 1]; 54 | } 55 | 56 | public static EvolutionType fromIndex(int generation, int index) { 57 | return reverseIndexes[generation - 1][index]; 58 | } 59 | 60 | public boolean usesLevel() { 61 | return (this == LEVEL) || (this == LEVEL_ATTACK_HIGHER) || (this == LEVEL_DEFENSE_HIGHER) 62 | || (this == LEVEL_ATK_DEF_SAME) || (this == LEVEL_LOW_PV) || (this == LEVEL_HIGH_PV) 63 | || (this == LEVEL_CREATE_EXTRA) || (this == LEVEL_IS_EXTRA) || (this == LEVEL_MALE_ONLY) 64 | || (this == LEVEL_FEMALE_ONLY); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/com/dabomstew/pkrandom/exceptions/InvalidSupplementFilesException.java: -------------------------------------------------------------------------------- 1 | package com.dabomstew.pkrandom.exceptions; 2 | 3 | /*----------------------------------------------------------------------------*/ 4 | /*-- InvalidSupplementFilesException.java - thrown when the trainer class --*/ 5 | /*-- or trainer name files found are--*/ 6 | /*-- different from those of the --*/ 7 | /*-- preset creator. --*/ 8 | /*-- --*/ 9 | /*-- Part of "Universal Pokemon Randomizer" by Dabomstew --*/ 10 | /*-- Pokemon and any associated names and the like are --*/ 11 | /*-- trademark and (C) Nintendo 1996-2012. --*/ 12 | /*-- --*/ 13 | /*-- The custom code written here is licensed under the terms of the GPL: --*/ 14 | /*-- --*/ 15 | /*-- This program is free software: you can redistribute it and/or modify --*/ 16 | /*-- it under the terms of the GNU General Public License as published by --*/ 17 | /*-- the Free Software Foundation, either version 3 of the License, or --*/ 18 | /*-- (at your option) any later version. --*/ 19 | /*-- --*/ 20 | /*-- This program is distributed in the hope that it will be useful, --*/ 21 | /*-- but WITHOUT ANY WARRANTY; without even the implied warranty of --*/ 22 | /*-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the --*/ 23 | /*-- GNU General Public License for more details. --*/ 24 | /*-- --*/ 25 | /*-- You should have received a copy of the GNU General Public License --*/ 26 | /*-- along with this program. If not, see . --*/ 27 | /*----------------------------------------------------------------------------*/ 28 | 29 | public class InvalidSupplementFilesException extends Exception { 30 | 31 | /** 32 | * 33 | */ 34 | private static final long serialVersionUID = -3778498838677886358L; 35 | 36 | public enum Type { 37 | UNKNOWN, TOO_SHORT, CUSTOM_NAMES 38 | } 39 | 40 | private final Type type; 41 | 42 | public InvalidSupplementFilesException(Type type, String message) { 43 | super(message); 44 | this.type = type; 45 | } 46 | 47 | public Type getType() { 48 | return type; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/com/dabomstew/pkrandom/config/realistic_gen1_english.tbl: -------------------------------------------------------------------------------- 1 | 01=□ 2 | 02=□ 3 | 03=□ 4 | 04=□ 5 | 05=□ 6 | 06=□ 7 | 07=□ 8 | 08=□ 9 | 09=□ 10 | 0A=□ 11 | 0B=□ 12 | 0C=□ 13 | 0D=□ 14 | 0E=□ 15 | 0F=□ 16 | 10=□ 17 | 11=□ 18 | 12=□ 19 | 13=□ 20 | 14=□ 21 | 15=□ 22 | 16=□ 23 | 17=□ 24 | 18=□ 25 | 19=□ 26 | 1A=□ 27 | 1B=□ 28 | 1C=□ 29 | 1D=□ 30 | 1E=□ 31 | 1F=□ 32 | 20=□ 33 | 21=□ 34 | 22=□ 35 | 23=□ 36 | 24=□ 37 | 25=□ 38 | 26=□ 39 | 27=□ 40 | 28=□ 41 | 29=□ 42 | 2A=□ 43 | 2B=□ 44 | 2C=□ 45 | 2D=□ 46 | 2E=□ 47 | 2F=□ 48 | 30=□ 49 | 31=□ 50 | 32=□ 51 | 33=□ 52 | 34=□ 53 | 35=□ 54 | 36=□ 55 | 37=□ 56 | 38=□ 57 | 39=□ 58 | 3A=□ 59 | 3B=□ 60 | 3C=□ 61 | 3D=□ 62 | 3E=□ 63 | 3F=□ 64 | 40=□ 65 | 41=□ 66 | 42=□ 67 | 43=□ 68 | 44=□ 69 | 45=□ 70 | 46=□ 71 | 47=□ 72 | 48=□ 73 | 49=[49] 74 | 4A=[PKMN] 75 | 4B=[4B] 76 | 4C=[4C] 77 | 4D=□ 78 | 4E=[4E] 79 | 4F=\n 80 | 51=\p 81 | 52=[Player] 82 | 53=[Rival] 83 | 54=POKé 84 | 55=\l 85 | 56=…… 86 | 57=\e 87 | 58=\x 88 | 59=[OtherMon] 89 | 5A=[CurrentMon] 90 | 5B=PC 91 | 5C=TM 92 | 5D=TRAINER 93 | 5E=ROCKET 94 | 5F=. 95 | 60=ᴀ 96 | 61=ʙ 97 | 62=ᴄ 98 | 63=ᴅ 99 | 64=ᴇ 100 | 65=ғ 101 | 66=ɢ 102 | 67=ʜ 103 | 68=ɪ 104 | 69=ᴠ 105 | 6A=s 106 | 6B=ʟ 107 | 6C=ᴍ 108 | 6D=: 109 | 6E=ぃ 110 | 6F=ぅ 111 | 70=‘ 112 | 71=’ 113 | 72=“ 114 | 73=” 115 | 74=• 116 | 75=… 117 | 76=ぁ 118 | 77=ぇ 119 | 78=ぉ 120 | 79=┌ 121 | 7A=─ 122 | 7B=┐ 123 | 7C=│ 124 | 7D=└ 125 | 7E=┘ 126 | 7F= 127 | 80=A 128 | 81=B 129 | 82=C 130 | 83=D 131 | 84=E 132 | 85=F 133 | 86=G 134 | 87=H 135 | 88=I 136 | 89=J 137 | 8A=K 138 | 8B=L 139 | 8C=M 140 | 8D=N 141 | 8E=O 142 | 8F=P 143 | 90=Q 144 | 91=R 145 | 92=S 146 | 93=T 147 | 94=U 148 | 95=V 149 | 96=W 150 | 97=X 151 | 98=Y 152 | 99=Z 153 | 9A=( 154 | 9B=) 155 | 9C=: 156 | 9D=; 157 | 9E=[ 158 | 9F=] 159 | A0=a 160 | A1=b 161 | A2=c 162 | A3=d 163 | A4=e 164 | A5=f 165 | A6=g 166 | A7=h 167 | A8=i 168 | A9=j 169 | AA=k 170 | AB=l 171 | AC=m 172 | AD=n 173 | AE=o 174 | AF=p 175 | B0=q 176 | B1=r 177 | B2=s 178 | B3=t 179 | B4=u 180 | B5=v 181 | B6=w 182 | B7=x 183 | B8=y 184 | B9=z 185 | BA=é 186 | BB='d 187 | BC='l 188 | BD='s 189 | BE='t 190 | BF='v 191 | C0= 192 | C1= 193 | C2= 194 | C3= 195 | C4= 196 | C5= 197 | C6= 198 | C7= 199 | C8= 200 | C9= 201 | CA= 202 | CB= 203 | CC= 204 | CD= 205 | CE= 206 | CF= 207 | D0= 208 | D1= 209 | D2= 210 | D3= 211 | D4= 212 | D5= 213 | D6= 214 | D7= 215 | D8= 216 | D9= 217 | DA= 218 | DB= 219 | DC= 220 | DD= 221 | DE= 222 | DF= 223 | E0=' 224 | E1=PK 225 | E2=MN 226 | E3=- 227 | E4='r 228 | E5='m 229 | E6=? 230 | E7=! 231 | E8=. 232 | E9=ァ 233 | EA=ゥ 234 | EB=ェ 235 | EC=˃ 236 | ED=˃ 237 | EE=˅ 238 | EF=♂ 239 | F0=$ 240 | F1=× 241 | F2=. 242 | F3=/ 243 | F4=, 244 | F5=♀ 245 | F6=0 246 | F7=1 247 | F8=2 248 | F9=3 249 | FA=4 250 | FB=5 251 | FC=6 252 | FD=7 253 | FE=8 254 | FF=9 -------------------------------------------------------------------------------- /src/com/dabomstew/pkrandom/pokemon/GenRestrictions.java: -------------------------------------------------------------------------------- 1 | package com.dabomstew.pkrandom.pokemon; 2 | 3 | public class GenRestrictions { 4 | 5 | public boolean allow_gen1, allow_gen2, allow_gen3, allow_gen4, allow_gen5; 6 | 7 | public boolean assoc_g1_g2, assoc_g1_g4; 8 | public boolean assoc_g2_g1, assoc_g2_g3, assoc_g2_g4; 9 | public boolean assoc_g3_g2, assoc_g3_g4; 10 | public boolean assoc_g4_g1, assoc_g4_g2, assoc_g4_g3; 11 | 12 | public GenRestrictions() { 13 | } 14 | 15 | public GenRestrictions(int state) { 16 | allow_gen1 = (state & 1) > 0; 17 | allow_gen2 = (state & 2) > 0; 18 | allow_gen3 = (state & 4) > 0; 19 | allow_gen4 = (state & 8) > 0; 20 | allow_gen5 = (state & 16) > 0; 21 | 22 | assoc_g1_g2 = (state & 32) > 0; 23 | assoc_g1_g4 = (state & 64) > 0; 24 | 25 | assoc_g2_g1 = (state & 128) > 0; 26 | assoc_g2_g3 = (state & 256) > 0; 27 | assoc_g2_g4 = (state & 512) > 0; 28 | 29 | assoc_g3_g2 = (state & 1024) > 0; 30 | assoc_g3_g4 = (state & 2048) > 0; 31 | 32 | assoc_g4_g1 = (state & 4096) > 0; 33 | assoc_g4_g2 = (state & 8192) > 0; 34 | assoc_g4_g3 = (state & 16384) > 0; 35 | } 36 | 37 | public boolean nothingSelected() { 38 | return !allow_gen1 && !allow_gen2 && !allow_gen3 && !allow_gen4 && !allow_gen5; 39 | } 40 | 41 | public int toInt() { 42 | return makeIntSelected(allow_gen1, allow_gen2, allow_gen3, allow_gen4, allow_gen5, assoc_g1_g2, assoc_g1_g4, 43 | assoc_g2_g1, assoc_g2_g3, assoc_g2_g4, assoc_g3_g2, assoc_g3_g4, assoc_g4_g1, assoc_g4_g2, assoc_g4_g3); 44 | } 45 | 46 | public void limitToGen(int generation) { 47 | if (generation < 2) { 48 | allow_gen2 = false; 49 | assoc_g1_g2 = false; 50 | assoc_g2_g1 = false; 51 | } 52 | if (generation < 3) { 53 | allow_gen3 = false; 54 | assoc_g2_g3 = false; 55 | assoc_g3_g2 = false; 56 | } 57 | if (generation < 4) { 58 | allow_gen4 = false; 59 | assoc_g1_g4 = false; 60 | assoc_g2_g4 = false; 61 | assoc_g3_g4 = false; 62 | assoc_g4_g1 = false; 63 | assoc_g4_g2 = false; 64 | assoc_g4_g3 = false; 65 | } 66 | if (generation < 5) { 67 | allow_gen5 = false; 68 | } 69 | } 70 | 71 | private int makeIntSelected(boolean... switches) { 72 | if (switches.length > 32) { 73 | // No can do 74 | return 0; 75 | } 76 | int initial = 0; 77 | int state = 1; 78 | for (boolean b : switches) { 79 | initial |= b ? state : 0; 80 | state *= 2; 81 | } 82 | return initial; 83 | } 84 | 85 | } 86 | -------------------------------------------------------------------------------- /src/com/dabomstew/pkrandom/gui/QSFileFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | package com.dabomstew.pkrandom.gui; 6 | 7 | /*----------------------------------------------------------------------------*/ 8 | /*-- PresetFileFilter.java - a file filter for the "randomization presets" --*/ 9 | /*-- which allow the same random ROM to be produced--*/ 10 | /*-- on demand. --*/ 11 | /*-- --*/ 12 | /*-- Part of "Universal Pokemon Randomizer" by Dabomstew --*/ 13 | /*-- Pokemon and any associated names and the like are --*/ 14 | /*-- trademark and (C) Nintendo 1996-2012. --*/ 15 | /*-- --*/ 16 | /*-- The custom code written here is licensed under the terms of the GPL: --*/ 17 | /*-- --*/ 18 | /*-- This program is free software: you can redistribute it and/or modify --*/ 19 | /*-- it under the terms of the GNU General Public License as published by --*/ 20 | /*-- the Free Software Foundation, either version 3 of the License, or --*/ 21 | /*-- (at your option) any later version. --*/ 22 | /*-- --*/ 23 | /*-- This program is distributed in the hope that it will be useful, --*/ 24 | /*-- but WITHOUT ANY WARRANTY; without even the implied warranty of --*/ 25 | /*-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the --*/ 26 | /*-- GNU General Public License for more details. --*/ 27 | /*-- --*/ 28 | /*-- You should have received a copy of the GNU General Public License --*/ 29 | /*-- along with this program. If not, see . --*/ 30 | /*----------------------------------------------------------------------------*/ 31 | 32 | import java.io.File; 33 | 34 | import javax.swing.filechooser.FileFilter; 35 | 36 | public class QSFileFilter extends FileFilter { 37 | 38 | @Override 39 | public boolean accept(File arg0) { 40 | if (arg0.isDirectory()) { 41 | return true; // needed to allow directory navigation 42 | } 43 | String filename = arg0.getName(); 44 | if (filename.contains(".") == false) { 45 | return false; 46 | } 47 | String extension = arg0.getName().substring(arg0.getName().lastIndexOf('.') + 1); 48 | return extension.toLowerCase().equals("rnqs"); 49 | } 50 | 51 | @Override 52 | public String getDescription() { 53 | return "Randomization Quick Settings (*.rnqs)"; 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /src/com/dabomstew/pkrandom/config/gba_jap.tbl: -------------------------------------------------------------------------------- 1 | 00= 2 | 01=あ 3 | 02=い 4 | 03=う 5 | 04=え 6 | 05=お 7 | 06=か 8 | 07=き 9 | 08=く 10 | 09=け 11 | 0A=こ 12 | 0B=さ 13 | 0C=し 14 | 0D=す 15 | 0E=せ 16 | 0F=そ 17 | 10=た 18 | 11=ち 19 | 12=つ 20 | 13=て 21 | 14=と 22 | 15=な 23 | 16=に 24 | 17=ぬ 25 | 18=ね 26 | 19=の 27 | 1A=は 28 | 1B=ひ 29 | 1C=ふ 30 | 1D=へ 31 | 1E=ほ 32 | 1F=ま 33 | 20=み 34 | 21=む 35 | 22=め 36 | 23=も 37 | 24=や 38 | 25=ゆ 39 | 26=よ 40 | 27=ら 41 | 28=り 42 | 29=る 43 | 2A=れ 44 | 2B=ろ 45 | 2C=わ 46 | 2D=を 47 | 2E=ん 48 | 2F=ぁ 49 | 30=ぃ 50 | 31=ぅ 51 | 32=ぇ 52 | 33=ぉ 53 | 34=ゃ 54 | 35=ゅ 55 | 36=ょ 56 | 37=が 57 | 38=ぎ 58 | 39=ぐ 59 | 3A=げ 60 | 3B=ご 61 | 3C=ざ 62 | 3D=じ 63 | 3E=ず 64 | 3F=ぜ 65 | 40=ぞ 66 | 41=だ 67 | 42=ぢ 68 | 43=づ 69 | 44=で 70 | 45=ど 71 | 46=ば 72 | 47=び 73 | 48=ぶ 74 | 49=べ 75 | 4A=ぼ 76 | 4B=ぱ 77 | 4C=ぴ 78 | 4D=ぷ 79 | 4E=ぺ 80 | 4F=ぽ 81 | 50=っ 82 | 51=ア 83 | 52=イ 84 | 53=ウ 85 | 54=エ 86 | 55=オ 87 | 56=カ 88 | 57=キ 89 | 58=ク 90 | 59=ケ 91 | 5A=コ 92 | 5B=サ 93 | 5C=シ 94 | 5D=ス 95 | 5E=セ 96 | 5F=ソ 97 | 60=タ 98 | 61=チ 99 | 62=ツ 100 | 63=テ 101 | 64=ト 102 | 65=ナ 103 | 66=ニ 104 | 67=ヌ 105 | 68=ネ 106 | 69=ノ 107 | 6A=ハ 108 | 6B=ヒ 109 | 6C=フ 110 | 6D=ヘ 111 | 6E=ホ 112 | 6F=マ 113 | 70=ミ 114 | 71=ム 115 | 72=メ 116 | 73=モ 117 | 74=ヤ 118 | 75=ユ 119 | 76=ヨ 120 | 77=ラ 121 | 78=リ 122 | 79=ル 123 | 7A=レ 124 | 7B=ロ 125 | 7C=ワ 126 | 7D=ヲ 127 | 7E=ン 128 | 7F=ァ 129 | 80=ィ 130 | 81=ゥ 131 | 82=ェ 132 | 83=ォ 133 | 84=ャ 134 | 85=ュ 135 | 86=ョ 136 | 87=ガ 137 | 88=ギ 138 | 89=グ 139 | 8A=ゲ 140 | 8B=ゴ 141 | 8C=ザ 142 | 8D=ジ 143 | 8E=ズ 144 | 8F=ゼ 145 | 90=ゾ 146 | 91=ダ 147 | 92=ヂ 148 | 93=ヅ 149 | 94=デ 150 | 95=ド 151 | 96=バ 152 | 97=ビ 153 | 98=ブ 154 | 99=ベ 155 | 9A=ボ 156 | 9B=パ 157 | 9C=ピ 158 | 9D=プ 159 | 9E=ペ 160 | 9F=ポ 161 | A0=ッ 162 | A1=0 163 | A2=1 164 | A3=2 165 | A4=3 166 | A5=4 167 | A6=5 168 | A7=6 169 | A8=7 170 | A9=8 171 | AA=9 172 | AB=! 173 | AC=? 174 | AD=. 175 | AE=ー 176 | AF=キ 177 | B0=封 178 | B1=ォ 179 | B2=サ 180 | B3=< 181 | B4=> 182 | B5=♂ 183 | B6=♀ 184 | B7=$ 185 | B8=, 186 | B9=* 187 | BA=/ 188 | BB=A 189 | BC=B 190 | BD=C 191 | BE=D 192 | BF=E 193 | C0=F 194 | C1=G 195 | C2=H 196 | C3=I 197 | C4=J 198 | C5=K 199 | C6=L 200 | C7=M 201 | C8=N 202 | C9=O 203 | CA=P 204 | CB=Q 205 | CC=R 206 | CD=S 207 | CE=T 208 | CF=U 209 | D0=V 210 | D1=W 211 | D2=X 212 | D3=Y 213 | D4=Z 214 | D5=a 215 | D6=b 216 | D7=c 217 | D8=d 218 | D9=e 219 | DA=f 220 | DB=g 221 | DC=h 222 | DD=i 223 | DE=j 224 | DF=k 225 | E0=l 226 | E1=m 227 | E2=n 228 | E3=o 229 | E4=p 230 | E5=q 231 | E6=r 232 | E7=s 233 | E8=t 234 | E9=u 235 | EA=v 236 | EB=w 237 | EC=x 238 | ED=y 239 | EE=z 240 | EF=[>] 241 | F0=: 242 | F1=ト 243 | F2=ヨ 244 | F3=ワ 245 | F4=ä 246 | F5=ö 247 | F6=ü 248 | F7=[u] 249 | F8=[d] 250 | F9=[l] 251 | FA=\l 252 | FB=\p 253 | FC=\c 254 | FE=\n 255 | -------------------------------------------------------------------------------- /src/com/dabomstew/pkrandom/gui/PresetFileFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | package com.dabomstew.pkrandom.gui; 6 | 7 | /*----------------------------------------------------------------------------*/ 8 | /*-- PresetFileFilter.java - a file filter for the "randomization presets" --*/ 9 | /*-- which allow the same random ROM to be produced--*/ 10 | /*-- on demand. --*/ 11 | /*-- --*/ 12 | /*-- Part of "Universal Pokemon Randomizer" by Dabomstew --*/ 13 | /*-- Pokemon and any associated names and the like are --*/ 14 | /*-- trademark and (C) Nintendo 1996-2012. --*/ 15 | /*-- --*/ 16 | /*-- The custom code written here is licensed under the terms of the GPL: --*/ 17 | /*-- --*/ 18 | /*-- This program is free software: you can redistribute it and/or modify --*/ 19 | /*-- it under the terms of the GNU General Public License as published by --*/ 20 | /*-- the Free Software Foundation, either version 3 of the License, or --*/ 21 | /*-- (at your option) any later version. --*/ 22 | /*-- --*/ 23 | /*-- This program is distributed in the hope that it will be useful, --*/ 24 | /*-- but WITHOUT ANY WARRANTY; without even the implied warranty of --*/ 25 | /*-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the --*/ 26 | /*-- GNU General Public License for more details. --*/ 27 | /*-- --*/ 28 | /*-- You should have received a copy of the GNU General Public License --*/ 29 | /*-- along with this program. If not, see . --*/ 30 | /*----------------------------------------------------------------------------*/ 31 | 32 | import java.io.File; 33 | 34 | import javax.swing.filechooser.FileFilter; 35 | 36 | public class PresetFileFilter extends FileFilter { 37 | 38 | @Override 39 | public boolean accept(File arg0) { 40 | if (arg0.isDirectory()) { 41 | return true; // needed to allow directory navigation 42 | } 43 | String filename = arg0.getName(); 44 | if (filename.contains(".") == false) { 45 | return false; 46 | } 47 | String extension = arg0.getName().substring( 48 | arg0.getName().lastIndexOf('.') + 1); 49 | return extension.toLowerCase().equals("rndp"); 50 | } 51 | 52 | @Override 53 | public String getDescription() { 54 | return "Pokemon Randomizer Preset (*.rndp)"; 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /src/com/dabomstew/pkrandom/pokemon/Type.java: -------------------------------------------------------------------------------- 1 | package com.dabomstew.pkrandom.pokemon; 2 | 3 | /*----------------------------------------------------------------------------*/ 4 | /*-- Type.java - represents a Pokemon or move type. --*/ 5 | /*-- --*/ 6 | /*-- Part of "Universal Pokemon Randomizer" by Dabomstew --*/ 7 | /*-- Pokemon and any associated names and the like are --*/ 8 | /*-- trademark and (C) Nintendo 1996-2012. --*/ 9 | /*-- --*/ 10 | /*-- The custom code written here is licensed under the terms of the GPL: --*/ 11 | /*-- --*/ 12 | /*-- This program is free software: you can redistribute it and/or modify --*/ 13 | /*-- it under the terms of the GNU General Public License as published by --*/ 14 | /*-- the Free Software Foundation, either version 3 of the License, or --*/ 15 | /*-- (at your option) any later version. --*/ 16 | /*-- --*/ 17 | /*-- This program is distributed in the hope that it will be useful, --*/ 18 | /*-- but WITHOUT ANY WARRANTY; without even the implied warranty of --*/ 19 | /*-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the --*/ 20 | /*-- GNU General Public License for more details. --*/ 21 | /*-- --*/ 22 | /*-- You should have received a copy of the GNU General Public License --*/ 23 | /*-- along with this program. If not, see . --*/ 24 | /*----------------------------------------------------------------------------*/ 25 | 26 | import java.util.Arrays; 27 | import java.util.Collections; 28 | import java.util.List; 29 | import java.util.Random; 30 | 31 | import com.dabomstew.pkrandom.RomFunctions; 32 | 33 | public enum Type { 34 | 35 | NORMAL, FIGHTING, FLYING, GRASS, WATER, FIRE, ROCK, GROUND, PSYCHIC, BUG, DRAGON, ELECTRIC, GHOST, POISON, ICE, STEEL, DARK, GAS( 36 | true), FAIRY(true), WOOD(true), ABNORMAL(true), WIND(true), SOUND(true), LIGHT(true), TRI(true); 37 | 38 | public boolean isHackOnly; 39 | 40 | private Type() { 41 | this.isHackOnly = false; 42 | } 43 | 44 | private Type(boolean isHackOnly) { 45 | this.isHackOnly = isHackOnly; 46 | } 47 | 48 | private static final List VALUES = Collections.unmodifiableList(Arrays.asList(values())); 49 | private static final int SIZE = VALUES.size(); 50 | 51 | public static Type randomType(Random random) { 52 | return VALUES.get(random.nextInt(SIZE)); 53 | } 54 | 55 | public String camelCase() { 56 | return RomFunctions.camelCase(this.toString()); 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /src/com/dabomstew/pkrandom/gui/ROMFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | package com.dabomstew.pkrandom.gui; 6 | 7 | /*----------------------------------------------------------------------------*/ 8 | /*-- ROMFilter.java - a file filter for the various games which can be --*/ 9 | /*-- randomized with this program. --*/ 10 | /*-- --*/ 11 | /*-- Part of "Universal Pokemon Randomizer" by Dabomstew --*/ 12 | /*-- Pokemon and any associated names and the like are --*/ 13 | /*-- trademark and (C) Nintendo 1996-2012. --*/ 14 | /*-- --*/ 15 | /*-- The custom code written here is licensed under the terms of the GPL: --*/ 16 | /*-- --*/ 17 | /*-- This program is free software: you can redistribute it and/or modify --*/ 18 | /*-- it under the terms of the GNU General Public License as published by --*/ 19 | /*-- the Free Software Foundation, either version 3 of the License, or --*/ 20 | /*-- (at your option) any later version. --*/ 21 | /*-- --*/ 22 | /*-- This program is distributed in the hope that it will be useful, --*/ 23 | /*-- but WITHOUT ANY WARRANTY; without even the implied warranty of --*/ 24 | /*-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the --*/ 25 | /*-- GNU General Public License for more details. --*/ 26 | /*-- --*/ 27 | /*-- You should have received a copy of the GNU General Public License --*/ 28 | /*-- along with this program. If not, see . --*/ 29 | /*----------------------------------------------------------------------------*/ 30 | 31 | import java.io.File; 32 | 33 | import javax.swing.filechooser.FileFilter; 34 | 35 | public class ROMFilter extends FileFilter { 36 | 37 | @Override 38 | public boolean accept(File arg0) { 39 | if (arg0.isDirectory()) { 40 | return true; // needed to allow directory navigation 41 | } 42 | String filename = arg0.getName(); 43 | if (filename.contains(".") == false) { 44 | return false; 45 | } 46 | String extension = arg0.getName().substring(arg0.getName().lastIndexOf('.') + 1).toLowerCase(); 47 | return extension.equals("gb") || extension.equals("sgb") || extension.equals("gbc") || extension.equals("gba") 48 | || extension.equals("nds"); 49 | } 50 | 51 | @Override 52 | public String getDescription() { 53 | return "Nintendo GB(C/A)/DS ROM File (*.gb,*.sgb,*.gbc,*.gba,*.nds)"; 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /src/com/dabomstew/pkrandom/SysConstants.java: -------------------------------------------------------------------------------- 1 | package com.dabomstew.pkrandom; 2 | 3 | /*----------------------------------------------------------------------------*/ 4 | /*-- SysConstants.java - contains constants not related to the --*/ 5 | /*-- randomization process itself, such as those --*/ 6 | /*-- relating to file I/O and the updating system. --*/ 7 | /*-- --*/ 8 | /*-- Part of "Universal Pokemon Randomizer" by Dabomstew --*/ 9 | /*-- Pokemon and any associated names and the like are --*/ 10 | /*-- trademark and (C) Nintendo 1996-2012. --*/ 11 | /*-- --*/ 12 | /*-- The custom code written here is licensed under the terms of the GPL: --*/ 13 | /*-- --*/ 14 | /*-- This program is free software: you can redistribute it and/or modify --*/ 15 | /*-- it under the terms of the GNU General Public License as published by --*/ 16 | /*-- the Free Software Foundation, either version 3 of the License, or --*/ 17 | /*-- (at your option) any later version. --*/ 18 | /*-- --*/ 19 | /*-- This program is distributed in the hope that it will be useful, --*/ 20 | /*-- but WITHOUT ANY WARRANTY; without even the implied warranty of --*/ 21 | /*-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the --*/ 22 | /*-- GNU General Public License for more details. --*/ 23 | /*-- --*/ 24 | /*-- You should have received a copy of the GNU General Public License --*/ 25 | /*-- along with this program. If not, see . --*/ 26 | /*----------------------------------------------------------------------------*/ 27 | 28 | import java.io.File; 29 | 30 | public class SysConstants { 31 | 32 | public static final String AUTOUPDATE_URL = "http://pokehacks.dabomstew.com/randomizer/autoupdate/"; 33 | public static final String WEBSITE_URL = "http://pokehacks.dabomstew.com/randomizer/"; 34 | public static final int UPDATE_VERSION = 1721; 35 | public static final String ROOT_PATH = getRootPath(); 36 | public static final String LINE_SEP = System.getProperty("line.separator"); 37 | public static final String customNamesFile = "customnames.rncn"; 38 | 39 | // OLD custom names files 40 | public static final String tnamesFile = "trainernames.txt"; 41 | public static final String tclassesFile = "trainerclasses.txt"; 42 | public static final String nnamesFile = "nicknames.txt"; 43 | 44 | private static String getRootPath() { 45 | try { 46 | File fh = Utils.getExecutionLocation().getParentFile(); 47 | return fh.getAbsolutePath() + File.separator; 48 | } catch (Exception e) { 49 | return "./"; 50 | } 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/com/dabomstew/pkrandom/gui/UpdateCheckThread.java: -------------------------------------------------------------------------------- 1 | package com.dabomstew.pkrandom.gui; 2 | 3 | import java.io.ByteArrayInputStream; 4 | import java.io.IOException; 5 | import java.util.Scanner; 6 | 7 | import javax.swing.SwingUtilities; 8 | 9 | import com.dabomstew.pkrandom.SysConstants; 10 | import com.dabomstew.pkrandom.FileFunctions; 11 | 12 | public class UpdateCheckThread extends Thread { 13 | private RandomizerGUI mainWindow; 14 | private boolean doNotifyNone; 15 | 16 | public UpdateCheckThread(RandomizerGUI mainWindow, boolean doNotifyNone) { 17 | this.mainWindow = mainWindow; 18 | this.doNotifyNone = doNotifyNone; 19 | } 20 | 21 | @Override 22 | public void run() { 23 | boolean found = false; 24 | try { 25 | byte[] versionCheck = FileFunctions.downloadFile(SysConstants.AUTOUPDATE_URL + "latest.txt"); 26 | int version = Integer.parseInt(new String(versionCheck)); 27 | if (version > SysConstants.UPDATE_VERSION) { 28 | byte[] output = FileFunctions.downloadFile(SysConstants.AUTOUPDATE_URL + "version.txt"); 29 | Scanner sc = new Scanner(new ByteArrayInputStream(output)); 30 | final int newVersion = Integer.parseInt(sc.nextLine()); 31 | if (newVersion > SysConstants.UPDATE_VERSION) { 32 | // Update found, parse changelog 33 | StringBuilder changelog = new StringBuilder(); 34 | int clid = Integer.parseInt(sc.nextLine()); 35 | String nl = System.getProperty("line.separator"); 36 | boolean first = true; 37 | while (clid > SysConstants.UPDATE_VERSION && sc.hasNext()) { 38 | if (!first) { 39 | changelog.append(nl); 40 | } 41 | first = false; 42 | String line = sc.nextLine(); 43 | while (line.equals("EOV") == false && sc.hasNext()) { 44 | changelog.append(line + nl); 45 | line = sc.nextLine(); 46 | } 47 | clid = Integer.parseInt(sc.nextLine()); 48 | } 49 | final String doneCL = changelog.toString(); 50 | found = true; 51 | SwingUtilities.invokeLater(new Runnable() { 52 | @Override 53 | public void run() { 54 | mainWindow.updateFound(newVersion, doneCL); 55 | } 56 | }); 57 | } 58 | sc.close(); 59 | } 60 | } catch (IOException ex) { 61 | ex.printStackTrace(); 62 | } catch (NumberFormatException ex) { 63 | ex.printStackTrace(); 64 | } 65 | if (!found && this.doNotifyNone) { 66 | SwingUtilities.invokeLater(new Runnable() { 67 | @Override 68 | public void run() { 69 | mainWindow.noUpdateFound(); 70 | } 71 | }); 72 | } 73 | } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /src/com/dabomstew/pkrandom/constants/GlobalConstants.java: -------------------------------------------------------------------------------- 1 | package com.dabomstew.pkrandom.constants; 2 | 3 | import java.util.Arrays; 4 | import java.util.List; 5 | 6 | public class GlobalConstants { 7 | 8 | public static final boolean[] bannedRandomMoves = new boolean[560], bannedForDamagingMove = new boolean[560]; 9 | static { 10 | bannedRandomMoves[144] = true; // Transform, glitched in RBY 11 | bannedRandomMoves[165] = true; // Struggle, self explanatory 12 | 13 | bannedForDamagingMove[120] = true; // SelfDestruct 14 | bannedForDamagingMove[138] = true; // Dream Eater 15 | bannedForDamagingMove[153] = true; // Explosion 16 | bannedForDamagingMove[173] = true; // Snore 17 | bannedForDamagingMove[206] = true; // False Swipe 18 | bannedForDamagingMove[248] = true; // Future Sight 19 | bannedForDamagingMove[252] = true; // Fake Out 20 | bannedForDamagingMove[264] = true; // Focus Punch 21 | bannedForDamagingMove[353] = true; // Doom Desire 22 | bannedForDamagingMove[364] = true; // Feint 23 | bannedForDamagingMove[387] = true; // Last Resort 24 | bannedForDamagingMove[389] = true; // Sucker Punch 25 | 26 | // new 160 27 | bannedForDamagingMove[132] = true; // Constrict, overly weak 28 | bannedForDamagingMove[99] = true; // Rage, lock-in in gen1 29 | bannedForDamagingMove[205] = true; // Rollout, lock-in 30 | bannedForDamagingMove[301] = true; // Ice Ball, Rollout clone 31 | 32 | // make sure these cant roll 33 | bannedForDamagingMove[39] = true; // Sonicboom 34 | bannedForDamagingMove[82] = true; // Dragon Rage 35 | bannedForDamagingMove[32] = true; // Horn Drill 36 | bannedForDamagingMove[12] = true; // Guillotine 37 | bannedForDamagingMove[90] = true; // Fissure 38 | bannedForDamagingMove[329] = true; // Sheer Cold 39 | 40 | } 41 | 42 | /* @formatter:off */ 43 | public static final List normalMultihitMoves = Arrays.asList( 44 | 292, // Arm Thrust 45 | 140, // Barrage 46 | 198, // Bone Rush 47 | 331, // Bullet Seed 48 | 4, // Comet Punch 49 | 3, // DoubleSlap 50 | 31, // Fury Attack 51 | 154, // Fury Swipes 52 | 333, // Icicle Spear 53 | 42, // Pin Missile 54 | 350, // Rock Blast 55 | 131, // Spike Cannon 56 | 541 // Tail Slap 57 | ); 58 | 59 | public static final List doubleHitMoves = Arrays.asList( 60 | 155, // Bonemerang 61 | 458, // Double Hit 62 | 24, // Double Kick 63 | 530, // Dual Chop 64 | 544, // Gear Grind 65 | 41 // Twineedle 66 | ); 67 | 68 | 69 | /* @formatter:on */ 70 | 71 | public static final List battleTrappingAbilities = Arrays.asList(23, 42, 71); 72 | 73 | public static final List negativeAbilities = Arrays.asList(129, 112, 54, 59, 161); 74 | // Defeatist, Slow Start, Truant, Forecast, Zen Mode 75 | // To test: Illusion, Imposter 76 | 77 | public static final int WONDER_GUARD_INDEX = 25; 78 | 79 | public static final int MIN_DAMAGING_MOVE_POWER = 50; 80 | 81 | public static final int METRONOME_MOVE = 118; 82 | 83 | public static final int TRIPLE_KICK_INDEX = 167; 84 | 85 | } 86 | -------------------------------------------------------------------------------- /src/com/dabomstew/pkrandom/pokemon/Evolution.java: -------------------------------------------------------------------------------- 1 | package com.dabomstew.pkrandom.pokemon; 2 | 3 | /*----------------------------------------------------------------------------*/ 4 | /*-- Evolution.java - represents an evolution between 2 Pokemon. --*/ 5 | /*-- --*/ 6 | /*-- Part of "Universal Pokemon Randomizer" by Dabomstew --*/ 7 | /*-- Pokemon and any associated names and the like are --*/ 8 | /*-- trademark and (C) Nintendo 1996-2012. --*/ 9 | /*-- --*/ 10 | /*-- The custom code written here is licensed under the terms of the GPL: --*/ 11 | /*-- --*/ 12 | /*-- This program is free software: you can redistribute it and/or modify --*/ 13 | /*-- it under the terms of the GNU General Public License as published by --*/ 14 | /*-- the Free Software Foundation, either version 3 of the License, or --*/ 15 | /*-- (at your option) any later version. --*/ 16 | /*-- --*/ 17 | /*-- This program is distributed in the hope that it will be useful, --*/ 18 | /*-- but WITHOUT ANY WARRANTY; without even the implied warranty of --*/ 19 | /*-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the --*/ 20 | /*-- GNU General Public License for more details. --*/ 21 | /*-- --*/ 22 | /*-- You should have received a copy of the GNU General Public License --*/ 23 | /*-- along with this program. If not, see . --*/ 24 | /*----------------------------------------------------------------------------*/ 25 | 26 | public class Evolution implements Comparable { 27 | 28 | public Pokemon from; 29 | public Pokemon to; 30 | public boolean carryStats; 31 | public EvolutionType type; 32 | public int extraInfo; 33 | 34 | public Evolution(Pokemon from, Pokemon to, boolean carryStats, EvolutionType type, int extra) { 35 | this.from = from; 36 | this.to = to; 37 | this.carryStats = carryStats; 38 | this.type = type; 39 | this.extraInfo = extra; 40 | } 41 | 42 | @Override 43 | public int hashCode() { 44 | final int prime = 31; 45 | int result = 1; 46 | result = prime * result + from.number; 47 | result = prime * result + to.number; 48 | result = prime * result + type.ordinal(); 49 | return result; 50 | } 51 | 52 | @Override 53 | public boolean equals(Object obj) { 54 | if (this == obj) 55 | return true; 56 | if (obj == null) 57 | return false; 58 | if (getClass() != obj.getClass()) 59 | return false; 60 | Evolution other = (Evolution) obj; 61 | if (from != other.from) 62 | return false; 63 | if (to != other.to) 64 | return false; 65 | if (type != other.type) 66 | return false; 67 | return true; 68 | } 69 | 70 | @Override 71 | public int compareTo(Evolution o) { 72 | if (this.from.number < o.from.number) { 73 | return -1; 74 | } else if (this.from.number > o.from.number) { 75 | return 1; 76 | } else if (this.to.number < o.to.number) { 77 | return -1; 78 | } else if (this.to.number > o.to.number) { 79 | return 1; 80 | } else if (this.type.ordinal() < o.type.ordinal()) { 81 | return -1; 82 | } else if (this.type.ordinal() > o.type.ordinal()) { 83 | return 1; 84 | } else { 85 | return 0; 86 | } 87 | } 88 | 89 | } 90 | -------------------------------------------------------------------------------- /src/com/dabomstew/pkrandom/gui/OperationDialog.form: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 |
80 | -------------------------------------------------------------------------------- /src/com/dabomstew/pkrandom/pokemon/Trainer.java: -------------------------------------------------------------------------------- 1 | package com.dabomstew.pkrandom.pokemon; 2 | 3 | /*----------------------------------------------------------------------------*/ 4 | /*-- Trainer.java - represents a Trainer's pokemon set/other details. --*/ 5 | /*-- --*/ 6 | /*-- Part of "Universal Pokemon Randomizer" by Dabomstew --*/ 7 | /*-- Pokemon and any associated names and the like are --*/ 8 | /*-- trademark and (C) Nintendo 1996-2012. --*/ 9 | /*-- --*/ 10 | /*-- The custom code written here is licensed under the terms of the GPL: --*/ 11 | /*-- --*/ 12 | /*-- This program is free software: you can redistribute it and/or modify --*/ 13 | /*-- it under the terms of the GNU General Public License as published by --*/ 14 | /*-- the Free Software Foundation, either version 3 of the License, or --*/ 15 | /*-- (at your option) any later version. --*/ 16 | /*-- --*/ 17 | /*-- This program is distributed in the hope that it will be useful, --*/ 18 | /*-- but WITHOUT ANY WARRANTY; without even the implied warranty of --*/ 19 | /*-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the --*/ 20 | /*-- GNU General Public License for more details. --*/ 21 | /*-- --*/ 22 | /*-- You should have received a copy of the GNU General Public License --*/ 23 | /*-- along with this program. If not, see . --*/ 24 | /*----------------------------------------------------------------------------*/ 25 | 26 | import java.util.ArrayList; 27 | import java.util.List; 28 | 29 | public class Trainer implements Comparable { 30 | public int offset; 31 | public List pokemon = new ArrayList(); 32 | public String tag; 33 | public boolean importantTrainer; 34 | public int poketype; 35 | public String name; 36 | public int trainerclass; 37 | public String fullDisplayName; 38 | 39 | public String toString() { 40 | StringBuilder sb = new StringBuilder("["); 41 | if (fullDisplayName != null) { 42 | sb.append(fullDisplayName + " "); 43 | } else if (name != null) { 44 | sb.append(name + " "); 45 | } 46 | if (trainerclass != 0) { 47 | sb.append("(" + trainerclass + ") - "); 48 | } 49 | sb.append(String.format("%x", offset)); 50 | sb.append(" => "); 51 | boolean first = true; 52 | for (TrainerPokemon p : pokemon) { 53 | if (!first) { 54 | sb.append(','); 55 | } 56 | sb.append(p.pokemon.name + " Lv" + p.level); 57 | first = false; 58 | } 59 | sb.append(']'); 60 | if (tag != null) { 61 | sb.append(" (" + tag + ")"); 62 | } 63 | return sb.toString(); 64 | } 65 | 66 | @Override 67 | public int hashCode() { 68 | final int prime = 31; 69 | int result = 1; 70 | result = prime * result + offset; 71 | return result; 72 | } 73 | 74 | @Override 75 | public boolean equals(Object obj) { 76 | if (this == obj) 77 | return true; 78 | if (obj == null) 79 | return false; 80 | if (getClass() != obj.getClass()) 81 | return false; 82 | Trainer other = (Trainer) obj; 83 | if (offset != other.offset) 84 | return false; 85 | return true; 86 | } 87 | 88 | @Override 89 | public int compareTo(Trainer o) { 90 | return offset - o.offset; 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /src/com/dabomstew/pkrandom/newnds/CRC16.java: -------------------------------------------------------------------------------- 1 | package com.dabomstew.pkrandom.newnds; 2 | 3 | /*----------------------------------------------------------------------------*/ 4 | /*-- CRC16.java - crc16 calculator for NDS checksums --*/ 5 | /*-- Code derived from "Nintendo DS rom tool", copyright (C) DevkitPro --*/ 6 | /*-- Original Code by Rafael Vuijk, Dave Murphy, Alexei Karpenko --*/ 7 | /*-- --*/ 8 | /*-- Ported to Java by Dabomstew under the terms of the GPL: --*/ 9 | /*-- --*/ 10 | /*-- This program is free software: you can redistribute it and/or modify --*/ 11 | /*-- it under the terms of the GNU General Public License as published by --*/ 12 | /*-- the Free Software Foundation, either version 3 of the License, or --*/ 13 | /*-- (at your option) any later version. --*/ 14 | /*-- --*/ 15 | /*-- This program is distributed in the hope that it will be useful, --*/ 16 | /*-- but WITHOUT ANY WARRANTY; without even the implied warranty of --*/ 17 | /*-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the --*/ 18 | /*-- GNU General Public License for more details. --*/ 19 | /*-- --*/ 20 | /*-- You should have received a copy of the GNU General Public License --*/ 21 | /*-- along with this program. If not, see . --*/ 22 | /*----------------------------------------------------------------------------*/ 23 | 24 | public class CRC16 { 25 | private static final int[] table = { 0x0000, 0xC0C1, 0xC181, 0x0140, 0xC301, 0x03C0, 0x0280, 0xC241, 0xC601, 26 | 0x06C0, 0x0780, 0xC741, 0x0500, 0xC5C1, 0xC481, 0x0440, 0xCC01, 0x0CC0, 0x0D80, 0xCD41, 0x0F00, 0xCFC1, 27 | 0xCE81, 0x0E40, 0x0A00, 0xCAC1, 0xCB81, 0x0B40, 0xC901, 0x09C0, 0x0880, 0xC841, 0xD801, 0x18C0, 0x1980, 28 | 0xD941, 0x1B00, 0xDBC1, 0xDA81, 0x1A40, 0x1E00, 0xDEC1, 0xDF81, 0x1F40, 0xDD01, 0x1DC0, 0x1C80, 0xDC41, 29 | 0x1400, 0xD4C1, 0xD581, 0x1540, 0xD701, 0x17C0, 0x1680, 0xD641, 0xD201, 0x12C0, 0x1380, 0xD341, 0x1100, 30 | 0xD1C1, 0xD081, 0x1040, 0xF001, 0x30C0, 0x3180, 0xF141, 0x3300, 0xF3C1, 0xF281, 0x3240, 0x3600, 0xF6C1, 31 | 0xF781, 0x3740, 0xF501, 0x35C0, 0x3480, 0xF441, 0x3C00, 0xFCC1, 0xFD81, 0x3D40, 0xFF01, 0x3FC0, 0x3E80, 32 | 0xFE41, 0xFA01, 0x3AC0, 0x3B80, 0xFB41, 0x3900, 0xF9C1, 0xF881, 0x3840, 0x2800, 0xE8C1, 0xE981, 0x2940, 33 | 0xEB01, 0x2BC0, 0x2A80, 0xEA41, 0xEE01, 0x2EC0, 0x2F80, 0xEF41, 0x2D00, 0xEDC1, 0xEC81, 0x2C40, 0xE401, 34 | 0x24C0, 0x2580, 0xE541, 0x2700, 0xE7C1, 0xE681, 0x2640, 0x2200, 0xE2C1, 0xE381, 0x2340, 0xE101, 0x21C0, 35 | 0x2080, 0xE041, 0xA001, 0x60C0, 0x6180, 0xA141, 0x6300, 0xA3C1, 0xA281, 0x6240, 0x6600, 0xA6C1, 0xA781, 36 | 0x6740, 0xA501, 0x65C0, 0x6480, 0xA441, 0x6C00, 0xACC1, 0xAD81, 0x6D40, 0xAF01, 0x6FC0, 0x6E80, 0xAE41, 37 | 0xAA01, 0x6AC0, 0x6B80, 0xAB41, 0x6900, 0xA9C1, 0xA881, 0x6840, 0x7800, 0xB8C1, 0xB981, 0x7940, 0xBB01, 38 | 0x7BC0, 0x7A80, 0xBA41, 0xBE01, 0x7EC0, 0x7F80, 0xBF41, 0x7D00, 0xBDC1, 0xBC81, 0x7C40, 0xB401, 0x74C0, 39 | 0x7580, 0xB541, 0x7700, 0xB7C1, 0xB681, 0x7640, 0x7200, 0xB2C1, 0xB381, 0x7340, 0xB101, 0x71C0, 0x7080, 40 | 0xB041, 0x5000, 0x90C1, 0x9181, 0x5140, 0x9301, 0x53C0, 0x5280, 0x9241, 0x9601, 0x56C0, 0x5780, 0x9741, 41 | 0x5500, 0x95C1, 0x9481, 0x5440, 0x9C01, 0x5CC0, 0x5D80, 0x9D41, 0x5F00, 0x9FC1, 0x9E81, 0x5E40, 0x5A00, 42 | 0x9AC1, 0x9B81, 0x5B40, 0x9901, 0x59C0, 0x5880, 0x9841, 0x8801, 0x48C0, 0x4980, 0x8941, 0x4B00, 0x8BC1, 43 | 0x8A81, 0x4A40, 0x4E00, 0x8EC1, 0x8F81, 0x4F40, 0x8D01, 0x4DC0, 0x4C80, 0x8C41, 0x4400, 0x84C1, 0x8581, 44 | 0x4540, 0x8701, 0x47C0, 0x4680, 0x8641, 0x8201, 0x42C0, 0x4380, 0x8341, 0x4100, 0x81C1, 0x8081, 0x4040 }; 45 | 46 | public static short calculate(byte[] data, int offset, int length) { 47 | int crc = 0xFFFF; 48 | for (int i = 0; i < length; i++) { 49 | crc = ((crc >>> 8) ^ table[(crc ^ data[i + offset]) & 0xff]); 50 | } 51 | return (short) crc; 52 | } 53 | } -------------------------------------------------------------------------------- /src/com/dabomstew/pkrandom/MiscTweak.java: -------------------------------------------------------------------------------- 1 | package com.dabomstew.pkrandom; 2 | 3 | /*----------------------------------------------------------------------------*/ 4 | /*-- MiscTweak.java - represents a miscellaneous tweak that can be applied --*/ 5 | /*-- to some or all games that the randomizer supports. --*/ 6 | /*-- --*/ 7 | /*-- Part of "Universal Pokemon Randomizer" by Dabomstew --*/ 8 | /*-- Pokemon and any associated names and the like are --*/ 9 | /*-- trademark and (C) Nintendo 1996-2012. --*/ 10 | /*-- --*/ 11 | /*-- The custom code written here is licensed under the terms of the GPL: --*/ 12 | /*-- --*/ 13 | /*-- This program is free software: you can redistribute it and/or modify --*/ 14 | /*-- it under the terms of the GNU General Public License as published by --*/ 15 | /*-- the Free Software Foundation, either version 3 of the License, or --*/ 16 | /*-- (at your option) any later version. --*/ 17 | /*-- --*/ 18 | /*-- This program is distributed in the hope that it will be useful, --*/ 19 | /*-- but WITHOUT ANY WARRANTY; without even the implied warranty of --*/ 20 | /*-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the --*/ 21 | /*-- GNU General Public License for more details. --*/ 22 | /*-- --*/ 23 | /*-- You should have received a copy of the GNU General Public License --*/ 24 | /*-- along with this program. If not, see . --*/ 25 | /*----------------------------------------------------------------------------*/ 26 | 27 | import java.util.ArrayList; 28 | import java.util.List; 29 | import java.util.ResourceBundle; 30 | 31 | public class MiscTweak implements Comparable { 32 | 33 | private static final ResourceBundle bundle = ResourceBundle.getBundle("com/dabomstew/pkrandom/gui/Bundle"); 34 | 35 | public static List allTweaks = new ArrayList(); 36 | 37 | /* @formatter:off */ 38 | // Higher priority value (third argument) = run first 39 | public static final MiscTweak BW_EXP_PATCH = new MiscTweak(1, "bwPatch", 0); 40 | public static final MiscTweak NERF_X_ACCURACY = new MiscTweak(2, "nerfXAcc", 0); 41 | public static final MiscTweak FIX_CRIT_RATE = new MiscTweak(4, "critRateFix", 0); 42 | public static final MiscTweak FASTEST_TEXT = new MiscTweak(8, "fastestText", 0); 43 | public static final MiscTweak RUNNING_SHOES_INDOORS = new MiscTweak(16, "runningShoes", 0); 44 | public static final MiscTweak RANDOMIZE_PC_POTION = new MiscTweak(32, "pcPotion", 0); 45 | public static final MiscTweak ALLOW_PIKACHU_EVOLUTION = new MiscTweak(64, "pikachuEvo", 0); 46 | public static final MiscTweak NATIONAL_DEX_AT_START = new MiscTweak(128, "nationalDex", 0); 47 | public static final MiscTweak UPDATE_TYPE_EFFECTIVENESS = new MiscTweak(256, "typeEffectiveness", 0); 48 | public static final MiscTweak RANDOMIZE_HIDDEN_HOLLOWS = new MiscTweak(512, "hiddenHollows", 0); 49 | public static final MiscTweak LOWER_CASE_POKEMON_NAMES = new MiscTweak(1024, "lowerCaseNames", 0); 50 | public static final MiscTweak RANDOMIZE_CATCHING_TUTORIAL = new MiscTweak(2048, "catchingTutorial", 0); 51 | public static final MiscTweak BAN_LUCKY_EGG = new MiscTweak(4096, "luckyEgg", 1); 52 | /* @formatter:on */ 53 | 54 | private final int value; 55 | private final String tweakName; 56 | private final String tooltipText; 57 | private final int priority; 58 | 59 | private MiscTweak(int value, String tweakID, int priority) { 60 | this.value = value; 61 | this.tweakName = bundle.getString("CodeTweaks." + tweakID + ".name"); 62 | this.tooltipText = bundle.getString("CodeTweaks." + tweakID + ".toolTipText"); 63 | this.priority = priority; 64 | allTweaks.add(this); 65 | } 66 | 67 | public int getValue() { 68 | return value; 69 | } 70 | 71 | public String getTweakName() { 72 | return tweakName; 73 | } 74 | 75 | public String getTooltipText() { 76 | return tooltipText; 77 | } 78 | 79 | @Override 80 | public int compareTo(MiscTweak o) { 81 | // Order according to reverse priority, so higher priority = earlier in 82 | // ordering 83 | return o.priority - priority; 84 | } 85 | 86 | } 87 | -------------------------------------------------------------------------------- /src/com/dabomstew/pkrandom/gui/OperationDialog.java: -------------------------------------------------------------------------------- 1 | package com.dabomstew.pkrandom.gui; 2 | 3 | import java.awt.Dialog; 4 | import java.awt.Frame; 5 | import java.awt.Image; 6 | import java.awt.Toolkit; 7 | import java.io.IOException; 8 | import java.io.InputStream; 9 | 10 | import javax.swing.ImageIcon; 11 | 12 | import com.dabomstew.pkrandom.FileFunctions; 13 | 14 | /** 15 | * 16 | * @author Stewart 17 | */ 18 | public class OperationDialog extends javax.swing.JDialog { 19 | 20 | /** 21 | * 22 | */ 23 | private static final long serialVersionUID = 5965463550336235236L; 24 | 25 | /** 26 | * Creates new form OperationDialog 27 | */ 28 | public OperationDialog(String text, Frame parent, boolean modal) { 29 | super(parent, modal); 30 | initComponents(); 31 | this.loadingLabel.setText(text); 32 | setLocationRelativeTo(parent); 33 | } 34 | 35 | public OperationDialog(String text, Dialog parent, boolean modal) { 36 | super(parent, modal); 37 | initComponents(); 38 | this.loadingLabel.setText(text); 39 | setLocationRelativeTo(parent); 40 | } 41 | 42 | /* @formatter:off */ 43 | /** 44 | * This method is called from within the constructor to initialize the form. 45 | * WARNING: Do NOT modify this code. The content of this method is always 46 | * regenerated by the Form Editor. 47 | */ 48 | // //GEN-BEGIN:initComponents 50 | private void initComponents() { 51 | 52 | jPanel1 = new javax.swing.JPanel(); 53 | loadingLabel = new javax.swing.JLabel(); 54 | 55 | setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE); 56 | setResizable(false); 57 | setUndecorated(true); 58 | 59 | jPanel1.setBorder(new javax.swing.border.LineBorder(new java.awt.Color( 60 | 0, 0, 0), 2, true)); 61 | 62 | loadingLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); 63 | loadingLabel.setIcon(getLoadingIcon()); 64 | loadingLabel.setText("Loading..."); 65 | 66 | javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout( 67 | jPanel1); 68 | jPanel1.setLayout(jPanel1Layout); 69 | jPanel1Layout.setHorizontalGroup(jPanel1Layout.createParallelGroup( 70 | javax.swing.GroupLayout.Alignment.LEADING).addGroup( 71 | jPanel1Layout.createSequentialGroup().addContainerGap() 72 | .addComponent(loadingLabel) 73 | .addContainerGap(53, Short.MAX_VALUE))); 74 | jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup( 75 | javax.swing.GroupLayout.Alignment.LEADING).addGroup( 76 | jPanel1Layout 77 | .createSequentialGroup() 78 | .addContainerGap() 79 | .addComponent(loadingLabel) 80 | .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, 81 | Short.MAX_VALUE))); 82 | 83 | javax.swing.GroupLayout layout = new javax.swing.GroupLayout( 84 | getContentPane()); 85 | getContentPane().setLayout(layout); 86 | layout.setHorizontalGroup(layout.createParallelGroup( 87 | javax.swing.GroupLayout.Alignment.LEADING).addComponent( 88 | jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 89 | javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)); 90 | layout.setVerticalGroup(layout.createParallelGroup( 91 | javax.swing.GroupLayout.Alignment.LEADING).addComponent( 92 | jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 93 | javax.swing.GroupLayout.DEFAULT_SIZE, 94 | javax.swing.GroupLayout.PREFERRED_SIZE)); 95 | 96 | pack(); 97 | }// //GEN-END:initComponents 98 | 99 | private ImageIcon getLoadingIcon() { 100 | try { 101 | InputStream in = OperationDialog.class 102 | .getResourceAsStream("/com/dabomstew/pkrandom/gui/loading.gif"); 103 | byte[] buf = FileFunctions.readFullyIntoBuffer(in, in.available()); 104 | in.close(); 105 | Image image = Toolkit.getDefaultToolkit().createImage(buf); 106 | return new ImageIcon(image); 107 | } catch (IOException ex) { 108 | return null; 109 | } 110 | } 111 | 112 | // Variables declaration - do not modify//GEN-BEGIN:variables 113 | private javax.swing.JPanel jPanel1; 114 | private javax.swing.JLabel loadingLabel; 115 | 116 | // End of variables declaration//GEN-END:variables 117 | /* @formatter:on */ 118 | } 119 | -------------------------------------------------------------------------------- /.settings/org.eclipse.jdt.ui.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | formatter_profile=_PokeRandomizer2 3 | formatter_settings_version=12 4 | org.eclipse.jdt.ui.javadoc=false 5 | org.eclipse.jdt.ui.text.custom_code_templates= 6 | -------------------------------------------------------------------------------- /src/com/dabomstew/pkrandom/newnds/NDSFile.java: -------------------------------------------------------------------------------- 1 | package com.dabomstew.pkrandom.newnds; 2 | 3 | import java.io.File; 4 | import java.io.FileOutputStream; 5 | import java.io.IOException; 6 | import java.io.RandomAccessFile; 7 | 8 | import com.dabomstew.pkrandom.FileFunctions; 9 | 10 | /*----------------------------------------------------------------------------*/ 11 | /*-- NDSFile.java - an entry in the FAT/FNT filesystem --*/ 12 | /*-- Code based on "Nintendo DS rom tool", copyright (C) DevkitPro --*/ 13 | /*-- Original Code by Rafael Vuijk, Dave Murphy, Alexei Karpenko --*/ 14 | /*-- --*/ 15 | /*-- Ported to Java by Dabomstew under the terms of the GPL: --*/ 16 | /*-- --*/ 17 | /*-- This program is free software: you can redistribute it and/or modify --*/ 18 | /*-- it under the terms of the GNU General Public License as published by --*/ 19 | /*-- the Free Software Foundation, either version 3 of the License, or --*/ 20 | /*-- (at your option) any later version. --*/ 21 | /*-- --*/ 22 | /*-- This program is distributed in the hope that it will be useful, --*/ 23 | /*-- but WITHOUT ANY WARRANTY; without even the implied warranty of --*/ 24 | /*-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the --*/ 25 | /*-- GNU General Public License for more details. --*/ 26 | /*-- --*/ 27 | /*-- You should have received a copy of the GNU General Public License --*/ 28 | /*-- along with this program. If not, see . --*/ 29 | /*----------------------------------------------------------------------------*/ 30 | 31 | public class NDSFile { 32 | 33 | private NDSRom parent; 34 | public int offset, size; 35 | public int fileID; 36 | public String fullPath; 37 | public Extracted status = Extracted.NOT; 38 | public String extFilename; 39 | public byte[] data; 40 | 41 | public NDSFile(NDSRom parent) { 42 | this.parent = parent; 43 | } 44 | 45 | public byte[] getContents() throws IOException { 46 | if (this.status == Extracted.NOT) { 47 | // extract file 48 | parent.reopenROM(); 49 | RandomAccessFile rom = parent.getBaseRom(); 50 | byte[] buf = new byte[this.size]; 51 | rom.seek(this.offset); 52 | rom.readFully(buf); 53 | if (parent.isWritingEnabled()) { 54 | // make a file 55 | String tmpDir = parent.getTmpFolder(); 56 | String tmpFilename = fullPath.replaceAll("[^A-Za-z0-9_]+", ""); 57 | this.extFilename = tmpFilename; 58 | File tmpFile = new File(tmpDir + extFilename); 59 | FileOutputStream fos = new FileOutputStream(tmpFile); 60 | fos.write(buf); 61 | fos.close(); 62 | tmpFile.deleteOnExit(); 63 | this.status = Extracted.TO_FILE; 64 | this.data = null; 65 | return buf; 66 | } else { 67 | this.status = Extracted.TO_RAM; 68 | this.data = buf; 69 | byte[] newcopy = new byte[buf.length]; 70 | System.arraycopy(buf, 0, newcopy, 0, buf.length); 71 | return newcopy; 72 | } 73 | } else if (this.status == Extracted.TO_RAM) { 74 | byte[] newcopy = new byte[this.data.length]; 75 | System.arraycopy(this.data, 0, newcopy, 0, this.data.length); 76 | return newcopy; 77 | } else { 78 | String tmpDir = parent.getTmpFolder(); 79 | byte[] file = FileFunctions.readFileFullyIntoBuffer(tmpDir + this.extFilename); 80 | return file; 81 | } 82 | } 83 | 84 | public void writeOverride(byte[] data) throws IOException { 85 | if (status == Extracted.NOT) { 86 | // temp extract 87 | getContents(); 88 | } 89 | if (status == Extracted.TO_FILE) { 90 | String tmpDir = parent.getTmpFolder(); 91 | FileOutputStream fos = new FileOutputStream(new File(tmpDir + this.extFilename)); 92 | fos.write(data); 93 | fos.close(); 94 | } else { 95 | if (this.data.length == data.length) { 96 | // copy new in 97 | System.arraycopy(data, 0, this.data, 0, data.length); 98 | } else { 99 | // make new array 100 | this.data = null; 101 | this.data = new byte[data.length]; 102 | System.arraycopy(data, 0, this.data, 0, data.length); 103 | } 104 | } 105 | } 106 | 107 | // returns null if no override 108 | public byte[] getOverrideContents() throws IOException { 109 | if (status == Extracted.NOT) { 110 | return null; 111 | } 112 | return getContents(); 113 | } 114 | 115 | private enum Extracted { 116 | NOT, TO_FILE, TO_RAM; 117 | } 118 | 119 | } 120 | -------------------------------------------------------------------------------- /src/com/dabomstew/pkrandom/RandomSource.java: -------------------------------------------------------------------------------- 1 | package com.dabomstew.pkrandom; 2 | 3 | /*----------------------------------------------------------------------------*/ 4 | /*-- RandomSource.java - functions as a centralized source of randomness --*/ 5 | /*-- to allow the same seed to produce the same random --*/ 6 | /*-- ROM consistently. --*/ 7 | /*-- --*/ 8 | /*-- Part of "Universal Pokemon Randomizer" by Dabomstew --*/ 9 | /*-- Pokemon and any associated names and the like are --*/ 10 | /*-- trademark and (C) Nintendo 1996-2012. --*/ 11 | /*-- --*/ 12 | /*-- The custom code written here is licensed under the terms of the GPL: --*/ 13 | /*-- --*/ 14 | /*-- This program is free software: you can redistribute it and/or modify --*/ 15 | /*-- it under the terms of the GNU General Public License as published by --*/ 16 | /*-- the Free Software Foundation, either version 3 of the License, or --*/ 17 | /*-- (at your option) any later version. --*/ 18 | /*-- --*/ 19 | /*-- This program is distributed in the hope that it will be useful, --*/ 20 | /*-- but WITHOUT ANY WARRANTY; without even the implied warranty of --*/ 21 | /*-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the --*/ 22 | /*-- GNU General Public License for more details. --*/ 23 | /*-- --*/ 24 | /*-- You should have received a copy of the GNU General Public License --*/ 25 | /*-- along with this program. If not, see . --*/ 26 | /*----------------------------------------------------------------------------*/ 27 | 28 | import java.security.SecureRandom; 29 | import java.util.Random; 30 | 31 | public class RandomSource { 32 | 33 | private static Random source = new Random(); 34 | private static int calls = 0; 35 | private static Random instance = new RandomSourceInstance(); 36 | 37 | public static void reset() { 38 | source = new Random(); 39 | calls = 0; 40 | } 41 | 42 | public static void seed(long seed) { 43 | source.setSeed(seed); 44 | calls = 0; 45 | } 46 | 47 | public static double random() { 48 | calls++; 49 | return source.nextDouble(); 50 | } 51 | 52 | public static int nextInt(int size) { 53 | calls++; 54 | return source.nextInt(size); 55 | } 56 | 57 | public static void nextBytes(byte[] bytes) { 58 | calls++; 59 | source.nextBytes(bytes); 60 | } 61 | 62 | public static int nextInt() { 63 | calls++; 64 | return source.nextInt(); 65 | } 66 | 67 | public static long nextLong() { 68 | calls++; 69 | return source.nextLong(); 70 | } 71 | 72 | public static boolean nextBoolean() { 73 | calls++; 74 | return source.nextBoolean(); 75 | } 76 | 77 | public static float nextFloat() { 78 | calls++; 79 | return source.nextFloat(); 80 | } 81 | 82 | public static double nextDouble() { 83 | calls++; 84 | return source.nextDouble(); 85 | } 86 | 87 | public static synchronized double nextGaussian() { 88 | calls++; 89 | return source.nextGaussian(); 90 | } 91 | 92 | public static long pickSeed() { 93 | long value = 0; 94 | byte[] by = SecureRandom.getSeed(6); 95 | for (int i = 0; i < by.length; i++) { 96 | value |= ((long) by[i] & 0xffL) << (8 * i); 97 | } 98 | return value; 99 | } 100 | 101 | public static Random instance() { 102 | return instance; 103 | } 104 | 105 | public static int callsSinceSeed() { 106 | return calls; 107 | } 108 | 109 | private static class RandomSourceInstance extends Random { 110 | 111 | /** 112 | * 113 | */ 114 | private static final long serialVersionUID = -4876737183441746322L; 115 | 116 | @Override 117 | public synchronized void setSeed(long seed) { 118 | RandomSource.seed(seed); 119 | } 120 | 121 | @Override 122 | public void nextBytes(byte[] bytes) { 123 | RandomSource.nextBytes(bytes); 124 | } 125 | 126 | @Override 127 | public int nextInt() { 128 | return RandomSource.nextInt(); 129 | } 130 | 131 | @Override 132 | public int nextInt(int n) { 133 | return RandomSource.nextInt(n); 134 | } 135 | 136 | @Override 137 | public long nextLong() { 138 | return RandomSource.nextLong(); 139 | } 140 | 141 | @Override 142 | public boolean nextBoolean() { 143 | return RandomSource.nextBoolean(); 144 | } 145 | 146 | @Override 147 | public float nextFloat() { 148 | return RandomSource.nextFloat(); 149 | } 150 | 151 | @Override 152 | public double nextDouble() { 153 | return RandomSource.nextDouble(); 154 | } 155 | 156 | @Override 157 | public synchronized double nextGaussian() { 158 | return RandomSource.nextGaussian(); 159 | } 160 | 161 | } 162 | } 163 | -------------------------------------------------------------------------------- /src/com/dabomstew/pkrandom/gui/UpdateFoundDialog.form: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 |
106 | -------------------------------------------------------------------------------- /src/compressors/Gen2Decmp.java: -------------------------------------------------------------------------------- 1 | package compressors; 2 | 3 | /** 4 | * Pokemon Gen 2 sprite decompressor Source: 5 | * https://github.com/pret/pokemon-reverse-engineering-tools/blob/master/pokemontools/lz.py 6 | * (and gfx.py for flatten()) 7 | * Ported to Java by Dabomstew 8 | * 9 | */ 10 | public class Gen2Decmp { 11 | 12 | private static final int LZ_END = 0xFF; 13 | private static final int INITIAL_BUF_SIZE = 0x1000; 14 | 15 | public byte[] data; 16 | public int address; 17 | private byte[] output; 18 | private int out_idx; 19 | private int cmd; 20 | private int len; 21 | private int offset; 22 | 23 | private static int[] bit_flipped; 24 | 25 | static { 26 | bit_flipped = new int[0x100]; 27 | for (int b = 0; b < 0x100; b++) { 28 | for (int i = 0; i < 8; i++) { 29 | bit_flipped[b] += ((b >> i) & 1) << (7 - i); 30 | } 31 | } 32 | } 33 | 34 | public Gen2Decmp(byte[] input, int baseOffset, int tilesWide, int tilesHigh) { 35 | this.data = input; 36 | this.address = baseOffset; 37 | decompress(); 38 | cutAndTranspose(tilesWide, tilesHigh); 39 | } 40 | 41 | public byte[] getData() { 42 | return output; 43 | } 44 | 45 | public byte[] getFlattenedData() { 46 | return flatten(output); 47 | } 48 | 49 | private void cutAndTranspose(int width, int height) { 50 | if (output == null) { 51 | return; 52 | } 53 | int tiles = width * height; 54 | 55 | byte[] newData = new byte[width * height * 16]; 56 | for (int tile = 0; tile < tiles; tile++) { 57 | int oldTileX = tile % width; 58 | int oldTileY = tile / width; 59 | int newTileNum = oldTileX * height + oldTileY; 60 | System.arraycopy(output, tile * 16, newData, newTileNum * 16, 16); 61 | } 62 | output = newData; 63 | 64 | } 65 | 66 | private void decompress() { 67 | output = new byte[INITIAL_BUF_SIZE]; 68 | while (true) { 69 | if (this.peek() == LZ_END) { 70 | this.next(); 71 | break; 72 | } 73 | 74 | cmd = (this.peek() & 0xE0) >> 5; 75 | if (cmd == 7) { 76 | // LONG command 77 | cmd = (this.peek() & 0x1C) >> 2; 78 | len = (this.next() & 0x03) * 0x100 + this.next() + 1; 79 | } else { 80 | // Normal length 81 | len = (this.next() & 0x1F) + 1; 82 | } 83 | 84 | while (out_idx + len > output.length) { 85 | resizeOutput(); 86 | } 87 | 88 | switch (cmd) { 89 | case 0: 90 | // Literal 91 | System.arraycopy(data, address, output, out_idx, len); 92 | out_idx += len; 93 | address += len; 94 | break; 95 | case 1: 96 | // Iterate 97 | byte repe = (byte) next(); 98 | for (int i = 0; i < len; i++) { 99 | output[out_idx++] = repe; 100 | } 101 | break; 102 | case 2: 103 | // Alternate 104 | byte[] alts = { (byte) next(), (byte) next() }; 105 | for (int i = 0; i < len; i++) { 106 | output[out_idx++] = alts[i & 1]; 107 | } 108 | break; 109 | case 3: 110 | // Zero-fill 111 | // Easy, since Java arrays are initialized to 0. 112 | out_idx += len; 113 | break; 114 | case 4: 115 | // Default repeat 116 | repeat(); 117 | break; 118 | case 5: 119 | repeat(1, bit_flipped); 120 | break; 121 | case 6: 122 | repeat(-1, null); 123 | break; 124 | } 125 | } 126 | 127 | byte[] finalOutput = new byte[out_idx]; 128 | System.arraycopy(output, 0, finalOutput, 0, out_idx); 129 | output = finalOutput; 130 | 131 | } 132 | 133 | private void repeat() { 134 | repeat(1, null); 135 | } 136 | 137 | private void repeat(int direction, int[] table) { 138 | get_offset(); 139 | for (int i = 0; i < len; i++) { 140 | int value = output[offset + i * direction] & 0xFF; 141 | output[out_idx++] = (byte) ((table == null) ? value : table[value]); 142 | } 143 | } 144 | 145 | private void get_offset() { 146 | if (this.peek() >= 0x80) { 147 | // Negative 148 | offset = this.next() & 0x7F; 149 | offset = out_idx - offset - 1; 150 | } else { 151 | // Positive, extended 152 | offset = this.next() * 0x100 + this.next(); 153 | } 154 | } 155 | 156 | private void resizeOutput() { 157 | byte[] newOut = new byte[output.length * 2]; 158 | System.arraycopy(output, 0, newOut, 0, out_idx); 159 | output = newOut; 160 | } 161 | 162 | public int peek() { 163 | return data[address] & 0xFF; 164 | } 165 | 166 | public int next() { 167 | return data[address++] & 0xFF; 168 | } 169 | 170 | private static byte[] flatten(byte[] planar) { 171 | byte[] strips = new byte[planar.length * 4]; 172 | for (int j = 0; j < planar.length / 2; j++) { 173 | int bottom = planar[j * 2] & 0xFF; 174 | int top = planar[j * 2 + 1] & 0xFF; 175 | byte[] strip = new byte[8]; 176 | for (int i = 7; i >= 0; i--) { 177 | strip[7 - i] = (byte) (((bottom >>> i) & 1) + ((top * 2 >>> i) & 2)); 178 | } 179 | System.arraycopy(strip, 0, strips, j * 8, 8); 180 | } 181 | return strips; 182 | } 183 | 184 | } 185 | -------------------------------------------------------------------------------- /src/com/dabomstew/pkrandom/GFXFunctions.java: -------------------------------------------------------------------------------- 1 | package com.dabomstew.pkrandom; 2 | 3 | /*----------------------------------------------------------------------------*/ 4 | /*-- GFXFunctions.java - functions relating to graphics rendering. --*/ 5 | /*-- Mainly used for rendering the sprites. --*/ 6 | /*-- --*/ 7 | /*-- Part of "Universal Pokemon Randomizer" by Dabomstew --*/ 8 | /*-- Pokemon and any associated names and the like are --*/ 9 | /*-- trademark and (C) Nintendo 1996-2012. --*/ 10 | /*-- --*/ 11 | /*-- The custom code written here is licensed under the terms of the GPL: --*/ 12 | /*-- --*/ 13 | /*-- This program is free software: you can redistribute it and/or modify --*/ 14 | /*-- it under the terms of the GNU General Public License as published by --*/ 15 | /*-- the Free Software Foundation, either version 3 of the License, or --*/ 16 | /*-- (at your option) any later version. --*/ 17 | /*-- --*/ 18 | /*-- This program is distributed in the hope that it will be useful, --*/ 19 | /*-- but WITHOUT ANY WARRANTY; without even the implied warranty of --*/ 20 | /*-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the --*/ 21 | /*-- GNU General Public License for more details. --*/ 22 | /*-- --*/ 23 | /*-- You should have received a copy of the GNU General Public License --*/ 24 | /*-- along with this program. If not, see . --*/ 25 | /*----------------------------------------------------------------------------*/ 26 | 27 | import java.awt.image.BufferedImage; 28 | import java.util.LinkedList; 29 | import java.util.Queue; 30 | 31 | public class GFXFunctions { 32 | 33 | public static BufferedImage drawTiledImage(byte[] data, int[] palette, int width, int height, int bpp) { 34 | return drawTiledImage(data, palette, 0, width, height, 8, 8, bpp); 35 | } 36 | 37 | public static BufferedImage drawTiledImage(byte[] data, int[] palette, int offset, int width, int height, int bpp) { 38 | return drawTiledImage(data, palette, offset, width, height, 8, 8, bpp); 39 | } 40 | 41 | public static BufferedImage drawTiledImage(byte[] data, int[] palette, int offset, int width, int height, 42 | int tileWidth, int tileHeight, int bpp) { 43 | if (bpp != 1 && bpp != 2 && bpp != 4 && bpp != 8) { 44 | throw new IllegalArgumentException("Bits per pixel must be a multiple of 2."); 45 | } 46 | int pixelsPerByte = 8 / bpp; 47 | if (width * height / pixelsPerByte + offset > data.length) { 48 | throw new IllegalArgumentException("Invalid input image."); 49 | } 50 | 51 | int bytesPerTile = tileWidth * tileHeight / pixelsPerByte; 52 | int numTiles = width * height / (tileWidth * tileHeight); 53 | int widthInTiles = width / tileWidth; 54 | 55 | BufferedImage bim = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); 56 | 57 | for (int tile = 0; tile < numTiles; tile++) { 58 | int tileX = tile % widthInTiles; 59 | int tileY = tile / widthInTiles; 60 | for (int yT = 0; yT < tileHeight; yT++) { 61 | for (int xT = 0; xT < tileWidth; xT++) { 62 | int value = data[tile * bytesPerTile + yT * tileWidth / pixelsPerByte + xT / pixelsPerByte + offset] & 0xFF; 63 | if (pixelsPerByte != 1) { 64 | value = (value >>> (xT % pixelsPerByte) * bpp) & ((1 << bpp) - 1); 65 | } 66 | bim.setRGB(tileX * tileWidth + xT, tileY * tileHeight + yT, palette[value]); 67 | } 68 | } 69 | } 70 | 71 | return bim; 72 | } 73 | 74 | public static int conv16BitColorToARGB(int palValue) { 75 | int red = (int) ((palValue & 0x1F) * 8.25); 76 | int green = (int) (((palValue & 0x3E0) >> 5) * 8.25); 77 | int blue = (int) (((palValue & 0x7C00) >> 10) * 8.25); 78 | return 0xFF000000 | (red << 16) | (green << 8) | blue; 79 | } 80 | 81 | public static void pseudoTransparency(BufferedImage img, int transColor) { 82 | int width = img.getWidth(); 83 | int height = img.getHeight(); 84 | Queue visitPixels = new LinkedList(); 85 | boolean[][] queued = new boolean[width][height]; 86 | 87 | for (int x = 0; x < width; x++) { 88 | queuePixel(x, 0, width, height, visitPixels, queued); 89 | queuePixel(x, height - 1, width, height, visitPixels, queued); 90 | } 91 | 92 | for (int y = 0; y < height; y++) { 93 | queuePixel(0, y, width, height, visitPixels, queued); 94 | queuePixel(width - 1, y, width, height, visitPixels, queued); 95 | } 96 | 97 | while (!visitPixels.isEmpty()) { 98 | int nextPixel = visitPixels.poll(); 99 | int x = nextPixel % width; 100 | int y = nextPixel / width; 101 | if (img.getRGB(x, y) == transColor) { 102 | img.setRGB(x, y, 0); 103 | queuePixel(x - 1, y, width, height, visitPixels, queued); 104 | queuePixel(x + 1, y, width, height, visitPixels, queued); 105 | queuePixel(x, y - 1, width, height, visitPixels, queued); 106 | queuePixel(x, y + 1, width, height, visitPixels, queued); 107 | } 108 | } 109 | } 110 | 111 | private static void queuePixel(int x, int y, int width, int height, Queue queue, boolean[][] queued) { 112 | if (x >= 0 && x < width && y >= 0 && y < height && !queued[x][y]) { 113 | queue.add((y) * width + (x)); 114 | queued[x][y] = true; 115 | } 116 | } 117 | 118 | } 119 | -------------------------------------------------------------------------------- /src/com/dabomstew/pkrandom/newnds/NDSY9Entry.java: -------------------------------------------------------------------------------- 1 | package com.dabomstew.pkrandom.newnds; 2 | 3 | import java.io.File; 4 | import java.io.FileOutputStream; 5 | import java.io.IOException; 6 | import java.io.RandomAccessFile; 7 | 8 | import com.dabomstew.pkrandom.FileFunctions; 9 | 10 | import cuecompressors.BLZCoder; 11 | 12 | /*----------------------------------------------------------------------------*/ 13 | /*-- NDSY9Entry.java - an entry in the arm9 overlay system --*/ 14 | /*-- Code based on "Nintendo DS rom tool", copyright (C) DevkitPro --*/ 15 | /*-- Original Code by Rafael Vuijk, Dave Murphy, Alexei Karpenko --*/ 16 | /*-- --*/ 17 | /*-- Ported to Java by Dabomstew under the terms of the GPL: --*/ 18 | /*-- --*/ 19 | /*-- This program is free software: you can redistribute it and/or modify --*/ 20 | /*-- it under the terms of the GNU General Public License as published by --*/ 21 | /*-- the Free Software Foundation, either version 3 of the License, or --*/ 22 | /*-- (at your option) any later version. --*/ 23 | /*-- --*/ 24 | /*-- This program is distributed in the hope that it will be useful, --*/ 25 | /*-- but WITHOUT ANY WARRANTY; without even the implied warranty of --*/ 26 | /*-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the --*/ 27 | /*-- GNU General Public License for more details. --*/ 28 | /*-- --*/ 29 | /*-- You should have received a copy of the GNU General Public License --*/ 30 | /*-- along with this program. If not, see . --*/ 31 | /*----------------------------------------------------------------------------*/ 32 | 33 | public class NDSY9Entry { 34 | 35 | private NDSRom parent; 36 | public int offset, size, original_size; 37 | public int fileID; 38 | public int overlay_id; 39 | public int ram_address, ram_size; 40 | public int bss_size; 41 | public int static_start, static_end; 42 | public int compressed_size; 43 | public int compress_flag; 44 | public Extracted status = Extracted.NOT; 45 | public String extFilename; 46 | public byte[] data; 47 | private boolean decompressed_data = false; 48 | 49 | public NDSY9Entry(NDSRom parent) { 50 | this.parent = parent; 51 | } 52 | 53 | public byte[] getContents() throws IOException { 54 | if (this.status == Extracted.NOT) { 55 | // extract file 56 | parent.reopenROM(); 57 | RandomAccessFile rom = parent.getBaseRom(); 58 | byte[] buf = new byte[this.original_size]; 59 | rom.seek(this.offset); 60 | rom.readFully(buf); 61 | // Compression? 62 | if (compress_flag != 0 && this.original_size == this.compressed_size && this.compressed_size != 0) { 63 | buf = new BLZCoder(null).BLZ_DecodePub(buf, "overlay " + overlay_id); 64 | decompressed_data = true; 65 | } 66 | if (parent.isWritingEnabled()) { 67 | // make a file 68 | String tmpDir = parent.getTmpFolder(); 69 | String fullPath = String.format("overlay_%04d", overlay_id); 70 | String tmpFilename = fullPath.replaceAll("[^A-Za-z0-9_]+", ""); 71 | this.extFilename = tmpFilename; 72 | File tmpFile = new File(tmpDir + extFilename); 73 | FileOutputStream fos = new FileOutputStream(tmpFile); 74 | fos.write(buf); 75 | fos.close(); 76 | tmpFile.deleteOnExit(); 77 | this.status = Extracted.TO_FILE; 78 | this.data = null; 79 | return buf; 80 | } else { 81 | this.status = Extracted.TO_RAM; 82 | this.data = buf; 83 | byte[] newcopy = new byte[buf.length]; 84 | System.arraycopy(buf, 0, newcopy, 0, buf.length); 85 | return newcopy; 86 | } 87 | } else if (this.status == Extracted.TO_RAM) { 88 | byte[] newcopy = new byte[this.data.length]; 89 | System.arraycopy(this.data, 0, newcopy, 0, this.data.length); 90 | return newcopy; 91 | } else { 92 | String tmpDir = parent.getTmpFolder(); 93 | byte[] file = FileFunctions.readFileFullyIntoBuffer(tmpDir + this.extFilename); 94 | return file; 95 | } 96 | } 97 | 98 | public void writeOverride(byte[] data) throws IOException { 99 | if (status == Extracted.NOT) { 100 | // temp extract 101 | getContents(); 102 | } 103 | size = data.length; 104 | if (status == Extracted.TO_FILE) { 105 | String tmpDir = parent.getTmpFolder(); 106 | FileOutputStream fos = new FileOutputStream(new File(tmpDir + this.extFilename)); 107 | fos.write(data); 108 | fos.close(); 109 | } else { 110 | if (this.data.length == data.length) { 111 | // copy new in 112 | System.arraycopy(data, 0, this.data, 0, data.length); 113 | } else { 114 | // make new array 115 | this.data = null; 116 | this.data = new byte[data.length]; 117 | System.arraycopy(data, 0, this.data, 0, data.length); 118 | } 119 | } 120 | } 121 | 122 | // returns null if no override 123 | public byte[] getOverrideContents() throws IOException { 124 | if (status == Extracted.NOT) { 125 | return null; 126 | } 127 | byte[] buf = getContents(); 128 | if (this.decompressed_data) { 129 | buf = new BLZCoder(null).BLZ_EncodePub(buf, false, false, "overlay " + overlay_id); 130 | // update our compressed size 131 | this.compressed_size = buf.length; 132 | } 133 | return buf; 134 | } 135 | 136 | private enum Extracted { 137 | NOT, TO_FILE, TO_RAM; 138 | } 139 | 140 | } 141 | -------------------------------------------------------------------------------- /src/com/dabomstew/pkrandom/romhandlers/AbstractGBRomHandler.java: -------------------------------------------------------------------------------- 1 | package com.dabomstew.pkrandom.romhandlers; 2 | 3 | /*----------------------------------------------------------------------------*/ 4 | /*-- AbstractGBRomHandler.java - a base class for GB/GBA rom handlers --*/ 5 | /*-- which standardises common GB(A) functions.--*/ 6 | /*-- --*/ 7 | /*-- Part of "Universal Pokemon Randomizer" by Dabomstew --*/ 8 | /*-- Pokemon and any associated names and the like are --*/ 9 | /*-- trademark and (C) Nintendo 1996-2012. --*/ 10 | /*-- --*/ 11 | /*-- The custom code written here is licensed under the terms of the GPL: --*/ 12 | /*-- --*/ 13 | /*-- This program is free software: you can redistribute it and/or modify --*/ 14 | /*-- it under the terms of the GNU General Public License as published by --*/ 15 | /*-- the Free Software Foundation, either version 3 of the License, or --*/ 16 | /*-- (at your option) any later version. --*/ 17 | /*-- --*/ 18 | /*-- This program is distributed in the hope that it will be useful, --*/ 19 | /*-- but WITHOUT ANY WARRANTY; without even the implied warranty of --*/ 20 | /*-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the --*/ 21 | /*-- GNU General Public License for more details. --*/ 22 | /*-- --*/ 23 | /*-- You should have received a copy of the GNU General Public License --*/ 24 | /*-- along with this program. If not, see . --*/ 25 | /*----------------------------------------------------------------------------*/ 26 | 27 | import java.io.File; 28 | import java.io.FileInputStream; 29 | import java.io.FileOutputStream; 30 | import java.io.IOException; 31 | import java.io.PrintStream; 32 | import java.util.Random; 33 | 34 | import com.dabomstew.pkrandom.FileFunctions; 35 | import com.dabomstew.pkrandom.exceptions.RandomizerIOException; 36 | 37 | public abstract class AbstractGBRomHandler extends AbstractRomHandler { 38 | 39 | protected byte[] rom; 40 | private String loadedFN; 41 | 42 | public AbstractGBRomHandler(Random random, PrintStream logStream) { 43 | super(random, logStream); 44 | } 45 | 46 | @Override 47 | public boolean loadRom(String filename) { 48 | byte[] loaded = loadFile(filename); 49 | if (!detectRom(loaded)) { 50 | return false; 51 | } 52 | this.rom = loaded; 53 | loadedFN = filename; 54 | loadedRom(); 55 | return true; 56 | } 57 | 58 | @Override 59 | public String loadedFilename() { 60 | return loadedFN; 61 | } 62 | 63 | @Override 64 | public boolean saveRom(String filename) { 65 | savingRom(); 66 | try { 67 | FileOutputStream fos = new FileOutputStream(filename); 68 | fos.write(rom); 69 | fos.close(); 70 | return true; 71 | } catch (IOException ex) { 72 | return false; 73 | } 74 | } 75 | 76 | @Override 77 | public boolean canChangeStaticPokemon() { 78 | return true; 79 | } 80 | 81 | @Override 82 | public boolean hasPhysicalSpecialSplit() { 83 | // Default value for Gen1-Gen3. 84 | // Handlers can override again in case of ROM hacks etc. 85 | return false; 86 | } 87 | 88 | public abstract boolean detectRom(byte[] rom); 89 | 90 | public abstract void loadedRom(); 91 | 92 | public abstract void savingRom(); 93 | 94 | protected static byte[] loadFile(String filename) { 95 | try { 96 | return FileFunctions.readFileFullyIntoBuffer(filename); 97 | } catch (IOException ex) { 98 | throw new RandomizerIOException(ex); 99 | } 100 | } 101 | 102 | protected static byte[] loadFilePartial(String filename, int maxBytes) { 103 | try { 104 | File fh = new File(filename); 105 | if (!fh.exists() || !fh.isFile() || !fh.canRead()) { 106 | return new byte[0]; 107 | } 108 | long fileSize = fh.length(); 109 | if (fileSize > Integer.MAX_VALUE) { 110 | return new byte[0]; 111 | } 112 | FileInputStream fis = new FileInputStream(filename); 113 | byte[] file = FileFunctions.readFullyIntoBuffer(fis, Math.min((int) fileSize, maxBytes)); 114 | fis.close(); 115 | return file; 116 | } catch (IOException ex) { 117 | return new byte[0]; 118 | } 119 | } 120 | 121 | protected void readByteIntoFlags(boolean[] flags, int offsetIntoFlags, int offsetIntoROM) { 122 | int thisByte = rom[offsetIntoROM] & 0xFF; 123 | for (int i = 0; i < 8 && (i + offsetIntoFlags) < flags.length; i++) { 124 | flags[offsetIntoFlags + i] = ((thisByte >> i) & 0x01) == 0x01; 125 | } 126 | } 127 | 128 | protected byte getByteFromFlags(boolean[] flags, int offsetIntoFlags) { 129 | int thisByte = 0; 130 | for (int i = 0; i < 8 && (i + offsetIntoFlags) < flags.length; i++) { 131 | thisByte |= (flags[offsetIntoFlags + i] ? 1 : 0) << i; 132 | } 133 | return (byte) thisByte; 134 | } 135 | 136 | protected int readWord(int offset) { 137 | return readWord(rom, offset); 138 | } 139 | 140 | protected int readWord(byte[] data, int offset) { 141 | return (data[offset] & 0xFF) + ((data[offset + 1] & 0xFF) << 8); 142 | } 143 | 144 | protected void writeWord(int offset, int value) { 145 | writeWord(rom, offset, value); 146 | } 147 | 148 | protected void writeWord(byte[] data, int offset, int value) { 149 | data[offset] = (byte) (value % 0x100); 150 | data[offset + 1] = (byte) ((value / 0x100) % 0x100); 151 | } 152 | 153 | protected boolean matches(byte[] data, int offset, byte[] needle) { 154 | for (int i = 0; i < needle.length; i++) { 155 | if (offset + i >= data.length) { 156 | return false; 157 | } 158 | if (data[offset + i] != needle[i]) { 159 | return false; 160 | } 161 | } 162 | return true; 163 | } 164 | 165 | } 166 | -------------------------------------------------------------------------------- /readme.txt: -------------------------------------------------------------------------------- 1 | Universal Pokemon Randomizer 1.7.2 2 | by Dabomstew, 2012-16 3 | 4 | Homepage: http://pokehacks.dabomstew.com/randomizer/index.php 5 | Source: https://github.com/Dabomstew/universal-pokemon-randomizer 6 | 7 | Contents 8 | -------- 9 | 1. Introduction 10 | 2. Acknowledgements 11 | 3. Libraries Used 12 | 4. Features 13 | 5. How To Use 14 | 6. Games/ROMs supported 15 | 7. License 16 | 8. Known Issues 17 | 9. Useful/Interesting Links 18 | 19 | Introduction 20 | ------------ 21 | 22 | This program allows you to customize your experience playing the Pokemon games 23 | by randomizing many aspects of them. This means that the Pokemon you get at 24 | the start of the game, the Pokemon you fight in the wild and the Pokemon 25 | trainers have can all be made completely different from the original game. 26 | 27 | Acknowledgements 28 | ---------------- 29 | Many people have put countless hours of their time into researching the 30 | structures contained within Pokemon games over the years. Without the research 31 | done by these people, this randomizer would not exist, or would have taken a 32 | lot longer to create. 33 | 34 | To see the full list of contributions, see 35 | http://pokehacks.dabomstew.com/randomizer/acks.php 36 | 37 | Also thanks to scheibo for forking the randomizer and refactoring some of the 38 | structures relating to randomization of games, the majority of which were 39 | eventually merged in 1.6.3. 40 | (The fork is at https://github.com/scheibo/universal-pokemon-randomizer/tree/gui) 41 | 42 | Libraries Used 43 | -------------- 44 | * thenewpoketext by loadingNOW for generation 4 text handling 45 | http://pokeguide.filb.de/ (source @ https://github.com/magical/ppre ) 46 | * PPTXT by ProjectPokemon for generation 5 text handling 47 | http://projectpokemon.org/forums/showthread.php?11582-PPTXT-Text-editing-tool 48 | * Code from ndstool for NDS file extraction/creation (under GPL) 49 | http://sourceforge.net/p/devkitpro/ndstool/ 50 | * Code from CUE's Nintendo DS Compressors for arm9.bin (de)compressing 51 | (under GPL) 52 | http://gbatemp.net/threads/nintendo-ds-gba-compressors.313278/ 53 | * DSDecmp for LZ10/11 decompression (under MIT) 54 | https://github.com/Barubary/dsdecmp 55 | * Code from pokemon-reverse-engineering tools for Gen1/2 pic decompression 56 | https://github.com/pret/pokemon-reverse-engineering-tools 57 | 58 | Features 59 | -------- 60 | Below is a list of what exactly can be randomized. You may not understand all 61 | of it if you haven't played Pokemon games much before. 62 | 63 | * The Starter Pokemon choices 64 | * The Wild Pokemon you encounter in grass, caves and other places 65 | * The Pokemon that Trainers use against you. 66 | * The base stats which define the potential of each Pokemon 67 | * The elemental types of each Pokemon 68 | * The abilities of each Pokemon, in games where Pokemon have abilities 69 | * The Pokemon that each Pokemon evolves into, if it evolved to begin with. 70 | * The properties of each move, such as its power, accuracy and typing. 71 | * The moves that Pokemon learn by gaining levels 72 | * The contents of each TM which can be taught to Pokemon to give them 73 | additional moves 74 | (HM moves are not changed to make sure you can still beat the game) 75 | * The ability of each Pokemon to learn each TM or HM move 76 | * The "static" Pokemon which you either are given, fight on the overworld, 77 | or are sold. 78 | * The names of trainers & the classes they belong in 79 | * The moves that Move Tutors teach, in certain games where they are 80 | particularly significant. 81 | * The items that it is possible for Pokemon to hold in the wild, and in 82 | certain situations the items that Pokemon given to you are holding. 83 | * The Pokemon that are traded to you by in-game NPCs (as opposed to 84 | trades with real people) 85 | * The items you pick up off the ground, from either item balls or 86 | hidden spots. 87 | 88 | How To Use 89 | ---------- 90 | Extract this ZIP file before doing anything else!!! 91 | 92 | Make sure you have Java 1.6 or later installed, then run the included EXE or JAR file. 93 | 94 | If you open the EXE file without Java installed, it should prompt you to 95 | install it. Follow the prompts and then re-open it once you have Java installed. 96 | 97 | If you're using the JAR release, in some situations, you will be able to just 98 | double-click on the JAR file and the program will run. If not, execute the 99 | following command from your command line in the directory where you have 100 | extracted the program: 101 | 102 | java -jar randomizer.jar 103 | 104 | From there you can open a ROM (legally acquired), customize what you want to be 105 | randomized, then save the randomized ROM. 106 | 107 | Games/ROMs supported 108 | -------------------- 109 | 110 | Version 1.7.0 supports the following official ROMs: 111 | 112 | * Pokemon Red (any) 113 | * Pokemon Blue (any) 114 | * Pokemon Green (J) 115 | * Pokemon Yellow (any) 116 | * Pokemon Gold (any except Korean) 117 | * Pokemon Silver (any except Korean) 118 | * Pokemon Crystal (any) 119 | * Pokemon Ruby (any) 120 | * Pokemon Sapphire (any) 121 | * Pokemon Emerald (any) 122 | * Pokemon FireRed (any) 123 | * Pokemon LeafGreen (any) 124 | * Pokemon Diamond (any) 125 | * Pokemon Pearl (any) 126 | * Pokemon Platinum (any) 127 | * Pokemon HeartGold (any) 128 | * Pokemon SoulSilver (any) 129 | * Pokemon Black (any) 130 | * Pokemon White (any) 131 | * Pokemon Black2 (any) 132 | * Pokemon White2 (any) 133 | 134 | As you can see, pretty much every game except the Korean releases of Gold 135 | and Silver are supported. This is because these releases were very much 136 | one-offs, and have little to nothing in the way of a ROM hacking community 137 | which would be needed to make it possible to support them. 138 | 139 | Whilst pretty much every release of every game is supported to a good level, 140 | this randomizer is still targeted at English games - so users of foreign 141 | language games may still find that the functionality is a bit limited or 142 | small amounts of English text appear ingame where they did not before. 143 | 144 | Randomizing ROM hacks of the above games is not supported for the most part. 145 | It may still be possible depending on the specifics of the hack itself. 146 | In general, the simpler a hack is, the more likely it will be able to be randomized. 147 | Fire Red hacks are more likely to work than any others, due to specific 148 | code added in 1.7.0 attempting to deal with them. 149 | 150 | License 151 | ------- 152 | This project and the majority of the libraries used are under the GNU GPL v3, 153 | attached as LICENSE.txt. 154 | 155 | Source code can be obtained from: 156 | https://github.com/Dabomstew/universal-pokemon-randomizer 157 | 158 | Other libraries used are under more liberal licenses, compatible with the GPL. 159 | 160 | Useful/Interesting Links 161 | ------------------------ 162 | If you have bugs, suggestions, or other concerns to tell me, contact me at 163 | http://pokehacks.dabomstew.com/randomizer/comments.php -------------------------------------------------------------------------------- /src/thenewpoketext/PokeTextData.java: -------------------------------------------------------------------------------- 1 | package thenewpoketext; 2 | 3 | /*----------------------------------------------------------------------------*/ 4 | /*-- PokeTextData.java - decodes gen4 games text into Unicode --*/ 5 | /*-- Code derived from "thenewpoketext", copyright (C) loadingNOW --*/ 6 | /*-- Ported to Java and bugfixed/customized by Dabomstew --*/ 7 | /*----------------------------------------------------------------------------*/ 8 | 9 | import java.util.ArrayList; 10 | import java.util.Arrays; 11 | import java.util.List; 12 | 13 | public class PokeTextData { 14 | private byte[] data; 15 | public List ptrlist; 16 | public List strlist; 17 | public boolean compressFlag; 18 | 19 | public PokeTextData(byte[] data) { 20 | this.data = Arrays.copyOf(data, data.length); 21 | } 22 | 23 | public byte[] get() { 24 | return data; 25 | } 26 | 27 | private int read16(int ofs) { 28 | return (data[ofs] & 0xFF) | ((data[ofs + 1] & 0xFF) << 8); 29 | } 30 | 31 | private void write16(int d, int ofs) { 32 | data[ofs] = (byte) (d & 0xFF); 33 | data[ofs + 1] = (byte) ((d >> 8) & 0xFF); 34 | } 35 | 36 | private int read32(int ofs) { 37 | return (data[ofs] & 0xFF) | ((data[ofs + 1] & 0xFF) << 8) | ((data[ofs + 2] & 0xFF) << 16) 38 | | ((data[ofs + 3] & 0xFF) << 24); 39 | } 40 | 41 | private void write32(int d, int ofs) { 42 | data[ofs] = (byte) (d & 0xFF); 43 | data[ofs + 1] = (byte) ((d >> 8) & 0xFF); 44 | data[ofs + 2] = (byte) ((d >> 16) & 0xFF); 45 | data[ofs + 3] = (byte) ((d >> 24) & 0xFF); 46 | } 47 | 48 | public void decrypt() { 49 | DecyptPtrs(read16(0), read16(2), 4); 50 | this.ptrlist = CreatePtrList(read16(0), 4); 51 | 52 | this.strlist = new ArrayList(); 53 | 54 | int num = read16(0); 55 | 56 | for (int i = 0; i < num; i++) { 57 | PointerEntry entry = this.ptrlist.get(i); 58 | DecyptTxt(entry.getChars(), i + 1, entry.getPtr()); 59 | this.strlist.add(MakeString(entry.getChars(), entry.getPtr())); 60 | } 61 | } 62 | 63 | public void encrypt() { 64 | this.ptrlist = CreatePtrList(read16(0), 4); 65 | int num = read16(0); 66 | for (int i = 0; i < num; i++) { 67 | PointerEntry entry = this.ptrlist.get(i); 68 | DecyptTxt(entry.getChars(), i + 1, entry.getPtr()); 69 | } 70 | 71 | DecyptPtrs(read16(0), read16(2), 4); 72 | } 73 | 74 | private void DecyptPtrs(int count, int key, int sdidx) { 75 | key = (key * 0x2FD) & 0xFFFF; 76 | 77 | for (int i = 0; i < count; i++) { 78 | int key2 = (key * (i + 1) & 0xFFFF); 79 | int realkey = key2 | (key2 << 16); 80 | write32(read32(sdidx) ^ realkey, sdidx); 81 | write32(read32(sdidx + 4) ^ realkey, sdidx + 4); 82 | sdidx += 8; 83 | } 84 | 85 | } 86 | 87 | private List CreatePtrList(int count, int sdidx) { 88 | List ptrlist = new ArrayList(); 89 | for (int i = 0; i < count; i++) { 90 | ptrlist.add(new PointerEntry(read32(sdidx), read32(sdidx + 4))); 91 | sdidx += 8; 92 | } 93 | return ptrlist; 94 | } 95 | 96 | private void DecyptTxt(int count, int id, int idx) { 97 | int key = (0x91BD3 * id) & 0xFFFF; 98 | for (int i = 0; i < count; i++) { 99 | write16(read16(idx) ^ key, idx); 100 | key += 0x493D; 101 | key = key & 0xFFFF; 102 | idx += 2; 103 | } 104 | 105 | } 106 | 107 | private String MakeString(int count, int idx) { 108 | StringBuilder string = new StringBuilder(); 109 | List chars = new ArrayList(); 110 | List uncomp = new ArrayList(); 111 | for (int i = 0; i < count; i++) { 112 | chars.add(read16(idx)); 113 | idx += 2; 114 | } 115 | 116 | if (chars.get(0) == 0xF100) { 117 | compressFlag = true; 118 | int j = 1; 119 | int shift1 = 0; 120 | int trans = 0; 121 | while (true) { 122 | int tmp = chars.get(j); 123 | tmp = tmp >> shift1; 124 | int tmp1 = tmp; 125 | if (shift1 >= 0xF) { 126 | shift1 -= 0xF; 127 | if (shift1 > 0) { 128 | tmp1 = (trans | ((chars.get(j) << (9 - shift1)) & 0x1FF)); 129 | if (tmp1 == 0x1FF) { 130 | break; 131 | } 132 | uncomp.add(tmp1); 133 | } 134 | } else { 135 | tmp1 = ((chars.get(j) >> shift1) & 0x1FF); 136 | if (tmp1 == 0x1FF) { 137 | break; 138 | } 139 | uncomp.add(tmp1); 140 | shift1 += 9; 141 | if (shift1 < 0xF) { 142 | trans = ((chars.get(j) >> shift1) & 0x1FF); 143 | shift1 += 9; 144 | } 145 | j += 1; 146 | } 147 | } 148 | chars = uncomp; 149 | } 150 | int i = 0; 151 | for (int c = 0; c < chars.size(); c++) { 152 | int currChar = chars.get(i); 153 | if (UnicodeParser.tb[currChar] != null) { 154 | string.append(UnicodeParser.tb[currChar]); 155 | } else { 156 | if (currChar == 0xFFFE) { 157 | i++; 158 | string.append("\\v" + String.format("%04X", chars.get(i))); 159 | i++; 160 | int total = chars.get(i); 161 | for (int z = 0; z < total; z++) { 162 | i++; 163 | string.append("\\z" + String.format("%04X", chars.get(i))); 164 | } 165 | } else if (currChar == 0xFFFF) { 166 | break; 167 | } else { 168 | string.append("\\x" + String.format("%04X", chars.get(i))); 169 | } 170 | } 171 | i++; 172 | } 173 | return string.toString(); 174 | } 175 | 176 | public void SetKey(int key) { 177 | write16(key, 2); 178 | } 179 | 180 | public int GetKey() { 181 | return read16(2); 182 | } 183 | 184 | public class PointerEntry { 185 | 186 | private int ptr; 187 | private int chars; 188 | 189 | public PointerEntry(int ptr, int chars) { 190 | this.ptr = ptr; 191 | this.chars = chars; 192 | } 193 | 194 | public int getPtr() { 195 | return ptr; 196 | } 197 | 198 | public int getChars() { 199 | return chars; 200 | } 201 | } 202 | 203 | } 204 | -------------------------------------------------------------------------------- /src/compressors/DSDecmp.java: -------------------------------------------------------------------------------- 1 | package compressors; 2 | 3 | import com.dabomstew.pkrandom.FileFunctions; 4 | 5 | //MODIFIED DSDECMP-JAVA SOURCE FOR RANDOMIZER'S NEEDS 6 | //License is below 7 | 8 | //Copyright (c) 2010 Nick Kraayenbrink 9 | // 10 | //Permission is hereby granted, free of charge, to any person obtaining a copy 11 | //of this software and associated documentation files (the "Software"), to deal 12 | //in the Software without restriction, including without limitation the rights 13 | //to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 14 | //copies of the Software, and to permit persons to whom the Software is 15 | //furnished to do so, subject to the following conditions: 16 | // 17 | //The above copyright notice and this permission notice shall be included in 18 | //all copies or substantial portions of the Software. 19 | // 20 | //THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 21 | //IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 22 | //FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 23 | //AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 24 | //LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 25 | //OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 26 | //THE SOFTWARE. 27 | 28 | public class DSDecmp { 29 | 30 | public static byte[] Decompress(byte[] data) { 31 | return Decompress(data, 0); 32 | } 33 | 34 | public static byte[] Decompress(byte[] data, int offset) { 35 | switch (data[offset] & 0xFF) { 36 | case 0x10: 37 | return decompress10LZ(data, offset); 38 | case 0x11: 39 | return decompress11LZ(data, offset); 40 | default: 41 | return null; 42 | } 43 | } 44 | 45 | private static byte[] decompress10LZ(byte[] data, int offset) { 46 | offset++; 47 | int length = (data[offset] & 0xFF) | ((data[offset + 1] & 0xFF) << 8) | ((data[offset + 2] & 0xFF) << 16); 48 | offset += 3; 49 | if (length == 0) { 50 | length = FileFunctions.readFullInt(data, offset); 51 | offset += 4; 52 | } 53 | 54 | byte[] outData = new byte[length]; 55 | int curr_size = 0; 56 | int flags; 57 | boolean flag; 58 | int disp, n, b, cdest; 59 | while (curr_size < outData.length) { 60 | flags = data[offset++] & 0xFF; 61 | for (int i = 0; i < 8; i++) { 62 | flag = (flags & (0x80 >> i)) > 0; 63 | if (flag) { 64 | disp = 0; 65 | b = data[offset++] & 0xFF; 66 | n = b >> 4; 67 | disp = (b & 0x0F) << 8; 68 | disp |= data[offset++] & 0xFF; 69 | n += 3; 70 | cdest = curr_size; 71 | if (disp > curr_size) 72 | throw new ArrayIndexOutOfBoundsException("Cannot go back more than already written"); 73 | for (int j = 0; j < n; j++) 74 | outData[curr_size++] = outData[cdest - disp - 1 + j]; 75 | 76 | if (curr_size > outData.length) 77 | break; 78 | } else { 79 | b = data[offset++] & 0xFF; 80 | try { 81 | outData[curr_size++] = (byte) b; 82 | } catch (ArrayIndexOutOfBoundsException ex) { 83 | if (b == 0) 84 | break; 85 | } 86 | 87 | if (curr_size > outData.length) 88 | break; 89 | } 90 | } 91 | } 92 | return outData; 93 | } 94 | 95 | private static byte[] decompress11LZ(byte[] data, int offset) { 96 | offset++; 97 | int length = (data[offset] & 0xFF) | ((data[offset + 1] & 0xFF) << 8) | ((data[offset + 2] & 0xFF) << 16); 98 | offset += 3; 99 | if (length == 0) { 100 | length = FileFunctions.readFullInt(data, offset); 101 | offset += 4; 102 | } 103 | 104 | byte[] outData = new byte[length]; 105 | 106 | int curr_size = 0; 107 | int flags; 108 | boolean flag; 109 | int b1, bt, b2, b3, len, disp, cdest; 110 | 111 | while (curr_size < outData.length) { 112 | flags = data[offset++] & 0xFF; 113 | 114 | for (int i = 0; i < 8 && curr_size < outData.length; i++) { 115 | flag = (flags & (0x80 >> i)) > 0; 116 | if (flag) { 117 | b1 = data[offset++] & 0xFF; 118 | 119 | switch (b1 >> 4) { 120 | case 0: 121 | // ab cd ef 122 | // => 123 | // len = abc + 0x11 = bc + 0x11 124 | // disp = def 125 | 126 | len = b1 << 4; 127 | bt = data[offset++] & 0xFF; 128 | len |= bt >> 4; 129 | len += 0x11; 130 | 131 | disp = (bt & 0x0F) << 8; 132 | b2 = data[offset++] & 0xFF; 133 | disp |= b2; 134 | break; 135 | 136 | case 1: 137 | // ab cd ef gh 138 | // => 139 | // len = bcde + 0x111 140 | // disp = fgh 141 | // 10 04 92 3F => disp = 0x23F, len = 0x149 + 0x11 = 142 | // 0x15A 143 | bt = data[offset++] & 0xFF; 144 | b2 = data[offset++] & 0xFF; 145 | b3 = data[offset++] & 0xFF; 146 | 147 | len = (b1 & 0xF) << 12; // len = b000 148 | len |= bt << 4; // len = bcd0 149 | len |= (b2 >> 4); // len = bcde 150 | len += 0x111; // len = bcde + 0x111 151 | disp = (b2 & 0x0F) << 8; // disp = f 152 | disp |= b3; // disp = fgh 153 | break; 154 | 155 | default: 156 | // ab cd 157 | // => 158 | // len = a + threshold = a + 1 159 | // disp = bcd 160 | 161 | len = (b1 >> 4) + 1; 162 | 163 | disp = (b1 & 0x0F) << 8; 164 | b2 = data[offset++] & 0xFF; 165 | disp |= b2; 166 | break; 167 | } 168 | 169 | if (disp > curr_size) 170 | throw new ArrayIndexOutOfBoundsException("Cannot go back more than already written"); 171 | 172 | cdest = curr_size; 173 | 174 | for (int j = 0; j < len && curr_size < outData.length; j++) 175 | outData[curr_size++] = outData[cdest - disp - 1 + j]; 176 | 177 | if (curr_size > outData.length) 178 | break; 179 | } else { 180 | outData[curr_size++] = data[offset++]; 181 | 182 | if (curr_size > outData.length) 183 | break; 184 | } 185 | } 186 | 187 | } 188 | return outData; 189 | } 190 | 191 | } 192 | -------------------------------------------------------------------------------- /src/com/dabomstew/pkrandom/Utils.java: -------------------------------------------------------------------------------- 1 | package com.dabomstew.pkrandom; 2 | 3 | /*----------------------------------------------------------------------------*/ 4 | /*-- Utils.java - contains functions related to specific parts of the --*/ 5 | /*-- randomizer's functionality which cannot really be used --*/ 6 | /*-- outside of that function but should still be separated --*/ 7 | /*-- from GUI code. --*/ 8 | /*-- --*/ 9 | /*-- Part of "Universal Pokemon Randomizer" by Dabomstew --*/ 10 | /*-- Pokemon and any associated names and the like are --*/ 11 | /*-- trademark and (C) Nintendo 1996-2012. --*/ 12 | /*-- --*/ 13 | /*-- The custom code written here is licensed under the terms of the GPL: --*/ 14 | /*-- --*/ 15 | /*-- This program is free software: you can redistribute it and/or modify --*/ 16 | /*-- it under the terms of the GNU General Public License as published by --*/ 17 | /*-- the Free Software Foundation, either version 3 of the License, or --*/ 18 | /*-- (at your option) any later version. --*/ 19 | /*-- --*/ 20 | /*-- This program is distributed in the hope that it will be useful, --*/ 21 | /*-- but WITHOUT ANY WARRANTY; without even the implied warranty of --*/ 22 | /*-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the --*/ 23 | /*-- GNU General Public License for more details. --*/ 24 | /*-- --*/ 25 | /*-- You should have received a copy of the GNU General Public License --*/ 26 | /*-- along with this program. If not, see . --*/ 27 | /*----------------------------------------------------------------------------*/ 28 | 29 | import java.io.File; 30 | import java.io.FileInputStream; 31 | import java.io.FileNotFoundException; 32 | import java.io.IOException; 33 | import java.io.UnsupportedEncodingException; 34 | import java.net.URL; 35 | import java.nio.ByteBuffer; 36 | import java.util.zip.CRC32; 37 | 38 | import javax.xml.bind.DatatypeConverter; 39 | 40 | import com.dabomstew.pkrandom.exceptions.InvalidSupplementFilesException; 41 | import com.dabomstew.pkrandom.gui.RandomizerGUI; 42 | 43 | public class Utils { 44 | 45 | public static void validateRomFile(File fh) throws InvalidROMException { 46 | // first, check for common filetypes that aren't ROMs 47 | // read first 10 bytes of the file to do this 48 | try { 49 | FileInputStream fis = new FileInputStream(fh); 50 | byte[] sig = new byte[10]; 51 | int sigLength = fis.read(sig); 52 | fis.close(); 53 | if (sigLength < 10) { 54 | throw new InvalidROMException(InvalidROMException.Type.LENGTH, String.format( 55 | "%s appears to be a blank or nearly blank file.", fh.getName())); 56 | } 57 | if (sig[0] == 0x50 && sig[1] == 0x4b && sig[2] == 0x03 && sig[3] == 0x04) { 58 | throw new InvalidROMException(InvalidROMException.Type.ZIP_FILE, String.format( 59 | "%s is a ZIP archive, not a ROM.", fh.getName())); 60 | } 61 | if (sig[0] == 0x52 && sig[1] == 0x61 && sig[2] == 0x72 && sig[3] == 0x21 && sig[4] == 0x1A 62 | && sig[5] == 0x07) { 63 | throw new InvalidROMException(InvalidROMException.Type.RAR_FILE, String.format( 64 | "%s is a RAR archive, not a ROM.", fh.getName())); 65 | } 66 | if (sig[0] == 'P' && sig[1] == 'A' && sig[2] == 'T' && sig[3] == 'C' && sig[4] == 'H') { 67 | throw new InvalidROMException(InvalidROMException.Type.IPS_FILE, String.format( 68 | "%s is a IPS patch, not a ROM.", fh.getName())); 69 | } 70 | } catch (IOException ex) { 71 | throw new InvalidROMException(InvalidROMException.Type.UNREADABLE, String.format( 72 | "Could not read %s from disk.", fh.getName())); 73 | } 74 | } 75 | 76 | // RomHandlers implicitly rely on these - call this before creating settings 77 | // etc. 78 | public static void testForRequiredConfigs() throws FileNotFoundException { 79 | String[] required = new String[] { "gameboy_jap.tbl", "rby_english.tbl", "rby_freger.tbl", "rby_espita.tbl", 80 | "green_translation.tbl", "gsc_english.tbl", "gsc_freger.tbl", "gsc_espita.tbl", "gba_english.tbl", 81 | "gba_jap.tbl", "Generation4.tbl", "Generation5.tbl", "gen1_offsets.ini", "gen2_offsets.ini", 82 | "gen3_offsets.ini", "gen4_offsets.ini", "gen5_offsets.ini", SysConstants.customNamesFile }; 83 | for (String filename : required) { 84 | if (!FileFunctions.configExists(filename)) { 85 | throw new FileNotFoundException(filename); 86 | } 87 | } 88 | } 89 | 90 | public static void validatePresetSupplementFiles(String config, CustomNamesSet customNames) 91 | throws UnsupportedEncodingException, InvalidSupplementFilesException { 92 | byte[] data = DatatypeConverter.parseBase64Binary(config); 93 | 94 | if (data.length < Settings.LENGTH_OF_SETTINGS_DATA + 9) { 95 | throw new InvalidSupplementFilesException(InvalidSupplementFilesException.Type.UNKNOWN, 96 | "The preset config is too short to be valid"); 97 | } 98 | 99 | // Check the checksum 100 | ByteBuffer buf = ByteBuffer.allocate(4).put(data, data.length - 8, 4); 101 | buf.rewind(); 102 | int crc = buf.getInt(); 103 | 104 | CRC32 checksum = new CRC32(); 105 | checksum.update(data, 0, data.length - 8); 106 | if ((int) checksum.getValue() != crc) { 107 | throw new IllegalArgumentException("Checksum failure."); 108 | } 109 | 110 | // Check the trainerclass & trainernames & nicknames crc 111 | if (customNames == null && !FileFunctions.checkOtherCRC(data, 16, 4, SysConstants.customNamesFile, data.length - 4)) { 112 | throw new InvalidSupplementFilesException(InvalidSupplementFilesException.Type.CUSTOM_NAMES, 113 | "Can't use this preset because you have a different set " + "of custom names to the creator."); 114 | } 115 | } 116 | 117 | public static File getExecutionLocation() throws UnsupportedEncodingException { 118 | URL location = RandomizerGUI.class.getProtectionDomain().getCodeSource().getLocation(); 119 | File fh = new File(java.net.URLDecoder.decode(location.getFile(), "UTF-8")); 120 | return fh; 121 | } 122 | 123 | public static class InvalidROMException extends Exception { 124 | /** 125 | * 126 | */ 127 | private static final long serialVersionUID = 6568398515886021477L; 128 | 129 | public enum Type { 130 | LENGTH, ZIP_FILE, RAR_FILE, IPS_FILE, UNREADABLE 131 | } 132 | 133 | private final Type type; 134 | 135 | public InvalidROMException(Type type, String message) { 136 | super(message); 137 | this.type = type; 138 | } 139 | 140 | public Type getType() { 141 | return type; 142 | } 143 | } 144 | } -------------------------------------------------------------------------------- /src/thenewpoketext/TextToPoke.java: -------------------------------------------------------------------------------- 1 | package thenewpoketext; 2 | 3 | /*----------------------------------------------------------------------------*/ 4 | /*-- TextToPoke.java - encodes gen4 games text from Unicode --*/ 5 | /*-- Code derived from "thenewpoketext", copyright (C) loadingNOW --*/ 6 | /*-- Ported to Java and bugfixed/customized by Dabomstew --*/ 7 | /*----------------------------------------------------------------------------*/ 8 | 9 | import java.util.ArrayList; 10 | import java.util.Arrays; 11 | import java.util.List; 12 | 13 | public class TextToPoke { 14 | 15 | public static byte[] MakeFile(List textarr, boolean compressed) { 16 | int base = textarr.size() * 8 + 4; 17 | List ptrtable = new ArrayList(); 18 | List> rawdata = new ArrayList>(); 19 | for (int i = 0; i < textarr.size(); i++) { 20 | List data = ToCode(textarr.get(i), compressed); 21 | int l = data.size(); 22 | ptrtable.add(new PointerEntry(base, l)); 23 | rawdata.add(data); 24 | base += l * 2; 25 | } 26 | 27 | List hdr = Arrays.asList(textarr.size(), 0); 28 | 29 | return join(wordListToBarr(hdr), pointerListToBarr(ptrtable), listOfWordListToBarr(rawdata)); 30 | } 31 | 32 | private static List ToCode(String text, boolean compressed) { 33 | List data = new ArrayList(); 34 | while (text.length() != 0) { 35 | int i = Math.max(0, 6 - text.length()); 36 | if (text.charAt(0) == '\\') { 37 | if (text.charAt(1) == 'x') { 38 | data.add(Integer.parseInt(text.substring(2, 6), 16)); 39 | text = text.substring(6); 40 | } else if (text.charAt(1) == 'v') { 41 | data.add(0xFFFE); 42 | data.add(Integer.parseInt(text.substring(2, 6), 16)); 43 | text = text.substring(6); 44 | } else if (text.charAt(1) == 'z') { 45 | List var = new ArrayList(); 46 | int w = 0; 47 | while (text.length() != 0) { 48 | if (text.charAt(0) == '\\' && text.charAt(1) == 'z') { 49 | w++; 50 | var.add(Integer.parseInt(text.substring(2, 6), 16)); 51 | text = text.substring(6); 52 | } else { 53 | break; 54 | } 55 | } 56 | data.add(w); 57 | data.addAll(var); 58 | } else if (text.charAt(1) == 'n') { 59 | data.add(0xE000); 60 | text = text.substring(2); 61 | } else if (text.charAt(1) == 'p') { 62 | data.add(0x25BC); 63 | text = text.substring(2); 64 | } else if (text.charAt(1) == 'l') { 65 | data.add(0x25BD); 66 | text = text.substring(2); 67 | } else if (text.substring(1, 4).equals("and")) { 68 | data.add(0x1C2); 69 | text = text.substring(4); 70 | } else { 71 | System.out.printf("unknown escape: %s\n", text.substring(1, 2)); 72 | text = text.substring(2); 73 | } 74 | } else { 75 | while (!(UnicodeParser.d.containsKey(text.substring(0, 6 - i)) || (i == 6))) { 76 | i++; 77 | } 78 | if (i == 6) { 79 | System.out.printf("Char not found %s(%d)", text.substring(0, 1), text.charAt(0)); 80 | text = text.substring(1); 81 | } else { 82 | data.add(UnicodeParser.d.get(text.substring(0, 6 - i))); 83 | text = text.substring(6 - i); 84 | } 85 | } 86 | } 87 | if (compressed) { 88 | if (data.size() % 5 != 0 || data.size() == 0) { 89 | data.add(0x1FF); 90 | } 91 | byte[] bits = new byte[data.size() * 9]; 92 | int bc = 0; 93 | for (int i = 0; i < data.size(); i++) { 94 | for (int j = 0; j < 9; j++) { 95 | bits[bc++] = (byte) ((data.get(i) >> j) & 1); 96 | } 97 | } 98 | int tmp_uint16 = 0; 99 | data.clear(); 100 | data.add(0xF100); 101 | for (int i = 0; i < bits.length; i++) { 102 | if (i % 15 == 0 && i != 0) { 103 | data.add(tmp_uint16); 104 | tmp_uint16 = 0; 105 | } 106 | tmp_uint16 |= (bits[i] << (i % 15)); 107 | } 108 | data.add(tmp_uint16); 109 | } 110 | data.add(0xFFFF); 111 | return data; 112 | } 113 | 114 | private static byte[] join(byte[]... args) { 115 | int tlen = 0; 116 | for (byte[] arr : args) { 117 | tlen += arr.length; 118 | } 119 | byte[] barr = new byte[tlen]; 120 | int offs = 0; 121 | for (byte[] arr : args) { 122 | System.arraycopy(arr, 0, barr, offs, arr.length); 123 | offs += arr.length; 124 | } 125 | return barr; 126 | } 127 | 128 | private static byte[] wordListToBarr(List list) { 129 | byte[] barr = new byte[list.size() * 2]; 130 | int l = list.size(); 131 | for (int i = 0; i < l; i++) { 132 | barr[i * 2] = (byte) (list.get(i) & 0xFF); 133 | barr[i * 2 + 1] = (byte) ((list.get(i) >> 8) & 0xFF); 134 | } 135 | return barr; 136 | } 137 | 138 | private static byte[] pointerListToBarr(List ptrList) { 139 | byte[] data = new byte[ptrList.size() * 8]; 140 | int l = ptrList.size(); 141 | for (int i = 0; i < l; i++) { 142 | int ofs = i * 8; 143 | PointerEntry ent = ptrList.get(i); 144 | data[ofs] = (byte) (ent.ptr & 0xFF); 145 | data[ofs + 1] = (byte) ((ent.ptr >> 8) & 0xFF); 146 | data[ofs + 2] = (byte) ((ent.ptr >> 16) & 0xFF); 147 | data[ofs + 3] = (byte) ((ent.ptr >> 24) & 0xFF); 148 | data[ofs + 4] = (byte) (ent.chars & 0xFF); 149 | data[ofs + 5] = (byte) ((ent.chars >> 8) & 0xFF); 150 | data[ofs + 6] = (byte) ((ent.chars >> 16) & 0xFF); 151 | data[ofs + 7] = (byte) ((ent.chars >> 24) & 0xFF); 152 | } 153 | return data; 154 | } 155 | 156 | private static byte[] listOfWordListToBarr(List> list) { 157 | int tlen = 0; 158 | for (List subList : list) { 159 | tlen += subList.size() * 2; 160 | } 161 | byte[] barr = new byte[tlen]; 162 | int offs = 0; 163 | int l1 = list.size(); 164 | for (int j = 0; j < l1; j++) { 165 | List slist = list.get(j); 166 | int l2 = slist.size(); 167 | for (int i = 0; i < l2; i++) { 168 | barr[offs] = (byte) (slist.get(i) & 0xFF); 169 | barr[offs + 1] = (byte) ((slist.get(i) >> 8) & 0xFF); 170 | offs += 2; 171 | } 172 | } 173 | return barr; 174 | } 175 | 176 | private static class PointerEntry { 177 | 178 | private int ptr; 179 | private int chars; 180 | 181 | public PointerEntry(int ptr, int chars) { 182 | this.ptr = ptr; 183 | this.chars = chars; 184 | } 185 | } 186 | 187 | } 188 | -------------------------------------------------------------------------------- /src/com/dabomstew/pkrandom/romhandlers/AbstractGBCRomHandler.java: -------------------------------------------------------------------------------- 1 | package com.dabomstew.pkrandom.romhandlers; 2 | 3 | import java.io.ByteArrayOutputStream; 4 | import java.io.FileNotFoundException; 5 | import java.io.PrintStream; 6 | import java.io.UnsupportedEncodingException; 7 | import java.util.HashMap; 8 | import java.util.Map; 9 | import java.util.Random; 10 | import java.util.Scanner; 11 | 12 | import com.dabomstew.pkrandom.FileFunctions; 13 | import com.dabomstew.pkrandom.constants.GBConstants; 14 | 15 | public abstract class AbstractGBCRomHandler extends AbstractGBRomHandler { 16 | 17 | private String[] tb; 18 | private Map d; 19 | private int longestTableToken; 20 | 21 | public AbstractGBCRomHandler(Random random, PrintStream logStream) { 22 | super(random, logStream); 23 | } 24 | 25 | protected void clearTextTables() { 26 | tb = new String[256]; 27 | if (d != null) { 28 | d.clear(); 29 | } else { 30 | d = new HashMap(); 31 | } 32 | longestTableToken = 0; 33 | } 34 | 35 | protected void readTextTable(String name) { 36 | try { 37 | Scanner sc = new Scanner(FileFunctions.openConfig(name + ".tbl"), "UTF-8"); 38 | while (sc.hasNextLine()) { 39 | String q = sc.nextLine(); 40 | if (!q.trim().isEmpty()) { 41 | String[] r = q.split("=", 2); 42 | if (r[1].endsWith("\r\n")) { 43 | r[1] = r[1].substring(0, r[1].length() - 2); 44 | } 45 | int hexcode = Integer.parseInt(r[0], 16); 46 | if (tb[hexcode] != null) { 47 | String oldMatch = tb[hexcode]; 48 | tb[hexcode] = null; 49 | if (d.get(oldMatch) == hexcode) { 50 | d.remove(oldMatch); 51 | } 52 | } 53 | tb[hexcode] = r[1]; 54 | longestTableToken = Math.max(longestTableToken, r[1].length()); 55 | d.put(r[1], (byte) hexcode); 56 | } 57 | } 58 | sc.close(); 59 | } catch (FileNotFoundException e) { 60 | } 61 | 62 | } 63 | 64 | protected String readString(int offset, int maxLength, boolean textEngineMode) { 65 | StringBuilder string = new StringBuilder(); 66 | for (int c = 0; c < maxLength; c++) { 67 | int currChar = rom[offset + c] & 0xFF; 68 | if (tb[currChar] != null) { 69 | string.append(tb[currChar]); 70 | if (textEngineMode && (tb[currChar].equals("\\r") || tb[currChar].equals("\\e"))) { 71 | break; 72 | } 73 | } else { 74 | if (currChar == GBConstants.stringTerminator) { 75 | break; 76 | } else { 77 | string.append("\\x" + String.format("%02X", currChar)); 78 | } 79 | } 80 | } 81 | return string.toString(); 82 | } 83 | 84 | protected int lengthOfStringAt(int offset, boolean textEngineMode) { 85 | int len = 0; 86 | while (rom[offset + len] != GBConstants.stringTerminator 87 | && (!textEngineMode || (rom[offset + len] != GBConstants.stringPrintedTextEnd && rom[offset + len] != GBConstants.stringPrintedTextPromptEnd))) { 88 | len++; 89 | } 90 | 91 | if (textEngineMode 92 | && (rom[offset + len] == GBConstants.stringPrintedTextEnd || rom[offset + len] == GBConstants.stringPrintedTextPromptEnd)) { 93 | len++; 94 | } 95 | return len; 96 | } 97 | 98 | protected byte[] translateString(String text) { 99 | ByteArrayOutputStream baos = new ByteArrayOutputStream(); 100 | while (text.length() != 0) { 101 | int i = Math.max(0, longestTableToken - text.length()); 102 | if (text.charAt(0) == '\\' && text.charAt(1) == 'x') { 103 | baos.write(Integer.parseInt(text.substring(2, 4), 16)); 104 | text = text.substring(4); 105 | } else { 106 | while (!(d.containsKey(text.substring(0, longestTableToken - i)) || (i == longestTableToken))) { 107 | i++; 108 | } 109 | if (i == longestTableToken) { 110 | text = text.substring(1); 111 | } else { 112 | baos.write(d.get(text.substring(0, longestTableToken - i)) & 0xFF); 113 | text = text.substring(longestTableToken - i); 114 | } 115 | } 116 | } 117 | return baos.toByteArray(); 118 | } 119 | 120 | protected String readFixedLengthString(int offset, int length) { 121 | return readString(offset, length, false); 122 | } 123 | 124 | // pads the length with terminators, so length should be at least str's len 125 | // + 1 126 | protected void writeFixedLengthString(String str, int offset, int length) { 127 | byte[] translated = translateString(str); 128 | int len = Math.min(translated.length, length); 129 | System.arraycopy(translated, 0, rom, offset, len); 130 | while (len < length) { 131 | rom[offset + len] = GBConstants.stringTerminator; 132 | len++; 133 | } 134 | } 135 | 136 | protected void writeVariableLengthString(String str, int offset, boolean alreadyTerminated) { 137 | byte[] translated = translateString(str); 138 | System.arraycopy(translated, 0, rom, offset, translated.length); 139 | if (!alreadyTerminated) { 140 | rom[offset + translated.length] = GBConstants.stringTerminator; 141 | } 142 | } 143 | 144 | protected int makeGBPointer(int offset) { 145 | if (offset < GBConstants.bankSize) { 146 | return offset; 147 | } else { 148 | return (offset % GBConstants.bankSize) + GBConstants.bankSize; 149 | } 150 | } 151 | 152 | protected int bankOf(int offset) { 153 | return (offset / GBConstants.bankSize); 154 | } 155 | 156 | protected int calculateOffset(int bank, int pointer) { 157 | if (pointer < GBConstants.bankSize) { 158 | return pointer; 159 | } else { 160 | return (pointer % GBConstants.bankSize) + bank * GBConstants.bankSize; 161 | } 162 | } 163 | 164 | protected String readVariableLengthString(int offset, boolean textEngineMode) { 165 | return readString(offset, Integer.MAX_VALUE, textEngineMode); 166 | } 167 | 168 | protected static boolean romSig(byte[] rom, String sig) { 169 | try { 170 | int sigOffset = GBConstants.romSigOffset; 171 | byte[] sigBytes = sig.getBytes("US-ASCII"); 172 | for (int i = 0; i < sigBytes.length; i++) { 173 | if (rom[sigOffset + i] != sigBytes[i]) { 174 | return false; 175 | } 176 | } 177 | return true; 178 | } catch (UnsupportedEncodingException ex) { 179 | return false; 180 | } 181 | 182 | } 183 | 184 | protected static boolean romCode(byte[] rom, String code) { 185 | try { 186 | int sigOffset = GBConstants.romCodeOffset; 187 | byte[] sigBytes = code.getBytes("US-ASCII"); 188 | for (int i = 0; i < sigBytes.length; i++) { 189 | if (rom[sigOffset + i] != sigBytes[i]) { 190 | return false; 191 | } 192 | } 193 | return true; 194 | } catch (UnsupportedEncodingException ex) { 195 | return false; 196 | } 197 | 198 | } 199 | 200 | } 201 | -------------------------------------------------------------------------------- /src/com/dabomstew/pkrandom/newnds/NARCArchive.java: -------------------------------------------------------------------------------- 1 | package com.dabomstew.pkrandom.newnds; 2 | 3 | import java.io.IOException; 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | import java.util.Map; 7 | import java.util.TreeMap; 8 | 9 | public class NARCArchive { 10 | 11 | public List filenames = new ArrayList(); 12 | public List files = new ArrayList(); 13 | 14 | public boolean hasFilenames = false; 15 | 16 | public NARCArchive() { 17 | // creates a new empty NARC with no filenames by default 18 | } 19 | 20 | public NARCArchive(byte[] data) throws IOException { 21 | Map frames = readNitroFrames(data); 22 | if (!frames.containsKey("FATB") || !frames.containsKey("FNTB") || !frames.containsKey("FIMG")) { 23 | throw new IOException("Not a valid narc file"); 24 | } 25 | 26 | // File contents 27 | byte[] fatbframe = frames.get("FATB"); 28 | byte[] fimgframe = frames.get("FIMG"); 29 | int fileCount = readLong(fatbframe, 0); 30 | for (int i = 0; i < fileCount; i++) { 31 | int startOffset = readLong(fatbframe, 4 + i * 8); 32 | int endOffset = readLong(fatbframe, 8 + i * 8); 33 | int length = (endOffset - startOffset); 34 | byte[] thisFile = new byte[length]; 35 | System.arraycopy(fimgframe, startOffset, thisFile, 0, length); 36 | files.add(thisFile); 37 | } 38 | 39 | // Filenames? 40 | byte[] fntbframe = frames.get("FNTB"); 41 | int unk1 = readLong(fntbframe, 0); 42 | if (unk1 == 8) { 43 | // Filenames exist 44 | hasFilenames = true; 45 | int offset = 8; 46 | for (int i = 0; i < fileCount; i++) { 47 | int fnLength = (fntbframe[offset] & 0xFF); 48 | offset++; 49 | byte[] filenameBA = new byte[fnLength]; 50 | System.arraycopy(fntbframe, offset, filenameBA, 0, fnLength); 51 | String filename = new String(filenameBA, "US-ASCII"); 52 | filenames.add(filename); 53 | } 54 | } else { 55 | hasFilenames = false; 56 | for (int i = 0; i < fileCount; i++) { 57 | filenames.add(null); 58 | } 59 | } 60 | } 61 | 62 | public byte[] getBytes() throws IOException { 63 | // Get bytes required for FIMG frame 64 | int bytesRequired = 0; 65 | for (byte[] file : files) { 66 | bytesRequired += Math.ceil(file.length / 4.0) * 4; 67 | } 68 | // FIMG frame & FATB frame build 69 | 70 | // 4 for numentries, 8*size for entries, 8 for nitro header 71 | byte[] fatbFrame = new byte[4 + files.size() * 8 + 8]; 72 | // bytesRequired + 8 for nitro header 73 | byte[] fimgFrame = new byte[bytesRequired + 8]; 74 | 75 | // Nitro headers 76 | fatbFrame[0] = 'B'; 77 | fatbFrame[1] = 'T'; 78 | fatbFrame[2] = 'A'; 79 | fatbFrame[3] = 'F'; 80 | writeLong(fatbFrame, 4, fatbFrame.length); 81 | 82 | fimgFrame[0] = 'G'; 83 | fimgFrame[1] = 'M'; 84 | fimgFrame[2] = 'I'; 85 | fimgFrame[3] = 'F'; 86 | writeLong(fimgFrame, 4, fimgFrame.length); 87 | int offset = 0; 88 | 89 | writeLong(fatbFrame, 8, files.size()); 90 | for (int i = 0; i < files.size(); i++) { 91 | byte[] file = files.get(i); 92 | int bytesRequiredForFile = (int) (Math.ceil(file.length / 4.0) * 4); 93 | System.arraycopy(file, 0, fimgFrame, offset + 8, file.length); 94 | for (int filler = file.length; filler < bytesRequiredForFile; filler++) { 95 | fimgFrame[offset + 8 + filler] = (byte) 0xFF; 96 | } 97 | writeLong(fatbFrame, 12 + i * 8, offset); 98 | writeLong(fatbFrame, 16 + i * 8, offset + file.length); 99 | offset += bytesRequiredForFile; 100 | } 101 | 102 | // FNTB Frame 103 | int bytesForFNTBFrame = 16; 104 | if (hasFilenames) { 105 | for (String filename : filenames) { 106 | bytesForFNTBFrame += filename.getBytes("US-ASCII").length + 1; 107 | } 108 | } 109 | byte[] fntbFrame = new byte[bytesForFNTBFrame]; 110 | 111 | fntbFrame[0] = 'B'; 112 | fntbFrame[1] = 'T'; 113 | fntbFrame[2] = 'N'; 114 | fntbFrame[3] = 'F'; 115 | writeLong(fntbFrame, 4, fntbFrame.length); 116 | 117 | if (hasFilenames) { 118 | writeLong(fntbFrame, 8, 8); 119 | writeLong(fntbFrame, 12, 0x10000); 120 | int fntbOffset = 16; 121 | for (String filename : filenames) { 122 | byte[] fntbfilename = filename.getBytes("US-ASCII"); 123 | fntbFrame[fntbOffset] = (byte) fntbfilename.length; 124 | System.arraycopy(fntbfilename, 0, fntbFrame, fntbOffset + 1, fntbfilename.length); 125 | fntbOffset += 1 + fntbfilename.length; 126 | } 127 | } else { 128 | writeLong(fntbFrame, 8, 4); 129 | writeLong(fntbFrame, 12, 0x10000); 130 | } 131 | 132 | // Now for the actual Nitro file 133 | int nitrolength = 16 + fatbFrame.length + fntbFrame.length + fimgFrame.length; 134 | byte[] nitroFile = new byte[nitrolength]; 135 | nitroFile[0] = 'N'; 136 | nitroFile[1] = 'A'; 137 | nitroFile[2] = 'R'; 138 | nitroFile[3] = 'C'; 139 | writeWord(nitroFile, 4, 0xFFFE); 140 | writeWord(nitroFile, 6, 0x0100); 141 | writeLong(nitroFile, 8, nitrolength); 142 | writeWord(nitroFile, 12, 0x10); 143 | writeWord(nitroFile, 14, 3); 144 | System.arraycopy(fatbFrame, 0, nitroFile, 16, fatbFrame.length); 145 | System.arraycopy(fntbFrame, 0, nitroFile, 16 + fatbFrame.length, fntbFrame.length); 146 | System.arraycopy(fimgFrame, 0, nitroFile, 16 + fatbFrame.length + fntbFrame.length, fimgFrame.length); 147 | 148 | return nitroFile; 149 | } 150 | 151 | private Map readNitroFrames(byte[] data) throws IOException { 152 | 153 | // Read the number of frames 154 | int frameCount = readWord(data, 0x0E); 155 | 156 | // each frame 157 | int offset = 0x10; 158 | Map frames = new TreeMap(); 159 | for (int i = 0; i < frameCount; i++) { 160 | byte[] magic = new byte[] { data[offset + 3], data[offset + 2], data[offset + 1], data[offset] }; 161 | String magicS = new String(magic, "US-ASCII"); 162 | 163 | int frame_size = readLong(data, offset + 4); 164 | // Patch for BB/VW and other DS hacks which don't update 165 | // the size of their expanded NARCs correctly 166 | if (i == frameCount - 1 && offset + frame_size < data.length) { 167 | frame_size = data.length - offset; 168 | } 169 | byte[] frame = new byte[frame_size - 8]; 170 | System.arraycopy(data, offset + 8, frame, 0, frame_size - 8); 171 | frames.put(magicS, frame); 172 | offset += frame_size; 173 | } 174 | return frames; 175 | } 176 | 177 | private int readWord(byte[] data, int offset) { 178 | return (data[offset] & 0xFF) | ((data[offset + 1] & 0xFF) << 8); 179 | } 180 | 181 | private int readLong(byte[] data, int offset) { 182 | return (data[offset] & 0xFF) | ((data[offset + 1] & 0xFF) << 8) | ((data[offset + 2] & 0xFF) << 16) 183 | | ((data[offset + 3] & 0xFF) << 24); 184 | } 185 | 186 | private void writeWord(byte[] data, int offset, int value) { 187 | data[offset] = (byte) (value & 0xFF); 188 | data[offset + 1] = (byte) ((value >> 8) & 0xFF); 189 | } 190 | 191 | private void writeLong(byte[] data, int offset, int value) { 192 | data[offset] = (byte) (value & 0xFF); 193 | data[offset + 1] = (byte) ((value >> 8) & 0xFF); 194 | data[offset + 2] = (byte) ((value >> 16) & 0xFF); 195 | data[offset + 3] = (byte) ((value >> 24) & 0xFF); 196 | } 197 | 198 | } 199 | -------------------------------------------------------------------------------- /src/com/dabomstew/pkrandom/CustomNamesSet.java: -------------------------------------------------------------------------------- 1 | package com.dabomstew.pkrandom; 2 | 3 | import java.io.ByteArrayInputStream; 4 | import java.io.ByteArrayOutputStream; 5 | import java.io.FileNotFoundException; 6 | import java.io.IOException; 7 | import java.io.InputStream; 8 | import java.io.OutputStream; 9 | import java.util.ArrayList; 10 | import java.util.Collections; 11 | import java.util.List; 12 | import java.util.Scanner; 13 | 14 | public class CustomNamesSet { 15 | 16 | private List trainerNames; 17 | private List trainerClasses; 18 | private List doublesTrainerNames; 19 | private List doublesTrainerClasses; 20 | private List pokemonNicknames; 21 | 22 | private static final int CUSTOM_NAMES_VERSION = 1; 23 | 24 | // Standard constructor: read binary data from an input stream. 25 | public CustomNamesSet(InputStream data) throws IOException { 26 | 27 | if (data.read() != CUSTOM_NAMES_VERSION) { 28 | throw new IOException("Invalid custom names file provided."); 29 | } 30 | 31 | trainerNames = readNamesBlock(data); 32 | trainerClasses = readNamesBlock(data); 33 | doublesTrainerNames = readNamesBlock(data); 34 | doublesTrainerClasses = readNamesBlock(data); 35 | pokemonNicknames = readNamesBlock(data); 36 | } 37 | 38 | // Alternate constructor: blank all lists 39 | // Used for importing old names and on the editor dialog. 40 | public CustomNamesSet() { 41 | trainerNames = new ArrayList(); 42 | trainerClasses = new ArrayList(); 43 | doublesTrainerNames = new ArrayList(); 44 | doublesTrainerClasses = new ArrayList(); 45 | pokemonNicknames = new ArrayList(); 46 | } 47 | 48 | private List readNamesBlock(InputStream in) throws IOException { 49 | // Read the size of the block to come. 50 | byte[] szData = FileFunctions.readFullyIntoBuffer(in, 4); 51 | int size = FileFunctions.readFullInt(szData, 0); 52 | if (in.available() < size) { 53 | throw new IOException("Invalid size specified."); 54 | } 55 | 56 | // Read the block and translate it into a list of names. 57 | byte[] namesData = FileFunctions.readFullyIntoBuffer(in, size); 58 | List names = new ArrayList(); 59 | Scanner sc = new Scanner(new ByteArrayInputStream(namesData), "UTF-8"); 60 | while (sc.hasNextLine()) { 61 | String name = sc.nextLine().trim(); 62 | if (!name.isEmpty()) { 63 | names.add(name); 64 | } 65 | } 66 | sc.close(); 67 | 68 | return names; 69 | } 70 | 71 | public byte[] getBytes() throws IOException { 72 | ByteArrayOutputStream baos = new ByteArrayOutputStream(); 73 | 74 | baos.write(CUSTOM_NAMES_VERSION); 75 | 76 | writeNamesBlock(baos, trainerNames); 77 | writeNamesBlock(baos, trainerClasses); 78 | writeNamesBlock(baos, doublesTrainerNames); 79 | writeNamesBlock(baos, doublesTrainerClasses); 80 | writeNamesBlock(baos, pokemonNicknames); 81 | 82 | return baos.toByteArray(); 83 | } 84 | 85 | private void writeNamesBlock(OutputStream out, List names) throws IOException { 86 | String newln = SysConstants.LINE_SEP; 87 | StringBuffer outNames = new StringBuffer(); 88 | boolean first = true; 89 | for (String name : names) { 90 | if (!first) { 91 | outNames.append(newln); 92 | } 93 | first = false; 94 | outNames.append(name); 95 | } 96 | byte[] namesData = outNames.toString().getBytes("UTF-8"); 97 | byte[] szData = new byte[4]; 98 | FileFunctions.writeFullInt(szData, 0, namesData.length); 99 | out.write(szData); 100 | out.write(namesData); 101 | } 102 | 103 | public List getTrainerNames() { 104 | return Collections.unmodifiableList(trainerNames); 105 | } 106 | 107 | public List getTrainerClasses() { 108 | return Collections.unmodifiableList(trainerClasses); 109 | } 110 | 111 | public List getDoublesTrainerNames() { 112 | return Collections.unmodifiableList(doublesTrainerNames); 113 | } 114 | 115 | public List getDoublesTrainerClasses() { 116 | return Collections.unmodifiableList(doublesTrainerClasses); 117 | } 118 | 119 | public List getPokemonNicknames() { 120 | return Collections.unmodifiableList(pokemonNicknames); 121 | } 122 | 123 | public void setTrainerNames(List names) { 124 | trainerNames.clear(); 125 | trainerNames.addAll(names); 126 | } 127 | 128 | public void setTrainerClasses(List names) { 129 | trainerClasses.clear(); 130 | trainerClasses.addAll(names); 131 | } 132 | 133 | public void setDoublesTrainerNames(List names) { 134 | doublesTrainerNames.clear(); 135 | doublesTrainerNames.addAll(names); 136 | } 137 | 138 | public void setDoublesTrainerClasses(List names) { 139 | doublesTrainerClasses.clear(); 140 | doublesTrainerClasses.addAll(names); 141 | } 142 | 143 | public void setPokemonNicknames(List names) { 144 | pokemonNicknames.clear(); 145 | pokemonNicknames.addAll(names); 146 | } 147 | 148 | public static CustomNamesSet importOldNames() throws FileNotFoundException { 149 | CustomNamesSet cns = new CustomNamesSet(); 150 | 151 | // Trainer Names 152 | if (FileFunctions.configExists(SysConstants.tnamesFile)) { 153 | Scanner sc = new Scanner(FileFunctions.openConfig(SysConstants.tnamesFile), "UTF-8"); 154 | while (sc.hasNextLine()) { 155 | String trainername = sc.nextLine().trim(); 156 | if (trainername.isEmpty()) { 157 | continue; 158 | } 159 | if (trainername.startsWith("\uFEFF")) { 160 | trainername = trainername.substring(1); 161 | } 162 | if (trainername.contains("&")) { 163 | cns.doublesTrainerNames.add(trainername); 164 | } else { 165 | cns.trainerNames.add(trainername); 166 | } 167 | } 168 | sc.close(); 169 | } 170 | 171 | // Trainer Classes 172 | if (FileFunctions.configExists(SysConstants.tclassesFile)) { 173 | Scanner sc = new Scanner(FileFunctions.openConfig(SysConstants.tclassesFile), "UTF-8"); 174 | while (sc.hasNextLine()) { 175 | String trainerClassName = sc.nextLine().trim(); 176 | if (trainerClassName.isEmpty()) { 177 | continue; 178 | } 179 | if (trainerClassName.startsWith("\uFEFF")) { 180 | trainerClassName = trainerClassName.substring(1); 181 | } 182 | String checkName = trainerClassName.toLowerCase(); 183 | int idx = (checkName.endsWith("couple") || checkName.contains(" and ") || checkName.endsWith("kin") 184 | || checkName.endsWith("team") || checkName.contains("&") || (checkName.endsWith("s") && !checkName 185 | .endsWith("ss"))) ? 1 : 0; 186 | if (idx == 1) { 187 | cns.doublesTrainerClasses.add(trainerClassName); 188 | } else { 189 | cns.trainerClasses.add(trainerClassName); 190 | } 191 | } 192 | sc.close(); 193 | } 194 | 195 | // Nicknames 196 | if (FileFunctions.configExists(SysConstants.nnamesFile)) { 197 | Scanner sc = new Scanner(FileFunctions.openConfig(SysConstants.nnamesFile), "UTF-8"); 198 | while (sc.hasNextLine()) { 199 | String nickname = sc.nextLine().trim(); 200 | if (nickname.isEmpty()) { 201 | continue; 202 | } 203 | if (nickname.startsWith("\uFEFF")) { 204 | nickname = nickname.substring(1); 205 | } 206 | cns.pokemonNicknames.add(nickname); 207 | } 208 | sc.close(); 209 | } 210 | 211 | return cns; 212 | } 213 | 214 | } 215 | --------------------------------------------------------------------------------