Author Topic: Advanced Script Compiler for NWN1 release thread  (Read 7369 times)

Legacy_SkywingvL

  • Full Member
  • ***
  • Posts: 115
  • Karma: +0/-0
Advanced Script Compiler for NWN1 release thread
« on: June 20, 2011, 04:44:46 am »


               

[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 .
                     
                  


            

Legacy_FunkySwerve

  • Hero Member
  • *****
  • Posts: 2325
  • Karma: +0/-0
Advanced Script Compiler for NWN1 release thread
« Reply #1 on: June 20, 2011, 08:12:54 am »


               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. '<img'> Any idea what the problem is?

Thanks,
Funky
               
               

               


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


            

Baaleos

  • Administrator
  • Hero Member
  • *****
  • Posts: 1916
  • Karma: +0/-0
Advanced Script Compiler for NWN1 release thread
« Reply #2 on: June 20, 2011, 11:58:05 am »


               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?
               
               

               
            

Legacy_FunkySwerve

  • Hero Member
  • *****
  • Posts: 2325
  • Karma: +0/-0
Advanced Script Compiler for NWN1 release thread
« Reply #3 on: June 20, 2011, 04:08:52 pm »


               There isn't a period in the folder name. You're thinking of logs.0.

Funky
               
               

               
            

Legacy_SkywingvL

  • Full Member
  • ***
  • Posts: 115
  • Karma: +0/-0
Advanced Script Compiler for NWN1 release thread
« Reply #4 on: June 20, 2011, 05:47:07 pm »


               

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. '<img'> 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 .
                     
                  


            

Legacy_FunkySwerve

  • Hero Member
  • *****
  • Posts: 2325
  • Karma: +0/-0
Advanced Script Compiler for NWN1 release thread
« Reply #5 on: June 20, 2011, 10:53:53 pm »


               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
               
               

               
            

Legacy_SkywingvL

  • Full Member
  • ***
  • Posts: 115
  • Karma: +0/-0
Advanced Script Compiler for NWN1 release thread
« Reply #6 on: June 20, 2011, 11:08:35 pm »


               Sounds like you found a bug, nice '<img'>

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 .
                     
                  


            

Legacy_FunkySwerve

  • Hero Member
  • *****
  • Posts: 2325
  • Karma: +0/-0
Advanced Script Compiler for NWN1 release thread
« Reply #7 on: June 20, 2011, 11:14:52 pm »


               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
               
               

               
            

Legacy_FunkySwerve

  • Hero Member
  • *****
  • Posts: 2325
  • Karma: +0/-0
Advanced Script Compiler for NWN1 release thread
« Reply #8 on: June 20, 2011, 11:19:55 pm »


               fky_3endcmb_art.nss blows up every time. Putting together a rar with all the includes...this is gonna take a while. ><

Funky
               
               

               
            

Legacy_SkywingvL

  • Full Member
  • ***
  • Posts: 115
  • Karma: +0/-0
Advanced Script Compiler for NWN1 release thread
« Reply #9 on: June 20, 2011, 11:23:51 pm »


               Thanks Funky.  I'll take a look when you've got it packaged up.
               
               

               
            

Legacy_FunkySwerve

  • Hero Member
  • *****
  • Posts: 2325
  • Karma: +0/-0
Advanced Script Compiler for NWN1 release thread
« Reply #10 on: June 20, 2011, 11:44:52 pm »


               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 .
                     
                  


            

Legacy_FunkySwerve

  • Hero Member
  • *****
  • Posts: 2325
  • Karma: +0/-0
Advanced Script Compiler for NWN1 release thread
« Reply #11 on: June 21, 2011, 12:36:29 am »


               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
               
               

               
            

Legacy_SkywingvL

  • Full Member
  • ***
  • Posts: 115
  • Karma: +0/-0
Advanced Script Compiler for NWN1 release thread
« Reply #12 on: June 21, 2011, 01:12:37 am »


               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.
               
               

               
            

Legacy_FunkySwerve

  • Hero Member
  • *****
  • Posts: 2325
  • Karma: +0/-0
Advanced Script Compiler for NWN1 release thread
« Reply #13 on: June 21, 2011, 01:21:01 am »


               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
               
               

               
            

Legacy_SkywingvL

  • Full Member
  • ***
  • Posts: 115
  • Karma: +0/-0
Advanced Script Compiler for NWN1 release thread
« Reply #14 on: June 21, 2011, 01:43:54 am »


               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.