WarDraft 
Version Beta 0.99

by Alexander Cech

email: e8900070@student.tuwien.ac.at
WWW: http://stud1.tuwien.ac.at/~e8900070/

Suggestions and bug-reports are welcome !

Disclaimer: WarDraft is freeware, so you may do whatever you want with it.
The author assumes no liability for damages, direct or consequential, which may result from the use of WarDraft.

What's new in this version
(for previous versions see Appendix E)

PUD-Viewer
Completely rewritten fast compression routine
Supports new graphic types: Cursors, Symbols
Datafiles can be passed via commandline, so associating .war files with WarDraft is now possible

Instructions

(Preliminary "Online-Help"; the final version will include a Windows-Help file)

About WarDraft and WAR archives
WarDraft is an editor for the data archives used in Warcraft II. These are found in the subdirectory "DATA" of Warcraft's installation directory (usually: C\WAR2\DATA\) or in the CD's "DATA" directory and have an ".WAR" extension (exception: SFXDAT.SUD, the sound archive, and MUDDAT.CUD). They include the builtin levels, pictures, sound, text and much more.

	This File		includes
	MAINDAT.WAR		levels,some pictures, fonts, unit/building-,cursor-,map-graphics and some (yet) unknown stuff
	REZDAT.WAR		mostly pictures
	STRDAT.WAR		all kinds of text appearing in the game
	SFXDAT.SUD		sound effects
	SNDDAT.WAR		spoken mission briefings
	MUDDAT.CUD		animated cutscenes

If you are interested in the WAR-format see Appendix A.

WarDraft is NOT a Level- or Map-Editor !
For constructing your own levels use the Editor included with Warcraft II.
I also recommend Daniel Lembergs War2xEd - a MUST for all PUD-creators (http://www.bayserve.net/~lemberg/)

Knowledge bases
WarDraft does its best to identify each entry in the archives, but it can only give a general description (e.g. it can identify a PUD (a level), but it cannot tell what number it is), and it's sometimes (very rarely) guesses wrong, especially image entries (this is not a bug). That's where Knowledge Bases come in. These are simple text files, similarily to Windows .INI files, containing all the information I could find out about the archives. Beside a short description they also contain the palette-numbers for stored images (Image files are stored without palette information, so you usually have to either view them in grayscale or search for the corresponding palette entry).
Knowledge Bases basically identify the current archive by its filename. If you often work with a renamed file (say MAIN.WAR instead of MAINDAT.WAR) you can now choose the respective entry in the Knowledge Base manually. See File/Select knowledge base entry.
Warcraft II V1.2 users (those of you who don't have the Expansion CD):
The included Knowledge Base "WAR131.KNW" describes the archives of Version 1.31 (i.e. the expansion-updated ones).
The first time you use WarDraft you have to load "WAR12.KNW" (File/(Re)load knowledge base)

How to use WarDraft
First, use the File/Open archive command to open an existing archive. The main part of the editor window is filled with information about the diferent entries in the archive. To do something with an entry, you have to select it in this list first. Now most of the entries in the Edit menu (and the corresponding toolbar buttons) become active.

Information about the entries
For each entry in the archive there is a lot of information displayed. If some of it is not be interesting to you, simply resize the corresponding column until it can no longer be seen. By clicking on the column headers you can switch between hex and decimal display.
Number:	The file number of the entry (it's position in the archive)
Offset:		Where in the archive the entry-header starts.
Length:		The space in the archive used by the entry (including it's header)
Orig.Length:	The real size of the entry (uncompressed, without header)
Flags:		Either CMP for "compressed" or blank
Description:	What WarDraft thinks this entry is (or info from the Knowledge Base)

Command overview

General:
By double-clicking an entry you invoke the default command: images will be shown, text-tables listed, audio files and animations played. Everything else is shown as hexdump.

File/Open
Reads information from an existing archive and displays it in the main window.

File/(Re)load knowledge base
Loads a selectable Knowledge Base. WarDraft remembers the filename of the Knowledge Base you load and uses it also when autoloading.

File/Select knowledge base entry
This is useful if you work with a copy of a war archive and there is no matching entry in the Knowledge Base. This submenu list all entries currently available. Just select one to use it.
Example: you are working with a copy of maindat.war, called maincopy.war. Now, since there is no entry in the Knowledge Base for a file called maincopy.war, you won't get any additional information. Now select maindat.war from the menu File/Select knowledge base entry and WarDraft will display all info it knows about maindat.war.

File/Exit
guess...

Edit/Extract file
Saves the selected entry as a stand-alone file (that's how you can extract PUDS and edit them with the level editor !)
If the entry is something that could be saved in different formats (like pictures, palettes, midi files) you can choose the format.
If the entry is compressed you also have the option to save it compressed or uncompressed.

Edit/Import file
This allows you to insert self-created or modified files into the archive (PUDs,images,sound,text....). You may optionally compress your file before inserting it into the archive - however I don't know if Warcraft II allows compression of any file. So it's best to use compression only if the entry you replace was also compressed.
A word of warning: always keep the entry-numbering as it was in the original archive; if you want to replace the title-screen for example (entry #299 in MAINDAT.WAR) make sure you REPLACE entry #299 with your image data. Although WarDraft allows you to ADD additional entries to the archive, these won't work with Warcraft II anymore. Only expert users should use the insert before or insert after commands. The same applies to the Edit/Delete file command.

Edit/Delete file
Deletes the selected file from the archive. Only for users who know what they do ! (see warning above)

Edit/Show as image data
Tries to view the selected entry as image data. The images are stored without palette information, so unless you have loaded a Knowledge Base (and it knows the corresponding palette-entry), you are given the option to either select a palette-entry manually or use a grayscale palette.
[See Appendix C - Known Bugs]

Edit/Show as hex dump
This displays a hex dump of the selected file. If it is compressed you may view it compressed or uncompressed.
[See Appendix C - Known Bugs]

Edit/Play WAV file
Plays the selected entry as a RIFF WAVE audio file. (Have a look at SFXDAT.SUD !)

Edit/Play MIDI file
Plays the selected entry as a MIDI sound file. (Many MIDIs are in MAINDAT.WAR !).
You can instantly resume your work while the sound plays in the background. Use the Play/Pause/Stop buttons at the upper right to control the playing.

Edit/Show as string table
Displays Text-entries, as found in STRDAT.WAR.

Edit/Play Smacker animation
Plays Smacker animation-entries. For this to work you need a smacker-compatible player (like SmackPlay from RAD-Software), and you need to tell WarDraft where to find it with Options/Utility paths.

Edit/Show PUD map
Displays the selected PUD (level) entry. For this to work you have to specify a path to a working copy of maindat.war in Options/Utility Paths.

Edit/Show graphics
Displays Units, Icons, Buildings, Missiles and similar stuff.

Options/Decompress automatically
If checked WarDraft doesn't ask you if you want to save or view entries in their compressed or decompressed form - if they are compressed they will automatically be decompressed before saving or viewing.

Options/Autoload knowledge base
If checked, every time you open an archive the corresponding Knowledge Base is loaded too.

Options/Ask for palette always
WarDraft usually doesnt asks for palette information only when viewing images which have an entry in the Knowledge Base and the corresponding palette is known too. By checking this option you will always be asked for palette information.

Options/Utility paths
If you use external utilities with WarDraft (like the SmackPlay animation player by RAD Software), WarDraft needs to know where to find these.
Also, if you want to view PUD entries, you have to specify a path for a working copy of maindat.war. (it can be changed, in fact you can also specify the same maindat.war you are currently working with, as long as it works fine in WarCraft II)

Tools/Image converter
If you want to replace the images in the archives, do it like this:
•	Save your image as a 256 color BMP file (uncompressed, or RGB-encoded like some paint programs call it ! NOT RLE-encoded !).
•	Select Tools/Image converter, Convert BMP to Image Data and save the resulting file.
•	If your picture uses another color palette than the original one, select Convert BMP to Color Palette and save it too.
•	Now just import the saved image data and replace the original picture in the archive.
•	If you use your own palette, import the saved palette over the original one.
Be careful when replacing color palettes; in some cases Warcraft uses the same palette entry for multiple images, so the other images will
look strange if you don't replace them too.

Appendix A - WAR file format

Here is a short description in Pseude-EBNF; all values are hex bytes unless specified otherwise:

<WAR-File>	=	<WAR-Header> (8 bytes)
			<Offset-Table>
			<Entries>

<WAR-Header>	=	19 00 00 00
			Number of Entries (WORD)
			Unknown (WORD)

<Offset-Table>	=	Offset (LONG)
			........		(Number of Entries Offsets)

<Entry>		=	<Standard-Entry> | <Pseudo-Entry>

<Pseudo-Entry>	=	anything which is shorter than 4 bytes
			(calculated from the offsets)

<Standard-Entry>=	<Entry-Header>
			Entry-Data	(number of databytes can be calculated from offsets)

<Entry-Header>	=	Orig.Length and Flags (LONG)
			(the hi-order-byte is Flags: 20 = compressed, 00 = uncompressed)
			(the3 lower bytes are the uncompressed length [without header])

Appendix B - Knowledge Base format

The knowledge base (default: WAR131.KNW) is a textfile, divided in sections like Windows INI-files; each section represents a different archive. 
The very first line in the file has to be "KNWB".
The beginning of a section is a filename enclosed in square brackets, e.g. "[MAINDAT.WAR]" (only the filename, no path information !).
After the section header there are a number of entries, each in the format:
	<Entry-Number>=<Type>,[Palette-Number,]<Description>
or	<Entry-Range>=<Type>,[Palette-Number,]<Description>

Entry-Number is the number of the entry in the archive (as in WarDrafts Number-column).
Entry-Range are two <Entry-Number>s, separated by a "-"
Type is a 3-character description of the entry-format. Currently the following types are supported:
	BMP	BMP (Windows-BitMap) picture
	CMT	to enter descriptions for unknown formats
	IMG	Image data file
	PAL	Color palette file
	PUD	PUD (level) file
	STR	String-Table (Text)
	WAV	RIFF WAVE Audio file
	SMK	Smacker Animation file
	XMI	XMI Midi music
	GFX	Graphics stored in the same format as units, icons, etc.
	CRS	Cursors (mouse pointers)
	GFU	Uncompressed graphics (like the symbols for magic and gold,wood,oil,etc.)

Palette-Number is used for Image (IMG), Graphics (GFX), Cursor (CRS) and Uncompressed Graphics (GFU)  files only (not optional ! If the palette number is not known use -1)
Description is a short description of the entry
Lines starting with ";" or "#" are comments, blank lines are ignored.
Multiple entries for the same number are allowed, the latest found are used.
Some examples:
	[MAINDAT.WAR]
	192=PUD,PUD Level  1  (Humans)
	299=IMG,300,Image: Title screen
	300=PAL,Palette: for 299
	244-251=PUD,PUD ???

Appendix C - Known Bugs

•	Sometimes crashes in a 256-color environment when viewing pictures (may also be a problem with my graphic card).
•	Viewing an entry as hexdump doesn't work vor very big entries; also preparing the dump is too slow .
•	On some configurations Smacker-Anims and audio files don't play (or only once) if WarDraft is installed in a directory with a long filename (> 8 characters)

Appendix D - To do

•	Editable string-tables
•	Font viewer/extractor
•	Rewrite hexdump routine
•	"real" Online-Help
•	multiple imports at the same time (shouldn't be slower than a single import)
•	Online menu to retrieve the latest knowledge bases via internet
•	Speed up the preparation of graphics for the PUD-Viewer
•	Avoid flickering when scrolling the map in the PUD-Viewer
•	Add more info to the PUD-Viewer (amount of gold in mines, etc.), and a minimap

Appendix E - News of previous versions

V0.96

Can view the unit-, building- and icon graphics.
Vastly enhanced Knowledge Bases.

V0.95

Can play XMI midi files (parallel to working with the archive !)
Export options let you choose standard formats for exports
Knowledge base entries selectable
Image converter to add your own pics to the archive
Some bugs fixed

V0.9

Faster compression algorithm (written by Daniel Lemberg)
Can play animation entries (needs SmackPlay)
Removed some bugs in reading old (V1.2) data archives
New Knowledge Base for V1.2
Knowledge Base for V1.31 updated