三国卡牌客户端基础资源仓库
yyl
5 天以前 cec146fc3fe287928e075c79ece20a20a9b16b20
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
/******************************************************************************
 * Spine Runtimes License Agreement
 * Last updated July 28, 2023. Replaces all prior versions.
 *
 * Copyright (c) 2013-2023, Esoteric Software LLC
 *
 * Integration of the Spine Runtimes into software or otherwise creating
 * derivative works of the Spine Runtimes is permitted under the terms and
 * conditions of Section 2 of the Spine Editor License Agreement:
 * http://esotericsoftware.com/spine-editor-license
 *
 * Otherwise, it is permitted to integrate the Spine Runtimes into software or
 * otherwise create derivative works of the Spine Runtimes (collectively,
 * "Products"), provided that each user of the Products must obtain their own
 * Spine Editor license and redistribution of the Products in any form must
 * include this license and copyright notice.
 *
 * THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
 * BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THE
 * SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *****************************************************************************/
 
#if (UNITY_5 || UNITY_5_3_OR_NEWER || UNITY_WSA || UNITY_WP8 || UNITY_WP8_1)
#define IS_UNITY
#endif
 
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.Serialization;
 
#if WINDOWS_STOREAPP
using System.Threading.Tasks;
using Windows.Storage;
#endif
 
namespace Spine {
    public class SkeletonBinary : SkeletonLoader {
        public const int BONE_ROTATE = 0;
        public const int BONE_TRANSLATE = 1;
        public const int BONE_TRANSLATEX = 2;
        public const int BONE_TRANSLATEY = 3;
        public const int BONE_SCALE = 4;
        public const int BONE_SCALEX = 5;
        public const int BONE_SCALEY = 6;
        public const int BONE_SHEAR = 7;
        public const int BONE_SHEARX = 8;
        public const int BONE_SHEARY = 9;
        public const int BONE_INHERIT = 10;
 
        public const int SLOT_ATTACHMENT = 0;
        public const int SLOT_RGBA = 1;
        public const int SLOT_RGB = 2;
        public const int SLOT_RGBA2 = 3;
        public const int SLOT_RGB2 = 4;
        public const int SLOT_ALPHA = 5;
 
        public const int ATTACHMENT_DEFORM = 0;
        public const int ATTACHMENT_SEQUENCE = 1;
 
        public const int PATH_POSITION = 0;
        public const int PATH_SPACING = 1;
        public const int PATH_MIX = 2;
 
        public const int PHYSICS_INERTIA = 0;
        public const int PHYSICS_STRENGTH = 1;
        public const int PHYSICS_DAMPING = 2;
        public const int PHYSICS_MASS = 4;
        public const int PHYSICS_WIND = 5;
        public const int PHYSICS_GRAVITY = 6;
        public const int PHYSICS_MIX = 7;
        public const int PHYSICS_RESET = 8;
 
        public const int CURVE_LINEAR = 0;
        public const int CURVE_STEPPED = 1;
        public const int CURVE_BEZIER = 2;
 
        private readonly List<LinkedMesh> linkedMeshes = new List<LinkedMesh>();
 
        public SkeletonBinary (AttachmentLoader attachmentLoader)
            : base(attachmentLoader) {
        }
 
        public SkeletonBinary (params Atlas[] atlasArray)
            : base(atlasArray) {
        }
 
#if !ISUNITY && WINDOWS_STOREAPP
        private async Task<SkeletonData> ReadFile(string path) {
            var folder = Windows.ApplicationModel.Package.Current.InstalledLocation;
            using (BufferedStream input = new BufferedStream(await folder.GetFileAsync(path).AsTask().ConfigureAwait(false))) {
                SkeletonData skeletonData = ReadSkeletonData(input);
                skeletonData.Name = Path.GetFileNameWithoutExtension(path);
                return skeletonData;
            }
        }
 
        public override SkeletonData ReadSkeletonData (string path) {
            return this.ReadFile(path).Result;
        }
#else
        public override SkeletonData ReadSkeletonData (string path) {
#if WINDOWS_PHONE
            using (BufferedStream input = new BufferedStream(Microsoft.Xna.Framework.TitleContainer.OpenStream(path))) {
#else
            using (FileStream input = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read)) {
#endif
                SkeletonData skeletonData = ReadSkeletonData(input);
                skeletonData.name = Path.GetFileNameWithoutExtension(path);
                return skeletonData;
            }
        }
#endif // WINDOWS_STOREAPP
 
        /// <summary>Returns the version string of binary skeleton data.</summary>
        public static string GetVersionString (Stream file) {
            if (file == null) throw new ArgumentNullException("file");
 
            SkeletonInput input = new SkeletonInput(file);
            return input.GetVersionString();
        }
 
