News: 11 March 2016 - Forum Rules

Author Topic: A question about adding or editing controller inputs  (Read 2110 times)

hodgermccodger

  • Jr. Member
  • **
  • Posts: 4
    • View Profile
A question about adding or editing controller inputs
« on: August 11, 2021, 07:27:37 am »
Hi,

I was hoping to learn about adding controller inputs and I'd be very grateful if anyone could point me in the right direction.

Suppose you're playing Turtles in Time using a Playstation Four controller and you wanted to make the game play a little bit like Bloodborne. In addition to the normal controls you wanted to add an input such that if the player presses L2 the turtle eats a slice of pizza that increases their health (like a blood vial in bloodborne) and if they press R2 they do a roll that gives them temporary invulnarbility.

How easy is that to do? Are there particular games that would lend themselves to doing that? Has it been done before and are there any resources directed to this kind of change?

Any thoughts or suggestions would be very welcome, thank you.

KingMike

  • Forum Moderator
  • Hero Member
  • *****
  • Posts: 7322
  • *sigh* A changed avatar. Big deal.
    • View Profile
Re: A question about adding or editing controller inputs
« Reply #1 on: August 11, 2021, 11:18:18 am »
You would have to edit the game's programming itself, which means having to learn how to program for the console in question.

Also, you can't use more buttons than the original console supported unless you intended to make a hack that only works with a specific modified emulator (which would not be an accepted hack here).
"My watch says 30 chickens" Google, 2018

Jorpho

  • Hero Member
  • *****
  • Posts: 5121
  • The cat screams with the voice of a man.
    • View Profile
Re: A question about adding or editing controller inputs
« Reply #2 on: August 11, 2021, 11:45:35 am »
Suppose you're playing Turtles in Time using a Playstation Four controller
The controller is the last thing to consider. Would this be Turtles in Time running on MAME, or some variety of port?

Quote
In addition to the normal controls you wanted to add an input such that if the player presses L2 the turtle eats a slice of pizza that increases their health (like a blood vial in bloodborne) and if they press R2 they do a roll that gives them temporary invulnarbility.
It would be relatively straightforward, if not exactly easy, to devise a cheat in MAME that completely refills your health or that toggles invulnerability. And I expect it might also be possible to bind those cheats to a keyboard combo and/or button press.  Writing something that will actually start the pizza-eating animation would be considerably more difficult. And if there are no sprites in the ROM for a rolling maneuver, such that you'd have to draw new sprites and re-insert them into the ROM – well, that's enormously difficult.
This signature is an illusion and is a trap devised by Satan. Go ahead dauntlessly! Make rapid progres!

FAST6191

  • Hero Member
  • *****
  • Posts: 3401
    • View Profile
Re: A question about adding or editing controller inputs
« Reply #3 on: August 11, 2021, 03:30:53 pm »
Three main approaches to such a thing.

1) Traditional control editing. This has two, maybe three approaches as well.

2) OS level editing.

3) Controller level tweaking.

In all cases mapping stick/analogue movement to button presses and vice versa can be tricky, though not necessarily impossible.

Going in reverse order.

Controller level stuff is much as it sounds. Here you open up a controller, take whatever button to whatever other button by cutting traces and throwing wires around. Those doing controllers for disabled people, rapid fire mods (see test points) and the like being what you probably want to look at for a start. To do more complicated actions you then get to investigate programmable micro controllers and such like (seen arduino, teensy family and other such things -- the blinking light patten that such things using for their basic intro tutorial being about as radical as most coding needs here).
Costs a controller per player and some time but works on any game, any console, no hacks needed, and depending upon how good you are can be reprogrammed to do other things.

2) OS level stuff is gained by more recent devices. Anything without an OS running in the background can't do this. Never the less many hacked firmwares/operating systems for things are this. I don't know enough about PS4 hacks to know what goes here but it is fairly common for most things that gain hacked firmware/software level hacks.

PC can do this sort of thing trivially, amusing video covering the general premise and a not unreasonable method.
https://www.youtube.com/watch?v=lIFE7h3m40U
I don't know what the kids are using instead of joy2key this week. The software layers in the video above also being pretty good for macros. You can also drag back your teensy family device in this if you had one from 1) as they can function as a keyboard and mouse.

