///////////////////////////////////////////////////////////////// // TMainClient // ----------- // void TMainClient::CmFileExtractRaw () { static char ObjectName[12]; WadPtr wad; MDirPtr entry; FILE *file; SET_HELP_CONTEXT(Extract_object); // Get objet name // Stupid InputDialog box, would be better with a list box if ( TInputDialog (this, "Enter object name", "Object :", ObjectName, 12).Execute() != IDOK ) goto End; // Check the name of the object exists for (entry = MasterDir ; entry != NULL ; entry = entry->next) if ( strnicmp (entry->dir.name, ObjectName, 8) == 0 ) break; if ( entry == NULL ) { Notify ("The object \"%s\" doesn't exist", ObjectName); goto End; } // // Display standard Open dialog box to select a file name. // *FileData.FileName = 0; if (TFileSaveDialog(this, FileData).Execute() != IDOK) goto End; // Check WAD isn't opened for (wad = WadFileList; wad; wad = wad->next) if (!stricmp(FileData.FileName, wad->filename)) break; if (wad) { Notify ("You may not overwrite an opened Wad file with raw data"); goto End; } // Opening .RAW file in .WAD entry WorkMessage ("Saving directory entry data to \"%s\".", FileData.FileName); file = fopen(FileData.FileName, "wb"); if (file == NULL) { Notify ("Error opening output file \"%s\"", FileData.FileName); } else { SaveEntryToRawFile(file, ObjectName); fclose(file); } End: RESTORE_HELP_CONTEXT(); }
/* the main program menu loop */ void MainLoop() { WadPtr wad; FILE *file; char input[ 120]; char *com, *out; BCINT episode, mission; for (;;) { /* get the input */ printf( "\n[? for help]> "); gets( input); if(feof(stdin)) strcpy(input, "QUIT"); printf( "\n"); /* eat the white space and get the first command word */ com = strtok( input, " "); strupr( com); /* user just hit return */ if (com == NULL) printf( "[Please enter a command or ? for help.]\n"); /* user inputting for help */ else if (!strcmp( com, "?") || !strcmp( com, "HELP") || !strcmp( com, "H")) { printf( "? or H[elp] -- to display this text\n"); printf( "A[nalyze] episode mission -- to analyze a game level's statistics\n"); printf( "D[ump] <DirEntry> [outfile] -- to dump a directory entry in hex\n"); printf( "F[lags] { <+-><24ABDEFGLMNPSTUZ>} -- to display/set the print flags\n"); printf( "L[ist] <WadFile> [outfile] -- to list the directory of a WAD file\n"); printf( "M[aster] [outfile] -- to list the master directory\n"); printf( "N[ame] [name or ''] -- to display/set the user level name\n"); printf( "P[rint] episode mission <PSfile> -- to print a game level to a PostScript file\n"); printf( "Q[uit] -- to quit\n"); printf( "R[ead] <WadFile> -- to read a new WAD patch file\n"); printf( "W[ads] -- to display the open WAD files\n"); printf( "X[tract] <DirEntry> <RawFile> -- to save (extract) one object to a raw file\n"); } /* user asked for list of open WAD files */ else if (!strcmp( com, "WADS") || !strcmp( com, "W")) { printf( "%-20s IWAD (Main ", WadFileList->filename); switch (GameVersion % 16) { case 0: printf( "Shareware"); break; case 1: printf( "Registered"); break; case 2: printf( "Commercial"); break; case 4: printf( "Ultimate"); break; } printf( " WAD file)\n"); for (wad = WadFileList->next; wad; wad = wad->next) { if (GameVersion == 2 && wad->directory[ 0].name[ 0] == 'M' && wad->directory[ 0].name[ 1] == 'A' && wad->directory[ 0].name[ 2] == 'P') printf( "%-20s PWAD (Patch WAD file for level %c%c)\n", wad->filename, wad->directory[ 0].name[ 3], wad->directory[ 0].name[ 4]); else if (GameVersion != 2 && wad->directory[ 0].name[ 0] == 'E' && wad->directory[ 0].name[ 2] == 'M') printf( "%-20s PWAD (Patch WAD file for episode %c mission %c)\n", wad->filename, wad->directory[ 0].name[ 1], wad->directory[ 0].name[ 3]); else { /* kludge */ strncpy( input, wad->directory[ 0].name, 8); input[ 8] = '\0'; printf( "%-20s PWAD (Patch WAD file for %s)\n", wad->filename, input); } } } /* user asked to quit */ else if (!strcmp( com, "QUIT") || !strcmp( com, "Q")) { if (GameVersion == 0) printf("Remember to register your copy of DOOM!\n"); else if (GameVersion == 16) printf("Remember to register your copy of Heretic!\n"); printf( "Goodbye...\n"); break; } /* user asked to display/set the print flags */ else if (!strcmp( com, "FLAGS") || !strcmp( com, "F")) { com = strtok( NULL, " "); if (com == NULL) DisplayFlags(); else while (com != NULL) { strupr( com); if (com[ 0] != '+' && com[ 0] != '-') printf( "[Flag must start with '+' or '-'.]\n"); else if (!strchr( "24ABDEFGLMNPSTUZ", com[ 1])) printf( "[Flag must be one of '24ABDEFGLMNPSTUZ'.]\n"); else if (com[ 2] != ' ' && com[ 2] != '\0') printf( "[Flag must be one character.]\n"); else SetFlag( com[ 1], com[ 0]); com = strtok( NULL, " "); } } /* user asked to display/set the user level name */ else if (!strcmp( com, "NAME") || !strcmp( com, "N")) { com = strtok( NULL, " "); if (com == NULL) if (UserLvlNm != NULL) printf( "User level name : %s\n", UserLvlNm); else printf( "[User level name is not set.]\n"); else if (! strcmp( com, "''")) { /* reset user level name */ FreeMemory( UserLvlNm); UserLvlNm = NULL; printf( "User level name reset\n"); } else { /* set user level name */ UserLvlNm = (char *) GetMemory( (strlen( com) + 1) * sizeof( char)); strcpy( UserLvlNm, com); while ((com = strtok( NULL, " ")) != NULL) { UserLvlNm = (char *) ResizeMemory( UserLvlNm, (strlen( UserLvlNm) + 1 + strlen( com)) * sizeof( char)); strcat( UserLvlNm, " "); strcat( UserLvlNm, com); } printf( "User level name set : %s\n", UserLvlNm); } } /* user asked to print a level */ else if (!strcmp( com, "PRINT") || !strcmp( com, "P")) { com = strtok( NULL, " "); if (com == NULL) { printf( "[Episode number argument missing.]\n"); continue; } episode = atoi( com); com = strtok( NULL, " "); if (com == NULL) { printf( "[Mission number argument missing.]\n"); continue; } mission = atoi( com); if (GameVersion == 2) { if (episode != 0) { printf( "[Invalid game episode number (%d).]\n", episode); continue; } if (mission < 1 || mission > 32) { printf( "[Invalid game mission number (%d).]\n", mission); continue; } } else /* GameVersion != 2 */ if (!(GameVersion == 17 && episode == 4 && mission == 1)) /* Heretic E4M1 */ { if (episode < 1 || episode > (GameVersion == 4 ? 4 : (GameVersion & 1 ? 3 : 1))) { printf( "[Invalid game episode number (%d).]\n", episode); continue; } if (mission < 1 || mission > 9) { printf( "[Invalid game mission number (%d).]\n", mission); continue; } } out = strtok( NULL, " "); if (! out) { printf( "[PostScript file name argument missing.]\n"); continue; } if (GameVersion == 2) printf( "Outputting PostScript map of level MAP%02d to \"%s\".\n", mission, out); else printf( "Outputting PostScript map of level E%dM%d to \"%s\".\n", episode, mission, out); if ((PSFile = fopen( out, "wt")) == NULL) ProgError( "error opening output file \"%s\"", out); fprintf( PSFile, "%%! DMPSMU: DooM PostScript Maps Utility, ver %s\n", DMPS_VERSION); PrintLevel( episode, mission); fprintf( PSFile, "\n%%%% End of file.\n"); fclose( PSFile); } /* user asked to analyze a level */ else if (!strcmp( com, "ANALYZE") || !strcmp( com, "A")) { com = strtok( NULL, " "); if (com == NULL) { printf( "[Episode number argument missing.]\n"); continue; } episode = atoi( com); com = strtok( NULL, " "); if (com == NULL) { printf( "[Mission number argument missing.]\n"); continue; } mission = atoi( com); if (GameVersion == 2) { if (episode != 0) { printf( "[Invalid game episode number (%d).]\n", episode); continue; } if (mission < 1 || mission > 32) { printf( "[Invalid game mission number (%d).]\n", mission); continue; } } else /* GameVersion != 2 */ if (!(GameVersion == 17 && episode == 4 && mission == 1)) /* Heretic E4M1 */ { if (episode < 1 || episode > (GameVersion == 4 ? 4 : (GameVersion & 1 ? 3 : 1))) { printf( "[Invalid game episode number (%d).]\n", episode); continue; } if (mission < 1 || mission > 9) { printf( "[Invalid game mission number (%d).]\n", mission); continue; } } AnalyzeLevel( episode, mission); } /* user ask for a listing of a WAD file */ else if (!strcmp( com, "LIST") || !strcmp( com, "L")) { com = strtok( NULL, " "); if (com == NULL) { printf( "[Wad file name argument missing.]\n"); continue; } for (wad = WadFileList; wad; wad = wad->next) if (!strcmp( com, wad->filename)) break; if (! wad) { printf( "[Wad file \"%s\" is not open.]\n", com); continue; } out = strtok( NULL, " "); if (out) { printf( "Outputting directory of \"%s\" to \"%s\".\n", wad->filename, out); if ((file = fopen( out, "wt")) == NULL) ProgError( "error opening output file \"%s\"", out); Credits( file); ListFileDirectory( file, wad); fprintf( file, "\nEnd of file.\n"); fclose( file); } else ListFileDirectory( stdout, wad); } /* user asked for the list of the master directory */ else if (!strcmp( com, "MASTER") || !strcmp( com, "M")) { out = strtok( NULL, " "); if (out) { printf( "Outputting master directory to \"%s\".\n", out); if ((file = fopen( out, "wt")) == NULL) ProgError( "error opening output file \"%s\"", out); Credits( file); ListMasterDirectory( file); fprintf( file, "\nEnd of file.\n"); fclose( file); } else ListMasterDirectory( stdout); } /* user asked to read a new patch WAD file */ else if (!strcmp( com, "READ") || !strcmp( com, "R")) { com = strtok( NULL, " "); if (com == NULL) { printf( "[Wad file name argument missing.]\n"); continue; } out = strtok( NULL, " "); if (out) *out = '\0'; out = (char *) GetMemory( (strlen( com) + 1) * sizeof( char)); strcpy( out, com); OpenPatchWad( out); CloseUnusedWadFiles(); } /* user asked to dump the contents of a WAD file entry */ else if (!strcmp( com, "DUMP") || !strcmp( com, "D")) { com = strtok( NULL, " "); if (com == NULL) { printf( "[Object name argument missing.]\n"); continue; } strupr( com); out = strtok( NULL, " "); if (out) { printf( "Outputting directory entry data to \"%s\".\n", out); if ((file = fopen( out, "wt")) == NULL) ProgError( "error opening output file \"%s\"", out); Credits( file); DumpDirectoryEntry( file, com); fprintf( file, "\nEnd of file.\n"); fclose( file); } else DumpDirectoryEntry( stdout, com); } /* user asked to extract an object to a raw binary file */ else if (!strcmp( com, "XTRACT") || !strcmp( com, "X") || !strcmp( com, "EXTRACT")) { com = strtok( NULL, " "); if (com == NULL) { printf( "[Object name argument missing.]\n"); continue; } if (strlen( com) > 8 || strchr( com, '.')) { printf( "[Invalid object name.]\n"); continue; } strupr( com); out = strtok( NULL, " "); if (! out) { printf( "[Raw file name argument missing.]\n"); continue; } for (wad = WadFileList; wad; wad = wad->next) if (!strcmp( out, wad->filename)) break; if (wad) { printf( "[You may not overwrite an opened Wad file with raw data.]\n"); continue; } printf( "Saving directory entry data to \"%s\".\n", out); if ((file = fopen( out, "wb")) == NULL) ProgError( "error opening output file \"%s\"", out); SaveEntryToRawFile( file, com); fclose( file); } /* unknown command */ else printf( "[Unknown command \"%s\"!]\n", com); } }