Skip to content

Commit

Permalink
DEH Reader|Hacx: Suppress warnings re unsupported [Cheat] patches for…
Browse files Browse the repository at this point in the history
… the Hacx IWAD

Cheat codes in the hacx game mode already use the relevant names, so
we don't need to apply this patch in any case.
  • Loading branch information
danij-deng committed Nov 29, 2014
1 parent f2532f3 commit 1c61b67
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 40 deletions.
16 changes: 8 additions & 8 deletions doomsday/plugins/dehread/include/dehreader.h
@@ -1,8 +1,9 @@
/** @file dehreader.h DeHackEd patch parser.
* @ingroup dehreader
*
* Parses DeHackEd patches and updates the engine's definition databases.
*
* @ingroup dehreader
*
* @authors Copyright © 2013-2014 Daniel Swanson <danij@dengine.net>
* @authors Copyright © 2012-2014 Jaakko Keränen <jaakko.keranen@iki.fi>
*
Expand All @@ -27,9 +28,7 @@
#include "dehread.h"
#include <de/Block>

/**
* Maximum number of nested patch file inclussions. Set to zero to disable.
*/
/// Maximum number of nested patch file inclussions. Set to zero to disable.
#define DEHREADER_INCLUDE_DEPTH_MAX 2

/// Flags used with @see readDehPatch() to alter read behavior.
Expand All @@ -46,9 +45,10 @@ Q_DECLARE_OPERATORS_FOR_FLAGS(DehReaderFlags)
* Parses a text stream as a DeHackEd patch and updates the engine's definition
* databases accordingly.
*
* @param patch DeHackEd patch to parse.
* @param flags @ref DehReaderFlags
* @param patch DeHackEd patch to parse.
* @param patchIsCustom Source of the patch data is a user-supplied add-on
* @param flags @ref DehReaderFlags
*/
void readDehPatch(de::Block const &patch, DehReaderFlags flags = 0);
void readDehPatch(de::Block const &patch, bool patchIsCustom, DehReaderFlags flags = 0);

#endif // LIBDEHREAD_DEHREADER_H
#endif // LIBDEHREAD_DEHREADER_H
27 changes: 16 additions & 11 deletions doomsday/plugins/dehread/src/dehread.cpp
@@ -1,5 +1,4 @@
/** @file dehread.cpp DeHackEd patch reader plugin for Doomsday Engine.
* @ingroup dehread
*
* @authors Copyright © 2013-2014 Daniel Swanson <danij@dengine.net>
* @authors Copyright © 2012-2014 Jaakko Keränen <jaakko.keranen@iki.fi>
Expand All @@ -19,6 +18,8 @@
* 02110-1301 USA</small>
*/

#include "dehread.h"

#include <QDir>
#include <QFile>
#include <doomsday/filesys/lumpindex.h>
Expand All @@ -27,7 +28,6 @@
#include <de/Log>
#include <de/String>

#include "dehread.h"
#include "dehreader.h"

using namespace de;
Expand Down Expand Up @@ -71,32 +71,37 @@ static void readLump(LumpIndex const &lumpIndex, lumpnum_t lumpNum)
deh.append(QChar(0));
lump.unlock();

LOG_RES_MSG("Applying DeHackEd patch lump #%i \"%s:%s\"")
/// @todo Custom status for contained files is not inherited from the container?
bool lumpIsCustom = (lump.isContained()? lump.container().hasCustom() : lump.hasCustom());

LOG_RES_MSG("Applying DeHackEd patch lump #%i \"%s:%s\"%s")
<< lumpNum
<< NativePath(lump.container().composePath()).pretty()
<< lump.name();
<< lump.name()
<< (lumpIsCustom? " (custom)" : "");

readDehPatch(deh, NoInclude | IgnoreEOF);
readDehPatch(deh, lumpIsCustom, NoInclude | IgnoreEOF);
}

