nipkownix / re4_tweaks

Fixes and tweaks for the "UHD" port of Resident Evil 4
zlib License
342 stars 32 forks source link

[Feature Request] Weapon Hotkey #320

Closed Herlockes closed 1 year ago

Herlockes commented 2 years ago

Describe the feature you'd like to see added

In RE5 you can press a button to swap weapons easily. I'm sure this will not be so simple to add to RE4 because 1) different engine I think, 2) there's no weapon changing animation in RE4. However I believe people like me will be okay with weapon swapping even if there's no animation and it just changes immediately. It'd be a nice feature to enable/disable in the menu.

Also, again, it'd be pretty nice if we could play other characters than Leon (the mercs) in campaign. But something that's QoL like weapon switching with a button like RE5 is probably more widely desired.

linkthehylian commented 2 years ago

RE4 and 5 run on the same engine. I think RE4 is just running on a very early version of it.

A similar request was made back in May (https://github.com/nipkownix/re4_tweaks/issues/195) and it seems that attempting to do so causes issues.

Mister-Curious commented 2 years ago

I think this was accomplished by Raz0r with his trainer. Might not be impossible.

emoose commented 2 years ago

I looked into weapon swapping before in another github issue (linked by linkthehylian above), IIRC it's possible to change weapons while in-game without needing to open inventory fine, but the problem was that inventory itself wouldn't update, eg. you could switch from pistol to shotgun fine, but opening inventory would still show you holding pistol.

Seems the inventory system itself is kinda detached from the main game, would need to learn some more about how inventory itself works since not much has been done on it afaik.

RE4 and 5 run on the same engine. I think RE4 is just running on a very early version of it.

Eh I wouldn't really say that, it looks a little similar, but RE5 is using MT which wasn't around till 2006 or so, code is a lot different since MT was multi-thread focused while RE4 is pretty single-threaded (at least the GC ver), not sure if any of the file-formats are shared between them at all neither.

(my guess is maybe RE5 game-code & UI was started on RE4 engine, since we do have some evidence that RE5 levels were started there at least, but then they ported things over to MT once it was made stable on the 7th gen consoles, would explain why UI is still kinda similar to RE4, no idea how correct any of this might be though since I haven't really looked into RE5 that much)

--

E: seems that ItemMgr->arm(ItemMgr->search(weapon_id)) does let us update inventory, but still needs game updated separately via WeaponChange too...

Some reason not all weapons work with it though, id 45 & 138 seem to work fine, but some reason calling ItemMgr->search(38) returns NULL, even though equipping that weapon manually does set m_wep_id to 38... not sure what's up with that yet.

emoose commented 2 years ago

Looks like we could get the pointer to current selected item in inventory & store it somewhere, and then itemMgr->arm can use that pointer fine (even for the weapon mentioned above), so we could have a setup like "select weapon to bind in inventory, then press CTRL+1 to bind to 1", besides some small issues like needing to clear our saved pointers when item is removed (when game reloads / exits to menu / etc) that seems to update the equipped weapon in inventory fine.

Changing the actual in-game item is a problem though, I mentioned in the last thread that it only worked properly in main thread, looks like our pInput stuff is being ran from the render thread though, so calling WeaponChange from the hotkey press just crashes atm, will try looking into hooking the main thread soon, maybe can have it setup so hotkeys can have a OnlyOnMainThread bool attached to them.

Then there's the issue of players needing to bind the weapons themselves each time the items are reloaded, we could use ItemMgr->search to try binding some defaults (1 for pistols, 2 for rifle, etc), or maybe try storing the weapon IDs for the users binded weapons & then rebind automatically from that, but like mentioned above some weapons just refuse to be found via search, still dunno what's going on there.

E: oh hmm, seems that weapon 38 is actually handled with a cItem that has ID 37, which I guess is why search failed. We could easily grab the ID from selected item though, so maybe won't have to deal with all that pointer crap 😄

emoose commented 2 years ago

Alright, seem to have something working 😸

Here's a build if anyone wants to try it out: dinput8-weaponSwitch.zip (source code at https://github.com/emoose/re4_tweaks/commits/weapon-hotkeys)

The included readme explains how to use it:

To bind weapons to number buttons, select the weapon in inventory so that the "Equip / Examine / Discard" menu is showing for it, then press CTRL + [number] Number can be any number key from 1 to 5. Once they've been bound, exit out of inventory, and you should be able to use the numbers to quickly change weapons :) No idea if this might mess with anything, maybe changing during cutscene could have some fun effects, let me know if you find anything!

Tested with 1.1.0, not sure how it works in other versions. Only issue I've seen so far is that the player model in inventory doesn't update if you use hotkey on the inventory screen, exiting out & back in seems to fix it though, so not a huge deal.

I'll probably try making it so you can just press the number key 1-5 in the inventory without needing CTRL to bind it, just need to find a way to tell if inventory is open or not first... (and of course, allow a way for people to customize the hotkey for each slot too)

Also want to look into letting it bind the weapon without needing to be on "Equip/Examine/Discard" menu, so it'd just use whatever the actual highlighted weapon is, the inventory is a mess of C++ classes though so a little difficult to find the right pointers etc for it :/

Might also try looking into adding defaults for this too, so eg 1 would be bound to any available pistols, 2 for shotguns, 3 for rifle, etc.. Need to find all the weapon IDs for each weapon first though, if anyone wants to try looking into that you can view the weapon ID from the Globals window (re4_tweaks menu -> Trainer -> Globals), the value listed as itemPiece pItem.id should be the correct ID, value will get updated whenever you open the Equip/Examine/Discard menu for the weapon.

linkthehylian commented 2 years ago

Just got done testing. Both 1.0.6 and 1.1.0 seem to work fine.

I did notice that whenever you change weapons while running it halts Leon for a split second. I wonder if there could be a workaround for that.

https://user-images.githubusercontent.com/20933012/186006856-d7609be3-a99f-4eec-96df-1404ccd3db8a.mp4

Need to find all the weapon IDs for each weapon first though, if anyone wants to try looking into that you can view the weapon ID from the Globals window (re4_tweaks menu -> Trainer -> Globals), the value listed as itemPiece pItem.id should be the correct ID, value will get updated whenever you open the Equip/Examine/Discard menu for the weapon.

Noted! I'll have a list ready asap.

linkthehylian commented 2 years ago

Handgun - 35 Red9 - 37 Punisher - 33 Blacktail - 39 Matilda - 3 Broken Butterfly - 41 Killer7 - 42 Handcannon - 55 Shotgun - 44 Striker - 45 Riot Gun - 148 Rifle - 46 Rifle (semi-auto) - 47 TMP - 48 Mine Thrower - 54 Chicago Typewriter - 52 Rocket Launcher - 53 Infinite Launcher - 109 P.R.L. 412 - 65 Rocket Launcher (Special) - 23 Hand Grenade - 1 Incendiary Grenade - 2 Flash Grenade - 14 Chicken Egg - 8 Brown Chicken Egg - 9 Gold Chicken Egg - 10

Here's everything! If I missed any, please let me know! 😄

emoose commented 2 years ago

Nice, thanks for the help! I'll try looking into setting up defaults soon, hopefully can get it cycling through different weps of the same type...

Found how to check if inventory is showing, and also use highlighted item instead of needing to open up the Equip/Examine/Discard menu, new build is here: dinput8-weaponSwitch-v2.zip

To bind weapons to number keys, highlight the weapon in your inventory and press a number key to bind to (1-5), you will switch to the weapon automatically if binding was successful. Once you've bound them as you want, exit out of inventory, and you should be able to use the numbers to quickly change weapons :) No idea if this might mess with anything, maybe changing during cutscene could have some fun effects, let me know if you find anything!

I'll try getting it reading/writing to the trainer.ini soon too, and hopefully merge it into the main trainer branch.

emoose commented 2 years ago

Think I've got weapon cycling to work, along with INI reading/writing, hopefully no off-by-one issues or anything like that.. seems to be working fine for me at least, but haven't tried with that many different weapons yet.

New build: dinput8-weaponSwitch-v3.zip

By default number keys will be bound to weapons by different groups 1 will cycle between any available pistols 2 will cycle between shotguns 3 will cycle between rifles/machine guns 4 will cycle between rocket/mine launchers 5 will cycle between grenades/throwables

To bind your own weapon to number keys, highlight the weapon in your inventory and press a number key to bind to (1-5), you will switch to the weapon automatically if binding was successful - the trainer.ini file will also be updated with the new weapon binding.

Once you've bound them as you want, exit out of inventory, and you should be able to use the numbers to quickly change weapons :)

No idea if this might mess with anything, maybe changing during cutscene could have some fun effects, let me know if you find anything!

albertre4HD commented 2 years ago

Wow! It's insane, haha It works really well :D Cutscene's weapons are entirely different weapons stored inside the EVD files, so, there's no interaction between cutscenes and weapon data. But you can change the weapon during the cutscene/room transition/etc. So, when the cutscene is over, the weapon associated to the number will already be equipped.

EDIT: I've just downloaded version 3... I'm speechless with all the trainer/debug UI stuff ... --and everything else-- you've added. I'm feeling like a kid with a new toy!! XD

nipkownix commented 2 years ago

Seems to be working nicely here. Amazing work!

Would be nice if we could trigger some animation when changing weapons, to mask the change a bit. Maybe playing the "ready" animation for a second or something. Hmm.

emoose commented 2 years ago

Sweet, glad to hear it's working fine, I'll try seeing if I can get it pushed to the main trainer branch in a little bit, can probably add some UI stuff to let the hotkeys be rebinded as well.

E: should be merged into trainer PR now

albertre4HD commented 2 years ago

Oh, even the slow-motion mode that was available in the debug trial edition is here! image

nipkownix commented 2 years ago

Oh, so the slow mo thing was actually used for something in a trial version? Interesting. We could probably fix it up so it doesn't stretch the image, but I don't think it would be useful for anything :p

albertre4HD commented 2 years ago

I think some people speculated this slow-motion effect with this blueish motion blur was a leftover effecr from 3.5 or something like that... but it's been a loooong time since I read that and they could be wrong (Or I simply don't recall it correctly XDD)

emoose commented 2 years ago

Hmm, only time I ever saw that effect was in this video of a debug build: https://youtu.be/BYW1NxIdDrw?t=10

Looks like it's meant to activate when enemy throws something, and makes Leon crouch & dodge in slow-mo, maybe something meant for easy difficulty (also note the green bar at the top decreases in slow-mo and slowly refills outside it, guess it eventually runs out)

Not sure if that's the public GC debug build or maybe some earlier one though, doesn't look like he explained how that was enabled neither... he does mention it's "only working in that area" though, if it is the GC debug I guess it's not disc 1 since I never saw any other videos about it, any chance someone knows what room that is?

linkthehylian commented 2 years ago

Hmm, only time I ever saw that effect was in this video of a debug build: https://youtu.be/BYW1NxIdDrw?t=10

any chance someone knows what room that is?

Looks like the area right after you kill Verdugo. Area Jump shows it as R223 - Mine Shaft.

Herlockes commented 2 years ago

Think I've got weapon cycling to work, along with INI reading/writing, hopefully no off-by-one issues or anything like that.. seems to be working fine for me at least, but haven't tried with that many different weapons yet.

New build: dinput8-weaponSwitch-v3.zip

By default number keys will be bound to weapons by different groups 1 will cycle between any available pistols 2 will cycle between shotguns 3 will cycle between rifles/machine guns 4 will cycle between rocket/mine launchers 5 will cycle between grenades/throwables

To bind your own weapon to number keys, highlight the weapon in your inventory and press a number key to bind to (1-5), you will switch to the weapon automatically if binding was successful - the trainer.ini file will also be updated with the new weapon binding.

Once you've bound them as you want, exit out of inventory, and you should be able to use the numbers to quickly change weapons :)

No idea if this might mess with anything, maybe changing during cutscene could have some fun effects, let me know if you find anything!

Works like a charm, and the default way it's set up by setting different weapon types to cycle on each button is really intuitive. But there's only one problem, it's really common to use a heavier weapon then want to go back to the regular handgun. But if I switch to the handgun by pressing 1, it'll continue cycling where it left off. So for example if I have a red9, Broken Butterfly, and a Handcannon. Let's say I was using the Red9 then swapped to a Shotgun for an enemy. If I try to switch back to my pistol, it'll simply go straight to the BB. In a regular playthrough it might cause the player, in a tense fight, to accidentally waste precious magnum ammo when they're only trying to shoot a fast pistol round.

Basically, would it be possible to make it remember the last weapon used in that slot? Also maybe leave 1-5 for weapons and make F a button for cycling through nades.

E: Noticed two things. While aiming and switching through different handguns by rapidly pressing the button, the game crashed. Also, if you start a reload animation and swap weapons then switch back the gun is fully reloaded effectively making a way to skip the animation. Perhaps it would be possible to make the hotkey inactive until the reload animation is over?

nipkownix commented 2 years ago

it's really common to use a heavier weapon then want to go back to the regular handgun. But if I switch to the handgun by pressing 1, it'll continue cycling where it left off. So for example if I have a red9, Broken Butterfly, and a Handcannon. Let's say I was using the Red9 then swapped to a Shotgun for an enemy. If I try to switch back to my pistol, it'll simply go straight to the BB.

Basically, would it be possible to make it remember the last weapon used in that slot?

I think Half-Life 2's approach to this is the best solution: a hotkey to switch to the last used weapon. Here's a build with it added: ~dinput8.zip~

I really wanted to make Q the default for this, but the game already uses it for something else. Grr.

Edit:

Also, if you start a reload animation and swap weapons then switch back the gun is fully reloaded effectively making a way to skip the animation. Perhaps it would be possible to make the hotkey inactive until the reload animation is over?

New build only allows using the hotkey when the player isn't reloading or shooting: dinput8.zip

Herlockes commented 2 years ago

I really wanted to make Q the default for this, but the game already uses it for something else. Grr.

What button did you end up going with? I can't tell what I'm supposed to press

nipkownix commented 2 years ago

The button is in the "hotkey" section in the trainer tab. Default is C. Let me know if you think we should go with another button as the default.

albertre4HD commented 2 years ago

I've noticed I can't reload anymore with the controller with the newest dll O_o (only when the weapon is empty, of course) I've replaced it with the previous version I had and the issue is gone... I'm the only one with this problem? XD

nipkownix commented 2 years ago

Do you have "AllowReloadWithoutAiming" enabled? that changes the default reload button for controlllers. It is off by default, though.

albertre4HD commented 2 years ago

I had to activate it in order to be able to reload again. But I'm using a customized input.ini and my run/reload button is X

emoose commented 2 years ago

But there's only one problem, it's really common to use a heavier weapon then want to go back to the regular handgun. But if I switch to the handgun by pressing 1, it'll continue cycling where it left off. So for example if I have a red9, Broken Butterfly, and a Handcannon. Let's say I was using the Red9 then swapped to a Shotgun for an enemy. If I try to switch back to my pistol, it'll simply go straight to the BB.

Ah yeah good point, it should probably only cycle if the weapon you're holding is in the same cycle-slot as the hotkey you pressed, else if you're switching slots then it'll use whatever the weapon was that you already had in that slot - unless that weapon isn't available anymore, in that case then it should try next weapon in cycle etc... will try looking into it soon.

E: got something working for it, haven't tested it too much yet, but seems to remember the slots previous position fine now, and if the wep for that position is no longer in inventory it'll skip to next available wep for that slot too (might be nice if we could add an ammo check to that...)

Build can be found at https://github.com/nipkownix/re4_tweaks/suites/7951981477/artifacts/339563607

albertre4HD commented 2 years ago

Hello! I think I've found a bug. When you take an item and I "Alt+TAB" the game while the item is rotating in the middle of the screen (game paused), the game crashes when I come back to the game. Here's the crash file: bio4.exe.20220824184120.zip

linkthehylian commented 2 years ago

Managed to reproduce the crash that Albert explained above. It seems to only happen when fullscreen is enabled. bio4.exe.20220825011110.zip

Herlockes commented 2 years ago

But there's only one problem, it's really common to use a heavier weapon then want to go back to the regular handgun. But if I switch to the handgun by pressing 1, it'll continue cycling where it left off. So for example if I have a red9, Broken Butterfly, and a Handcannon. Let's say I was using the Red9 then swapped to a Shotgun for an enemy. If I try to switch back to my pistol, it'll simply go straight to the BB.

Ah yeah good point, it should probably only cycle if the weapon you're holding is in the same cycle-slot as the hotkey you pressed, else if you're switching slots then it'll use whatever the weapon was that you already had in that slot - unless that weapon isn't available anymore, in that case then it should try next weapon in cycle etc... will try looking into it soon.

E: got something working for it, haven't tested it too much yet, but seems to remember the slots previous position fine now, and if the wep for that position is no longer in inventory it'll skip to next available wep for that slot too (might be nice if we could add an ammo check to that...)

Build can be found at https://github.com/nipkownix/re4_tweaks/suites/7951981477/artifacts/339563607

After using this, I can't hear any sound effects from Leon climbing up a ladder, or jumping across ledges. However the weapon swapping functions as intended.

nipkownix commented 2 years ago

Managed to reproduce the crash that Albert explained above. It seems to only happen when fullscreen is enabled.

Ah, if it only crashes when you Alt+Tab with full screen enabled, then it is probably triggered by IDirect3DDevice9::Reset. Might not be related to this hotkeys feature after all.

Edit: Ah, lol, it is caused by RestorePickupTransparency. We finally figured out why QLOC disabled it: They couldn't/didn't bother fixing this crash. Pffff.

emoose commented 2 years ago

After using this, I can't hear any sound effects from Leon climbing up a ladder, or jumping across ledges. However the weapon swapping functions as intended.

Hmm that's weird, don't think this should be changing anything around the volumes, have you checked the audio section of re4_tweaks menu to see if everything is still turned up?

Did recently change some of the code around volume stuff in the main branch though, maybe that's affecting something here, could you see if the build at https://github.com/nipkownix/re4_tweaks/suites/7983040787/artifacts/341675962 also has volume issues for you? (that won't have the weapon hotkeys included, but does have the slightly changed audio code)

