shithub: pokecrystal

Download patch

ref: 09603bf0315862d7c008e08a9960e6111a0859f8
parent: eb39f6a3396b21047a11dd871263c6dbc5f2c65f
author: PikalaxALT <[email protected]>
date: Sat Nov 7 09:38:52 EST 2015

More Battle Tower shenanigans

--- a/constants/misc_constants.asm
+++ b/constants/misc_constants.asm
@@ -114,6 +114,7 @@
 BATTLETOWER_TRAINERDATALENGTH EQU $24
 BATTLETOWER_NROFTRAINERS EQU 7
 BATTLETOWER_NRMONSPERLEVELBRACKET EQU BATTLETOWER_NROFPKMNS * BATTLETOWER_NROFTRAINERS
+BATTLE_TOWER_STRUCT_LENGTH EQU $e0 ; NAME_LENGTH + 3 * (PARTYMON_STRUCT_LENGTH + PKMN_NAME_LENGTH) + BATTLETOWER_TRAINERDATALENGTH
 
 NUM_WILDMONS_PER_AREA_TIME_OF_DAY EQU 7
 WILDMON_GRASS_STRUCTURE_LENGTH EQU 2 + 3 * (1 + 2 * NUM_WILDMONS_PER_AREA_TIME_OF_DAY)
--- a/data/battle_tower.asm
+++ b/data/battle_tower.asm
@@ -1,13 +1,13 @@
 Function_LoadOpponentTrainerAndPokemons: ; 1f8000
 	ld a, [rSVBK]
 	push af
-	ld a, BANK(BT_OTrainer)
+	ld a, BANK(BT_OTTrainer)
 	ld [rSVBK], a
 	
-	; Fill BT_OTrainer with zeros
+	; Fill BT_OTTrainer with zeros
 	xor a
-	ld hl, BT_OTrainer
-	ld bc, BT_OTrainerEnd - BT_OTrainer
+	ld hl, BT_OTTrainer
+	ld bc, BT_OTTrainerEnd - BT_OTTrainer
 	call ByteFill
 	
 	; Write $ff into the Item-Slots
@@ -17,7 +17,7 @@
 	ld [BT_OTPkmn3Item], a
 	
 	; Set BT_OTTrainer as start address to write the following data to
-	ld de, BT_OTrainer
+	ld de, BT_OTTrainer
 
 	ld a, [hRandomAdd]
 	ld b, a
--- a/engine/specials.asm
+++ b/engine/specials.asm
@@ -141,7 +141,7 @@
 	add_special Function170114
 	add_special BattleTowerBattle
 	add_special Function1704e1
-	add_special Function17021d
+	add_special EmptySpecial_17021d
 	add_special Function_LoadOpponentTrainerAndPokemonsWithOTSprite
 	add_special Function11ba38
 	add_special SpecialCheckForBattleTowerRules
--- a/main.asm
+++ b/main.asm
@@ -15809,7 +15809,7 @@
 	push bc
 	call Function13b71
 	push de
-	callba Function17d073
+	callba CheckStringForErrors
 	pop hl
 	pop bc
 	jr nc, .asm_13b0e
@@ -15847,7 +15847,7 @@
 	push bc
 	call Function13b71
 	push de
-	callba Function17d073
+	callba CheckStringForErrors
 	pop hl
 	jr nc, .asm_13b34
 	ld d, h
--- a/misc/battle_tower_47.asm
+++ b/misc/battle_tower_47.asm
@@ -1,16 +1,16 @@
 BattleTowerText:: ; 11c000
-; Print text c for trainer [BT_OTrainer_TrainerClass]
+; Print text c for trainer [BT_OTTrainerClass]
 ; 1: Intro text
 ; 2: Player lost
 ; 3: Player won
 	ld a, [rSVBK]
 	push af
-	ld a, 3 ; BANK(BT_OTrainer_TrainerClass)
+	ld a, 3 ; BANK(BT_OTTrainerClass)
 	ld [rSVBK], a
 IF DEF(CRYSTAL11)
-	ld hl, BT_OTrainer_TrainerClass
+	ld hl, BT_OTTrainerClass
 ELSE
-	ld hl, BT_OTrainer_Name + 5
+	ld hl, BT_OTName + 5
 ENDC
 	ld a, [hl]
 	dec a