        public SkeletonData ReadSkeletonData (Stream file) {
            if (file == null) throw new ArgumentNullException("file");
            float scale = this.scale;
 
            SkeletonData skeletonData = new SkeletonData();
            SkeletonInput input = new SkeletonInput(file);
 
            long hash = input.ReadLong();
            skeletonData.hash = hash == 0 ? null : hash.ToString();
            skeletonData.version = input.ReadString();
            if (skeletonData.version.Length == 0) skeletonData.version = null;
            // early return for old 3.8 format instead of reading past the end
            if (skeletonData.version.Length > 13) return null;
            skeletonData.x = input.ReadFloat();
            skeletonData.y = input.ReadFloat();
            skeletonData.width = input.ReadFloat();
            skeletonData.height = input.ReadFloat();
            skeletonData.referenceScale = input.ReadFloat() * scale;
 
            bool nonessential = input.ReadBoolean();
 
            if (nonessential) {
                skeletonData.fps = input.ReadFloat();
 
                skeletonData.imagesPath = input.ReadString();
                if (string.IsNullOrEmpty(skeletonData.imagesPath)) skeletonData.imagesPath = null;
 
                skeletonData.audioPath = input.ReadString();
                if (string.IsNullOrEmpty(skeletonData.audioPath)) skeletonData.audioPath = null;
            }
 
            int n;
            Object[] o;
 
            // Strings.
            o = input.strings = new String[n = input.ReadInt(true)];
            for (int i = 0; i < n; i++)
                o[i] = input.ReadString();
 
            // Bones.
            BoneData[] bones = skeletonData.bones.Resize(n = input.ReadInt(true)).Items;
            for (int i = 0; i < n; i++) {
                String name = input.ReadString();
                BoneData parent = i == 0 ? null : bones[input.ReadInt(true)];
                BoneData data = new BoneData(i, name, parent);
                data.rotation = input.ReadFloat();
                data.x = input.ReadFloat() * scale;
                data.y = input.ReadFloat() * scale;
                data.scaleX = input.ReadFloat();
                data.scaleY = input.ReadFloat();
                data.shearX = input.ReadFloat();
                data.shearY = input.ReadFloat();
                data.Length = input.ReadFloat() * scale;
                data.inherit = InheritEnum.Values[input.ReadInt(true)];
                data.skinRequired = input.ReadBoolean();
                if (nonessential) { // discard non-essential data
                    input.ReadInt(); // Color.rgba8888ToColor(data.color, input.readInt());
                    input.ReadString(); // data.icon = input.readString();
                    input.ReadBoolean(); // data.visible = input.readBoolean();
                }
                bones[i] = data;
            }
 
            // Slots.
            SlotData[] slots = skeletonData.slots.Resize(n = input.ReadInt(true)).Items;
            for (int i = 0; i < n; i++) {
                String slotName = input.ReadString();
 
                BoneData boneData = bones[input.ReadInt(true)];
                SlotData slotData = new SlotData(i, slotName, boneData);
                int color = input.ReadInt();
                slotData.r = ((color & 0xff000000) >> 24) / 255f;
                slotData.g = ((color & 0x00ff0000) >> 16) / 255f;
                slotData.b = ((color & 0x0000ff00) >> 8) / 255f;
                slotData.a = ((color & 0x000000ff)) / 255f;
 
                int darkColor = input.ReadInt(); // 0x00rrggbb
                if (darkColor != -1) {
                    slotData.hasSecondColor = true;
                    slotData.r2 = ((darkColor & 0x00ff0000) >> 16) / 255f;
                    slotData.g2 = ((darkColor & 0x0000ff00) >> 8) / 255f;
                    slotData.b2 = ((darkColor & 0x000000ff)) / 255f;
                }
 
                slotData.attachmentName = input.ReadStringRef();
                slotData.blendMode = (BlendMode)input.ReadInt(true);
                if (nonessential) {
                    input.ReadBoolean(); // data.visible = input.readBoolean(); data.path = path;
                }
                slots[i] = slotData;
            }
 
            // IK constraints.
            o = skeletonData.ikConstraints.Resize(n = input.ReadInt(true)).Items;
            for (int i = 0, nn; i < n; i++) {
                IkConstraintData data = new IkConstraintData(input.ReadString());
                data.order = input.ReadInt(true);
                BoneData[] constraintBones = data.bones.Resize(nn = input.ReadInt(true)).Items;
                for (int ii = 0; ii < nn; ii++)
                    constraintBones[ii] = bones[input.ReadInt(true)];
                data.target = bones[input.ReadInt(true)];
                int flags = input.Read();
                data.skinRequired = (flags & 1) != 0;
                data.bendDirection = (flags & 2) != 0 ? 1 : -1;
                data.compress = (flags & 4) != 0;
                data.stretch = (flags & 8) != 0;
                data.uniform = (flags & 16) != 0;
                if ((flags & 32) != 0) data.mix = (flags & 64) != 0 ? input.ReadFloat() : 1;
                if ((flags & 128) != 0) data.softness = input.ReadFloat() * scale;
                o[i] = data;
            }
 
            // Transform constraints.
            o = skeletonData.transformConstraints.Resize(n = input.ReadInt(true)).Items;
            for (int i = 0, nn; i < n; i++) {
                TransformConstraintData data = new TransformConstraintData(input.ReadString());
                data.order = input.ReadInt(true);
                BoneData[] constraintBones = data.bones.Resize(nn = input.ReadInt(true)).Items;
                for (int ii = 0; ii < nn; ii++)
                    constraintBones[ii] = bones[input.ReadInt(true)];
                data.target = bones[input.ReadInt(true)];
                int flags = input.Read();
                data.skinRequired = (flags & 1) != 0;
                data.local = (flags & 2) != 0;
                data.relative = (flags & 4) != 0;
                if ((flags & 8) != 0) data.offsetRotation = input.ReadFloat();
                if ((flags & 16) != 0) data.offsetX = input.ReadFloat() * scale;
                if ((flags & 32) != 0) data.offsetY = input.ReadFloat() * scale;
                if ((flags & 64) != 0) data.offsetScaleX = input.ReadFloat();
                if ((flags & 128) != 0) data.offsetScaleY = input.ReadFloat();
                flags = input.Read();
                if ((flags & 1) != 0) data.offsetShearY = input.ReadFloat();
                if ((flags & 2) != 0) data.mixRotate = input.ReadFloat();
                if ((flags & 4) != 0) data.mixX = input.ReadFloat();
                if ((flags & 8) != 0) data.mixY = input.ReadFloat();
                if ((flags & 16) != 0) data.mixScaleX = input.ReadFloat();
                if ((flags & 32) != 0) data.mixScaleY = input.ReadFloat();
                if ((flags & 64) != 0) data.mixShearY = input.ReadFloat();
                o[i] = data;
            }
 
            // Path constraints
            o = skeletonData.pathConstraints.Resize(n = input.ReadInt(true)).Items;
            for (int i = 0, nn; i < n; i++) {
                PathConstraintData data = new PathConstraintData(input.ReadString());
                data.order = input.ReadInt(true);
                data.skinRequired = input.ReadBoolean();
                BoneData[] constraintBones = data.bones.Resize(nn = input.ReadInt(true)).Items;
                for (int ii = 0; ii < nn; ii++)
                    constraintBones[ii] = bones[input.ReadInt(true)];
                data.target = slots[input.ReadInt(true)];
                int flags = input.Read();
                data.positionMode = (PositionMode)Enum.GetValues(typeof(PositionMode)).GetValue(flags & 1);
                data.spacingMode = (SpacingMode)Enum.GetValues(typeof(SpacingMode)).GetValue((flags >> 1) & 3);
                data.rotateMode = (RotateMode)Enum.GetValues(typeof(RotateMode)).GetValue((flags >> 3) & 3);
                if ((flags & 128) != 0) data.offsetRotation = input.ReadFloat();
 
                data.position = input.ReadFloat();
                if (data.positionMode == PositionMode.Fixed) data.position *= scale;
                data.spacing = input.ReadFloat();
                if (data.spacingMode == SpacingMode.Length || data.spacingMode == SpacingMode.Fixed) data.spacing *= scale;
                data.mixRotate = input.ReadFloat();
                data.mixX = input.ReadFloat();
                data.mixY = input.ReadFloat();
                o[i] = data;
            }
 
            // Physics constraints.
            o = skeletonData.physicsConstraints.Resize(n = input.ReadInt(true)).Items;
            for (int i = 0; i < n; i++) {
                PhysicsConstraintData data = new PhysicsConstraintData(input.ReadString());
                data.order = input.ReadInt(true);
                data.bone = bones[input.ReadInt(true)];
                int flags = input.Read();
                data.skinRequired = (flags & 1) != 0;
                if ((flags & 2) != 0) data.x = input.ReadFloat();
                if ((flags & 4) != 0) data.y = input.ReadFloat();
                if ((flags & 8) != 0) data.rotate = input.ReadFloat();
                if ((flags & 16) != 0) data.scaleX = input.ReadFloat();
                if ((flags & 32) != 0) data.shearX = input.ReadFloat();
                data.limit = ((flags & 64) != 0 ? input.ReadFloat() : 5000) * scale;
                data.step = 1f / input.ReadUByte();
                data.inertia = input.ReadFloat();
                data.strength = input.ReadFloat();
                data.damping = input.ReadFloat();
                data.massInverse = (flags & 128) != 0 ? input.ReadFloat() : 1;
                data.wind = input.ReadFloat();
                data.gravity = input.ReadFloat();
                flags = input.Read();
                if ((flags & 1) != 0) data.inertiaGlobal = true;
                if ((flags & 2) != 0) data.strengthGlobal = true;
                if ((flags & 4) != 0) data.dampingGlobal = true;
                if ((flags & 8) != 0) data.massGlobal = true;
                if ((flags & 16) != 0) data.windGlobal = true;
                if ((flags & 32) != 0) data.gravityGlobal = true;
                if ((flags & 64) != 0) data.mixGlobal = true;
                data.mix = (flags & 128) != 0 ? input.ReadFloat() : 1;
                o[i] = data;
            }
 
            // Default skin.
            Skin defaultSkin = ReadSkin(input, skeletonData, true, nonessential);
            if (defaultSkin != null) {
                skeletonData.defaultSkin = defaultSkin;
                skeletonData.skins.Add(defaultSkin);
            }
 
            // Skins.
            {
                int i = skeletonData.skins.Count;
                o = skeletonData.skins.Resize(n = i + input.ReadInt(true)).Items;
                for (; i < n; i++)
                    o[i] = ReadSkin(input, skeletonData, false, nonessential);
            }
 
            // Linked meshes.
            n = linkedMeshes.Count;
            for (int i = 0; i < n; i++) {
                LinkedMesh linkedMesh = linkedMeshes[i];
                Skin skin = skeletonData.skins.Items[linkedMesh.skinIndex];
                Attachment parent = skin.GetAttachment(linkedMesh.slotIndex, linkedMesh.parent);
                if (parent == null) throw new Exception("Parent mesh not found: " + linkedMesh.parent);
                linkedMesh.mesh.TimelineAttachment = linkedMesh.inheritTimelines ? (VertexAttachment)parent : linkedMesh.mesh;
                linkedMesh.mesh.ParentMesh = (MeshAttachment)parent;
                if (linkedMesh.mesh.Sequence == null) linkedMesh.mesh.UpdateRegion();
            }
            linkedMeshes.Clear();
 
            // Events.
            o = skeletonData.events.Resize(n = input.ReadInt(true)).Items;
            for (int i = 0; i < n; i++) {
                EventData data = new EventData(input.ReadString());
                data.Int = input.ReadInt(false);
                data.Float = input.ReadFloat();
                data.String = input.ReadString();
                data.AudioPath = input.ReadString();
                if (data.AudioPath != null) {
                    data.Volume = input.ReadFloat();
                    data.Balance = input.ReadFloat();
                }
                o[i] = data;
            }
 
            // Animations.
            o = skeletonData.animations.Resize(n = input.ReadInt(true)).Items;
            for (int i = 0; i < n; i++)
                o[i] = ReadAnimation(input.ReadString(), input, skeletonData);
 
            return skeletonData;
        }
 
