From 5444d0cdef4c17de34a9ef8fd74670345b4923e6 Mon Sep 17 00:00:00 2001 From: PseudoResonance Date: Mon, 12 Aug 2019 22:13:06 -0700 Subject: [PATCH] Add compatibility for NBS Version 3 --- src/main/java/com/xxmicloxx/NoteBlockAPI/NBSDecoder.java | 7 +++++-- .../java/com/xxmicloxx/NoteBlockAPI/utils/NBSDecoder.java | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/xxmicloxx/NoteBlockAPI/NBSDecoder.java b/src/main/java/com/xxmicloxx/NoteBlockAPI/NBSDecoder.java index 332cb52..85798c3 100644 --- a/src/main/java/com/xxmicloxx/NoteBlockAPI/NBSDecoder.java +++ b/src/main/java/com/xxmicloxx/NoteBlockAPI/NBSDecoder.java @@ -63,9 +63,12 @@ private static Song parse(InputStream inputStream, File songFile) { int firstcustominstrument = 10; //Backward compatibility - most of songs with old structure are from 1.12 int firstcustominstrumentdiff; int nbsversion = 0; - if (length == 0){ + if (length == 0) { nbsversion = dataInputStream.readByte(); firstcustominstrument = dataInputStream.readByte(); + if (nbsversion >= 3) { + length = readShort(dataInputStream); + } } firstcustominstrumentdiff = InstrumentUtils.getCustomInstrumentFirstIndex() - firstcustominstrument; short songHeight = readShort(dataInputStream); @@ -110,7 +113,7 @@ private static Song parse(InputStream inputStream, File songFile) { } } - if (nbsversion > 0) { + if (nbsversion > 0 && nbsversion < 3) { length = tick; } diff --git a/src/main/java/com/xxmicloxx/NoteBlockAPI/utils/NBSDecoder.java b/src/main/java/com/xxmicloxx/NoteBlockAPI/utils/NBSDecoder.java index c82b684..dd81167 100644 --- a/src/main/java/com/xxmicloxx/NoteBlockAPI/utils/NBSDecoder.java +++ b/src/main/java/com/xxmicloxx/NoteBlockAPI/utils/NBSDecoder.java @@ -66,9 +66,12 @@ private static Song parse(InputStream inputStream, File songFile) { int firstcustominstrument = 10; //Backward compatibility - most of songs with old structure are from 1.12 int firstcustominstrumentdiff; int nbsversion = 0; - if (length == 0){ + if (length == 0) { nbsversion = dataInputStream.readByte(); firstcustominstrument = dataInputStream.readByte(); + if (nbsversion >= 3) { + length = readShort(dataInputStream); + } } firstcustominstrumentdiff = InstrumentUtils.getCustomInstrumentFirstIndex() - firstcustominstrument; short songHeight = readShort(dataInputStream); @@ -113,7 +116,7 @@ private static Song parse(InputStream inputStream, File songFile) { } } - if (nbsversion > 0) { + if (nbsversion > 0 && nbsversion < 3) { length = tick; }