--- /dev/null
+++ b/misc/battle_tower_5c.asm
@@ -1,0 +1,422 @@
+BattleTowerBattle: ; 170215
+	xor a
+	ld [wcf63], a
+	call _BattleTowerBattle
+	ret
+; 17021d
+
+EmptySpecial_17021d: ; 17021d
+	ret
+; 17021e
+
+Function17021e: ; 17021e
+	xor a
+	ld [wcf63], a
+	ld [wcf64], a
+	ld [wcf65], a
+	ld [wcf66], a
+	ret
+; 17022c
+
+_BattleTowerBattle: ; 17022c
+.loop
+	call .do_jumptable
+	call DelayFrame
+	ld a, [wcf63]
+	cp $1
+	jr nz, .loop
+	ret
+; 17023a
+
+.do_jumptable: ; 17023a
+	ld a, [wcf63]
+	ld e, a
+	ld d, 0
+	ld hl, .jumptable
+rept 2
+	add hl, de
+endr
+	ld a, [hli]
+	ld h, [hl]
+	ld l, a
+	jp [hl]
+; 170249
+
+.jumptable: ; 170249
+	dw RunBattleTowerTrainer
+	dw SkipBattleTowerTrainer
+; 17024d
+
+RunBattleTowerTrainer: ; 17024d
+	ld a, [Options]
+	push af
+	ld hl, Options
+	set BATTLE_SHIFT, [hl] ; SET MODE
+
+	ld a, [InBattleTowerBattle]
+	push af
+	or $1
+	ld [InBattleTowerBattle], a
+
+	xor a
+	ld [wLinkMode], a
+	callba Mobile_HealParty
+	callba HealParty
+	call ReadBTTrainerParty
+	call Clears5_a89a
+	predef StartBattle
+	callba LoadPokemonData
+	callba HealParty
+	ld a, [wBattleResult]
+	ld [ScriptVar], a
+	and a
+	jr nz, .lost
+	ld a, BANK(sNrOfBeatenBattleTowerTrainers)
+	call GetSRAMBank
+	ld a, [sNrOfBeatenBattleTowerTrainers]
+	ld [wNrOfBeatenBattleTowerTrainers], a ; wcf64
+	call CloseSRAM
+	ld hl, StringBuffer3
+	ld a, [wNrOfBeatenBattleTowerTrainers] ; wcf64
+	add "1"
+	ld [hli], a
+	ld a, "@"
+	ld [hl], a
+
+.lost
+	pop af
+	ld [InBattleTowerBattle], a
+	pop af
+	ld [Options], a
+	ld a, $1
+	ld [wcf63], a
+	ret
+
+
+ReadBTTrainerParty: ; 1702b7
+; Initialise the BattleTower-Trainer and his Pkmn
+	call CopyBTTrainer_FromBT_OT_TowBT_OTTemp
+
+; Check the nicknames for illegal characters, and replace bad nicknames
+; with their species names.
+	ld de, wBT_OTTempPkmn1Name ; $c643
+	ld c, PKMN_NAME_LENGTH
+	callba CheckStringForErrors
+	jr nc, .skip_mon_1
+
+	ld a, [wBT_OTTempPkmn1]
+	ld [wNamedObjectIndexBuffer], a
+	call GetPokemonName
+	ld l, e
+	ld h, d
+	ld de, wBT_OTTempPkmn1Name ; $c643
+	ld bc, PKMN_NAME_LENGTH
+	call CopyBytes
+
+.skip_mon_1
+	ld de, wBT_OTTempPkmn2Name ; $c67e
+	ld c, PKMN_NAME_LENGTH
+	callba CheckStringForErrors
+	jr nc, .skip_mon_2
+	ld a, [wBT_OTTempPkmn2] ; [$c64e]
+	ld [wNamedObjectIndexBuffer], a
+	call GetPokemonName
+	ld l, e
+	ld h, d
+	ld de, wBT_OTTempPkmn2Name ; $c67e
+	ld bc, PKMN_NAME_LENGTH
+	call CopyBytes
+
+.skip_mon_2
+	ld de, wBT_OTTempPkmn3Name ; $c686 + 51 = $c6b9
+	ld c, PKMN_NAME_LENGTH
+	callba CheckStringForErrors
+	jr nc, .skip_mon_3
+	ld a, [wBT_OTTempPkmn3] ; [$c689]
+	ld [wNamedObjectIndexBuffer], a
+	call GetPokemonName
+	ld l, e
+	ld h, d
+	ld de, wBT_OTTempPkmn3Name ; $c686 + 51 = $c6b9
+	ld bc, PKMN_NAME_LENGTH
+	call CopyBytes
+
+.skip_mon_3
+; Add the terminator character to each of these names
+	ld a, "@"
+	ld [wBT_OTTempPkmn1NameEnd - 1], a ; $c64d
+	ld [wBT_OTTempPkmn2NameEnd - 1], a ; $c688
+	ld [wBT_OTTempPkmn3NameEnd - 1], a ; $c68a + 57 = $c6c3
+; Fix errors in the movesets
+	call CheckBTMonMovesForErrors
+; Repair the trainer name if needed, then copy it to OTPlayerName
+	ld de, wBT_OTTempName
+	ld c, NAME_LENGTH - 1
+	callba CheckStringForErrors
+	jr nc, .trainer_name_okay
+	ld hl, BT_ChrisName
+	jr .done_trainer_name
+
+.trainer_name_okay
+	ld hl, wBT_OTTempName ; 0xc608
+
+.done_trainer_name
+	ld de, OTPlayerName
+	ld bc, NAME_LENGTH - 1
+	call CopyBytes
+	ld a, "@"
+	ld [de], a
+
+	ld hl, wBT_OTTempTrainerClass
+	ld a, [hli]
+	ld [OtherTrainerClass], a
+	ld a, OTPartyMonNicknames % $100
+	ld [BGMapBuffer], a
+	ld a, OTPartyMonNicknames / $100
+	ld [BGMapBuffer + 1], a
+
+	; Copy Pkmn into Memory from the address in hl
+	ld de, OTPartyMon1Species
+	ld bc, OTPartyCount
+	ld a, BATTLETOWER_NROFPKMNS		; Number of Pkmn the BattleTower-Trainer has
+	ld [bc], a
+	inc bc
+.otpartymon_loop
+	push af
+	ld a, [hl]
+	ld [bc], a
+	inc bc
+	push bc
+	ld bc, PARTYMON_STRUCT_LENGTH
+	call CopyBytes
+	push de
+	ld a, [BGMapBuffer]
+	ld e, a
+	ld a, [BGMapBuffer + 1]
+	ld d, a
+	ld bc, PKMN_NAME_LENGTH
+	call CopyBytes
+	ld a, e
+	ld [BGMapBuffer], a
+	ld a, d
+	ld [BGMapBuffer + 1], a
+	pop de
+	pop bc
+	pop af
+	dec a
+	and a
+	jr nz, .otpartymon_loop
+	ld a, -1
+	ld [bc], a
+	ret
+; 170394
+
+Function170394: ; 170394
+	ld hl, $c608 + 11
+	ld d, $3
+.asm_170399
+	push de
+	push hl
+	ld b, h
+	ld c, l
+	ld a, [hl]
+	and a
+	jr z, .asm_1703b1
+	cp $ff
+	jr z, .asm_1703b1
+	cp $fe
+	jr z, .asm_1703b1
+	cp $fd
+	jr z, .asm_1703b1
+	cp $fc
+	jr nz, .asm_1703b4
+
+.asm_1703b1
+	ld a, $eb
+	ld [hl], a
+
+.asm_1703b4
+	ld [CurSpecies], a
+	call GetBaseData
+	ld a, $5
+	call GetSRAMBank
+	ld a, [$b2fb]
+	call CloseSRAM
+	ld e, a
+	ld hl, $001f
+	add hl, bc
+	ld a, [hl]
+	cp $2
+	ld a, $2
+	jr c, .asm_1703d6
+	ld a, [hl]
+	cp e
+	jr c, .asm_1703d7
+	ld a, e
+
+.asm_1703d6
+	ld [hl], a
+
+.asm_1703d7
+	ld [CurPartyLevel], a
+	ld hl, $0002
+	add hl, bc
+	ld d, $3
+	ld a, [hli]
+	and a
+	jr z, .asm_1703ea
+	cp $fc
+	jr nc, .asm_1703ea
+	jr .asm_1703f4
+
+.asm_1703ea
+	dec hl
+	ld a, $1
+	ld [hli], a
+	xor a
+rept 2
+	ld [hli], a
+endr
+	ld [hl], a
+	jr .asm_1703ff
+
+.asm_1703f4
+	ld a, [hl]
+	cp $fc
+	jr c, .asm_1703fb
+	ld [hl], $0
+
+.asm_1703fb
+	inc hl
+	dec d
+	jr nz, .asm_1703f4
+
+.asm_1703ff
+	ld hl, $0024
+	add hl, bc
+	ld d, h
+	ld e, l
+	push hl
+	push de
+	ld hl, $000a
+	add hl, bc
+	ld b, $1
+	predef CalcPkmnStats
+	pop de
+	pop hl
+rept 2
+	dec de
+endr
+	ld a, [hli]
+	ld [de], a
+	inc de
+	ld a, [hl]
+	ld [de], a
+	pop hl
+	ld bc, PARTYMON_STRUCT_LENGTH + PKMN_NAME_LENGTH
+	add hl, bc
+	pop de
+	dec d
+	jp nz, .asm_170399
+	ret
+; 170426
+
+BT_ChrisName: ; 170426
+	db "CHRIS@"
+; 17042c
+
+Function17042c: ; 17042c
+	ld hl, OTPartyMon2ID
+	ld a, $7
+.asm_170431
+	push af
+	push hl
+	ld c, $12
+.asm_170435
+	ld a, [hli]
+	ld b, a
+	ld a, [hli]
+	and a
+	jr z, .asm_170451
+	cp $f
+	jr nc, .asm_17045b
+	push hl
+	ld hl, Unknown_170470
+	dec a
+	ld e, a
+	ld d, 0
+	add hl, de
+	ld a, [hl]
+	pop hl
+	cp b
+	jr c, .asm_17045b
+	jr z, .asm_17045b
+	jr .asm_170456
+
+.asm_170451
+	ld a, b
+	cp $fc
+	jr nc, .asm_17045b
+
+.asm_170456
+	dec c
+	jr nz, .asm_170435
+	jr .asm_170466
+
+.asm_17045b
+	pop de
+	push de
+	ld hl, Unknown_17047e
+	ld bc, BATTLETOWER_TRAINERDATALENGTH
+	call CopyBytes
+
+.asm_170466
+	pop hl
+	ld de, $00e0
+	add hl, de
+	pop af
+	dec a
+	jr nz, .asm_170431
+	ret
+; 170470
+
+Unknown_170470:
+	db $12, $24, $45, $45, $42, $42, $45, $42, $27, $27, $45, $27, $42, $24
+
+Unknown_17047e:
+	db $03, $04, $05, $08
+	db $03, $05, $0e, $06
+	db $03, $02, $00, $00
+	db $39, $07, $07, $04
+	db $00, $05, $04, $07
+	db $01, $05, $00, $00
+	db $0f, $05, $14, $07
+	db $05, $05, $11, $0c
+	db $0c, $06, $06, $04
+
+
+CopyBTTrainer_FromBT_OT_TowBT_OTTemp: ; 1704a2
+; copy the BattleTower-Trainer data that lies at 'BT_OTTrainer' to 'wBT_OTTemp'
+	ld a, [rSVBK]
+	push af
+	ld a, $3 ; BANK(BT_OTTrainer)
+	ld [rSVBK], a
+
+	ld hl, BT_OTTrainer ; $d100
+	ld de, wBT_OTTemp ; $c608
+	ld bc, BATTLE_TOWER_STRUCT_LENGTH
+	call CopyBytes
+
+	pop af
+	ld [rSVBK], a
+
+	ld a, BANK(s1_be45)
+	call GetSRAMBank
+	ld a, $2
+	ld [s1_be45], a
+	ld hl, sNrOfBeatenBattleTowerTrainers
+	inc [hl]
+	call CloseSRAM
+SkipBattleTowerTrainer: ; 1704c9
+	ret
+; 1704ca
--- a/misc/mobile_46.asm
+++ b/misc/mobile_46.asm
@@ -7543,7 +7543,7 @@
 	ld [$c628], a
 	ld de, $c63d
 	ld c, $5
