In the previous chapters you learned how to convert animations, using Gamani GIF Movie Gear. By now you have the goblin's dcc files ready for use, with correct offsets and everything. Now comes the delicate process of putting your animation to work in the game.
This chapter will be somewhat heavier in information than the previous ones. Two new types of archives will be introduced, the files with .D2 and .COF extension. The modifications to be done in such files will require a HEX Editor software; in this tutorial we are going to use the XVI32 hex editor. We assume the reader understands hexadecimal numbers and has some knowledge on how to work with this software (there are tutorials covering this, like Sir_General's Code Editing Tutorial for example). By the end of this chapter, you should have successfuly replaced the Quill Rat with your new Goblin animations.
Roughly speaking, XVI32 is similar to an ordinary text editor; you can type in new bytes, overwrite bytes, select several bytes at once and copy/cut/paste them etc. Here are some tips that will help you make the necessary changes in the files we will discuss later:
There are two ways of typing bytes with XVI32, they are called Overwrite mode and Insert mode. When typing in overwrite mode, you are doing just that: overwriting already existing bytes in the file. This mode is useful and used when you want to replace bytes in a file. When typing in Insert mode, you are again doing just what is says: inserting new bytes in the file. You can insert new bytes anywhere in the file, not necessarily at the end; when you add bytes in the middle of the file, all subsequent bytes will be shifted down to give room to the new bytes. It all works like a txt file editor! To toggle between Insert/Overwrite mode, use the Insert key on the keyboard (NOTE that it is very important that you know in which mode you are typing at all times. Hex Editing wrong any Diablo 2 file will surely produce some nasty crashes. Always know what you're doing). You can check at the Status Bar at the bottom of the XVI32 screen whether you are in Overwrite or Insert mode.
To select a block of several bytes, you can use Shift+(arrow keys) for example, just like in a txt editor. Alternatively, you can mark a block like this: click on the first byte of the block you want to select, press CTRL+B; then, click on the last byte of the block you want to select, and press CTRL+B again; the block you specified will then be selected. Another very useful way of selecting bytes is like this: let's say you want to select a certain block with 40 bytes in your file. Click on the first byte of this block you want to select. Then, go to the Edit menu, and select the Block <n> chars... option. This will bring up a window where you can select the size of the block to be selected, in decimal or hexadecimal. In this example, you would select the decimal option, and put 40 in the block size to be selected. Click the OK button, the 40-byte block will be selected.
Copying a block to be pasted inside the file is done with CTRL+C (if you want to paste a block outside the file. like in notepad or something, use CTRL+H instead). Deleting a block is done with CTRL+D.
In order to accomplish the modifications in the files to be discussed later in a fast and efficient way, it is required a good amount of block selecting and copying/pasting or deleting, so pay attention not to make mistakes.
As mentioned already in Chapter 2, inside the folder of a monster token there is always a subfolder entitled COF. The COF folder contains files with a .cof extension; also mentioned in Chapter 2 is that these cof files tell the Diablo II graphics engine how to 'glue' all the pieces of a monster together during the game.
First thing to do is extract the Quill Rat's COF files. The quill rat is a monster from D2 Classic, that means you will find its animations and COF files inside d2data.mpq. The quill rat's token is SI, so you will find the COF files for the quill rat in the data\global\monsters\SI\COF folder. There is one COF file for each animation mode, and their filenames are coded in a very similar way than the .dcc filenames, you should have no problems identifying the structure in the COF filenames by now.
The following is a list of the Quill Rat's COF files:
Now it is time to open one of these files and see how they are structured. Open the XVI32 hex editor; then, open the file sia1hth.cof. This is what you will see:
sia1hth.cof is basically the following bytes:
01 10 08 14 01 00 13 00 BF FF FF FF 2D 00 00 00 D0 FF FF FF 14 00 00 00 00 01 00 00 01 01 01 00 00 68 74 68 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 |
This byte sequence is structured, and you must learn to recognize the structures upon seeing the cof file. For the purposes of framecount editing, here's how you will see this file after some practice:
01 10 08 14 01 00 13 00 BF FF FF FF 2D 00 00 00 D0 FF FF FF 14 00 00 00 00 01 00 00 01 01 01 00 00 68 74 68 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 |
An explanation of what each of these colored sections represent is in order:
The original quill rat attack1 animation has 128 frames (16 frames per direction, 8 directions). The attack1 mode of the quill rat uses only the torso layer, thus we have a blue section with a size of 16*8*1=128 bytes.
The goblin attack1 animation we are going to replace the quill rat with has 120 frames, that's 8 frames less than the original animation. We need to modify the COF file accordingly to avoid crashes. The modification is quite logical:
The modified COF with the changes mentioned above will look like this:
01 0F 08 14 01 00 13 00 BF FF FF FF 2D 00 00 00 D0 FF FF FF 14 00 00 00 00 01 00 00 01 01 01 00 00 68 74 68 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 |
You can save this file. Now, you have to modify the COF files for the other animation modes. To make the job faster, do a list of the framecounts (together with the number of frames per direction, in decimal and hexadecimal characters) of all the new animations you're going to use. In our Goblin conversion, the listing is as follows (notice the DD (corpse) token wasn't included, since it always contains 1 frame per direction and, as such, we don't have to edit it):
This is the original sia2hth.cof:
sia2hth.cof - ORIGINAL | 01 0D 08 14 01 F0 FD 7F B2 FF FF FF 3A 00 00 00 C5 FF FF FF 16 00 00 00 00 01 00 00 01 01 01 00 00 68 74 68 00 00 00 00 00 00 02 00 00 00 00 00 00 00 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 |
The new animation has 15 frames per direction, therefore we must have 0F in the red byte, an orange section with 15 bytes in size, and a blue section with 15*8*1 = 120 bytes in size; here's the modified sia2hth.cof for reference:
sia2hth.cof - MODIFIED | 01 0F 08 14 01 F0 FD 7F B2 FF FF FF 3A 00 00 00 C5 FF FF FF 16 00 00 00 00 01 00 00 01 01 01 00 00 68 74 68 00 00 00 00 00 00 02 00 00 00 00 00 00 00 00 00 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 |
You can save this file. Next, we will edit the COF for the death mode. Open sidthth.cof, this is what you'll see:
sidthth.cof - ORIGINAL | 02 0E 08 14 00 FC 12 00 D0 FF FF FF 30 00 00 00 DF FF FF FF 16 00 00 00 00 01 00 00 0F 01 01 00 05 68 74 68 00 01 01 01 00 05 68 74 68 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 |
This cof file is a bit different than what we saw so far. The blue section has a different pattern, composed of a repetitive sequence of the 0F 01 bytes. Each one of these two bytes refer to a different layer of this animation mode (notice the yellow byte, we have a 02 in there, indicating this animation mode uses 2 layers as expected).
The changes are processed in much the same way as before. The goblin death mode has 18 frames per direction, therefore we must have 12 in the red byte, an orange section with 18 bytes in size, and a blue section with 18*8*2 = 288 bytes in size. Remember to mantain the layer structure (the repetitive pattern of bytes 0F 01) when adding or removing bytes in the blue section. For example:
CORRECT | 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 |
WRONG | 0F 01 0F 01 0F 01 0F 01 0F 01 01 0F 01 0F 01 0F 01 0F 01 0F |
WRONG | 0F 01 0F 01 0F 01 0F 01 0F 0F 01 0F 01 0F 01 0F 01 0F 01 0F |
To be more precise, the blue section does not need to have a regular pattern of bytes. In the example above, you could have 0F 01 01 0F for example. As I said, the 0F byte refers to one layer of the animation, and the 01 byte refers to another layer. Since the animation has two layers, each set of 2 bytes in the blue section refers to one single frame in the animation. So, for every frame you can choose wether you put 0F 01 or 01 0F in there. The order of the bytes tells the game which layer of the animation must be drawn first in the game screen. First byte is drawn first, second byte goes right after, and so on if there are more layers. What you cannot have is the same layer bytes for a single frame (for example, in the example we are looking you could not have 01 01 or 0F 0F as the layer information for a single frame; that would be redundant and cause graphical glitches).
The modified file will look like this:
sidthth.cof - MODIFIED | 02 12 08 14 00 FC 12 00 D0 FF FF FF 30 00 00 00 DF FF FF FF 16 00 00 00 00 01 00 00 0F 01 01 00 05 68 74 68 00 01 01 01 00 05 68 74 68 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 0F 01 |
You can save this file. Next on the list is the GetHit mode; open sighhth.cof, this is what you will see:
sighhth.cof - ORIGINAL | 01 06 08 14 01 F0 FD 7F BF FF FF FF 2C 00 00 00 D6 FF FF FF 17 00 00 00 00 01 00 00 01 01 01 00 00 68 74 68 00 00 00 00 00 00 00 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 |
Checking the list we made before, we see the new gethit animation has 13 frames per direction. Therefore, we need to have 0D in the red byte, an orange section with 13 bytes in size, and a blue section with 13*8*1 = 104 bytes in size. After the changes, the file will look like this:
sighhth.cof - MODIFIED | 01 0D 08 14 01 F0 FD 7F BF FF FF FF 2C 00 00 00 D6 FF FF FF 17 00 00 00 00 01 00 00 01 01 01 00 00 68 74 68 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 |
Now, the Neutral mode; open sinuhth.cof, this is the original file you will see:
sinuhth.cof - ORIGINAL | 01 08 08 14 01 F0 FD 7F C4 FF FF FF 2C 00 00 00 DD FF FF FF 14 00 00 00 00 01 00 00 01 01 01 00 00 68 74 68 00 00 00 00 00 00 00 00 00 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 0101 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 |
The goblin's neutral mode animation has 12 frames per direction, as our listing indicates. By now you should have mastered the concept of COF editing already: 0C in the red byte, an orange section with a size of 12 bytes, and a blue section with a size of 12*8*1 = 96 bytes is what we need in this case. Here's the modified file:
sinuhth.cof - MODIFIED | 01 0C 08 14 01 F0 FD 7F C4 FF FF FF 2C 00 00 00 DD FF FF FF 14 00 00 00 00 01 00 00 01 01 01 00 00 68 74 68 00 00 00 00 00 00 00 00 00 00 00 00 00 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 0101 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 |
The Walk mode is the last in our list; open siwlhth.cof, this is the original file you will see:
siwlhth.cof - ORIGINAL | 01 09 08 14 01 F0 FD 7F C4 FF FF FF 2C 00 00 00 E0 FF FF FF 14 00 00 00 00 01 00 00 01 01 01 00 00 68 74 68 00 00 00 00 00 00 00 00 00 00 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 |
The new walk animation has 16 frames per direction, therefore the changes will consist of putting a 10 in the red byte, making an orange section with 16 bytes in size, and a blue section with size of 16*8*1 = 128 bytes. As usual, here follows the modified file for reference:
siwlhth.cof - MODIFIED | 01 10 08 14 01 F0 FD 7F C4 FF FF FF 2C 00 00 00 E0 FF FF FF 14 00 00 00 00 01 00 00 01 01 01 00 00 68 74 68 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 |
This finishes all the modifications that had to be made in the COF files. Your conversion is almost ready; before, we need to introduce a new file, and some modifications will have to be made in it as well. This is the subject of the next section; but, before we go there, a VERY important step that will make all your animation conversions work in your mod: download this file, and extract its contents to your mod's data\global folder. This step is VERY IMPORTANT!! If you don't do this, the editing you've done in the COF files will not work. Note: These files simply allow you to make ANY converted animation work in the game by editing the cof files and animdata.d2 only, nothing more.
The last file to be edited is Animdata.D2. This file contains information on all animations, but the only information we are interested in is in how to modify the framecount of the animation modes. This modification is a lot easier than editing the COF files, you'll only have to overwrite at most one byte for each animation mode of your token.
Animdata.d2 can be found inside d2exp.mpq, in the data\global folder (or, if you are modding Diablo 2 Classic, without the Expansion Set, you have to use the Animdata.d2 found inside d2data.mpq, in the data\global folder. Once it is extracted, open it with XVI32. The following screenshot shows what you should know about the structure of this file:
You will see the filenames of several COF files inscribed in this file; for example, the filename of the COF F3NUHTH.cof is marked in red in the screenshot above (note that the filename is listed in animdata.d2 in capital letters, and without the .cof extention). Two bytes after the filename, there is a byte that tells how many frames per direction (in hexadecimal) the animation mode corresponding to that COF file has. This byte is marked blue in the screenshot above.
The task now consists in finding where the cof files of the quill rat animation modes are listed in Animdata.d2, and change their framecounts to match the new animations that are going to be used in this token. Finding the cof filenames in here is easy, you just have to use the Find option. Go to the Search menu, and select the Find... option (or simply hit CTRL+F on the keyboard). This will bring up the Find window:
First, let's find where to change the framecount of the attack1 animation mode of the quill rat. The COF file related to this animation mode is sia1hth.cof; therefore, in the Text String field put SIA1HTH (all in CAPS and without the .cof extention, this is very important), see how it is done in the screenshot above. Then, press the Text->Hex button. Make sure all options marked in the screenshot are selected correctly (options - case sensitive, direction - down, scope from - begin), and then press the OK button. XVI32 will automatically bring you to the place where the entry you want is stored:
Notice the blue byte has 10 in it. That's the original framecount per direction for the attack1 animation mode of the quill rat token. The new attack1 animation going to be used has 15 frames per direction, therefore put 0F in the blue byte here (remember to check if XVI32 is in overwrite mode when you do this).
Easy, isn't it? Just repeat the process to all other animation modes of the quill rat, and you are done with all the animation work!
The final touches to make the Goblin behave properly in the game are not covered here, since they are not related to the animation stage of the conversion; basically you will need to edit the tbl files to change the name of the quill rat to Goblin, and do the proper changes in monstats.txt, to make it behave like a melee monster. You can find more information on this in the Advanced Monster Modding Tutorial, by FoxBat and Jbouley. You may also want to replace the quill rat sounds with other sounds more appropriate to the Goblin, using sounds.txt or directly replacing the wav files.
You can now proceed to Chapter 6 - Errors and Tips.