xoreos  0.0.5
Classes | Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
Aurora::NWScript::NCSFile Class Reference

An NCS, BioWare's NWN Compile Script. More...

#include <ncsfile.h>

Inheritance diagram for Aurora::NWScript::NCSFile:
Inheritance graph
[legend]
Collaboration diagram for Aurora::NWScript::NCSFile:
Collaboration graph
[legend]

Classes

struct  Opcode
 

Public Member Functions

 NCSFile (Common::SeekableReadStream *ncs)
 
 NCSFile (const Common::UString &ncs)
 
 ~NCSFile ()
 
const Common::UStringgetName () const
 
VariableContainergetEnvironment ()
 Return the script's environment variables. More...
 
void setEnvironment (const VariableContainer &env)
 Overwrite the environment. More...
 
const Variablerun (Object *owner=0, Object *triggerer=0)
 Run the current script, from start to finish. More...
 
const Variablerun (const ObjectReference owner=ObjectReference(), const ObjectReference triggerer=ObjectReference())
 
const Variablerun (const ScriptState &state, Object *owner=0, Object *triggerer=0)
 Run the current script, from this state to finish. More...
 
const Variablerun (const ScriptState &state, const ObjectReference owner=ObjectReference(), const ObjectReference triggerer=ObjectReference())
 
- Public Member Functions inherited from Aurora::AuroraFile
 AuroraFile ()
 
void clear ()
 
uint32 getID () const
 Return the file's ID. More...
 
uint32 getVersion () const
 Return the file's version. More...
 
bool isUTF16LE () const
 Were the ID and version encoded in little-endian UTF-16 in the file? More...
 

Static Public Member Functions

static ScriptState getEmptyState ()
 
- Static Public Member Functions inherited from Aurora::AuroraFile
static void readHeader (Common::ReadStream &stream, uint32 &id, uint32 &version, bool &utf16le)
 Read the header out of a stream. More...
 
static void readHeader (Common::ReadStream &stream, uint32 &id, uint32 &version)
 Read the ID and version out of a stream. More...
 
static uint32 readHeaderID (Common::ReadStream &stream)
 Read the ID out of a stream. More...
 

Private Types

enum  InstructionType {
  kInstTypeNone = 0, kInstTypeDirect = 1, kInstTypeInt = 3, kInstTypeFloat = 4,
  kInstTypeString = 5, kInstTypeObject = 6, kInstTypeResource = 96, kInstTypeEngineType0 = 16,
  kInstTypeEngineType1 = 17, kInstTypeEngineType2 = 18, kInstTypeEngineType3 = 19, kInstTypeEngineType4 = 20,
  kInstTypeEngineType5 = 21, kInstTypeIntArray = 64, kInstTypeFloatArray = 65, kInstTypeStringArray = 66,
  kInstTypeObjectArray = 67, kInstTypeResourceArray = 68, kInstTypeEngineType0Array = 80, kInstTypeEngineType1Array = 81,
  kInstTypeEngineType2Array = 82, kInstTypeEngineType3Array = 83, kInstTypeEngineType4Array = 84, kInstTypeEngineType5Array = 85,
  kInstTypeIntInt = 32, kInstTypeFloatFloat = 33, kInstTypeObjectObject = 34, kInstTypeStringString = 35,
  kInstTypeStructStruct = 36, kInstTypeIntFloat = 37, kInstTypeFloatInt = 38, kInstTypeEngineType0EngineType0 = 48,
  kInstTypeEngineType1EngineType1 = 49, kInstTypeEngineType2EngineType2 = 50, kInstTypeEngineType3EngineType3 = 51, kInstTypeEngineType4EngineType4 = 52,
  kInstTypeEngineType5EngineType5 = 53, kInstTypeVectorVector = 58, kInstTypeVectorFloat = 59, kInstTypeFloatVector = 60
}
 
typedef void(NCSFile::* OpcodeProc) (InstructionType type)
 

Private Member Functions

void setupOpcodes ()
 
void load ()
 
void reset ()
 Reset the script for another execution. More...
 
const Variableexecute (const ObjectReference owner=ObjectReference(), const ObjectReference triggerer=ObjectReference())
 
bool executeStep ()
 Execute one script step. More...
 
void decompile ()
 
void callEngine (Aurora::NWScript::FunctionContext &ctx, uint32 function, uint8 argCount)
 Helper function for o_action(), doing the actual engine function calling. More...
 
void o_nop (InstructionType type)
 NOP: no operation. More...
 
void o_cpdownsp (InstructionType type)
 CPDOWNSP: copy a value into an existing stack element. More...
 
void o_rsadd (InstructionType type)
 RSADD: push an empty variable onto the stack. More...
 
void o_cptopsp (InstructionType type)
 CPTOPSP: push a copy of a stack element on top of the stack. More...
 
void o_const (InstructionType type)
 CONST: push a constant (predetermined value) variable onto the stack. More...
 
void o_action (InstructionType type)
 ACTION: call a game-specific engine function. More...
 
void o_logand (InstructionType type)
 LOGAND: perform a logical boolean AND (&&). More...
 
void o_logor (InstructionType type)
 LOGOR: perform a logical boolean OR (||). More...
 
void o_incor (InstructionType type)
 INCOR: perform a bit-wise inclusive OR (|). More...
 
void o_excor (InstructionType type)
 EXCOR: perform a bit-wise exclusive OR (^). More...
 
void o_booland (InstructionType type)
 BOOLAND: perform a bit-wise AND (&). More...
 
