1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
|
#define export extern "C" __declspec (dllexport)
export double _KFTIMRip(char File[], char Target[])
{
FILE *Source, *Source2, *Path;
int byteCheck1, byteCheck2, byteCheck3, byteCheck4, byteCheck5, byteCheck6; //init some ints
int fileStart, fileEnd, fileSize, fileCount, i, Byte; //init some more ints
//Makes sure we're not ripping thin air, send 0 back, for error handling if we are...
if(File == NULL)
{
return 0;
}
Source = fopen(File, "rb"); //Opens the file we want to seek...
//Start a while look, which goes through the bytes of the file...
while(!feof(Source))
{
byteCheck1 = readByte(Source);
byteCheck2 = readByte(Source);
byteCheck3 = readByte(Source);
byteCheck4 = readByte(Source);
byteCheck5 = readByte(Source);
byteCheck6 = readByte(Source);
//Provisional file checking...
if(byteCheck1 == byteCheck4 && byteCheck2 == byteCheck5 && byteCheck3 == byteCheck6)
{
if(byteCheck3*4 == byteCheck6 && byteCheck2*4 == byteCheck3)
{
if(byteCheck1 != 0 && byteCheck2 != 0 && byteCheck3 != 0 && byteCheck4 != 0 && byteCheck5 != 0 && byteCheck6 != 0) // Make sure they're not padding bytes...
{//And now we've got a KFTim!
if(fileStart == 0) //Check if the file start is equal to 0, if it is, set it to something else.
{
fileStart = ftell(Source)-64; //sets it to the start of the file, we know a KFTim header is 64 bytes long, so we minus that from the current pos.
}
if(fileEnd == 0) //Check if the file end is equal to 0, if it is, set it to something else.
{
fileEnd = (fileStart+64) + ((byteCheck5*4)*(byteCheck6)); //Sets it to: current position + header, + imagewidth*imageheight.
}
fileSize = (fileEnd - fileStart); //Gets the files size
fileCount++; //add one to the file counter
fseek(Source,(size_t) fileStart, SEEK_SET); //Set the file position
//Full speed ahead!
Source2 = fopen(Target, "wb"); //Opens the file we're writing.
while(i < fileEnd) //loops, until i is = or > fileEnd (end of file we want to rip)
{
Byte = readByte(Source); //reads a byte
writeByte(Source2 ,Byte); //writes the byte we just read to the new file.
i++; //adds 1 to i,
}
fclose(Source2); //Closes the file we were writing too.
fileStart = 0; //Sets the file start back to 0
fileEnd = 0; //Sets the fileEnd back to 0
}
}
}
}
fclose(Source); //Closes the file we were checking
return (double) fileCount; //Returns the amount of files it found.
}
|