SceneObjectSerializer.cs 83 KB

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