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

Fix mercenary features #260

Merged
merged 1 commit into from
May 3, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
88 changes: 23 additions & 65 deletions Descent3/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1051,6 +1051,8 @@ int CD_inserted = 0;
float Mouselook_sensitivity = kAnglesPerDegree * kDefaultMouselookSensitivity;
float Mouse_sensitivity = 1.0f;

int merc_hid = -1;

int IsLocalOk(void) {
#ifdef WIN32
#ifdef ALLOW_ALL_LANG
Expand Down Expand Up @@ -1548,40 +1550,6 @@ tTempFileInfo temp_file_wildcards[] = {{"d3s*.tmp"}, {"d3m*.tmp"}, {"d3o*.tmp"},
{"d3c*.tmp"}, {"d3t*.tmp"}, {"d3i*.tmp"}};
int num_temp_file_wildcards = sizeof(temp_file_wildcards) / sizeof(tTempFileInfo);

// Returns true if Mercenary is installed
bool MercInstalled() {
#if defined(LINUX)
return false; // TODO: check for mercenary
#else
HKEY key;
DWORD lType;
LONG error;

#define BUFLEN 2000
char dir[BUFLEN];
DWORD dir_len = BUFLEN;

error =
RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Descent3 Mercenary", 0,
KEY_ALL_ACCESS, &key);

if ((error == ERROR_SUCCESS)) {
lType = REG_EXPAND_SZ;

unsigned long len = BUFLEN;
error = RegQueryValueEx(key, "UninstallString", NULL, &lType, (unsigned char *)dir, &len);

if (error == ERROR_SUCCESS) {
// Mercenary is installed
return true;
}
}

// Mercenary not installed
return false;
#endif
}

/*
I/O systems initialization
*/
Expand Down Expand Up @@ -1668,7 +1636,7 @@ void InitIOSystems(bool editor) {
}

// Init hogfiles
int d3_hid = -1, extra_hid = -1, merc_hid = -1, sys_hid = -1, extra13_hid = -1;
int d3_hid = -1, extra_hid = -1, sys_hid = -1, extra13_hid = -1;
char fullname[_MAX_PATH];

#ifdef DEMO
Expand All @@ -1688,40 +1656,25 @@ void InitIOSystems(bool editor) {
ddio_MakePath(fullname, LocalD3Dir, "d3-osx.hog", NULL);
sys_hid = cf_OpenLibrary(fullname);
#endif


// JC: Steam release uses extra1.hog instead of extra.hog, so try loading it first
// Open this file if it's present for stuff we might add later
ddio_MakePath(fullname, LocalD3Dir, "extra.hog", NULL);
ddio_MakePath(fullname, LocalD3Dir, "extra1.hog", NULL);
extra_hid = cf_OpenLibrary(fullname);
if (extra_hid == 0) {
ddio_MakePath(fullname, LocalD3Dir, "extra.hog", NULL);
extra_hid = cf_OpenLibrary(fullname);
}

// Opens the mercenary hog if it exists and the registry entery is present
// Win32 only. Mac and Linux users are SOL for now
#ifdef WIN32
HKEY key;
DWORD lType;
LONG error;

#define BUFLEN 2000
char dir[BUFLEN];
DWORD dir_len = BUFLEN;

error =
RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Descent3 Mercenary", 0,
KEY_ALL_ACCESS, &key);

