SkeletonBinary.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. namespace Spine
  5. {
  6. public class SkeletonBinary
  7. {
  8. public SkeletonBinary(params Atlas[] atlasArray) : this(new AtlasAttachmentLoader(atlasArray))
  9. {
  10. }
  11. public SkeletonBinary(AttachmentLoader attachmentLoader)
  12. {
  13. if (attachmentLoader == null)
  14. {
  15. throw new ArgumentNullException("attachmentLoader cannot be null.");
  16. }
  17. this.attachmentLoader = attachmentLoader;
  18. this.Scale = 1f;
  19. }
  20. public float Scale { get; set; }
  21. public SkeletonData ReadSkeletonData(string path)
  22. {
  23. SkeletonData result;
  24. using (BufferedStream bufferedStream = new BufferedStream(new FileStream(path, FileMode.Open)))
  25. {
  26. SkeletonData skeletonData = this.ReadSkeletonData(bufferedStream);
  27. skeletonData.name = Path.GetFileNameWithoutExtension(path);
  28. result = skeletonData;
  29. }
  30. return result;
  31. }
  32. public SkeletonData ReadSkeletonData(Stream input)
  33. {
  34. if (input == null)
  35. {
  36. throw new ArgumentNullException("input cannot be null.");
  37. }
  38. float scale = this.Scale;
  39. SkeletonData skeletonData = new SkeletonData();
  40. skeletonData.hash = this.ReadString(input);
  41. if (skeletonData.hash.Length == 0)
  42. {
  43. skeletonData.hash = null;
  44. }
  45. skeletonData.version = this.ReadString(input);
  46. if (skeletonData.version.Length == 0)
  47. {
  48. skeletonData.version = null;
  49. }
  50. skeletonData.width = this.ReadFloat(input);
  51. skeletonData.height = this.ReadFloat(input);
  52. bool flag = this.ReadBoolean(input);
  53. if (flag)
  54. {
  55. skeletonData.imagesPath = this.ReadString(input);
  56. if (skeletonData.imagesPath.Length == 0)
  57. {
  58. skeletonData.imagesPath = null;
  59. }
  60. }
  61. int i = 0;
  62. int num = this.ReadInt(input, true);
  63. while (i < num)
  64. {
  65. string name = this.ReadString(input);
  66. BoneData parent = null;
  67. int num2 = this.ReadInt(input, true) - 1;
  68. if (num2 != -1)
  69. {
  70. parent = skeletonData.bones[num2];
  71. }
  72. BoneData boneData = new BoneData(name, parent);
  73. boneData.x = this.ReadFloat(input) * scale;
  74. boneData.y = this.ReadFloat(input) * scale;
  75. boneData.scaleX = this.ReadFloat(input);
  76. boneData.scaleY = this.ReadFloat(input);
  77. boneData.rotation = this.ReadFloat(input);
  78. boneData.length = this.ReadFloat(input) * scale;
  79. boneData.flipX = this.ReadBoolean(input);
  80. boneData.flipY = this.ReadBoolean(input);
  81. boneData.inheritScale = this.ReadBoolean(input);
  82. boneData.inheritRotation = this.ReadBoolean(input);
  83. if (flag)
  84. {
  85. this.ReadInt(input);
  86. }
  87. skeletonData.bones.Add(boneData);
  88. i++;
  89. }
  90. int j = 0;
  91. int num3 = this.ReadInt(input, true);
  92. while (j < num3)
  93. {
  94. IkConstraintData ikConstraintData = new IkConstraintData(this.ReadString(input));
  95. int k = 0;
  96. int num4 = this.ReadInt(input, true);
  97. while (k < num4)
  98. {
  99. ikConstraintData.bones.Add(skeletonData.bones[this.ReadInt(input, true)]);
  100. k++;
  101. }
  102. ikConstraintData.target = skeletonData.bones[this.ReadInt(input, true)];
  103. ikConstraintData.mix = this.ReadFloat(input);
  104. ikConstraintData.bendDirection = (int)this.ReadSByte(input);
  105. skeletonData.ikConstraints.Add(ikConstraintData);
  106. j++;
  107. }
  108. int l = 0;
  109. int num5 = this.ReadInt(input, true);
  110. while (l < num5)
  111. {
  112. string name2 = this.ReadString(input);
  113. BoneData boneData2 = skeletonData.bones[this.ReadInt(input, true)];
  114. SlotData slotData = new SlotData(name2, boneData2);
  115. int num6 = this.ReadInt(input);
  116. slotData.r = (float)(((long)num6 & (long)((ulong)0xFF000000)) >> 24) / 255f;
  117. slotData.g = (float)((num6 & 16711680) >> 16) / 255f;
  118. slotData.b = (float)((num6 & 65280) >> 8) / 255f;
  119. slotData.a = (float)(num6 & 255) / 255f;
  120. slotData.attachmentName = this.ReadString(input);
  121. slotData.blendMode = (BlendMode)this.ReadInt(input, true);
  122. skeletonData.slots.Add(slotData);
  123. l++;
  124. }
  125. Skin skin = this.ReadSkin(input, "default", flag);
  126. if (skin != null)
  127. {
  128. skeletonData.defaultSkin = skin;
  129. skeletonData.skins.Add(skin);
  130. }
  131. int m = 0;
  132. int num7 = this.ReadInt(input, true);
  133. while (m < num7)
  134. {
  135. skeletonData.skins.Add(this.ReadSkin(input, this.ReadString(input), flag));
  136. m++;
  137. }
  138. int n = 0;
  139. int num8 = this.ReadInt(input, true);
  140. while (n < num8)
  141. {
  142. EventData eventData = new EventData(this.ReadString(input));
  143. eventData.Int = this.ReadInt(input, false);
  144. eventData.Float = this.ReadFloat(input);
  145. eventData.String = this.ReadString(input);
  146. skeletonData.events.Add(eventData);
  147. n++;
  148. }
  149. int num9 = 0;
  150. int num10 = this.ReadInt(input, true);
  151. while (num9 < num10)
  152. {
  153. this.ReadAnimation(this.ReadString(input), input, skeletonData);
  154. num9++;
  155. }
  156. skeletonData.bones.TrimExcess();
  157. skeletonData.slots.TrimExcess();
  158. skeletonData.skins.TrimExcess();
  159. skeletonData.events.TrimExcess();
  160. skeletonData.animations.TrimExcess();
  161. skeletonData.ikConstraints.TrimExcess();
  162. return skeletonData;
  163. }
  164. private Skin ReadSkin(Stream input, string skinName, bool nonessential)
  165. {
  166. int num = this.ReadInt(input, true);
  167. if (num == 0)
  168. {
  169. return null;
  170. }
  171. Skin skin = new Skin(skinName);
  172. for (int i = 0; i < num; i++)
  173. {
  174. int slotIndex = this.ReadInt(input, true);
  175. int j = 0;
  176. int num2 = this.ReadInt(input, true);
  177. while (j < num2)
  178. {
  179. string text = this.ReadString(input);
  180. skin.AddAttachment(slotIndex, text, this.ReadAttachment(input, skin, text, nonessential));
  181. j++;
  182. }
  183. }
  184. return skin;
  185. }
  186. private Attachment ReadAttachment(Stream input, Skin skin, string attachmentName, bool nonessential)
  187. {
  188. float scale = this.Scale;
  189. string text = this.ReadString(input);
  190. if (text == null)
  191. {
  192. text = attachmentName;
  193. }
  194. switch (input.ReadByte())
  195. {
  196. case 0:
  197. {
  198. string text2 = this.ReadString(input);
  199. if (text2 == null)
  200. {
  201. text2 = text;
  202. }
  203. RegionAttachment regionAttachment = this.attachmentLoader.NewRegionAttachment(skin, text, text2);
  204. if (regionAttachment == null)
  205. {
  206. return null;
  207. }
  208. regionAttachment.Path = text2;
  209. regionAttachment.x = this.ReadFloat(input) * scale;
  210. regionAttachment.y = this.ReadFloat(input) * scale;
  211. regionAttachment.scaleX = this.ReadFloat(input);
  212. regionAttachment.scaleY = this.ReadFloat(input);
  213. regionAttachment.rotation = this.ReadFloat(input);
  214. regionAttachment.width = this.ReadFloat(input) * scale;
  215. regionAttachment.height = this.ReadFloat(input) * scale;
  216. int num = this.ReadInt(input);
  217. regionAttachment.r = (float)(((long)num & (long)((ulong)0xFF000000)) >> 24) / 255f;
  218. regionAttachment.g = (float)((num & 16711680) >> 16) / 255f;
  219. regionAttachment.b = (float)((num & 65280) >> 8) / 255f;
  220. regionAttachment.a = (float)(num & 255) / 255f;
  221. regionAttachment.UpdateOffset();
  222. return regionAttachment;
  223. }
  224. case 1:
  225. {
  226. BoundingBoxAttachment boundingBoxAttachment = this.attachmentLoader.NewBoundingBoxAttachment(skin, text);
  227. if (boundingBoxAttachment == null)
  228. {
  229. return null;
  230. }
  231. boundingBoxAttachment.vertices = this.ReadFloatArray(input, scale);
  232. return boundingBoxAttachment;
  233. }
  234. case 2:
  235. {
  236. string text3 = this.ReadString(input);
  237. if (text3 == null)
  238. {
  239. text3 = text;
  240. }
  241. MeshAttachment meshAttachment = this.attachmentLoader.NewMeshAttachment(skin, text, text3);
  242. if (meshAttachment == null)
  243. {
  244. return null;
  245. }
  246. meshAttachment.Path = text3;
  247. meshAttachment.regionUVs = this.ReadFloatArray(input, 1f);
  248. meshAttachment.triangles = this.ReadShortArray(input);
  249. meshAttachment.vertices = this.ReadFloatArray(input, scale);
  250. meshAttachment.UpdateUVs();
  251. int num2 = this.ReadInt(input);
  252. meshAttachment.r = (float)(((long)num2 & (long)((ulong)0xFF000000)) >> 24) / 255f;
  253. meshAttachment.g = (float)((num2 & 16711680) >> 16) / 255f;
  254. meshAttachment.b = (float)((num2 & 65280) >> 8) / 255f;
  255. meshAttachment.a = (float)(num2 & 255) / 255f;
  256. meshAttachment.HullLength = this.ReadInt(input, true) * 2;
  257. if (nonessential)
  258. {
  259. meshAttachment.Edges = this.ReadIntArray(input);
  260. meshAttachment.Width = this.ReadFloat(input) * scale;
  261. meshAttachment.Height = this.ReadFloat(input) * scale;
  262. }
  263. return meshAttachment;
  264. }
  265. case 3:
  266. {
  267. string text4 = this.ReadString(input);
  268. if (text4 == null)
  269. {
  270. text4 = text;
  271. }
  272. SkinnedMeshAttachment skinnedMeshAttachment = this.attachmentLoader.NewSkinnedMeshAttachment(skin, text, text4);
  273. if (skinnedMeshAttachment == null)
  274. {
  275. return null;
  276. }
  277. skinnedMeshAttachment.Path = text4;
  278. float[] array = this.ReadFloatArray(input, 1f);
  279. int[] triangles = this.ReadShortArray(input);
  280. int num3 = this.ReadInt(input, true);
  281. List<float> list = new List<float>(array.Length * 3 * 3);
  282. List<int> list2 = new List<int>(array.Length * 3);
  283. for (int i = 0; i < num3; i++)
  284. {
  285. int num4 = (int)this.ReadFloat(input);
  286. list2.Add(num4);
  287. int num5 = i + num4 * 4;
  288. while (i < num5)
  289. {
  290. list2.Add((int)this.ReadFloat(input));
  291. list.Add(this.ReadFloat(input) * scale);
  292. list.Add(this.ReadFloat(input) * scale);
  293. list.Add(this.ReadFloat(input));
  294. i += 4;
  295. }
  296. }
  297. skinnedMeshAttachment.bones = list2.ToArray();
  298. skinnedMeshAttachment.weights = list.ToArray();
  299. skinnedMeshAttachment.triangles = triangles;
  300. skinnedMeshAttachment.regionUVs = array;
  301. skinnedMeshAttachment.UpdateUVs();
  302. int num6 = this.ReadInt(input);
  303. skinnedMeshAttachment.r = (float)(((long)num6 & (long)((ulong)0xFF000000)) >> 24) / 255f;
  304. skinnedMeshAttachment.g = (float)((num6 & 16711680) >> 16) / 255f;
  305. skinnedMeshAttachment.b = (float)((num6 & 65280) >> 8) / 255f;
  306. skinnedMeshAttachment.a = (float)(num6 & 255) / 255f;
  307. skinnedMeshAttachment.HullLength = this.ReadInt(input, true) * 2;
  308. if (nonessential)
  309. {
  310. skinnedMeshAttachment.Edges = this.ReadIntArray(input);
  311. skinnedMeshAttachment.Width = this.ReadFloat(input) * scale;
  312. skinnedMeshAttachment.Height = this.ReadFloat(input) * scale;
  313. }
  314. return skinnedMeshAttachment;
  315. }
  316. default:
  317. return null;
  318. }
  319. }
  320. private float[] ReadFloatArray(Stream input, float scale)
  321. {
  322. int num = this.ReadInt(input, true);
  323. float[] array = new float[num];
  324. if (scale == 1f)
  325. {
  326. for (int i = 0; i < num; i++)
  327. {
  328. array[i] = this.ReadFloat(input);
  329. }
  330. }
  331. else
  332. {
  333. for (int j = 0; j < num; j++)
  334. {
  335. array[j] = this.ReadFloat(input) * scale;
  336. }
  337. }
  338. return array;
  339. }
  340. private int[] ReadShortArray(Stream input)
  341. {
  342. int num = this.ReadInt(input, true);
  343. int[] array = new int[num];
  344. for (int i = 0; i < num; i++)
  345. {
  346. array[i] = (input.ReadByte() << 8) + input.ReadByte();
  347. }
  348. return array;
  349. }
  350. private int[] ReadIntArray(Stream input)
  351. {
  352. int num = this.ReadInt(input, true);
  353. int[] array = new int[num];
  354. for (int i = 0; i < num; i++)
  355. {
  356. array[i] = this.ReadInt(input, true);
  357. }
  358. return array;
  359. }
  360. private void ReadAnimation(string name, Stream input, SkeletonData skeletonData)
  361. {
  362. List<Timeline> list = new List<Timeline>();
  363. float scale = this.Scale;
  364. float num = 0f;
  365. int i = 0;
  366. int num2 = this.ReadInt(input, true);
  367. while (i < num2)
  368. {
  369. int slotIndex = this.ReadInt(input, true);
  370. int j = 0;
  371. int num3 = this.ReadInt(input, true);
  372. while (j < num3)
  373. {
  374. int num4 = input.ReadByte();
  375. int num5 = this.ReadInt(input, true);
  376. if (num4 != 4)
  377. {
  378. if (num4 == 3)
  379. {
  380. AttachmentTimeline attachmentTimeline = new AttachmentTimeline(num5);
  381. attachmentTimeline.slotIndex = slotIndex;
  382. for (int k = 0; k < num5; k++)
  383. {
  384. attachmentTimeline.SetFrame(k, this.ReadFloat(input), this.ReadString(input));
  385. }
  386. list.Add(attachmentTimeline);
  387. num = Math.Max(num, attachmentTimeline.frames[num5 - 1]);
  388. }
  389. }
  390. else
  391. {
  392. ColorTimeline colorTimeline = new ColorTimeline(num5);
  393. colorTimeline.slotIndex = slotIndex;
  394. for (int l = 0; l < num5; l++)
  395. {
  396. float time = this.ReadFloat(input);
  397. int num6 = this.ReadInt(input);
  398. float r = (float)(((long)num6 & (long)((ulong)0xFF000000)) >> 24) / 255f;
  399. float g = (float)((num6 & 16711680) >> 16) / 255f;
  400. float b = (float)((num6 & 65280) >> 8) / 255f;
  401. float a = (float)(num6 & 255) / 255f;
  402. colorTimeline.SetFrame(l, time, r, g, b, a);
  403. if (l < num5 - 1)
  404. {
  405. this.ReadCurve(input, l, colorTimeline);
  406. }
  407. }
  408. list.Add(colorTimeline);
  409. num = Math.Max(num, colorTimeline.frames[num5 * 5 - 5]);
  410. }
  411. j++;
  412. }
  413. i++;
  414. }
  415. int m = 0;
  416. int num7 = this.ReadInt(input, true);
  417. while (m < num7)
  418. {
  419. int boneIndex = this.ReadInt(input, true);
  420. int n = 0;
  421. int num8 = this.ReadInt(input, true);
  422. while (n < num8)
  423. {
  424. int num9 = input.ReadByte();
  425. int num10 = this.ReadInt(input, true);
  426. switch (num9)
  427. {
  428. case 0:
  429. case 2:
  430. {
  431. float num11 = 1f;
  432. TranslateTimeline translateTimeline;
  433. if (num9 == 0)
  434. {
  435. translateTimeline = new ScaleTimeline(num10);
  436. }
  437. else
  438. {
  439. translateTimeline = new TranslateTimeline(num10);
  440. num11 = scale;
  441. }
  442. translateTimeline.boneIndex = boneIndex;
  443. for (int num12 = 0; num12 < num10; num12++)
  444. {
  445. translateTimeline.SetFrame(num12, this.ReadFloat(input), this.ReadFloat(input) * num11, this.ReadFloat(input) * num11);
  446. if (num12 < num10 - 1)
  447. {
  448. this.ReadCurve(input, num12, translateTimeline);
  449. }
  450. }
  451. list.Add(translateTimeline);
  452. num = Math.Max(num, translateTimeline.frames[num10 * 3 - 3]);
  453. break;
  454. }
  455. case 1:
  456. {
  457. RotateTimeline rotateTimeline = new RotateTimeline(num10);
  458. rotateTimeline.boneIndex = boneIndex;
  459. for (int num13 = 0; num13 < num10; num13++)
  460. {
  461. rotateTimeline.SetFrame(num13, this.ReadFloat(input), this.ReadFloat(input));
  462. if (num13 < num10 - 1)
  463. {
  464. this.ReadCurve(input, num13, rotateTimeline);
  465. }
  466. }
  467. list.Add(rotateTimeline);
  468. num = Math.Max(num, rotateTimeline.frames[num10 * 2 - 2]);
  469. break;
  470. }
  471. case 5:
  472. case 6:
  473. {
  474. FlipXTimeline flipXTimeline = (num9 != 5) ? new FlipYTimeline(num10) : new FlipXTimeline(num10);
  475. flipXTimeline.boneIndex = boneIndex;
  476. for (int num14 = 0; num14 < num10; num14++)
  477. {
  478. flipXTimeline.SetFrame(num14, this.ReadFloat(input), this.ReadBoolean(input));
  479. }
  480. list.Add(flipXTimeline);
  481. num = Math.Max(num, flipXTimeline.frames[num10 * 2 - 2]);
  482. break;
  483. }
  484. }
  485. n++;
  486. }
  487. m++;
  488. }
  489. int num15 = 0;
  490. int num16 = this.ReadInt(input, true);
  491. while (num15 < num16)
  492. {
  493. IkConstraintData item = skeletonData.ikConstraints[this.ReadInt(input, true)];
  494. int num17 = this.ReadInt(input, true);
  495. IkConstraintTimeline ikConstraintTimeline = new IkConstraintTimeline(num17);
  496. ikConstraintTimeline.ikConstraintIndex = skeletonData.ikConstraints.IndexOf(item);
  497. for (int num18 = 0; num18 < num17; num18++)
  498. {
  499. ikConstraintTimeline.SetFrame(num18, this.ReadFloat(input), this.ReadFloat(input), (int)this.ReadSByte(input));
  500. if (num18 < num17 - 1)
  501. {
  502. this.ReadCurve(input, num18, ikConstraintTimeline);
  503. }
  504. }
  505. list.Add(ikConstraintTimeline);
  506. num = Math.Max(num, ikConstraintTimeline.frames[num17 * 3 - 3]);
  507. num15++;
  508. }
  509. int num19 = 0;
  510. int num20 = this.ReadInt(input, true);
  511. while (num19 < num20)
  512. {
  513. Skin skin = skeletonData.skins[this.ReadInt(input, true)];
  514. int num21 = 0;
  515. int num22 = this.ReadInt(input, true);
  516. while (num21 < num22)
  517. {
  518. int slotIndex2 = this.ReadInt(input, true);
  519. int num23 = 0;
  520. int num24 = this.ReadInt(input, true);
  521. while (num23 < num24)
  522. {
  523. Attachment attachment = skin.GetAttachment(slotIndex2, this.ReadString(input));
  524. int num25 = this.ReadInt(input, true);
  525. FFDTimeline ffdtimeline = new FFDTimeline(num25);
  526. ffdtimeline.slotIndex = slotIndex2;
  527. ffdtimeline.attachment = attachment;
  528. for (int num26 = 0; num26 < num25; num26++)
  529. {
  530. float time2 = this.ReadFloat(input);
  531. int num27;
  532. if (attachment is MeshAttachment)
  533. {
  534. num27 = ((MeshAttachment)attachment).vertices.Length;
  535. }
  536. else
  537. {
  538. num27 = ((SkinnedMeshAttachment)attachment).weights.Length / 3 * 2;
  539. }
  540. int num28 = this.ReadInt(input, true);
  541. float[] array;
  542. if (num28 == 0)
  543. {
  544. if (attachment is MeshAttachment)
  545. {
  546. array = ((MeshAttachment)attachment).vertices;
  547. }
  548. else
  549. {
  550. array = new float[num27];
  551. }
  552. }
  553. else
  554. {
  555. array = new float[num27];
  556. int num29 = this.ReadInt(input, true);
  557. num28 += num29;
  558. if (scale == 1f)
  559. {
  560. for (int num30 = num29; num30 < num28; num30++)
  561. {
  562. array[num30] = this.ReadFloat(input);
  563. }
  564. }
  565. else
  566. {
  567. for (int num31 = num29; num31 < num28; num31++)
  568. {
  569. array[num31] = this.ReadFloat(input) * scale;
  570. }
  571. }
  572. if (attachment is MeshAttachment)
  573. {
  574. float[] vertices = ((MeshAttachment)attachment).vertices;
  575. int num32 = 0;
  576. int num33 = array.Length;
  577. while (num32 < num33)
  578. {
  579. array[num32] += vertices[num32];
  580. num32++;
  581. }
  582. }
  583. }
  584. ffdtimeline.SetFrame(num26, time2, array);
  585. if (num26 < num25 - 1)
  586. {
  587. this.ReadCurve(input, num26, ffdtimeline);
  588. }
  589. }
  590. list.Add(ffdtimeline);
  591. num = Math.Max(num, ffdtimeline.frames[num25 - 1]);
  592. num23++;
  593. }
  594. num21++;
  595. }
  596. num19++;
  597. }
  598. int num34 = this.ReadInt(input, true);
  599. if (num34 > 0)
  600. {
  601. DrawOrderTimeline drawOrderTimeline = new DrawOrderTimeline(num34);
  602. int count = skeletonData.slots.Count;
  603. for (int num35 = 0; num35 < num34; num35++)
  604. {
  605. int num36 = this.ReadInt(input, true);
  606. int[] array2 = new int[count];
  607. for (int num37 = count - 1; num37 >= 0; num37--)
  608. {
  609. array2[num37] = -1;
  610. }
  611. int[] array3 = new int[count - num36];
  612. int num38 = 0;
  613. int num39 = 0;
  614. for (int num40 = 0; num40 < num36; num40++)
  615. {
  616. int num41 = this.ReadInt(input, true);
  617. while (num38 != num41)
  618. {
  619. array3[num39++] = num38++;
  620. }
  621. array2[num38 + this.ReadInt(input, true)] = num38++;
  622. }
  623. while (num38 < count)
  624. {
  625. array3[num39++] = num38++;
  626. }
  627. for (int num42 = count - 1; num42 >= 0; num42--)
  628. {
  629. if (array2[num42] == -1)
  630. {
  631. array2[num42] = array3[--num39];
  632. }
  633. }
  634. drawOrderTimeline.SetFrame(num35, this.ReadFloat(input), array2);
  635. }
  636. list.Add(drawOrderTimeline);
  637. num = Math.Max(num, drawOrderTimeline.frames[num34 - 1]);
  638. }
  639. int num43 = this.ReadInt(input, true);
  640. if (num43 > 0)
  641. {
  642. EventTimeline eventTimeline = new EventTimeline(num43);
  643. for (int num44 = 0; num44 < num43; num44++)
  644. {
  645. float time3 = this.ReadFloat(input);
  646. EventData eventData = skeletonData.events[this.ReadInt(input, true)];
  647. eventTimeline.SetFrame(num44, time3, new Event(eventData)
  648. {
  649. Int = this.ReadInt(input, false),
  650. Float = this.ReadFloat(input),
  651. String = ((!this.ReadBoolean(input)) ? eventData.String : this.ReadString(input))
  652. });
  653. }
  654. list.Add(eventTimeline);
  655. num = Math.Max(num, eventTimeline.frames[num43 - 1]);
  656. }
  657. list.TrimExcess();
  658. skeletonData.animations.Add(new Animation(name, list, num));
  659. }
  660. private void ReadCurve(Stream input, int frameIndex, CurveTimeline timeline)
  661. {
  662. int num = input.ReadByte();
  663. if (num != 1)
  664. {
  665. if (num == 2)
  666. {
  667. timeline.SetCurve(frameIndex, this.ReadFloat(input), this.ReadFloat(input), this.ReadFloat(input), this.ReadFloat(input));
  668. }
  669. }
  670. else
  671. {
  672. timeline.SetStepped(frameIndex);
  673. }
  674. }
  675. private sbyte ReadSByte(Stream input)
  676. {
  677. int num = input.ReadByte();
  678. if (num == -1)
  679. {
  680. throw new EndOfStreamException();
  681. }
  682. return (sbyte)num;
  683. }
  684. private bool ReadBoolean(Stream input)
  685. {
  686. return input.ReadByte() != 0;
  687. }
  688. private float ReadFloat(Stream input)
  689. {
  690. this.buffer[3] = (byte)input.ReadByte();
  691. this.buffer[2] = (byte)input.ReadByte();
  692. this.buffer[1] = (byte)input.ReadByte();
  693. this.buffer[0] = (byte)input.ReadByte();
  694. return BitConverter.ToSingle(this.buffer, 0);
  695. }
  696. private int ReadInt(Stream input)
  697. {
  698. return (input.ReadByte() << 24) + (input.ReadByte() << 16) + (input.ReadByte() << 8) + input.ReadByte();
  699. }
  700. private int ReadInt(Stream input, bool optimizePositive)
  701. {
  702. int num = input.ReadByte();
  703. int num2 = num & 127;
  704. if ((num & 128) != 0)
  705. {
  706. num = input.ReadByte();
  707. num2 |= (num & 127) << 7;
  708. if ((num & 128) != 0)
  709. {
  710. num = input.ReadByte();
  711. num2 |= (num & 127) << 14;
  712. if ((num & 128) != 0)
  713. {
  714. num = input.ReadByte();
  715. num2 |= (num & 127) << 21;
  716. if ((num & 128) != 0)
  717. {
  718. num = input.ReadByte();
  719. num2 |= (num & 127) << 28;
  720. }
  721. }
  722. }
  723. }
  724. return (!optimizePositive) ? (num2 >> 1 ^ -(num2 & 1)) : num2;
  725. }
  726. private string ReadString(Stream input)
  727. {
  728. int num = this.ReadInt(input, true);
  729. if (num == 0)
  730. {
  731. return null;
  732. }
  733. if (num != 1)
  734. {
  735. num--;
  736. char[] array = this.chars;
  737. if (array.Length < num)
  738. {
  739. array = (this.chars = new char[num]);
  740. }
  741. int i = 0;
  742. int num2 = 0;
  743. while (i < num)
  744. {
  745. num2 = input.ReadByte();
  746. if (num2 > 127)
  747. {
  748. break;
  749. }
  750. array[i++] = (char)num2;
  751. }
  752. if (i < num)
  753. {
  754. this.ReadUtf8_slow(input, num, i, num2);
  755. }
  756. return new string(array, 0, num);
  757. }
  758. return string.Empty;
  759. }
  760. private void ReadUtf8_slow(Stream input, int charCount, int charIndex, int b)
  761. {
  762. char[] array = this.chars;
  763. for (;;)
  764. {
  765. switch (b >> 4)
  766. {
  767. case 0:
  768. case 1:
  769. case 2:
  770. case 3:
  771. case 4:
  772. case 5:
  773. case 6:
  774. case 7:
  775. array[charIndex] = (char)b;
  776. break;
  777. case 12:
  778. case 13:
  779. array[charIndex] = (char)((b & 31) << 6 | (input.ReadByte() & 63));
  780. break;
  781. case 14:
  782. array[charIndex] = (char)((b & 15) << 12 | (input.ReadByte() & 63) << 6 | (input.ReadByte() & 63));
  783. break;
  784. }
  785. if (++charIndex >= charCount)
  786. {
  787. break;
  788. }
  789. b = (input.ReadByte() & 255);
  790. }
  791. }
  792. public const int TIMELINE_SCALE = 0;
  793. public const int TIMELINE_ROTATE = 1;
  794. public const int TIMELINE_TRANSLATE = 2;
  795. public const int TIMELINE_ATTACHMENT = 3;
  796. public const int TIMELINE_COLOR = 4;
  797. public const int TIMELINE_FLIPX = 5;
  798. public const int TIMELINE_FLIPY = 6;
  799. public const int CURVE_LINEAR = 0;
  800. public const int CURVE_STEPPED = 1;
  801. public const int CURVE_BEZIER = 2;
  802. private AttachmentLoader attachmentLoader;
  803. private char[] chars = new char[32];
  804. private byte[] buffer = new byte[4];
  805. }
  806. }