Binary Hack Research & DevelopmentGot a well-founded knack with your binary Pokémon hacks? Love reverse-engineering them? For the traditional Pokémon ROM hacker, 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!
I just wanted to one thing,
most commonly in many post is this thread I have seen "Battle script" and "hold effect byte"
I am almost new to these terms in hacking so can someone simply explain about it to me,
.
.
I studied the item editor and found that "hold effect byte" is simply the value dealing with the effect if the item is held.... but what are those effect and where they exist in table (pointer) and simply how can I know which effect byte works as what???
.
.
sorry I am new to these so asking a lot of question to know about it!
.
.
and also if anyone would like to pls tell me about "battle scripts".
.
thanks in advance.
~sorry noob here! :P
I don't know if anyone's been working on this lately, but I've been itching to share this.
FireRed lacks a system that uses a Region Dex order seperate from the National Dex. If you were to have a Region Dex and a National Dex, your National Dex would look unprofessional. What I'm putting here is my work towards a Region Dex system for FireRed. I would like to stress however that it is both unoptimized and unfinished, but I really wanted to release this.
To-Do list
Fix counting the Region Dex for things like the start screen and talking to the Professor
Displaying the Region Dex number when you don't have the National Dex on the summary screen
Making searches and habitat lists use Region Dex numbers before the National Dex
Send me a PM if you're interested in fixing up what's left.
There is a ".dexarea" in Correct numbering routine that doesn't have any value. I tried inserting .dexarea .word 0x8a90000 at the bottom of the code but it doesn't work. Any idea?
__________________
This signature has been disabled.
Scrollbar appears
Please review and fix the issues by reading the signature rules.
You must edit it to meet the limits set by the rules before you may remove the [sig-reason] code from your signature. Removing this tag will re-enable it.
Do not remove the tag until you fix the issues in your signature. You may be infracted for removing this tag if you do not fix the specified issues. Do not use this tag for decoration purposes.
There is a ".dexarea" in Correct numbering routine that doesn't have any value. I tried inserting .dexarea .word 0x8a90000 at the bottom of the code but it doesn't work. Any idea?
I keep trying it but to no avail I just can't seem to get it to work.
I assemble the routine and place it at 0x7900B0, then edit the given script to;
XSEscript:
Code:
#dynamic 0x740000
'----Main----
#org @start
special 0x9F ///Choose Pokemon from Party & store it on var 0x8004
waitstate
bufferpartypokemon 0x0 0x8004
setvar 0x800D 0x1A ///EV-stat 0x1A = HP
setvar 0x8000 0xA ///EV-stat amount to subtract 0xA = 10
callasm 0x87900B1 ///EV-Reducing Berries ASM(pointer + 1)
compare 0x800D 0xFF ///Compare last result to 255
if 0x1 goto @snippetFail
buffernumber 0x1 0x800F
msgbox @stringDecrese 0x6
removeitem 0x99 0x1 ///Item 0x99 = Pomeg Berry
release
end
'---------------
#org @snippetFail
msgbox @stringFail 0x6
release
end
'---------
' Strings
'---------
#org @stringDecrese
= [buffer1] lost [buffer2]\nHP EVs!
#org @stringFail
= It would have no effect!
Is there something I'm doing wrong or is there a better way to do this?
I'm merely trying to recreate the Pomeg Berry from Emerald in Fire Red...
Not to mention EV-Reducing Berries are rather useful when EV training...
Also since I'm here I was wondering what gltiches from the first gen could be simulated with asm in Fire Red?
Would like to make a working MissingNo that will check the players name and base its form off of the characters in the certain spots like in Blue and Red. Would be cool to have the item duplication glitch as well but one step at a time...
The reason I ask is because I'm trying to make a Glitch/Error Version...
Keeping their sporadic nature but making them contained and fun to play with...
GlitchQuests are rather fun when they work and do some crazy stuffs>_< hahaha.
Anyway thanks for the time and any advice given...
What I did was put the script to a ow and if it works, I failed you can in a berry, besides that resets me every time I talk to the guy, and also I freeze if I do not have the necessary berries nor if I have evs is reset
I was wondering if it would be possible to update the Everstone to have its Gen Six breeding effect?
To review, the Gen Six Everstone:
•Has a 100% chance to pass down the nature of the parent holding it.
•If both parents are holding the Everstone, the Nature passed down will be randomly chosen from the two parents (if they both have the same nature this is unnoticeable.)
__________________
"The human sacrificed himself, to save the Pokemon. I pitted them against each other, but not until they set aside their differences did I see the true power they all share deep inside. I see now that the circumstances of one's birth are irrelevant; it is what you do with the gift of life that determines who you are." -Mewtwo
I was wondering if it would be possible to update the Everstone to have its Gen Six breeding effect?
To review, the Gen Six Everstone:
•Has a 100% chance to pass down the nature of the parent holding it.
•If both parents are holding the Everstone, the Nature passed down will be randomly chosen from the two parents (if they both have the same nature this is unnoticeable.)
Wouldn't be hard. Take a look at that function in Emerald: 08070084. Apparently they already inherit nature if poke is female or Ditto, but only with 50% chance.
I was wondering if it would be possible to update the Everstone to have its Gen Six breeding effect?
To review, the Gen Six Everstone:
•Has a 100% chance to pass down the nature of the parent holding it.
•If both parents are holding the Everstone, the Nature passed down will be randomly chosen from the two parents (if they both have the same nature this is unnoticeable.)
I believe FBI has code for that somewhere? Though that might just be for Fire Red. Should be easy enough to port.
I believe FBI has code for that somewhere? Though that might just be for Fire Red. Should be easy enough to port.
I know he has a Destiny Knot port, but I've yet to see an Everstone one. I'll check though because it might have slipped under my radar.
Also I should have probably specified that I'm using Fire Red already (although Emerald ports probably wouldn't be too hard, hopefully, since they already have that function in the game, albeit slightly different).
EDIT: I can't seem to find it. :(
__________________
"The human sacrificed himself, to save the Pokemon. I pitted them against each other, but not until they set aside their differences did I see the true power they all share deep inside. I see now that the circumstances of one's birth are irrelevant; it is what you do with the gift of life that determines who you are." -Mewtwo
Wow, you took that well. I was expecting you to be a little annoyed at me for practically butchering through most of your suggestions. I like people who understand. Here's something you'll enjoy :)
Introducing ASM to your Bank scripts
Bank scripts are normally very simple. There's a variable which holds the amount of money you have, normally holding $65, 535. Or if the scripter who wrote the script is good like I am, it'd become 999, 999, 999. Anyways, bragging aside, I made two routines to help improve your banking experience :P
This is very specific to the bank variable you're using. I'll show you the routine first. There's some orange text for you to look at again. The first orange text is how often to add interest, 0x1 is every minute and 0x3b would be every hour. The second orange text is the amount you need to subtract from 0x4100 to reach your variable. Note, you bank variable should be in the range of 0x4011 - 0x40FF. If it's not you're using an unsafe variable and should change it to something.
After you've fixed the orange text to match your bank script compile and insert into free space.
Spoiler:
Code:
.text
.align 2
.thumb
.thumb_func
main:
push {r0-r5, lr}
ldr r0, =(0x300500C)
ldr r0, [r0]
add r0, r0, #0x10
ldrb r0, [r0] @mins
mov r1, #0x1 @frequency (range is from 0x1 to 0x3B). 0x1 = every minute
ldr r2, =(0x81E4684 +1)
bl linker2
cmp r0, #0x0
beq end
calculateInterest:
mov r0, #0x82 @ r0 = var = 0x82
lsl r0, #0x7 @ var = 0x82 * 0x80 = 4100
sub r0, r0, #0x1 @4100 -1 = 0x40FF. Subtract a sufficient amount to reach your var
@ the above is the variable tracking bank deposit value. Change amount subtracted if your var is different
mov r5, r0
ldr r4, =(0x806E568 +1) @get var
bl linker
mov r1, #0xA @0xA = 10%
mov r4, r0
mul r0, r0, r1 @multiply (percent * 100) * (Original price)
mov r1, #0x64
ldr r2, =(0x81E4018 +1) @integer divide by 100 = rounded price
bl linker2
add r1, r0, r4 @finalized total
mov r0, r5
ldr r4, =(0x806E584 +1) @set var
bl linker
end:
pop {r0-r5, pc}
linker:
bx r4
linker2:
bx r2
.align 2
After you've inserted this routine, append a pointer to it to the Minute Routine Framework table.
Usage:
No usage. Interest is added on a minute basis to your variable of choice (which should be deposited value).
Battle Money Straight into a variable
So this one is kind of specific, but I kinda felt like helping someone out so I did it. All it does is, intercept the money being given to the bag, and adds it to a given variable instead. It's toggled by flag 0x250.
How to insert:
Look at the orange text. Similar to the first routine, you will need to change the amount subtracted to match your variable (remember you're subtracting two hex numbers). Once you've fixed it, you can go ahead and compile the routine into free space (write down the place you compiled it to).
Now navigate to 0x259EC and insert the following byte changes:
Code:
00 49 08 47 XX XX XX 08
Where XX XX XX is the reverse hex pointer to where you inserted this routine +1.
Usage:
Flag 0x250 must be set for the routine to be toggled on, else money will be put in the player's bag as normal.
Hello. Glad I'd implemented it on my hack there are two problems and one question though.
My problem is upon defeating a trainer, the money that is supposed to be decreased by 10% is decreased by 100%. Upon setting flag 250, the every money that I get from a training is sent directly to the Var I had specified on the routine, and the playtime in trainer card stops at 00:59.
And one question, how to deposit the saved money?
__________________
This signature has been disabled.
Scrollbar appears
Please review and fix the issues by reading the signature rules.
You must edit it to meet the limits set by the rules before you may remove the [sig-reason] code from your signature. Removing this tag will re-enable it.
Do not remove the tag until you fix the issues in your signature. You may be infracted for removing this tag if you do not fix the specified issues. Do not use this tag for decoration purposes.
Hello. Glad I'd implemented it on my hack there are two problems and one question though.
My problem is upon defeating a trainer, the money that is supposed to be decreased by 10% is decreased by 100%. Upon setting flag 250, the every money that I get from a training is sent directly to the Var I had specified on the routine, and the playtime in trainer card stops at 00:59.
And one question, how to deposit the saved money?
Hello. As I'm aware, reading through the second routine, it basically stores all the money that would go to the player into the bank var instead, if a flag is set. To change the functionality there, you will have to edit the routine a little bit.
The first routine seems to just increment a variable based on the play time. It requires some other playtime fetching routine be installed already, make sure you've got all of that set up. If you have further problems feel free to ask in the ASM help thread.
Hello. As I'm aware, reading through the second routine, it basically stores all the money that would go to the player into the bank var instead, if a flag is set. To change the functionality there, you will have to edit the routine a little bit.
The first routine seems to just increment a variable based on the play time. It requires some other playtime fetching routine be installed already, make sure you've got all of that set up. If you have further problems feel free to ask in the ASM help thread.
the only problem left to me is the time stops upong setting flag and I don't know how to deposit the saved money. Anyway thanks for the reply.
__________________
This signature has been disabled.
Scrollbar appears
Please review and fix the issues by reading the signature rules.
You must edit it to meet the limits set by the rules before you may remove the [sig-reason] code from your signature. Removing this tag will re-enable it.
Do not remove the tag until you fix the issues in your signature. You may be infracted for removing this tag if you do not fix the specified issues. Do not use this tag for decoration purposes.
the only problem left to me is the time stops upong setting flag and I don't know how to deposit the saved money. Anyway thanks for the reply.
The money is in the bank variable. You deposit money by adding to that variable, and withdraw with a givemoney script and subtracting from the variable.
I cannot know the cause of your time being frozen, but it seems like an insertion error, because from a glance I cannot see any errors here. Remember to end your table with 0xFFs, stupid I know, but this is kind of from a stupid time. :)
I'm here again and here's some information about double wild battle in BPRE. The system is not yet perfect, but I don't have time to improve it so I decided to release the code. Please credit Jambo51 because some of the codes are ripped from his FR649. However, iirr, Karatekid552 has released the ASM codes in FR649 on github, so I think it's not inappropriate to post them here. These routines will make it possible to have "double wild battle" in "grass battles".
Bugs fixed:
1. Loading only 1 pokemon
2. Capture animation
3. Audio error
4. Captured pokemon data
5. pokedex things
6. can't flee
7. nickname issues
Wild Double Battle in BPRE
Now the main bugs are all fixed and here's a picture of what we can do now. (I don't use an English ROM, sorry.)
The byte changes are in the comments of the routines, so please read carefully.
After inserting the first routine, there will be a table in this format: 0A 00 05 00 0B 00 05 00 0C 00 05 00...... (The table is in the first routine and you can search for it)
The "05" is the rate of double battle in grass battles, which means 5% and you can change that on your own.
A, B, C, D are the ID of the 4 grass tile blocks and it's compatible with the clean BPRE 1.0 ROM.
As for now, there should still be some bugs like the fact that the name of captured pokemon is not shown right, but I won't do it now because I'm busy with my univ life. :)
I read your codes on guthub
And it says about 64 bit pc but what if one has 32 bit computer??
By basic asm do you mean compiling the asm codes and then writing the codes from .bin file to game pr writing asm codes???
The hooks and byte changes are in "insert.s", and the global symbols used are the pointer to the routines. The routines should be compiled at free space absolutely. Another issue is the battle script cmd header file, and you should change the path according to the location of the compiler.
Otherwise you can create a python script by using FBI's or others' template, I guess it can work, lol.
Despite gender being binary in the games, there is actually an entire byte set aside for it in the second saveblock. You can change this byte with a simple ASM routine, e.g.
Spoiler:
Code:
.align 2
.thumb
@ Set gender from value in script var 0x8000
set_gender_byte:
ldr r0, saveblock2_trainerdata
ldr r0, [r0]
ldr r1, variable
ldrb r1, [r1]
strb r1, [r0, #8] @ gender
bx lr
.align 2
saveblock2_trainerdata: .word 0x0300500C
variable: .word 0x020370B8 @ script var 0x8000
Set it to zero for male and one for female. Use another byte for another for another character
Note, this will break the script checkgender command! In order to restore it, you should first call checkgender, copy the value it returns in 0x800D to another unused var. Then set the gender using the above. Then you can restore it properly.
Lastly, apply this hook (untested):
Spoiler:
Code:
.align 2
.thumb
@ 00 48 00 47 XX + 1 XX XX 08 at 0x05C7E8 (0805C7E8 via r0)
character_table_hook:
lsr r0, #0x18
cmp r1, #2 @ check gender < 2
blo character_table_normal
@@ Load custom table
adr r3, character_table_custom
sub r1, #2 @ (gender - 2) * 6
lsl r2, r1, #2
sub r2, r1
lsl r2, #1
add r3, r2
add r0, r3
ldrb r0, [r1]
bx lr
character_table_normal:
lsl r0, #1
add r1, r0
add r1, r2
ldrb r0, [r1]
bx lr
.align 2
@@ Select overworld numbers for your new character
character_table_custom:
.byte 0 @ walking
.byte 1 @ biking
.byte 2 @ sitting (surfing)
.byte 3 @ vs seeker/pokeball
.byte 4 @ fishing
.byte 5 @ vs seeker/pokeball
You'll need to customise that table at the bottom. Each character you want must have its own 6 byte entry, even if you don't plan on using all the frames. The example entry above is a duplicate male character. Just change the bytes to the overworld sprites of your new character (the same in advance map when chooses a sprite for an NPC). Keep in mind you'll need running frames for the target character.
This probably will only refresh when you change map, so use the next hack.
Instant NPC sprite switch
This is related to the last hack, but can be more useful for a less permanent change. It can also work on other NPCs. Callasm as usual with the NPC person number in 0x8000 (same ID you use with applymovement - and 0xFF for the player) and the target sprite (the sprite index you'd use in advance map) in 0x8001.
Code untested.
Spoiler:
Code:
.align 2
.thumb
instant_npc_frame_switch:
push {r4-r6, lr}
sub sp, #4
ldr r4, variables
@@ Determine npc state id from person id
ldr r0, saveblock1_mapdata
ldr r0, [r0]
ldrb r0, [r4] @ person/local ID from var 0x8000
ldrb r1, [r0, #5] @ current map
ldrb r2, [r0, #4] @ current bank
mov r3, sp
ldr r5, npc_id_by_local_id_and_map_ret_success
bl call_via_r5
cmp r0, #0 @ failure check
bne instant_npc_frame_switch_return
@@ Get npc_state
mov r0, sp
ldrb r1, [r0] @ npc_id
lsl r0, r1, #3 @ npc_states + 0x24 * npc_id
add r0, r1
lsl r0, #2
ldr r1, npc_states
add r6, r0, r1
@@ Change Sprite
mov r0, r6 @ npc_state
ldrb r1, [r4, #2] @ sprite index from var 0x8001
ldr r5, npc_change_sprite
bl call_via_r5
@@ Update direction to prevent graphical artifacts
mov r0, r6
ldrb r1, [r0, #0x18] @ npc direction
lsr r1, #4
ldr r5, npc_turn
bl call_via_r5
instant_npc_frame_switch_return:
add sp, #4
pop {r4-r6, pc}
call_via_r5:
bx r5
.align 2
variables: .word 0x020370B8 @ script var 0x8000
saveblock1_mapdata: .word 0x03005008
npc_states: .word 0x02036E38
npc_change_sprite: .word 0x081507BC + 1
npc_turn: .word 0x0805F218 + 1
npc_id_by_local_id_and_map_ret_success: .word 0x0805DF84 + 1
It would be cool if someone could test these and write example scripts. I am too lazy.
Hello Touched, I have teste the codes already. The hook is not working properly, instead of walking sprites, it shows Surfing sprites.
And the NPC Change, overworlds other than the player are not changing when the ASM is called. There's amn issue also in changing the sprite of player, the color is not loaded properly.
__________________
This signature has been disabled.
Scrollbar appears
Please review and fix the issues by reading the signature rules.
You must edit it to meet the limits set by the rules before you may remove the [sig-reason] code from your signature. Removing this tag will re-enable it.
Do not remove the tag until you fix the issues in your signature. You may be infracted for removing this tag if you do not fix the specified issues. Do not use this tag for decoration purposes.
I don't hack Emerald but my friend jirachiwishmaker requested the code, so I will share it.
This is a port of Jambo51's codes in this thread to Emerald Version
If you still don't know what it is, please take a look at this picture:
1. Make these byte changes:
2. Insert these 3 ASM codes in free space and change bytes accordingly: insert 00 48 00 47 AA AA AA 08 at 0xB0F44, in which AA AA AA 08 is the pointer to the following routine (thumb mode +1)
insert 01 49 08 47 00 00 CC CC CC 08 at 0x147C42, CC CC CC 08 = pointer to the following code (thumb mode +1)
change 0x8FFFFFF to the palette table in your ROM and it can have 255 custom palettes.
The table's structure is [pointer1][pointer2]........................
Every pointer will point to a 16-color uncompressed palette (32 bytes)
D5 18 CE 39 52 4A D6 5A 5A 6B 41 07 A4 13 C6 1B E9 27 EF 3F FC 45 3E 4E 7F 56 BF 5E FF 66 FC 45
Give credit to Jambo51 (for the routines for BPRE) and jirachiwishmaker (for finding some offsets) if you use this hack. I only adjusted the routines so that it will be compatible with Emerald's RAM structure and fixed a small glitch in Jambo51's code1. So no credit needed for me, if you don't want to make your credit list long.
It doesn't change Elite Four and Champion classes. What I mean is... if I set 0x100, 0x200, or any value, it doesn't go to the specific value but it goes to 0x100 instead.
It doesn't change Elite Four and Champion classes. What I mean is... if I set 0x100, 0x200, or any value, it doesn't go to the specific value but it goes to 0x100 instead.
This one is ported from Jambo51's firered one, so it inherited the fact that the elite 4 and champion's classes won't be changed. You can try to remove the relative checks in the codes, I guess it should work. (perhaps you should adjust it a bit. I'm not sure since I don't have time to hack for months)
Hey o/ !
I'm posting here because i need a really little help. I'd like to add a Shining Charm to a Fire Red Hack. I know how to do it, I already did it before. But i've a problem this time. In the post, FBI takes the basic (NEW) rate of 1/4096 with this way :
But I'd like to use the REAL classic one, aka 1/8192 rate. But to be honnest, if I know how to apply ASM in hack, i'm not good enough to make ASM myself, so if somebody could give me the right lines to have the 1/8192 rate, it'd be nice
Hey o/ !
I'm posting here because i need a really little help. I'd like to add a Shining Charm to a Fire Red Hack. I know how to do it, I already did it before. But i've a problem this time. In the post, FBI takes the basic (NEW) rate of 1/4096 with this way :
But I'd like to use the REAL classic one, aka 1/8192 rate. But to be honnest, if I know how to apply ASM in hack, i'm not good enough to make ASM myself, so if somebody could give me the right lines to have the 1/8192 rate, it'd be nice
Thanks o/
small lesson
every hexadecimal byte represents an arrangement of bits
little "table":
Spoiler:
0 - 0000
1 - 0001
2 - 0010
3 - 0011
4 - 0100
5 - 0101
6 - 0110
7 - 0111
8 - 1000
9 - 1001
a - 1010
b - 1011
c - 1100
d -1101
e - 1110
f - 1111
this gives the byte 0x47 in hex a binary representation of 0100 0111
so, what about it? well, the lsl command in asm (logical shift left) takes the value in the register taken as a parameter, shifts its bit position the amount to the left as what is defined, and then puts the result in the other register that was a parameter.
let's take a look at the code snippet.
Code:
normal:
mov r0, #0x20 @puts the value 0x20 into register 0
lsl r0, r0, #0x7 @"bitshifts" the value in register 0 left by 7 places, storing it back in register 0
so, how do we know the resulting value?
well...
0x20 in binary is 0010 0000.
move that value left seven places by appending the necessary zeros on at the end
0010 0000 0000000
cut it up into correct pattern, appending zeros at the front when necessary (it is)
001|0 000|0 000|0000 = 0001 0000 0000 0000
new value: 0x1000. decimal equivalent? 4096.
so, what about getting 8192 in there?
do this process, but backwards~ report back your thought process, i wouldn't want you to get it wrong~
Sorry for the so late answer (was working so didn't have the time to check) but I have to say THANK YOU SO MUCH. I'm using this for many hack and wanted to test different shiny rate. With this, i'll be able to use the rate I want, so much better than a simple answer, I can't thank you enough for that.
About my conversion, I've to admit there's a part that i'm hitting something, but not sure if i'm right.
SO backwards.
Sorry for the so late answer (was working so didn't have the time to check) but I have to say THANK YOU SO MUCH. I'm using this for many hack and wanted to test different shiny rate. With this, i'll be able to use the rate I want, so much better than a simple answer, I can't thank you enough for that.
About my conversion, I've to admit there's a part that i'm hitting something, but not sure if i'm right.
SO backwards.