예제 #1
0
void playmusic(char *fn)
{
    int fp;
    char * testfn, * extension;

    if(MusicToggle == 0) return;
    if(MusicDevice < 0) return;

    stopmusic();
    
    testfn = (char *) malloc( strlen(fn) + 5 );
    printf("Playing song: %s\n", fn);
    strcpy(testfn, fn);
    extension = strrchr(testfn, '.');

    do {
       if (extension && !Bstrcasecmp(extension, ".mid")) {
	  // we've been asked to load a .mid file, but first
	  // let's see if there's an ogg with the same base name
	  // lying around
           strcpy(extension, ".ogg");
           fp = kopen4load(testfn, 0);
           if (fp >= 0) {
               printf("OGG found: %s\n", testfn);
               free(testfn);
               break;
           }
       }
       free(testfn);

       // just use what we've been given
       fp = kopen4load(fn, 0);
    } while (0);

    if (fp < 0) return;

    MusicLen = kfilelength( fp );
    MusicPtr = (char *) malloc(MusicLen);
    kread( fp, MusicPtr, MusicLen);
    kclose( fp );
    
    if (!memcmp(MusicPtr, "MThd", 4)) {
       MUSIC_PlaySong( MusicPtr, MusicLen, MUSIC_LoopSong );
       MusicIsWaveform = 0;
    } else {
       MusicVoice = FX_PlayLoopedAuto(MusicPtr, MusicLen, 0, 0, 0,
                                      MusicVolume, MusicVolume, MusicVolume,
				      FX_MUSIC_PRIORITY, MUSIC_ID);
       MusicIsWaveform = 1;
    }

    MusicPaused = 0;
}
예제 #2
0
char * LoadAnm ( short anim_num )
{
    long handle;
    char *animbuf, *palptr;
    long i, j, k;
    DSPRINTF ( ds, "LoadAnm" );
    MONO_PRINT ( ds );
    // this seperate allows the anim to be precached easily
    ANIMnum = anim_num;
    // lock it
    walock[ANIM_TILE ( ANIMnum )] = 219;
    
    if ( anm_ptr[anim_num] == 0 )
    {
        handle = kopen4load ( ANIMname[ANIMnum], 0 );
        
        if ( handle == -1 )
        {
            return ( NULL );
        }
        
        length = kfilelength ( handle );
        allocache ( ( intptr_t * ) &anm_ptr[anim_num], length + sizeof ( anim_t ), &walock[ANIM_TILE ( ANIMnum )] );
        animbuf = ( char * ) ( FP_OFF ( anm_ptr[anim_num] ) + sizeof ( anim_t ) );
        kread ( handle, animbuf, length );
        kclose ( handle );
    }
    
    else
    {
        animbuf = ( char * ) ( FP_OFF ( anm_ptr[anim_num] ) + sizeof ( anim_t ) );
    }
    
    return ( animbuf );
}
예제 #3
0
BOOL LoadScriptFile (char *filename)
{
	long size, readsize;
	int fp;


	if((fp=kopen4load(filename,0)) == -1)
	{
		// If there's no script file, forget it.
		return FALSE;
	}

    size = kfilelength(fp);    

    scriptbuffer = (char *)malloc(size);

	ASSERT(scriptbuffer != NULL);

	readsize = kread(fp, scriptbuffer, size);

    kclose(fp);

	ASSERT(readsize == size);


	// Convert filebuffer to all upper case
	//strupr(scriptbuffer);

	script_p = scriptbuffer;
	scriptend_p = script_p + size;
	scriptline = 1;
	endofscript = FALSE;
	tokenready = FALSE;
	return TRUE;
}
예제 #4
0
scriptfile *scriptfile_fromfile(char *fn)
{
	int fp;
	scriptfile *sf;
	char *tx;
	unsigned int flen;

	fp = kopen4load(fn,0);
	if (fp<0) return NULL;

	flen = kfilelength(fp);
	tx = (char *) malloc(flen + 2);
	if (!tx) {
		kclose(fp);
		return NULL;
	}

	sf = (scriptfile*) malloc(sizeof(scriptfile));
	if (!sf) {
		kclose(fp);
		free(tx);
		return NULL;
	}

	kread(fp, tx, flen);
	tx[flen] = tx[flen+1] = 0;

	kclose(fp);

	scriptfile_preparse(sf,tx,flen);
	sf->filename = strdup(fn);

	return sf;
}
예제 #5
0
int osdcmd_fileinfo(const osdfuncparm_t *parm)
{
	unsigned long crc, length;
	int i,j;
	char buf[256];

	if (parm->numparms != 1) return OSDCMD_SHOWHELP;
	
	if ((i = kopen4load((char *)parm->parms[0],0)) < 0) {
		OSD_Printf("fileinfo: File \"%s\" does not exist.\n", parm->parms[0]);
		return OSDCMD_OK;
	}

	length = kfilelength(i);

	crc32init(&crc);
	do {
		j = kread(i,buf,256);
		crc32block(&crc,buf,j);
	} while (j == 256);
	crc32finish(&crc);
	
	kclose(i);

	OSD_Printf("fileinfo: %s\n"
	           "  File size: %d\n"
		   "  CRC-32:    %08X\n",
		   parm->parms[0], length, crc);

	return OSDCMD_OK;
}
예제 #6
0
char loadsound(unsigned short num)
{
    long   fp, l;

    if(num >= NUM_SOUNDS || SoundToggle == 0) return 0;
    if (FXDevice < 0) return 0;

    fp = kopen4load(sounds[num],loadfromgrouponly);
    if(fp == -1)
    {
        sprintf(&fta_quotes[113][0],"Sound %s(#%d) not found.",sounds[num],num);
        FTA(113,&ps[myconnectindex]);
        return 0;
    }

    l = kfilelength( fp );
    soundsiz[num] = l;

    Sound[num].lock = 200;

    allocache((long *)&Sound[num].ptr,l,(char *)&Sound[num].lock);
    kread( fp, Sound[num].ptr , l);
    kclose( fp );
    return 1;
}
예제 #7
0
파일: common.c 프로젝트: dahlor/Duke3DS
// returns: 1 if file could be opened, 0 else
int32_t testkopen(const char *filename, char searchfirst)
{
    int32_t fd = kopen4load(filename, searchfirst);
    if (fd >= 0)
        kclose(fd);
    return (fd >= 0);
}
예제 #8
0
SWBOOL
LoadSong(const char *filename)
{
    int handle;
    int size;
    char *ptr;

    if ((handle = kopen4load(filename, 0)) == -1)
    {
        return FALSE;
    }

    size = kfilelength(handle);

    ptr = (char *) AllocMem(size);
    if (ptr == NULL)
    {
        kclose(handle);
        return FALSE;
    }

    if (kread(handle, ptr, size) != size)
    {
        FreeMem(ptr);
        kclose(handle);
        return FALSE;
    }

    kclose(handle);

    SongPtr = ptr;
    SongLength = size;

    return TRUE;
}
예제 #9
0
static int32_t read_whole_file(const char *fn, char **retbufptr)
{
    int32_t fid, flen, i;
    char *buf;

    *retbufptr = NULL;

    fid = kopen4load(fn, 0);  // TODO: g_loadFromGroupOnly, kopen4loadfrommod ?

    if (fid < 0)
        return 1;

    flen = kfilelength(fid);
    if (flen == 0)
        return 5;

    buf = (char *)Xmalloc(flen+1);

    i = kread(fid, buf, flen);
    kclose(fid);

    if (i != flen)
    {
        Bfree(buf);
        return 2;
    }

    buf[flen] = 0;
    *retbufptr = buf;

    return 0;
}
예제 #10
0
파일: sound.c 프로젝트: wosigh/duke3d
void loadwaves(void)
{
	long fil, dawaversionum, i, tmp;
	long wavleng[MAXWAVES], repstart[MAXWAVES], repleng[MAXWAVES], finetune[MAXWAVES];
	char *p;

	fil = kopen4load("WAVES.KWV", 0);

	if (fil != -1) {
		kread(fil, &dawaversionum, 4); dawaversionum = B_LITTLE32(dawaversionum);
		if (dawaversionum != 0) { kclose(fil); return; }

		kread(fil, &numwaves, 4); numwaves = B_LITTLE32(numwaves);
		for (i=0; i<numwaves; i++) {
			kread(fil, &instname[i][0], 16);
			kread(fil, &wavleng[i], 4);  wavleng[i]  = B_LITTLE32(wavleng[i]);
			kread(fil, &repstart[i], 4); repstart[i] = B_LITTLE32(repstart[i]);
			kread(fil, &repleng[i], 4);  repleng[i]  = B_LITTLE32(repleng[i]);
			kread(fil, &finetune[i], 4); finetune[i] = B_LITTLE32(finetune[i]);
		}
	} else {
		dawaversionum = 0;
		numwaves = 0;
	}

	for (i=numwaves; i<MAXWAVES; i++) {
		memset(&instname[i][0], 0, 16);
		wavleng[i] = 0;
		repstart[i] = 0;
		repleng[i] = 0;
		finetune[i] = 0;
		samples[i] = NULL;
	}

	if (fil == -1) return;

#if 0
	for (i=0; i<numwaves; i++) {
		if (repleng[i]) tmp = FSOUND_LOOP_NORMAL;
		else tmp = FSOUND_LOOP_OFF;
		samples[i] = FSOUND_Sample_Alloc(FSOUND_FREE, wavleng[i], tmp, 11025, 255, 128, 1);
		if (!samples[i]) continue;

		p = (char*)Bmalloc(wavleng[i]);
		kread(fil,p,wavleng[i]);
		FSOUND_Sample_Upload(samples[i], p, FSOUND_8BITS | FSOUND_MONO | FSOUND_UNSIGNED);
		Bfree(p);

		if (repleng[i]) FSOUND_Sample_SetLoopPoints(samples[i], repstart[i], repstart[i]+repleng[i]);
	}
#endif

	kclose(fil);

	printOSD("Loaded %d waves\n", numwaves);
}
예제 #11
0
void loadtmb(void)
{
    char tmb[8000];
    int fil, l;

    fil = kopen4load("swtimbr.tmb",0);
    if (fil == -1)
        return;

    l = min(kfilelength(fil), sizeof(tmb));
    kread(fil,tmb,l);
    MUSIC_RegisterTimbreBank(tmb);
    kclose(fil);
}
예제 #12
0
SWBOOL
OpenSound(VOC_INFOp vp, int *handle, int *length)
{
    *handle = kopen4load(vp->name, 0);

    if (*handle == -1)
    {
        return FALSE;
    }

    *length = kfilelength(*handle);

    return TRUE;
}
예제 #13
0
int osdcmd_map(const osdfuncparm_t *parm)
{
	int i;
	char filename[256];

	if (parm->numparms != 1) return OSDCMD_SHOWHELP;
	
	strcpy(filename,parm->parms[0]);
	if( strchr(filename,'.') == 0)
        	strcat(filename,".map");

	if ((i = kopen4load(filename,0)) < 0) {
		OSD_Printf("map: file \"%s\" does not exist.\n", filename);
		return OSDCMD_OK;
	}
	kclose(i);

	strcpy(boardfilename, filename);
	
	if (ps[myconnectindex].gm & MODE_GAME) {
		// in-game behave like a cheat
		osdcmd_cheatsinfo_stat.cheatnum = 2;
		osdcmd_cheatsinfo_stat.volume = 0;
		osdcmd_cheatsinfo_stat.level = 7;
	} else {
		// out-of-game behave like a menu command
		osdcmd_cheatsinfo_stat.cheatnum = -1;

		ud.m_volume_number = 0;
		ud.m_level_number = 7;

                ud.m_monsters_off = ud.monsters_off = 0;

                ud.m_respawn_items = 0;
                ud.m_respawn_inventory = 0;

                ud.multimode = 1;
		
	 	newgame(ud.m_volume_number,ud.m_level_number,ud.m_player_skill);
                if (enterlevel(MODE_GAME)) backtomenu();
	}
       
	return OSDCMD_OK;
}
예제 #14
0
파일: sounds.c 프로젝트: Arc0re/dukenukem3d
void playmusic(char *fn)
{
    short      fp;
    long        l;

    if(MusicToggle == 0) return;
    if(MusicDevice == NumSoundCards) return;
    if(eightytwofifty && numplayers > 1) return;

    fp = kopen4load(fn,0);

    if(fp == -1) return;

    l = kfilelength( fp );
    if(l >= 72000)
    {
        kclose(fp);
        return;
    }

    kread( fp, MusicPtr, l);
    kclose( fp );
    MUSIC_PlaySong( MusicPtr, MUSIC_LoopSong );
}
예제 #15
0
int32 RTS_AddFile (char *filename)
   {
   wadinfo_t  header;
   lumpinfo_t *lump_p;
   uint32     i;
   int32      handle, length;
   int32      startlump;
   filelump_t *fileinfo, *fileinfoo;

//
// read the entire file in
//      FIXME: shared opens

   handle = kopen4load(filename, 0);
   if (handle < 0) {
	initprintf("RTS file %s was not found\n",filename);
	return -1;
   }

   startlump = numlumps;

   // WAD file
   initprintf("    Adding %s.\n",filename);
   kread( handle, &header, sizeof( header ) );
   if (strncmp(header.identification,"IWAD",4)) {
	initprintf("RTS file %s doesn't have IWAD id\n",filename);
	kclose(handle);
	return -1;
   }
   header.numlumps = IntelLong(header.numlumps);
   header.infotableofs = IntelLong(header.infotableofs);
   length = header.numlumps*sizeof(filelump_t);
   fileinfo = fileinfoo = (filelump_t*)malloc (length);
   if (!fileinfo) {
	initprintf("RTS file could not allocate header info\n");
	kclose(handle);
	return -1;
   }
   klseek (handle, header.infotableofs, SEEK_SET);
   kread(handle, fileinfo, length);

//
// Fill in lumpinfo
//
   lump_p = realloc(lumpinfo, (numlumps + header.numlumps)*sizeof(lumpinfo_t));
   if (!lump_p) {
	kclose(handle);
	return -1;
   }
   lumpinfo = lump_p;

   numlumps += header.numlumps;

   lump_p = &lumpinfo[startlump];

   for (i=startlump ; i<(uint32)numlumps ; i++,lump_p++, fileinfo++)
      {
      lump_p->handle = handle;
      lump_p->position = IntelLong(fileinfo->filepos);
      lump_p->size = IntelLong(fileinfo->size);
      strncpy (lump_p->name, fileinfo->name, 8);
      }

   free(fileinfoo);

   return 0;
   }
