/////////////////////////////////////////////////////////////////
// TMainClient
// -----------
//
void TMainClient::CmFileOpenWad ()
{
	// save current working directory (of windeu32.exe)
	// the TFileOpenDialog below is going to set
	// it to the folder of the file being opened...
	char workdir[256];
	GetCurrentDirectory(256, workdir);

	SET_HELP_CONTEXT(Open_WAD_file);
	//
	// Display standard Open dialog box to select a file name.
	//
	*FileData.FileName = 0;
	if (TFileOpenDialog(this, FileData).Execute() == IDOK)
	{
		// restore workingdirectory to folder of windeu32.exe
		SetCurrentDirectory(workdir);
#if 0
		OpenPatchWad(FileData.FileName);
		CloseUnusedWadFiles();
#endif
		// Sets a new client window (the editor) and destroy
		// the old one (the main client)
		TMainFrame *MainFrame =
			TYPESAFE_DOWNCAST (GetApplication()->GetMainWindow(), TMainFrame);
		MainFrame->EditLevel (FileData.FileName, FALSE) ;
		
	}
	RESTORE_HELP_CONTEXT();
}
Beispiel #2
0
/*
   the main program
*/
int main( int argc, char *argv[])
{
   Credits( stdout);
   argv++;
   argc--;
   /* read command line options */
   ParseCommandLineOptions( argc, argv);

   /* load the Wad files */
   OpenMainWad( MainWad);
   if (PatchWads)
      while (PatchWads[ 0])
      {
	 OpenPatchWad( PatchWads[ 0]);
	 PatchWads++;
      }
   /* sanity check */
   CloseUnusedWadFiles();

   /* all systems go! */
   MainLoop();
   /* that's all, folks! */
   CloseWadFiles();
   exit( 0);
}
Beispiel #3
0
//////////////////////////////////////////////////////////
// WinDEUApp
// ---------
// Application instance intialisation. Read the INI file
// for default application options.
void WinDEUApp::InitInstance ()
{
	// Initialize and create MainWindow
	TApplication::InitInstance();

	// Retrieve module directory to construct help file full path
	if ( GetModuleFileName (HelpFileName, MAX_PATH) )
	{
		int i;
		for (i = strlen(HelpFileName) - 1;
			 (i >= 0) && (HelpFileName[i] != '\\');
			 i--)
			;

		HelpFileName[i+1] = '\0';

		strcat (HelpFileName, HelpName);
	}

	// Keyboard hook for F1 help
	hKeyboardHook = SetWindowsHookEx(WH_KEYBOARD,
									 KeyboardProc,
									 *this,
									 0);
	// Parse command line and INI file.
	InitWindeu(argc, argv, init_level);

// removed annoyances ARK
#if 0
	// Create and display credits for WinDEU
	CmHelpAbout();

	//RP moved from InitWinDEU
	if (Quieter == TRUE)
		Quiet = TRUE;
	if (Reminder == TRUE)
		FunnyMessage();
#endif

	/* load the wad files */
	// Don't load Doom WAD   ARK
#if 0
	OpenMainWad(MainWad);
	if (PatchWads)
		while (PatchWads[ 0])
		{
			OpenPatchWad( strupr( PatchWads[ 0]));
			PatchWads++;
		}
#endif

	/* sanity check */
	CloseUnusedWadFiles();

	// Load initial level if specified on command line
	if (init_level[0] != 0)
	{
		// Sets a new client window (the editor) and destroy
		// the old one (the main client)
		TMainFrame *MainFrame =
			TYPESAFE_DOWNCAST(MainWindow->GetApplication()->GetMainWindow(), TMainFrame);
		MainFrame->EditLevel (init_level, FALSE) ;
	}
}
Beispiel #4
0
/*
   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);
   }
}