WopsS / RED4ext.SDK

A library to create mods for REDengine 4 (Cyberpunk 2077), independently of RED4ext.
MIT License
93 stars 31 forks source link

Native func support #48

Closed flibdev closed 2 years ago

flibdev commented 2 years ago

Added a hook to the RTTIRegistrator constructor to add callback functions that are called before the final.redscripts is loaded, allowing for new native methods to be defined in RED4ext and called from Redscript.

RTTIRegistrator::Add() can be called immediately after the dll attaches:

RED4EXT_C_EXPORT void RED4EXT_CALL RegisterTypes() {}
RED4EXT_C_EXPORT void RED4EXT_CALL PostRegisterTypes() {}

BOOL APIENTRY DllMain(HMODULE aModule, DWORD aReason, LPVOID aReserved)
{
    switch (aReason)
    {
    case DLL_PROCESS_ATTACH:
        DisableThreadLibraryCalls(aModule);
        RED4ext::RTTIRegistrator::Add(RegisterTypes, PostRegisterTypes);
        break;
    }

    return TRUE;
}

Also fleshed out one of the unknown chunks in the CBaseFunction class: a DataBuffer to the compiled redscript bytecode

WopsS commented 2 years ago

This is image

Thanks!