void o_eq (InstructionType type)
 EQ: compare the top-most stack elements for equality (==). More...
 
void o_neq (InstructionType type)
 NEQ: compare the top-most stack elements for inequality (!=). More...
 
void o_geq (InstructionType type)
 GEQ: compare the top-most stack elements, greater-or-equal (>=). More...
 
void o_gt (InstructionType type)
 GT: compare the top-most stack elements, greater (>). More...
 
void o_lt (InstructionType type)
 LT: compare the top-most stack elements, less (<). More...
 
void o_leq (InstructionType type)
 LEQ: compare the top-most stack elements, less-or-equal (<=). More...
 
void o_shleft (InstructionType type)
 SHLEFT: shift the top-most stack element to the left (<<). More...
 
void o_shright (InstructionType type)
 SHRIGHT: signed-shift the top-most stack element to the right (>>>). More...
 
void o_ushright (InstructionType type)
 USHRIGHT: shift the top-most stack element to the right (>>). More...
 
void o_add (InstructionType type)
 ADD: add the top-most stack elements (+). More...
 
void o_sub (InstructionType type)
 SUB: subtract the top-most stack elements (-). More...
 
void o_mul (InstructionType type)
 MUL: multiply the top-most stack elements (*). More...
 
void o_div (InstructionType type)
 DIV: divide the top-most stack elements (/). More...
 
void o_mod (InstructionType type)
 MOD: calculate the remainder (modulo) of an integer division (%). More...
 
void o_neg (InstructionType type)
 NEQ: negate the top-most stack element (unary -). More...
 
void o_comp (InstructionType type)
 COMP: calculate the 1-complement of the top-most stack element (~). More...
 
void o_movsp (InstructionType type)
 MOVSP: pop elements off the stack. More...
 
void o_storestateall (InstructionType type)
 STORESTATEALL: unused, obsolete opcode. More...
 
void o_jmp (InstructionType type)
 JMP: jump directly to a different script offset. More...
 
void o_jsr (InstructionType type)
 JSR: call a subroutine. More...
 
void o_jz (InstructionType type)
 JZ: jump conditionally if the top-most stack element is 0. More...
 
void o_retn (InstructionType type)
 RETN: return from a subroutine call. More...
 
void o_destruct (InstructionType type)
 DESTRUCT: remove elements from the stack. More...
 
void o_not (InstructionType type)
 NOT: boolean-negate the top-most stack element (!). More...
 
void o_decsp (InstructionType type)
 DECSP: decrement the value of a stack element (–). More...
 
void o_incsp (InstructionType type)
 INCSP: increment the value of a stack element (++). More...
 
void o_jnz (InstructionType type)
 JNZ: jump conditionally if the top-most stack element is not 0. More...
 
void o_cpdownbp (InstructionType type)
 CPDOWNBP: copy a value into an existing base-pointer stack element. More...
 
void o_cptopbp (InstructionType type)
 CPTOPBP: push a copy of a base-pointer stack element on top of the stack. More...
 
void o_decbp (InstructionType type)
 DECBP: decrement the value of a base-pointer stack element (–). More...
 
void o_incbp (InstructionType type)
 INCBP: increment the value of a base-pointer stack element (++). More...
 
void o_savebp (InstructionType type)
 SAVEBP: set the value of the base-pointer. More...
 
void o_restorebp (InstructionType type)
 RESTOREBP: restore the value of the base-pointer to a prior value. More...
 
void o_storestate (InstructionType type)
 STORESTATE: create a functor of a subroutine with the current stack. More...
 
void o_writearray (InstructionType type)
 WRITEARRAY: write the value of an array element on the stack. More...
 
void o_readarray (InstructionType type)
 READARRAY: push the value of an array element onto of the stack. More...
 
void o_getref (InstructionType type)
 GETREF: push the reference to a stack element onto the stack. More...
 
void o_getrefarray (InstructionType type)
 GETREFARRAY: push the reference to an array element onto the stack. More...
 

Private Attributes

Common::UString _name
 
NCSStack _stack
 
Common::ScopedPtr< Common::SeekableReadStream_script
 
Variable _return
 
ObjectReference _owner
 
ObjectReference _triggerer
 
VariableContainer _env
 
std::stack< uint32_returnOffsets
 
Variable _storedState
 
const Opcode_opcodes
 
size_t _opcodeListSize
 

Additional Inherited Members

- Protected Member Functions inherited from Aurora::AuroraFile
void readHeader (Common::ReadStream &stream)
 
- Static Protected Member Functions inherited from Aurora::AuroraFile
static uint32 convertUTF16LE (uint32 x1, uint32 x2)
 
- Protected Attributes inherited from Aurora::AuroraFile
uint32 _id
 The file's ID. More...
 
uint32 _version
 The file's version. More...
 
bool _utf16le
 The file's ID and version are in little-endian UTF-16. More...
 

Detailed Description

An NCS, BioWare's NWN Compile Script.

Definition at line 86 of file ncsfile.h.

Member Typedef Documentation

◆ OpcodeProc

typedef void(NCSFile::* Aurora::NWScript::NCSFile::OpcodeProc) (InstructionType type)
private

Definition at line 183 of file ncsfile.h.

Member Enumeration Documentation

◆ InstructionType

