Raised This Month: $32 Target: $400
 8% 

[Help] Call function trough #emit opcodes


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
KORD_12.7
Senior Member
Join Date: Aug 2009
Location: Russia, Vladivostok
Old 04-06-2015 , 06:11   [Help] Call function trough #emit opcodes
Reply With Quote #1

I found nice tutor about #emit on samp forums. I'm trying to call public function, here is a code:
PHP Code:
#include <amxmodx>

public Func(const iVar)
{
server_print(" * Func called, var is %d"iVar);
}

public 
plugin_init()
{
new 
iPointeriVar random_num(0255);

server_print(" * plugin_init: random_num is %d"iVar);

// Get pointer to function
#emit CONST.pri    Func
#emit STOR.S.pri    iPointer

// Push variable
#emit LOAD.S.pri    iVar
#emit PUSH.pri

// Bytes passed to "Func"
#emit PUSH.C    4

// Call "Func"
#emit LOAD.S.pri    iPointer
#emit CALL.pri

It works fine, but i don't know how to get function pointer by funcidx. I tried insctructions from tutor above, but server crashes. I tried to use this code to get pointer by idx:
PHP Code:
new
idx funcidx("Func1"),
pointer;
// Get the pointer to the public function list.
#emit LCTRL 1
#emit NEG
#emit ADD.C 32
#emit STOR.S.pri pointer
#emit LREF.S.alt pointer
// Get the pointer to the function at the given index.
#emit LCTRL 1
#emit NEG
#emit ADD
#emit LOAD.S.alt idx
#emit SHL.C.alt 3
#emit ADD
#emit STOR.S.pri pointer
#emit LREF.S.pri pointer
#emit STOR.S.pri pointer 
Any ideas?
__________________

Vi Veri Veniversum Vivus Vici
Russian Half-Life and Adrenaline Gamer community

Last edited by Arkshine; 04-07-2015 at 06:29. Reason: nvm
KORD_12.7 is offline
Send a message via ICQ to KORD_12.7
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 23:26.


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