improved dat interfaces
authorecalot <ecalot>
Sat, 12 Jun 2004 01:44:30 +0000 (01:44 +0000)
committerecalot <ecalot>
Sat, 12 Jun 2004 01:44:30 +0000 (01:44 +0000)
PR/src/include/dat.h
PR/src/lib/actions/export.c
PR/src/lib/actions/import.c
PR/src/lib/formats/bmp.c
PR/src/lib/formats/mid.c
PR/src/lib/formats/pal.c
PR/src/lib/formats/plv.c
PR/src/lib/formats/wav.c
PR/src/lib/layers/dat.c

index e7aff46d81422bc34e057b1043e324d4a0341017..a162a60d3bf9c4e6b9590aa8c12c985b68cb5942 100644 (file)
@@ -52,7 +52,7 @@ mWriteCloseDatFile(r,dontSave,optionflag,backupExtension)
 #ifdef PR_DAT_INCLUDE_DATREAD
 /* DAT reading primitives */
 int  mReadBeginDatFile(unsigned short int *numberOfItems,const char* vFile);
-int  mReadGetFileInDatFile(int indexNumber,unsigned char* *data,unsigned long  int *size);
+int  mReadFileInDatFile(int indexNumber,unsigned char* *data,unsigned long  int *size);
 int  mReadInitResource(tResource** res,const unsigned char* data,long size);
 void mReadCloseDatFile();
 #endif
@@ -60,8 +60,8 @@ void mReadCloseDatFile();
 #ifdef PR_DAT_INCLUDE_DATWRITE
 /* DAT writing primitives */
 int  mWriteBeginDatFile(const char* vFile, int optionflag);
-void mWriteSetFileInDatFile(const unsigned char* data, int size);
-void mWriteSetFileInDatFileIgnoreChecksum(unsigned char* data,int size);
+void mWriteFileInDatFile(const unsigned char* data, int size);
+void mWriteFileInDatFileIgnoreChecksum(unsigned char* data,int size);
 void mWriteInitResource(tResource** res);
 void mWriteCloseDatFile(tResource* r[],int dontSave,int optionflag, const char* backupExtension);
 #endif