Enumerator
kInstTypeNone 
kInstTypeDirect 
kInstTypeInt 
kInstTypeFloat 
kInstTypeString 
kInstTypeObject 
kInstTypeResource 
kInstTypeEngineType0 
kInstTypeEngineType1 
kInstTypeEngineType2 
kInstTypeEngineType3 
kInstTypeEngineType4 
kInstTypeEngineType5 
kInstTypeIntArray 
kInstTypeFloatArray 
kInstTypeStringArray 
kInstTypeObjectArray 
kInstTypeResourceArray 
kInstTypeEngineType0Array 
kInstTypeEngineType1Array 
kInstTypeEngineType2Array 
kInstTypeEngineType3Array 
kInstTypeEngineType4Array 
kInstTypeEngineType5Array 
kInstTypeIntInt 
kInstTypeFloatFloat 
kInstTypeObjectObject 
kInstTypeStringString 
kInstTypeStructStruct 
kInstTypeIntFloat 
kInstTypeFloatInt 
kInstTypeEngineType0EngineType0 
kInstTypeEngineType1EngineType1 
kInstTypeEngineType2EngineType2 
kInstTypeEngineType3EngineType3 
kInstTypeEngineType4EngineType4 
kInstTypeEngineType5EngineType5 
kInstTypeVectorVector 
kInstTypeVectorFloat 
kInstTypeFloatVector 

Definition at line 119 of file ncsfile.h.

Constructor & Destructor Documentation

◆ NCSFile() [1/2]

Aurora::NWScript::NCSFile::NCSFile ( Common::SeekableReadStream ncs)

Definition at line 277 of file ncsfile.cpp.

References _script, and load().

Here is the call graph for this function:

◆ NCSFile() [2/2]

Aurora::NWScript::NCSFile::NCSFile ( const Common::UString ncs)

Definition at line 283 of file ncsfile.cpp.

References _script, Common::UString::c_str(), Aurora::kFileTypeNCS, load(), Common::ScopedPtrBase< T, Deallocator >::reset(), and ResMan.

Here is the call graph for this function:

◆ ~NCSFile()

Aurora::NWScript::NCSFile::~NCSFile ( )

Definition at line 291 of file ncsfile.cpp.

Member Function Documentation

◆ callEngine()

void Aurora::NWScript::NCSFile::callEngine ( Aurora::NWScript::FunctionContext ctx,
uint32  function,
uint8  argCount 
)
private

Helper function for o_action(), doing the actual engine function calling.

Definition at line 529 of file ncsfile.cpp.

References _owner, _stack, _storedState, _triggerer, Common::UString::c_str(), debugC(), FunctionMan, Aurora::NWScript::Variable::getFloat(), Aurora::NWScript::FunctionContext::getName(), Aurora::NWScript::FunctionContext::getParamMax(), Aurora::NWScript::FunctionContext::getParamMin(), Aurora::NWScript::FunctionContext::getParams(), Aurora::NWScript::FunctionContext::getReturn(), Aurora::NWScript::Variable::getScriptState(), Aurora::NWScript::Variable::getType(), Aurora::NWScript::Variable::getVector(), Common::kDebugScripts, Aurora::NWScript::kTypeAny, Aurora::NWScript::kTypeArray, Aurora::NWScript::kTypeEngineType, Aurora::NWScript::kTypeFloat, Aurora::NWScript::kTypeInt, Aurora::NWScript::kTypeObject, Aurora::NWScript::kTypeReference, Aurora::NWScript::kTypeScriptState, Aurora::NWScript::kTypeString, Aurora::NWScript::kTypeVector, Aurora::NWScript::kTypeVoid, Aurora::NWScript::NCSStack::pop(), Aurora::NWScript::NCSStack::push(), Aurora::NWScript::FunctionContext::setCaller(), Aurora::NWScript::FunctionContext::setCurrentScript(), Aurora::NWScript::FunctionContext::setParamsSpecified(), Aurora::NWScript::FunctionContext::setTriggerer(), Aurora::NWScript::Variable::setType(), Aurora::NWScript::Variable::setVector(), and Aurora::NWScript::NCSStack::top().

Referenced by o_action().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ decompile()

void Aurora::NWScript::NCSFile::decompile ( )
private

Definition at line 428 of file ncsfile.cpp.

References _script.

◆ execute()

const Variable & Aurora::NWScript::NCSFile::execute ( const ObjectReference  owner = ObjectReference(),
const ObjectReference  triggerer = ObjectReference() 
)
private

◆ executeStep()

bool Aurora::NWScript::NCSFile::executeStep ( )
private

Execute one script step.

Definition at line 404 of file ncsfile.cpp.

References _opcodeListSize, _opcodes, _returnOffsets, _script, _stack, debugC(), Common::kDebugScripts, Aurora::NWScript::NCSStack::print(), and Aurora::NWScript::NCSFile::Opcode::proc.

Referenced by execute().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getEmptyState()

ScriptState Aurora::NWScript::NCSFile::getEmptyState ( )
static

◆ getEnvironment()

VariableContainer & Aurora::NWScript::NCSFile::getEnvironment ( )

Return the script's environment variables.

Environment variables can be set by script engine functions and will persist for the whole run of the script. Similar to an environment in a UNIX shell, if the script spawns off a second script, that child script will inherit the environment of its parent script.

Definition at line 298 of file ncsfile.cpp.

References _env.

Referenced by Aurora::NWScript::FunctionContext::getCurrentEnvironment(), Engines::DragonAge2::ScriptContainer::runScript(), and Engines::DragonAge::ScriptContainer::runScript().

Here is the caller graph for this function:

◆ getName()

const Common::UString & Aurora::NWScript::NCSFile::getName ( ) const

◆ load()

void Aurora::NWScript::NCSFile::load ( )
private