-	callba Function17d073
+	callba CheckStringForErrors
 	jr nc, .asm_11b70f
 	callba Function17d187
 
@@ -7557,7 +7557,7 @@
 .asm_11b723
 	ld de, $c642
 	ld c, $5
-	callba Function17d073
+	callba CheckStringForErrors
 	jr nc, .asm_11b736
 	callba Function17d199
 
@@ -7571,7 +7571,7 @@
 .asm_11b74a
 	ld de, $c647
 	ld c, $21
-	callba Function17d073
+	callba CheckStringForErrors
 	jr nc, .asm_11b75d
 	callba Function17d1ab
 
@@ -7590,7 +7590,7 @@
 .asm_11b776
 	ld de, $c668
 	ld c, $5
-	callba Function17d073
+	callba CheckStringForErrors
 	jr nc, .asm_11b789
 	callba Function17d1c9
 
--- a/misc/mobile_5c.asm
+++ b/misc/mobile_5c.asm
@@ -251,419 +251,8 @@
 	ret
 ; 170215
 
-BattleTowerBattle: ; 170215
-	xor a
-	ld [wJumptableIndex], a
-	call Function17022c
-	ret
-; 17021d
+INCLUDE "misc/battle_tower_5c.asm"
 
-Function17021d: ; 17021d
-	ret
-; 17021e
-
-Function17021e: ; 17021e
-	xor a
-	ld [wJumptableIndex], a
-	ld [wcf64], a
-	ld [wcf65], a
-	ld [wcf66], a
-	ret
-; 17022c
-
-Function17022c: ; 17022c
-.loop
-	call Jumpto_BattleTowerBattleFunction
-	call DelayFrame
-	ld a, [wJumptableIndex]
-	cp $1
-	jr nz, .loop
-	ret
-; 17023a
-
-Jumpto_BattleTowerBattleFunction: ; 17023a
-	ld a, [wJumptableIndex]
-	ld e, a
-	ld d, 0
-	ld hl, Jumptable_BattleTowerBattleFunctions
-rept 2
-	add hl, de
-endr
-	ld a, [hli]
-	ld h, [hl]
-	ld l, a
-	jp [hl]
-; 170249
-
-Jumptable_BattleTowerBattleFunctions: ; 170249
-	dw RunBattleTowerBattle
-	dw SkipBattleTowerBattle
-; 17024d
-
-RunBattleTowerBattle: ; 17024d
-	ld a, [Options]
-	push af
-	ld hl, Options
-	set 6, [hl]
-	ld a, [InBattleTowerBattle]
-	push af
-	or $1
-	ld [InBattleTowerBattle], a
-	xor a
-	ld [wLinkMode], a
-	callba Mobile_HealParty
-	callba HealParty
-	call Function1702b7
-	call Function170bf7
-	predef StartBattle
-	callba LoadPokemonData
-	callba HealParty
-	ld a, [wBattleResult]
-	ld [ScriptVar], a
-	and a
-	jr nz, .lost
-	ld a, BANK(sNrOfBeatenBattleTowerTrainers)
-	call GetSRAMBank
-	ld a, [sNrOfBeatenBattleTowerTrainers]
-	ld [wNrOfBeatenBattleTowerTrainers], a ; wcf64
-	call CloseSRAM
-	ld hl, StringBuffer3
-	ld a, [wNrOfBeatenBattleTowerTrainers] ; wcf64
-	add $f7
-	ld [hli], a
-	ld a, $50
-	ld [hl], a
-
-.lost
-	pop af
-	ld [InBattleTowerBattle], a
-	pop af
-	ld [Options], a
-	ld a, $1
-	ld [wJumptableIndex], a
-	ret
-
-
-Function1702b7: ; 1702b7
-; Initialise the BattleTower-Trainer and his Pkmn
-	call CopyBTTrainer_FromBT_OTrainer_TowBT_OTTempCopy
-	ld de, wBT_OTTempCopy + wBT_OTTempCopy_Pkmn1Name ; $c643
-	ld c, PKMN_NAME_LENGTH
-	callba Function17d073
-	jr nc, .asm_1702db
-
-	ld a, [wBT_OTTempCopy + wBT_OTTempCopy_Pkmn1]
-	ld [wd265], a
-	call GetPokemonName
-	ld l, e
-	ld h, d
-	ld de, wBT_OTTempCopy + wBT_OTTempCopy_Pkmn1Name ; $c643
-	ld bc, PKMN_NAME_LENGTH
-	call CopyBytes
-
-.asm_1702db
-	ld de, wBT_OTTempCopy + wBT_OTTempCopy_Pkmn2Name ; $c67e
-	ld c, PKMN_NAME_LENGTH
-	callba Function17d073
-	jr nc, .asm_1702fc
-	ld a, [wBT_OTTempCopy + wBT_OTTempCopy_Pkmn2] ; [$c64e]
-	ld [wd265], a
-	call GetPokemonName
-	ld l, e
-	ld h, d
-	ld de, wBT_OTTempCopy + wBT_OTTempCopy_Pkmn2Name ; $c67e
-	ld bc, PKMN_NAME_LENGTH
-	call CopyBytes
-
-.asm_1702fc
-	ld de, wBT_OTTempCopy + wBT_OTTempCopy_Pkmn3Name ; $c686 + 51 = $c6b9
-	ld c, PKMN_NAME_LENGTH
-	callba Function17d073
-	jr nc, .asm_17031d
-	ld a, [wBT_OTTempCopy + wBT_OTTempCopy_Pkmn3] ; [$c689]
-	ld [wd265], a
-	call GetPokemonName
-	ld l, e
-	ld h, d
-	ld de, wBT_OTTempCopy + wBT_OTTempCopy_Pkmn3Name ; $c686 + 51 = $c6b9
-	ld bc, PKMN_NAME_LENGTH
-	call CopyBytes
-
-.asm_17031d
-	ld a, $50
-	ld [wBT_OTTempCopy + wBT_OTTempCopy_45], a ; $c64d
-	ld [wBT_OTTempCopy + wBT_OTTempCopy_80], a ; $c688
-	ld [wBT_OTTempCopy + wBT_OTTempCopy_BB], a ; $c68a + 57 = $c6c3
-	call Function170c98
-	ld de, wBT_OTTempCopy
-	ld c, $a
-	callba Function17d073
-	jr nc, .asm_17033d
-	ld hl, String_170426
-	jr .asm_170340
-
-.asm_17033d
-	ld hl, wBT_OTTempCopy ; 0xc608
-
-.asm_170340
-	ld de, wd26b
-	ld bc, $000a
-	call CopyBytes
-	ld a, $50
-	ld [de], a
-	ld hl, wBT_OTTempCopy + wBT_OTTempCopy_TrainerClass
-	ld a, [hli]
-	ld [OtherTrainerClass], a
-	ld a, $ea
-	ld [BGMapBuffer], a
-	ld a, $d3
-	ld [wcd21], a
-
-	; Copy Pkmn into Memory from the address in hl
-	ld de, OTPartyMon1Species
-	ld bc, OTPartyCount
-	ld a, BATTLETOWER_NROFPKMNS		; Number of Pkmn the BattleTower-Trainer has
-	ld [bc], a
-	inc bc
-.asm_170367
-	push af
-	ld a, [hl]
-	ld [bc], a
-	inc bc
-	push bc
-	ld bc, PARTYMON_STRUCT_LENGTH
-	call CopyBytes
-	push de
-	ld a, [BGMapBuffer]
-	ld e, a
-	ld a, [wcd21]
-	ld d, a
-	ld bc, $000b
-	call CopyBytes
-	ld a, e
-	ld [BGMapBuffer], a
-	ld a, d
-	ld [wcd21], a
-	pop de
-	pop bc
-	pop af
-	dec a
-	and a
-	jr nz, .asm_170367
-	ld a, $ff
-	ld [bc], a
-	ret
-; 170394
-
-Function170394: ; 170394
-	ld hl, $c608 + 11
-	ld d, $3
-.asm_170399
-	push de
-	push hl
-	ld b, h
-	ld c, l
-	ld a, [hl]
-	and a
-	jr z, .asm_1703b1
-	cp $ff
-	jr z, .asm_1703b1
-	cp $fe
-	jr z, .asm_1703b1
-	cp $fd
-	jr z, .asm_1703b1
-	cp $fc
-	jr nz, .asm_1703b4
-
-.asm_1703b1
-	ld a, $eb
-	ld [hl], a
-
-.asm_1703b4
-	ld [CurSpecies], a
-	call GetBaseData
-	ld a, $5
-	call GetSRAMBank
-	ld a, [$b2fb]
-	call CloseSRAM
-	ld e, a
-	ld hl, $001f
-	add hl, bc
-	ld a, [hl]
-	cp $2
-	ld a, $2
-	jr c, .asm_1703d6
-	ld a, [hl]
-	cp e
-	jr c, .asm_1703d7
-	ld a, e
-
-.asm_1703d6
-	ld [hl], a
-
-.asm_1703d7
-	ld [CurPartyLevel], a
-	ld hl, $0002
-	add hl, bc
-	ld d, $3
-	ld a, [hli]
-	and a
-	jr z, .asm_1703ea
-	cp $fc
-	jr nc, .asm_1703ea
-	jr .asm_1703f4
-
-.asm_1703ea
-	dec hl
-	ld a, $1
-	ld [hli], a
-	xor a
-rept 2
-	ld [hli], a
-endr
-	ld [hl], a
-	jr .asm_1703ff
-
-.asm_1703f4
-	ld a, [hl]
-	cp $fc
-	jr c, .asm_1703fb
-	ld [hl], $0
-
-.asm_1703fb
-	inc hl
-	dec d
-	jr nz, .asm_1703f4
-
-.asm_1703ff
-	ld hl, $0024
-	add hl, bc
-	ld d, h
-	ld e, l
-	push hl
-	push de
-	ld hl, $000a
-	add hl, bc
-	ld b, $1
-	predef CalcPkmnStats
-	pop de
-	pop hl
-rept 2
-	dec de
-endr
-	ld a, [hli]
-	ld [de], a
-	inc de
-	ld a, [hl]
-	ld [de], a
-	pop hl
-	ld bc, $003b
-	add hl, bc
-	pop de
-	dec d
-	jp nz, .asm_170399
-	ret
-; 170426
-
-String_170426: ; 170426
-	db "CHRIS@"
-; 17042c
-
-Function17042c: ; 17042c
-	ld hl, OTPartyMon2ID
-	ld a, $7
-.asm_170431
-	push af
-	push hl
-	ld c, $12
-.asm_170435
-	ld a, [hli]
-	ld b, a
-	ld a, [hli]
-	and a
-	jr z, .asm_170451
-	cp $f
-	jr nc, .asm_17045b
-	push hl
-	ld hl, Unknown_170470
-	dec a
-	ld e, a
-	ld d, 0
-	add hl, de
-	ld a, [hl]
-	pop hl
-	cp b
-	jr c, .asm_17045b
-	jr z, .asm_17045b
-	jr .asm_170456
-
-.asm_170451
-	ld a, b
-	cp $fc
-	jr nc, .asm_17045b
-
-.asm_170456
-	dec c
-	jr nz, .asm_170435
-	jr .asm_170466
-
-.asm_17045b
-	pop de
-	push de
-	ld hl, Unknown_17047e
-	ld bc, $0024
-	call CopyBytes
-
-.asm_170466
-	pop hl
-	ld de, $00e0
-	add hl, de
-	pop af
-	dec a
-	jr nz, .asm_170431
-	ret
-; 170470
-
-Unknown_170470:
-	db $12, $24, $45, $45, $42, $42, $45, $42, $27, $27, $45, $27, $42, $24
-
-Unknown_17047e:
-	db $03, $04, $05, $08
-	db $03, $05, $0e, $06
-	db $03, $02, $00, $00
-	db $39, $07, $07, $04
-	db $00, $05, $04, $07
-	db $01, $05, $00, $00
-	db $0f, $05, $14, $07
-	db $05, $05, $11, $0c
-	db $0c, $06, $06, $04
-
-
-CopyBTTrainer_FromBT_OTrainer_TowBT_OTTempCopy: ; 1704a2
-; copy the BattleTower-Trainer data that lies at 'BT_OTrainer' to 'wBT_OTTempCopy'
-	ld a, [rSVBK]
-	push af
-	ld a, $3
-	ld [rSVBK], a
-	ld hl, BT_OTrainer ; $d100
-	ld de, wBT_OTTempCopy ; $c608
-	ld bc, BT_OTrainerEnd - BT_OTrainer ; $e0 = $a + $1 + 3*$3b + $24
-                                        ;	  = $a + $1 + BATTLETOWER_NROFPKMNS * (PARTYMON_STRUCT_LENGTH + PKMN_NAME_LENGTH) + BATTLETOWER_TRAINERDATALENGTH
-	call CopyBytes
-	pop af
-	ld [rSVBK], a
-	ld a, BANK(s1_be45)
-	call GetSRAMBank
-	ld a, $2
-	ld [s1_be45], a
-	ld hl, sNrOfBeatenBattleTowerTrainers
-	inc [hl]
-	call CloseSRAM
-SkipBattleTowerBattle: ; 1704c9
-	ret
-; 1704ca
-
-
 Function1704ca: ; 1704ca
 	ld a, [$be46]
 	cp $7
