2006-03-20 17:12:09 +00:00
|
|
|
/*
|
|
|
|
THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
|
|
|
|
SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
|
|
|
|
END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
|
|
|
|
ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
|
|
|
|
IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
|
|
|
|
SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
|
|
|
|
FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
|
|
|
|
CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
|
|
|
|
AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
|
|
|
|
COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
* contains routine(s) to read in the configuration file which contains
|
|
|
|
* game configuration stuff like detail level, sound card, etc
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <conf.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <ctype.h>
|
2007-04-09 02:41:45 +00:00
|
|
|
#if !(defined(__APPLE__) && defined(__MACH__))
|
2006-03-20 17:12:09 +00:00
|
|
|
#include <physfs.h>
|
2007-04-09 02:41:45 +00:00
|
|
|
#else
|
|
|
|
#include <physfs/physfs.h>
|
|
|
|
#endif
|
2008-04-06 20:23:28 +00:00
|
|
|
#include "config.h"
|
2006-03-20 17:12:09 +00:00
|
|
|
#include "pstypes.h"
|
|
|
|
#include "game.h"
|
|
|
|
#include "menu.h"
|
|
|
|
#include "movie.h"
|
|
|
|
#include "digi.h"
|
|
|
|
#include "kconfig.h"
|
|
|
|
#include "palette.h"
|
|
|
|
#include "joy.h"
|
|
|
|
#include "songs.h"
|
|
|
|
#include "args.h"
|
|
|
|
#include "player.h"
|
|
|
|
#include "mission.h"
|
|
|
|
#include "physfsx.h"
|
|
|
|
|
2008-04-06 20:23:28 +00:00
|
|
|
struct Cfg GameCfg;
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2007-07-26 23:57:29 +00:00
|
|
|
static char *DigiVolumeStr = "DigiVolume";
|
2008-05-24 08:59:35 +00:00
|
|
|
static char *MusicVolumeStr = "MidiVolume";
|
|
|
|
static char *SndEnableRedbookStr = "RedbookEnabled";
|
2007-11-06 20:33:22 +00:00
|
|
|
static char *ReverseStereoStr = "ReverseStereo";
|
2007-07-26 23:57:29 +00:00
|
|
|
static char *GammaLevelStr = "GammaLevel";
|
|
|
|
static char *LastPlayerStr = "LastPlayer";
|
|
|
|
static char *LastMissionStr = "LastMission";
|
|
|
|
static char *ResolutionXStr="ResolutionX";
|
|
|
|
static char *ResolutionYStr="ResolutionY";
|
2008-04-06 20:23:28 +00:00
|
|
|
static char *AspectXStr="AspectX";
|
|
|
|
static char *AspectYStr="AspectY";
|
|
|
|
static char *WindowModeStr="WindowMode";
|
|
|
|
static char *TexFiltStr="TexFilt";
|
2008-04-21 18:39:49 +00:00
|
|
|
static char *VSyncStr="VSync";
|
2008-04-22 08:29:29 +00:00
|
|
|
static char *MultisampleStr="Multisample";
|
2008-05-01 21:40:34 +00:00
|
|
|
static char *JukeboxOnStr="JukeboxOn";
|
|
|
|
static char *JukeboxPathStr="JukeboxPath";
|
2008-05-16 11:39:27 +00:00
|
|
|
static char *IPHostAddrStr="IPHostAddr";
|
2006-03-20 17:12:09 +00:00
|
|
|
|
|
|
|
int ReadConfigFile()
|
|
|
|
{
|
|
|
|
PHYSFS_file *infile;
|
|
|
|
char line[80], *token, *value, *ptr;
|
|
|
|
|
2008-04-06 20:23:28 +00:00
|
|
|
// set defaults
|
|
|
|
GameCfg.DigiVolume = 8;
|
2008-05-24 08:59:35 +00:00
|
|
|
GameCfg.MusicVolume = 8;
|
|
|
|
GameCfg.SndEnableRedbook = 0;
|
2008-04-06 20:23:28 +00:00
|
|
|
GameCfg.ReverseStereo = 0;
|
|
|
|
GameCfg.GammaLevel = 0;
|
|
|
|
memset(GameCfg.LastPlayer,0,CALLSIGN_LEN+1);
|
|
|
|
memset(GameCfg.LastMission,0,MISSION_NAME_LEN+1);
|
|
|
|
GameCfg.ResolutionX = 640;
|
|
|
|
GameCfg.ResolutionY = 480;
|
|
|
|
GameCfg.AspectX = 3;
|
|
|
|
GameCfg.AspectY = 4;
|
|
|
|
GameCfg.WindowMode = 0;
|
|
|
|
GameCfg.TexFilt = 0;
|
2008-04-21 18:39:49 +00:00
|
|
|
GameCfg.VSync = 0;
|
2008-04-22 08:29:29 +00:00
|
|
|
GameCfg.Multisample = 0;
|
2008-05-01 21:40:34 +00:00
|
|
|
GameCfg.JukeboxOn = 0;
|
|
|
|
memset(GameCfg.JukeboxPath,0,PATH_MAX+1);
|
2008-07-01 11:22:36 +00:00
|
|
|
#ifndef macintosh // Mac OS 9 binary is in .app bundle
|
2008-05-18 07:13:07 +00:00
|
|
|
strncpy(GameCfg.JukeboxPath, "Jukebox", PATH_MAX+1); // maybe include this directory with the binary
|
2008-07-01 11:22:36 +00:00
|
|
|
#else
|
|
|
|
strncpy(GameCfg.JukeboxPath, "::::Jukebox", PATH_MAX+1);
|
|
|
|
#endif
|
2008-10-28 17:58:54 +00:00
|
|
|
memset(GameCfg.MplIpHostAddr, '\x0', sizeof(GameCfg.MplIpHostAddr));
|
2006-03-20 17:12:09 +00:00
|
|
|
|
|
|
|
infile = PHYSFSX_openReadBuffered("descent.cfg");
|
2007-07-26 23:57:29 +00:00
|
|
|
|
2006-03-20 17:12:09 +00:00
|
|
|
if (infile == NULL) {
|
|
|
|
return 1;
|
|
|
|
}
|
2007-07-26 23:57:29 +00:00
|
|
|
|
2006-03-20 17:12:09 +00:00
|
|
|
while (!PHYSFS_eof(infile))
|
|
|
|
{
|
|
|
|
memset(line, 0, 80);
|
|
|
|
PHYSFSX_gets(infile, line);
|
|
|
|
ptr = &(line[0]);
|
|
|
|
while (isspace(*ptr))
|
|
|
|
ptr++;
|
|
|
|
if (*ptr != '\0') {
|
|
|
|
token = strtok(ptr, "=");
|
|
|
|
value = strtok(NULL, "=");
|
|
|
|
if (!value)
|
|
|
|
value = "";
|
2007-07-26 23:57:29 +00:00
|
|
|
if (!strcmp(token, DigiVolumeStr))
|
2008-04-06 20:23:28 +00:00
|
|
|
GameCfg.DigiVolume = strtol(value, NULL, 10);
|
2008-05-24 08:59:35 +00:00
|
|
|
else if (!strcmp(token, MusicVolumeStr))
|
|
|
|
GameCfg.MusicVolume = strtol(value, NULL, 10);
|
|
|
|
else if (!strcmp(token, SndEnableRedbookStr))
|
|
|
|
GameCfg.SndEnableRedbook = strtol(value, NULL, 10);
|
2007-11-06 20:33:22 +00:00
|
|
|
else if (!strcmp(token, ReverseStereoStr))
|
2008-04-06 20:23:28 +00:00
|
|
|
GameCfg.ReverseStereo = strtol(value, NULL, 10);
|
2007-07-26 23:57:29 +00:00
|
|
|
else if (!strcmp(token, GammaLevelStr)) {
|
2008-04-06 20:23:28 +00:00
|
|
|
GameCfg.GammaLevel = strtol(value, NULL, 10);
|
|
|
|
gr_palette_set_gamma( GameCfg.GammaLevel );
|
2006-03-20 17:12:09 +00:00
|
|
|
}
|
2007-07-26 23:57:29 +00:00
|
|
|
else if (!strcmp(token, LastPlayerStr)) {
|
2006-03-20 17:12:09 +00:00
|
|
|
char * p;
|
2008-04-06 20:23:28 +00:00
|
|
|
strncpy( GameCfg.LastPlayer, value, CALLSIGN_LEN );
|
|
|
|
p = strchr( GameCfg.LastPlayer, '\n');
|
2006-03-20 17:12:09 +00:00
|
|
|
if ( p ) *p = 0;
|
|
|
|
}
|
2007-07-26 23:57:29 +00:00
|
|
|
else if (!strcmp(token, LastMissionStr)) {
|
2006-03-20 17:12:09 +00:00
|
|
|
char * p;
|
2008-04-06 20:23:28 +00:00
|
|
|
strncpy( GameCfg.LastMission, value, MISSION_NAME_LEN );
|
|
|
|
p = strchr( GameCfg.LastMission, '\n');
|
2006-03-20 17:12:09 +00:00
|
|
|
if ( p ) *p = 0;
|
|
|
|
}
|
2007-07-26 23:57:29 +00:00
|
|
|
else if (!strcmp(token, ResolutionXStr))
|
2008-04-06 20:23:28 +00:00
|
|
|
GameCfg.ResolutionX = strtol(value, NULL, 10);
|
2007-07-26 23:57:29 +00:00
|
|
|
else if (!strcmp(token, ResolutionYStr))
|
2008-04-06 20:23:28 +00:00
|
|
|
GameCfg.ResolutionY = strtol(value, NULL, 10);
|
|
|
|
else if (!strcmp(token, AspectXStr))
|
|
|
|
GameCfg.AspectX = strtol(value, NULL, 10);
|
|
|
|
else if (!strcmp(token, AspectYStr))
|
|
|
|
GameCfg.AspectY = strtol(value, NULL, 10);
|
|
|
|
else if (!strcmp(token, WindowModeStr))
|
|
|
|
GameCfg.WindowMode = strtol(value, NULL, 10);
|
|
|
|
else if (!strcmp(token, TexFiltStr))
|
|
|
|
GameCfg.TexFilt = strtol(value, NULL, 10);
|
2008-04-21 18:39:49 +00:00
|
|
|
else if (!strcmp(token, VSyncStr))
|
|
|
|
GameCfg.VSync = strtol(value, NULL, 10);
|
2008-04-22 08:29:29 +00:00
|
|
|
else if (!strcmp(token, MultisampleStr))
|
|
|
|
GameCfg.Multisample = strtol(value, NULL, 10);
|
2008-05-01 21:40:34 +00:00
|
|
|
else if (!strcmp(token, JukeboxOnStr))
|
|
|
|
GameCfg.JukeboxOn = strtol(value, NULL, 10);
|
|
|
|
else if (!strcmp(token, JukeboxPathStr)) {
|
|
|
|
char * p;
|
|
|
|
strncpy( GameCfg.JukeboxPath, value, PATH_MAX );
|
|
|
|
p = strchr( GameCfg.JukeboxPath, '\n');
|
|
|
|
if ( p ) *p = 0;
|
|
|
|
}
|
2008-05-16 11:39:27 +00:00
|
|
|
else if (!strcmp(token, IPHostAddrStr)) {
|
|
|
|
char * p;
|
|
|
|
strncpy( GameCfg.MplIpHostAddr, value, 128 );
|
|
|
|
p = strchr( GameCfg.MplIpHostAddr, '\n');
|
|
|
|
if ( p ) *p = 0;
|
|
|
|
}
|
2006-03-20 17:12:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PHYSFS_close(infile);
|
|
|
|
|
2008-04-06 20:23:28 +00:00
|
|
|
if ( GameCfg.DigiVolume > 8 ) GameCfg.DigiVolume = 8;
|
2008-05-24 08:59:35 +00:00
|
|
|
if ( GameCfg.MusicVolume > 8 ) GameCfg.MusicVolume = 8;
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2008-05-24 08:59:35 +00:00
|
|
|
digi_set_volume( (GameCfg.DigiVolume*32768)/8, (GameCfg.MusicVolume*128)/8 );
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2008-04-06 20:23:28 +00:00
|
|
|
if (GameCfg.ResolutionX >= 320 && GameCfg.ResolutionY >= 200)
|
|
|
|
Game_screen_mode = SM(GameCfg.ResolutionX,GameCfg.ResolutionY);
|
2006-03-20 17:12:09 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int WriteConfigFile()
|
|
|
|
{
|
|
|
|
PHYSFS_file *infile;
|
2008-04-06 20:23:28 +00:00
|
|
|
|
|
|
|
GameCfg.GammaLevel = gr_palette_get_gamma();
|
2006-03-20 17:12:09 +00:00
|
|
|
|
|
|
|
infile = PHYSFSX_openWriteBuffered("descent.cfg");
|
2007-07-26 23:57:29 +00:00
|
|
|
|
2006-03-20 17:12:09 +00:00
|
|
|
if (infile == NULL) {
|
|
|
|
return 1;
|
|
|
|
}
|
2007-07-26 23:57:29 +00:00
|
|
|
|
2008-04-06 20:23:28 +00:00
|
|
|
PHYSFSX_printf(infile, "%s=%d\n", DigiVolumeStr, GameCfg.DigiVolume);
|
2008-05-24 08:59:35 +00:00
|
|
|
PHYSFSX_printf(infile, "%s=%d\n", MusicVolumeStr, GameCfg.MusicVolume);
|
|
|
|
PHYSFSX_printf(infile, "%s=%d\n", SndEnableRedbookStr, GameCfg.SndEnableRedbook);
|
2008-04-06 20:23:28 +00:00
|
|
|
PHYSFSX_printf(infile, "%s=%d\n", ReverseStereoStr, GameCfg.ReverseStereo);
|
|
|
|
PHYSFSX_printf(infile, "%s=%d\n", GammaLevelStr, GameCfg.GammaLevel);
|
2008-10-28 17:58:54 +00:00
|
|
|
PHYSFSX_printf(infile, "%s=%s\n", LastPlayerStr, Players[Player_num].callsign);
|
|
|
|
PHYSFSX_printf(infile, "%s=%s\n", LastMissionStr, GameCfg.LastMission);
|
2008-04-06 20:23:28 +00:00
|
|
|
PHYSFSX_printf(infile, "%s=%i\n", ResolutionXStr, SM_W(Game_screen_mode));
|
|
|
|
PHYSFSX_printf(infile, "%s=%i\n", ResolutionYStr, SM_H(Game_screen_mode));
|
|
|
|
PHYSFSX_printf(infile, "%s=%i\n", AspectXStr, GameCfg.AspectX);
|
|
|
|
PHYSFSX_printf(infile, "%s=%i\n", AspectYStr, GameCfg.AspectY);
|
|
|
|
PHYSFSX_printf(infile, "%s=%i\n", WindowModeStr, GameCfg.WindowMode);
|
|
|
|
PHYSFSX_printf(infile, "%s=%i\n", TexFiltStr, GameCfg.TexFilt);
|
2008-04-21 18:39:49 +00:00
|
|
|
PHYSFSX_printf(infile, "%s=%i\n", VSyncStr, GameCfg.VSync);
|
2008-04-22 08:29:29 +00:00
|
|
|
PHYSFSX_printf(infile, "%s=%i\n", MultisampleStr, GameCfg.Multisample);
|
2008-05-01 21:40:34 +00:00
|
|
|
PHYSFSX_printf(infile, "%s=%i\n", JukeboxOnStr, GameCfg.JukeboxOn);
|
2008-10-28 17:58:54 +00:00
|
|
|
PHYSFSX_printf(infile, "%s=%s\n", JukeboxPathStr, GameCfg.JukeboxPath);
|
|
|
|
PHYSFSX_printf(infile, "%s=%s\n", IPHostAddrStr, GameCfg.MplIpHostAddr);
|
2006-03-20 17:12:09 +00:00
|
|
|
|
|
|
|
PHYSFS_close(infile);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|