index cf75a5ff6e9ca0533439697da791824b4b942142..6e9b1e51f99bb17916af95fc330b50d754100d1a 100644 (file)
@@ -84,28 +84,33 @@ int extract(const char* vFiledat,const char* vDirExt, tResource* r[], int option
 
        /* Initialize abstract variables to read this new DAT file */
        if (!mReadBeginDatFile(&numberOfItems,vFiledat)) return -1;
-
+fld("a");
        /* Initializes the palette list */
        initializePaletteList;
+fld("b");
 
        /* main loop */
        for (indexNumber=0;ok&&(indexNumber<numberOfItems);indexNumber++) {
-               id=mReadGetFileInDatFile(indexNumber,&data,&size);
+               id=mReadFileInDatFile(indexNumber,&data,&size);
+fld("c");
+printf("*K) id=%d size=%d %d:%d:%d:%d:%d:%d\n",id,size,data[0],data[1],data[2],data[3],data[4],data[5]);
 
                if (id<0) return -3; /* Read error */
                if (id==0xFFFF) continue; /* Tammo Jan Bug fix */
                if (id>=MAX_RES_COUNT) return -3; /* A file with an ID out of range will be treated as invalid */
+fld("d");
 
                /* set resource information on this index entry */
                if (mReadInitResource(r+id,data,size)) return -2;
-
+fld("e");
+printf("z->%d\n",r[id]->type);
                if ((r[id]->type==RES_TYPE_PALETTE)||isInThePartialList(r[id]->path,id)) { /* If the resource was specified or is a palette, do the tasks */
                        if (!(hasFlag(unknown_flag))) { /* If unknown flag is set do nothing but generate the unknown.xml file */
                                if (hasFlag(raw_flag)) r[id]->type=0; /* If "extract as raw" is set, type is 0 */
 
                                /* get save file name (if unknown document it in the xml) */
                                getFileName(vFileext,vDirExt,r[id],(unsigned short)id,vFiledat,vDatFileName,optionflag,backupExtension);
-
+fld("f");
                                switch (r[id]->type) {
                                        case RES_TYPE_LEVEL:
                                                ok=ok&&mFormatExportPlv(data,vFileext,size,r[id]->number,vDatFileName,r[id]->name,r[id]->desc,vDatAuthor,optionflag,backupExtension);
@@ -128,13 +133,16 @@ int extract(const char* vFiledat,const char* vDirExt, tResource* r[], int option
                                                break;
                                        case RES_TYPE_PCSPEAKER: /* save pcs file */
                                        case RES_TYPE_MIDI:     /* save midi file */
+printf("a->%d\n",ok);
                                                ok=ok&&mFormatExportMid(data,vFileext,size,optionflag,backupExtension);
+printf("b->%d\n",ok);
                                                break;
                                        case RES_TYPE_WAVE: /* save wav file */
                                                ok=ok&&mFormatExportWav(data,vFileext,size,optionflag,backupExtension);
                                                break;
                                        case RES_TYPE_IMAGE: /* save image */
                                                /* Palette handling */
+fld("Z1");
                                                if (r[id]->palette!=paletteId) { /* The palette isn't the already loaded */
                                                        if (r[id]->palette) { /* We need a palette */
                                                                /*
@@ -148,7 +156,9 @@ int extract(const char* vFiledat,const char* vDirExt, tResource* r[], int option
                                                        }
                                                }
                                                /* Export bitmap */
+fld("Z2");
                                                ok=ok&&mFormatExportBmp(data,vFileext,size,image,optionflag,backupExtension);
+fld("Z3");
                                                break;
                                }
                                /* Verbose information */
index 084b9cfa864aa83c4a5b2015219db1f523e2c67b..83384621cdeab21803d1d137233ab114a52975e9 100644 (file)
@@ -72,7 +72,7 @@ int mAddCompiledFileToDatFile(unsigned char* data, tResource* res,const char* vF
                        return mFormatImportPal(data,res,vFile);
                case RES_TYPE_BINARY:
                default:
-                       mWriteSetFileInDatFile(data,res->size);
+                       mWriteFileInDatFile(data,res->size);
                        break;
        }
        return 1;
@@ -88,7 +88,6 @@ for (id=0;id<MAX_RES_COUNT;id++) {\
        }\
 }
 
-
 /***************************************************************\
 |                   M A I N   F U N C T I O N                   |
 \***************************************************************/
@@ -106,9 +105,9 @@ int fullCompile(const char* vFiledat, const char* vDirExt, tResource* r[], int o
        int ok=0;
        unsigned char* data;
        unsigned short int id=1;
-
+fld("itdb");
        if (!mWriteBeginDatFile(vFiledat,optionflag)) return -1; /* File couldn't be open */
-
+fld("tb");
        for (;id!=MAX_RES_COUNT;id++) {
                if (r[id]!=NULL) {
                        if (hasFlag(raw_flag)) r[id]->type=0; /* compile from raw */
@@ -130,12 +129,13 @@ int fullCompile(const char* vFiledat, const char* vDirExt, tResource* r[], int o
                        }
                }
        }
-       /* Close file.  if empty, don't save */
+fld("kb");
+       /* Close file. If empty, don't save */
        mWriteCloseDatFile(r,!ok,optionflag,backupExtension);
-
+fld("db");
        /* Free allocated resources and dynamic strings */
        freeResources;
-
+fld("zb");
        if (hasFlag(verbose_flag)) fprintf(outputStream,PR_TEXT_IMPORT_DONE,ok,error);
        return error;
 }
@@ -163,15 +163,16 @@ int partialCompile(const char* vFiledat, const char* vDirExt, tResource* r[], in
 
        /* main loop */
        for (indexNumber=0;(indexNumber<numberOfItems);indexNumber++) {
-               id=mReadGetFileInDatFile(indexNumber,&data,&size);
+               id=mReadFileInDatFile(indexNumber,&data,&size);
                if (id<0) RW_ERROR; /* Read error */ /* TODO BUG: return doesn't close file */
                if (id==0xFFFF) continue; /* Tammo Jan Bug fix */
                if (id>=MAX_RES_COUNT) RW_ERROR; /* A file with an ID out of range will be treated as invalid */
-
+fld("e");
                mWriteInitResource(r+id);
                if (r[id]&&isInThePartialList(r[id]->path,id)) { /* If the resource was specified */
                        if (hasFlag(raw_flag)) r[id]->type=0; /* compile from raw */
                        getFileName(vFileext,vDirExt,r[id],(unsigned short)id,vFiledat,vDatFileName,optionflag,backupExtension);
+fld("g");
                        /* the file is in the archive, so i'll add it to the main dat body */
                        if ((r[id]->size=((unsigned long)mLoadFileArray(vFileext,&data)))) {
                                if (!mAddCompiledFileToDatFile(data,r[id],vFileext)) {
@@ -188,24 +189,29 @@ int partialCompile(const char* vFiledat, const char* vDirExt, tResource* r[], in
                        }
                } else {
                        r[id]->size=size-1;
-                       mWriteSetFileInDatFileIgnoreChecksum(data,size);
+                       mWriteFileInDatFileIgnoreChecksum(data,size);
                }
        }
+fld("k");
 
        /* Close dat file */
        mRWCloseDatFile(0);
 
        /* Free allocated resources and dynamic strings */
        freeResources;
+fld("b");
 
        if (hasFlag(verbose_flag)) fprintf(outputStream,PR_TEXT_IMPORT_DONE,ok,error);
        return error;
 }
 
 int compile(const char* vFiledat, const char* vDirExt, tResource* r[], int optionflag, const char* vDatFileName,const char* backupExtension) {
+fld("b");
        if (partialListActive()) {
+fld("fub");
                return partialCompile(vFiledat,vDirExt,r,optionflag,vDatFileName,backupExtension);
        } else {
+fld("fdb");
                return fullCompile(vFiledat,vDirExt,r,optionflag,vDatFileName,backupExtension);
        }
 }
index 1b8ae6201379b8bbef2f7e08c9b00b102c879ec5..c328adff81f0225a6ac6f2610eadb7ac3dd10550 100644 (file)
@@ -41,6 +41,8 @@ bmp.c: Princed Resources : BMP file support
 #include "memory.h"
 #include "dat.h"
 
+extern FILE* outputStream;
+
 int mFormatExportBmp(const unsigned char* data, const char *vFileext,unsigned long int size,tImage image,int optionflag, const char* backupExtension) {
        /*
                This function will expand the data into an image structure,
@@ -50,15 +52,19 @@ int mFormatExportBmp(const unsigned char* data, const char *vFileext,unsigned lo
                      keep the right palette.
        */
        int result;
+fld("ZA1");
 
        /* Expand graphic and check results */
        result=mExpandGraphic(data,&image,size);
+printf("0) %d+%d*%d,%d\n",image.pix,image.height,image.widthInBytes,image.widthInBytes);
        if ((result==COMPRESS_RESULT_WARNING)&&hasFlag(verbose_flag))
-               printf (PR_TEXT_EXPORT_BMP_WARN);
+               fprintf(outputStream,PR_TEXT_EXPORT_BMP_WARN);
        if (result==COMPRESS_RESULT_FATAL) return 0;
+fld("ZA2");
 
        /* Write bitmap */
        mWriteBitMap(image,vFileext,optionflag,backupExtension);
+fld("ZA3");
 
        /* free bitmap */
        free(image.pix);
@@ -69,14 +75,15 @@ int mFormatExportBmp(const unsigned char* data, const char *vFileext,unsigned lo
 int mFormatImportBmp(unsigned char* data, tResource *res) {
        int size;
        tImage img;
-       unsigned char aux[32700];
+       unsigned char* aux;
 
        if (!mReadBitMap(&img,data,res->size)) return 0;
-       mCompressGraphic(aux,&img,&size);
+       mCompressGraphic(&aux,&img,&size);
+       mWriteFileInDatFile(aux,size);
        free(img.pix);
-       mWriteSetFileInDatFile(aux,size);
-       res->size=(unsigned short)size; /* this was a bug (added to debug ;) ironic, don't you think? */
-       /* Note: after the debugging we realized this line was missing so this is not a bug anymore*/
+       free(aux);
+       res->size=(unsigned short)size;
+
        return 1;
 }
 
@@ -100,9 +107,11 @@ int mWriteBitMap(tImage img,const char* vFile,int optionflag,const char* backupE
        const unsigned long int zero=0;
        char lineSerialization;
        FILE* bitmap;
-
+fld("alpha");
        /* open file */
        if (!writeOpen(vFile,&bitmap,optionflag)) return 0;
+fld("beta");
+printf("a) %d+%d*%d,%d\n",img.pix,img.height,img.widthInBytes,img.widthInBytes);
 
        /* initialize variables */
        width=img.width;
@@ -114,23 +123,26 @@ int mWriteBitMap(tImage img,const char* vFile,int optionflag,const char* backupE
        r=(g=(b=(unsigned char*)&extra)+1)+1;
        lineSerialization=(-img.widthInBytes)&3;
        filesize=offset+(img.widthInBytes+lineSerialization)*height;
+printf("b) %d+%d*%d,%d\n",img.pix,img.height,img.widthInBytes,img.widthInBytes);
+fld("gamma");
 
        /* Write header */
-       fwrite("BM"       ,2,1,bitmap);    /* Magic identifier            */
-       fwrite(&filesize  ,4,1,bitmap);    /* File size in bytes          */
-       fwrite(&zero      ,4,1,bitmap);    /* reserved                    */
-       fwrite(&offset    ,4,1,bitmap);    /* Offset to image data, bytes */
-       fwrite(&headerSize,4,1,bitmap);    /* Header size in bytes        */
-       fwrite(&width     ,4,1,bitmap);    /* Width of image              */
-       fwrite(&height    ,4,1,bitmap);    /* Height of image             */
-       fwrite(&planes    ,2,1,bitmap);    /* Number of colour planes     */
-       fwrite(&bits      ,2,1,bitmap);    /* Bits per pixel              */
-       fwrite(&zero      ,4,1,bitmap);    /* Compression type (0=none)   */
-       fwrite(&zero      ,4,1,bitmap);    /* Image size in bytes         */
-       fwrite(&extra     ,4,1,bitmap);    /* Pixels per meter x          */
-       fwrite(&extra     ,4,1,bitmap);    /* Pixels per meter y          */
-       fwrite(&colours   ,4,1,bitmap);    /* Number of colours           */
-       fwrite(&zero      ,4,1,bitmap);    /* Important colours           */
+       fwrite     ("BM",2,1   ,bitmap);    /* Magic identifier            */
+       fwritelong (&filesize  ,bitmap);    /* File size in bytes          */
+       fwritelong (&zero      ,bitmap);    /* reserved                    */
+       fwritelong (&offset    ,bitmap);    /* Offset to image data, bytes */
+       fwritelong (&headerSize,bitmap);    /* Header size in bytes        */
+       fwritelong (&width     ,bitmap);    /* Width of image              */
+       fwritelong (&height    ,bitmap);    /* Height of image             */
+       fwriteshort(&planes    ,bitmap);    /* Number of colour planes     */
+       fwriteshort(&bits      ,bitmap);    /* Bits per pixel              */
+       fwritelong (&zero      ,bitmap);    /* Compression type (0=none)   */
+       fwritelong (&zero      ,bitmap);    /* Image size in bytes         */
+       fwritelong (&extra     ,bitmap);    /* Pixels per meter x          */
+       fwritelong (&extra     ,bitmap);    /* Pixels per meter y          */
+       fwritelong (&colours   ,bitmap);    /* Number of colours           */
+       fwritelong (&zero      ,bitmap);    /* Important colours           */
+fld("delta");
 
        /* Write ColorTable */
        if (colours==2) {
@@ -142,17 +154,23 @@ int mWriteBitMap(tImage img,const char* vFile,int optionflag,const char* backupE
                        *r=(unsigned char)(img.pal[x++]<<2);  /* Red   */
                        *g=(unsigned char)(img.pal[x++]<<2);  /* Green */
                        *b=(unsigned char)(img.pal[x++]<<2);  /* Blue  */
-                       fwrite(&extra,4,1,bitmap);    /* 24-bit Color value */
+                       fwritelong (&extra,bitmap);    /* 24-bit Color value */
                }
        }
+fld("epsilon");
 
        /* Write data */
        while (img.height--) {
+fld("e1");
+printf("c) %d+%d*%d,%d\n",img.pix,img.height,img.widthInBytes,img.widthInBytes);
                fwrite(img.pix+img.height*img.widthInBytes,img.widthInBytes,1,bitmap);
+fld("e2");
                fwrite(&zero,lineSerialization,1,bitmap);
        }
+fld("zeta");
 
        writeCloseOk(bitmap,optionflag,backupExtension);
+fld("etha");
        return 1;
 }
 
@@ -173,8 +191,8 @@ int mReadBitMap(tImage* image,unsigned char* data, int size) {
        ok    = size>50;
        ok=ok&& data[0]=='B' && data[1]=='M';
        /* Read sizes from header */
-       width=(unsigned short)(data[18]+(data[19]<<8));
-       height=(unsigned short)(data[22]+(data[23]<<8));
+       width=(unsigned short)array2short(data+18);
+       height=(unsigned short)array2short(data+22);
        bits=(unsigned short)(data[28]);
 
        /* Save sizes into image */
@@ -194,7 +212,7 @@ int mReadBitMap(tImage* image,unsigned char* data, int size) {
 
        /* Validate image and file size; get memory to allocate the image */
        ok=ok&& (filesize==size);
-       ok=ok&& (       (image->pix=getMemory(height*image->widthInBytes)) != NULL      );
+       ok=ok&& (       (image->pix=getMemory(height*image->widthInBytes*2)) != NULL    );
        /* if validations==wrong */
        if (!ok) {
                freeAllocation(image->pix);
index 5e895f46fede2e2512622f42865d16cd51ba5c1c..0cf5ce6e86fc2d4cdb0191c9b053fe21408923d1 100644 (file)
@@ -51,7 +51,7 @@ int mFormatImportMid(unsigned char* data, tResource *res) {
        file[0]=(unsigned char)((res->type==4)?2:0); /* Now should be 0x02: First character must be a 0x01 (wav type in dat) */
        memcpy(file+1,data,res->size);
        res->size++;
-       mWriteSetFileInDatFile(file,res->size);
+       mWriteFileInDatFile(file,res->size);
        free(file);
        return 1;
 }
index ff3b20bdce45ecc86cac75aa05ecfb7fcbb57c60..ca47143ba8efdb25c0d62c9f616bb7f6af69ba53 100644 (file)
@@ -135,7 +135,7 @@ int mFormatImportPal(unsigned char* data, tResource *res,const char* vFile) {
        }
 
        /* save and free palette */
-       mWriteSetFileInDatFile(pal,res->size=100);
+       mWriteFileInDatFile(pal,res->size=100);
        free(pal);
 
        return 1;
index 21b1843f8381960e5996876b5e53e2144d6cba44..4eb9b0d6a405a4579df74a5e770d1652a1b0b9bd 100644 (file)
@@ -187,7 +187,7 @@ int mFormatImportPlv(unsigned char* data, tResource *res) {
        if (!checkSum(pos,res->size)) return 0;
 
        /* save data */
-       mWriteSetFileInDatFileIgnoreChecksum(pos,res->size--);
+       mWriteFileInDatFileIgnoreChecksum(pos,res->size--);
 
        return 1;
 }
index d5ec6fb722ce2450f5e727696b09489e788a1509..ec1f985ea9f56f876d8d0c47d284211c89433682 100644 (file)
@@ -70,6 +70,6 @@ int mFormatImportWav(unsigned char* data, tResource *res) {
        res->size-=(--i);
        while ((i==4||i==5||i==6||i==7||i==40||i==41||i==42||i==43||(data[i]==wav[i]))&&(i--));
        data[sizeof(wav)-1]=1; /* First character must be a 0x01 (wav type in dat) */
-       if (i==-1) mWriteSetFileInDatFile(data+sizeof(wav)-1,res->size);
+       if (i==-1) mWriteFileInDatFile(data+sizeof(wav)-1,res->size);
        return 1;
 }
index 28b59cf42c465dc6b6dd8b561abdc272160c57c1..cb056e507b2a5bb2062e1932cbee851e0df9c92a 100644 (file)
@@ -38,11 +38,14 @@ dat.c: Princed Resources : DAT library
 #include "resources.h"
 #include "disk.h"
 #include "memory.h"
+#include "dat.h"
 
 /***************************************************************\
 |                     DAT reading primitives                    |
 \***************************************************************/
 
+#ifdef PR_DAT_INCLUDE_DATREAD
+
 char               recordSize;
 int                ofk=0;
 int                pop1;
@@ -100,14 +103,16 @@ int mReadBeginDatFile(unsigned short int *numberOfItems,const char* vFiledat){
        return 1;
 }
 
-int mReadGetFileInDatFile(int k,unsigned char* *data,unsigned long  int *size) {
-       int ok=1; /* TODO: rename mReadGet* for mRead* and mWriteSet for mWrite */
+int mReadFileInDatFile(int k,unsigned char* *data,unsigned long  int *size) {
+       int ok=1; /* TODO: rename mRead* for mRead* and mWrite for mWrite */
        unsigned short int id;
 
        /* for each archived file the index is read */
-       id=    (indexPointer[ofk+k*recordSize])+(indexPointer[ofk+k*recordSize+1]<<8);
-       offset=(indexPointer[ofk+k*recordSize+2])+(indexPointer[ofk+k*recordSize+3]<<8)+(indexPointer[ofk+k*recordSize+4]<<16)+(indexPointer[ofk+k*recordSize+5]<<24);
-       *size= (indexPointer[ofk+k*recordSize+6])+(indexPointer[ofk+k*recordSize+7]<<8)+1;
+       id=    array2short(indexPointer+ofk+k*recordSize);//(indexPointer[ofk+k*recordSize])+(indexPointer[ofk+k*recordSize+1]<<8);
+       printf("a ver: %d %d\n",id,(indexPointer[ofk+k*recordSize])+(indexPointer[ofk+k*recordSize+1]<<8));
+       
+       offset=array2long(indexPointer+ofk+k*recordSize+2);//indexPointer[ofk+k*recordSize+2])+(indexPointer[ofk+k*recordSize+3]<<8)+(indexPointer[ofk+k*recordSize+4]<<16)+(indexPointer[ofk+k*recordSize+5]<<24);
+       *size= array2short(indexPointer+ofk+k*recordSize+6);//indexPointer[ofk+k*recordSize+6])+(indexPointer[ofk+k*recordSize+7]<<8)+1;
        if ((!pop1)&&(!(indexPointer[ofk+k*recordSize+8]==0x40)&&(!indexPointer[ofk+k*recordSize+9])&&(!indexPointer[ofk+k*recordSize+10]))) return -1;
        if (offset+indexSize>readDatFileSize) return -1;
        *data=readDatFile+offset;
@@ -132,11 +137,13 @@ int mReadInitResource(tResource** res,const unsigned char* data,long size) {
        }
        return 0;
 }
+#endif
 
 /***************************************************************\
 |                     DAT Writing primitives                    |
 \***************************************************************/
 
+#ifdef PR_DAT_INCLUDE_DATWRITE
 FILE* writeDatFile;
 
 int mWriteBeginDatFile(const char* vFile, int optionflag) {
@@ -149,7 +156,6 @@ int mWriteBeginDatFile(const char* vFile, int optionflag) {
                         0 File couldn't be open
 
        */
-
        if (writeOpen(vFile,&writeDatFile,optionflag|backup_flag)) {
                fseek(writeDatFile,6,SEEK_SET);
                return 1;
@@ -161,11 +167,15 @@ int mWriteBeginDatFile(const char* vFile, int optionflag) {
 void mWriteInitResource(tResource** res) {
        if ((*res)==NULL) {
                (*res)=(tResource*)malloc(sizeof(tResource));
+               (*res)->path=NULL;
+               (*res)->palAux=NULL;
+               (*res)->desc=NULL;
+               (*res)->name=NULL;
        }
        (*res)->offset=(unsigned long)ftell(writeDatFile);
 }
 
-void mWriteSetFileInDatFile(unsigned char* data, int size) {
+void mWriteFileInDatFile(const unsigned char* data, int size) {
        /*
                Adds a data resource to a dat file keeping
                abstractly the checksum ver     ifications
@@ -174,18 +184,18 @@ void mWriteSetFileInDatFile(unsigned char* data, int size) {
        /* Declare variables */
        int            k        = size;
        unsigned char  checksum = 0;
-       unsigned char* dataAux  = data;
+       const unsigned char* dataAux  = data;
 
        /* calculates the checksum */
        while (k--) checksum+=*(dataAux++);
        checksum=~checksum;
 
        /* writes the checksum and the data content */
-       fwrite(&checksum,1,1,writeDatFile);
+       fwritechar(&checksum,writeDatFile);
        fwrite(data,size,1,writeDatFile);
 }
 
-void mWriteSetFileInDatFileIgnoreChecksum(unsigned char* data, int size) {
+void mWriteFileInDatFileIgnoreChecksum(unsigned char* data, int size) {
        fwrite(data,size,1,writeDatFile);
 }
 
@@ -199,33 +209,36 @@ void mWriteCloseDatFile(tResource* r[],int dontSave,int optionflag, const char*
        unsigned long  int size1=ftell(writeDatFile);
 
        /* Write index */
-       fwrite(&totalItems,2,1,writeDatFile); /* Junk total items count to reserve 2 bytes */
+       fwriteshort(&totalItems,writeDatFile); /* Junk total items count to reserve 2 bytes */
        for (;id!=MAX_RES_COUNT;id++) {
                if (r[id]!=NULL) {
                        /* the file is in the archive, so i'll add it to the index */
                        totalItems++;
-                       fwrite(&id,2,1,writeDatFile);
-                       fwrite(&(r[id]->offset),4,1,writeDatFile);
-                       fwrite(&(r[id]->size),2,1,writeDatFile);
+                       fwriteshort(&id,writeDatFile);
+                       fwritelong(&(r[id]->offset),writeDatFile);
+                       fwriteshort(&(r[id]->size),writeDatFile);
                }
        }
        size2+=totalItems<<3;
        fseek(writeDatFile,size1,SEEK_SET);
-       fwrite(&totalItems,2,1,writeDatFile); /* Definitive total items count */
+       fwriteshort(&totalItems,writeDatFile); /* Definitive total items count */
 
        /* Write first 6 bytes header */
        fseek(writeDatFile,0,SEEK_SET);
-       fwrite(&size1,4,1,writeDatFile);
-       fwrite(&size2,2,1,writeDatFile);
+       fwritelong(&size1,writeDatFile);
+       fwriteshort(&size2,writeDatFile);
 
        /* Closes the file and flushes the buffer */
        writeClose(writeDatFile,dontSave,optionflag,backupExtension);
 }
+#endif
 
 /***************************************************************\
 |                       DAT R/W primitives                      |
 \***************************************************************/
 
+#ifdef PR_DAT_INCLUDE_DATREAD
+#ifdef PR_DAT_INCLUDE_DATWRITE
 int mRWBeginDatFile(const char* vFile, unsigned short int *numberOfItems, int optionflag) {
        if (!mReadBeginDatFile(numberOfItems,vFile)) return -2;
        if (!mWriteBeginDatFile(vFile,optionflag)) {
@@ -234,10 +247,5 @@ int mRWBeginDatFile(const char* vFile, unsigned short int *numberOfItems, int op
        }
        return 0;
 }
-
-
-
-
-
-
-
+#endif
+#endif