author | ecalot
<ecalot> 2003-12-03 16:10:43 UTC |
committer | ecalot
<ecalot> 2003-12-03 16:10:43 UTC |
parent | 47ef79f3ec594e33fcea83ebe528676648d64611 |
PR/src/include/plv.h | +27 | -0 |
PR/src/lib/formats/Attic/plv.c | +133 | -0 |
diff --git a/PR/src/include/plv.h b/PR/src/include/plv.h new file mode 100644 index 0000000..4d99252 --- /dev/null +++ b/PR/src/include/plv.h @@ -0,0 +1,27 @@ + +#ifndef _PLV_H_ +#define _PLV_H_ + +#include <stdio.h> +#include "resources.h" + +char mFormatCompilePlv(unsigned char* data, FILE* fp, tResource *res); +char mFormatExtractPlv(unsigned char* data, char *vFileext,unsigned long int size,unsigned char level, char* filename, char* desc, char* title); + +//Dias de la semana y meses del anio +#define DATE_WEEKDAYS "Sun\0Mon\0Tue\0Wed\0Thu\0Fri\0Sat" +#define DATE_MONTHS "Jan\0Feb\0Mar\0Apr\0May\0Jun\0Jul\0Aug\0Sep\0Oct\0Nov\0Dec" + +#define PLV_HEADER_A "" +#define PLV_HEADER_A_SIZE sizeof(PLV_HEADER_A)-1 +#define PLV_HEADER_B "" +#define PLV_HEADER_B_SIZE sizeof(PLV_HEADER_B)-1 +#define PLV_FOOT "EDITORNAME\0PR\0EDITORVERS\00.9AUTHOR\0Pr User\0TITLE" +#define PLV_FOOT_DESC "DESCRIPTION" +#define PLV_FOOT_TCREAT "TIMECREATED" +#define PLV_FOOT_TMODIF "TIMELASTMODIF" +#define PLV_FOOT_ORIG_FILE "ORIGINALFILENAME" +#define PLV_HEADER_SIZE_OFFSET 1 + + +#endif diff --git a/PR/src/lib/formats/Attic/plv.c b/PR/src/lib/formats/Attic/plv.c new file mode 100644 index 0000000..221a862 --- /dev/null +++ b/PR/src/lib/formats/Attic/plv.c @@ -0,0 +1,133 @@ +/* Princed V3 - Prince of Persia Level Editor for PC Version + Copyright (C) 2003 Princed Development Team + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + The authors of this program may be contacted at http://forum.princed.com.ar +*/ + +/* +plv.c: Princed Resources : PLV prince level files support +\xaf\xaf\xaf\xaf\xaf + Copyright 2003 Princed Development Team + Created: 29 Nov 2003 + + Author: Enrique Calot <ecalot.cod@princed.com.ar> + Version: 1.00 (2003-Nov-29) + + PLV file format: + Defined: 28 Nov 2003 + + Authors: + Brendon James <roomshaker@princed.com.ar> + Enrique Calot <ecalot.cod@princed.com.ar> + Version: 1.00 (2003-Nov-28) + + + Note: + DO NOT remove this copyright notice +*/ + +//Includes +#include "plv.h" +#include "disk.h" +#include "compile.h" +#include "memory.h" +#include <string.h> +#include <time.h> + +//Private function to get the currect date/time +char* getDate() { + //Code taken from RDR 1.4.1a coded by Enrique Calot + //TODO: improve variable names + //TODO: define date string format for plv + + //Declare variables + static char semana [] = DATE_WEEKDAYS; + static char meses [] = DATE_MONTHS; + static char formated [37]; + time_t fechat; + struct tm* fecha; + int agno; + + time(&fechat); + fecha = gmtime(&fechat); + agno = (*fecha).tm_year+1900; + + //Format: "Tue, 26 Nov 2002 22:16:39 GMT" + sprintf(formated,"%s, %d %s %.4d %.2d:%.2d:%.2d GMT",(semana+(4*((*fecha).tm_wday))),((*fecha).tm_mday),(meses+(4*((*fecha).tm_mon))),agno,((*fecha).tm_hour),((*fecha).tm_min),((*fecha).tm_sec)); + return formated; +} + + +char mFormatExtractPlv(unsigned char* data, char *vFileext,unsigned long int size,unsigned char level, char* filename, char* desc, char* title) { + //Plv files are saved as raw except you must ignore the checksum and add the plv constant file header + + //Variables + FILE* target; + char ok; + char sizeOfNow; + char* now; + + //Get current time + now=getDate(); + sizeOfNow=strlen(now)+1; + + //Ignore checksum + size--; + + /* Writing file */ + + //Safe open for writing mode + ok=writeOpen(vFileext,&target); + + //Write headers + ok=ok&&fwrite(PLV_HEADER_A,PLV_HEADER_A_SIZE,1,target); + ok=ok&&fwrite(&level,1,1,target); + ok=ok&&fwrite(PLV_HEADER_B,PLV_HEADER_B_SIZE,1,target); + ok=ok&&fwrite(&size,1,sizeof(size),target); + + //Write raw data ignoring checksum + ok=ok&&fwrite(data+1,size,1,target); + + //Write footers + ok=ok&&fwrite(PLV_FOOT,sizeof(PLV_FOOT),1,target); + ok=ok&&fwrite(title,strlen(title)+1,1,target); + ok=ok&&fwrite(PLV_FOOT_DESC,sizeof(PLV_FOOT_DESC),1,target); + ok=ok&&fwrite(desc,strlen(desc)+1,1,target); + ok=ok&&fwrite(PLV_FOOT_TCREAT,sizeof(PLV_FOOT_TCREAT),1,target); + ok=ok&&fwrite(now,sizeOfNow,1,target); + ok=ok&&fwrite(PLV_FOOT_TMODIF,sizeof(PLV_FOOT_TMODIF),1,target); + ok=ok&&fwrite(now,sizeOfNow,1,target); + ok=ok&&fwrite(PLV_FOOT_ORIG_FILE,sizeof(PLV_FOOT_ORIG_FILE),1,target); + ok=ok&&fwrite(filename,strlen(filename)+1,1,target); + + ok=ok&&(!fclose(target)); + return ok; + +} + +char mFormatCompilePlv(unsigned char* data, FILE* fp, tResource *res) { + +// unsigned char* file; + unsigned long int size; + //This is ignoring all kind of verifications and assuming (res->size)>PLV_HEADER_SIZE !!! + //TODO: must verify the plv format version, if not 1, then PR is too old! + + memcpy(&size,data+PLV_HEADER_SIZE_OFFSET,4); //Only when longs are 4 bytes + mAddFileToDatFile(fp,data+PLV_HEADER_A_SIZE+PLV_HEADER_B_SIZE+1+4,size); +// free(file); + return 1; +}