• Our software update is now concluded. You will need to reset your password to log in. In order to do this, you will have to click "Log in" in the top right corner and then "Forgot your password?".
  • Welcome to PokéCommunity! Register now and join one of the best fan communities on the 'net to talk Pokémon and more! We are not affiliated with The Pokémon Company or Nintendo.

[Other] Beginning Hacking (Gen 1)

56
Posts
8
Years
    • Seen Nov 27, 2016
    Basically the sla instruction causes a left shift leading to a multiplication by 2 while the srl instruction causes a right shift leading to a division by 2. By removing a srl b and a sla b for the non-focus energy case we leave it unaffected, while by replacing the two srl b affecting the focus energy used case with sla b, we make the crit rate four times higher instead of quartering it. jr c, .guaranteedCritical are there to make sure the value does not overflow.

    I'm not sure I would have figured that out on my own. Thank's a heap!

    When adding the label .gauranteedCritical some of my line numbers are different. Should I be more concerned with where they are in the code than with the line number they fall on? Is there a bit of code that should come before it? I see a lot of .variouslines that follow a "jr c" or "jr z".

    Spoiler:


    That's what I have from line 4684 to line 4745 since editing, if it helps.
     
    Last edited:
    170
    Posts
    11
    Years
  • Remove in red, add in green:

    CriticalHitTest: ; 3e023 (f:6023)
    xor a
    ld [wCriticalHitOrOHKO], a
    ld a, [H_WHOSETURN]
    and a
    ld a, [wEnemyMonSpecies]
    jr nz, .asm_3e032
    ld a, [wBattleMonSpecies]
    .asm_3e032
    ld [wd0b5], a
    call GetMonHeader
    ld a, [wMonHBaseSpeed]
    ld b, a
    ld a, [H_WHOSETURN]
    and a
    ld hl, wPlayerMovePower
    ld de, wPlayerBattleStatus2
    jr z, .calcCriticalHitProbability
    ld hl, wEnemyMovePower
    ld de, wEnemyBattleStatus2
    .calcCriticalHitProbability
    ld a, [hld] ; read base power from RAM
    and a
    ret z ; do nothing if zero
    dec hl
    ld c, [hl] ; read move id
    ld a, [de]
    bit GettingPumped, a ; test for focus energy
    jr z, .nofocusEnergyUsed ; bug: using focus energy causes a shift to the right instead of left,
    sla b
    jr c, .guaranteedCritical
    sla b
    jr c, .guaranteedCritical

    .noFocusEnergyUsed
    ld hl, HighCriticalMoves ; table of high critical hit moves

    .Loop
    ld a, [hli] ; read move from move table
    cp c ; does it match the move about to be used?
    jr z, .HighCritical ; if so, the move about to be used is a high critical hit ratio move
    inc a ; move on to the next move, FF terminates loop
    jr nz, .Loop ; check the next move in HighCriticalMoves
    srl b ; /2 for regular move (effective (base speed / 2))
    jr .SkipHighCritical ; continue as a normal move
    .HighCritical
    sla b ; *2 for high critical hit moves
    jr nc, .noCarry
    ld b, $ff ; cap at 255/256
    .noCarry
    sla b ; *4 for high critical move (effective (base speed/2)*8))
    jr nc, .SkipHighCritical
    ld b, $ff
    .SkipHighCritical
    call BattleRandom ; generates a random value, in "a"
    rlc a
    rlc a
    rlc a
    cp b ; check a against calculated crit rate
    ret nc ; no critical hit if no borrow
    jr nc, .guaranteedCritical
    ld a, $1
    ld [wCriticalHitOrOHKO], a ; set critical hit flag
    ret


    The difference between jr nc, .guaranteedCritical and .guaranteedCritical is that the former is a jump instruction while the second is a label. Labels are used so that when you want to use a jump or call instruction you don't have to figure out the hexadecimal address of where you want to jump to. The assembler will translate every label to the numeric position it is at. However you cannot reference a label in an instruction without creating the label itself, because in that case the assembler won't understand that unexisting label.
     
    Last edited:
    56
    Posts
    8
    Years
    • Seen Nov 27, 2016
    I'm now getting an error "Macro '.noFocusEnergyUsed' not defined". I'm not sure what was missing, but it pointed to the line I added in green above. :/
     
    170
    Posts
    11
    Years
  • Labels like .noFocusEnergyUsed cannot be tabulated like the rest of the code. Otherwise they are interpreted as a instruction, or failing that, as a macro.

    Also make sure that .noFocusEnergyUsed and jr z, .nofocusEnergyUsed (five lines above) use both either a capitalized or uncapitalized 'F' for the word focus.
     
    56
    Posts
    8
    Years
    • Seen Nov 27, 2016
    Labels like .noFocusEnergyUsed cannot be tabulated like the rest of the code. Otherwise they are interpreted as a instruction, or failing that, as a macro.
    So how do I get it to be recognized as a label?

    I double checked EVERY instance of .nofocusEnergyUsed and .noFocusEnergyUsed to make sure their spelling and instances match. They do match up, and unfortunately still I get exactly the same error.
     
    Last edited by a moderator:
    170
    Posts
    11
    Years
  • So how do I get it to be recognized as a label?
    Remove any identation or spacing of the line where the label is. Labels should be aligned to the left with no spacing or else rgbds will interpret them as instructions or macros.
     
    56
    Posts
    8
    Years
    • Seen Nov 27, 2016
    I see. That wasn't clear from the alignment change when I brought the code to the forum.
     
    56
    Posts
    8
    Years
    • Seen Nov 27, 2016
    Any suggestions for Hex Editors to open the map files (which are .BLKs)? I've tried THINGY and THING32, but they don't seem to recognize the BLK tag. Supposedly I can open my ROM in a program to find the offsets of map edits I've done with PokeMap, but still need a way to get the changes into the actual files so it doesn't overwrite the mapping when I compile other changes (seems tricky).
     

    miksy91

    Dark Energy is back in action! ;)
    1,480
    Posts
    15
    Years
  • Any suggestions for Hex Editors to open the map files (which are .BLKs)? I've tried THINGY and THING32, but they don't seem to recognize the BLK tag. Supposedly I can open my ROM in a program to find the offsets of map edits I've done with PokeMap, but still need a way to get the changes into the actual files so it doesn't overwrite the mapping when I compile other changes (seems tricky).
    You could always change the extension of the file to some other type that the hex editor you'd like to use is able to open. Or not totally change it at all, but add another extension to the end if needed.

    Anyway, I use GoldFinger for hex editing myself and it has been pretty handy in doing everything, so you might like it as well. I have not only used it for rom hacking but checking the data of several other files as well sometimes when I have needed (mostly related to programming really). But it can open a file with any extension.
     
    56
    Posts
    8
    Years
    • Seen Nov 27, 2016
    So I was initially trying to get a person to give an item, but it looked a little too involved when I compared it against scripts that did it. So now I'm just adding an item ball on the ground. So far so good, but the "GotItemText" isn't appearing in the text box when I g to pick the item up, and one of the other sources of text is doing the same (it wasn't before). Additionally, the item isn't being picked up off the ground.

    I'll bet it's some kind of script pointing issue, but up to this point I haven't messed too much with adding material, only changing things that were there before. For the sake of learning, I checked the text, script, and mapObject files for the area I'm adding the item against the files for an area that already had an item. I've matched the mapObject files, but can't figure out what's missing between the text and script files.

    Unfortunately it doesn't look like I'm going to have time to spend on hex editing for mapping purposes, so I've saved a spare rom with the map changes and will use it as a reference for just doing the mapping again (since that will be faster for me).

    EDITED-- Moot point. There was no initial disassembly on my part. DERP.
     
    Last edited:
    56
    Posts
    8
    Years
    • Seen Nov 27, 2016
    In hindsight, I realize how naive the thought of simply disassembling my ROM sounds. If it were that easy, it wouldn't have been such huge initial undertaking. I guess I'm back on the manual re-editing page. Although I still haven't quite the hang of those item issues. So close...
     
    56
    Posts
    8
    Years
    • Seen Nov 27, 2016
    So I've found some resources on adding scripts (which is part of the problem with adding obtainable items), but even these haven't solved my issue. After some reading, it seemed much simpler to have an NPC give a FRESH_WATER, but now I can't figure out why the code I'm using isn't working. I don't know if it's because pokered has been updated since the article was written, but it says that only a few lines of code are necessary (when other examples of similar code are much longer).

    This is my resource, just for point of reference.

    Based on the Warden's Gold Teeth script (FuschiaHouse2.asm), I may need to use the jr nz command, but if I do, how do I know what to call the label? Does it even matter? There are some numerical labels and I don't want to repeat one someplace else and not know it. I'm using the Route 1 potion sample guy as an example as well, and I want to make sure any new text sets I use don't overlap others or otherwise cause problems within my new scripts.

    So I figured out some more pieces and can receive the item from the NPC! However, it doesn't display all the text I have set up. I have the script file followed by the text file below. What's it missing?

    Spoiler:


    Spoiler:


    Can anybody point me in the right direction?
     
    Last edited:
    170
    Posts
    11
    Years
  • Could you be more specific about which is the script that doesn't work? I'm not sure what I should be looking at since you listed the whole viridian city script and text files.

    Based on the Warden's Gold Teeth script (FuschiaHouse2.asm), I may need to use the jr nz command, but if I do, how do I know what to call the label? Does it even matter? There are some numerical labels and I don't want to repeat one someplace else and not know it. I'm using the Route 1 potion sample guy as an example as well, and I want to make sure any new text sets I use don't overlap others or otherwise cause problems within my new scripts.
    Local labels are only relevant within the scope of the function they are at, so you can repeat them anywhere else. If you accidentally create a duplicate label inside the same function the build will fail so you'll notice it.
     
    56
    Posts
    8
    Years
    • Seen Nov 27, 2016
    Spoiler:


    Spoiler:

    That should be all the stuff I added. I also added sections of something "dw", which I figured was like "write" or something, since all the other scripts had them.
     
    170
    Posts
    11
    Years
  • dw defines a 2-byte word or a list of 2-byte words if you separe them with commas. A two-byte word could be a pointer, a 2-byte number or whatever. For example dw VermilionCityText1 defines a 2-byte pointer to VermilionCityText1. Some function will read that word in order to execute the VermilionCityText1 function from the right location.

    Anyway, the script looks good. Which is the text you had trouble displaying?
     
    56
    Posts
    8
    Years
    • Seen Nov 27, 2016
    Well, it skips "VermilionText4" entirely, although that should be the first text written.

    I think my problem is somewhere with setting and checking the event, as it seems to run the text
    like I've engaged the event already, hence skipping down to "VermilionTextFull" or "VermilionTextDrink" (since I've been playing with it). Even though it still awards me an item.
     
    170
    Posts
    11
    Years
  • The problem is that VermilionText4 isn't a text, but a script. So you're essentially trying to print a script's code as text.

    Replace ld hl, VermilionCityText4 with ld hl, WhateverYouLikeText and add below:

    WhateverYouLikeText:
    TX_FAR _VermilionCityText4
    db "@"
     
    56
    Posts
    8
    Years
    • Seen Nov 27, 2016
    I see! That fixed all the text, but now i have 2 other issues one big, one not so big:

    BIG: I must be missing part of the script that keeps the event from resetting when you leave the area. If I leave Vermilion City and come back I can obtain unlimited Fresh Waters.

    Not so big: The text automatically skips to the GotDrink message, instead of waiting for a button press. I tried adding "Prompt" to the end of "VermilionCityText4" in the actual text file, but didn't get any results. Small, but I want it to be as perfect as I can. By a stroke of luck, I also figured out how to get the item music to play. So that's solved.
     
    170
    Posts
    11
    Years
  • BIG: I must be missing part of the script that keeps the event from resetting when you leave the area. If I leave Vermilion City and come back I can obtain unlimited Fresh Waters.
    Where and how did you define EVENT_GOT_DRINK?

    Not so big: The text automatically skips to the GotDrink message, instead of waiting for a button press.
    I'm not sure but it's probably supposed to work that way between PrintText's.
     
    56
    Posts
    8
    Years
    • Seen Nov 27, 2016
    Where and how did you define EVENT_GOT_DRINK?

    I'm not sure but it's probably supposed to work that way between PrintText's.

    I added a bit for it in Event Constants, because pretty much every event had one. I simply put it at the end as "const EVENT_GOT_DRINK", and then added the next digit in hex on the list.

    That section turned green, and it's "; A00, (D887, bit 0)". Did I do it wrong or am missing something?

    It wouldn't bug me so much if I hadn't directly compared this new script with the Route 1 potion dude's script. I can confirm that it waits for a button press before giving the item.
     
    Back
    Top