XenonRecomp icon indicating copy to clipboard operation
XenonRecomp copied to clipboard

How would I reimplement a function?

Open Lockl00p opened this issue 10 months ago • 2 comments

So, with the game I'm trying to recomp (Fallout 3), I got a few functions that, well, don't exist. How would I reimplement them? Would I just add a source file that has the function in it and treat it like a normal C function?

Lockl00p avatar Mar 09 '25 22:03 Lockl00p

In your runtime, just define the function anywhere you want, and the linker will resolve it. For example:

PPC_FUNC(__imp__NtCreateFile)
{
    // implementation here...
}

I recommend checking out what UnleashedRecomp does: https://github.com/hedge-dev/UnleashedRecomp/blob/main/UnleashedRecomp/kernel/imports.cpp

The hooks are created at the bottom of the file through a GUEST_FUNCTION_HOOK macro, which is a helper macro that auto generates the PPC function declaration while translating the PPC registers to real function arguments for easier usage. The macro is implemented here: https://github.com/hedge-dev/UnleashedRecomp/blob/main/UnleashedRecomp/kernel/function.h

With that NtCreateFile would look like:

uint32_t NtCreateFile
(
    be<uint32_t>* FileHandle,
    uint32_t DesiredAccess,
    XOBJECT_ATTRIBUTES* Attributes,
    XIO_STATUS_BLOCK* IoStatusBlock,
    uint64_t* AllocationSize,
    uint32_t FileAttributes,
    uint32_t ShareAccess,
    uint32_t CreateDisposition,
    uint32_t CreateOptions
)
{
    // implementation here...
}

GUEST_FUNCTION_HOOK(__imp__NtCreateFile, NtCreateFile);

blueskythlikesclouds avatar Mar 09 '25 22:03 blueskythlikesclouds

How do you stub the unnecessary functions, I cant make sense of the files you suggested.

Organizationguy avatar Apr 14 '25 18:04 Organizationguy