Homebrew [WIP] ButtonSwap3DS - Remap buttons on your 3DS

mcaboosec

Active Member
OP
Newcomer
Joined
Sep 15, 2009
Messages
34
Trophies
0
XP
408
Country
United States

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 @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.
His patch was pretty easy for me to read to see what was going on, and I thought, "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?" After some experimentation, it worked!

I've put quite a bit of work to make this as user-friendly as possible, but be aware of a few things:
  • 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.
How To Use
Code is located at my repo: https://github.com/MikahJC/ButtonSwap3DS
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.
You will also need this library by @Stary2001: https://github.com/Stary2001/ScenicRoute. Clone it, then run make install in the ScenicRoute directory.
Finally, clone the repository at https://github.com/MikahJC/ButtonSwap3DS.
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 make.
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:
Code:
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.
The data that will be sent as the touchscreen. Use the provided tool to generate this 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!

2020 Update: I know I've been absent from this thread for a long time, so I want to thank @AmberLoss for putting together an FAQ here and helping others get mappings built. As of yesterday, I finished a project that should make this a lot easier to use. 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.

I've attached a basic version that swaps A and B for demonstration purposes.

Thanks and credit to @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. :)
2/15/2017: Uploaded a new zip with the mode3 version as well.
3/28/2017: @Vague Rant pointed out an error with the combo swap documentation. Thanks!
4/15/2017: Changed how button pressing and un-pressing works. As @Vague Rant and @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.
 

Attachments

  • ButtonSwap3DS.zip
    708.9 KB · Views: 2,543
Last edited by mcaboosec,

Stary2001

Member
Newcomer
Joined
Aug 1, 2016
Messages
7
Trophies
0
Age
24
XP
130
Country
Interesting - good work! I might look into being able to make it configurable on the 3DS itself somehow, via a background service or something. If that's doable I'll look into merging this into mainline InputRedirection, as it seems like a logical next step :)
Also,
I'm looking into hooking the IR process to achieve this.
I've looked into IR a bit - can we work together on this?
 

Alex658

Well-Known Member
Member
Joined
Jun 4, 2010
Messages
1,206
Trophies
1
Age
29
Location
Colombia
XP
1,194
Country
Colombia
Does this work with AGB_FIRM? I'm guessing no?

If this is a CTR program/app you'd lose arm11 control as soon as you boot up TWL or AGB modes... Since the 3ds downclocks itself, basically.

This is why you can't possibly use hans/ntr/etc on thosr modes.
 

ChrisN8

Well-Known Member
Member
Joined
May 13, 2015
Messages
332
Trophies
0
Age
39
XP
265
Country
France
amazing ! i tried the a to b .cia and it works fine. I hope it will end in a easy remapper, New3ds have a lot of button that Nintendo doesn't even care to use them correctly...
 
Last edited by ChrisN8,
  • Like
Reactions: jeffyTheHomebrewer

mcaboosec

Active Member
OP
Newcomer
Joined
Sep 15, 2009
Messages
34
Trophies
0
XP
408
Country
United States
Does that mean that could be able to use ZL and ZR on o3DS ..?
Not right now, but it's an interesting thought. I'm not sure if it would work given that the hardware is built into the N3DS, but was available to the O3DS via the circle pad pro attachment. Most games on the N3DS that use ZL and ZR also report that the CPP is attached.

I've looked into IR a bit - can we work together on this?
Sure! I've looked at ShinyQuagsire's writeup, but haven't had much luck trying to figure out the IR process myself.
 

mcaboosec

Active Member
OP
Newcomer
Joined
Sep 15, 2009
Messages
34
Trophies
0
XP
408
Country
United States
The B <-> A sample you provided works with non-mode3 games. Trying to use it with mode3 does not work (crash when starting ntr-mode3).
Yep, my bad. I originally only uploaded the standard version. I just attached a new zip with the mode3 cia as well.

Could someone here plz provide a Y <-> B swapper (non-mode3)? I always wanted to play Super Mario 3D Land with Super Mario World controls, never could enjoy that game with jumping on B.
Ask and ye shall receive! ;)
 

Attachments

  • ButtonSwap3DS_B_Y.zip
    708.9 KB · Views: 522

Vague Rant

Deceptively cute
Member
Joined
Aug 7, 2008
Messages
2,463
Trophies
2
Location
Melbourne
Website
vaguerant.tumblr.com
XP
3,302
Country
Could someone here plz provide a Y <-> B swapper (non-mode3)? I always wanted to play Super Mario 3D Land with Super Mario World controls, never could enjoy that game with jumping on B.
Buh? What Super Mario World did you play? It's always been Y to dash and B to jump.
 

ChrisN8

Well-Known Member
Member
Joined
May 13, 2015
Messages
332
Trophies
0
Age
39
XP
265
Country
France
So... is it possible to have a A <> Y version ?
By the way does your App switch the button between two specifify input or can assign any input or any button ?
 

ChrisN8

Well-Known Member
Member
Joined
May 13, 2015
Messages
332
Trophies
0
Age
39
XP
265
Country
France
@ChrisN8 It should be any combination (of the standard 3DS inputs, i.e. no ZL/ZR or C-Stick). mcaboosec posted a version a while ago that rotated A/B/Y clockwise, so that e.g. NES Virtual Console uses Y/B, and the leftover "Y" button is moved to "A".

that's interesting, clockwise means that A input will be on B button ? I need to have the A input on Y button.
 
Last edited by ChrisN8,

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
    K3Nv2 @ K3Nv2: https://youtu.be/MddR6PTmGKg?si=mU2EO5hoE7XXSbSr