예제 #16
0
void ContextHelp(short spritenum)
{
    int i,fp;
    char t,*tc;
    char x=0,y=4;
    char *name,*hightag;
    char *filebuffer;
    SPRITEp sp;
    short hitag=0;
    long size=0,tokresult=0;

    
    sp = &sprite[spritenum];

    clearmidstatbar16();

    if((fp=kopen4load("swbhelp.hlp",0)) == -1)
    {
        Msg("ERROR: Help file not found.",M_RED);
        return;
    }

    // Read in whole file
    size = kfilelength(fp);    
    filebuffer = (char *)malloc(size);
    if (filebuffer == NULL)
    {
        Msg("Not enough memory to load swhelp.hlp",M_RED);
        return;
    }

    if (kread(fp, filebuffer, size) != size)
    {
        Msg("Unexpected end of file while reading swhelp.hlp",M_RED);
        kclose(fp);
        return;
    }

    // close the file
    kclose(fp);

    // Conver filebuffer to all upper case
    //strupr(filebuffer);

    // Assign a token name to search for based on the sprite being pointed to.
    name = (char *)malloc(20);
    hightag = (char *)malloc(sizeof(short));

    // Make the token
    strcpy(name,"@TAG");
    // Make sure 500-600 SOBJ bounding tags all say the same thing.
    hitag = sp->hitag;
    if(hitag > 500 && hitag <= 600 ) hitag = 500;
    // Give help summary for unknown sprites.
    if((hitag == 0 || hitag > 1006) && sp->lotag == 0) hitag = 999;

    sprintf(hightag,"%d",hitag);
    //itoa(hitag,hightag,10);
    strcat(name,hightag);

    tc = filebuffer;
    
    if(!(tokresult = GetAToken(name,tc,size)))
    {
        // This message should never happen unless something is real wrong!
        Msg("No help available.",M_RED);
        return;
    }       

    tc += tokresult;

    do {
        tc++;
        t = *tc;
        while(t!='\n' && t!='@' && t!='#' && x<128)
        {
            tempbuf[x]=t;
            tc++;
            t = *tc;
            x++;
            if(x >= 128) break;
        }
        tempbuf[x]=0;
        x=0;
        printext16(x*4,ydim16+(y*6)+2,11,-1,tempbuf,1);
        y++;

        if(y>16)
        {
            y=18;
            printext16(x*4,ydim16+(y*6)+2,11,-1,"Hit any key to continue or Q to quit....",1);
            while (BKeyPressed() == NULL);
            if (keystatus[KEYSC_Q])
            {
                clearmidstatbar16();
                return;
            }
            ResetKeys();
            clearmidstatbar16();

            y=6;
        }

     } while(t!='@' && t!='#');
}
예제 #17
0
파일: sound.c 프로젝트: wosigh/duke3d
static unsigned int F_CALLBACKAPI f_open(const char *name)
{
	return kopen4load((char *)name, 0) + 1;
}