SceneObjectSerializer.cs 84 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSimulator Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System;
  28. using System.Collections.Generic;
  29. using System.Collections.Frozen;
  30. using System.Drawing;
  31. using System.IO;
  32. using System.Reflection;
  33. using System.Xml;
  34. using log4net;
  35. using OpenMetaverse;
  36. using OpenSim.Framework;
  37. using OpenSim.Framework.Serialization.External;
  38. namespace OpenSim.Region.Framework.Scenes.Serialization
  39. {
  40. /// <summary>
  41. /// Serialize and deserialize scene objects.
  42. /// </summary>
  43. /// This should really be in OpenSim.Framework.Serialization but this would mean circular dependency problems
  44. /// right now - hopefully this isn't forever.
  45. public class SceneObjectSerializer
  46. {
  47. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  48. private static IUserManagement m_UserManagement;
  49. /// <summary>
  50. /// Deserialize a scene object from the original xml format
  51. /// </summary>
  52. /// <param name="xmlData"></param>
  53. /// <returns>The scene object deserialized. Null on failure.</returns>
  54. public static SceneObjectGroup FromOriginalXmlFormat(string xmlData)
  55. {
  56. string fixedData = ExternalRepresentationUtils.SanitizeXml(xmlData);
  57. using (XmlTextReader wrappedReader = new(fixedData, XmlNodeType.Element, null))
  58. {
  59. using (XmlReader reader = XmlReader.Create(wrappedReader, Util.SharedXmlReaderSettings))
  60. {
  61. try
  62. {
  63. return FromOriginalXmlFormat(reader);
  64. }
  65. catch (Exception e)
  66. {
  67. m_log.Error("[SERIALIZER]: Deserialization of xml failed ", e);
  68. Util.LogFailedXML("[SERIALIZER]:", fixedData);
  69. return null;
  70. }
  71. }
  72. }
  73. }
  74. /*
  75. public static SceneObjectGroup FromOriginalXmlData(byte[] data)
  76. {
  77. int len = data.Length;
  78. if(len < 32)
  79. return null;
  80. if(data[len -1 ] == 0)
  81. --len;
  82. XmlReaderSettings xset = new XmlReaderSettings() { IgnoreWhitespace = true, ConformanceLevel = ConformanceLevel.Fragment, CloseInput = true };
  83. XmlParserContext xpc = new XmlParserContext(null, null, null, XmlSpace.None);
  84. xpc.Encoding = Util.UTF8NoBomEncoding;
  85. MemoryStream ms = new MemoryStream(data, 0, len, false);
  86. using (XmlReader reader = XmlReader.Create(ms, xset, xpc))
  87. {
  88. try
  89. {
  90. return FromOriginalXmlFormat(reader);
  91. }
  92. catch (Exception e)
  93. {
  94. m_log.Error("[SERIALIZER]: Deserialization of xml data failed ", e);
  95. return null;
  96. }
  97. }
  98. }
  99. */
  100. /// <summary>
  101. /// Deserialize a scene object from the original xml format
  102. /// </summary>
  103. /// <param name="xmlData"></param>
  104. /// <returns>The scene object deserialized. Null on failure.</returns>
  105. public static SceneObjectGroup FromOriginalXmlFormat(XmlReader reader)
  106. {
  107. //m_log.DebugFormat("[SOG]: Starting deserialization of SOG");
  108. //int time = System.Environment.TickCount;
  109. int linkNum;
  110. reader.ReadToFollowing("RootPart");
  111. reader.ReadToFollowing("SceneObjectPart");
  112. SceneObjectGroup sceneObject = new(SceneObjectPart.FromXml(reader));
  113. reader.ReadToFollowing("OtherParts");
  114. if (reader.ReadToDescendant("Part"))
  115. {
  116. do
  117. {
  118. if (reader.ReadToDescendant("SceneObjectPart"))
  119. {
  120. SceneObjectPart part = SceneObjectPart.FromXml(reader);
  121. linkNum = part.LinkNum;
  122. sceneObject.AddPart(part);
  123. part.LinkNum = linkNum;
  124. part.TrimPermissions();
  125. }
  126. }
  127. while (reader.ReadToNextSibling("Part"));
  128. reader.ReadEndElement();
  129. }
  130. else
  131. reader.Read();
  132. if (reader.Name == "KeyframeMotion" && reader.NodeType == XmlNodeType.Element)
  133. {
  134. string innerkeytxt = reader.ReadElementContentAsString();
  135. sceneObject.RootPart.KeyframeMotion = KeyframeMotion.FromData(sceneObject, Convert.FromBase64String(innerkeytxt));
  136. }
  137. if (reader.Name == "lnkstdt" && reader.NodeType == XmlNodeType.Element)
  138. {
  139. string innerlnkstdttxt = reader.ReadElementContentAsString();
  140. sceneObject.LinksetData = LinksetData.FromXML(innerlnkstdttxt.AsSpan());
  141. }
  142. if (reader.Name == "StartStr" && reader.NodeType == XmlNodeType.Element)
  143. {
  144. sceneObject.RezStringParameter = reader.ReadElementContentAsString();
  145. }
  146. // Script state may, or may not, exist. Not having any, is NOT
  147. // ever a problem.
  148. sceneObject.LoadScriptState(reader);
  149. sceneObject.InvalidateDeepEffectivePerms();
  150. return sceneObject;
  151. }
  152. /// <summary>
  153. /// Serialize a scene object to the original xml format
  154. /// </summary>
  155. /// <param name="sceneObject"></param>
  156. /// <returns></returns>
  157. public static string ToOriginalXmlFormat(SceneObjectGroup sceneObject)
  158. {
  159. return ToOriginalXmlFormat(sceneObject, true);
  160. }
  161. /// <summary>
  162. /// Serialize a scene object to the original xml format
  163. /// </summary>
  164. /// <param name="sceneObject"></param>
  165. /// <param name="doScriptStates">Control whether script states are also serialized.</para>
  166. /// <returns></returns>
  167. public static string ToOriginalXmlFormat(SceneObjectGroup sceneObject, bool doScriptStates)
  168. {
  169. using (StringWriter sw = new())
  170. {
  171. using (XmlTextWriter writer = new(sw))
  172. {
  173. ToOriginalXmlFormat(sceneObject, writer, doScriptStates);
  174. }
  175. return sw.ToString();
  176. }
  177. }
  178. /// <summary>
  179. /// Serialize a scene object to the original xml format
  180. /// </summary>
  181. /// <param name="sceneObject"></param>
  182. /// <returns></returns>
  183. public static void ToOriginalXmlFormat(SceneObjectGroup sceneObject, XmlTextWriter writer, bool doScriptStates)
  184. {
  185. ToOriginalXmlFormat(sceneObject, writer, doScriptStates, false);
  186. }
  187. public static string ToOriginalXmlFormat(SceneObjectGroup sceneObject, string scriptedState)
  188. {
  189. using (StringWriter sw = new())
  190. {
  191. using (XmlTextWriter writer = new(sw))
  192. {
  193. writer.WriteStartElement(string.Empty, "SceneObjectGroup", string.Empty);
  194. ToOriginalXmlFormat(sceneObject, writer, false, true);
  195. writer.WriteRaw(scriptedState);
  196. writer.WriteEndElement();
  197. }
  198. return sw.ToString();
  199. }
  200. }
  201. /// <summary>
  202. /// Serialize a scene object to the original xml format
  203. /// </summary>
  204. /// <param name="sceneObject"></param>
  205. /// <param name="writer"></param>
  206. /// <param name="noRootElement">If false, don't write the enclosing SceneObjectGroup element</param>
  207. /// <returns></returns>
  208. public static void ToOriginalXmlFormat(
  209. SceneObjectGroup sceneObject, XmlTextWriter writer, bool doScriptStates, bool noRootElement)
  210. {
  211. //m_log.DebugFormat("[SERIALIZER]: Starting serialization of {0}", sceneObject.Name);
  212. //int time = System.Environment.TickCount;
  213. if (!noRootElement)
  214. writer.WriteStartElement(string.Empty, "SceneObjectGroup", string.Empty);
  215. writer.WriteStartElement(string.Empty, "RootPart", string.Empty);
  216. ToXmlFormat(sceneObject.RootPart, writer);
  217. writer.WriteEndElement();
  218. writer.WriteStartElement(string.Empty, "OtherParts", string.Empty);
  219. SceneObjectPart[] parts = sceneObject.Parts;
  220. for (int i = 0; i < parts.Length; i++)
  221. {
  222. SceneObjectPart part = parts[i];
  223. if (part.UUID != sceneObject.RootPart.UUID)
  224. {
  225. writer.WriteStartElement(string.Empty, "Part", string.Empty);
  226. ToXmlFormat(part, writer);
  227. writer.WriteEndElement();
  228. }
  229. }
  230. writer.WriteEndElement(); // OtherParts
  231. if (sceneObject.RootPart.KeyframeMotion != null)
  232. {
  233. byte[] data = sceneObject.RootPart.KeyframeMotion.Serialize();
  234. writer.WriteStartElement(string.Empty, "KeyframeMotion", string.Empty);
  235. writer.WriteBase64(data, 0, data.Length);
  236. writer.WriteEndElement();
  237. }
  238. if(sceneObject.RezStringParameter is not null)
  239. writer.WriteElementString("StartStr", sceneObject.RezStringParameter);
  240. sceneObject.LinksetData?.ToXML(writer);
  241. if (doScriptStates)
  242. sceneObject.SaveScriptedState(writer);
  243. if (!noRootElement)
  244. writer.WriteEndElement(); // SceneObjectGroup
  245. //m_log.DebugFormat("[SERIALIZER]: Finished serialization of SOG {0}, {1}ms", sceneObject.Name, System.Environment.TickCount - time);
  246. }
  247. protected static void ToXmlFormat(SceneObjectPart part, XmlTextWriter writer)
  248. {
  249. SOPToXml2(writer, part, new Dictionary<string, object>());
  250. }
  251. public static SceneObjectGroup FromXml2Format(string xmlData)
  252. {
  253. //m_log.DebugFormat("[SOG]: Starting deserialization of SOG");
  254. //int time = System.Environment.TickCount;
  255. try
  256. {
  257. XmlDocument doc = new();
  258. doc.LoadXml(xmlData);
  259. XmlNodeList parts = doc.GetElementsByTagName("SceneObjectPart");
  260. if (parts.Count == 0)
  261. {
  262. m_log.Error("[SERIALIZER]: Deserialization of xml failed: No SceneObjectPart nodes");
  263. Util.LogFailedXML("[SERIALIZER]:", xmlData);
  264. return null;
  265. }
  266. SceneObjectGroup sceneObject;
  267. using(StringReader sr = new(parts[0].OuterXml))
  268. {
  269. using(XmlTextReader reader = new(sr))
  270. {
  271. reader.DtdProcessing = DtdProcessing.Ignore;
  272. sceneObject = new SceneObjectGroup(SceneObjectPart.FromXml(reader));
  273. }
  274. }
  275. // Then deal with the rest
  276. SceneObjectPart part;
  277. for (int i = 1; i < parts.Count; i++)
  278. {
  279. using(StringReader sr = new(parts[i].OuterXml))
  280. {
  281. using(XmlTextReader reader = new(sr))
  282. {
  283. reader.DtdProcessing = DtdProcessing.Ignore;
  284. part = SceneObjectPart.FromXml(reader);
  285. }
  286. }
  287. int originalLinkNum = part.LinkNum;
  288. sceneObject.AddPart(part);
  289. // SceneObjectGroup.AddPart() tries to be smart and automatically set the LinkNum.
  290. // We override that here
  291. if (originalLinkNum != 0)
  292. part.LinkNum = originalLinkNum;
  293. }
  294. XmlNodeList keymotion = doc.GetElementsByTagName("KeyframeMotion");
  295. if (keymotion.Count > 0)
  296. sceneObject.RootPart.KeyframeMotion = KeyframeMotion.FromData(sceneObject, Convert.FromBase64String(keymotion[0].InnerText));
  297. XmlNodeList keylinksetdata = doc.GetElementsByTagName("lnkstdt");
  298. if (keylinksetdata.Count > 0)
  299. sceneObject.LinksetData = LinksetData.FromXML(keylinksetdata[0].InnerText.AsSpan());
  300. XmlNodeList StartStr = doc.GetElementsByTagName("StartStr");
  301. if (StartStr.Count > 0)
  302. sceneObject.RezStringParameter = StartStr[0].InnerText;
  303. // Script state may, or may not, exist. Not having any, is NOT
  304. // ever a problem.
  305. sceneObject.LoadScriptState(doc);
  306. //sceneObject.AggregatePerms();
  307. return sceneObject;
  308. }
  309. catch (Exception e)
  310. {
  311. m_log.Error("[SERIALIZER]: Deserialization of xml failed ", e);
  312. Util.LogFailedXML("[SERIALIZER]:", xmlData);
  313. return null;
  314. }
  315. }
  316. /// <summary>
  317. /// Serialize a scene object to the 'xml2' format.
  318. /// </summary>
  319. /// <param name="sceneObject"></param>
  320. /// <returns></returns>
  321. public static string ToXml2Format(SceneObjectGroup sceneObject)
  322. {
  323. using (StringWriter sw = new())
  324. {
  325. using (XmlTextWriter writer = new(sw))
  326. {
  327. SOGToXml2(writer, sceneObject, new Dictionary<string,object>());
  328. }
  329. return sw.ToString();
  330. }
  331. }
  332. /// <summary>
  333. /// Modifies a SceneObjectGroup.
  334. /// </summary>
  335. /// <param name="sog">The object</param>
  336. /// <returns>Whether the object was actually modified</returns>
  337. public delegate bool SceneObjectModifier(SceneObjectGroup sog);
  338. /// <summary>
  339. /// Modifies an object by deserializing it; applying 'modifier' to each SceneObjectGroup; and reserializing.
  340. /// </summary>
  341. /// <param name="assetId">The object's UUID</param>
  342. /// <param name="data">Serialized data</param>
  343. /// <param name="modifier">The function to run on each SceneObjectGroup</param>
  344. /// <returns>The new serialized object's data, or null if an error occurred</returns>
  345. public static byte[] ModifySerializedObject(UUID assetId, byte[] data, SceneObjectModifier modifier)
  346. {
  347. List<SceneObjectGroup> sceneObjects = new();
  348. string xmlData = ExternalRepresentationUtils.SanitizeXml(Utils.BytesToString(data));
  349. if (CoalescedSceneObjectsSerializer.TryFromXml(xmlData, out CoalescedSceneObjects coa))
  350. {
  351. // m_log.DebugFormat("[SERIALIZER]: Loaded coalescence {0} has {1} objects", assetId, coa.Count);
  352. if (coa.Objects.Count == 0)
  353. {
  354. m_log.WarnFormat("[SERIALIZER]: Aborting load of coalesced object from asset {0} as it has zero loaded components", assetId);
  355. return null;
  356. }
  357. sceneObjects.AddRange(coa.Objects);
  358. }
  359. else
  360. {
  361. SceneObjectGroup deserializedObject = FromOriginalXmlFormat(xmlData);
  362. if (deserializedObject is not null)
  363. {
  364. sceneObjects.Add(deserializedObject);
  365. }
  366. else
  367. {
  368. m_log.WarnFormat("[SERIALIZER]: Aborting load of object from asset {0} as deserialization failed", assetId);
  369. return null;
  370. }
  371. }
  372. bool modified = false;
  373. foreach (SceneObjectGroup sog in sceneObjects)
  374. {
  375. if (modifier(sog))
  376. modified = true;
  377. }
  378. if (modified)
  379. {
  380. if (coa is not null)
  381. data = Utils.StringToBytes(CoalescedSceneObjectsSerializer.ToXml(coa));
  382. else
  383. data = Utils.StringToBytes(ToOriginalXmlFormat(sceneObjects[0]));
  384. }
  385. return data;
  386. }
  387. #region manual serialization
  388. private static readonly FrozenDictionary<string, Action<SceneObjectPart, XmlReader>> m_SOPXmlProcessors = new Dictionary<string, Action<SceneObjectPart, XmlReader>>()
  389. {
  390. {"AllowedDrop", ProcessAllowedDrop },
  391. {"CreatorID", ProcessCreatorID },
  392. {"CreatorData", ProcessCreatorData },
  393. {"FolderID", ProcessFolderID },
  394. {"InventorySerial", ProcessInventorySerial },
  395. {"TaskInventory", ProcessTaskInventory },
  396. {"UUID", ProcessUUID },
  397. {"LocalId", ProcessLocalId },
  398. {"Name", ProcessName },
  399. {"Material", ProcessMaterial },
  400. {"PassTouches", ProcessPassTouches },
  401. {"PassCollisions", ProcessPassCollisions },
  402. {"RegionHandle", ProcessRegionHandle },
  403. {"ScriptAccessPin", ProcessScriptAccessPin },
  404. {"GroupPosition", ProcessGroupPosition },
  405. {"OffsetPosition", ProcessOffsetPosition },
  406. {"RotationOffset", ProcessRotationOffset },
  407. {"Velocity", ProcessVelocity },
  408. {"AngularVelocity", ProcessAngularVelocity },
  409. {"Acceleration", ProcessAcceleration },
  410. {"Description", ProcessDescription },
  411. {"Color", ProcessColor },
  412. {"Text", ProcessText },
  413. {"SitName", ProcessSitName },
  414. {"TouchName", ProcessTouchName },
  415. {"LinkNum", ProcessLinkNum },
  416. {"ClickAction", ProcessClickAction },
  417. {"Shape", ProcessShape },
  418. {"Scale", ProcessScale },
  419. {"SitTargetOrientation", ProcessSitTargetOrientation },
  420. {"SitTargetPosition", ProcessSitTargetPosition },
  421. {"SitTargetPositionLL", ProcessSitTargetPositionLL },
  422. {"SitTargetOrientationLL", ProcessSitTargetOrientationLL },
  423. {"StandTarget", ProcessStandTarget },
  424. {"ParentID", ProcessParentID },
  425. {"CreationDate", ProcessCreationDate },
  426. {"Category", ProcessCategory },
  427. {"SalePrice", ProcessSalePrice },
  428. {"ObjectSaleType", ProcessObjectSaleType },
  429. {"OwnershipCost", ProcessOwnershipCost },
  430. {"GroupID", ProcessGroupID },
  431. {"OwnerID", ProcessOwnerID },
  432. {"LastOwnerID", ProcessLastOwnerID },
  433. {"RezzerID", ProcessRezzerID },
  434. {"BaseMask", ProcessBaseMask },
  435. {"OwnerMask", ProcessOwnerMask },
  436. {"GroupMask", ProcessGroupMask },
  437. {"EveryoneMask", ProcessEveryoneMask },
  438. {"NextOwnerMask", ProcessNextOwnerMask },
  439. {"Flags", ProcessFlags },
  440. {"CollisionSound", ProcessCollisionSound },
  441. {"CollisionSoundVolume", ProcessCollisionSoundVolume },
  442. {"MediaUrl", ProcessMediaUrl },
  443. {"AttachedPos", ProcessAttachedPos },
  444. {"DynAttrs", ProcessDynAttrs },
  445. {"TextureAnimation", ProcessTextureAnimation },
  446. {"ParticleSystem", ProcessParticleSystem },
  447. {"PayPrice0", ProcessPayPrice0 },
  448. {"PayPrice1", ProcessPayPrice1 },
  449. {"PayPrice2", ProcessPayPrice2 },
  450. {"PayPrice3", ProcessPayPrice3 },
  451. {"PayPrice4", ProcessPayPrice4 },
  452. {"Buoyancy", ProcessBuoyancy },
  453. {"Force", ProcessForce },
  454. {"Torque", ProcessTorque },
  455. {"VolumeDetectActive", ProcessVolumeDetectActive },
  456. {"Vehicle", ProcessVehicle },
  457. {"PhysicsInertia", ProcessPhysicsInertia },
  458. {"RotationAxisLocks", ProcessRotationAxisLocks },
  459. {"PhysicsShapeType", ProcessPhysicsShapeType },
  460. {"Density", ProcessDensity },
  461. {"Friction", ProcessFriction },
  462. {"Bounce", ProcessBounce },
  463. {"GravityModifier", ProcessGravityModifier },
  464. {"CameraEyeOffset", ProcessCameraEyeOffset },
  465. {"CameraAtOffset", ProcessCameraAtOffset },
  466. {"SoundID", ProcessSoundID },
  467. {"SoundGain", ProcessSoundGain },
  468. {"SoundFlags", ProcessSoundFlags },
  469. {"SoundRadius", ProcessSoundRadius },
  470. {"SoundQueueing", ProcessSoundQueueing },
  471. {"SOPAnims", ProcessSOPAnims },
  472. {"SitActRange", ProcessSitActRange }
  473. }.ToFrozenDictionary();
  474. private static readonly FrozenDictionary<string, Action<TaskInventoryItem, XmlReader>> m_TaskInventoryXmlProcessors = new Dictionary<string, Action<TaskInventoryItem, XmlReader>>()
  475. {
  476. {"AssetID", ProcessTIAssetID },
  477. {"BasePermissions", ProcessTIBasePermissions },
  478. {"CreationDate", ProcessTICreationDate },
  479. {"CreatorID", ProcessTICreatorID },
  480. {"CreatorData", ProcessTICreatorData },
  481. {"Description", ProcessTIDescription },
  482. {"EveryonePermissions", ProcessTIEveryonePermissions },
  483. {"Flags", ProcessTIFlags },
  484. {"GroupID", ProcessTIGroupID },
  485. {"GroupPermissions", ProcessTIGroupPermissions },
  486. {"InvType", ProcessTIInvType },
  487. {"ItemID", ProcessTIItemID },
  488. {"OldItemID", ProcessTIOldItemID },
  489. {"LastOwnerID", ProcessTILastOwnerID },
  490. {"Name", ProcessTIName },
  491. {"NextPermissions", ProcessTINextPermissions },
  492. {"OwnerID", ProcessTIOwnerID },
  493. {"CurrentPermissions", ProcessTICurrentPermissions },
  494. {"ParentID", ProcessTIParentID },
  495. {"ParentPartID", ProcessTIParentPartID },
  496. {"PermsGranter", ProcessTIPermsGranter },
  497. {"PermsMask", ProcessTIPermsMask },
  498. {"Type", ProcessTIType },
  499. {"OwnerChanged", ProcessTIOwnerChanged }
  500. }.ToFrozenDictionary();
  501. private static readonly FrozenDictionary<string, Action<PrimitiveBaseShape, XmlReader>> m_ShapeXmlProcessors = new Dictionary<string, Action<PrimitiveBaseShape, XmlReader>>()
  502. {
  503. {"ProfileCurve", ProcessShpProfileCurve },
  504. {"TextureEntry", ProcessShpTextureEntry },
  505. {"ExtraParams", ProcessShpExtraParams },
  506. {"PathBegin", ProcessShpPathBegin },
  507. {"PathCurve", ProcessShpPathCurve },
  508. {"PathEnd", ProcessShpPathEnd },
  509. {"PathRadiusOffset", ProcessShpPathRadiusOffset },
  510. {"PathRevolutions", ProcessShpPathRevolutions },
  511. {"PathScaleX", ProcessShpPathScaleX },
  512. {"PathScaleY", ProcessShpPathScaleY },
  513. {"PathShearX", ProcessShpPathShearX },
  514. {"PathShearY", ProcessShpPathShearY },
  515. {"PathSkew", ProcessShpPathSkew },
  516. {"PathTaperX", ProcessShpPathTaperX },
  517. {"PathTaperY", ProcessShpPathTaperY },
  518. {"PathTwist", ProcessShpPathTwist },
  519. {"PathTwistBegin", ProcessShpPathTwistBegin },
  520. {"PCode", ProcessShpPCode },
  521. {"ProfileBegin", ProcessShpProfileBegin },
  522. {"ProfileEnd", ProcessShpProfileEnd },
  523. {"ProfileHollow", ProcessShpProfileHollow },
  524. {"Scale", ProcessShpScale },
  525. {"LastAttachPoint", ProcessShpLastAttach },
  526. {"State", ProcessShpState },
  527. {"ProfileShape", ProcessShpProfileShape },
  528. {"HollowShape", ProcessShpHollowShape },
  529. {"SculptTexture", ProcessShpSculptTexture },
  530. {"SculptType", ProcessShpSculptType },
  531. // Ignore "SculptData"; this element is deprecated
  532. {"FlexiSoftness", ProcessShpFlexiSoftness },
  533. {"FlexiTension", ProcessShpFlexiTension },
  534. {"FlexiDrag", ProcessShpFlexiDrag },
  535. {"FlexiGravity", ProcessShpFlexiGravity },
  536. {"FlexiWind", ProcessShpFlexiWind },
  537. {"FlexiForceX", ProcessShpFlexiForceX },
  538. {"FlexiForceY", ProcessShpFlexiForceY },
  539. {"FlexiForceZ", ProcessShpFlexiForceZ },
  540. {"LightColorR", ProcessShpLightColorR },
  541. {"LightColorG", ProcessShpLightColorG },
  542. {"LightColorB", ProcessShpLightColorB },
  543. {"LightColorA", ProcessShpLightColorA },
  544. {"LightRadius", ProcessShpLightRadius },
  545. {"LightCutoff", ProcessShpLightCutoff },
  546. {"LightFalloff", ProcessShpLightFalloff },
  547. {"LightIntensity", ProcessShpLightIntensity },
  548. {"FlexiEntry", ProcessShpFlexiEntry },
  549. {"LightEntry", ProcessShpLightEntry },
  550. {"SculptEntry", ProcessShpSculptEntry },
  551. {"Media", ProcessShpMedia },
  552. {"MatOvrd", ProcessShpMatOvrd }
  553. }.ToFrozenDictionary();
  554. #region SOPXmlProcessors
  555. private static void ProcessAllowedDrop(SceneObjectPart obj, XmlReader reader)
  556. {
  557. obj.AllowedDrop = Util.ReadBoolean(reader);
  558. }
  559. private static void ProcessCreatorID(SceneObjectPart obj, XmlReader reader)
  560. {
  561. obj.CreatorID = Util.ReadUUID(reader, "CreatorID");
  562. }
  563. private static void ProcessCreatorData(SceneObjectPart obj, XmlReader reader)
  564. {
  565. obj.CreatorData = reader.ReadElementContentAsString("CreatorData", string.Empty);
  566. }
  567. private static void ProcessFolderID(SceneObjectPart obj, XmlReader reader)
  568. {
  569. obj.FolderID = Util.ReadUUID(reader, "FolderID");
  570. }
  571. private static void ProcessInventorySerial(SceneObjectPart obj, XmlReader reader)
  572. {
  573. obj.InventorySerial = (uint)reader.ReadElementContentAsInt("InventorySerial", string.Empty);
  574. }
  575. private static void ProcessTaskInventory(SceneObjectPart obj, XmlReader reader)
  576. {
  577. obj.TaskInventory = ReadTaskInventory(reader, "TaskInventory");
  578. }
  579. private static void ProcessUUID(SceneObjectPart obj, XmlReader reader)
  580. {
  581. obj.UUID = Util.ReadUUID(reader, "UUID");
  582. }
  583. private static void ProcessLocalId(SceneObjectPart obj, XmlReader reader)
  584. {
  585. obj.LocalId = (uint)reader.ReadElementContentAsLong("LocalId", string.Empty);
  586. }
  587. private static void ProcessName(SceneObjectPart obj, XmlReader reader)
  588. {
  589. obj.Name = reader.ReadElementString("Name");
  590. }
  591. private static void ProcessMaterial(SceneObjectPart obj, XmlReader reader)
  592. {
  593. obj.Material = (byte)reader.ReadElementContentAsInt("Material", string.Empty);
  594. }
  595. private static void ProcessPassTouches(SceneObjectPart obj, XmlReader reader)
  596. {
  597. obj.PassTouches = Util.ReadBoolean(reader);
  598. }
  599. private static void ProcessPassCollisions(SceneObjectPart obj, XmlReader reader)
  600. {
  601. obj.PassCollisions = Util.ReadBoolean(reader);
  602. }
  603. private static void ProcessRegionHandle(SceneObjectPart obj, XmlReader reader)
  604. {
  605. obj.RegionHandle = (ulong)reader.ReadElementContentAsLong("RegionHandle", string.Empty);
  606. }
  607. private static void ProcessScriptAccessPin(SceneObjectPart obj, XmlReader reader)
  608. {
  609. obj.ScriptAccessPin = reader.ReadElementContentAsInt("ScriptAccessPin", string.Empty);
  610. }
  611. private static void ProcessGroupPosition(SceneObjectPart obj, XmlReader reader)
  612. {
  613. obj.GroupPosition = Util.ReadVector(reader, "GroupPosition");
  614. }
  615. private static void ProcessOffsetPosition(SceneObjectPart obj, XmlReader reader)
  616. {
  617. obj.OffsetPosition = Util.ReadVector(reader, "OffsetPosition"); ;
  618. }
  619. private static void ProcessRotationOffset(SceneObjectPart obj, XmlReader reader)
  620. {
  621. obj.RotationOffset = Util.ReadQuaternion(reader, "RotationOffset");
  622. }
  623. private static void ProcessVelocity(SceneObjectPart obj, XmlReader reader)
  624. {
  625. obj.Velocity = Util.ReadVector(reader, "Velocity");
  626. }
  627. private static void ProcessAngularVelocity(SceneObjectPart obj, XmlReader reader)
  628. {
  629. obj.AngularVelocity = Util.ReadVector(reader, "AngularVelocity");
  630. }
  631. private static void ProcessAcceleration(SceneObjectPart obj, XmlReader reader)
  632. {
  633. obj.Acceleration = Util.ReadVector(reader, "Acceleration");
  634. }
  635. private static void ProcessDescription(SceneObjectPart obj, XmlReader reader)
  636. {
  637. obj.Description = reader.ReadElementString("Description");
  638. }
  639. private static void ProcessColor(SceneObjectPart obj, XmlReader reader)
  640. {
  641. reader.ReadStartElement("Color");
  642. if (reader.Name == "R")
  643. {
  644. float r = reader.ReadElementContentAsFloat("R", string.Empty);
  645. float g = reader.ReadElementContentAsFloat("G", string.Empty);
  646. float b = reader.ReadElementContentAsFloat("B", string.Empty);
  647. float a = reader.ReadElementContentAsFloat("A", string.Empty);
  648. obj.Color = Color.FromArgb((int)a, (int)r, (int)g, (int)b);
  649. reader.ReadEndElement();
  650. }
  651. }
  652. private static void ProcessText(SceneObjectPart obj, XmlReader reader)
  653. {
  654. obj.Text = reader.ReadElementString("Text", string.Empty);
  655. }
  656. private static void ProcessSitName(SceneObjectPart obj, XmlReader reader)
  657. {
  658. obj.SitName = reader.ReadElementString("SitName", string.Empty);
  659. }
  660. private static void ProcessTouchName(SceneObjectPart obj, XmlReader reader)
  661. {
  662. obj.TouchName = reader.ReadElementString("TouchName", string.Empty);
  663. }
  664. private static void ProcessLinkNum(SceneObjectPart obj, XmlReader reader)
  665. {
  666. obj.LinkNum = reader.ReadElementContentAsInt("LinkNum", string.Empty);
  667. }
  668. private static void ProcessClickAction(SceneObjectPart obj, XmlReader reader)
  669. {
  670. obj.ClickAction = (byte)reader.ReadElementContentAsInt("ClickAction", string.Empty);
  671. }
  672. private static void ProcessRotationAxisLocks(SceneObjectPart obj, XmlReader reader)
  673. {
  674. obj.RotationAxisLocks = (byte)reader.ReadElementContentAsInt("RotationAxisLocks", string.Empty);
  675. }
  676. private static void ProcessPhysicsShapeType(SceneObjectPart obj, XmlReader reader)
  677. {
  678. obj.PhysicsShapeType = (byte)reader.ReadElementContentAsInt("PhysicsShapeType", string.Empty);
  679. }
  680. private static void ProcessDensity(SceneObjectPart obj, XmlReader reader)
  681. {
  682. obj.Density = reader.ReadElementContentAsFloat("Density", string.Empty);
  683. }
  684. private static void ProcessFriction(SceneObjectPart obj, XmlReader reader)
  685. {
  686. obj.Friction = reader.ReadElementContentAsFloat("Friction", string.Empty);
  687. }
  688. private static void ProcessBounce(SceneObjectPart obj, XmlReader reader)
  689. {
  690. obj.Restitution = reader.ReadElementContentAsFloat("Bounce", string.Empty);
  691. }
  692. private static void ProcessGravityModifier(SceneObjectPart obj, XmlReader reader)
  693. {
  694. obj.GravityModifier = reader.ReadElementContentAsFloat("GravityModifier", string.Empty);
  695. }
  696. private static void ProcessCameraEyeOffset(SceneObjectPart obj, XmlReader reader)
  697. {
  698. obj.SetCameraEyeOffset(Util.ReadVector(reader, "CameraEyeOffset"));
  699. }
  700. private static void ProcessCameraAtOffset(SceneObjectPart obj, XmlReader reader)
  701. {
  702. obj.SetCameraAtOffset(Util.ReadVector(reader, "CameraAtOffset"));
  703. }
  704. private static void ProcessSoundID(SceneObjectPart obj, XmlReader reader)
  705. {
  706. obj.Sound = Util.ReadUUID(reader, "SoundID");
  707. }
  708. private static void ProcessSoundGain(SceneObjectPart obj, XmlReader reader)
  709. {
  710. obj.SoundGain = reader.ReadElementContentAsDouble("SoundGain", string.Empty);
  711. }
  712. private static void ProcessSoundFlags(SceneObjectPart obj, XmlReader reader)
  713. {
  714. obj.SoundFlags = (byte)reader.ReadElementContentAsInt("SoundFlags", string.Empty);
  715. }
  716. private static void ProcessSoundRadius(SceneObjectPart obj, XmlReader reader)
  717. {
  718. obj.SoundRadius = reader.ReadElementContentAsDouble("SoundRadius", string.Empty);
  719. }
  720. private static void ProcessSoundQueueing(SceneObjectPart obj, XmlReader reader)
  721. {
  722. obj.SoundQueueing = Util.ReadBoolean(reader);
  723. }
  724. private static void ProcessSitActRange(SceneObjectPart obj, XmlReader reader)
  725. {
  726. obj.SitActiveRange = reader.ReadElementContentAsFloat("SitActRange", string.Empty);
  727. }
  728. private static void ProcessVehicle(SceneObjectPart obj, XmlReader reader)
  729. {
  730. SOPVehicle vehicle = SOPVehicle.FromXml2(reader);
  731. if (vehicle == null)
  732. {
  733. obj.VehicleParams = null;
  734. m_log.DebugFormat(
  735. "[SceneObjectSerializer]: Parsing Vehicle for object part {0} {1} encountered errors. Please see earlier log entries.",
  736. obj.Name, obj.UUID);
  737. }
  738. else
  739. {
  740. obj.VehicleParams = vehicle;
  741. }
  742. }
  743. private static void ProcessPhysicsInertia(SceneObjectPart obj, XmlReader reader)
  744. {
  745. PhysicsInertiaData pdata = PhysicsInertiaData.FromXml2(reader);
  746. if (pdata == null)
  747. {
  748. obj.PhysicsInertia = null;
  749. m_log.DebugFormat(
  750. "[SceneObjectSerializer]: Parsing PhysicsInertiaData for object part {0} {1} encountered errors. Please see earlier log entries.",
  751. obj.Name, obj.UUID);
  752. }
  753. else
  754. {
  755. obj.PhysicsInertia = pdata;
  756. }
  757. }
  758. private static void ProcessSOPAnims(SceneObjectPart obj, XmlReader reader)
  759. {
  760. obj.Animations = null;
  761. try
  762. {
  763. string datastr = reader.ReadElementContentAsString();
  764. if (string.IsNullOrEmpty(datastr))
  765. return;
  766. byte[] pdata = Convert.FromBase64String(datastr);
  767. obj.DeSerializeAnimations(pdata);
  768. return;
  769. }
  770. catch { }
  771. m_log.DebugFormat(
  772. "[SceneObjectSerializer]: Parsing ProcessSOPAnims for object part {0} {1} encountered errors",
  773. obj.Name, obj.UUID);
  774. }
  775. private static void ProcessShape(SceneObjectPart obj, XmlReader reader)
  776. {
  777. obj.Shape = ReadShape(reader, "Shape", out List<string> errorNodeNames, obj);
  778. if (errorNodeNames != null)
  779. {
  780. m_log.DebugFormat(
  781. "[SceneObjectSerializer]: Parsing PrimitiveBaseShape for object part {0} {1} encountered errors in properties {2}.",
  782. obj.Name, obj.UUID, string.Join(", ", errorNodeNames.ToArray()));
  783. }
  784. }
  785. private static void ProcessScale(SceneObjectPart obj, XmlReader reader)
  786. {
  787. obj.Scale = Util.ReadVector(reader, "Scale");
  788. }
  789. private static void ProcessSitTargetOrientation(SceneObjectPart obj, XmlReader reader)
  790. {
  791. obj.SitTargetOrientation = Util.ReadQuaternion(reader, "SitTargetOrientation");
  792. }
  793. private static void ProcessSitTargetPosition(SceneObjectPart obj, XmlReader reader)
  794. {
  795. obj.SitTargetPosition = Util.ReadVector(reader, "SitTargetPosition");
  796. }
  797. private static void ProcessSitTargetPositionLL(SceneObjectPart obj, XmlReader reader)
  798. {
  799. obj.SitTargetPositionLL = Util.ReadVector(reader, "SitTargetPositionLL");
  800. }
  801. private static void ProcessSitTargetOrientationLL(SceneObjectPart obj, XmlReader reader)
  802. {
  803. obj.SitTargetOrientationLL = Util.ReadQuaternion(reader, "SitTargetOrientationLL");
  804. }
  805. private static void ProcessStandTarget(SceneObjectPart obj, XmlReader reader)
  806. {
  807. obj.StandOffset = Util.ReadVector(reader, "StandTarget");
  808. }
  809. private static void ProcessParentID(SceneObjectPart obj, XmlReader reader)
  810. {
  811. string str = reader.ReadElementContentAsString("ParentID", string.Empty);
  812. obj.ParentID = Convert.ToUInt32(str);
  813. }
  814. private static void ProcessCreationDate(SceneObjectPart obj, XmlReader reader)
  815. {
  816. obj.CreationDate = reader.ReadElementContentAsInt("CreationDate", string.Empty);
  817. }
  818. private static void ProcessCategory(SceneObjectPart obj, XmlReader reader)
  819. {
  820. obj.Category = (uint)reader.ReadElementContentAsInt("Category", string.Empty);
  821. }
  822. private static void ProcessSalePrice(SceneObjectPart obj, XmlReader reader)
  823. {
  824. obj.SalePrice = reader.ReadElementContentAsInt("SalePrice", string.Empty);
  825. }
  826. private static void ProcessObjectSaleType(SceneObjectPart obj, XmlReader reader)
  827. {
  828. obj.ObjectSaleType = (byte)reader.ReadElementContentAsInt("ObjectSaleType", string.Empty);
  829. }
  830. private static void ProcessOwnershipCost(SceneObjectPart obj, XmlReader reader)
  831. {
  832. obj.OwnershipCost = reader.ReadElementContentAsInt("OwnershipCost", string.Empty);
  833. }
  834. private static void ProcessGroupID(SceneObjectPart obj, XmlReader reader)
  835. {
  836. obj.GroupID = Util.ReadUUID(reader, "GroupID");
  837. }
  838. private static void ProcessOwnerID(SceneObjectPart obj, XmlReader reader)
  839. {
  840. obj.OwnerID = Util.ReadUUID(reader, "OwnerID");
  841. }
  842. private static void ProcessLastOwnerID(SceneObjectPart obj, XmlReader reader)
  843. {
  844. obj.LastOwnerID = Util.ReadUUID(reader, "LastOwnerID");
  845. }
  846. private static void ProcessRezzerID(SceneObjectPart obj, XmlReader reader)
  847. {
  848. obj.RezzerID = Util.ReadUUID(reader, "RezzerID");
  849. }
  850. private static void ProcessBaseMask(SceneObjectPart obj, XmlReader reader)
  851. {
  852. obj.BaseMask = (uint)reader.ReadElementContentAsInt("BaseMask", string.Empty);
  853. }
  854. private static void ProcessOwnerMask(SceneObjectPart obj, XmlReader reader)
  855. {
  856. obj.OwnerMask = (uint)reader.ReadElementContentAsInt("OwnerMask", string.Empty);
  857. }
  858. private static void ProcessGroupMask(SceneObjectPart obj, XmlReader reader)
  859. {
  860. obj.GroupMask = (uint)reader.ReadElementContentAsInt("GroupMask", string.Empty);
  861. }
  862. private static void ProcessEveryoneMask(SceneObjectPart obj, XmlReader reader)
  863. {
  864. obj.EveryoneMask = (uint)reader.ReadElementContentAsInt("EveryoneMask", string.Empty);
  865. }
  866. private static void ProcessNextOwnerMask(SceneObjectPart obj, XmlReader reader)
  867. {
  868. obj.NextOwnerMask = (uint)reader.ReadElementContentAsInt("NextOwnerMask", string.Empty);
  869. }
  870. private static void ProcessFlags(SceneObjectPart obj, XmlReader reader)
  871. {
  872. obj.Flags = Util.ReadEnum<PrimFlags>(reader, "Flags");
  873. }
  874. private static void ProcessCollisionSound(SceneObjectPart obj, XmlReader reader)
  875. {
  876. obj.CollisionSound = Util.ReadUUID(reader, "CollisionSound");
  877. }
  878. private static void ProcessCollisionSoundVolume(SceneObjectPart obj, XmlReader reader)
  879. {
  880. obj.CollisionSoundVolume = reader.ReadElementContentAsFloat("CollisionSoundVolume", string.Empty);
  881. }
  882. private static void ProcessMediaUrl(SceneObjectPart obj, XmlReader reader)
  883. {
  884. obj.MediaUrl = reader.ReadElementContentAsString("MediaUrl", string.Empty);
  885. }
  886. private static void ProcessAttachedPos(SceneObjectPart obj, XmlReader reader)
  887. {
  888. obj.AttachedPos = Util.ReadVector(reader, "AttachedPos");
  889. }
  890. private static void ProcessDynAttrs(SceneObjectPart obj, XmlReader reader)
  891. {
  892. DAMap waste = new();
  893. waste.ReadXml(reader);
  894. if(waste.CountNamespaces > 0)
  895. obj.DynAttrs = waste;
  896. else
  897. obj.DynAttrs = null;
  898. }
  899. private static void ProcessTextureAnimation(SceneObjectPart obj, XmlReader reader)
  900. {
  901. obj.TextureAnimation = Convert.FromBase64String(reader.ReadElementContentAsString("TextureAnimation", string.Empty));
  902. }
  903. private static void ProcessParticleSystem(SceneObjectPart obj, XmlReader reader)
  904. {
  905. obj.ParticleSystem = Convert.FromBase64String(reader.ReadElementContentAsString("ParticleSystem", string.Empty));
  906. }
  907. private static void ProcessPayPrice0(SceneObjectPart obj, XmlReader reader)
  908. {
  909. obj.PayPrice[0] = (int)reader.ReadElementContentAsInt("PayPrice0", string.Empty);
  910. }
  911. private static void ProcessPayPrice1(SceneObjectPart obj, XmlReader reader)
  912. {
  913. obj.PayPrice[1] = (int)reader.ReadElementContentAsInt("PayPrice1", string.Empty);
  914. }
  915. private static void ProcessPayPrice2(SceneObjectPart obj, XmlReader reader)
  916. {
  917. obj.PayPrice[2] = (int)reader.ReadElementContentAsInt("PayPrice2", string.Empty);
  918. }
  919. private static void ProcessPayPrice3(SceneObjectPart obj, XmlReader reader)
  920. {
  921. obj.PayPrice[3] = (int)reader.ReadElementContentAsInt("PayPrice3", string.Empty);
  922. }
  923. private static void ProcessPayPrice4(SceneObjectPart obj, XmlReader reader)
  924. {
  925. obj.PayPrice[4] = (int)reader.ReadElementContentAsInt("PayPrice4", string.Empty);
  926. }
  927. private static void ProcessBuoyancy(SceneObjectPart obj, XmlReader reader)
  928. {
  929. obj.Buoyancy = (float)reader.ReadElementContentAsFloat("Buoyancy", string.Empty);
  930. }
  931. private static void ProcessForce(SceneObjectPart obj, XmlReader reader)
  932. {
  933. obj.Force = Util.ReadVector(reader, "Force");
  934. }
  935. private static void ProcessTorque(SceneObjectPart obj, XmlReader reader)
  936. {
  937. obj.Torque = Util.ReadVector(reader, "Torque");
  938. }
  939. private static void ProcessVolumeDetectActive(SceneObjectPart obj, XmlReader reader)
  940. {
  941. obj.VolumeDetectActive = Util.ReadBoolean(reader);
  942. }
  943. #endregion
  944. #region TaskInventoryXmlProcessors
  945. private static void ProcessTIAssetID(TaskInventoryItem item, XmlReader reader)
  946. {
  947. item.AssetID = Util.ReadUUID(reader, "AssetID");
  948. }
  949. private static void ProcessTIBasePermissions(TaskInventoryItem item, XmlReader reader)
  950. {
  951. item.BasePermissions = (uint)reader.ReadElementContentAsInt("BasePermissions", string.Empty);
  952. }
  953. private static void ProcessTICreationDate(TaskInventoryItem item, XmlReader reader)
  954. {
  955. item.CreationDate = (uint)reader.ReadElementContentAsInt("CreationDate", string.Empty);
  956. }
  957. private static void ProcessTICreatorID(TaskInventoryItem item, XmlReader reader)
  958. {
  959. item.CreatorID = Util.ReadUUID(reader, "CreatorID");
  960. }
  961. private static void ProcessTICreatorData(TaskInventoryItem item, XmlReader reader)
  962. {
  963. item.CreatorData = reader.ReadElementContentAsString("CreatorData", string.Empty);
  964. }
  965. private static void ProcessTIDescription(TaskInventoryItem item, XmlReader reader)
  966. {
  967. item.Description = reader.ReadElementContentAsString("Description", string.Empty);
  968. }
  969. private static void ProcessTIEveryonePermissions(TaskInventoryItem item, XmlReader reader)
  970. {
  971. item.EveryonePermissions = (uint)reader.ReadElementContentAsInt("EveryonePermissions", string.Empty);
  972. }
  973. private static void ProcessTIFlags(TaskInventoryItem item, XmlReader reader)
  974. {
  975. item.Flags = (uint)reader.ReadElementContentAsInt("Flags", string.Empty);
  976. }
  977. private static void ProcessTIGroupID(TaskInventoryItem item, XmlReader reader)
  978. {
  979. item.GroupID = Util.ReadUUID(reader, "GroupID");
  980. }
  981. private static void ProcessTIGroupPermissions(TaskInventoryItem item, XmlReader reader)
  982. {
  983. item.GroupPermissions = (uint)reader.ReadElementContentAsInt("GroupPermissions", string.Empty);
  984. }
  985. private static void ProcessTIInvType(TaskInventoryItem item, XmlReader reader)
  986. {
  987. item.InvType = reader.ReadElementContentAsInt("InvType", string.Empty);
  988. }
  989. private static void ProcessTIItemID(TaskInventoryItem item, XmlReader reader)
  990. {
  991. item.ItemID = Util.ReadUUID(reader, "ItemID");
  992. }
  993. private static void ProcessTIOldItemID(TaskInventoryItem item, XmlReader reader)
  994. {
  995. item.OldItemID = Util.ReadUUID(reader, "OldItemID");
  996. }
  997. private static void ProcessTILastOwnerID(TaskInventoryItem item, XmlReader reader)
  998. {
  999. item.LastOwnerID = Util.ReadUUID(reader, "LastOwnerID");
  1000. }
  1001. private static void ProcessTIName(TaskInventoryItem item, XmlReader reader)
  1002. {
  1003. item.Name = reader.ReadElementContentAsString("Name", string.Empty);
  1004. }
  1005. private static void ProcessTINextPermissions(TaskInventoryItem item, XmlReader reader)
  1006. {
  1007. item.NextPermissions = (uint)reader.ReadElementContentAsInt("NextPermissions", string.Empty);
  1008. }
  1009. private static void ProcessTIOwnerID(TaskInventoryItem item, XmlReader reader)
  1010. {
  1011. item.OwnerID = Util.ReadUUID(reader, "OwnerID");
  1012. }
  1013. private static void ProcessTICurrentPermissions(TaskInventoryItem item, XmlReader reader)
  1014. {
  1015. item.CurrentPermissions = (uint)reader.ReadElementContentAsInt("CurrentPermissions", string.Empty);
  1016. }
  1017. private static void ProcessTIParentID(TaskInventoryItem item, XmlReader reader)
  1018. {
  1019. item.ParentID = Util.ReadUUID(reader, "ParentID");
  1020. }
  1021. private static void ProcessTIParentPartID(TaskInventoryItem item, XmlReader reader)
  1022. {
  1023. item.ParentPartID = Util.ReadUUID(reader, "ParentPartID");
  1024. }
  1025. private static void ProcessTIPermsGranter(TaskInventoryItem item, XmlReader reader)
  1026. {
  1027. item.PermsGranter = Util.ReadUUID(reader, "PermsGranter");
  1028. }
  1029. private static void ProcessTIPermsMask(TaskInventoryItem item, XmlReader reader)
  1030. {
  1031. item.PermsMask = reader.ReadElementContentAsInt("PermsMask", string.Empty);
  1032. }
  1033. private static void ProcessTIType(TaskInventoryItem item, XmlReader reader)
  1034. {
  1035. item.Type = reader.ReadElementContentAsInt("Type", string.Empty);
  1036. }
  1037. private static void ProcessTIOwnerChanged(TaskInventoryItem item, XmlReader reader)
  1038. {
  1039. item.OwnerChanged = Util.ReadBoolean(reader);
  1040. }
  1041. #endregion
  1042. #region ShapeXmlProcessors
  1043. private static void ProcessShpProfileCurve(PrimitiveBaseShape shp, XmlReader reader)
  1044. {
  1045. shp.ProfileCurve = (byte)reader.ReadElementContentAsInt("ProfileCurve", string.Empty);
  1046. }
  1047. private static void ProcessShpTextureEntry(PrimitiveBaseShape shp, XmlReader reader)
  1048. {
  1049. byte[] teData = Convert.FromBase64String(reader.ReadElementString("TextureEntry"));
  1050. shp.Textures = new Primitive.TextureEntry(teData, 0, teData.Length);
  1051. }
  1052. private static void ProcessShpExtraParams(PrimitiveBaseShape shp, XmlReader reader)
  1053. {
  1054. shp.ExtraParams = Convert.FromBase64String(reader.ReadElementString("ExtraParams"));
  1055. }
  1056. private static void ProcessShpPathBegin(PrimitiveBaseShape shp, XmlReader reader)
  1057. {
  1058. shp.PathBegin = (ushort)reader.ReadElementContentAsInt("PathBegin", string.Empty);
  1059. }
  1060. private static void ProcessShpPathCurve(PrimitiveBaseShape shp, XmlReader reader)
  1061. {
  1062. shp.PathCurve = (byte)reader.ReadElementContentAsInt("PathCurve", string.Empty);
  1063. }
  1064. private static void ProcessShpPathEnd(PrimitiveBaseShape shp, XmlReader reader)
  1065. {
  1066. shp.PathEnd = (ushort)reader.ReadElementContentAsInt("PathEnd", string.Empty);
  1067. }
  1068. private static void ProcessShpPathRadiusOffset(PrimitiveBaseShape shp, XmlReader reader)
  1069. {
  1070. shp.PathRadiusOffset = (sbyte)reader.ReadElementContentAsInt("PathRadiusOffset", string.Empty);
  1071. }
  1072. private static void ProcessShpPathRevolutions(PrimitiveBaseShape shp, XmlReader reader)
  1073. {
  1074. shp.PathRevolutions = (byte)reader.ReadElementContentAsInt("PathRevolutions", string.Empty);
  1075. }
  1076. private static void ProcessShpPathScaleX(PrimitiveBaseShape shp, XmlReader reader)
  1077. {
  1078. shp.PathScaleX = (byte)reader.ReadElementContentAsInt("PathScaleX", string.Empty);
  1079. }
  1080. private static void ProcessShpPathScaleY(PrimitiveBaseShape shp, XmlReader reader)
  1081. {
  1082. shp.PathScaleY = (byte)reader.ReadElementContentAsInt("PathScaleY", string.Empty);
  1083. }
  1084. private static void ProcessShpPathShearX(PrimitiveBaseShape shp, XmlReader reader)
  1085. {
  1086. shp.PathShearX = (byte)reader.ReadElementContentAsInt("PathShearX", string.Empty);
  1087. }
  1088. private static void ProcessShpPathShearY(PrimitiveBaseShape shp, XmlReader reader)
  1089. {
  1090. shp.PathShearY = (byte)reader.ReadElementContentAsInt("PathShearY", string.Empty);
  1091. }
  1092. private static void ProcessShpPathSkew(PrimitiveBaseShape shp, XmlReader reader)
  1093. {
  1094. shp.PathSkew = (sbyte)reader.ReadElementContentAsInt("PathSkew", string.Empty);
  1095. }
  1096. private static void ProcessShpPathTaperX(PrimitiveBaseShape shp, XmlReader reader)
  1097. {
  1098. shp.PathTaperX = (sbyte)reader.ReadElementContentAsInt("PathTaperX", string.Empty);
  1099. }
  1100. private static void ProcessShpPathTaperY(PrimitiveBaseShape shp, XmlReader reader)
  1101. {
  1102. shp.PathTaperY = (sbyte)reader.ReadElementContentAsInt("PathTaperY", string.Empty);
  1103. }
  1104. private static void ProcessShpPathTwist(PrimitiveBaseShape shp, XmlReader reader)
  1105. {
  1106. shp.PathTwist = (sbyte)reader.ReadElementContentAsInt("PathTwist", string.Empty);
  1107. }
  1108. private static void ProcessShpPathTwistBegin(PrimitiveBaseShape shp, XmlReader reader)
  1109. {
  1110. shp.PathTwistBegin = (sbyte)reader.ReadElementContentAsInt("PathTwistBegin", string.Empty);
  1111. }
  1112. private static void ProcessShpPCode(PrimitiveBaseShape shp, XmlReader reader)
  1113. {
  1114. shp.PCode = (byte)reader.ReadElementContentAsInt("PCode", string.Empty);
  1115. }
  1116. private static void ProcessShpProfileBegin(PrimitiveBaseShape shp, XmlReader reader)
  1117. {
  1118. shp.ProfileBegin = (ushort)reader.ReadElementContentAsInt("ProfileBegin", string.Empty);
  1119. }
  1120. private static void ProcessShpProfileEnd(PrimitiveBaseShape shp, XmlReader reader)
  1121. {
  1122. shp.ProfileEnd = (ushort)reader.ReadElementContentAsInt("ProfileEnd", string.Empty);
  1123. }
  1124. private static void ProcessShpProfileHollow(PrimitiveBaseShape shp, XmlReader reader)
  1125. {
  1126. shp.ProfileHollow = (ushort)reader.ReadElementContentAsInt("ProfileHollow", string.Empty);
  1127. }
  1128. private static void ProcessShpScale(PrimitiveBaseShape shp, XmlReader reader)
  1129. {
  1130. shp.Scale = Util.ReadVector(reader, "Scale");
  1131. }
  1132. private static void ProcessShpState(PrimitiveBaseShape shp, XmlReader reader)
  1133. {
  1134. shp.State = (byte)reader.ReadElementContentAsInt("State", string.Empty);
  1135. }
  1136. private static void ProcessShpLastAttach(PrimitiveBaseShape shp, XmlReader reader)
  1137. {
  1138. shp.LastAttachPoint = (byte)reader.ReadElementContentAsInt("LastAttachPoint", string.Empty);
  1139. }
  1140. private static void ProcessShpProfileShape(PrimitiveBaseShape shp, XmlReader reader)
  1141. {
  1142. shp.ProfileShape = Util.ReadEnum<ProfileShape>(reader, "ProfileShape");
  1143. }
  1144. private static void ProcessShpHollowShape(PrimitiveBaseShape shp, XmlReader reader)
  1145. {
  1146. shp.HollowShape = Util.ReadEnum<HollowShape>(reader, "HollowShape");
  1147. }
  1148. private static void ProcessShpSculptTexture(PrimitiveBaseShape shp, XmlReader reader)
  1149. {
  1150. shp.SculptTexture = Util.ReadUUID(reader, "SculptTexture");
  1151. }
  1152. private static void ProcessShpSculptType(PrimitiveBaseShape shp, XmlReader reader)
  1153. {
  1154. shp.SculptType = (byte)reader.ReadElementContentAsInt("SculptType", string.Empty);
  1155. }
  1156. private static void ProcessShpFlexiSoftness(PrimitiveBaseShape shp, XmlReader reader)
  1157. {
  1158. shp.FlexiSoftness = reader.ReadElementContentAsInt("FlexiSoftness", string.Empty);
  1159. }
  1160. private static void ProcessShpFlexiTension(PrimitiveBaseShape shp, XmlReader reader)
  1161. {
  1162. shp.FlexiTension = reader.ReadElementContentAsFloat("FlexiTension", string.Empty);
  1163. }
  1164. private static void ProcessShpFlexiDrag(PrimitiveBaseShape shp, XmlReader reader)
  1165. {
  1166. shp.FlexiDrag = reader.ReadElementContentAsFloat("FlexiDrag", string.Empty);
  1167. }
  1168. private static void ProcessShpFlexiGravity(PrimitiveBaseShape shp, XmlReader reader)
  1169. {
  1170. shp.FlexiGravity = reader.ReadElementContentAsFloat("FlexiGravity", string.Empty);
  1171. }
  1172. private static void ProcessShpFlexiWind(PrimitiveBaseShape shp, XmlReader reader)
  1173. {
  1174. shp.FlexiWind = reader.ReadElementContentAsFloat("FlexiWind", string.Empty);
  1175. }
  1176. private static void ProcessShpFlexiForceX(PrimitiveBaseShape shp, XmlReader reader)
  1177. {
  1178. shp.FlexiForceX = reader.ReadElementContentAsFloat("FlexiForceX", string.Empty);
  1179. }
  1180. private static void ProcessShpFlexiForceY(PrimitiveBaseShape shp, XmlReader reader)
  1181. {
  1182. shp.FlexiForceY = reader.ReadElementContentAsFloat("FlexiForceY", string.Empty);
  1183. }
  1184. private static void ProcessShpFlexiForceZ(PrimitiveBaseShape shp, XmlReader reader)
  1185. {
  1186. shp.FlexiForceZ = reader.ReadElementContentAsFloat("FlexiForceZ", string.Empty);
  1187. }
  1188. private static void ProcessShpLightColorR(PrimitiveBaseShape shp, XmlReader reader)
  1189. {
  1190. shp.LightColorR = reader.ReadElementContentAsFloat("LightColorR", string.Empty);
  1191. }
  1192. private static void ProcessShpLightColorG(PrimitiveBaseShape shp, XmlReader reader)
  1193. {
  1194. shp.LightColorG = reader.ReadElementContentAsFloat("LightColorG", string.Empty);
  1195. }
  1196. private static void ProcessShpLightColorB(PrimitiveBaseShape shp, XmlReader reader)
  1197. {
  1198. shp.LightColorB = reader.ReadElementContentAsFloat("LightColorB", string.Empty);
  1199. }
  1200. private static void ProcessShpLightColorA(PrimitiveBaseShape shp, XmlReader reader)
  1201. {
  1202. shp.LightColorA = reader.ReadElementContentAsFloat("LightColorA", string.Empty);
  1203. }
  1204. private static void ProcessShpLightRadius(PrimitiveBaseShape shp, XmlReader reader)
  1205. {
  1206. shp.LightRadius = reader.ReadElementContentAsFloat("LightRadius", string.Empty);
  1207. }
  1208. private static void ProcessShpLightCutoff(PrimitiveBaseShape shp, XmlReader reader)
  1209. {
  1210. shp.LightCutoff = reader.ReadElementContentAsFloat("LightCutoff", string.Empty);
  1211. }
  1212. private static void ProcessShpLightFalloff(PrimitiveBaseShape shp, XmlReader reader)
  1213. {
  1214. shp.LightFalloff = reader.ReadElementContentAsFloat("LightFalloff", string.Empty);
  1215. }
  1216. private static void ProcessShpLightIntensity(PrimitiveBaseShape shp, XmlReader reader)
  1217. {
  1218. shp.LightIntensity = reader.ReadElementContentAsFloat("LightIntensity", string.Empty);
  1219. }
  1220. private static void ProcessShpFlexiEntry(PrimitiveBaseShape shp, XmlReader reader)
  1221. {
  1222. shp.FlexiEntry = Util.ReadBoolean(reader);
  1223. }
  1224. private static void ProcessShpLightEntry(PrimitiveBaseShape shp, XmlReader reader)
  1225. {
  1226. shp.LightEntry = Util.ReadBoolean(reader);
  1227. }
  1228. private static void ProcessShpSculptEntry(PrimitiveBaseShape shp, XmlReader reader)
  1229. {
  1230. shp.SculptEntry = Util.ReadBoolean(reader);
  1231. }
  1232. private static void ProcessShpMedia(PrimitiveBaseShape shp, XmlReader reader)
  1233. {
  1234. string value;
  1235. try
  1236. {
  1237. // The STANDARD content of Media elemet is escaped XML string (with &gt; etc).
  1238. value = reader.ReadElementContentAsString("Media", string.Empty);
  1239. shp.Media = PrimitiveBaseShape.MediaList.FromXml(value);
  1240. }
  1241. catch (XmlException)
  1242. {
  1243. // There are versions of OAR files that contain unquoted XML.
  1244. // ie ONE comercial fork that never wanted their oars to be read by our code
  1245. try
  1246. {
  1247. value = reader.ReadInnerXml();
  1248. shp.Media = PrimitiveBaseShape.MediaList.FromXml(value);
  1249. }
  1250. catch
  1251. {
  1252. m_log.ErrorFormat("[SERIALIZER] Failed parsing halcyon MOAP information");
  1253. }
  1254. }
  1255. }
  1256. private static void ProcessShpMatOvrd(PrimitiveBaseShape shp, XmlReader reader)
  1257. {
  1258. try
  1259. {
  1260. string datastr = reader.ReadElementContentAsString();
  1261. if (!string.IsNullOrEmpty(datastr))
  1262. {
  1263. byte[] pdata = Convert.FromBase64String(datastr);
  1264. shp.RenderMaterialsOvrFromRawBin(pdata);
  1265. }
  1266. return;
  1267. }
  1268. catch
  1269. {
  1270. shp.RenderMaterialsOvrFromRawBin(null);
  1271. }
  1272. }
  1273. #endregion
  1274. ////////// Write /////////
  1275. public static void SOGToXml2(XmlTextWriter writer, SceneObjectGroup sog, Dictionary<string, object>options)
  1276. {
  1277. writer.WriteStartElement(string.Empty, "SceneObjectGroup", string.Empty);
  1278. SOPToXml2(writer, sog.RootPart, options);
  1279. writer.WriteStartElement(string.Empty, "OtherParts", string.Empty);
  1280. sog.ForEachPart(delegate(SceneObjectPart sop)
  1281. {
  1282. if (sop.UUID != sog.RootPart.UUID)
  1283. SOPToXml2(writer, sop, options);
  1284. });
  1285. writer.WriteEndElement();
  1286. if (sog.RootPart.KeyframeMotion != null)
  1287. {
  1288. Byte[] data = sog.RootPart.KeyframeMotion.Serialize();
  1289. writer.WriteStartElement(string.Empty, "KeyframeMotion", string.Empty);
  1290. writer.WriteBase64(data, 0, data.Length);
  1291. writer.WriteEndElement();
  1292. }
  1293. if(sog.RezStringParameter is not null)
  1294. writer.WriteElementString("StartStr", sog.RezStringParameter);
  1295. sog.LinksetData?.ToXML(writer);
  1296. writer.WriteEndElement();
  1297. }
  1298. public static void SOPToXml2(XmlTextWriter writer, SceneObjectPart sop, Dictionary<string, object> options)
  1299. {
  1300. writer.WriteStartElement("SceneObjectPart");
  1301. writer.WriteAttributeString("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
  1302. writer.WriteAttributeString("xmlns:xsd", "http://www.w3.org/2001/XMLSchema");
  1303. writer.WriteElementString("AllowedDrop", sop.AllowedDrop.ToString().ToLower());
  1304. WriteUUID(writer, "CreatorID", sop.CreatorID, options);
  1305. if (!string.IsNullOrEmpty(sop.CreatorData))
  1306. writer.WriteElementString("CreatorData", sop.CreatorData);
  1307. else if (options.TryGetValue("home", out object ohome))
  1308. {
  1309. m_UserManagement ??= sop.ParentGroup.Scene.RequestModuleInterface<IUserManagement>();
  1310. string name = m_UserManagement.GetUserName(sop.CreatorID);
  1311. writer.WriteElementString("CreatorData", ExternalRepresentationUtils.CalcCreatorData((string)ohome, name));
  1312. }
  1313. WriteUUID(writer, "FolderID", sop.FolderID, options);
  1314. writer.WriteElementString("InventorySerial", sop.InventorySerial.ToString());
  1315. WriteTaskInventory(writer, sop.TaskInventory, options, sop.ParentGroup.Scene);
  1316. WriteUUID(writer, "UUID", sop.UUID, options);
  1317. writer.WriteElementString("LocalId", sop.LocalId.ToString());
  1318. writer.WriteElementString("Name", sop.Name);
  1319. writer.WriteElementString("Material", sop.Material.ToString());
  1320. writer.WriteElementString("PassTouches", sop.PassTouches.ToString().ToLower());
  1321. writer.WriteElementString("PassCollisions", sop.PassCollisions.ToString().ToLower());
  1322. writer.WriteElementString("RegionHandle", sop.RegionHandle.ToString());
  1323. writer.WriteElementString("ScriptAccessPin", sop.ScriptAccessPin.ToString());
  1324. WriteVector(writer, "GroupPosition", sop.GroupPosition);
  1325. WriteVector(writer, "OffsetPosition", sop.OffsetPosition);
  1326. WriteQuaternion(writer, "RotationOffset", sop.RotationOffset);
  1327. WriteVector(writer, "Velocity", sop.Velocity);
  1328. WriteVector(writer, "AngularVelocity", sop.AngularVelocity);
  1329. WriteVector(writer, "Acceleration", sop.Acceleration);
  1330. writer.WriteElementString("Description", sop.Description);
  1331. writer.WriteStartElement("Color");
  1332. writer.WriteElementString("R", sop.Color.R.ToString(Culture.FormatProvider));
  1333. writer.WriteElementString("G", sop.Color.G.ToString(Culture.FormatProvider));
  1334. writer.WriteElementString("B", sop.Color.B.ToString(Culture.FormatProvider));
  1335. writer.WriteElementString("A", sop.Color.A.ToString(Culture.FormatProvider));
  1336. writer.WriteEndElement();
  1337. writer.WriteElementString("Text", sop.Text);
  1338. writer.WriteElementString("SitName", sop.SitName);
  1339. writer.WriteElementString("TouchName", sop.TouchName);
  1340. writer.WriteElementString("LinkNum", sop.LinkNum.ToString());
  1341. writer.WriteElementString("ClickAction", sop.ClickAction.ToString());
  1342. WriteShape(writer, sop.Shape, options);
  1343. WriteVector(writer, "Scale", sop.Scale);
  1344. WriteQuaternion(writer, "SitTargetOrientation", sop.SitTargetOrientation);
  1345. WriteVector(writer, "SitTargetPosition", sop.SitTargetPosition);
  1346. WriteVector(writer, "SitTargetPositionLL", sop.SitTargetPositionLL);
  1347. WriteQuaternion(writer, "SitTargetOrientationLL", sop.SitTargetOrientationLL);
  1348. if(sop.StandOffset.IsNotZero())
  1349. WriteVector(writer, "StandTarget", sop.StandOffset);
  1350. writer.WriteElementString("ParentID", sop.ParentID.ToString());
  1351. writer.WriteElementString("CreationDate", sop.CreationDate.ToString());
  1352. writer.WriteElementString("Category", sop.Category.ToString());
  1353. writer.WriteElementString("SalePrice", sop.SalePrice.ToString());
  1354. writer.WriteElementString("ObjectSaleType", sop.ObjectSaleType.ToString());
  1355. writer.WriteElementString("OwnershipCost", sop.OwnershipCost.ToString());
  1356. UUID groupID = options.ContainsKey("wipe-owners") ? UUID.Zero : sop.GroupID;
  1357. WriteUUID(writer, "GroupID", groupID, options);
  1358. UUID ownerID = options.ContainsKey("wipe-owners") ? UUID.Zero : sop.OwnerID;
  1359. WriteUUID(writer, "OwnerID", ownerID, options);
  1360. UUID lastOwnerID = options.ContainsKey("wipe-owners") ? UUID.Zero : sop.LastOwnerID;
  1361. WriteUUID(writer, "LastOwnerID", lastOwnerID, options);
  1362. UUID rezzerID = options.ContainsKey("wipe-owners") ? UUID.Zero : sop.RezzerID;
  1363. WriteUUID(writer, "RezzerID", rezzerID, options);
  1364. writer.WriteElementString("BaseMask", sop.BaseMask.ToString());
  1365. writer.WriteElementString("OwnerMask", sop.OwnerMask.ToString());
  1366. writer.WriteElementString("GroupMask", sop.GroupMask.ToString());
  1367. writer.WriteElementString("EveryoneMask", sop.EveryoneMask.ToString());
  1368. writer.WriteElementString("NextOwnerMask", sop.NextOwnerMask.ToString());
  1369. WriteFlags(writer, "Flags", sop.Flags.ToString(), options);
  1370. WriteUUID(writer, "CollisionSound", sop.CollisionSound, options);
  1371. writer.WriteElementString("CollisionSoundVolume", sop.CollisionSoundVolume.ToString(Culture.FormatProvider));
  1372. if (!string.IsNullOrEmpty(sop.MediaUrl))
  1373. writer.WriteElementString("MediaUrl", sop.MediaUrl.ToString());
  1374. WriteVector(writer, "AttachedPos", sop.AttachedPos);
  1375. if (sop.DynAttrs != null && sop.DynAttrs.CountNamespaces > 0)
  1376. {
  1377. writer.WriteStartElement("DynAttrs");
  1378. sop.DynAttrs.WriteXml(writer);
  1379. writer.WriteEndElement();
  1380. }
  1381. WriteBytes(writer, "TextureAnimation", sop.TextureAnimation);
  1382. WriteBytes(writer, "ParticleSystem", sop.ParticleSystem);
  1383. writer.WriteElementString("PayPrice0", sop.PayPrice[0].ToString());
  1384. writer.WriteElementString("PayPrice1", sop.PayPrice[1].ToString());
  1385. writer.WriteElementString("PayPrice2", sop.PayPrice[2].ToString());
  1386. writer.WriteElementString("PayPrice3", sop.PayPrice[3].ToString());
  1387. writer.WriteElementString("PayPrice4", sop.PayPrice[4].ToString());
  1388. writer.WriteElementString("Buoyancy", sop.Buoyancy.ToString(Culture.FormatProvider));
  1389. WriteVector(writer, "Force", sop.Force);
  1390. WriteVector(writer, "Torque", sop.Torque);
  1391. writer.WriteElementString("VolumeDetectActive", sop.VolumeDetectActive.ToString().ToLower());
  1392. sop.VehicleParams?.ToXml2(writer);
  1393. sop.PhysicsInertia?.ToXml2(writer);
  1394. if(sop.IsRoot && sop.RotationAxisLocks != 0)
  1395. writer.WriteElementString("RotationAxisLocks", sop.RotationAxisLocks.ToString().ToLower());
  1396. writer.WriteElementString("PhysicsShapeType", sop.PhysicsShapeType.ToString().ToLower());
  1397. if (sop.Density != 1000.0f)
  1398. writer.WriteElementString("Density", sop.Density.ToString(Culture.FormatProvider));
  1399. if (sop.Friction != 0.6f)
  1400. writer.WriteElementString("Friction", sop.Friction.ToString(Culture.FormatProvider));
  1401. if (sop.Restitution != 0.5f)
  1402. writer.WriteElementString("Bounce", sop.Restitution.ToString(Culture.FormatProvider));
  1403. if (sop.GravityModifier != 1.0f)
  1404. writer.WriteElementString("GravityModifier", sop.GravityModifier.ToString(Culture.FormatProvider));
  1405. WriteVector(writer, "CameraEyeOffset", sop.GetCameraEyeOffset());
  1406. WriteVector(writer, "CameraAtOffset", sop.GetCameraAtOffset());
  1407. // if (sop.Sound != UUID.Zero) force it till sop crossing does clear it on child prim
  1408. {
  1409. WriteUUID(writer, "SoundID", sop.Sound, options);
  1410. writer.WriteElementString("SoundGain", sop.SoundGain.ToString(Culture.FormatProvider));
  1411. writer.WriteElementString("SoundFlags", sop.SoundFlags.ToString().ToLower());
  1412. writer.WriteElementString("SoundRadius", sop.SoundRadius.ToString(Culture.FormatProvider));
  1413. }
  1414. writer.WriteElementString("SoundQueueing", sop.SoundQueueing.ToString().ToLower());
  1415. if (sop.Animations != null)
  1416. {
  1417. Byte[] data = sop.SerializeAnimations();
  1418. if(data != null && data.Length > 0)
  1419. writer.WriteElementString("SOPAnims", Convert.ToBase64String(data));
  1420. }
  1421. if(Math.Abs(sop.SitActiveRange) > 1e-5)
  1422. writer.WriteElementString("SitActRange", sop.SitActiveRange.ToString(Culture.FormatProvider));
  1423. writer.WriteEndElement();
  1424. }
  1425. static void WriteUUID(XmlTextWriter writer, string name, UUID id, Dictionary<string, object> options)
  1426. {
  1427. writer.WriteStartElement(name);
  1428. if (options.ContainsKey("old-guids"))
  1429. writer.WriteElementString("Guid", id.ToString());
  1430. else
  1431. writer.WriteElementString("UUID", id.ToString());
  1432. writer.WriteEndElement();
  1433. }
  1434. static void WriteVector(XmlTextWriter writer, string name, Vector3 vec)
  1435. {
  1436. writer.WriteStartElement(name);
  1437. writer.WriteElementString("X", vec.X.ToString(Culture.FormatProvider));
  1438. writer.WriteElementString("Y", vec.Y.ToString(Culture.FormatProvider));
  1439. writer.WriteElementString("Z", vec.Z.ToString(Culture.FormatProvider));
  1440. writer.WriteEndElement();
  1441. }
  1442. static void WriteQuaternion(XmlTextWriter writer, string name, Quaternion quat)
  1443. {
  1444. writer.WriteStartElement(name);
  1445. writer.WriteElementString("X", quat.X.ToString(Culture.FormatProvider));
  1446. writer.WriteElementString("Y", quat.Y.ToString(Culture.FormatProvider));
  1447. writer.WriteElementString("Z", quat.Z.ToString(Culture.FormatProvider));
  1448. writer.WriteElementString("W", quat.W.ToString(Culture.FormatProvider));
  1449. writer.WriteEndElement();
  1450. }
  1451. static void WriteBytes(XmlTextWriter writer, string name, byte[] data)
  1452. {
  1453. writer.WriteStartElement(name);
  1454. byte[] d;
  1455. if (data != null)
  1456. d = data;
  1457. else
  1458. d = Utils.EmptyBytes;
  1459. writer.WriteBase64(d, 0, d.Length);
  1460. writer.WriteEndElement(); // name
  1461. }
  1462. static void WriteFlags(XmlTextWriter writer, string name, string flagsStr, Dictionary<string, object> options)
  1463. {
  1464. // Older versions of serialization can't cope with commas, so we eliminate the commas
  1465. writer.WriteElementString(name, flagsStr.Replace(",", ""));
  1466. }
  1467. public static void WriteTaskInventory(XmlTextWriter writer, TaskInventoryDictionary tinv, Dictionary<string, object> options, Scene scene)
  1468. {
  1469. if (tinv.Count > 0) // otherwise skip this
  1470. {
  1471. writer.WriteStartElement("TaskInventory");
  1472. foreach (TaskInventoryItem item in tinv.Values)
  1473. {
  1474. writer.WriteStartElement("TaskInventoryItem");
  1475. WriteUUID(writer, "AssetID", item.AssetID, options);
  1476. writer.WriteElementString("BasePermissions", item.BasePermissions.ToString());
  1477. writer.WriteElementString("CreationDate", item.CreationDate.ToString());
  1478. WriteUUID(writer, "CreatorID", item.CreatorID, options);
  1479. if (!string.IsNullOrEmpty(item.CreatorData))
  1480. writer.WriteElementString("CreatorData", item.CreatorData);
  1481. else if (options.TryGetValue("home", out object ohome))
  1482. {
  1483. m_UserManagement ??= scene.RequestModuleInterface<IUserManagement>();
  1484. string name = m_UserManagement.GetUserName(item.CreatorID);
  1485. writer.WriteElementString("CreatorData", ExternalRepresentationUtils.CalcCreatorData((string)ohome, name));
  1486. }
  1487. writer.WriteElementString("Description", item.Description);
  1488. writer.WriteElementString("EveryonePermissions", item.EveryonePermissions.ToString());
  1489. writer.WriteElementString("Flags", item.Flags.ToString());
  1490. UUID groupID = options.ContainsKey("wipe-owners") ? UUID.Zero : item.GroupID;
  1491. WriteUUID(writer, "GroupID", groupID, options);
  1492. writer.WriteElementString("GroupPermissions", item.GroupPermissions.ToString());
  1493. writer.WriteElementString("InvType", item.InvType.ToString());
  1494. WriteUUID(writer, "ItemID", item.ItemID, options);
  1495. WriteUUID(writer, "OldItemID", item.OldItemID, options);
  1496. UUID lastOwnerID = options.ContainsKey("wipe-owners") ? UUID.Zero : item.LastOwnerID;
  1497. WriteUUID(writer, "LastOwnerID", lastOwnerID, options);
  1498. writer.WriteElementString("Name", item.Name);
  1499. writer.WriteElementString("NextPermissions", item.NextPermissions.ToString());
  1500. UUID ownerID = options.ContainsKey("wipe-owners") ? UUID.Zero : item.OwnerID;
  1501. WriteUUID(writer, "OwnerID", ownerID, options);
  1502. writer.WriteElementString("CurrentPermissions", item.CurrentPermissions.ToString());
  1503. WriteUUID(writer, "ParentID", item.ParentID, options);
  1504. WriteUUID(writer, "ParentPartID", item.ParentPartID, options);
  1505. WriteUUID(writer, "PermsGranter", item.PermsGranter, options);
  1506. writer.WriteElementString("PermsMask", item.PermsMask.ToString());
  1507. writer.WriteElementString("Type", item.Type.ToString());
  1508. bool ownerChanged = !options.ContainsKey("wipe-owners") && item.OwnerChanged;
  1509. writer.WriteElementString("OwnerChanged", ownerChanged.ToString().ToLower());
  1510. writer.WriteEndElement(); // TaskInventoryItem
  1511. }
  1512. writer.WriteEndElement(); // TaskInventory
  1513. }
  1514. }
  1515. public static void WriteShape(XmlTextWriter writer, PrimitiveBaseShape shp, Dictionary<string, object> options)
  1516. {
  1517. if (shp != null)
  1518. {
  1519. writer.WriteStartElement("Shape");
  1520. writer.WriteElementString("ProfileCurve", shp.ProfileCurve.ToString());
  1521. writer.WriteStartElement("TextureEntry");
  1522. byte[] te;
  1523. if (shp.TextureEntry != null)
  1524. te = shp.TextureEntry;
  1525. else
  1526. te = Utils.EmptyBytes;
  1527. writer.WriteBase64(te, 0, te.Length);
  1528. writer.WriteEndElement(); // TextureEntry
  1529. writer.WriteStartElement("ExtraParams");
  1530. byte[] ep;
  1531. if (shp.ExtraParams != null)
  1532. ep = shp.ExtraParams;
  1533. else
  1534. ep = Utils.EmptyBytes;
  1535. writer.WriteBase64(ep, 0, ep.Length);
  1536. writer.WriteEndElement(); // ExtraParams
  1537. writer.WriteElementString("PathBegin", shp.PathBegin.ToString());
  1538. writer.WriteElementString("PathCurve", shp.PathCurve.ToString());
  1539. writer.WriteElementString("PathEnd", shp.PathEnd.ToString());
  1540. writer.WriteElementString("PathRadiusOffset", shp.PathRadiusOffset.ToString());
  1541. writer.WriteElementString("PathRevolutions", shp.PathRevolutions.ToString());
  1542. writer.WriteElementString("PathScaleX", shp.PathScaleX.ToString());
  1543. writer.WriteElementString("PathScaleY", shp.PathScaleY.ToString());
  1544. writer.WriteElementString("PathShearX", shp.PathShearX.ToString());
  1545. writer.WriteElementString("PathShearY", shp.PathShearY.ToString());
  1546. writer.WriteElementString("PathSkew", shp.PathSkew.ToString());
  1547. writer.WriteElementString("PathTaperX", shp.PathTaperX.ToString());
  1548. writer.WriteElementString("PathTaperY", shp.PathTaperY.ToString());
  1549. writer.WriteElementString("PathTwist", shp.PathTwist.ToString());
  1550. writer.WriteElementString("PathTwistBegin", shp.PathTwistBegin.ToString());
  1551. writer.WriteElementString("PCode", shp.PCode.ToString());
  1552. writer.WriteElementString("ProfileBegin", shp.ProfileBegin.ToString());
  1553. writer.WriteElementString("ProfileEnd", shp.ProfileEnd.ToString());
  1554. writer.WriteElementString("ProfileHollow", shp.ProfileHollow.ToString());
  1555. writer.WriteElementString("State", shp.State.ToString());
  1556. writer.WriteElementString("LastAttachPoint", shp.LastAttachPoint.ToString());
  1557. WriteFlags(writer, "ProfileShape", shp.ProfileShape.ToString(), options);
  1558. WriteFlags(writer, "HollowShape", shp.HollowShape.ToString(), options);
  1559. WriteUUID(writer, "SculptTexture", shp.SculptTexture, options);
  1560. writer.WriteElementString("SculptType", shp.SculptType.ToString());
  1561. // Don't serialize SculptData. It's just a copy of the asset, which can be loaded separately using 'SculptTexture'.
  1562. writer.WriteElementString("FlexiSoftness", shp.FlexiSoftness.ToString());
  1563. writer.WriteElementString("FlexiTension", shp.FlexiTension.ToString(Culture.FormatProvider));
  1564. writer.WriteElementString("FlexiDrag", shp.FlexiDrag.ToString(Culture.FormatProvider));
  1565. writer.WriteElementString("FlexiGravity", shp.FlexiGravity.ToString(Culture.FormatProvider));
  1566. writer.WriteElementString("FlexiWind", shp.FlexiWind.ToString(Culture.FormatProvider));
  1567. writer.WriteElementString("FlexiForceX", shp.FlexiForceX.ToString(Culture.FormatProvider));
  1568. writer.WriteElementString("FlexiForceY", shp.FlexiForceY.ToString(Culture.FormatProvider));
  1569. writer.WriteElementString("FlexiForceZ", shp.FlexiForceZ.ToString(Culture.FormatProvider));
  1570. writer.WriteElementString("LightColorR", shp.LightColorR.ToString(Culture.FormatProvider));
  1571. writer.WriteElementString("LightColorG", shp.LightColorG.ToString(Culture.FormatProvider));
  1572. writer.WriteElementString("LightColorB", shp.LightColorB.ToString(Culture.FormatProvider));
  1573. writer.WriteElementString("LightColorA", shp.LightColorA.ToString(Culture.FormatProvider));
  1574. writer.WriteElementString("LightRadius", shp.LightRadius.ToString(Culture.FormatProvider));
  1575. writer.WriteElementString("LightCutoff", shp.LightCutoff.ToString(Culture.FormatProvider));
  1576. writer.WriteElementString("LightFalloff", shp.LightFalloff.ToString(Culture.FormatProvider));
  1577. writer.WriteElementString("LightIntensity", shp.LightIntensity.ToString(Culture.FormatProvider));
  1578. writer.WriteElementString("FlexiEntry", shp.FlexiEntry.ToString().ToLower());
  1579. writer.WriteElementString("LightEntry", shp.LightEntry.ToString().ToLower());
  1580. writer.WriteElementString("SculptEntry", shp.SculptEntry.ToString().ToLower());
  1581. if (shp.Media is not null)
  1582. writer.WriteElementString("Media", shp.Media.ToXml());
  1583. byte[] matoverrides = shp.RenderMaterialsOvrToRawBin();
  1584. if(matoverrides is not null)
  1585. {
  1586. writer.WriteStartElement("MatOvrd");
  1587. writer.WriteBase64(matoverrides, 0, matoverrides.Length);
  1588. writer.WriteEndElement();
  1589. }
  1590. writer.WriteEndElement(); // Shape
  1591. }
  1592. }
  1593. public static SceneObjectPart Xml2ToSOP(XmlReader reader)
  1594. {
  1595. SceneObjectPart obj = new();
  1596. reader.ReadStartElement("SceneObjectPart");
  1597. bool errors = ExternalRepresentationUtils.ExecuteReadProcessors(
  1598. obj,
  1599. m_SOPXmlProcessors,
  1600. reader,
  1601. (o, nodeName, e) => {
  1602. m_log.Debug(string.Format("[SceneObjectSerializer]: Error while parsing element {0} in object {1} {2} ",
  1603. nodeName, ((SceneObjectPart)o).Name, ((SceneObjectPart)o).UUID), e);
  1604. });
  1605. if (errors)
  1606. throw new XmlException(string.Format("Error parsing object {0} {1}", obj.Name, obj.UUID));
  1607. reader.ReadEndElement(); // SceneObjectPart
  1608. obj.AggregateInnerPerms();
  1609. // m_log.DebugFormat("[SceneObjectSerializer]: parsed SOP {0} {1}", obj.Name, obj.UUID);
  1610. return obj;
  1611. }
  1612. public static TaskInventoryDictionary ReadTaskInventory(XmlReader reader, string name)
  1613. {
  1614. TaskInventoryDictionary tinv = new();
  1615. reader.ReadStartElement(name, string.Empty);
  1616. while (reader.Name == "TaskInventoryItem")
  1617. {
  1618. reader.ReadStartElement("TaskInventoryItem", string.Empty); // TaskInventory
  1619. TaskInventoryItem item = new();
  1620. ExternalRepresentationUtils.ExecuteReadProcessors(
  1621. item,
  1622. m_TaskInventoryXmlProcessors,
  1623. reader);
  1624. reader.ReadEndElement(); // TaskInventoryItem
  1625. tinv.Add(item.ItemID, item);
  1626. }
  1627. if (reader.NodeType == XmlNodeType.EndElement)
  1628. reader.ReadEndElement(); // TaskInventory
  1629. return tinv;
  1630. }
  1631. /// <summary>
  1632. /// Read a shape from xml input
  1633. /// </summary>
  1634. /// <param name="reader"></param>
  1635. /// <param name="name">The name of the xml element containing the shape</param>
  1636. /// <param name="errors">a list containing the failing node names. If no failures then null.</param>
  1637. /// <returns>The shape parsed</returns>
  1638. public static PrimitiveBaseShape ReadShape(XmlReader reader, string name, out List<string> errorNodeNames, SceneObjectPart obj)
  1639. {
  1640. List<string> internalErrorNodeNames = null;
  1641. PrimitiveBaseShape shape = new();
  1642. if (reader.IsEmptyElement)
  1643. {
  1644. reader.Read();
  1645. errorNodeNames = null;
  1646. return shape;
  1647. }
  1648. reader.ReadStartElement(name, string.Empty); // Shape
  1649. ExternalRepresentationUtils.ExecuteReadProcessors(
  1650. shape,
  1651. m_ShapeXmlProcessors,
  1652. reader,
  1653. (o, nodeName, e) => {
  1654. m_log.Debug(string.Format("[SceneObjectSerializer]: Error while parsing element {0} in Shape property of object {1} {2} ",
  1655. nodeName, obj.Name, obj.UUID), e);
  1656. internalErrorNodeNames ??= new List<string>();
  1657. internalErrorNodeNames.Add(nodeName);
  1658. });
  1659. reader.ReadEndElement(); // Shape
  1660. errorNodeNames = internalErrorNodeNames;
  1661. return shape;
  1662. }
  1663. #endregion
  1664. }
  1665. }