nwnintf.format.mod
Class ModFile

java.lang.Object
  |
  +--nwnintf.format.mod.ModFile

public class ModFile
extends java.lang.Object

Represent a "mod"/"sav"/"erf"/"hak"/"nwm" etc. file. Cannot be used to create a new module file entirely from scratch, but it could be modified to do so. See Torlack's file format description: http://www.torlack.com/index.html?topics=nwndata_mod


Field Summary
static int DAY
           
static int NRESOURCES
           
static int NSTRINGS
           
static int PADDING
           
static int PADDINGSIZE
           
static int POSOFFSET
           
static int RESOFFSET
           
static int SIZE
           
static int STRINGOFFSET
           
static int STRINGSLEN
           
static int TYPE
           
static int TYPE_MOD
           
static int TYPE_NWM
           
static int TYPE_SAV
           
static int TYPECODE
           
static int VERSION
           
static int YEAR
           
 
Constructor Summary
ModFile(java.io.File f)
           
 
Method Summary
 void addupdateresource(ResRef resref, byte[] resdata)
          Add a new resource to the file, or update an existing one.
 boolean contains(ResRef resref)
          Test whether the module contains a resource by this name and type.
 void deleteresource(ResRef resref)
          Delete a resource from the module file.
 ModResDesc descAt(int idx)
          Return the idx'th ModResDesc.
 java.util.Iterator iterator(int type)
          Produce an iterator that iterates over all ResRef objects in the file that have the given type.
static void main(java.lang.String[] args)
           
 int nresources()
           
 byte[] resource(ModResDesc desc)
           
 byte[] resource(ModResPosn posn)
           
 byte[] resource(ResRef resref)
          Get a copy of a resource file in the module.
 java.lang.String type()
           
 java.lang.String version()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TYPE

public static int TYPE

VERSION

public static int VERSION

NSTRINGS

public static int NSTRINGS

STRINGSLEN

public static int STRINGSLEN

NRESOURCES

public static int NRESOURCES

STRINGOFFSET

public static int STRINGOFFSET

RESOFFSET

public static int RESOFFSET

POSOFFSET

public static int POSOFFSET

YEAR

public static int YEAR

DAY

public static int DAY

TYPECODE

public static int TYPECODE

PADDING

public static int PADDING

PADDINGSIZE

public static int PADDINGSIZE

SIZE

public static int SIZE

TYPE_MOD

public static int TYPE_MOD

TYPE_SAV

public static int TYPE_SAV

TYPE_NWM

public static int TYPE_NWM
Constructor Detail

ModFile

public ModFile(java.io.File f)
        throws java.lang.Exception
Method Detail

type

public java.lang.String type()

version

public java.lang.String version()

descAt

public ModResDesc descAt(int idx)
Return the idx'th ModResDesc.


nresources

public int nresources()

iterator

public java.util.Iterator iterator(int type)
Produce an iterator that iterates over all ResRef objects in the file that have the given type.


contains

public boolean contains(ResRef resref)
Test whether the module contains a resource by this name and type.


resource

public byte[] resource(ResRef resref)
                throws java.io.IOException
Get a copy of a resource file in the module. Notes: this does a linear search through the list of resources every time. Should cache a map of ResRef -> ModResDesc.

Returns:
bytes of the resource, null if not found.
java.io.IOException

resource

public byte[] resource(ModResDesc desc)
                throws java.io.IOException
java.io.IOException

resource

public byte[] resource(ModResPosn posn)
                throws java.io.IOException
java.io.IOException

addupdateresource

public void addupdateresource(ResRef resref,
                              byte[] resdata)
                       throws java.io.IOException
Add a new resource to the file, or update an existing one. This function makes a mess of the file, wasting space and moving things all over the place.

Parameters:
resref - Name of resource file.
resdata - Bytes making up the resource.
java.io.IOException

deleteresource

public void deleteresource(ResRef resref)
                    throws java.io.IOException
Delete a resource from the module file.

java.io.IOException

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
java.lang.Exception