Hi, i'm reading a game format, it consists of two files one stores the file names, sizes and offsets of there location in the other file, the other holds the data. My problem is that i'm set at the offset where the data is but i dont know how to get it out into a seperate file. i think i need to use the file size in this but now sure. anyone got any ideas?
Extracting data from file?
Blitz3D Forums/Blitz3D Programming/Extracting data from file? Ok i'll try that, thanks.
Ok tryed it but it failed, not because of the code, it's because i've missed something along the line. I have an email with basic info that helped me, and also got some vb code of exporting the file but i dont understand it. would it be alright to post the code to see if anyone can understand it?
Thanks
Thanks
[codebox][/codebox]
I've got some c++ code here that is meant to read and write the data by i dont understand it as i dont program in c++. Can anyone understand this:
Thanks
// Open Raw File FILE* pFile = fopen("Oni.raw", "rb"); if(pFile == NULL) return; // Seek to TXMP Data offset fseek(pFile, TxmpOffset, SEEK_SET); // Allocate buffer char* pBuffer = (char*)malloc(TxmpSize); if(pBuffer == NULL) { fclose(pFile); return; } // Read Data fread(pBuffer, TxmpSize, 1, pFile); // Close source file fclose(pFile); // Open output file pFile = fopen("outfile.txmp", "wb") if(pFile == NULL) { free(pBuffer); return; } // Write data fwrite(pBuffer, TxmpSize, 1, pFile); // Close output file fclose(pFile); // Free buffer free(pBuffer);
Thanks
Update to post.
That code snippet seems to simply open a file, seek to a specific position, read a specific number of bytes from that position into a buffer(bank), and finally write the buffer contents out to a second file.
The file position to read from and the number of bytes to be read are specified via TxmpOffset and TxmpSize, respectively. As these variables aren't defined in the code, I can't tell you what they are. :)
The file position to read from and the number of bytes to be read are specified via TxmpOffset and TxmpSize, respectively. As these variables aren't defined in the code, I can't tell you what they are. :)
Ok, well i have the offset and the size of the txmp file already from some of my earlier coding for reading the dat file, Ok you said that it is store into a bank, does that mean that i have to do the same to get the correct data i want from the file i am reading?
Thanks
Thanks
If you want to do the same as the above code (i.e. read data in from one file and write it out to another) then it'd be best to use a bank. Luckily, blitz makes it easy to read/write data between files and banks: take a look at the ReadBytes and WriteBytes commands (note the plural of 'Bytes' - these commands are different from the Read/WriteByte commands).
Ok well i've done what i think is right but i'm still not getting equaly compared data between the two files, it just looks completely different from the actual file that it is meant to be (When opened in a text editor) Don't know if anyone can follow my coding but i put it below for you to see, it now uses banks and the read and writebytes commands:
I would have included in two files my exported file and the correctly exported file but thay are to big to even fit in a code box.
Thanks
onifile=OpenFile("level0_Final.dat") SeekFile(onifile,20) ;Read in the header LibRecs = ReadInt(onifile) Block1Recs = ReadInt(onifile) Block2Recs = ReadInt(onifile) DataStart = ReadInt(onifile) DataSize = ReadInt(onifile) NamesOffset = ReadInt(onifile) NamesSize = ReadInt(onifile) Unknown = ReadInt(onifile)*ReadInt(onifile)*ReadInt(onifile)*ReadInt(onifile) Dim librecsdata$(librecs,8) ;read librecs For Datasearch = 1 To Librecs librecsdata(datasearch,1) = Chr$(ReadByte(onifile)) + Chr$(ReadByte(onifile)) + Chr$(ReadByte(onifile)) + Chr$(ReadByte(onifile)) ;Lib type librecsdata(datasearch,2) = ReadInt(onifile) ;lib offset librecsdata(datasearch,3) = ReadInt(onifile) ;lib name offset librecsdata(datasearch,4) = ReadInt(onifile) ;lib size librecsdata(datasearch,5) = ReadShort(onifile) ;lib unknown1 librecsdata(datasearch,6) = ReadShort(onifile) ;lib unknown2 Next ;Block Recs SeekFile(onifile,NamesOffset) For Dat = 1 To LibRecs librecsdata(dat,7) = "" ;dat type librecsdata(dat,8) = "" ;dat name librecsdata(dat,7) = Chr$(ReadByte(onifile)) + Chr$(ReadByte(onifile)) + Chr$(ReadByte(onifile)) + Chr$(ReadByte(onifile)) ;dat type data Repeat NameByte = ReadByte(onifile) If (NameByte <> 0) librecsdata(dat,8) = librecsdata(dat,8) + Chr$(Namebyte) EndIf Until NameByte = 0 If (Eof(onifile)) Exit EndIf Next For t= 1 To librecs If librecsdata(t,7) = "TXMP" And librecsdata(t,1) = "PMXT" Then Print "" Print "type: " + librecsdata(t,1) Print "offset: " + librecsdata(t,2) Print "Name Offset: " + librecsdata(t,3) Print "Size: " + librecsdata(t,4) Print "Unknown 1: " + librecsdata(t,5) Print "Unknown 2: " + librecsdata(t,6) Print "Extension: ." + librecsdata(t,7) Print "File name: " + librecsdata(t,8) Print "librec: " + t EndIf Next ;get data from the raw file with reference from dat file onirawfile=OpenFile("level0_Final.raw") SeekFile(onirawfile, librecsdata(437,2));657672) databuffer = CreateBank(librecsdata(437,4)) ReadBytes databuffer,onirawfile,0,librecsdata(437,4) des = WriteFile(librecsdata(dat,8)+"."+librecsdata(dat,7)) WriteBytes databuffer,des,0,librecsdata(437,4)
I would have included in two files my exported file and the correctly exported file but thay are to big to even fit in a code box.
Thanks
Kain, I'll take a look at this tomorrow, when I get time. It's Friday night and I'm not 'in the right frame of mind'? ;)
Hmm, well, because I'm not familiar with the file formats you're working with, I'm not in a position help much. Sorry.
librecsdata(datasearch,1) = Chr$(ReadByte(onifile)) + Chr$(ReadByte(onifile)) + Chr$(ReadByte(onifile)) + Chr$(ReadByte(onifile)) ;Lib type
You can't be sure that each of these bytes will be read from the file in that order. If you do something like ..
a$ = chr$( readbyte (onfile))
b$ = chr$( readbyte( onfile ) )
etc ....
liberectdata( datasearch, 1 ) = a$+b$
It may work.
Stevie
big10p, would it help if i sent you the dat file as that is only about 2Mb, The file i am working with the from the game oni which it would probably be quite easy to get hold of a demo of it. The site that i got the specs of the dat file was http://mirex.mypage.sk in documents and Unmass archives descriptions. If you can help any further with this information it would be most appreciated.
Thanks
Thanks
Did you try implementing the changes Stevie G suggested?
Stevie G i applied your changes and still get the same result but from doing so and trying some things out i noticed that some of the data i have read in not correct to a program that can export these files, and it is to do with the typesfor example the sound files in the game should have the type DDNS but have some other one instead, i chaged some of the other code aswell to make it better but still not found out what causes the incorrect data.