@@ -1753,7 +1342,7 @@
 	ret
 ; 170bf7
 
-Function170bf7: ; 170bf7
+Clears5_a89a: ; 170bf7
 	ld a, $5
 	call GetSRAMBank
 	ld hl, $a89a
@@ -1881,46 +1470,46 @@
 	ret
 ; 170c98
 
-Function170c98: ; 170c98
-	ld c, $3
-	ld hl, $c608 + 13
-.asm_170c9d
+CheckBTMonMovesForErrors: ; 170c98
+	ld c, BATTLETOWER_NROFPKMNS
+	ld hl, wBT_OTTempPkmn1Moves
+.loop
 	push hl
 	ld a, [hl]
-	cp $fc
-	jr c, .asm_170ca6
-	ld a, $1
+	cp NUM_ATTACKS + 1
+	jr c, .okay
+	ld a, POUND
 	ld [hl], a
 
-.asm_170ca6
+.okay
 	inc hl
-	ld b, $3
-.asm_170ca9
+	ld b, NUM_MOVES - 1
+.loop2
 	ld a, [hl]
 	and a
-	jr z, .asm_170cb1
-	cp $fc
-	jr c, .asm_170cb9
+	jr z, .loop3
+	cp NUM_ATTACKS + 1
+	jr c, .next
 
