Zelda64Recomp / Zelda64Recomp

Static recompilation of Majora's Mask (and soon Ocarina of Time) for PC (Windows/Linux)
GNU General Public License v3.0
5.43k stars 264 forks source link

[Question] How to import function from original game without editing/patching the function #486

Closed Captainkittyca2 closed 1 month ago

Captainkittyca2 commented 1 month ago

So I'm using the MMRecompModTemplate, and i'm patching the function EnItem00_Draw. The problem is that, EnItem00_Draw calls EnItem00_DrawRupee, EnItem00_DrawHeartPiece, and EnItem00_DrawHeartContainer and that causes an error when compiling because those specific functions are apparently not found by the code mod. So I was wondering if there's a way to import those 3 functions in the mod without patching them.

I tried using RECOMP_IMPORT but idk what to put in the first argument of RECOMP_IMPORT, since I'm not importing a function from a mod, but from the regular game.

Also, some things like gMagicMeterEndTex I can't get to work at all in MMRecompModTemplate. It might have to do with how gMagicMeterEndTex is located in parameter_static.xml and so maybe the mod template can't read it.

Mr-Wiseguy commented 1 month ago

You don't need to import functions from the original game to call them, you're just missing function declarations for those. Same deal for the variables, you just need to extern them. RECOMP_IMPORT is only for brand new functions that didn't exist in the original game, like recomp_printf or functions from other mods that are dependencies of the one you're making.

Captainkittyca2 commented 1 month ago

ah how do i declare them?

Mr-Wiseguy commented 1 month ago

The normal way you'd do it in C, either include a header from decomp that declares the function or if they're not in a header then just declare then manually like these lines from z_en_item00.c: image

Captainkittyca2 commented 1 month ago

ah i tried doing that earlier but then the game would crash when launching with the mod. But maybe the crash was caused by something else

image

Mr-Wiseguy commented 1 month ago

You need to go through the offline mod recompilation process detailed in the mod template readme and copy the DLL it produces into the same folder. If you have issues getting that working then I'd recommend just waiting until the offline mod recompiler is no longer needed, which will happen before 1.2 releases.

Captainkittyca2 commented 1 month ago

Ah for some reason i completely forgot about the offlineModRecomp part. Tried it and the mod seems to be working. Thanks for the help!

Although for some reason it only works when playing in debug mod of recomp and not release.

Also, would the recomp be more powerful than the N64 version of the game? Like would it be able to handle 3D item drops if N64 version couldn't?

One more question: how do i call functions/arguments that are from parameter_static.xml? Like gMagicMeterEndTex. I think I got the hang of everything else now.

Captainkittyca2 commented 1 month ago

Also, looking forward to the 1.2 release :)

Mr-Wiseguy commented 1 month ago

Although for some reason it only works when playing in debug mod of recomp and not release.

I'd double check that you've built the release version after switching to the modding branch, as mod loading works fine on release builds.

Also, would the recomp be more powerful than the N64 version of the game? Like would it be able to handle 3D item drops if N64 version couldn't?

Orders of magnitude more powerful, yes. The game is running fully natively and rendering takes full advantage of your GPU. Recomp can easily run with 3D item drops.

One more question: how do i call functions/arguments that are from parameter_static.xml?

Building the MM decompilation will generate headers for the xml files, so for example you'd have assets/interface/parameter_static/parameter_static.h which shows the type of the variable. You can then copy the declarations from those headers.

Captainkittyca2 commented 1 month ago

Thanks for the info! I'm loving MM Recomp and looking forward to future updates