emoose / re4-research

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

Working Em09 / Tyrant code & data #22

Open emoose opened 1 year ago

emoose commented 1 year ago

As discussed at #21, seems Em09 actually has working code/data in the game, a video of it & instructions to make it spawn (replacing the Em2d Novistadors) can be found at https://github.com/emoose/re4-research/issues/21#issuecomment-1332362257

Unfortunately it does have some issues though:

The code responsible for setting it as Anger can be seen here:

    if ( pEm->l_pl_378 >= 2250000.0 )           // if player dist is greater than or equals 2250000
    {
      if ( pEm->l_pl_378 <= 2250000.0 )         // and dist is less than or equals 2250000??
      {
        if ( pEm->l_pl_378 > 25000000.0 && (pEm->flags_408 & 1) != 0 ) // and dist is more than 25000000 ??
          *(_DWORD *)&pEm->r_no_0_FC = 0x401;   // set R1_Anger
      }
      else
      {
        *(_DWORD *)&pEm->r_no_0_FC = 0x101;     // set R1_Walk
      }
    }
    else if ( pEm->field_5E8 >= 0.7853981852531433 ) // rotation related?
    {
      *(_DWORD *)&pEm->r_no_0_FC = 0x901;       // set R1_Turn90_Harai (attack)
    }
    else
    {
      *(_DWORD *)&pEm->r_no_0_FC = 0x801;       // set R1_Harai (attack)
    }

I think the main breakage there is the less than/equals line if ( pEm->l_pl_378 <= 2250000.0 ), with that removed the code seems to make much more sense, but maybe there is a reason for that check being there, could be meant to check against a larger distance to limit how far it allows activating Anger or something.

Unfortunately the way those checks were actually assembled into x87 instructions makes it hard to change one without also changing the other, will probably need to hook something there instead.


E: figured out a way to get it to work as Em09 without needing too many patches, unfortunately that brings a big issue with it though: a lot of the code like GetWepTargetList2 only checks for/returns Ems that use id 0x10 or above, and there's a big switch statement there which would be hard to add Em09 to... guess it could maybe be worked around by temporarily overriding the ID to a different one if it was 09.

No idea how many other parts of the code might only allow certain Ems too though, right now the Tyrants spawned as Em09 can't be damaged at all, even with knife, and bullets just go through them :/

Might end up easier to replace certain Em number with 09 instead, maybe could add an INI setting that lets modders pick which Em to overwrite.

emoose commented 1 year ago

Alright, got Em09 spawning & receiving damage fine as its own separate Em09 now (rather than replacing any existing Em class), and was even able to pattern-match for most of it too - unfortunately not sure if prologEm09 is able to be pattern searched though, seeing as nothing calls it and it normally went unused, and the func itself matches almost every other prologEmXX function too...

Was thinking of working back from the cEm09 class and find the func that inits that, then from there find the prolog func that calls that, but since the j_ thunk functions between those calls use relative jumps I'm not so sure that can actually be searched very easily... might just have to include a table of the prologEm09 addrs for each game version, but any ideas about that would be welcomed.