-.asm_170cb1
+.loop3
 	xor a
 	ld [hl], a
 	inc hl
 	dec b
-	jr nz, .asm_170cb1
-	jr .asm_170cbd
+	jr nz, .loop3
+	jr .done
 
-.asm_170cb9
+.next
 	inc hl
 	dec b
-	jr nz, .asm_170ca9
+	jr nz, .loop2
 
-.asm_170cbd
+.done
 	pop hl
-	ld de, $003b
+	ld de, PARTYMON_STRUCT_LENGTH + PKMN_NAME_LENGTH
 	add hl, de
 	dec c
-	jr nz, .asm_170c9d
+	jr nz, .loop
 	ret
 ; 170cc6
 
--- a/misc/mobile_5f.asm
+++ b/misc/mobile_5f.asm
@@ -178,48 +178,50 @@
 	RGB  0,  0,  0
 
 
-Function17d073: ; 17d073
-.asm_17d073
+CheckStringForErrors: ; 17d073
+; Valid character ranges:
+; $00, $05 - $13, $19 - $1c, $26 - $34, $3a - $3e, $40 - $48, $60 - $ff
+.loop
 	ld a, [de]
 	inc de
 	and a
-	jr z, .asm_17d0ae
+	jr z, .NextChar
 	cp $60
