From e78df42a969ccc693dd5cd2403a12a9d20746bcd Mon Sep 17 00:00:00 2001 From: "konstantin.chuprin" Date: Mon, 17 Oct 2022 15:09:55 +0300 Subject: [PATCH] fix version detection of binary spine file #415 --- packages/loader-uni/src/SpineLoader.ts | 39 +++++++++++++++++++------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/packages/loader-uni/src/SpineLoader.ts b/packages/loader-uni/src/SpineLoader.ts index 0612bbda..614cac8e 100644 --- a/packages/loader-uni/src/SpineLoader.ts +++ b/packages/loader-uni/src/SpineLoader.ts @@ -10,20 +10,13 @@ class UniBinaryParser implements ISkeletonParser { scale = 1; readSkeletonData(atlas: TextureAtlas, dataToParse: Uint8Array): ISkeletonData { - let input = new BinaryInput(dataToParse); - input.readString(); - let version = input.readString(); - let ver = detectSpineVersion(version); let parser: any = null; - + let version = this.readVersionOldFormat(dataToParse); + let ver = detectSpineVersion(version); if (ver === SPINE_VERSION.VER38) { parser = new spine38.SkeletonBinary(new spine38.AtlasAttachmentLoader(atlas)); } - - input = new BinaryInput(dataToParse); - input.readInt32(); - input.readInt32(); - version = input.readString(); + version = this.readVersionNewFormat(dataToParse); ver = detectSpineVersion(version); if (ver === SPINE_VERSION.VER40 || ver === SPINE_VERSION.VER41) { parser = new spine41.SkeletonBinary(new spine41.AtlasAttachmentLoader(atlas)); @@ -36,6 +29,32 @@ class UniBinaryParser implements ISkeletonParser { parser.scale = this.scale; return parser.readSkeletonData(dataToParse); } + + readVersionOldFormat(dataToParse: Uint8Array){ + let input = new BinaryInput(dataToParse); + let version; + try { + input.readString(); + version = input.readString(); + }catch (e){ + version = ""; + } + return version || "" + } + + readVersionNewFormat(dataToParse: Uint8Array){ + let input = new BinaryInput(dataToParse); + input.readInt32(); + input.readInt32(); + let version; + try { + version = input.readString(); + }catch (e){ + version = "" + } + + return version || "" + } } class UniJsonParser implements ISkeletonParser {