Definition at line 314 of file ncsfile.cpp.

References Aurora::AuroraFile::_id, _script, Aurora::AuroraFile::_version, kNCSTag, Aurora::kVersion10, Aurora::AuroraFile::readHeader(), reset(), setupOpcodes(), and warning().

Referenced by NCSFile().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ o_action()

void Aurora::NWScript::NCSFile::o_action ( InstructionType  type)
private

ACTION: call a game-specific engine function.

Definition at line 625 of file ncsfile.cpp.

References _script, Common::StackException::add(), Common::UString::c_str(), callEngine(), FunctionMan, Aurora::NWScript::FunctionContext::getName(), and kInstTypeNone.

Referenced by setupOpcodes().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ o_add()

void Aurora::NWScript::NCSFile::o_add ( InstructionType  type)
private

◆ o_booland()

void Aurora::NWScript::NCSFile::o_booland ( InstructionType  type)
private

BOOLAND: perform a bit-wise AND (&).

Definition at line 684 of file ncsfile.cpp.

References _stack, Aurora::NWScript::Variable::getInt(), kInstTypeIntInt, Aurora::NWScript::NCSStack::pop(), and Aurora::NWScript::NCSStack::push().

Referenced by setupOpcodes().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ o_comp()

void Aurora::NWScript::NCSFile::o_comp ( InstructionType  type)
private

COMP: calculate the 1-complement of the top-most stack element (~).

Definition at line 926 of file ncsfile.cpp.

References _stack, Aurora::NWScript::Variable::getInt(), kInstTypeInt, Aurora::NWScript::NCSStack::pop(), and Aurora::NWScript::NCSStack::push().

Referenced by setupOpcodes().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ o_const()

void Aurora::NWScript::NCSFile::o_const ( InstructionType  type)
private

CONST: push a constant (predetermined value) variable onto the stack.

Definition at line 482 of file ncsfile.cpp.

References _owner, _script, _stack, Common::kEncodingASCII, kInstTypeFloat, kInstTypeInt, kInstTypeObject, kInstTypeResource, kInstTypeString, kScriptObjectInvalid, kScriptObjectInvalid2, kScriptObjectSelf, kScriptObjectTypeInvalid, Aurora::NWScript::NCSStack::push(), and Common::readStringFixed().

Referenced by setupOpcodes().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ o_cpdownbp()

void Aurora::NWScript::NCSFile::o_cpdownbp ( InstructionType  type)
private

CPDOWNBP: copy a value into an existing base-pointer stack element.

Used to write into a global variable.

Definition at line 1423 of file ncsfile.cpp.

References _script, _stack, Aurora::NWScript::NCSStack::getRelSP(), kInstTypeDirect, and Aurora::NWScript::NCSStack::setRelBP().

Referenced by setupOpcodes().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ o_cpdownsp()

void Aurora::NWScript::NCSFile::o_cpdownsp ( InstructionType  type)
private

CPDOWNSP: copy a value into an existing stack element.

Definition at line 1049 of file ncsfile.cpp.

References _script, _stack, Aurora::NWScript::NCSStack::getRelSP(), kInstTypeDirect, and Aurora::NWScript::NCSStack::setRelSP().

Referenced by setupOpcodes().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ o_cptopbp()

void Aurora::NWScript::NCSFile::o_cptopbp ( InstructionType  type)
private

CPTOPBP: push a copy of a base-pointer stack element on top of the stack.

Used to read from a global variable.

Definition at line 1447 of file ncsfile.cpp.

References _script, _stack, Aurora::NWScript::NCSStack::getRelBP(), kInstTypeDirect, and Aurora::NWScript::NCSStack::push().

Referenced by setupOpcodes().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ o_cptopsp()

void Aurora::NWScript::NCSFile::o_cptopsp ( InstructionType  type)
private

CPTOPSP: push a copy of a stack element on top of the stack.

Definition at line 1070 of file ncsfile.cpp.

References _script, _stack, Aurora::NWScript::NCSStack::getRelSP(), kInstTypeDirect, and Aurora::NWScript::NCSStack::push().

Referenced by setupOpcodes().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ o_decbp()

void Aurora::NWScript::NCSFile::o_decbp ( InstructionType  type)
private

DECBP: decrement the value of a base-pointer stack element (–).

Definition at line 1001 of file ncsfile.cpp.

References _script, _stack, Aurora::NWScript::Variable::getInt(), Aurora::NWScript::NCSStack::getRelBP(), kInstTypeInt, and Aurora::NWScript::NCSStack::setRelBP().

Referenced by setupOpcodes().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ o_decsp()

void Aurora::NWScript::NCSFile::o_decsp ( InstructionType  type)
private

DECSP: decrement the value of a stack element (–).

Definition at line 970 of file ncsfile.cpp.

References _script, _stack, Aurora::NWScript::Variable::getInt(), Aurora::NWScript::NCSStack::getRelSP(), kInstTypeInt, and Aurora::NWScript::NCSStack::setRelSP().

Referenced by setupOpcodes().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ o_destruct()

void Aurora::NWScript::NCSFile::o_destruct ( InstructionType  type)
private

DESTRUCT: remove elements from the stack.

Used to isolate struct elements.

Definition at line 1389 of file ncsfile.cpp.

References _script, _stack, Aurora::NWScript::NCSStack::pop(), Aurora::NWScript::NCSStack::push(), and Aurora::NWScript::NCSStack::top().

Referenced by setupOpcodes().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ o_div()

void Aurora::NWScript::NCSFile::o_div ( InstructionType  type)
private