if ((error == ERROR_SUCCESS)) {
lType = REG_EXPAND_SZ;

unsigned long len = BUFLEN;
error = RegQueryValueEx(key, "UninstallString", NULL, &lType, (unsigned char *)dir, &len);

if (error == ERROR_SUCCESS) {
merc_hid = cf_OpenLibrary("merc.hog");
}
// JC: Steam release uses extra.hog instead of merc.hog, so try loading it last (so we don't conflict with the above)
// Open mercenary hog if it exists
ddio_MakePath(fullname, LocalD3Dir, "merc.hog", NULL);
merc_hid = cf_OpenLibrary(fullname);
if (merc_hid == 0) {
ddio_MakePath(fullname, LocalD3Dir, "extra.hog", NULL);
merc_hid = cf_OpenLibrary(fullname);
}
#else
// non-windows platforms always get merc!
merc_hid = cf_OpenLibrary("merc.hog");
#endif

// Open this for extra 1.3 code (Black Pyro, etc)
ddio_MakePath(fullname, LocalD3Dir, "extra13.hog", NULL);
extra13_hid = cf_OpenLibrary(fullname);
Expand Down Expand Up @@ -1765,6 +1718,11 @@ void InitIOSystems(bool editor) {
Osiris_ExtractScriptsFromHog(d3_hid, false);
}

// Returns true if Mercenary is installed (inits the Black Pyro and Red GB)
bool MercInstalled() {
return merc_hid > 0;
}

extern int Num_languages;
void InitStringTable() {

Expand Down
4 changes: 0 additions & 4 deletions Descent3/object_external.h
Original file line number Diff line number Diff line change
Expand Up @@ -352,10 +352,6 @@

// Static Robot ids
#define ROBOT_GUIDEBOT 0 // NOTE: this must match GENOBJ_GUIDEBOT
#ifdef _WIN32
#define ROBOT_GUIDEBOTRED 2 // NOTE: this must match GENOBJ_GUIDEBOTRED
#else
#define ROBOT_GUIDEBOTRED 0 // NOTE: this must match GENOBJ_GUIDEBOTRED
#endif

#endif
2 changes: 1 addition & 1 deletion Descent3/objinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ int Num_object_ids[MAX_OBJECT_TYPES];
// #ifdef _WIN32
// char *Static_object_names[]={TBL_GENERIC("GuideBot"),TBL_GENERIC("ChaffChunk"),TBL_GENERIC("GuideBotRed")};
// #else
const char *Static_object_names[] = {TBL_GENERIC("GuideBot"), TBL_GENERIC("ChaffChunk")};
const char *Static_object_names[] = {TBL_GENERIC("GuideBot"), TBL_GENERIC("ChaffChunk"),TBL_GENERIC("GuideBotRed")};
// #endif

#define NUM_STATIC_OBJECTS (sizeof(Static_object_names) / sizeof(*Static_object_names))
Expand Down
4 changes: 0 additions & 4 deletions Descent3/objinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -358,11 +358,7 @@ extern char *Anim_state_names[];
// These defines must correspond to the Static_object_names array
#define GENOBJ_GUIDEBOT 0 // NOTE: This must match ROBOT_GUIDEBOT
#define GENOBJ_CHAFFCHUNK 1
#ifdef _WIN32
#define GENOBJ_GUIDEBOTRED 2 // NOTE: This must match ROBOT_GUIDEBOTRED
#else
#define GENOBJ_GUIDEBOTRED 0 // NOTE: This must match ROBOT_GUIDEBOTRED
#endif

#define IS_GUIDEBOT(x) \
(((object *)x)->type == OBJ_ROBOT && \
Expand Down
50 changes: 10 additions & 40 deletions Descent3/pilot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2910,46 +2910,16 @@ bool PltSelectShip(pilot *Pilot) {
#ifdef DEMO
if (strcmpi(Ships[i].name, DEFAULT_SHIP) == 0) {
#endif
#ifdef WIN32
HKEY key;
DWORD lType;
LONG error;

#define BUFLEN 2000
char dir[BUFLEN];
DWORD dir_len = BUFLEN;

if (!stricmp(Ships[i].name, "Black Pyro")) {
// make sure they have mercenary in order to play with Black Pyro
shipoktoadd = false;

error = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Descent3 Mercenary", 0,
KEY_ALL_ACCESS, &key);

if ((error == ERROR_SUCCESS)) {
lType = REG_EXPAND_SZ;

unsigned long len = BUFLEN;
error = RegQueryValueEx(key, "UninstallString", NULL, &lType, (unsigned char *)dir, &len);

if (error == ERROR_SUCCESS) {
// they have mercenary, and this is a black pyro...add it
shipoktoadd = true;
}
}
} else {
// this isn't a black pyro
shipoktoadd = true;
}
#else
// Non-Windows versions don't have to check
if (!stricmp(Ships[i].name, "Black Pyro")) {
shipoktoadd = false;
} else {
shipoktoadd = true;
}
#endif
// make sure they have mercenary in order to play with Black Pyro
if (!stricmp(Ships[i].name, "Black Pyro")) {
shipoktoadd = false;
extern bool MercInstalled();
if (MercInstalled()) {
shipoktoadd = true;
}
}
else
shipoktoadd = true;
if (shipoktoadd)
ship_list->AddItem(Ships[i].name);
#ifdef DEMO
Expand Down