Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <windows.h>
- #include <direct.h>
- #include "vars.h"
- #include "complib.h"
- char* AssignExtension(char *name, int n0, int n1, int n2, int n3);
- int main(int argc, char *argv[])
- {
- FILE *bin, *ext, *exe, *tbl;
- int compression=0;
- char *finalname,thei[8],name[16],comptoe[250];
- unsigned char est[4];
- unsigned long int null,x,numpoint, pointer, fpoints[18000],i,rpoints[18000],c,temp,padding[18000],dim[18000],n0=0,n1=0,n2=0,n3=0;
- unsigned int comprbyte;
- int err,declen,complen;
- printf("Shitty Dat.bin/Mov.bin extractor for Tales of Destiny: Director's cut\nby StorMyu and Vash v0.1\n");
- bin=fopen(argv[1],"r+b");
- exe=fopen("DAT.TBL","r+b");
- if (!(exe))
- {
- printf("Can't find or open DAT.TBL.");
- return(0);
- }
- if ((strcmp(argv[1],"DAT.BIN") == 0))
- {
- numpoint=16314;
- _mkdir("DAT");
- _chdir("DAT");
- _mkdir("MGLK");
- _mkdir("TIM2");
- _mkdir("ELF");
- _mkdir("iSE2");
- _mkdir("DUMMY");
- _mkdir("ARCH");
- _mkdir("iTPK");
- _mkdir("ARCH2S");
- }
- fseek(exe,0,SEEK_SET);
- for (i=0;i<numpoint;i++) // Get each pointer in fpoints
- {
- fread(&fpoints[i],4,1,exe);
- fseek(exe,4,SEEK_CUR); //Skip the unknown data
- }
- for (i=0;i<numpoint-1;i++)
- {
- temp=fpoints[i]; //Storing the actual pointer to "temp"
- for(c=0;c<0x40;c++)
- {
- if (((temp%64) == 0) || (temp == 0) ) // If / by 0x40 OR first file then
- {
- rpoints[i]=temp; // Then Temp is the good pointer so we store it in rpoints
- c=0x41; // Force cycle to end.
- }else{
- temp--; // substract 1 till Euclidian division is correct
- }
- }
- padding[i]=fpoints[i]-rpoints[i]; // get real adress
- }
- rpoints[numpoint-1]=fpoints[numpoint-1]; // for further purpose
- for (i=0;i<numpoint-1;i++)
- {
- dim[i]=rpoints[i+1]-rpoints[i]-padding[i]; // Get the Size of the file.
- sprintf(name,"%d%d%d%d.dat\0",n0,n1,n2,n3);
- // Extraction to File
- ext=fopen(name,"w+b");
- fseek(bin,rpoints[i],SEEK_SET);
- printf("%s \n",name);
- //test compressione
- compression=0;
- comprbyte=fgetc(bin);
- if (comprbyte == 0x01 || comprbyte == 0x02 || comprbyte == 0x03)
- {
- fread(&complen,4,1,bin);
- if (complen==dim[i]-9)
- {
- printf("...compression type %X found.\n",comprbyte);
- compression=1;
- fread(&declen,4,1,bin);
- dec=(BYTE *)malloc(declen);
- }else{
- printf("\n");
- fseek(bin,rpoints[i],SEEK_SET);
- complen=dim[i];
- }
- }else{
- printf("\n");
- fseek(bin,rpoints[i],SEEK_SET);
- complen=dim[i];
- }
- //fine test compressione
- comp=(BYTE *)malloc(complen);
- fread(comp,complen,1,bin);
- //se รจ compresso
- if (compression == 1)
- {
- if (comprbyte == 0x01)
- {
- x=1;
- }
- if (comprbyte == 0x02)
- {
- x=2;
- }
- if (comprbyte == 0x03)
- {
- x=3;
- }
- err=Decode(x, comp, complen, dec, &declen);
- if (err == 0)
- {
- fwrite(dec,declen,1,ext);
- free(dec);
- } else {
- fseek(bin,rpoints[i],SEEK_SET);
- free(comp);
- comp=(BYTE *)malloc(dim[i]);
- fread(comp,dim[i],1,bin);
- fwrite(comp,dim[i],1,ext);
- free(comp);
- }
- }else{
- fwrite(comp,complen,1,ext);
- free(comp);
- }
- fclose(ext);
- finalname=AssignExtension(name,n0,n1,n2,n3);
- // Increase the size of the variable number.
- if (n3==9)
- {
- n3=0;
- n2=n2+1;
- }else{
- n3=n3+1;
- }
- if (n2==10)
- {
- n2=0;
- n1=n1+1;
- }
- if (n1==10)
- {
- n1=0;
- n0=n0+1;
- }
- }
- return(1);
- }
- char* AssignExtension( char *name,int n0, int n1, int n2, int n3)
- {
- FILE *ext;
- char thei[8],finalname[17],comptoe[250];
- unsigned char est[4];
- unsigned long int null;
- //controllo dell'estensione
- est[0]=0;
- ext=fopen(name,"rb");
- fread(&est,4,1,ext);
- est[4]=0;
- fseek(ext,0,SEEK_END);
- null=ftell(ext);
- fclose(ext);
- //lista estensioni
- //printf("\n%s\n",est);
- sprintf(finalname,"NONAME\0");
- //if (strcmp(est,"SCPK")==0)
- if (est[0] == 0x69 && est[1]==0x53 && est[2] == 0x45 && est[3] == 0x32)
- {
- sprintf(comptoe,"ren %d%d%d%d.dat %d%d%d%d.iSE2\0",n0,n1,n2,n3,n0,n1,n2,n3);
- system(comptoe);
- sprintf(comptoe,"move %d%d%d%d.iSE2 iSE2\0",n0,n1,n2,n3);
- system(comptoe);
- sprintf(finalname,"iSE2\\%d%d%d%d.iSE2\0",n0,n1,n2,n3);
- return(finalname);
- }
- // printf("\n%s\n",est);
- // system("pause");
- if (null == 0)
- {
- sprintf(comptoe,"ren %d%d%d%d.dat %d%d%d%d.null\0",n0,n1,n2,n3,n0,n1,n2,n3);
- system(comptoe);
- sprintf(comptoe,"move %d%d%d%d.null DUMMY\0",n0,n1,n2,n3);
- system(comptoe);
- sprintf(finalname,"DUMMY\\%d%d%d%d.null\0",n0,n1,n2,n3);
- return(finalname);
- }
- // if (strcmp(est,"TIM2")==0)
- if (est[0] == 0x54 && est[1]==0x49 && est[2] == 0x4D && est[3] == 0x32)
- {
- sprintf(comptoe,"ren %d%d%d%d.dat %d%d%d%d.tm2\0",n0,n1,n2,n3,n0,n1,n2,n3);
- system(comptoe);
- sprintf(comptoe,"move %d%d%d%d.tm2 TIM2\0",n0,n1,n2,n3);
- system(comptoe);
- sprintf(finalname,"TIM2\\%d%d%d%d.tm2\0",n0,n1,n2,n3);
- return(finalname);
- }
- //if (strcmp(est,"RIFF")==0)
- if (est[0] == 0x00 && est[1]==0x00 && est[2] == 0x00 && est[3] == 0x00)
- {
- sprintf(comptoe,"ren %d%d%d%d.dat %d%d%d%d.ARCH2S\0",n0,n1,n2,n3,n0,n1,n2,n3);
- system(comptoe);
- sprintf(comptoe,"move %d%d%d%d.ARCH2S ARCH2S\0",n0,n1,n2,n3);
- system(comptoe);
- sprintf(finalname,"ARCH2S\\%d%d%d%d.ARCH2S\0",n0,n1,n2,n3);
- return(finalname);
- }
- if (est[0] == 0x4D && est[1]==0x47 && est[2] == 0x4C && est[3] == 0x4B)
- {
- sprintf(comptoe,"ren %d%d%d%d.dat %d%d%d%d.mglk\0",n0,n1,n2,n3,n0,n1,n2,n3);
- system(comptoe);
- sprintf(comptoe,"move %d%d%d%d.mglk MGLK\0",n0,n1,n2,n3);
- system(comptoe);
- sprintf(finalname,"MGLK\\%d%d%d%d.mglk\0",n0,n1,n2,n3);
- return(finalname);
- }
- if (est[0] == 0x69 && est[1]==0x54 && est[2] == 0x50 && est[3] == 0x4B)
- {
- sprintf(comptoe,"ren %d%d%d%d.dat %d%d%d%d.iTPK\0",n0,n1,n2,n3,n0,n1,n2,n3);
- system(comptoe);
- sprintf(comptoe,"move %d%d%d%d.iTPK iTPK\0",n0,n1,n2,n3);
- system(comptoe);
- sprintf(finalname,"iTPK\\%d%d%d%d.iTPK\0",n0,n1,n2,n3);
- return(finalname);
- }
- //if (strcmp(est,"VAGp")==0)
- if (est[0] == 0x56 && est[1]==0x41 && est[2] == 0x47 && est[3] == 0x70)
- {
- sprintf(comptoe,"ren %d%d%d%d.dat %d%d%d%d.vag\0",n0,n1,n2,n3,n0,n1,n2,n3);
- system(comptoe);
- sprintf(comptoe,"move %d%d%d%d.vag VAG\0",n0,n1,n2,n3);
- system(comptoe);
- sprintf(finalname,"VAG\\%d%d%d%d.vag\0",n0,n1,n2,n3);
- return(finalname);
- }
- if (est[0] == 0x7F && est[1]==0x45 && est[2] == 0x4C && est[3] == 0x46)
- {
- sprintf(comptoe,"ren %d%d%d%d.dat %d%d%d%d.elf\0",n0,n1,n2,n3,n0,n1,n2,n3);
- system(comptoe);
- sprintf(comptoe,"move %d%d%d%d.elf ELF\0",n0,n1,n2,n3);
- system(comptoe);
- sprintf(finalname,"ELF\\%d%d%d%d.elf\0",n0,n1,n2,n3);
- return(finalname);
- }
- //if (strcmp(est,"YPC2")==0)
- if (est[0] == 0x04 && est[1]==0x00 && est[2] == 0x00 && est[3] == 0x00)
- {
- sprintf(comptoe,"ren %d%d%d%d.dat %d%d%d%d.arch\0",n0,n1,n2,n3,n0,n1,n2,n3);
- system(comptoe);
- sprintf(comptoe,"move %d%d%d%d.arch ARCH\0",n0,n1,n2,n3);
- system(comptoe);
- sprintf(finalname,"ARCH\\%d%d%d%d.arch\0",n0,n1,n2,n3);
- return(finalname);
- }
- if (strcmp(finalname,"NONAME")==0)
- {
- sprintf(finalname,"%s\0",name);
- }
- return(finalname);
- }
Add Comment
Please, Sign In to add comment