Aller au contenu

Photo

Advanced Script Compiler for NWN1 release thread


  • Veuillez vous connecter pour répondre
81 réponses à ce sujet

#1
SkywingvL

SkywingvL
  • Members
  • 351 messages

[Main thread]

The Advanced Scirpt Compiler (old, defunct vault page) is an updated and renovated version of Torlack's script compiler (otherwise sometimes known as the "PRC script compiler").  Because the other compiler forks no longer have any interested maintainer, I am taking over maintainership for the open source compiler project.

The project includes a new standalone script compiler (NWNScriptCompiler.exe), which is compatible with both NWN1 and NWN2.  Only Windows builds of the updated compiler are available right now.

Additionally, a toolset compiler plugin for the NWN2 toolset is included in the release package.  The NWN2 toolset plugin changes the toolset to use the improved compiler (which is likely not of interest to this forum).

Virusman produces a toolset compiler plugin for the NWN1 toolset, NWNTX, which you can find here.  (Both projects share the same compiler core module and will pick up improvements to the compiler as time goes on.)  If you prefer working with the toolset as your compiler and editor, I recommend using virusman's plugin instead of the standalone compiler; compiler functionality is equivalent in both packages.

Details on compiler improvements versus Torlack's compiler and the standard BioWare toolset compiler can be found in the readme notes of the distribution.  In summary, numerous compiler bugs (including some bad code generation issues) have been fixed, and many new compile time errors and warnings are available that help detect potentially problematic issues with scripts being compiled.  Additionally, many constructs that are incompatible for one reason or another with the standard BioWare toolset compiler will emit a warning if compiler version 1.69 or earlier is requested, to aid content creators in avoiding introducing incompatibilities with the standard BioWare toolset compiler (which has various bugs and non-obvious internal limitations).

Typical usage of NWNScriptCompiler.exe for compiling projects with NWN1, if you are in the directory containing your module's scripts and module.ifo, is:

NWNScriptCompiler.exe -1clov1.69 -r . -n "path to NWN1 install" *.nss

Command line syntax is compatible with (and an extension of) the old nwnnsscomp syntax.  You may specify raw fileystem include paths via -i, if you do not want the compiler to search in the game's data files for includes and nwscript.nss (in which case you would want to omit the -l option).  If you want to compile freestanding scripts not associated with a module, the '-r .' option can be omitted.

Additional documentation is available by running the compiler on the command line, or by looking in the readme documentation in the release package on NWVault linked at the top of the thread.


Modifié par SkywingvL, 29 juin 2014 - 01:05 .


#2
FunkySwerve

FunkySwerve
  • Members
  • 1 308 messages
I tried swapping in this exe for our nwnnsscomp.exe in the bat file we have been using to compile. Here's the modified bat:

@ECHO OFF
set mask="%1*.nss"
CD C:\\NeverwinterNights\\NWN\\MODULES\\TEMP0
..\\..\\NWNScriptCompiler.EXE -cego %mask%
CD ..\\..
PAUSE
This is with the exe in the NWN folder, same as the old exe. I then tried to compile all fky_ prefixed scripts, and got the resulting errors:

Error: Failed to process file "fky_chat_inf_inc.nss".
Compiling: fky_chat_instant.NSS
Unable to load nwscript.nss
Failed to initialize compiler; compilation aborted.
Compilation aborted with errors.
Error: Failed to process file "fky_chat_instant.nss".
Compiling: fky_chat_levelup.NSS
Unable to load nwscript.nss
Failed to initialize compiler; compilation aborted.
Compilation aborted with errors.
Error: Failed to process file "fky_chat_levelup.nss".
Compiling: fky_chat_local.NSS
Unable to load nwscript.nss
Failed to initialize compiler; compilation aborted.
Compilation aborted with errors.
Error: Failed to process file "fky_chat_local.nss".
Compiling: fky_chat_misc.NSS
Unable to load nwscript.nss
Failed to initialize compiler; compilation aborted.
Compilation aborted with errors.