DIV: divide the top-most stack elements (/).

Definition at line 1268 of file ncsfile.cpp.

References _stack, Aurora::NWScript::Variable::getFloat(), Aurora::NWScript::Variable::getInt(), INT32_MIN, kInstTypeFloatFloat, kInstTypeFloatInt, kInstTypeFloatVector, kInstTypeIntFloat, kInstTypeIntInt, kInstTypeVectorFloat, Aurora::NWScript::NCSStack::pop(), and Aurora::NWScript::NCSStack::push().

Referenced by setupOpcodes().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ o_eq()

void Aurora::NWScript::NCSFile::o_eq ( InstructionType  type)
private

EQ: compare the top-most stack elements for equality (==).

Definition at line 694 of file ncsfile.cpp.

References _script, _stack, kInstTypeStructStruct, Aurora::NWScript::NCSStack::pop(), and Aurora::NWScript::NCSStack::push().

Referenced by setupOpcodes().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ o_excor()

void Aurora::NWScript::NCSFile::o_excor ( InstructionType  type)
private

EXCOR: perform a bit-wise exclusive OR (^).

Definition at line 674 of file ncsfile.cpp.

References _stack, Aurora::NWScript::Variable::getInt(), kInstTypeIntInt, Aurora::NWScript::NCSStack::pop(), and Aurora::NWScript::NCSStack::push().

Referenced by setupOpcodes().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ o_geq()

void Aurora::NWScript::NCSFile::o_geq ( InstructionType  type)
private

GEQ: compare the top-most stack elements, greater-or-equal (>=).

Definition at line 752 of file ncsfile.cpp.

References _stack, Aurora::NWScript::Variable::getFloat(), Aurora::NWScript::Variable::getInt(), kInstTypeFloatFloat, kInstTypeIntInt, Aurora::NWScript::NCSStack::pop(), and Aurora::NWScript::NCSStack::push().

Referenced by setupOpcodes().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ o_getref()

void Aurora::NWScript::NCSFile::o_getref ( InstructionType  type)
private

GETREF: push the reference to a stack element onto the stack.

Creates a reference to a variable, usually an engine type like Event or Effect, so that it can be modified by an engine function directly, without having to create a modified copy. Added with Dragon Age II.

The offset to the variable to create a reference to is passed as a direct argument to the instruction.

Definition at line 1573 of file ncsfile.cpp.

References _script, _stack, Aurora::NWScript::NCSStack::getRelSP(), kInstTypeDirect, Aurora::NWScript::kTypeReference, Aurora::NWScript::NCSStack::push(), Aurora::NWScript::Variable::setReference(), and Aurora::NWScript::NCSStack::top().

Referenced by setupOpcodes().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ o_getrefarray()

void Aurora::NWScript::NCSFile::o_getrefarray ( InstructionType  type)
private

GETREFARRAY: push the reference to an array element onto the stack.

Like GETREF, this creates a reference to a variable, usually an engine type like Event or Effect, so that it can be modified by an engine function directly, without having to create a modified copy. GETREFARRAY, however, create a reference to a variable held inside a dynamic array variable. Added with Dragon Age II.

The index of the array is at the top-most stack position; the offset to the array variable is passed as a direct argument to the instruction.

The index is popped off the stack, and the reference to the variable inside the array is pushed on top.

Definition at line 1604 of file ncsfile.cpp.

References _script, _stack, Aurora::NWScript::Variable::getArray(), Aurora::NWScript::Variable::getInt(), Aurora::NWScript::NCSStack::getRelSP(), kInstTypeDirect, Aurora::NWScript::kTypeReference, Aurora::NWScript::NCSStack::pop(), Aurora::NWScript::NCSStack::push(), Aurora::NWScript::Variable::setReference(), and Aurora::NWScript::NCSStack::top().

Referenced by setupOpcodes().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ o_gt()

void Aurora::NWScript::NCSFile::o_gt ( InstructionType  type)
private

GT: compare the top-most stack elements, greater (>).

Definition at line 776 of file ncsfile.cpp.

References _stack, Aurora::NWScript::Variable::getFloat(), Aurora::NWScript::Variable::getInt(), kInstTypeFloatFloat, kInstTypeIntInt, Aurora::NWScript::NCSStack::pop(), and Aurora::NWScript::NCSStack::push().

Referenced by setupOpcodes().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ o_incbp()

void Aurora::NWScript::NCSFile::o_incbp ( InstructionType  type)
private

INCBP: increment the value of a base-pointer stack element (++).

Definition at line 1011 of file ncsfile.cpp.

References _script, _stack, Aurora::NWScript::Variable::getInt(), Aurora::NWScript::NCSStack::getRelBP(), kInstTypeInt, and Aurora::NWScript::NCSStack::setRelBP().

Referenced by setupOpcodes().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ o_incor()

void Aurora::NWScript::NCSFile::o_incor ( InstructionType  type)
private

INCOR: perform a bit-wise inclusive OR (|).

Definition at line 664 of file ncsfile.cpp.

References _stack, Aurora::NWScript::Variable::getInt(), kInstTypeIntInt, Aurora::NWScript::NCSStack::pop(), and Aurora::NWScript::NCSStack::push().

Referenced by setupOpcodes().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ o_incsp()

void Aurora::NWScript::NCSFile::o_incsp ( InstructionType  type)
private

INCSP: increment the value of a stack element (++).

Definition at line 980 of file ncsfile.cpp.