-	jr nc, .asm_17d0ae
+	jr nc, .NextChar
 	cp $4e
-	jr z, .asm_17d0ae
-	cp $50
-	jr z, .asm_17d0b1
+	jr z, .NextChar
+	cp "@"
+	jr z, .Done
 	cp $5
-	jr c, .asm_17d0ac
-	cp $14
-	jr c, .asm_17d0ae
+	jr c, .Fail
+	cp "<PLAY_G>"
+	jr c, .NextChar
 	cp $19
-	jr c, .asm_17d0ac
+	jr c, .Fail
 	cp $1d
-	jr c, .asm_17d0ae
+	jr c, .NextChar
 	cp $26
-	jr c, .asm_17d0ac
+	jr c, .Fail
 	cp $35
-	jr c, .asm_17d0ae
+	jr c, .NextChar
 	cp $3a
-	jr c, .asm_17d0ac
+	jr c, .Fail
 	cp $3f
-	jr c, .asm_17d0ae
+	jr c, .NextChar
 	cp $40
-	jr c, .asm_17d0ac
+	jr c, .Fail
 	cp $49
-	jr c, .asm_17d0ae
+	jr c, .NextChar
 
-.asm_17d0ac
+.Fail
 	scf
 	ret
 
-.asm_17d0ae
+.NextChar
 	dec c
