mirror of https://github.com/OpenTTD/OpenTTD
(svn r25488) -Fix [FS#5613]: do not send encoded texts to names, but decode them into a plain C string and then pass them on
parent
8463335b00
commit
19eca468fc
|
@ -38,7 +38,7 @@
|
||||||
EnforcePrecondition(false, ScriptObject::GetCompany() != OWNER_DEITY);
|
EnforcePrecondition(false, ScriptObject::GetCompany() != OWNER_DEITY);
|
||||||
EnforcePrecondition(false, IsValidBaseStation(station_id));
|
EnforcePrecondition(false, IsValidBaseStation(station_id));
|
||||||
EnforcePrecondition(false, name != NULL);
|
EnforcePrecondition(false, name != NULL);
|
||||||
const char *text = name->GetEncodedText();
|
const char *text = name->GetDecodedText();
|
||||||
EnforcePreconditionEncodedText(false, text);
|
EnforcePreconditionEncodedText(false, text);
|
||||||
EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_STATION_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG);
|
EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_STATION_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG);
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,7 @@
|
||||||
CCountedPtr<Text> counter(name);
|
CCountedPtr<Text> counter(name);
|
||||||
|
|
||||||
EnforcePrecondition(false, name != NULL);
|
EnforcePrecondition(false, name != NULL);
|
||||||
const char *text = name->GetEncodedText();
|
const char *text = name->GetDecodedText();
|
||||||
EnforcePreconditionEncodedText(false, text);
|
EnforcePreconditionEncodedText(false, text);
|
||||||
EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_COMPANY_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG);
|
EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_COMPANY_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG);
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@
|
||||||
CCountedPtr<Text> counter(name);
|
CCountedPtr<Text> counter(name);
|
||||||
|
|
||||||
EnforcePrecondition(false, name != NULL);
|
EnforcePrecondition(false, name != NULL);
|
||||||
const char *text = name->GetEncodedText();
|
const char *text = name->GetDecodedText();
|
||||||
EnforcePreconditionEncodedText(false, text);
|
EnforcePreconditionEncodedText(false, text);
|
||||||
EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_PRESIDENT_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG);
|
EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_PRESIDENT_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG);
|
||||||
|
|
||||||
|
|
|
@ -53,7 +53,7 @@
|
||||||
|
|
||||||
EnforcePrecondition(false, IsValidGroup(group_id));
|
EnforcePrecondition(false, IsValidGroup(group_id));
|
||||||
EnforcePrecondition(false, name != NULL);
|
EnforcePrecondition(false, name != NULL);
|
||||||
const char *text = name->GetEncodedText();
|
const char *text = name->GetDecodedText();
|
||||||
EnforcePreconditionEncodedText(false, text);
|
EnforcePreconditionEncodedText(false, text);
|
||||||
EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_GROUP_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG);
|
EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_GROUP_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG);
|
||||||
|
|
||||||
|
|
|
@ -287,6 +287,8 @@ ScriptObject::ActiveInstance::~ActiveInstance()
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assert(StrEmpty(text) || (GetCommandFlags(cmd) & CMD_STR_CTRL) != 0 || StrValid(text, text + strlen(text)));
|
||||||
|
|
||||||
/* Set the default callback to return a true/false result of the DoCommand */
|
/* Set the default callback to return a true/false result of the DoCommand */
|
||||||
if (callback == NULL) callback = &ScriptInstance::DoCommandReturn;
|
if (callback == NULL) callback = &ScriptInstance::DoCommandReturn;
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,7 @@
|
||||||
|
|
||||||
EnforcePrecondition(false, IsValidSign(sign_id));
|
EnforcePrecondition(false, IsValidSign(sign_id));
|
||||||
EnforcePrecondition(false, name != NULL);
|
EnforcePrecondition(false, name != NULL);
|
||||||
const char *text = name->GetEncodedText();
|
const char *text = name->GetDecodedText();
|
||||||
EnforcePreconditionEncodedText(false, text);
|
EnforcePreconditionEncodedText(false, text);
|
||||||
EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_SIGN_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG);
|
EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_SIGN_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG);
|
||||||
|
|
||||||
|
@ -72,7 +72,7 @@
|
||||||
|
|
||||||
EnforcePrecondition(INVALID_SIGN, ::IsValidTile(location));
|
EnforcePrecondition(INVALID_SIGN, ::IsValidTile(location));
|
||||||
EnforcePrecondition(INVALID_SIGN, name != NULL);
|
EnforcePrecondition(INVALID_SIGN, name != NULL);
|
||||||
const char *text = name->GetEncodedText();
|
const char *text = name->GetDecodedText();
|
||||||
EnforcePreconditionEncodedText(INVALID_SIGN, text);
|
EnforcePreconditionEncodedText(INVALID_SIGN, text);
|
||||||
EnforcePreconditionCustomError(INVALID_SIGN, ::Utf8StringLength(text) < MAX_LENGTH_SIGN_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG);
|
EnforcePreconditionCustomError(INVALID_SIGN, ::Utf8StringLength(text) < MAX_LENGTH_SIGN_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG);
|
||||||
|
|
||||||
|
|
|
@ -11,9 +11,12 @@
|
||||||
|
|
||||||
#include "../../stdafx.h"
|
#include "../../stdafx.h"
|
||||||
#include "../../string_func.h"
|
#include "../../string_func.h"
|
||||||
|
#include "../../strings_func.h"
|
||||||
#include "script_text.hpp"
|
#include "script_text.hpp"
|
||||||
#include "../../table/control_codes.h"
|
#include "../../table/control_codes.h"
|
||||||
|
|
||||||
|
#include "table/strings.h"
|
||||||
|
|
||||||
ScriptText::ScriptText(HSQUIRRELVM vm) :
|
ScriptText::ScriptText(HSQUIRRELVM vm) :
|
||||||
ZeroedMemoryAllocator()
|
ZeroedMemoryAllocator()
|
||||||
{
|
{
|
||||||
|
@ -191,3 +194,13 @@ char *ScriptText::_GetEncodedText(char *p, char *lastofp, int ¶m_count)
|
||||||
|
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char *Text::GetDecodedText()
|
||||||
|
{
|
||||||
|
const char *encoded_text = this->GetEncodedText();
|
||||||
|
if (encoded_text == NULL) return NULL;
|
||||||
|
|
||||||
|
static char buf[1024];
|
||||||
|
::SetDParamStr(0, encoded_text);
|
||||||
|
return ::GetString(buf, STR_JUST_RAW_STRING, lastof(buf));
|
||||||
|
}
|
||||||
|
|
|
@ -27,6 +27,13 @@ public:
|
||||||
* @api -all
|
* @api -all
|
||||||
*/
|
*/
|
||||||
virtual const char *GetEncodedText() = 0;
|
virtual const char *GetEncodedText() = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert a #ScriptText into a decoded normal string.
|
||||||
|
* @return A string (in a static buffer), or NULL.
|
||||||
|
* @api -all
|
||||||
|
*/
|
||||||
|
const char *GetDecodedText();
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -43,7 +43,7 @@
|
||||||
CCountedPtr<Text> counter(text);
|
CCountedPtr<Text> counter(text);
|
||||||
|
|
||||||
EnforcePrecondition(false, text != NULL);
|
EnforcePrecondition(false, text != NULL);
|
||||||
const char *encoded_text = text->GetEncodedText();
|
const char *encoded_text = text->GetDecodedText();
|
||||||
EnforcePreconditionEncodedText(false, encoded_text);
|
EnforcePreconditionEncodedText(false, encoded_text);
|
||||||
EnforcePrecondition(false, IsValidTown(town_id));
|
EnforcePrecondition(false, IsValidTown(town_id));
|
||||||
EnforcePreconditionCustomError(false, ::Utf8StringLength(encoded_text) < MAX_LENGTH_TOWN_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG);
|
EnforcePreconditionCustomError(false, ::Utf8StringLength(encoded_text) < MAX_LENGTH_TOWN_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG);
|
||||||
|
|
|
@ -219,7 +219,7 @@
|
||||||
EnforcePrecondition(false, ScriptObject::GetCompany() != OWNER_DEITY);
|
EnforcePrecondition(false, ScriptObject::GetCompany() != OWNER_DEITY);
|
||||||
EnforcePrecondition(false, IsValidVehicle(vehicle_id));
|
EnforcePrecondition(false, IsValidVehicle(vehicle_id));
|
||||||
EnforcePrecondition(false, name != NULL);
|
EnforcePrecondition(false, name != NULL);
|
||||||
const char *text = name->GetEncodedText();
|
const char *text = name->GetDecodedText();
|
||||||
EnforcePreconditionEncodedText(false, text);
|
EnforcePreconditionEncodedText(false, text);
|
||||||
EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_VEHICLE_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG);
|
EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_VEHICLE_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue