emoose / re4-research

Various tools & modding research for Resident Evil 4
BSD 3-Clause "New" or "Revised" License
37 stars 4 forks source link

Unused code & other oddities #21

Open emoose opened 1 year ago

emoose commented 1 year ago

Some oddities I've come across looking through different RE4 builds/ports, been wanting to add to the RE4 TCRF page for a while but the only RE4 page there is marked GC only - almost all unused things in GC got carried forward to later ports though, GC seems to have very little unique to it, so not sure why it's marked like that.

Hopefully my request to move that page from a couple months ago might get answered eventually, until then I'll write whatever I find here to keep me from forgetting anything :smile_cat:

PSX / PlayStation SDK graphics code

For whatever reason the game includes a bunch of graphics functions with names taken straight from the PSX / PsyQ SDK, eg. ClearOTagR, DrawOTag - these names are unique to the PSX and aren't used by any other console / SDK. (TODO: IIRC there were a couple other PSX functions too)

These take the same parameters/structs as the PSX SDK functions did but don't actually use any PSX SDK code inside them, instead it seems some effort was made to emulate the behavior using Gamecubes GX functions.

Best guess is these were to help bring small parts of Capcom PSX code over to the new engine without too much work, or maybe these were added to make Capcom's PSX developers feel more at home working on the new system - alternately maybe some single component of the game (UI/Sound/FMV/Debug?) required these functions to work.

(or maybe the RE4/PN03 engine actually started back on PSX, and RE4 gamecube is just another port in disguise? who can say :P)

TODO: check with PN03 .MAP file and other symbol sources to find what object file these functions are compiled under, maybe the filename could reveal something more.

Unused rooms

Data for a bunch of unused rooms is included, Albert from RE4HD has made a great video documenting these here: https://www.youtube.com/watch?v=tyoy2NPmXcY (ENG subtitles can be enabled for non-Spanish speakers)

There's also code (but no data) for even more unused rooms under the R1XX/R2XX stage IDs - seems the code of these is mostly copied from other existing (and in-use) rooms, and since this unused code was only introduced with the PS2+ releases that included Separate Ways - which also copied from existing rooms - it's plausible these could be earlier versions of those Separate Ways duplicates. Maybe before they knew they could put Separate Ways as R5XX stages they were first added into the R1XX/R2XX code, and then forgotten to be removed after moving.

It's not known if these are any different, and without room data for them there's likely no chance of seeing any kind of visual differences neither - maybe copying the room data from the R1XX/R2XX stage it was duplicated from (or the R5XX SW duplicate) could let them be loaded in though, to see if they play any differently.

The PS2 release also contained mentions of rooms R021 thru R026, but without any early/debug PS2 builds available to check it's not known if any room data is actually available for these (oddly, the code for them was actually included with the 2007 SourceNext release though, but sadly still no room data: https://github.com/emoose/re4-research/issues/20)

BIO5 ESL enemy list

All the ESL enemy spawning lists are named as emleonXX.esl / omakeXX.esl in the games files, but PS2 symbols reveal that the code internally has an enum that associates those files with actual names:

typedef enum {
EM_LIST_FALSE = -1,
EM_LIST_ST1_0,
[..],
EM_LIST_BIO5,
EM_LIST_ADA,
} EM_LIST_KIND;

