logo logo

 Back to main page

The NWNX Community Forum

 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
All NWScript functions identified

 
Post new topic   Reply to topic    nwnx.org Forum Index -> Development
View previous topic :: View next topic  
Author Message
Papillon
x-man


Joined: 28 Dec 2004
Posts: 1060
Location: Germany

PostPosted: Sat Jun 02, 2007 17:19    Post subject: All NWScript functions identified Reply with quote

This is just a heads-up for NWNX hackers.

By backtracing a known virtual machine function, I was able to correlate nwscript.nss and the virtual machine function table. This resulted in a complete list of all NWScript functions (GetTimeMillisecond, ActionSit, GetLastTrapDetected, and so on) and their exact memory locations in nwn2server.

I am not sure if it would be a wise idea to post the list here, but I think some instructions can not hurt Wink.

1) Call a known NWScript function and let it RET in the debugger. It will jump into a small code section of 21 lines (starting with MOV EAX, ... and ending with RETN 8 ).
2) After the first few lines, EDX will contain the location of the function pointer table
3) EAX contains the function ID. This ID conveniently correlates with the position of the function definition in nwscript.nss (*)
4) The function adress is calculated from the lookup table like this: EDX+EAX*4.
5) Using an editor of your choice, copy the lookup table into a text file, and match the functions from nwscript.nss, line by line. An editor which supports column operations (e.g. UltraEdit) helps.

(*) int Random() is ID 0, each (real) line following this increments the ID by one.

I am not sure what to do with this yet, but it will surely proove helpful in the future Smile.
_________________
Papillon
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
virusman



Joined: 30 Jan 2005
Posts: 1020
Location: Russia

PostPosted: Sat Jun 02, 2007 22:57    Post subject: Reply with quote

I thought you knew this.. It's very useful for describing memory structures, finding offsets and specific functions, etc.
This table is being built dynamically on server startup with a special function. (1.05: 0x54ADD0) I guess it's a CNWVirtualMachineCommands constructor.
Groups of certain NWScript functions are handled by one function (like ItemProperties, some kinds of Effects, dices, SetLocal*, GetLocal*, math functions, etc.).
All functions use script stack (push&pop functions for every data type) to get parameters and pass return values.
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
Papillon
x-man


Joined: 28 Dec 2004
Posts: 1060
Location: Germany

PostPosted: Mon Jun 04, 2007 15:03    Post subject: Reply with quote

Well, I knew before, but I never bothered to compile all functions into a comprehensive list.

Since you mentioned the stack functions: Have you ever tried to manipulate the stack and then call an engine funtions (which takes the arguments from stack) ?
_________________
Papillon
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
virusman



Joined: 30 Jan 2005
Posts: 1020
Location: Russia

PostPosted: Mon Jun 04, 2007 18:15    Post subject: Reply with quote

Papillon wrote:
Since you mentioned the stack functions: Have you ever tried to manipulate the stack and then call an engine funtions (which takes the arguments from stack) ?
No.. There was no need for that. The NWScript functions call engine functions, which I use.
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
Papillon
x-man


Joined: 28 Dec 2004
Posts: 1060
Location: Germany

PostPosted: Tue Jun 05, 2007 22:39    Post subject: Reply with quote

I do see a need for calling e.g. DelayCommand(ExecuteScript()), that's why I am asking.
_________________
Papillon
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
virusman



Joined: 30 Jan 2005
Posts: 1020
Location: Russia

PostPosted: Tue Jun 05, 2007 23:12    Post subject: Reply with quote

I think, it'd be better to call the corresponding engine function instead.
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
Papillon
x-man


Joined: 28 Dec 2004
Posts: 1060
Location: Germany

PostPosted: Thu Jun 07, 2007 9:57    Post subject: Reply with quote

In fact, I am talking about engine functions, like SetString and the like (see above). What type of functions are you talking about ?
_________________
Papillon
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
GodBeastX



Joined: 09 Aug 2006
Posts: 65

PostPosted: Fri Sep 14, 2007 2:51    Post subject: Reply with quote

Oh, I didn't even see this thread! This is awesome news! Maybe I can finally put in a backend to ExportCharacter
Back to top
View user's profile Send private message
Urlord



Joined: 17 Nov 2006
Posts: 122

PostPosted: Fri Sep 14, 2007 22:28    Post subject: Reply with quote

Could one of you plugin development folks possibly use this information to find the function that dumps all an object's variables (like the DM command)?
_________________
Jim (aka, Urlord)
Visit the Persistent World of Nymri
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    nwnx.org Forum Index -> Development All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group