author | ecalot
<ecalot> 2003-10-20 16:33:49 UTC |
committer | ecalot
<ecalot> 2003-10-20 16:33:49 UTC |
parent | 387b8ee5a4d8fb258ec28084a5c46553132278d7 |
PR/compile.bat | +0 | -2 |
PR/destroy.bat | +0 | -4 |
PR/doc/changelog.txt | +34 | -26 |
PR/doc/readme.coders.txt | +2 | -2 |
PR/doc/readme.txt | +1 | -5 |
PR/extract.bat | +0 | -9 |
PR/help.bat | +0 | -2 |
PR/makedll.bat | +0 | -2 |
PR/memory.h | +0 | -11 |
PR/ps.h | +0 | -5 |
PR/realres.txt | +0 | -253 |
PR/src/Makefile | +52 | -0 |
PR/src/addons/vb/samples/pr.dll | +0 | -0 |
PR/src/addons/vb/samples/prvbdll.zip | +0 | -0 |
PR/src/console/main.c | +226 | -0 |
PR/{resources.h => src/include/autodetect.h} | +0 | -0 |
PR/src/include/bitmap.h | +23 | -0 |
PR/src/{lib/formats => include}/bmp.h | +6 | -1 |
PR/{tasks.h => src/include/classify.h} | +7 | -0 |
PR/src/include/common.h | +28 | -0 |
PR/{pg.h => src/include/compress.h} | +2 | -2 |
PR/{extract.h => src/include/export.h} | +2 | -9 |
PR/src/include/idlist.h | +56 | -0 |
PR/src/include/image.h | +57 | -0 |
PR/{compile.h => src/include/import.h} | +1 | -5 |
PR/src/include/memory.h | +12 | -0 |
PR/src/include/mid.h | +5 | -0 |
PR/src/{lib/formats => include}/pal.h | +5 | -1 |
PR/{ => src/include}/parser.h | +0 | -0 |
PR/src/include/png.h | +23 | -0 |
PR/{ => src/include}/pr.h | +6 | -5 |
PR/src/include/tree.h | +56 | -0 |
PR/src/include/unknown.h | +56 | -0 |
PR/src/{lib/formats => include}/wav.h | +4 | -1 |
PR/{tasks.c => src/lib/actions/classify.c} | +2 | -0 |
PR/{extract.c => src/lib/actions/export.c} | +32 | -42 |
PR/{compile.c => src/lib/actions/import.c} | +10 | -2 |
PR/{pg.c => src/lib/compression/rle_compress.c} | +22 | -7 |
PR/src/lib/compression/rle_decompress.c | +250 | -0 |
PR/src/lib/compression/rlev_decompress.c | +250 | -0 |
PR/src/lib/formats/Attic/bmp.c | +43 | -11 |
PR/src/lib/formats/Attic/mid.c | +5 | -0 |
PR/src/lib/formats/Attic/pal.c | +22 | -4 |
PR/src/lib/formats/Attic/wav.c | +6 | -0 |
PR/src/lib/formats/mid.h | +0 | -0 |
PR/{resources.c => src/lib/layers/autodetect.c} | +9 | -5 |
PR/src/lib/layers/idlist.c | +303 | -0 |
PR/{ => src/lib/layers}/memory.c | +0 | -0 |
PR/src/lib/object/image/image16.c | +250 | -0 |
PR/src/lib/object/image/image2.c | +250 | -0 |
PR/src/lib/object/image/image256.c | +250 | -0 |
PR/src/lib/object/image/image_common.c | +250 | -0 |
PR/{ => src/lib}/pr.c | +7 | -21 |
PR/src/lib/xml/tree.c | +303 | -0 |
PR/src/lib/xml/unknown.c | +303 | -0 |
PR/{ => src}/parser.c | +2 | -0 |
PR/{ => src/ports/winfiles}/pr.def | +0 | -0 |
PR/{ => src/ports/winfiles}/pr.dll | +0 | -0 |
PR/{ => src/ports/winfiles}/pr.exe | +0 | -0 |
PR/{ => src/ports/winfiles}/pr.exp | +0 | -0 |
PR/{ => src/ports/winfiles}/pr.lib | +0 | -0 |
PR/{ => src/ports/winfiles}/pr.obj | +0 | -0 |
PR/{ => src}/resources.txt | +0 | -0 |
PR/{ => src}/resources.xml | +0 | -0 |
PR/vd.bat | +0 | -2 |
PR/vdr.bat | +0 | -3 |
PR/vp.bat | +0 | -2 |
diff --git a/PR/compile.bat b/PR/compile.bat deleted file mode 100755 index 2d15a2a..0000000 --- a/PR/compile.bat +++ /dev/null @@ -1,2 +0,0 @@ -@echo off -pr comp\%1 -c ext \ No newline at end of file diff --git a/PR/destroy.bat b/PR/destroy.bat deleted file mode 100755 index b1845cf..0000000 --- a/PR/destroy.bat +++ /dev/null @@ -1,4 +0,0 @@ -@echo off -pr . -t -deltree /Y ext -mkdir ext \ No newline at end of file diff --git a/PR/doc/changelog.txt b/PR/doc/changelog.txt index 06bcc1e..1e40900 100644 --- a/PR/doc/changelog.txt +++ b/PR/doc/changelog.txt @@ -1,4 +1,4 @@ -Princed Resources Editor V0.6 beta +Princed Resources Editor V0.7 (c) Copyright 2003 - Princed Development Team http://www.princed.com.ar This program is open source under the GNU General Public License terms @@ -13,54 +13,62 @@ This program is open source under the GNU General Public License terms - Added support to indexed dat files * PR 0.1 Alpha - Merged PS and PG into one extractor. - - Added resource.txt parser. - - Solved several bugs. - - Coded type header verification - Added dynamic palette extraction - - Added support to export JASC palette for .pal files. + - Added resource.txt parser. - Added support to .wav files. + - Added support to export JASC palette for .pal files. + - Coded type header verification + - Solved several bugs. * PR 0.2 Alpha - - Added support to import .bmp files - - Source files were abstracted - Added classifing dat type feature + - Added support to import .bmp files - Implemented CGI output support for UNIX versions + - Source files were abstracted * PR 0.3 beta - - Added pr.dll compiling - Added modifiers -x[rnu] -c[r] - - Solved bugs in bitmap format - - Solved segmentation fault in title.dat + - Added pr.dll compiling + - Bitmaps aren't upside down anymore - Images bigger than 256 pixels lenght or width now are recognized - Improved decompression algorithm in bigger images - Optimized bitmap handling - - Bitmaps aren't upside down anymore + - Solved bugs in bitmap format + - Solved segmentation fault in title.dat * PR 0.4 beta - Fixed a memory bug since v0.3 - Pop2 DAT files detected (file type 11) * PR 0.5 beta - - Optimized bmp saving algorithm - Abstracted format handling + - Optimized bmp saving algorithm - Solved and optimized decompression for big images - Some Pop2 graphics are extracted (palettes aren't supported yet) * PR 0.6 alpha - - Optimized PG algorithms and reserved memory sizes - - Completed and tested bmp reading algorithm - Coded full import/export bmp (in separate files not included in this distribution) + - Completed and tested bmp reading algorithm + - Optimized PG algorithms and reserved memory sizes * PR 0.6 beta - Added full import bmp support + - Solved palette import bug + * PR 0.7 + x Solved corrupted images on compression bug + x Source changed to ANSI C compatible + - Moved PG module to compress.c and bmp.c + - Moved midi support to mid.c + - Added Makefile + 2) ToDo List - i) Fix bug in palette compiling - ii) Improve support of bitmap compiling - iii) Codify the compression algorithms (B1 to B4) to optimize the bitmap compiled dat files - iv) Move PG to bmp.c (only when all bitmaps are Ok) - v) Add full pop2 support - vi) Add resources tree. See the sample resources.xml - vii) Change the code to ANSI C + i) Code the compression algorithms (B0, B1, B2) to optimize the bitmap compiled dat files + ii) Add full pop2 support + iii) Add resources tree in xml. See the sample resources.xml and folder.xml + iv) Code the compression algorithms (B3, B4) to optimize the bitmap compiled dat files + v) Add a C++ class to use PR -3) Versions: - PR v0.6 beta: unestable, added ii, iv, first full working version - PR v0.7: vii, tested & stable - PR v0.8 beta: added i,iii,vi +3) Future Versions: + PR v0.8 beta: added i,iii PR v0.9: tested and stable - PR v1.0: First optimized & stable version for win32 and linux + PR v1.0: First optimized & stable version for win32 and unix based systems + PR v1.1: added v + PR v1.5: added iv + PR v2.0 beta: added ii + PR v2.0: Optimized & stable version for win32 and unix based systems diff --git a/PR/doc/readme.coders.txt b/PR/doc/readme.coders.txt index c96b68b..9122a68 100644 --- a/PR/doc/readme.coders.txt +++ b/PR/doc/readme.coders.txt @@ -1,4 +1,4 @@ -Princed Resources Handler V0.6 beta +Princed Resources Handler V0.7 (c) Copyright 2003 - Princed Development Team http://www.princed.com.ar This program is open source under the GNU General Public License terms @@ -9,7 +9,7 @@ GCC with the C99 standard will work: -shell-2.05b$ gcc -std=c99 pr.c -o pr -shell-2.05b$ ./pr -Princed resources (PR) V0.5 beta. +Princed resources (PR) V0.7 (c) Copyright 2003 - Princed Development Team http://www.princed.com.ar diff --git a/PR/doc/readme.txt b/PR/doc/readme.txt index 2cd1af1..90e7d4a 100644 --- a/PR/doc/readme.txt +++ b/PR/doc/readme.txt @@ -1,4 +1,4 @@ -Princed Resources Editor V0.6 beta +Princed Resources Editor V0.7 (c) Copyright 2003 - Princed Development Team http://www.princed.com.ar This program is open source under the GNU General Public License terms @@ -127,8 +127,4 @@ Type 06: 4) New versions It's strongly recommended that you download a newer stable version of this program as soon as it comes available in the official url (http://www.princed.com.ar) -5) Platforms - Binary files are compiled in DOS/Win32 console (v0.5) and in Unix/Alpha versions (v0.5). The DOS executable is pr.exe and the Unix executable is prunix. The Unix version will be used to automate the classification of server uploaded files in our unix-based web server. - - Please enjoy using Princed Resource Editor! \ No newline at end of file diff --git a/PR/extract.bat b/PR/extract.bat deleted file mode 100755 index 61c3b33..0000000 --- a/PR/extract.bat +++ /dev/null @@ -1,9 +0,0 @@ -@echo off -if not exist dat\%1 goto error -pr dat\%1 -x ext >%1.txt -dir ext\res*.* >realres.txt -goto end -:error -echo The file '%1' does not exist in dat folder -echo: -:end \ No newline at end of file diff --git a/PR/help.bat b/PR/help.bat deleted file mode 100755 index 6e7c31b..0000000 --- a/PR/help.bat +++ /dev/null @@ -1,2 +0,0 @@ -@echo off -type readme.txt |more \ No newline at end of file diff --git a/PR/makedll.bat b/PR/makedll.bat deleted file mode 100755 index be3dacd..0000000 --- a/PR/makedll.bat +++ /dev/null @@ -1,2 +0,0 @@ -@echo off -c:\archiv~1\lcc\bin\lcclnk.exe -dll pr.obj pr.def \ No newline at end of file diff --git a/PR/memory.h b/PR/memory.h deleted file mode 100644 index a60d215..0000000 --- a/PR/memory.h +++ /dev/null @@ -1,11 +0,0 @@ - -#ifndef _MEMORY_H_ -#define _MEMORY_H_ - -#include <stdlib.h> - -//Reserves a memory space to allocate an image -unsigned char* getMemory(int size); - -#endif - diff --git a/PR/ps.h b/PR/ps.h deleted file mode 100644 index 8ebecfe..0000000 --- a/PR/ps.h +++ /dev/null @@ -1,5 +0,0 @@ - -#ifndef _PS_H_ -#define _PS_H_ - -#endif diff --git a/PR/realres.txt b/PR/realres.txt deleted file mode 100644 index 2180382..0000000 --- a/PR/realres.txt +++ /dev/null @@ -1,253 +0,0 @@ - - El volumen de la unidad C es KKX1 - El n\xa3mero de serie del volumen es 9336-E800 - Directorio de C:\WINDOWS\Escritorio\princed\pr\prlib\ext - -RES00200 PAL 194 08/07/03 12.49 res00200.pal -RES00201 EXT 1 08/07/03 12.49 res00201.ext -RES00202 EXT 1 08/07/03 12.49 res00202.ext -RES00203 EXT 1 08/07/03 12.49 res00203.ext -RES00204 EXT 1 08/07/03 12.49 res00204.ext -RES00205 EXT 1 08/07/03 12.49 res00205.ext -RES00206 EXT 1 08/07/03 12.49 res00206.ext -RES00207 EXT 1 08/07/03 12.49 res00207.ext -RES00208 EXT 1 08/07/03 12.49 res00208.ext -RES00209 EXT 1 08/07/03 12.49 res00209.ext -RES00210 EXT 1 08/07/03 12.49 res00210.ext -RES00211 EXT 1 08/07/03 12.49 res00211.ext -RES00212 EXT 1 08/07/03 12.49 res00212.ext -RES00213 EXT 1 08/07/03 12.49 res00213.ext -RES00214 EXT 1 08/07/03 12.49 res00214.ext -RES00215 EXT 1 08/07/03 12.49 res00215.ext -RES00216 EXT 1 08/07/03 12.49 res00216.ext -RES00217 EXT 1 08/07/03 12.49 res00217.ext -RES00218 EXT 1 08/07/03 12.49 res00218.ext -RES00219 EXT 1 08/07/03 12.49 res00219.ext -RES00220 EXT 1 08/07/03 12.49 res00220.ext -RES00221 EXT 1 08/07/03 12.49 res00221.ext -RES00222 EXT 1 08/07/03 12.49 res00222.ext -RES00223 EXT 1 08/07/03 12.49 res00223.ext -RES00224 EXT 1 08/07/03 12.49 res00224.ext -RES00225 EXT 1 08/07/03 12.49 res00225.ext -RES00226 EXT 1 08/07/03 12.49 res00226.ext -RES00227 EXT 1 08/07/03 12.49 res00227.ext -RES00228 EXT 1 08/07/03 12.49 res00228.ext -RES00229 EXT 1 08/07/03 12.49 res00229.ext -RES00230 EXT 1 08/07/03 12.49 res00230.ext -RES00231 EXT 1 08/07/03 12.49 res00231.ext -RES00232 BMP 214 08/07/03 12.49 res00232.bmp -RES00233 BMP 262 08/07/03 12.49 res00233.bmp -RES00234 BMP 262 08/07/03 12.49 res00234.bmp -RES00235 BMP 374 08/07/03 12.49 res00235.bmp -RES00236 BMP 166 08/07/03 12.49 res00236.bmp -RES00237 BMP 1.078 08/07/03 12.49 res00237.bmp -RES00238 BMP 374 08/07/03 12.49 res00238.bmp -RES00239 BMP 1.110 08/07/03 12.49 res00239.bmp -RES00240 BMP 374 08/07/03 12.49 res00240.bmp -RES00241 BMP 326 08/07/03 12.49 res00241.bmp -RES00242 BMP 358 08/07/03 12.49 res00242.bmp -RES00243 BMP 166 08/07/03 12.49 res00243.bmp -RES00244 BMP 550 08/07/03 12.49 res00244.bmp -RES00245 BMP 470 08/07/03 12.49 res00245.bmp -RES00246 BMP 1.078 08/07/03 12.49 res00246.bmp -RES00247 BMP 1.110 08/07/03 12.49 res00247.bmp -RES00248 BMP 326 08/07/03 12.49 res00248.bmp -RES00249 BMP 358 08/07/03 12.49 res00249.bmp -RES00250 BMP 262 08/07/03 12.49 res00250.bmp -RES00251 BMP 198 08/07/03 12.49 res00251.bmp -RES00252 BMP 214 08/07/03 12.49 res00252.bmp -RES00253 BMP 202 08/07/03 12.49 res00253.bmp -RES00254 BMP 190 08/07/03 12.49 res00254.bmp -RES00255 BMP 178 08/07/03 12.49 res00255.bmp -RES00256 BMP 166 08/07/03 12.49 res00256.bmp -RES00257 BMP 154 08/07/03 12.49 res00257.bmp -RES00258 BMP 142 08/07/03 12.49 res00258.bmp -RES00259 BMP 130 08/07/03 12.49 res00259.bmp -RES00260 BMP 226 08/07/03 12.49 res00260.bmp -RES00261 BMP 226 08/07/03 12.49 res00261.bmp -RES00262 BMP 226 08/07/03 12.49 res00262.bmp -RES00263 BMP 226 08/07/03 12.49 res00263.bmp -RES00264 BMP 226 08/07/03 12.49 res00264.bmp -RES00265 BMP 226 08/07/03 12.49 res00265.bmp -RES00266 BMP 226 08/07/03 12.49 res00266.bmp -RES00267 BMP 226 08/07/03 12.49 res00267.bmp -RES00268 EXT 23 08/07/03 12.49 res00268.ext -RES00269 BMP 342 08/07/03 12.49 res00269.bmp -RES00270 BMP 326 08/07/03 12.49 res00270.bmp -RES00271 BMP 374 08/07/03 12.49 res00271.bmp -RES00272 BMP 374 08/07/03 12.49 res00272.bmp -RES00273 BMP 166 08/07/03 12.49 res00273.bmp -RES00274 BMP 166 08/07/03 12.49 res00274.bmp -RES00275 EXT 1 08/07/03 12.49 res00275.ext -RES00276 EXT 1 08/07/03 12.49 res00276.ext -RES00277 EXT 1 08/07/03 12.49 res00277.ext -RES00278 EXT 1 08/07/03 12.49 res00278.ext -RES00279 EXT 1 08/07/03 12.49 res00279.ext -RES00280 EXT 1 08/07/03 12.49 res00280.ext -RES00281 EXT 1 08/07/03 12.49 res00281.ext -RES00282 EXT 1 08/07/03 12.49 res00282.ext -RES00283 EXT 1 08/07/03 12.49 res00283.ext -RES00284 EXT 1 08/07/03 12.49 res00284.ext -RES00285 BMP 182 08/07/03 12.49 res00285.bmp -RES00286 EXT 1 08/07/03 12.49 res00286.ext -RES00287 EXT 1 08/07/03 12.49 res00287.ext -RES00288 EXT 1 08/07/03 12.49 res00288.ext -RES00289 EXT 1 08/07/03 12.49 res00289.ext -RES00290 EXT 1 08/07/03 12.49 res00290.ext -RES00291 EXT 1 08/07/03 12.49 res00291.ext -RES00292 BMP 1.078 08/07/03 12.49 res00292.bmp -RES00293 BMP 1.110 08/07/03 12.49 res00293.bmp -RES00294 BMP 174 08/07/03 12.49 res00294.bmp -RES00295 BMP 838 08/07/03 12.49 res00295.bmp -RES00296 BMP 166 08/07/03 12.49 res00296.bmp -RES00297 BMP 326 08/07/03 12.49 res00297.bmp -RES00298 BMP 374 08/07/03 12.49 res00298.bmp -RES00299 BMP 214 08/07/03 12.49 res00299.bmp -RES00300 BMP 262 08/07/03 12.49 res00300.bmp -RES00301 EXT 1 08/07/03 12.49 res00301.ext -RES00302 EXT 1 08/07/03 12.49 res00302.ext -RES00303 EXT 1 08/07/03 12.49 res00303.ext -RES00304 EXT 1 08/07/03 12.49 res00304.ext -RES00305 EXT 1 08/07/03 12.49 res00305.ext -RES00306 EXT 1 08/07/03 12.49 res00306.ext -RES00307 EXT 1 08/07/03 12.49 res00307.ext -RES00308 EXT 1 08/07/03 12.49 res00308.ext -RES00309 EXT 1 08/07/03 12.49 res00309.ext -RES00310 EXT 1 08/07/03 12.49 res00310.ext -RES00311 EXT 1 08/07/03 12.49 res00311.ext -RES00312 EXT 1 08/07/03 12.49 res00312.ext -RES00313 EXT 1 08/07/03 12.49 res00313.ext -RES00314 EXT 1 08/07/03 12.49 res00314.ext -RES00315 EXT 1 08/07/03 12.49 res00315.ext -RES00316 EXT 1 08/07/03 12.49 res00316.ext -RES00317 EXT 1 08/07/03 12.49 res00317.ext -RES00318 EXT 1 08/07/03 12.49 res00318.ext -RES00319 EXT 1 08/07/03 12.49 res00319.ext -RES00320 EXT 1 08/07/03 12.49 res00320.ext -RES00321 EXT 1 08/07/03 12.49 res00321.ext -RES00322 EXT 1 08/07/03 12.49 res00322.ext -RES00323 EXT 1 08/07/03 12.49 res00323.ext -RES00324 BMP 630 08/07/03 12.49 res00324.bmp -RES00325 BMP 646 08/07/03 12.49 res00325.bmp -RES00326 BMP 950 08/07/03 12.49 res00326.bmp -RES00327 EXT 1 08/07/03 12.49 res00327.ext -RES00328 EXT 1 08/07/03 12.49 res00328.ext -RES00329 EXT 1 08/07/03 12.49 res00329.ext -RES00330 EXT 1 08/07/03 12.49 res00330.ext -RES00331 EXT 1 08/07/03 12.49 res00331.ext -RES00332 EXT 1 08/07/03 12.49 res00332.ext -RES00333 EXT 1 08/07/03 12.49 res00333.ext -RES00334 EXT 1 08/07/03 12.49 res00334.ext -RES00335 EXT 1 08/07/03 12.49 res00335.ext -RES00336 EXT 1 08/07/03 12.49 res00336.ext -RES00337 EXT 1 08/07/03 12.49 res00337.ext -RES00338 EXT 1 08/07/03 12.49 res00338.ext -RES00339 EXT 1 08/07/03 12.49 res00339.ext -RES00340 EXT 1 08/07/03 12.49 res00340.ext -RES00341 EXT 1 08/07/03 12.49 res00341.ext -RES00342 EXT 1 08/07/03 12.49 res00342.ext -RES00343 EXT 1 08/07/03 12.49 res00343.ext -RES00344 BMP 1.198 08/07/03 12.49 res00344.bmp -RES00345 EXT 1 08/07/03 12.49 res00345.ext -RES00346 BMP 358 08/07/03 12.49 res00346.bmp -RES00347 BMP 342 08/07/03 12.49 res00347.bmp -RES00348 BMP 342 08/07/03 12.49 res00348.bmp -RES00349 BMP 166 08/07/03 12.49 res00349.bmp -RES00350 BMP 238 08/07/03 12.49 res00350.bmp -RES00351 BMP 238 08/07/03 12.49 res00351.bmp -RES00360 PAL 194 08/07/03 12.49 res00360.pal -RES00361 BMP 1.110 08/07/03 12.49 res00361.bmp -RES00362 BMP 310 08/07/03 12.49 res00362.bmp -RES00363 BMP 166 08/07/03 12.49 res00363.bmp -RES00364 BMP 1.078 08/07/03 12.49 res00364.bmp -RES00365 BMP 166 08/07/03 12.49 res00365.bmp -RES00366 BMP 1.078 08/07/03 12.49 res00366.bmp -RES00367 BMP 166 08/07/03 12.49 res00367.bmp -RES00368 BMP 1.078 08/07/03 12.49 res00368.bmp -RES00369 BMP 166 08/07/03 12.49 res00369.bmp -RES00370 BMP 1.078 08/07/03 12.49 res00370.bmp -RES00371 BMP 286 08/07/03 12.49 res00371.bmp -RES00372 BMP 202 08/07/03 12.49 res00372.bmp -RES00373 BMP 454 08/07/03 12.49 res00373.bmp -RES00374 BMP 158 08/07/03 12.49 res00374.bmp -RES00375 BMP 158 08/07/03 12.49 res00375.bmp -RES00376 BMP 158 08/07/03 12.49 res00376.bmp -RES00377 BMP 158 08/07/03 12.49 res00377.bmp -RES01230 BMP 422 08/07/03 12.49 res01230.bmp -RES01231 BMP 454 08/07/03 12.49 res01231.bmp -RES01286 BMP 1.078 08/07/03 12.49 res01286.bmp -RES01287 BMP 1.110 08/07/03 12.49 res01287.bmp -RES01288 BMP 838 08/07/03 12.49 res01288.bmp -RES01289 BMP 622 08/07/03 12.49 res01289.bmp -RES01290 BMP 190 08/07/03 12.49 res01290.bmp -RES01291 BMP 874 08/07/03 12.49 res01291.bmp -RES01301 BMP 1.078 08/07/03 12.49 res01301.bmp -RES01302 BMP 1.078 08/07/03 12.49 res01302.bmp -RES01303 BMP 598 08/07/03 12.49 res01303.bmp -RES01304 BMP 454 08/07/03 12.49 res01304.bmp -RES01305 BMP 390 08/07/03 12.49 res01305.bmp -RES01306 BMP 598 08/07/03 12.49 res01306.bmp -RES01307 BMP 598 08/07/03 12.49 res01307.bmp -RES01308 BMP 598 08/07/03 12.49 res01308.bmp -RES01309 BMP 598 08/07/03 12.49 res01309.bmp -RES01310 BMP 598 08/07/03 12.49 res01310.bmp -RES01311 BMP 486 08/07/03 12.49 res01311.bmp -RES01312 BMP 274 08/07/03 12.49 res01312.bmp -RES01313 BMP 238 08/07/03 12.49 res01313.bmp -RES01314 EXT 33 08/07/03 12.49 res01314.ext -RES01315 EXT 30 08/07/03 12.49 res01315.ext -RES01316 EXT 23 08/07/03 12.49 res01316.ext -RES01317 EXT 14 08/07/03 12.49 res01317.ext -RES01318 EXT 10 08/07/03 12.49 res01318.ext -RES01319 EXT 17 08/07/03 12.49 res01319.ext -RES01320 EXT 21 08/07/03 12.49 res01320.ext -RES01321 EXT 21 08/07/03 12.49 res01321.ext -RES01322 EXT 12 08/07/03 12.49 res01322.ext -RES01323 EXT 9 08/07/03 12.49 res01323.ext -RES01327 BMP 326 08/07/03 12.49 res01327.bmp -RES01328 BMP 238 08/07/03 12.49 res01328.bmp -RES01329 BMP 438 08/07/03 12.49 res01329.bmp -RES01330 BMP 550 08/07/03 12.49 res01330.bmp -RES01331 BMP 534 08/07/03 12.49 res01331.bmp -RES01332 BMP 534 08/07/03 12.49 res01332.bmp -RES01333 BMP 358 08/07/03 12.49 res01333.bmp -RES01334 BMP 130 08/07/03 12.49 res01334.bmp -RES01335 BMP 238 08/07/03 12.49 res01335.bmp -RES01336 BMP 238 08/07/03 12.49 res01336.bmp -RES01337 BMP 278 08/07/03 12.49 res01337.bmp -RES01338 BMP 270 08/07/03 12.49 res01338.bmp -RES01339 BMP 158 08/07/03 12.49 res01339.bmp -RES01340 BMP 326 08/07/03 12.49 res01340.bmp -RES01341 BMP 502 08/07/03 12.49 res01341.bmp -RES01342 BMP 486 08/07/03 12.49 res01342.bmp -RES01343 BMP 454 08/07/03 12.49 res01343.bmp -RES00040 PAL 183 08/07/03 12.44 res00040.pal -RES00041 BMP 32.118 08/07/03 12.44 res00041.bmp -RES00042 EXT 1.656 08/07/03 12.44 res00042.ext -RES00043 EXT 1.620 08/07/03 12.44 res00043.ext -RES00044 EXT 1.822 08/07/03 12.44 res00044.ext -RES00045 EXT 1.459 08/07/03 12.44 res00045.ext -RES00050 PAL 188 08/07/03 12.44 res00050.pal -RES00051 BMP 32.118 08/07/03 12.44 res00051.bmp -RES00052 BMP 3.126 08/07/03 12.44 res00052.bmp -RES00053 BMP 2.038 08/07/03 12.44 res00053.bmp -RES00054 BMP 8.958 08/07/03 12.44 res00054.bmp -RES00055 BMP 1.350 08/07/03 12.44 res00055.bmp -RES02000 PET 2.304 16/04/03 20.35 res02000.pet -RES02001 PET 2.304 16/04/03 20.35 res02001.pet -RES02002 PET 2.304 16/04/03 20.35 res02002.pet -RES02003 PET 2.304 16/04/03 20.35 res02003.pet -RES02004 PET 2.304 16/04/03 20.35 res02004.pet -RES02005 PET 2.304 16/04/03 20.35 res02005.pet -RES02006 PET 2.304 16/04/03 20.35 res02006.pet -RES02007 PET 2.304 16/04/03 20.35 res02007.pet -RES02008 PET 2.304 16/04/03 20.35 res02008.pet -RES02009 PET 2.304 16/04/03 20.35 res02009.pet -RES02010 PET 2.304 16/04/03 20.35 res02010.pet -RES02011 PET 2.304 16/04/03 20.35 res02011.pet -RES02012 PET 2.304 16/04/03 20.35 res02012.pet -RES02013 PET 2.304 16/04/03 20.35 res02013.pet -RES02014 PET 2.304 16/04/03 20.35 res02014.pet -RES02015 PET 2.303 16/04/03 20.35 res02015.pet - 246 archivos 175.570 bytes - 0 directorios 26.423,94 MB libres diff --git a/PR/src/Makefile b/PR/src/Makefile new file mode 100644 index 0000000..aec6396 --- /dev/null +++ b/PR/src/Makefile @@ -0,0 +1,52 @@ +bin/pr: compile.o compress.o extract.o parser.o pr.o resources.o tasks.o bmp.o mid.o pal.o wav.o + + @echo Linking files... + @gcc -o bin/pr compile.o compress.o extract.o parser.o pr.o resources.o tasks.o bmp.o mid.o pal.o wav.o -s + @echo Program succesfully compiled + @echo + @echo Please read readme.txt for syntax information + @echo + +parser.o: parser.c + @echo Compiling parsing library... + @gcc -c parser.c -Iinclude/ + +compile.o: compile.c + @echo Compiling import module... + @gcc -c compile.c -Iinclude/ -O3 + +extract.o: extract.c + @echo Compiling export module... + @gcc -c extract.c -Iinclude/ -O3 + +compress.o: compress.c + @echo Compiling compression module... + @gcc -c compress.c -Iinclude/ -O3 + +pr.o: pr.c + @echo Compiling main module... + @gcc -c pr.c -Iinclude/ + +resources.o: resources.c + @echo Compiling resource manager module... + @gcc -c resources.c -Iinclude/ + +tasks.o: tasks.c + @echo Compiling extra tasks module... + @gcc -c tasks.c -Iinclude/ -O3 + +bmp.o: formats/bmp.c + @echo Compiling bitmap files support \(bmp\)... + @gcc -c formats/bmp.c -Iinclude/ -O3 + +mid.o: formats/mid.c + @echo Compiling midi audio files support \(mid\)... + @gcc -c formats/mid.c -Iinclude/ + +pal.o: formats/pal.c + @echo Compiling JASC palette support \(pal\)... + @gcc -c formats/pal.c -Iinclude/ + +wav.o: formats/wav.c + @echo Compiling digital wave audio support \(wav\)... + @gcc -c formats/wav.c -Iinclude/ diff --git a/PR/src/addons/vb/samples/pr.dll b/PR/src/addons/vb/samples/pr.dll index 60f5994..eb545ad 100644 Binary files a/PR/src/addons/vb/samples/pr.dll and b/PR/src/addons/vb/samples/pr.dll differ diff --git a/PR/src/addons/vb/samples/prvbdll.zip b/PR/src/addons/vb/samples/prvbdll.zip deleted file mode 100644 index 991cb8b..0000000 Binary files a/PR/src/addons/vb/samples/prvbdll.zip and /dev/null differ diff --git a/PR/src/console/main.c b/PR/src/console/main.c new file mode 100644 index 0000000..eddc1b7 --- /dev/null +++ b/PR/src/console/main.c @@ -0,0 +1,226 @@ +/* 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 +*/ + +/* +pr.c: Main source file for Princed Resources +\xaf\xaf\xaf\xaf + Princed Resources editor + (c) Copyright 2003, Princed Development Team + + Authors + Coding & main routines + Enrique Calot + + Graphic compression algorithms + Tammo Jan Dijkema + Enrique Calot + + Graphic format development + Tammo Jan Dijkema + Anke Balderer + + MID Sound format development + Christian Lundheim + + Note: + DO NOT remove this copyright notice +*/ + +//Headers +#include <string.h> + +#include "pr.h" + +#include "compress.h" + +#include "extract.h" +#include "compile.h" +#include "tasks.h" + +//functions + +int prExportDat(char* vDatFile, char* vDirName, char* vResFile) { + return prExportDatOpt(vDatFile,vDirName,vResFile,3); +} + +int prExportDatOpt(char* vDatFile, char* vDirName, char* vResFile,char opt) { + /* + Options: + 0 - none + 1 - extract + 2 - update resources (rebuild resources list) + 3 - 1&2 + 4 - use raw file if extraction + 5 - 1&4 + 8 - Don't save + + Return values: + 00 Ok + -1 Error accesing the file + -2 Memory error + -3 Invalid DAT file + */ + tResource* r[65536]; + int a; + parseFile (vResFile,r); + //printf("kkkkkkkkkkk: %x\n",opt); + a=extract(vDatFile, vDirName,r,opt); + if (!(opt&8)) generateFile(vResFile,r); + return a; +} + +int prImportDat(char* vDatFile, char* vDirName, char* vResFile) { + return prImportDatOpt(vDatFile,vDirName,vResFile,1); +} + +int prImportDatOpt(char* vDatFile, char* vDirName, char* vResFile,char opt) { + /* + Options: + 0 - use raw files + 1 - read data type + + Return values: + -1 File couldn't be open for writing + 00 File succesfully compiled + positive number: number of missing files + */ + tResource* r[65536]; + int a; + parseFile (vResFile,r); + a=compile (vDatFile, vDirName,r,opt); + generateFile (vResFile,r); + return a; +} + +int prClearRes(char* vResFile) { + /* + Return values: + 01 Ok + 00 Error + */ + tResource* r[65536]; + emptyTable(r); + return generateFile(vResFile,r); +} + + + +//Main program +#ifndef DLL +void syntax() { + printf("Syntax:\r\n pr datfile option [extract dir]\r\n\r\nValid options:\r\n -x[rnus] for extract\r\n r: raw extraction\r\n n: don't extract\r\n u: update res file in case there were records\r\n s: don't save res file\r\n -c[r] for compile\r\n r: raw compiling\r\n -d for type\r\n -t to clear the resource file.\r\n"); +} + +int main(int argc, char* argv[]) { + + //declare variables + char dir[260]="."; + int returnValue=1; + int option; + int i; + + //bmp vars + char vFileraw[100]; + char vFilebmp[100]; + unsigned char* data; + tImage img; + int size; + +#ifdef UNIX + if (argc==2) { + printf("Content-Type:text/html\n\nRunning as a cgi\n"); + printf("Result: %02d type\r\n",prVerifyDatType(argv[1])); + return 1; + } +#endif + + printf(PR_ABOUT); + + //Verify syntax + if ((argc<3)||(argc>4)||(argv[2][0])!='-') { + syntax(); + return -1; + } + if (argc==4) { + sprintf(dir,argv[3]); + } + + //do selected taskbars + switch (argv[2][1]) { + case 'e': + case 'x': // file.dat --> files.ext + resource.txt + option=1; + for (i=2;argv[2][i];i++) { + switch (argv[2][i]) { + case 'n':option&=0xFE;break; + case 'r':option|=0x04;break; + case 'u':option|=0x02;break; + case 's':option|=0x08;break; + default:printf("Found invalid option '%c', skiping . . .\r\n",argv[2][i]);break; + } + } + printf("Extracting '%s' to '%s' with %d\r\n",argv[1],dir,option); + printf("Result: %d\r\n",returnValue=prExportDatOpt(argv[1],dir,"resources.txt",option)); + break; + case 'd': // get type of file.dat + printf("Classifing '%s'\r\n",argv[1]); + printf("Result: %d type\r\n",returnValue=prVerifyDatType(argv[1])); + break; + case 'i': + case 'c': // files.ext + resource.txt --> files.dat + option=1; + for (i=2;argv[2][i];i++) { + switch (argv[2][i]) { + case 'r':option&=0xFE;break; + default:printf("Found invalid option '%c', skiping . . .\r\n",argv[2][i]);break; + } + } + printf("Compiling '%s' from '%s' with %d\r\n",argv[1],dir,option); + printf("Result: %d\r\n",returnValue=prImportDatOpt(argv[1],dir,"resources.txt",option)); + break; + case 't': // none --> resource.txt (destroy resource table) + printf("Clearing 'resources.txt'\r\n"); + printf("Result: %d\r\n",returnValue=prClearRes("resources.txt")); + break; + case 'b': // img.bmp --> img.ext + sprintf(vFileraw,"%s%cres%s.raw",dir,DIR_SEPARATOR,argv[1]); + sprintf(vFilebmp,"%s%cres%s.bmp",dir,DIR_SEPARATOR,argv[1]); + + printf("Converting '%s' into '%s'\r\n",vFilebmp,vFileraw); + size=mLoadFileArray(vFilebmp,&data); + if (size && mReadBitMap(&img,data,size)) { + free(data); + mCompressGraphic(data,img,&size); + free(img.pix); + mSaveRaw(vFileraw,data,size); + free(data); + } else { + printf("No access to the file\r\n"); + break; + } + break; + default: + syntax(); + return -1; + } + return returnValue; +} + +#endif diff --git a/PR/resources.h b/PR/src/include/autodetect.h similarity index 100% rename from PR/resources.h rename to PR/src/include/autodetect.h diff --git a/PR/src/include/bitmap.h b/PR/src/include/bitmap.h new file mode 100644 index 0000000..5310b89 --- /dev/null +++ b/PR/src/include/bitmap.h @@ -0,0 +1,23 @@ + +#ifndef _BMP_H_ +#define _BMP_H_ +/* +#include <stdio.h> +#if DIR_SEPARATOR=='/' +#include "../pg.h" +#include "../resources.h" +#else +#include "pg.h" +#include "resources.h" +#endif +*/ +#include "resources.h" +#include "compress.h" + + +char mFormatExtractBmp(unsigned char* data, char *vFileext,unsigned long int size,tImage image); +char mFormatCompileBmp(unsigned char* data, FILE* fp, tResource *res); +char mWriteBitMap(tImage img,char* vFile); +char mReadBitMap(tImage* img,char* data, int size); //Note: this will ignore the palette + +#endif diff --git a/PR/src/lib/formats/bmp.h b/PR/src/include/bmp.h similarity index 72% rename from PR/src/lib/formats/bmp.h rename to PR/src/include/bmp.h index a4eaf59..5310b89 100644 --- a/PR/src/lib/formats/bmp.h +++ b/PR/src/include/bmp.h @@ -1,7 +1,7 @@ #ifndef _BMP_H_ #define _BMP_H_ - +/* #include <stdio.h> #if DIR_SEPARATOR=='/' #include "../pg.h" @@ -10,7 +10,12 @@ #include "pg.h" #include "resources.h" #endif +*/ +#include "resources.h" +#include "compress.h" + +char mFormatExtractBmp(unsigned char* data, char *vFileext,unsigned long int size,tImage image); char mFormatCompileBmp(unsigned char* data, FILE* fp, tResource *res); char mWriteBitMap(tImage img,char* vFile); char mReadBitMap(tImage* img,char* data, int size); //Note: this will ignore the palette diff --git a/PR/tasks.h b/PR/src/include/classify.h similarity index 83% rename from PR/tasks.h rename to PR/src/include/classify.h index 9360a76..80dc3c6 100644 --- a/PR/tasks.h +++ b/PR/src/include/classify.h @@ -17,3 +17,10 @@ 11 Pop2 dat files */ + +#ifndef _TASKS_H_ +#define _TASKS_H_ + +int prVerifyDatType(char* vFiledat); + +#endif diff --git a/PR/src/include/common.h b/PR/src/include/common.h new file mode 100644 index 0000000..26c948a --- /dev/null +++ b/PR/src/include/common.h @@ -0,0 +1,28 @@ +#ifndef _PR_H_ +#define _PR_H_ + +//princed resource library + +//User configuration defines +#define UNIX +//#define DLL +#define PR_ABOUT "Princed resources (PR) V0.7\r\n(c) Copyright 2003 - Princed Development Team\r\nhttp://www.princed.com.ar\r\n\r\n" + +//Path defines +#ifdef UNIX + #define DIR_SEPARATOR '/' +#else + #define DIR_SEPARATOR '\\' +#endif + +//Main functions +int prExportDat(char* vDatFile, char* vDirName, char* vResFile); +int prImportDat(char* vDatFile, char* vDirName, char* vResFile); +int prClearRes(char* vResFile); +int prVerifyDatType(char* vFiledat); + +//Extra featured functions +int prExportDatOpt(char* vDatFile, char* vDirName, char* vResFile,char opt); +int prImportDatOpt(char* vDatFile, char* vDirName, char* vResFile,char opt); + +#endif diff --git a/PR/pg.h b/PR/src/include/compress.h similarity index 99% rename from PR/pg.h rename to PR/src/include/compress.h index f23982d..d83c8f6 100644 --- a/PR/pg.h +++ b/PR/src/include/compress.h @@ -46,12 +46,12 @@ private: int imageArrayLength; */ - +/* #include <stdio.h> #include <stdlib.h> #include "pg.h" #include "formats/bmp.h" #include "formats/pal.h" #include "memory.h" - +*/ #endif diff --git a/PR/extract.h b/PR/src/include/export.h similarity index 61% rename from PR/extract.h rename to PR/src/include/export.h index 7e4cd2f..3cbf13a 100644 --- a/PR/extract.h +++ b/PR/src/include/export.h @@ -2,17 +2,10 @@ #ifndef _EXTARCT_H_ #define _EXTRACT_H_ -/***************************************************************\ -| I M P L E M E N T A T I O N | -\***************************************************************/ - -#include <stdio.h> -#include <stdlib.h> -#include "formats/wav.h" -#include "pg.h" -#include "parser.h" #include "resources.h" +char writeData(unsigned char* data, int ignoreChars, char* vFileext, int size); + /***************************************************************\ | M A I N E X T R A C T | \***************************************************************/ diff --git a/PR/src/include/idlist.h b/PR/src/include/idlist.h new file mode 100644 index 0000000..2905db2 --- /dev/null +++ b/PR/src/include/idlist.h @@ -0,0 +1,56 @@ + +#ifndef _RESOURCES_H_ +#define _RESOURCES_H_ + +#define HEADER "Princed V3.0 alpha game resources list\n(c) Copyright 2003 - Enrique P. Calot\n(c) Copyright 2003 - Princed Development Team\n\nSyntax:\nId Size Offset File Type Description Comments\nXXXXX YYYYY ZZZZZ SSSSSSSS.DAT TT Ddddddddddddd... #cccccccc....\n\nComments are optional\n\nNote:\n You can edit description and commets here in the file and\n they will be saved in the dat files.\n\nResource Types:\n 01 Levels\n 02 Bitmaps\n 03 Waves\n 04 Midis\n" +#define BEGIN_TABLE "BEGIN resources table\n" +#define END_TABLE "END resources table\n" + +#define MAX_LINE_SIZE 300 + +//types +typedef struct { + unsigned short int size; + unsigned short int offset; + char file[13]; + char type; + char* desc; + char* coms; +}tResource; + +//Verify header +char verifyHeader(char* array, int size); + +/* + Headers may be: + 01 Levels + 02 Bitmaps + 03 Waves + 04 Midis + 05 Undefined + 06 Palette +*/ + +/***************************************************************\ +| File format handling | +\***************************************************************/ + +//Empty resource table +void emptyTable(tResource* r[]); + +//parse file +char parseFile(char* vFile,tResource* r[]); + +//generate file +char generateFile(char* vFile,tResource* r[]); + +//Resources extras + +void getFileName(char* vFileext,char* vDirExt,char type, unsigned short int id); +void getUpperFolder(char* aux, char* vFiledat); + +//File handrling +int mLoadFileArray(char* vFile,unsigned char** array); +char mSaveRaw(char* vFile,unsigned char* output, int size); + +#endif diff --git a/PR/src/include/image.h b/PR/src/include/image.h new file mode 100644 index 0000000..d83c8f6 --- /dev/null +++ b/PR/src/include/image.h @@ -0,0 +1,57 @@ + +#ifndef _PG_H_ +#define _PG_H_ + +#define SIZE_OF_FILE 64*1024 +#define SIZE_OF_ARRAY 1000 +#define SIZE_OF_PALETTE 3*16 + +#define PG_COMP_RAW 0xB0 +#define PG_COMP_RLE_LR 0xB1 +#define PG_COMP_RLE_UD 0xB2 +#define PG_COMP_LZX_LR 0xB3 +#define PG_COMP_LZX_UD 0xB4 + +typedef struct { + int width; + int height; + int size; + unsigned char* pix; + unsigned char pal[SIZE_OF_PALETTE]; +}tImage; + +//Prototypes: + +int mCompressGraphic(unsigned char* a,tImage i, int* size); +int mExpandGraphic(char* array,tImage *image, int size); + +/* + Class future definitions + +public: + char cPrincedGraph::mOpenGraphDat (char* fileName); + char cPrincedGraph::mSaveGraphDat (char* fileName); + char cPrincedGraph::mGetGraphFull (int id, CBitmap &bitmap, CBitmap &mask); + char cPrincedGraph::mGetGraphMap (int id, CBitmap &bitmap); + char cPrincedGraph::mGetGraphMask (int id, CBitmap &bmask); + char cPrincedGraph::mSetGraph (int id, CBitmap &bitmap); + int cPrincedGraph::mGetGraphCount (); + char cPrincedGraph::mSaveImportBmp (int id, char* fileName); + char cPrincedGraph::mSaveExportBmp (int id, char* fileName); + +private: + unsigned char* file; + int fileSize; + tImage* imageArray[256]; + int imageArrayLength; + +*/ +/* +#include <stdio.h> +#include <stdlib.h> +#include "pg.h" +#include "formats/bmp.h" +#include "formats/pal.h" +#include "memory.h" +*/ +#endif diff --git a/PR/compile.h b/PR/src/include/import.h similarity index 78% rename from PR/compile.h rename to PR/src/include/import.h index 2ca0098..0e0dec9 100644 --- a/PR/compile.h +++ b/PR/src/include/import.h @@ -6,13 +6,9 @@ #define _COMPILE_H_ #include <stdio.h> -#include <stdlib.h> -#include "formats/wav.h" -#include "pg.h" #include "resources.h" -#include "memory.h" -#include "parser.h" +void mAddFileToDatFile(FILE* fp, char* data, int size); int compile(char* vFiledat, char* vDirExt, tResource* r[], char opt); #endif diff --git a/PR/src/include/memory.h b/PR/src/include/memory.h new file mode 100644 index 0000000..20c0883 --- /dev/null +++ b/PR/src/include/memory.h @@ -0,0 +1,12 @@ + +#ifndef _MEMORY_H_ +#define _MEMORY_H_ + +#include <stdlib.h> + +//Reserves a memory space to allocate an image +//TODO change "unsigned char*" for "unsigned char" in sizeof +#define getMemory(size) ((unsigned char*)malloc(sizeof(unsigned char*)*(size))) + +#endif + diff --git a/PR/src/include/mid.h b/PR/src/include/mid.h new file mode 100644 index 0000000..7763acc --- /dev/null +++ b/PR/src/include/mid.h @@ -0,0 +1,5 @@ + +#ifndef _MID_H_ +#define _MID_H_ +char mFormatExtractMid(unsigned char* data, char *vFileext,unsigned long int size); +#endif diff --git a/PR/src/lib/formats/pal.h b/PR/src/include/pal.h similarity index 91% rename from PR/src/lib/formats/pal.h rename to PR/src/include/pal.h index e5ae074..fb74ae7 100644 --- a/PR/src/lib/formats/pal.h +++ b/PR/src/include/pal.h @@ -5,16 +5,20 @@ #ifndef _PAL_H_ #define _PAL_H_ - +/* #if DIR_SEPARATOR=='/' #include "../pg.h" #else #include "pg.h" #endif +*/ + +#include "compress.h" #define PAL_HEADER "JASC-PAL\r\n0100\r\n16\r\n" #define PAL_SAMPLE {0x97, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x03, 0x08, 0x0F, 0x07, 0x0C, 0x13, 0x0C, 0x11, 0x16, 0x11, 0x17, 0x1C, 0x1E, 0x21, 0x25, 0x2F, 0x31, 0x33, 0x3F, 0x3F, 0x3F, 0x2A, 0x2A, 0x2A, 0x15, 0x15, 0x15, 0x17, 0x1C, 0x20, 0x07, 0x0C, 0x13, 0x0C, 0x12, 0x17, 0x15, 0x1A, 0x1F, 0x00, 0x1D, 0x13, 0x00, 0x29, 0x27, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} +char mFormatExtractPal(unsigned char** data, char *vFileext,unsigned long int size); char mImportPalette(unsigned char** data, unsigned short *size); void mExportPalette(unsigned char** data, unsigned long int *size); diff --git a/PR/parser.h b/PR/src/include/parser.h similarity index 100% rename from PR/parser.h rename to PR/src/include/parser.h diff --git a/PR/src/include/png.h b/PR/src/include/png.h new file mode 100644 index 0000000..5310b89 --- /dev/null +++ b/PR/src/include/png.h @@ -0,0 +1,23 @@ + +#ifndef _BMP_H_ +#define _BMP_H_ +/* +#include <stdio.h> +#if DIR_SEPARATOR=='/' +#include "../pg.h" +#include "../resources.h" +#else +#include "pg.h" +#include "resources.h" +#endif +*/ +#include "resources.h" +#include "compress.h" + + +char mFormatExtractBmp(unsigned char* data, char *vFileext,unsigned long int size,tImage image); +char mFormatCompileBmp(unsigned char* data, FILE* fp, tResource *res); +char mWriteBitMap(tImage img,char* vFile); +char mReadBitMap(tImage* img,char* data, int size); //Note: this will ignore the palette + +#endif diff --git a/PR/pr.h b/PR/src/include/pr.h similarity index 72% rename from PR/pr.h rename to PR/src/include/pr.h index db90d6a..26c948a 100644 --- a/PR/pr.h +++ b/PR/src/include/pr.h @@ -3,17 +3,18 @@ //princed resource library +//User configuration defines +#define UNIX +//#define DLL +#define PR_ABOUT "Princed resources (PR) V0.7\r\n(c) Copyright 2003 - Princed Development Team\r\nhttp://www.princed.com.ar\r\n\r\n" + +//Path defines #ifdef UNIX #define DIR_SEPARATOR '/' #else #define DIR_SEPARATOR '\\' #endif -#include <string.h> -#include "extract.h" -#include "compile.h" -#include "tasks.h" - //Main functions int prExportDat(char* vDatFile, char* vDirName, char* vResFile); int prImportDat(char* vDatFile, char* vDirName, char* vResFile); diff --git a/PR/src/include/tree.h b/PR/src/include/tree.h new file mode 100644 index 0000000..2905db2 --- /dev/null +++ b/PR/src/include/tree.h @@ -0,0 +1,56 @@ + +#ifndef _RESOURCES_H_ +#define _RESOURCES_H_ + +#define HEADER "Princed V3.0 alpha game resources list\n(c) Copyright 2003 - Enrique P. Calot\n(c) Copyright 2003 - Princed Development Team\n\nSyntax:\nId Size Offset File Type Description Comments\nXXXXX YYYYY ZZZZZ SSSSSSSS.DAT TT Ddddddddddddd... #cccccccc....\n\nComments are optional\n\nNote:\n You can edit description and commets here in the file and\n they will be saved in the dat files.\n\nResource Types:\n 01 Levels\n 02 Bitmaps\n 03 Waves\n 04 Midis\n" +#define BEGIN_TABLE "BEGIN resources table\n" +#define END_TABLE "END resources table\n" + +#define MAX_LINE_SIZE 300 + +//types +typedef struct { + unsigned short int size; + unsigned short int offset; + char file[13]; + char type; + char* desc; + char* coms; +}tResource; + +//Verify header +char verifyHeader(char* array, int size); + +/* + Headers may be: + 01 Levels + 02 Bitmaps + 03 Waves + 04 Midis + 05 Undefined + 06 Palette +*/ + +/***************************************************************\ +| File format handling | +\***************************************************************/ + +//Empty resource table +void emptyTable(tResource* r[]); + +//parse file +char parseFile(char* vFile,tResource* r[]); + +//generate file +char generateFile(char* vFile,tResource* r[]); + +//Resources extras + +void getFileName(char* vFileext,char* vDirExt,char type, unsigned short int id); +void getUpperFolder(char* aux, char* vFiledat); + +//File handrling +int mLoadFileArray(char* vFile,unsigned char** array); +char mSaveRaw(char* vFile,unsigned char* output, int size); + +#endif diff --git a/PR/src/include/unknown.h b/PR/src/include/unknown.h new file mode 100644 index 0000000..2905db2 --- /dev/null +++ b/PR/src/include/unknown.h @@ -0,0 +1,56 @@ + +#ifndef _RESOURCES_H_ +#define _RESOURCES_H_ + +#define HEADER "Princed V3.0 alpha game resources list\n(c) Copyright 2003 - Enrique P. Calot\n(c) Copyright 2003 - Princed Development Team\n\nSyntax:\nId Size Offset File Type Description Comments\nXXXXX YYYYY ZZZZZ SSSSSSSS.DAT TT Ddddddddddddd... #cccccccc....\n\nComments are optional\n\nNote:\n You can edit description and commets here in the file and\n they will be saved in the dat files.\n\nResource Types:\n 01 Levels\n 02 Bitmaps\n 03 Waves\n 04 Midis\n" +#define BEGIN_TABLE "BEGIN resources table\n" +#define END_TABLE "END resources table\n" + +#define MAX_LINE_SIZE 300 + +//types +typedef struct { + unsigned short int size; + unsigned short int offset; + char file[13]; + char type; + char* desc; + char* coms; +}tResource; + +//Verify header +char verifyHeader(char* array, int size); + +/* + Headers may be: + 01 Levels + 02 Bitmaps + 03 Waves + 04 Midis + 05 Undefined + 06 Palette +*/ + +/***************************************************************\ +| File format handling | +\***************************************************************/ + +//Empty resource table +void emptyTable(tResource* r[]); + +//parse file +char parseFile(char* vFile,tResource* r[]); + +//generate file +char generateFile(char* vFile,tResource* r[]); + +//Resources extras + +void getFileName(char* vFileext,char* vDirExt,char type, unsigned short int id); +void getUpperFolder(char* aux, char* vFiledat); + +//File handrling +int mLoadFileArray(char* vFile,unsigned char** array); +char mSaveRaw(char* vFile,unsigned char* output, int size); + +#endif diff --git a/PR/src/lib/formats/wav.h b/PR/src/include/wav.h similarity index 92% rename from PR/src/lib/formats/wav.h rename to PR/src/include/wav.h index 592b21d..c072ba1 100644 --- a/PR/src/lib/formats/wav.h +++ b/PR/src/include/wav.h @@ -1,13 +1,16 @@ #ifndef _WAV_H_ #define _WAV_H_ - +/* #include <stdio.h> #if DIR_SEPARATOR=='/' #include "../resources.h" #else #include "resources.h" #endif +*/ +#include "resources.h" +#include <stdio.h> #define WAVE_HEADER {0x52, 0x49, 0x46, 0x46, 0x12, 0x16, 0x00, 0x00, 0x57, 0x41, 0x56, 0x45, 0x66, 0x6D, 0x74, 0x20, 0x10, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x11, 0x2B, 0x00, 0x00, 0x11, 0x2B, 0x00, 0x00, 0x01, 0x00, 0x08, 0x00, 0x64, 0x61, 0x74, 0x61, 0xA3, 0x15, 0x00, 0x00} diff --git a/PR/tasks.c b/PR/src/lib/actions/classify.c similarity index 97% rename from PR/tasks.c rename to PR/src/lib/actions/classify.c index 16b22b3..56feb81 100644 --- a/PR/tasks.c +++ b/PR/src/lib/actions/classify.c @@ -1,5 +1,7 @@ +#include <stdio.h> #include "tasks.h" +#include "memory.h" int prVerifyDatType(char* vFiledat) { diff --git a/PR/extract.c b/PR/src/lib/actions/export.c similarity index 76% rename from PR/extract.c rename to PR/src/lib/actions/export.c index 4be245a..380b096 100644 --- a/PR/extract.c +++ b/PR/src/lib/actions/export.c @@ -2,7 +2,23 @@ | I M P L E M E N T A T I O N | \***************************************************************/ +#include <stdio.h> #include "extract.h" +#include "memory.h" +#include "bmp.h" +#include "wav.h" +#include "pal.h" +#include "mid.h" + +char writeData(unsigned char* data, int ignoreChars, char* vFileext, int size) { + FILE* target; + char ok; + + ok=((target=fopen(vFileext,"wb"))!=NULL); + ok=ok&&fwrite(data+ignoreChars,size-ignoreChars,1,target); + ok=ok&&(!fclose(target)); + return ok; +} /***************************************************************\ | M A I N E X T R A C T | @@ -47,8 +63,6 @@ int extract(char* vFiledat,char* vDirExt, tResource* r[], char task) { //verify dat format ok = fread(&indexOffset,4,1,fp); - //ok=ok&& fread(&val,2,1,fp); - //ok=ok&& (!val); ok=ok&& fread(&indexSize,2,1,fp); ok=ok&& !fseek(fp,indexOffset,SEEK_SET); ok=ok&& fread(&numberOfItems,2,1,fp); @@ -57,7 +71,7 @@ int extract(char* vFiledat,char* vDirExt, tResource* r[], char task) { if (!pop1) { //verify if pop2 ofk=numberOfItems*6+2+(numberOfItems-2)*13; numberOfItems=((indexSize-6-(numberOfItems*6)-((numberOfItems-2)*13))/11); - //printf("verificando pop2: numberOfItems=%d, indexSize=%d\r\n",numberOfItems,indexSize); +//printf("verificando pop2: numberOfItems=%d, indexSize=%d\r\n",numberOfItems,indexSize); } recordSize=pop1?8:11; if (!ok) { @@ -84,14 +98,14 @@ int extract(char* vFiledat,char* vDirExt, tResource* r[], char task) { printf("jajaA %d\r\n",ok); //printf("verificando pop2: %d, k=%d, record size=%d\r\n",size,k,recordSize); ok=ok&&(index[ofk+k*recordSize+8]==0x40)&&(!index[ofk+k*recordSize+9])&&(!index[ofk+k*recordSize+10]); -// printf("jajaB %d\r\n",ok); + printf("jajaB %d\r\n",ok); } ok=ok&&((data=getMemory(size))!=NULL); -// printf("jajaC %d offset=%d\r\n",ok,offset); + printf("jajaC %d offset=%d\r\n",ok,offset); ok=ok&&(!fseek(fp,offset,SEEK_SET)); -// printf("jajaD %d\r\n",ok); + printf("jajaD %d\r\n",ok); ok=ok&&fread(data,size,1,fp); -// printf("jajaE %d\r\n",ok); + printf("jajaE %d\r\n",ok); if (!ok) return -3; //For the moment rebuilt option will be mandatory: @@ -113,61 +127,37 @@ int extract(char* vFiledat,char* vDirExt, tResource* r[], char task) { (*(r[id])).desc=NULL; (*(r[id])).coms=NULL; (*(r[id])).type=verifyHeader(data,(unsigned short int)size); - //printf("%d: %d %d %d\n",id,(*(r[id])).type,(*(r[id])).offset,(*(r[id])).size); } if (task&1) { //select type - //printf("kkkkkkk: %x -> %d\n",task,(*(r[id])).type); - if (task&4) (*(r[id])).type=0; //save file getFileName(vFileext,vDirExt,(*(r[id])).type,id); +printf("voy por %s\n",vFileext); switch ((*(r[id])).type) { case 1: case 5: - case 0: - ok=ok&&((target=fopen(vFileext,"wb"))!=NULL); - ok=ok&&fwrite(data+1,size-1,1,target); //Ignore checksum - ok=ok&&(!fclose(target)); + case 0: //Raw files + ok=ok&&writeData(data,1,vFileext,size); //Ignore checksum break; - case 6: - + case 6: //save and remember palette file + //This will remember the palette for the next extacted images if (1/*isntImageSet*/) { mLoadPalette(data,&image); isntImageSet=0; } - //todo send to pal.c - mExportPalette(&data,&size); - //save palette - ok=ok&&((target=fopen(vFileext,"wb"))!=NULL); - ok=ok&&fwrite(data,size,1,target); - ok=ok&&(!fclose(target)); - - //until here +printf("paso el load palette\n"); + ok=ok&&mFormatExtractPal(&data,vFileext,size); break; - case 4: - //save file - - //TODO send to mid.c - ok=ok&&((target=fopen(vFileext,"wb"))!=NULL); - ok=ok&&fwrite(data+2,size-2,1,target); //Ignore checksum & sound type - ok=ok&&(!fclose(target)); - - //until here + case 4: //save midi file + ok=ok&&mFormatExtractMid(data,vFileext,size); break; case 3: //save wav file ok=ok&&mFormatExtractWav(data,vFileext,size); break; - case 2: - //save image - //Todo send to bmp.c - if ((mExpandGraphic(data,&image,size))>0) { - mWriteBitMap(image,vFileext); - free(image.pix); - } - - //until here + case 2: //save image + ok=ok&&mFormatExtractBmp(data,vFileext,size,image); break; } } diff --git a/PR/compile.c b/PR/src/lib/actions/import.c similarity index 95% rename from PR/compile.c rename to PR/src/lib/actions/import.c index 884e3a7..1f0e1b9 100644 --- a/PR/compile.c +++ b/PR/src/lib/actions/import.c @@ -2,7 +2,13 @@ | I M P L E M E N T A T I O N | \***************************************************************/ +#include <string.h> #include "compile.h" +#include "memory.h" +#include "bmp.h" +#include "wav.h" +#include "pal.h" +#include "parser.h" /***************************************************************\ | Dat compiling primitives | @@ -55,7 +61,8 @@ int mCreateIndexInDatFile(FILE* fp, tResource* r[], char* vUpperFile) { int pos=ftell(fp); fwrite(&tot,2,1,fp); - for (unsigned short int i=0;i!=65535;i++) { + unsigned short int i=0; + for (;i!=65535;i++) { if (r[i]!=NULL) { if (equals((*r[i]).file,vUpperFile)) { //the file is in the archive, so I'll add it to the index @@ -145,7 +152,8 @@ int compile(char* vFiledat, char* vDirExt, tResource* r[], char opt) { getUpperFolder(vUpperFile,vFiledat); - for (unsigned short int i=0;i!=65535;i++) { + unsigned short int i=0; + for (;i!=65535;i++) { if (r[i]!=NULL) { if (equals((*r[i]).file,vUpperFile)) { getFileName(vFileext,vDirExt,(opt&1)?(*(r[i])).type:0,i); diff --git a/PR/pg.c b/PR/src/lib/compression/rle_compress.c similarity index 87% rename from PR/pg.c rename to PR/src/lib/compression/rle_compress.c index 57592b5..921cef9 100644 --- a/PR/pg.c +++ b/PR/src/lib/compression/rle_compress.c @@ -2,6 +2,10 @@ | I M P L E M E N T A T I O N | \***************************************************************/ +#include <stdio.h> +#include "compress.h" +#include "memory.h" + //reserved memory for the Lzx algorithm #define MAX_MOD_SIZE_IN_LZX 32001 //38401 @@ -26,12 +30,14 @@ unsigned char popBit(unsigned char *byte) { //Expands B3/B4 algorithm void expandLzx(char* array,tImage* img, int *i,int cursor, int virtualSize) { +printf("expandLzx %d %d \n",virtualSize,cursor); int pos,h; + char k; unsigned char maskbyte,rep; for(pos=0;pos<MAX_MXD_SIZE_IN_LZX;(*img).pix[pos++]=0); //clean output garbage while (cursor<virtualSize) { maskbyte=array[(*i)++]; - for (char k=8;k&&(cursor<virtualSize);k--) { + for (k=8;k&&(cursor<virtualSize);k--) { if (popBit(&maskbyte)) { (*img).pix[cursor++]=array[(*i)++]; } else { @@ -65,7 +71,7 @@ void compressRle(unsigned char* data,tImage* img,int *dataSize) { (*counter)++; *(cursorData++)=*(cursorPix-1); } -printf("llega 3.55 cd=%d cp=%d ie=%d\n",cursorData-data,cursorPix,imgEnd); +//printf("llega 3.55 cd=%d cp=%d ie=%d\n",cursorData-data,cursorPix,imgEnd); cursorPix--; //Step 3: If there was a repeated string, let's ignore it and add the cursor with the repetitions @@ -76,9 +82,9 @@ printf("llega 3.55 cd=%d cp=%d ie=%d\n",cursorData-data,cursorPix,imgEnd); } *(cursorData++)=0; *(cursorData++)=*(cursorPix); - printf("llega 3.59\n"); +// printf("llega 3.59\n"); - *dataSize=(int)(cursorData-data); + *dataSize=(int)cursorData-(int)data; } @@ -97,17 +103,22 @@ int mExpandGraphic(char* array,tImage *image, int virtualSize) { normaly: (* ignored types) checksum* - height - 00 - width - 00 - 00* - compression type */ +printf("expand graphic le ejecuta %d\n",virtualSize); int cursor=0; int i=1; //Get memory for the image - (*image).height=(unsigned char)array[i++]+256*(unsigned char)array[i++]; - (*image).width =(unsigned char)array[i++]+256*(unsigned char)array[i++]; + image->height=((unsigned char)array[(i)])+256*((unsigned char)array[(i+1)]) ; +i=i+2; + image->width =((unsigned char)array[(i)])+256*((unsigned char)array[(i+1)]); +i=i+2; (*image).size =(*image).height*(*image).width; - virtualSize=((*image).height*((*image).width+((*image).width&1)))>>1; +printf("h=%d, w=%d %x %x %x %x \n",(*image).height,image->width,(unsigned char)array[1],(unsigned char)array[2],(unsigned char)array[3],(unsigned char)array[4]); + virtualSize=(((*image).height*((*image).width+((*image).width&1)))>>1); i++; +printf("geteo memoria %x %d\n",(unsigned char)array[i],virtualSize); switch ((unsigned char)array[i++]) { case PG_COMP_RAW: //No Compression Algorithm if (((*image).pix=getMemory(virtualSize))==NULL) return -1; @@ -144,14 +155,18 @@ int mExpandGraphic(char* array,tImage *image, int virtualSize) { } break; case PG_COMP_LZX_LR: //LZ Groody Up to Down Version Compression Algorithm + printf("llega b4\n"); if (((*image).pix=getMemory(MAX_MOD_SIZE_IN_LZX))==NULL) return -1; expandLzx(array,image,&i,cursor,virtualSize); break; case PG_COMP_LZX_UD: //LZ Groody Left to Right Version Compression Algorithm +printf("hi\n"); if (((*image).pix=getMemory(MAX_MOD_SIZE_IN_LZX))==NULL) return -1; { unsigned char* outputaux=getMemory(virtualSize); + printf("antes\n"); expandLzx(array,image,&i,cursor,virtualSize); + printf("despues\n"); //Transpose while (cursor<virtualSize) outputaux[transpose(cursor,(*image).width,(*image).height)]=(*image).pix[cursor++]; free((*image).pix); diff --git a/PR/src/lib/compression/rle_decompress.c b/PR/src/lib/compression/rle_decompress.c new file mode 100644 index 0000000..921cef9 --- /dev/null +++ b/PR/src/lib/compression/rle_decompress.c @@ -0,0 +1,250 @@ +/***************************************************************\ +| I M P L E M E N T A T I O N | +\***************************************************************/ + +#include <stdio.h> +#include "compress.h" +#include "memory.h" + +//reserved memory for the Lzx algorithm +#define MAX_MOD_SIZE_IN_LZX 32001 +//38401 +//modulus to be used in the 10 bits of the algorithm +#define MAX_MXD_SIZE_IN_LZX 0x400 + +/***************************************************************\ +| Compression algorithm handling | +\***************************************************************/ + +//Determines where the transposed byte must be saved +int transpose(int x,int n,int m) { + return ((x%m)*((n+1)/2))+(int)(x/m); +} + +//B3 and B4 expansion algorithm sub function +unsigned char popBit(unsigned char *byte) { + unsigned char bit=(*byte)&1; + (*byte)>>=1; + return bit; +} + +//Expands B3/B4 algorithm +void expandLzx(char* array,tImage* img, int *i,int cursor, int virtualSize) { +printf("expandLzx %d %d \n",virtualSize,cursor); + int pos,h; + char k; + unsigned char maskbyte,rep; + for(pos=0;pos<MAX_MXD_SIZE_IN_LZX;(*img).pix[pos++]=0); //clean output garbage + while (cursor<virtualSize) { + maskbyte=array[(*i)++]; + for (k=8;k&&(cursor<virtualSize);k--) { + if (popBit(&maskbyte)) { + (*img).pix[cursor++]=array[(*i)++]; + } else { + pos=66+((0x100)*((rep=array[(*i)++])&3))+(unsigned char)array[(*i)++]; + rep=(rep>>2)+3; + while (rep--) { //Be careful in big images + h=cursor/MAX_MXD_SIZE_IN_LZX-(pos%MAX_MXD_SIZE_IN_LZX>cursor%MAX_MXD_SIZE_IN_LZX); + (*img).pix[cursor++]=(*img).pix[((h<0)?0:h)*MAX_MXD_SIZE_IN_LZX+pos++%MAX_MXD_SIZE_IN_LZX]; + } + } + } + } +} + +//Compress B1/B2 algorithm +void compressRle(unsigned char* data,tImage* img,int *dataSize) { + printf("llega 3.51\n"); + //Declare pointers + char* cursorData = data; + char* counter; + char* cursorPix = (*img).pix; + char* imgEnd = (*img).pix+((*img).size>>1)-1; + printf("llega 3.52\n"); + + while (cursorPix<imgEnd) { + //Step 1: Create counter + *(counter=(cursorData++))=-1; + + //Step 2: Look and copy the string until a repeated byte is found + while ((cursorPix<=imgEnd)&&(*cursorPix!=*(++cursorPix))&&((*counter)!=127)) { + (*counter)++; + *(cursorData++)=*(cursorPix-1); + } +//printf("llega 3.55 cd=%d cp=%d ie=%d\n",cursorData-data,cursorPix,imgEnd); + + cursorPix--; + //Step 3: If there was a repeated string, let's ignore it and add the cursor with the repetitions + if (*counter==-1) { + while ((cursorPix<imgEnd)&&(*cursorPix==(*(++cursorPix)))) (*counter)--; + *(cursorData++)=*(cursorPix-1); //Print repeated char + } + } + *(cursorData++)=0; + *(cursorData++)=*(cursorPix); +// printf("llega 3.59\n"); + + *dataSize=(int)cursorData-(int)data; +} + + + + + + +//Expands an array into an image +int mExpandGraphic(char* array,tImage *image, int virtualSize) { + /* + Reads array and extracts tImage + returns the next image address or -1 in case of error + + Header info: + char checksum, short int height, short int width, (char)0, char compressionType + normaly: (* ignored types) + checksum* - height - 00 - width - 00 - 00* - compression type + */ +printf("expand graphic le ejecuta %d\n",virtualSize); + + int cursor=0; + int i=1; + + //Get memory for the image + image->height=((unsigned char)array[(i)])+256*((unsigned char)array[(i+1)]) ; +i=i+2; + image->width =((unsigned char)array[(i)])+256*((unsigned char)array[(i+1)]); +i=i+2; + (*image).size =(*image).height*(*image).width; +printf("h=%d, w=%d %x %x %x %x \n",(*image).height,image->width,(unsigned char)array[1],(unsigned char)array[2],(unsigned char)array[3],(unsigned char)array[4]); + virtualSize=(((*image).height*((*image).width+((*image).width&1)))>>1); + i++; + +printf("geteo memoria %x %d\n",(unsigned char)array[i],virtualSize); + switch ((unsigned char)array[i++]) { + case PG_COMP_RAW: //No Compression Algorithm + if (((*image).pix=getMemory(virtualSize))==NULL) return -1; + while (cursor<virtualSize) { + (*image).pix[cursor++]=array[i++]; + } + break; + case PG_COMP_RLE_LR: //RLE Left to Right Compression Algorithm + if (((*image).pix=getMemory(virtualSize))==NULL) return -1; + while (cursor<virtualSize) { + if ((signed char)array[i]<0) { + //negative + while (array[i]++) (*image).pix[(cursor++)]=array[i+1]; + i+=2; + } else { + //Positive + char cx=array[i++]+1; + while (cx--) (*image).pix[(cursor++)]=array[i++]; + } + } + break; + case PG_COMP_RLE_UD: //RLE Up to Down Compression Algorithm + if (((*image).pix=getMemory(virtualSize))==NULL) return -1; + while (cursor<virtualSize) { + if ((signed char)array[i]<0) { + //negative + while (array[i]++) (*image).pix[(transpose(cursor++,(*image).width,(*image).height))]=array[i+1]; + i+=2; + } else { + //Positive + char cx=array[i++]+1; + while (cx--) (*image).pix[transpose(cursor++,(*image).width,(*image).height)]=array[i++]; + } + } + break; + case PG_COMP_LZX_LR: //LZ Groody Up to Down Version Compression Algorithm + printf("llega b4\n"); + if (((*image).pix=getMemory(MAX_MOD_SIZE_IN_LZX))==NULL) return -1; + expandLzx(array,image,&i,cursor,virtualSize); + break; + case PG_COMP_LZX_UD: //LZ Groody Left to Right Version Compression Algorithm +printf("hi\n"); + if (((*image).pix=getMemory(MAX_MOD_SIZE_IN_LZX))==NULL) return -1; + { + unsigned char* outputaux=getMemory(virtualSize); + printf("antes\n"); + expandLzx(array,image,&i,cursor,virtualSize); + printf("despues\n"); + //Transpose + while (cursor<virtualSize) outputaux[transpose(cursor,(*image).width,(*image).height)]=(*image).pix[cursor++]; + free((*image).pix); + (*image).pix=outputaux; + } + break; + default: + return -1; + } + return i; +} + +//Compress an image into an array in the most quick & dirty way +int mCompressGraphic(unsigned char* data,tImage i, int* size) { + int dataSize; +// unsigned char* data; + + /* + *size=(i.size/2)+6; + a=getMemory(*size); + //height - 00 - width - 00 - 00 - compression type + a[2]=i.width; + a[3]=i.width>>8; + + a[0]=i.height; + a[1]=i.height>>8; + + a[4]=0; + a[5]=0xB0; // how q&d I am :) + + memcpy(i.pix,a+6,*size); //TODO it should be a+6,i.pix + */ +//printf("llega 3\n"); + //=getMemory(10*i.size+50); //This will reserve 10*2*(image size)+50 bytes, to allocate the compressed file +//printf("llega 3.3\n"); + compressRle(data+6,&i,&dataSize); +//printf("llega 3.6\n"); + //a=getMemory(*size=(dataSize+6)); +//printf("llega 4\n"); + /* + Header Settings: + height - 00 - width - 00 - 00 - compression type + */ + data[2]=i.width; + data[3]=i.width>>8; + + data[0]=i.height; + data[1]=i.height>>8; + + data[4]=0; + data[5]=0xB1; + + //memcpy(a+6,data,dataSize); + //free(data); +*size=(dataSize+6); +//printf("Tize: %d %02x %02x %02x %02x %02x %02x %02x\n",*size,a[0],a[1],a[2],a[3],a[4],a[5],a[6]); + + + return 1; +} + +/***************************************************************\ +| File handling | +\***************************************************************/ + +//Deprecated +/* +char mLoadFilePalette(char* vFile,int address, char* pal) { + FILE *fp; + char aux; + + if ((fp=fopen(vFile,"rb"))==NULL) { + return 0; + } else { + fseek (fp, address, SEEK_SET); + aux=fread (pal,SIZE_OF_PALETTE,1,fp); + fclose(fp); + return aux; + } +} +*/ diff --git a/PR/src/lib/compression/rlev_decompress.c b/PR/src/lib/compression/rlev_decompress.c new file mode 100644 index 0000000..921cef9 --- /dev/null +++ b/PR/src/lib/compression/rlev_decompress.c @@ -0,0 +1,250 @@ +/***************************************************************\ +| I M P L E M E N T A T I O N | +\***************************************************************/ + +#include <stdio.h> +#include "compress.h" +#include "memory.h" + +//reserved memory for the Lzx algorithm +#define MAX_MOD_SIZE_IN_LZX 32001 +//38401 +//modulus to be used in the 10 bits of the algorithm +#define MAX_MXD_SIZE_IN_LZX 0x400 + +/***************************************************************\ +| Compression algorithm handling | +\***************************************************************/ + +//Determines where the transposed byte must be saved +int transpose(int x,int n,int m) { + return ((x%m)*((n+1)/2))+(int)(x/m); +} + +//B3 and B4 expansion algorithm sub function +unsigned char popBit(unsigned char *byte) { + unsigned char bit=(*byte)&1; + (*byte)>>=1; + return bit; +} + +//Expands B3/B4 algorithm +void expandLzx(char* array,tImage* img, int *i,int cursor, int virtualSize) { +printf("expandLzx %d %d \n",virtualSize,cursor); + int pos,h; + char k; + unsigned char maskbyte,rep; + for(pos=0;pos<MAX_MXD_SIZE_IN_LZX;(*img).pix[pos++]=0); //clean output garbage + while (cursor<virtualSize) { + maskbyte=array[(*i)++]; + for (k=8;k&&(cursor<virtualSize);k--) { + if (popBit(&maskbyte)) { + (*img).pix[cursor++]=array[(*i)++]; + } else { + pos=66+((0x100)*((rep=array[(*i)++])&3))+(unsigned char)array[(*i)++]; + rep=(rep>>2)+3; + while (rep--) { //Be careful in big images + h=cursor/MAX_MXD_SIZE_IN_LZX-(pos%MAX_MXD_SIZE_IN_LZX>cursor%MAX_MXD_SIZE_IN_LZX); + (*img).pix[cursor++]=(*img).pix[((h<0)?0:h)*MAX_MXD_SIZE_IN_LZX+pos++%MAX_MXD_SIZE_IN_LZX]; + } + } + } + } +} + +//Compress B1/B2 algorithm +void compressRle(unsigned char* data,tImage* img,int *dataSize) { + printf("llega 3.51\n"); + //Declare pointers + char* cursorData = data; + char* counter; + char* cursorPix = (*img).pix; + char* imgEnd = (*img).pix+((*img).size>>1)-1; + printf("llega 3.52\n"); + + while (cursorPix<imgEnd) { + //Step 1: Create counter + *(counter=(cursorData++))=-1; + + //Step 2: Look and copy the string until a repeated byte is found + while ((cursorPix<=imgEnd)&&(*cursorPix!=*(++cursorPix))&&((*counter)!=127)) { + (*counter)++; + *(cursorData++)=*(cursorPix-1); + } +//printf("llega 3.55 cd=%d cp=%d ie=%d\n",cursorData-data,cursorPix,imgEnd); + + cursorPix--; + //Step 3: If there was a repeated string, let's ignore it and add the cursor with the repetitions + if (*counter==-1) { + while ((cursorPix<imgEnd)&&(*cursorPix==(*(++cursorPix)))) (*counter)--; + *(cursorData++)=*(cursorPix-1); //Print repeated char + } + } + *(cursorData++)=0; + *(cursorData++)=*(cursorPix); +// printf("llega 3.59\n"); + + *dataSize=(int)cursorData-(int)data; +} + + + + + + +//Expands an array into an image +int mExpandGraphic(char* array,tImage *image, int virtualSize) { + /* + Reads array and extracts tImage + returns the next image address or -1 in case of error + + Header info: + char checksum, short int height, short int width, (char)0, char compressionType + normaly: (* ignored types) + checksum* - height - 00 - width - 00 - 00* - compression type + */ +printf("expand graphic le ejecuta %d\n",virtualSize); + + int cursor=0; + int i=1; + + //Get memory for the image + image->height=((unsigned char)array[(i)])+256*((unsigned char)array[(i+1)]) ; +i=i+2; + image->width =((unsigned char)array[(i)])+256*((unsigned char)array[(i+1)]); +i=i+2; + (*image).size =(*image).height*(*image).width; +printf("h=%d, w=%d %x %x %x %x \n",(*image).height,image->width,(unsigned char)array[1],(unsigned char)array[2],(unsigned char)array[3],(unsigned char)array[4]); + virtualSize=(((*image).height*((*image).width+((*image).width&1)))>>1); + i++; + +printf("geteo memoria %x %d\n",(unsigned char)array[i],virtualSize); + switch ((unsigned char)array[i++]) { + case PG_COMP_RAW: //No Compression Algorithm + if (((*image).pix=getMemory(virtualSize))==NULL) return -1; + while (cursor<virtualSize) { + (*image).pix[cursor++]=array[i++]; + } + break; + case PG_COMP_RLE_LR: //RLE Left to Right Compression Algorithm + if (((*image).pix=getMemory(virtualSize))==NULL) return -1; + while (cursor<virtualSize) { + if ((signed char)array[i]<0) { + //negative + while (array[i]++) (*image).pix[(cursor++)]=array[i+1]; + i+=2; + } else { + //Positive + char cx=array[i++]+1; + while (cx--) (*image).pix[(cursor++)]=array[i++]; + } + } + break; + case PG_COMP_RLE_UD: //RLE Up to Down Compression Algorithm + if (((*image).pix=getMemory(virtualSize))==NULL) return -1; + while (cursor<virtualSize) { + if ((signed char)array[i]<0) { + //negative + while (array[i]++) (*image).pix[(transpose(cursor++,(*image).width,(*image).height))]=array[i+1]; + i+=2; + } else { + //Positive + char cx=array[i++]+1; + while (cx--) (*image).pix[transpose(cursor++,(*image).width,(*image).height)]=array[i++]; + } + } + break; + case PG_COMP_LZX_LR: //LZ Groody Up to Down Version Compression Algorithm + printf("llega b4\n"); + if (((*image).pix=getMemory(MAX_MOD_SIZE_IN_LZX))==NULL) return -1; + expandLzx(array,image,&i,cursor,virtualSize); + break; + case PG_COMP_LZX_UD: //LZ Groody Left to Right Version Compression Algorithm +printf("hi\n"); + if (((*image).pix=getMemory(MAX_MOD_SIZE_IN_LZX))==NULL) return -1; + { + unsigned char* outputaux=getMemory(virtualSize); + printf("antes\n"); + expandLzx(array,image,&i,cursor,virtualSize); + printf("despues\n"); + //Transpose + while (cursor<virtualSize) outputaux[transpose(cursor,(*image).width,(*image).height)]=(*image).pix[cursor++]; + free((*image).pix); + (*image).pix=outputaux; + } + break; + default: + return -1; + } + return i; +} + +//Compress an image into an array in the most quick & dirty way +int mCompressGraphic(unsigned char* data,tImage i, int* size) { + int dataSize; +// unsigned char* data; + + /* + *size=(i.size/2)+6; + a=getMemory(*size); + //height - 00 - width - 00 - 00 - compression type + a[2]=i.width; + a[3]=i.width>>8; + + a[0]=i.height; + a[1]=i.height>>8; + + a[4]=0; + a[5]=0xB0; // how q&d I am :) + + memcpy(i.pix,a+6,*size); //TODO it should be a+6,i.pix + */ +//printf("llega 3\n"); + //=getMemory(10*i.size+50); //This will reserve 10*2*(image size)+50 bytes, to allocate the compressed file +//printf("llega 3.3\n"); + compressRle(data+6,&i,&dataSize); +//printf("llega 3.6\n"); + //a=getMemory(*size=(dataSize+6)); +//printf("llega 4\n"); + /* + Header Settings: + height - 00 - width - 00 - 00 - compression type + */ + data[2]=i.width; + data[3]=i.width>>8; + + data[0]=i.height; + data[1]=i.height>>8; + + data[4]=0; + data[5]=0xB1; + + //memcpy(a+6,data,dataSize); + //free(data); +*size=(dataSize+6); +//printf("Tize: %d %02x %02x %02x %02x %02x %02x %02x\n",*size,a[0],a[1],a[2],a[3],a[4],a[5],a[6]); + + + return 1; +} + +/***************************************************************\ +| File handling | +\***************************************************************/ + +//Deprecated +/* +char mLoadFilePalette(char* vFile,int address, char* pal) { + FILE *fp; + char aux; + + if ((fp=fopen(vFile,"rb"))==NULL) { + return 0; + } else { + fseek (fp, address, SEEK_SET); + aux=fread (pal,SIZE_OF_PALETTE,1,fp); + fclose(fp); + return aux; + } +} +*/ diff --git a/PR/src/lib/formats/Attic/bmp.c b/PR/src/lib/formats/Attic/bmp.c index 06f2f96..d3b1b84 100644 --- a/PR/src/lib/formats/Attic/bmp.c +++ b/PR/src/lib/formats/Attic/bmp.c @@ -1,8 +1,31 @@ +/* #if DIR_SEPARATOR=='/' #include "bmp.h" #else #include "formats/bmp.h" #endif +*/ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include "bmp.h" +#include "memory.h" +#include "compile.h" + +char mFormatExtractBmp(unsigned char* data, char *vFileext,unsigned long int size,tImage image) { +printf("hola, vengo a colgarme\n"); + if ((mExpandGraphic(data,&image,size))>0) { +printf("ya expandi\n"); + mWriteBitMap(image,vFileext); +printf("Escribi el bitmap\n"); + free(image.pix); + return 1; + } else { + return 0; + } +} + char mFormatCompileBmp(unsigned char* data, FILE* fp, tResource *res) { int size; @@ -22,15 +45,18 @@ char mFormatCompileBmp(unsigned char* data, FILE* fp, tResource *res) { } char mWriteBitMap(tImage img,char* vFile) { + //declare variables unsigned char i=0; unsigned char j=0; + char b; + char c; + char a; FILE* bitmap; - if ((bitmap = fopen (vFile,"wb"))==NULL) return 0; - - unsigned long int filesize=((img.size+1)/2+118); - unsigned long int width=img.width; - unsigned long int height=img.height; + unsigned long int filesize; + unsigned long int width; + unsigned long int height; + char junk[3]={0,0,0}; unsigned char header[]={ 'B','M', @@ -68,6 +94,14 @@ char mWriteBitMap(tImage img,char* vFile) { 0x22,0x22,0x22,0 }; + + if ((bitmap = fopen (vFile,"wb"))==NULL) return 0; + + filesize=((img.size+1)/2+118); + width=img.width; + height=img.height; + + //TODO: avoid using header array andwrite everithing in one run header[2]=filesize; @@ -83,9 +117,7 @@ char mWriteBitMap(tImage img,char* vFile) { //BEGIN of format writing //Write ColorTable - char b; - char c; - for (char a=0;a<16;a++) { + for (a=0;a<16;a++) { b=a*3; c=a<<2; header[54+c]=(img.pal[b+2])*4; //Red @@ -95,7 +127,6 @@ char mWriteBitMap(tImage img,char* vFile) { //Write header fwrite(header,118,1,bitmap); //Write data - char junk[3]={0,0,0}; img.width=(img.width+1)>>1; while (img.height--) { fwrite(img.pix+img.height*img.width,img.width,1,bitmap); @@ -112,6 +143,8 @@ char mReadBitMap(tImage* img,char* data, int size) { char ok; unsigned short int width; unsigned short int height; + int width2; + int x=0; //Validate if there is header and if it starts in BM ok = size>118; @@ -128,7 +161,7 @@ char mReadBitMap(tImage* img,char* data, int size) { //Calculate serialized widths width=(width+1)>>1; //raw serialized width - int width2=width+((-width)&3); //bmp serialized width + width2=width+((-width)&3); //bmp serialized width //Validate image and file size; get memory to allocate the image ok=ok&& ( ((*img).height*width2) == (size-118)); @@ -141,7 +174,6 @@ char mReadBitMap(tImage* img,char* data, int size) { } //Serialize bitmap-->raw array - int x=0; while (height--) memcpy((*img).pix+(x++)*width,data+118+height*width2,width); return 1; diff --git a/PR/src/lib/formats/Attic/mid.c b/PR/src/lib/formats/Attic/mid.c index e69de29..3f703e7 100644 --- a/PR/src/lib/formats/Attic/mid.c +++ b/PR/src/lib/formats/Attic/mid.c @@ -0,0 +1,5 @@ + +char mFormatExtractMid(unsigned char* data, char *vFileext,unsigned long int size) { + //Ignore checksum & sound type + return writeData(data,2,vFileext,size); +} diff --git a/PR/src/lib/formats/Attic/pal.c b/PR/src/lib/formats/Attic/pal.c index 3c6d038..4d8313a 100644 --- a/PR/src/lib/formats/Attic/pal.c +++ b/PR/src/lib/formats/Attic/pal.c @@ -1,14 +1,31 @@ - +/* #if DIR_SEPARATOR=='/' #include "pal.h" #else #include "formats/pal.h" #endif +*/ + +#include <string.h> +#include <stdlib.h> +#include <stdio.h> +#include "pal.h" +#include "memory.h" +#include "extract.h" +#include "parser.h" +#include "resources.h" /***************************************************************\ | Jasc Palette handling functions | \***************************************************************/ +char mFormatExtractPal(unsigned char** data, char *vFileext,unsigned long int size) { + //Convert palette from POP format to JASC format + mExportPalette(data,&size); + //save JASC palette + return writeData(*data,0,vFileext,size); +} + char mImportPalette(unsigned char** data, unsigned short *size) { //check size if (*size<130) return 0; @@ -19,6 +36,7 @@ char mImportPalette(unsigned char** data, unsigned short *size) { unsigned char* pal=getMemory(100); unsigned short int parsed; int i=0; + int k=0; //set palette with sample memcpy(pal,pals,100); @@ -28,7 +46,7 @@ char mImportPalette(unsigned char** data, unsigned short *size) { if (i!=sizeof(palh)) return 0; //set current values - for (int k=0;k<16;k++) { + for (;k<16;k++) { getNumberToken((*data),&parsed,' ',&i,4); pal[(k*3)+4]=(parsed+2)>>2; getNumberToken((*data),&parsed,' ',&i,4); @@ -65,8 +83,8 @@ void mExportPalette(unsigned char** data, unsigned long int *size) { void mLoadPalette(char* array,tImage *image) { int k=0; - for (int i=5;i<5+16*3;i++) { + int i; + for (i=5;i<5+16*3;i++) { (*image).pal[k++]=array[i]; } } - diff --git a/PR/src/lib/formats/Attic/wav.c b/PR/src/lib/formats/Attic/wav.c index e602b6e..4c75e29 100644 --- a/PR/src/lib/formats/Attic/wav.c +++ b/PR/src/lib/formats/Attic/wav.c @@ -1,3 +1,4 @@ +/* #if DIR_SEPARATOR=='/' #include "wav.h" #include "../compile.h" @@ -5,6 +6,11 @@ #include "formats/wav.h" #include "compile.h" #endif +*/ + +#include "wav.h" +#include "compile.h" + char mFormatExtractWav(unsigned char* data, char *vFileext,unsigned long int size) { diff --git a/PR/src/lib/formats/mid.h b/PR/src/lib/formats/mid.h deleted file mode 100644 index e69de29..0000000 diff --git a/PR/resources.c b/PR/src/lib/layers/autodetect.c similarity index 97% rename from PR/resources.c rename to PR/src/lib/layers/autodetect.c index 9b439e0..fd30a5f 100644 --- a/PR/resources.c +++ b/PR/src/lib/layers/autodetect.c @@ -1,8 +1,13 @@ + + //Needed files #include <stdio.h> #include <stdlib.h> +#include "pr.h" #include "parser.h" #include "memory.h" +#include "resources.h" +#include "compress.h" /***************************************************************\ | File format handling | @@ -88,7 +93,8 @@ void parseResource(tResource* r[], char* line) { } void emptyTable(tResource* r[]) { - for (int i=0;i<65536;i++) r[i]=NULL; + int i=0; + for (;i<65536;i++) r[i]=NULL; } //parse file @@ -157,7 +163,8 @@ char generateFile(char* vFile,tResource* r[]) { //insert main body file fputs(B,fp); fputs("\n",fp); - for (int id=0;id<65536;id++) { + int id=0; + for (;id<65536;id++) { if (r[id]!=NULL) { if ((*(r[id])).desc==NULL) { if ((*(r[id])).coms==NULL) { @@ -251,9 +258,6 @@ void getUpperFolder(char* aux, char* vFiledat) { - - - //File handling functions diff --git a/PR/src/lib/layers/idlist.c b/PR/src/lib/layers/idlist.c new file mode 100644 index 0000000..fd30a5f --- /dev/null +++ b/PR/src/lib/layers/idlist.c @@ -0,0 +1,303 @@ + + +//Needed files +#include <stdio.h> +#include <stdlib.h> +#include "pr.h" +#include "parser.h" +#include "memory.h" +#include "resources.h" +#include "compress.h" + +/***************************************************************\ +| File format handling | +\***************************************************************/ + +char verifyLevelHeader(char* array, int size) { + return (((size==2306)||(size==2305))&&!(array[1698]&0x0F)&&!(array[1700]&0x0F)&&!(array[1702]&0x0F)); +} + +char verifyImageHeader(char* array, int size) { + //return (size>6) && (!(((!array[1])||(array[2])||(!array[3])||(array[4])||(array[5])||(((unsigned char)array[6]&0xF0)!=0xB0)))); + return (size>7) && (!array[5]) && (((unsigned char)array[6]&0xF0)==0xB0); + //todo: fix the expression +} + +char verifyPaletteHeader(char* array, int size) { + return ((size==101)&&(!array[2])&&(!array[3])&&(array[4]==0x10)); +} + +char verifyMidiHeader(char* array, int size) { + return + (size>6) && + (array[1]==0x02) && + (array[2]=='M') && + (array[3]=='T') && + (array[4]=='h') && + (array[5]=='d') + ; +} + +char verifyWaveHeader(char* array, int size) { + return + (size>1)&&(array[1]==0x01) + ; +} + +char verifyHeader(char* array, int size) { + if (verifyLevelHeader(array,size)) return 1; + if (verifyMidiHeader(array,size)) return 4; + if (verifyImageHeader(array,size)) return 2; + if (verifyPaletteHeader(array,size)) return 6; + if (verifyWaveHeader(array,size)) return 3; + return 05; +} + + +/***************************************************************\ +| Parsing resource file | +\***************************************************************/ + + +//Parse line +void parseResource(tResource* r[], char* line) { + //declare variables + int i=0; + unsigned short int id,ty; + int k=0; + + //Begin parsing + + for (;!(line[k]=='\r'||line[k]=='\n'||(!line[k]));k++); + line[k]=0; + + if (getNumberToken(line,&id,' ',&i,6)) { + r[id]=(tResource*)malloc(sizeof(tResource)); + getNumberToken(line,&(*(r[id])).size,' ',&i,6); + getNumberToken(line,&(*(r[id])).offset,' ',&i,6); + getUpperToken(line,(*(r[id])).file,' ',&i,12); + if (getNumberToken(line,&ty,' ',&i,3)) { + (*(r[id])).desc=(char*)malloc(255); + if (getToken(line,(*(r[id])).desc,'#',&i,255)) { + (*(r[id])).coms=(char*)malloc(1023); + if (!getToken(line,(*(r[id])).coms,0,&i,1023)) { + free ((*(r[id])).coms); + (*(r[id])).coms=NULL; + } + } + } else { + (*(r[id])).desc=NULL; + } + (*(r[id])).type=ty; + } +} + +void emptyTable(tResource* r[]) { + int i=0; + for (;i<65536;i++) r[i]=NULL; +} + +//parse file +char parseFile(char* vFile,tResource* r[]) { + //declare variables + char parsing=0; + char line[MAX_LINE_SIZE]; + char token[MAX_LINE_SIZE]; + char B[]=BEGIN_TABLE; + char E[]=END_TABLE; + FILE* fp; + + //empty resource array + emptyTable(r); + + //parse file + if ((fp=fopen(vFile,"rt"))!=NULL) { + while (fgets(line,MAX_LINE_SIZE,fp)!=NULL) { + if (parsing) { + if (equals(line,E)) { + parsing=0; + } else { + parseResource(r,line); + } + } else { + if (equals(line,B)) parsing=1; + } + } + fclose(fp); + return 1; + } else { + return 0; + } +} + +//generate file +char generateFile(char* vFile,tResource* r[]) { + //declare variables + char parsing=0; + char line[MAX_LINE_SIZE]; + char coms[MAX_LINE_SIZE]; + char B[]=BEGIN_TABLE; + char E[]=END_TABLE; + char none[]=""; + FILE* fp; + FILE* source; + + if ((fp=fopen("res.tmp","wt"))!=NULL) { + //insert headers + if ((source=fopen(vFile,"rt"))!=NULL) { + while ((parsing!=2)&&(fgets(line,MAX_LINE_SIZE,source)!=NULL)) { + if (parsing) { + if (equals(line,E)) { + parsing=2; + } + } else { + if (equals(line,B)) { + parsing=1; + } else { + fputs(line,fp); + } + } + } + } + + //insert main body file + fputs(B,fp); + fputs("\n",fp); + int id=0; + for (;id<65536;id++) { + if (r[id]!=NULL) { + if ((*(r[id])).desc==NULL) { + if ((*(r[id])).coms==NULL) { + sprintf(coms,none); + } else { + sprintf(coms," #",(*(r[id])).coms); + } + } else { + if ((*(r[id])).coms==NULL) { + sprintf(coms," %s",(*(r[id])).desc); + } else { + sprintf(coms," %s#%s",(*(r[id])).desc,(*(r[id])).coms); + } + } + sprintf(line,"%05d %05d %05d %s %02d%s\n", + id, + (*(r[id])).size, + (*(r[id])).offset, + (*(r[id])).file, + (*(r[id])).type, + coms); + fputs(line,fp); + } + } + fputs("\n",fp); + fputs(E,fp); + + //insert footers + if (source!=NULL) { + while ((parsing==2) && (fgets(line,MAX_LINE_SIZE,source)!=NULL)) { + fputs(line,fp); + } + fclose(source); + } + fclose(fp); + remove(vFile); + rename("res.tmp",vFile); + return 1; + } else { + return 0; + } +} + +//Resources extras + +void getFileName(char* vFileext,char* vDirExt,char type, unsigned short int id) { + char extMidi[] = "mid"; + char extWave[] = "wav"; + char extBmp[] = "bmp"; + char extLevel[] = "pet"; + char extExtra[] = "ext"; + char extRaw[] = "raw"; + char extPal[] = "pal"; + char* ext; + + switch (type) { + case 0: + ext=extRaw; + break; + case 1: + ext=extLevel; + break; + case 2: + ext=extBmp; + break; + case 4: + ext=extMidi; + break; + case 3: + ext=extWave; + break; + case 6: + ext=extPal; + break; + default: + ext=extExtra; + break; + } + + //set filename + sprintf(vFileext,"%s%cres%05d.%s",vDirExt,DIR_SEPARATOR,id,ext); +} + +void getUpperFolder(char* aux, char* vFiledat) { + int i=0; + while (getUpperToken(vFiledat,aux,DIR_SEPARATOR,&i,260)); + aux[12]=0; +} + + + + + +//File handling functions + + + + +int mLoadFileArray(char* vFile,unsigned char** array) { + //declare variables + FILE *fp; + int aux; + + //Open the file + if ((fp=fopen(vFile,"rb"))==NULL) { + return 0; + } else { + //get file size + fseek(fp,0,SEEK_END); + aux=ftell(fp); + if ( !aux || (aux>SIZE_OF_FILE) || ( ((*array=(char*)malloc(sizeof(char)*aux))==NULL) ) ) { + //if the file was null or bigger than the max size or couldn't allocate the file in memory + fclose(fp); + return 0; + } else { + //if the filewas succesfully open + fseek(fp,0,SEEK_SET); + aux=fread (*array,1,aux,fp); + fclose(fp); + return aux; + } + } +} + +char mSaveRaw(char* vFile,unsigned char* output, int size) { + FILE * pFile; + if ((pFile = fopen (vFile , "wb"))==NULL) { + return 0; + } + if (!size) { + return 0; + } + fwrite (output, 1, size, pFile); + fclose (pFile); + return 1; +} diff --git a/PR/memory.c b/PR/src/lib/layers/memory.c similarity index 100% rename from PR/memory.c rename to PR/src/lib/layers/memory.c diff --git a/PR/src/lib/object/image/image16.c b/PR/src/lib/object/image/image16.c new file mode 100644 index 0000000..921cef9 --- /dev/null +++ b/PR/src/lib/object/image/image16.c @@ -0,0 +1,250 @@ +/***************************************************************\ +| I M P L E M E N T A T I O N | +\***************************************************************/ + +#include <stdio.h> +#include "compress.h" +#include "memory.h" + +//reserved memory for the Lzx algorithm +#define MAX_MOD_SIZE_IN_LZX 32001 +//38401 +//modulus to be used in the 10 bits of the algorithm +#define MAX_MXD_SIZE_IN_LZX 0x400 + +/***************************************************************\ +| Compression algorithm handling | +\***************************************************************/ + +//Determines where the transposed byte must be saved +int transpose(int x,int n,int m) { + return ((x%m)*((n+1)/2))+(int)(x/m); +} + +//B3 and B4 expansion algorithm sub function +unsigned char popBit(unsigned char *byte) { + unsigned char bit=(*byte)&1; + (*byte)>>=1; + return bit; +} + +//Expands B3/B4 algorithm +void expandLzx(char* array,tImage* img, int *i,int cursor, int virtualSize) { +printf("expandLzx %d %d \n",virtualSize,cursor); + int pos,h; + char k; + unsigned char maskbyte,rep; + for(pos=0;pos<MAX_MXD_SIZE_IN_LZX;(*img).pix[pos++]=0); //clean output garbage + while (cursor<virtualSize) { + maskbyte=array[(*i)++]; + for (k=8;k&&(cursor<virtualSize);k--) { + if (popBit(&maskbyte)) { + (*img).pix[cursor++]=array[(*i)++]; + } else { + pos=66+((0x100)*((rep=array[(*i)++])&3))+(unsigned char)array[(*i)++]; + rep=(rep>>2)+3; + while (rep--) { //Be careful in big images + h=cursor/MAX_MXD_SIZE_IN_LZX-(pos%MAX_MXD_SIZE_IN_LZX>cursor%MAX_MXD_SIZE_IN_LZX); + (*img).pix[cursor++]=(*img).pix[((h<0)?0:h)*MAX_MXD_SIZE_IN_LZX+pos++%MAX_MXD_SIZE_IN_LZX]; + } + } + } + } +} + +//Compress B1/B2 algorithm +void compressRle(unsigned char* data,tImage* img,int *dataSize) { + printf("llega 3.51\n"); + //Declare pointers + char* cursorData = data; + char* counter; + char* cursorPix = (*img).pix; + char* imgEnd = (*img).pix+((*img).size>>1)-1; + printf("llega 3.52\n"); + + while (cursorPix<imgEnd) { + //Step 1: Create counter + *(counter=(cursorData++))=-1; + + //Step 2: Look and copy the string until a repeated byte is found + while ((cursorPix<=imgEnd)&&(*cursorPix!=*(++cursorPix))&&((*counter)!=127)) { + (*counter)++; + *(cursorData++)=*(cursorPix-1); + } +//printf("llega 3.55 cd=%d cp=%d ie=%d\n",cursorData-data,cursorPix,imgEnd); + + cursorPix--; + //Step 3: If there was a repeated string, let's ignore it and add the cursor with the repetitions + if (*counter==-1) { + while ((cursorPix<imgEnd)&&(*cursorPix==(*(++cursorPix)))) (*counter)--; + *(cursorData++)=*(cursorPix-1); //Print repeated char + } + } + *(cursorData++)=0; + *(cursorData++)=*(cursorPix); +// printf("llega 3.59\n"); + + *dataSize=(int)cursorData-(int)data; +} + + + + + + +//Expands an array into an image +int mExpandGraphic(char* array,tImage *image, int virtualSize) { + /* + Reads array and extracts tImage + returns the next image address or -1 in case of error + + Header info: + char checksum, short int height, short int width, (char)0, char compressionType + normaly: (* ignored types) + checksum* - height - 00 - width - 00 - 00* - compression type + */ +printf("expand graphic le ejecuta %d\n",virtualSize); + + int cursor=0; + int i=1; + + //Get memory for the image + image->height=((unsigned char)array[(i)])+256*((unsigned char)array[(i+1)]) ; +i=i+2; + image->width =((unsigned char)array[(i)])+256*((unsigned char)array[(i+1)]); +i=i+2; + (*image).size =(*image).height*(*image).width; +printf("h=%d, w=%d %x %x %x %x \n",(*image).height,image->width,(unsigned char)array[1],(unsigned char)array[2],(unsigned char)array[3],(unsigned char)array[4]); + virtualSize=(((*image).height*((*image).width+((*image).width&1)))>>1); + i++; + +printf("geteo memoria %x %d\n",(unsigned char)array[i],virtualSize); + switch ((unsigned char)array[i++]) { + case PG_COMP_RAW: //No Compression Algorithm + if (((*image).pix=getMemory(virtualSize))==NULL) return -1; + while (cursor<virtualSize) { + (*image).pix[cursor++]=array[i++]; + } + break; + case PG_COMP_RLE_LR: //RLE Left to Right Compression Algorithm + if (((*image).pix=getMemory(virtualSize))==NULL) return -1; + while (cursor<virtualSize) { + if ((signed char)array[i]<0) { + //negative + while (array[i]++) (*image).pix[(cursor++)]=array[i+1]; + i+=2; + } else { + //Positive + char cx=array[i++]+1; + while (cx--) (*image).pix[(cursor++)]=array[i++]; + } + } + break; + case PG_COMP_RLE_UD: //RLE Up to Down Compression Algorithm + if (((*image).pix=getMemory(virtualSize))==NULL) return -1; + while (cursor<virtualSize) { + if ((signed char)array[i]<0) { + //negative + while (array[i]++) (*image).pix[(transpose(cursor++,(*image).width,(*image).height))]=array[i+1]; + i+=2; + } else { + //Positive + char cx=array[i++]+1; + while (cx--) (*image).pix[transpose(cursor++,(*image).width,(*image).height)]=array[i++]; + } + } + break; + case PG_COMP_LZX_LR: //LZ Groody Up to Down Version Compression Algorithm + printf("llega b4\n"); + if (((*image).pix=getMemory(MAX_MOD_SIZE_IN_LZX))==NULL) return -1; + expandLzx(array,image,&i,cursor,virtualSize); + break; + case PG_COMP_LZX_UD: //LZ Groody Left to Right Version Compression Algorithm +printf("hi\n"); + if (((*image).pix=getMemory(MAX_MOD_SIZE_IN_LZX))==NULL) return -1; + { + unsigned char* outputaux=getMemory(virtualSize); + printf("antes\n"); + expandLzx(array,image,&i,cursor,virtualSize); + printf("despues\n"); + //Transpose + while (cursor<virtualSize) outputaux[transpose(cursor,(*image).width,(*image).height)]=(*image).pix[cursor++]; + free((*image).pix); + (*image).pix=outputaux; + } + break; + default: + return -1; + } + return i; +} + +//Compress an image into an array in the most quick & dirty way +int mCompressGraphic(unsigned char* data,tImage i, int* size) { + int dataSize; +// unsigned char* data; + + /* + *size=(i.size/2)+6; + a=getMemory(*size); + //height - 00 - width - 00 - 00 - compression type + a[2]=i.width; + a[3]=i.width>>8; + + a[0]=i.height; + a[1]=i.height>>8; + + a[4]=0; + a[5]=0xB0; // how q&d I am :) + + memcpy(i.pix,a+6,*size); //TODO it should be a+6,i.pix + */ +//printf("llega 3\n"); + //=getMemory(10*i.size+50); //This will reserve 10*2*(image size)+50 bytes, to allocate the compressed file +//printf("llega 3.3\n"); + compressRle(data+6,&i,&dataSize); +//printf("llega 3.6\n"); + //a=getMemory(*size=(dataSize+6)); +//printf("llega 4\n"); + /* + Header Settings: + height - 00 - width - 00 - 00 - compression type + */ + data[2]=i.width; + data[3]=i.width>>8; + + data[0]=i.height; + data[1]=i.height>>8; + + data[4]=0; + data[5]=0xB1; + + //memcpy(a+6,data,dataSize); + //free(data); +*size=(dataSize+6); +//printf("Tize: %d %02x %02x %02x %02x %02x %02x %02x\n",*size,a[0],a[1],a[2],a[3],a[4],a[5],a[6]); + + + return 1; +} + +/***************************************************************\ +| File handling | +\***************************************************************/ + +//Deprecated +/* +char mLoadFilePalette(char* vFile,int address, char* pal) { + FILE *fp; + char aux; + + if ((fp=fopen(vFile,"rb"))==NULL) { + return 0; + } else { + fseek (fp, address, SEEK_SET); + aux=fread (pal,SIZE_OF_PALETTE,1,fp); + fclose(fp); + return aux; + } +} +*/ diff --git a/PR/src/lib/object/image/image2.c b/PR/src/lib/object/image/image2.c new file mode 100644 index 0000000..921cef9 --- /dev/null +++ b/PR/src/lib/object/image/image2.c @@ -0,0 +1,250 @@ +/***************************************************************\ +| I M P L E M E N T A T I O N | +\***************************************************************/ + +#include <stdio.h> +#include "compress.h" +#include "memory.h" + +//reserved memory for the Lzx algorithm +#define MAX_MOD_SIZE_IN_LZX 32001 +//38401 +//modulus to be used in the 10 bits of the algorithm +#define MAX_MXD_SIZE_IN_LZX 0x400 + +/***************************************************************\ +| Compression algorithm handling | +\***************************************************************/ + +//Determines where the transposed byte must be saved +int transpose(int x,int n,int m) { + return ((x%m)*((n+1)/2))+(int)(x/m); +} + +//B3 and B4 expansion algorithm sub function +unsigned char popBit(unsigned char *byte) { + unsigned char bit=(*byte)&1; + (*byte)>>=1; + return bit; +} + +//Expands B3/B4 algorithm +void expandLzx(char* array,tImage* img, int *i,int cursor, int virtualSize) { +printf("expandLzx %d %d \n",virtualSize,cursor); + int pos,h; + char k; + unsigned char maskbyte,rep; + for(pos=0;pos<MAX_MXD_SIZE_IN_LZX;(*img).pix[pos++]=0); //clean output garbage + while (cursor<virtualSize) { + maskbyte=array[(*i)++]; + for (k=8;k&&(cursor<virtualSize);k--) { + if (popBit(&maskbyte)) { + (*img).pix[cursor++]=array[(*i)++]; + } else { + pos=66+((0x100)*((rep=array[(*i)++])&3))+(unsigned char)array[(*i)++]; + rep=(rep>>2)+3; + while (rep--) { //Be careful in big images + h=cursor/MAX_MXD_SIZE_IN_LZX-(pos%MAX_MXD_SIZE_IN_LZX>cursor%MAX_MXD_SIZE_IN_LZX); + (*img).pix[cursor++]=(*img).pix[((h<0)?0:h)*MAX_MXD_SIZE_IN_LZX+pos++%MAX_MXD_SIZE_IN_LZX]; + } + } + } + } +} + +//Compress B1/B2 algorithm +void compressRle(unsigned char* data,tImage* img,int *dataSize) { + printf("llega 3.51\n"); + //Declare pointers + char* cursorData = data; + char* counter; + char* cursorPix = (*img).pix; + char* imgEnd = (*img).pix+((*img).size>>1)-1; + printf("llega 3.52\n"); + + while (cursorPix<imgEnd) { + //Step 1: Create counter + *(counter=(cursorData++))=-1; + + //Step 2: Look and copy the string until a repeated byte is found + while ((cursorPix<=imgEnd)&&(*cursorPix!=*(++cursorPix))&&((*counter)!=127)) { + (*counter)++; + *(cursorData++)=*(cursorPix-1); + } +//printf("llega 3.55 cd=%d cp=%d ie=%d\n",cursorData-data,cursorPix,imgEnd); + + cursorPix--; + //Step 3: If there was a repeated string, let's ignore it and add the cursor with the repetitions + if (*counter==-1) { + while ((cursorPix<imgEnd)&&(*cursorPix==(*(++cursorPix)))) (*counter)--; + *(cursorData++)=*(cursorPix-1); //Print repeated char + } + } + *(cursorData++)=0; + *(cursorData++)=*(cursorPix); +// printf("llega 3.59\n"); + + *dataSize=(int)cursorData-(int)data; +} + + + + + + +//Expands an array into an image +int mExpandGraphic(char* array,tImage *image, int virtualSize) { + /* + Reads array and extracts tImage + returns the next image address or -1 in case of error + + Header info: + char checksum, short int height, short int width, (char)0, char compressionType + normaly: (* ignored types) + checksum* - height - 00 - width - 00 - 00* - compression type + */ +printf("expand graphic le ejecuta %d\n",virtualSize); + + int cursor=0; + int i=1; + + //Get memory for the image + image->height=((unsigned char)array[(i)])+256*((unsigned char)array[(i+1)]) ; +i=i+2; + image->width =((unsigned char)array[(i)])+256*((unsigned char)array[(i+1)]); +i=i+2; + (*image).size =(*image).height*(*image).width; +printf("h=%d, w=%d %x %x %x %x \n",(*image).height,image->width,(unsigned char)array[1],(unsigned char)array[2],(unsigned char)array[3],(unsigned char)array[4]); + virtualSize=(((*image).height*((*image).width+((*image).width&1)))>>1); + i++; + +printf("geteo memoria %x %d\n",(unsigned char)array[i],virtualSize); + switch ((unsigned char)array[i++]) { + case PG_COMP_RAW: //No Compression Algorithm + if (((*image).pix=getMemory(virtualSize))==NULL) return -1; + while (cursor<virtualSize) { + (*image).pix[cursor++]=array[i++]; + } + break; + case PG_COMP_RLE_LR: //RLE Left to Right Compression Algorithm + if (((*image).pix=getMemory(virtualSize))==NULL) return -1; + while (cursor<virtualSize) { + if ((signed char)array[i]<0) { + //negative + while (array[i]++) (*image).pix[(cursor++)]=array[i+1]; + i+=2; + } else { + //Positive + char cx=array[i++]+1; + while (cx--) (*image).pix[(cursor++)]=array[i++]; + } + } + break; + case PG_COMP_RLE_UD: //RLE Up to Down Compression Algorithm + if (((*image).pix=getMemory(virtualSize))==NULL) return -1; + while (cursor<virtualSize) { + if ((signed char)array[i]<0) { + //negative + while (array[i]++) (*image).pix[(transpose(cursor++,(*image).width,(*image).height))]=array[i+1]; + i+=2; + } else { + //Positive + char cx=array[i++]+1; + while (cx--) (*image).pix[transpose(cursor++,(*image).width,(*image).height)]=array[i++]; + } + } + break; + case PG_COMP_LZX_LR: //LZ Groody Up to Down Version Compression Algorithm + printf("llega b4\n"); + if (((*image).pix=getMemory(MAX_MOD_SIZE_IN_LZX))==NULL) return -1; + expandLzx(array,image,&i,cursor,virtualSize); + break; + case PG_COMP_LZX_UD: //LZ Groody Left to Right Version Compression Algorithm +printf("hi\n"); + if (((*image).pix=getMemory(MAX_MOD_SIZE_IN_LZX))==NULL) return -1; + { + unsigned char* outputaux=getMemory(virtualSize); + printf("antes\n"); + expandLzx(array,image,&i,cursor,virtualSize); + printf("despues\n"); + //Transpose + while (cursor<virtualSize) outputaux[transpose(cursor,(*image).width,(*image).height)]=(*image).pix[cursor++]; + free((*image).pix); + (*image).pix=outputaux; + } + break; + default: + return -1; + } + return i; +} + +//Compress an image into an array in the most quick & dirty way +int mCompressGraphic(unsigned char* data,tImage i, int* size) { + int dataSize; +// unsigned char* data; + + /* + *size=(i.size/2)+6; + a=getMemory(*size); + //height - 00 - width - 00 - 00 - compression type + a[2]=i.width; + a[3]=i.width>>8; + + a[0]=i.height; + a[1]=i.height>>8; + + a[4]=0; + a[5]=0xB0; // how q&d I am :) + + memcpy(i.pix,a+6,*size); //TODO it should be a+6,i.pix + */ +//printf("llega 3\n"); + //=getMemory(10*i.size+50); //This will reserve 10*2*(image size)+50 bytes, to allocate the compressed file +//printf("llega 3.3\n"); + compressRle(data+6,&i,&dataSize); +//printf("llega 3.6\n"); + //a=getMemory(*size=(dataSize+6)); +//printf("llega 4\n"); + /* + Header Settings: + height - 00 - width - 00 - 00 - compression type + */ + data[2]=i.width; + data[3]=i.width>>8; + + data[0]=i.height; + data[1]=i.height>>8; + + data[4]=0; + data[5]=0xB1; + + //memcpy(a+6,data,dataSize); + //free(data); +*size=(dataSize+6); +//printf("Tize: %d %02x %02x %02x %02x %02x %02x %02x\n",*size,a[0],a[1],a[2],a[3],a[4],a[5],a[6]); + + + return 1; +} + +/***************************************************************\ +| File handling | +\***************************************************************/ + +//Deprecated +/* +char mLoadFilePalette(char* vFile,int address, char* pal) { + FILE *fp; + char aux; + + if ((fp=fopen(vFile,"rb"))==NULL) { + return 0; + } else { + fseek (fp, address, SEEK_SET); + aux=fread (pal,SIZE_OF_PALETTE,1,fp); + fclose(fp); + return aux; + } +} +*/ diff --git a/PR/src/lib/object/image/image256.c b/PR/src/lib/object/image/image256.c new file mode 100644 index 0000000..921cef9 --- /dev/null +++ b/PR/src/lib/object/image/image256.c @@ -0,0 +1,250 @@ +/***************************************************************\ +| I M P L E M E N T A T I O N | +\***************************************************************/ + +#include <stdio.h> +#include "compress.h" +#include "memory.h" + +//reserved memory for the Lzx algorithm +#define MAX_MOD_SIZE_IN_LZX 32001 +//38401 +//modulus to be used in the 10 bits of the algorithm +#define MAX_MXD_SIZE_IN_LZX 0x400 + +/***************************************************************\ +| Compression algorithm handling | +\***************************************************************/ + +//Determines where the transposed byte must be saved +int transpose(int x,int n,int m) { + return ((x%m)*((n+1)/2))+(int)(x/m); +} + +//B3 and B4 expansion algorithm sub function +unsigned char popBit(unsigned char *byte) { + unsigned char bit=(*byte)&1; + (*byte)>>=1; + return bit; +} + +//Expands B3/B4 algorithm +void expandLzx(char* array,tImage* img, int *i,int cursor, int virtualSize) { +printf("expandLzx %d %d \n",virtualSize,cursor); + int pos,h; + char k; + unsigned char maskbyte,rep; + for(pos=0;pos<MAX_MXD_SIZE_IN_LZX;(*img).pix[pos++]=0); //clean output garbage + while (cursor<virtualSize) { + maskbyte=array[(*i)++]; + for (k=8;k&&(cursor<virtualSize);k--) { + if (popBit(&maskbyte)) { + (*img).pix[cursor++]=array[(*i)++]; + } else { + pos=66+((0x100)*((rep=array[(*i)++])&3))+(unsigned char)array[(*i)++]; + rep=(rep>>2)+3; + while (rep--) { //Be careful in big images + h=cursor/MAX_MXD_SIZE_IN_LZX-(pos%MAX_MXD_SIZE_IN_LZX>cursor%MAX_MXD_SIZE_IN_LZX); + (*img).pix[cursor++]=(*img).pix[((h<0)?0:h)*MAX_MXD_SIZE_IN_LZX+pos++%MAX_MXD_SIZE_IN_LZX]; + } + } + } + } +} + +//Compress B1/B2 algorithm +void compressRle(unsigned char* data,tImage* img,int *dataSize) { + printf("llega 3.51\n"); + //Declare pointers + char* cursorData = data; + char* counter; + char* cursorPix = (*img).pix; + char* imgEnd = (*img).pix+((*img).size>>1)-1; + printf("llega 3.52\n"); + + while (cursorPix<imgEnd) { + //Step 1: Create counter + *(counter=(cursorData++))=-1; + + //Step 2: Look and copy the string until a repeated byte is found + while ((cursorPix<=imgEnd)&&(*cursorPix!=*(++cursorPix))&&((*counter)!=127)) { + (*counter)++; + *(cursorData++)=*(cursorPix-1); + } +//printf("llega 3.55 cd=%d cp=%d ie=%d\n",cursorData-data,cursorPix,imgEnd); + + cursorPix--; + //Step 3: If there was a repeated string, let's ignore it and add the cursor with the repetitions + if (*counter==-1) { + while ((cursorPix<imgEnd)&&(*cursorPix==(*(++cursorPix)))) (*counter)--; + *(cursorData++)=*(cursorPix-1); //Print repeated char + } + } + *(cursorData++)=0; + *(cursorData++)=*(cursorPix); +// printf("llega 3.59\n"); + + *dataSize=(int)cursorData-(int)data; +} + + + + + + +//Expands an array into an image +int mExpandGraphic(char* array,tImage *image, int virtualSize) { + /* + Reads array and extracts tImage + returns the next image address or -1 in case of error + + Header info: + char checksum, short int height, short int width, (char)0, char compressionType + normaly: (* ignored types) + checksum* - height - 00 - width - 00 - 00* - compression type + */ +printf("expand graphic le ejecuta %d\n",virtualSize); + + int cursor=0; + int i=1; + + //Get memory for the image + image->height=((unsigned char)array[(i)])+256*((unsigned char)array[(i+1)]) ; +i=i+2; + image->width =((unsigned char)array[(i)])+256*((unsigned char)array[(i+1)]); +i=i+2; + (*image).size =(*image).height*(*image).width; +printf("h=%d, w=%d %x %x %x %x \n",(*image).height,image->width,(unsigned char)array[1],(unsigned char)array[2],(unsigned char)array[3],(unsigned char)array[4]); + virtualSize=(((*image).height*((*image).width+((*image).width&1)))>>1); + i++; + +printf("geteo memoria %x %d\n",(unsigned char)array[i],virtualSize); + switch ((unsigned char)array[i++]) { + case PG_COMP_RAW: //No Compression Algorithm + if (((*image).pix=getMemory(virtualSize))==NULL) return -1; + while (cursor<virtualSize) { + (*image).pix[cursor++]=array[i++]; + } + break; + case PG_COMP_RLE_LR: //RLE Left to Right Compression Algorithm + if (((*image).pix=getMemory(virtualSize))==NULL) return -1; + while (cursor<virtualSize) { + if ((signed char)array[i]<0) { + //negative + while (array[i]++) (*image).pix[(cursor++)]=array[i+1]; + i+=2; + } else { + //Positive + char cx=array[i++]+1; + while (cx--) (*image).pix[(cursor++)]=array[i++]; + } + } + break; + case PG_COMP_RLE_UD: //RLE Up to Down Compression Algorithm + if (((*image).pix=getMemory(virtualSize))==NULL) return -1; + while (cursor<virtualSize) { + if ((signed char)array[i]<0) { + //negative + while (array[i]++) (*image).pix[(transpose(cursor++,(*image).width,(*image).height))]=array[i+1]; + i+=2; + } else { + //Positive + char cx=array[i++]+1; + while (cx--) (*image).pix[transpose(cursor++,(*image).width,(*image).height)]=array[i++]; + } + } + break; + case PG_COMP_LZX_LR: //LZ Groody Up to Down Version Compression Algorithm + printf("llega b4\n"); + if (((*image).pix=getMemory(MAX_MOD_SIZE_IN_LZX))==NULL) return -1; + expandLzx(array,image,&i,cursor,virtualSize); + break; + case PG_COMP_LZX_UD: //LZ Groody Left to Right Version Compression Algorithm +printf("hi\n"); + if (((*image).pix=getMemory(MAX_MOD_SIZE_IN_LZX))==NULL) return -1; + { + unsigned char* outputaux=getMemory(virtualSize); + printf("antes\n"); + expandLzx(array,image,&i,cursor,virtualSize); + printf("despues\n"); + //Transpose + while (cursor<virtualSize) outputaux[transpose(cursor,(*image).width,(*image).height)]=(*image).pix[cursor++]; + free((*image).pix); + (*image).pix=outputaux; + } + break; + default: + return -1; + } + return i; +} + +//Compress an image into an array in the most quick & dirty way +int mCompressGraphic(unsigned char* data,tImage i, int* size) { + int dataSize; +// unsigned char* data; + + /* + *size=(i.size/2)+6; + a=getMemory(*size); + //height - 00 - width - 00 - 00 - compression type + a[2]=i.width; + a[3]=i.width>>8; + + a[0]=i.height; + a[1]=i.height>>8; + + a[4]=0; + a[5]=0xB0; // how q&d I am :) + + memcpy(i.pix,a+6,*size); //TODO it should be a+6,i.pix + */ +//printf("llega 3\n"); + //=getMemory(10*i.size+50); //This will reserve 10*2*(image size)+50 bytes, to allocate the compressed file +//printf("llega 3.3\n"); + compressRle(data+6,&i,&dataSize); +//printf("llega 3.6\n"); + //a=getMemory(*size=(dataSize+6)); +//printf("llega 4\n"); + /* + Header Settings: + height - 00 - width - 00 - 00 - compression type + */ + data[2]=i.width; + data[3]=i.width>>8; + + data[0]=i.height; + data[1]=i.height>>8; + + data[4]=0; + data[5]=0xB1; + + //memcpy(a+6,data,dataSize); + //free(data); +*size=(dataSize+6); +//printf("Tize: %d %02x %02x %02x %02x %02x %02x %02x\n",*size,a[0],a[1],a[2],a[3],a[4],a[5],a[6]); + + + return 1; +} + +/***************************************************************\ +| File handling | +\***************************************************************/ + +//Deprecated +/* +char mLoadFilePalette(char* vFile,int address, char* pal) { + FILE *fp; + char aux; + + if ((fp=fopen(vFile,"rb"))==NULL) { + return 0; + } else { + fseek (fp, address, SEEK_SET); + aux=fread (pal,SIZE_OF_PALETTE,1,fp); + fclose(fp); + return aux; + } +} +*/ diff --git a/PR/src/lib/object/image/image_common.c b/PR/src/lib/object/image/image_common.c new file mode 100644 index 0000000..921cef9 --- /dev/null +++ b/PR/src/lib/object/image/image_common.c @@ -0,0 +1,250 @@ +/***************************************************************\ +| I M P L E M E N T A T I O N | +\***************************************************************/ + +#include <stdio.h> +#include "compress.h" +#include "memory.h" + +//reserved memory for the Lzx algorithm +#define MAX_MOD_SIZE_IN_LZX 32001 +//38401 +//modulus to be used in the 10 bits of the algorithm +#define MAX_MXD_SIZE_IN_LZX 0x400 + +/***************************************************************\ +| Compression algorithm handling | +\***************************************************************/ + +//Determines where the transposed byte must be saved +int transpose(int x,int n,int m) { + return ((x%m)*((n+1)/2))+(int)(x/m); +} + +//B3 and B4 expansion algorithm sub function +unsigned char popBit(unsigned char *byte) { + unsigned char bit=(*byte)&1; + (*byte)>>=1; + return bit; +} + +//Expands B3/B4 algorithm +void expandLzx(char* array,tImage* img, int *i,int cursor, int virtualSize) { +printf("expandLzx %d %d \n",virtualSize,cursor); + int pos,h; + char k; + unsigned char maskbyte,rep; + for(pos=0;pos<MAX_MXD_SIZE_IN_LZX;(*img).pix[pos++]=0); //clean output garbage + while (cursor<virtualSize) { + maskbyte=array[(*i)++]; + for (k=8;k&&(cursor<virtualSize);k--) { + if (popBit(&maskbyte)) { + (*img).pix[cursor++]=array[(*i)++]; + } else { + pos=66+((0x100)*((rep=array[(*i)++])&3))+(unsigned char)array[(*i)++]; + rep=(rep>>2)+3; + while (rep--) { //Be careful in big images + h=cursor/MAX_MXD_SIZE_IN_LZX-(pos%MAX_MXD_SIZE_IN_LZX>cursor%MAX_MXD_SIZE_IN_LZX); + (*img).pix[cursor++]=(*img).pix[((h<0)?0:h)*MAX_MXD_SIZE_IN_LZX+pos++%MAX_MXD_SIZE_IN_LZX]; + } + } + } + } +} + +//Compress B1/B2 algorithm +void compressRle(unsigned char* data,tImage* img,int *dataSize) { + printf("llega 3.51\n"); + //Declare pointers + char* cursorData = data; + char* counter; + char* cursorPix = (*img).pix; + char* imgEnd = (*img).pix+((*img).size>>1)-1; + printf("llega 3.52\n"); + + while (cursorPix<imgEnd) { + //Step 1: Create counter + *(counter=(cursorData++))=-1; + + //Step 2: Look and copy the string until a repeated byte is found + while ((cursorPix<=imgEnd)&&(*cursorPix!=*(++cursorPix))&&((*counter)!=127)) { + (*counter)++; + *(cursorData++)=*(cursorPix-1); + } +//printf("llega 3.55 cd=%d cp=%d ie=%d\n",cursorData-data,cursorPix,imgEnd); + + cursorPix--; + //Step 3: If there was a repeated string, let's ignore it and add the cursor with the repetitions + if (*counter==-1) { + while ((cursorPix<imgEnd)&&(*cursorPix==(*(++cursorPix)))) (*counter)--; + *(cursorData++)=*(cursorPix-1); //Print repeated char + } + } + *(cursorData++)=0; + *(cursorData++)=*(cursorPix); +// printf("llega 3.59\n"); + + *dataSize=(int)cursorData-(int)data; +} + + + + + + +//Expands an array into an image +int mExpandGraphic(char* array,tImage *image, int virtualSize) { + /* + Reads array and extracts tImage + returns the next image address or -1 in case of error + + Header info: + char checksum, short int height, short int width, (char)0, char compressionType + normaly: (* ignored types) + checksum* - height - 00 - width - 00 - 00* - compression type + */ +printf("expand graphic le ejecuta %d\n",virtualSize); + + int cursor=0; + int i=1; + + //Get memory for the image + image->height=((unsigned char)array[(i)])+256*((unsigned char)array[(i+1)]) ; +i=i+2; + image->width =((unsigned char)array[(i)])+256*((unsigned char)array[(i+1)]); +i=i+2; + (*image).size =(*image).height*(*image).width; +printf("h=%d, w=%d %x %x %x %x \n",(*image).height,image->width,(unsigned char)array[1],(unsigned char)array[2],(unsigned char)array[3],(unsigned char)array[4]); + virtualSize=(((*image).height*((*image).width+((*image).width&1)))>>1); + i++; + +printf("geteo memoria %x %d\n",(unsigned char)array[i],virtualSize); + switch ((unsigned char)array[i++]) { + case PG_COMP_RAW: //No Compression Algorithm + if (((*image).pix=getMemory(virtualSize))==NULL) return -1; + while (cursor<virtualSize) { + (*image).pix[cursor++]=array[i++]; + } + break; + case PG_COMP_RLE_LR: //RLE Left to Right Compression Algorithm + if (((*image).pix=getMemory(virtualSize))==NULL) return -1; + while (cursor<virtualSize) { + if ((signed char)array[i]<0) { + //negative + while (array[i]++) (*image).pix[(cursor++)]=array[i+1]; + i+=2; + } else { + //Positive + char cx=array[i++]+1; + while (cx--) (*image).pix[(cursor++)]=array[i++]; + } + } + break; + case PG_COMP_RLE_UD: //RLE Up to Down Compression Algorithm + if (((*image).pix=getMemory(virtualSize))==NULL) return -1; + while (cursor<virtualSize) { + if ((signed char)array[i]<0) { + //negative + while (array[i]++) (*image).pix[(transpose(cursor++,(*image).width,(*image).height))]=array[i+1]; + i+=2; + } else { + //Positive + char cx=array[i++]+1; + while (cx--) (*image).pix[transpose(cursor++,(*image).width,(*image).height)]=array[i++]; + } + } + break; + case PG_COMP_LZX_LR: //LZ Groody Up to Down Version Compression Algorithm + printf("llega b4\n"); + if (((*image).pix=getMemory(MAX_MOD_SIZE_IN_LZX))==NULL) return -1; + expandLzx(array,image,&i,cursor,virtualSize); + break; + case PG_COMP_LZX_UD: //LZ Groody Left to Right Version Compression Algorithm +printf("hi\n"); + if (((*image).pix=getMemory(MAX_MOD_SIZE_IN_LZX))==NULL) return -1; + { + unsigned char* outputaux=getMemory(virtualSize); + printf("antes\n"); + expandLzx(array,image,&i,cursor,virtualSize); + printf("despues\n"); + //Transpose + while (cursor<virtualSize) outputaux[transpose(cursor,(*image).width,(*image).height)]=(*image).pix[cursor++]; + free((*image).pix); + (*image).pix=outputaux; + } + break; + default: + return -1; + } + return i; +} + +//Compress an image into an array in the most quick & dirty way +int mCompressGraphic(unsigned char* data,tImage i, int* size) { + int dataSize; +// unsigned char* data; + + /* + *size=(i.size/2)+6; + a=getMemory(*size); + //height - 00 - width - 00 - 00 - compression type + a[2]=i.width; + a[3]=i.width>>8; + + a[0]=i.height; + a[1]=i.height>>8; + + a[4]=0; + a[5]=0xB0; // how q&d I am :) + + memcpy(i.pix,a+6,*size); //TODO it should be a+6,i.pix + */ +//printf("llega 3\n"); + //=getMemory(10*i.size+50); //This will reserve 10*2*(image size)+50 bytes, to allocate the compressed file +//printf("llega 3.3\n"); + compressRle(data+6,&i,&dataSize); +//printf("llega 3.6\n"); + //a=getMemory(*size=(dataSize+6)); +//printf("llega 4\n"); + /* + Header Settings: + height - 00 - width - 00 - 00 - compression type + */ + data[2]=i.width; + data[3]=i.width>>8; + + data[0]=i.height; + data[1]=i.height>>8; + + data[4]=0; + data[5]=0xB1; + + //memcpy(a+6,data,dataSize); + //free(data); +*size=(dataSize+6); +//printf("Tize: %d %02x %02x %02x %02x %02x %02x %02x\n",*size,a[0],a[1],a[2],a[3],a[4],a[5],a[6]); + + + return 1; +} + +/***************************************************************\ +| File handling | +\***************************************************************/ + +//Deprecated +/* +char mLoadFilePalette(char* vFile,int address, char* pal) { + FILE *fp; + char aux; + + if ((fp=fopen(vFile,"rb"))==NULL) { + return 0; + } else { + fseek (fp, address, SEEK_SET); + aux=fread (pal,SIZE_OF_PALETTE,1,fp); + fclose(fp); + return aux; + } +} +*/ diff --git a/PR/pr.c b/PR/src/lib/pr.c similarity index 91% rename from PR/pr.c rename to PR/src/lib/pr.c index fe13d9e..eddc1b7 100644 --- a/PR/pr.c +++ b/PR/src/lib/pr.c @@ -21,7 +21,7 @@ /* pr.c: Main source file for Princed Resources \xaf\xaf\xaf\xaf - Princed Resources library V1 beta + Princed Resources editor (c) Copyright 2003, Princed Development Team Authors @@ -43,30 +43,16 @@ pr.c: Main source file for Princed Resources DO NOT remove this copyright notice */ -//Compilation options - -#define UNIX -//#define DLL -#define PR_ABOUT "Princed resources (PR) V0.6 beta.\r\n(c) Copyright 2003 - Princed Development Team\r\nhttp://www.princed.com.ar\r\n\r\n" - //Headers +#include <string.h> #include "pr.h" -//Inclusion of implementations - -#include "compile.c" -#include "extract.c" -#include "memory.c" -#include "parser.c" -#include "pg.c" -#include "resources.c" -#include "tasks.c" +#include "compress.h" -//format support -#include "formats/wav.c" -#include "formats/bmp.c" -#include "formats/pal.c" +#include "extract.h" +#include "compile.h" +#include "tasks.h" //functions @@ -94,7 +80,7 @@ int prExportDatOpt(char* vDatFile, char* vDirName, char* vResFile,char opt) { tResource* r[65536]; int a; parseFile (vResFile,r); - printf("kkkkkkkkkkk: %x\n",opt); + //printf("kkkkkkkkkkk: %x\n",opt); a=extract(vDatFile, vDirName,r,opt); if (!(opt&8)) generateFile(vResFile,r); return a; diff --git a/PR/src/lib/xml/tree.c b/PR/src/lib/xml/tree.c new file mode 100644 index 0000000..fd30a5f --- /dev/null +++ b/PR/src/lib/xml/tree.c @@ -0,0 +1,303 @@ + + +//Needed files +#include <stdio.h> +#include <stdlib.h> +#include "pr.h" +#include "parser.h" +#include "memory.h" +#include "resources.h" +#include "compress.h" + +/***************************************************************\ +| File format handling | +\***************************************************************/ + +char verifyLevelHeader(char* array, int size) { + return (((size==2306)||(size==2305))&&!(array[1698]&0x0F)&&!(array[1700]&0x0F)&&!(array[1702]&0x0F)); +} + +char verifyImageHeader(char* array, int size) { + //return (size>6) && (!(((!array[1])||(array[2])||(!array[3])||(array[4])||(array[5])||(((unsigned char)array[6]&0xF0)!=0xB0)))); + return (size>7) && (!array[5]) && (((unsigned char)array[6]&0xF0)==0xB0); + //todo: fix the expression +} + +char verifyPaletteHeader(char* array, int size) { + return ((size==101)&&(!array[2])&&(!array[3])&&(array[4]==0x10)); +} + +char verifyMidiHeader(char* array, int size) { + return + (size>6) && + (array[1]==0x02) && + (array[2]=='M') && + (array[3]=='T') && + (array[4]=='h') && + (array[5]=='d') + ; +} + +char verifyWaveHeader(char* array, int size) { + return + (size>1)&&(array[1]==0x01) + ; +} + +char verifyHeader(char* array, int size) { + if (verifyLevelHeader(array,size)) return 1; + if (verifyMidiHeader(array,size)) return 4; + if (verifyImageHeader(array,size)) return 2; + if (verifyPaletteHeader(array,size)) return 6; + if (verifyWaveHeader(array,size)) return 3; + return 05; +} + + +/***************************************************************\ +| Parsing resource file | +\***************************************************************/ + + +//Parse line +void parseResource(tResource* r[], char* line) { + //declare variables + int i=0; + unsigned short int id,ty; + int k=0; + + //Begin parsing + + for (;!(line[k]=='\r'||line[k]=='\n'||(!line[k]));k++); + line[k]=0; + + if (getNumberToken(line,&id,' ',&i,6)) { + r[id]=(tResource*)malloc(sizeof(tResource)); + getNumberToken(line,&(*(r[id])).size,' ',&i,6); + getNumberToken(line,&(*(r[id])).offset,' ',&i,6); + getUpperToken(line,(*(r[id])).file,' ',&i,12); + if (getNumberToken(line,&ty,' ',&i,3)) { + (*(r[id])).desc=(char*)malloc(255); + if (getToken(line,(*(r[id])).desc,'#',&i,255)) { + (*(r[id])).coms=(char*)malloc(1023); + if (!getToken(line,(*(r[id])).coms,0,&i,1023)) { + free ((*(r[id])).coms); + (*(r[id])).coms=NULL; + } + } + } else { + (*(r[id])).desc=NULL; + } + (*(r[id])).type=ty; + } +} + +void emptyTable(tResource* r[]) { + int i=0; + for (;i<65536;i++) r[i]=NULL; +} + +//parse file +char parseFile(char* vFile,tResource* r[]) { + //declare variables + char parsing=0; + char line[MAX_LINE_SIZE]; + char token[MAX_LINE_SIZE]; + char B[]=BEGIN_TABLE; + char E[]=END_TABLE; + FILE* fp; + + //empty resource array + emptyTable(r); + + //parse file + if ((fp=fopen(vFile,"rt"))!=NULL) { + while (fgets(line,MAX_LINE_SIZE,fp)!=NULL) { + if (parsing) { + if (equals(line,E)) { + parsing=0; + } else { + parseResource(r,line); + } + } else { + if (equals(line,B)) parsing=1; + } + } + fclose(fp); + return 1; + } else { + return 0; + } +} + +//generate file +char generateFile(char* vFile,tResource* r[]) { + //declare variables + char parsing=0; + char line[MAX_LINE_SIZE]; + char coms[MAX_LINE_SIZE]; + char B[]=BEGIN_TABLE; + char E[]=END_TABLE; + char none[]=""; + FILE* fp; + FILE* source; + + if ((fp=fopen("res.tmp","wt"))!=NULL) { + //insert headers + if ((source=fopen(vFile,"rt"))!=NULL) { + while ((parsing!=2)&&(fgets(line,MAX_LINE_SIZE,source)!=NULL)) { + if (parsing) { + if (equals(line,E)) { + parsing=2; + } + } else { + if (equals(line,B)) { + parsing=1; + } else { + fputs(line,fp); + } + } + } + } + + //insert main body file + fputs(B,fp); + fputs("\n",fp); + int id=0; + for (;id<65536;id++) { + if (r[id]!=NULL) { + if ((*(r[id])).desc==NULL) { + if ((*(r[id])).coms==NULL) { + sprintf(coms,none); + } else { + sprintf(coms," #",(*(r[id])).coms); + } + } else { + if ((*(r[id])).coms==NULL) { + sprintf(coms," %s",(*(r[id])).desc); + } else { + sprintf(coms," %s#%s",(*(r[id])).desc,(*(r[id])).coms); + } + } + sprintf(line,"%05d %05d %05d %s %02d%s\n", + id, + (*(r[id])).size, + (*(r[id])).offset, + (*(r[id])).file, + (*(r[id])).type, + coms); + fputs(line,fp); + } + } + fputs("\n",fp); + fputs(E,fp); + + //insert footers + if (source!=NULL) { + while ((parsing==2) && (fgets(line,MAX_LINE_SIZE,source)!=NULL)) { + fputs(line,fp); + } + fclose(source); + } + fclose(fp); + remove(vFile); + rename("res.tmp",vFile); + return 1; + } else { + return 0; + } +} + +//Resources extras + +void getFileName(char* vFileext,char* vDirExt,char type, unsigned short int id) { + char extMidi[] = "mid"; + char extWave[] = "wav"; + char extBmp[] = "bmp"; + char extLevel[] = "pet"; + char extExtra[] = "ext"; + char extRaw[] = "raw"; + char extPal[] = "pal"; + char* ext; + + switch (type) { + case 0: + ext=extRaw; + break; + case 1: + ext=extLevel; + break; + case 2: + ext=extBmp; + break; + case 4: + ext=extMidi; + break; + case 3: + ext=extWave; + break; + case 6: + ext=extPal; + break; + default: + ext=extExtra; + break; + } + + //set filename + sprintf(vFileext,"%s%cres%05d.%s",vDirExt,DIR_SEPARATOR,id,ext); +} + +void getUpperFolder(char* aux, char* vFiledat) { + int i=0; + while (getUpperToken(vFiledat,aux,DIR_SEPARATOR,&i,260)); + aux[12]=0; +} + + + + + +//File handling functions + + + + +int mLoadFileArray(char* vFile,unsigned char** array) { + //declare variables + FILE *fp; + int aux; + + //Open the file + if ((fp=fopen(vFile,"rb"))==NULL) { + return 0; + } else { + //get file size + fseek(fp,0,SEEK_END); + aux=ftell(fp); + if ( !aux || (aux>SIZE_OF_FILE) || ( ((*array=(char*)malloc(sizeof(char)*aux))==NULL) ) ) { + //if the file was null or bigger than the max size or couldn't allocate the file in memory + fclose(fp); + return 0; + } else { + //if the filewas succesfully open + fseek(fp,0,SEEK_SET); + aux=fread (*array,1,aux,fp); + fclose(fp); + return aux; + } + } +} + +char mSaveRaw(char* vFile,unsigned char* output, int size) { + FILE * pFile; + if ((pFile = fopen (vFile , "wb"))==NULL) { + return 0; + } + if (!size) { + return 0; + } + fwrite (output, 1, size, pFile); + fclose (pFile); + return 1; +} diff --git a/PR/src/lib/xml/unknown.c b/PR/src/lib/xml/unknown.c new file mode 100644 index 0000000..fd30a5f --- /dev/null +++ b/PR/src/lib/xml/unknown.c @@ -0,0 +1,303 @@ + + +//Needed files +#include <stdio.h> +#include <stdlib.h> +#include "pr.h" +#include "parser.h" +#include "memory.h" +#include "resources.h" +#include "compress.h" + +/***************************************************************\ +| File format handling | +\***************************************************************/ + +char verifyLevelHeader(char* array, int size) { + return (((size==2306)||(size==2305))&&!(array[1698]&0x0F)&&!(array[1700]&0x0F)&&!(array[1702]&0x0F)); +} + +char verifyImageHeader(char* array, int size) { + //return (size>6) && (!(((!array[1])||(array[2])||(!array[3])||(array[4])||(array[5])||(((unsigned char)array[6]&0xF0)!=0xB0)))); + return (size>7) && (!array[5]) && (((unsigned char)array[6]&0xF0)==0xB0); + //todo: fix the expression +} + +char verifyPaletteHeader(char* array, int size) { + return ((size==101)&&(!array[2])&&(!array[3])&&(array[4]==0x10)); +} + +char verifyMidiHeader(char* array, int size) { + return + (size>6) && + (array[1]==0x02) && + (array[2]=='M') && + (array[3]=='T') && + (array[4]=='h') && + (array[5]=='d') + ; +} + +char verifyWaveHeader(char* array, int size) { + return + (size>1)&&(array[1]==0x01) + ; +} + +char verifyHeader(char* array, int size) { + if (verifyLevelHeader(array,size)) return 1; + if (verifyMidiHeader(array,size)) return 4; + if (verifyImageHeader(array,size)) return 2; + if (verifyPaletteHeader(array,size)) return 6; + if (verifyWaveHeader(array,size)) return 3; + return 05; +} + + +/***************************************************************\ +| Parsing resource file | +\***************************************************************/ + + +//Parse line +void parseResource(tResource* r[], char* line) { + //declare variables + int i=0; + unsigned short int id,ty; + int k=0; + + //Begin parsing + + for (;!(line[k]=='\r'||line[k]=='\n'||(!line[k]));k++); + line[k]=0; + + if (getNumberToken(line,&id,' ',&i,6)) { + r[id]=(tResource*)malloc(sizeof(tResource)); + getNumberToken(line,&(*(r[id])).size,' ',&i,6); + getNumberToken(line,&(*(r[id])).offset,' ',&i,6); + getUpperToken(line,(*(r[id])).file,' ',&i,12); + if (getNumberToken(line,&ty,' ',&i,3)) { + (*(r[id])).desc=(char*)malloc(255); + if (getToken(line,(*(r[id])).desc,'#',&i,255)) { + (*(r[id])).coms=(char*)malloc(1023); + if (!getToken(line,(*(r[id])).coms,0,&i,1023)) { + free ((*(r[id])).coms); + (*(r[id])).coms=NULL; + } + } + } else { + (*(r[id])).desc=NULL; + } + (*(r[id])).type=ty; + } +} + +void emptyTable(tResource* r[]) { + int i=0; + for (;i<65536;i++) r[i]=NULL; +} + +//parse file +char parseFile(char* vFile,tResource* r[]) { + //declare variables + char parsing=0; + char line[MAX_LINE_SIZE]; + char token[MAX_LINE_SIZE]; + char B[]=BEGIN_TABLE; + char E[]=END_TABLE; + FILE* fp; + + //empty resource array + emptyTable(r); + + //parse file + if ((fp=fopen(vFile,"rt"))!=NULL) { + while (fgets(line,MAX_LINE_SIZE,fp)!=NULL) { + if (parsing) { + if (equals(line,E)) { + parsing=0; + } else { + parseResource(r,line); + } + } else { + if (equals(line,B)) parsing=1; + } + } + fclose(fp); + return 1; + } else { + return 0; + } +} + +//generate file +char generateFile(char* vFile,tResource* r[]) { + //declare variables + char parsing=0; + char line[MAX_LINE_SIZE]; + char coms[MAX_LINE_SIZE]; + char B[]=BEGIN_TABLE; + char E[]=END_TABLE; + char none[]=""; + FILE* fp; + FILE* source; + + if ((fp=fopen("res.tmp","wt"))!=NULL) { + //insert headers + if ((source=fopen(vFile,"rt"))!=NULL) { + while ((parsing!=2)&&(fgets(line,MAX_LINE_SIZE,source)!=NULL)) { + if (parsing) { + if (equals(line,E)) { + parsing=2; + } + } else { + if (equals(line,B)) { + parsing=1; + } else { + fputs(line,fp); + } + } + } + } + + //insert main body file + fputs(B,fp); + fputs("\n",fp); + int id=0; + for (;id<65536;id++) { + if (r[id]!=NULL) { + if ((*(r[id])).desc==NULL) { + if ((*(r[id])).coms==NULL) { + sprintf(coms,none); + } else { + sprintf(coms," #",(*(r[id])).coms); + } + } else { + if ((*(r[id])).coms==NULL) { + sprintf(coms," %s",(*(r[id])).desc); + } else { + sprintf(coms," %s#%s",(*(r[id])).desc,(*(r[id])).coms); + } + } + sprintf(line,"%05d %05d %05d %s %02d%s\n", + id, + (*(r[id])).size, + (*(r[id])).offset, + (*(r[id])).file, + (*(r[id])).type, + coms); + fputs(line,fp); + } + } + fputs("\n",fp); + fputs(E,fp); + + //insert footers + if (source!=NULL) { + while ((parsing==2) && (fgets(line,MAX_LINE_SIZE,source)!=NULL)) { + fputs(line,fp); + } + fclose(source); + } + fclose(fp); + remove(vFile); + rename("res.tmp",vFile); + return 1; + } else { + return 0; + } +} + +//Resources extras + +void getFileName(char* vFileext,char* vDirExt,char type, unsigned short int id) { + char extMidi[] = "mid"; + char extWave[] = "wav"; + char extBmp[] = "bmp"; + char extLevel[] = "pet"; + char extExtra[] = "ext"; + char extRaw[] = "raw"; + char extPal[] = "pal"; + char* ext; + + switch (type) { + case 0: + ext=extRaw; + break; + case 1: + ext=extLevel; + break; + case 2: + ext=extBmp; + break; + case 4: + ext=extMidi; + break; + case 3: + ext=extWave; + break; + case 6: + ext=extPal; + break; + default: + ext=extExtra; + break; + } + + //set filename + sprintf(vFileext,"%s%cres%05d.%s",vDirExt,DIR_SEPARATOR,id,ext); +} + +void getUpperFolder(char* aux, char* vFiledat) { + int i=0; + while (getUpperToken(vFiledat,aux,DIR_SEPARATOR,&i,260)); + aux[12]=0; +} + + + + + +//File handling functions + + + + +int mLoadFileArray(char* vFile,unsigned char** array) { + //declare variables + FILE *fp; + int aux; + + //Open the file + if ((fp=fopen(vFile,"rb"))==NULL) { + return 0; + } else { + //get file size + fseek(fp,0,SEEK_END); + aux=ftell(fp); + if ( !aux || (aux>SIZE_OF_FILE) || ( ((*array=(char*)malloc(sizeof(char)*aux))==NULL) ) ) { + //if the file was null or bigger than the max size or couldn't allocate the file in memory + fclose(fp); + return 0; + } else { + //if the filewas succesfully open + fseek(fp,0,SEEK_SET); + aux=fread (*array,1,aux,fp); + fclose(fp); + return aux; + } + } +} + +char mSaveRaw(char* vFile,unsigned char* output, int size) { + FILE * pFile; + if ((pFile = fopen (vFile , "wb"))==NULL) { + return 0; + } + if (!size) { + return 0; + } + fwrite (output, 1, size, pFile); + fclose (pFile); + return 1; +} diff --git a/PR/parser.c b/PR/src/parser.c similarity index 99% rename from PR/parser.c rename to PR/src/parser.c index 76b6f49..1a2f683 100644 --- a/PR/parser.c +++ b/PR/src/parser.c @@ -6,6 +6,8 @@ #define PARSER_DEFINED +#include "parser.h" + //Letras a numeros char num(char n) { return ((0x2F<n)&&(n<0x3A))?(n-(0x30)):0; diff --git a/PR/pr.def b/PR/src/ports/winfiles/pr.def similarity index 100% rename from PR/pr.def rename to PR/src/ports/winfiles/pr.def diff --git a/PR/pr.dll b/PR/src/ports/winfiles/pr.dll similarity index 100% rename from PR/pr.dll rename to PR/src/ports/winfiles/pr.dll diff --git a/PR/pr.exe b/PR/src/ports/winfiles/pr.exe similarity index 100% rename from PR/pr.exe rename to PR/src/ports/winfiles/pr.exe diff --git a/PR/pr.exp b/PR/src/ports/winfiles/pr.exp similarity index 100% rename from PR/pr.exp rename to PR/src/ports/winfiles/pr.exp diff --git a/PR/pr.lib b/PR/src/ports/winfiles/pr.lib similarity index 100% rename from PR/pr.lib rename to PR/src/ports/winfiles/pr.lib diff --git a/PR/pr.obj b/PR/src/ports/winfiles/pr.obj similarity index 100% rename from PR/pr.obj rename to PR/src/ports/winfiles/pr.obj diff --git a/PR/resources.txt b/PR/src/resources.txt similarity index 100% rename from PR/resources.txt rename to PR/src/resources.txt diff --git a/PR/resources.xml b/PR/src/resources.xml similarity index 100% rename from PR/resources.xml rename to PR/src/resources.xml diff --git a/PR/vd.bat b/PR/vd.bat deleted file mode 100755 index f3dda4c..0000000 --- a/PR/vd.bat +++ /dev/null @@ -1,2 +0,0 @@ -@echo off -call extract vdungeon.dat \ No newline at end of file diff --git a/PR/vdr.bat b/PR/vdr.bat deleted file mode 100755 index 5ea614d..0000000 --- a/PR/vdr.bat +++ /dev/null @@ -1,3 +0,0 @@ -@echo off -call destroy -call extract vdungeon.dat \ No newline at end of file diff --git a/PR/vp.bat b/PR/vp.bat deleted file mode 100755 index 35c9003..0000000 --- a/PR/vp.bat +++ /dev/null @@ -1,2 +0,0 @@ -@echo off -call extract vpalace.dat \ No newline at end of file