Detouring functions that do not belong to any class/created from vscript?
Say there's a function defined within scriptedmode_addon.nut (L4D2)
//::CommandIssued <- function (...)
getroottable().CommandIssued <- function ( cmd = 0, subject = -1, target = -1 )
{
if (cmd == -1)
return true;
// some code
return false;
}
How would one make a detour for said function? It doesn't seem to appear in VScript_GetAllGlobalFunctions()
Neither readme not vscript_test.sp has any examples that cover this case.
Detour only offers native functions from C++, aka all of these functions. Currently there isn't support to detour/hook a function from nut files, and I'm not sure if it's even possible to make it work.
I'm not familiar with L4D2, when does getroottable().CommandIssued get called? Does it get called directly from C++, or from another nut script/function?
Described function is defined in a .nut script, which is (my best educated guess) done "before gameplay", then supposed to be called by various scripts during gameplay. The script file in question can be different per-addon (see "addon scripts")
then supposed to be called by various scripts during gameplay.
Doesn't sound like there'll be a solution to directly detour it then, you would need to find a workaround solution for it, like creating a new native function at VScript_CreateGlobalFunction and have CommandIssued script call it.
Otherwise, you can directly call a script function by VScriptExecute methodmap, just not for detouring it.
Turning CommandIssued into an empty native function and calling it from VScript seems to work fine in my case.