yancharkin / SpelunkyClassicHD

A modified version of Derek Yu's game Spelunky Classic.
Other
160 stars 26 forks source link

Gamepad controls broken after remap #19

Closed s1eve-mcdichae1 closed 2 years ago

s1eve-mcdichae1 commented 2 years ago

I am using the "1.1.7 Final - Android" release: https://github.com/yancharkin/SpelunkyClassicHD/releases/download/1.1.7/spelunky_classic_hd-android.apk

Running in RetroPie on Raspberry Pi 4 (Debian 10 Linux console, no desktop), using droidports/gmloader to run the game: https://github.com/JohnnyonFlame/droidports/commit/faf3970

I wish to swap the left & right face buttons. I can do this under "gamepad configuration" and it works for the duration of that session. However, after exiting & restarting the game, none of the buttons work. I can still move via D-pad, but none of the buttons respond at all. I can remap them again (using the keyboard to access the menu) and again they will work for the remainder of that session, but again they are unresponsive on next start.

Deleting gamepad.json restores the buttons' functionality but obviously in the default layout which is not what I want (it's a Logitech controller with standard Xbox layout -- I really feel like attack should be on "X" and switch be on "B" but default is the other way around.)

Any help? Even if you could just show me where the defaults are set so I could swap them in the code (and then if you could tell me how to compile it locally? I'm not sure how it goes from git repo -> Android apk.)

yancharkin commented 2 years ago

Looks like something goes wrong when saving the gamepad config (maybe because of gmloader).

Things you can try:

I have few more ideas if nothing above helps.

I can't remember where exactly defaults are set. It's not hard to find by searching for "gamepad.json" in GameMaker, which you need anyway to compile the game. But I'm do not recommend it, too much work, GM Studio 1.4 is obsolete, it's not easy to make everything to work as intended.

s1eve-mcdichae1 commented 2 years ago

Ah, so it looks like I'd have to set up a whole "developer environment" on my PC to compile this as an APK? That might be over my head, I think; I was hoping it was something I could do with a couple of terminal commands...

What do I do with an .AppImage? I made it executable and ran it, and got this:

pi@retropie:~/temp $ ./spelunky_classic_hd_html5-linux-armv7l.AppImage 
/tmp/.mount_spelunYq5oAd/spelunky_classic_hd_html5: error while loading shared libraries: libnss3.so: cannot open shared object file: No such file or directory

Is there something else I need to do, or does this just mean it don't work on my system?

The .apk version of the HTML5 version does not run in GMLoader:

pi@retropie:~/temp $ /opt/retropie/ports/gmloader/gmloader spelunky_classic_hd_html5-android.apk 
/home/pi/RetroPie-Setup/tmp/build/gmloader/platform/common/zip_util.c:66: Failed to stat file 'lib/armeabi-v7a/libyoyo.so'.
/home/pi/RetroPie-Setup/tmp/build/gmloader/ports/gmloader/main.c:73: Failed to acquire shared library, exiting.

This is my gamepad.json after mapping in-game:

pi@retropie:~ $ cat ~/.config/gmloader/spelunky_classic_hd_android/gamepad.json 
{ "joyPayVal": 32775, "joyJumpVal": 32769, "joyRunVal": 32775, "joyRopeVal": 32774, "joyAttackVal": 32771, "joyBombVal": 32773, "joyStartVal": 32778, "joyFlareVal": 32772, "joyItemVal": 32770 }

(#no newline at end of file)

Based on the table in this Reddit post, the values look mostly like what I've set (the ones I did set, anyway; it never asked me to define a "flare" button.) Except the "pay" value -- I pressed right-trigger but this has it set to left-trigger. In fact, anything I set to right-trigger, gets assigned as left-trigger instead (here in the .json, or even immediately going back into the config menu, it will say the button is "current: LT".)

I tried changing the "pay" value in the .json to "32776" which should be the correct value for right-trigger (and eliminate the duplication of 32775) -- now when I go into the config menu it does say "RT", but the buttons still don't work.

If I go into the menu and configure the gamepad, and press "Esc to keep same", the buttons don't work. But if I actually press the (same) buttons, they will work (for the duration of that session). If I then go back in and Esc through all of them, they still work with the mappings I had set previously (again, only for the session). When I exit the game I see that gamepad.json was re-written (timestamp is new) but with the same values it had prior.

yancharkin commented 2 years ago

I tried changing the "pay" value in the .json to "32776" which should be the correct value for right-trigger (and eliminate the duplication of 32775) -- now when I go into the config menu it does say "RT", but the buttons still don't work.

Well, in this case I don't see an easy way to fix this (maybe there is one I just don't see it). Gamepad and keyboard mappings can be different on Android and on Linux maybe that's why config messed up. Changing the default values and recompile the game probable most straightforward option. But that's TOO MUCH work. Also, you are using the Android executable on Linux, can't say that problems are unexpected :)

The better option is to try to make an HTML5 version work.

Is there something else I need to do, or does this just mean it don't work on my system?

sudo apt install libnss3

OR

s1eve-mcdichae1 commented 2 years ago

sudo apt install libnss3

Ah okay. So after I did this it was missing something else and when I added that, another thing. I ended up adding libnss3 libatk1.0-0 libatk-bridge-2.0-0 libgtk-3-0 and then it gave a segmentation fault :-S

OR

  • you can download and unpack this
  • install (if it is available in Debian's repo) or download electron (recent version should work, but the latest version tested with the game was 13)
  • run electron passing the path to the unpacked game as an argument, for example: electron ./spelunky_classic_hd_html5-electron_ready

I didn't see anything that looked right in apt list "*electron*" so I tried the download.

I had removed the installed libraries and it complained about libnss3.so again so I reinstalled them all, and got segmentation fault again, this time along with Missing X server or $DISPLAY.

So I set it up to run with XINIT:. I've not been able to grok exactly what this does "behind the scenes" in order to replicate it on command-line, but when run through RetroPie's runcommand.sh if you put XINIT: in front of a command (and have xorg installed), it loads the program in an X server window.

And it works! At least it loads and plays, and I can remap my controller and the changes will persist across play sessions. Initially, I had used the latest stable electron version 19.0.10; that did a thing where when you die, if I press "Start" instead of "X" it would lock up and I'd have to remote in and pkill electron to get control of my system back, but I tried it again in v13.6.9 and that issue disappeared.

I did have to select a 4:3 video mode to make it fill the screen vertically, which means I don't get the full widescreen experience. I suppose I could live with that, but unfortunately, it is also noticeably slower (gameplay) and less responsive (input lag) than the Android version...

These issues are not present in the Android version, but of course the remapping issue, is.

I suppose I'm probably going to stick with Android for the smoother gameplay, and just live with the backwards controls unless or until I work out how to compile it at home. I suppose the controls would be changed by swapping a couple of values in https://github.com/yancharkin/SpelunkyClassicHD/blob/master/scripts/configLoad.gml, yeah?

Would you reckon it's something'll take a couple hours to learn and set up, or am I looking at like a weekend project or longer? I can follow instructions, but I'm starting with zero knowledge. I started looking through the link you gave but it didn't take long before I became lost...

yancharkin commented 2 years ago

I suppose the controls would be changed by swapping a couple of values in https://github.com/yancharkin/SpelunkyClassicHD/blob/master/scripts/configLoad.gml, yeah?

That should do the trick. From line 26 to 34.

Would you reckon it's something'll take a couple hours to learn and set up, or am I looking at like a weekend project or longer?

I'd say probably at least a weekend. FYI: you need Windows (wine no good), Game Maker: Studio 1.4, an Android module for GM: S and full Android development environment. The worst thing is that GM: S is obsolete, so it can be very tricky to make everything work (that's one of the main reasons I'm no longer working on this project). Again, I do not recommend to do it, unless you have tons of free time and don't mind to spend it without getting any result. Also, there is almost no reason to learn how to use obsolete tool.

In my opinion, it is better to find another way to solve this problem. You can try to run the Linux x86 version with box86, it should be easier to compile. Or you can remap gamepad buttons with moltengampad or similar tool. While surely you can face some difficulties, usefulness of these tools not limited to one game.

s1eve-mcdichae1 commented 2 years ago

So, I found a hack. gmloader is using SDL input, and I already have the SDL controllermap utility on my system.

I ran controllermap, and just lied to it when I mapped the face buttons. Then I export SDL_GAMECONTROLLERCONFIG= with this (erroneous) value in the script that's used to launch the game.

It only works for this one controller and I'll have to redo the mapping if I ever use another one, but it works for now anyway.

Thanks for your help!

I'm sure there's a better place I can ask, but while I'm here, do you know anything about SDL and game controllers? Specifically I'm wondering if I can export more than one GAMECONTROLLERCONFIG at a time (perhaps by appending them one after another.) So that if I end up with multiple gamepads I could have them all configured all the time. Or if I really do have to reapply the mapping every time I switch.

yancharkin commented 2 years ago

So, I found a hack. gmloader is using SDL input, and I already have the SDL controllermap utility on my system.

Good idea.

Specifically I'm wondering if I can export more than one GAMECONTROLLERCONFIG at a time (perhaps by appending them one after another.)

Yeah, that's exactly how you do it. Example (also other info on this page can be useful, it's Arch Linux wiki, but most of it applies to any Linux flavor). As far as I remember, new line before each config not necessary, in some cases can be even harmful, better write everything in one line.

The downside of this method is that not every game uses SDL. For such games you can use xboxdrv, moltengamepad or antimicrox

s1eve-mcdichae1 commented 2 years ago

I think xboxdrv comes prepacked in RetroPie, too. I'll try to keep that in mind when something like this comes up again.

yancharkin commented 2 years ago

Ok, good luck!