- implemented 'map' CCMD for all games.

This commit is contained in:
Christoph Oelckers 2020-01-28 11:20:30 +01:00
parent 809b687969
commit 8657ecb35d
10 changed files with 141 additions and 129 deletions

View file

@ -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 <mapfile>: loads the given user map", osdcmd_map);
OSD_RegisterFunction("map","map <mapname>: loads the given map", osdcmd_map);
OSD_RegisterFunction("demo","demo <demofile or demonum>: starts the given demo", osdcmd_demo);
OSD_RegisterFunction("give","give <all|health|weapons|ammo|armor|keys|inventory>: gives requested item", osdcmd_give);

View file

@ -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<ti; ii++) fprintf(stderr,"%d ", t[ii]-t[ii-1]); fprintf(stderr,"\n"); } while (0)
#if defined _WIN32 && !defined EDUKE32_STANDALONE
int Paths_ReadRegistryValue(char const * const SubKey, char const * const Value, char * const Output, DWORD * OutputSize);
#endif
#endif

View file

@ -29,13 +29,6 @@ void SetClipshapes()
#endif
}
#ifdef HAVE_CLIPSHAPE_FEATURE
void G_AddClipMap(const char *buffer)
{
g_clipMapFiles.Push(buffer);
}
#endif
//////////
int32_t getatoken(scriptfile *sf, const tokenlist *tl, int32_t ntokens)
@ -97,39 +90,3 @@ int32_t FindDistance3D(int32_t x, int32_t y, int32_t z)
{
return sepdist(x, y, z);
}
#if defined _WIN32 && !defined EDUKE32_STANDALONE
# define NEED_SHLWAPI_H
# include "windows_inc.h"
# ifndef KEY_WOW64_64KEY
# define KEY_WOW64_64KEY 0x0100
# endif
# ifndef KEY_WOW64_32KEY
# define KEY_WOW64_32KEY 0x0200
# endif
int Paths_ReadRegistryValue(char const * const SubKey, char const * const Value, char * const Output, DWORD * 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

View file

@ -130,7 +130,7 @@ void G_AddExternalSearchPaths(TArray<FString> &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

View file

@ -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 <mapname>: loads the given map", osdcmd_map);
if (!VOLUMEONE)
{
OSD_RegisterFunction("map","map <mapfile>: loads the given user map", osdcmd_map);
OSD_RegisterFunction("demo","demo <demofile or demonum>: starts the given demo", osdcmd_demo);
}

View file

@ -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 <level>: warps to the given level", osdcmd_changelevel);
//else
//{
// OSD_RegisterFunction("changelevel","changelevel <volume> <level>: warps to the given level", osdcmd_changelevel);
// OSD_RegisterFunction("map","map <mapfile>: loads the given user map", osdcmd_map);
OSD_RegisterFunction("map","map <mapname>: loads the given map", osdcmd_map);
// OSD_RegisterFunction("demo","demo <demofile or demonum>: starts the given demo", osdcmd_demo);
//}

View file

@ -59,6 +59,7 @@
#include <mmsystem.h>
#include <richedit.h>
#include <wincrypt.h>
#include <shlwapi.h>
#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

View file

@ -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

View file

@ -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 <demonum or demofn> [<prof>]
//
// To profile a demo ("timedemo mode"), <prof> 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 <mapname>: loads the given map", osdcmd_map);
if (!VOLUMEONE)
{
OSD_RegisterFunction("map","map <mapfile>: loads the given user map", osdcmd_map);
OSD_RegisterFunction("demo","demo <demofile or demonum>: starts the given demo", osdcmd_demo);
}
OSD_RegisterFunction("levelwarp","levelwarp <e> <m>: warp to episode 'e' and map 'm'", osdcmd_levelwarp);

View file

@ -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 <mapfile>: loads the given map", osdcmd_map);
OSD_RegisterFunction("give","give <all|health|weapons|ammo|armor|keys|inventory>: gives requested item", osdcmd_give);
OSD_RegisterFunction("god","god: toggles god mode", osdcmd_god);
OSD_RegisterFunction("activatecheat","activatecheat <string>: activates a classic cheat code", osdcmd_activatecheat);