--- /dev/null
+launcher: added ability to specify a different data installation directory.
+Changes since the first version:
+added re-building of the game mod lists and updating of several game options;
+added disabling of the custom dir option during typing.
+Changes since the second version:
+cleaned-up game mod list building (the first entry in the lookup table is
+always available); un-checked the portals toggle button only if the portals
+option is set.
+
+diff -urNp uhexen2-20070523/launcher/config_file.c uhexen2-20070531/launcher/config_file.c
+--- uhexen2-20070523/launcher/config_file.c 2007-04-28 18:31:08.000000000 +0300
++++ uhexen2-20070531/launcher/config_file.c 2007-05-31 19:27:03.000000000 +0300
+@@ -29,6 +29,8 @@
+ #include "config_file.h"
+
+ // Default values for the options
++char game_basedir[MAX_OSPATH];
++int basedir_nonstd = 0;
+ int destiny = DEST_H2;
+ int opengl_support = 1;
+ int fullscreen = 1;
+@@ -87,13 +89,14 @@ int write_config_file (void)
+ {
+ fprintf(stderr, " Error: couldn't open config file for writing\n");
+ return 1;
+-
+ }
+ else
+ {
+ fprintf(cfg_file, "# Hexen II Launcher Options file\n\n");
+ fprintf(cfg_file, "# This file has been automatically generated\n\n");
+
++ fprintf(cfg_file, "game_basedir=\"%s\"\n",game_basedir);
++ fprintf(cfg_file, "basedir_nonstd=%d\n",basedir_nonstd);
+ fprintf(cfg_file, "destiny=%d\n",destiny);
+ #ifndef DEMOBUILD
+ fprintf(cfg_file, "h2game=%d\n",h2game);
+@@ -132,6 +135,70 @@ int write_config_file (void)
+ return 0;
+ }
+
++int cfg_read_basedir (void)
++{
++ FILE *cfg_file;
++ char buff[1024], *tmp;
++
++ game_basedir[0] = '\0';
++ cfg_file = open_config_file("r");
++ if (cfg_file == NULL)
++ {
++ printf("Creating default configuration file...\n");
++ return write_config_file();
++ }
++ else
++ {
++ int cnt = 0;
++
++ do {
++ memset(buff, 0, sizeof(buff));
++ fgets(buff, sizeof(buff), cfg_file);
++ if (!feof(cfg_file))
++ {
++ if (buff[0] == '#')
++ continue;
++ // remove end-of-line characters
++ tmp = buff;
++ while (*tmp)
++ {
++ if (*tmp == '\r' || *tmp == '\n')
++ *tmp = '\0';
++ tmp++;
++ }
++ // parse: whitespace isn't tolerated.
++ if (strstr(buff, "game_basedir=") == buff)
++ {
++ size_t len;
++ tmp = buff+13;
++ len = strlen(tmp);
++ // first and last chars must be quotes
++ if (tmp[0] != '\"' || tmp[len-1] != '\"' || len-2 >= sizeof(game_basedir))
++ continue;
++ memset (game_basedir, 0, sizeof(game_basedir));
++ memcpy (game_basedir, tmp+1, len-2);
++ ++cnt;
++ }
++ else if (strstr(buff, "basedir_nonstd=") == buff)
++ {
++ basedir_nonstd = atoi(buff + 15);
++ if (basedir_nonstd != 0 && basedir_nonstd != 1)
++ basedir_nonstd = 0;
++ ++cnt;
++ }
++
++ if (cnt >= 2)
++ break;
++ }
++
++ } while (!feof(cfg_file));
++
++ fclose (cfg_file);
++ }
++
++ return 0;
++}
++
+ int read_config_file (void)
+ {
+ FILE *cfg_file;
+@@ -141,8 +208,7 @@ int read_config_file (void)
+ if (cfg_file == NULL)
+ {
+ printf("Creating default configuration file...\n");
+- write_config_file();
+- return 0;
++ return write_config_file();
+ }
+ else
+ {
+diff -urNp uhexen2-20070523/launcher/config_file.h uhexen2-20070531/launcher/config_file.h
+--- uhexen2-20070523/launcher/config_file.h 2007-04-15 23:40:38.000000000 +0300
++++ uhexen2-20070531/launcher/config_file.h 2007-05-31 19:27:03.000000000 +0300
+@@ -28,6 +28,8 @@
+
+ #define LAUNCHER_CONFIG_FILE "launcher_options"
+
++extern char game_basedir[MAX_OSPATH];
++extern int basedir_nonstd;
+ extern int destiny;
+ extern int opengl_support;
+ extern int fullscreen;
+@@ -63,6 +65,7 @@ extern int hwgame;
+
+ int write_config_file (void);
+ int read_config_file (void);
++int cfg_read_basedir (void);
+
+ #endif // CONFIG_FILE_H
+
+diff -urNp uhexen2-20070523/launcher/games.c uhexen2-20070531/launcher/games.c
+--- uhexen2-20070523/launcher/games.c 2007-04-28 18:49:16.000000000 +0300
++++ uhexen2-20070531/launcher/games.c 2007-05-31 19:42:13.000000000 +0300
+@@ -27,6 +27,7 @@
+ #include "games.h"
+ #include "crc.h"
+ #include "pakfile.h"
++#include "config_file.h"
+
+ #if !defined(LITTLE_ENDIAN) || !defined(BIG_ENDIAN)
+ #undef LITTLE_ENDIAN
+@@ -65,6 +66,7 @@ static int LongSwap (int l)
+ }
+
+ unsigned int gameflags;
++static char *scan_dir;
+
+ typedef struct
+ {
+@@ -189,7 +191,7 @@ finish:
+ }
+
+ #if !defined(DEMOBUILD)
+-h2game_t h2game_names[] =
++h2game_t h2game_names[] = /* first entry is always available */
+ {
+ { NULL , "( None )" , NULL, 0, 1 },
+ { "hcbots" , "BotMatch: HC bots", "progs.dat", 1, 0 },
+@@ -200,7 +202,7 @@ h2game_t h2game_names[] =
+
+ const int MAX_H2GAMES = sizeof(h2game_names) / sizeof(h2game_names[0]);
+
+-hwgame_t hwgame_names[] =
++hwgame_t hwgame_names[] = /* first entry is always available */
+ {
+ { NULL , "Plain DeathMatch", NULL, 1 },
+ { "hexarena", "HexArena" , "sound/ha/fight.wav", 0 },
+@@ -212,12 +214,14 @@ hwgame_t hwgame_names[] =
+
+ const int MAX_HWGAMES = sizeof(hwgame_names) / sizeof(hwgame_names[0]);
+
+-static size_t string_size = 0;
++static size_t string_size;
+
+ static void FindMaxStringSize (void)
+ {
+ size_t i, len;
+
++ string_size = 0;
++
+ for (i = 1; i < MAX_H2GAMES; i++)
+ {
+ len = strlen(h2game_names[i].dirname) + strlen(hwgame_names[i].checkfile);
+@@ -235,7 +239,7 @@ static void FindMaxStringSize (void)
+ string_size = len;
+ }
+
+- string_size += 2; // 1 for "/" + 1 for null termination
++ string_size = string_size + strlen(scan_dir) + 3; // 2 for two "/" + 1 for null termination
+ }
+
+ static void scan_h2_mods (void)
+@@ -243,14 +247,11 @@ static void scan_h2_mods (void)
+ int i;
+ char *path;
+
+- if (!string_size)
+- FindMaxStringSize ();
+-
+ printf ("Scanning for known hexen2 mods\n");
+ path = (char *)malloc(string_size);
+ for (i = 1; i < MAX_H2GAMES; i++)
+ {
+- sprintf (path, "%s/%s", h2game_names[i].dirname, h2game_names[i].checkfile);
++ sprintf (path, "%s/%s/%s", scan_dir, h2game_names[i].dirname, h2game_names[i].checkfile);
+ if (access(path, R_OK) == 0)
+ h2game_names[i].available = 1;
+ }
+@@ -262,18 +263,15 @@ static void scan_hw_mods (void)
+ int i, j;
+ char *path;
+
+- if (!string_size)
+- FindMaxStringSize ();
+-
+ printf ("Scanning for known hexenworld mods\n");
+ path = (char *)malloc(string_size);
+ for (i = 1; i < MAX_HWGAMES; i++)
+ {
+- sprintf (path, "%s/hwprogs.dat", hwgame_names[i].dirname);
++ sprintf (path, "%s/%s/hwprogs.dat", scan_dir, hwgame_names[i].dirname);
+ j = access(path, R_OK);
+ if (j == 0)
+ {
+- sprintf (path, "%s/%s", hwgame_names[i].dirname, hwgame_names[i].checkfile);
++ sprintf (path, "%s/%s/%s", scan_dir, hwgame_names[i].dirname, hwgame_names[i].checkfile);
+ j = access(path, R_OK);
+ }
+ if (j == 0)
+@@ -315,10 +313,15 @@ void scan_game_installation (void)
+ if (endien == 0)
+ printf ("Warning: Unknown byte order!\n");
+
++ if (basedir_nonstd && game_basedir[0])
++ scan_dir = game_basedir;
++ else
++ scan_dir = basedir;
++
+ printf ("Scanning base hexen2 installation\n");
+ for (i = 0; i < MAX_PAKDATA-1; i++)
+ {
+- snprintf (pakfile, sizeof(pakfile), "%s/pak%d.pak", pakdata[i].dirname, i);
++ snprintf (pakfile, sizeof(pakfile), "%s/%s/pak%d.pak", scan_dir, pakdata[i].dirname, i);
+ scan_pak_files (pakfile, i);
+ }
+
+@@ -357,6 +360,7 @@ void scan_game_installation (void)
+ }
+
+ #if !defined(DEMOBUILD)
++ FindMaxStringSize ();
+ scan_h2_mods ();
+ scan_hw_mods ();
+ #endif /* DEMOBUILD */
+diff -urNp uhexen2-20070523/launcher/interface.c uhexen2-20070531/launcher/interface.c
+--- uhexen2-20070523/launcher/interface.c 2007-04-28 18:31:08.000000000 +0300
++++ uhexen2-20070531/launcher/interface.c 2007-05-31 19:41:31.000000000 +0300
+@@ -58,6 +58,10 @@ int thread_alive;
+ // Private data:
+
+ static GtkTooltips *tooltips;
++static GtkWidget *H2G_Entry; // Hexen2 games listing
++#ifndef DEMOBUILD
++static GtkWidget *HWG_Entry; // Hexenworld games listing
++#endif /* DEMOBUILD */
+
+ static options_widget_t Options;
+ static MainWindow_t main_win;
+@@ -218,6 +222,7 @@ static void report_status (GtkObject *Un
+
+ Log_printf ("Installation Summary:\n\n");
+ Log_printf ("Base directory: %s\n", basedir);
++ Log_printf ("Data directory: %s\n", (basedir_nonstd && game_basedir[0]) ? game_basedir : basedir);
+ Log_printf ("PAK file health: %s", (gameflags & GAME_INSTBAD) ? "BAD. Reason(s):\n" : "OK ");
+ if (gameflags & GAME_INSTBAD)
+ {
+@@ -575,6 +580,81 @@ static void on_MORE (GtkButton *button,
+ gtk_widget_hide (BOOK1);
+ }
+
++static void basedir_Change (GtkButton *unused, gpointer user_data)
++{
++#if !defined(DEMOBUILD)
++ int i;
++ GList *TmpList = NULL;
++#endif /* ! DEMOBUILD */
++
++ if (lock)
++ return;
++
++ lock = 1;
++ basedir_nonstd ^= 1;
++ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(patch_win.bBASEDIR), basedir_nonstd);
++ scan_game_installation();
++ UpdateStats ();
++ report_status (NULL, &patch_win);
++
++// activate the extra game options, if necessary
++ gtk_widget_set_sensitive (WGT_H2WORLD, (gameflags & GAME_HEXENWORLD) ? TRUE : FALSE);
++// rebuild the game mod lists
++#if !defined(DEMOBUILD)
++ if (mp_support)
++ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(WGT_PORTALS), FALSE);
++ h2game = hwgame = mp_support = 0;
++ for (i = 0; i < MAX_H2GAMES; i++)
++ {
++ if (h2game_names[i].available)
++ TmpList = g_list_append (TmpList, h2game_names[i].name);
++ }
++ gtk_combo_set_popdown_strings (GTK_COMBO(WGT_H2GAME), TmpList);
++ g_list_free (TmpList);
++ TmpList = NULL;
++ for (i = 0; i < MAX_HWGAMES; i++)
++ {
++ if (hwgame_names[i].available)
++ TmpList = g_list_append (TmpList, hwgame_names[i].name);
++ }
++ gtk_combo_set_popdown_strings (GTK_COMBO(WGT_HWGAME), TmpList);
++ g_list_free (TmpList);
++ gtk_entry_set_text (GTK_ENTRY(H2G_Entry), h2game_names[0].name);
++ gtk_entry_set_text (GTK_ENTRY(HWG_Entry), hwgame_names[0].name);
++ if (gameflags & (GAME_REGISTERED|GAME_REGISTERED_OLD))
++ {
++ gtk_widget_set_sensitive (WGT_H2GAME, TRUE);
++ gtk_widget_set_sensitive (WGT_HWGAME, TRUE);
++ if (gameflags & GAME_PORTALS && destiny == DEST_H2)
++ gtk_widget_set_sensitive (WGT_PORTALS, TRUE);
++ }
++ else
++ {
++ gtk_widget_set_sensitive (WGT_H2GAME, FALSE);
++ gtk_widget_set_sensitive (WGT_HWGAME, FALSE);
++ gtk_widget_set_sensitive (WGT_PORTALS, FALSE);
++ }
++#endif /* ! DEMOBUILD */
++
++ lock = 0;
++}
++
++static void basedir_ChangePath (GtkEditable *editable, gpointer user_data)
++{
++ size_t len;
++ gchar *tmp = gtk_editable_get_chars (editable, 0, -1);
++ len = strlen(tmp);
++ if (len > sizeof(game_basedir)-1)
++ len = sizeof(game_basedir)-1;
++ if (len)
++ memcpy (game_basedir, tmp, len);
++ game_basedir[len] = 0;
++ g_free (tmp);
++
++ if (basedir_nonstd) /* FIXME: any better way? */
++ basedir_Change (NULL, NULL);
++}
++
+ /*********************************************************************
+ WINDOW CREATING
+ *********************************************************************/
+@@ -599,7 +679,7 @@ static void create_window2 (GtkWidget *u
+ gtk_window_set_title (GTK_WINDOW(PATCH_WINDOW), "Hexen II PAK patch");
+ gtk_window_set_resizable (GTK_WINDOW(PATCH_WINDOW), FALSE);
+ gtk_window_set_modal (GTK_WINDOW(PATCH_WINDOW), TRUE);
+- gtk_widget_set_size_request(PATCH_WINDOW, 360, 240);
++ gtk_widget_set_size_request(PATCH_WINDOW, 360, 272);
+
+ PATCH_TAB = gtk_fixed_new ();
+ gtk_widget_ref (PATCH_TAB);
+@@ -613,11 +693,30 @@ static void create_window2 (GtkWidget *u
+ gtk_fixed_put (GTK_FIXED(PATCH_TAB), Txt1, 14, 12);
+ gtk_label_set_justify (GTK_LABEL(Txt1), GTK_JUSTIFY_LEFT);
+
++// custom basedir entry:
++ patch_win.bBASEDIR = gtk_check_button_new_with_label (_("Data install path:"));
++ gtk_widget_ref (patch_win.bBASEDIR);
++ gtk_widget_show (patch_win.bBASEDIR);
++ gtk_fixed_put (GTK_FIXED(PATCH_TAB), patch_win.bBASEDIR, 14, 186);
++ gtk_widget_set_size_request (patch_win.bBASEDIR, 128, 24);
++ gtk_widget_set_sensitive (patch_win.bBASEDIR, TRUE);
++ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(patch_win.bBASEDIR), basedir_nonstd);
++ GTK_WIDGET_UNSET_FLAGS (patch_win.bBASEDIR, GTK_CAN_FOCUS);
++ gtk_tooltips_set_tip (tooltips, patch_win.bBASEDIR, _("Mark this in order to use a different game installation directory"), NULL);
++
++ patch_win.dir_Entry = gtk_entry_new();
++ gtk_widget_show (patch_win.dir_Entry);
++ gtk_fixed_put (GTK_FIXED(PATCH_TAB), patch_win.dir_Entry, 148, 186);
++ gtk_widget_set_size_request (patch_win.dir_Entry, 190, 24);
++ gtk_entry_set_max_length (GTK_ENTRY(patch_win.dir_Entry), sizeof(game_basedir)-1);
++ gtk_entry_set_text (GTK_ENTRY(patch_win.dir_Entry), game_basedir);
++ gtk_widget_ref (patch_win.dir_Entry);
++
+ // Apply Patch button
+ patch_win.bAPPLY = gtk_button_new_with_label (_("Apply Pak Patch"));
+ gtk_widget_ref (patch_win.bAPPLY);
+ gtk_widget_show (patch_win.bAPPLY);
+- gtk_fixed_put (GTK_FIXED(PATCH_TAB), patch_win.bAPPLY, 14, 186);
++ gtk_fixed_put (GTK_FIXED(PATCH_TAB), patch_win.bAPPLY, 14, 218);
+ gtk_widget_set_size_request (patch_win.bAPPLY, 112, 24);
+ #if !defined(DEMOBUILD)
+ gtk_tooltips_set_tip (tooltips, patch_win.bAPPLY, _("Apply the v1.11 pakfiles patch by Raven Software."), NULL);
+@@ -627,7 +726,7 @@ static void create_window2 (GtkWidget *u
+ patch_win.bREPORT = gtk_button_new_with_label (_("Make Report"));
+ gtk_widget_ref (patch_win.bREPORT);
+ gtk_widget_show (patch_win.bREPORT);
+- gtk_fixed_put (GTK_FIXED(PATCH_TAB), patch_win.bREPORT, 132, 186);
++ gtk_fixed_put (GTK_FIXED(PATCH_TAB), patch_win.bREPORT, 132, 218);
+ gtk_widget_set_size_request (patch_win.bREPORT, 112, 24);
+
+ // Holder window for the textview
+@@ -669,14 +768,14 @@ static void create_window2 (GtkWidget *u
+ patch_win.bCLOSE = gtk_button_new_with_label (_("Close"));
+ gtk_widget_ref (patch_win.bCLOSE);
+ gtk_widget_show (patch_win.bCLOSE);
+- gtk_fixed_put (GTK_FIXED(PATCH_TAB), patch_win.bCLOSE, 250, 186);
++ gtk_fixed_put (GTK_FIXED(PATCH_TAB), patch_win.bCLOSE, 250, 218);
+ gtk_widget_set_size_request (patch_win.bCLOSE, 88, 24);
+
+ // Statusbar
+ PATCH_STATBAR = gtk_statusbar_new ();
+ gtk_widget_ref (PATCH_STATBAR);
+ gtk_widget_show (PATCH_STATBAR);
+- gtk_fixed_put (GTK_FIXED(PATCH_TAB), PATCH_STATBAR, 0, 214);
++ gtk_fixed_put (GTK_FIXED(PATCH_TAB), PATCH_STATBAR, 0, 246);
+ gtk_widget_set_size_request (PATCH_STATBAR, 354, 24);
+ gtk_statusbar_set_has_resize_grip (GTK_STATUSBAR(PATCH_STATBAR), FALSE);
+ gtk_container_set_border_width (GTK_CONTAINER(PATCH_STATBAR), 2);
+@@ -687,6 +786,8 @@ static void create_window2 (GtkWidget *u
+ gtk_object_set_data_full (GTK_OBJECT(PATCH_WINDOW), "Txt1", Txt1, GTK_DESTROYNOTIFY(gtk_widget_unref));
+ gtk_object_set_data_full (GTK_OBJECT(PATCH_WINDOW), "bAPPLY", patch_win.bAPPLY, GTK_DESTROYNOTIFY(gtk_widget_unref));
+ gtk_object_set_data_full (GTK_OBJECT(PATCH_WINDOW), "bREPORT", patch_win.bREPORT, GTK_DESTROYNOTIFY(gtk_widget_unref));
++ gtk_object_set_data_full (GTK_OBJECT(PATCH_WINDOW), "bBASEDIR", patch_win.bBASEDIR, GTK_DESTROYNOTIFY(gtk_widget_unref));
++ gtk_object_set_data_full (GTK_OBJECT(PATCH_WINDOW), "dir_Entry", patch_win.dir_Entry, GTK_DESTROYNOTIFY(gtk_widget_unref));
+ gtk_object_set_data_full (GTK_OBJECT(PATCH_WINDOW), "TxtWindow", TxtWindow, GTK_DESTROYNOTIFY(gtk_widget_unref));
+ gtk_object_set_data_full (GTK_OBJECT(PATCH_WINDOW), "LOGVIEW", patch_win.LOGVIEW, GTK_DESTROYNOTIFY(gtk_widget_unref));
+ gtk_object_set_data_full (GTK_OBJECT(PATCH_WINDOW), "bCLOSE", patch_win.bCLOSE, GTK_DESTROYNOTIFY(gtk_widget_unref));
+@@ -694,6 +795,8 @@ static void create_window2 (GtkWidget *u
+
+ gtk_signal_connect (GTK_OBJECT(PATCH_WINDOW), "destroy", GTK_SIGNAL_FUNC(destroy_window2), NULL);
+ gtk_signal_connect (GTK_OBJECT(patch_win.bCLOSE), "clicked", GTK_SIGNAL_FUNC(destroy_window2), NULL);
++ gtk_signal_connect (GTK_OBJECT(patch_win.bBASEDIR), "toggled", GTK_SIGNAL_FUNC(basedir_Change), NULL);
++ gtk_signal_connect (GTK_OBJECT(patch_win.dir_Entry), "changed", GTK_SIGNAL_FUNC(basedir_ChangePath), NULL);
+ #if !defined(DEMOBUILD)
+ gtk_signal_connect (GTK_OBJECT(patch_win.bAPPLY), "clicked", GTK_SIGNAL_FUNC(start_xpatch), &patch_win);
+ gtk_signal_connect (GTK_OBJECT(patch_win.bREPORT), "clicked", GTK_SIGNAL_FUNC(report_status), &patch_win);
+@@ -741,10 +844,6 @@ static void create_window1 (void)
+ GtkWidget *TxtPatch; // Data patch label
+ GtkWidget *bPATCH; // PATCH button
+ GtkWidget *SRATE_Entry; // Sampling rate listing
+- GtkWidget *H2G_Entry; // Hexen2 games listing
+-#ifndef DEMOBUILD
+- GtkWidget *HWG_Entry; // Hexenworld games listing
+-#endif /* DEMOBUILD */
+
+ // Separators
+ GtkWidget *hseparator0;
+@@ -1039,9 +1138,8 @@ static void create_window1 (void)
+ gtk_widget_set_size_request (WGT_H2GAME, 172, 32);
+ #ifndef DEMOBUILD
+ TmpList = NULL;
+- TmpList = g_list_append (TmpList, (gpointer) "( None )");
+ gtk_combo_set_use_arrows (GTK_COMBO(WGT_H2GAME), FALSE);
+- for (i = 1; i < MAX_H2GAMES; i++)
++ for (i = 0; i < MAX_H2GAMES; i++)
+ {
+ if (h2game_names[i].available)
+ TmpList = g_list_append (TmpList, h2game_names[i].name);
+@@ -1075,9 +1173,8 @@ static void create_window1 (void)
+ gtk_widget_ref (WGT_HWGAME);
+ gtk_widget_set_size_request (WGT_HWGAME, 172, 32);
+ TmpList = NULL;
+- TmpList = g_list_append (TmpList, (gpointer) "Plain DeathMatch");
+ gtk_combo_set_use_arrows (GTK_COMBO(WGT_HWGAME), FALSE);
+- for (i = 1; i < MAX_HWGAMES; i++)
++ for (i = 0; i < MAX_HWGAMES; i++)
+ {
+ if (hwgame_names[i].available)
+ TmpList = g_list_append (TmpList, hwgame_names[i].name);
+diff -urNp uhexen2-20070523/launcher/launch_bin.c uhexen2-20070531/launcher/launch_bin.c
+--- uhexen2-20070523/launcher/launch_bin.c 2007-04-15 23:40:38.000000000 +0300
++++ uhexen2-20070531/launcher/launch_bin.c 2007-05-31 19:27:03.000000000 +0300
+@@ -86,6 +86,12 @@ void launch_hexen2_bin (void)
+ i = 0;
+ args[i] = binary_name;
+
++ if (basedir_nonstd && game_basedir[0])
++ {
++ args[++i] = "-basedir";
++ args[++i] = game_basedir;
++ }
++
+ #if !defined(DEMOBUILD)
+ if (destiny == DEST_H2 && mp_support)
+ args[++i] = "-portals";
+diff -urNp uhexen2-20070523/launcher/launcher_defs.h uhexen2-20070531/launcher/launcher_defs.h
+--- uhexen2-20070523/launcher/launcher_defs.h 2007-04-15 00:30:16.000000000 +0300
++++ uhexen2-20070531/launcher/launcher_defs.h 2007-05-31 19:27:03.000000000 +0300
+@@ -40,7 +40,7 @@
+ // Launcher version num.
+ #define LAUNCHER_VERSION_MAJ 1
+ #define LAUNCHER_VERSION_MID 0
+-#define LAUNCHER_VERSION_MIN 0
++#define LAUNCHER_VERSION_MIN 1
+ #define LAUNCHER_VERSION_STR STRINGIFY(LAUNCHER_VERSION_MAJ) "." STRINGIFY(LAUNCHER_VERSION_MID) "." STRINGIFY(LAUNCHER_VERSION_MIN)
+
+ #ifndef DEMOBUILD
+diff -urNp uhexen2-20070523/launcher/main.c uhexen2-20070531/launcher/main.c
+--- uhexen2-20070523/launcher/main.c 2007-04-15 00:30:16.000000000 +0300
++++ uhexen2-20070531/launcher/main.c 2007-05-31 19:27:03.000000000 +0300
+@@ -206,6 +206,7 @@ int main (int argc, char *argv[])
+ // go into the binary's directory
+ chdir (basedir);
+
++ cfg_read_basedir();
+ scan_game_installation();
+ read_config_file();
+
+diff -urNp uhexen2-20070523/launcher/widget_defs.h uhexen2-20070531/launcher/widget_defs.h
+--- uhexen2-20070523/launcher/widget_defs.h 2007-04-15 00:30:17.000000000 +0300
++++ uhexen2-20070531/launcher/widget_defs.h 2007-05-31 19:27:03.000000000 +0300
+@@ -49,10 +49,12 @@ typedef struct
+ {
+ GtkWidget *mywindow; // Main window
+ GtkWidget *fixed1; // Widgets container
++ GtkWidget *bBASEDIR; // Use a different game basedir
+ GtkWidget *bCLOSE; // Close button
+ GtkWidget *bAPPLY; // Apply patch button
+ GtkWidget *bREPORT; // Report installation status
+ GtkWidget *LOGVIEW; // LogEntry line for patch process
++ GtkWidget *dir_Entry; // path for game basedir
+ GtkWidget *StatusBar; // Status bar, (patch status)
+ gint statbar_id; // statbar context id
+ guint delete_handler;
--- /dev/null
+# Copyright 1999-2007 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Header: $
+
+inherit eutils flag-o-matic toolchain-funcs versionator games
+
+DATA_PV="1.19-rc1"
+HW_PV="0.15"
+MY_PN="hexen2"
+MY_PV=$(replace_version_separator 3 '-')
+DEMO_PV="1.4.1"
+
+DESCRIPTION="Hexen 2 port - Hammer of Thyrion"
+HOMEPAGE="http://uhexen2.sourceforge.net/"
+SRC_URI="mirror://sourceforge/${PN}/${MY_PN}source-${MY_PV}.tgz
+ mirror://sourceforge/${PN}/gamedata-all-${DATA_PV}.tgz
+ hexenworld? ( mirror://sourceforge/${PN}/hexenworld-pakfiles-${HW_PV}.tgz )"
+
+LICENSE="GPL-2"
+SLOT="0"
+KEYWORDS="~amd64 ~x86"
+IUSE="alsa cdaudio debug dedicated demo dynamic hexenworld gtk lights opengl
+optimize-cflags oss sdlaudio sdlcd timidity tools"
+
+QA_EXECSTACK="${GAMES_BINDIR:1}/hexen2
+ ${GAMES_BINDIR:1}/glhexen2
+ ${GAMES_BINDIR:1}/hexen2-demo
+ ${GAMES_BINDIR:1}/glhexen2-demo
+ ${GAMES_BINDIR:1}/hwcl
+ ${GAMES_BINDIR:1}/glhwcl
+ ${GAMES_BINDIR:1}/hwcl-demo
+ ${GAMES_BINDIR:1}/glhwcl-demo"
+
+UIDEPEND=">=media-libs/libsdl-1.2.7
+ >=media-libs/sdl-mixer-1.2.5
+ alsa? ( >=media-libs/alsa-lib-1.0.7 )
+ opengl? ( virtual/opengl )
+ timidity? ( media-sound/timidity++ )
+ amd64? ( virtual/opengl )"
+
+# Launcher depends from GTK+ libs
+LNCHDEPEND="gtk? ( =x11-libs/gtk+-2* )"
+
+# xdelta is needed to manually run the patch script
+RDEPEND="!games-fps/uhexen2-cvs
+ ${UIDEPEND}
+ ${LNCHDEPEND}
+ demo? ( >=games-fps/hexen2-demodata-${DEMO_PV} )
+ lights? ( games-fps/hexen2-lights )
+ >=dev-util/xdelta-1.1.3-r1"
+DEPEND="${UIDEPEND}
+ ${LNCHDEPEND}
+ x86? ( >=dev-lang/nasm-0.98.38 )"
+
+S=${WORKDIR}/hexen2source-${MY_PV}
+dir=${GAMES_DATADIR}/${MY_PN}
+
+pkg_setup() {
+ games_pkg_setup
+
+ if use timidity ; then
+ if ! built_with_use "media-libs/sdl-mixer" timidity ; then
+ eerror "Recompile media-libs/sdl-mixer with 'timidity' USE flag."
+ die "sdl-mixer without timidity support detected"
+ fi
+ if use sdlaudio ; then
+ ewarn "timidity (midi music) does not work with sdlaudio."
+ fi
+ else
+ ewarn "timidity is needed if midi music is desired."
+ fi
+
+ ! use alsa && ewarn "alsa is the recommended sound driver."
+}
+
+src_unpack() {
+ unpack ${A}
+ cd "${S}"
+
+ epatch "${FILESDIR}/${P}-h2launcher_improvements.diff"
+ cd hexen2
+ epatch "${S}/00_Patches/external-music-file-support.diff"
+ cd ..
+
+ # Fix a little bug in cd_null.c
+ sed -i \
+ -e "/\#endif/d" \
+ {hexen2,hexenworld/Client}/cd_null.c \
+ || die "sed cd_null.c failed"
+
+ # Whether to use the demo directory
+ local demo
+ use demo && demo="/demo"
+
+ # Use default basedir - has 2 variations
+ sed -i \
+ -e "s:parms.basedir = cwd;:parms.basedir = \"${dir}${demo}\";:" \
+ -e "s:parms.basedir = \".\";:parms.basedir = \"${dir}${demo}\";:" \
+ {hexen2,hexen2/server,hexenworld/{Client,Server}}/sys_unix.c \
+ || die "sed sys_unix.c failed"
+
+ # Change default sndspeed from 11025 to 44100,
+ # to improve the quality/reliability.
+ sed -i \
+ -e "s:desired_speed = 11025:desired_speed = 44100:" \
+ {hexen2,hexenworld/Client}/snd_dma.c || die "sed snd_dma.c failed"
+
+ # Change patch script to be suitable
+ sed -i \
+ -e "s:chmod :#chmod :" \
+ -e 's:"xdelta113":"/usr/bin/xdelta":' \
+ -e "s:./xdelta113:xdelta": \
+ "${WORKDIR}"/update_xdelta.sh || die "sed update_xdelta.sh failed"
+
+ if use demo ; then
+ # Allow lightmaps in demo
+ sed -i \
+ -e "s:!override_pack:0:" \
+ hexen2/common.c || die "sed common.c demo failed"
+ fi
+
+ if use gtk ; then
+ # Tweak the default games data dir for graphical launcher
+ sed -i \
+ -e "/char game_basedir/s:;: = \"${dir}${demo}\";:" \
+ -e "/int basedir_nonstd/s:= 0:= 1:" \
+ -e "/game_basedir\[0\]/d" \
+ launcher/config_file.c || die "sed config_file.c failed"
+ # Tweak the default name for binary executables,if DEMO version is enabled
+ use demo && sed -i \
+ -e "/BINARY_NAME/s:\"$:-demo\":" \
+ launcher/games.h || die "sed games.g failed"
+ fi
+
+ rm -rf docs/{activision,COMPILE,COPYING,LICENSE,README.win32}
+}
+
+src_compile() {
+ yesno() { useq $1 && echo yes || echo no ; }
+
+ local h2bin="h2" hwbin="hw" link_gl_libs="no" opts
+
+ if use opengl ; then
+ if use amd64 ; then
+ # On AMD64 can be built only OpenGL binaries
+ h2bin="gl${h2bin}"
+ hwbin="gl${hwbin}"
+ else
+ h2bin="${h2bin} gl${h2bin}"
+ hwbin="${hwbin} gl${hwbin}"
+ fi
+ link_gl_libs=$(yesno dynamic)
+ fi
+
+ use debug && opts="${opts} DEBUG=1"
+ use demo && opts="${opts} DEMO=1"
+
+ if use gtk ; then
+ # Build launcher
+ cd "${S}/launcher"
+ einfo "Compiling graphical launcher"
+ emake \
+ AUTOTOOLS=1 \
+ ${opts} \
+ CPUFLAGS="${CFLAGS}" \
+ CC="$(tc-getCC)" \
+ || die "emake launcher failed"
+ fi
+
+ if use tools ; then
+ # Build Hexen2 utils
+ cd "${S}/utils"
+ einfo "Compiling utils"
+ local utils_list="hcc maputils genmodel qfiles dcc jsh2color hcc_old"
+ for x in ${utils_list}
+ do
+ emake -C ${x} \
+ ${opts} \
+ CPUFLAGS="${CFLAGS}" \
+ CC="$(tc-getCC)" \
+ || die "emake ${x} failed"
+ done
+ fi
+
+ if use dedicated ; then
+ # Dedicated Server
+ cd "${S}/${MY_PN}"
+ einfo "Compiling Dedicated Server"
+ emake \
+ ${opts} \
+ OPT_EXTRA=$(yesno optimize-cflags) \
+ CPUFLAGS="${CFLAGS}" \
+ CC="$(tc-getCC)" \
+ -f Makefile.sv \
+ || die "emake Dedicated server failed"
+ fi
+
+ if use hexenworld ; then
+ if use tools; then
+ # Hexenworld utils
+ local hw_utils="hwmquery hwrcon"
+ einfo "Compiling Hexenworld utils"
+ cd "${S}/hw_utils"
+ for x in ${hw_utils} ; do
+ emake \
+ ${opts} \
+ CPUFLAGS="${CFLAGS}" \
+ CC="$(tc-getCC)" \
+ -C ${x} \
+ || die "emake ${x} failed"
+ done
+ fi
+
+ # Hexenworld
+ einfo "Compiling Hexenworld servers"
+ cd "${S}"/hexenworld
+ # Hexenworld servers
+ emake \
+ ${opts} \
+ CPUFLAGS="${CFLAGS}" \
+ CC="$(tc-getCC)" \
+ -C Server \
+ || die "emake HexenWorld Server failed"
+ emake \
+ ${opts} \
+ CPUFLAGS="${CFLAGS}" \
+ CC="$(tc-getCC)" \
+ -C Master \
+ || die "emake HexenWorld Master failed"
+
+ # Hexenworld client
+ einfo "Compiling Hexenworld client(s)"
+ use amd64 && ewarn "On AMD64 only GL Hexenworld client version is built"
+ for m in ${hwbin} ; do
+ emake -C Client clean
+ emake \
+ ${opts} \
+ USE_ALSA=$(yesno alsa) \
+ USE_OSS=$(yesno oss) \
+ USE_CDAUDIO=$(yesno cdaudio) \
+ USE_MIDI=$(yesno timidity) \
+ USE_SDLAUDIO=$(yesno sdlaudio) \
+ USE_SDLCD=$(yesno sdlcd) \
+ USE_X86_ASM=$(yesno x86) \
+ OPT_EXTRA=$(yesno optimize-cflags) \
+ LINK_GL_LIBS=${link_gl_libs} \
+ CPUFLAGS="${CFLAGS}" \
+ CC="$(tc-getCC)" \
+ ${m} \
+ -C Client \
+ || die "emake Hexenworld Client (${m}) failed"
+ done
+ fi
+
+ # Hexen 2 game executable
+ cd "${S}/${MY_PN}"
+
+ einfo "Compiling UHexen2 game executable(s)"
+ use amd64 && ewarn "On AMD64 only GL game binary version is built"
+ for m in ${h2bin} ; do
+ emake clean
+ emake \
+ ${opts} \
+ USE_ALSA=$(yesno alsa) \
+ USE_OSS=$(yesno oss) \
+ USE_CDAUDIO=$(yesno cdaudio) \
+ USE_MIDI=$(yesno timidity) \
+ USE_SDLAUDIO=$(yesno sdlaudio) \
+ USE_SDLCD=$(yesno sdlcd) \
+ USE_X86_ASM=$(yesno x86) \
+ OPT_EXTRA=$(yesno optimize-cflags) \
+ LINK_GL_LIBS=${link_gl_libs} \
+ CPUFLAGS="${CFLAGS}" \
+ CC="$(tc-getCC)" \
+ ${m} \
+ || die "emake Hexen2 (${m}) failed"
+ done
+
+}
+
+src_install() {
+ local demo demo_title demo_suffix
+ use demo && demo="-demo" && demo_title=" (Demo)" && demo_suffix="demo"
+
+ newicon hexen2/icons/h2_32x32x4.png ${PN}.png || die
+ if ! use amd64 ; then
+ make_desktop_entry "${MY_PN}${demo}" "Hexen 2${demo_title}" ${PN}.png
+ newgamesbin "${MY_PN}/${MY_PN}" "${MY_PN}${demo}" \
+ || die "newgamesbin ${MY_PN} failed"
+ fi
+ if use opengl || use amd64 ; then
+ make_desktop_entry "gl${MY_PN}${demo}" "GLHexen 2${demo_title}" ${PN}.png
+ newgamesbin "${MY_PN}/gl${MY_PN}" "gl${MY_PN}${demo}" \
+ || die "newgamesbin gl${MY_PN} failed"
+ fi
+
+ if use dedicated ; then
+ newgamesbin "${MY_PN}"/h2ded "${MY_PN}${demo}-ded" \
+ || die "newgamesbin h2ded failed"
+ fi
+
+ if use hexenworld ; then
+ if use tools; then
+ # Hexenworld utils
+ dobin hw_utils/hwmquery/hwmquery || die "dobin hwmquery failed"
+ dobin hw_utils/hwrcon/{hwrcon,hwterm} || die "dobin hwrcon/hwterm failed"
+
+ dodoc hw_utils/hwmquery/hwmquery.txt || die "dodoc hwmquery.txt failed"
+ dodoc hw_utils/hwrcon/{hwrcon,hwterm}.txt \
+ || die "dodoc hwrcon/hwterm.txt failed"
+ fi
+
+ # Hexenworld Servers
+ newgamesbin hexenworld/Server/hwsv hwsv${demo} \
+ || die "newgamesbin hwsv failed"
+
+ newgamesbin hexenworld/Master/hwmaster hwmaster${demo} \
+ || die "newgamesbin hwmaster failed"
+
+ # HexenWorld client(s)
+ newicon hexenworld/icons/hw2_32x32x8.png hwcl.png || die
+ if ! use amd64 ; then
+ make_desktop_entry \
+ "hwcl${demo}" "Hexen 2${demo_title} Hexenworld Client" hwcl.png
+ newgamesbin "hexenworld/Client/hwcl" "hwcl${demo}" \
+ || die "newgamesbin hwcl failed"
+ fi
+ if use opengl || use amd64; then
+ make_desktop_entry \
+ "glhwcl${demo}" "GLHexen 2${demo_title} Hexenworld Client" hwcl.png
+ newgamesbin "hexenworld/Client/glhwcl" "glhwcl${demo}" \
+ || die "newgamesbin glhwcl failed"
+ fi
+
+ insinto "${dir}"/${demo_suffix}
+ doins -r "${WORKDIR}"/hw || die "doins hexenworld pak failed"
+ fi
+
+ if use gtk ; then
+ # GTK launcher
+ local lnch_name="h2launcher"
+ use demo && lnch_name="h2demo"
+ newgamesbin launcher/${lnch_name} h2launcher \
+ || die "newgamesbin h2launcher failed"
+ make_desktop_entry \
+ "h2launcher" "Hexen 2${demo_title} Launcher" ${PN}.png
+ fi
+
+ # Forge a new useful document 8)
+ head -22 "00_Patches/external-music-file-support.diff" > \
+ "docs/external_music.README" || die "make readme failed"
+
+ dodoc docs/*
+
+ if ! use demo ; then
+ # Install updated game data
+ insinto "${dir}"
+ doins -r "${WORKDIR}"/{data1,patchdata,portals,siege} || die
+ # Patching should really be done by a future "hexen2-data" ebuild.
+ # But this works for now.
+ doins "${WORKDIR}"/update_xdelta.sh || die
+ dodoc "${WORKDIR}"/*.txt
+ fi
+
+ if use tools ; then
+ dobin \
+ utils/bin/{bspinfo,dhcc,genmodel,hcc,jsh2colour,light,qbsp,qfiles,vis} \
+ || die "dobin utils failed"
+ newbin utils/hcc_old/hcc hcc_old || die "newbin hcc_old failed"
+ docinto utils
+ dodoc utils/README || die "dodoc README failed"
+ dodoc utils/bin/hcc.txt || die "dodoc hcc.txt failed"
+ newdoc utils/dcc/README README.dcc || die "newdoc dcc.txt failed"
+ dodoc utils/dcc/dcc.txt || die "dodoc dcc.txt failed"
+ newdoc utils/hcc_old/README hcc_old.txt || die "newdoc hcc_old failed"
+ newdoc utils/jsh2color/README README.jsh2color \
+ || die "newdoc README.jsh2color failed"
+ newdoc utils/jsh2color/ChangeLog ChangeLog.jsh2color \
+ || die "newdoc Changelog.jsh2color failed"
+ fi
+
+ prepgamesdirs
+}
+
+pkg_postinst() {
+ games_pkg_postinst
+
+ if ! use timidity ; then
+ elog "MIDI music requires the 'timidity' USE flag."
+ echo
+ fi
+
+ if use demo ; then
+ elog "uhexen2 has been compiled specifically to play the demo maps."
+ elog "Example command-line:"
+ elog " hexen2-demo -width 1024 -height 768 -conwidth 640"
+ echo
+ else
+ elog "To play the demo, emerge with the 'demo' USE flag."
+ elog
+ elog "For the Hexen 2 original game..."
+ elog "Put the following files into ${dir}/data1 before playing:"
+ elog " pak0.pak pak1.pak"
+ elog "Then to play: hexen2"
+ elog
+ elog "For the 'Portal of Praevus' mission pack..."
+ elog "Put the following file into ${dir}/portals before playing:"
+ elog " pak3.pak"
+ elog "Then to play: hexen2 -portals"
+ elog
+ elog "To ensure the data files from the CD are patched, run as root:"
+ elog " cd ${dir} && sh update_xdelta.sh"
+ elog
+ elog "Example command-line:"
+ elog " hexen2 -width 1024 -height 768 -conwidth 640"
+ echo
+ fi
+ if use gtk ; then
+ elog "You've also installed a nice graphical launcher. Simply run:"
+ elog
+ elog " h2launcher"
+ elog
+ elog "to enjoy it :)"
+ echo
+ fi
+ if use tools ; then
+ if use hexenworld; then
+ elog "You've also installed some Hexenworld utility:"
+ elog
+ elog " - hwmquery (console app to query HW master servers)"
+ elog " - hwrcon (remote interface to HW rcon command)"
+ elog " - hwterm (HW remote console terminal)"
+ echo
+ fi
+ elog "You've also installed some Hexen2 utility"
+ elog "(useful for mod developing)"
+ elog
+ elog " - dhcc (old progs.dat compiler/decompiler"
+ elog " - genmodel (3-D model grabber"
+ elog " - hcc (HexenC compiler)"
+ elog " - hcc_old (old version of HexenC compiler)"
+ elog " - jsh2color (light colouring utility)"
+ elog " - maputils (Map compiling tools: bspinfo, light, qbsp, vis)"
+ elog " - qfiles (build pak files and regenerate bsp models)"
+ elog
+ elog "See relevant documentation for further informations"
+ echo
+ fi
+}