From a5b417fca1bf5f3ad9383c073969d572add3909c Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Sat, 2 Oct 2021 01:04:26 +0100 Subject: [PATCH] dont let llInsertString break a surrogate pair --- .../Shared/Api/Implementation/LSL_Api.cs | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index fad67a481a..5543f641c6 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs @@ -1211,7 +1211,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api if (text.Length > 1023) text = text.Substring(0, 1023); - byte[] binText = Util.StringToBytesNoTerm(text, 1023); + byte[] binText = Utils.StringToBytesNoTerm(text, 1023); World.SimChat(binText, ChatTypeEnum.Whisper, channelID, m_host.AbsolutePosition, m_host.Name, m_host.UUID, false); @@ -1248,7 +1248,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api } else { - byte[] binText = Util.StringToBytesNoTerm(text, 1023); + byte[] binText = Utils.StringToBytesNoTerm(text, 1023); World.SimChat(binText, ChatTypeEnum.Say, channelID, m_host.AbsolutePosition, m_host.Name, m_host.UUID, false); @@ -1268,7 +1268,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api if (m_SayShoutCount >= 11) ScriptSleep(2000); - byte[] binText = Util.StringToBytesNoTerm(text, 1023); + byte[] binText = Utils.StringToBytesNoTerm(text, 1023); World.SimChat(binText, ChatTypeEnum.Shout, channelID, m_host.AbsolutePosition, m_host.Name, m_host.UUID, true); @@ -1286,8 +1286,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api return; } - byte[] binText = Util.StringToBytesNoTerm(text, 1023); - + byte[] binText = Utils.StringToBytesNoTerm(text, 1023); // debug channel is also sent to avatars if (channelID == ScriptBaseClass.DEBUG_CHANNEL) @@ -3392,6 +3391,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api /// which case it is end-relative. The index may exceed either /// string bound, with the result being a concatenation. /// + // this is actually wrong. acording to SL wiki, this function should not support negative indexes. public LSL_String llInsertString(string dest, int index, string src) { @@ -3400,12 +3400,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api // negative, but that is now relative to // the start, rather than the end, of the // sequence. + char c; if (index < 0) { index = dest.Length+index; // Negative now means it is less than the lower // bound of the string. + if(index > 0) + { + c = dest[index]; + if (c >= 0xDC00 && c <= 0xDFFF) + --index; + } if (index < 0) { @@ -3413,6 +3420,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api } } + else + { + c = dest[index]; + if (c >= 0xDC00 && c <= 0xDFFF) + ++index; + } if (index >= dest.Length) { @@ -4181,7 +4194,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api public void llStartObjectAnimation(string anim) { - // Do NOT try to parse UUID, animations cannot be triggered by ID UUID animID = ScriptUtils.GetAssetIdFromItemName(m_host, anim, (int)AssetType.Animation); if (animID == UUID.Zero) @@ -12701,7 +12713,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api public void llOwnerSay(string msg) { - World.SimChatBroadcast(Utils.StringToBytes(msg), ChatTypeEnum.Owner, 0, m_host.AbsolutePosition, m_host.Name, m_host.UUID, false); // IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface();