From what I can tell looking at the script_execute disassembly, it seems to expect argcnt+1 elements in the argument array for some reason. It creates a new (stack allocated) argument array, and then runs a loop argcnt times copying the arguments into the new array, starting from args[1], which naturally over runs the original array and crashes. So I guess GM has an extra empty value on the ends of its argument arrays for some reason, cant think how it would possibly be useful and such an element is referenced by none of the fixed-argument functions as far as I can see (but then they often seem to not even bother checking the argument count or types).
Not got time to really work on it till tomorrow night, but if you want to try something on the off chance I found these 2 internal functions in there and have a pretty good idea what they do.
getScript
void *getScriptPtr = 0x004048B8;
__asm
{
mov eax, scriptId
call getScriptPtr
mov scriptPtr, eax
}
scriptExecute
void *scriptExecutePtr = 0x00588AF8
__asm
{
;arguments, do not include the scriptId, there the args the script sees in argument0, argument1, etc
push argcnt
push args
push 15 ;max args? was hardcoded
push 1; really no idea this time, again gm hardcoded the value
push pretvar; A gm::Value* for the return value
eax = scriptPtr
edx = self; Instance*
ecx = other; Instance*
}
The other thing to be aware of with any of the methods to call back into GML is that if it then calls a dll again (doesn't need to be yours, or any GMAPI extension, just anything that would use external_call) it will overwrite the stored self and other pointers, possibly to different instances, so either don't depend on self and other being the same afterwards, or save/restore them yourself (and in the event someone thinks multi threading is a good idea, then that gets even more complicated).
EDIT:
Also you could add the extra element yourselves:
gm::Value args[] = {scr, arg1, arg2, gm::Value()};
retstr = gm::script_execute(3, args).str;
Edited by SyncViews, 12 August 2012 - 06:57 PM.