Edit: Ah, lol, it is caused by RestorePickupTransparency. We finally figured out why QLOC disabled it: They couldn't/didn't bother fixing this crash. Pffff.

Isn't the X360 port also missing transparency? Maybe X360 had a similar problem when the guide menu was brought up or something like that.

IIRC D3D9Ex usually helps improve alt-tabbing in most games that have option for it, guess it probably handles device resetting differently, will have to try digging up the code for that again. (can't actually find any good sources for everything D3D9Ex changes, just a document about what Win7 added to it, seems MS doesn't like keeping D3D9 docs available ;_;)

E: Ah https://docs.microsoft.com/en-gb/windows/win32/direct3d9/dx9lh does go over 9Ex a bit, mentions about how device-loss is handled differently:

In previous versions of DirectX, when an application experienced a mode change, the only way to recover was to reset the device and re-create all video memory resources and swap chains. Now with DirectX for Windows Vista, calling Reset after a mode change does not cause texture memory surfaces, textures and state information to be lost and these resources do not need to be recreated.

I'd guess that might be able to help with the issue here, of course would be better if we could maybe find a way to skip the pickup transparency stuff during alt-tab instead though...

Also wonder if dxvk might handle it any better? IIRC that did help with some performance issues.

Might not be related to this hotkeys feature after all.

