Mercurial > hg > openttd
changeset 20528:167b5c60aabf draft
(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
author | rubidium <rubidium@openttd.org> |
---|---|
date | Thu, 27 Jun 2013 19:57:41 +0000 |
parents | 75d239e18307 |
children | b21e6286ba31 |
files | src/script/api/script_basestation.cpp src/script/api/script_company.cpp src/script/api/script_group.cpp src/script/api/script_object.cpp src/script/api/script_sign.cpp src/script/api/script_text.cpp src/script/api/script_text.hpp src/script/api/script_town.cpp src/script/api/script_vehicle.cpp |
diffstat | 9 files changed, 30 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/src/script/api/script_basestation.cpp +++ b/src/script/api/script_basestation.cpp @@ -38,7 +38,7 @@ EnforcePrecondition(false, ScriptObject::GetCompany() != OWNER_DEITY); EnforcePrecondition(false, IsValidBaseStation(station_id)); EnforcePrecondition(false, name != NULL); - const char *text = name->GetEncodedText(); + const char *text = name->GetDecodedText(); EnforcePreconditionEncodedText(false, text); EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_STATION_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG);
--- a/src/script/api/script_company.cpp +++ b/src/script/api/script_company.cpp @@ -43,7 +43,7 @@ CCountedPtr<Text> counter(name); EnforcePrecondition(false, name != NULL); - const char *text = name->GetEncodedText(); + const char *text = name->GetDecodedText(); EnforcePreconditionEncodedText(false, text); EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_COMPANY_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG); @@ -64,7 +64,7 @@ CCountedPtr<Text> counter(name); EnforcePrecondition(false, name != NULL); - const char *text = name->GetEncodedText(); + const char *text = name->GetDecodedText(); EnforcePreconditionEncodedText(false, text); EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_PRESIDENT_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG);
--- a/src/script/api/script_group.cpp +++ b/src/script/api/script_group.cpp @@ -53,7 +53,7 @@ EnforcePrecondition(false, IsValidGroup(group_id)); EnforcePrecondition(false, name != NULL); - const char *text = name->GetEncodedText(); + const char *text = name->GetDecodedText(); EnforcePreconditionEncodedText(false, text); EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_GROUP_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG);
--- a/src/script/api/script_object.cpp +++ b/src/script/api/script_object.cpp @@ -287,6 +287,8 @@ 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 */ if (callback == NULL) callback = &ScriptInstance::DoCommandReturn;
--- a/src/script/api/script_sign.cpp +++ b/src/script/api/script_sign.cpp @@ -37,7 +37,7 @@ EnforcePrecondition(false, IsValidSign(sign_id)); EnforcePrecondition(false, name != NULL); - const char *text = name->GetEncodedText(); + const char *text = name->GetDecodedText(); EnforcePreconditionEncodedText(false, text); 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, name != NULL); - const char *text = name->GetEncodedText(); + const char *text = name->GetDecodedText(); EnforcePreconditionEncodedText(INVALID_SIGN, text); EnforcePreconditionCustomError(INVALID_SIGN, ::Utf8StringLength(text) < MAX_LENGTH_SIGN_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG);
--- a/src/script/api/script_text.cpp +++ b/src/script/api/script_text.cpp @@ -11,9 +11,12 @@ #include "../../stdafx.h" #include "../../string_func.h" +#include "../../strings_func.h" #include "script_text.hpp" #include "../../table/control_codes.h" +#include "table/strings.h" + ScriptText::ScriptText(HSQUIRRELVM vm) : ZeroedMemoryAllocator() { @@ -191,3 +194,13 @@ 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)); +}
--- a/src/script/api/script_text.hpp +++ b/src/script/api/script_text.hpp @@ -27,6 +27,13 @@ * @api -all */ 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(); }; /**
--- a/src/script/api/script_town.cpp +++ b/src/script/api/script_town.cpp @@ -43,7 +43,7 @@ CCountedPtr<Text> counter(text); EnforcePrecondition(false, text != NULL); - const char *encoded_text = text->GetEncodedText(); + const char *encoded_text = text->GetDecodedText(); EnforcePreconditionEncodedText(false, encoded_text); EnforcePrecondition(false, IsValidTown(town_id)); EnforcePreconditionCustomError(false, ::Utf8StringLength(encoded_text) < MAX_LENGTH_TOWN_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG);
--- a/src/script/api/script_vehicle.cpp +++ b/src/script/api/script_vehicle.cpp @@ -219,7 +219,7 @@ EnforcePrecondition(false, ScriptObject::GetCompany() != OWNER_DEITY); EnforcePrecondition(false, IsValidVehicle(vehicle_id)); EnforcePrecondition(false, name != NULL); - const char *text = name->GetEncodedText(); + const char *text = name->GetDecodedText(); EnforcePreconditionEncodedText(false, text); EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_VEHICLE_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG);