int scriptfile_getbraces(scriptfile *sf, char **braceend) { int bracecnt; char *bracestart; skipoverws(sf); if (sf->textptr >= sf->eof) { buildprintf("Error on line %s:%d: unexpected eof\n",sf->filename,scriptfile_getlinum(sf,sf->textptr)); return -1; } if (sf->textptr[0] != '{') { buildprintf("Error on line %s:%d: expecting '{'\n",sf->filename,scriptfile_getlinum(sf,sf->textptr)); return -1; } bracestart = ++sf->textptr; bracecnt = 1; while (1) { if (sf->textptr >= sf->eof) return(0); if (sf->textptr[0] == '{') bracecnt++; if (sf->textptr[0] == '}') { bracecnt--; if (!bracecnt) break; } sf->textptr++; } (*braceend) = sf->textptr; sf->textptr = bracestart; return 0; }
void SoundStartup(void) { int32_t status; void *initdata = 0; int fxdevicetype; // if they chose None lets return if (FXDevice < 0) { gs.FxOn = FALSE; return; } else if (FXDevice == 0) { fxdevicetype = ASS_AutoDetect; } else { fxdevicetype = FXDevice - 1; } #ifdef MIXERTYPEWIN initdata = (void *) win_gethwnd(); #endif //gs.FxOn = TRUE; status = FX_Init(fxdevicetype, NumVoices, NumChannels, NumBits, MixRate, initdata); if (status == FX_Ok) { FxInitialized = TRUE; FX_SetVolume(gs.SoundVolume); if (gs.FlipStereo) FX_SetReverseStereo(!FX_GetReverseStereo()); } if (status != FX_Ok) { buildprintf("Sound error: %s\n",FX_ErrorString(FX_Error)); } status = FX_SetCallBack(SoundCallBack); if (status != FX_Ok) { buildprintf("Sound error: %s\n",FX_ErrorString(FX_Error)); } }
void MusicStartup( void ) { int32 status; int musicdevicetype; // if they chose None lets return if (MusicDevice < 0) { return; } else if (MusicDevice == 0) { musicdevicetype = ASS_AutoDetect; } else { musicdevicetype = MusicDevice - 1; } status = MUSIC_Init( musicdevicetype, MusicParams ); if ( status == MUSIC_Ok ) { MUSIC_SetVolume( MusicVolume ); } else { buildprintf("Couldn't find selected sound card, or, error w/ sound card itself.\n"); SoundShutdown(); uninittimer(); uninitengine(); CONTROL_Shutdown(); CONFIG_WriteSetup(); KB_Shutdown(); uninitgroupfile(); //unlink("duke3d.tmp"); exit(-1); } }
char testcd( char *fn, long testsiz ) { DWORD driveletters; int i, fil, dalen; char name[32]="x:\\SUPPORT\\",driv[4]="x:\\"; strcat(name,fn); driveletters = GetLogicalDrives(); for (i=2; i<26; i++) { if (!(driveletters & (1ul<<i))) continue; driv[0] = 'A'+i; if (GetDriveType(driv) != DRIVE_CDROM) continue; name[0] = 'A'+i; fil = Bopen(name,O_RDONLY,S_IREAD); if (fil<0) continue; dalen = Bfilelength(fil); Bclose(fil); if (dalen == testsiz) { buildprintf("Copy Protection: Found CDROM in drive %c:\n", driv[0]); return 0; } } wm_msgbox("Duke Nukem 3D","Copy Protection: Failed to find CDROM"); return 1; }
// // initinput() -- init input system // int initinput(void) { int i,j; #ifdef __APPLE__ // force OS X to operate in >1 button mouse mode so that LMB isn't adulterated if (!getenv("SDL_HAS3BUTTONMOUSE")) putenv("SDL_HAS3BUTTONMOUSE=1"); #endif if (SDL_EnableKeyRepeat(250, 30)) buildputs("Error enabling keyboard repeat.\n"); inputdevices = 1|2; // keyboard (1) and mouse (2) mouseacquired = 0; SDL_EnableUNICODE(1); // let's hope this doesn't hit us too hard memset(keynames,0,sizeof(keynames)); for (i=0; i<SDLK_LAST; i++) { if (!keytranslation[i]) continue; strncpy(keynames[ keytranslation[i] ], SDL_GetKeyName(i), sizeof(keynames[i])-1); } if (!SDL_InitSubSystem(SDL_INIT_JOYSTICK)) { i = SDL_NumJoysticks(); buildprintf("%d joystick(s) found\n",i); for (j=0;j<i;j++) buildprintf(" %d. %s\n", j+1, SDL_JoystickName(j)); joydev = SDL_JoystickOpen(0); if (joydev) { SDL_JoystickEventState(SDL_ENABLE); inputdevices |= 4; joynumaxes = SDL_JoystickNumAxes(joydev); joynumbuttons = min(32,SDL_JoystickNumButtons(joydev)); joynumhats = SDL_JoystickNumHats(joydev); buildprintf("Joystick 1 has %d axes, %d buttons, and %d hat(s).\n", joynumaxes,joynumbuttons,joynumhats); joyaxis = Bcalloc(joynumaxes, sizeof(int)); if (joynumhats > 0) { joyhat = malloc(joynumhats * sizeof(int)); memset(joyhat, -1, sizeof(int)*joynumhats); } } } return 0; }
int scriptfile_getstring(scriptfile *sf, char **retst) { (*retst) = scriptfile_gettoken(sf); if (*retst == NULL) { buildprintf("Error on line %s:%d: unexpected eof\n",sf->filename,scriptfile_getlinum(sf,sf->textptr)); return(-2); } return(0); }
int scriptfile_getnumber(scriptfile *sf, int *num) { skipoverws(sf); if (sf->textptr >= sf->eof) { buildprintf("Error on line %s:%d: unexpected eof\n",sf->filename,scriptfile_getlinum(sf,sf->textptr)); return -1; } while ((sf->textptr[0] == '0') && (sf->textptr[1] >= '0') && (sf->textptr[1] <= '9')) sf->textptr++; //hack to treat octal numbers like decimal sf->ltextptr = sf->textptr; (*num) = strtol((const char *)sf->textptr,&sf->textptr,0); if (!ISWS(*sf->textptr) && *sf->textptr) { char *p = sf->textptr; skipovertoken(sf); buildprintf("Error on line %s:%d: expecting int, got \"%s\"\n",sf->filename,scriptfile_getlinum(sf,sf->ltextptr),p); return -2; } return 0; }
int scriptfile_getdouble(scriptfile *sf, double *num) { skipoverws(sf); if (sf->textptr >= sf->eof) { buildprintf("Error on line %s:%d: unexpected eof\n",sf->filename,scriptfile_getlinum(sf,sf->textptr)); return -1; } sf->ltextptr = sf->textptr; // On Linux, locale settings interfere with interpreting x.y format numbers //(*num) = strtod((const char *)sf->textptr,&sf->textptr); (*num) = parsedouble(sf->textptr, &sf->textptr); if (!ISWS(*sf->textptr) && *sf->textptr) { char *p = sf->textptr; skipovertoken(sf); buildprintf("Error on line %s:%d: expecting float, got \"%s\"\n",sf->filename,scriptfile_getlinum(sf,sf->ltextptr),p); return -2; } return 0; }
int scriptfile_getsymbol(scriptfile *sf, int *num) { char *t, *e; int v; t = scriptfile_gettoken(sf); if (!t) return -1; v = Bstrtol(t, &e, 10); if (*e) { // looks like a string, so find it in the symbol table if (scriptfile_getsymbolvalue(t, num)) return 0; buildprintf("Error on line %s:%d: expecting symbol, got \"%s\"\n",sf->filename,scriptfile_getlinum(sf,sf->ltextptr),t); return -2; // not found } *num = v; return 0; }
void MusicShutdown(void) { int32_t status; // if they chose None lets return if (MusicDevice < 0) return; if (!MusicInitialized) return; StopSong(); status = MUSIC_Shutdown(); if (status != MUSIC_Ok) { buildprintf("Music error: %s\n",MUSIC_ErrorString(MUSIC_ErrorCode)); } }
void SoundShutdown(void) { int32_t status; // if they chose None lets return if (FXDevice < 0) { return; } if (!FxInitialized) return; status = FX_Shutdown(); if (status != FX_Ok) { buildprintf("Sound error: %s\n",FX_ErrorString(FX_Error)); } }
void MusicStartup(void) { int32_t status; int devicetype; // if they chose None lets return if (MusicDevice < 0) { gs.MusicOn = FALSE; return; } else if (MusicDevice == 0) { devicetype = ASS_AutoDetect; } else { devicetype = MusicDevice - 1; } status = MUSIC_Init(devicetype, 0); if (status == MUSIC_Ok) { MusicInitialized = TRUE; MUSIC_SetVolume(gs.MusicVolume); } else { buildprintf("Music error: %s\n",MUSIC_ErrorString(MUSIC_ErrorCode)); gs.MusicOn = FALSE; } if (MusicInitialized) loadtmb(); }
void ReadGameSetup(int32_t scripthandle) { int dummy; int ret; extern char WangBangMacro[10][64]; for (dummy = 0; dummy < 10; dummy++) { sprintf(ds,"CommbatMacro#%d",dummy); SCRIPT_GetString(scripthandle, "Comm Setup",ds,WangBangMacro[dummy]); } SCRIPT_GetString(scripthandle, "Options","Rooster",gs.Password); DecodePassword(gs.Password); // option stuff dummy = -1; ret = SCRIPT_GetNumber(scripthandle, "Options", "BorderNum",&dummy); if (dummy != -1) gs.BorderNum = dummy; dummy = -1; SCRIPT_GetNumber(scripthandle, "Options", "Brightness",&dummy); if (dummy != -1) gs.Brightness = dummy; dummy = -1; SCRIPT_GetNumber(scripthandle, "Options", "BorderTile",&dummy); if (dummy != -1) gs.BorderTile = dummy; dummy = -1; SCRIPT_GetNumber(scripthandle, "Options", "Bobbing",&dummy); if (dummy != -1) gs.Bobbing = dummy; dummy = -1; SCRIPT_GetNumber(scripthandle, "Options", "Tilting",&dummy); if (dummy != -1) gs.Tilting = dummy; dummy = -1; SCRIPT_GetNumber(scripthandle, "Options", "Shadows",&dummy); if (dummy != -1) gs.Shadows = dummy; dummy = -1; SCRIPT_GetNumber(scripthandle, "Options", "AutoRun",&dummy); if (dummy != -1) gs.AutoRun = dummy; dummy = -1; SCRIPT_GetNumber(scripthandle, "Options", "Crosshair",&dummy); if (dummy != -1) gs.Crosshair = dummy; dummy = -1; SCRIPT_GetNumber(scripthandle, "Options", "AutoAim",&dummy); if (dummy != -1) gs.AutoAim = dummy; dummy = -1; SCRIPT_GetNumber(scripthandle, "Options", "Messages",&dummy); if (dummy != -1) gs.Messages = dummy; dummy = -1; SCRIPT_GetNumber(scripthandle, "Options", "Talking",&dummy); if (dummy != -1) gs.Talking = dummy; dummy = -1; SCRIPT_GetNumber(scripthandle, "Options", "Ambient",&dummy); if (dummy != -1) gs.Ambient = dummy; dummy = -1; SCRIPT_GetNumber(scripthandle, "Options", "FxOn",&dummy); if (dummy != -1) gs.FxOn = dummy; dummy = -1; SCRIPT_GetNumber(scripthandle, "Options", "MusicOn",&dummy); if (dummy != -1) gs.MusicOn = dummy; dummy = -1; SCRIPT_GetNumber(scripthandle, "Controls", "MouseAiming",&dummy); if (dummy != -1) gs.MouseAimingType = dummy; dummy = -1; SCRIPT_GetNumber(scripthandle, "Options", "NetGameType",&dummy); if (dummy != -1) gs.NetGameType = dummy; dummy = -1; SCRIPT_GetNumber(scripthandle, "Options", "NetLevel",&dummy); if (dummy != -1) gs.NetLevel = dummy; dummy = -1; SCRIPT_GetNumber(scripthandle, "Options", "NetMonsters",&dummy); if (dummy != -1) gs.NetMonsters = dummy; dummy = -1; SCRIPT_GetNumber(scripthandle, "Options", "NetHurtTeammate",&dummy); if (dummy != -1) gs.NetHurtTeammate = dummy; dummy = -1; SCRIPT_GetNumber(scripthandle, "Options", "NetSpawnMarkers",&dummy); if (dummy != -1) gs.NetSpawnMarkers = dummy; dummy = -1; SCRIPT_GetNumber(scripthandle, "Options", "NetTeamPlay",&dummy); if (dummy != -1) gs.NetTeamPlay = dummy; dummy = -1; SCRIPT_GetNumber(scripthandle, "Options", "NetKillLimit",&dummy); if (dummy != -1) gs.NetKillLimit = dummy; dummy = -1; SCRIPT_GetNumber(scripthandle, "Options", "NetTimeLimit",&dummy); if (dummy != -1) gs.NetTimeLimit = dummy; dummy = -1; SCRIPT_GetNumber(scripthandle, "Options", "NetColor",&dummy); if (dummy != -1) gs.NetColor = dummy; dummy = -1; SCRIPT_GetNumber(scripthandle, "Options", "Voxels",&dummy); if (dummy != -1) gs.Voxels = dummy; dummy = -1; SCRIPT_GetNumber(scripthandle, "Options", "Stats",&dummy); if (dummy != -1) gs.Stats = dummy; dummy = -1; SCRIPT_GetNumber(scripthandle, "Options", "MouseAimingOn",&dummy); if (dummy != -1) gs.MouseAimingOn = dummy; dummy = -1; SCRIPT_GetNumber(scripthandle, "Options", "MouseInvert",&dummy); if (dummy != -1) gs.MouseInvert = dummy; dummy = -1; SCRIPT_GetNumber(scripthandle, "Options", "Kiwi",&dummy); if (dummy != -1) gs.ParentalLock = dummy; dummy = -1; SCRIPT_GetNumber(scripthandle, "Options", "PlayCD",&dummy); if (dummy != -1) gs.PlayCD = dummy; dummy = -1; SCRIPT_GetNumber(scripthandle, "Options", "CDDevice",&dummy); if (dummy < 0) dummy = -1; if (SW_SHAREWARE) { dummy = -1; SCRIPT_GetNumber(scripthandle, "Options", "Chickens",&dummy); if (dummy != -1) GamePlays = dummy; buildprintf( "\n" "You have played Shadow Warrior %d times. Please call and order the full\n" "version at 1(800)-3DREALMS or see the ORDER.FRM file.\n\n" ,GamePlays); GamePlays++; } }
int loadsetup(const char *fn) { scriptfile *cfg; char *token; int item; cfg = scriptfile_fromfile(fn); if (!cfg) { return -1; } scriptfile_clearsymbols(); option[0] = 1; // vesa all the way... option[1] = 1; // sound all the way... option[4] = 0; // no multiplayer option[5] = 0; while (1) { token = scriptfile_gettoken(cfg); if (!token) break; //EOF for (item = 0; configspec[item].name; item++) { if (!Bstrcasecmp(token, configspec[item].name)) { // Seek past any = symbol. token = scriptfile_peektoken(cfg); if (!Bstrcasecmp("=", token)) { scriptfile_gettoken(cfg); } switch (configspec[item].type) { case type_bool: { int value = 0; if (scriptfile_getnumber(cfg, &value)) break; *(int*)configspec[item].store = (value != 0); break; } case type_int: { int value = 0; if (scriptfile_getnumber(cfg, &value)) break; *(int*)configspec[item].store = value; break; } case type_hex: { int value = 0; if (scriptfile_gethex(cfg, &value)) break; *(int*)configspec[item].store = value; break; } case type_double: { double value = 0.0; if (scriptfile_getdouble(cfg, &value)) break; *(double*)configspec[item].store = value; break; } default: { buildputs("loadsetup: unhandled value type\n"); break; } } break; } } if (!configspec[item].name) { buildprintf("loadsetup: error on line %d\n", scriptfile_getlinum(cfg, cfg->ltextptr)); continue; } } #if USE_POLYMOST if (tmprenderer >= 0) { setrendermode(tmprenderer); } #endif if (tmpbrightness >= 0) { brightness = min(max(tmpbrightness,0),15); } OSD_CaptureKey(keys[19]); scriptfile_close(cfg); scriptfile_clearsymbols(); return 0; }
// // initsystem() -- init SDL systems // int initsystem(void) { const SDL_VideoInfo *vid; const SDL_version *linked = SDL_Linked_Version(); SDL_version compiled; char drvname[32]; SDL_VERSION(&compiled); buildprintf("Initialising SDL system interface " "(compiled with SDL version %d.%d.%d, DLL version %d.%d.%d)\n", linked->major, linked->minor, linked->patch, compiled.major, compiled.minor, compiled.patch); if (SDL_Init(SDL_INIT_VIDEO //| SDL_INIT_TIMER #ifdef NOSDLPARACHUTE | SDL_INIT_NOPARACHUTE #endif )) { buildprintf("Initialisation failed! (%s)\n", SDL_GetError()); return -1; } atexit(uninitsystem); frameplace = 0; lockcount = 0; #ifdef USE_OPENGL if (loadgldriver(getenv("BUILD_GLDRV"))) { buildputs("Failed loading OpenGL driver. GL modes will be unavailable.\n"); nogl = 1; } #endif #ifndef __APPLE__ { SDL_Surface *icon; icon = loadappicon(); if (icon) { SDL_WM_SetIcon(icon, 0); SDL_FreeSurface(icon); } } #endif if (SDL_VideoDriverName(drvname, 32)) buildprintf("Using \"%s\" video driver\n", drvname); // dump a quick summary of the graphics hardware #ifdef DEBUGGINGAIDS vid = SDL_GetVideoInfo(); buildputs("Video device information:\n"); buildprintf(" Can create hardware surfaces? %s\n", (vid->hw_available)?"Yes":"No"); buildprintf(" Window manager available? %s\n", (vid->wm_available)?"Yes":"No"); buildprintf(" Accelerated hardware blits? %s\n", (vid->blit_hw)?"Yes":"No"); buildprintf(" Accelerated hardware colourkey blits? %s\n", (vid->blit_hw_CC)?"Yes":"No"); buildprintf(" Accelerated hardware alpha blits? %s\n", (vid->blit_hw_A)?"Yes":"No"); buildprintf(" Accelerated software blits? %s\n", (vid->blit_sw)?"Yes":"No"); buildprintf(" Accelerated software colourkey blits? %s\n", (vid->blit_sw_CC)?"Yes":"No"); buildprintf(" Accelerated software alpha blits? %s\n", (vid->blit_sw_A)?"Yes":"No"); buildprintf(" Accelerated colour fills? %s\n", (vid->blit_fill)?"Yes":"No"); buildprintf(" Total video memory: %dKB\n", vid->video_mem); #endif return 0; }
SWBOOL PlaySong(char *song_file_name, int cdaudio_track, SWBOOL loop, SWBOOL restart) { if (!gs.MusicOn) { return FALSE; } if (DemoMode) return FALSE; if (!restart) { if (SongType == SongTypeWave) { if (SongTrack > 0 && SongTrack == cdaudio_track) { // ogg replacement for a CD track return TRUE; } else if (SongName && song_file_name && !strcmp(SongName, song_file_name)) { return TRUE; } } else if (SongType == SongTypeMIDI) { if (SongName && song_file_name && !strcmp(SongName, song_file_name)) { return TRUE; } } } StopSong(); if (!SW_SHAREWARE) { if (cdaudio_track >= 0) { char waveformtrack[MAXWAVEFORMTRACKLENGTH]; Bstrncpy(waveformtrack, gs.WaveformTrackName, MAXWAVEFORMTRACKLENGTH - 1); char *numPos = Bstrstr(waveformtrack, "??"); if (numPos && (numPos-waveformtrack) < MAXWAVEFORMTRACKLENGTH - 2) { static const char *tracktypes[] = { ".flac", ".ogg" }; const size_t tracknamebaselen = Bstrlen(waveformtrack); size_t i; numPos[0] = '0' + (cdaudio_track / 10) % 10; numPos[1] = '0' + cdaudio_track % 10; for (i = 0; i < ARRAY_SIZE(tracktypes); ++i) { waveformtrack[tracknamebaselen] = '\0'; Bstrncat(waveformtrack, tracktypes[i], MAXWAVEFORMTRACKLENGTH); if (LoadSong(waveformtrack)) { SongVoice = FX_PlayLoopedAuto(SongPtr, SongLength, 0, 0, 0, 255, 255, 255, FX_MUSIC_PRIORITY, MUSIC_ID); if (SongVoice > FX_Ok) { SongType = SongTypeWave; SongTrack = cdaudio_track; SongName = Bstrdup(waveformtrack); return TRUE; } } } buildprintf("Can't find CD track %i!\n", cdaudio_track); } else { buildprintf("Make sure to have \"??\" as a placeholder for the track number in your WaveformTrackName!\n"); buildprintf(" e.g. WaveformTrackName = \"MUSIC/Track??\"\n"); } } } if (!song_file_name || !LoadSong(song_file_name)) { return FALSE; } if (!memcmp(SongPtr, "MThd", 4)) { MUSIC_PlaySong(SongPtr, /*SongLength,*/ MUSIC_LoopSong); SongType = SongTypeMIDI; SongName = strdup(song_file_name); return TRUE; } else { SongVoice = FX_PlayLoopedAuto(SongPtr, SongLength, 0, 0, 0, 255, 255, 255, FX_MUSIC_PRIORITY, MUSIC_ID); if (SongVoice > FX_Ok) { SongType = SongTypeWave; SongName = strdup(song_file_name); return TRUE; } } return FALSE; }