ButtonSwap3DS: Difference between revisions

From GameBrew
No edit summary
No edit summary
Line 1: Line 1:
{{Obsolete}}
{{Infobox 3DS homebrew
{{Infobox 3DS homebrew
| title = ButtonSwap3DS
| title = ButtonSwap3DS
Line 5: Line 7:
| version = 4/15/2017
| version = 4/15/2017
| licence = Mixed
| licence = Mixed
| author =  
| author = mcaboosec (aka mikahjc)
| website = https://www.reddit.com/r/3dshacks/comments/f1k1gj/buttonswap3ds_builder_web_tool_for_configuring/
| website = https://github.com/MikahJC/ButtonSwap3DS
| download = https://dlhb.gamebrew.org/3dshomebrew/ButtonSwap3DS.rar
| download = https://dlhb.gamebrew.org/3dshomebrew/ButtonSwap3DS.rar
}}
ButtonSwap3DS is a 3DS homebrew application for button mapping based on [https://github.com/Kazo/InputRedirection InputRedirection by Kazo], which hooks into the HID process (which is responsible for user input), and redirects where the values for user input are read from in memory through Arm assembly.
'''Update from developer 2020:'''
You can use the web application [https://young-ravine-66468.herokuapp.com/config ButtonSwap3DS Builder] to configure the mappings you want and download a CIA with those mappings. It is based off ButtonSwap3DS, but instead of building your own from source it generates the remappings for you.
==Installation==
===Installing===
Once you have your CIA file for your remappings, install it on your 3DS with CIA manager.
Attached download link is a basic version that swaps A and B for demonstration purposes.


}}
===Building===
The instructions for each type of mapping are provided in the [https://github.com/mikahjc/ButtonSwap3DS/blob/master/source/injected.s source/injected.s] file. A Java program to is available for generating the correct button masks and coordinate values. When you have saved your mappings into this file, you will need to compile it. To build, change to the ButtonSwap3DS directory in a terminal, then run <code>make</code>.
 
'''Button Masks:'''


=ButtonSwap3DS=
This is the data that defines which buttons will activate the remapping and which buttons will be pressed as a result. Either use the provided program, or manually calculate the mask using [https://www.3dbrew.org/wiki/HID_Shared_Memory#PAD_State this table]. For example, this code would swap A and B:


===FAQ Here===
ldr r4, =0x1
ldr r5, =0x2
bl .button
ldr r4, =0x2
ldr r5, =0x1
bl .button
The next two data fields are six-digit numbers. The first 3 digits are the Y coordinate data, and the last 3 digits are the X coordinate data.


I originally started looking into swapping buttons when I got the MHGen hunting grip. I've always thought Nintendo's placement of the L/R and ZL/ZR is backwards from everyone else, and I don't like it. While searching for something to swap the two, I looked at the source for InputRedirection from [https://gbatemp.net/members/397085/ @Stary2001]. If you don't know how it works, it hooks into the HID process (which is responsible for user input), and redirects where the values for user input are read from in memory through Arm assembly.<br />
'''Touchscreen Data:'''
His patch was pretty easy for me to read to see what was going on, and I thought, &quot;What if we could get the values from what buttons were pressed, then modify the values before the value gets written to this redirected memory?&quot; After some experimentation, it worked!<br />
<br />
I've put quite a bit of work to make this as user-friendly as possible, but be aware of a few things:<br />
* This code works at almost the lowest level possible-assembly code; it is really hard to debug. As long as you don't touch the other functions (.single, .combo, .touch, .cpad), the worst that can happen is your console will get bad input data and be uncontrollable. Just reboot and try a different configuration.
* You '''''cannot''''' reconfigure this on the 3DS! Every time you want to change your button mappings, you need to edit the injected file and recompile the program. Hopefully I can change that in the future - I'm open to help for this.
* The C-stick and ZL/ZR are not mappable right now. I'm looking into hooking the IR process to achieve this.
* The Home button and Power button are not remappable. These buttons use a separate part of the hardware, and there are no plans to make this possible.
* While based on InputRedirection, it is not compatible. This program would overwrite any data sent by the InputRedirection desktop programs.
* It can still be a bit buggy. It is designed to un-press any buttons that were pressed if you use touchscreen or C-pad mappings, but I noticed that it doesn't always work when used with combos. YMMV.
* I've just merged with Stary's latest changes, but I haven't tested the Mode3 version, as I don't have an O3DS.
<div class="ToggleTriggerAnchor bbCodeSpoilerContainer">
<span>Spoiler: <span class="SpoilerTitle">Old &quot;How To Use&quot; and technical info</span></span>
<div class="SpoilerTarget bbCodeSpoilerText" style="display: block; opacity: 1;">


Code is located at my repo: https://github.com/MikahJC/ButtonSwap3DS<br />
<div class="ToggleTriggerAnchor bbCodeSpoilerContainer">
<span>Spoiler: <span class="SpoilerTitle">Build Environment</span></span>
<div class="SpoilerTarget bbCodeSpoilerText">
You will need a working setup of the devkitARM toolchain for 3DS, follow this guide if you need help: https://www.3dbrew.org/wiki/Setting_up_Development_Environment.<br />
You will also need this library by [https://gbatemp.net/members/397085/ @Stary2001]: https://github.com/Stary2001/ScenicRoute. Clone it, then run <span style="font-family: 'Courier New'">make install</span> in the ScenicRoute directory.<br />
Finally, clone the repository at https://github.com/MikahJC/ButtonSwap3DS.
</div>
</div>
The instructions for each type of mapping are provided in the source/injected.s file. I've provided a Java program to generate the correct button masks and coordinate values. When you have saved your mappings into this file, you will need to compile it. To build, change to the ButtonSwap3DS directory in a terminal, then run <span style="font-family: 'Courier New'">make</span>.<br />
<div class="ToggleTriggerAnchor bbCodeSpoilerContainer">
<span>Spoiler: <span class="SpoilerTitle">Each data field, and how to get it</span></span>
<div class="SpoilerTarget bbCodeSpoilerText">
<div class="ToggleTriggerAnchor bbCodeSpoilerContainer">
<span>Spoiler: <span class="SpoilerTitle">Button Masks</span></span>
<div class="SpoilerTarget bbCodeSpoilerText">
This is the data that defines which buttons will activate the remapping and which buttons will be pressed as a result. Either use the provided program, or manually calculate the mask using [https://www.3dbrew.org/wiki/HID_Shared_Memory#PAD_State this table]. For example, this code would swap A and B:<br />
<div class="bbCodeBlock bbCodeCode">
<div class="type">
Code:
</div>
<pre>ldr r4, =0x1
ldr r5, =0x2
bl .button
ldr r4, =0x2
ldr r5, =0x1
bl .button</pre>
</div>
</div>
</div>
The next two data fields are six-digit numbers. The first 3 digits are the Y coordinate data, and the last 3 digits are the X coordinate data.<br />
<div class="ToggleTriggerAnchor bbCodeSpoilerContainer">
<span>Spoiler: <span class="SpoilerTitle">Touchscreen Data</span></span>
<div class="SpoilerTarget bbCodeSpoilerText">
The data that will be sent as the touchscreen. Use the provided tool to generate this data.
The data that will be sent as the touchscreen. Use the provided tool to generate this data.
</div>
</div>
<div class="ToggleTriggerAnchor bbCodeSpoilerContainer">
<span>Spoiler: <span class="SpoilerTitle">C-pad Data</span></span>
<div class="SpoilerTarget bbCodeSpoilerText">
Data that will be sent as the c-pad. This data is a bit harder to calculate. The default value for the C-pad is 0x800800. To calculate this value, you will need to use the developer mode on your calculator. Xor 0x800800 by the value you want the C-pad to have. For example, if you want to have the C-pad pushed to the right, you would xor 0x800800 by 0x800FFF, giving you 0x7FF. Pad this with 3 zeroes in front (0x0007FF), and you have your data!


<br />
'''C-pad Data:'''
'''2020 Update''': I know I've been absent from this thread for a long time, so I want to thank [https://gbatemp.net/members/454375/ @AmberLoss] for putting together an FAQ [https://gbatemp.net/threads/wip-buttonswap3ds-remap-buttons-on-your-3ds.460891/page-14#post-8364487 here] and helping others get mappings built. As of yesterday, I finished a project that should make this a lot easier to use. [https://young-ravine-66468.herokuapp.com/config ButtonSwap3DS Builder] is a web application that lets you configure what mappings you want and download a CIA with those mappings. This eliminates the need to set up a build environment or use tools to calculate mappings. I'm on my phone right now but I'll try to add some more info to the FAQ once I get to a real computer.<br />
 
<br />
Data that will be sent as the c-pad. This data is a bit harder to calculate.
I've attached a basic version that swaps A and B for demonstration purposes.<br />
 
<br />
The default value for the C-pad is <code>0x800800</code>. To calculate this value, you will need to use the developer mode on your calculator. Xor <code>0x800800</code> by the value you want the C-pad to have.  
Thanks and credit to [https://gbatemp.net/members/397085/ @Stary2001]. He wrote all of the injection code and almost all of the setup code. I just figured out how to mess with the values in-between. [[File:styles/default/xenforo/clear.png|class=mceSmilieSprite mceSmilie48|:)]]<br />
 
<div class="ToggleTriggerAnchor bbCodeSpoilerContainer">
For example, if you want to have the C-pad pushed to the right, you would xor <code>0x800800</code> by <code>0x800FFF</code>, giving you <code>0x7FF</code>.
<span>Spoiler: <span class="SpoilerTitle">Changelog</span></span>
 
<div class="SpoilerTarget bbCodeSpoilerText" style="display: block; opacity: 1;">
Pad this with 3 zeroes in front (<code>0x0007FF</code>), and you have your data.
2/15/2017: Uploaded a new zip with the mode3 version as well.<br />
 
3/28/2017: [https://gbatemp.net/members/132767/ @Vague Rant] pointed out an error with the combo swap documentation. Thanks!<br />
==User guide==
4/15/2017: Changed how button pressing and un-pressing works. As [https://gbatemp.net/members/132767/ @Vague Rant] and [https://gbatemp.net/members/94928/ @rolim91] pointed out, multiple mappings had the possibility of affecting each other, resulting in undesirable results when multiple buttons were pressed. The new system maintains a record of which buttons need to be pressed and unpressed, then applies all changes at the end of the mapping process. My initial testing shows that it is working much better, but I appreciate any feedback if there are still bugs.
You cannot reconfigure this on the 3DS. Every time you want to change your button mappings, you need to edit the injected file and recompile the program.
 
To reset swap, simply reboot your 3DS and it will return to the original settings.
 
===Limitations===
Buttons that do not work with ButtonSwap:
* C-pad is only partially supported (any button can pretend they're the C-pad, but the original C-pad can't be modified).
* ZL/ZR aren't supported at all
* Home and Power buttons are impossible to remap.
 
===FAQ===
'''Q. My build environment is set up, but now I'm lost!'''
 
You can use @danger229's [https://github.com/danger229/ButtonSwap3dsMaker/releases ButtonSwap3dsMaker] instead, it's very user-friendly and will help you modify all the files you have to (you need to have ButtonSwap's build environment set up for it to work, though, so it's not a workaround).
 
'''Q. I've got the CIA file, now what?'''
 
You need to transfer your file to your 3DS and install the CIA. Many apps can help you with that, one of most common being [[FBL 3DS|FBI]]. Once it's installed, just run the application when you want to use the mappings.
 
'''Q. Can a button be disabled?'''
 
Yes it can. Just map r5 as 0x0 if you're doing the mapping yourself.
 
'''The screen says something about NTR-mode3, what does that mean?'''
 
If you don't know what it is, you're not using NTR-mode3 and just need to press START.
 
'''What is mode3? ButtonSwap isn't working with some games!'''
 
Mode3 is another word for the extended memory mode that O3DS has. If a game makes your 3DS' screen go black once you exit it, you're probably playing a mode3 game. ButtonSwap currently does not work with mode3 games, and sadly there are no devs around to fix it (N3DS players don't have to worry about all that, they don't have an extended memory mode).
 
'''Q. I want to switch different mappings, is that possible?'''
 
You'll need to have two (or more) different ButtonSwap apps, and you'll need to reboot your 3DS every time you want to switch between them. But yes, it's possible. Just tell the person doing your mappings that you want to do that. If you're the one doing them, remember to make sure your different mappings' UniqueIds are different (edit meta/cia.rsf and meta/cia_mode3.rsf).
 
'''Q. Can we have this new feature that I've just thought of?'''
 
There currently are no devs working on ButtonSwap, so not unless you (or someone you convince) do it.
 
'''Q. I'm in the middle of homebrewing and...'''
 
You can try to use ButtonSwap during the process but it probably won't work, sorry.
 
'''Q. Do I need anything on my 3DS for ButtonSwap to work?'''
 
Not really. All you need is a way to get the .cia file into your 3DS, and a way to install CIA files.
 
If you have FBI, you already have both.
 
'''Q. Can I have another way of installing this, like a .3dsx file?'''
 
Impossible, sorry. It has to be a .cia file.
 
'''Q. Does this work with VC or DS games?'''
 
It works with VC games (NES, GB, SNES etc), it doesn't work with GBA and DS/i games since they reboot the console on a different mode (thanks @Feffe for the info).
 
==Known issues==
It can still be a bit buggy. It is designed to un-press any buttons that were pressed if you use touchscreen or C-pad mappings, but it doesn't always work when used with combos. YMMV.
 
This code works at almost the lowest level possible-assembly code; it is really hard to debug. As long as you don't touch the other functions (.single, .combo, .touch, .cpad), the worst that can happen is your console will get bad input data and be uncontrollable. Just reboot and try a different configuration.
 
==Credits==
Memory patching code taken from BootNTR.
 
Shinyquagsire for his writeup on redirecting input over WiFi.
 
Stary & Kazo for InputRedirector, upon which almost all of this is based.
 
Thanks to AmberLoss for putting together the FAQ and helping others get mappings built.


==External links==
* GibHub - https://github.com/MikahJC/ButtonSwap3DS
* GBAtemp - https://gbatemp.net/threads/wip-buttonswap3ds-remap-buttons-on-your-3ds.460891
* Reddit - https://www.reddit.com/r/3dshacks/comments/f1k1gj/buttonswap3ds_builder_web_tool_for_configuring


<div class="_292iotee39Lmt0MkQZ2hPV RichTextJSON-root" theme="[object Object]" style="color:#1A1A1B">
[[Category:3DS homebrew applications]]
TL;DR: [https://young-ravine-66468.herokuapp.com/ New tool for building ButtonSwap3DS, homebrew that lets you remap 3DS buttons.]
[[Category:Homebrew utility applications on 3DS]]
Back in 2017, I figured out how to remap buttons based on the Input Redirection codebase. I posted it to [https://gbatemp.net/threads/wip-buttonswap3ds-remap-buttons-on-your-3ds.460891/ GBATemp] and I'm surprised the thread is still somewhat active. There are a number of problems with it though:
* In order to configure it, tools had to be made to calculate the data for you easily.
* You had to set up a small development environment to build the CIA.
* You can't reconfigure it on the 3DS. You want a new mapping, you need to rebuild it.
ButtonSwap3DS Builder solves the first two points, and provides a workaround for the third. It's a web based tool that provides an easy way to write remaps and get the CIA for it. Under the main configuration panel, you can change the unique ID of the generated CIA so you can have multiple versions installed.
It's currently hosted on a free tier Heroku instance, so if it's not responding you may need to wait for traffic to die down. If it's down too often, I'll look into hosting it somewhere else.
Enjoy!

Revision as of 06:07, 12 July 2021

Template:Infobox 3DS homebrew

ButtonSwap3DS is a 3DS homebrew application for button mapping based on InputRedirection by Kazo, which hooks into the HID process (which is responsible for user input), and redirects where the values for user input are read from in memory through Arm assembly.

Update from developer 2020:

You can use the web application ButtonSwap3DS Builder to configure the mappings you want and download a CIA with those mappings. It is based off ButtonSwap3DS, but instead of building your own from source it generates the remappings for you.

Installation

Installing

Once you have your CIA file for your remappings, install it on your 3DS with CIA manager.

Attached download link is a basic version that swaps A and B for demonstration purposes.

Building

The instructions for each type of mapping are provided in the source/injected.s file. A Java program to is available for generating the correct button masks and coordinate values. When you have saved your mappings into this file, you will need to compile it. To build, change to the ButtonSwap3DS directory in a terminal, then run make.

Button Masks:

This is the data that defines which buttons will activate the remapping and which buttons will be pressed as a result. Either use the provided program, or manually calculate the mask using this table. For example, this code would swap A and B:

ldr r4, =0x1
ldr r5, =0x2
bl .button
ldr r4, =0x2
ldr r5, =0x1
bl .button

The next two data fields are six-digit numbers. The first 3 digits are the Y coordinate data, and the last 3 digits are the X coordinate data.

Touchscreen Data:

The data that will be sent as the touchscreen. Use the provided tool to generate this data.

C-pad Data:

Data that will be sent as the c-pad. This data is a bit harder to calculate.

The default value for the C-pad is 0x800800. To calculate this value, you will need to use the developer mode on your calculator. Xor 0x800800 by the value you want the C-pad to have.

For example, if you want to have the C-pad pushed to the right, you would xor 0x800800 by 0x800FFF, giving you 0x7FF.

Pad this with 3 zeroes in front (0x0007FF), and you have your data.

User guide

You cannot reconfigure this on the 3DS. Every time you want to change your button mappings, you need to edit the injected file and recompile the program.

To reset swap, simply reboot your 3DS and it will return to the original settings.

Limitations

Buttons that do not work with ButtonSwap:

  • C-pad is only partially supported (any button can pretend they're the C-pad, but the original C-pad can't be modified).
  • ZL/ZR aren't supported at all
  • Home and Power buttons are impossible to remap.

FAQ

Q. My build environment is set up, but now I'm lost!

You can use @danger229's ButtonSwap3dsMaker instead, it's very user-friendly and will help you modify all the files you have to (you need to have ButtonSwap's build environment set up for it to work, though, so it's not a workaround).

Q. I've got the CIA file, now what?

You need to transfer your file to your 3DS and install the CIA. Many apps can help you with that, one of most common being FBI. Once it's installed, just run the application when you want to use the mappings.

Q. Can a button be disabled?

Yes it can. Just map r5 as 0x0 if you're doing the mapping yourself.

The screen says something about NTR-mode3, what does that mean?

If you don't know what it is, you're not using NTR-mode3 and just need to press START.

What is mode3? ButtonSwap isn't working with some games!

Mode3 is another word for the extended memory mode that O3DS has. If a game makes your 3DS' screen go black once you exit it, you're probably playing a mode3 game. ButtonSwap currently does not work with mode3 games, and sadly there are no devs around to fix it (N3DS players don't have to worry about all that, they don't have an extended memory mode).

Q. I want to switch different mappings, is that possible?

You'll need to have two (or more) different ButtonSwap apps, and you'll need to reboot your 3DS every time you want to switch between them. But yes, it's possible. Just tell the person doing your mappings that you want to do that. If you're the one doing them, remember to make sure your different mappings' UniqueIds are different (edit meta/cia.rsf and meta/cia_mode3.rsf).

Q. Can we have this new feature that I've just thought of?

There currently are no devs working on ButtonSwap, so not unless you (or someone you convince) do it.

Q. I'm in the middle of homebrewing and...

You can try to use ButtonSwap during the process but it probably won't work, sorry.

Q. Do I need anything on my 3DS for ButtonSwap to work?

Not really. All you need is a way to get the .cia file into your 3DS, and a way to install CIA files.

If you have FBI, you already have both.

Q. Can I have another way of installing this, like a .3dsx file?

Impossible, sorry. It has to be a .cia file.

Q. Does this work with VC or DS games?

It works with VC games (NES, GB, SNES etc), it doesn't work with GBA and DS/i games since they reboot the console on a different mode (thanks @Feffe for the info).

Known issues

It can still be a bit buggy. It is designed to un-press any buttons that were pressed if you use touchscreen or C-pad mappings, but it doesn't always work when used with combos. YMMV.

This code works at almost the lowest level possible-assembly code; it is really hard to debug. As long as you don't touch the other functions (.single, .combo, .touch, .cpad), the worst that can happen is your console will get bad input data and be uncontrollable. Just reboot and try a different configuration.

Credits

Memory patching code taken from BootNTR.

Shinyquagsire for his writeup on redirecting input over WiFi.

Stary & Kazo for InputRedirector, upon which almost all of this is based.

Thanks to AmberLoss for putting together the FAQ and helping others get mappings built.

External links

Advertising: