resources

The resources module provides access to the file system and resources stored in NWN container files.

nw::Resref

Unlike Neverwinter Nights 1 or 2 a resref is not a fixed character array. It’s simply a wrapper around an interned string. The constraint on its length is 4096.

This is not exposed to Python, in Python a resref maps directly to a str, i.e. “nw_chicken”.

nw::ResourceType

ResourceType has only one difference from NWN(:EE)’s implementation: it contains some categories, i.e. nw::ResourceType::texture that aligns with the available image types.

Example - Checking a ResourceType category

if(nw::ResourceType::check_category(nw::ResourceType::texture, some_res_type)) {
    // Proceed with some image resource type agnostic function.
}

nw::Resource

Resources are referred to by a nw::Resource, which is just a nw::Resref and nw::ResourceType pair.

This is not exposed to Python, in Python one can referrer to an asset as a filename, i.e. “nw_chicken.utc”.


nw::Container

Containers in rollnw are designed around the performance of the resource manager and are not for direct use. Classes that inherit the nw::Container interface are expected to be thread-safe.

The built in containers nw::StaticDirectory, nw::StaticErf, nw::StaticKey, and nw::StaticZip are all static and immutable and after construction proceed with the assumption that the underlying files do not change. They are not exposed to Python.

Support for nwsync was removed since it is not applicable to module/persistant world development, nor do I see it as having any ‘future tense’, i.e., a hypothetical NWN3 would not use nwsync.

The ability to add new container types is limited in utility due to NWNX:EE’s lack of a ResMan plugin.

There is experimental support for a package.json file (currently empty) that will serve to signal to containers that they are ‘modern’ containers. So, in the case of nw::StaticDirectory if package.json is present at the toplevel then path is preseved, i,e:

├── hak_with_package_json
│   ├── package.json
│   └── test
│       └── cloth028.UTI

one resulting resref in this container is hak_with_package_json/test/cloth028. This is ultimately the future of parts of the system that needn’t be compatible with NWN(:EE).


nw::Erf

A dynamic implementation of the Erf file format, which is also exposed to Python:

Example - Load an Erf and Print Contents

import rollnw

erf = rollnw.Erf("tests/test_data/user/hak/hak_with_description.hak")
print(erf.name(), erf.size())
for rd in erf.all():
    print(rd.name.filename(), rd.size)

nw::ResourceManager

The global resource mananger is available by calling nw::kernel::resman().

Example - Demanding a resource from resman

import rollnw

rollnw.kernel.start()
assert rollnw.kernel.resman().contains('nw_chicken.utc')
data = rollnw.kernel.resman().demand('nw_chicken.utc')
assert len(data.bytes)