HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Various libraries for map parsing

08-08-2008, 11:13 AM#1
d07.RiV
I'm uploading libraries I made at some point that might be useful for getting information from map files and other WC3 archives. They are all for C++ but you can try converting them to whatever you use, if you need to.
Mostly they should be cross platform if you remove some stuff (don't know, never tried compiling it for anything other than windows). Also I haven't tried compiling with anything other than visual studio so it might have some specifics, but they shouldn't be hard to fix. filesys.cpp in rmpq library has functions for opening files, if you don't need to work with archives that are > 4GB you can change them to use the normal FILE* or something.

I have not documented anything, if it is unclear how to use it, ask here.

First of all, rmpq library for working with MPQ archives, I have already posted it but here is an updated version with some bugs fixed and added other compression methods (actually just took zezula's code as everyone else did). It is pretty fast, allows creating "file streams" that you can write data into/read data from and then flush it. Note that I'm not sure writing archives work, I think last time I tried it crashed, that was a long time ago. But reading works fine.
It is required by all other libraries. To use it, add the zlib.lib to your project (it is compiled for visual studio, you can compile the library for your own system. I took the sources from some other project instead of downloading them from zlib website so it might be different, and I uploaded what I compiled just in case).
Functions in rmpq.h are commented
Usage:
- MPQInit is called first, MPQCleanup is called last
- MPQARCHIVE mpq = MPQOpen ("filename", mode)
mode = MPQFILE_READ, MPQFILE_REWRITE, MPQFILE_MODIFY
- MPQCreateArchive is equivalent to MPQOpen (, MPQFILE_REWRITE) but provides more parameters.
- MPQClose (mpq)
- MPQFILE file = MPQOpenFile (mpq, "filename", mode - as in MPQOpen)
- MPQCloseFile (file)
- MPQFileRead, MPQFileWrite, MPQFileSeek, MPQFileTell etc should be self-explanatory
- MPQOpenFSys opens a file system file, so that you can pass it as a parameter to functions that are supposed to work with MPQ files
- MPQFlush - compacts files in the archive (since write operations just append the file at the end of the archive)
- MPQLOADER is an object that contains references to archives in some order and provides functions for loading a file from the last added archive, if not found it will look in the previous one etc until it finds the file - as WC3 does (except it doesnt use file system files). The prefix parameter for MPQCreateLoader is something like "Custom_V1" - it will first look in that folder. You should probably initialize it as
Code:
  MPQLOADER loader = MPQCreateLoader ("Custom_V1");
  MPQLoadArchive (loader, mprintf ("%s\\war3.mpq", wc3path));
  MPQLoadArchive (loader, mprintf ("%s\\war3x.mpq", wc3path));
  MPQLoadArchive (loader, mprintf ("%s\\war3xlocal.mpq", wc3path));
  MPQLoadArchive (loader, mprintf ("%s\\war3patch.mpq", wc3path));
  MPQAddArchive (loader, mpq);
  <do something>
  MPQReleaseLoader (mpq); // all archives loaded with MPQLoadArchive will be deleted automatically
(mprintf is just an in-place sprintf that uses an array of static strings)

Next, object data library. Reads guess what from a map and can dump it in external files (or your program can use the data in-place). It takes about 1 second to load all data and about 25 mb memory.
Create a GameData struct and use LoadGameData to load data from an MPQLOADER. Flags specify what and how it will load it. WC3_LOAD_<object> specifies which objects to load, WC3_LOAD_ALL is a mask for all object types. WC3_LOAD_MERGED will not use data[] variable of GameData but will instead use "merged" and store object data for all types in it. WC3_LOAD_NO_WEONLY will save some memory by not loading the huge WESTRINGS file for worldeditor-only strings (some doodads have names defined in this file). WC3LOAD_KEEP_METADATA will not delete the metaData[] objects after it finishes loading, and you can use them to display stuff.

Last, image library. It provides functions for loading a BLP file, a TGA file (they return a pointer to BLPImage structure defined in image.h) and a windows-only function that will determine the type of the image, load it and create 2 bitmap handles, one with alpha bits ignored and one with checkerboard background behind transparent pixels.
It includes a jpeg library, and as with zlib, jpeg.lib it is compiled for visual studio and you can recompile it if you use another compiler.

Hope these "tools" will be useful for someone.

E: I have some issues with uploading so for now its only the main sources, without optional zlib/jpeglib sources.
Attached Files
File type: 7zdatafile.7z (7.4 KB)
File type: 7zimage.7z (137.1 KB)
File type: 7zrmpq.7z (72.3 KB)
08-08-2008, 07:09 PM#2
midiway
can this create a .blp from a .jpeg?
08-11-2008, 09:01 AM#3
d07.RiV
No I don't have functions for that but this is exetremely easy, you can just add a specific data in the beginning of the file with any hex editor.