home *** CD-ROM | disk | FTP | other *** search
/ Deathday Collection / dday.bin / edit / dfe / dfe.pas < prev    next >
Pascal/Delphi Source File  |  1994-05-26  |  30KB  |  1,026 lines

  1. {****************************************************************************
  2. *                      The DOOM Hacker's Tool Kit                           *
  3. *****************************************************************************
  4. * Program: DFE v1.31                                                        *
  5. * Purpose: DOOM 1.2  Front End                                              *
  6. * Date:    4/28/94                                                          *
  7. * Author:  Joshua Jackson        Internet: joshjackson@delphi.com           *
  8. ****************************************************************************}
  9.  
  10. {As of this point in time, I have not found a way to allow execution of
  11.  the Watcom DOS extender while running under DPMI... however I am looking
  12.  into a way to switch the system back to real mode before launching DOOM}
  13.  
  14. {$IFNDEF DPMI}
  15. uses     app,objects,menus,drivers,views,memory,dialogs,strings,windos,Dos,crt,
  16.         WadDecl,Wad,mapread,StdDlg,Swap,MsgBox;
  17. {$ELSE} {You CAN NOT use the SWAP unit under DPMI!!!}
  18. uses     app,objects,menus,drivers,views,memory,dialogs,strings,windos,Dos,crt,
  19.         WadDecl,Wad,mapread,StdDlg,MsgBox;
  20. {$ENDIF}
  21.  
  22. const    cmOnePlayerMenu    = 100;
  23.         cmSerialMenu        = 101;
  24.         cmIPXMenu            = 102;
  25.         cmModemMenu            = 103;
  26.         cmViewMaps            = 105;
  27.         cmNull                = 255;
  28.  
  29.         gtNormal                = 00;
  30.         gtIPXNet                = 01;
  31.         gtModem                = 02;
  32.         gtDirLinkModem        = 03;
  33.         gtSerial                = 04;
  34.         gtSetMode            = 05;
  35.         gtViewSprites        = 06;
  36.         gtViewMaps            = 07;
  37.  
  38. type    PMyApp=^TMyApp;
  39.         TMyApp=Object(Tapplication)
  40.             Constructor Init;
  41.             Procedure InitMenuBar; virtual;
  42.             Procedure Idle; virtual;
  43.             Procedure HandleEvent(Var Event:TEvent); virtual;
  44.             Function GetPalette:PPalette; virtual;
  45.             Procedure RunDoom(GameType:integer;Params:string);
  46.             Procedure OnePlayerMenu;
  47.             Procedure SerialMenu;
  48.             Procedure IPXMenu;
  49.             Procedure ModemMenu;
  50.             Procedure ViewMaps;
  51.         end;
  52.         SelLevelArray=array[1..4] of PCluster;
  53.         LevelNameArray=array[1..9] of String;
  54.  
  55. var    MyApp:TMyApp;
  56.         Debug:boolean;
  57.  
  58. Procedure SetLevelData(R:TRect;var SelLevel:PRadioButtons;Level:word);
  59.  
  60.     begin
  61.         case Level of
  62.             1:SelLevel:=New(PRadioButtons, Init(R,
  63.               NewSItem('~1~ Hanger',
  64.               NewSItem('~2~ Nuclear Plant',
  65.               NewSItem('~3~ Toxin Refinery',
  66.               NewSItem('~4~ Command Control',
  67.               NewSItem('~5~ Phobos Lab',
  68.               NewSItem('~6~ Central Processing',
  69.               NewSItem('~7~ Computer Station',
  70.               NewSItem('~8~ Phobos Anomaly',
  71.               NewSItem('~9~ Military Base',
  72.               nil)))))))))));
  73.             2:SelLevel:=New(PRadioButtons, Init(R,
  74.               NewSItem('~1~ Deimos Anomaly',
  75.               NewSItem('~2~ Containment Area',
  76.               NewSItem('~3~ Refinery',
  77.               NewSItem('~4~ Deimos Lab',
  78.               NewSItem('~5~ Command Center',
  79.               NewSItem('~6~ Halls of the Damned',
  80.               NewSItem('~7~ Spawning Vats',
  81.               NewSItem('~8~ Towel of Babel',
  82.               NewSItem('~9~ Fortress of Mystery',
  83.               nil)))))))))));
  84.             3:SelLevel:=New(PRadioButtons, Init(R,
  85.               NewSItem('~1~ Hell Keep',
  86.               NewSItem('~2~ Slough of Despair',
  87.               NewSItem('~3~ Pandemonium',
  88.               NewSItem('~4~ House of Pain',
  89.               NewSItem('~5~ Unholy Cathedrial',
  90.               NewSItem('~6~ Mount Erebus',
  91.               NewSItem('~7~ Limbo',
  92.               NewSItem('~8~ DIS',
  93.               NewSItem('~9~ Warrens',
  94.               nil)))))))))));
  95.         end;
  96.     end;
  97.  
  98. Procedure FindLevelNames(FileSpec:PathStr;var Levels:LevelNameArray;R:TRect; var SelLevel:PRadioButtons);
  99.  
  100.     var   PDir:PWadDirectory;
  101.             t,i1,i2,CurLevel:integer;
  102.             tmpstr:string;
  103.             Code:integer;
  104.             TmpArray:PSItem;
  105.             CurItem,ItemList:PSitem;
  106.  
  107.     begin
  108.         TmpStr:=FileSpec;
  109.         PDir:=new(PWadDirectory, Init(FileSpec));
  110.         if WadResult<>wrOk then begin
  111.             MessageBox(WadResultMsg(WadResult),Nil,mfError+ mfOkButton);
  112.             exit;
  113.         end;
  114.         CurLevel:=1;
  115.         CurItem:=Nil;
  116.         ItemList:=Nil;
  117.         Levels[1]:='';
  118.         for t:=1 to PDir^.DirEntries do begin
  119.             if (PDir^.DirEntry^[t].ObjName[1]='E') and (PDir^.DirEntry^[t].ObjName[3]='M') then begin
  120.                 tmpstr:=PDir^.DirEntry^[t].ObjName[2];
  121.                 val(TmpStr,i1,Code);
  122.                 if Code<>0 then
  123.                     continue;
  124.                 tmpstr:=PDir^.DirEntry^[t].ObjName[4];
  125.                 val(TmpStr,i2,Code);
  126.                 if Code<>0 then
  127.                     continue;
  128.                 Levels[CurLevel]:=PDir^.DirEntry^[t].ObjName;
  129.                 if ItemList=Nil then begin
  130.                     ItemList:=New(PSItem);
  131.                     ItemList^.Value:=NewStr(Levels[CurLevel]);
  132.                     ItemList^.Next:=Nil;
  133.                     CurItem:=ItemList;
  134.                  end
  135.                 else begin
  136.                     CurItem^.Next:=New(PSItem);
  137.                     CurItem:=CurItem^.Next;
  138.                     CurItem^.Value:=NewStr(Levels[CurLevel]);
  139.                     CurItem^.Next:=Nil;
  140.                 end;
  141.                 inc(CurLevel);
  142.                 if CurLevel=10 then begin
  143.                     PDir^.Done;
  144.                     Dispose(PDir);
  145.                     SelLevel:=New(PRadioButtons, Init(R,ItemList));
  146.                     exit;
  147.                 end;
  148.             end;
  149.         end;
  150.         PDir^.Done;
  151.         Dispose(PDir);
  152.         SelLevel:=New(PRadioButtons, Init(R,ItemList));
  153.     end;
  154.  
  155. Procedure SetMenuData(MenuNum:byte;var Param1,Param2:string);
  156.  
  157.     var    R:Trect;
  158.             SelModem,SelGame,Monsters,SelSkill,Players:PCluster;
  159.             DialNum:PInputLine;
  160.             SelLevel:PRadioButtons;
  161.             Dialog1,Dialog2:PDialog;
  162.             Dialog3:PFileDialog;
  163.             ComPort:PCluster;
  164.             Control,Episode:word;
  165.             TmpStr,DmParam,ModeParam:string;
  166.             ExtFile:PathStr;
  167.             ExtLevelPos:byte;
  168.             jb:byte;
  169.             FileName: FNameStr;
  170.             LevelNames:LevelNameArray;
  171.  
  172.     begin
  173.         Case MenuNum of
  174.             1:begin
  175.                 R.Assign(2,1,30,5);
  176.                 SelGame:=New(PRadioButtons, Init(R,
  177.                   NewSItem('~K~nee-Deep In The Dead',
  178.                   NewSItem('~S~hores Of Hell',
  179.                   NewSItem('~I~nferno!',
  180.                   NewSItem('~L~oad External Wad File',
  181.                   nil))))));
  182.                 R.Assign(20,6,60,15);
  183.                 Dialog1:=New(PDialog,Init(r,'Episodes'));
  184.                 with Dialog1^ do begin
  185.                     R.Assign(5,6,15,8);
  186.                     Insert(New(PButton,Init(R,'~O~k',cmOk,bfDefault)));
  187.                     R.Assign(25,6,35,8);
  188.                     Insert(New(PButton,Init(R,'~C~ancel',cmCancel,bfNormal)));
  189.                     Insert(SelGame);
  190.                 end;
  191.                 Control:=Desktop^.ExecView(Dialog1);
  192.                 Episode:=SelGame^.Value + 1;
  193.                 Param1:='';
  194.                 DmParam:='';
  195.                 if Episode=4 then begin
  196.                     FileName := '*.WAD';
  197.                     Dialog3:=New(PFileDialog, Init('*.WAD', 'Select Wad File','~N~ame',fdOkButton,100));
  198.                     Dialog3^.SetData(FileName);
  199.                     Control:=Desktop^.ExecView(Dialog3);
  200.                     if Control=cmFileOpen then
  201.                         Control:=cmOk;
  202.                     if Control=cmOK then begin
  203.                         ExtFile:=Dialog3^.Directory^+(Dialog3^.FileName^.Data^);
  204.                         R.Assign(2, 1, 28, 10);
  205.                         FindLevelNames(ExtFile,LevelNames,R,SelLevel);
  206.                         if WadResult<>wrOk then
  207.                             exit;
  208.                         if LevelNames[1]='' then begin
  209.                             Param1:='';
  210.                             MessageBox('No valid level entries found.',Nil,mfError+mfOkButton);
  211.                             control:=cmCancel;
  212.                          end
  213.                         else begin
  214.                             Episode:=4;
  215.                             Param1:='-file '+ExtFile+' ';
  216.                         end;
  217.                     end;
  218.                     Dialog3^.Done;
  219.                     Dispose(Dialog3);
  220.                 end;
  221.                 if Control=cmOK then begin
  222.                     R.Assign(30, 3, 55, 8);
  223.                     SelSkill:=New(PRadioButtons, Init(R,
  224.                       NewSItem('~I~''m too young to die',
  225.                       NewSItem('~H~ey Not too Rough',
  226.                       NewSItem('H~u~rt Me Plenty',
  227.                       NewSItem('U~l~tra Violence',
  228.                       NewSItem('~N~ightmare!',
  229.                       nil)))))));
  230.                     R.Assign(30, 1, 50, 2);
  231.                     Monsters:=New(PCheckBoxes, Init(R,
  232.                       NewSItem('No ~M~onsters',
  233.                       nil)));
  234.                     R.Assign(2, 1, 28, 10);
  235.                     if Episode < 4 then
  236.                         SetLevelData(R,SelLevel,1);
  237.                     R.Assign(11,4,69,18);
  238.                     Dialog2:=New(PDialog,Init(r,'Game Options'));
  239.                     with Dialog2^ do begin
  240.                         Insert(Monsters);
  241.                         Insert(SelSkill);
  242.                         R.Assign(15,11,25,13);
  243.                         Insert(New(PButton,Init(R,'~C~ancel',cmCancel,bfNormal)));
  244.                         R.Assign(2,11,12,13);
  245.                         Insert(New(PButton,Init(R,'~O~k',cmOk,bfDefault)));
  246.                         Insert(SelLevel);
  247.                     end;
  248.                     Control:=Desktop^.ExecView(Dialog2);
  249.                     if Control=cmOk then begin
  250.                         if Episode < 4 then begin
  251.                             Str(Episode,TmpStr);
  252.                             DmParam:='-devparm -warp '+TmpStr+' ';
  253.                             Str(SelLevel^.Value + 1,TmpStr);
  254.                             DmParam:=DmParam+TmpStr
  255.                          end
  256.                         else begin
  257.                             DmParam:='-devparm -warp ';
  258.                             DmParam:=DmParam+LevelNames[SelLevel^.Value+1][2]+' ';
  259.                             DmParam:=DmParam+LevelNames[SelLevel^.Value+1][4];
  260.                         end;
  261.                         Str(SelSkill^.Value + 1,TmpStr);
  262.                         DmParam:=DmParam+' -skill '+TmpStr+' ';
  263.                         if (Monsters^.Value and 1) = 1 then
  264.                             DmParam:=DmParam+'-nomonsters';
  265.                      end
  266.                     else
  267.                         Param1:='';
  268.                     Dialog2^.Done;
  269.                     Dispose(Dialog2);
  270.                     Param1:=Param1+DmParam;
  271.                 end;
  272.                 Dialog1^.Done;
  273.                 Dispose(Dialog1);
  274.               end;
  275.             2:begin
  276.                 R.Assign(2,1,30,5);
  277.                 SelGame:=New(PRadioButtons, Init(R,
  278.                   NewSItem('~K~nee-Deep In The Dead',
  279.                   NewSItem('~S~hores Of Hell',
  280.                   NewSItem('~I~nferno!',
  281.                   NewSItem('~L~oad External Wad File',
  282.                   nil))))));
  283.                 R.Assign(20,7,60,16);
  284.                 Dialog1:=New(PDialog,Init(r,'Episodes'));
  285.                 with Dialog1^ do begin
  286.                     R.Assign(5,6,15,8);
  287.                     Insert(New(PButton,Init(R,'~O~k',cmOk,bfDefault)));
  288.                     R.Assign(25,6,35,8);
  289.                     Insert(New(PButton,Init(R,'~C~ancel',cmCancel,bfNormal)));
  290.                     Insert(SelGame);
  291.                 end;
  292.                 Control:=Desktop^.ExecView(Dialog1);
  293.                 Episode:=SelGame^.Value + 1;
  294.                 DmParam:='';
  295.                 Param1:='';
  296.                 if Episode=4 then begin
  297.                     Dialog3:=New(PFileDialog,Init('*.WAD','Load External WAD','WAD Files',fdOkButton,jb));
  298.                     Control:=Desktop^.ExecView(Dialog3);
  299.                     if Control=cmFileOpen then
  300.                         Control:=cmOk;
  301.                     if Control=cmOK then begin
  302.                         ExtFile:=Dialog3^.Directory^+(Dialog3^.FileName^.Data^);
  303.                         R.Assign(2, 1, 28, 10);
  304.                         FindLevelNames(ExtFile,LevelNames,R,SelLevel);
  305.                         if WadResult<>wrOk then
  306.                             exit;
  307.                         if LevelNames[1]='' then begin
  308.                             Param1:='';
  309.                             MessageBox('No valid level entries found.',Nil,mfError+mfOkButton);
  310.                             control:=cmCancel;
  311.                          end
  312.                         else begin
  313.                             Episode:=4;
  314.                             Param1:='-file '+ExtFile+' ';
  315.                         end;
  316.                     end;
  317.                     Dialog3^.Done;
  318.                     Dispose(Dialog3);
  319.                 end;
  320.                 if Control=cmOK then begin
  321.                     R.Assign(30,10,55,14);
  322.                     ComPort:=New(PRadioButtons, Init(R,
  323.                       NewSItem('COM1',
  324.                       NewSItem('COM2',
  325.                       NewSItem('COM3',
  326.                       NewSItem('COM4',
  327.                       nil))))));
  328.                     R.Assign(30, 4, 55, 9);
  329.                     SelSkill:=New(PRadioButtons, Init(R,
  330.                       NewSItem('~I~''m too young to die',
  331.                       NewSItem('~H~ey Not too Rough',
  332.                       NewSItem('H~u~rt Me Plenty',
  333.                       NewSItem('U~l~tra Violence',
  334.                       NewSItem('~N~ightmare!',
  335.                       nil)))))));
  336.                     R.Assign(30, 1, 50, 3);
  337.                     Monsters:=New(PCheckBoxes, Init(R,
  338.                       NewSItem('No ~M~onsters',
  339.                       NewSItem('~D~eath Match',
  340.                       nil))));
  341.                     R.Assign(2, 1, 28, 10);
  342.                     if Episode < 4 then
  343.                         SetLevelData(R,SelLevel,Episode);
  344.                     R.Assign(11,3,69,18);
  345.                     Dialog2:=New(PDialog,Init(r,'Game Options'));
  346.                     with Dialog2^ do begin
  347.                         Insert(Monsters);
  348.                         Insert(SelSkill);
  349.                         Insert(ComPort);
  350.                         R.Assign(15,12,25,14);
  351.                         Insert(New(PButton,Init(R,'~C~ancel',cmCancel,bfNormal)));
  352.                         R.Assign(2,12,12,14);
  353.                         Insert(New(PButton,Init(R,'~O~k',cmOk,bfDefault)));
  354.                         Insert(SelLevel);
  355.                     end;
  356.                     Control:=Desktop^.ExecView(Dialog2);
  357.                     if Control=cmOk then begin
  358.                         if Episode < 4 then begin
  359.                             Str(Episode,TmpStr);
  360.                             DmParam:='-devparm -warp '+TmpStr+' ';
  361.                             Str(SelLevel^.Value + 1,TmpStr);
  362.                             DmParam:=DmParam+TmpStr
  363.                          end
  364.                         else begin
  365.                             DmParam:='-devparm -warp ';
  366.                             DmParam:=DmParam+LevelNames[SelLevel^.Value+1][2]+' ';
  367.                             DmParam:=DmParam+LevelNames[SelLevel^.Value+1][4];
  368.                         end;
  369.                         Str(SelSkill^.Value + 1,TmpStr);
  370.                         DmParam:=DmParam+' -skill '+TmpStr+' ';
  371.                         DmParam:=DmParam+' -COM';
  372.                         Str(ComPort^.Value + 1,TmpStr);
  373.                         ModeParam:='COM'+TmpStr+':9600,N,8,1';
  374.                         DmParam:=DmParam+TmpStr+' ';
  375.                         if (Monsters^.Value and 1) = 1 then
  376.                             DmParam:=DmParam+'-nomonsters ';
  377.                         if (Monsters^.Value and 2) = 2 then
  378.                             DmParam:=DmParam+'-deathmatch';
  379.                      end
  380.                     else
  381.                         Param1:='';
  382.                     Dialog2^.Done;
  383.                     Dispose(Dialog2);
  384.                     Param1:=Param1+DmParam;
  385.                 end;
  386.                 Param2:=ModeParam;
  387.                 Param1:=Param1+dmParam;
  388.                 Dialog1^.Done;
  389.                 Dispose(Dialog1);
  390.               end;
  391.             3:begin
  392.                 R.Assign(2,1,30,5);
  393.                 SelGame:=New(PRadioButtons, Init(R,
  394.                   NewSItem('~K~nee-Deep In The Dead',
  395.                   NewSItem('~S~hores Of Hell',
  396.                   NewSItem('~I~nferno!',
  397.                   NewSItem('~L~oad External Wad File',
  398.                   nil))))));
  399.                 R.Assign(20,7,60,16);
  400.                 Dialog1:=New(PDialog,Init(r,'Episodes'));
  401.                 with Dialog1^ do begin
  402.                     R.Assign(5,6,15,8);
  403.                     Insert(New(PButton,Init(R,'~O~k',cmOk,bfDefault)));
  404.                     R.Assign(25,6,35,8);
  405.                     Insert(New(PButton,Init(R,'~C~ancel',cmCancel,bfNormal)));
  406.                     Insert(SelGame);
  407.                 end;
  408.                 Control:=Desktop^.ExecView(Dialog1);
  409.                 Episode:=SelGame^.Value + 1;
  410.                 DmParam:='';
  411.                 Param1:='';
  412.                 if Episode=4 then begin
  413.                     Dialog3:=New(PFileDialog,Init('*.WAD','Load External WAD','WAD Files',fdOkButton,jb));
  414.                     Control:=Desktop^.ExecView(Dialog3);
  415.                     if Control=cmFileOpen then
  416.                         Control:=cmOk;
  417.                     if Control=cmOK then begin
  418.                         ExtFile:=Dialog3^.Directory^+(Dialog3^.FileName^.Data^);
  419.                         R.Assign(2, 1, 28, 10);
  420.                         FindLevelNames(ExtFile,LevelNames,R,SelLevel);
  421.                         if WadResult<>wrOk then
  422.                             exit;
  423.                         if LevelNames[1]='' then begin
  424.                             Param1:='';
  425.                             MessageBox('No valid level entries found.',Nil,mfError+mfOkButton);
  426.                             control:=cmCancel;
  427.                          end
  428.                         else begin
  429.                             Episode:=4;
  430.                             Param1:='-file '+ExtFile+' ';
  431.                         end;
  432.                     end;
  433.                     Dialog3^.Done;
  434.                     Dispose(Dialog3);
  435.                 end;
  436.                 if Control=cmOK then begin
  437.                     R.Assign(30,10,55,13);
  438.                     Players:=New(PRadioButtons, Init(R,
  439.                       NewSItem('Two Players',
  440.                       NewSItem('Three Players',
  441.                       NewSItem('Four Players',
  442.                       nil)))));
  443.                     R.Assign(30, 4, 55, 9);
  444.                     SelSkill:=New(PRadioButtons, Init(R,
  445.                       NewSItem('~I~''m too young to die',
  446.                       NewSItem('~H~ey Not too Rough',
  447.                       NewSItem('H~u~rt Me Plenty',
  448.                       NewSItem('U~l~tra Violence',
  449.                       NewSItem('~N~ightmare!',
  450.                       nil)))))));
  451.                     R.Assign(30, 1, 50, 3);
  452.                     Monsters:=New(PCheckBoxes, Init(R,
  453.                       NewSItem('No ~M~onsters',
  454.                       NewSItem('~D~eath Match',
  455.                       nil))));
  456.                     R.Assign(2, 1, 28, 10);
  457.                     if Episode < 4 then
  458.                         SetLevelData(R,SelLevel,Episode);
  459.                     R.Assign(11,3,69,17);
  460.                     Dialog2:=New(PDialog,Init(r,'Game Options'));
  461.                     with Dialog2^ do begin
  462.                         Insert(Monsters);
  463.                         Insert(SelSkill);
  464.                         Insert(Players);
  465.                         R.Assign(15,11,25,13);
  466.                         Insert(New(PButton,Init(R,'~C~ancel',cmCancel,bfNormal)));
  467.                         R.Assign(2,11,12,13);
  468.                         Insert(New(PButton,Init(R,'~O~k',cmOk,bfDefault)));
  469.                         Insert(SelLevel);
  470.                     end;
  471.                     Control:=Desktop^.ExecView(Dialog2);
  472.                     if Control=cmOk then begin
  473.                         if Episode < 4 then begin
  474.                             Str(Episode,TmpStr);
  475.                             DmParam:='-devparm -warp '+TmpStr+' ';
  476.                             Str(SelLevel^.Value + 1,TmpStr);
  477.                             DmParam:=DmParam+TmpStr
  478.                          end
  479.                         else begin
  480.                             DmParam:='-devparm -warp ';
  481.                             DmParam:=DmParam+LevelNames[SelLevel^.Value+1][2]+' ';
  482.                             DmParam:=DmParam+LevelNames[SelLevel^.Value+1][4];
  483.                         end;
  484.                         Str(SelSkill^.Value + 1,TmpStr);
  485.                         DmParam:=DmParam+' -skill '+TmpStr+' ';
  486.                         DmParam:=DmParam+' -nodes ';
  487.                         Str(Players^.Value + 2,TmpStr);
  488.                         DmParam:=DmParam+TmpStr+' ';
  489.                         if (Monsters^.Value and 1) = 1 then
  490.                             DmParam:=DmParam+'-nomonsters ';
  491.                         if (Monsters^.Value and 2) = 2 then
  492.                             DmParam:=DmParam+'-deathmatch';
  493.                      end
  494.                     else
  495.                         Param1:='';
  496.                     Dialog2^.Done;
  497.                     Dispose(Dialog2);
  498.                     Param1:=Param1+DmParam;
  499.                 end;
  500.                 Param1:=Param1+DmParam;
  501.                 Dialog1^.Done;
  502.                 Dispose(Dialog1);
  503.               end;
  504.             4:begin
  505.                 R.Assign(2,1,30,5);
  506.                 SelGame:=New(PRadioButtons, Init(R,
  507.                   NewSItem('~K~nee-Deep In The Dead',
  508.                   NewSItem('~S~hores Of Hell',
  509.                   NewSItem('~I~nferno!',
  510.                   NewSItem('~L~oad External Wad File',
  511.                   nil))))));
  512.                 R.Assign(20,7,60,16);
  513.                 Dialog1:=New(PDialog,Init(r,'Episodes'));
  514.                 with Dialog1^ do begin
  515.                     R.Assign(5,6,15,8);
  516.                     Insert(New(PButton,Init(R,'~O~k',cmOk,bfDefault)));
  517.                     R.Assign(25,6,35,8);
  518.                     Insert(New(PButton,Init(R,'~C~ancel',cmCancel,bfNormal)));
  519.                     Insert(SelGame);
  520.                 end;
  521.                 Control:=Desktop^.ExecView(Dialog1);
  522.                 Episode:=SelGame^.Value + 1;
  523.                 DmParam:='';
  524.                 Param1:='';
  525.                 if Episode=4 then begin
  526.                     Dialog3:=New(PFileDialog,Init('*.WAD','Load External WAD','WAD Files',fdOkButton,jb));
  527.                     Control:=Desktop^.ExecView(Dialog3);
  528.                     if Control=cmFileOpen then
  529.                         Control:=cmOk;
  530.                     if Control=cmOK then begin
  531.                         ExtFile:=Dialog3^.Directory^+(Dialog3^.FileName^.Data^);
  532.                         R.Assign(2, 1, 28, 10);
  533.                         FindLevelNames(ExtFile,LevelNames,R,SelLevel);
  534.                         if WadResult<>wrOk then
  535.                             exit;
  536.                         if LevelNames[1]='' then begin
  537.                             Param1:='';
  538.                             MessageBox('No valid level entries found.',Nil,mfError+mfOkButton);
  539.                             control:=cmCancel;
  540.                          end
  541.                         else begin
  542.                             Episode:=4;
  543.                             Param1:='-file '+ExtFile+' ';
  544.                         end;
  545.                     end;
  546.                     Dialog3^.Done;
  547.                     Dispose(Dialog3);
  548.                 end;
  549.                 if Control=cmOK then begin
  550.                     R.Assign(30,10,55,14);
  551.                     ComPort:=New(PRadioButtons, Init(R,
  552.                       NewSItem('COM1',
  553.                       NewSItem('COM2',
  554.                       NewSItem('COM3',
  555.                       NewSItem('COM4',
  556.                       nil))))));
  557.                     R.Assign(2,11,28,14);
  558.                     SelModem:=New(PRadioButtons, Init(R,
  559.                       NewSItem('~A~lready Connected',
  560.                       NewSItem('~W~ait For Call',
  561.                       NewSItem('~D~ial:',
  562.                       nil)))));
  563.                     R.Assign(12,13,25,14);
  564.                     DialNum:=New(PInputLine, Init(R,11));
  565.                     R.Assign(30, 4, 55, 9);
  566.                     SelSkill:=New(PRadioButtons, Init(R,
  567.                       NewSItem('~I~''m too young to die',
  568.                       NewSItem('~H~ey Not too Rough',
  569.                       NewSItem('H~u~rt Me Plenty',
  570.                       NewSItem('U~l~tra Violence',
  571.                       NewSItem('~N~ightmare!',
  572.                       nil)))))));
  573.                     R.Assign(30, 1, 50, 3);
  574.                     Monsters:=New(PCheckBoxes, Init(R,
  575.                       NewSItem('No ~M~onsters',
  576.                       NewSItem('~D~eath Match',
  577.                       nil))));
  578.                     R.Assign(2, 1, 28, 10);
  579.                     if Episode < 4 then
  580.                         SetLevelData(R,SelLevel,Episode);
  581.                     R.Assign(11,2,69,20);
  582.                     Dialog2:=New(PDialog,Init(r,'Game Options'));
  583.                     with Dialog2^ do begin
  584.                         Insert(SelModem);
  585.                         Insert(DialNum);
  586.                         Insert(Monsters);
  587.                         Insert(SelSkill);
  588.                         Insert(ComPort);
  589.                         R.Assign(15,15,25,17);
  590.                         Insert(New(PButton,Init(R,'~C~ancel',cmCancel,bfNormal)));
  591.                         R.Assign(2,15,12,17);
  592.                         Insert(New(PButton,Init(R,'~O~k',cmOk,bfDefault)));
  593.                         Insert(SelLevel);
  594.                     end;
  595.                     Control:=Desktop^.ExecView(Dialog2);
  596.                     if Control=cmOk then begin
  597.                         DmParam:='';
  598.                         if SelModem^.Value = 2 then
  599.                             DmParam:=DmParam+'-dial '+DialNum^.Data^;
  600.                         if SelModem^.Value = 1 then
  601.                             DmParam:=DmParam+'-answer ';
  602.                         if Episode < 4 then begin
  603.                             Str(Episode,TmpStr);
  604.                             DmParam:=DmParam+'-devparm -warp '+TmpStr+' ';
  605.                             Str(SelLevel^.Value + 1,TmpStr);
  606.                             DmParam:=DmParam+TmpStr
  607.                          end
  608.                         else begin
  609.                             DmParam:=DmParam+'-devparm -warp ';
  610.                             DmParam:=DmParam+LevelNames[SelLevel^.Value+1][2]+' ';
  611.                             DmParam:=DmParam+LevelNames[SelLevel^.Value+1][4];
  612.                         end;
  613.                         Str(SelSkill^.Value + 1,TmpStr);
  614.                         DmParam:=DmParam+' -skill '+TmpStr+' ';
  615.                         DmParam:=DmParam+' -COM';
  616.                         Str(ComPort^.Value + 1,TmpStr);
  617.                         ModeParam:='COM'+TmpStr+':9600,N,8,1';
  618.                         DmParam:=DmParam+TmpStr+' ';
  619.                         if (Monsters^.Value and 1) = 1 then
  620.                             DmParam:=DmParam+'-nomonsters ';
  621.                         if (Monsters^.Value and 2) = 2 then
  622.                             DmParam:=DmParam+'-deathmatch ';
  623.                      end
  624.                     else
  625.                         Param1:='';
  626.                     Dialog2^.Done;
  627.                     Dispose(Dialog2);
  628.                     Param1:=Param1+DmParam;
  629.                 end;
  630.                 Param1:=Param1+DmParam;
  631.                 Param2:=ModeParam;
  632.                 Dialog1^.Done;
  633.                 Dispose(Dialog1);
  634.               end;
  635.         end;
  636.     end;
  637.  
  638. Constructor TMyApp.Init;
  639.  
  640.     var     Regs:Registers;
  641.             E:TEvent;
  642.             AboutBox:PWindow;
  643.             R:TRect;
  644.             ch:char;
  645.  
  646.     begin
  647.         TApplication.Init;
  648.         if not Debug then begin
  649.             R.Assign(28,6,52,15);
  650.             AboutBox:=New(PWindow,Init(R,'',0));
  651.             With AboutBox^ do begin
  652.                 Flags:=0;
  653.                 R.Assign(4,2,21,3);
  654.                 Insert(New(PStaticText,Init(R,'DOOM! Front End')));
  655.                 R.Assign(11,4,13,5);
  656.                 Insert(New(PStaticText,Init(R,'by')));
  657.                 R.Assign(4,6,21,7);
  658.                 Insert(New(PStaticText,Init(R,'Jackson Software')));
  659.             end;
  660.             Desktop^.Insert(AboutBox);
  661.             delay(1000);
  662.             Desktop^.Delete(AboutBox);
  663.             AboutBox^.Done;
  664.         end;
  665.         Regs.ax:=$7A00;
  666.         Intr($2F,Regs);
  667.         if Regs.al <> $FF then
  668.             DisableCommands([cmIPXMenu]);
  669.         while keypressed do
  670.             ch:=ReadKey;
  671.         E.What:=evKeyDown;
  672.         E.Command:=evKeyDown;
  673.         E.KeyCode:=kbAltG;
  674.         PutEvent(E);
  675.     end;
  676.  
  677. Procedure TMyApp.Idle;
  678.  
  679.     begin
  680.         Inherited Idle;
  681. {        Gotoxy(65,1);
  682.         writeln(MemAvail);}
  683.     end;
  684.  
  685. Procedure TMyApp.HandleEvent(Var Event:TEvent);
  686.  
  687.     begin
  688.         TApplication.HandleEvent(Event);
  689.         if Event.What=evCommand then begin
  690.             Case Event.Command of
  691.                 cmOnePlayerMenu:OnePlayerMenu;
  692.                 cmSerialMenu:SerialMenu;
  693.                 cmIPXMenu:IPXMenu;
  694.                 cmModemMenu:ModemMenu;
  695.                 cmViewMaps:ViewMaps;
  696.             else
  697.                 exit;
  698.             end;
  699.             ClearEvent(Event);
  700.         end;
  701.     end;
  702.  
  703. procedure TMyApp.InitMenuBar;
  704.  
  705.     var    r:TRect;
  706.  
  707.     begin
  708.         GetExtent(r);
  709.         R.B.Y:=1;
  710.         MenuBar:=New(PMenuBar,Init(r,NewMenu(
  711.             NewSubMenu('~G~ames',hcNoContext,NewMenu(
  712.                 NewItem('~O~ne Player','',0,cmOnePlayerMenu,hcNoContext,
  713.                 NewItem('~S~erial Link','',0,cmSerialMenu,hcNoContext,
  714.                 NewItem('~I~PX Network','',0,cmIPXMenu,hcNoContext,
  715.                 NewItem('~M~odem Link','',0,cmModemMenu,hcNoContext,
  716.                 Nil))))),
  717.             NewSubMenu('~V~iewers',hcNoContext,NewMenu(
  718.                 NewItem('~M~aps','',0,cmViewMaps,hcNoContext,
  719.                 Nil)),
  720.             Nil)))));
  721.     end;
  722.  
  723. Function TMyApp.GetPalette:PPalette;
  724.  
  725.     const MyBackColor:TPalette=CColor;
  726.  
  727.     var    t:integer;
  728.  
  729.     begin
  730.         for t:=8 to 15 do
  731.             MyBackColor[t+24]:=MyBackColor[t];
  732.         MyBackColor[46]:=#16;
  733.         MyBackColor[50]:=#15;
  734.         MyBackColor[42]:=#$2F;
  735.         MyBackColor[47]:=#23;
  736.         MyBackColor[48]:=#31;
  737.         MyBackColor[49]:=#30;
  738.         GetPalette:=@MyBackColor;
  739.     end;
  740.  
  741. Procedure TMyApp.RunDoom(GameType:integer;Params:string);
  742.  
  743.     var     RunName:String;
  744.             R:TRect;
  745.             e:TEvent;
  746.             S,Rn:array[0..79] of char;
  747.             InfoBox:PWindow;
  748.             SwapErr:word;
  749.  
  750.     begin
  751.         case GameType of
  752.             gtNormal:RunName:='DOOM.EXE';
  753.             gtModem,gtSerial,gtDirLinkModem:RunName:='SERSETUP.EXE';
  754.             gtIPXNet:RunName:='IPXSETUP.EXE';
  755.             gtSetMode:RunName:='MODE.COM';
  756.         end;
  757.         if GameType=gtSetMode then begin
  758.             StrPCopy(Rn,RunName);
  759.             FileSearch(S,Rn,GetEnvVar('Path'));
  760.             RunName:=strpas(s);
  761.             R.Assign(20,8,60,11);
  762.             InfoBox:=New(PWindow, Init(R,'',0));
  763.             R.Assign(5,1,35,2);
  764.             InfoBox^.Insert(New(PStaticText, Init(R,'Initializing: '+Params)));
  765.             InfoBox^.Flags:=0;
  766.             DeskTop^.Insert(InfoBox);
  767.             if RunName<>'' then begin
  768.                 DoneDosMem;
  769.                 SwapVectors;
  770.                 Exec(RunName,Params+' >NUL');
  771.                 SwapVectors;
  772.                 InitDosMem;
  773.                 DeskTop^.Delete(InfoBox);
  774.                 InfoBox^.Done;
  775.              end
  776.             else begin
  777.                 DeskTop^.Delete(InfoBox);
  778.                 InfoBox^.Done;
  779.                 R.Assign(20,8,60,11);
  780.                 InfoBox:=New(PWindow, Init(R,'**Error**',0));
  781.                 R.Assign(5,1,35,2);
  782.                 InfoBox^.Insert(New(PStaticText, Init(R,'Could Not Locate MODE.COM')));
  783.                 InfoBox^.Flags:=0;
  784.                 DeskTop^.Insert(InfoBox);
  785.                 delay(2000);
  786.                 DeskTop^.Delete(InfoBox);
  787.                 InfoBox^.Done;
  788.             end
  789.          end {If GameType}
  790.         else begin
  791.             DoneSysError;
  792.             DoneEvents;
  793.             DoneVideo;
  794.             DoneDosMem;
  795.             if Debug then
  796.                 writeln(RunName,' ',Params);
  797.         {$IFNDEF DPMI}
  798.             SwapErr:=ExecPrg(RunName+' '+Params);
  799.         {$ELSE}
  800.             Exec(RunName,Params);
  801.         {$ENDIF}
  802.             delay(500);
  803.             InitDosMem;
  804.             InitVideo;
  805.             InitEvents;
  806.             InitSysError;
  807.             Redraw;
  808.             E.What:=evKeyDown;
  809.             E.Command:=evKeyDown;
  810.             E.KeyCode:=kbAltG;
  811.             PutEvent(E);
  812.         end;
  813.     end;
  814.  
  815. Procedure TMyApp.OnePlayerMenu;
  816.  
  817.     var    DmParam,TmpStr:String;
  818.  
  819.     begin
  820.         SetMenuData(1,DmParam,TmpStr);
  821.         if DmParam<>'' then
  822.             RunDoom(gtNormal,DmParam);
  823.     end;
  824.  
  825.  
  826. Procedure TMyApp.SerialMenu;
  827.  
  828.     var    ModeParam,DmParam:String;
  829.  
  830.     begin
  831.         SetMenuData(2,DmParam,ModeParam);
  832.         if DmParam<>'' then begin
  833.             RunDoom(gtSetMode,ModeParam);
  834.             RunDoom(gtSerial,DmParam);
  835.       end;
  836.     end;
  837.  
  838. Procedure TMyApp.IPXMenu;
  839.  
  840.     var    DmParam,TmpStr:String;
  841.  
  842.     begin
  843.         SetMenuData(3,DmParam,TmpStr);
  844.         if DmParam<>'' then
  845.             RunDoom(gtIPXNet,DmParam);
  846.     end;
  847.  
  848. Procedure TMyApp.ModemMenu;
  849.  
  850.     var    ModeParam,DmParam:String;
  851.  
  852.     begin
  853.         SetMenuData(4,DmParam,ModeParam);
  854.         if DmParam<>'' then begin
  855.             RunDoom(gtSetMode,ModeParam);
  856.             RunDoom(gtModem,DmParam);
  857.         end;
  858.     end;
  859.  
  860. Procedure TMyApp.ViewMaps;
  861.  
  862.     var    r:TRect;
  863.             Episode,Control:integer;
  864.             SelGame,Monsters,SelSkill:PCluster;
  865.             SelLevel:PRadioButtons;
  866.             Dialog1,Dialog2:PDialog;
  867.             Dialog3:PFileDialog;
  868.             TmpStr:String;
  869.             ExtFile,WadName:PathStr;
  870.             DmParam:ObjNameStr;
  871.             ViewerMask,ThingMask:word;
  872.             LevelNames:LevelNameArray;
  873.  
  874.     begin
  875.         R.Assign(2,1,30,5);
  876.         SelGame:=New(PRadioButtons, Init(R,
  877.           NewSItem('~K~nee-Deep In The Dead',
  878.           NewSItem('~S~hores Of Hell',
  879.           NewSItem('~I~nferno!',
  880.           NewSItem('~E~xternal Map',
  881.           nil))))));
  882.         R.Assign(20,7,60,16);
  883.         Dialog1:=New(PDialog,Init(r,'Episodes'));
  884.         with Dialog1^ do begin
  885.             R.Assign(5,6,15,8);
  886.             Insert(New(PButton,Init(R,'~O~k',cmOk,bfDefault)));
  887.             R.Assign(25,6,35,8);
  888.             Insert(New(PButton,Init(R,'~C~ancel',cmCancel,bfNormal)));
  889.             Insert(SelGame);
  890.         end;
  891.         Control:=Desktop^.ExecView(Dialog1);
  892.         Episode:=SelGame^.Value + 1;
  893.         ExtFile:='DOOM.WAD';
  894.         if Episode=4 then begin
  895.             Dialog3:=New(PFileDialog,Init('*.WAD','Load External WAD','WAD Files',fdOpenButton,100));
  896.             Control:=ExecView(Dialog3);
  897.             if Control=cmFileOpen then
  898.                 Control:=cmOk;
  899.             if Control=cmOK then begin
  900.                 ExtFile:=Dialog3^.Directory^+(Dialog3^.FileName^.Data^);
  901.                 R.Assign(2, 1, 28, 10);
  902.                 FindLevelNames(ExtFile,LevelNames,R,SelLevel);
  903.                 if WadResult<>wrOk then
  904.                     exit;
  905.                 if LevelNames[1]='' then begin
  906.                     MessageBox('No valid level entries found.',Nil,mfError+mfOkButton);
  907.                     Control:=cmCancel;
  908.                 end;
  909.                 Episode:=4;
  910.             end;
  911.             Dialog3^.Done;
  912.             Dispose(Dialog3);
  913.         end;
  914.         if Control=cmOK then begin
  915.             R.Assign(30, 6, 55, 11);
  916.             SelSkill:=New(PRadioButtons, Init(R,
  917.               NewSItem('~I~''m too young to die',
  918.               NewSItem('~H~ey Not too Rough',
  919.               NewSItem('H~u~rt Me Plenty',
  920.               NewSItem('U~l~tra Violence',
  921.               NewSItem('~N~ightmare!',
  922.               nil)))))));
  923.             R.Assign(30, 1, 50, 5);
  924.             Monsters:=New(PCheckBoxes, Init(R,
  925.               NewSItem('Show ~M~onsters',
  926.               NewSItem('Show ~W~eapons',
  927.               NewSItem('Show ~G~oodies',
  928.               NewSItem('Muti~P~layer',
  929.               nil))))));
  930.             R.Assign(2, 1, 28, 10);
  931.             SetLevelData(R,SelLevel,Episode);
  932.             R.Assign(11,2,69,16);
  933.             Dialog2:=New(PDialog,Init(r,'Map Viewer Options'));
  934.             with Dialog2^ do begin
  935.                 Insert(Monsters);
  936.                 Insert(SelSkill);
  937.                 R.Assign(15,11,25,13);
  938.                 Insert(New(PButton,Init(R,'~C~ancel',cmCancel,bfNormal)));
  939.                 R.Assign(2,11,12,13);
  940.                 Insert(New(PButton,Init(R,'~O~k',cmOk,bfDefault)));
  941.                 Insert(SelLevel);
  942.             end;
  943.             Control:=Desktop^.ExecView(Dialog2);
  944.             ViewerMask:=0;
  945.             ThingMask:=0;
  946.             if Control=cmOk then begin
  947.                 if Episode < 4 then begin
  948.                     DmParam:='E M     ';
  949.                     Str(Episode,TmpStr);
  950.                     DmParam[2]:=TmpStr[1];
  951.                     Str(SelLevel^.Value + 1,TmpStr);
  952.                     DmParam[4]:=TmpStr[1];
  953.                  end
  954.                 else begin
  955.                     TmpStr:=LevelNames[SelLevel^.Value + 1]+'        ';
  956.                     move(TmpStr[1],DmParam[1],8);
  957.                 end;
  958.                 if (Monsters^.Value and 1) = 1 then
  959.                     ViewerMask:=ViewerMask or 1;
  960.                 if (Monsters^.Value and 2) = 2 then
  961.                     ViewerMask:=ViewerMask or 4;
  962.                 if (Monsters^.Value and 4) = 4 then
  963.                     ViewerMask:=ViewerMask or 2;
  964.                 if (Monsters^.Value and 8) = 8 then
  965.                     ViewerMask:=ViewerMask or 64;
  966.                 if (SelSkill^.Value=3) or (SelSkill^.Value=4) then
  967.                     ViewerMask:=ViewerMask or 32;
  968.                 if SelSkill^.Value=2 then
  969.                     ViewerMask:=ViewerMask or 16;
  970.                 if (SelSkill^.Value=0) or (SelSkill^.Value=1) then
  971.                     ViewerMask:=ViewerMask or 8;
  972.                 DoneSysError;
  973.                 DoneEvents;
  974.                 DoneVideo;
  975.                 TerminateOnWadError:=True;
  976.                 WadName:=ExtFile;
  977.                 ViewMap(WadName,DmParam,ViewerMask,0);
  978.                 TerminateOnWadError:=False;
  979.                 InitVideo;
  980.                 InitEvents;
  981.                 InitSysError;
  982.                 Redraw;
  983.             end;
  984.             Dialog2^.Done;
  985.             Dispose(Dialog2);
  986.         end;
  987.         Dialog1^.Done;
  988.         Dispose(Dialog1);
  989.     end;
  990.  
  991. begin
  992. {$IFNDEF DFE}
  993.     writeln('Please include the conditional symbol DFE in you compiler options');
  994.    writeln('and recompile DFE!');
  995.    halt;
  996. {$ENDIF}
  997. {$IFNDEF DPMI}
  998.     if (ParamStr(1)='/NOEMS') or (ParamStr(1)='/noems') then
  999.         AllowEMSswap:=False;
  1000.     if (ParamStr(1)='-NOEMS') or (ParamStr(1)='-noems') then
  1001.         AllowEMSswap:=False;
  1002.     if not AllowEMSswap then
  1003.         writeln('EMS_Swap: disabled');
  1004.     delay(1000);
  1005. {$ENDIF}
  1006.     TerminateOnWadError:=False;
  1007. {$IFDEF DPMI}
  1008.     writeln;
  1009.     write('================================>>WARNING<<=====================================');
  1010.     writeln('SysDPMI_Init:');
  1011.     writeln;
  1012.     writeln('DFE is not designed to be compiled under DPMI!  You will not be able to');
  1013.     writeln('successfully launch DOOM with the current system configuration.  Please');
  1014.     writeln('recompile for real mode before attempting to execute DOOM.');
  1015.     writeln;
  1016.     writeln('                          Press ENTER to continue.');
  1017.     write('================================================================================');
  1018.     readln;
  1019. {$ENDIF}
  1020.     writeln('SysApplication_Init');
  1021.     delay(500);
  1022.     MyApp.Init;
  1023.     MyApp.Run;
  1024.     MyApp.Done;
  1025. end.
  1026.