References _script, _stack, Aurora::NWScript::Variable::getInt(), Aurora::NWScript::NCSStack::getRelSP(), kInstTypeInt, and Aurora::NWScript::NCSStack::setRelSP().

Referenced by setupOpcodes().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ o_jmp()

void Aurora::NWScript::NCSFile::o_jmp ( InstructionType  type)
private

JMP: jump directly to a different script offset.

Definition at line 942 of file ncsfile.cpp.

References _script, and kInstTypeNone.

Referenced by setupOpcodes().

Here is the caller graph for this function:

◆ o_jnz()

void Aurora::NWScript::NCSFile::o_jnz ( InstructionType  type)
private

JNZ: jump conditionally if the top-most stack element is not 0.

Definition at line 990 of file ncsfile.cpp.

References _script, _stack, Aurora::NWScript::Variable::getInt(), kInstTypeNone, and Aurora::NWScript::NCSStack::pop().

Referenced by setupOpcodes().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ o_jsr()

void Aurora::NWScript::NCSFile::o_jsr ( InstructionType  type)
private

JSR: call a subroutine.

Definition at line 1362 of file ncsfile.cpp.

References _returnOffsets, _script, and kInstTypeNone.

Referenced by setupOpcodes().

Here is the caller graph for this function:

◆ o_jz()

void Aurora::NWScript::NCSFile::o_jz ( InstructionType  type)
private

JZ: jump conditionally if the top-most stack element is 0.

Definition at line 951 of file ncsfile.cpp.

References _script, _stack, Aurora::NWScript::Variable::getInt(), kInstTypeNone, and Aurora::NWScript::NCSStack::pop().

Referenced by setupOpcodes().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ o_leq()

void Aurora::NWScript::NCSFile::o_leq ( InstructionType  type)
private

LEQ: compare the top-most stack elements, less-or-equal (<=).

Definition at line 824 of file ncsfile.cpp.

References _stack, Aurora::NWScript::Variable::getFloat(), Aurora::NWScript::Variable::getInt(), kInstTypeFloatFloat, kInstTypeIntInt, Aurora::NWScript::NCSStack::pop(), and Aurora::NWScript::NCSStack::push().

Referenced by setupOpcodes().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ o_logand()

void Aurora::NWScript::NCSFile::o_logand ( InstructionType  type)
private

LOGAND: perform a logical boolean AND (&&).

Definition at line 644 of file ncsfile.cpp.

References _stack, Aurora::NWScript::Variable::getInt(), kInstTypeIntInt, Aurora::NWScript::NCSStack::pop(), and Aurora::NWScript::NCSStack::push().

Referenced by setupOpcodes().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ o_logor()

void Aurora::NWScript::NCSFile::o_logor ( InstructionType  type)
private

LOGOR: perform a logical boolean OR (||).

Definition at line 654 of file ncsfile.cpp.

References _stack, Aurora::NWScript::Variable::getInt(), kInstTypeIntInt, Aurora::NWScript::NCSStack::pop(), and Aurora::NWScript::NCSStack::push().

Referenced by setupOpcodes().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ o_lt()

void Aurora::NWScript::NCSFile::o_lt ( InstructionType  type)
private

LT: compare the top-most stack elements, less (<).

Definition at line 800 of file ncsfile.cpp.

References _stack, Aurora::NWScript::Variable::getFloat(), Aurora::NWScript::Variable::getInt(), kInstTypeFloatFloat, kInstTypeIntInt, Aurora::NWScript::NCSStack::pop(), and Aurora::NWScript::NCSStack::push().

Referenced by setupOpcodes().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ o_mod()

void Aurora::NWScript::NCSFile::o_mod ( InstructionType  type)
private

MOD: calculate the remainder (modulo) of an integer division (%).

Definition at line 894 of file ncsfile.cpp.

References _stack, Aurora::NWScript::Variable::getInt(), kInstTypeIntInt, Aurora::NWScript::NCSStack::pop(), and Aurora::NWScript::NCSStack::push().

Referenced by setupOpcodes().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ o_movsp()

void Aurora::NWScript::NCSFile::o_movsp ( InstructionType  type)
private

MOVSP: pop elements off the stack.

Definition at line 934 of file ncsfile.cpp.

References _script, _stack, Aurora::NWScript::NCSStack::getStackPtr(), kInstTypeNone, and Aurora::NWScript::NCSStack::setStackPtr().

Referenced by setupOpcodes().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ o_mul()

void Aurora::NWScript::NCSFile::o_mul ( InstructionType  type)
private

MUL: multiply the top-most stack elements (*).

Definition at line 1204 of file ncsfile.cpp.

References _stack, Aurora::NWScript::Variable::getFloat(), Aurora::NWScript::Variable::getInt(), kInstTypeFloatFloat, kInstTypeFloatInt, kInstTypeFloatVector, kInstTypeIntFloat, kInstTypeIntInt, kInstTypeVectorFloat, Aurora::NWScript::NCSStack::pop(), and Aurora::NWScript::NCSStack::push().

Referenced by setupOpcodes().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ o_neg()

void Aurora::NWScript::NCSFile::o_neg ( InstructionType  type)
private

NEQ: negate the top-most stack element (unary -).

Definition at line 910 of file ncsfile.cpp.

References _stack, Aurora::NWScript::Variable::getFloat(), Aurora::NWScript::Variable::getInt(), kInstTypeFloat, kInstTypeInt, Aurora::NWScript::NCSStack::pop(), and Aurora::NWScript::NCSStack::push().

Referenced by setupOpcodes().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ o_neq()

