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 
 
CLR/managed script (C# or other .NET) engine integration

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



Joined: 03 Jan 2008
Posts: 321

PostPosted: Sat Dec 24, 2011 11:07    Post subject: CLR/managed script (C# or other .NET) engine integration Reply with quote



The next NWScript Accelerator plugin release (not yet posted) will include support for writing game scripts in CLR languages, which is off by default but can be enabled in the configuration file.

SDK is available here.
Download the NWScript Accelerator with CLR script support here.
You must set AllowManagedScripts=1 in AuroraServerNWScript.ini under [Settings], and you must upgrade ALL of the plugin DLLs.

CLR scripts have full access to both all CLR APIs and all NWScript.nss engine function APIs (including functions that take 'action' arguments, like DelayCommand!). Consequently, CLR scripts enable the construction of script customizations with greatly expanded capabilities compared to standard NWScript scripts. In addition, the integration model allows for seamless integration to engine event handlers (anywhere a conventional NWScript script can be referenced in an object template or event handler, a CLR script can be substituted). This permits a more natural way to expand advanced capabilities into the server than the traditional NWNX4 plugin approach.

CLR scripts are packaged into specially-formatted .ncs files that are referenced like any other script. They are specially recognized to be a CLR script and not a NWScript-language script by the NWScript Accelerator plugin. These specially-formatted .ncs files can be distributed via .hak files, or included in the module proper. Anywhere that a conventional .ncs script could be referenced, a packaged CLR script can be substituted seamlessly.

Each CLR script is contained within its own assembly and module (one .dll that is packaged into a specially-formatted .ncs file). Any tool .NET development environment, such as csc.exe or Visual Studio, can be used to build CLR scripts. The associated NWScript Accelerator release will include a tool to package CLR script DLL modules into .ncs files that can be consumed by a server with CLR script support enabled. In addition, a sample script and a reference assembly exposing the server engine function APIs will be included.

CLR scripts can, via appropriate use of reflection, make calls to script functions exposed by other scripts (including plain NWScript scripts that have been JIT'd to .NET by the NWScript accelerator library). This allows re-use and interoperability with existing library code already written in NWScript, on a per-function level, without requiring that all existing scripts be reimplemented in managed code.

A CLR script starts out by declaring a class deriving from a NWScript Accelerator plugin defined interface, IGeneratedScriptProgram. The NWScript Accelerator object will create instances of this class and call a series of interface methods when the script is invoked by the game server. The supplied reference assembly exposes the full engine action function API surface as natively referenceable CLR functions.

A prerelease example script program written in C# can be found here. The version included in the final release will include delegate wrappers for 'action' handlers and friendlier names for engine functions.


Last edited by Skywing on Sun Feb 17, 2013 20:49; edited 3 times in total
Back to top
View user's profile Send private message
Skywing



Joined: 03 Jan 2008
Posts: 321

PostPosted: Sun Dec 25, 2011 10:04    Post subject: Reply with quote

An updated SDK has been posted. The SDK includes four sample scripts, including samples for .NET 4.0 and .NET 2.0. All CLR scripts run under .NET 4.0, but earlier .NET versions can be targetted to allow CLR scripts to be built previous Visual Studio versions.

Visual Studio 2005 or newer is required to use the IDE to build scripts. Alternatively, csc.exe and MSBuild.exe are included with .NET framework client installations and can be used to build CLR scripts on most machines, even if Visual Studio is not installed.

A basic tutorial for creating CLR scripts is included in the SDK.
Back to top
View user's profile Send private message
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