        /// <returns>May be null.</returns>
        private Skin ReadSkin (SkeletonInput input, SkeletonData skeletonData, bool defaultSkin, bool nonessential) {
 
            Skin skin;
            int slotCount;
 
            if (defaultSkin) {
                slotCount = input.ReadInt(true);
                if (slotCount == 0) return null;
                skin = new Skin("default");
            } else {
                skin = new Skin(input.ReadString());
 
                if (nonessential) input.ReadInt(); // discard, Color.rgba8888ToColor(skin.color, input.readInt());
 
                Object[] bones = skin.bones.Resize(input.ReadInt(true)).Items;
                BoneData[] bonesItems = skeletonData.bones.Items;
                for (int i = 0, n = skin.bones.Count; i < n; i++)
                    bones[i] = bonesItems[input.ReadInt(true)];
 
                IkConstraintData[] ikConstraintsItems = skeletonData.ikConstraints.Items;
                for (int i = 0, n = input.ReadInt(true); i < n; i++)
                    skin.constraints.Add(ikConstraintsItems[input.ReadInt(true)]);
                TransformConstraintData[] transformConstraintsItems = skeletonData.transformConstraints.Items;
                for (int i = 0, n = input.ReadInt(true); i < n; i++)
                    skin.constraints.Add(transformConstraintsItems[input.ReadInt(true)]);
                PathConstraintData[] pathConstraintsItems = skeletonData.pathConstraints.Items;
                for (int i = 0, n = input.ReadInt(true); i < n; i++)
                    skin.constraints.Add(pathConstraintsItems[input.ReadInt(true)]);
                PhysicsConstraintData[] physicsConstraintsItems = skeletonData.physicsConstraints.Items;
                for (int i = 0, n = input.ReadInt(true); i < n; i++)
                    skin.constraints.Add(physicsConstraintsItems[input.ReadInt(true)]);
                skin.constraints.TrimExcess();
 
                slotCount = input.ReadInt(true);
            }
            for (int i = 0; i < slotCount; i++) {
                int slotIndex = input.ReadInt(true);
                for (int ii = 0, nn = input.ReadInt(true); ii < nn; ii++) {
                    String name = input.ReadStringRef();
                    Attachment attachment = ReadAttachment(input, skeletonData, skin, slotIndex, name, nonessential);
                    if (attachment != null) skin.SetAttachment(slotIndex, name, attachment);
                }
            }
            return skin;
        }
 
        private Attachment ReadAttachment (SkeletonInput input, SkeletonData skeletonData, Skin skin, int slotIndex,
            String attachmentName, bool nonessential) {
            float scale = this.scale;
 
            int flags = input.ReadUByte();
            string name = (flags & 8) != 0 ? input.ReadStringRef() : attachmentName;
 
            switch ((AttachmentType)(flags & 0x7)) { // 0b111
            case AttachmentType.Region: {
                string path = (flags & 16) != 0 ? input.ReadStringRef() : null;
                uint color = (flags & 32) != 0 ? (uint)input.ReadInt() : 0xffffffff;
                Sequence sequence = (flags & 64) != 0 ? ReadSequence(input) : null;
                float rotation = (flags & 128) != 0 ? input.ReadFloat() : 0;
                float x = input.ReadFloat();
                float y = input.ReadFloat();
                float scaleX = input.ReadFloat();
                float scaleY = input.ReadFloat();
                float width = input.ReadFloat();
                float height = input.ReadFloat();
 
                if (path == null) path = name;
                RegionAttachment region = attachmentLoader.NewRegionAttachment(skin, name, path, sequence);
                if (region == null) return null;
                region.Path = path;
                region.x = x * scale;
                region.y = y * scale;
                region.scaleX = scaleX;
                region.scaleY = scaleY;
                region.rotation = rotation;
                region.width = width * scale;
                region.height = height * scale;
                region.r = ((color & 0xff000000) >> 24) / 255f;
                region.g = ((color & 0x00ff0000) >> 16) / 255f;
                region.b = ((color & 0x0000ff00) >> 8) / 255f;
                region.a = ((color & 0x000000ff)) / 255f;
                region.sequence = sequence;
                if (sequence == null) region.UpdateRegion();
                return region;
            }
            case AttachmentType.Boundingbox: {
                Vertices vertices = ReadVertices(input, (flags & 16) != 0);
                if (nonessential) input.ReadInt(); // discard, int color = nonessential ? input.readInt() : 0;
 
                BoundingBoxAttachment box = attachmentLoader.NewBoundingBoxAttachment(skin, name);
                if (box == null) return null;
                box.worldVerticesLength = vertices.length;
                box.vertices = vertices.vertices;
                box.bones = vertices.bones;
                // skipped porting: if (nonessential) Color.rgba8888ToColor(box.getColor(), color);
                return box;
            }
            case AttachmentType.Mesh: {
                string path = (flags & 16) != 0 ? input.ReadStringRef() : name;
                uint color = (flags & 32) != 0 ? (uint)input.ReadInt() : 0xffffffff;
                Sequence sequence = (flags & 64) != 0 ? ReadSequence(input) : null;
                int hullLength = input.ReadInt(true);
                Vertices vertices = ReadVertices(input, (flags & 128) != 0);
                float[] uvs = ReadFloatArray(input, vertices.length, 1);
                int[] triangles = ReadShortArray(input, (vertices.length - hullLength - 2) * 3);
 
                int[] edges = null;
                float width = 0, height = 0;
                if (nonessential) {
                    edges = ReadShortArray(input, input.ReadInt(true));
                    width = input.ReadFloat();
                    height = input.ReadFloat();
                }
 
                MeshAttachment mesh = attachmentLoader.NewMeshAttachment(skin, name, path, sequence);
                if (mesh == null) return null;
                mesh.Path = path;
                mesh.r = ((color & 0xff000000) >> 24) / 255f;
                mesh.g = ((color & 0x00ff0000) >> 16) / 255f;
                mesh.b = ((color & 0x0000ff00) >> 8) / 255f;
                mesh.a = ((color & 0x000000ff)) / 255f;
                mesh.bones = vertices.bones;
                mesh.vertices = vertices.vertices;
                mesh.WorldVerticesLength = vertices.length;
                mesh.triangles = triangles;
                mesh.regionUVs = uvs;
                if (sequence == null) mesh.UpdateRegion();
                mesh.HullLength = hullLength << 1;
                mesh.Sequence = sequence;
                if (nonessential) {
                    mesh.Edges = edges;
                    mesh.Width = width * scale;
                    mesh.Height = height * scale;
                }
                return mesh;
            }
            case AttachmentType.Linkedmesh: {
                String path = (flags & 16) != 0 ? input.ReadStringRef() : name;
                uint color = (flags & 32) != 0 ? (uint)input.ReadInt() : 0xffffffff;
                Sequence sequence = (flags & 64) != 0 ? ReadSequence(input) : null;
                bool inheritTimelines = (flags & 128) != 0;
                int skinIndex = input.ReadInt(true);
                string parent = input.ReadStringRef();
                float width = 0, height = 0;
                if (nonessential) {
                    width = input.ReadFloat();
                    height = input.ReadFloat();
                }
 
                MeshAttachment mesh = attachmentLoader.NewMeshAttachment(skin, name, path, sequence);
                if (mesh == null) return null;
                mesh.Path = path;
                mesh.r = ((color & 0xff000000) >> 24) / 255f;
                mesh.g = ((color & 0x00ff0000) >> 16) / 255f;
                mesh.b = ((color & 0x0000ff00) >> 8) / 255f;
                mesh.a = ((color & 0x000000ff)) / 255f;
                mesh.Sequence = sequence;
                if (nonessential) {
                    mesh.Width = width * scale;
                    mesh.Height = height * scale;
                }
                linkedMeshes.Add(new LinkedMesh(mesh, skinIndex, slotIndex, parent, inheritTimelines));
                return mesh;
            }
            case AttachmentType.Path: {
                bool closed = (flags & 16) != 0;
                bool constantSpeed = (flags & 32) != 0;
                Vertices vertices = ReadVertices(input, (flags & 64) != 0);
                float[] lengths = new float[vertices.length / 6];
                for (int i = 0, n = lengths.Length; i < n; i++)
                    lengths[i] = input.ReadFloat() * scale;
                if (nonessential) input.ReadInt(); //int color = nonessential ? input.ReadInt() : 0;
 
                PathAttachment path = attachmentLoader.NewPathAttachment(skin, name);
                if (path == null) return null;
                path.closed = closed;
                path.constantSpeed = constantSpeed;
                path.worldVerticesLength = vertices.length;
                path.vertices = vertices.vertices;
                path.bones = vertices.bones;
                path.lengths = lengths;
                // skipped porting: if (nonessential) Color.rgba8888ToColor(path.getColor(), color);
                return path;
            }
            case AttachmentType.Point: {
                float rotation = input.ReadFloat();
                float x = input.ReadFloat();
                float y = input.ReadFloat();
                if (nonessential) input.ReadInt(); //int color = nonessential ? input.ReadInt() : 0;
 
                PointAttachment point = attachmentLoader.NewPointAttachment(skin, name);
                if (point == null) return null;
                point.x = x * scale;
                point.y = y * scale;
                point.rotation = rotation;
                // skipped porting: if (nonessential) point.color = color;
                return point;
            }
            case AttachmentType.Clipping: {
                int endSlotIndex = input.ReadInt(true);
                Vertices vertices = ReadVertices(input, (flags & 16) != 0);
                if (nonessential) input.ReadInt();
 
                ClippingAttachment clip = attachmentLoader.NewClippingAttachment(skin, name);
                if (clip == null) return null;
                clip.EndSlot = skeletonData.slots.Items[endSlotIndex];
                clip.worldVerticesLength = vertices.length;
                clip.vertices = vertices.vertices;
                clip.bones = vertices.bones;
                // skipped porting: if (nonessential) Color.rgba8888ToColor(clip.getColor(), color);
                return clip;
            }
            }
            return null;
        }
 