(E: ah, looks like prologEm09 is actually the first prologEmXX func in the EXE, so it's not too hard to find actually, updated the code below to search it - seems to work fine on 1.1.0, need to check other versions.)

Here's what I got so far, added to ModExpansion.cpp atm:

struct OSLinkData_mb
{
    uint32_t rel_filetbl_no_0;
    void(__cdecl* prolog_4)();
    void(__cdecl* epilog_8)();
    void(__cdecl* unresolved_C)();
};
#define OSLINKDATA_ORIG_COUNT 75
OSLinkData_mb g_OSLinkData_Em_Extended[OSLINKDATA_ORIG_COUNT + 1];

BOOL(__fastcall* cEmMgr__construct)(cEmMgr* thisptr, void* unused, cEm* pEm, uint32_t id);
BOOL __fastcall cEmMgr__construct_Hook(cEmMgr* thisptr, void* unused, cEm* pEm, uint32_t id)
{
    BOOL ret = cEmMgr__construct(thisptr, unused, pEm, id);

    // Make Em09 pretend to be Em39 instead, see "Em09 fixing" comments below for why
    if (pEm->id_100 == 9)
        pEm->id_100 = 0x39;

    return ret;
}

void re4t::init::ModExpansion()
{
[...]
    // Em09 enabling: code & data exists for the Em09 / Tyrant enemy from REmake, code seems to be setup to call into the proper RE4-engine functions fine(!)
    // Unfortunately what doesn't exist is any link for the actual Em id 09 to call into the Em09 code that's available for it
    // Main things missing for it to work:
    // - EmFileTbl defines the link between the ID & the Rel/Dat file number to use (number from there then gets looked up in the FileTbl array)
    //   Em06 - Em0c are setup with the Rel/Dat IDs for Em10, for whatever reason, maybe as placeholders
    //   Would need to change the EmFileTbl[9].Rel/.Dat to point to Em09 entries inside FileTbl, but unfortunately...
    //
    // - FileTbl doesn't contain any entry for the Em09 Rel/Dat
    //   Not a huge deal though, since luckily it does include unused Em06 Rel/Dat entries, which can be easily overwritten
    //
    // - Func that associates DAS files with imagepacks needs updating, would normally set em06.das to use imagepack 6, can just set it to imagepack 9
    //
    // - g_OSLinkData_Em array links Rel IDs up to the actual prolog/epilog/"unresolved" functions
    //   (those are normally loaded/ran from the Rel itself, but UHD merged all the Rel files into the main EXE, so this is how those merged-in functions get mapped)
    //   Sadly there's no Em09 mapping defined there though, and even worse all the mappings that are defined seem to all be for things that are actually used
    //   (with no spare room at the end of it neither, there is one blanked out entry, but seems to be used by the code to signal the end of the array, so can't be overwritten)
    //   Would need to make a copy of the existing array into our own array that has extra space for the new entry
    //
    // ... and hopefully that's it! Then can just edit ESL to use Em id 09 and hopefully it should spawn in fine

    // First let's find the FileTbl:
    struct FileTblEntry
    {
        const char* path;
        int dvdEntryNum;
    };
    pattern = hook::pattern("0F B7 D0 8B 04 D5 ? ? ? ?");
    FileTblEntry* FileTbl = (FileTblEntry*)(*pattern.count(1).get(0).get<uint8_t*>(6) - 4);
    // Patch path inside entries for em06.das/em06.rel to use em09.das/em09.rel instead
    auto& entryDas = FileTbl[0x1C];
    auto& entryRel = FileTbl[0x1D];
    Patch(entryDas.path + 6, '9');
    Patch(entryRel.path + 7, '9');

    // Locate EmFileTbl and patch the Em09 entry to point to the FileTbl entries above
    // TODO: seems each playable char has it's own EmFileTbl for whatever reason, would need to patch those too...
    struct EMD_READ_SET
    {
        uint16_t Dat;
        uint16_t Rel;
        uint16_t LowDat;
        uint16_t Dll;
    };
    pattern = hook::pattern("8D 04 CD ? ? ? ? 89 85 ? ? ? ? 8B 8D ? ? ? ?");
    EMD_READ_SET* EmFileTbl = *pattern.count(1).get(0).get<EMD_READ_SET*>(3);
    EmFileTbl[9].Dat = 0x1C;
    EmFileTbl[9].Rel = 0x1D;

    // Patch func that sets up FileTbl <-> ImagePack mappings, change em06.das = 6 to em09.das = 9
    pattern = hook::pattern("01 C7 05 ? ? ? ? 06 00 00 00 C7 05");
    Patch(pattern.count(1).get(0).get<uint32_t>(7), uint32_t(9));

    // Patch OSLinkData pointer to point to our own array & copy data for it over
    pattern = hook::pattern("8B 45 10 8B 4D 14 C7 45 F0 ? ? ? ?");
    OSLinkData_mb** g_OSLinkData_Em_ptr = pattern.count(1).get(0).get<OSLinkData_mb*>(9);

    // Copy orig data to our extended array
    std::copy_n(*g_OSLinkData_Em_ptr, OSLINKDATA_ORIG_COUNT, g_OSLinkData_Em_Extended);

    // Locate the unused prologEm09 func, easier said than done since nothing ever calls it, and almost all prologEmXX funcs share the same instructions...
    // Fortunately prologEm09 appears to always be the first instance of a prologEmXX func, so we can just search for the prologEmXX pattern and use first result
    pattern = hook::pattern("C7 05 ? ? ? ? ? ? ? ? C3");
    void* prologEm09 = pattern.count(1).get(0).get<uint8_t>(0);

    // Set up the g_OSLinkData entry for Em09
    g_OSLinkData_Em_Extended[74].rel_filetbl_no_0 = 0x1D;
    g_OSLinkData_Em_Extended[74].prolog_4 = (void(*)())prologEm09;
    g_OSLinkData_Em_Extended[74].epilog_8 = g_OSLinkData_Em_Extended[0].epilog_8; // nullsub from [0]
    g_OSLinkData_Em_Extended[74].unresolved_C = g_OSLinkData_Em_Extended[0].epilog_8; // nullsub from [0]

    // End-of-records indicator
    g_OSLinkData_Em_Extended[75] = { 0 };

    // Patch game to use the extended array
    Patch(g_OSLinkData_Em_ptr, &g_OSLinkData_Em_Extended);

    // Em09 fixing: of course enabling & spawning it is only the first step, there's also some issues with the Em itself that need to be fixed.
    // The above lets it spawn in fine, but none of the targeting/hit detection code actually responds to it
    // Seems the detection code checks what Em ID it is and only allows certain IDs to be hit, with ID 9 left out of all those checks...
    // Rather than trying to find & update each of them, we can overwrite the instances cEm::id_100 field to an Em which is known to work
    // (fooling those checks into thinking it's a different Em, while it still runs the Em09 code)
    // 
    // The question is which Em should it masquerade as - some rooms do perform searches for certain Ems and then call functions on them
    // eg. r205 searches for Em2d and tries calling a vtable func on it, which Em09 wouldn't contain, causing a crash...
    // Em10 also seems to crash for some reason, but Em39 appears to work fine, so we'll go with that for now, until someone eventually finds a room that breaks it...

    // Unfortunately easiest way to handle this is hooking cEmMgr::construct, which is only referenced in the cEmMgr vftable, ugh
    // Need to find offset for the vftable and grab addr for construct from it
    // Kinda ugly method which grabs the vftable from the static EmMgr instance
    pattern = hook::pattern("? ? ? ? 00 00 00 00 00 00 00 00 08 0E 00 00 02");
    uint32_t* cEmMgr_vftable = *pattern.count(1).get(0).get<uint32_t*>(0);
    uint32_t cEmMgr_construct_thunk = cEmMgr_vftable[6];
    ReadCall(cEmMgr_construct_thunk, cEmMgr__construct);
    InjectHook(cEmMgr_construct_thunk, cEmMgr__construct_Hook, PATCH_JUMP);
}

With this in place just make sure EnableModExpansion is set inside dinput8.ini, and edit one of the ESLs to spawn Em 09 somewhere, and you should be good to go. Here's an edited emleon03.esl, should spawn it on r205 like the earlier method did: emleon03.zip

nipkownix commented 1 year ago

Very nice work!

About prologEm09, you can pattern scan the address to it by scanning the thunk above it (j_cObj16__clearLostWait), and then adding 0x5 to the address. Just tested it here and it seems to work fine:

auto pattern = hook::pattern("E8 ? ? ? ? 8B 86 ? ? ? ? 0F B6 8E ? ? ? ? 6A ? 50 51 6A ? E8");
con.AddLogHex(injector::GetBranchDestination(pattern.count(1).get(0).get<uint32_t>(0)).as_int() + 0x5);

Edit: Ah, just saw your edit lol This should still work as a backup if needed, though.

emoose commented 1 year ago

Some fixups for the main AI issues, should be able to attack when it gets within melee range now without needing to be attacked first, and being too far from the Em will also put it into R1_Anger: (E: moved to the new branch mentioned below)

Maybe will make a new branch with this soon so we can get builds out for people that wanna test.

emoose commented 1 year ago

Pushed what I got so far to em09 branch: https://github.com/nipkownix/re4_tweaks/tree/em09

Artifact builds for that can be found at https://github.com/nipkownix/re4_tweaks/actions?query=branch%3Aem09

You can replace most of the Novistadors on r205 with Em09 instead with the ESL from https://github.com/emoose/re4-research/files/10134211/emleon03.zip (extract to BIO4/Etc/ folder, and rename/delete the existing emleon03.esl.lfs)

Make sure to set EnableModExpansion = true in your dinput8.ini for the Em09 patches to take effect too!

One big issue I'm not sure how to deal with atm is the sounds for the enemy, kinda seems like it might be using the Em's id_100 value (09 in this case) as a sound index into some SND file or the XACT data (with Em09 set on r205 it starts playing some creepy/action bgm, from another map I guess, might need to add some hooks to sound code to make it use a different ID, hopefully we can borrow some sounds from another Em or something...)

Don't really know too much how the sound stuff works for enemies though, would welcome any info about that if anyone knows more.

E: ah, the BGM sound that gets played is the music that plays when novistadors become aware of you, not sure why Em09 is making it play it straight away though, it didn't happen with the older em2d->em09 method at least, will need to figure out what makes that BGM start playing I guess. BTW if anyone has any suggestion what Em's sounds would be a good fit for tyrant let me know (Verdugo maybe?)

(E2: seems to be getting enabled by r205_StrCheck, that func uses SceCkFindPL that ends up calling cEmWrap::ckFindPL to check if Em can find player, which is the func I had to patch with the older method, so guess that patch might have stopped it playing with the older method then? - not completely sure why this FindPL stuff is making Em09 always aware of the player though, kinda looks like cEmWrap::ckFindPL maybe defaults to always being aware except for certain Ems: Em10-18, Em2d, Em36...))

