Raised This Month: $51 Target: $400
 12% 

IScriptVM->LookupFunction() always returns NULL


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
roge
New Member
Join Date: Oct 2016
Old 10-16-2016 , 17:27   IScriptVM->LookupFunction() always returns NULL
Reply With Quote #1

I'm trying to write a MM:S plugin that extends the Vscript scripting interface in CS:GO. But I'm running into this problem, I can't get IScriptVM->LookupFunction() to return anything except NULL. If you look here in the SDK, you'll see this example:

Code:
// Generally, use the "Call" functions. This example is the equivalent of DoIt("Har", 6.0, 99).

hFunction = pScriptVM->LookupFunction( "DoIt", hScope );
pScriptVM->Call( hFunction, hScope, true, NULL, "Har", 6.0, 99 );
Now some of my test code looks something like this:

Code:
void VpTestScriptFunctionCall() {
    HSCRIPT func = g_mScriptVM->LookupFunction("ScriptPrintMessageChatAll");
    g_mScriptVM->Call(func, NULL, true, NULL, "It works!");
}
But after a little bit of debugging I realized that `g_mScriptVM->LookupFunction` was always returning NULL, I tried giving it a scope(even though that's an optional argument), I tried giving it a function name that I added through "ScriptRegisterFunction", and I tried giving it a function listed in the CS:GO Vscript Documentation, none of that seemed to have helped, it still just returns NULL. Does anyone have any ideas how I can get LookupFunction to do anything? ...or does this just seem to be a problem with the SDK?

(Just in case anyone is interested, I'm getting my instance of IScriptVM by hooking CreateVM in IScriptManager.)

Last edited by roge; 10-16-2016 at 17:40.
roge is offline
psychonic

BAFFLED
Join Date: May 2008
Old 10-16-2016 , 17:58   Re: IScriptVM->LookupFunction() always returns NULL
Reply With Quote #2

Do it do the same if you pass INVALID_HSCRIPT as the second param to LookupFunction? (instead of the default of NULL)

I've only messed with the VScript interface in Dota with Lua, but it definitely works there. INVALID_SCRIPT is the global "scope", else the the the scope is the HSCRIPT of a class instance.
psychonic is offline
roge
New Member
Join Date: Oct 2016
Old 10-16-2016 , 18:08   Re: IScriptVM->LookupFunction() always returns NULL
Reply With Quote #3

Quote:
Originally Posted by psychonic View Post
Do it do the same if you pass INVALID_HSCRIPT as the second param to LookupFunction? (instead of the default of NULL)

I've only messed with the VScript interface in Dota with Lua, but it definitely works there. INVALID_SCRIPT is the global "scope", else the the the scope is the HSCRIPT of a class instance.
Nope, still hasn't seem to have done anything.
roge is offline
psychonic

BAFFLED
Join Date: May 2008
Old 10-16-2016 , 18:12   Re: IScriptVM->LookupFunction() always returns NULL
Reply With Quote #4

Oh! Instead of:
Code:
HSCRIPT func = g_mScriptVM->LookupFunction("ScriptPrintMessageChatAll");
Have you tried?
Code:
HSCRIPT func = g_mScriptVM->LookupFunction("PrintMessageChatAll");
You should be using the name of the function in the scripting language, not the name of the C++ function that it points at.
psychonic is offline
roge
New Member
Join Date: Oct 2016
Old 10-16-2016 , 18:18   Re: IScriptVM->LookupFunction() always returns NULL
Reply With Quote #5

Quote:
Originally Posted by psychonic View Post
Oh! Instead of:
Code:
HSCRIPT func = g_mScriptVM->LookupFunction("ScriptPrintMessageChatAll");
Have you tried?
Code:
HSCRIPT func = g_mScriptVM->LookupFunction("PrintMessageChatAll");
You should be using the name of the function in the scripting language, not the name of the C++ function that it points at.
That is the name of the function in the scripting language, and like I said I tried doing LookupFunction() on functions that I created with ScriptRegisterFunction(), and that doesn't work either.
roge is offline
Peace-Maker
SourceMod Plugin Approver
Join Date: Aug 2008
Location: Germany
Old 10-17-2016 , 01:06   Re: IScriptVM->LookupFunction() always returns NULL
Reply With Quote #6

You could try to log all the functions registered in the vscript vm and see if the ones you try to hook are present.
See the source of this especially the Register* hooks here.
__________________
Peace-Maker is offline
roge
New Member
Join Date: Oct 2016
Old 10-17-2016 , 03:20   Re: IScriptVM->LookupFunction() always returns NULL
Reply With Quote #7

Quote:
Originally Posted by Peace-Maker View Post
You could try to log all the functions registered in the vscript vm and see if the ones you try to hook are present.
See the source of this especially the Register* hooks here.
Yes the functions I'm trying to get at are present in the VM. This still hasn't lead me to fixing the problem of LookupFunction() returning nothing but NULL. But it did kinda help me achieve what I was interested in doing. If I hook RegisterFunction() inside IScriptVM, and then hold onto the function bindings for the functions I want I can call them later by doing something like this:

Code:
ScriptVariant_t args[1];
args[0] = "It works!!!";
chatPrintBinding->m_pfnBinding(chatPrintBinding->m_pFunction, NULL, args, 1, NULL);
I've tested this, and it works. Thanks.
roge is offline
psychonic

BAFFLED
Join Date: May 2008
Old 10-17-2016 , 08:37   Re: IScriptVM->LookupFunction() always returns NULL
Reply With Quote #8

I dug into this a bit more for the sake of curiosity.

The LookupFunction implementation in the squirrel VM calls the more generic LookupObject (not exposed on the interface) to get the function by name, but then checks sq_isclosure. Since Squirrel differentiates between closures and native closures, the script functions implemented in C++ don't pass that check, only functions written in Squirrel.

Edit: It looks like GetValue should work for getting at functions.

Last edited by psychonic; 10-17-2016 at 08:41.
psychonic is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 12:26.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode