Ejemplo n.º 1
0
//
// FromCurr
//
// Copying files from savepathtemp to savepath
//
void FromCurr(void)
{
    DIR *sp2dir = NULL;
    struct dirent *f = NULL;

    if(!(sp2dir = opendir(savepathtemp)))
        I_Error("FromCurr: Couldn't open dir %s", savepathtemp);

    while((f = readdir(sp2dir)))
    {
        byte *filebuffer  = NULL;
        int   filelen     = 0;
        char *srcfilename = NULL;
        char *dstfilename = NULL;

        // haleyjd: skip "." and ".." without assuming they're the
        // first two entries like the original code did.
        if(!strcmp(f->d_name, ".") || !strcmp(f->d_name, ".."))
            continue;

        // haleyjd: use M_SafeFilePath, NOT sprintf.
        srcfilename = M_SafeFilePath(savepathtemp, f->d_name);
        dstfilename = M_SafeFilePath(savepath,     f->d_name);

        filelen = M_ReadFile(srcfilename, &filebuffer);
        M_WriteFile(dstfilename, filebuffer, filelen);

        Z_Free(filebuffer);
        Z_Free(srcfilename);
        Z_Free(dstfilename);
    }

    closedir(sp2dir);
}
Ejemplo n.º 2
0
//
// FromCurr
//
// Copying files from savepathtemp to savepath
//
void FromCurr(void)
{
    glob_t *glob;

    glob = I_StartGlob(savepathtemp, "*", 0);

    if (glob == NULL)
        I_Error("FromCurr: Couldn't open dir %s", savepathtemp);

    for (;;)
    {
        byte *filebuffer;
        int filelen;
        const char *srcfilename;
        char *dstfilename;

        srcfilename = I_NextGlob(glob);
        if (srcfilename == NULL)
        {
            break;
        }

        dstfilename = M_SafeFilePath(savepath, M_BaseName(srcfilename));

        filelen = M_ReadFile(srcfilename, &filebuffer);
        M_WriteFile(dstfilename, filebuffer, filelen);

        Z_Free(filebuffer);
        Z_Free(dstfilename);
    }

    I_EndGlob(glob);
}
Ejemplo n.º 3
0
//
// SC_OpenFile
//
// Loads a script (from a file). Uses the zone memory allocator for
// memory allocation and de-allocation.
//
void SC_OpenFile (const char *name)
{
	SC_Close ();
	ScriptSize = M_ReadFile (name, (byte **)&ScriptBuffer);
	M_ExtractFileBase (name, ScriptName);
	FreeScript = true;
	SC_PrepareScript ();
}
Ejemplo n.º 4
0
static boolean SV_OpenFile_Hr_v13(const char* filePath)
{
    boolean fileOpened;
#if _DEBUG
    if(saveBuffer)
        Con_Error("SV_OpenFile_Hr_v13: A save state file has already been opened!");
#endif
    fileOpened = 0 != M_ReadFile(filePath, (char**)&saveBuffer);
    if(!fileOpened) return false;
    savePtr = saveBuffer;
    return true;
}
Ejemplo n.º 5
0
void FScanner::OpenFile (const char *name)
{
	BYTE *filebuf;
	int filesize;

	Close ();
	filesize = M_ReadFile (name, &filebuf);
	ScriptBuffer = FString((const char *)filebuf, filesize);
	delete[] filebuf;
	ScriptName = name;	// This is used for error messages so the full file name is preferable
	LumpNum = -1;
	PrepareScript ();
}
Ejemplo n.º 6
0
dboolean P_QuickReadSaveHeader(char* name, char* date,
                               int* thumbnail, int* skill, int* map) {
    int i;
    int size;

    if(M_ReadFile(name, &savebuffer) == -1) {
        return 0;
    }

    save_offset = 0;

    // skip the description field
    for(i = 0; i < SAVESTRINGSIZE; i++) {
        saveg_read8();
    }

    for(i = 0; i < 32; i++) {
        date[i] = saveg_read8();
    }

    size = saveg_read32() / sizeof(int);

    for(i = 0; i < size; i++) {
        thumbnail[i] = saveg_read32();
    }

    // skip password
    for(i = 0; i < 16; i++) {
        saveg_read8();
    }

    *skill  = saveg_read8();
    *map    = saveg_read8();

    Z_Free(savebuffer);

    return 1;
}
Ejemplo n.º 7
0
//
// ToCurr
//
// Copying files from savepath to savepathtemp
//
void ToCurr(void)
{
    DIR *spdir = NULL;
    struct dirent *f = NULL;

    ClearTmp();

    // BUG: Rogue copypasta'd this error message, which is why we don't know
    // the real original name of this function.
    if(!(spdir = opendir(savepath)))
        I_Error("ClearSlot: Couldn't open dir %s", savepath);

    while((f = readdir(spdir)))
    {
        byte *filebuffer  = NULL;
        int   filelen     = 0;
        char *srcfilename = NULL;
        char *dstfilename = NULL;

        if(!strcmp(f->d_name, ".") || !strcmp(f->d_name, ".."))
            continue;

        // haleyjd: use M_SafeFilePath, NOT sprintf.
        srcfilename = M_SafeFilePath(savepath,     f->d_name);
        dstfilename = M_SafeFilePath(savepathtemp, f->d_name);

        filelen = M_ReadFile(srcfilename, &filebuffer);
        M_WriteFile(dstfilename, filebuffer, filelen);

        Z_Free(filebuffer);
        Z_Free(srcfilename);
        Z_Free(dstfilename);
    }

    closedir(spdir);
}
Ejemplo n.º 8
0
dboolean P_ReadSaveGame(char* name) {
    M_ReadFile(name, &savebuffer);
    save_offset = 0;

    saveg_read_header();

    // load a base level
    G_InitNew(gameskill, gamemap);
    G_DoLoadLevel();

    P_UnArchiveMobjs();
    P_UnArchivePlayers();
    P_UnArchiveWorld();
    P_UnArchiveSpecials();
    P_UnArchiveMacros();

    if(!saveg_read_marker(SAVEGAME_EOF)) {
        I_Error("Bad savegame");
    }

    Z_Free(savebuffer);

    return true;
}
Ejemplo n.º 9
0
static void OpenScript(char *name, int type)
{
	SC_Close();
	if (type == LUMP_SCRIPT)
	{                           // Lump script
		ScriptLumpNum = W_GetNumForName(name);
		ScriptBuffer = (char *) W_CacheLumpNum(ScriptLumpNum, PU_STATIC);
		ScriptSize = W_LumpLength(ScriptLumpNum);
		M_StringCopy(ScriptName, name, sizeof(ScriptName));
	}
	else if (type == FILE_ZONE_SCRIPT)
	{                           // File script - zone
		ScriptLumpNum = -1;
		ScriptSize = M_ReadFile(name, (byte **) & ScriptBuffer);
		M_ExtractFileBase(name, ScriptName);
	}
	ScriptPtr = ScriptBuffer;
	ScriptEndPtr = ScriptPtr + ScriptSize;
	sc_Line = 1;
	sc_End = false;
	ScriptOpen = true;
	sc_String = StringBuffer;
	AlreadyGot = false;
}
Ejemplo n.º 10
0
//
// ToCurr
//
// Copying files from savepath to savepathtemp
//
void ToCurr(void)
{
    glob_t *glob;

    ClearTmp();

    // BUG: Rogue copypasta'd this error message, which is why we don't know
    // the real original name of this function.
    glob = I_StartGlob(savepath, "*", 0);
    if (glob == NULL)
        I_Error("ClearSlot: Couldn't open dir %s", savepath);

    for (;;)
    {
        byte *filebuffer;
        int filelen;
        const char *srcfilename;
        char *dstfilename;

        srcfilename = I_NextGlob(glob);
        if (srcfilename == NULL)
        {
            break;
        }

        dstfilename = M_SafeFilePath(savepathtemp, M_BaseName(srcfilename));

        filelen = M_ReadFile(srcfilename, &filebuffer);
        M_WriteFile(dstfilename, filebuffer, filelen);

        Z_Free(filebuffer);
        Z_Free(dstfilename);
    }

    I_EndGlob(glob);
}
Ejemplo n.º 11
0
static void FindResponseFile (void)
{
  int i;

  for (i = 1;i < myargc;i++)
    if (myargv[i][0] == '@')
      {
        int  size;
        int  index;
	int indexinfile;
        byte *file = NULL;
        const char **moreargs = malloc(myargc * sizeof(const char*));
        const char **newargv;
        // proff 04/05/2000: Added for searching responsefile
        char fname[PATH_MAX+1];

        strcpy(fname,&myargv[i][1]);
        AddDefaultExtension(fname,".rsp");

        // READ THE RESPONSE FILE INTO MEMORY
        // proff 04/05/2000: changed for searching responsefile
        // cph 2002/08/09 - use M_ReadFile for simplicity
	size = M_ReadFile(fname, &file);
        // proff 04/05/2000: Added for searching responsefile
        if (size < 0)
        {
          strcat(strcpy(fname,I_DoomExeDir()),&myargv[i][1]);
          AddDefaultExtension(fname,".rsp");
	  size = M_ReadFile(fname, &file);
        }
        if (size < 0)
        {
            /* proff 04/05/2000: Changed from LO_FATAL
             * proff 04/05/2000: Simply removed the exit(1);
       * cph - made fatal, don't drop through and SEGV
       */
            I_Error("No such response file: %s",fname);
        }
        //jff 9/3/98 use logical output routine
        lprintf(LO_CONFIRM,"Found response file %s\n",fname);
        // proff 04/05/2000: Added check for empty rsp file
        if (size<=0)
        {
	  int k;
          lprintf(LO_ERROR,"\nResponse file empty!\n");

	  newargv = calloc(sizeof(char *),MAXARGVS);
	  newargv[0] = myargv[0];
          for (k = 1,index = 1;k < myargc;k++)
          {
            if (i!=k)
              newargv[index++] = myargv[k];
          }
          myargc = index; myargv = newargv;
          return;
        }

        // KEEP ALL CMDLINE ARGS FOLLOWING @RESPONSEFILE ARG
	memcpy((void *)moreargs,&myargv[i+1],(index = myargc - i - 1) * sizeof(myargv[0]));

	{
	  const char *firstargv = myargv[0];
	  newargv = calloc(sizeof(char *),MAXARGVS);
	  newargv[0] = firstargv;
	}

        {
	  byte *infile = file;
	  indexinfile = 0;
	  indexinfile++;  // SKIP PAST ARGV[0] (KEEP IT)
	  do {
	    while (size > 0 && isspace(*infile)) { infile++; size--; }
	    if (size > 0) {
	      char *s = malloc(size+1);
	      char *p = s;
	      int quoted = 0; 

	      while (size > 0) {
		// Whitespace terminates the token unless quoted
		if (!quoted && isspace(*infile)) break;
		if (*infile == '\"') {
		  // Quotes are removed but remembered
		  infile++; size--; quoted ^= 1; 
		} else {
		  *p++ = *infile++; size--;
		}
	      }
	      if (quoted) I_Error("Runaway quoted string in response file");

	      // Terminate string, realloc and add to argv
	      *p = 0;
	      newargv[indexinfile++] = realloc(s,strlen(s)+1);
	    }
	  } while(size > 0);
	}
	free(file);

	memcpy((void *)&newargv[indexinfile],moreargs,index*sizeof(moreargs[0]));
	free((void *)moreargs);

        myargc = indexinfile+index; myargv = newargv;

        // DISPLAY ARGS
        //jff 9/3/98 use logical output routine
        lprintf(LO_CONFIRM,"%d command-line args:\n",myargc);
	for (index=1;index<myargc;index++)
	  //jff 9/3/98 use logical output routine
          lprintf(LO_CONFIRM,"%s\n",myargv[index]);
        break;
      }
}
Ejemplo n.º 12
0
void G_PlayDemo(const char* name) {
    int i;
    int p;
    char filename[256];

    gameaction = ga_nothing;
    endDemo = false;

    p = M_CheckParm("-playdemo");
    if(p && p < myargc-1) {
        // 20120107 bkw: add .lmp extension if missing.
        if(dstrrchr(myargv[p+1], '.')) {
            dstrcpy(filename, myargv[p+1]);
        }
        else {
            dsprintf(filename, "%s.lmp", myargv[p+1]);
        }

        CON_DPrintf("--------Reading demo %s--------\n", filename);
        if(M_ReadFile(filename, &demobuffer) == -1) {
            gameaction = ga_exitdemo;
            return;
        }

        demo_p = demobuffer;
    }
    else {
        if(W_CheckNumForName(name) == -1) {
            gameaction = ga_exitdemo;
            return;
        }

        CON_DPrintf("--------Playing demo %s--------\n", name);
        demobuffer = demo_p = W_CacheLumpName(name, PU_STATIC);
    }
    
    if(strncmp((char*)demo_p, "DM64", 4)) {
        I_Error("G_PlayDemo: Mismatched demo header");
        return;
    }

    G_SaveDefaults();

    demo_p++;
    demo_p++;
    demo_p++;
    demo_p++;
    demo_p++;

    startskill      = *demo_p++;
    startmap        = *demo_p++;
    deathmatch      = *demo_p++;
    respawnparm     = *demo_p++;
    respawnitem     = *demo_p++;
    fastparm        = *demo_p++;
    nomonsters      = *demo_p++;
    consoleplayer   = *demo_p++;
    
    rngseed  = *demo_p++ & 0xff;
    rngseed <<= 8;
    rngseed += *demo_p++ & 0xff;
    rngseed <<= 8;
    rngseed += *demo_p++ & 0xff;
    rngseed <<= 8;
    rngseed += *demo_p++ & 0xff;
    
    gameflags  = *demo_p++ & 0xff;
    gameflags <<= 8;
    gameflags += *demo_p++ & 0xff;
    gameflags <<= 8;
    gameflags += *demo_p++ & 0xff;
    gameflags <<= 8;
    gameflags += *demo_p++ & 0xff;
    
    compatflags  = *demo_p++ & 0xff;
    compatflags <<= 8;
    compatflags += *demo_p++ & 0xff;
    compatflags <<= 8;
    compatflags += *demo_p++ & 0xff;
    compatflags <<= 8;
    compatflags += *demo_p++ & 0xff;

    for(i = 0; i < MAXPLAYERS; i++) {
        playeringame[i] = *demo_p++;
    }

    G_InitNew(startskill, startmap);

    if(playeringame[1]) {
        netgame = true;
        netdemo = true;
    }

    precache = true;
    usergame = false;
    demoplayback = true;

    G_RunGame();
    iwadDemo = false;
}
Ejemplo n.º 13
0
void SV_v19_LoadGame(char *savename)
{
	int     length;
	int     i;
	int     a, b, c;
	char    vcheck[VERSIONSIZE];

	length = M_ReadFile(savename, &savebuffer);
	// Skip the description field.
	save_p = savebuffer + SAVESTRINGSIZE;
	// Check version.
	memset(vcheck, 0, sizeof(vcheck));
	sprintf(vcheck, "version %i", SAVE_VERSION);
	if(strcmp(save_p, vcheck))
	{
		int     saveVer;

		sscanf(save_p, "version %i", &saveVer);
		if(saveVer >= SAVE_VERSION_BASE)
		{
			// Must be from the wrong game.
			Con_Message("Bad savegame version.\n");
			return;
		}
		// Just give a warning.
		Con_Message("Savegame ID '%s': incompatible?\n", save_p);
	}
	save_p += VERSIONSIZE;

	gameskill = *save_p++;
	gameepisode = *save_p++;
	gamemap = *save_p++;
	for(i = 0; i < 4; i++)
		players[i].plr->ingame = *save_p++;

	// Load a base level.
	G_InitNew(gameskill, gameepisode, gamemap);

	// get the times 
	a = *save_p++;
	b = *save_p++;
	c = *save_p++;
	leveltime = (a << 16) + (b << 8) + c;

	// dearchive all the modifications
	P_v19_UnArchivePlayers();
	P_v19_UnArchiveWorld();
	P_v19_UnArchiveThinkers();
	P_v19_UnArchiveSpecials();

	if(*save_p != 0x1d)
		Con_Error
			("SV_v19_LoadGame: Bad savegame (consistency test failed!)\n");

	// done 
	Z_Free(savebuffer);
	savebuffer = NULL;

	// Spawn particle generators.
	R_SetupLevel("", DDSLF_AFTER_LOADING);
}