static void readFile(String const &filePath)
static void readFile(String const &sourcePath, bool sourceIsCustom = true)
{
QFile file(filePath);
QFile file(sourcePath);
if(!file.open(QFile::ReadOnly | QFile::Text))
{
LOG_AS("DehRead::readFile");
LOG_WARNING("Failed opening \"%s\" for read, aborting...") << QDir::toNativeSeparators(filePath);
LOG_WARNING("Failed opening \"%s\" for read, aborting...") << QDir::toNativeSeparators(sourcePath);
return;
}

/// @todo Do not use a local buffer.
Block deh = file.readAll();
deh.append(QChar(0));

LOG_RES_MSG("Applying DeHackEd patch file \"%s\"")
<< NativePath(filePath).pretty();
LOG_RES_MSG("Applying DeHackEd patch file \"%s\"%s")
<< NativePath(sourcePath).pretty()
<< (sourceIsCustom? " (custom)" : "");

readDehPatch(deh, IgnoreEOF);
readDehPatch(deh, sourceIsCustom, IgnoreEOF);
}

static void readPatchLumps(LumpIndex const &lumpIndex)
Expand Down
45 changes: 24 additions & 21 deletions doomsday/plugins/dehread/src/dehreader.cpp
Expand Up @@ -22,23 +22,24 @@
* 02110-1301 USA</small>
*/

#include "dehread.h"
#include "dehreader.h"

#include <QDebug>
#include <QDir>
#include <QFile>
#include <QRegExp>
#include <QStringList>

#include <de/memory.h>
#include <doomsday/filesys/lumpindex.h>
#include <de/App>
#include <de/Block>
#include <de/Error>
#include <de/Log>
#include <de/String>
#include <de/memory.h>
#include <de/game/Game>

#include "dehreader.h"
#include "dehread.h"
#include "dehreader_util.h"
#include "info.h"

Expand All @@ -58,31 +59,30 @@ class DehReader
{
/// The parser encountered a syntax error in the source file. @ingroup errors
DENG2_ERROR(SyntaxError);

/// The parser encountered an unknown section in the source file. @ingroup errors
DENG2_ERROR(UnknownSection);

/// The parser reached the end of the source file. @ingroup errors
DENG2_ERROR(EndOfFile);

public:
Block const &patch;
int pos;
int currentLineNumber;
bool patchIsCustom = true;

DehReaderFlags flags;
int pos = 0;
int currentLineNumber = 0;

int patchVersion;
int doomVersion;
DehReaderFlags flags = 0;

String line; ///< Current line.
int patchVersion = -1; ///< @c -1= Unknown.
int doomVersion = -1; ///< @c -1= Unknown.

String line; ///< Current line.

public:
DehReader(Block const &_patch, DehReaderFlags _flags = 0)
: patch(_patch)
, pos(0)
, currentLineNumber(0)
, flags(_flags)
, patchVersion(-1) // unknown
, doomVersion(-1) // unknown
, line("")
DehReader(Block const &patch, bool patchIsCustom = true, DehReaderFlags flags = 0)
: patch(patch), patchIsCustom(patchIsCustom), flags(flags)
{
stackDepth++;
}
Expand Down Expand Up @@ -408,7 +408,10 @@ class DehReader
}
else if(line.beginsWith("Cheat", Qt::CaseInsensitive))
{
LOG_WARNING("DeHackEd [Cheat] patches are not supported.");
if(!(!patchIsCustom && App::game().id() == "hacx"))
{
LOG_WARNING("DeHackEd [Cheat] patches are not supported.");
}
skipToNextSection();
}
else if(line.beginsWith("[CODEPTR]", Qt::CaseInsensitive)) // BEX
Expand Down Expand Up @@ -653,7 +656,7 @@ class DehReader

try
{
DehReader(deh, includeFlags).parse();
DehReader(deh, true/*is-custom*/, includeFlags).parse();
}
catch(Error const &er)
{
Expand Down Expand Up @@ -1852,11 +1855,11 @@ class DehReader
}
};

void readDehPatch(Block const &patch, DehReaderFlags flags)
void readDehPatch(Block const &patch, bool patchIsCustom, DehReaderFlags flags)
{
try
{
DehReader(patch, flags).parse();
DehReader(patch, patchIsCustom, flags).parse();
}
catch(Error const &er)
{
Expand Down

0 comments on commit 1c61b67

Please sign in to comment.