BioWare Atari
BioWare Info BioWare Games Support Forums Visit the BioWare Store
Neverwinter Nights Home
Neverwinter Nights Home

Tutorial: Building a Custom ERF Data Extractor

Intended Audience: For Developers
By Don Moar

NOTICE: This tutorial is to give software developers an example of how to use the Encapsulated Resource File (ERF) Format. The source code provided is unsupported; compile and run at your own risk. Please refer to the For Developers FAQ and the NWN End User License Agreement (EULA) for more information.

Description

1. Purpose

I need a command-line program that can extract resources by type id / name from an erf and save them to another directory. I can use this to help automate the merging of data files from different modules into the same module.

2. Command Line

The command line should look like this:
erfget erfname restype resref dirname

Parameter Description
erfname Required Name of the encapsulated resource file from which to extract the resource
restype Required ID number of the resource type
resref Required Name of the resource to extract
dirname Required Name of the directory to save extracted resources

3. Program Architecture

In an ideal world, I would create a class that handles all ERF behaviours and put it in a library that I would then link into my executable. However, it's Saturday afternoon and I want to get this done as quickly as possible and all I really want at this moment is to get that data out of the ERF. So, I'll forego all the standard practices and just stick all that code required to accomplish what I want in my main function.

Note: This is not the recommended approach!

4. Class Definitions

None.

C Source Code

To view or download the C Source Code you need to be logged into your BioWare Community Account. If you don't have an account you can sign up for a free BioWare Community Account.

Extra Credit

1. Clean Up The Code

Okay, while functional, this really isn't the best approach. Restructure the program by creating an interface to the set of typical ERF behaviours that we expect most programs to require: OpenFile, CloseFile, SaveFile, AddResource, GetResource, RemoveResource. Put this interface in a separate library to which the program will link. The program should then be modified to create an instance of this class and use it to navigate the ERF file.

2. Make the Program More Robust

The command line system that the program currently supports is very fragile. If you don't get the parameters exactly right, the program will fail (and it won't report anything). Extend the program to make it handle extracting all the resources from the erf, all the resources of a particular type and all the resources of a particular name.

3. Write the ERF Data Integrator

Write a program that takes data files in a directory and adds them to the specified ERF, creating the file if it doesn't already exist. The program should take an ERF file name and a directory as parameters. Watch out of files that don't correspond to known resource types and resources that already exist in the ERF.

Together these two programs then allow you to transfer data between ERFs (modules) without having to use the toolset.

 

 

BioWare Blog
Neverwinter Nights 2 Forums
Hide/Show

English
Deutsch
Français
Español
Italiano

Hide/Show

View Latest Screenshots 

View Latest Screenshots
Hide/Show

Multiplayer Games at Neverwinter Connections

Today
Schedule a Game...



Current time is: (set time)
Sun, 08 November 2009 01:21AM

Hide/Show

Buy Premium Modules

Top NWN: HotU Modules:
1. Good vs Evil III
2. More...

Top NWN: SoU Modules:
1. Good vs Evil III
2. More...

Top CEP Modules:
1. The Lord of Terror The Diablo Campa...
2. More...

Top Modules - NWVault:
1. Hall of Fame
2. More...

Total Modules: 4423

Hide/Show

4,826,037 BioWare Users:
  187 Logged In
  12 Hidden
  1347 Guests

1369 Playing Online
  100% NWN
  100% NWN: SoU
  99% NWN: HotU

446 Registered Guilds

8,714,843 posts in forums

Newest Forum Topics:
1. Blood Ring (Dragon Age: Origins Story and Plot (Spoilers) Forum)

2. Got DA, and my computer is missi... (Dragon Age: Origins General Discussion)

3. Exp (Dragon Age: Origins General Discussion)

4. Where is the manual for dowloade... (Dragon Age: Origins General Discussion)

5. Where to find templar armor? (Dragon Age: Origins General Discussion)