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-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Functions for accessing arguments.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <conf.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include "physfsx.h"
|
|
|
|
#include "args.h"
|
|
|
|
#include "u_mem.h"
|
|
|
|
#include "strio.h"
|
|
|
|
#include "strutil.h"
|
2007-07-14 22:36:04 +00:00
|
|
|
#include "digi.h"
|
2007-10-13 23:52:17 +00:00
|
|
|
#include "game.h"
|
2007-07-15 15:23:45 +00:00
|
|
|
#include "gauges.h"
|
2008-04-06 20:23:28 +00:00
|
|
|
#include "console.h"
|
2007-07-15 21:22:07 +00:00
|
|
|
#ifdef OGL
|
|
|
|
#if defined(__APPLE__) && defined(__MACH__)
|
|
|
|
#include <OpenGL/glu.h>
|
|
|
|
#else
|
|
|
|
#include <GL/glu.h>
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2007-07-16 02:34:51 +00:00
|
|
|
#define MAX_ARGS 1000
|
2007-10-12 20:09:26 +00:00
|
|
|
#define INI_FILENAME "d2x.ini"
|
|
|
|
|
2006-03-20 17:12:09 +00:00
|
|
|
int Num_args=0;
|
|
|
|
char * Args[MAX_ARGS];
|
|
|
|
|
2007-07-14 20:33:42 +00:00
|
|
|
struct Arg GameArg;
|
|
|
|
|
2007-10-12 20:09:26 +00:00
|
|
|
void ReadCmdArgs(void);
|
|
|
|
|
2006-03-20 17:12:09 +00:00
|
|
|
int FindArg(char *s)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i=0; i<Num_args; i++ )
|
|
|
|
if (! stricmp( Args[i], s))
|
|
|
|
return i;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int FindResArg(char *prefix, int *sw, int *sh)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int w, h;
|
|
|
|
char *endptr;
|
|
|
|
int prefixlen = strlen(prefix);
|
|
|
|
|
|
|
|
for (i = 0; i < Num_args; ++i)
|
|
|
|
if (Args[i][0] == '-' && !strnicmp(Args[i] + 1, prefix, prefixlen))
|
|
|
|
{
|
|
|
|
w = strtol(Args[i] + 1 + prefixlen, &endptr, 10);
|
|
|
|
if (w > 0 && endptr && endptr[0] == 'x')
|
|
|
|
{
|
|
|
|
h = strtol(endptr + 1, &endptr, 10);
|
|
|
|
if (h > 0 && endptr[0] == '\0')
|
|
|
|
{
|
|
|
|
*sw = w;
|
|
|
|
*sh = h;
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-07-14 20:33:42 +00:00
|
|
|
void AppendIniArgs(void)
|
|
|
|
{
|
|
|
|
PHYSFS_file *f;
|
2008-06-01 12:53:03 +00:00
|
|
|
char *line, *token;
|
|
|
|
char separator[] = " ";
|
2007-10-13 23:52:17 +00:00
|
|
|
|
2007-10-12 20:09:26 +00:00
|
|
|
f = PHYSFSX_openReadBuffered(INI_FILENAME);
|
2007-07-14 20:33:42 +00:00
|
|
|
|
|
|
|
if(f) {
|
|
|
|
while(!PHYSFS_eof(f) && Num_args < MAX_ARGS)
|
|
|
|
{
|
|
|
|
line=fgets_unlimited(f);
|
2008-06-01 12:53:03 +00:00
|
|
|
|
|
|
|
token = strtok(line, separator); /* first token in current line */
|
|
|
|
if (token)
|
|
|
|
Args[Num_args++] = d_strdup(token);
|
|
|
|
while( token != NULL )
|
|
|
|
{
|
|
|
|
token = strtok(NULL, separator); /* next tokens in current line */
|
|
|
|
if (token)
|
|
|
|
Args[Num_args++] = d_strdup(token);
|
|
|
|
}
|
|
|
|
|
|
|
|
d_free(line);
|
2007-07-14 20:33:42 +00:00
|
|
|
}
|
|
|
|
PHYSFS_close(f);
|
|
|
|
}
|
2007-10-12 20:09:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Utility function to get an integer provided as argument
|
|
|
|
int get_int_arg(char *arg_name, int default_value) {
|
|
|
|
int t;
|
|
|
|
return ((t = FindArg(arg_name)) ? atoi(Args[t+1]) : default_value);
|
|
|
|
|
|
|
|
}
|
|
|
|
// Utility function to get a string provided as argument
|
|
|
|
char *get_str_arg(char *arg_name, char *default_value) {
|
|
|
|
int t;
|
|
|
|
return ((t = FindArg(arg_name)) ? Args[t+1] : default_value);
|
2007-07-14 20:33:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// All FindArg calls should be here to keep the code clean
|
|
|
|
void ReadCmdArgs(void)
|
|
|
|
{
|
|
|
|
// System Options
|
|
|
|
|
2007-10-12 20:09:26 +00:00
|
|
|
GameArg.SysShowCmdHelp = (FindArg( "-help" ) || FindArg( "-h" ) || FindArg( "-?" ) || FindArg( "?" ));
|
|
|
|
GameArg.SysFPSIndicator = FindArg("-fps");
|
2008-04-21 18:39:49 +00:00
|
|
|
GameArg.SysUseNiceFPS = !FindArg("-nonicefps");
|
2007-07-14 20:33:42 +00:00
|
|
|
|
2007-10-12 20:09:26 +00:00
|
|
|
GameArg.SysMaxFPS = get_int_arg("-maxfps", MAXIMUM_FPS);
|
|
|
|
if (GameArg.SysMaxFPS <= 0 || GameArg.SysMaxFPS > MAXIMUM_FPS)
|
|
|
|
GameArg.SysMaxFPS = MAXIMUM_FPS;
|
2007-10-12 14:21:21 +00:00
|
|
|
|
2007-10-12 20:09:26 +00:00
|
|
|
GameArg.SysHogDir = get_str_arg("-hogdir", NULL);
|
|
|
|
if (GameArg.SysHogDir == NULL)
|
|
|
|
GameArg.SysNoHogDir = FindArg("-nohogdir");
|
2007-07-15 21:22:07 +00:00
|
|
|
|
2007-10-12 20:09:26 +00:00
|
|
|
GameArg.SysUsePlayersDir = FindArg("-use_players_dir");
|
|
|
|
GameArg.SysLowMem = FindArg("-lowmem");
|
|
|
|
GameArg.SysLegacyHomers = FindArg("-legacyhomers");
|
|
|
|
GameArg.SysPilot = get_str_arg("-pilot", NULL);
|
|
|
|
GameArg.SysWindow = FindArg("-window");
|
|
|
|
GameArg.SysNoMovies = FindArg("-nomovies");
|
|
|
|
GameArg.SysAutoDemo = FindArg("-autodemo");
|
2008-06-01 12:53:03 +00:00
|
|
|
GameArg.SysNoRedundancy = FindArg("-noredundancy");
|
2007-10-01 20:42:35 +00:00
|
|
|
|
2007-07-14 20:33:42 +00:00
|
|
|
// Control Options
|
|
|
|
|
2007-10-12 20:09:26 +00:00
|
|
|
GameArg.CtlNoMouse = FindArg("-nomouse");
|
|
|
|
GameArg.CtlNoJoystick = FindArg("-nojoystick");
|
|
|
|
GameArg.CtlMouselook = FindArg("-mouselook");
|
|
|
|
GameArg.CtlGrabMouse = FindArg("-grabmouse");
|
2007-07-14 22:36:04 +00:00
|
|
|
|
|
|
|
// Sound Options
|
|
|
|
|
2007-10-12 20:09:26 +00:00
|
|
|
GameArg.SndNoSound = FindArg("-nosound");
|
|
|
|
GameArg.SndNoMusic = FindArg("-nomusic");
|
|
|
|
GameArg.SndDigiSampleRate = (FindArg("-sound11k") ? SAMPLE_RATE_11K : SAMPLE_RATE_22K);
|
2007-07-14 22:36:04 +00:00
|
|
|
|
2007-09-18 13:37:39 +00:00
|
|
|
#ifdef USE_SDLMIXER
|
2008-05-01 21:40:34 +00:00
|
|
|
GameArg.SndDisableSdlMixer = FindArg("-nosdlmixer");
|
2007-10-12 20:09:26 +00:00
|
|
|
GameArg.SndExternalMusic = get_str_arg("-music_ext", NULL);
|
2007-09-18 13:37:39 +00:00
|
|
|
#endif
|
|
|
|
|
2007-10-12 20:09:26 +00:00
|
|
|
|
2007-07-15 15:23:45 +00:00
|
|
|
// Graphics Options
|
|
|
|
|
2008-02-24 14:41:27 +00:00
|
|
|
GameArg.GfxHiresGFXAvailable = !FindArg("-lowresgraphics");
|
|
|
|
GameArg.GfxHiresFNTAvailable = !FindArg("-lowresfont");
|
2007-10-12 20:09:26 +00:00
|
|
|
GameArg.GfxMovieHires = !FindArg( "-lowresmovies" );
|
|
|
|
GameArg.GfxMovieSubtitles = FindArg("-subtitles");
|
2007-07-15 15:23:45 +00:00
|
|
|
|
2007-07-15 21:22:07 +00:00
|
|
|
#ifdef OGL
|
|
|
|
// OpenGL Options
|
|
|
|
|
2007-10-18 14:44:02 +00:00
|
|
|
GameArg.OglFixedFont = FindArg("-gl_fixedfont");
|
2008-05-19 19:28:27 +00:00
|
|
|
GameArg.OglFixedFontWidth = FindArg("-gl_fontfixwidth");
|
2007-07-15 21:22:07 +00:00
|
|
|
#endif
|
|
|
|
|
2007-07-16 02:34:51 +00:00
|
|
|
// Multiplayer Options
|
|
|
|
|
2007-10-12 20:09:26 +00:00
|
|
|
GameArg.MplGameProfile = FindArg("-mprofile");
|
|
|
|
GameArg.MplNoRankings = FindArg("-norankings");
|
|
|
|
GameArg.MplPlayerMessages = FindArg("-playermessages");
|
|
|
|
GameArg.MplIpxNetwork = get_str_arg("-ipxnetwork", NULL);
|
|
|
|
GameArg.MplIpBasePort = get_int_arg("-ip_baseport", 0);
|
2008-05-07 14:02:01 +00:00
|
|
|
GameArg.MplIpRelay = FindArg("-ip_relay");
|
2008-10-20 12:34:45 +00:00
|
|
|
GameArg.MplIpHostAddr = get_str_arg("-ip_hostaddr", "");
|
2007-07-16 02:34:51 +00:00
|
|
|
|
2007-07-15 21:22:07 +00:00
|
|
|
#ifdef EDITOR
|
2007-07-14 22:36:04 +00:00
|
|
|
// Editor Options
|
|
|
|
|
2007-10-12 20:09:26 +00:00
|
|
|
GameArg.EdiAutoLoad = get_str_arg("-autoload", NULL);
|
|
|
|
GameArg.EdiMacData = FindArg("-macdata");
|
|
|
|
GameArg.EdiSaveHoardData = FindArg("-hoarddata");
|
2007-07-15 21:22:07 +00:00
|
|
|
#endif
|
2007-07-18 20:13:17 +00:00
|
|
|
|
|
|
|
// Debug Options
|
|
|
|
|
2008-04-06 20:23:28 +00:00
|
|
|
if (FindArg("-debug")) GameArg.DbgVerbose = CON_DEBUG;
|
|
|
|
else if (FindArg("-verbose")) GameArg.DbgVerbose = CON_VERBOSE;
|
|
|
|
else GameArg.DbgVerbose = CON_NORMAL;
|
2007-07-18 20:13:17 +00:00
|
|
|
|
2007-10-12 20:09:26 +00:00
|
|
|
GameArg.DbgNoRun = FindArg("-norun");
|
|
|
|
GameArg.DbgRenderStats = FindArg("-renderstats");
|
|
|
|
GameArg.DbgAltTex = get_str_arg("-text", NULL);
|
|
|
|
GameArg.DbgTexMap = get_str_arg("-tmap", NULL);
|
|
|
|
GameArg.DbgShowMemInfo = FindArg("-showmeminfo");
|
|
|
|
GameArg.DbgUseDoubleBuffer = !FindArg("-nodoublebuffer");
|
|
|
|
GameArg.DbgBigPig = !FindArg("-bigpig");
|
2007-07-22 20:40:39 +00:00
|
|
|
|
2007-07-22 01:34:00 +00:00
|
|
|
#ifdef OGL
|
2007-10-12 20:09:26 +00:00
|
|
|
GameArg.DbgAltTexMerge = !FindArg("-gl_oldtexmerge");
|
|
|
|
GameArg.DbgGlBpp = (FindArg("-gl_16bpp") ? 16 : 32);
|
|
|
|
GameArg.DbgGlIntensity4Ok = get_int_arg("-gl_intensity4_ok", 1);
|
|
|
|
GameArg.DbgGlLuminance4Alpha4Ok = get_int_arg("-gl_luminance4_alpha4_ok", 1);
|
|
|
|
GameArg.DbgGlRGBA2Ok = get_int_arg("-gl_rgba2_ok", 1);
|
|
|
|
GameArg.DbgGlReadPixelsOk = get_int_arg("-gl_readpixels_ok", 1);
|
|
|
|
GameArg.DbgGlGetTexLevelParamOk = get_int_arg("-gl_gettexlevelparam_ok", 1);
|
2007-07-23 18:13:49 +00:00
|
|
|
#else
|
2007-10-12 20:09:26 +00:00
|
|
|
GameArg.DbgSdlHWSurface = FindArg("-hwsurface");
|
2008-11-03 11:36:16 +00:00
|
|
|
GameArg.DbgSdlASyncBlit = FindArg("-asyncblit");
|
2007-07-22 01:34:00 +00:00
|
|
|
#endif
|
2007-07-14 20:33:42 +00:00
|
|
|
}
|
|
|
|
|
2006-03-20 17:12:09 +00:00
|
|
|
void args_exit(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i=0; i< Num_args; i++ )
|
|
|
|
d_free(Args[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
void InitArgs( int argc,char **argv )
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
Num_args=0;
|
|
|
|
|
|
|
|
for (i=0; i<argc; i++ )
|
|
|
|
Args[Num_args++] = d_strdup( argv[i] );
|
2007-07-14 20:33:42 +00:00
|
|
|
|
2006-03-20 17:12:09 +00:00
|
|
|
|
|
|
|
for (i=0; i< Num_args; i++ ) {
|
|
|
|
if ( Args[i][0] == '-' )
|
|
|
|
strlwr( Args[i] ); // Convert all args to lowercase
|
|
|
|
}
|
|
|
|
|
2007-07-14 20:33:42 +00:00
|
|
|
AppendIniArgs();
|
2007-10-13 23:52:17 +00:00
|
|
|
ReadCmdArgs();
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2007-07-14 20:33:42 +00:00
|
|
|
atexit(args_exit);
|
2006-03-20 17:12:09 +00:00
|
|
|
}
|