No description
Find a file
Milos Tijanic db755db7fd
Scriptcomp optimizations refactor (#149)
- Remove constant folding from the optimization lists; it's a core
language feature. You can't disable it.
- Group the optimizations into groups: NONE, SAFE, AGGRESSIVE,
EXPERIMENTAL
- Default to SAFE everywhere. This is just dead code elimination, which
was default prior to all the compiler improvements
- Provide CLI args for -O{0..3} to pick the groups

```
  -O N                        Optimisation levels [default: 1]
                                0: Optimise nothing
                                1: Safe optimisations only, as used by the game and toolset
                                    +RemoveDeadCode
                                2: Aggressive optimisations; faster and smaller code size
                                    +RemoveDeadCode
                                    +RemoveDeadBranches
                                3: Experimental optimisations; untested or known to break something
                                    +RemoveDeadCode
                                    +MeldInstructions
                                    +RemoveDeadBranches
```

This is in response to #148 , but it only fixes it insofar that it
disables the problematic behavior by default.

## Testing

nwscript test corpus. Also ran manually with all four different -O
options and looked at disassembly.

## Changelog

### Changed
- nwn_script_comp: the default optimization level has been lowered from
2 to 1***

## Licence

- [x] I am licencing my change under the project's MIT licence,
including all changes to GPL-3.0 licenced parts of the codebase.
2025-08-17 10:23:49 +02:00
.github/workflows zig: bump gh action 2025-05-29 11:38:09 +02:00
bin having a bin/ directory is helpful to actually build 2017-03-02 23:24:08 +01:00
dist/pkg-x86_64-windows scripts and config for building packages with zig 2025-05-06 15:21:34 +02:00
docs add some useful documentation 2023-07-12 10:36:59 +02:00
neverwinter Scriptcomp optimizations refactor (#149) 2025-08-17 10:23:49 +02:00
private netutil: fix sendTo not being awaited, resulting in breakage on 2.0.10 2024-10-12 10:56:53 +02:00
scripts build linux-gnu, not -musl (nim seems to depend on glibc anyways) 2025-05-29 11:13:50 +02:00
tests add support for binary (0b[0|1...]) and octal (0o[0-7...]) integers (#133) 2024-10-12 22:46:34 +02:00
.editorconfig editorconfig: yaml should be 2 deep 2025-05-06 15:21:34 +02:00
.gitattributes make GitHub linguist (language detector) ignore zstd lib files 2020-08-27 17:10:10 +02:00
.gitignore scripts and config for building packages with zig 2025-05-06 15:21:34 +02:00
CHANGELOG.md 2.1.1 2025-05-29 11:38:09 +02:00
config.nims release workflow: update and modernise, also build universal binaries on macos 2025-05-04 21:53:04 +02:00
LICENCE 1.3.2 2020-10-26 15:17:21 +01:00
neverwinter.nimble 2.1.1 2025-05-29 11:38:09 +02:00
nim.cfg build with stacktraces available even in release mode 2023-12-25 22:03:32 +01:00
nimble.lock bump checksums pkg to 0.2.1 2024-10-12 11:01:40 +02:00
nwn_asm.nim remove one more redundant import 2023-08-05 18:51:02 +02:00
nwn_compressedbuf.nim utils: read input file fully before writing, this allows writing back to same file 2023-02-26 10:12:11 +01:00
nwn_erf.nim Fix checksums import when used as library (#110) 2024-02-17 12:58:12 +01:00
nwn_erf_tlkify.nim tidy up all import statements 2024-04-01 11:16:27 +02:00
nwn_gff.nim utils: read input file fully before writing, this allows writing back to same file 2023-02-26 10:12:11 +01:00
nwn_key_pack.nim Fix checksums import when used as library (#110) 2024-02-17 12:58:12 +01:00
nwn_key_shadows.nim resman: add support for compressed res and checksums 2020-11-04 13:53:42 +01:00
nwn_key_transparent.nim resman: add support for compressed res and checksums 2020-11-04 13:53:42 +01:00
nwn_key_unpack.nim resman, key: annotate gcsafety expectations 2023-08-05 18:28:52 +02:00
nwn_net.nim don't include packets.nim, make it properly importable 2024-04-01 16:00:39 +02:00
nwn_nwsync_fetch.nim nwsync: integrate 2024-03-26 09:47:51 +01:00
nwn_nwsync_print.nim nwsync: integrate 2024-03-26 09:47:51 +01:00
nwn_nwsync_prune.nim fix incorrect size reporting on ref pruning 2024-09-28 15:21:53 +02:00
nwn_nwsync_write.nim tidy up all import statements 2024-04-01 11:16:27 +02:00
nwn_resman_cat.nim resref: now a direct object, not a ref, also remove dodgy string converter 2023-07-09 16:16:52 +02:00
nwn_resman_diff.nim remove 1.69 support, fix defaultResMan 2022-11-03 11:25:27 +01:00
nwn_resman_extract.nim filterByMatch: fix --all never having worked 2024-04-07 10:12:02 +02:00
nwn_resman_grep.nim filterByMatch: fix --all never having worked 2024-04-07 10:12:02 +02:00
nwn_resman_pkg.nim support new nwn_retail keybif 2024-05-04 11:45:04 +02:00
nwn_resman_stats.nim ditch progressbar support 2022-10-22 12:59:36 +02:00
nwn_script_comp.nim Scriptcomp optimizations refactor (#149) 2025-08-17 10:23:49 +02:00
nwn_script_comp.nim.cfg nwn_script_comp: multithreaded operations, more cli flags 2023-07-11 11:08:57 +02:00
nwn_ssf.nim utils: read input file fully before writing, this allows writing back to same file 2023-02-26 10:12:11 +01:00
nwn_tlk.nim utils: read input file fully before writing, this allows writing back to same file 2023-02-26 10:12:11 +01:00
nwn_twoda.nim utils: read input file fully before writing, this allows writing back to same file 2023-02-26 10:12:11 +01:00
pull_request_template.md add a PR template 2023-07-13 13:57:54 +02:00
README.md pin nimble pkgs 2024-04-01 12:02:23 +02:00
VERSION.tpl VERSION -> VERSION.tpl to make new xcode happy 2023-06-28 13:17:04 +02:00

neverwinter.nim

This is a nim-lang library and utility collection to read and write data files used by Neverwinter Nights: Enhanced Edition.

It also includes the official script compiler source code and CLI utility, as well as tools to maintain a serverside NWSync repository.

Binary releases are available on the Github Releases page of this project. You do not need to install anything else.

Tools

All utilities write their working output to stdout, and any library- or tool- related logging goes to stderr. You can turn on debug logging with --verbose, and turn off all logging except errors with --quiet.

Call each utility with --help to get documentation on their usage.

General resman utilities

  • nwn_resman_stats: Get data on what is in a resman view.
  • nwn_resman_grep: Grep a resman view for data.
  • nwn_resman_extract: Pull files from resman into directory.
  • nwn_resman_cat: Pull file(s) from resman and pipe them to stdout.
  • nwn_resman_diff: Diffs two resman views (for language support).
  • nwn_resman_pkgsrv: Repackage a resman view suitable for docker deployment.
  • nwn_key_pack, nwn_key_unpack: Un/packs a keyfile into/from a directory structure.
  • nwn_key_shadows: Get data on file shadowing in a list of key files.
  • nwn_key_transparent: Get data on file duplication in a list of key files.

Most of these utilities embed a complete resman. The general idea is NOT to operate on single file formats. Instead, they all utilise the underlying resman implementation from the neverwinter library included in this repository.

For example, if you want to get statistics about a key file, you do not unpack it: Instead, you use nwn_resman_stats and tell it to only load the key file you are interested in.

Format conversion and user data utilities

  • nwn_gff: Transforms gff data to/from various formats, extract/embed SQLite.
  • nwn_erf: Un/pack erf files.
  • nwn_tlk: Transforms tlk tables from/to various formats.
  • nwn_twoda: Transforms 2da files from/to various formats.
  • nwn_erf_tlkify: Refactor strings in a erf into a exisiting or new tlk.
  • nwn_sff: Convert SSF files to/from csv.
  • nwn_compressedbuf: De/compress NWCompressedBuf payloads.
  • nwn_net: A utility providing some network-related helpers, like querying servers.

Script compiler

  • nwn_script_comp: NWScript compiler using the official open-source compiler library.
  • nwn_asm: Utility to deal with nwscript assembly.

NWSync

These utilities are the official way to maintain a NWSync serverside repository.

Note that all of these were previously at home on Beamdog/nwsync, but were moved here.

  • nwn_nwsync_write: Generate a serverside NWSync manifest.
  • nwn_nwsync_prune: Trim serverside NWSync repository of unreferenced data, to save diskspace.
  • nwn_nwsync_print: Print manifest contents in human-readable format.
  • nwn_nwsync_fetch: Helper to synchronise a manifest server-to-server with aria2c.

Development

neverwinter.nim requires nim 2.0 or later set up to develop against.

Since moving to 2.0, the file nimble.lock is used to pin dependencies to specific versions.

You can keep building it simply by typing nimble build -d:release (where -d:release is optional). If you want to use nim or testament directly, you need to set up the local search path file with nimble setup.