-	jr nz, .asm_17d073
+	jr nz, .loop
 
-.asm_17d0b1
+.Done
 	and a
 	ret
 ; 17d0b3
--- a/wram.asm
+++ b/wram.asm
@@ -129,6 +129,22 @@
                       ds 1 ; c132
 ENDM
 
+battle_tower_struct: MACRO
+\1Name:: ds NAME_LENGTH +- 1
+\1TrainerClass:: ds 1
+\1Pkmn1:: party_struct \1Pkmn1
+\1Pkmn1Name:: ds PKMN_NAME_LENGTH
+\1Pkmn1NameEnd::
+\1Pkmn2:: party_struct \1Pkmn2
+\1Pkmn2Name:: ds PKMN_NAME_LENGTH
+\1Pkmn2NameEnd::
+\1Pkmn3:: party_struct \1Pkmn3
+\1Pkmn3Name:: ds PKMN_NAME_LENGTH
+\1Pkmn3NameEnd::
+\1TrainerData:: ds BATTLETOWER_TRAINERDATALENGTH
+\1TrainerEnd::
+endm
+
 INCLUDE "vram.asm"
 
 SECTION "Stack", WRAM0
@@ -435,10 +451,12 @@
 wOddEggOTName:: ds PKMN_NAME_LENGTH
 	ds -70
 
+wBT_OTTemp:: battle_tower_struct wBT_OTTemp
+	ds -BATTLE_TOWER_STRUCT_LENGTH
+
 wMisc::
 wBattle::
 wc608::
-wBT_OTTempCopy:: ; used to copy the data of the BattleTower-Trainer and the 3 Pkmn
 
 wEnemyMoveStruct::  ds MOVE_LENGTH ; c608
 wc60f::