void Aurora::NWScript::NCSFile::o_neq ( InstructionType  type)
private

NEQ: compare the top-most stack elements for inequality (!=).

Definition at line 723 of file ncsfile.cpp.

References _script, _stack, kInstTypeStructStruct, Aurora::NWScript::NCSStack::pop(), and Aurora::NWScript::NCSStack::push().

Referenced by setupOpcodes().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ o_nop()

void Aurora::NWScript::NCSFile::o_nop ( InstructionType  type)
private

NOP: no operation.

Definition at line 1044 of file ncsfile.cpp.

Referenced by setupOpcodes().

Here is the caller graph for this function:

◆ o_not()

void Aurora::NWScript::NCSFile::o_not ( InstructionType  type)
private

NOT: boolean-negate the top-most stack element (!).

Definition at line 962 of file ncsfile.cpp.

References _stack, Aurora::NWScript::Variable::getInt(), kInstTypeInt, Aurora::NWScript::NCSStack::pop(), and Aurora::NWScript::NCSStack::push().

Referenced by setupOpcodes().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ o_readarray()

void Aurora::NWScript::NCSFile::o_readarray ( InstructionType  type)
private

READARRAY: push the value of an array element onto of the stack.

Reads out of the dynamic array variables types added with Dragon Age: Origins.

The index of the array to read is at the top-most stack position; the offset to the array variable is passed as a direct argument to the instruction.

The index is popped off the stack, and the value read out of the array is pushed on top.

Definition at line 1541 of file ncsfile.cpp.

References _script, _stack, Aurora::NWScript::Variable::getArray(), Aurora::NWScript::Variable::getInt(), Aurora::NWScript::NCSStack::getRelSP(), kInstTypeDirect, Aurora::NWScript::NCSStack::pop(), and Aurora::NWScript::NCSStack::push().

Referenced by setupOpcodes().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ o_restorebp()

void Aurora::NWScript::NCSFile::o_restorebp ( InstructionType  type)
private

RESTOREBP: restore the value of the base-pointer to a prior value.

Destroy the global variables anchor point after use.

Definition at line 1036 of file ncsfile.cpp.

References _stack, Aurora::NWScript::Variable::getInt(), kInstTypeNone, Aurora::NWScript::NCSStack::pop(), and Aurora::NWScript::NCSStack::setBasePtr().

Referenced by setupOpcodes().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ o_retn()

void Aurora::NWScript::NCSFile::o_retn ( InstructionType  type)
private

RETN: return from a subroutine call.

Definition at line 1375 of file ncsfile.cpp.

References _returnOffsets, and _script.

Referenced by setupOpcodes().

Here is the caller graph for this function:

◆ o_rsadd()

void Aurora::NWScript::NCSFile::o_rsadd ( InstructionType  type)
private

◆ o_savebp()

void Aurora::NWScript::NCSFile::o_savebp ( InstructionType  type)
private

SAVEBP: set the value of the base-pointer.

Used to create an anchor point to access global variables.

Definition at line 1024 of file ncsfile.cpp.

References _stack, Aurora::NWScript::NCSStack::getBasePtr(), Aurora::NWScript::NCSStack::getStackPtr(), kInstTypeNone, Aurora::NWScript::NCSStack::push(), and Aurora::NWScript::NCSStack::setBasePtr().

Referenced by setupOpcodes().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ o_shleft()

void Aurora::NWScript::NCSFile::o_shleft ( InstructionType  type)
private

SHLEFT: shift the top-most stack element to the left (<<).

Definition at line 848 of file ncsfile.cpp.

References _stack, Aurora::NWScript::Variable::getInt(), kInstTypeIntInt, Aurora::NWScript::NCSStack::pop(), and Aurora::NWScript::NCSStack::push().

Referenced by setupOpcodes().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ o_shright()

void Aurora::NWScript::NCSFile::o_shright ( InstructionType  type)
private

SHRIGHT: signed-shift the top-most stack element to the right (>>>).

Definition at line 858 of file ncsfile.cpp.

References _stack, Aurora::NWScript::Variable::getInt(), kInstTypeIntInt, Aurora::NWScript::NCSStack::pop(), and Aurora::NWScript::NCSStack::push().

Referenced by setupOpcodes().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ o_storestate()

void Aurora::NWScript::NCSFile::o_storestate ( InstructionType  type)
private

STORESTATE: create a functor of a subroutine with the current stack.

Used to create the "action" variables when calling an engine function that assigns a function to an object, or delays a function, or similar.

Definition at line 1470 of file ncsfile.cpp.

References _script, _stack, _storedState, Aurora::NWScript::NCSStack::getRelBP(), Aurora::NWScript::NCSStack::getRelSP(), Aurora::NWScript::Variable::getScriptState(), Aurora::NWScript::ScriptState::globals, Aurora::NWScript::kTypeScriptState, Aurora::NWScript::ScriptState::locals, Aurora::NWScript::ScriptState::offset, and Aurora::NWScript::Variable::setType().

Referenced by setupOpcodes().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ o_storestateall()

void Aurora::NWScript::NCSFile::o_storestateall ( InstructionType  type)
private

STORESTATEALL: unused, obsolete opcode.

Hopefully.

Definition at line 1353 of file ncsfile.cpp.

References warning().

Referenced by setupOpcodes().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ o_sub()

void Aurora::NWScript::NCSFile::o_sub ( InstructionType  type)
private

SUB: subtract the top-most stack elements (-).

Definition at line 1150 of file ncsfile.cpp.

