From a7dcb7c6e850ab933aa88dae075190088ec981ba Mon Sep 17 00:00:00 2001 From: gez Date: Sat, 12 Jan 2013 14:29:18 +0000 Subject: [PATCH] * Updated to ZDoom 4025: - Do not clear the CF_WEAPONSWITCHOK flag each tic, so that the last setting from A_WeaponReady will carry over until the next A_WeaponReady. Changed P_CheckWeaponSwitch() to clear any pending weapon requests while weapon switching is disabled. - Removed the BuildString() override that took a char** argv, because it was used nowhere. - Fixed: BuildString() failed to properly generate command lines for arguments with embedded " characters. git-svn-id: http://mancubus.net/svn/hosted/gzdoom/trunk@1505 b0f79afe-0144-0410-b225-9a4edf0717df --- src/c_dispatch.cpp | 46 ++++++++++++++++----------------------- src/c_dispatch.h | 1 - src/p_pspr.cpp | 54 +++++++++++++++++++++++++++++++--------------- src/svnrevision.h | 4 ++-- 4 files changed, 57 insertions(+), 48 deletions(-) diff --git a/src/c_dispatch.cpp b/src/c_dispatch.cpp index 83c6ae37..7b701bd5 100644 --- a/src/c_dispatch.cpp +++ b/src/c_dispatch.cpp @@ -1019,32 +1019,7 @@ FConsoleAlias::~FConsoleAlias () m_Command[1] = m_Command[0] = FString(); } -FString BuildString (int argc, char **argv) -{ - if (argc == 1) - { - return *argv; - } - else - { - FString buf; - int arg; - - for (arg = 0; arg < argc; arg++) - { - if (strchr (argv[arg], ' ')) - { - buf.AppendFormat ("\"%s\" ", argv[arg]); - } - else - { - buf.AppendFormat ("%s ", argv[arg]); - } - } - return buf; - } -} - +// Given an argument vector, reconstitute the command line it could have been produced from. FString BuildString (int argc, FString *argv) { if (argc == 1) @@ -1058,8 +1033,23 @@ FString BuildString (int argc, FString *argv) for (arg = 0; arg < argc; arg++) { - if (strchr (argv[arg], ' ')) - { + if (strchr(argv[arg], '"')) + { // If it contains one or more quotes, we need to escape them. + buf << '"'; + long substr_start = 0, quotepos; + while ((quotepos = argv[arg].IndexOf('"', substr_start)) >= 0) + { + if (substr_start < quotepos) + { + buf << argv[arg].Mid(substr_start, quotepos - substr_start); + } + buf << "\\\""; + substr_start = quotepos + 1; + } + buf << argv[arg].Mid(substr_start) << "\" "; + } + else if (strchr(argv[arg], ' ')) + { // If it contains a space, it needs to be quoted. buf << '"' << argv[arg] << "\" "; } else diff --git a/src/c_dispatch.h b/src/c_dispatch.h index 5aa3f987..12ea559d 100644 --- a/src/c_dispatch.h +++ b/src/c_dispatch.h @@ -61,7 +61,6 @@ void C_SetAlias (const char *name, const char *cmd); void C_ClearAliases (); // build a single string out of multiple strings -FString BuildString (int argc, char **argv); FString BuildString (int argc, FString *argv); // Class that can parse command lines diff --git a/src/p_pspr.cpp b/src/p_pspr.cpp index f5a1c45d..5f0943ca 100644 --- a/src/p_pspr.cpp +++ b/src/p_pspr.cpp @@ -95,7 +95,7 @@ void P_SetPsprite (player_t *player, int position, FState *state, bool nofunctio if (position == ps_weapon && !nofunction) { // A_WeaponReady will re-set these as needed - player->cheats &= ~(CF_WEAPONREADY | CF_WEAPONREADYALT | CF_WEAPONBOBBING | CF_WEAPONSWITCHOK | CF_WEAPONRELOADOK | CF_WEAPONZOOMOK); + player->cheats &= ~(CF_WEAPONREADY | CF_WEAPONREADYALT | CF_WEAPONBOBBING | CF_WEAPONRELOADOK | CF_WEAPONZOOMOK); } psp = &player->psprites[position]; @@ -565,12 +565,30 @@ DEFINE_ACTION_FUNCTION_PARAMS(AInventory, A_WeaponReady) ACTION_PARAM_START(1); ACTION_PARAM_INT(paramflags, 0); - if (!(paramflags & WRF_NoSwitch)) DoReadyWeaponToSwitch(self); - if ((paramflags & WRF_NoFire) != WRF_NoFire) DoReadyWeaponToFire(self, - (!(paramflags & WRF_NoPrimary)), (!(paramflags & WRF_NoSecondary))); - if (!(paramflags & WRF_NoBob)) DoReadyWeaponToBob(self); - if ((paramflags & WRF_AllowReload)) DoReadyWeaponToReload(self); - if ((paramflags & WRF_AllowZoom)) DoReadyWeaponToZoom(self); + if (!(paramflags & WRF_NoSwitch)) + { + DoReadyWeaponToSwitch(self); + } + else if (self->player != NULL) + { + self->player->cheats &= ~CF_WEAPONSWITCHOK; + } + if ((paramflags & WRF_NoFire) != WRF_NoFire) + { + DoReadyWeaponToFire(self, !(paramflags & WRF_NoPrimary), !(paramflags & WRF_NoSecondary)); + } + if (!(paramflags & WRF_NoBob)) + { + DoReadyWeaponToBob(self); + } + if ((paramflags & WRF_AllowReload)) + { + DoReadyWeaponToReload(self); + } + if ((paramflags & WRF_AllowZoom)) + { + DoReadyWeaponToZoom(self); + } } //--------------------------------------------------------------------------- @@ -631,15 +649,20 @@ void P_CheckWeaponSwitch (player_t *player) if (!player || !(weapon = player->ReadyWeapon)) return; - // Put the weapon away if the player has a pending weapon or has died. - if ((player->morphTics == 0 && player->PendingWeapon != WP_NOCHANGE) || player->health <= 0) - { + if (player->health <= 0) + { // Dead, so put the weapon away. + P_SetPsprite(player, ps_weapon, weapon->GetDownState()); + } + else if (!(player->cheats & CF_WEAPONSWITCHOK)) + { // Weapon changing has been disabled. + player->PendingWeapon = WP_NOCHANGE; + } + else if (player->morphTics == 0 && player->PendingWeapon != WP_NOCHANGE) + { // Put the weapon away if the player has a pending weapon P_SetPsprite (player, ps_weapon, weapon->GetDownState()); - return; } else if (player->morphTics != 0) - { - // morphed classes cannot change weapons so don't even try again. + { // Morphed classes cannot change weapons, so don't even try again. player->PendingWeapon = WP_NOCHANGE; } } @@ -1052,10 +1075,7 @@ void P_MovePsprites (player_t *player) } player->psprites[ps_flash].sx = player->psprites[ps_weapon].sx; player->psprites[ps_flash].sy = player->psprites[ps_weapon].sy; - if (player->cheats & CF_WEAPONSWITCHOK) - { - P_CheckWeaponSwitch (player); - } + P_CheckWeaponSwitch (player); if (player->cheats & (CF_WEAPONREADY | CF_WEAPONREADYALT)) { P_CheckWeaponFire (player); diff --git a/src/svnrevision.h b/src/svnrevision.h index 831b50d1..1fcdb01d 100644 --- a/src/svnrevision.h +++ b/src/svnrevision.h @@ -3,5 +3,5 @@ // This file was automatically generated by the // updaterevision tool. Do not edit by hand. -#define ZD_SVN_REVISION_STRING "4023" -#define ZD_SVN_REVISION_NUMBER 4023 +#define ZD_SVN_REVISION_STRING "4025" +#define ZD_SVN_REVISION_NUMBER 4025