#include #include #include #include #include #include #include #include #include #include "dffviewer.h" #include "../libdff/dff.h" void ToUpperLine(char *in) { int i, len; len = strlen(in); for (i = 0; i < len; i++) if (islower(in[i])) in[i] = toupper(in[i]); } char *ReadConfigLine(FILE *f, char *Buf) { int i; char Line[512]; readline: if (fgets(Line, 512, f) == NULL) return NULL; while (1) { if (Line[strlen(Line)-1] == 0xd || Line[strlen(Line)-1] == 0xa) Line[strlen(Line)-1] = '\0'; else break; } for (i = 0; i < strlen(Line); i++) if (Line[i] == '#' || Line[i] == ';') { Line[i] = '\0'; break; } if (Line[0] == '\0') goto readline; strcpy(Buf, Line); return Buf; } /* int main() { char Buf[512]; FILE *Config; if ((Config = fopen("GTA3.DAT", "r")) == NULL) exit(1); while (ReadConfigLine(Config, Buf) != NULL) puts(Buf); return 0; } */ void CorrectPath(char *Path) { int i; for (i = 0; i < strlen(Path); i++) { if (Path[i] == '\\') Path[i] = '/'; } } void ReadGTADat(char *datpath) { int i; char Type[16], Path[64]; int colint; char Line[512]; FILE *dat; IdeCount = TxdCount = DffCount = IplCount = ImgCount = 0; Ide = malloc(1); Txd = malloc(1); Dff = malloc(1); Ipl = malloc(1); Img = malloc(2*sizeof(ImgFile)); ImgCount = 1; strcpy(Img[0].DirPath, "MODELS/GTA3.DIR"); strcpy(Img[0].ImgPath, "MODELS/GTA3.IMG"); Img[0].IsOpen = 0; if ((dat = fopen(datpath, "r")) == NULL) { fprintf(stderr, "Couldn't open file: %s\n", datpath); exit(1); } while (ReadConfigLine(dat, Line) != NULL) { sscanf(Line, "%s %s", Type, Path); CorrectPath(Path); if (strcmp(Type, "IDE") == 0) { IdeCount++; Ide = realloc(Ide, IdeCount*sizeof(IdeFile)); strcpy(Ide[IdeCount-1].Path, Path); Ide[IdeCount-1].IsOpen = 0; } else if (strcmp(Type, "TEXDICTION") == 0) { TxdCount++; Txd = realloc(Txd, TxdCount*sizeof(TxdFile)); strcpy(Txd[TxdCount-1].Path, Path); Txd[TxdCount-1].IsOpen = 0; } else if (strcmp(Type, "MODELFILE") == 0) { DffCount++; Dff = realloc(Dff, DffCount*sizeof(DffFile)); strcpy(Dff[DffCount-1].Path, Path); Dff[DffCount-1].IsOpen = 0; } else if (strcmp(Type, "COLFILE") == 0) { sscanf(Line, "%s %d %s", Type, &colint, Path); } else if (strcmp(Type, "SPLASH") == 0) { } else if (strcmp(Type, "MAPZONE") == 0) { } else if (strcmp(Type, "IPL") == 0) { IplCount++; Ipl = realloc(Ipl, IplCount*sizeof(IplFile)); strcpy(Ipl[IplCount-1].Path, Path); Ipl[IplCount-1].IsOpen = 0; } else if (strcmp(Type, "IMG") == 0) { ImgCount++; Img = realloc(Img, ImgCount*sizeof(ImgFile)); strcpy(Img[ImgCount-1].ImgPath, Path); Img[ImgCount-1].IsOpen = 0; } } printf("%d %d %d %d %d\n", IdeCount, TxdCount, DffCount, IplCount, ImgCount); for (i = 0; i < IdeCount; i++) printf("%s\n", Ide[i].Path); for (i = 0; i < TxdCount; i++) printf("%s\n", Txd[i].Path); for (i = 0; i < DffCount; i++) printf("%s\n", Dff[i].Path); for (i = 0; i < IplCount; i++) printf("%s\n", Ipl[i].Path); } int main(int argc, char* argv[]) { int i; FILE *config; char dirname[2][180], imgname[2][180]; char idename[180]; /* Open second argument as logfile. * If there is no second argument, use stdout */ if (argc < 2) logfile = stdout; else if ((logfile = fopen(argv[1], "w")) == NULL) { fprintf(stderr, "Couldn't open %s\n", argv[1]); exit(1); } if ((config = fopen("dffviewer.conf", "r")) == NULL) { fprintf(stderr, "Couldn't open %s\n", "dffviewer.conf"); exit(1); } ReadConfigLine(config, GtaPath); ReadConfigLine(config, DatPath); if (chdir(GtaPath) == -1) { fprintf(stderr, "Couldn't cd to %s\n", GtaPath); exit(1); } ReadGTADat(DatPath); free(Ide); free(Txd); free(Dff); free(Ipl); free(Img); exit(0); strcpy(dirname[0], "gta3ps2.dir"); strcpy(imgname[0], "gta3ps2.img"); strcpy(dirname[1], "gtavcps2.dir"); strcpy(imgname[1], "gtavcps2.img"); /* fscanf(config, "%s\n", idename); fscanf(config, "%s\n", dirname[0]); fscanf(config, "%s\n", imgname[0]); */ /* Read the config file */ archivenum = 1; dir = malloc(archivenum * sizeof(FILE *)); img = malloc(archivenum * sizeof(FILE *)); filenum = malloc(archivenum * sizeof(int)); filelist = malloc(archivenum * sizeof(DirEntry *)); for (i = 0; i < archivenum; i++) { if ((dir[i] = fopen(dirname[i], "rb")) == NULL) { fprintf(stderr,"Couldn't open %s\n",dirname[i]); exit(1); } if ((img[i] = fopen(imgname[i], "rb")) == NULL) { fprintf(stderr,"Couldn't open %s\n",imgname[i]); exit(1); } filenum[i] = ReadDir(dir[i], &filelist[i]); } if ((generic = fopen("GENERIC.TXD", "rb")) == NULL) { fprintf(stderr,"Couldn't open %s\n", "GENERIC.TXD"); exit(1); } UseTextures = 1; objscount = 0; objs = NULL; // objs = malloc(sizeof(Objs)*4); // objs[0].mdl = LoadModel(objs[0].Model, objs[0].Texture, img, 0); // objs[1].mdl = LoadModel(objs[1].Model, objs[1].Texture, img, 0); // objs[2].mdl = LoadModel(objs[2].Model, objs[2].Texture, img, 1); if ((ide = fopen(idename, "r")) == NULL) { fprintf(stderr, "Couldn't open file %s\n", idename); exitprog(0); } /* Allow program to shut down gracefully if program receives * interrupt signal */ signal(SIGINT, exitprog); InitOGL(argc, argv); return 0; }