#ifndef MPLE_V2_H
#define MPLE_V2_H
#include <glib.h>

#include <libnw.h>
#include <libnw_internals.h>

nw_device_t *mple_v2_dev_init( gchar * );
GList *mple_v2_parse_directory( nw_device_t * );
NWFILE *mple_v2_open( nw_device_t *, guint32, guint32, const gchar *, char * );
size_t mple_v2_write( void *, size_t, size_t, NWFILE * );
size_t mple_v2_read( void *, size_t, size_t, NWFILE * );

typedef struct _mple_v2_device {
  nw_device_t devdata;

  guint32 dvid;

  gchar *omgpath;
  gchar *omapath;
  gchar *dvidpath;

  /* avoid having a named variable for every single file */
  GHashTable *files;
} mple_v2_device_t;

typedef struct _MPLEV2FILE {
  NWFILE nwfile; /* NW common data */
} MPLEV2FILE;

typedef struct _hdr {
  gchar magic[4];   /* type of file */
  gchar unknown[4]; /* appears to be constant: 0101 0000 */
  guint8 blocks;    /* 1 or 2 */
  gchar padding[7]; /* 00 */
} mple_v2_hdr;

typedef struct _ptr {
  gchar magic[4]; /* type of block */
  guint32 offset; /* absolute file offset */
  guint32 length; /* length of data */
  gchar pad[4];   /* 00 */
} mple_v2_ptr;

typedef struct _blk {
  gchar magic[4]; /* type of block */
  guint16 count;  /* number of records */
  guint16 size;   /* size of record */
  gchar pad[8];   /* 00 */
} mple_v2_blk;

/*
  "EKB " => 00010021.dat
  "GTLT" => 00gtrlst.dat
  "TREE" => 01treeNN.dat
  "GTIF" => 02treinf.dat
  "GPIF" => 03ginfNN.dat
  "CNIF" => 04cntinf.dat
  "CIDL" => 05cidlst.dat
*/
typedef struct _ea3_hdr {
  guint8 signature[4]; /* EA3\2 */
  guint16 size;
  guint16 thing; /* FFFE */
  guint16 padding[12];
  guint32 thing2; /* 0380db10 or thereabouts */
  guint32 duration; /* length in milliseconds */
  guint32 frames;
} ea3_hdr;

#endif /* MPLE_V2_H */