E2: the health & damage values for it could probably use some tweaking as well, does ESL maybe let you adjust health when spawning them? I saw some people on twitter mention that the damage from it seemed low (though it is still able to kill you in like 4/5 hits on normal...) Guess this should probably be treated more as a boss enemy than a common one, so maybe will look into the damage data for some other boss Ems and try tweaking the damage here to be more in line with those.

Mister-Curious commented 1 year ago

I'm not sure what's going on here . I spawn this with ESL flags 01 09 00, There is no modded files, just vanilla em09.udas.lfs

https://www.youtube.com/watch?v=mmPKrhE09t0

It appears there is some symmetry with the player bones and the enemy.

emoose commented 1 year ago

Huh that's weird, are you able to check your EXE on r205 with the ESL I posted? Wonder if it's something up with the ESL entry you showed on discord, there is stuff in ESL like "emset_no" that might be set (which I don't really know purpose of), or maybe something like rotation angle is messing it up somehow.

Also I'm guessing you're using 1.0.6 right? It seemed to work on 1.0.6 for me, but I only tested 1.0.6 EXE with 1.1.0 data files, maybe the em09.udas.lfs that came with 1.0.6 could be messed up somehow, could try backing up your existing one and see if this works any better: em09.udas.zip

Besides those only other thing I can think of is maybe another mod there is conflicting with it somehow, IIRC someone did post on discord a little while ago about modded player affecting bones on some stage object (water-wheel I think?), maybe tyrant model doesn't like modded player model for some reason.

Mister-Curious commented 1 year ago

Ok to answer a few questions:

I think the issue might be that it is spawning a Tyrant instead of a Novistador.

emoose commented 1 year ago

The ESL should be changing most of the Em2d/Novistadors to Em09/Tyrant in the sewers, so that's fine, you still get the bugs with the sewer tyrants though?

Not really sure what could be breaking it like that, I'd guess it's down to some incompatibility somewhere... are you using any custom weapon model maybe? If you have a vanilla version of the game maybe worth trying that, could be a graphics driver issue for all we know.

The newest re4_tweaks builds do change renderer from DX9 to Vulkan too, I guess it could possibly cause something like that, setting UseVulkanRenderer = False in the INI can disable it if you want to try with the normal DX9 renderer (probably a slim chance this would be the cause though..)

E: also, are you using companion DLL or any other thing with it too? I haven't tried testing with that yet, we did have some problems with companion overwriting things we patched in the past though.

Mister-Curious commented 1 year ago

Thanks for the help here. I put in ALL vanilla game files, but kept Companion DLL. Issue persists Removed the Companion DLL and it works fine. I don't think I can do much more testing without the Companion DLL, though as my test rooms are all reliant on that DLL. Kteo might be able to help with the sound stuff as he doesn't use the Companion DLL AFAIK.

Edit - I did try to narrow it down though. Removing the 'FILES' folder for companion and that did not do anything. REmoving the .cfg file also had no effect. Same weird distorted model.

Cheers

emoose commented 1 year ago

Ah right, well good to know where the problem might be coming from at least. I did have a quick test with companion after posting but wasn't able to get the same result as you, guess it might be something in companion that has to be enabled first?

IIRC that does have some side-loading features doesn't it? Maybe whatever method they use for that is causing problems for how we're making the game load from em09 - could be overwriting the patched "em09.das" string we use maybe...

If you can show me / send me files on discord to try that sideload stuff maybe can figure some way around that, would be good to try getting this compatible with it.

E: oh just saw your edit.. do you know what version companion you use? I know some are using an older version maybe?

Mister-Curious commented 1 year ago

The build I have is the latest public release of the Companion DLL. Hit me up on Discord if you need other files. I disabled anything from side-loading by renaming the FILES folder, so nothing is actually loading, but the instructions might be there. I suspect it might have something to do with any enemy compatibility patches Raz0r may have implemented, like the grey screen fix etc.

emoose commented 1 year ago

Sure, will probably message you tomorrow since it's getting late here now though.

BTW what way are you using to load both DLLs into it? You using companion as dinput8.dll & tweaks as x3daudio1_7 or something like that? Or maybe using the WrappedDLLPath stuff? (companion didn't seem to load for me with that tho...)

Also kinda interesting: tried switching the em06 & em09 data files to see if that made any difference, since if companion was overwriting our patch it would probably make em09 load the em06 data, and seems em06 model/animations do load in fine: bio4_22-12-05_23-05-55-786 Wasn't able to get textures working for that though, but looks kinda promising, just too bad we don't have any code for em06 ;_; Is this the model your seeker mod uses too? (probably not related to the bug, but wondering if anyone has done anything with this model yet...)

Mister-Curious commented 1 year ago

"BTW what way are you using to load both DLLs into it"?

I am using dinput for Companion and xinput_3 for RE4Tweaks. I haven't tried the WrappedDLLPath stuff (not sure how to use that but would love to find out, as renaming the files is tedious).

"Is this the model your seeker mod uses too"?

Yes, I got it from some download pack from a long time ago. I think it was Codeman's model. I ported to UHD over the Novistadors (rigged the whole thing myself).

Im kind of confused about all of this. Are there models for Seeker and Tyrant in em09? Are there going to be two enemies that are new or just one?

qingsheng8848 commented 1 year ago

Tyrant's model problem is indeed caused by razor's dll. razor's dll allows models to have finer rigging. But apparently em09.udas file bag rigging does not support razordll code

qingsheng8848 commented 1 year ago

https://github.com/nipkownix/re4_tweaks/issues/28#issuecomment-1336126029

linkthehylian commented 1 year ago

Holy shit. Great find @emoose! I never would've thought the final boss from RE1R would have leftover data in my favorite game.

Interested to see this being used in randomizers in the future!

Atomoksetin1996 commented 1 year ago

Hello. I'm not a coder or a programmer, but I'm very impressed with the work you've done. A few months ago I tried to replace the models and animations of various enemies with em06/em09 models and animations. In my case, the model was also always in a T pose, even when I used animations from em06/em09 along with their model.

I downloaded your build with em09 AI enabledby this link. https://github.com/nipkownix/re4_tweaks/tree/em09

Please tell me where exactly should I write EnableModExpansion = true? I found such a parameter only in the file along the path: re4_tweaks>settings>settings.ini However, when entering location r205, the game creates a non-collision ganado that does not have sound data.

emoose commented 1 year ago

@Atomoksetin1996 the release build of em09 branch at https://github.com/nipkownix/re4_tweaks/actions/runs/3622548661 includes a dinput8.ini file, after extracting both dll + ini next to bio4.exe you can set the EnableModExpansion = true in there, with that and the modded emleon03.esl above (make sure to rename/remove the original emleon03.esl.lfs) r205 should hopefully spawn it in.

If you use any other mods like RE4 companion or RE4HD I'm not sure how compatible it might be with those, so if you're using those and it doesn't spawn maybe try removing them.

I was wondering about trying to edit another Em to use the model/anims from this instead, the Em09 AI code is pretty basic and unfinished, would probably be better to get it running using a different Em instead IMO - Em09 does at least show that the anims etc should work fine in the game, too bad you couldn't get them to work by swapping though, maybe the code has to set something up first for them to be used properly.

Atomoksetin1996 commented 1 year ago

I was able to get the Tyrant up and running in the game, I also had to remove the "Raz0rd DLL" to make it display properly, because as "qingsheng" wrote, his DLL breaks the Tyrant's bones. Could you please tell us about how you found the unused "em09prolog" AI, and does the enemy "em06" have the same unused AI? I understand it has something to do with ".rel" files, could you tell me more about these files and what role they play in the game? Since there is no corresponding ".rel" fil e for the "em06" enemy, does that mean it can't be made playable as Tyrant?

peg

emoose commented 1 year ago

In the older console releases REL files contained the code for enemies/rooms/weapons, that way they could save memory usage by making it only load in the REL code for things that are actually used in the loaded level.

The original GC/Wii releases didn't contain any REL file for em06 or em09, but the debug GC build that leaked a few years ago did contain SYM files for them both (the SYM just names all the functions inside the REL), that still didn't contain any actual REL for them though, but did imply that both em06 and em09 were ported to the RE4 engine at some point.

One of the later Japanese Wii releases did actually contain the REL for em09, and the data too (would probably be possible to enable em09 on that release as well), though it didn't contain any REL for em06.

For the HD "remake" they combined all the REL files into the actual main EXE, I guess these remakes were based on that Japanese Wii version, since they also combined the em09 REL into the EXE with them, but sadly again no em06 code to be found - although HD versions do seem to contain the model/anim data for both em09 and em06.

Since all the REL code is combined into EXE now that makes it easier for us to activate it, by overwriting existing Em to call it, or to register a new Em like the new method did.

Hope that helps explain it, while em06 doesn't have code it seems the model & animations work fine on this engine though, so maybe with some work one of the existing Ems could use those. (also even though em09 code is pretty limited, I wonder if it might have even more animations which just didn't get linked up to the code yet...)

Atomoksetin1996 commented 1 year ago

Hello, some time ago in this forum thread, the possibility of adding a Tyrant enemy to the game was discussed, it was a few months ago, then I clicked on this link " https://github.com/nipkownix/re4_tweaks/actions/runs/3622548661", downloaded a special version of tweaks that had support for the em09 enemy, for about a week my game worked fine and I managed to meet the Tyrant in the sewers and play with him, but one day, for some reason unknown to me, my game refused to start. I didn't know what caused the error so I tried reinstalling NetFraemwork and Microsoft Visual C++, but now when I start the game, the bio4.exe process ends almost as soon as I start it, the game does not even have time to open. My friend also does not have your build with Tyrant, but he always gets the error Microsft Visual - Runtime Error when starting the game, we also tried to reinstall the NetFraemwork and Microsoft Visual C++ components, but to no avail. Raz0r DLL companion is completely removed, there are no files from other re_tweaks builds, which in theory could interfere with the launch of your build. I also tried to create a CrashDumps folder in the specified folder, but no new files are created in it. I have no idea what could be the cause of this error, I took a screenshot of the log file, maybe the information indicated in it will shed light on the causes of this error.

221647340-02ec702c-4819-45d7-bfbd-a80e307ac3e5

221647344-402584e8-e408-4c6e-851f-9ae1b4c225e8

emoose commented 1 year ago

@Atomoksetin1996 that's a strange issue, not really sure how that build would cause it, the only things I can think of are maybe some data files were modified (some early Em09 instructions included file changes I think), or maybe something bad was written into your save data.

Maybe try deleting / renaming your steamapps\common\Resident Evil 4\ folder, then right click game on Steam, go to Properties, Betas tab, make sure selected beta is "None" (new update changed this for some people), and then go to Local files > Verify integrity, let that finish & redownload game for you.

After download is finished, activate Steam offline-mode, and clear your Documents\My Games\Capcom\RE4 folder, and the <Steam-folder>\userdata\<user-id>\254700\remote\ folder.

Make sure to use offline mode on Steam before clearing them, or it might download broken files again from Steam cloud saves.

Then try running RE4 through Steam without any re4_tweaks installed (again stay offline though), and see if that lets you start it up.

Atomoksetin1996 commented 1 year ago

@emoose I completely uninstalled Resident Evil 4, then downloaded it again via file integrity check, then I went to Properties, Betas tab, make sure selected beta is "None". After that, I set offline mode in Steam and deleted the folder with my saves.

The game starts up fine, I tried to copy your tweaks again, but as soon as I install it, the game stops starting again.

The bio4.exe process ends almost immediately after launch, the game window does not even have time to open, other builds of twekas work fine on my computer, the problem occurs only in the build with Tyrant.

I tried the steps you listed a month ago, but then I also didn’t succeed. I want to review the Tyrant on my BIO4.EXE channel, but due to the refusal of this build to run, I can’t do it.

Should it be possible to activate the Tyrant in later builds of Tweaks? I found that the EnableModExpansion setting is also present in tweaks 1.8.

emoose commented 1 year ago

Ah I misunderstood your post, thought you meant RE4 itself was broken entirely after using the build, even with re4_tweaks removed - if it's just an issue with the Em09 re4_tweaks build hopefully we can find a fix for it.

The bio4.exe process ends almost immediately after launch, the game window does not even have time to open, other builds of twekas work fine on my computer, the problem occurs only in the build with Tyrant.

I noticed the log you posted mentions you're using 1.0.6, I only ever tested that build with 1.1.0, it /should/ work with 1.0.6 too, but it looks like Mister-Curious also had issues with 1.0.6 as well, so maybe it's only really stable on 1.1.0.

The new Steam update seems to have updated a lot of people to 1.1.0 but not sure if it updated everyone, could you try verifying game files in Steam again and see if it might update you to 1.1.0?

If it doesn't update you, you could try applying the xdelta from https://github.com/emoose/re4-research/issues/5 to your game EXE, but I'm not sure if 1.1.0 will actually work properly with the 1.0.6 data files (they're missing the added languages in 1.1.0, so might not work properly...) (if mixing 1.0.6 data with 1.1.0 EXE does give you issues, installing RE4HD should replace your game files with 1.1.0 compatible ones - I'm not really sure how compatible RE4HD is with the Em09 stuff though...)

Hopefully 1.1.0 might have better luck running with that Em09 build, just make sure to set EnableModExpansion in the included dinput8.ini, let me know if it's any help or not and we can try some other things otherwise.

Should it be possible to activate the Tyrant in later builds of Tweaks? I found that the EnableModExpansion setting is also present in tweaks 1.8.

Nah Tyrant is only included in this Em09 branch, I just tied it into the existing EnableModExpansion setting so I had an easy way to turn it off/on.

I tried the steps you listed a month ago, but then I also didn’t succeed. I want to review the Tyrant on my BIO4.EXE channel, but due to the refusal of this build to run, I can’t do it.

Oh didn't realize you were the owner of that channel, great videos there btw, showed a lot I didn't know about the game. (I did try leaving a comment once about the "mood" stuff I found at https://github.com/emoose/re4-research/issues/21, looked like one of the builds you showed had something for that, but seemed like it either didn't go through or YT deleted it)

Atomoksetin1996 commented 1 year ago

@emoose Using Deltapatcher, I updated BIO4.exe 1.0.6 to 1.1.0, but this unfortunately did not fix the problem of launching the game. In Steam in the Beta Versions section, I can choose version 1.0.2, I tried to download it earlier, but Tweaks with a Tyrant still does not work with this version.

I tried to launch this twekas in build with pirate bio4.exe and bio4.exe (Debug), but nothing changes.

bio4 exe1 1 0

emoose commented 1 year ago

Yeah 1.0.2 isn't supported by any tweaks version, I don't know why capcom even kept that up there.

Maybe it could be an issue with vulkan, could you try changing UseVulkanRenderer in the dinput8.ini to false and see if that helps at all (with 1.1.0 exe)

Also btw which ver of the em09 build are you using? re4_tweaks_release_em09_2022-12-05_173906.zip should be working one afaik, maybe try the build from that link.

Atomoksetin1996 commented 1 year ago

I have a GTX 1060 with Vulkan support, but I've tried turning it off, I've also tried setting all the variables in dinput.ini to false, but even setting all the variables to false didn't work. I downloaded builds "re4_tweaks_release_em09_2022-12-05_173906" and "re4_tweaks_debug_em09_2022-12-05_173911", but in both cases the game doesn't even start.

I also tried downloading the build from this link "https://github.com/nipkownix/re4_tweaks/tree/em09" and mixing it with your previous 2 builds hoping to get a different result. I also tried using dinput.ini from other newer and earlier tweaks, but that didn't work either.

As I mentioned earlier, attempts to use different versions of bio4.exe, including pirated ones, did not work.

I tried running your build on my friend's computer, but your build won't run on his friend either.

When I set UseVulkanRenderer = false the log messages don't change much, the last lines say something about "st7_0 -> st6_0 patch applied".

For the sake of experiment, I deleted the St7 and St6 folders and the St6.rel file, and also tried to extract all the .lfs archives, including em09.udas.lfs, but again to no avail.

Log

emoose commented 1 year ago

I'll try redownloading clean ver and check on my side, but still not really sure why it wouldn't work for you. Maybe it's the other re4_tweaks stuff included in that build, a lot of the other re4_tweaks features were still WIP back then I think, maybe some issue with that somehow.

Just to be sure, the latest re4_tweaks from https://github.com/nipkownix/re4_tweaks/actions/runs/4322069750 runs fine for you correct? I'll try making a build with the Em09 stuff added + some extra logging and we'll see if that can help at all.

E: here's a build of latest re4_tweaks with the Em09 stuff added: re4tweaks_em09mod-1.0.zip I know you mentioned mixing builds before, but there's also a lot more logging there now too, so log file might be able to tell us if it's getting stuck on a certain part of the Em09 patches. (EnableModExpansion = true still needs to be set in INI though) Still downloading game so haven't actually tested on my side yet, will update once I try it...

E2: well it seems to work fine for me, along with the extra logging. I did notice that the st7_0 -> st6_0 line was logged right before Em09 stuff though, so could mean it's having an issue during those patches, hopefully new logging can tell us where exactly.

Atomoksetin1996 commented 1 year ago

I managed ! Your new build ran successfully, it also works with bio4.exe version 1.0.6. Now I can review the Tyrant. By the way, you do not plan to improve the Tyrant's AI, I found that any type of weapon does the same damage to him, which is not good. Thank you very much for giving me so much of your time, I am very grateful to you.

Tyrant

emoose commented 1 year ago

By the way, you do not plan to improve the Tyrant's AI, I found that any type of weapon does the same damage to him, which is not good.

IIRC the AI code is checking for one weapon specifically, was either knife, pistol or shotgun, and only allows damage from that properly - thought I included a fix for that here but maybe not.

Can't remember which weapon it was now though, but interesting thing is the code actually checks for the RE4-only ID for the weapon specifically, not the REmake ID AFAIK, so this code must have been developed/updated for RE4.

(E: was wrong about this - any weapon can do damage, but the damage code does include a check for a specific weapon and reduces the damage amount if it's that wep, seems to be checking for wep id 2 - also only enters pain state when it's not that wep)

I tried comparing to REmake's tyrant AI code before too and seemed completely different, probably made from scratch, would explain why it doesn't have many actions available.

This build does include a fix for the tyrant walking/running toward you, the unpatched version would just always walk toward you and never run, would only start running if you did a ton of damage at once & were also far away from it at the time, the code seemed it was actually broken and not intended at all though (detailed in first post), so this patches it to start running if you're too far away instead.

Atomoksetin1996 commented 1 year ago

In a video that I recently posted on my channel, unused one-shot animations were also shown. The tyrant, while running, could pierce the player through and then throw his body to the ground. How did you manage to recognize the AI of the Tyrant in the Remake and compare it to the AI of the Tyrant from RE 4? In one of your posts, you also said that the code from the .rel files in the HD version was moved to bio4.exe, does this mean that Hunter's AI is also inside bio4.exe ?

emoose commented 1 year ago

Oh cool, had a feeling there might be more anims there which didn't have any code for them.

How did you manage to recognize the AI of the Tyrant in the Remake and compare it to the AI of the Tyrant from RE 4?

I just found a list of the Em IDs that REmake uses and checked the .rel for it, IIRC it was both Em0b and Em09 in REmake.

Neither seemed very similar to the RE4 code though, wasn't actually sure I was looking at Tyrant since code seemed so much different, but I did try checking some other Ems too and couldn't find anything that was close.

In one of your posts, you also said that the code from the .rel files in the HD version was moved to bio4.exe, does this mean that Hunter's AI is also inside bio4.exe ?

Nah no code for Hunter sadly, I haven't found a .rel for that yet neither, only the .sym file that describes the .rel, hopefully a dev build might show up one day that might include it.

DarthxVoid commented 1 year ago

@emoose Could you help me? i went to test the tyrant and it ta giving this model problem, i'm using a executeable 1.0.6, with modifications pro my mod and the only's dll i'm using is the tweaks and the qingsheng dll.

image

Atomoksetin1996 commented 1 year ago

The Raz0r DLL is causing Tyrant bone problems, just remove it and you should be fine.

Atomoksetin1996 commented 1 year ago

I've been looking for a way to make the Japanese trial version of Biohazard 4 fully work for a long time, the problem is that this trial version does not have its own stX.rel files that are necessary for the scripts to work. I have tried copying similar .rel files from builds of the final version of the game, but this either leads to a crash or crash of the game. It is also interesting that the American trial version does not need stX.rel files for scripts to work on locations, these files are simply not there, but this does not prevent game scripts from working. Is it possible to create new .rel files for the Japanese trial version, or edit the .rel files from the final version of the game so that they work in the Japanese trial version?

DarthxVoid commented 1 year ago

The Raz0r DLL is causing Tyrant bone problems, just remove it and you should be fine.

I use the qingsheng dll not to the Raz0r

emoose commented 1 year ago

It is also interesting that the American trial version does not need stX.rel files for scripts to work on locations, these files are simply not there, but this does not prevent game scripts from working.

Huh I hadn't noticed that before, looks like the code that would be inside st1.rel might be included into main.dol instead, at least main.dol seems to have strings for R100Init etc.

Unfortunately porting .rel from another build would take some effort, the rels make calls into functions in the main dol using fixed relative offsets, but if you knew the addresses of all the functions inside both build you're copying from & build you're copying to, then it'd probably be possible to make a tool that could find all the function calls in the rel, figure out what function it's calling, then look up that function in the build you're porting to & fix the offset for it (as long as the function didn't change too much/change parameters etc it should work at least)

We only really know the functions in the debug build though, you could probably compare against funcs in target build to name them (like we did in the PC IDA database), but that's really pretty time consuming, if funcs didn't change too much something like bindiff would probably help though.

If another build ever shows up that includes symbols it's maybe worth looking into, besides that it's too much effort IMO.

Interestingly on the PS2 side the RELs there don't use fixed offsets but actually include a list of function names/addrs in the main EXE, and REL actually looks up function names in the EXE before running, so if any demo builds ever show up for that it might be possible to swap out RELs there (probably not as interesting as GC demos though since game was already complete for PS2)

Also PC 2007 does include PS2 RELs inside rel.dat that seem to be from a debug build, but seems they removed the fun t_camera.rel etc files before releasing, might be possible to mix the RELs that are there with the retail release though (if the RELs call any debug funcs that don't exist in retail exe it'd probably break tho)

FutonGama commented 1 year ago

E: here's a build of latest re4_tweaks with the Em09 stuff added: re4tweaks_em09mod-1.0.zip

Hi Emoose, can you make a version without the console menu? Thank you!

SaacK12 commented 4 months ago

I'll try redownloading clean ver and check on my side, but still not really sure why it wouldn't work for you. Maybe it's the other re4_tweaks stuff included in that build, a lot of the other re4_tweaks features were still WIP back then I think, maybe some issue with that somehow.

Just to be sure, the latest re4_tweaks from https://github.com/nipkownix/re4_tweaks/actions/runs/4322069750 runs fine for you correct? I'll try making a build with the Em09 stuff added + some extra logging and we'll see if that can help at all.

E: here's a build of latest re4_tweaks with the Em09 stuff added: re4tweaks_em09mod-1.0.zip I know you mentioned mixing builds before, but there's also a lot more logging there now too, so log file might be able to tell us if it's getting stuck on a certain part of the Em09 patches. (EnableModExpansion = true still needs to be set in INI though) Still downloading game so haven't actually tested on my side yet, will update once I try it...

E2: well it seems to work fine for me, along with the extra logging. I did notice that the st7_0 -> st6_0 line was logged right before Em09 stuff though, so could mean it's having an issue during those patches, hopefully new logging can tell us where exactly.

Hi Emoose, it is certainly a great job you did to make the Tyrant work. A few months ago I had tried on my own with this re4_tweaks build that you uploaded and it worked for me. Now I want to put it back in my game but it won't let me, it always crashes when I go to room r205.

I have tried 1.1.0 and 1.0.6 and it doesn't work in both. I also made sure to have EnableModExpansion = true and to disable Vulkan.

emoose commented 4 months ago

Hm, are you using a different player character than Leon? Game has different EmFileTbl tables for each char which says where to find the data for each Em, not really sure why it's setup like that, but IIRC the Em09 build only changed the first table, so might break stuff if you aren't playing as Leon.

If you have a 1.1.0 crash dump I could try taking a look too.

DarthxVoid commented 4 months ago

emoose, could you make a build of tyrant with tweaks 1.8?