diff --git a/.idea/workspace.xml b/.idea/workspace.xml index ce9e03e..5b61f3a 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -28,9 +28,39 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -102,7 +135,7 @@ - + @@ -156,7 +189,8 @@ - diff --git a/Misc/fix_externaltex.patch b/Misc/fix_externaltex.patch index be22dbc..bcad208 100644 --- a/Misc/fix_externaltex.patch +++ b/Misc/fix_externaltex.patch @@ -15,7 +15,7 @@ index 239d361..80948f1 100644 @@ -549,6 +551,13 @@ static void Mod_LoadTextures (lump_t *l) { - if (!q_strncasecmp(tx->name,"sky",3)) //sky texture //also note -- was Q_strncmp, changed to match qbsp + if (!common::strncasecmp(tx->name,"sky",3)) //sky texture //also note -- was Q_strncmp, changed to match qbsp { + if (r_externaltexture_fix.value) { //mk + if (strstr(tx->name,"sky4")) { diff --git a/Quake/bgmusic.cpp b/Quake/bgmusic.cpp index 4212129..8df8f93 100644 --- a/Quake/bgmusic.cpp +++ b/Quake/bgmusic.cpp @@ -123,13 +123,13 @@ namespace music { void _loop() { if (command::argc() == 2) { - if (q_strcasecmp(command::argv(1)->c_str(), "0") == 0 || - q_strcasecmp(command::argv(1)->c_str(), "off") == 0) + if (std::is_eq(common::strcasecmp(command::argv(1).value(), "0")) || + std::is_eq(common::strcasecmp(command::argv(1).value(), "off"))) looping = false; - else if (q_strcasecmp(command::argv(1)->c_str(), "1") == 0 || - q_strcasecmp(command::argv(1)->c_str(), "on") == 0) + else if (std::is_eq(common::strcasecmp(command::argv(1).value(), "1")) || + std::is_eq(common::strcasecmp(command::argv(1).value(), "on"))) looping = true; - else if (q_strcasecmp(command::argv(1)->c_str(), "toggle") == 0) + else if (std::is_eq(common::strcasecmp(command::argv(1).value(), "toggle"))) looping = !looping; if (stream) stream->loop = looping; @@ -326,7 +326,7 @@ namespace music { const handler *chosen = nullptr; for (const auto &handler: active_handlers) { if (handler.is_available && - !q_strcasecmp(ext, handler.ext)) { + std::is_eq(common::strcasecmp(ext, handler.ext))) { chosen = &handler; break; } diff --git a/Quake/cd_sdl.cpp b/Quake/cd_sdl.cpp index cf0a22e..d350bd5 100644 --- a/Quake/cd_sdl.cpp +++ b/Quake/cd_sdl.cpp @@ -232,13 +232,13 @@ static void CD_f (void) command = command::argv (1)->c_str(); - if (q_strcasecmp(command, "on") == 0) + if (std::is_eq(common::strcasecmp(command, "on"))) { enabled = true; return; } - if (q_strcasecmp(command, "off") == 0) + if (std::is_eq(common::strcasecmp(command, "off"))) { if (playing) CDAudio_Stop(); @@ -246,7 +246,7 @@ static void CD_f (void) return; } - if (q_strcasecmp(command, "reset") == 0) + if (std::is_eq(common::strcasecmp(command, "reset"))) { enabled = true; if (playing) @@ -257,7 +257,7 @@ static void CD_f (void) return; } - if (q_strcasecmp(command, "remap") == 0) + if (std::is_eq(common::strcasecmp(command, "remap"))) { ret = command::argc() - 2; if (ret <= 0) @@ -282,7 +282,7 @@ static void CD_f (void) } } - if (q_strcasecmp(command, "play") == 0) + if (std::is_eq(common::strcasecmp(command, "play"))) { n = atoi(command::argv (2)->c_str()); if (n == 0) @@ -291,31 +291,31 @@ static void CD_f (void) return; } - if (q_strcasecmp(command, "loop") == 0) + if (std::is_eq(common::strcasecmp(command, "loop"))) { CDAudio_Play((byte)atoi(command::argv (2)->c_str()), true); return; } - if (q_strcasecmp(command, "stop") == 0) + if (std::is_eq(common::strcasecmp(command, "stop"))) { CDAudio_Stop(); return; } - if (q_strcasecmp(command, "pause") == 0) + if (std::is_eq(common::strcasecmp(command, "pause"))) { CDAudio_Pause(); return; } - if (q_strcasecmp(command, "resume") == 0) + if (std::is_eq(common::strcasecmp(command, "resume"))) { CDAudio_Resume(); return; } - if (q_strcasecmp(command, "eject") == 0) + if (std::is_eq(common::strcasecmp(command, "eject"))) { if (playing) CDAudio_Stop(); @@ -324,7 +324,7 @@ static void CD_f (void) return; } - if (q_strcasecmp(command, "info") == 0) + if (std::is_eq(common::strcasecmp(command, "info"))) { int current_min, current_sec, current_frame; int length_min, length_sec, length_frame; @@ -351,7 +351,7 @@ static void CD_f (void) return; } - if (q_strcasecmp(command, "next") == 0) + if (std::is_eq(common::strcasecmp(command, "next"))) { if (playTrack == cd_handle->numtracks) playTrack = get_first_audiotrk() - 1; @@ -359,7 +359,7 @@ static void CD_f (void) return; } - if (q_strcasecmp(command, "prev") == 0) + if (std::is_eq(common::strcasecmp(command, "prev"))) { if (playTrack == get_first_audiotrk()) playTrack = cd_handle->numtracks + 1; @@ -486,10 +486,10 @@ static void export_cddev_arg (void) * not needed for windows due to the way SDL_cdrom works. */ #if !defined(_WIN32) auto i = common::check_param("-cddev"); - if (i.has_value() && i.value() < com_argc - 1 && com_argv[i.value()+1][0] != '\0') + if (i.has_value() && i.value() < common::_argv.size() - 1 && common::_argv[i.value()+1][0] != '\0') { static char arg[64]; - q_snprintf(arg, sizeof(arg), "SDL_CDROM=%s", com_argv[i.value()+1]); + q_snprintf(arg, sizeof(arg), "SDL_CDROM=%s", common::_argv[i.value()+1].c_str()); putenv(arg); } #endif @@ -497,7 +497,7 @@ static void export_cddev_arg (void) int CDAudio_Init(void) { - if (safemode || common::check_param("-nocdaudio").has_value()) + if (common::safe_mode || common::check_param("-nocdaudio").has_value()) return -1; export_cddev_arg(); @@ -515,9 +515,9 @@ int CDAudio_Init(void) if (sdl_num_drives < 1) return -1; - if (const auto dev = common::check_param("-cddev"); dev.has_value() && dev.value() < com_argc - 1) + if (const auto dev = common::check_param("-cddev"); dev.has_value() && dev.value() < common::_argv.size() - 1) { - const char *userdev = get_cddev_arg(com_argv[dev.value()+1]); + const char *userdev = get_cddev_arg(common::_argv[dev.value()+1].c_str()); if (!userdev) { console::info("Invalid argument to -cddev\n"); @@ -525,7 +525,7 @@ int CDAudio_Init(void) } for (auto i = 0; i < sdl_num_drives; i++) { - if (!q_strcasecmp(SDL_CDName(i), userdev)) + if (std::is_eq(common::strcasecmp(SDL_CDName(i), userdev))) { cd_dev = i; break; diff --git a/Quake/cfgfile.cpp b/Quake/cfgfile.cpp index e03d975..04145ca 100644 --- a/Quake/cfgfile.cpp +++ b/Quake/cfgfile.cpp @@ -132,10 +132,10 @@ void CFG_ReadCvarOverrides (const char **vars, int num_vars) { q_strlcpy (&buff[1], vars[i], sizeof(buff) - 1); j = common::check_param(buff).has_value(); - if (j != 0 && j < com_argc - 1) + if (j != 0 && j < common::_argv.size() - 1) { - if (com_argv[j + 1][0] != '-' && com_argv[j + 1][0] != '+') - convar::set(vars[i], com_argv[j + 1]); + if (common::_argv[j + 1][0] != '-' && common::_argv[j + 1][0] != '+') + convar::set(vars[i], common::_argv[j + 1]); } } } diff --git a/Quake/cl_demo.cpp b/Quake/cl_demo.cpp index 5c55341..2985bff 100644 --- a/Quake/cl_demo.cpp +++ b/Quake/cl_demo.cpp @@ -40,8 +40,10 @@ read from the demo file. */ // from ProQuake: space to fill out the demo header for record at any time -static byte *demo_head; -static int *demo_head_sizes; +// static byte *demo_head; +// static int *demo_head_sizes; + +std::vector> demo_head{}; /* ============== @@ -49,8 +51,7 @@ CL_ClearSignons ============== */ void CL_ClearSignons(void) { - VEC_CLEAR(demo_head); - VEC_CLEAR(demo_head_sizes); + demo_head.clear(); cls.signon = 0; } @@ -178,8 +179,10 @@ int CL_GetMessage(void) { if (cls.signon < 2) { // record messages before full connection, so that a // demo record can happen after connection is done - Vec_Append((void **) &demo_head, 1, net_message.data(), net_message.size()); - VEC_PUSH(demo_head_sizes, net_message.size()); + std::vector new_msg{}; + new_msg.resize(net_message.size()); + std::memcpy(new_msg.data(), net_message.data(), net_message.size()); + demo_head.push_back(new_msg); } return r; @@ -300,12 +303,9 @@ void CL_Record_f(void) { static byte tmpbuf[NET_MAXMESSAGE]; net::msg old = net_message; - const auto count = VEC_SIZE(demo_head_sizes); - auto offset = 0; - for (auto i = 0; i < count; i++) { + for (auto msg : demo_head) { net_message = net::msg{}; - net_message.write(&demo_head[offset], demo_head_sizes[i]); - offset += demo_head_sizes[i]; + net_message.write(msg.data(), msg.size()); CL_WriteDemoMessage(); } diff --git a/Quake/cmd.cpp b/Quake/cmd.cpp index 26a0317..48cac65 100644 --- a/Quake/cmd.cpp +++ b/Quake/cmd.cpp @@ -366,7 +366,7 @@ namespace command { Sys_Error("Cmd_CheckParm: null input\n"); for (auto i = 1; i < argc(); i++) - if (!q_strcasecmp(parm.c_str(), argv(i)->c_str())) + if (std::is_eq(common::strcasecmp(parm, *argv(i)))) return i; return 0; @@ -417,7 +417,7 @@ namespace command { const auto needle = argv(0).value(); // check functions for (const auto &[name, ref]: REFS) { - if (!q_strcasecmp(needle.c_str(), name.c_str())) { + if (std::is_eq(common::strcasecmp(needle, name.c_str()))) { ref.func(); return; } @@ -425,7 +425,7 @@ namespace command { // check alias for (const auto &[name, alias]: ALIASES) { - if (!q_strcasecmp(argv(0).value().c_str(), name.c_str())) { + if (std::is_eq(common::strcasecmp(argv(0).value().c_str(), name.c_str()))) { buffer::insert_text(alias.value); return; } @@ -446,7 +446,7 @@ namespace command { return; // not really connected cls.message.write_byte(clc_stringcmd); - if (q_strcasecmp(argv(0).value_or("").c_str(), "cmd") != 0) { + if (std::is_eq(common::strcasecmp(argv(0).value_or(""), "cmd"))) { if (argc() > 1) { cls.message.write_string(std::format("{} {}", argv(0).value(), args())); } else { diff --git a/Quake/common.cpp b/Quake/common.cpp index 6f16620..c2fef92 100644 --- a/Quake/common.cpp +++ b/Quake/common.cpp @@ -31,11 +31,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "miniz.hpp" -static char *largv[MAX_NUM_ARGVS + 1]; static char argvdummy[] = " "; -int safemode; - convar registered = {"registered", "1", {.rom = true}}; /* set to correct value in COM_CheckRegistered() */ convar cmdline = {"cmdline", "", {.rom = true}/*|CVAR_SERVERINFO*/}; /* sending cmdline upon CCREQ_RULE_INFO is evil */ @@ -54,11 +51,6 @@ static void COM_Path_f(void); #define PAK0_COUNT_V091 308 /* id1/pak0.pak - v0.91/0.92, not supported */ #define PAK0_CRC_V091 28804 /* id1/pak0.pak - v0.91/0.92, not supported */ -int com_argc; -char **com_argv; - -#define CMDLINE_LENGTH 256 /* johnfitz -- mirrored in cmd.c */ -char com_cmdline[CMDLINE_LENGTH]; bool standard_quake = true, rogue, hipnotic; @@ -142,62 +134,6 @@ void InsertLinkAfter(link_t *l, link_t *after) { l->next->prev = l; } -/* -============================================================================ - - DYNAMIC VECTORS - -============================================================================ -*/ - -void Vec_Grow(void **pvec, size_t element_size, size_t count) { - vec_header_t header; - if (*pvec) - header = VEC_HEADER(*pvec); - else - header.size = header.capacity = 0; - - if (header.size + count > header.capacity) { - void *new_buffer; - size_t total_size; - - header.capacity = header.size + count; - header.capacity += header.capacity >> 1; - if (header.capacity < 16) - header.capacity = 16; - total_size = sizeof(vec_header_t) + header.capacity * element_size; - - if (*pvec) - new_buffer = realloc(((vec_header_t *) *pvec) - 1, total_size); - else - new_buffer = malloc(total_size); - if (!new_buffer) - Sys_Error("Vec_Grow: failed to allocate %lu bytes\n", (unsigned long) total_size); - - *pvec = 1 + (vec_header_t *) new_buffer; - VEC_HEADER(*pvec) = header; - } -} - -void Vec_Append(void **pvec, size_t element_size, const void *data, size_t count) { - if (!count) - return; - Vec_Grow(pvec, element_size, count); - memcpy((byte *) *pvec + VEC_HEADER(*pvec).size, data, count * element_size); - VEC_HEADER(*pvec).size += count; -} - -void Vec_Clear(void **pvec) { - if (*pvec) - VEC_HEADER(*pvec).size = 0; -} - -void Vec_Free(void **pvec) { - if (*pvec) { - free(&VEC_HEADER(*pvec)); - *pvec = NULL; - } -} /* ============================================================================ @@ -247,7 +183,7 @@ char *q_strcasestr(const char *haystack, const char *needle) { const size_t len = strlen(needle); while (*haystack) { - if (!q_strncasecmp(haystack, needle, len)) + if (std::is_eq(common::strncasecmp(haystack, needle, len))) return (char *) haystack; ++haystack; @@ -285,7 +221,7 @@ char *q_strupr(char *str) { #define vsnprintf_func vsnprintf #endif -int q_vsnprintf(char *str, size_t size, const char *format, va_list args) { +int q_vsnprintf(char *str, const size_t size, const char *format, va_list args) { int ret; ret = vsnprintf_func(str, size, format, args); @@ -300,7 +236,7 @@ int q_vsnprintf(char *str, size_t size, const char *format, va_list args) { return ret; } -int q_snprintf(char *str, size_t size, const char *format, ...) { +int q_snprintf(char *str, const size_t size, const char *format, ...) { int ret; va_list argptr; @@ -333,7 +269,7 @@ float (*BigFloat)(float l); float (*LittleFloat)(float l); -short ShortSwap(short l) { +short ShortSwap(const short l) { byte b1, b2; b1 = l & 255; @@ -342,11 +278,11 @@ short ShortSwap(short l) { return (b1 << 8) + b2; } -short ShortNoSwap(short l) { +short ShortNoSwap(const short l) { return l; } -int LongSwap(int l) { +int LongSwap(const int l) { byte b1, b2, b3, b4; b1 = l & 255; @@ -357,11 +293,11 @@ int LongSwap(int l) { return ((int) b1 << 24) + ((int) b2 << 16) + ((int) b3 << 8) + b4; } -int LongNoSwap(int l) { +int LongNoSwap(const int l) { return l; } -float FloatSwap(float f) { +float FloatSwap(const float f) { union { float f; byte b[4]; @@ -376,346 +312,10 @@ float FloatSwap(float f) { return dat2.f; } -float FloatNoSwap(float f) { +float FloatNoSwap(const float f) { return f; } -/* -============================================================================== - - MESSAGE IO FUNCTIONS - -Handles byte ordering and avoids alignment errors -============================================================================== -*/ - -// -// writing functions -// - -// void MSG_WriteChar(sizebuf_t *sb, int c) { -// byte *buf; -// -// #ifdef PARANOID -// if (c < -128 || c > 127) -// Sys_Error("MSG_WriteChar: range error"); -// #endif -// -// buf = (byte *) SZ_GetSpace(sb, 1); -// buf[0] = c; -// } -// -// void MSG_WriteByte(sizebuf_t *sb, int c) { -// byte *buf; -// -// #ifdef PARANOID -// if (c < 0 || c > 255) -// Sys_Error("MSG_WriteByte: range error"); -// #endif -// -// buf = (byte *) SZ_GetSpace(sb, 1); -// buf[0] = c; -// } -// -// void MSG_WriteShort(sizebuf_t *sb, int c) { -// byte *buf; -// -// #ifdef PARANOID -// if (c < ((short) 0x8000) || c > (short) 0x7fff) -// Sys_Error("MSG_WriteShort: range error"); -// #endif -// -// buf = (byte *) SZ_GetSpace(sb, 2); -// buf[0] = c & 0xff; -// buf[1] = c >> 8; -// } -// -// void MSG_WriteLong(sizebuf_t *sb, int c) { -// byte *buf; -// -// buf = (byte *) SZ_GetSpace(sb, 4); -// buf[0] = c & 0xff; -// buf[1] = (c >> 8) & 0xff; -// buf[2] = (c >> 16) & 0xff; -// buf[3] = c >> 24; -// } -// -// void MSG_WriteFloat(sizebuf_t *sb, float f) { -// union { -// float f; -// int l; -// } dat; -// -// dat.f = f; -// dat.l = LittleLong(dat.l); -// -// SZ_Write(sb, &dat.l, 4); -// } -// -// void MSG_WriteString(sizebuf_t *sb, const char *s) { -// if (!s) -// SZ_Write(sb, "", 1); -// else -// SZ_Write(sb, s, std::strlen(s) + 1); -// } -// -// //johnfitz -- original behavior, 13.3 fixed point coords, max range +-4096 -// void MSG_WriteCoord16(sizebuf_t *sb, float f) { -// MSG_WriteShort(sb, Q_rint(f*8)); -// } -// -// //johnfitz -- 16.8 fixed point coords, max range +-32768 -// void MSG_WriteCoord24(sizebuf_t *sb, float f) { -// MSG_WriteShort(sb, f); -// MSG_WriteByte(sb, (int) (f * 255) % 255); -// } -// -// //johnfitz -- 32-bit float coords -// void MSG_WriteCoord32f(sizebuf_t *sb, float f) { -// MSG_WriteFloat(sb, f); -// } -// -// void MSG_WriteCoord(sizebuf_t *sb, float f, unsigned int flags) { -// if (flags & PRFL_FLOATCOORD) -// MSG_WriteFloat(sb, f); -// else if (flags & PRFL_INT32COORD) -// MSG_WriteLong(sb, Q_rint(f * 16)); -// else if (flags & PRFL_24BITCOORD) -// MSG_WriteCoord24(sb, f); -// else MSG_WriteCoord16(sb, f); -// } -// -// void MSG_WriteAngle(sizebuf_t *sb, float f, unsigned int flags) { -// if (flags & PRFL_FLOATANGLE) -// MSG_WriteFloat(sb, f); -// else if (flags & PRFL_SHORTANGLE) -// MSG_WriteShort(sb, Q_rint(f * 65536.0 / 360.0) & 65535); -// else MSG_WriteByte(sb, Q_rint(f * 256.0 / 360.0) & 255); //johnfitz -- use Q_rint instead of (int) } -// } -// -// //johnfitz -- for PROTOCOL_FITZQUAKE -// void MSG_WriteAngle16(sizebuf_t *sb, float f, unsigned int flags) { -// if (flags & PRFL_FLOATANGLE) -// MSG_WriteFloat(sb, f); -// else MSG_WriteShort(sb, Q_rint(f * 65536.0 / 360.0) & 65535); -// } -// -// //johnfitz -// -// // -// // reading functions -// // -// int msg_readcount; -// bool msg_badread; -// -// void MSG_BeginReading(void) { -// msg_readcount = 0; -// msg_badread = false; -// } -// -// // returns -1 and sets msg_badread if no more characters are available -// int MSG_ReadChar(void) { -// int c; -// -// if (msg_readcount + 1 > net_message.cursize) { -// msg_badread = true; -// return -1; -// } -// -// c = (signed char) net_message.data[msg_readcount]; -// msg_readcount++; -// -// return c; -// } -// -// int MSG_ReadByte(void) { -// int c; -// -// if (msg_readcount + 1 > net_message.cursize) { -// msg_badread = true; -// return -1; -// } -// -// c = (unsigned char) net_message.data[msg_readcount]; -// msg_readcount++; -// -// return c; -// } -// -// int MSG_ReadShort(void) { -// int c; -// -// if (msg_readcount + 2 > net_message.cursize) { -// msg_badread = true; -// return -1; -// } -// -// c = (short) (net_message.data[msg_readcount] -// + (net_message.data[msg_readcount + 1] << 8)); -// -// msg_readcount += 2; -// -// return c; -// } -// -// int MSG_ReadLong(void) { -// int c; -// -// if (msg_readcount + 4 > net_message.cursize) { -// msg_badread = true; -// return -1; -// } -// -// c = net_message.data[msg_readcount] -// + (net_message.data[msg_readcount + 1] << 8) -// + (net_message.data[msg_readcount + 2] << 16) -// + (net_message.data[msg_readcount + 3] << 24); -// -// msg_readcount += 4; -// -// return c; -// } -// -// float MSG_ReadFloat(void) { -// union { -// byte b[4]; -// float f; -// int l; -// } dat; -// -// dat.b[0] = net_message.data[msg_readcount]; -// dat.b[1] = net_message.data[msg_readcount + 1]; -// dat.b[2] = net_message.data[msg_readcount + 2]; -// dat.b[3] = net_message.data[msg_readcount + 3]; -// msg_readcount += 4; -// -// dat.l = LittleLong(dat.l); -// -// return dat.f; -// } -// -// const char *MSG_ReadString(void) { -// static char string[2048]; -// int c; -// size_t l; -// -// l = 0; -// do { -// c = net_message.read_byte().value(); -// if (c == -1 || c == 0) -// break; -// string[l] = c; -// l++; -// } while (l < sizeof(string) - 1); -// -// string[l] = 0; -// -// return string; -// } -// -// //johnfitz -- original behavior, 13.3 fixed point coords, max range +-4096 -// float MSG_ReadCoord16(void) { -// return MSG_ReadShort() * (1.0 / 8); -// } -// -// //johnfitz -- 16.8 fixed point coords, max range +-32768 -// float MSG_ReadCoord24(void) { -// return MSG_ReadShort() + net_message.read_byte().value() * (1.0 / 255); -// } -// -// //johnfitz -- 32-bit float coords -// float MSG_ReadCoord32f(void) { -// return MSG_ReadFloat(); -// } -// -// float MSG_ReadCoord(unsigned int flags) { -// if (flags & PRFL_FLOATCOORD) -// return MSG_ReadFloat(); -// else if (flags & PRFL_INT32COORD) -// return MSG_ReadLong() * (1.0 / 16.0); -// else if (flags & PRFL_24BITCOORD) -// return MSG_ReadCoord24(); -// else return MSG_ReadCoord16(); -// } -// -// float MSG_ReadAngle(unsigned int flags) { -// if (flags & PRFL_FLOATANGLE) -// return MSG_ReadFloat(); -// else if (flags & PRFL_SHORTANGLE) -// return MSG_ReadShort() * (360.0 / 65536); -// else return MSG_ReadChar() * (360.0 / 256); -// } -// -// //johnfitz -- for PROTOCOL_FITZQUAKE -// float MSG_ReadAngle16(unsigned int flags) { -// if (flags & PRFL_FLOATANGLE) -// return MSG_ReadFloat(); // make sure -// else return MSG_ReadShort() * (360.0 / 65536); -// } -// -// //johnfitz - -//=========================================================================== - -void SZ_Alloc(sizebuf_t *buf, int startsize) { - if (startsize < 256) - startsize = 256; - buf->data = (byte *) Hunk_AllocName(startsize, "sizebuf"); - buf->maxsize = startsize; - buf->cursize = 0; -} - - -void SZ_Free(sizebuf_t *buf) { - // Z_Free (buf->data); - // buf->data = NULL; - // buf->maxsize = 0; - buf->cursize = 0; -} - -void SZ_Clear(sizebuf_t *buf) { - buf->cursize = 0; -} - -void *SZ_GetSpace(sizebuf_t *buf, int length) { - void *data; - - if (buf->cursize + length > buf->maxsize) { - if (!buf->allowoverflow) - Host_Error("SZ_GetSpace: overflow without allowoverflow set"); - // ericw -- made Host_Error to be less annoying - - if (length > buf->maxsize) - Sys_Error("SZ_GetSpace: %i is > full buffer size", length); - - buf->overflowed = true; - console::info("SZ_GetSpace: overflow\n"); - SZ_Clear(buf); - } - - data = buf->data + buf->cursize; - buf->cursize += length; - - return data; -} - -void SZ_Write(sizebuf_t *buf, const void *data, int length) { - std::memcpy(SZ_GetSpace(buf, length), data, length); -} - -void SZ_Print(sizebuf_t *buf, const char *data) { - int len = std::strlen(data) + 1; - - if (buf->data[buf->cursize - 1]) { - /* no trailing 0 */ - std::memcpy(SZ_GetSpace(buf, len), data, len); - } else { - /* write over trailing 0 */ - std::memcpy(static_cast(SZ_GetSpace(buf, len - 1)) - 1, data, len); - } -} - - //============================================================================ /* @@ -740,7 +340,7 @@ const char *COM_SkipPath(const char *pathname) { COM_StripExtension ============ */ -void COM_StripExtension(const char *in, char *out, size_t outsize) { +void COM_StripExtension(const char *in, char *out, const size_t outsize) { int length; if (!*in) { @@ -786,7 +386,7 @@ const char *COM_FileGetExtension(const char *in) { COM_ExtractExtension ============ */ -void COM_ExtractExtension(const char *in, char *out, size_t outsize) { +void COM_ExtractExtension(const char *in, char *out, const size_t outsize) { const char *ext = COM_FileGetExtension(in); if (!*ext) *out = '\0'; @@ -801,7 +401,7 @@ take 'somedir/otherdir/filename.ext', write only 'filename' to the output ============ */ -void COM_FileBase(const char *in, char *out, size_t outsize) { +void COM_FileBase(const char *in, char *out, const size_t outsize) { const char *dot, *slash, *s; s = in; @@ -859,13 +459,16 @@ if path extension doesn't match .EXT, append it (extension should include the leading ".") ================== */ -void COM_AddExtension(char *path, const char *extension, size_t len) { +void COM_AddExtension(char *path, const char *extension, const size_t len) { if (strcmp(COM_FileGetExtension(path), extension + 1) != 0) q_strlcat(path, extension, len); } namespace common { + std::vector _argv{}; + std::string cmdline{}; + bool safe_mode{false}; void init() { int i = 0x12345678; @@ -883,11 +486,9 @@ namespace common { */ if (*reinterpret_cast(&i) == 0x12) { host_bigendian = true; - } - else if (*reinterpret_cast(&i) == 0x78) { + } else if (*reinterpret_cast(&i) == 0x78) { host_bigendian = false; - } - else { + } else { Sys_Error("Unsupported endianism."); } @@ -913,12 +514,43 @@ namespace common { } } - std::optional check_param(std::string_view parm) { - for (auto i = 1; i < com_argc; i++) { - if (!com_argv[i]) { + void init_argv(const int nargc, char **nargv) { + for (auto j = 0; (j < MAX_NUM_ARGVS) && (j < nargc); j++) { + cmdline += nargv[j]; + cmdline += " "; + } + + if (!cmdline.empty() && cmdline.back() == ' ') + cmdline.pop_back(); + + console::info("Command line: %s\n", cmdline.c_str()); + + for (auto i = 0; (i < MAX_NUM_ARGVS) && (i < nargc); i++) { + _argv.emplace_back(nargv[i]); + if (_argv.back() == "-safe") + safe_mode = true; + } + + _argv.push_back(" "); + + if (check_param("-rogue").has_value()) { + rogue = true; + standard_quake = false; + } + + if (check_param("-hipnotic").has_value() || check_param("-quoth").has_value()) //johnfitz -- "-quoth" support + { + hipnotic = true; + standard_quake = false; + } + } + + std::optional check_param(const std::string_view parm) { + for (auto i = 1; i < _argv.size(); i++) { + if (_argv[i].empty()) { continue; // NEXTSTEP sometimes clears appkit vars. } - if (parm == com_argv[i]) { + if (parm == _argv[i]) { return i; } } @@ -1047,6 +679,21 @@ namespace common { return res; } + + std::partial_ordering strcasecmp(const std::string_view lhs, const std::string_view rhs) { + return std::lexicographical_compare_three_way(lhs.begin(), lhs.end(), rhs.begin(), rhs.end(), + [](const char c, const char d) { + return q_tolower(c) <=> q_tolower(d); + }); + } + + std::partial_ordering strncasecmp(const std::string_view lhs, const std::string_view rhs, const size_t n) { + return std::lexicographical_compare_three_way(lhs.begin(), lhs.begin() + std::min(lhs.size(), n), rhs.begin(), + rhs.begin() + std::min(rhs.size(), n), + [](const char c, const char d) { + return q_tolower(c) <=> q_tolower(d); + }); + } } @@ -1091,67 +738,17 @@ static void COM_CheckRegistered(void) { } } - for (i = 0; com_cmdline[i]; i++) { - if (com_cmdline[i] != ' ') + for (i = 0; common::cmdline[i]; i++) { + if (common::cmdline[i] != ' ') break; } - convar::set_rom("cmdline", &com_cmdline[i]); + convar::set_rom("cmdline", &common::cmdline[i]); convar::set_rom("registered", "1"); console::info("Playing registered version.\n"); } -/* -================ -COM_InitArgv -================ -*/ -void COM_InitArgv(int argc, char **argv) { - int i, j, n; - - // reconstitute the command line for the cmdline externally visible cvar - n = 0; - - for (j = 0; (j < MAX_NUM_ARGVS) && (j < argc); j++) { - i = 0; - - while ((n < (CMDLINE_LENGTH - 1)) && argv[j][i]) { - com_cmdline[n++] = argv[j][i++]; - } - - if (n < (CMDLINE_LENGTH - 1)) - com_cmdline[n++] = ' '; - else - break; - } - - if (n > 0 && com_cmdline[n - 1] == ' ') - com_cmdline[n - 1] = 0; //johnfitz -- kill the trailing space - - console::info("Command line: %s\n", com_cmdline); - - for (com_argc = 0; (com_argc < MAX_NUM_ARGVS) && (com_argc < argc); com_argc++) { - largv[com_argc] = argv[com_argc]; - if (!std::strcmp("-safe", argv[com_argc])) - safemode = 1; - } - - largv[com_argc] = argvdummy; - com_argv = largv; - - if (common::check_param("-rogue").has_value()) { - rogue = true; - standard_quake = false; - } - - if (common::check_param("-hipnotic").has_value() || common::check_param("-quoth").has_value()) //johnfitz -- "-quoth" support - { - hipnotic = true; - standard_quake = false; - } -} - /* ============ va @@ -1242,7 +839,7 @@ COM_WriteFile The filename will be prefixed by the current game directory ============ */ -void COM_WriteFile(const char *filename, const void *data, int len) { +void COM_WriteFile(const char *filename, const void *data, const int len) { int handle; char name[MAX_OSPATH]; @@ -1436,7 +1033,7 @@ COM_CloseFile If it is a pak file handle, don't really close it ============ */ -void COM_CloseFile(int h) { +void COM_CloseFile(const int h) { searchpath_t *s; for (s = com_searchpaths; s; s = s->next) @@ -1466,7 +1063,7 @@ static byte *loadbuf; static cache_user_t *loadcache; static int loadsize; -byte *COM_LoadFile(const char *path, int usehunk, unsigned int *path_id) { +byte *COM_LoadFile(const char *path, const int usehunk, unsigned int *path_id) { int h; byte *buf; char base[32]; @@ -1539,7 +1136,7 @@ void COM_LoadCacheFile(const char *path, struct cache_user_s *cu, unsigned int * } // uses temp hunk if larger than bufsize -byte *COM_LoadStackFile(const char *path, void *buffer, int bufsize, unsigned int *path_id) { +byte *COM_LoadStackFile(const char *path, void *buffer, const int bufsize, unsigned int *path_id) { byte *buf; loadbuf = (byte *) buffer; @@ -1774,7 +1371,7 @@ static void COM_Game_f(void) { console::info("invalid mission pack argument to \"game\"\n"); return; } - if (!q_strcasecmp(p, GAMENAME)) { + if (std::is_eq(common::strcasecmp(p, GAMENAME))) { console::info("no mission pack arguments to %s game\n", GAMENAME); return; } @@ -1788,14 +1385,14 @@ static void COM_Game_f(void) { } } - if (!q_strcasecmp(p, COM_SkipPath(com_gamedir))) //no change + if (std::is_eq(common::strcasecmp(p, COM_SkipPath(com_gamedir)))) //no change { if (com_searchpaths->path_id > 1) { //current game not id1 if (*p2 && com_searchpaths->path_id == 2) { // rely on QuakeSpasm extension treating '-game missionpack' // as '-missionpack', otherwise would be a mess - if (!q_strcasecmp(p, &p2[1])) + if (std::is_eq(common::strcasecmp(p, &p2[1]))) goto _same; console::info("reloading game \"%s\" with \"%s\" support\n", p, &p2[1]); } else if (!*p2 && com_searchpaths->path_id > 2) @@ -1832,7 +1429,7 @@ static void COM_Game_f(void) { rogue = false; standard_quake = true; - if (q_strcasecmp(p, GAMENAME)) //game is not id1 + if (is_neq(common::strcasecmp(p, GAMENAME))) //game is not id1 { if (*p2) { COM_AddGameDirectory(com_basedir, &p2[1]); @@ -1841,15 +1438,15 @@ static void COM_Game_f(void) { hipnotic = true; else if (!strcmp(p2, "-rogue")) rogue = true; - if (q_strcasecmp(p, &p2[1])) //don't load twice + if (is_neq(common::strcasecmp(p, &p2[1]))) //don't load twice COM_AddGameDirectory(com_basedir, p); } else { COM_AddGameDirectory(com_basedir, p); // QuakeSpasm extension: treat '-game missionpack' as '-missionpack' - if (!q_strcasecmp(p, "hipnotic") || !q_strcasecmp(p, "quoth")) { + if (std::is_eq(common::strcasecmp(p, "hipnotic")) || std::is_eq(common::strcasecmp(p, "quoth"))) { hipnotic = true; standard_quake = false; - } else if (!q_strcasecmp(p, "rogue")) { + } else if (std::is_eq(common::strcasecmp(p, "rogue"))) { rogue = true; standard_quake = false; } @@ -1896,10 +1493,9 @@ void COM_InitFilesystem(void) //johnfitz -- modified based on topaz's tutorial command::add("game", COM_Game_f); //johnfitz auto i = common::check_param("-basedir"); - if (i.has_value() && i.value() < com_argc - 1) { - q_strlcpy(com_basedir, com_argv[i.value() + 1], sizeof(com_basedir)); - } - else { + if (i.has_value() && i.value() < common::_argv.size() - 1) { + q_strlcpy(com_basedir, common::_argv[i.value() + 1].c_str(), sizeof(com_basedir)); + } else { q_strlcpy(com_basedir, host_parms->basedir, sizeof(com_basedir)); } @@ -1930,30 +1526,32 @@ void COM_InitFilesystem(void) //johnfitz -- modified based on topaz's tutorial } i = common::check_param("-game"); - if (i.has_value() && i.value() < com_argc - 1) { - const char *p = com_argv[i.value() + 1]; - if (!*p || !strcmp(p, ".") || strstr(p, "..") || strstr(p, "/") || strstr(p, "\\") || strstr(p, ":")) { + if (i.has_value() && i.value() < common::_argv.size() - 1) { + std::optional p = common::_argv[i.value() + 1]; + if (p.value().empty() || p == "." || p->contains("..") || p->contains("/") || p->contains("\\") || p-> + contains(":")) { Sys_Error("gamedir should be a single directory name, not a path\n"); } com_modified = true; // don't load mission packs twice - if (common::check_param("-rogue").has_value() && !q_strcasecmp(p, "rogue")) { - p = nullptr; + if (common::check_param("-rogue").has_value() && std::is_eq(common::strcasecmp(p->c_str(), "rogue"))) { + p = std::nullopt; } - if (p && common::check_param("-hipnotic").has_value() && !q_strcasecmp(p, "hipnotic")) { - p = nullptr; + if (p.has_value() && common::check_param("-hipnotic").has_value() && + std::is_eq(common::strcasecmp(*p, "hipnotic"))) { + p = std::nullopt; } - if (p && common::check_param("-quoth").has_value() && !q_strcasecmp(p, "quoth")) { - p = nullptr; + if (p.has_value() && common::check_param("-quoth").has_value() && std::is_eq(common::strcasecmp(*p, "quoth"))) { + p = std::nullopt; } - if (p != nullptr) { - COM_AddGameDirectory(com_basedir, p); + if (p.has_value()) { + COM_AddGameDirectory(com_basedir, p->c_str()); // QuakeSpasm extension: treat '-game missionpack' as '-missionpack' - if (!q_strcasecmp(p, "rogue")) { + if (std::is_eq(common::strcasecmp(*p, "rogue"))) { rogue = true; standard_quake = false; } - if (!q_strcasecmp(p, "hipnotic") || !q_strcasecmp(p, "quoth")) { + if (std::is_eq(common::strcasecmp(*p, "hipnotic")) || std::is_eq(common::strcasecmp(*p, "quoth"))) { hipnotic = true; standard_quake = false; } @@ -1970,7 +1568,7 @@ void COM_InitFilesystem(void) //johnfitz -- modified based on topaz's tutorial * Allocating and filling in the fshandle_t structure is the users' * responsibility when the file is initially opened. */ -size_t FS_fread(void *ptr, size_t size, size_t nmemb, fshandle_t *fh) { +size_t FS_fread(void *ptr, const size_t size, const size_t nmemb, fshandle_t *fh) { long byte_size; long bytes_read; size_t nmemb_read; @@ -2006,7 +1604,7 @@ size_t FS_fread(void *ptr, size_t size, size_t nmemb, fshandle_t *fh) { return nmemb_read; } -int FS_fseek(fshandle_t *fh, long offset, int whence) { +int FS_fseek(fshandle_t *fh, long offset, const int whence) { /* I don't care about 64 bit off_t or fseeko() here. * the quake/hexen2 file system is 32 bits, anyway. */ int ret; @@ -2159,7 +1757,7 @@ unsigned COM_HashString(const char *str) { return hash; } -static size_t mz_zip_file_read_func(void *opaque, mz_uint64 ofs, void *buf, size_t n) { +static size_t mz_zip_file_read_func(void *opaque, const mz_uint64 ofs, void *buf, const size_t n) { if (SDL_RWseek((SDL_RWops*)opaque, (Sint64)ofs, RW_SEEK_SET) < 0) return 0; #ifdef USE_SDL2 diff --git a/Quake/common.hpp b/Quake/common.hpp index 0efad68..516ede2 100644 --- a/Quake/common.hpp +++ b/Quake/common.hpp @@ -2,6 +2,7 @@ Copyright (C) 1996-2001 Id Software, Inc. Copyright (C) 2002-2009 John Fitzgibbons and others Copyright (C) 2010-2014 QuakeSpasm developers +Copyright (C) 2026 iikorni This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -20,8 +21,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#ifndef _Q_COMMON_H -#define _Q_COMMON_H +#pragma once + +#include + #include "convar.hpp" // comndef.h -- general definitions @@ -40,64 +43,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #endif /* _MSC_VER */ #endif /* _WIN32 */ -#undef min -#undef max - -#if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)) -#define GENERIC_TYPES(x, separator) \ - x(int, i) separator \ - x(unsigned int, u) separator \ - x(long, l) separator \ - x(unsigned long, ul) separator \ - x(long long, ll) separator \ - x(unsigned long long, ull) separator \ - x(float, f) separator \ - x(double, d) - -#define COMMA , -#define NO_COMMA - -#define IMPL_GENERIC_FUNCS(type, suffix) \ -static inline type std::min_##suffix (type a, type b) { \ - return (a < b) ? a : b; \ -} \ -static inline type std::max_##suffix (type a, type b) { \ - return (a > b) ? a : b; \ -} \ -static inline type clamp_##suffix (type minval, type val, type maxval) { \ - return (val < minval) ? minval : ((val > maxval) ? maxval : val); \ -} - -GENERIC_TYPES (IMPL_GENERIC_FUNCS, NO_COMMA) - -#define SELECT_std::min(type, suffix) type: std::min_##suffix -#define std::min(a, b) _Generic((a) + (b), GENERIC_TYPES (SELECT_std::min, COMMA))(a, b) - -#define SELECT_std::max(type, suffix) type: std::max_##suffix -#define std::max(a, b) _Generic((a) + (b), GENERIC_TYPES (SELECT_std::max, COMMA))(a, b) - -#define SELECT_CLAMP(type, suffix) type: clamp_##suffix -#define CLAMP(minval, val, maxval) _Generic((minval) + (val) + (maxval), \ - GENERIC_TYPES (SELECT_CLAMP, COMMA))(minval, val, maxval) -#endif - -// TODO: Maybe some special casing on an std::vector? -typedef struct sizebuf_s -{ - bool allowoverflow; // if false, do a Sys_Error - bool overflowed; // set to true if the buffer size failed - byte *data; - int maxsize; - int cursize; -} sizebuf_t; - -void SZ_Alloc (sizebuf_t *buf, int startsize); -void SZ_Free (sizebuf_t *buf); -void SZ_Clear (sizebuf_t *buf); -void *SZ_GetSpace (sizebuf_t *buf, int length); -void SZ_Write (sizebuf_t *buf, const void *data, int length); -void SZ_Print (sizebuf_t *buf, const char *data); // strcats onto the sizebuf - //============================================================================ typedef struct link_s @@ -118,25 +63,6 @@ void InsertLinkAfter (link_t *l, link_t *after); //============================================================================ -typedef struct vec_header_t { - size_t capacity; - size_t size; -} vec_header_t; - -#define VEC_HEADER(v) (((vec_header_t*)(v))[-1]) - -#define VEC_PUSH(v,n) do { Vec_Grow((void**)&(v), sizeof((v)[0]), 1); (v)[VEC_HEADER(v).size++] = (n); } while (0) -#define VEC_SIZE(v) ((v) ? VEC_HEADER(v).size : 0) -#define VEC_FREE(v) Vec_Free((void**)&(v)) -#define VEC_CLEAR(v) Vec_Clear((void**)&(v)) - -void Vec_Grow (void **pvec, size_t element_size, size_t count); -void Vec_Append (void **pvec, size_t element_size, const void *data, size_t count); -void Vec_Clear (void **pvec); -void Vec_Free (void **pvec); - -//============================================================================ - extern bool host_bigendian; extern short (*BigShort) (short l); @@ -155,8 +81,8 @@ extern float (*LittleFloat) (float l); #include "strl_fn.hpp" /* locale-insensitive strcasecmp replacement functions: */ -extern int q_strcasecmp (const char * s1, const char * s2); -extern int q_strncasecmp (const char *s1, const char *s2, size_t n); +// extern int common::strcasecmp (const char * s1, const char * s2); +// extern int common::strncasecmp (const char *s1, const char *s2, size_t n); /* locale-insensitive case-insensitive alternative to strstr */ extern char *q_strcasestr(const char *haystack, const char *needle); @@ -175,8 +101,18 @@ extern bool com_eof; namespace common { + extern std::vector _argv; + /** + * When \c true, the engine will behave as if each of these arguments were applied to + * the command line: + * -nosound,-nocdaudio, -nomidi, -stdvid, -dibonly, -nomouse, -nojoy, -nolan + */ + extern bool safe_mode; + void init(); + void init_argv(int argc, char **nargv); + std::optional check_param(std::string_view parm); std::optional parse_token(std::istringstream &ss); @@ -184,20 +120,13 @@ namespace common { int parse_int_newline(std::istringstream &ss); float parse_float_newline(std::istringstream &ss); + + std::partial_ordering strcasecmp(std::string_view lhs, std::string_view rhs); + + std::partial_ordering strncasecmp(std::string_view lhs, std::string_view rhs, size_t n); } -extern int com_argc; -extern char **com_argv; - -extern int safemode; -/* safe mode: in true, the engine will behave as if one - of these arguments were actually on the command line: - -nosound, -nocdaudio, -nomidi, -stdvid, -dibonly, - -nomouse, -nojoy, -nolan - */ - -void COM_InitArgv (int argc, char **argv); void COM_InitFilesystem (void); const char *COM_SkipPath (const char *pathname); @@ -329,5 +258,3 @@ extern bool standard_quake, rogue, hipnotic; extern bool fitzmode; /* if true, run in fitzquake mode disabling custom quakespasm hacks */ -#endif /* _Q_COMMON_H */ - diff --git a/Quake/console.cpp b/Quake/console.cpp index 8bf71f7..cba65c6 100644 --- a/Quake/console.cpp +++ b/Quake/console.cpp @@ -269,8 +269,8 @@ namespace console { } void init() { - if (const auto i = common::check_param("-consize"); i.has_value() && i.value() < com_argc - 1) { - con_buffersize = std::atoi(com_argv[i.value() + 1]) * 1024; + if (const auto i = common::check_param("-consize"); i.has_value() && i.value() < common::_argv.size() - 1) { + con_buffersize = std::atoi(common::_argv[i.value() + 1].c_str()) * 1024; if (con_buffersize < CON_MINSIZE) con_buffersize = CON_MINSIZE; } else diff --git a/Quake/gl_model.cpp b/Quake/gl_model.cpp index cd66b06..6ceedc9 100644 --- a/Quake/gl_model.cpp +++ b/Quake/gl_model.cpp @@ -547,7 +547,7 @@ static void Mod_LoadTextures (lump_t *l) //johnfitz -- lots of changes if (!isDedicated) //no texture uploading for dedicated server { - if (!q_strncasecmp(tx->name,"sky",3)) //sky texture //also note -- was Q_strncmp, changed to match qbsp + if (std::is_eq(common::strncasecmp(tx->name,"sky",3))) //sky texture //also note -- was Q_strncmp, changed to match qbsp { if (loadmodel->bspversion == BSPVERSION_QUAKE64) Sky_LoadTextureQ64 (loadmodel, tx); @@ -1306,7 +1306,7 @@ static void Mod_LoadFaces (lump_t *l, bool bsp2) out->samples = loadmodel->lightdata + (lofs * 3); //johnfitz -- lit support via lordhavoc (was "+ i") //johnfitz -- this section rewritten - if (!q_strncasecmp(out->texinfo->texture->name,"sky",3)) // sky surface //also note -- was Q_strncmp, changed to match qbsp + if (std::is_eq(common::strncasecmp(out->texinfo->texture->name,"sky",3))) // sky surface //also note -- was Q_strncmp, changed to match qbsp { out->flags |= (SURF_DRAWSKY | SURF_DRAWTILED); Mod_PolyForUnlitSurface (out); //no more subdivision @@ -2129,7 +2129,7 @@ static FILE *Mod_FindVisibilityExternal(void) fclose(f); return NULL; } - if (!q_strcasecmp(header.mapname, shortname)) + if (std::is_eq(common::strcasecmp(header.mapname, shortname))) break; pos += header.filelen + VISPATCH_HEADER_LEN; fseek(f, pos, SEEK_SET); @@ -2231,7 +2231,7 @@ static void Mod_LoadBrushModel (qmodel_t *mod, void *buffer) Mod_LoadFaces (&header->lumps[LUMP_FACES], bsp2); Mod_LoadMarksurfaces (&header->lumps[LUMP_MARKSURFACES], bsp2); - if (mod->bspversion == BSPVERSION && external_vis.value && sv.modelname[0] && !q_strcasecmp(loadname, sv.name)) + if (mod->bspversion == BSPVERSION && external_vis.value && sv.modelname[0] && std::is_eq(common::strcasecmp(loadname, sv.name))) { FILE* fvis; console::debug("trying to open external vis file\n"); diff --git a/Quake/gl_screen.cpp b/Quake/gl_screen.cpp index 2f1e83f..099acb6 100644 --- a/Quake/gl_screen.cpp +++ b/Quake/gl_screen.cpp @@ -734,9 +734,9 @@ void SCR_ScreenShot_f(void) { if (command::argc() >= 2) { const char *requested_ext = command::argv(1)->c_str(); - if (!q_strcasecmp("png", requested_ext) - || !q_strcasecmp("tga", requested_ext) - || !q_strcasecmp("jpg", requested_ext)) + if (std::is_eq(common::strcasecmp("png", requested_ext)) + || std::is_eq(common::strcasecmp("tga", requested_ext)) + || std::is_eq(common::strcasecmp("jpg", requested_ext))) std::strncpy(ext, requested_ext, sizeof(ext)); else { SCR_ScreenShot_Usage(); @@ -775,11 +775,11 @@ void SCR_ScreenShot_f(void) { glReadPixels(glx, gly, glwidth, glheight, GL_RGB, GL_UNSIGNED_BYTE, buffer); // now write the file - if (!q_strncasecmp(ext, "png", sizeof(ext))) + if (std::is_eq(common::strncasecmp(ext, "png", sizeof(ext)))) ok = Image_WritePNG(imagename, buffer, glwidth, glheight, 24, false); - else if (!q_strncasecmp(ext, "tga", sizeof(ext))) + else if (std::is_eq(common::strncasecmp(ext, "tga", sizeof(ext)))) ok = Image_WriteTGA(imagename, buffer, glwidth, glheight, 24, false); - else if (!q_strncasecmp(ext, "jpg", sizeof(ext))) + else if (std::is_eq(common::strncasecmp(ext, "jpg", sizeof(ext)))) ok = Image_WriteJPG(imagename, buffer, glwidth, glheight, 24, quality, false); else ok = false; diff --git a/Quake/gl_texmgr.cpp b/Quake/gl_texmgr.cpp index 3bbb4a5..51b1092 100644 --- a/Quake/gl_texmgr.cpp +++ b/Quake/gl_texmgr.cpp @@ -132,7 +132,7 @@ static void TexMgr_TextureMode_f(convar *var) { } for (i = 0; i < NUM_GLMODES; i++) { - if (!q_strcasecmp(glmodes[i].name, gl_texturemode.string)) { + if (std::is_eq(common::strcasecmp(glmodes[i].name, gl_texturemode.string))) { gl_texturemode.set(glmodes[i].name); return; } diff --git a/Quake/gl_vidsdl.cpp b/Quake/gl_vidsdl.cpp index 417bf7a..60e3b8f 100644 --- a/Quake/gl_vidsdl.cpp +++ b/Quake/gl_vidsdl.cpp @@ -1612,28 +1612,28 @@ void VID_Init(void) { fullscreen = true; } else { auto p = common::check_param("-width"); - if (p.has_value() && p.value() < com_argc - 1) { - width = std::atoi(com_argv[p.value() + 1]); + if (p.has_value() && p.value() < common::_argv.size() - 1) { + width = std::atoi(common::_argv[p.value() + 1].c_str()); if (!common::check_param("-height").has_value()) height = width * 3 / 4; } p = common::check_param("-height"); - if (p.has_value() && p.value() < com_argc - 1) { - height = std::atoi(com_argv[p.value() + 1]); + if (p.has_value() && p.value() < common::_argv.size() - 1) { + height = std::atoi(common::_argv[p.value() + 1].c_str()); if (!common::check_param("-width").has_value()) width = height * 4 / 3; } p = common::check_param("-refreshrate"); - if (p.has_value() && p.value() < com_argc - 1) - refreshrate = std::atoi(com_argv[p.value() + 1]); + if (p.has_value() && p.value() < common::_argv.size() - 1) + refreshrate = std::atoi(common::_argv[p.value() + 1].c_str()); p = common::check_param("-bpp"); - if (p.has_value() && p.value() < com_argc - 1) - bpp = std::atoi(com_argv[p.value() + 1]); + if (p.has_value() && p.value() < common::_argv.size() - 1) + bpp = std::atoi(common::_argv[p.value() + 1].c_str()); if (common::check_param("-window").has_value() || common::check_param("-w").has_value()) fullscreen = false; @@ -1642,8 +1642,8 @@ void VID_Init(void) { } auto p = common::check_param("-fsaa"); - if (p.has_value() && p.value() < com_argc - 1) - fsaa = atoi(com_argv[p.value() + 1]); + if (p.has_value() && p.value() < common::_argv.size() - 1) + fsaa = atoi(common::_argv[p.value() + 1].c_str()); if (!VID_ValidMode(width, height, refreshrate, bpp, fullscreen)) { width = (int) vid_width.value; diff --git a/Quake/host.cpp b/Quake/host.cpp index c19458f..3563eee 100644 --- a/Quake/host.cpp +++ b/Quake/host.cpp @@ -189,8 +189,8 @@ void Host_FindMaxClients(void) { auto i = common::check_param("-dedicated"); if (i.has_value()) { cls.state = ca_dedicated; - if (i != (com_argc - 1)) { - svs.maxclients = std::atoi(com_argv[i.value() + 1]); + if (i != (common::_argv.size() - 1)) { + svs.maxclients = std::atoi(common::_argv[i.value() + 1].c_str()); } else svs.maxclients = 8; } else @@ -200,8 +200,8 @@ void Host_FindMaxClients(void) { if (i.has_value()) { if (cls.state == ca_dedicated) Sys_Error("Only one of -dedicated or -listen can be specified"); - if (i != (com_argc - 1)) - svs.maxclients = std::atoi(com_argv[i.value() + 1]); + if (i != (common::_argv.size() - 1)) + svs.maxclients = std::atoi(common::_argv[i.value() + 1].c_str()); else svs.maxclients = 8; } @@ -773,8 +773,10 @@ void Host_Init(void) { if (host_parms->memsize < minimum_memory) Sys_Error("Only %4.1f megs of memory available, can't execute game", host_parms->memsize / (float) 0x100000); - com_argc = host_parms->argc; - com_argv = host_parms->argv; + common::_argv.clear(); + for (auto i = 0;i < host_parms->argc;i++) { + common::_argv.emplace_back(host_parms->argv[i]); + } Memory_Init(host_parms->membase, host_parms->memsize); command::buffer::init(); diff --git a/Quake/host_cmd.cpp b/Quake/host_cmd.cpp index efd9684..5451810 100644 --- a/Quake/host_cmd.cpp +++ b/Quake/host_cmd.cpp @@ -72,7 +72,7 @@ static void FileList_Add(const char *name, filelist_item_t **list) { // insert each entry in alphabetical order if (*list == NULL || - q_strcasecmp(item->name, (*list)->name) < 0) //insert at front + is_lt(common::strcasecmp(item->name, (*list)->name))) //insert at front { item->next = *list; *list = item; @@ -80,7 +80,7 @@ static void FileList_Add(const char *name, filelist_item_t **list) { { prev = *list; cursor = (*list)->next; - while (cursor && (q_strcasecmp(item->name, cursor->name) > 0)) { + while (cursor && (is_gt(common::strcasecmp(item->name, cursor->name)))) { prev = cursor; cursor = cursor->next; } @@ -143,7 +143,7 @@ void ExtraMaps_Init(void) { if (dir_p == NULL) continue; while ((dir_t = readdir(dir_p)) != NULL) { - if (q_strcasecmp(COM_FileGetExtension(dir_t->d_name), "bsp") != 0) + if (std::is_neq(common::strcasecmp(COM_FileGetExtension(dir_t->d_name), "bsp"))) continue; COM_StripExtension(dir_t->d_name, mapname, sizeof(mapname)); ExtraMaps_Add(mapname); @@ -244,7 +244,7 @@ void Modlist_Init(void) { while ((dir_t = readdir(dir_p)) != NULL) { if (!strcmp(dir_t->d_name, ".") || !strcmp(dir_t->d_name, "..")) continue; - if (!q_strcasecmp(COM_FileGetExtension(dir_t->d_name), "app")) // skip .app bundles on macOS + if (std::is_eq(common::strcasecmp(COM_FileGetExtension(dir_t->d_name), "app"))) // skip .app bundles on macOS continue; q_snprintf(mod_string, sizeof(mod_string), "%s%s/", dir_string, dir_t->d_name); mod_dir_p = opendir(mod_string); @@ -313,7 +313,7 @@ void DemoList_Init(void) { if (dir_p == NULL) continue; while ((dir_t = readdir(dir_p)) != NULL) { - if (q_strcasecmp(COM_FileGetExtension(dir_t->d_name), "dem") != 0) + if (std::is_neq(common::strcasecmp(COM_FileGetExtension(dir_t->d_name), "dem"))) continue; COM_StripExtension(dir_t->d_name, demname, sizeof(demname)); FileList_Add(demname, &demolist); @@ -1332,7 +1332,7 @@ static void Host_Tell_f(void) { for (j = 0, client = svs.clients; j < svs.maxclients; j++, client++) { if (!client->active || !client->spawned) continue; - if (q_strcasecmp(client->name, command::argv(1)->c_str())) + if (std::is_neq(common::strcasecmp(client->name, command::argv(1)->c_str()))) continue; host_client = client; SV_ClientPrintf("%s", text); @@ -1632,7 +1632,7 @@ static void Host_Kick_f(void) { for (i = 0, host_client = svs.clients; i < svs.maxclients; i++, host_client++) { if (!host_client->active) continue; - if (q_strcasecmp(host_client->name, command::argv(1).value_or("").c_str()) == 0) + if (std::is_eq(common::strcasecmp(host_client->name, command::argv(1).value_or("").c_str()))) break; } } diff --git a/Quake/in_sdl.cpp b/Quake/in_sdl.cpp index c46c4d3..83bc835 100644 --- a/Quake/in_sdl.cpp +++ b/Quake/in_sdl.cpp @@ -331,7 +331,7 @@ void IN_Init(void) { else SDL_StopTextInput(); #endif - if (safemode || common::check_param("-nomouse").has_value()) { + if (common::safe_mode || common::check_param("-nomouse").has_value()) { no_mouse = true; /* discard all mouse events when input is deactivated */ IN_BeginIgnoringMouseEvents(); diff --git a/Quake/keys.cpp b/Quake/keys.cpp index f9ebd87..c65ddc0 100644 --- a/Quake/keys.cpp +++ b/Quake/keys.cpp @@ -535,7 +535,7 @@ int Key_StringToKeynum(const char *str) { return str[0]; for (kn = keynames; kn->name; kn++) { - if (!q_strcasecmp(str, kn->name)) + if (std::is_eq(common::strcasecmp(str, kn->name))) return kn->keynum; } return -1; diff --git a/Quake/main_sdl.cpp b/Quake/main_sdl.cpp index 3c4da51..0b2e568 100644 --- a/Quake/main_sdl.cpp +++ b/Quake/main_sdl.cpp @@ -75,7 +75,7 @@ int main(int argc, char *argv[]) { parms.errstate = 0; - COM_InitArgv(parms.argc, parms.argv); + common::init_argv(parms.argc, parms.argv); isDedicated = (common::check_param("-dedicated").has_value()); @@ -87,8 +87,8 @@ int main(int argc, char *argv[]) { parms.memsize = DEFAULT_MEMORY; if (common::check_param("-heapsize").has_value()) { - if (const auto t = common::check_param("-heapsize").value() + 1; t < com_argc) - parms.memsize = std::atoi(com_argv[t]) * 1024; + if (const auto t = common::check_param("-heapsize").value() + 1; t < common::_argv.size()) + parms.memsize = std::atoi(common::_argv[t].c_str()) * 1024; } parms.membase = malloc(parms.memsize); diff --git a/Quake/net_dgrm.cpp b/Quake/net_dgrm.cpp index 3add1fd..ed2e51c 100644 --- a/Quake/net_dgrm.cpp +++ b/Quake/net_dgrm.cpp @@ -101,7 +101,7 @@ static void NET_Ban_f(void) { break; case 2: - if (q_strcasecmp(command::argv(1)->c_str(), "off") == 0) + if (std::is_eq(common::strcasecmp(command::argv(1)->c_str(), "off"))) banAddr.s_addr = INADDR_ANY; else banAddr.s_addr = inet_addr(command::argv(1)->c_str()); @@ -419,13 +419,13 @@ static void NET_Stats_f(void) { PrintStats(s); } else { for (s = net_activeSockets; s; s = s->next) { - if (q_strcasecmp(command::argv(1)->c_str(), s->address) == 0) + if (std::is_eq(common::strcasecmp(command::argv(1)->c_str(), s->address))) break; } if (s == NULL) { for (s = net_freeSockets; s; s = s->next) { - if (q_strcasecmp(command::argv(1)->c_str(), s->address) == 0) + if (std::is_eq(common::strcasecmp(command::argv(1)->c_str(), s->address))) break; } } @@ -538,7 +538,7 @@ static void Test_f(void) { if (host && hostCacheCount) { for (n = 0; n < hostCacheCount; n++) { - if (q_strcasecmp(host, hostcache[n].name) == 0) { + if (std::is_eq(common::strcasecmp(host, hostcache[n].name))) { if (hostcache[n].driver != myDriverLevel) continue; net_landriverlevel = hostcache[n].ldriver; @@ -670,7 +670,7 @@ static void Test2_f(void) { if (host && hostCacheCount) { for (n = 0; n < hostCacheCount; n++) { - if (q_strcasecmp(host, hostcache[n].name) == 0) { + if (std::is_eq(common::strcasecmp(host, hostcache[n].name))) { if (hostcache[n].driver != myDriverLevel) continue; net_landriverlevel = hostcache[n].ldriver; @@ -729,7 +729,7 @@ int Datagram_Init(void) { command::add("net_stats", NET_Stats_f); - if (safemode || common::check_param("-nolan").has_value()) + if (common::safe_mode || common::check_param("-nolan").has_value()) return -1; num_inited = 0; @@ -1109,7 +1109,7 @@ static void _Datagram_SearchForHosts(bool xmit) { for (i = 0; i < hostCacheCount; i++) { if (i == n) continue; - if (q_strcasecmp(hostcache[n].name, hostcache[i].name) == 0) { + if (std::is_eq(common::strcasecmp(hostcache[n].name, hostcache[i].name))) { i = std::strlen(hostcache[n].name); if (i < 15 && hostcache[n].name[i - 1] > '8') { hostcache[n].name[i] = '0'; diff --git a/Quake/net_main.cpp b/Quake/net_main.cpp index 8d4c422..9b576ea 100644 --- a/Quake/net_main.cpp +++ b/Quake/net_main.cpp @@ -388,14 +388,14 @@ qsocket_t *NET_Connect(const char *host) { host = NULL; if (host) { - if (q_strcasecmp(host, "local") == 0) { + if (std::is_eq(common::strcasecmp(host, "local"))) { numdrivers = 1; goto JustDoIt; } if (hostCacheCount) { for (n = 0; n < hostCacheCount; n++) - if (q_strcasecmp(host, hostcache[n].name) == 0) { + if (std::is_eq(common::strcasecmp(host, hostcache[n].name))) { host = hostcache[n].cname; break; } @@ -419,7 +419,7 @@ qsocket_t *NET_Connect(const char *host) { if (hostCacheCount) { for (n = 0; n < hostCacheCount; n++) { - if (q_strcasecmp(host, hostcache[n].name) == 0) { + if (std::is_eq(common::strcasecmp(host, hostcache[n].name))) { host = hostcache[n].cname; break; } @@ -690,8 +690,8 @@ void NET_Init(void) { port = common::check_param("-ipxport"); if (port.has_value()) { - if (port < com_argc - 1) - DEFAULTnet_hostport = std::atoi(com_argv[port.value() + 1]); + if (port < common::_argv.size() - 1) + DEFAULTnet_hostport = std::atoi(common::_argv[port.value() + 1].c_str()); else Sys_Error("NET_Init: you must specify a number after -port"); } diff --git a/Quake/net_msg.cpp b/Quake/net_msg.cpp index d8a9776..8e5f813 100644 --- a/Quake/net_msg.cpp +++ b/Quake/net_msg.cpp @@ -31,7 +31,7 @@ namespace net { const auto c = read_short(); const auto d = read_byte(); - if (!c.has_value()) { + if (!c.has_value() || !d.has_value()) { return std::nullopt; } @@ -125,7 +125,7 @@ namespace net { return std::nullopt; } - return _data[_offset++]; + return static_cast(_data[_offset++]); } std::optional msg::read_byte() { diff --git a/Quake/net_udp.cpp b/Quake/net_udp.cpp index 9ad12dc..9bc1b7c 100644 --- a/Quake/net_udp.cpp +++ b/Quake/net_udp.cpp @@ -84,12 +84,12 @@ sys_socket_t UDP_Init (void) auto i = common::check_param ("-ip"); if (i.has_value()) { - if (i.value() < com_argc-1) + if (i.value() < common::_argv.size()-1) { - myAddr = inet_addr(com_argv[i.value() + 1]); + myAddr = inet_addr(common::_argv[i.value() + 1].c_str()); if (myAddr == INADDR_NONE) - Sys_Error ("%s is not a valid IP address", com_argv[i.value() + 1]); - strcpy(my_tcpip_address, com_argv[i.value() + 1]); + Sys_Error ("%s is not a valid IP address", common::_argv[i.value() + 1].c_str()); + strcpy(my_tcpip_address, common::_argv[i.value() + 1].c_str()); } else { diff --git a/Quake/net_wins.cpp b/Quake/net_wins.cpp index 70d573f..00888be 100644 --- a/Quake/net_wins.cpp +++ b/Quake/net_wins.cpp @@ -146,7 +146,7 @@ sys_socket_t WINS_Init (void) i = COM_CheckParm ("-ip"); if (i) { - if (i < com_argc-1) + if (i < common::_argv.size()-1) { myAddr = inet_addr(com_argv[i + 1]); if (myAddr == INADDR_NONE) diff --git a/Quake/quakedef.hpp b/Quake/quakedef.hpp index de7ab7f..973e011 100644 --- a/Quake/quakedef.hpp +++ b/Quake/quakedef.hpp @@ -62,7 +62,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define MINIMUM_MEMORY 0x550000 #define MINIMUM_MEMORY_LEVELPAK (MINIMUM_MEMORY + 0x100000) -#define MAX_NUM_ARGVS 50 +constexpr size_t MAX_NUM_ARGVS = 50; // up / down #define PITCH 0 diff --git a/Quake/r_part.cpp b/Quake/r_part.cpp index bf44f83..e5342b3 100644 --- a/Quake/r_part.cpp +++ b/Quake/r_part.cpp @@ -146,8 +146,8 @@ R_InitParticles void R_InitParticles(void) { auto i = common::check_param("-particles"); - if (i.has_value() && i.value() < com_argc - 1) { - r_numparticles = atoi(com_argv[i.value() + 1]); + if (i.has_value() && i.value() < common::_argv.size() - 1) { + r_numparticles = atoi(common::_argv[i.value() + 1].c_str()); if (r_numparticles < ABSOLUTE_MIN_PARTICLES) r_numparticles = ABSOLUTE_MIN_PARTICLES; else if (r_numparticles > ABSOLUTE_MAX_PARTICLES) diff --git a/Quake/snd_codec.cpp b/Quake/snd_codec.cpp index 60996dc..99fe091 100644 --- a/Quake/snd_codec.cpp +++ b/Quake/snd_codec.cpp @@ -169,7 +169,7 @@ snd_stream_t *S_CodecOpenStreamExt (const char *filename, bool loop) codec = codecs; while (codec) { - if (!q_strcasecmp(ext, codec->ext)) + if (std::is_eq(common::strcasecmp(ext, codec->ext))) break; codec = codec->next; } @@ -220,7 +220,7 @@ snd_stream_t *S_CodecOpenStreamAny (const char *filename, bool loop) codec = codecs; while (codec) { - if (!q_strcasecmp(ext, codec->ext)) + if (std::is_eq(common::strcasecmp(ext, codec->ext))) break; codec = codec->next; } diff --git a/Quake/snd_dma.cpp b/Quake/snd_dma.cpp index 4b12f1b..c47dcbf 100644 --- a/Quake/snd_dma.cpp +++ b/Quake/snd_dma.cpp @@ -172,7 +172,7 @@ void S_Init(void) { snd_mixspeed.inscribe(); snd_filterquality.inscribe(); - if (safemode || common::check_param("-nosound").has_value()) + if (common::safe_mode || common::check_param("-nosound").has_value()) return; console::info("\nSound Initialization\n"); @@ -184,13 +184,13 @@ void S_Init(void) { command::add("soundinfo", S_SoundInfo_f); auto i = common::check_param("-sndspeed"); - if (i.has_value() && i.value() < com_argc - 1) { - sndspeed.set(com_argv[i.value() + 1]); + if (i.has_value() && i.value() < common::_argv.size() - 1) { + sndspeed.set(common::_argv[i.value() + 1]); } i = common::check_param("-mixspeed"); - if (i.has_value() && i.value() < com_argc - 1) { - snd_mixspeed.set(com_argv[i.value() + 1]); + if (i.has_value() && i.value() < common::_argv.size() - 1) { + snd_mixspeed.set(common::_argv[i.value() + 1]); } if (host_parms->memsize < 0x800000) { diff --git a/Quake/snd_umx.cpp b/Quake/snd_umx.cpp index 35fb540..f423b09 100644 --- a/Quake/snd_umx.cpp +++ b/Quake/snd_umx.cpp @@ -263,7 +263,7 @@ static int probe_umx (fshandle_t *f, const struct upkg_hdr *hdr, if (read_typname(f, hdr, t, buf) < 0) return -1; for (i = 0; mustype[i] != NULL; i++) { - if (!q_strcasecmp(buf, mustype[i])) { + if (!common::strcasecmp(buf, mustype[i])) { t = i; break; } diff --git a/Quake/sv_main.cpp b/Quake/sv_main.cpp index 858e078..9da91bc 100644 --- a/Quake/sv_main.cpp +++ b/Quake/sv_main.cpp @@ -108,8 +108,8 @@ void SV_Init(void) { for (auto i = 0; i < MAX_MODELS; i++) sprintf(localmodels[i], "*%i", i); - if (const auto i = common::check_param("-protocol"); i && i < com_argc - 1) - sv_protocol = atoi(com_argv[i.value() + 1]); + if (const auto i = common::check_param("-protocol"); i && i < common::_argv.size() - 1) + sv_protocol = atoi(common::_argv[i.value() + 1].c_str()); switch (sv_protocol) { case PROTOCOL_NETQUAKE: p = "NetQuake"; diff --git a/Quake/sv_user.cpp b/Quake/sv_user.cpp index a1dc55e..7a9d283 100644 --- a/Quake/sv_user.cpp +++ b/Quake/sv_user.cpp @@ -499,50 +499,50 @@ bool SV_ReadClientMessage(void) { case clc_stringcmd: { auto s = net_message.read_string().value(); - ret = 0; - if (q_strncasecmp(s.c_str(), "status", 6) == 0) - ret = 1; - else if (q_strncasecmp(s.c_str(), "god", 3) == 0) - ret = 1; - else if (q_strncasecmp(s.c_str(), "notarget", 8) == 0) - ret = 1; - else if (q_strncasecmp(s.c_str(), "fly", 3) == 0) - ret = 1; - else if (q_strncasecmp(s.c_str(), "name", 4) == 0) - ret = 1; - else if (q_strncasecmp(s.c_str(), "noclip", 6) == 0) - ret = 1; - else if (q_strncasecmp(s.c_str(), "setpos", 6) == 0) - ret = 1; - else if (q_strncasecmp(s.c_str(), "say", 3) == 0) - ret = 1; - else if (q_strncasecmp(s.c_str(), "say_team", 8) == 0) - ret = 1; - else if (q_strncasecmp(s.c_str(), "tell", 4) == 0) - ret = 1; - else if (q_strncasecmp(s.c_str(), "color", 5) == 0) - ret = 1; - else if (q_strncasecmp(s.c_str(), "kill", 4) == 0) - ret = 1; - else if (q_strncasecmp(s.c_str(), "pause", 5) == 0) - ret = 1; - else if (q_strncasecmp(s.c_str(), "spawn", 5) == 0) - ret = 1; - else if (q_strncasecmp(s.c_str(), "begin", 5) == 0) - ret = 1; - else if (q_strncasecmp(s.c_str(), "prespawn", 8) == 0) - ret = 1; - else if (q_strncasecmp(s.c_str(), "kick", 4) == 0) - ret = 1; - else if (q_strncasecmp(s.c_str(), "ping", 4) == 0) - ret = 1; - else if (q_strncasecmp(s.c_str(), "give", 4) == 0) - ret = 1; - else if (q_strncasecmp(s.c_str(), "ban", 3) == 0) - ret = 1; + bool ret = false; + if (std::is_eq(common::strncasecmp(s, "status", 6))) + ret = true; + else if (std::is_eq(common::strncasecmp(s, "god", 3))) + ret = true; + else if (std::is_eq(common::strncasecmp(s, "notarget", 8))) + ret = true; + else if (std::is_eq(common::strncasecmp(s, "fly", 3))) + ret = true; + else if (std::is_eq(common::strncasecmp(s, "name", 4))) + ret = true; + else if (std::is_eq(common::strncasecmp(s, "noclip", 6))) + ret = true; + else if (std::is_eq(common::strncasecmp(s, "setpos", 6))) + ret = true; + else if (std::is_eq(common::strncasecmp(s, "say", 3))) + ret = true; + else if (std::is_eq(common::strncasecmp(s, "say_team", 8))) + ret = true; + else if (std::is_eq(common::strncasecmp(s, "tell", 4))) + ret = true; + else if (std::is_eq(common::strncasecmp(s, "color", 5))) + ret = true; + else if (std::is_eq(common::strncasecmp(s, "kill", 4))) + ret = true; + else if (std::is_eq(common::strncasecmp(s, "pause", 5))) + ret = true; + else if (std::is_eq(common::strncasecmp(s, "spawn", 5))) + ret = true; + else if (std::is_eq(common::strncasecmp(s, "begin", 5))) + ret = true; + else if (std::is_eq(common::strncasecmp(s, "prespawn", 8))) + ret = true; + else if (std::is_eq(common::strncasecmp(s, "kick", 4))) + ret = true; + else if (std::is_eq(common::strncasecmp(s, "ping", 4))) + ret = true; + else if (std::is_eq(common::strncasecmp(s, "give", 4))) + ret = true; + else if (std::is_eq(common::strncasecmp(s, "ban", 3))) + ret = true; - if (ret == 1) - command::execute_string(s.c_str(), command::source::client); + if (ret) + command::execute_string(s, command::source::client); else console::debug("%s tried to %s\n", host_client->name, s.c_str()); break; diff --git a/Quake/zone.cpp b/Quake/zone.cpp index 19372a9..1847392 100644 --- a/Quake/zone.cpp +++ b/Quake/zone.cpp @@ -977,8 +977,8 @@ void Memory_Init (void *buf, int size) auto p = common::check_param ("-zone"); if (p.has_value()) { - if (p < com_argc-1) - zonesize = std::atoi (com_argv[p.value()+1]) * 1024; + if (p < common::_argv.size()-1) + zonesize = std::atoi (common::_argv[p.value()+1].c_str()) * 1024; else Sys_Error ("Memory_Init: you must specify a size in KB after -zone"); }