Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pull ROTT data from various common install paths #72

Merged
merged 9 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 105 additions & 1 deletion rott/rt_datadir.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,80 @@
See the GNU General Public License for more details.
*/

#include "SDL_filesystem.h"
#include <sys/stat.h>

#include "SDL.h"

#include "m_misc2.h"
#include "rt_util.h"

#ifndef _WIN32
#include <pwd.h>
#endif

/*
* storefronts
*
* retrieve ROTT data directories from various digital storefronts
*
* supported:
* - steam
* - heroic
* - gog
*/

#ifdef _WIN32

/* format strings for potential data paths relative to a drive */
/* TODO: use the registry to query some of these */
static const char *storefront_paths[] = {
/* steam - classic rott */
"\\Program Files (x86)\\Steam\\steamapps\\common\\Rise of the Triad Dark War\\Rise of the Triad - Dark War\\",
/* steam - ludicrous edition */
"\\Program Files (x86)\\Steam\\steamapps\\common\\Rise of the Triad - Ludicrous Edition\\assets\\",
/* gog - ludicrous edition */
"\\GOG Games\\Rise of the Triad - Ludicrous Edition\\",
/* gog - classic rott */
"\\GOG Games\\Rise of the Triad\\",
/* original ms-dos installers */
"\\ROTT\\"
};

#else

/* format strings for potential data paths relative to $HOME */
/* these are all the default or expected paths, if the user customized it, oh well... */
static const char *storefront_paths[] = {
/* steam - classic rott */
"/.steam/steam/steamapps/common/Rise of the Triad Dark War/Rise of the Triad - Dark War/",
/* steam - ludicrous edition */
"/.steam/steam/steamapps/common/Rise of the Triad - Ludicrous Edition/assets/",
/* steam - ludicrous edition (savegames) */
"/.steam/steam/steamapps/compatdata/1421490/pfx/drive_c/users/steamuser/Saved Games/Nightdive Studios/Rise of the Triad - Ludicrous Edition/",
/* steam - ludicrous edition (user mapsets) */
"/.steam/steam/steamapps/compatdata/1421490/pfx/drive_c/users/steamuser/Saved Games/Nightdive Studios/Rise of the Triad - Ludicrous Edition/projects/",
/* heroic - classic rott */
"/Games/Heroic/Rise of the Triad/data/",
/* gog - ludicrous edition (wine) */
"/.wine/drive_c/GOG Games/Rise of the Triad - Ludicrous Edition/",
/* gog - ludicrous edition (native) */
"/GOG Games/Rise of the Triad - Ludicrous Edition/",
/* gog - classic rott (wine) */
"/.wine/drive_c/GOG Games/Rise of the Triad/",
/* gog - classic rott (native) */
"/GOG Games/Rise of the Triad Dark War/"
};

#endif

static const int num_storefront_paths = sizeof(storefront_paths) / sizeof(const char *);

/*
*
* we now return to your regularly scheduled programming
*
*/

static char *GetExeDir (void)
{
static char *dir;
Expand Down Expand Up @@ -163,6 +232,39 @@ static void AddXdgDirs(void)
}
#endif

static void AddStorefrontDirs(void)
{
struct stat st;
char path[1024];

#ifndef _WIN32
char *prefix = getenv("HOME");

if (prefix == NULL)
{
struct passwd *pwd = getpwuid(getuid());

if (pwd == NULL)
{
perror("getpwuid");
return;
}

prefix = pwd->pw_dir;
}
#else
const char prefix[] = "C:";
#endif

for (int i = 0; i < num_storefront_paths; i++)
{
M_snprintf(path, sizeof(path), "%s%s", prefix, storefront_paths[i]);

if (stat(path, &st) == 0 && S_ISDIR(st.st_mode))
AddDataDir(M_StringDuplicate(path));
}
}

static void BuildDataDirList(void)
{
if (datadirs[0])
Expand All @@ -184,6 +286,8 @@ static void BuildDataDirList(void)
#ifndef _WIN32
AddXdgDirs();
#endif

AddStorefrontDirs();
}

char *FindFileByName(const char *name)
Expand Down
2 changes: 1 addition & 1 deletion rott/rt_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -7976,7 +7976,7 @@ void ShowBattleOptions
}
ShowBattleOption( inmenu, PosX, PosY, 0, 9, "Danger Damage", string );

GetMapFileName ( text );
GetMapFileName ( text, sizeof(text) );
ShowBattleOption( inmenu, PosX, PosY, 0, 10, "Filename", text );

itoa( numplayers, text, 10 );
Expand Down
2 changes: 1 addition & 1 deletion rott/rt_net.c
Original file line number Diff line number Diff line change
Expand Up @@ -2420,7 +2420,7 @@ void SendGameDescription( void )
desc->teamplay = gamestate.teamplay;
memcpy( &desc->SpecialsTimes, &gamestate.SpecialsTimes, sizeof( specials ) );
BATTLE_GetOptions( &( desc->options ) );
GetMapFileName( &(desc->battlefilename[0]) );
GetMapFileName( &(desc->battlefilename[0]), sizeof(desc->battlefilename) );
desc->randomseed=GetRNGindex ( );
gamestate.randomseed=desc->randomseed;
desc->ludicrousgibs=battlegibs;
Expand Down
32 changes: 14 additions & 18 deletions rott/rt_ted.c
Original file line number Diff line number Diff line change
Expand Up @@ -1622,24 +1622,20 @@ void GetMapFileInfo
=
======================
*/
void GetMapFileName ( char * filename )
void GetMapFileName ( char * filename, size_t n )
{
if ( ( BATTLEMODE ) && (BattleLevels.avail == true) )
{
strcpy(filename,BattleLevels.file);
}
else if (GameLevels.avail == true)
{
strcpy(filename,GameLevels.file);
}
else if ( BATTLEMODE )
{
strcpy(filename,BATTMAPS);
}
else
{
strcpy(filename,ROTTMAPS);
}
const char *src;

if (BATTLEMODE && BattleLevels.avail == true)
src = M_BaseName(BattleLevels.file);
else if (GameLevels.avail == true)
src = M_BaseName(GameLevels.file);
else if (BATTLEMODE)
src = M_BaseName(BATTMAPS);
else
src = M_BaseName(ROTTMAPS);

strncpy(filename,src,n);
}

/*
Expand Down Expand Up @@ -1673,7 +1669,7 @@ unsigned short GetMapCRC
RTLMAP RTLMap;
size_t mapsoffset;

GetMapFileName( &filename[ 0 ] );
GetMapFileName( &filename[ 0 ], sizeof(filename) );
CheckRTLVersion( filename );
filehandle = SafeOpenRead( filename );
mapsoffset = GetMapArrayOffset( filehandle );
Expand Down
2 changes: 1 addition & 1 deletion rott/rt_ted.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ void PrintMapStats (void);
void PrintTileStats (void);

void GetMapInfo (mapfileinfo_t * mapinfo);
void GetMapFileName ( char * filename );
void GetMapFileName ( char * filename, size_t n );
void SetBattleMapFileName ( char * filename );
unsigned short GetMapCRC ( int num );

Expand Down
Loading