*edit out a lot more of the same*
Total Execution time = 187ms
Press any key to continue . . .

C:\\NeverwinterNights\\NWN>
So I'm guessing it's not finding nwscript. :P Any idea what the problem is?

Thanks,
Funky

Modifié par FunkySwerve, 20 juin 2011 - 07:14 .


#3
Baaleos

Baaleos
  • Members
  • 1 315 messages
im just guessing at this point,
but could it be a typo in your path?

CD C:\\NeverwinterNights\\NWN\\MODULES\\TEMP0

should this not be

CD C:\\NeverwinterNights\\NWN\\MODULES\\TEMP.0


Perhaps the . (period) doesnt need to be present in the dos file path?

#4
FunkySwerve

FunkySwerve
  • Members
  • 1 308 messages
There isn't a period in the folder name. You're thinking of logs.0.

Funky

#5
SkywingvL

SkywingvL
  • Members
  • 351 messages

FunkySwerve wrote...

I tried swapping in this exe for our nwnnsscomp.exe in the bat file we have been using to compile. Here's the modified bat:

@ECHO OFF
set mask="%1*.nss"
CD C:NeverwinterNightsNWNMODULESTEMP0
....NWNScriptCompiler.EXE -cego %mask%
CD ....
PAUSE
This is with the exe in the NWN folder, same as the old exe. I then tried to compile all fky_ prefixed scripts, and got the resulting errors:

Error: Failed to process file "fky_chat_inf_inc.nss".
Compiling: fky_chat_instant.NSS
Unable to load nwscript.nss
Failed to initialize compiler; compilation aborted.
Compilation aborted with errors.
Error: Failed to process file "fky_chat_instant.nss".
Compiling: fky_chat_levelup.NSS
Unable to load nwscript.nss
Failed to initialize compiler; compilation aborted.
Compilation aborted with errors.
Error: Failed to process file "fky_chat_levelup.nss".
Compiling: fky_chat_local.NSS
Unable to load nwscript.nss
Failed to initialize compiler; compilation aborted.
Compilation aborted with errors.
Error: Failed to process file "fky_chat_local.nss".
Compiling: fky_chat_misc.NSS
Unable to load nwscript.nss
Failed to initialize compiler; compilation aborted.
Compilation aborted with errors.

*edit out a lot more of the same*
Total Execution time = 187ms
Press any key to continue . . .

C:NeverwinterNightsNWN>
So I'm guessing it's not finding nwscript. :P Any idea what the problem is?

Thanks,
Funky


You'll probably want to use:
NWNScriptCompiler -1ceglo -n C:\\NeverwinterNights\\NWN -r . %mask%

I'll add automatic discovery of the NWN1 install path if -1 is specified in the next release (from the registry).

Modifié par SkywingvL, 20 juin 2011 - 05:12 .


#6
FunkySwerve

FunkySwerve
  • Members
  • 1 308 messages
Here's the bat modified per your suggestion:
@ECHO OFF
set mask="%1*.nss"
CD C:\\NeverwinterNights\\NWN\\MODULES\\TEMP0
..\\..\\NWNScriptCompiler -1ceglo -n C:\\NeverwinterNights\\NWN -r . %mask%
CD ..\\..
PAUSE

Here's the output:
C:\\NeverwinterNights\\NWN>compile fky_
NWNScriptCompiler - built Jun 19 2011 20:13:40
Copyright (C) 2008-2011 Skywing.
Portions copyright (C) 2003-2003, Edward T. Smith.
Portions copyright (C) 2003, The Open Knights Consortium.
Loading base game resources...
WARNING: Failed to open .key archive 'C:\\NeverwinterNights\\NWN//xp1patch.key': e
xception 'Failed to open KEY file.'.
Compiling: fky_1heart_hell.NSS
Compiling: fky_1heart_hellb.NSS
Compiling: fky_1heart_wall.NSS
Compiling: fky_3endcmb_arti.NSS


And here's the error it gave at that point, when it went kablooey:

NWScript compiler, disassembler, and analyzer utility for NWN and NWN2 has stopped working

