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; }
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 ); }
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; }
uint8_t loadsound(uint16_t num) { int32_t fp, l; if (num >= NUM_SOUNDS || SoundToggle == 0) { return 0; } if (FXDevice == NumSoundCards) { return 0; } fp = TCkopen4load(sounds[num],0); if (fp == -1) { sprintf(&fta_quotes[113][0],"Sound %s(#%d) not found.",sounds[num],num); FTA(113,&ps[myconnectindex],1); return 0; } l = kfilelength( fp ); soundsiz[num] = l; Sound[num].lock = 200; allocache(&Sound[num].ptr,l,(uint8_t *)&Sound[num].lock); kread( fp, Sound[num].ptr , l); kclose( fp ); return 1; }
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; }
// returns number of bytes read int32_t S_LoadSound(uint32_t num) { if (num > (unsigned)g_maxSoundPos || !ud.config.SoundToggle ) return 0; if (EDUKE32_PREDICT_FALSE(g_sounds[num].filename == NULL)) { OSD_Printf(OSD_ERROR "Sound (#%d) not defined!\n",num); return 0; } int32_t fp = S_OpenAudio(g_sounds[num].filename, g_loadFromGroupOnly, 0); if (EDUKE32_PREDICT_FALSE(fp == -1)) { OSD_Printf(OSDTEXT_RED "Sound %s(#%d) not found!\n",g_sounds[num].filename,num); return 0; } int32_t l = kfilelength(fp); g_soundlocks[num] = 200; g_sounds[num].soundsiz = l; allocache((intptr_t *)&g_sounds[num].ptr, l, (char *)&g_soundlocks[num]); l = kread(fp, g_sounds[num].ptr, l); kclose(fp); return l; }
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; }
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; }
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; }
int32_t S_PlayMusic(const char *fn) { if (!ud.config.MusicToggle || fn == NULL) return 0; int32_t fp = S_OpenAudio(fn, 0, 1); if (EDUKE32_PREDICT_FALSE(fp < 0)) { OSD_Printf(OSD_ERROR "S_PlayMusic(): error: can't open \"%s\" for playback!\n",fn); return 0; } S_StopMusic(); int32_t MusicLen = kfilelength(fp); if (EDUKE32_PREDICT_FALSE(MusicLen < 4)) { OSD_Printf(OSD_ERROR "S_PlayMusic(): error: empty music file \"%s\"\n", fn); kclose(fp); return 0; } ALIGNED_FREE_AND_NULL(MusicPtr); // in case the following allocation was never freed MusicPtr = (char *)Xaligned_alloc(16, MusicLen); g_musicSize = kread(fp, (char *)MusicPtr, MusicLen); if (EDUKE32_PREDICT_FALSE(g_musicSize != MusicLen)) { OSD_Printf(OSD_ERROR "S_PlayMusic(): error: read %d bytes from \"%s\", expected %d\n", g_musicSize, fn, MusicLen); kclose(fp); g_musicSize = 0; return 0; } kclose(fp); if (!Bmemcmp(MusicPtr, "MThd", 4)) { MUSIC_PlaySong(MusicPtr, MUSIC_LoopSong); MusicIsWaveform = 0; } else { int32_t const mvol = MASTER_VOLUME(ud.config.MusicVolume); MusicVoice = FX_PlayLoopedAuto(MusicPtr, MusicLen, 0, 0, 0, mvol, mvol, mvol, FX_MUSIC_PRIORITY, MUSIC_ID); if (MusicVoice > FX_Ok) MusicIsWaveform = 1; } return 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; }
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); }
SWBOOL OpenSound(VOC_INFOp vp, int *handle, int *length) { *handle = kopen4load(vp->name, 0); if (*handle == -1) { return FALSE; } *length = kfilelength(*handle); return TRUE; }
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 ); }
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!='#'); }