Browse Source

Implement --data-dir for setting mpq path

This also implements a much cleaner version of diablo_parse_flags
Fixes #219
pull/523/head
Anders Jenbo 6 years ago
parent
commit
40d272241b
  1. 3
      3rdParty/Storm/Source/storm.h
  2. 2
      Source/control.cpp
  3. 233
      Source/diablo.cpp
  4. 6
      Source/diablo.h
  5. 1
      SourceS/miniwin/misc.h
  6. 64
      SourceX/main.cpp
  7. 20
      SourceX/miniwin/misc.cpp
  8. 7
      SourceX/storm/storm.cpp

3
3rdParty/Storm/Source/storm.h vendored

@ -4,8 +4,11 @@
#define __BLIZZARD_STORM_HEADER
#include <limits>
#include <string>
namespace dvl {
extern std::string basePath;
// Note to self: Linker error => forgot a return value in cpp
// Storm API definition

2
Source/control.cpp

@ -1906,7 +1906,7 @@ void control_drop_gold(char vkey)
}
memset(input, 0, sizeof(input));
_itoa(dropGoldValue, input, 10);
SDL_itoa(dropGoldValue, input, 10);
if (vkey == VK_RETURN) {
if (dropGoldValue > 0)
control_remove_gold(myplr, initialDropGoldIndex);

233
Source/diablo.cpp

@ -1,6 +1,7 @@
#include "diablo.h"
#include "../3rdParty/Storm/Source/storm.h"
#include "../DiabloUI/diabloui.h"
#include <config.h>
DEVILUTION_BEGIN_NAMESPACE
@ -38,8 +39,8 @@ int color_cycle_timer;
/* rdata */
BOOL fullscreen = TRUE;
#ifdef _DEBUG
int showintrodebug = 1;
#ifdef _DEBUG
int questdebug = -1;
int debug_mode_key_s;
int debug_mode_key_w;
@ -249,9 +250,8 @@ void free_game()
FreeGameMem();
}
void diablo_init(const char *lpCmdLine)
void diablo_init()
{
diablo_parse_flags(lpCmdLine);
init_create_window();
SFileEnableDirectAccess(TRUE);
@ -292,155 +292,112 @@ void diablo_splash()
UiTitleDialog();
}
int DiabloMain(const char *lpCmdLine)
int DiabloMain(int argc, char **argv)
{
diablo_init(lpCmdLine);
diablo_parse_flags(argc, argv);
diablo_init();
diablo_splash();
mainmenu_loop();
return 0;
}
void diablo_parse_flags(const char *args)
static void print_help_and_exit()
{
char c;
printf("Options:\n");
printf(" %-20s %-30s\n", "-h, --help", "Print this message and exit");
printf(" %-20s %-30s\n", "--version", "Print the version and exit");
printf(" %-20s %-30s\n", "--data-dir", "Specify the folder of diabdat.mpq");
printf(" %-20s %-30s\n", "-n", "Skip startup videos");
printf(" %-20s %-30s\n", "-f", "Display frames per second");
printf(" %-20s %-30s\n", "-x", "Run in windowed mode");
#ifdef _DEBUG
int i;
printf("\nDebug options:\n");
printf(" %-20s %-30s\n", "-d", "Increaased item drops");
printf(" %-20s %-30s\n", "-w", "Enable cheats");
printf(" %-20s %-30s\n", "-$", "Enable god mode");
printf(" %-20s %-30s\n", "-^", "Enable god mode and debug tools");
//printf(" %-20s %-30s\n", "-b", "Enable item drop log");
printf(" %-20s %-30s\n", "-v", "Highlight visibility");
printf(" %-20s %-30s\n", "-i", "Ignore network timeout");
//printf(" %-20s %-30s\n", "-j <##>", "Init trigger at level");
printf(" %-20s %-30s\n", "-l <##> <##>", "Start in level as type");
printf(" %-20s %-30s\n", "-m <##>", "Add debug monster, up to 10 allowed");
printf(" %-20s %-30s\n", "-q <#>", "Force a certain quest");
printf(" %-20s %-30s\n", "-r <##########>", "Set map seed");
printf(" %-20s %-30s\n", "-t <##>", "Set current quest level");
#endif
printf("\nReport bugs at https://github.com/diasurgical/devilutionX/\n");
exit(0);
}
while (*args != '\0') {
while (isspace(*args)) {
args++;
}
{
c = tolower(*args);
args++;
switch (c) {
#ifdef _DEBUG
case '^':
debug_mode_key_inverted_v = 1;
break;
case '$':
debug_mode_dollar_sign = 1;
break;
case 'b':
/*
debug_mode_key_b = 1;
*/
break;
case 'd':
debug_mode_key_d = 1;
break;
#endif
case 'f':
EnableFrameCount();
break;
#ifdef _DEBUG
case 'i':
debug_mode_key_i = 1;
break;
case 'j':
/*
while(isspace(*args)) {
args++;
}
i = 0;
while(isdigit(*args)) {
i = *args + 10 * i - '0';
args++;
}
debug_mode_key_J_trigger = i;
*/
break;
case 'l':
setlevel = FALSE;
leveldebug = TRUE;
while (isspace(*args)) {
args++;
}
i = 0;
while (isdigit(*args)) {
i = *args + 10 * i - '0';
args++;
}
leveltype = i;
while (isspace(*args)) {
args++;
}
i = 0;
while (isdigit(*args)) {
i = *args + 10 * i - '0';
args++;
}
currlevel = i;
plr[0].plrlevel = i;
break;
case 'm':
monstdebug = TRUE;
while (isspace(*args)) {
args++;
}
i = 0;
while (isdigit(*args)) {
i = *args + 10 * i - '0';
args++;
}
DebugMonsters[debugmonsttypes++] = i;
break;
void diablo_parse_flags(int argc, char **argv)
{
for (int i = 1; i < argc; i++) {
if (strcasecmp("-h", argv[i]) == 0 || strcasecmp("--help", argv[i]) == 0) {
print_help_and_exit();
} else if (strcasecmp("--version", argv[i]) == 0) {
printf("%s v%s\n", PROJECT_NAME, PROJECT_VERSION);
exit(0);
} else if (strcasecmp("--data-dir", argv[i]) == 0) {
basePath = argv[++i];
#ifdef _WIN32
if (basePath.back() != '\\')
basePath += '\\';
#else
if (basePath.back() != '/')
basePath += '/';
#endif
case 'n':
showintrodebug = 0;
break;
} else if (strcasecmp("-n", argv[i]) == 0) {
showintrodebug = 0;
} else if (strcasecmp("-f", argv[i]) == 0) {
EnableFrameCount();
} else if (strcasecmp("-x", argv[i]) == 0) {
fullscreen = FALSE;
#ifdef _DEBUG
case 'q':
while (isspace(*args)) {
args++;
}
i = 0;
while (isdigit(*args)) {
i = *args + 10 * i - '0';
args++;
}
questdebug = i;
break;
case 'r':
while (isspace(*args)) {
args++;
}
i = 0;
while (isdigit(*args)) {
i = *args + 10 * i - '0';
args++;
}
setseed = i;
break;
case 's':
debug_mode_key_s = 1;
break;
case 't':
leveldebug = TRUE;
setlevel = TRUE;
while (isspace(*args)) {
args++;
}
i = 0;
while (isdigit(*args)) {
i = *args + 10 * i - '0';
args++;
}
setlvlnum = i;
break;
case 'v':
visiondebug = TRUE;
break;
case 'w':
debug_mode_key_w = 1;
break;
} else if (strcasecmp("-^", argv[i]) == 0) {
debug_mode_key_inverted_v = 1;
} else if (strcasecmp("-$", argv[i]) == 0) {
debug_mode_dollar_sign = 1;
/*
} else if (strcasecmp("-b", argv[i]) == 0) {
debug_mode_key_b = 1;
*/
} else if (strcasecmp("-d", argv[i]) == 0) {
debug_mode_key_d = 1;
} else if (strcasecmp("-i", argv[i]) == 0) {
debug_mode_key_i = 1;
/*
} else if (strcasecmp("-j", argv[i]) == 0) {
debug_mode_key_J_trigger = argv[++i];
*/
} else if (strcasecmp("-l", argv[i]) == 0) {
setlevel = FALSE;
leveldebug = TRUE;
leveltype = SDL_atoi(argv[++i]);
currlevel = SDL_atoi(argv[++i]);
plr[0].plrlevel = currlevel;
} else if (strcasecmp("-m", argv[i]) == 0) {
monstdebug = TRUE;
DebugMonsters[debugmonsttypes++] = SDL_atoi(argv[++i]);
} else if (strcasecmp("-q", argv[i]) == 0) {
questdebug = SDL_atoi(argv[++i]);
} else if (strcasecmp("-r", argv[i]) == 0) {
setseed = SDL_atoi(argv[++i]);
} else if (strcasecmp("-s", argv[i]) == 0) {
debug_mode_key_s = 1;
} else if (strcasecmp("-t", argv[i]) == 0) {
leveldebug = TRUE;
setlevel = TRUE;
setlvlnum = SDL_atoi(argv[++i]);
} else if (strcasecmp("-v", argv[i]) == 0) {
visiondebug = TRUE;
} else if (strcasecmp("-w", argv[i]) == 0) {
debug_mode_key_w = 1;
#endif
case 'x':
fullscreen = FALSE;
break;
}
} else {
printf("unrecognized option '%s'\n", argv[i]);
print_help_and_exit();
}
}
}

6
Source/diablo.h

@ -125,8 +125,8 @@ BOOL StartGame(BOOL bNewGame, BOOL bSinglePlayer);
void run_game_loop(unsigned int uMsg);
void start_game(unsigned int uMsg);
void free_game();
int DiabloMain(const char *lpCmdLine);
void diablo_parse_flags(const char *args);
int DiabloMain(int argc, char **argv);
void diablo_parse_flags(int argc, char **argv);
void diablo_init_screen();
void diablo_reload_process(HINSTANCE hInstance);
BOOL PressEscKey();
@ -158,8 +158,8 @@ void diablo_color_cyc_logic();
/* rdata */
extern BOOL fullscreen;
#ifdef _DEBUG
extern int showintrodebug;
#ifdef _DEBUG
extern int questdebug;
extern int debug_mode_key_s;
extern int debug_mode_key_w;

1
SourceS/miniwin/misc.h

@ -212,7 +212,6 @@ int wsprintfA(LPSTR, LPCSTR, ...);
int wvsprintfA(LPSTR dest, LPCSTR format, va_list arglist);
int _strcmpi(const char *_Str1, const char *_Str2);
int _strnicmp(const char *_Str1, const char *_Str2, size_t n);
char *_itoa(int _Value, char *_Dest, int _Radix);
//
// File I/O

64
SourceX/main.cpp

@ -1,9 +1,7 @@
#include <string>
#include <SDL.h>
#ifdef __SWITCH__
#include "platform/switch/network.h"
#endif
#include <config.h>
#include "devilution.h"
@ -14,71 +12,11 @@ extern "C" const char *__asan_default_options()
}
#endif
static std::string build_cmdline(int argc, char **argv)
{
std::string str;
for (int i = 1; i < argc; i++) {
if (i != 1) {
str += ' ';
}
str += argv[i];
}
return str;
}
static bool HasArgumst(const char *arg, int argc, char **argv)
{
for (int i = 1; i < argc; i++) {
if (strcasecmp(arg, argv[i]) == 0) {
return true;
}
}
return false;
}
static void ShowCLIinfo(int argc, char **argv)
{
if (HasArgumst("-h", argc, argv) || HasArgumst("--help", argc, argv)) {
printf("Options:\n");
printf(" %-20s %-30s\n", "-h, --help", "Print this message and exit");
printf(" %-20s %-30s\n", "--version", "Print the version and exit");
printf(" %-20s %-30s\n", "-n", "Skip startup videos");
printf(" %-20s %-30s\n", "-f", "Display frames per second");
printf(" %-20s %-30s\n", "-x", "Run in windows mode");
#ifdef _DEBUG
printf("\nDebug options:\n");
printf(" %-20s %-30s\n", "-d", "Increaased item drops");
printf(" %-20s %-30s\n", "-w", "Enable cheats");
printf(" %-20s %-30s\n", "-$", "Enable god mode");
printf(" %-20s %-30s\n", "-^", "Enable god mode and debug tools");
//printf(" %-20s %-30s\n", "-b", "Enable item drop log");
printf(" %-20s %-30s\n", "-v", "Highlight visibility");
printf(" %-20s %-30s\n", "-i", "Ignore network timeout");
//printf(" %-20s %-30s\n", "-j <##>", "Init trigger at level");
printf(" %-20s %-30s\n", "-l <##> <##>", "Start in level as type");
printf(" %-20s %-30s\n", "-m <##>", "Add debug monster, up to 10 allowed");
printf(" %-20s %-30s\n", "-q <#>", "Force a certain quest");
printf(" %-20s %-30s\n", "-r <##########>", "Set map seed");
printf(" %-20s %-30s\n", "-t <##>", "Set current quest level");
#endif
printf("\nReport bugs at https://github.com/diasurgical/devilutionX/\n");
exit(0);
}
if (HasArgumst("--version", argc, argv)) {
printf("%s v%s\n", PROJECT_NAME, PROJECT_VERSION);
exit(0);
}
}
int main(int argc, char **argv)
{
ShowCLIinfo(argc, argv);
#ifdef __SWITCH__
switch_enable_network();
#endif
auto cmdline = build_cmdline(argc, argv);
return dvl::DiabloMain(cmdline.c_str());
return dvl::DiabloMain(argc, argv);
}

20
SourceX/miniwin/misc.cpp

@ -62,26 +62,6 @@ int _strnicmp(const char *_Str1, const char *_Str2, size_t n)
return strncasecmp(_Str1, _Str2, n);
}
char *_itoa(int _Value, char *_Dest, int _Radix)
{
switch (_Radix) {
case 8:
sprintf(_Dest, "%o", _Value);
break;
case 10:
sprintf(_Dest, "%d", _Value);
break;
case 16:
sprintf(_Dest, "%x", _Value);
break;
default:
UNIMPLEMENTED();
break;
}
return _Dest;
}
DWORD GetTickCount()
{
return SDL_GetTicks();

7
SourceX/storm/storm.cpp

@ -16,6 +16,8 @@
namespace dvl {
std::string basePath;
DWORD nLastError = 0;
bool directFileAccess = false;
@ -33,6 +35,11 @@ static Mix_Chunk *SFileChunk;
void GetBasePath(char *buffer, size_t size)
{
if (basePath.length()) {
snprintf(buffer, size, "%s", basePath.c_str());
return;
}
char *path = SDL_GetBasePath();
if (path == NULL) {
SDL_Log(SDL_GetError());

Loading…
Cancel
Save