A problem caused the program to stop working correctly. Windows will close the program and notify you if a solution is available.

I'm guessing I'll need to wait for you to add the automatic discovery before using the -1, but I'm posting anyway in case this helps with troubleshooting.

Funky

#7
SkywingvL

SkywingvL
  • Members
  • 351 messages
Sounds like you found a bug, nice :)

Does this crash 100% of the time if you attempt to compile just fky_3endcmb_arti.nss on its own? If so, can you send me that script and its include dependencies?

Modifié par SkywingvL, 20 juin 2011 - 10:09 .


#8
FunkySwerve

FunkySwerve
  • Members
  • 1 308 messages
I'll check that and get back to you. I'll also check another script that has been driving me nuts, giving a stack underflow despite compiling fine with the old PRC. The toolset-integrated compiler whined about declarations outside of braces, so I added a set, and have yet to retest.

Funky

#9
FunkySwerve

FunkySwerve
  • Members
  • 1 308 messages
fky_3endcmb_art.nss blows up every time. Putting together a rar with all the includes...this is gonna take a while. ><

Funky

#10
SkywingvL

SkywingvL
  • Members
  • 351 messages
Thanks Funky. I'll take a look when you've got it packaged up.

#11
FunkySwerve

FunkySwerve
  • Members
  • 1 308 messages
Just sent it to you via pm'd link. I'm looking into the stack underflow script now. Thank you for developing this - I've been using the old Torlack/PRC compiler for years, and it's fantastic to see it being improved on. Once this is hammered out, I'll be running a full compile with it, which may turn up some more issues.

Funky

Modifié par FunkySwerve, 20 juin 2011 - 10:53 .


#12
FunkySwerve

FunkySwerve
  • Members
  • 1 308 messages
It would appear that the new toolset compiler has fixed the issue with the stack underflow script. Posting it here in case it's of interest to you - though I'm guessing you've got a pretty good bead on what improvements you've made over the old compiler.

Script
The error it fired that was not being reported by the old compiler was of the 'skipping declaration' variety. The only change to the script I made was the addition of brackets around case 14 (lines 180-189).

Thanks,
Funky

#13
SkywingvL

SkywingvL
  • Members
  • 351 messages
This ncs you linked passes my .ncs verifier so I don't think it should be causing a stack underflow at runtime - that's the fixed version I assume?

One of the bugs in Torlack's compiler that I fixed was related to incorrectly claiming to permit variables declared within a case block without an enclosing scope, if any further cases followed.

#14
FunkySwerve

FunkySwerve
  • Members
  • 1 308 messages
Yup, that's the fixed version, and that explains it. We have another one that pops up rarely sometimes, look forward to finding it.

Thanks,
Funky

#15
SkywingvL

SkywingvL
  • Members
  • 351 messages
If you are still trying to track down the underflow issue, BTW, try the following:

1) Extract all of your compiled scripts (*.ncs, you'll get better information if you have the NDB debug symbols too, though they aren't strictly required)
2) Run NWNScriptCompiler.exe -1dl -r . *.ncs

