示例#1
0
void *
GetResourceData (uio_Stream *fp, DWORD length)
{
	void *result;
	DWORD compLen;

	// Resource data used to be prefixed by its length in package files.
	// A valid length prefix indicated compressed data, and
	// a length prefix ~0 meant uncompressed.
	// Currently, .ct and .xlt files still carry a ~0 length prefix.
	if (ReadResFile (&compLen, sizeof (compLen), 1, fp) != 1)
		return NULL;
	if (compLen != ~(DWORD)0)
	{
		log_add (log_Warning, "LZ-compressed binary data not supported");
		return NULL;
	}
	length -= sizeof (DWORD);

	result = AllocResourceData (length);
	if (!result)
		return NULL;

	if (ReadResFile (result, 1, length, fp) != length)
	{
		FreeResourceData (result);
		result = NULL;
	}

	return result;
}
示例#2
0
static inline COUNT
read_32 (void *fp, DWORD *v)
{
	DWORD t;
	if (!v) /* read value ignored */
		v = &t;
	return ReadResFile (v, 4, 1, fp);
}
示例#3
0
static inline COUNT
read_16 (void *fp, UWORD *v)
{
	UWORD t;
	if (!v) /* read value ignored */
		v = &t;
	return ReadResFile (v, 2, 1, fp);
}
示例#4
0
static inline COUNT
read_8 (void *fp, BYTE *v)
{
	BYTE t;
	if (!v) /* read value ignored */
		v = &t;
	return ReadResFile (v, 1, 1, fp);
}
示例#5
0
void
PropFile_from_file (uio_Stream *f, PROPERTY_HANDLER handler, const char *prefix)
{
	long flen;
	char *data;

	flen = LengthResFile (f);

	data = malloc (flen + 1);
	if (!data) {
		return;
	}

	flen = ReadResFile (data, 1, flen, f);
	data[flen] = '\0';

	PropFile_from_string (data, handler, prefix);
	free (data);
}
void
OpenJournal (void)
{
    DWORD start_seed;

#if CREATE_JOURNAL
    if (create_journal)
    {
        if (journal_fh = copen (journal_buf, MEMORY_STREAM, STREAM_WRITE))
        {
            start_seed = SeedRandomNumbers ();
            cwrite ((PBYTE)&start_seed, sizeof (start_seed), 1, journal_fh);
        }
    }
    else
#endif /* CREATE_JOURNAL */
    {
        uio_Stream *fp;

        if (fp = res_OpenResFile ("starcon.jnl", "rb"))
        {
            ReadResFile (journal_buf, 1, sizeof (journal_buf), fp);
            res_CloseResFile (fp);

            if (journal_fh = copen (journal_buf, MEMORY_STREAM, STREAM_READ))
            {
                OldArrowInput = ArrowInput;
                ArrowInput = DemoInput;
                PlayerInput[0] = PlayerInput[1] = DemoInput;

                FlushInput ();

                cread ((PBYTE)&start_seed, sizeof (start_seed), 1, journal_fh);
                TFB_SeedRandom (start_seed);
            }
        }
    }
}
示例#7
0
static inline COUNT
read_a8 (void *fp, BYTE *ar, COUNT count)
{
	assert (ar != NULL);
	return ReadResFile (ar, 1, count, fp) == count;
}