Sign in to follow this  
Followers 0

Extracting Lumps

Hi Csabo, I originally sent this as a pm, but I don't think you've received it...

Anyhow, I am creating a script editor for Legacy in Delphi - which is no problem, however I am hitting a snag when it comes to extracting the script from any map in a wad (well, extracting anything for that matter).

I am not exactly sure where to start.

I assume I should load a wad with TMemoryStream and seek to the fs lump (I've only ever worked with text files or other peoples components to read different formats), are you able to explain the process I should go through to get data I need?

Cheers,

Planky

Share this post


Link to post

I wouldn't suggest using TMemoryStream (you can guess what happens when you open a wad file with it, unless you have a reasonable amount of memory to load a wad file into)

I suggest using TFileStream instead.

Also, you may want to check out this wrapper for wad files I wrote a while back: http://russell.slipgate.org/files/waded.zip <- its incomplete in areas and I suggest making backups of your wads before using it.

Share this post


Link to post

Yes, I attempted to load a 10 megabyte wad file with it and it proceeded to lock the application for a good five minutes :D

Ok, so I use TFileStream. But how to I locate the area I need?

Share this post


Link to post

Well now that you pointed out that I have a PM I got it. (I'd like to note quietly that I find the current PM system on DoomWorld somewhat lame. The PM's are not displayed prominently enough.)

This is how XWE handles the text lumps. We need to know the size and position of the lump.

- The file is opened and we seek to the lump's position
- We start a loop that runs 'lump-length' times
- Read one byte. If it's a 10 or 13, the current line is added to the textbox. Otherwise the character is added to the current line.

That's pretty much it. The drawback ofcourse is that the textbox may not be able to handle all the text, however, XWE supports the CodeMax 2.0 control. If the user has that, a CodeMax textbox is used, which can pretty much handle unlimited data and has all the syntax highlighting features etc.

Share this post


Link to post

In the user options section of your user control panel, you can tell the forum software to send you an e-mail when you get a new private message (may not work), or pop up a message box if you have a new private message (won't work without JavaScript).

Share this post


Link to post
Csabo said:

Well now that you pointed out that I have a PM I got it. (I'd like to note quietly that I find the current PM system on DoomWorld somewhat lame. The PM's are not displayed prominently enough.)


I had a feeling that was the case, so that s why I created this topic :)

Two questions:

1, What is the position of said lump (or rather how do I find out)
2, How do I find out the size (using sizeof?).

I am new to using filestreams, so forgive me if my questions are n00bish.

Cheers.

Share this post


Link to post

OK, I just hacked in a new feature to the forum software. If you have any unread PMs, it displays a little message in the upper right hand corner of the main forum page, under "View New Posts".

Share this post


Link to post

Planky, the WAD format is pretty simple. On position 8 you have a 32 bit value that points you to the "lump directory" within the file. The lump directory has entries like this:

32-bit int: lump position
32-bit int: lump size
8 byte char: lump name

That's it, hope it helps.

BloodShedder, that's good work. However, I only have the XWE forum bookmarked. I'm happy when I can find the time to pop in and read the posts... So it would be nice to have it displayed all the time (or at least on every forum). Or this could be an option.

Share this post


Link to post

Are you able to post an example?

Whenever I attempt to get the value from the position, it just returns 0.

Share this post


Link to post

Just give up Planky, thou shalt never prevail!

Share this post


Link to post

Not only shall I prevail, I shall cast your program of WOE into a pit of fire!

*ahem*

Share this post


Link to post

Just debug your code, you should see if all the values you are reading are correct. Anyway, something like this should work:

AssignFile ( f, 'filename.wad' );
Reset ( f, 1 );
Seek ( f, 8 );
BlockRead ( f, intPosition, 4 );
Seek ( f, intPosition + intEntry * 16 );
BlockRead ( f, intPosition, 4 );
BlockRead ( f, intLength, 4 );

You should have the position and length of entry number 'iEntry' (0 based) in the respective variables. 16 is the length of the directory entry, as I mentioned it my previous post.

Of course you'd want to verify that the file is infact a WAD file (has IWAD or PWAD signature), and that the value on pos 8 is within the file, etc.

Share this post


Link to post

I couldn't get blockread/write to work with data 2mb+ in size, do you have some sort of trick for that Csabo?

Share this post


Link to post

I don't think I ever tried to BlockRead that much in one shot, but you could obviously read in 1MB chunks in sequence for example.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0