3) Game editing, naturally needs the means to run a custom game.
As mentioned three main avenues of attack
i) Debounce area editing.
Consoles have the data for the controller appear in memory somehow (serial, packet, parallel... you can consider those if you want but ultimately it ends up in memory). However most won't use it directly from memory -- possibly too slow, and bounce issues. Bounce is a failure mode in switches but also a general concept; ever had a mouse double click on you when you had only clicked once, this is switch bounce, even healthy switches however do it on millisecond levels where it might flick a few times between pressed and not before settling. Very annoying for users where things are measured in milliseconds for various things or might have two things depend upon a button press that might be pressed for the first aspect but not when it goes to check again.
This debounce area is generally normal memory and thus you can go in and change bit 1 (call it X in this hypothetical) to be high and instead have bit 3 (O in this example) be low when bit 3 was originally high and vice versa (this is your X-O swap). Probably going to be game wide rather than specific things, and won't have corresponding on screen tweaks unless you do those separately.

ii) Traditional editing.
In the game will be a function that checks a button press (or more likely is an interrupt as checking all the time is dubious use of computing resources) and correspondingly does an action. You tell it to respond to another button aspect and bam.
Needs every action you want changing to have this done to it.
This would also be how most add serious extra functions/features to games (diagonal movement in games without it being the classic example, however your one for potions if it is not something a simple macro can do might be one).
Depending upon what you are doing this is a reasonable assembly level hack-- something with a nice definitive action (jumping, consuming something -- the sort of thing that has a definite effect on some area of memory you can find with a cheat or basic analysis) that you can latch onto and work backwards from that point (use a potion and somewhere in the preceding instructions before the potion counter is reduced by 1 dealing with the sound, animation and whatnot will be the button press it looked for in the first place). If there is not already an invincibility move then you get to make one, and in that case we get to talk about graphics editing and hitboxes (bit basic but a nice intro https://www.pcgamer.com/uk/how-hitboxes-work/ ) which is a far bigger ask -- while limits for ROM hacks are "whatever you can make the device in question do" then more practically "something the game already does" tends to be the limit before things get hard.

iii) Caveat for in game custom controller setups, even basic ones where you can only swap between premade schemes. These are something of a combination between i) and ii) and the game will have its own scheme to go between bounce and actions happening. Find this scheme and you can edit things, for more customisable stuff than premade then a lot of the time restrictions are just things the dev put in there because they thought nobody would want that and as such you might be able to poke it with a cheat to have it be what you think is necessary.

hodgermccodger

  • Jr. Member
  • **
  • Posts: 4
    • View Profile
Re: A question about adding or editing controller inputs
« Reply #4 on: August 11, 2021, 08:31:01 pm »
Thank you all very much for your replies, this is very helpful and I'll carefully look through them. My plan was to use the SNES port of Turtles in Time as I'm slightly familiar with the assembly language (although this is not saying very much at all). 

Jorpho

  • Hero Member
  • *****
  • Posts: 5121
  • The cat screams with the voice of a man.
    • View Profile