@@ -888,21 +906,21 @@
 wc7e8:: ds 24
 
 
-RSSET 0 ; Offsets for wBT_OTTempCopy:: @ $c608
-wBT_OTTempCopy_0			RB NAME_LENGTH + -1      ; $c608
-wBT_OTTempCopy_TrainerClass	RB 1	                 ; $c608 + $a = $c612
-wBT_OTTempCopy_Pkmn1		RB $30 ; PARTYMON_STRUCT_LENGTH   ; $c608 + $b = $c613
-wBT_OTTempCopy_Pkmn1Name	RB PKMN_NAME_LENGTH + -1 ; $c608 + $45 = $c64d
-wBT_OTTempCopy_45           RB 1
-wBT_OTTempCopy_Pkmn2		RB $30 ; PARTYMON_STRUCT_LENGTH   ; $c608 + $46 = $c64e
-wBT_OTTempCopy_Pkmn2Name	RB PKMN_NAME_LENGTH + -1 ; $c608 + $76 = $c67e
-wBT_OTTempCopy_80           RB 1
-wBT_OTTempCopy_Pkmn3		RB $30 ; PARTYMON_STRUCT_LENGTH   ; $c608 + $81 = $c689
-wBT_OTTempCopy_Pkmn3Name	RB PKMN_NAME_LENGTH + -1 ; $c608 + $b1 = $c6b9
-wBT_OTTempCopy_BB           RB 1
+RSSET 0 ; Offsets for wBT_OTTemp:: @ $c608
+wBT_OTTemp_0			RB NAME_LENGTH + -1      ; $c608
+wBT_OTTemp_TrainerClass	RB 1	                 ; $c608 + $a = $c612
+wBT_OTTemp_Pkmn1		RB $30 ; PARTYMON_STRUCT_LENGTH   ; $c608 + $b = $c613
+wBT_OTTemp_Pkmn1Name	RB PKMN_NAME_LENGTH + -1 ; $c608 + $45 = $c64d
+wBT_OTTemp_45           RB 1
+wBT_OTTemp_Pkmn2		RB $30 ; PARTYMON_STRUCT_LENGTH   ; $c608 + $46 = $c64e
+wBT_OTTemp_Pkmn2Name	RB PKMN_NAME_LENGTH + -1 ; $c608 + $76 = $c67e
+wBT_OTTemp_80           RB 1
+wBT_OTTemp_Pkmn3		RB $30 ; PARTYMON_STRUCT_LENGTH   ; $c608 + $81 = $c689
+wBT_OTTemp_Pkmn3Name	RB PKMN_NAME_LENGTH + -1 ; $c608 + $b1 = $c6b9
+wBT_OTTemp_BB           RB 1
 
-GLOBAL wBT_OTTempCopy_TrainerClass, wBT_OTTempCopy_Pkmn1, wBT_OTTempCopy_Pkmn1Name, wBT_OTTempCopy_Pkmn2, wBT_OTTempCopy_Pkmn2Name, wBT_OTTempCopy_Pkmn3, wBT_OTTempCopy_Pkmn3Name
-GLOBAL wBT_OTTempCopy_45, wBT_OTTempCopy_80, wBT_OTTempCopy_BB
+GLOBAL wBT_OTTemp_TrainerClass, wBT_OTTemp_Pkmn1, wBT_OTTemp_Pkmn1Name, wBT_OTTemp_Pkmn2, wBT_OTTemp_Pkmn2Name, wBT_OTTemp_Pkmn3, wBT_OTTemp_Pkmn3Name
+GLOBAL wBT_OTTemp_45, wBT_OTTemp_80, wBT_OTTemp_BB
 
 
 
@@ -1205,7 +1223,8 @@
 
 wNamedObjectTypeBuffer:: ds 1
 	ds 1
-wJumptableIndex:: ds 1
+wJumptableIndex::
+wcf63:: ds 1
 wNrOfBeatenBattleTowerTrainers::
 wMomBankDigitCursorPosition::
 wIntroSceneFrameCounter::
@@ -2695,22 +2714,9 @@
 w3_d090::
 	ds $70
 
-BT_OTrainer::
 w3_d100:: ; BattleTower OpponentTrainer-Data (length = 0xe0 = $a + $1 + 3*$3b + $24)
-BT_OTrainer_Name::
-	ds NAME_LENGTH + -1
-BT_OTrainer_TrainerClass::
-	ds 1
-BT_OTPkmn1:: party_struct BT_OTPkmn1
-BT_OTPkmn1Name:: ds PKMN_NAME_LENGTH
-BT_OTPkmn2:: party_struct BT_OTPkmn2
-BT_OTPkmn2Name:: ds PKMN_NAME_LENGTH
-BT_OTPkmn3:: party_struct BT_OTPkmn3
-BT_OTPkmn3Name:: ds PKMN_NAME_LENGTH
-	
-BT_OTrainerData:: ds $24
-BT_OTrainerEnd:: ; w3_d1e0
-	
+BT_OTTrainer:: battle_tower_struct BT_OT
+; d1e0	
 	ds $20
 BT_TrainerTextIndex::
 	ds $600