diff --git a/source/blood/src/osdcmd.cpp b/source/blood/src/osdcmd.cpp index be1585662..d8278df4a 100644 --- a/source/blood/src/osdcmd.cpp +++ b/source/blood/src/osdcmd.cpp @@ -58,7 +58,7 @@ static int osdcmd_map(osdcmdptr_t parm) strcpy(filename, parm->parms[0]); ChangeExtension(filename, ""); - if (!gSysRes.Lookup(filename, "MAP")) + if (!fileSystem.Lookup(filename, "MAP")) { OSD_Printf(OSD_ERROR "map: file \"%s\" not found.\n", filename); return OSDCMD_OK; @@ -255,7 +255,7 @@ static int osdcmd_levelwarp(osdcmdptr_t parm) int32_t registerosdcommands(void) { - OSD_RegisterFunction("map","map : loads the given user map", osdcmd_map); + OSD_RegisterFunction("map","map : loads the given map", osdcmd_map); OSD_RegisterFunction("demo","demo : starts the given demo", osdcmd_demo); OSD_RegisterFunction("give","give : gives requested item", osdcmd_give); diff --git a/source/build/include/common.h b/source/build/include/common.h index dfa16bc22..754f247de 100644 --- a/source/build/include/common.h +++ b/source/build/include/common.h @@ -46,9 +46,6 @@ extern const char *s_buildTimestamp; void G_AddDef(const char *buffer); void G_AddDefModule(const char *buffer); -#ifdef HAVE_CLIPSHAPE_FEATURE -void G_AddClipMap(const char *buffer); -#endif // returns a buffer of size BMAX_PATH static inline char *dup_filename(const char *fn) @@ -115,8 +112,4 @@ void COMMON_clearbackground(int32_t numcols, int32_t numrows); #define EDUKE32_TMRTIC t[ti++]=timerGetTicks() #define EDUKE32_TMRPRN do { int ii=0; fprintf(stderr,"%s: ",tmrstr); for (ii=1; ii &searchpaths) // 3D Realms Anthology char buf[PATH_MAX]; DWORD bufsize = sizeof(buf); - if (Paths_ReadRegistryValue(entry.regPath, entry.regKey, buf, &bufsize)) + if (I_ReadRegistryValue(entry.regPath, entry.regKey, buf, &bufsize)) { if (!entry.subpaths) AddSearchPath(searchpaths, buf); else diff --git a/source/duke3d/src/osdcmds.cpp b/source/duke3d/src/osdcmds.cpp index e118be8ac..0ed4fa039 100644 --- a/source/duke3d/src/osdcmds.cpp +++ b/source/duke3d/src/osdcmds.cpp @@ -73,37 +73,48 @@ static int osdcmd_levelwarp(osdcmdptr_t parm) static int osdcmd_map(osdcmdptr_t parm) { - char filename[BMAX_PATH]; + FString mapname; - const int32_t wildcardp = parm->numparms==1 && - (Bstrchr(parm->parms[0], '*') != NULL); - - if (parm->numparms != 1 || wildcardp) + if (parm->numparms != 1) { return OSDCMD_SHOWHELP; } - - maybe_append_ext(filename, sizeof(filename), parm->parms[0], ".map"); - - if (!fileSystem.FileExists(filename)) + + if (!fileSystem.Lookup(mapname, "MAP")) { - OSD_Printf(OSD_ERROR "map: file \"%s\" not found.\n", filename); + OSD_Printf(OSD_ERROR "map: file \"%s\" not found.\n", mapname.GetChars()); return OSDCMD_OK; } - + + // Check if the map is already defined. + for (int i = 0; i < 512; i++) + { + if (mapList[i].labelName.CompareNoCase(mapname) == 0) + { + ud.m_volume_number = i / MAXLEVELS; + m_level_number = i % MAXLEVELS; + goto foundone; + } + } + if (VOLUMEONE) + { + OSD_Printf(OSD_ERROR "Cannot use user maps in shareware.\n"); + return OSDCMD_OK; + } + // Treat as user map boardfilename[0] = '/'; boardfilename[1] = 0; - strcat(boardfilename, filename); - + ud.m_volume_number = 0; + m_level_number = 7; + DefaultExtension(mapname, ".map"); + strcat(boardfilename, mapname); +foundone: if (numplayers > 1) { return OSDCMD_OK; } osdcmd_cheatsinfo_stat.cheatnum = -1; - ud.m_volume_number = 0; - m_level_number = 7; - ud.m_monsters_off = ud.monsters_off = 0; ud.m_respawn_items = 0; @@ -712,9 +723,9 @@ int32_t registerosdcommands(void) OSD_RegisterFunction("playerinfo", "Prints information about the current player", osdcmd_playerinfo); #endif + OSD_RegisterFunction("map","map : loads the given map", osdcmd_map); if (!VOLUMEONE) { - OSD_RegisterFunction("map","map : loads the given user map", osdcmd_map); OSD_RegisterFunction("demo","demo : starts the given demo", osdcmd_demo); } diff --git a/source/exhumed/src/osdcmds.cpp b/source/exhumed/src/osdcmds.cpp index 06a1f205f..2f2506bb0 100644 --- a/source/exhumed/src/osdcmds.cpp +++ b/source/exhumed/src/osdcmds.cpp @@ -26,6 +26,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "exhumed.h" #include "osdcmds.h" #include "view.h" +#include "mapinfo.h" BEGIN_PS_NS @@ -60,6 +61,34 @@ static int osdcmd_noclip(osdcmdptr_t UNUSED(parm)) return OSDCMD_OK; } +static int osdcmd_map(osdcmdptr_t parm) +{ + FString mapname; + + if (parm->numparms != 1) + { + return OSDCMD_SHOWHELP; + } + + if (!fileSystem.Lookup(mapname, "MAP")) + { + OSD_Printf(OSD_ERROR "map: file \"%s\" not found.\n", mapname.GetChars()); + return OSDCMD_OK; + } + + // Check if the map is already defined. + for (int i = 0; i <= ISDEMOVER? 4 : 32; i++) + { + if (mapList[i].labelName.CompareNoCase(mapname) == 0) + { + levelnew = i; + levelnum = i; + return OSDCMD_OK; + } + } + return OSDCMD_OK; +} + static int osdcmd_changelevel(osdcmdptr_t parm) { char* p; @@ -97,10 +126,7 @@ int32_t registerosdcommands(void) { //if (VOLUMEONE) OSD_RegisterFunction("changelevel","changelevel : warps to the given level", osdcmd_changelevel); - //else - //{ - // OSD_RegisterFunction("changelevel","changelevel : warps to the given level", osdcmd_changelevel); - // OSD_RegisterFunction("map","map : loads the given user map", osdcmd_map); + OSD_RegisterFunction("map","map : loads the given map", osdcmd_map); // OSD_RegisterFunction("demo","demo : starts the given demo", osdcmd_demo); //} diff --git a/source/platform/win32/i_system.cpp b/source/platform/win32/i_system.cpp index 5af77c428..ac66e8a49 100644 --- a/source/platform/win32/i_system.cpp +++ b/source/platform/win32/i_system.cpp @@ -59,6 +59,7 @@ #include #include #include +#include #include "hardware.h" #include "printf.h" @@ -1289,3 +1290,35 @@ void I_SetThreadNumaNode(std::thread &thread, int numaNode) SetThreadAffinityMask(handle, (DWORD_PTR)numaNodes[numaNode].affinityMask); } } + +# ifndef KEY_WOW64_64KEY +# define KEY_WOW64_64KEY 0x0100 +# endif +# ifndef KEY_WOW64_32KEY +# define KEY_WOW64_32KEY 0x0200 +# endif + +int I_ReadRegistryValue(char const * const SubKey, char const * const Value, char * const Output, size_t * OutputSize) +{ + // KEY_WOW64_32KEY gets us around Wow6432Node on 64-bit builds + REGSAM const wow64keys[] = { KEY_WOW64_32KEY, KEY_WOW64_64KEY }; + + for (auto &wow64key : wow64keys) + { + HKEY hkey; + LONG keygood = RegOpenKeyEx(HKEY_LOCAL_MACHINE, NULL, 0, KEY_READ | wow64key, &hkey); + + if (keygood != ERROR_SUCCESS) + continue; + + LONG retval = SHGetValueA(hkey, SubKey, Value, NULL, Output, OutputSize); + + RegCloseKey(hkey); + + if (retval == ERROR_SUCCESS) + return 1; + } + + return 0; +} +#endif diff --git a/source/platform/win32/i_system.h b/source/platform/win32/i_system.h index b7b65b65e..fac4d60ea 100644 --- a/source/platform/win32/i_system.h +++ b/source/platform/win32/i_system.h @@ -154,4 +154,6 @@ int I_GetNumaNodeCount(); int I_GetNumaNodeThreadCount(int numaNode); void I_SetThreadNumaNode(std::thread &thread, int numaNode); +int I_ReadRegistryValue(char const * const SubKey, char const * const Value, char * const Output, size_t * OutputSize); + #endif diff --git a/source/rr/src/osdcmds.cpp b/source/rr/src/osdcmds.cpp index 70de75d3e..ed2606645 100644 --- a/source/rr/src/osdcmds.cpp +++ b/source/rr/src/osdcmds.cpp @@ -71,37 +71,48 @@ static int osdcmd_levelwarp(osdcmdptr_t parm) static int osdcmd_map(osdcmdptr_t parm) { - char filename[BMAX_PATH]; + FString mapname; - const int32_t wildcardp = parm->numparms==1 && - (Bstrchr(parm->parms[0], '*') != NULL); - - if (parm->numparms != 1 || wildcardp) + if (parm->numparms != 1) { return OSDCMD_SHOWHELP; } - - maybe_append_ext(filename, sizeof(filename), parm->parms[0], ".map"); - - if (!fileSystem.FileExists(filename)) + + if (!fileSystem.Lookup(mapname, "MAP")) { - OSD_Printf(OSD_ERROR "map: file \"%s\" not found.\n", filename); + OSD_Printf(OSD_ERROR "map: file \"%s\" not found.\n", mapname.GetChars()); return OSDCMD_OK; } - + + // Check if the map is already defined. + for (int i = 0; i < 512; i++) + { + if (mapList[i].labelName.CompareNoCase(mapname) == 0) + { + ud.m_volume_number = i / MAXLEVELS; + m_level_number = i % MAXLEVELS; + goto foundone; + } + } + if (VOLUMEONE) + { + OSD_Printf(OSD_ERROR "Cannot use user maps in shareware.\n"); + return OSDCMD_OK; + } + // Treat as user map boardfilename[0] = '/'; boardfilename[1] = 0; - strcat(boardfilename, filename); - + ud.m_volume_number = 0; + m_level_number = 7; + DefaultExtension(mapname, ".map"); + strcat(boardfilename, mapname); +foundone: if (numplayers > 1) { return OSDCMD_OK; } osdcmd_cheatsinfo_stat.cheatnum = -1; - ud.m_volume_number = 0; - m_level_number = 7; - ud.m_monsters_off = ud.monsters_off = 0; ud.m_respawn_items = 0; @@ -119,6 +130,7 @@ static int osdcmd_map(osdcmdptr_t parm) return OSDCMD_OK; } + // demo [] // // To profile a demo ("timedemo mode"), can be given in the range 0-8, @@ -552,9 +564,9 @@ static int osdcmd_printtimes(osdcmdptr_t UNUSED(parm)) int32_t registerosdcommands(void) { + OSD_RegisterFunction("map","map : loads the given map", osdcmd_map); if (!VOLUMEONE) { - OSD_RegisterFunction("map","map : loads the given user map", osdcmd_map); OSD_RegisterFunction("demo","demo : starts the given demo", osdcmd_demo); } OSD_RegisterFunction("levelwarp","levelwarp : warp to episode 'e' and map 'm'", osdcmd_levelwarp); diff --git a/source/sw/src/osdcmds.cpp b/source/sw/src/osdcmds.cpp index a927c3e9e..b8940a7a5 100644 --- a/source/sw/src/osdcmds.cpp +++ b/source/sw/src/osdcmds.cpp @@ -53,57 +53,34 @@ char boardfilename[BMAX_PATH] = {0}; struct osdcmd_cheatsinfo osdcmd_cheatsinfo_stat = { -1, 0, 0 }; -#if 0 static int osdcmd_map(osdcmdptr_t parm) { - char filename[BMAX_PATH]; + FString mapname; - const int32_t wildcardp = parm->numparms==1 && - (Bstrchr(parm->parms[0], '*') != NULL); - - if (parm->numparms != 1 || wildcardp) + if (parm->numparms != 1) { return OSDCMD_SHOWHELP; } - - maybe_append_ext(filename, sizeof(filename), parm->parms[0], ".map"); - - if (!fileSystem.FileExists(filename)) + + if (!fileSystem.Lookup(mapname, "MAP")) { - OSD_Printf(OSD_ERROR "map: file \"%s\" not found.\n", filename); + OSD_Printf(OSD_ERROR "map: file \"%s\" not found.\n", mapname.GetChars()); return OSDCMD_OK; } - - boardfilename[0] = '/'; - boardfilename[1] = 0; - strcat(boardfilename, filename); - - if (numplayers > 1) + + // Check if the map is already defined. + for (int i = 0; i < 32; i++) { - return OSDCMD_OK; + if (mapList[i].labelName.CompareNoCase(mapname) == 0) + { + FStringf cheatcode("swtrek%02d", i+1); + WarpCheat(Player, cheatcode); + return OSDCMD_OK; + } } - - osdcmd_cheatsinfo_stat.cheatnum = -1; - //ud.m_volume_number = 0; - m_level_number = 7; - - //ud.m_monsters_off = ud.monsters_off = 0; - - //ud.m_respawn_items = 0; - //ud.m_respawn_inventory = 0; - - //ud.multimode = 1; - - if (g_player[myconnectindex].ps->gm & MODE_GAME) - { - //G_NewGame(ud.m_volume_number, m_level_number, ud.m_player_skill); - g_player[myconnectindex].ps->gm = MODE_RESTART; - } - else G_NewGame_EnterLevel(); - return OSDCMD_OK; } -#endif + static int osdcmd_activatecheat(osdcmdptr_t parm) { @@ -299,6 +276,7 @@ static int osdcmd_give(osdcmdptr_t parm) int32_t registerosdcommands(void) { + OSD_RegisterFunction("map","map : loads the given map", osdcmd_map); OSD_RegisterFunction("give","give : gives requested item", osdcmd_give); OSD_RegisterFunction("god","god: toggles god mode", osdcmd_god); OSD_RegisterFunction("activatecheat","activatecheat : activates a classic cheat code", osdcmd_activatecheat);