Re: A question about adding or editing controller inputs
« Reply #5 on: August 12, 2021, 10:03:15 am »
My plan was to use the SNES port of Turtles in Time as I'm slightly familiar with the assembly language (although this is not saying very much at all).
Since you're playing with a PS4 controller, I assume you're running the game in an emulator. (I don't think anyone's made a general-purpose USB-to-SNES controller adapter yet, though considering things like TASbot, it's certainly not impossible.)

You may want to look into using LUA scripts, which are somewhat easier to write.
This signature is an illusion and is a trap devised by Satan. Go ahead dauntlessly! Make rapid progres!

hodgermccodger

  • Jr. Member
  • **
  • Posts: 4
    • View Profile
Re: A question about adding or editing controller inputs
« Reply #6 on: August 14, 2021, 08:01:46 am »
Thank you, I'll have a look into that too as I'm using Lua for something I'm working on at the moment.

I'd be interested to know if there were examples of this already. If it were possible, I'd be surprised it hasn't been done by some method.

Thanks again for your help.

FAST6191

  • Hero Member
  • *****
  • Posts: 3401
    • View Profile
Re: A question about adding or editing controller inputs
« Reply #7 on: August 14, 2021, 12:41:07 pm »
Plenty of Lua scripts acting as very specialised macros, functioning as cheats (would be trivial to create a variable in Lua, or maybe just in a free space in the game's memory, saying you have 4 slices of pizza per level, pressing this button combo uses one to heal you however much -- health is just a variable in memory you can find like you would any other cheat, assuming someone has not made a cheat before you can just read the memory address from. https://web.archive.org/web/20080309104350/http://etk.scener.org/?op=tutorial and https://doc.kodewerx.org/hacking_snes.html if you are needing some links, if the second one is down the wiki thing is called enhacklopedia and has several mirrors about the place).

I would probably have a scan of various disabled gamers forums as that will be where you find most of the good stuff here for your purposes, though the tool assisted speedrun set will probably also have some interesting things.

https://www.dropbox.com/s/b2kuma6zs89di8n/Metroid.lua is for the NES but probably also one of the more expansive takes on what can be accomplished with Lua whilst still being nice and commented/readable for introductory purposes. Some discussion on the script was had from http://www.romhacking.net/forum/index.php?topic=18717.0 which is also where I got the link.

KingMike

  • Forum Moderator
  • Hero Member
  • *****
  • Posts: 7322
  • *sigh* A changed avatar. Big deal.
    • View Profile
Re: A question about adding or editing controller inputs
« Reply #8 on: August 14, 2021, 12:41:25 pm »
Since you're playing with a PS4 controller, I assume you're running the game in an emulator. (I don't think anyone's made a general-purpose USB-to-SNES controller adapter yet, though considering things like TASbot, it's certainly not impossible.)

You may want to look into using LUA scripts, which are somewhat easier to write.

I use my Retrode to use my real SNES controller on PC, and I'm sure it's far from the only USB device on the market.
"My watch says 30 chickens" Google, 2018

Jorpho

  • Hero Member
  • *****
  • Posts: 5121
  • The cat screams with the voice of a man.
    • View Profile
Re: A question about adding or editing controller inputs
« Reply #9 on: August 14, 2021, 01:35:19 pm »
I use my Retrode to use my real SNES controller on PC, and I'm sure it's far from the only USB device on the market.
Of course; I would call that a SNES-to-USB adapter. But while I'm sure it's not impossible to make one, I can't imagine there's much demand for a device that would let you plug a USB controller (like the aforementioned PS4 controller) into a SNES.
This signature is an illusion and is a trap devised by Satan. Go ahead dauntlessly! Make rapid progres!

KingMike

  • Forum Moderator
  • Hero Member
  • *****
  • Posts: 7322
  • *sigh* A changed avatar. Big deal.
    • View Profile
Re: A question about adding or editing controller inputs
« Reply #10 on: August 14, 2021, 05:47:17 pm »
Oh, I seem to have gotten the reverse idea of what you said.
I thought you were talking about using a SNES controller on PC (through USB).
Were you talking about using a USB controller (like PS4) on SNES?

I don't see that working. I see it likely game software could only read as many buttons as the original controller supported.
Not unless a connector device is somehow wired up to send more button inputs similar to official add-on devices (such as how I imagine the mouse or Super Scope sent inputs, which I think I read was through the NES-format manual polling registers $4016/4017 and not the dedicated auto-poll $4218-421F registers).
"My watch says 30 chickens" Google, 2018

Jorpho

  • Hero Member
  • *****
  • Posts: 5121
  • The cat screams with the voice of a man.
    • View Profile
Re: A question about adding or editing controller inputs
« Reply #11 on: August 14, 2021, 11:26:17 pm »
Yes, that's why I bought up TASbot – which is a device that can be hooked up to the original SNES controller ports.  Apparently it simulates a multitap, and once you get arbitrary code execution in a game, TASbot can accordingly be used to send ridiculous amounts of data.
This signature is an illusion and is a trap devised by Satan. Go ahead dauntlessly! Make rapid progres!