        private Sequence ReadSequence (SkeletonInput input) {
            Sequence sequence = new Sequence(input.ReadInt(true));
            sequence.Start = input.ReadInt(true);
            sequence.Digits = input.ReadInt(true);
            sequence.SetupIndex = input.ReadInt(true);
            return sequence;
        }
 
        private Vertices ReadVertices (SkeletonInput input, bool weighted) {
            float scale = this.scale;
            int vertexCount = input.ReadInt(true);
            Vertices vertices = new Vertices();
            vertices.length = vertexCount << 1;
            if (!weighted) {
                vertices.vertices = ReadFloatArray(input, vertices.length, scale);
                return vertices;
            }
            ExposedList<float> weights = new ExposedList<float>(vertices.length * 3 * 3);
            ExposedList<int> bonesArray = new ExposedList<int>(vertices.length * 3);
            for (int i = 0; i < vertexCount; i++) {
                int boneCount = input.ReadInt(true);
                bonesArray.Add(boneCount);
                for (int ii = 0; ii < boneCount; ii++) {
                    bonesArray.Add(input.ReadInt(true));
                    weights.Add(input.ReadFloat() * scale);
                    weights.Add(input.ReadFloat() * scale);
                    weights.Add(input.ReadFloat());
                }
            }
 
            vertices.vertices = weights.ToArray();
            vertices.bones = bonesArray.ToArray();
            return vertices;
        }
 
        private float[] ReadFloatArray (SkeletonInput input, int n, float scale) {
            float[] array = new float[n];
            if (scale == 1) {
                for (int i = 0; i < n; i++)
                    array[i] = input.ReadFloat();
            } else {
                for (int i = 0; i < n; i++)
                    array[i] = input.ReadFloat() * scale;
            }
            return array;
        }
 
        private int[] ReadShortArray (SkeletonInput input, int n) {
            int[] array = new int[n];
            for (int i = 0; i < n; i++)
                array[i] = input.ReadInt(true);
            return array;
        }
 