References _stack, Aurora::NWScript::Variable::getFloat(), Aurora::NWScript::Variable::getInt(), kInstTypeFloatFloat, kInstTypeFloatInt, kInstTypeIntFloat, kInstTypeIntInt, kInstTypeVectorVector, Aurora::NWScript::NCSStack::pop(), and Aurora::NWScript::NCSStack::push().

Referenced by setupOpcodes().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ o_ushright()

void Aurora::NWScript::NCSFile::o_ushright ( InstructionType  type)
private

USHRIGHT: shift the top-most stack element to the right (>>).

Definition at line 879 of file ncsfile.cpp.

References _stack, Aurora::NWScript::Variable::getInt(), kInstTypeIntInt, Aurora::NWScript::NCSStack::pop(), and Aurora::NWScript::NCSStack::push().

Referenced by setupOpcodes().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ o_writearray()

void Aurora::NWScript::NCSFile::o_writearray ( InstructionType  type)
private

WRITEARRAY: write the value of an array element on the stack.

Writes into the dynamic array variables types added with Dragon Age: Origins.

The index of the array to write and the value to write are at the top-most stack position; the offset to the array variable is passed as a direct argument to the instruction.

The index is popped off the stack, but the value written remains.

Definition at line 1506 of file ncsfile.cpp.

References _script, _stack, Aurora::NWScript::Variable::getArray(), Aurora::NWScript::Variable::getInt(), Aurora::NWScript::NCSStack::getRelSP(), Aurora::NWScript::Variable::getType(), Aurora::NWScript::Variable::growArray(), kInstTypeDirect, Aurora::NWScript::NCSStack::pop(), and Aurora::NWScript::NCSStack::top().

Referenced by setupOpcodes().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ reset()

void Aurora::NWScript::NCSFile::reset ( )
private

Reset the script for another execution.

Definition at line 338 of file ncsfile.cpp.

References _return, _returnOffsets, _script, _stack, _storedState, Aurora::NWScript::kTypeVoid, Aurora::NWScript::NCSStack::reset(), and Aurora::NWScript::Variable::setType().

Referenced by load(), and run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ run() [1/4]

const Variable & Aurora::NWScript::NCSFile::run ( Object owner = 0,
Object triggerer = 0 
)

◆ run() [2/4]

const Variable & Aurora::NWScript::NCSFile::run ( const ObjectReference  owner = ObjectReference(),
const ObjectReference  triggerer = ObjectReference() 
)

Definition at line 354 of file ncsfile.cpp.

References getEmptyState(), and run().

Here is the call graph for this function:

◆ run() [3/4]

const Variable & Aurora::NWScript::NCSFile::run ( const ScriptState state,
Object owner = 0,
Object triggerer = 0 
)

Run the current script, from this state to finish.

Definition at line 358 of file ncsfile.cpp.

References run().

Here is the call graph for this function:

◆ run() [4/4]

const Variable & Aurora::NWScript::NCSFile::run ( const ScriptState state,
const ObjectReference  owner = ObjectReference(),
const ObjectReference  triggerer = ObjectReference() 
)

◆ setEnvironment()

void Aurora::NWScript::NCSFile::setEnvironment ( const VariableContainer env)

Overwrite the environment.

Definition at line 302 of file ncsfile.cpp.

References _env.

Referenced by Engines::Witcher::Functions::executeScript(), Engines::NWN::Functions::executeScript(), and Engines::NWN2::Functions::executeScript().

Here is the caller graph for this function:

◆ setupOpcodes()

void Aurora::NWScript::NCSFile::setupOpcodes ( )
private

Member Data Documentation

◆ _env

VariableContainer Aurora::NWScript::NCSFile::_env
private

Definition at line 177 of file ncsfile.h.

Referenced by getEnvironment(), and setEnvironment().

◆ _name

Common::UString Aurora::NWScript::NCSFile::_name
private

Definition at line 167 of file ncsfile.h.

Referenced by execute(), getName(), and run().

◆ _opcodeListSize

size_t Aurora::NWScript::NCSFile::_opcodeListSize
private

Definition at line 189 of file ncsfile.h.

Referenced by executeStep(), and setupOpcodes().

◆ _opcodes

const Opcode* Aurora::NWScript::NCSFile::_opcodes
private

Definition at line 188 of file ncsfile.h.

Referenced by executeStep(), and setupOpcodes().

◆ _owner

ObjectReference Aurora::NWScript::NCSFile::_owner
private

Definition at line 174 of file ncsfile.h.

Referenced by callEngine(), execute(), and o_const().

◆ _return

Variable Aurora::NWScript::NCSFile::_return
private

Definition at line 172 of file ncsfile.h.

Referenced by execute(), and reset().

◆ _returnOffsets

std::stack<uint32> Aurora::NWScript::NCSFile::_returnOffsets
private

Definition at line 179 of file ncsfile.h.

Referenced by executeStep(), o_jsr(), o_retn(), and reset().

◆ _script

Common::ScopedPtr<Common::SeekableReadStream> Aurora::NWScript::NCSFile::_script
private

◆ _stack

NCSStack Aurora::NWScript::NCSFile::_stack
private

◆ _storedState

Variable Aurora::NWScript::NCSFile::_storedState
private

Definition at line 181 of file ncsfile.h.

Referenced by callEngine(), o_storestate(), and reset().

◆ _triggerer

ObjectReference Aurora::NWScript::NCSFile::_triggerer
private

Definition at line 175 of file ncsfile.h.

Referenced by callEngine(), and execute().


The documentation for this class was generated from the following files: