Exemplo n.º 1
0
// Save a whole buffer to disk
unsigned int j1FileSystem::Save(const char* file, const char* buffer, unsigned int size) const
{
	unsigned int ret = 0;

	PHYSFS_file* fs_file = PHYSFS_openWrite(file);

	if(fs_file != NULL)
	{
		unsigned int written = PHYSFS_write(fs_file, (const void*)buffer, 1, size);
		if(written != size)
			LOG("File System error while writing to file %s: %s\n", file, PHYSFS_getLastError());
		else
			ret = written;

		if(PHYSFS_close(fs_file) == 0)
			LOG("File System error while closing file %s: %s\n", file, PHYSFS_getLastError());
	}
	else
		LOG("File System error while opening file %s: %s\n", file, PHYSFS_getLastError());

	return ret;
}
Exemplo n.º 2
0
bool physfsFile::Write(Bit8u * data,Bit16u * size) {
	if ((this->flags & 0xf) == OPEN_READ) { // check if file opened in read-only mode
		DOS_SetError(DOSERR_ACCESS_DENIED);
		return false;
	}
	if (last_action==READ) prepareWrite();
	last_action=WRITE;
	if (*size==0) {
		if (PHYSFS_tell(fhandle) == 0) {
			PHYSFS_close(PHYSFS_openWrite(pname));
            return false;
			//LOG_MSG("Truncate %s (%s)",name,PHYSFS_getLastError());
		} else {
			LOG_MSG("PHYSFS TODO: truncate not yet implemented (%s at %lld)",pname,PHYSFS_tell(fhandle));
			return false;
		}
	} else {
		PHYSFS_sint64 mysize = PHYSFS_write(fhandle,data,1,(PHYSFS_uint32)*size);
		//LOG_MSG("Wrote %i bytes (wanted %i) at %i of %s (%s)",(int)mysize,(int)*size,(int)PHYSFS_tell(fhandle),name,PHYSFS_getLastError());
		*size = (Bit16u)mysize;
		return true;
	}
}
Exemplo n.º 3
0
/** Finishes the enemy recording and moves it to the specified file. 
 */
void finish(glm::dvec3 end_position, const char * target_file) {
    std::vector<point3f> record;
    for (glm::dvec3 p : old_position) {
        point3f pt = {(float)p.x,(float)p.y,(float)p.z};
        record.push_back(pt);
    }
    for (int i=1; i<=8; i++) {
        glm::dvec3 p = (
            old_position.back()*(double)(8-i) + 
            old_velocity.back()*(double)((8-i) * i) + 
            end_position*(double)i
        ) / 8.;
        point3f pt = {(float)p.x,(float)p.y,(float)p.z};
        record.push_back(pt);
    }
    PHYSFS_File * w = PHYSFS_openWrite(target_file);
    if (w) {
        PHYSFS_write(w, record.data(), sizeof(point3f), record.size());
        PHYSFS_close(w);
    } else {
        fprintf(stderr, "Failed to write record: %s\n", PHYSFS_getLastError());
    }
}
Exemplo n.º 4
0
bool
vsFile::Record( vsRecord *r )
{
	vsAssert(r != NULL, "Called vsFile::Record with a NULL vsRecord!");

	if ( m_mode == MODE_Write )
	{
		vsString recordString = r->ToString();

		PHYSFS_write( m_file, recordString.c_str(), 1, recordString.size() );

		return true;
	}
	else
	{
		// we want to read the next line into this vsRecord class, so initialise
		// it before we start.
		r->Init();

		return r->Parse(this);
	}

	return false;
}
Exemplo n.º 5
0
// -----------------------------------------------------------------------------
// saves to an already-open file
static int save_mine_data(PHYSFS_File * SaveFile)
{
	int  header_offset, editor_offset, vertex_offset, segment_offset, texture_offset, walls_offset, triggers_offset; //, links_offset;
	int  newseg_verts_offset;
	int  newsegment_offset;
	med_compress_mine();
	warn_if_concave_segments();
	
	for (int i=0;i<NumTextures;i++)
		current_tmap_list[i] = TmapInfo[i].filename;

	//=================== Calculate offsets into file ==================

	header_offset = PHYSFS_tell(SaveFile) + sizeof(mine_fileinfo);
	editor_offset = header_offset + sizeof(mine_header);
	texture_offset = editor_offset + sizeof(mine_editor);
	vertex_offset  = texture_offset + (13*NumTextures);
	segment_offset = vertex_offset + (sizeof(vms_vector)*Num_vertices);
	newsegment_offset = segment_offset + (sizeof(segment)*Num_segments);
	newseg_verts_offset = newsegment_offset + sizeof(segment);
	walls_offset = newseg_verts_offset + (sizeof(vms_vector)*8);
	triggers_offset =	walls_offset + (sizeof(wall)*Num_walls);
// 	doors_offset = triggers_offset + (sizeof(trigger)*Num_triggers);

	//===================== SAVE FILE INFO ========================

	mine_fileinfo.fileinfo_signature=	0x2884;
	mine_fileinfo.fileinfo_version  =   MINE_VERSION;
	mine_fileinfo.fileinfo_sizeof   =   sizeof(mine_fileinfo);
	mine_fileinfo.header_offset     =   header_offset;
	mine_fileinfo.header_size       =   sizeof(mine_header);
	mine_fileinfo.editor_offset     =   editor_offset;
	mine_fileinfo.editor_size       =   sizeof(mine_editor);
	mine_fileinfo.vertex_offset     =   vertex_offset;
	mine_fileinfo.vertex_howmany    =   Num_vertices;
	mine_fileinfo.vertex_sizeof     =   sizeof(vms_vector);
	mine_fileinfo.segment_offset    =   segment_offset;
	mine_fileinfo.segment_howmany   =   Num_segments;
	mine_fileinfo.segment_sizeof    =   sizeof(segment);
	mine_fileinfo.newseg_verts_offset     =   newseg_verts_offset;
	mine_fileinfo.newseg_verts_howmany    =   8;
	mine_fileinfo.newseg_verts_sizeof     =   sizeof(vms_vector);
	mine_fileinfo.texture_offset    =   texture_offset;
	mine_fileinfo.texture_howmany   =   NumTextures;
	mine_fileinfo.texture_sizeof    =   13;  // num characters in a name
	mine_fileinfo.walls_offset		  =	walls_offset;
	mine_fileinfo.walls_howmany	  =	Num_walls;
	mine_fileinfo.walls_sizeof		  =	sizeof(wall);  
	mine_fileinfo.triggers_offset	  =	triggers_offset;
	mine_fileinfo.triggers_howmany  =	Num_triggers;
	mine_fileinfo.triggers_sizeof	  =	sizeof(trigger);  

	// Write the fileinfo
	PHYSFS_write( SaveFile, &mine_fileinfo, sizeof(mine_fileinfo), 1 );

	//===================== SAVE HEADER INFO ========================

	mine_header.num_vertices        =   Num_vertices;
	mine_header.num_segments        =   Num_segments;

	// Write the editor info
	if (header_offset != PHYSFS_tell(SaveFile))
		Error( "OFFSETS WRONG IN MINE.C!" );

	PHYSFS_write( SaveFile, &mine_header, sizeof(mine_header), 1 );

	//===================== SAVE EDITOR INFO ==========================
	mine_editor.current_seg         =   Cursegp;
	mine_editor.newsegment_offset   =   newsegment_offset; 
	mine_editor.newsegment_size     =   sizeof(segment);

	// Next 3 vars added 10/07 by JAS
	mine_editor.Curside             =   Curside;
	if (Markedsegp)
		mine_editor.Markedsegp      =   Markedsegp;
	else									  
		mine_editor.Markedsegp       =   -1;
	mine_editor.Markedside          =   Markedside;
	for (int i=0;i<10;i++)
		mine_editor.Groupsegp[i]	  =	vsegptridx(Groupsegp[i]);
	for (int i=0;i<10;i++)
		mine_editor.Groupside[i]     =	Groupside[i];

	if (editor_offset != PHYSFS_tell(SaveFile))
		Error( "OFFSETS WRONG IN MINE.C!" );
	PHYSFS_write( SaveFile, &mine_editor, sizeof(mine_editor), 1 );

	//===================== SAVE TEXTURE INFO ==========================

	if (texture_offset != PHYSFS_tell(SaveFile))
		Error( "OFFSETS WRONG IN MINE.C!" );
	range_for (auto &i, partial_const_range(current_tmap_list, NumTextures))
		PHYSFS_write(SaveFile, i.data(), i.size(), 1);
	
	//===================== SAVE VERTEX INFO ==========================

	if (vertex_offset != PHYSFS_tell(SaveFile))
		Error( "OFFSETS WRONG IN MINE.C!" );
	PHYSFS_write( SaveFile, Vertices, sizeof(vms_vector), Num_vertices );

	//===================== SAVE SEGMENT INFO =========================

	if (segment_offset != PHYSFS_tell(SaveFile))
		Error( "OFFSETS WRONG IN MINE.C!" );
	PHYSFS_write( SaveFile, &Segments.front(), sizeof(segment), Num_segments );

	//===================== SAVE NEWSEGMENT INFO ======================

	if (newsegment_offset != PHYSFS_tell(SaveFile))
		Error( "OFFSETS WRONG IN MINE.C!" );
	PHYSFS_write( SaveFile, &New_segment, sizeof(segment), 1 );

	if (newseg_verts_offset != PHYSFS_tell(SaveFile))
		Error( "OFFSETS WRONG IN MINE.C!" );
	PHYSFS_write( SaveFile, &Vertices[New_segment.verts[0]], sizeof(vms_vector), 8 );

	//==================== CLOSE THE FILE =============================

	return 0;

}
Exemplo n.º 6
0
static int cmd_stressbuffer(char *args)
{
    int num;

    if (*args == '\"')
    {
        args++;
        args[strlen(args) - 1] = '\0';
    } /* if */

    num = atoi(args);
    if (num < 0)
        printf("buffer must be greater than or equal to zero.\n");
    else
    {
        PHYSFS_File *f;
        int rndnum;

        printf("Stress testing with (%d) byte buffer...\n", num);
        f = PHYSFS_openWrite("test.txt");
        if (f == NULL)
            printf("Couldn't open test.txt for writing: %s.\n", PHYSFS_getLastError());
        else
        {
            int i, j;
            char buf[37];
            char buf2[37];

            if (!PHYSFS_setBuffer(f, num))
            {
                printf("PHYSFS_setBuffer() failed: %s.\n", PHYSFS_getLastError());
                PHYSFS_close(f);
                PHYSFS_delete("test.txt");
                return(1);
            } /* if */

            strcpy(buf, "abcdefghijklmnopqrstuvwxyz0123456789");
            srand((unsigned int) time(NULL));

            for (i = 0; i < 10; i++)
            {
                for (j = 0; j < 10000; j++)
                {
                    PHYSFS_uint32 right = 1 + (PHYSFS_uint32) (35.0 * rand() / (RAND_MAX + 1.0));
                    PHYSFS_uint32 left = 36 - right;
                    if (PHYSFS_write(f, buf, left, 1) != 1)
                    {
                        printf("PHYSFS_write() failed: %s.\n", PHYSFS_getLastError());
                        PHYSFS_close(f);
                        return(1);
                    } /* if */

                    rndnum = 1 + (int) (1000.0 * rand() / (RAND_MAX + 1.0));
                    if (rndnum == 42)
                    {
                        if (!PHYSFS_flush(f))
                        {
                            printf("PHYSFS_flush() failed: %s.\n", PHYSFS_getLastError());
                            PHYSFS_close(f);
                            return(1);
                        } /* if */
                    } /* if */

                    if (PHYSFS_write(f, buf + left, 1, right) != right)
                    {
                        printf("PHYSFS_write() failed: %s.\n", PHYSFS_getLastError());
                        PHYSFS_close(f);
                        return(1);
                    } /* if */

                    rndnum = 1 + (int) (1000.0 * rand() / (RAND_MAX + 1.0));
                    if (rndnum == 42)
                    {
                        if (!PHYSFS_flush(f))
                        {
                            printf("PHYSFS_flush() failed: %s.\n", PHYSFS_getLastError());
                            PHYSFS_close(f);
                            return(1);
                        } /* if */
                    } /* if */
                } /* for */

                if (!PHYSFS_flush(f))
                {
                    printf("PHYSFS_flush() failed: %s.\n", PHYSFS_getLastError());
                    PHYSFS_close(f);
                    return(1);
                } /* if */

            } /* for */

            if (!PHYSFS_close(f))
            {
                printf("PHYSFS_close() failed: %s.\n", PHYSFS_getLastError());
                return(1);  /* oh well. */
            } /* if */

            printf(" ... test file written ...\n");
            f = PHYSFS_openRead("test.txt");
            if (f == NULL)
            {
                printf("Failed to reopen stress file for reading: %s.\n", PHYSFS_getLastError());
                return(1);
            } /* if */

            if (!PHYSFS_setBuffer(f, num))
            {
                printf("PHYSFS_setBuffer() failed: %s.\n", PHYSFS_getLastError());
                PHYSFS_close(f);
                return(1);
            } /* if */

            for (i = 0; i < 10; i++)
            {
                for (j = 0; j < 10000; j++)
                {
                    PHYSFS_uint32 right = 1 + (PHYSFS_uint32) (35.0 * rand() / (RAND_MAX + 1.0));
                    PHYSFS_uint32 left = 36 - right;
                    if (PHYSFS_read(f, buf2, left, 1) != 1)
                    {
                        printf("PHYSFS_read() failed: %s.\n", PHYSFS_getLastError());
                        PHYSFS_close(f);
                        return(1);
                    } /* if */

                    rndnum = 1 + (int) (1000.0 * rand() / (RAND_MAX + 1.0));
                    if (rndnum == 42)
                    {
                        if (!PHYSFS_flush(f))
                        {
                            printf("PHYSFS_flush() failed: %s.\n", PHYSFS_getLastError());
                            PHYSFS_close(f);
                            return(1);
                        } /* if */
                    } /* if */

                    if (PHYSFS_read(f, buf2 + left, 1, right) != right)
                    {
                        printf("PHYSFS_read() failed: %s.\n", PHYSFS_getLastError());
                        PHYSFS_close(f);
                        return(1);
                    } /* if */

                    rndnum = 1 + (int) (1000.0 * rand() / (RAND_MAX + 1.0));
                    if (rndnum == 42)
                    {
                        if (!PHYSFS_flush(f))
                        {
                            printf("PHYSFS_flush() failed: %s.\n", PHYSFS_getLastError());
                            PHYSFS_close(f);
                            return(1);
                        } /* if */
                    } /* if */

                    if (memcmp(buf, buf2, 36) != 0)
                    {
                        printf("readback is mismatched on iterations (%d, %d).\n", i, j);
                        printf("wanted: [");
                        for (i = 0; i < 36; i++)
                            printf("%c", buf[i]);
                        printf("]\n");

                        printf("   got: [");
                        for (i = 0; i < 36; i++)
                            printf("%c", buf2[i]);
                        printf("]\n");
                        PHYSFS_close(f);
                        return(1);
                    } /* if */
                } /* for */

                if (!PHYSFS_flush(f))
                {
                    printf("PHYSFS_flush() failed: %s.\n", PHYSFS_getLastError());
                    PHYSFS_close(f);
                    return(1);
                } /* if */

            } /* for */

            printf(" ... test file read ...\n");

            if (!PHYSFS_eof(f))
                printf("PHYSFS_eof() returned true! That's wrong.\n");

            if (!PHYSFS_close(f))
            {
                printf("PHYSFS_close() failed: %s.\n", PHYSFS_getLastError());
                return(1);  /* oh well. */
            } /* if */

            PHYSFS_delete("test.txt");
            printf("stress test completed successfully.\n");
        } /* else */
    } /* else */

    return(1);
} /* cmd_stressbuffer */
Exemplo n.º 7
0
bool NETlogEntry(const char *str, UDWORD a, UDWORD b)
{
    static const char star_line[] = "************************************************************\n";
    static UDWORD lastframe = 0;
    UDWORD frame = frameGetFrameNumber();
    time_t aclock;
    struct tm *newtime;
    char buf[256];

    if (!pFileHandle)
    {
        return false;
    }

    time(&aclock);					/* Get time in seconds */
    newtime = localtime(&aclock);		/* Convert time to struct */

    if (!newtime || !pFileHandle)
    {
        debug(LOG_ERROR, "Fatal error averted in NETlog");
        return false;
    }

    // check to see if a new frame.
    if (frame != lastframe)
    {
        static const char dash_line[] = "-----------------------------------------------------------\n";

        lastframe = frame;
        PHYSFS_write(pFileHandle, dash_line, strlen(dash_line), 1);
    }

    if (a < NUM_GAME_PACKETS)
        // replace common msgs with txt descriptions
    {
        snprintf(buf, sizeof(buf), "%s \t: %s \t:%d\t\t%s", str, messageTypeToString(a), b, asctime(newtime));
    }
    else if (a == SYNC_FLAG)
    {
        snprintf(buf, sizeof(buf), "%s \t: %d \t(Sync) \t%s", str, b, asctime(newtime));
    }
    else
    {
        snprintf(buf, sizeof(buf), "%s \t:%d \t\t\t:%d\t\t%s", str, a, b, asctime(newtime));
    }

    if (a == NET_PLAYER_LEAVING || a == NET_PLAYER_DROPPED)
    {
        // Write a starry line above NET_LEAVING messages
        PHYSFS_write(pFileHandle, star_line, strlen(star_line), 1);
        PHYSFS_write(pFileHandle, buf, strlen(buf), 1);
        PHYSFS_write(pFileHandle, star_line, strlen(star_line), 1);
    }
    else
    {
        PHYSFS_write(pFileHandle, buf, strlen(buf), 1);
    }

    PHYSFS_flush(pFileHandle);
    return true;
}
Exemplo n.º 8
0
static void con_print_file(const char *const buffer)
{
	char buf[1024];
#if !DXX_CONSOLE_SHOW_TIME_STDOUT
#ifndef _WIN32
	/* Print output to stdout */
	puts(buffer);
#endif

	/* Print output to gamelog.txt */
	if (gamelog_fp)
#endif
	{
#if DXX_CONSOLE_TIME_SHOW_YMD
#define DXX_CONSOLE_TIME_FORMAT_YMD	"%04i-%02i-%02i "
#define DXX_CONSOLE_TIME_ARG_YMD	tm_year, tm_month, tm_day,
#else
#define DXX_CONSOLE_TIME_FORMAT_YMD	""
#define DXX_CONSOLE_TIME_ARG_YMD
#endif
#if DXX_CONSOLE_TIME_SHOW_MSEC
#ifdef _WIN32
#define DXX_CONSOLE_TIME_FORMAT_MSEC	".%03i"
#else
#define DXX_CONSOLE_TIME_FORMAT_MSEC	".%06i"
#endif
#define DXX_CONSOLE_TIME_ARG_MSEC	tm_msec,
#else
#define DXX_CONSOLE_TIME_FORMAT_MSEC	""
#define DXX_CONSOLE_TIME_ARG_MSEC
#endif
		int
			DXX_CONSOLE_TIME_ARG_YMD
			DXX_CONSOLE_TIME_ARG_MSEC
			tm_hour, tm_min, tm_sec;
#ifdef _WIN32
#define DXX_LF	"\r\n"
		SYSTEMTIME st = {};
		GetLocalTime(&st);
#if DXX_CONSOLE_TIME_SHOW_YMD
		tm_year = st.wYear;
		tm_month = st.wMonth;
		tm_day = st.wDay;
#endif
		tm_hour = st.wHour;
		tm_min = st.wMinute;
		tm_sec = st.wSecond;
#if DXX_CONSOLE_TIME_SHOW_MSEC
		tm_msec = st.wMilliseconds;
#endif
#else
#define DXX_LF	"\n"
		struct timeval tv;
		if (gettimeofday(&tv, nullptr))
			tv = {};
		if (const auto lt = localtime(&tv.tv_sec))
		{
#if DXX_CONSOLE_TIME_SHOW_YMD
			tm_year = lt->tm_year;
			tm_month = lt->tm_mon;
			tm_day = lt->tm_mday;
#endif
			tm_hour = lt->tm_hour;
			tm_min = lt->tm_min;
			tm_sec = lt->tm_sec;
#if DXX_CONSOLE_TIME_SHOW_MSEC
			tm_msec = tv.tv_usec;
#endif
		}
		else
		{
#if DXX_CONSOLE_TIME_SHOW_YMD
			tm_year = tm_month = tm_day =
#endif
#if DXX_CONSOLE_TIME_SHOW_MSEC
			tm_msec =
#endif
			tm_hour = tm_min = tm_sec = -1;
		}
#endif
		const size_t len = snprintf(buf, sizeof(buf), DXX_CONSOLE_TIME_FORMAT_YMD "%02i:%02i:%02i" DXX_CONSOLE_TIME_FORMAT_MSEC " %s" DXX_LF, DXX_CONSOLE_TIME_ARG_YMD tm_hour, tm_min, tm_sec, DXX_CONSOLE_TIME_ARG_MSEC buffer);
#if DXX_CONSOLE_SHOW_TIME_STDOUT
#ifndef _WIN32
		fputs(buf, stdout);
#endif
		if (gamelog_fp)
#endif
		{
			PHYSFS_write(gamelog_fp, buf, 1, len);
		}
#undef DXX_LF
#undef DXX_CONSOLE_TIME_ARG_MSEC
#undef DXX_CONSOLE_TIME_FORMAT_MSEC
#undef DXX_CONSOLE_TIME_ARG_YMD
#undef DXX_CONSOLE_TIME_FORMAT_YMD
	}
}
Exemplo n.º 9
0
Arquivo: luac.c Projeto: jcubic/ToME
static void DumpBlock_file(void *buf, size_t size, void *D)
{
	PHYSFS_write((PHYSFS_file*)D, buf, size, 1);
}
Exemplo n.º 10
0
int PHYSFS_writeSBE32(PHYSFS_File *file, PHYSFS_sint32 val)
{
    PHYSFS_sint32 out = PHYSFS_swapSBE32(val);
    BAIL_IF_MACRO(PHYSFS_write(file, &out, sizeof (out), 1) != 1, NULL, 0);
    return(1);
} /* PHYSFS_writeSBE32 */
Exemplo n.º 11
0
Arquivo: state.c Projeto: btb/d2x
//	-----------------------------------------------------------------------------------
//	blind_save means don't prompt user for any info.
int state_save_all(int between_levels, int secret_save, char *filename_override, int blind_save)
{
	int	rval, filenum = -1;

	char	filename[128], desc[DESC_LENGTH+1];

	Assert(between_levels == 0);	//between levels save ripped out

#ifdef NETWORK
	if ( Game_mode & GM_MULTI )	{
			multi_initiate_save_game();
		return 0;
	}
#endif

	if ((Current_level_num < 0) && (secret_save == 0)) {
		HUD_init_message( "Can't save in secret level!" );
		return 0;
	}

	if (Final_boss_is_dead)		//don't allow save while final boss is dying
		return 0;

	mprintf(( 0, "CL=%d, NL=%d\n", Current_level_num, Next_level_num ));
	
	//	If this is a secret save and the control center has been destroyed, don't allow
	//	return to the base level.
	if (secret_save && (Control_center_destroyed)) {
		mprintf((0, "Deleting secret.sgb so player can't return to base level.\n"));
		PHYSFS_delete(PLAYER_DIR "secret.sgb");
		return 0;
	}

	stop_time();

	if (secret_save == 1) {
		filename_override = filename;
		sprintf(filename_override, PLAYER_DIR "secret.sgb");
	} else if (secret_save == 2) {
		filename_override = filename;
		sprintf(filename_override, PLAYER_DIR "secret.sgc");
	} else {
		if (filename_override) {
			strcpy( filename, filename_override);
			sprintf(desc, "[autosave backup]");
		}
		else if (!(filenum = state_get_save_file(filename, desc, 0, blind_save)))
		{
			start_time();
			return 0;
		}
	}
		
	//	MK, 1/1/96
	//	If not in multiplayer, do special secret level stuff.
	//	If secret.sgc exists, then copy it to Nsecret.sgc (where N = filenum).
	//	If it doesn't exist, then delete Nsecret.sgc
	if (!secret_save && !(Game_mode & GM_MULTI)) {
		int	rval;
		char	temp_fname[32], fc;

		if (filenum != -1) {

			if (filenum >= 10)
				fc = (filenum-10) + 'a';
			else
				fc = '0' + filenum;

			sprintf(temp_fname, PLAYER_DIR "%csecret.sgc", fc);

			mprintf((0, "Trying to copy secret.sgc to %s.\n", temp_fname));

			if (PHYSFS_exists(temp_fname))
			{
				mprintf((0, "Deleting file %s\n", temp_fname));
				if (!PHYSFS_delete(temp_fname))
					Error("Cannot delete file <%s>: %s", temp_fname, PHYSFS_getLastError());
			}

			if (PHYSFS_exists(PLAYER_DIR "secret.sgc"))
			{
				mprintf((0, "Copying secret.sgc to %s.\n", temp_fname));
				rval = copy_file(PLAYER_DIR "secret.sgc", temp_fname);
				Assert(rval == 0);	//	Oops, error copying secret.sgc to temp_fname!
			}
		}
	}

	//	Save file we're going to save over in last slot and call "[autosave backup]"
	if (!filename_override) {
		PHYSFS_file *tfp;

		tfp = PHYSFSX_openWriteBuffered(filename);

		if ( tfp ) {
			char	newname[128];

			sprintf( newname, PLAYER_DIR "%s.sg%x", Players[Player_num].callsign, NUM_SAVES );

			PHYSFS_seek(tfp, DESC_OFFSET);
			PHYSFS_write(tfp, "[autosave backup]", sizeof(char) * DESC_LENGTH, 1);
			PHYSFS_close(tfp);
			PHYSFS_delete(newname);
			PHYSFSX_rename(filename, newname);
		}
	}
	
	rval = state_save_all_sub(filename, desc, between_levels);
	if (rval && !secret_save)
		HUD_init_message("Game saved.");

	return rval;
}
Exemplo n.º 12
0
void piggy_dump_all()
{
	int i, xlat_offset;
	PHYSFS_file * fp;
#ifndef RELEASE
	PHYSFS_file * fp1;
	PHYSFS_file * fp2;
#endif
	char * filename;
	int data_offset;
	int org_offset;
	DiskBitmapHeader bmh;
	DiskSoundHeader sndh;
	int header_offset;
	char subst_name[32];

	#ifdef NO_DUMP_SOUNDS
	Num_sound_files = 0;
	Num_sound_files_new = 0;
	#endif

//	{
//	bitmap_index bi;
//	bi.index = 614;
//	PIGGY_PAGE_IN( bi );
//	count_colors( bi.index, &GameBitmaps[bi.index] );
//	key_getch();
//	}
//	{
//	bitmap_index bi;
//	bi.index = 478;
//	PIGGY_PAGE_IN( bi );
//	Int3();
//	count_colors( bi.index, &GameBitmaps[bi.index] );
//	key_getch();
//	}
//	{
//	bitmap_index bi;
//	bi.index = 1398;
//	PIGGY_PAGE_IN( bi );
//	count_colors( bi.index, &GameBitmaps[bi.index] );
//	key_getch();
//	}
//	{
//	bitmap_index bi;
//	bi.index = 642;
//	PIGGY_PAGE_IN( bi );
//	count_colors( bi.index, &GameBitmaps[bi.index] );
//	key_getch();
//	}
//	{
//	bitmap_index bi;
//	bi.index = 529;
//	PIGGY_PAGE_IN( bi );
//	count_colors( bi.index, &GameBitmaps[bi.index] );
//	key_getch();
//	}
//	exit(0);
//
	if ((Num_bitmap_files_new == 0) && (Num_sound_files_new == 0) )
		return;

	for (i=0; i < Num_bitmap_files; i++ )	{
		bitmap_index bi;
		bi.index = i;
		PIGGY_PAGE_IN( bi );
	}

	piggy_close_file();

        filename = SHAREPATH "descent.pig";

	fp = PHYSFSX_openWriteBuffered( filename );
	Assert( fp!=NULL );

#ifndef RELEASE
	fp1 = PHYSFSX_openWriteBuffered( "piggy.lst" );
	fp2 = PHYSFSX_openWriteBuffered( "piggy.all" );
#endif

	i = 0;
	PHYSFS_write( fp, &i, sizeof(int), 1 );	
	bm_write_all(fp);
	xlat_offset = PHYSFS_tell(fp);
	PHYSFS_write( fp, GameBitmapXlat, sizeof(ushort)*MAX_BITMAP_FILES, 1 );
	i = PHYSFS_tell(fp);
	PHYSFSX_fseek( fp, 0, SEEK_SET );
	PHYSFS_write( fp, &i, sizeof(int), 1 );
	PHYSFSX_fseek( fp, i, SEEK_SET );
		
	Num_bitmap_files--;
	PHYSFS_write( fp, &Num_bitmap_files, sizeof(int), 1 );
	Num_bitmap_files++;
	PHYSFS_write( fp, &Num_sound_files, sizeof(int), 1 );

	header_offset = PHYSFS_tell(fp);
	header_offset += ((Num_bitmap_files-1)*sizeof(DiskBitmapHeader)) + (Num_sound_files*sizeof(DiskSoundHeader));
	data_offset = header_offset;

	for (i=1; i < Num_bitmap_files; i++ )	{
		int *size;
		grs_bitmap *bmp;

		{		
			char * p, *p1;
			p = strchr(AllBitmaps[i].name,'#');
			if (p)	{
				int n;
				p1 = p; p1++; 
				n = atoi(p1);
				*p = 0;
#ifndef RELEASE
				if (n==0)	{		
					PHYSFSX_printf( fp2, "%s.abm\n", AllBitmaps[i].name );
				}	
#endif
				memcpy( bmh.name, AllBitmaps[i].name, 8 );
				Assert( n <= 63 );
				bmh.dflags = DBM_FLAG_ABM + n;
				*p = '#';
			}else {
#ifndef RELEASE
				PHYSFSX_printf( fp2, "%s.bbm\n", AllBitmaps[i].name );
#endif
				memcpy( bmh.name, AllBitmaps[i].name, 8 );
				bmh.dflags = 0;
			}
		}
		bmp = &GameBitmaps[i];

		Assert( !(bmp->bm_flags&BM_FLAG_PAGED_OUT) );

#ifndef RELEASE
		PHYSFSX_printf( fp1, "BMP: %s, size %d bytes", AllBitmaps[i].name, bmp->bm_rowsize * bmp->bm_h );
#endif
		org_offset = PHYSFS_tell(fp);
		bmh.offset = data_offset - header_offset;
		PHYSFSX_fseek( fp, data_offset, SEEK_SET );

		if ( bmp->bm_flags & BM_FLAG_RLE )	{
			size = (int *)bmp->bm_data;
			PHYSFS_write( fp, bmp->bm_data, sizeof(ubyte), *size );
			data_offset += *size;
			//bmh.data_length = *size;
#ifndef RELEASE
			PHYSFSX_printf( fp1, ", and is already compressed to %d bytes.\n", *size );
#endif
		} else {
			PHYSFS_write( fp, bmp->bm_data, sizeof(ubyte), bmp->bm_rowsize * bmp->bm_h );
			data_offset += bmp->bm_rowsize * bmp->bm_h;
			//bmh.data_length = bmp->bm_rowsize * bmp->bm_h;
#ifndef RELEASE
			PHYSFSX_printf( fp1, ".\n" );
#endif
		}
		PHYSFSX_fseek( fp, org_offset, SEEK_SET );
		if ( GameBitmaps[i].bm_w > 255 )	{
			Assert( GameBitmaps[i].bm_w < 512 );
			bmh.width = GameBitmaps[i].bm_w - 256;
			bmh.dflags |= DBM_FLAG_LARGE;
		} else {
			bmh.width = GameBitmaps[i].bm_w;
		}
		Assert( GameBitmaps[i].bm_h < 256 );
		bmh.height = GameBitmaps[i].bm_h;
		bmh.flags = GameBitmaps[i].bm_flags;
		if (piggy_is_substitutable_bitmap( AllBitmaps[i].name, subst_name ))	{
			bitmap_index other_bitmap;
			other_bitmap = piggy_find_bitmap( subst_name );
			GameBitmapXlat[i] = other_bitmap.index;
			bmh.flags |= BM_FLAG_PAGED_OUT;
		} else	{
#ifdef BUILD_PSX_DATA
			count_colors( i, &GameBitmaps[i] );
#endif
			bmh.flags &= ~BM_FLAG_PAGED_OUT;
		}
		bmh.avg_color=GameBitmaps[i].avg_color;
		PHYSFS_write( fp, &bmh, sizeof(DiskBitmapHeader), 1 );			// Mark as a bitmap
	}

	for (i=0; i < Num_sound_files; i++ )
         {
		digi_sound *snd;

		snd = &GameSounds[i];
		strcpy( sndh.name, AllSounds[i].name );
#ifdef ALLEGRO
		sndh.length = GameSounds[i].len;
#else
                sndh.length = GameSounds[i].length;
#endif
		sndh.offset = data_offset - header_offset;

		org_offset = PHYSFS_tell(fp);
		PHYSFSX_fseek( fp, data_offset, SEEK_SET );

		sndh.data_length = sndh.length;
		PHYSFS_write( fp, snd->data, sizeof(ubyte), sndh.length );
		data_offset += sndh.length;
		PHYSFSX_fseek( fp, org_offset, SEEK_SET );
		PHYSFS_write( fp, &sndh, sizeof(DiskSoundHeader), 1 );			// Mark as a bitmap

#ifndef RELEASE
		PHYSFSX_printf( fp1, "SND: %s, size %d bytes\n", AllSounds[i].name, sndh.length );

		PHYSFSX_printf( fp2, "%s.raw\n", AllSounds[i].name );
#endif
         }

	PHYSFSX_fseek( fp, xlat_offset, SEEK_SET );
	PHYSFS_write( fp, GameBitmapXlat, sizeof(ushort)*MAX_BITMAP_FILES, 1 );

	PHYSFS_close(fp);

#ifndef RELEASE
	PHYSFSX_printf( fp1, " Dumped %d assorted bitmaps.\n", Num_bitmap_files );
	PHYSFSX_printf( fp1, " Dumped %d assorted sounds.\n", Num_sound_files );

	PHYSFS_close(fp1);
	PHYSFS_close(fp2);
#endif

#ifdef BUILD_PSX_DATA
	fp = PHYSFSX_openWriteBuffered( "psx/descent.dat" );
	PHYSFS_write( fp, &i, sizeof(int), 1 );	
	bm_write_all(fp);
	PHYSFS_write( fp, GameBitmapXlat, sizeof(ushort)*MAX_BITMAP_FILES, 1 );
	PHYSFS_close(fp);
#endif

	// Never allow the game to run after building pig.
	exit(0);
}
Exemplo n.º 13
0
void WriteFile::write8(Sint8 val)
{
    if(PHYSFS_write(file, &val, 1, 1) != 1)
        throw Exception("couldn't write: %s", PHYSFS_getLastError());
}
Exemplo n.º 14
0
sf::Int64 VFile::write(void const* data, sf::Int64 size)
{
    assert(size >= 0);
    return m_f ?
        check(PHYSFS_write(m_f, data, 1, static_cast<PHYSFS_uint32>(size)), size, "write") : -1;
}
Exemplo n.º 15
0
static void wzpng_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
{
	PHYSFS_file* fileHandle = (PHYSFS_file*)png_get_io_ptr(png_ptr);

	PHYSFS_write(fileHandle, data, length, 1);
}
Exemplo n.º 16
0
Arquivo: luac.c Projeto: jcubic/ToME
static void DumpVector_file(void *buf, size_t nb, size_t size, void *D)
{
	PHYSFS_write((PHYSFS_file*)D, buf, size, nb);
}
Exemplo n.º 17
0
Arquivo: state.c Projeto: btb/d2x
int state_save_all_sub(char *filename, char *desc, int between_levels)
{
	int i,j;
	PHYSFS_file *fp;
	grs_canvas * cnv;
	ubyte *pal;

	Assert(between_levels == 0);	//between levels save ripped out

/*	if ( Game_mode & GM_MULTI )	{
		{
		start_time();
		return 0;
		}
	}*/

	#if defined(MACINTOSH) && !defined(NDEBUG)
	if ( strncmp(filename, PLAYER_DIR, 9) )
		Int3();
	#endif

	fp = PHYSFSX_openWriteBuffered(filename);
	if ( !fp ) {
		if ( !(Game_mode & GM_MULTI) )
			nm_messagebox(NULL, 1, TXT_OK, "Error writing savegame.\nPossibly out of disk\nspace.");
		start_time();
		return 0;
	}

//Save id
	PHYSFS_write(fp, dgss_id, sizeof(char) * 4, 1);

//Save version
	i = STATE_VERSION;
	PHYSFS_write(fp, &i, sizeof(int), 1);

//Save description
	PHYSFS_write(fp, desc, sizeof(char) * DESC_LENGTH, 1);
	
// Save the current screen shot...

	cnv = gr_create_canvas( THUMBNAIL_W, THUMBNAIL_H );
	if ( cnv )
	{
#ifdef OGL
		ubyte *buf;
		int k;
		GLint gl_draw_buffer;
#endif
		grs_canvas * cnv_save;
		cnv_save = grd_curcanv;

		gr_set_current_canvas( cnv );

		render_frame(0, 0);

#if defined(OGL)
		buf = d_malloc(THUMBNAIL_W * THUMBNAIL_H * 3);
		glGetIntegerv(GL_DRAW_BUFFER, &gl_draw_buffer);
		glReadBuffer(gl_draw_buffer);
		glReadPixels(0, SHEIGHT - THUMBNAIL_H, THUMBNAIL_W, THUMBNAIL_H, GL_RGB, GL_UNSIGNED_BYTE, buf);
		k = THUMBNAIL_H;
		for (i = 0; i < THUMBNAIL_W * THUMBNAIL_H; i++) {
			if (!(j = i % THUMBNAIL_W))
				k--;
			cnv->cv_bitmap.bm_data[THUMBNAIL_W * k + j] =
				gr_find_closest_color(buf[3*i]/4, buf[3*i+1]/4, buf[3*i+2]/4);
		}
		d_free(buf);
#endif

		pal = gr_palette;

		PHYSFS_write(fp, cnv->cv_bitmap.bm_data, THUMBNAIL_W * THUMBNAIL_H, 1);

		gr_set_current_canvas(cnv_save);
		gr_free_canvas( cnv );
		PHYSFS_write(fp, pal, 3, 256);
	}
	else
	{
	 	ubyte color = 0;
	 	for ( i=0; i<THUMBNAIL_W*THUMBNAIL_H; i++ )
			PHYSFS_write(fp, &color, sizeof(ubyte), 1);		
	} 

// Save the Between levels flag...
	PHYSFS_write(fp, &between_levels, sizeof(int), 1);

// Save the mission info...
        mprintf ((0, "HEY! Mission name is %s\n", Current_mission_filename));
	PHYSFS_write(fp, Current_mission_filename, 9 * sizeof(char), 1);

//Save level info
	PHYSFS_write(fp, &Current_level_num, sizeof(int), 1);
	PHYSFS_write(fp, &Next_level_num, sizeof(int), 1);

//Save GameTime
	PHYSFS_write(fp, &GameTime, sizeof(fix), 1);

// If coop save, save all
#ifdef NETWORK
   if (Game_mode & GM_MULTI_COOP)
	 {
		PHYSFS_write(fp, &state_game_id,sizeof(int), 1);
		PHYSFS_write(fp, &Netgame,sizeof(netgame_info), 1);
		PHYSFS_write(fp, &NetPlayers,sizeof(AllNetPlayers_info), 1);
		PHYSFS_write(fp, &N_players,sizeof(int), 1);
		PHYSFS_write(fp, &Player_num,sizeof(int), 1);
		for (i=0;i<N_players;i++)
			PHYSFS_write(fp, &Players[i], sizeof(player), 1);

#ifdef RISKY_PROPOSITION
		PHYSFS_write(fp, &robot_controlled[0], 4 * MAX_ROBOTS_CONTROLLED, 1);
		PHYSFS_write(fp, &robot_agitation[0], 4 * MAX_ROBOTS_CONTROLLED, 1);
		PHYSFS_write(fp, &robot_controlled_time[0], 4 * MAX_ROBOTS_CONTROLLED, 1);
		PHYSFS_write(fp, &robot_last_send_time[0], 4 * MAX_ROBOTS_CONTROLLED, 1);
		PHYSFS_write(fp, &robot_last_message_time[0], 4 * MAX_ROBOTS_CONTROLLED, 1);
		PHYSFS_write(fp, &robot_send_pending[0], 4 * MAX_ROBOTS_CONTROLLED, 1);
		PHYSFS_write(fp, &robot_fired[0], 4 * MAX_ROBOTS_CONTROLLED, 1);
 
      for (i=0;i<MAX_ROBOTS_CONTROLLED;i++)
			PHYSFS_write(fp, robot_fire_buf[i][0], 18 + 3, 1);
#endif

	 }
#endif

//Save player info
	PHYSFS_write(fp, &Players[Player_num], sizeof(player), 1);

// Save the current weapon info
	PHYSFS_write(fp, &Primary_weapon, sizeof(sbyte), 1);
	PHYSFS_write(fp, &Secondary_weapon, sizeof(sbyte), 1);

// Save the difficulty level
	PHYSFS_write(fp, &Difficulty_level, sizeof(int), 1);
// Save cheats enabled
	PHYSFS_write(fp, &Cheats_enabled.intval, sizeof(int), 1);

	if ( !between_levels )	{

	//Finish all morph objects
		for (i=0; i<=Highest_object_index; i++ )	{
			if ( (Objects[i].type != OBJ_NONE) && (Objects[i].render_type==RT_MORPH))	{
				morph_data *md;
				md = find_morph_data(&Objects[i]);
				if (md) {					
					md->obj->control_type = md->morph_save_control_type;
					md->obj->movement_type = md->morph_save_movement_type;
					md->obj->render_type = RT_POLYOBJ;
					md->obj->mtype.phys_info = md->morph_save_phys_info;
					md->obj = NULL;
				} else {						//maybe loaded half-morphed from disk
					Objects[i].flags |= OF_SHOULD_BE_DEAD;
					Objects[i].render_type = RT_POLYOBJ;
					Objects[i].control_type = CT_NONE;
					Objects[i].movement_type = MT_NONE;
				}
			}
		}
	
	//Save object info
		i = Highest_object_index+1;
		PHYSFS_write(fp, &i, sizeof(int), 1);
		PHYSFS_write(fp, Objects, sizeof(object), i);
		
	//Save wall info
		i = Num_walls;
		PHYSFS_write(fp, &i, sizeof(int), 1);
		PHYSFS_write(fp, Walls, sizeof(wall), i);

	//Save exploding wall info
		i = MAX_EXPLODING_WALLS;
		PHYSFS_write(fp, &i, sizeof(int), 1);
		PHYSFS_write(fp, expl_wall_list, sizeof(*expl_wall_list), i);
	
	//Save door info
		i = Num_open_doors;
		PHYSFS_write(fp, &i, sizeof(int), 1);
		PHYSFS_write(fp, ActiveDoors, sizeof(active_door), i);
	
	//Save cloaking wall info
		i = Num_cloaking_walls;
		PHYSFS_write(fp, &i, sizeof(int), 1);
		PHYSFS_write(fp, CloakingWalls, sizeof(cloaking_wall), i);
	
	//Save trigger info
		PHYSFS_write(fp, &Num_triggers, sizeof(int), 1);
		PHYSFS_write(fp, Triggers, sizeof(trigger), Num_triggers);
	
	//Save tmap info
		for (i = 0; i <= Highest_segment_index; i++)
		{
			for (j = 0; j < 6; j++)
			{
				PHYSFS_write(fp, &Segments[i].sides[j].wall_num, sizeof(short), 1);
				PHYSFS_write(fp, &Segments[i].sides[j].tmap_num, sizeof(short), 1);
				PHYSFS_write(fp, &Segments[i].sides[j].tmap_num2, sizeof(short), 1);
			}
		}
	
	// Save the fuelcen info
		PHYSFS_write(fp, &Control_center_destroyed, sizeof(int), 1);
		PHYSFS_write(fp, &Countdown_timer, sizeof(int), 1);
		PHYSFS_write(fp, &Num_robot_centers, sizeof(int), 1);
		PHYSFS_write(fp, RobotCenters, sizeof(matcen_info), Num_robot_centers);
		PHYSFS_write(fp, &ControlCenterTriggers, sizeof(control_center_triggers), 1);
		PHYSFS_write(fp, &Num_fuelcenters, sizeof(int), 1);
		PHYSFS_write(fp, Station, sizeof(FuelCenter), Num_fuelcenters);
	
	// Save the control cen info
		PHYSFS_write(fp, &Control_center_been_hit, sizeof(int), 1);
		PHYSFS_write(fp, &Control_center_player_been_seen, sizeof(int), 1);
		PHYSFS_write(fp, &Control_center_next_fire_time, sizeof(int), 1);
		PHYSFS_write(fp, &Control_center_present, sizeof(int), 1);
		PHYSFS_write(fp, &Dead_controlcen_object_num, sizeof(int), 1);
	
	// Save the AI state
		ai_save_state( fp );
	
	// Save the automap visited info
		PHYSFS_write(fp, Automap_visited, sizeof(ubyte), MAX_SEGMENTS);

	}
	PHYSFS_write(fp, &state_game_id, sizeof(uint), 1);
	PHYSFS_write(fp, &Laser_rapid_fire, sizeof(int), 1);
	PHYSFS_write(fp, &Lunacy, sizeof(int), 1);  //  Yes, writing this twice.  Removed the Ugly robot system, but didn't want to change savegame format.
	PHYSFS_write(fp, &Lunacy, sizeof(int), 1);

	// Save automap marker info

	PHYSFS_write(fp, MarkerObject, sizeof(MarkerObject) ,1);
	PHYSFS_write(fp, MarkerOwner, sizeof(MarkerOwner), 1);
	PHYSFS_write(fp, MarkerMessage, sizeof(MarkerMessage), 1);

	PHYSFS_write(fp, &Afterburner_charge, sizeof(fix), 1);

	//save last was super information
	PHYSFS_write(fp, &Primary_last_was_super, sizeof(Primary_last_was_super), 1);
	PHYSFS_write(fp, &Secondary_last_was_super, sizeof(Secondary_last_was_super), 1);

	//	Save flash effect stuff
	PHYSFS_write(fp, &Flash_effect, sizeof(int), 1);
	PHYSFS_write(fp, &Time_flash_last_played, sizeof(int), 1);
	PHYSFS_write(fp, &PaletteRedAdd, sizeof(int), 1);
	PHYSFS_write(fp, &PaletteGreenAdd, sizeof(int), 1);
	PHYSFS_write(fp, &PaletteBlueAdd, sizeof(int), 1);

	PHYSFS_write(fp, Light_subtracted, sizeof(Light_subtracted[0]), MAX_SEGMENTS);

	PHYSFS_write(fp, &First_secret_visit, sizeof(First_secret_visit), 1);

	if (PHYSFS_write(fp, &Omega_charge, sizeof(Omega_charge), 1) < 1)
	{
		if ( !(Game_mode & GM_MULTI) ) {
			nm_messagebox(NULL, 1, TXT_OK, "Error writing savegame.\nPossibly out of disk\nspace.");
			PHYSFS_close(fp);
			PHYSFS_delete(filename);
		}
	} else  {
		PHYSFS_close(fp);

		#ifdef MACINTOSH		// set the type and creator of the saved game file
		{
			FInfo finfo;
			OSErr err;
			Str255 pfilename;
	
			strcpy(pfilename, filename);
			c2pstr(pfilename);
			err = HGetFInfo(0, 0, pfilename, &finfo);
			finfo.fdType = 'SVGM';
			finfo.fdCreator = 'DCT2';
			err = HSetFInfo(0, 0, pfilename, &finfo);
		}
		#endif
	}
	
	start_time();

	return 1;
}
Exemplo n.º 18
0
int fs_write(const void *data, int size, int count, fs_file fh)
{
    return PHYSFS_write(fh->handle, data, size, count);
}
Exemplo n.º 19
0
void saveStringIntoFile(const std::string& pFileName, const std::string& pString) {
	PHYSFS_file* file = PHYSFS_openWrite(pFileName.c_str());
	PHYSFS_write(file, pString.c_str(), sizeof(char), pString.length());
	PHYSFS_close(file);
}
Exemplo n.º 20
0
int PG_File::write(void *buffer, unsigned int objSize, unsigned int objCount) {
	return static_cast<int>(PHYSFS_write((PHYSFS_file*)file, buffer, objSize, objCount));
}
Exemplo n.º 21
0
bool NETstopLogging(void)
{
    static const char dash_line[] = "-----------------------------------------------------------\n";
    char buf[256];
    int i;
    UDWORD totalBytessent = 0, totalBytesrecv = 0, totalPacketsent = 0, totalPacketrecv = 0;

    if (!pFileHandle)
    {
        return false;
    }

    /* Output stats */
    for (i = 0; i < NUM_GAME_PACKETS; i++)
    {
        snprintf(buf, sizeof(buf), "%-24s:\t received %u times, %u bytes; sent %u times, %u bytes\n", messageTypeToString(i),
                 packetcount[1][i], packetsize[1][i], packetcount[0][i], packetsize[0][i]);
        PHYSFS_write(pFileHandle, buf, strlen(buf), 1);
        totalBytessent += packetsize[0][i];
        totalBytesrecv += packetsize[1][i];
        totalPacketsent += packetcount[0][i];
        totalPacketrecv += packetcount[1][i];
    }
    snprintf(buf, sizeof(buf), "== Total bytes sent %u, Total bytes received %u ==\n", totalBytessent, totalBytesrecv);
    PHYSFS_write(pFileHandle, buf, strlen(buf), 1);
    snprintf(buf, sizeof(buf), "== Total packets sent %u, recv %u ==\n", totalPacketsent, totalPacketrecv);
    PHYSFS_write(pFileHandle, buf, strlen(buf), 1);
    snprintf(buf, sizeof(buf), "\n-Sync statistics -\n");
    PHYSFS_write(pFileHandle, buf, strlen(buf), 1);
    PHYSFS_write(pFileHandle, dash_line, strlen(dash_line), 1);
    snprintf(buf, sizeof(buf), "joins: %hhu, kicks: %hhu, drops: %hhu, left %hhu\n", sync_counter.joins, sync_counter.kicks, sync_counter.drops, sync_counter.left );
    PHYSFS_write(pFileHandle, buf, strlen(buf), 1);
    snprintf(buf, sizeof(buf), "banned: %hhu, cantjoin: %hhu, rejected: %hhu\n", sync_counter.banned, sync_counter.cantjoin, sync_counter.rejected );
    PHYSFS_write(pFileHandle, buf, strlen(buf), 1);
    if (sync_counter.banned && IPlist)
    {
        snprintf(buf, sizeof(buf), "Banned list:\n");
        PHYSFS_write(pFileHandle, buf, strlen(buf), 1);
        for (i = 0; i < MAX_BANS; i++)
        {
            if (IPlist[i].IPAddress[0] != '\0')
            {
                snprintf(buf, sizeof(buf), "player %s, IP: %s\n", IPlist[i].pname, IPlist[i].IPAddress);
                PHYSFS_write(pFileHandle, buf, strlen(buf), 1);
            }
        }

    }
    PHYSFS_write(pFileHandle, dash_line, strlen(dash_line), 1);
    PHYSFS_write(pFileHandle, dash_line, strlen(dash_line), 1);

    if (!PHYSFS_close(pFileHandle))
    {
        debug(LOG_ERROR, "Could not close net log: %s", PHYSFS_getLastError());
        return false;
    }
    pFileHandle = NULL;

    return true;
}
Exemplo n.º 22
0
// -----------------------------------------------------------------------------
// Save game
int save_game_data(PHYSFS_file *SaveFile)
{
	short game_top_fileinfo_version = Gamesave_current_version >= 5 ? 31 : GAME_VERSION;
	int  player_offset=0, object_offset=0, walls_offset=0, doors_offset=0, triggers_offset=0, control_offset=0, matcen_offset=0; //, links_offset;
	int offset_offset=0, end_offset=0;
	int i;

	//===================== SAVE FILE INFO ========================

	PHYSFS_writeSLE16(SaveFile, 0x6705);	// signature
	PHYSFS_writeSLE16(SaveFile, game_top_fileinfo_version);
	PHYSFS_writeSLE32(SaveFile, sizeof(game_fileinfo));
	PHYSFS_write(SaveFile, Current_level_name, 15, 1);
	PHYSFS_writeSLE32(SaveFile, Current_level_num);
	offset_offset = PHYSFS_tell(SaveFile);	// write the offsets later
	PHYSFS_writeSLE32(SaveFile, -1);
	PHYSFS_writeSLE32(SaveFile, sizeof(player));

#define WRITE_HEADER_ENTRY(t, n) do { PHYSFS_writeSLE32(SaveFile, -1); PHYSFS_writeSLE32(SaveFile, n); PHYSFS_writeSLE32(SaveFile, sizeof(t)); } while(0)

	WRITE_HEADER_ENTRY(object, Highest_object_index + 1);
	WRITE_HEADER_ENTRY(wall, Num_walls);
	WRITE_HEADER_ENTRY(active_door, Num_open_doors);
	WRITE_HEADER_ENTRY(trigger, Num_triggers);
	WRITE_HEADER_ENTRY(0, 0);		// links (removed by Parallax)
	WRITE_HEADER_ENTRY(control_center_triggers, 1);
	WRITE_HEADER_ENTRY(matcen_info, Num_robot_centers);

	// Write the mine name
	PHYSFSX_printf(SaveFile, "%s\n", Current_level_name);

	PHYSFS_writeSLE16(SaveFile, N_polygon_models);
	PHYSFS_write(SaveFile, Pof_names, sizeof(*Pof_names), N_polygon_models);

	//==================== SAVE PLAYER INFO ===========================

	player_offset = PHYSFS_tell(SaveFile);
	PHYSFS_write(SaveFile, &Players[Player_num], sizeof(player), 1);	// not endian friendly, but not used either

	//==================== SAVE OBJECT INFO ===========================

	object_offset = PHYSFS_tell(SaveFile);
	//fwrite( &Objects, sizeof(object), game_fileinfo.object_howmany, SaveFile );
	for (i = 0; i <= Highest_object_index; i++)
		write_object(&Objects[i], SaveFile);

	//==================== SAVE WALL INFO =============================

	walls_offset = PHYSFS_tell(SaveFile);
	for (i = 0; i < Num_walls; i++)
		wall_write(&Walls[i], game_top_fileinfo_version, SaveFile);

	//==================== SAVE DOOR INFO =============================

#if 0 // FIXME: okay to leave this out?
	doors_offset = PHYSFS_tell(SaveFile);
	for (i = 0; i < Num_open_doors; i++)
		door_write(&ActiveDoors[i], game_top_fileinfo_version, SaveFile);
#endif

	//==================== SAVE TRIGGER INFO =============================

	triggers_offset = PHYSFS_tell(SaveFile);
	for (i = 0; i < Num_triggers; i++)
		trigger_write(&Triggers[i], game_top_fileinfo_version, SaveFile);

	//================ SAVE CONTROL CENTER TRIGGER INFO ===============

	control_offset = PHYSFS_tell(SaveFile);
	control_center_triggers_write(&ControlCenterTriggers, SaveFile);


	//================ SAVE MATERIALIZATION CENTER TRIGGER INFO ===============

	matcen_offset = PHYSFS_tell(SaveFile);
	for (i = 0; i < Num_robot_centers; i++)
		matcen_info_write(&RobotCenters[i], game_top_fileinfo_version, SaveFile);

	//============= REWRITE FILE INFO, TO SAVE OFFSETS ===============

	end_offset = PHYSFS_tell(SaveFile);

	// Update the offset fields

#define WRITE_OFFSET(o, n) do { PHYSFS_seek(SaveFile, offset_offset); PHYSFS_writeSLE32(SaveFile, o ## _offset); offset_offset += sizeof(int)*n; } while (0)

	WRITE_OFFSET(player, 2);
	WRITE_OFFSET(object, 3);
	WRITE_OFFSET(walls, 3);
	WRITE_OFFSET(doors, 3);
	WRITE_OFFSET(triggers, 6);
	WRITE_OFFSET(control, 3);
	WRITE_OFFSET(matcen, 3);

	// Go back to end of data
	PHYSFS_seek(SaveFile, end_offset);

	return 0;
}
Exemplo n.º 23
0
int PHYSFS_writeULE16(PHYSFS_File *file, PHYSFS_uint16 val)
{
    PHYSFS_uint16 out = PHYSFS_swapULE16(val);
    BAIL_IF_MACRO(PHYSFS_write(file, &out, sizeof (out), 1) != 1, NULL, 0);
    return(1);
} /* PHYSFS_writeULE16 */
Exemplo n.º 24
0
//write out player's saved games.  returns errno (0 == no error)
int write_player_file()
{
	char filename[PATH_MAX];
	PHYSFS_file *file;
	int errno_ret, i;

	if ( Newdemo_state == ND_STATE_PLAYBACK )
		return -1;

	errno_ret = WriteConfigFile();

	memset(filename, '\0', PATH_MAX);
        snprintf(filename, PATH_MAX, GameArg.SysUsePlayersDir? "Players/%.8s.plx" : "%.8s.plx", Players[Player_num].callsign);
	write_player_d1x(filename);

	snprintf(filename, PATH_MAX, GameArg.SysUsePlayersDir? "Players/%.8s.plr" : "%.8s.plr", Players[Player_num].callsign);
	file = PHYSFSX_openWriteBuffered(filename);

	if (!file)
		return errno;

	PHYSFS_writeULE32(file, SAVE_FILE_ID);
	PHYSFS_writeULE16(file, SAVED_GAME_VERSION);
	PHYSFS_writeULE16(file, PLAYER_STRUCT_VERSION);
	PHYSFS_writeSLE32(file, PlayerCfg.NHighestLevels);
	PHYSFS_writeSLE32(file, PlayerCfg.DefaultDifficulty);
	PHYSFS_writeSLE32(file, PlayerCfg.AutoLeveling);
	errno_ret = EZERO;

	//write higest level info
	if ((PHYSFS_write( file, PlayerCfg.HighestLevels, sizeof(hli), PlayerCfg.NHighestLevels) != PlayerCfg.NHighestLevels)) {
		errno_ret = errno;
		PHYSFS_close(file);
		return errno_ret;
	}

	if (PHYSFS_write( file, saved_games,sizeof(saved_games),1) != 1) {
		errno_ret = errno;
		PHYSFS_close(file);
		return errno_ret;
	}

	#ifdef NETWORK
	if ((PHYSFS_write( file, PlayerCfg.NetworkMessageMacro, MAX_MESSAGE_LEN, 4) != 4)) {
		errno_ret = errno;
		PHYSFS_close(file);
		return errno_ret;
	}
	#else
	{
		//PHYSFS_seek( file, PHYSFS_tell(file)+MAX_MESSAGE_LEN * 4 );	// Seeking is bad for Mac OS 9
		char dummy[MAX_MESSAGE_LEN][4];
		
		if ((PHYSFS_write( file, dummy, MAX_MESSAGE_LEN, 4) != 4)) {
			errno_ret = errno;
			PHYSFS_close(file);
			return errno_ret;
		}
	}
	#endif

	//write kconfig info
	{
		if (PHYSFS_write(file, PlayerCfg.KeySettings[0], sizeof(PlayerCfg.KeySettings[0]), 1) != 1)
			errno_ret=errno;
		if (PHYSFS_write(file, PlayerCfg.KeySettings[1], sizeof(PlayerCfg.KeySettings[1]), 1) != 1)
			errno_ret=errno;
		for (i = 0; i < MAX_CONTROLS*3; i++)
			if (PHYSFS_write(file, "0", sizeof(ubyte), 1) != 1) // Skip obsolete Flightstick/Thrustmaster/Gravis map fields
				errno_ret=errno;
		if (PHYSFS_write(file, PlayerCfg.KeySettings[2], sizeof(PlayerCfg.KeySettings[2]), 1) != 1)
			errno_ret=errno;
		for (i = 0; i < MAX_CONTROLS; i++)
			if (PHYSFS_write(file, "0", sizeof(ubyte), 1) != 1) // Skip obsolete Cyberman map field
				errno_ret=errno;
	
		if(errno_ret == EZERO)
		{
			ubyte old_avg_joy_sensitivity = 8;
			if (PHYSFS_write( file,  &PlayerCfg.ControlType, sizeof(ubyte), 1 )!=1)
				errno_ret=errno;
			else if (PHYSFS_write( file, &old_avg_joy_sensitivity, sizeof(ubyte), 1 )!=1)
				errno_ret=errno;
		}
	}

	if (!PHYSFS_close(file))
		errno_ret = errno;

	if (errno_ret != EZERO) {
		PHYSFS_delete(filename);			//delete bogus file
		nm_messagebox(TXT_ERROR, 1, TXT_OK, "%s\n\n%s",TXT_ERROR_WRITING_PLR, strerror(errno_ret));
	}

	return errno_ret;
}
Exemplo n.º 25
0
int PHYSFS_writeUBE64(PHYSFS_File *file, PHYSFS_uint64 val)
{
    PHYSFS_uint64 out = PHYSFS_swapUBE64(val);
    BAIL_IF_MACRO(PHYSFS_write(file, &out, sizeof (out), 1) != 1, NULL, 0);
    return(1);
} /* PHYSFS_writeUBE64 */
Exemplo n.º 26
0
 size_t on_data(void* ptr, size_t size, size_t nmemb)
 {
   PHYSFS_write(m_fout.get(), ptr, size, nmemb);
   return size * nmemb;
 }