        /// <exception cref="SerializationException">SerializationException will be thrown when a Vertex attachment is not found.</exception>
        /// <exception cref="IOException">Throws IOException when a read operation fails.</exception>
        private Animation ReadAnimation (String name, SkeletonInput input, SkeletonData skeletonData) {
            ExposedList<Timeline> timelines = new ExposedList<Timeline>(input.ReadInt(true));
            float scale = this.scale;
 
            // Slot timelines.
            for (int i = 0, n = input.ReadInt(true); i < n; i++) {
                int slotIndex = input.ReadInt(true);
                for (int ii = 0, nn = input.ReadInt(true); ii < nn; ii++) {
                    int timelineType = input.ReadUByte(), frameCount = input.ReadInt(true), frameLast = frameCount - 1;
                    switch (timelineType) {
                    case SLOT_ATTACHMENT: {
                        AttachmentTimeline timeline = new AttachmentTimeline(frameCount, slotIndex);
                        for (int frame = 0; frame < frameCount; frame++)
                            timeline.SetFrame(frame, input.ReadFloat(), input.ReadStringRef());
                        timelines.Add(timeline);
                        break;
                    }
                    case SLOT_RGBA: {
                        RGBATimeline timeline = new RGBATimeline(frameCount, input.ReadInt(true), slotIndex);
                        float time = input.ReadFloat();
                        float r = input.Read() / 255f, g = input.Read() / 255f;
                        float b = input.Read() / 255f, a = input.Read() / 255f;
                        for (int frame = 0, bezier = 0; ; frame++) {
                            timeline.SetFrame(frame, time, r, g, b, a);
                            if (frame == frameLast) break;
                            float time2 = input.ReadFloat();
                            float r2 = input.Read() / 255f, g2 = input.Read() / 255f;
                            float b2 = input.Read() / 255f, a2 = input.Read() / 255f;
                            switch (input.ReadUByte()) {
                            case CURVE_STEPPED:
                                timeline.SetStepped(frame);
                                break;
                            case CURVE_BEZIER:
                                SetBezier(input, timeline, bezier++, frame, 0, time, time2, r, r2, 1);
                                SetBezier(input, timeline, bezier++, frame, 1, time, time2, g, g2, 1);
                                SetBezier(input, timeline, bezier++, frame, 2, time, time2, b, b2, 1);
                                SetBezier(input, timeline, bezier++, frame, 3, time, time2, a, a2, 1);
                                break;
                            }
                            time = time2;
                            r = r2;
                            g = g2;
                            b = b2;
                            a = a2;
                        }
                        timelines.Add(timeline);
                        break;
                    }
                    case SLOT_RGB: {
                        RGBTimeline timeline = new RGBTimeline(frameCount, input.ReadInt(true), slotIndex);
                        float time = input.ReadFloat();
                        float r = input.Read() / 255f, g = input.Read() / 255f, b = input.Read() / 255f;
                        for (int frame = 0, bezier = 0; ; frame++) {
                            timeline.SetFrame(frame, time, r, g, b);
                            if (frame == frameLast) break;
                            float time2 = input.ReadFloat();
                            float r2 = input.Read() / 255f, g2 = input.Read() / 255f, b2 = input.Read() / 255f;
                            switch (input.ReadUByte()) {
                            case CURVE_STEPPED:
                                timeline.SetStepped(frame);
                                break;
                            case CURVE_BEZIER:
                                SetBezier(input, timeline, bezier++, frame, 0, time, time2, r, r2, 1);
                                SetBezier(input, timeline, bezier++, frame, 1, time, time2, g, g2, 1);
                                SetBezier(input, timeline, bezier++, frame, 2, time, time2, b, b2, 1);
                                break;
                            }
                            time = time2;
                            r = r2;
                            g = g2;
                            b = b2;
                        }
                        timelines.Add(timeline);
                        break;
                    }
                    case SLOT_RGBA2: {
                        RGBA2Timeline timeline = new RGBA2Timeline(frameCount, input.ReadInt(true), slotIndex);
                        float time = input.ReadFloat();
                        float r = input.Read() / 255f, g = input.Read() / 255f;
                        float b = input.Read() / 255f, a = input.Read() / 255f;
                        float r2 = input.Read() / 255f, g2 = input.Read() / 255f, b2 = input.Read() / 255f;
                        for (int frame = 0, bezier = 0; ; frame++) {
                            timeline.SetFrame(frame, time, r, g, b, a, r2, g2, b2);
                            if (frame == frameLast) break;
                            float time2 = input.ReadFloat();
                            float nr = input.Read() / 255f, ng = input.Read() / 255f;
                            float nb = input.Read() / 255f, na = input.Read() / 255f;
                            float nr2 = input.Read() / 255f, ng2 = input.Read() / 255f, nb2 = input.Read() / 255f;
                            switch (input.ReadUByte()) {
                            case CURVE_STEPPED:
                                timeline.SetStepped(frame);
                                break;
                            case CURVE_BEZIER:
                                SetBezier(input, timeline, bezier++, frame, 0, time, time2, r, nr, 1);
                                SetBezier(input, timeline, bezier++, frame, 1, time, time2, g, ng, 1);
                                SetBezier(input, timeline, bezier++, frame, 2, time, time2, b, nb, 1);
                                SetBezier(input, timeline, bezier++, frame, 3, time, time2, a, na, 1);
                                SetBezier(input, timeline, bezier++, frame, 4, time, time2, r2, nr2, 1);
                                SetBezier(input, timeline, bezier++, frame, 5, time, time2, g2, ng2, 1);
                                SetBezier(input, timeline, bezier++, frame, 6, time, time2, b2, nb2, 1);
                                break;
                            }
                            time = time2;
                            r = nr;
                            g = ng;
                            b = nb;
                            a = na;
                            r2 = nr2;
                            g2 = ng2;
                            b2 = nb2;
                        }
                        timelines.Add(timeline);
                        break;
                    }
                    case SLOT_RGB2: {
                        RGB2Timeline timeline = new RGB2Timeline(frameCount, input.ReadInt(true), slotIndex);
                        float time = input.ReadFloat();
                        float r = input.Read() / 255f, g = input.Read() / 255f, b = input.Read() / 255f;
                        float r2 = input.Read() / 255f, g2 = input.Read() / 255f, b2 = input.Read() / 255f;
                        for (int frame = 0, bezier = 0; ; frame++) {
                            timeline.SetFrame(frame, time, r, g, b, r2, g2, b2);
                            if (frame == frameLast) break;
                            float time2 = input.ReadFloat();
                            float nr = input.Read() / 255f, ng = input.Read() / 255f, nb = input.Read() / 255f;
                            float nr2 = input.Read() / 255f, ng2 = input.Read() / 255f, nb2 = input.Read() / 255f;
                            switch (input.ReadUByte()) {
                            case CURVE_STEPPED:
                                timeline.SetStepped(frame);
                                break;
                            case CURVE_BEZIER:
                                SetBezier(input, timeline, bezier++, frame, 0, time, time2, r, nr, 1);
                                SetBezier(input, timeline, bezier++, frame, 1, time, time2, g, ng, 1);
                                SetBezier(input, timeline, bezier++, frame, 2, time, time2, b, nb, 1);
                                SetBezier(input, timeline, bezier++, frame, 3, time, time2, r2, nr2, 1);
                                SetBezier(input, timeline, bezier++, frame, 4, time, time2, g2, ng2, 1);
                                SetBezier(input, timeline, bezier++, frame, 5, time, time2, b2, nb2, 1);
                                break;
                            }
                            time = time2;
                            r = nr;
                            g = ng;
                            b = nb;
                            r2 = nr2;
                            g2 = ng2;
                            b2 = nb2;
                        }
                        timelines.Add(timeline);
                        break;
                    }
                    case SLOT_ALPHA: {
                        AlphaTimeline timeline = new AlphaTimeline(frameCount, input.ReadInt(true), slotIndex);
                        float time = input.ReadFloat(), a = input.Read() / 255f;
                        for (int frame = 0, bezier = 0; ; frame++) {
                            timeline.SetFrame(frame, time, a);
                            if (frame == frameLast) break;
                            float time2 = input.ReadFloat();
                            float a2 = input.Read() / 255f;
                            switch (input.ReadUByte()) {
                            case CURVE_STEPPED:
                                timeline.SetStepped(frame);
                                break;
                            case CURVE_BEZIER:
                                SetBezier(input, timeline, bezier++, frame, 0, time, time2, a, a2, 1);
                                break;
                            }
                            time = time2;
                            a = a2;
                        }
                        timelines.Add(timeline);
                        break;
                    }
                    }
                }
            }
 
            // Bone timelines.
            for (int i = 0, n = input.ReadInt(true); i < n; i++) {
                int boneIndex = input.ReadInt(true);
                for (int ii = 0, nn = input.ReadInt(true); ii < nn; ii++) {
                    int type = input.ReadUByte(), frameCount = input.ReadInt(true);
                    if (type == BONE_INHERIT) {
                        InheritTimeline timeline = new InheritTimeline(frameCount, boneIndex);
                        for (int frame = 0; frame < frameCount; frame++)
                            timeline.SetFrame(frame, input.ReadFloat(), InheritEnum.Values[input.ReadUByte()]);
                        timelines.Add(timeline);
                        continue;
                    }
                    int bezierCount = input.ReadInt(true);
                    switch (type) {
                    case BONE_ROTATE:
                        ReadTimeline(input, timelines, new RotateTimeline(frameCount, bezierCount, boneIndex), 1);
                        break;
                    case BONE_TRANSLATE:
                        ReadTimeline(input, timelines, new TranslateTimeline(frameCount, bezierCount, boneIndex), scale);
                        break;
                    case BONE_TRANSLATEX:
                        ReadTimeline(input, timelines, new TranslateXTimeline(frameCount, bezierCount, boneIndex), scale);
                        break;
                    case BONE_TRANSLATEY:
                        ReadTimeline(input, timelines, new TranslateYTimeline(frameCount, bezierCount, boneIndex), scale);
                        break;
                    case BONE_SCALE:
                        ReadTimeline(input, timelines, new ScaleTimeline(frameCount, bezierCount, boneIndex), 1);
                        break;
                    case BONE_SCALEX:
                        ReadTimeline(input, timelines, new ScaleXTimeline(frameCount, bezierCount, boneIndex), 1);
                        break;
                    case BONE_SCALEY:
                        ReadTimeline(input, timelines, new ScaleYTimeline(frameCount, bezierCount, boneIndex), 1);
                        break;
                    case BONE_SHEAR:
                        ReadTimeline(input, timelines, new ShearTimeline(frameCount, bezierCount, boneIndex), 1);
                        break;
                    case BONE_SHEARX:
                        ReadTimeline(input, timelines, new ShearXTimeline(frameCount, bezierCount, boneIndex), 1);
                        break;
                    case BONE_SHEARY:
                        ReadTimeline(input, timelines, new ShearYTimeline(frameCount, bezierCount, boneIndex), 1);
                        break;
                    }
                }
            }
 
            // IK constraint timelines.
            for (int i = 0, n = input.ReadInt(true); i < n; i++) {
                int index = input.ReadInt(true), frameCount = input.ReadInt(true), frameLast = frameCount - 1;
                IkConstraintTimeline timeline = new IkConstraintTimeline(frameCount, input.ReadInt(true), index);
                int flags = input.Read();
                float time = input.ReadFloat(), mix = (flags & 1) != 0 ? ((flags & 2) != 0 ? input.ReadFloat() : 1) : 0;
                float softness = (flags & 4) != 0 ? input.ReadFloat() * scale : 0;
                for (int frame = 0, bezier = 0; ; frame++) {
                    timeline.SetFrame(frame, time, mix, softness, (flags & 8) != 0 ? 1 : -1, (flags & 16) != 0, (flags & 32) != 0);
 
                    if (frame == frameLast) break;
                    flags = input.Read();
                    float time2 = input.ReadFloat(), mix2 = (flags & 1) != 0 ? ((flags & 2) != 0 ? input.ReadFloat() : 1) : 0;
                    float softness2 = (flags & 4) != 0 ? input.ReadFloat() * scale : 0;
                    if ((flags & 64) != 0)
                        timeline.SetStepped(frame);
                    else if ((flags & 128) != 0) {
                        SetBezier(input, timeline, bezier++, frame, 0, time, time2, mix, mix2, 1);
                        SetBezier(input, timeline, bezier++, frame, 1, time, time2, softness, softness2, scale);
                    }
                    time = time2;
                    mix = mix2;
                    softness = softness2;
                }
                timelines.Add(timeline);
            }
 
            // Transform constraint timelines.
            for (int i = 0, n = input.ReadInt(true); i < n; i++) {
                int index = input.ReadInt(true), frameCount = input.ReadInt(true), frameLast = frameCount - 1;
                TransformConstraintTimeline timeline = new TransformConstraintTimeline(frameCount, input.ReadInt(true), index);
                float time = input.ReadFloat(), mixRotate = input.ReadFloat(), mixX = input.ReadFloat(), mixY = input.ReadFloat(),
                mixScaleX = input.ReadFloat(), mixScaleY = input.ReadFloat(), mixShearY = input.ReadFloat();
                for (int frame = 0, bezier = 0; ; frame++) {
                    timeline.SetFrame(frame, time, mixRotate, mixX, mixY, mixScaleX, mixScaleY, mixShearY);
                    if (frame == frameLast) break;
                    float time2 = input.ReadFloat(), mixRotate2 = input.ReadFloat(), mixX2 = input.ReadFloat(), mixY2 = input.ReadFloat(),
                    mixScaleX2 = input.ReadFloat(), mixScaleY2 = input.ReadFloat(), mixShearY2 = input.ReadFloat();
                    switch (input.ReadUByte()) {
                    case CURVE_STEPPED:
                        timeline.SetStepped(frame);
                        break;
                    case CURVE_BEZIER:
                        SetBezier(input, timeline, bezier++, frame, 0, time, time2, mixRotate, mixRotate2, 1);
                        SetBezier(input, timeline, bezier++, frame, 1, time, time2, mixX, mixX2, 1);
                        SetBezier(input, timeline, bezier++, frame, 2, time, time2, mixY, mixY2, 1);
                        SetBezier(input, timeline, bezier++, frame, 3, time, time2, mixScaleX, mixScaleX2, 1);
                        SetBezier(input, timeline, bezier++, frame, 4, time, time2, mixScaleY, mixScaleY2, 1);
                        SetBezier(input, timeline, bezier++, frame, 5, time, time2, mixShearY, mixShearY2, 1);
                        break;
                    }
                    time = time2;
                    mixRotate = mixRotate2;
                    mixX = mixX2;
                    mixY = mixY2;
                    mixScaleX = mixScaleX2;
                    mixScaleY = mixScaleY2;
                    mixShearY = mixShearY2;
                }
                timelines.Add(timeline);
            }
 
            // Path constraint timelines.
            for (int i = 0, n = input.ReadInt(true); i < n; i++) {
                int index = input.ReadInt(true);
                PathConstraintData data = skeletonData.pathConstraints.Items[index];
                for (int ii = 0, nn = input.ReadInt(true); ii < nn; ii++) {
                    int type = input.ReadUByte(), frameCount = input.ReadInt(true), bezierCount = input.ReadInt(true);
                    switch (type) {
                    case PATH_POSITION:
                        ReadTimeline(input, timelines, new PathConstraintPositionTimeline(frameCount, bezierCount, index),
                            data.positionMode == PositionMode.Fixed ? scale : 1);
                        break;
                    case PATH_SPACING:
                        ReadTimeline(input, timelines, new PathConstraintSpacingTimeline(frameCount, bezierCount, index),
                            data.spacingMode == SpacingMode.Length || data.spacingMode == SpacingMode.Fixed ? scale : 1);
                        break;
                    case PATH_MIX:
                        PathConstraintMixTimeline timeline = new PathConstraintMixTimeline(frameCount, bezierCount, index);
                        float time = input.ReadFloat(), mixRotate = input.ReadFloat(), mixX = input.ReadFloat(), mixY = input.ReadFloat();
                        for (int frame = 0, bezier = 0, frameLast = timeline.FrameCount - 1; ; frame++) {
                            timeline.SetFrame(frame, time, mixRotate, mixX, mixY);
                            if (frame == frameLast) break;
                            float time2 = input.ReadFloat(), mixRotate2 = input.ReadFloat(), mixX2 = input.ReadFloat(),
                                mixY2 = input.ReadFloat();
                            switch (input.ReadUByte()) {
                            case CURVE_STEPPED:
                                timeline.SetStepped(frame);
                                break;
                            case CURVE_BEZIER:
                                SetBezier(input, timeline, bezier++, frame, 0, time, time2, mixRotate, mixRotate2, 1);
                                SetBezier(input, timeline, bezier++, frame, 1, time, time2, mixX, mixX2, 1);
                                SetBezier(input, timeline, bezier++, frame, 2, time, time2, mixY, mixY2, 1);
                                break;
                            }
                            time = time2;
                            mixRotate = mixRotate2;
                            mixX = mixX2;
                            mixY = mixY2;
                        }
                        timelines.Add(timeline);
                        break;
                    }
                }
            }
 
            // Physics timelines.
            for (int i = 0, n = input.ReadInt(true); i < n; i++) {
                int index = input.ReadInt(true) - 1;
                for (int ii = 0, nn = input.ReadInt(true); ii < nn; ii++) {
                    int type = input.ReadUByte(), frameCount = input.ReadInt(true);
                    if (type == PHYSICS_RESET) {
                        PhysicsConstraintResetTimeline timeline = new PhysicsConstraintResetTimeline(frameCount, index);
                        for (int frame = 0; frame < frameCount; frame++)
                            timeline.SetFrame(frame, input.ReadFloat());
                        timelines.Add(timeline);
                        continue;
                    }
                    int bezierCount = input.ReadInt(true);
                    switch (type) {
                    case PHYSICS_INERTIA:
                        ReadTimeline(input, timelines, new PhysicsConstraintInertiaTimeline(frameCount, bezierCount, index), 1);
                        break;
                    case PHYSICS_STRENGTH:
                        ReadTimeline(input, timelines, new PhysicsConstraintStrengthTimeline(frameCount, bezierCount, index), 1);
                        break;
                    case PHYSICS_DAMPING:
                        ReadTimeline(input, timelines, new PhysicsConstraintDampingTimeline(frameCount, bezierCount, index), 1);
                        break;
                    case PHYSICS_MASS:
                        ReadTimeline(input, timelines, new PhysicsConstraintMassTimeline(frameCount, bezierCount, index), 1);
                        break;
                    case PHYSICS_WIND:
                        ReadTimeline(input, timelines, new PhysicsConstraintWindTimeline(frameCount, bezierCount, index), 1);
                        break;
                    case PHYSICS_GRAVITY:
                        ReadTimeline(input, timelines, new PhysicsConstraintGravityTimeline(frameCount, bezierCount, index), 1);
                        break;
                    case PHYSICS_MIX:
                        ReadTimeline(input, timelines, new PhysicsConstraintMixTimeline(frameCount, bezierCount, index), 1);
                        break;
                    }
                }
            }
 
            // Attachment timelines.
            for (int i = 0, n = input.ReadInt(true); i < n; i++) {
                Skin skin = skeletonData.skins.Items[input.ReadInt(true)];
                for (int ii = 0, nn = input.ReadInt(true); ii < nn; ii++) {
                    int slotIndex = input.ReadInt(true);
                    for (int iii = 0, nnn = input.ReadInt(true); iii < nnn; iii++) {
                        String attachmentName = input.ReadStringRef();
                        Attachment attachment = skin.GetAttachment(slotIndex, attachmentName);
                        if (attachment == null) throw new SerializationException("Timeline attachment not found: " + attachmentName);
 
                        int timelineType = input.ReadUByte(), frameCount = input.ReadInt(true), frameLast = frameCount - 1;
                        switch (timelineType) {
                        case ATTACHMENT_DEFORM: {
                            VertexAttachment vertexAttachment = (VertexAttachment)attachment;
                            bool weighted = vertexAttachment.Bones != null;
                            float[] vertices = vertexAttachment.Vertices;
                            int deformLength = weighted ? (vertices.Length / 3) << 1 : vertices.Length;
 
                            DeformTimeline timeline = new DeformTimeline(frameCount, input.ReadInt(true), slotIndex, vertexAttachment);
 
                            float time = input.ReadFloat();
                            for (int frame = 0, bezier = 0; ; frame++) {
                                float[] deform;
                                int end = input.ReadInt(true);
                                if (end == 0)
                                    deform = weighted ? new float[deformLength] : vertices;
                                else {
                                    deform = new float[deformLength];
                                    int start = input.ReadInt(true);
                                    end += start;
                                    if (scale == 1) {
                                        for (int v = start; v < end; v++)
                                            deform[v] = input.ReadFloat();
                                    } else {
                                        for (int v = start; v < end; v++)
                                            deform[v] = input.ReadFloat() * scale;
                                    }
                                    if (!weighted) {
                                        for (int v = 0, vn = deform.Length; v < vn; v++)
                                            deform[v] += vertices[v];
                                    }
                                }
                                timeline.SetFrame(frame, time, deform);
                                if (frame == frameLast) break;
                                float time2 = input.ReadFloat();
                                switch (input.ReadUByte()) {
                                case CURVE_STEPPED:
                                    timeline.SetStepped(frame);
                                    break;
                                case CURVE_BEZIER:
                                    SetBezier(input, timeline, bezier++, frame, 0, time, time2, 0, 1, 1);
                                    break;
                                }
                                time = time2;
                            }
                            timelines.Add(timeline);
                            break;
                        }
                        case ATTACHMENT_SEQUENCE: {
                            SequenceTimeline timeline = new SequenceTimeline(frameCount, slotIndex, attachment);
                            for (int frame = 0; frame < frameCount; frame++) {
                                float time = input.ReadFloat();
                                int modeAndIndex = input.ReadInt();
                                timeline.SetFrame(frame, time, (SequenceMode)(modeAndIndex & 0xf), modeAndIndex >> 4,
                                    input.ReadFloat());
                            }
                            timelines.Add(timeline);
                            break;
                        } // end case
                        } // end switch
                    }
                }
            }
 
            // Draw order timeline.
            int drawOrderCount = input.ReadInt(true);
            if (drawOrderCount > 0) {
                DrawOrderTimeline timeline = new DrawOrderTimeline(drawOrderCount);
                int slotCount = skeletonData.slots.Count;
                for (int i = 0; i < drawOrderCount; i++) {
                    float time = input.ReadFloat();
                    int offsetCount = input.ReadInt(true);
                    int[] drawOrder = new int[slotCount];
                    for (int ii = slotCount - 1; ii >= 0; ii--)
                        drawOrder[ii] = -1;
                    int[] unchanged = new int[slotCount - offsetCount];
                    int originalIndex = 0, unchangedIndex = 0;
                    for (int ii = 0; ii < offsetCount; ii++) {
                        int slotIndex = input.ReadInt(true);
                        // Collect unchanged items.
                        while (originalIndex != slotIndex)
                            unchanged[unchangedIndex++] = originalIndex++;
                        // Set changed items.
                        drawOrder[originalIndex + input.ReadInt(true)] = originalIndex++;
                    }
                    // Collect remaining unchanged items.
                    while (originalIndex < slotCount)
                        unchanged[unchangedIndex++] = originalIndex++;
                    // Fill in unchanged items.
                    for (int ii = slotCount - 1; ii >= 0; ii--)
                        if (drawOrder[ii] == -1) drawOrder[ii] = unchanged[--unchangedIndex];
                    timeline.SetFrame(i, time, drawOrder);
                }
                timelines.Add(timeline);
            }
 
            // Event timeline.
            int eventCount = input.ReadInt(true);
            if (eventCount > 0) {
                EventTimeline timeline = new EventTimeline(eventCount);
                for (int i = 0; i < eventCount; i++) {
                    float time = input.ReadFloat();
                    EventData eventData = skeletonData.events.Items[input.ReadInt(true)];
                    Event e = new Event(time, eventData);
                    e.intValue = input.ReadInt(false);
                    e.floatValue = input.ReadFloat();
                    e.stringValue = input.ReadString();
                    if (e.stringValue == null) e.stringValue = eventData.String;
                    if (e.Data.AudioPath != null) {
                        e.volume = input.ReadFloat();
                        e.balance = input.ReadFloat();
                    }
                    timeline.SetFrame(i, e);
                }
                timelines.Add(timeline);
            }
 
            float duration = 0;
            Timeline[] items = timelines.Items;
            for (int i = 0, n = timelines.Count; i < n; i++)
                duration = Math.Max(duration, items[i].Duration);
            return new Animation(name, timelines, duration);
        }
 
