NWScript is a scripting language used in the game Neverwinter Nights. The script source (.NSS) can be compiled into binary form (.NCS) in the Aurora Toolset or via commandline tools (CLCOMPILE.EXE or NWNNSSCOMP.EXE).
The binary form can also be decompiled into byte codes by NWNNSSCOMP.
For those who are interested, this program demonstrates how to assemble the bytecodes into the binary form using a batch file and FASM.
The sample bytecode source file (example.nsm) looks like this:
So what does this all mean? Probably not much. It is an alternate way to code scripts and may allow (possibly, I think) one to produce binary output that are not possible before.
ps. The output produced by NSM is for Neverwinter Nights v1.69 and may not work in earlier versions.
ps2. The files inside the include directory are scripts that translate bytecodes. NW.INC in particular contains the byte code definitions. NWFUNC.INC holds the NWScript engine routines, and NWCONST.INC the constants.
Updates
9/11/2008:
- Fixed JMP, JSR, JZ, JNZ
- Added support for parameters
- Fixed declaration of floats
Thanks! Unfortunately pointer operations are still not possible because stack instructions only accepts immediate constants and not memory addresses.
Probably the only dubious advantages of coding in byte code is a smaller output binary size (even smaller than using NWNNSSCOMP) and the ability to pass variable number of arguments to subroutines.
My skills are rather limited, but I hope I can add type checking and ability to support the full range of parameter types for the engine routines, such that one can write lines like this:
SendMessageToPC GetFirstPC,"Hello World!"
Posted by Saduj at 2008-11-09 10:57:02 Voted 10.00 on 11/09/08