Can you edit the button controls on a ds rom?

Discussion in 'NDS - ROM Hacking and Translations' started by Jugo, Jul 4, 2011.

  1. Jugo
    OP

    Jugo Advanced Member

    Newcomer
    83
    0
    Apr 17, 2010
    United States
    I mean like swapping them. Ex: Switching the B and X buttons in pokemon so you can use the menu with B and run with X.
     
  2. Cyan

    Cyan GBATemp's lurking knight

    Global Moderator
    18,076
    8,586
    Oct 27, 2002
    France
    Engine room, learning
    Such a hack has already been done on other games (like Zelda to enable moving with D-pad instead of stylus).

    I don't know how hard it is to change the button layout, but I just wanted to tell you that it's possible.
     
  3. syko5150

    syko5150 GBAtemp Syko!

    Member
    3,091
    40
    Apr 25, 2009
    United States
    California
    I would say it's possible as it's been done on games like Guitar Hero to allow you to change which buttons match to which colors.
     
  4. FAST6191

    FAST6191 Techromancer

    pip Reporter
    23,361
    9,154
    Nov 21, 2005
    Guitar hero, zelda Dpad and starfox Dpad hacks were actually a cut above what you want to do here. The touch screen to dpad stuff actually rewrote parts of the game to operate in such a manner (it made the buttons change things the touch screen was previously responsible for) where the guitar hero used part of the GBA slot as a bus which actually added buttons to the DS that the hacks then turned the game away from and pointed at the buttons. I also recall a cheat for trauma center that reset patient health based upon a "miss" that might be worth looking at (or not as a miss probably registers in other places).

    Generally speaking the buttons which all have their own memory mapping are read every so often (might be refresh) and usually dumped to another memory section to use. Theory behind that if you have ever had a mouse that would double click for a single click chances are the switch was experiencing a failure method known as switch bounce (part was worn and making the circuit twice usually)- by copying it to the memory section and only using that you can negate this somewhat (the method is called debouncing).
    That aside over getting back to the hacking the button register is detailed http://nocash.emubase.de/gbatek.htm#dskeypad
    GBA part which has a bit more info
    http://nocash.emubase.de/gbatek.htm#gbakeypadinput

    You get to figure out what the game does and edit it. Naturally this means ASM hacking (if cheats do it they change the binary in memory).

    I personally would find the debounced copy (it might be a straight copy of the register but some games have been known to set a byte for each which is awesome as you then just have to change (or in your case swap) the destination) and fiddle with that (or indeed change how it gets there) so what was the button "a" bit is now the button "b" otherwise you run the risk of having to chase down interrupts and game logic and changing how they all work which is potentially a very long and boring process.

    Although I said starfox stuff was actually a bit outside what you want there is a nice guide to it http://crackerscrap.com/docs/sfchacktut.html which covers a lot of the background theory and implementation of the hack.

    Others have gone the electrical engineering route and physically remapped the buttons which is easier if you can swing a soldering iron.
     
  5. Galaxia

    Galaxia Newbie

    Newcomer
    7
    0
    Feb 5, 2017
    Could you please explain how to find the controls and how to edit the values of the buttons? The links you gave are all down. I would like to edit the atrocious controls of Kirby Super Star Ultra and Kirby Squeak Squad, and swap the b and y buttons.
     
  6. FAST6191

    FAST6191 Techromancer

    pip Reporter
    23,361
    9,154
    Nov 21, 2005
    The starfox one was archived
    https://web.archive.org/web/20110604163902/http://crackerscrap.com/docs/sfchacktut.html

    GBAtek is now located
    http://problemkaputt.de/gbatek.htm

    The stuff I wrote above is pretty much what I would say today.

    The GBAtek link shows the (read only) bit of memory which the system changes when buttons are pressed. For the reasons mentioned in the first post then sensible game coders will copy this state every vblank usually (maybe hblank for something really strange or it could be some other set period or prior to a certain operation in some cases) to somewhere in memory. Anything that depends upon the button press will likely then read that area of memory.
    You then get to figure out what the game reads from that area and does in response. Three main approaches game devs will use

    1) All hard coded right down to the assembly level
    2) Control mapping setups
    3) Full remapping.

    At a code level 2) and 3) will probably look fairly similar but where you might need to go full bore assembly hack you might be able to find a sort of table in the game somewhere to change what it calls a given setup.

    1) will probably look something like
    [read control state into memory/register]
    either compare or do some boolean operation and then compare to find if the button you want is pressed
    if pressed call jump/shoot/start game/glug potion/whatever routine
    else carry on with life

    You then get to alter this compare to read the results of another button. In the case of the DS it might be slightly more complex if you want to read the X and Y buttons as they are DS special registers and not GBA buttons which are A and B. Chances are the devs will do it all in one lump and it will probably not be anything drastic but be aware of that.
    Quote from gbatek
    4000136h - NDS7 - EXTKEYIN - Key X/Y Input (R)

    0 Button X (0=Pressed, 1=Released)
    1 Button Y (0=Pressed, 1=Released)

    To this end if you wanted to read the result of Y rather than X you would want to get the function to look at bit 1 rather than bit 0 by altering whatever means it uses (could be many things but will be fairly obvious).

    The cowboy method is also an option but will probably be game wide where the above is more precise. If you don't care then great, it is also useful if you have many functions all looking at one button and you want to change them all without hunting down each individual one.
    I mentioned it copying to memory. After it has copied to memory then you jump in and swap whatever bits or disable whatever bit you want (some people like this if their shoulder buttons fail and look as though they are constantly pressed). Or to go back to the case above and say swap X and Y then you would want to figure out if either was pressed, store that and that alone in a number that represents the other, set both to be low and then probably do a logical OR with the results of that to swap buttons.
     
    Galaxia likes this.
  7. Galaxia

    Galaxia Newbie

    Newcomer
    7
    0
    Feb 5, 2017
    Thank you for replying to something on a 6 year old post so quickly. Most of what you wrote went over my head, (I am but a simple man that wishes to play Kirby properly) but I think I'll try the cowboy method and replace all instances of one button press causing something with another button press. I don't no what I'm doing, but I still appreciate ya. ^ĚŽ^
     
  8. FAST6191

    FAST6191 Techromancer

    pip Reporter
    23,361
    9,154
    Nov 21, 2005
    Afraid there are not really any easy ins here. In the case of 2 and 3 there might be but identifying what goes in the first place still has to happen. In the case of text and graphics you can learn enough to change some games fairly radically in short order but assembly is often the end stage in learning and most far reaching thing for a reason. Similarly if someone hands a worked up version to you then you can do a lot; if you found the guitar hero stuff here then the later threads were all people tweaking the cheat button mappings to their preference, though it is a different type of hack in some ways it is not entirely dissimilar in how it would play out for the end user wanting to refine things.

    I am sitting here trying to think if there is a means to teach you what is likely to be seen in control hacking and spare some of the other stuff that might not be so relevant. However it is all so variable in what goes that I can't do much without basically doing the hack for you, and while it is not going to be a months long slog it is not a postpone my afternoon film thing either.
     
    Galaxia likes this.
  9. skawo

    skawo GBAtemp Regular

    Member
    203
    401
    Aug 18, 2015
    Which game would you want this done to?

    I'm fairly sure I could get it done pretty quickly.

    EDIT:
    Oh. OK. Will try.
     
    Last edited by skawo, Feb 6, 2017
    Galaxia likes this.
  10. Galaxia

    Galaxia Newbie

    Newcomer
    7
    0
    Feb 5, 2017
    Thank you. I'll make a WordPress for these hacks. :lol:
     
  11. Galaxia

    Galaxia Newbie

    Newcomer
    7
    0
    Feb 5, 2017
  12. skawo

    skawo GBAtemp Regular

    Member
    203
    401
    Aug 18, 2015
    I dunno, is this OK? Seems to work to me, but please check:
    https://dl.dropboxusercontent.com/u/4558852/2696 - Kirby Super Stars Ultra (U)(XenoPhobia).xdelta

    Applies to ROM w/ same filename.

    It's a fairly lame approach, but whatever:
    Code:
    nsub_0200182C_main:
       STMFD SP!, {R0-R3}
       MOV R0, R4
       MOV R1, R4
       LDR R2, =0x802
       LSR R0, R0, #1
       LSR R1, R1, #11
       ANDS R0, #1
       EORNE R4, R2
       ANDS R1, #1
       EORNE R4, R2
       LDMFD SP!, {R0-R3}
       STRH R4, [R0, #0xE4]
       STRH R4, [R0, #0xE6]
       STRH R4, [R0, #0xE8]
       B 0x2001830
    
     
    Galaxia likes this.
  13. Galaxia

    Galaxia Newbie

    Newcomer
    7
    0
    Feb 5, 2017
    It isn't working. Xdelta says it can't find the patch when I try to apply it.
     
  14. skawo

    skawo GBAtemp Regular

    Member
    203
    401
    Aug 18, 2015
    ...That would imply you haven't selected the patch, or are doing something else wrong in the patcher, not a problem with the patch itself.
     
    Galaxia likes this.
  15. Galaxia

    Galaxia Newbie

    Newcomer
    7
    0
    Feb 5, 2017
    Yup, you were right...
    While you're at it, could you make something like this for Squeak Squad? From what I understand the game uses the same engine.
     
  16. Galaxia

    Galaxia Newbie

    Newcomer
    7
    0
    Feb 5, 2017
    Wait, I still can't patch it, when I try it "xdelta3: target window checksum mismatch: XD3_INVALID_INPUT" comes up. I'm pretty sure that it is a bad ROM... Perhap you shoul try it again with the (E) version.
     
  17. FAST6191

    FAST6191 Techromancer

    pip Reporter
    23,361
    9,154
    Nov 21, 2005
    I have seen a few pre trimmed ROMs about the place as well. Xdelta should have the option to force ignore any input checksums.
     
  18. skawo

    skawo GBAtemp Regular

    Member
    203
    401
    Aug 18, 2015
    If you type that filename into Google, the first result should be the correct ROM