        /// <exception cref="IOException">Throws IOException when a read operation fails.</exception>
        private void ReadTimeline (SkeletonInput input, ExposedList<Timeline> timelines, CurveTimeline1 timeline, float scale) {
            float time = input.ReadFloat(), value = input.ReadFloat() * scale;
            for (int frame = 0, bezier = 0, frameLast = timeline.FrameCount - 1; ; frame++) {
                timeline.SetFrame(frame, time, value);
                if (frame == frameLast) break;
                float time2 = input.ReadFloat(), value2 = input.ReadFloat() * scale;
                switch (input.ReadUByte()) {
                case CURVE_STEPPED:
                    timeline.SetStepped(frame);
                    break;
                case CURVE_BEZIER:
                    SetBezier(input, timeline, bezier++, frame, 0, time, time2, value, value2, scale);
                    break;
                }
                time = time2;
                value = value2;
            }
            timelines.Add(timeline);
        }
 
        /// <exception cref="IOException">Throws IOException when a read operation fails.</exception>
        private void ReadTimeline (SkeletonInput input, ExposedList<Timeline> timelines, CurveTimeline2 timeline, float scale) {
            float time = input.ReadFloat(), value1 = input.ReadFloat() * scale, value2 = input.ReadFloat() * scale;
            for (int frame = 0, bezier = 0, frameLast = timeline.FrameCount - 1; ; frame++) {
                timeline.SetFrame(frame, time, value1, value2);
                if (frame == frameLast) break;
                float time2 = input.ReadFloat(), nvalue1 = input.ReadFloat() * scale, nvalue2 = input.ReadFloat() * scale;
                switch (input.ReadUByte()) {
                case CURVE_STEPPED:
                    timeline.SetStepped(frame);
                    break;
                case CURVE_BEZIER:
                    SetBezier(input, timeline, bezier++, frame, 0, time, time2, value1, nvalue1, scale);
                    SetBezier(input, timeline, bezier++, frame, 1, time, time2, value2, nvalue2, scale);
                    break;
                }
                time = time2;
                value1 = nvalue1;
                value2 = nvalue2;
            }
            timelines.Add(timeline);
        }
 
