• Advertisement

Archived

This topic is now archived and is closed to further replies.

PAK files

This topic is 5943 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

so, i went to wotsit, got the file spec for PAK files, wrote a quick app to display the: (header struct)sig, dir offset, dir length. (directory struct) file name, file position amd file length all in a console app now, the rest of the doc goes like this: (copy and pasted, errors are not mine) File at each position (? bytes, char) file data Description - The signature must be present in all PAKs; it's the way Quake knows its a real PAK file. The directory offset is where the directory listing starts, and the lenght is its lenght. In the actuall directory listing, the three options, 56 bytes of a name, the files position and lenght, are repeating until the running total of the length (increment by 64) is reached. If the directory lenght mod 64 is not a even number, you know their is something wrong. And directories are just handled by a making the name something like "/foobar/yeahs.txt". Short and simple. well, i created a pak file, with one txt file inside it (i used a pak file creating tool) anyhow, i know im doing it right (well guess so) because my screen read out was: sig: PACK dir offset:12 dir length: 64 filename: engine.txt file position: 76 file length: 139 now could anyone explain to me how i can load "engine.txt" and display it in my console window? as that discription doesnt really help, and if it does, could you please explain it so its understandable? many thanks edit: damn typo Edited by - Bezzant on November 12, 2001 4:23:33 PM

Share this post

Share on other sites
Advertisement
In order to get the contents of the file, you can simply just fseek to the file position, then read in as many bytes as the the file length is, in this case, you would be reading in 139 bytes.

Share this post

Share on other sites
quote:
Original post by Lunatic Raven
In order to get the contents of the file, you can simply just fseek to the file position, then read in as many bytes as the the file length is, in this case, you would be reading in 139 bytes.

thanks, however (im not familier with fseek, fopen, fread) well i am now i guess.... but i have another question....

my code:

  /*Header(4 bytes) signature = 'PACK' (4 bytes, int) directory offeset(4 bytes, int) directory lenghtDirectory(56 bytes, char) file name(4 bytes, int) file position(4 bytes, int) file lenght*/#include #include struct Header{ char signature[3]; int offset; int length;}H;struct Directory{ char filename[56]; int position; int length; char engine[138];}D;main(){//blah blah blah (load and print code)fseek(File,76,0);//seek 76bytes incout<< D.engine << endl << endl; return(0);}

how would i read from the file starting at the place i just fseek'ed to? the way i have done it doesnt need me to fseek at all, it just reads another 139 bytes (to fill the char engine[138]).... so im just reading engine.txt as part of the header, am i not?

Edited by - Bezzant on November 12, 2001 5:08:49 PM

Share this post

Share on other sites
AGH!

i tried:
char enginetxt[138] //139bytes
fread(&enginetxt,sizeof(enginetxt),1,File);
cout << enginetxt << endl;

well that works, sorta... it puts the engine.txt file into char engine.txt, whoever, it also puts in some funky ascii characters, so there must be an error somewhere.... any ideas?

Edited by - Bezzant on November 12, 2001 6:37:24 PM

Share this post

Share on other sites
You are close with your fread. However your fread should look something like this

fread(enginetxt, sizeof(char), 138, File);

Share this post

Share on other sites
AP, that works, it works the same as what i had though, still getting funky ascii characters at the end of my file....

just tested something by extracting the contents of engine.txt (file inside the pak) to a new file, it seems that 4bytes are being added to the end of the file (hence the funk ascii characters)

ok, i got it extracting the file perfect, however, after i put the contents of the txt file inside the PAK into a char (for writing to a file its ok) but when i print that char on the screen it adds extra characters, any idea what it could be?

Edited by - Bezzant on November 12, 2001 6:54:28 PM

Edited by - Bezzant on November 12, 2001 7:27:46 PM

Share this post

Share on other sites
What are you making the txt file in? Could be formating characters in wordpad, word,etc. Try making a normal text file using notepad or edit under dos if your not.

Share this post

Share on other sites
i was using notepad

anyhow, i got it writing the files good, just doesnt display them right in the console window. odd. oh well.... i'll play around with it to see what i can do.

Edited by - Bezzant on November 12, 2001 8:09:24 PM

Share this post

Share on other sites
It seems to be if the crazy ASCII stuff is being added to the end, your sting may be too bigger than what you are loading in, and it is just showing what is already stored in there. You may also be reading in past the length of the text in the text file and by doing that you are accessing memory allocated for something else.

Share this post

Share on other sites
Are you sure the string received is null terminated?

fread returns the number of bytes read so try this:

#define ENGINE_FILE_SIZE 138

int bytes_read;
char enginetxt[ENGINE_FILE_SIZE + 1];

// read
bytes_read = fread(enginetxt, sizeof(char), ENGINE_FILE_SIZE, File);

// null terminate
enginetxt[bytes_read] = 0;

Share this post

Share on other sites
quote:
Original post by Lunatic Raven
It seems to be if the crazy ASCII stuff is being added to the end, your sting may be too bigger than what you are loading in, and it is just showing what is already stored in there. You may also be reading in past the length of the text in the text file and by doing that you are accessing memory allocated for something else.

thats what i thought, that the char array was too big to hold the string. i tested that by making it smaller, however that only cut the last few letters of the file off, yet the extra ascii characters remained there

Share this post

Share on other sites
quote:
Original post by Anonymous Poster
Are you sure the string received is null terminated?

fread returns the number of bytes read so try this:

#define ENGINE_FILE_SIZE 138

int bytes_read;
char enginetxt[ENGINE_FILE_SIZE + 1];

// read
bytes_read = fread(enginetxt, sizeof(char), ENGINE_FILE_SIZE, File);

// null terminate
enginetxt[bytes_read] = 0;

it wasnt, but i null terminated it, had it show how many bytes it wrote, it was 36, which is corect (i started over with a new PAK file that had a different txt file in)

its weird, it prints the contents out then this: "H«B" is added.... its not as bad anymore, when i started there was about 8 characters, but null terminating it, changing the size of the char array hasnt made a difference either. strange

Share this post

Share on other sites

• Advertisement
• Advertisement
• Popular Tags

• Advertisement
• Popular Now

• 9
• 10
• 12
• 10
• 10
• Advertisement