Allow messageboxes arguments to have newline characters (bug #3836)

pull/1876/head
Andrei Kortunov 6 years ago
parent dc9aedca7d
commit a560a9e00d

@ -23,6 +23,7 @@
Bug #3591: Angled hit distance too low
Bug #3629: DB assassin attack never triggers creature spawning
Bug #3788: GetPCInJail and GetPCTraveling do not work as in vanilla
Bug #3836: Script fails to compile when command argument contains "\n"
Bug #3876: Landscape texture painting is misaligned
Bug #3897: Have Goodbye give all choices the effects of Goodbye
Bug #3911: [macOS] Typing in the "Content List name" dialog box produces double characters

@ -306,10 +306,22 @@ namespace Compiler
int i = 0;
std::string lowerCase = Misc::StringUtils::lowerCase(name);
bool isKeyword = false;
for (; sKeywords[i]; ++i)
if (lowerCase==sKeywords[i])
{
isKeyword = true;
break;
}
// Russian localization and some mods use a quirk - add newline character directly
// to compiled bytecode via HEX-editor to implement multiline messageboxes.
// Of course, original editor will not compile such script.
// Allow messageboxes to bybass the "incomplete string or name" error.
if (lowerCase == "messagebox")
enableIgnoreNewlines();
else if (isKeyword)
mIgnoreNewline = false;
if (sKeywords[i])
{
@ -357,9 +369,14 @@ namespace Compiler
// }
else if (c=='\n')
{
error = true;
mErrorHandler.error ("incomplete string or name", mLoc);
break;
if (mIgnoreNewline)
mErrorHandler.warning ("string contains newline character, make sure that it is intended", mLoc);
else
{
error = true;
mErrorHandler.error ("incomplete string or name", mLoc);
break;
}
}
}
else if (!(c=='"' && name.empty()))
@ -578,7 +595,7 @@ namespace Compiler
const Extensions *extensions)
: mErrorHandler (errorHandler), mStream (inputStream), mExtensions (extensions),
mPutback (Putback_None), mPutbackCode(0), mPutbackInteger(0), mPutbackFloat(0),
mStrictKeywords (false), mTolerantNames (false)
mStrictKeywords (false), mTolerantNames (false), mIgnoreNewline(false)
{
}
@ -631,6 +648,11 @@ namespace Compiler
mExtensions->listKeywords (keywords);
}
void Scanner::enableIgnoreNewlines()
{
mIgnoreNewline = true;
}
void Scanner::enableStrictKeywords()
{
mStrictKeywords = true;

@ -39,6 +39,7 @@ namespace Compiler
TokenLoc mPutbackLoc;
bool mStrictKeywords;
bool mTolerantNames;
bool mIgnoreNewline;
public:
@ -126,6 +127,11 @@ namespace Compiler
void listKeywords (std::vector<std::string>& keywords);
///< Append all known keywords to \a keywords.
/// Treat newline character as a part of script command.
///
/// \attention This mode lasts only until the next keyword is reached.
void enableIgnoreNewlines();
/// Do not accept keywords in quotation marks anymore.
///
/// \attention This mode lasts only until the next newline is reached.

Loading…
Cancel
Save