Go Back   The PokéCommunity Forums > ROM Hacking > Research & Development
Reload this Page Development: Trainer interrupting battles

Notices
For all updates, view the main page.

Research & Development Got a well-founded knack with ROM hacking? Love reverse-engineering the Pokémon games? Or perhaps you love your assembly language. This is the spot for polling and gathering your ideas, and then implementing them! Share your hypothesis, get ideas from others, and collaborate to create!
Research & Development programs in this forum are subject to moderator approval before they are displayed.



Reply
 
Thread Tools
  #1    
Old November 24th, 2014 (03:52 PM).
FBI agent's Avatar
FBI agent FBI agent is offline
If my PM box is full, VM instead :x
 
Join Date: Jan 2013
Location: Unknown Island
Gender: Male
Posts: 817

R&D on Pokemon Trainer's Interrupting battles:



Before I begin, skip to 5:50 and watch till 5:55 of this video to see what I'm talking about: https://www.youtube.com/watch?v=W609NJs9h-o

I want to implement that in Fire Red. So recently I've been reading, researching and tracking down different routines in battles in FireRed to basically find a point in the game which is run once per turn. Well I found that point. The game seems to have a "turn counter" which is incremented once at the end of each turn at 0x8013CB0

From there I need to call my own routine. A routine whose purpose was simply to check if the opponent was on their last Pokemon, and to check if their last Pokemon is lower than Half health.
In the newer games this, "trainer interrupt" happens 100% in these two conditions vs important NPCs.
So I should do an interrupt at those two stages.

The next problem is knowing which text to execute. The solution to that imo is simple. I decided the best way to do it, is to make a table of pointers to strings, and just use a variable to browse these pointers. (Getting the battle to display this string is another issue in itself).

The last, and probably the biggest problem is the trainer sliding in and out in both of these scenarios.

So right now, what I have done is the main routine that does the check of whether or not to do the trainer sliding process, and a helper function which basically just gives information about the opponents team.

Code for Main:

Spoiler:

Code:
.text
.align 2
.thumb
.thumb_func
 
@Main function. This checks whether to execute a slide + text and then does it.
@If no slide + text to be executed, restores previous instructions
@Uses a separate called checkPokemon which I wrote
 
main:
        push {r2-r5, lr}
        ldr r0, .checkPokemon @check trainer's pokemon
        bl checkPokemon
        cmp r1, #0x0 @check if last pokemon
        bne skip
        mov r1, #0x39
        mov r3, r0 @save r0
        ldr r5, VAR2
        cmp r5, #0x0 @if last Pokemon and we haven't displayed text before display
        beq text
        ldr r2, = (0x803FBE8 + 1) @check if last Pokemon less than half
        bl linkerTwo
        mov r4, r0 @r4 = currentHP
        mov r0, r3
        mov r1, #3A
        bl linkerTwo
        mov r1, #0x2
        mul r4, r4, r1
        cmp r0, r4
        ble skip @if more than half, no text display
 
text:
        @slide trainer (todo)
        @
        @below is the text, for some reason it appears to come on screen delayed :/
        @
        mov r0, #0x1 @set a flag (cover cases player spamming growl, doing no dmg..ect)
        strb r0, [r5]
        ldr r1, .VAR @get pointer number var from table. Var is index
        ldrb r1, [r1]
        ldr r0, .TABLE
        lsl r1, #0x2
        add r0, r0, r1
        ldr r0, [r0] @r0 contains pointer
        mov r1, #0x0  @check that it's a valid pointer, not free space
        ldrb r0, [r1]
        cmp r1, #0xFF
        beq skip
        ldr r1, =(0x80D77F4 +1) @battle text functions
        bl linkerOne
        mov r1, #0x18
        ldr r2, =(0x80D87BC +1)
        bl linkerTwo
        @unslide trainer (todo)
 