        /// <exception cref="IOException">Throws IOException when a read operation fails.</exception>
        void SetBezier (SkeletonInput input, CurveTimeline timeline, int bezier, int frame, int value, float time1, float time2,
            float value1, float value2, float scale) {
            timeline.SetBezier(bezier, frame, value, time1, value1, input.ReadFloat(), input.ReadFloat() * scale, input.ReadFloat(),
                    input.ReadFloat() * scale, time2, value2);
        }
 
        internal class Vertices {
            public int length;
            public int[] bones;
            public float[] vertices;
        }
 
        internal class SkeletonInput {
            private byte[] chars = new byte[32];
            private byte[] bytesBigEndian = new byte[8];
            internal string[] strings;
            Stream input;
 
            public SkeletonInput (Stream input) {
                this.input = input;
            }
 
            public int Read () {
                return input.ReadByte();
            }
 
            /// <summary>Explicit unsigned byte variant to prevent pitfalls porting Java reference implementation
            /// where byte is signed vs C# where byte is unsigned.</summary>
            public byte ReadUByte () {
                return (byte)input.ReadByte();
            }
 
            /// <summary>Explicit signed byte variant to prevent pitfalls porting Java reference implementation
            /// where byte is signed vs C# where byte is unsigned.</summary>
            public sbyte ReadSByte () {
                int value = input.ReadByte();
                if (value == -1) throw new EndOfStreamException();
                return (sbyte)value;
            }
 