The disassembler in this compiler build also includes a full verifier for NCS files that is capable of detecting inconsistent stack usage in the compiled script (although certain server bugs such as buggy engine functions that don't manage their argument stack properly can still cause this issue - but this is fairly rare).

If you receive errors when disassembling, this is a good sign that the script won't really work (properly) at runtime.

#16
CID-78

CID-78
  • Members
  • 1 124 messages
Any plans to support more bioware games?

#17
OldTimeRadio

OldTimeRadio
  • Members
  • 1 400 messages
Thanks for taking this on, SkywingvL!

#18
SkywingvL

SkywingvL
  • Members
  • 351 messages

CID-78 wrote...

Any plans to support more bioware games?


If you feed the compiler the necessary script files directly via -i, I would expect that it will work for Jade Empire and KOTOR.  I don't know offhand if those use the same datafile formats and layouts that would allow automatic loading via '-n', though.

Modifié par SkywingvL, 22 juin 2011 - 04:25 .


#19
CID-78

CID-78
  • Members
  • 1 124 messages
Jade Empire is similar but has a few datatypes that is specific. the nwscript file is slightly diffrent so i don't know if that cause any issues

The Witcher shouldn't be a issue, in many cases they are using almost the same functions

KOTOR i think was also basically the same as NWN.

but dascript would require work to support arrays.

#20
SkywingvL

SkywingvL
  • Members
  • 351 messages
DAScript is likely a new instruction set.

For the others, I suspect only the engine structure type names changed, which the compiler is agnostic to (given a suitable NWScript.nss to consume). Your best bet would be to try it out and see.

#21
SkywingvL

SkywingvL
  • Members
  • 351 messages
An upcoming release (not yet posted) will include support for the following nonstandard extensions, which are only supported if -e is used:

#pragma default_function(function-identifier) // Mark 'function-identifier', which must be a declared but not yet defined function, as permissible for the compiler to autogenerate a stub implementation (throws arguments away and returns default values).  A stub implementation is only generated if the script doesn't define the function, but the function is referenced.

#define symbol [value] // Simple define preprocessor replacement support. Works for defining identifiers to any typical identifier and/or token sequence as per C, but no function-like macros yet.  Ifdef support is not in yet either, but may appear eventually.

#undef symbol // Remove symbol as a define macro

The following builtin preprocessor defines will be available in a future release, in extensions mode:

__DATE__ - script build date (quoted string)
__TIME__ - script build time (quoted string)
__NSC_COMPILER_DATE__ - compiler build date (quoted string)
__NSC_COMPILER_TIME__ - compiler build time (quoted string)
__FILE__ - current source file name, as a resref (quoted string)
__LINE__ - current source line number, as an integer
__COUNTER__ - increasing sequence number, as an integer
__FUNCTION__ - current function name (quoted string; only permissible within a function body)

Remember that for NWN2 usage, you generally can't use nonstandard extensions for scripts that the server must compile (e.g. GUI scripts and other parameterized scripts).

Modifié par SkywingvL, 23 juin 2011 - 08:37 .


#22
ShadowM

ShadowM
  • Members
  • 768 messages
sorry wrong area

Modifié par ShadowM, 24 juin 2011 - 07:26 .


#23
Baaleos

Baaleos
  • Members
  • 1 315 messages
Hi Skywing -
Sorry to necro post.

But I read the original post, and saw the bit that says

The project includes a new standalone script compiler (NWNScriptCompiler.exe), which is compatible with both NWN1 and NWN2. Only Windows builds of the updated compiler are available right now.


However, when I try using the application as a 'StandAlone' compiler, I get an error saying that nwnscript.nss cannot be found.
Would it be safe to say, that it is not stand-alone then? It still requires nwn installed on the pc you are trying to compile on.

What im trying to do, is compile nwn scripts on my work laptop, at work - when nwn is not installed on it.

What all does the script compiler require to compile a script - is it possible to accomplish what im trying to do?

#24
CID-78

CID-78
  • Members
  • 1 124 messages
you need the game(s) nwscript.nss, because it defines all the engine functions and constants, You do not need the rest of the game.

#25
SkywingvL

SkywingvL
  • Members
  • 351 messages
The compiler can function without a full game install, but you need to provide it with some of the data files so that it knows what engine functions are there (and so that it can handle scripts that reference inbox/"standard" includes).  This keeps the compiler agnostic with respect to whether it's used for NWN1, NWN2, KoToR, etc, and avoids it having to be updated every time the game(s) involved are modified.

If you want to run the compiler without a game install, then extract all of the scripts from the game data files and pass the directory where the scripts are extracted to with "-i <dir>".

At a minimum, you will need nwscript.nss. You'll probably want the rest of the scripts, though, if you use any inbox includes.

Be sure to extract scripts in the correct order if you go this route. The most recently updated datafiles should be extracted last (so that they overwrite scripts that were from the unpatched/pre-expansion versions of the game).

Modifié par SkywingvL, 23 juillet 2011 - 06:54 .