home *** CD-ROM | disk | FTP | other *** search
/ 1,001 Nights of Doom / 1001NightsOfDoom1995wickedSensations.iso / modem / ser6_src.zip / DOOMNET.C < prev    next >
C/C++ Source or Header  |  1994-11-16  |  8KB  |  320 lines

  1. // doomnet.c
  2. // Created by Id Software for SERSETUP.EXE, 1993, 1994.
  3. // Hacked by Russell Gilbert and others SER4.EXE, SER5.EXE, and SER6.EXE 1994.
  4. // Hacked by Paul T. Hermann for SER5.EXE, SER6.EXE 1994.
  5. //
  6. // Compiled under Borland C++ 3.1 using the Compact Memory module
  7. // Using 80386 instruction set and 80387 emualation support
  8. // Optimizations for speed enabled
  9. //
  10.  
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include <string.h>
  14. #include <process.h>
  15. #include <dos.h>
  16. #include <conio.h>
  17. #include "doomnet.h"
  18.  
  19. doomcom_t    doomcom;
  20. int             vectorishooked=0;
  21. void interrupt (*olddoomvect) ();
  22.  
  23. extern int loadgame;
  24. extern char config [80+1];
  25. extern char devparm [256+1];
  26. extern char doomexe [12+1];
  27. extern int nomonsters;
  28. extern int respawn;
  29. extern int episode;
  30. extern int map;
  31. extern int skill;
  32. extern int deathmatch;
  33. extern int altdeath;
  34. extern int doom2;
  35.  
  36.  
  37. /*
  38. =============
  39. =
  40. = LaunchDOOM
  41. =
  42. These fields in doomcom should be filled in before calling:
  43.  
  44.     short    numnodes;        // console is allways node 0
  45.     short    ticdup;            // 1 = no duplication, 2-5 = dup for slow nets
  46.     short    extratics;        // 1 = send a backup tic in every packet
  47.  
  48.     short    consoleplayer;    // 0-3 = player number
  49.     short    numplayers;        // 1-4
  50.     short    angleoffset;    // 1 = left, 0 = center, -1 = right
  51.     short    drone;            // 1 = drone
  52. =============
  53. */
  54.  
  55. void LaunchDOOM1_2 (void)
  56. {
  57.     char    *newargs[99];
  58.     char    adrstring[10];
  59.     long  flatadr;
  60.     char epstr [2];
  61.     char mapstr [2];
  62.     char skstr [2];
  63.     char lostr [2];
  64.     int argnum = 0;
  65.     int i;
  66.     int prev;
  67.     char devstr [256+1];
  68.  
  69.  
  70.     /* LaunchDOOM specifically for Doom v1.2 and below (no response files) */
  71. // prepare for DOOM
  72.     if ( !vectorishooked )            //check if vector is already hooked
  73.     {
  74.         olddoomvect = getvect (doomcom.intnum);
  75.         setvect (doomcom.intnum,NetISR);
  76.         vectorishooked = 1;
  77.     }
  78.  
  79. // build the argument list for DOOM, adding "-net" and the address of doomcom.
  80.  
  81. /* Copy our program name first - isn't necessary, but doom relies on it */
  82.     newargs [argnum++] = _argv [0];
  83.  
  84.     newargs [argnum++] = "-devparm";
  85.     if (deathmatch)
  86.         newargs [argnum++] = "-deathmatch";
  87.     if (altdeath)
  88.         newargs [argnum++] = "-altdeath";
  89.     if (nomonsters)
  90.         newargs [argnum++] = "-nomonsters";
  91.     if (respawn)
  92.         newargs [argnum++] = "-respawn";
  93.     if (map != -1)
  94.     {
  95. //        if (devparm [0] == EOS)
  96. //            newargs [argnum++] = "-devparm";
  97.         newargs [argnum++] = "-warp";
  98.         sprintf (epstr, "%d", episode == -1 ? 1 : episode);
  99.         if (!doom2)
  100.             newargs [argnum++] = epstr;
  101.         sprintf (mapstr, "%d", map);
  102.         newargs [argnum++] = mapstr;
  103.     }
  104.     else if( (episode != -1) && (!doom2) )
  105.     {
  106.             newargs [argnum++] = "-episode";
  107.             sprintf (epstr, "%d", episode);
  108.             newargs [argnum++] = epstr;
  109.     }
  110.     if (skill != -1)
  111.     {
  112.         newargs [argnum++] = "-skill";
  113.         sprintf (skstr, "%d", skill);
  114.         newargs [argnum++] = skstr;
  115.     }
  116.     if (loadgame != -1)
  117.     {
  118.         newargs [argnum++] = "-loadgame";
  119.         sprintf (lostr, "%d", loadgame);
  120.         newargs [argnum++] = lostr;
  121.     }
  122.     if (config [0] != EOS)
  123.     {
  124.         newargs [argnum++] = "-config";
  125.         newargs [argnum++] = config;
  126.     }
  127.  
  128.     if (devparm [0] != EOS)
  129.     {
  130. //        newargs [argnum++] = "-devparm";
  131.         /* Copy all devparm args */
  132.         strcpy (devstr, devparm);
  133.         prev = 0;
  134.         i = -1;
  135.         while (devstr [++i] != EOS)
  136.         {
  137.             if (devstr [i] == ' ')
  138.             {
  139.                 devstr [i] = EOS;
  140.                 newargs [argnum++] = &devstr [prev];
  141.                 prev = i+1;
  142.             }
  143.         }
  144.         newargs [argnum++] = &devstr [prev];
  145.     }
  146.     newargs [argnum++] = "-net";
  147.  
  148.     /* Add address of doomcom structure */
  149.     flatadr = (long)_DS*16 + (unsigned)&doomcom;
  150.     sprintf (adrstring,"%lu",flatadr);
  151.     newargs [argnum++] = adrstring;
  152.  
  153.     newargs [argnum] = NULL;
  154.  
  155.     printf ("About to launch doom.exe -- Passing these arguments:\n");
  156.     for (i = 0; i < argnum; i++)
  157.         printf ("  arg %d = %s\n", i, newargs [i]);
  158.     printf ("  player = %d\n", doomcom.consoleplayer);
  159.     printf ("  extratics = %d\n", doomcom.extratics);
  160.     printf ("\nPress ESC to abort, or any other key to continue...");
  161.     if (getch () == ESC)
  162.     {
  163.         printf ("\n\n");
  164.         return;
  165.     }
  166.     if (spawnv  (P_WAIT, doomexe, newargs) == -1)
  167.     {
  168.         textcolor(YELLOW);
  169.         cprintf("\a\r\nAn error occured trying to execute DOOM!!\r\n"
  170.                   "This can be due to a large number of arguments.\r\n"
  171.                   "If this is the case simply shorten the number of options\r\n"
  172.                   "you are passing Doom\r\n");
  173.         textcolor(LIGHTGRAY);
  174.         return;
  175.     }
  176.     printf ("\nReturned from DOOM\n\n");
  177. }
  178.  
  179. void LaunchDOOM (void)
  180. {
  181.     char    adrstring[10];
  182.     long  flatadr;
  183.     int argnum = 0;
  184.     int i;
  185.     int prev;
  186.     char devstr [256+1];
  187.     char  *newargs[5];
  188.     FILE *outfile;
  189.     struct time t;
  190.     char response[9];
  191.     int len;
  192.  
  193.     /* LaunchDOOM for Doom v1.6 and above (uses response files for args) */
  194. // prepare for DOOM
  195.     if ( !vectorishooked )    //check if vector is already hooked
  196.     {
  197.         olddoomvect = getvect (doomcom.intnum);
  198.         setvect (doomcom.intnum,NetISR);
  199.         vectorishooked = 1;
  200.     }
  201.  
  202. // build the argument list for DOOM, adding "-net" and the address of doomcom.
  203.     gettime (&t);
  204.     sprintf(response,"ID%02d%02d%02d", t.ti_hour, t.ti_min, t.ti_sec);
  205.  
  206.     if ( (outfile=fopen( response, "w+t" )) == NULL)
  207.     {
  208.         printf("There is a Major Problem opening a response file./n"
  209.                  "Press any key to return to the main menu.");
  210.         getch();
  211.         return;
  212.     }
  213.  
  214.     /* Copy our program name first - isn't necessary, but doom relies on it */
  215.     newargs [argnum++] = _argv [0];
  216.  
  217.     fprintf(outfile,"-devparm\n");
  218.     if (deathmatch)
  219.         fprintf(outfile,"-deathmatch\n");
  220.     if (altdeath)
  221.         fprintf(outfile,"-altdeath\n");
  222.     if (nomonsters)
  223.         fprintf(outfile,"-nomonsters\n");
  224.     if (respawn)
  225.         fprintf(outfile,"-respawn\n");
  226.     if (map != -1)
  227.     {
  228. //        if (devparm [0] == EOS)
  229. //            fprintf(outfile,"-devparm\n");
  230.         fprintf(outfile,"-warp\n");
  231.         if (!doom2)   // Doom ][ does not have episode
  232.             fprintf(outfile,"%d\n", episode == -1 ? 1 : episode);
  233.         fprintf(outfile,"%d\n", map);
  234.     }
  235.     else if( (episode != -1) && (!doom2) )
  236.     {
  237.             fprintf(outfile,"-episode\n");
  238.             fprintf(outfile,"%d\n", episode);
  239.     }
  240.     if (skill != -1)
  241.     {
  242.         fprintf(outfile,"-skill\n");
  243.         fprintf(outfile,"%d\n",skill);
  244.     }
  245.     if (loadgame != -1)
  246.     {
  247.         fprintf(outfile,"-loadgame\n");
  248.         fprintf(outfile,"%d\n", loadgame);
  249.     }
  250.     if (config [0] != EOS)
  251.     {
  252.         fprintf(outfile,"-config\n");
  253.         fprintf(outfile,"%s\n",config);
  254.     }
  255.  
  256.     if (devparm [0] != EOS)
  257.     {
  258. //        fprintf(outfile,"-devparm\n");
  259.         /* Copy all devparm args */
  260.         strcpy (devstr, devparm);
  261.         prev = 0;
  262.         i = -1;
  263.         while (devstr [++i] != EOS)
  264.         {
  265.             if (devstr [i] == ' ')
  266.             {
  267.                 devstr [i] = EOS;
  268.                 fprintf(outfile,"%s\n", &devstr [prev]);
  269.                 prev = i+1;
  270.             }
  271.         }
  272.         fprintf(outfile,"%s\n", &devstr [prev]);
  273.     }
  274.     fclose(outfile);
  275.     sprintf(newargs [argnum],"@%s",response);
  276.     argnum++;
  277.     newargs [argnum++] = "-net";
  278.  
  279.     /* Add address of doomcom structure */
  280.     flatadr = (long)_DS*16 + (unsigned)&doomcom;
  281.     sprintf (adrstring,"%lu",flatadr);
  282.     newargs [argnum++] = adrstring;
  283.  
  284.     newargs [argnum] = NULL;
  285.  
  286.     if ( (outfile=fopen( response, "rt" )) == NULL)
  287.     {
  288.         printf("There is a Major Problem opening a response file./n"
  289.                  "Press any key to return to the main menu.");
  290.         getch();
  291.         return;
  292.     }
  293.  
  294.     printf ("About to launch doom.exe -- Passing these arguments:\n");
  295.     for (i = 0; i < argnum; i++)
  296.         printf ("arg %d = %s\n", i, newargs [i]);
  297.     printf ("player = %d\n", doomcom.consoleplayer);
  298.     printf ("extratics = %d\n", doomcom.extratics);
  299.     printf ("Response file contents:\n");
  300.     while (fgets (devstr, 81, outfile) != NULL)
  301.     {
  302.         if (devstr [(len = strlen (devstr))-1] == '\n')    /* Get rid of cr at end */
  303.             devstr [len-1] = EOS;
  304.         if (wherex()+len > 80)
  305.             printf("\n");
  306.         printf(" %s",devstr);
  307.     }
  308.     fclose(outfile);
  309.     printf ("\nPress ESC to abort, or any other key to continue...");
  310.     if (getch () == ESC)
  311.     {
  312.         printf ("\n\n");
  313.         remove(response);
  314.         return;
  315.     }
  316.     spawnv(P_WAIT, doomexe, newargs);
  317.     remove( response );
  318.     printf ("\nReturned from DOOM\n\n");
  319. }
  320.