Page 1 of 1
Modifying the PIG files
Posted: Wed Aug 20, 2014 12:44 pm
by Xfing
Ok, so I thought that after the successful endeavor of reintroducing D1 sounds to the D2 files, I could as well try the same with textures. This might seem pointless, as textures are easy to replace when needed, however certain animated textures are very difficult to replace with the regular means at our disposal. Monitors and lava are a drag to replace and even after much work many monitors cannot be rendered faithfully due to conflicts in frame count. Simply squeezing the textures back into the PIG file would solve this problem once and for all. Can't drive it home with a hammer, do it with a wrecking ball. Hee hee.
What I expect needs to be done:
- Rename exported textures with names redundant to those from D2 so there's no conflict
- Import the file batch into the six PIG files. That's enough if a texture doesn't do anything special
- For textures that do special stuff, assign behavior and relationships with other textures using HAXMED32 (like which popping animation is played when a monitor's popped).
I would like some advice whether this is feasible and it is, how exactly to proceed. Jeff250, this goes out to you
If it can be done, the product would be six .PIG files containing all hitherto textures as well as all those that got axed in the transition from D1 to D2. Of course there would also be a drawback of these files being required for playing levels made using them, but let's not think about that right now
Re: Modifying the PIG files
Posted: Sat Aug 23, 2014 1:55 pm
by Jeff250
It can probably be done. It looks like there's at least a spec available this time:
http://www.descent2.com/ddn/specs/pig/
I'll see if I can hack something up one of these days.
Re: Modifying the PIG files
Posted: Sun Aug 24, 2014 2:36 pm
by Xfing
Jeff250 wrote:It can probably be done. It looks like there's at least a spec available this time:
http://www.descent2.com/ddn/specs/pig/
I'll see if I can hack something up one of these days.
Cool man, you're the best
Re: Modifying the PIG files
Posted: Tue Dec 16, 2014 7:39 pm
by Xfing
I just got back to this problem and I'm kinda stuck.
For starters, I've got a temporary solution for my problems with one texture. I've created a very extensive POG file that replaces most of those D2-exclusive monitors with D1-exclusive ones. The replacement is of course imprefect, as every texture in the PIG file has a set amount of frames, which does not always correspond to the number of frames of the old textures (which is why it would be best to simply reinsert them into the PIG and make the game recognize them correctly).
But as of right now: suppose I want to assign the spiderbot screen (misc067) which is the single leftover monitor texture from D1, to a different popped screen texture than it has currently. Currently it seems to be associated with either blown103 or blown06 (not sure right now, as they are replaced with pretty much the same texture in my custom POG). I would like the texture to associate with blown02 instead. As you probably know, the popping animation of this texture in unmodded Descent 2 is a complete mess - with both the animation itself and the resting frame not matching. In my current POG I've managed to replace the textures in such a way that the animation is fine, the only thing I would need to rearrange is the resting shattered frame (blown02 is the target piece).
I know it seems like quite a messy solution, but it's only temporary and more of an exercise than a fix. Any suggestions please?
Re: Modifying the PIG files
Posted: Tue Dec 16, 2014 11:26 pm
by Sirius
You would probably need to move the texture for misc067 to a different texture slot that happens to map to blown02 when destroyed, and has the same number of frames as misc067 - if such a texture slot exists. I couldn't be certain that it does.
If that's not an option, there might be something in the .PIG or .HAM (not POG, that doesn't support remapping things) that you could edit to get things working. If it's not there, though, it's probably in the source code.
Re: Modifying the PIG files
Posted: Wed Dec 17, 2014 4:36 am
by Xfing
Sirius wrote:You would probably need to move the texture for misc067 to a different texture slot that happens to map to blown02 when destroyed, and has the same number of frames as misc067 - if such a texture slot exists. I couldn't be certain that it does.
If that's not an option, there might be something in the .PIG or .HAM (not POG, that doesn't support remapping things) that you could edit to get things working. If it's not there, though, it's probably in the source code.
I think there is stuff for that in the HAM, after all I've managed to reassign door sounds for D1 to new ones, and it was done in the HAM. Not everything's always clear in that file, because the editor is a beta, though
Re: Modifying the PIG files
Posted: Wed Dec 17, 2014 12:03 pm
by Jeff250
So it looks like I had already coded this up but just never uploaded it.
Here's the example usage that I included in the file:
Code: Select all
def example_usage():
pig = read_from_path('groupa.pig')
pig.add_entries('mywall')
pig.add_entries('myanim', 16)
pig.write_to_path('new.pig')
This will open the groupa.pig file, create a blank, unanimated entry in the pig called "mywall", create a blank, animated entry called "myanim" with 16 frames, and then dump the resulting pig file to new.pig. It looks like you can then use DTX2 to fill in the textures with something meaningful. They appear in the "Other" category.
Re: Modifying the PIG files
Posted: Wed Dec 17, 2014 6:16 pm
by Xfing
Jeff250 wrote:So it looks like I had already coded this up but just never uploaded it.
Here's the example usage that I included in the file:
Code: Select all
def example_usage():
pig = read_from_path('groupa.pig')
pig.add_entries('mywall')
pig.add_entries('myanim', 16)
pig.write_to_path('new.pig')
This will open the groupa.pig file, create a blank, unanimated entry in the pig called "mywall", create a blank, animated entry called "myanim" with 16 frames, and then dump the resulting pig file to new.pig. It looks like you can then use DTX2 to fill in the textures with something meaningful. They appear in the "Other" category.
Holy crap, sounds easy enough! It will still take a minute to do because there are six PIG files to cover, but I'll enjoy doing it a great deal. Thanks again <3
Re: Modifying the PIG files
Posted: Thu Dec 18, 2014 12:14 pm
by Xfing
The attachment's gone, though! It disappeared before I could download it, where'd it go?
EDIT: Nvm, I managed to download it by opening it in another tab.
Re: Modifying the PIG files
Posted: Thu Dec 18, 2014 4:43 pm
by Xfing
Ok, suppose I've inserted all the D1 textures into the file, which is now called "groupaX.pig". Now how to check which textures are which in the HAM to establish their relationships (or even if there are enough vacant flags to even do that, like in the case of the sounds)? I know for example that the doors are "WCLIPS", and there are certain elements which could be used to reintroduce the axed green cobblestone door from D1 (old "door25"), such as for example Element #2, "Unnamed Wclips Element #2", which doesn't have an icon of its own and doesn't seem to be used by any door in-game. I think what I need to do is edit the entry, assign textures to it, (from the TEXTURES_1 or 2 tab) and assign proper sounds to it.
But how to find your way around the two Textures tabs? They're not really intelligible, both have 900 entries each, there's really no way to see which are vacant and which aren't.
EDIT: the frames of moving textures (such as monitors) can go into 1500s, and I can find correspondence between these numbers and the displayed properties of objects in the Textures_1 tab. How to know which object represents which texture? Or even if the new textures in the PIG were read and recognized like it was with the sounds?
Re: Modifying the PIG files
Posted: Fri Jan 02, 2015 8:03 am
by Xfing
I'm stuck badly - there's no way I can progress with this with the tools and knowledge at my disposal
Could someone enlighten me? Or even tell me it's impossible to pull off, I won't be wasting my time that way. For now I'll just make some POGs to kill the time
Re: Modifying the PIG files
Posted: Sat Jan 03, 2015 3:27 pm
by Sirius
Alright, I'll (hopefully remember to
) take a look at how D2 manages that hopefully later today... I figure it's either through the HAM or hard-coded, but I should have the resources to figure it out somehow.
Re: Modifying the PIG files
Posted: Sat Jan 03, 2015 8:23 pm
by Xfing
Sirius wrote:Alright, I'll (hopefully remember to
) take a look at how D2 manages that hopefully later today... I figure it's either through the HAM or hard-coded, but I should have the resources to figure it out somehow.
Thanks, man! Much appreciated. The primary issues I need sorted out:
- Are there vacant spots for textures in the HAM and do new textures occupy them when inserted as the case was with the sounds
- Which numbers found in Haxmed32 correspond to which textures. Knowing this would allow me to link up the new monitor textures with their blow, selfdestruct and blown counterparts.
This is not at all urgent though, I've already got POGs which do basically the same job. This whole thing is just me getting carried away, though I admit that having all the monitors together, working, would be neat.
Re: Modifying the PIG files
Posted: Sun Jan 04, 2015 4:43 am
by Sirius
Yeah, this is controlled by the HAM in D2. From
http://www.descent2.com/ddn/specs/ham/ -
Code: Select all
//Offset 0x000008 - 910 textures a 2+20 bytes
UINT32 n_textures;
BITMAP_INDEX bitmaps[n_textures];
TMAP_INFO tmap_info[n_textures];
This (particularly the first two lines) is exactly what controls it. n_textures governs how many textures a level has access to; I don't believe it's designed with any "free space", but you could make some by increasing that number and appending new texture data in the next two blocks.
So how it works is more or less like this:
The D2 level file format basically contains a data structure for each cube. Part of this data structure describes the texture indexes, alignment and lighting for each side of the cube.
When D2 has a level loaded in memory and wants to render the cube, it doesn't use that texture index directly but "maps" it to another number that describes the index of the texture in the actual PIG. It does this by looking up the "level texture index" in that "bitmaps" array I quoted above.
An example - say you have a cube with rock021 as its primary texture. This has an index of 0 that will be stored in the level file (little trivia detail: you can't use rock021 for a secondary texture because 0 has a special meaning for those - it means there
is no secondary texture). It reads entry 0 from "bitmaps", which contains the number 722 - i.e. it's texture #722 in groupa.pig (or any other D2 PIG). So D2 then knows which bitmap to display for that side.
That "tmap_info" array is also important; that contains information on various "properties" of the texture. From bm.h in the D2 source (I chopped out an ifdef used for Miner for clarity):
Code: Select all
//tmapinfo flags
#define TMI_VOLATILE 1 //this material blows up when hit
#define TMI_WATER 2 //this material is water
#define TMI_FORCE_FIELD 4 //this is force field - flares don't stick
#define TMI_GOAL_BLUE 8 //this is used to remap the blue goal
#define TMI_GOAL_RED 16 //this is used to remap the red goal
#define TMI_GOAL_HOARD 32 //this is used to remap the goals
typedef struct {
ubyte flags; //values defined above
ubyte pad[3]; //keep alignment
fix lighting; //how much light this casts
fix damage; //how much damage being against this does (for lava)
short eclip_num; //the eclip that changes this, or -1
short destroyed; //bitmap to show when destroyed, or -1
short slide_u,slide_v; //slide rates of texture, stored in 8:8 fix
} __pack__ tmap_info;
That stuff is what you would have to tweak to get it to point to the right eclip - also contained in the HAM - and I believe those govern the animation timings and frame counts.
Re: Modifying the PIG files
Posted: Sun Jan 04, 2015 7:58 am
by Xfing
Ok, and what program to do it with? Haxmed32 is severely limited, and the HAM itself seems to be encoded so editing it with a text editor is out of the question.
Well, actually I could do the eclip matching part in Haxmed but first I need a way to see which texture index points to which texture number and which texture number corresponds to which actual texture.
Re: Modifying the PIG files
Posted: Sun Jan 04, 2015 1:58 pm
by Sirius
Hmm... that probably is a problem. You are going to need to add new bitmap indexes, tmap_info and eclip items to the HAM. I don't know of any existing HAM/HXM editor that allows you to do that. It could be done - albeit it'd be slow and error-prone - with a hex editor, or a combination of a hex editor and HAXMEDIT32 (you would increment the item counts and block out the extra space with zeroes in the hex editor, then open the result in HAXMEDIT32 and set things up properly).
Really, though, this is one of those things there should have been an editor for but never was.
Re: Modifying the PIG files
Posted: Sun Jan 04, 2015 3:47 pm
by Xfing
Well, if that's the case then I'll probably give it a rest. The D1 sounds have been restored and once Pumo's done with his PIG we'll be able to have 99% D1-like levels in D2 anyway, so there isn't much point in trying to pull off something like this. Thanks anyway for the help - who knows, maybe one day I'll pick it up again too.