🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

PAK files

Started by
10 comments, last by Bezzant 22 years, 7 months ago
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
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.
"...."
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 <fstream.h>#include <stdio.h>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
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
You are close with your fread. However your fread should look something like this

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



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
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.
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
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.
"...."
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;









This topic is closed to new replies.

Advertisement