Of note there is EM_LIST_BIO5, which is associated with emleon09.esl - that ESL is pretty stripped down & boring in the UHD release, but the PS2 emleon09.esl actually contains spawns for enemies on the unused R7XX maps! (aka the maps that look very similar to RE5 in Albert's video above 🤔) https://github.com/emoose/re4-research/issues/18#issuecomment-1219630412 shows the map loaded with those enemy spawns in place.

The code that actually maps the R7XX stages to that ESL file is also only present on PS2 builds and later, likely meaning this was added sometime between the GC and PS2 release.

DebugTrg

Many room & event functions seem to have calls to a certain function, and appear to skip certain triggers depending on what that function returned - this func is named by debug symbols as DebugTrg, however in almost every build checked the function was empty with no code/implementation inside it (even inside debug builds), leaving it unknown how it was meant to work.

In 2022 speedrunners for the 2007 SourceNext port found that pressing a specific button combo at certain moments could allow them to skip sections of the game: https://www.speedrun.com/re4console/guide/43pbn Some digging into a non-DRM-protected version of 2007 showed that this was likely DebugTrg - SourceNext appears to be the only build available publicly that actually includes it. (more info at #20)

Thanks to this re4_tweaks can now optionally re-enable DebugTrg in the UHD version, along with including keyboard bindings for it & an on-screen message to indicate when the game is actively checking it, hopefully coming in useful for modders & others that need to test things quickly 🥳

Merchant "mood"

PS2 symbols for the Merchant class make mention of a m_friendship field, along with a Merchant::mood func & MOOD enum (with values for bad / normal / good).

Seems the m_friendship value is used to determine which MOOD the merchant is in, the mood is then used to pick a "ratio" from m_off_ratio_bad / m_off_ratio_normal / m_off_ratio_good, which gets stored inside m_reduction_ratio, which then gets used by Merchant::sellPrice to adjust the price.

m_friendship increases inside Merchant::buyup (presumably when buying items), but seems to get reduced inside Merchant::study (maybe the Buy XXX for YYY? screen) - study also seems to be the func that picks the ratio & updates m_reduction_ratio too.

However I couldn't see any info online about merchant sell prices ever being adjusted (besides upgraded weapons having price increased), seems everywhere pretty much just has a table of static item prices.

Maybe something is broken with this friendship system making the adjustment from m_reduction_ratio have no effect, or the m_off_ratio_XXX fields are maybe all set to zero for all the items.

E: ah, BIO4 EXE has noted this feature was present and actually functional in an earlier trial build: https://www.youtube.com/watch?v=hgOjF95DYeg&t=750s The build shown there seems to feature a very early merchant menu which displays an "ASK FOR DISCOUNT" option when purchasing - I've never seen any option like that in the final menus though unfortunately, so not sure how possible it'd be to reactivate in the final game... (wasn't able to contact them about this since my youtube comments keep disappearing, too bad)

Item ID oddities

RE4VR helpfully includes an enum associating all the item IDs with actual names, there's many entries inside there that don't seem usable though (due to piece_info entries being missing in the EXE for them they can't be displayed in inventory), not known if there's anything more to them besides the enum names.

See https://github.com/nipkownix/re4_tweaks/blob/15472c5dbb2810ce319b77c0d9f7e95d52a90ef0/dllmain/GameFlags.cpp#L905 for a cleaned-up enum list, ones marked "Wep"/"Item"/"Ammo" are available to add to inventory, some treasures are also listed there (which would also be able to be added), but then there are weird entries like Ruger_SA Mauser_ST New_Weapon_SC Ada_New_Weapon, which don't seem to be usable atm.

There's also two separate Wep: Punisher items which can be added to inventory fine, one marked FN70 and the other Item_40, not sure what kind of difference there is with them. (E: seems game code actually forces one of these to switch over to the other ID instead, only code of that type in the game, weird)

Item ID name changes

The RE4VR item ID names might be interesting for some since they appear to be internal names taken from the games source code, and so don't always match the names that actually get shown in game - this maybe reveals items that were renamed at some point, or even replaced entirely.

I don't have any list comparing internal with in-game yet, but you can check out the internal enum in re4_tweaks code here, and the friendly names we show in the item adder (which we've tried to make match with the names shown in-game) here.

Some examples, Piece_Of_Slate became Stone Tablet, Golden_Gem,Silver_Gem & Cupric_Gem became Lion Ornament, Goat Ornament & Serpent Ornament, Ore_White & Ore_Black became Velvet Blue & Spinel... The commit from @nipkownix renaming these items shows even more: https://github.com/nipkownix/re4_tweaks/pull/375/commits/6951f965807eb26459560a90a9848b791fcf35ea (note that the commit doesn't show all items that were renamed this way though, some items were renamed already in other commits, hopefully can make a proper comparison between internal<->in-game eventually)

Em06

GC debug build includes a single file related to Em06, Bio4.em06.sym, listing the function names inside the (sadly not included) em06.rel file.

The names seem to be formatted a lot differently to how other EmXX functions are named, with different capitalization & names like Em06_dm_ck, likely indicating this code is from earlier in development (or maybe is using REmake conventions): image Two functions of note are Em06BendBody and em06AlphaControl, implying this enemy could bend itself somehow, and maybe had some sort of transparency or invisibility effect to it.

UHD does also include an Em06.udas file, similar to Em09 below the TPL is empty though - however, it looks like UHD does have code that links the Em06.udas up with 00000006.pack ImagePack, which contains such textures: image

Looks like that could be the hunter enemy from REmake: https://oyster.ignimgs.com/wordpress/stg.ign.com/2012/08/2-Hunter.jpg?width=1280&fit=bounds&height=720&quality=20&dpr=0.05

Em09

AI code exists inside UHD for an unused Em09 enemy, though sadly with nothing calling into the prologEm09 function for it, making the code go completely unused.

The functions available for it can maybe give some ideas about it: image

Just like Em06 there is also an Em09.udas file shipped with UHD edition, again with an empty TPL, but unfortunately UHD doesn't seem to link this up to any ImagePack file, however assuming the filename is based on Em ID, there does seem to be a 00000009.pack file, which contains these textures: image

Maybe the Tyrant enemy that's also from REmake? https://www.evilresource.com/images/data/full/remake/tyrant.png?2a027f3f

... so the only thing stopping this Em09 Tyrant AI from being activated might just be a missing ImagePack link & call to Em09's prolog setup? Does anyone dare look further? 😄

Misc

Small miscellaneous things that seem to go unused:

emoose commented 1 year ago

E: clarifying some things I've seen mentioned about the unused RE4 Tyrant:


Had a play around changing some things with CE:

bio4_22-11-30_15-25-21-511-2.webm

To get that working using Cheat Engine:

Addrs are for 1.1.0 with relocations disabled

(E: a method of adding it properly instead of replacing an existing Em class is at https://github.com/emoose/re4-research/issues/22#issuecomment-1337763983, now to start trying to fix the broken AI actions...)

nipkownix commented 1 year ago

Wait, em09 is a Tyrant?! No way! This is incredible! @albertre4HD you gotta see this!

Would be amazing if we could add an option in re4_tweaks to randomly replace enemies with Tyrants or something like that.

emoose commented 1 year ago

Seems along with what's in that vid it also has a death anim too after enough hits, some reason handgun shots make a blood splatter effect but doesn't make it have any pain anim like the knife hit did in the video, weird. (does seem to have some wep ID checks in the damage code...)

Editing the code to use R1_Anger does let it start running toward you + swiping though, there's a bunch of places that need to be edited for that to work, but think it might be able to use R1_Anger without edits if some flag is set. At around 0x426DD3 it's checking player distance along with that flag, if the checks pass it sets R1_Anger (0x401), otherwise it uses R1_Walk (0x101) - R1_Anger itself also checks the same flag at 0x427181, goes back to R1_Walk if it's not set, or to R1_Dash_S if it is.

Not sure what's meant to set up that flag, wasn't able to find anything to set it in-game by attacking or anything, maybe that's something that's meant to be set by the room code? (haven't played REmake so not sure how it works there 😅) (E: oh em09RouteCk does set that flag if RouteCkToPos returns true - guess that's whether it's able to find a route to the player, not sure why it would have returned false there...)

Would be great if this could be setup to work as its own Em instead of needing to replace existing one, then could probably just change the Em ID inside the ESL/EM_LIST stuff to swap it with any enemy we like, will need to try looking more into how that Em loading stuff works...

E: seems once it gets into the R1_Walk state it's stuck there unless the player damages it, which can be seen in the vid too, attacking it puts it back into R1_Wait, which then checks if player is close enough to attack & uses R1_Harai / R1_Turn90_Harai if so.

Walk only has code to go back to Wait if player HP is 0, otherwise it just keeps walking, strange, maybe something was removed in there.

Mister-Curious commented 1 year ago

Would be great if this could be setup to work as its own Em instead of needing to replace existing one, then could probably just change the Em ID inside the ESL/EM_LIST stuff to swap it with any enemy we like, will need to try looking more into how that Em loading stuff works...

Great finds! Please let me know if you would like me to make any models with working TPL files for your experiments. I am eager to see if this can all be used, as I have been using these enemies for my mod, but had to replace certain enemies for them (using Verdugo for the Tyrant, and Novistadors for the Seekers).

albertre4HD commented 1 year ago

Ha! So it can be used after all! I found the textures but I thought it wasn't used em06 texture pack is a Hunter huhuhu image