Yeah probably not, made a new issue page to track it here: https://github.com/nipkownix/re4_tweaks/issues/324

Herlockes commented 2 years ago

Hmm that's weird, don't think this should be changing anything around the volumes, have you checked the audio section of re4_tweaks menu to see if everything is still turned up?

Did recently change some of the code around volume stuff in the main branch though, maybe that's affecting something here, could you see if the build at https://github.com/nipkownix/re4_tweaks/suites/7983040787/artifacts/341675962 also has volume issues for you? (that won't have the weapon hotkeys included, but does have the slightly changed audio code)

Turns out I had something messed up in my sound settings. But I might be imagining it, if someone else could test ladder sound effects I'd appreciate it to know if I am or not.

There's also an issue with the weapon hotkey, I was swapping weapons as the bingo cutscene was about to start, and it caused a crash. I didn't mean to time it like that, it just happened at the same time. Another thing is, if you use a handgun with a silencer, swapping back to it will sometimes result in a handgun with the silencer unequipped, meaning you'll have to re-equip it.

pas-de-2 commented 1 year ago

Built the latest weapon-hotkeys branch dll. If I have AllowReloadWithoutAiming enabled under Keyboard, but not under Controller, I can no longer reload with a gamepad. If I enable AllowReloadWithoutAiming under both Keyboard and Controller, I can.

EDIT: Oh, seems this was fixed by https://github.com/nipkownix/re4_tweaks/commit/5a1646fcdf4f2ed12237aab947db59788f605999, just had to pull that in.

emoose commented 1 year ago

@pas-de-2 the weapon-hotkeys stuff was added into the trainer branch, mostly been working on it over there now, probably should have mentioned that here...

That branch can be found at https://github.com/nipkownix/re4_tweaks/pull/312 / https://github.com/emoose/re4_tweaks/tree/debugwindow-ui

nipkownix commented 1 year ago

weapon-hotkeys are now merged, so I'll close this. Feel free to open a new issue if there's any problem related to it.