            public bool ReadBoolean () {
                return input.ReadByte() != 0;
            }
 
            public float ReadFloat () {
                input.Read(bytesBigEndian, 0, 4);
                chars[3] = bytesBigEndian[0];
                chars[2] = bytesBigEndian[1];
                chars[1] = bytesBigEndian[2];
                chars[0] = bytesBigEndian[3];
                return BitConverter.ToSingle(chars, 0);
            }
 
            public int ReadInt () {
                input.Read(bytesBigEndian, 0, 4);
                return (bytesBigEndian[0] << 24)
                    + (bytesBigEndian[1] << 16)
                    + (bytesBigEndian[2] << 8)
                    + bytesBigEndian[3];
            }
 
            public long ReadLong () {
                input.Read(bytesBigEndian, 0, 8);
                return ((long)(bytesBigEndian[0]) << 56)
                    + ((long)(bytesBigEndian[1]) << 48)
                    + ((long)(bytesBigEndian[2]) << 40)
                    + ((long)(bytesBigEndian[3]) << 32)
                    + ((long)(bytesBigEndian[4]) << 24)
                    + ((long)(bytesBigEndian[5]) << 16)
                    + ((long)(bytesBigEndian[6]) << 8)
                    + (long)(bytesBigEndian[7]);
            }
 
            public int ReadInt (bool optimizePositive) {
                int b = input.ReadByte();
                int result = b & 0x7F;
                if ((b & 0x80) != 0) {
                    b = input.ReadByte();
                    result |= (b & 0x7F) << 7;
                    if ((b & 0x80) != 0) {
                        b = input.ReadByte();
                        result |= (b & 0x7F) << 14;
                        if ((b & 0x80) != 0) {
                            b = input.ReadByte();
                            result |= (b & 0x7F) << 21;
                            if ((b & 0x80) != 0) result |= (input.ReadByte() & 0x7F) << 28;
                        }
                    }
                }
                return optimizePositive ? result : ((int)((uint)result >> 1) ^ -(result & 1));
            }
 
            public string ReadString () {
                int byteCount = ReadInt(true);
                switch (byteCount) {
                case 0:
                    return null;
                case 1:
                    return "";
                }
                byteCount--;
                byte[] buffer = this.chars;
                if (buffer.Length < byteCount) buffer = new byte[byteCount];
                ReadFully(buffer, 0, byteCount);
                return System.Text.Encoding.UTF8.GetString(buffer, 0, byteCount);
            }
 
            /// <return>May be null.</return>
            public String ReadStringRef () {
                int index = ReadInt(true);
                return index == 0 ? null : strings[index - 1];
            }
 
            public void ReadFully (byte[] buffer, int offset, int length) {
                while (length > 0) {
                    int count = input.Read(buffer, offset, length);
                    if (count <= 0) throw new EndOfStreamException();
                    offset += count;
                    length -= count;
                }
            }
 
            /// <summary>Returns the version string of binary skeleton data.</summary>
            public string GetVersionString () {
                try {
                    // try reading 4.0+ format
                    long initialPosition = input.Position;
                    ReadLong(); // long hash
 
                    long stringPosition = input.Position;
                    int stringByteCount = ReadInt(true);
                    input.Position = stringPosition;
                    if (stringByteCount <= 13) {
                        string version = ReadString();
                        if (char.IsDigit(version[0]))
                            return version;
                    }
                    // fallback to old version format
                    input.Position = initialPosition;
                    return GetVersionStringOld3X();
                } catch (Exception e) {
                    throw new ArgumentException("Stream does not contain valid binary Skeleton Data.\n" + e, "input");
                }
            }
 
            /// <summary>Returns old 3.8 and earlier format version string of binary skeleton data.</summary>
            public string GetVersionStringOld3X () {
                // Hash.
                int byteCount = ReadInt(true);
                if (byteCount > 1) input.Position += byteCount - 1;
 
                // Version.
                byteCount = ReadInt(true);
                if (byteCount > 1 && byteCount <= 13) {
                    byteCount--;
                    byte[] buffer = new byte[byteCount];
                    ReadFully(buffer, 0, byteCount);
                    return System.Text.Encoding.UTF8.GetString(buffer, 0, byteCount);
                }
                throw new ArgumentException("Stream does not contain valid binary Skeleton Data.");
            }
        }
 
        private class LinkedMesh {
            internal string parent;
            internal int skinIndex, slotIndex;
            internal MeshAttachment mesh;
            internal bool inheritTimelines;
 
            public LinkedMesh (MeshAttachment mesh, int skinIndex, int slotIndex, string parent, bool inheritTimelines) {
                this.mesh = mesh;
                this.skinIndex = skinIndex;
                this.slotIndex = slotIndex;
                this.parent = parent;
                this.inheritTimelines = inheritTimelines;
            }
        }
    }
}