skip:
        ldr r1, = 0x3004F90
        ldrb r0, [r1, #0x13]
        cmp r0, #0xFE
        bhi replacer
        add r0, #0x1
        strb r0, [r1, #0x13]
 
replacer:
        ldr r2, = (0x8013CBC + 1)
 
linkerTwo:
        bx r2
 
linkerOne:
        bx r1
 
 
 
.align 2
.VAR:
        .word 0x020270B4 + (0x8001 * 2)
 
.VAR2:
        .word 0x020270B4 + (0x8002 * 2)
 
.TABLE:
        .word (0x8xxxxxx) @table of string pointers
 
.checkPokemon
        .word (0x8xxxxxx) @need to insert still


Here's the checkPokemon used in the routine above:
Spoiler:

Code:
.text
.align 2
.thumb
.thumb_func
 
@Loops trainers pokemon, returns amount alive
@if last pokemon, return's that pokemon's address in r0
@else gives scalar number of pokemon alive in r0
@ready for checking last pokemon is half HP flag
 
main:
        push {lr}
        mov r3, #0x0 @pokeslot zero
        mov r2, r3 @r2 holds number of alive pokemon
        b loop
 
loop:
        cmp r3, #0x5 @if all pokemon looped through, finish
        bge finalizeReturn
        ldr r0, =(0x202402C) @get pokemon at slot
        mov r1, #0x64
        mul r1, r1, r3
        add r0, r0, r1
        mov r1, #0x39
        ldr r4, =(0x803FBE8 +1)
        bl caller
        cmp r0,  #0x0 @check current HP zero
        bne increment   @if not zero increment r2
        add r3, r3, #0x1 @go next slot
        b loop
 
increment:
        add r2, r2, #0x1
        add r3, r3, #0x1 @also have to do slot increment
        mov r5, r0 @store in r5, last alive pokemon's location
        b loop
 
caller:
        bx r4
 
finalizeReturn:
        cmp r2, #0x1 @check if only 1 alive
        bne end
        mov r0, r5 @if 1 pokemon alive it must be in r5, put it in r0
        mov r1, #0x0 @r1 is a boolean r1: 0 means 1 alive pokemon
        pop {pc}
 
end
        mov r0, r2 @r0 = number of alive pokemon
        mov r1, #0x1 @r1: 1 means more than 1 alive
        pop {pc}
 
.align 2


As you can tell, all I have to really do is to "Slide trainer" and "Unslide" the trainer in the battle. Followed by, fixing the text glitch I'm getting.

Basically the text comes out at the same time as the normal battle text. And one is overwriting pieces of the other, which causes this:


I have looked into battlescripts, but honestly, I don't know if I really even need to use one. Maybe using one would help with the text appearing, I haven't tested (and don't have experience on it to really know)

The reason I'm making the thread is to seek help/expertise of someone who's done this kind of thing before. Or perhaps knows how. Currently I'm at a wall, and am not quite sure what to do.

Things I've tried (though maybe unsuccessfully):
calling 0803227C: trainer enter field
Using Oak's tutorial text routines


If you have questions, optimizations, suggestions or solutions please do voice them :)
__________________
...

My name forum name is FBI Agent, though you can call me FBI because it's shorter.

Some of my stuff:
ASM request/resource thread
ASM tutorials thread
ASM Workshop
Reply With Quote
  #2    
Old November 24th, 2014 (07:43 PM). Edited November 24th, 2014 by Derlo.
Derlo's Avatar
Derlo Derlo is offline
Braziliam Hacker!! De Mossoró
 
Join Date: Aug 2007
Posts: 115
Send a message via Windows Live Messenger to Derlo
you could try to take a look at the kind of battle where the oak explain how to fight.
in it, the texts are loaded when it afflicts / takes damage; when using the bag, trying to get out of the fight or decreases stats pokemon.
about the trainer sprite... could try to see how the routine that ends the battle is, to be able to use as a base.

edit: here a very, very old data of T.battle 0x09 that I researched. maybe help or not. xD
Quote:
=> 080E837c (off the texts before starting the battle)
=> 08036114 (inflict damege text off)
=> 080ea5ec & 080ea5f0 (low stats)
=> 0812207e substitute 00 to 0812210f [92 bytes] (choose pokemon and stock menu when using potion)
=> 080E85a8 substitute 083fcdb3 [exit text]
=> 080ea5f4 until 080ea647 [00] mesnsagem when you win!
=> 0803853c put 0x00 (defeat message!) 1byte
__________________



Pokémon
Essence of Light

Comming Soon...
Reply With Quote
  #3    
Old November 24th, 2014 (08:53 PM). Edited November 24th, 2014 by kearnseyboy6.
kearnseyboy6's Avatar
kearnseyboy6 kearnseyboy6 is offline
Aussie's Toughest Mudder
 
Join Date: Dec 2008
Posts: 273
On a broader more scale you might need to implement if the variable is 0x0 then skip entirely, so this doesn't occur with every single trainer.

Might it also be worth researching on the battle string "It's super effective!"?

Edit: Found a battle string table at 0x3FDF3C and really contains heaps of pointers to text strings. "It's super effective!" appears to be pointer 207 (0xCF). Also the table goes past a byte and reaches up to 0x175 so limits is not a problem.

I think finding how these are called will give you your answer.

Also 0x0751C4 seems to be possibly the trainer slide function? See the IDA file by knizz labelled battle_side_get_owner
__________________
HOLIDAYING CURRENTLY!!
Reply With Quote
  #4    
Old November 25th, 2014 (06:42 PM).
FBI agent's Avatar
FBI agent FBI agent is offline
If my PM box is full, VM instead :x
 
Join Date: Jan 2013
Location: Unknown Island
Gender: Male
Posts: 817
Quote originally posted by Derlo:
you could try to take a look at the kind of battle where the oak explain how to fight.
in it, the texts are loaded when it afflicts / takes damage; when using the bag, trying to get out of the fight or decreases stats pokemon.
about the trainer sprite... could try to see how the routine that ends the battle is, to be able to use as a base.

edit: here a very, very old data of T.battle 0x09 that I researched. maybe help or not. xD
Hmm, I don't think we need to use the Oak text. The reason it creates this text error is because it's overlapping somewhere. I'm not sure where :D

Quote originally posted by kearnseyboy6:
On a broader more scale you might need to implement if the variable is 0x0 then skip entirely, so this doesn't occur with every single trainer.

Might it also be worth researching on the battle string "It's super effective!"?

Edit: Found a battle string table at 0x3FDF3C and really contains heaps of pointers to text strings. "It's super effective!" appears to be pointer 207 (0xCF). Also the table goes past a byte and reaches up to 0x175 so limits is not a problem.

I think finding how these are called will give you your answer.

Also 0x0751C4 seems to be possibly the trainer slide function? See the IDA file by knizz labelled battle_side_get_owner
I've tried calling those functions, the game freezes in place. I'm probably calling incorrectly or maybe there are some assumptions set in place when that function is called. It'll take some investigating.
__________________
...

My name forum name is FBI Agent, though you can call me FBI because it's shorter.

Some of my stuff:
ASM request/resource thread
ASM tutorials thread
ASM Workshop
Reply With Quote
  #5    
Old November 28th, 2014 (03:20 AM).
Touched's Avatar
Touched Touched is offline
Resident ASMAGICIAN
 
Join Date: Jul 2014
Gender: Male
Posts: 179
I did like a thing which added an extra trainer to the screen at the start and then slid them out. So like, maybe that'll help.
__________________
My Emerald IDB
Knizz's FireRed IDB
I will ASMentor people who exhibit enough enthusiASM. Join the IRC to become an ASMentee.
Reply With Quote
  #6    
Old November 28th, 2014 (06:57 AM).
FBI agent's Avatar
FBI agent FBI agent is offline
If my PM box is full, VM instead :x
 
Join Date: Jan 2013
Location: Unknown Island
Gender: Male
Posts: 817
Quote originally posted by Touched:
I did like a thing which added an extra trainer to the screen at the start and then slid them out. So like, maybe that'll help. :P
Sounds like it will help. Feel free to explain :D
__________________
...

My name forum name is FBI Agent, though you can call me FBI because it's shorter.

Some of my stuff:
ASM request/resource thread
ASM tutorials thread
ASM Workshop
Reply With Quote
  #7    
Old February 3rd, 2015 (09:39 AM).
Zehn's Avatar
Zehn Zehn is online now
City of Snow
Crystal Tier
 
Join Date: Oct 2014
Location: England (that's all you need to know)
Gender: Male
Nature: Relaxed
Posts: 407
Send a message via Skype™ to Zehn
You could try displaying text as if you where in the old Man tut
__________________
Snowpoint City
"City of Snow"
Supporter City Collab 2015


Crystal Supporter


I'm friendly, shoot me a VM if you want
Reply With Quote
  #8    
Old February 3rd, 2015 (10:16 AM).
daniilS's Avatar
daniilS daniilS is offline
busy trying to do stuff not done yet
 
Join Date: Aug 2013
Age: 15
Gender: Male
Posts: 326
Quote originally posted by Zehn:
You could try displaying text as if you where in the old Man tut
It's better to use a regular text printing function, and that isn't a problem at all. The only real problem left is sliding the trainer out in a way that won't glitch everything.
__________________
Reply With Quote
Reply
Quick Reply

Sponsored Links
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are UTC -8. The time now is 08:39 AM.