Public Group

#### Archived

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

# PAK files

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

## 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 on other sites
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 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 on other sites
AGH!

i tried:
char enginetxt[138] //139bytes
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 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 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 on other sites

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 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 on other sites
Are you sure the string received is null terminated?

#define ENGINE_FILE_SIZE 138

char enginetxt[ENGINE_FILE_SIZE + 1];

// null terminate

• 36
• 12
• 10
• 10
• 9
• ### Forum Statistics

• Total Topics
631359
• Total Posts
2999545
×