S3M import: fix crash on Android
This commit is contained in:
parent
d814aaebee
commit
8a8784dd5a
|
@ -230,7 +230,7 @@ bool DivEngine::loadIT(unsigned char* file, size_t len) {
|
||||||
throw EndOfFileException(&reader,reader.tell());
|
throw EndOfFileException(&reader,reader.tell());
|
||||||
}
|
}
|
||||||
|
|
||||||
ds.name=reader.readString(26);
|
ds.name=reader.readStringLatin1(26);
|
||||||
|
|
||||||
unsigned char hilight1=reader.readC();
|
unsigned char hilight1=reader.readC();
|
||||||
unsigned char hilight2=reader.readC();
|
unsigned char hilight2=reader.readC();
|
||||||
|
@ -381,7 +381,7 @@ bool DivEngine::loadIT(unsigned char* file, size_t len) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
String dosName=reader.readString(12);
|
String dosName=reader.readStringLatin1(12);
|
||||||
|
|
||||||
reader.readC(); // 0
|
reader.readC(); // 0
|
||||||
|
|
||||||
|
@ -441,7 +441,7 @@ bool DivEngine::loadIT(unsigned char* file, size_t len) {
|
||||||
reader.readI();
|
reader.readI();
|
||||||
}
|
}
|
||||||
|
|
||||||
ins->name=reader.readString(26);
|
ins->name=reader.readStringLatin1(26);
|
||||||
|
|
||||||
if (compatTracker<0x200) { // old format
|
if (compatTracker<0x200) { // old format
|
||||||
// x
|
// x
|
||||||
|
@ -554,7 +554,7 @@ bool DivEngine::loadIT(unsigned char* file, size_t len) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
String dosName=reader.readString(12);
|
String dosName=reader.readStringLatin1(12);
|
||||||
|
|
||||||
reader.readC(); // 0
|
reader.readC(); // 0
|
||||||
|
|
||||||
|
@ -562,7 +562,7 @@ bool DivEngine::loadIT(unsigned char* file, size_t len) {
|
||||||
unsigned char flags=reader.readC();
|
unsigned char flags=reader.readC();
|
||||||
defVol[i]=reader.readC();
|
defVol[i]=reader.readC();
|
||||||
|
|
||||||
s->name=reader.readString(26);
|
s->name=reader.readStringLatin1(26);
|
||||||
|
|
||||||
unsigned char convert=reader.readC();
|
unsigned char convert=reader.readC();
|
||||||
unsigned char defPan=reader.readC();
|
unsigned char defPan=reader.readC();
|
||||||
|
|
|
@ -96,7 +96,7 @@ bool DivEngine::loadMod(unsigned char* file, size_t len) {
|
||||||
logD("couldn't seek to 0");
|
logD("couldn't seek to 0");
|
||||||
throw EndOfFileException(&reader,reader.tell());
|
throw EndOfFileException(&reader,reader.tell());
|
||||||
}
|
}
|
||||||
ds.name=reader.readString(20);
|
ds.name=reader.readStringLatin1(20);
|
||||||
logI("%s",ds.name);
|
logI("%s",ds.name);
|
||||||
|
|
||||||
// samples
|
// samples
|
||||||
|
@ -105,7 +105,7 @@ bool DivEngine::loadMod(unsigned char* file, size_t len) {
|
||||||
for (int i=0; i<insCount; i++) {
|
for (int i=0; i<insCount; i++) {
|
||||||
DivSample* sample=new DivSample;
|
DivSample* sample=new DivSample;
|
||||||
sample->depth=DIV_SAMPLE_DEPTH_8BIT;
|
sample->depth=DIV_SAMPLE_DEPTH_8BIT;
|
||||||
sample->name=reader.readString(22);
|
sample->name=reader.readStringLatin1(22);
|
||||||
logD("%d: %s",i+1,sample->name);
|
logD("%d: %s",i+1,sample->name);
|
||||||
int slen=((unsigned short)reader.readS_BE())*2;
|
int slen=((unsigned short)reader.readS_BE())*2;
|
||||||
sampLens[i]=slen;
|
sampLens[i]=slen;
|
||||||
|
|
|
@ -117,7 +117,7 @@ bool DivEngine::loadS3M(unsigned char* file, size_t len) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ds.name=reader.readString(28);
|
ds.name=reader.readStringLatin1(28);
|
||||||
|
|
||||||
reader.readC(); // 0x1a
|
reader.readC(); // 0x1a
|
||||||
if (reader.readC()!=16) {
|
if (reader.readC()!=16) {
|
||||||
|
@ -366,7 +366,7 @@ bool DivEngine::loadS3M(unsigned char* file, size_t len) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
String name=reader.readString(28);
|
String name=reader.readStringLatin1(28);
|
||||||
ins->name=name;
|
ins->name=name;
|
||||||
|
|
||||||
ds.ins.push_back(ins);
|
ds.ins.push_back(ins);
|
||||||
|
@ -401,7 +401,7 @@ bool DivEngine::loadS3M(unsigned char* file, size_t len) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String dosName=reader.readString(12);
|
String dosName=reader.readStringLatin1(12);
|
||||||
|
|
||||||
if (ins->type==DIV_INS_ES5506) {
|
if (ins->type==DIV_INS_ES5506) {
|
||||||
unsigned int memSeg=0;
|
unsigned int memSeg=0;
|
||||||
|
@ -434,7 +434,7 @@ bool DivEngine::loadS3M(unsigned char* file, size_t len) {
|
||||||
reader.readI();
|
reader.readI();
|
||||||
reader.readI();
|
reader.readI();
|
||||||
|
|
||||||
String name=reader.readString(28);
|
String name=reader.readStringLatin1(28);
|
||||||
s->name=dosName;
|
s->name=dosName;
|
||||||
ins->name=name;
|
ins->name=name;
|
||||||
|
|
||||||
|
@ -581,7 +581,7 @@ bool DivEngine::loadS3M(unsigned char* file, size_t len) {
|
||||||
// x
|
// x
|
||||||
reader.seek(12,SEEK_CUR);
|
reader.seek(12,SEEK_CUR);
|
||||||
|
|
||||||
String name=reader.readString(28);
|
String name=reader.readStringLatin1(28);
|
||||||
ins->name=name;
|
ins->name=name;
|
||||||
|
|
||||||
// "SCRI"
|
// "SCRI"
|
||||||
|
|
|
@ -55,12 +55,12 @@ bool DivEngine::loadXM(unsigned char* file, size_t len) {
|
||||||
throw EndOfFileException(&reader,reader.tell());
|
throw EndOfFileException(&reader,reader.tell());
|
||||||
}
|
}
|
||||||
|
|
||||||
ds.name=reader.readString(20);
|
ds.name=reader.readStringLatin1(20);
|
||||||
|
|
||||||
// 0x1a
|
// 0x1a
|
||||||
reader.readC();
|
reader.readC();
|
||||||
|
|
||||||
String trackerName=reader.readString(20);
|
String trackerName=reader.readStringLatin1(20);
|
||||||
unsigned short trackerVer=reader.readS();
|
unsigned short trackerVer=reader.readS();
|
||||||
|
|
||||||
if (trackerName!="") logV("made with %s",trackerName);
|
if (trackerName!="") logV("made with %s",trackerName);
|
||||||
|
@ -230,7 +230,7 @@ bool DivEngine::loadXM(unsigned char* file, size_t len) {
|
||||||
headerSeek=reader.tell();
|
headerSeek=reader.tell();
|
||||||
headerSeek+=reader.readI();
|
headerSeek+=reader.readI();
|
||||||
|
|
||||||
ins->name=reader.readString(22);
|
ins->name=reader.readStringLatin1(22);
|
||||||
ins->type=DIV_INS_AMIGA;
|
ins->type=DIV_INS_AMIGA;
|
||||||
ins->amiga.useNoteMap=true;
|
ins->amiga.useNoteMap=true;
|
||||||
|
|
||||||
|
@ -341,7 +341,7 @@ bool DivEngine::loadXM(unsigned char* file, size_t len) {
|
||||||
|
|
||||||
reader.readC(); // reserved
|
reader.readC(); // reserved
|
||||||
|
|
||||||
s->name=reader.readString(22);
|
s->name=reader.readStringLatin1(22);
|
||||||
|
|
||||||
// load sample data
|
// load sample data
|
||||||
s->depth=(flags&4)?DIV_SAMPLE_DEPTH_16BIT:DIV_SAMPLE_DEPTH_8BIT;
|
s->depth=(flags&4)?DIV_SAMPLE_DEPTH_16BIT:DIV_SAMPLE_DEPTH_8BIT;
|
||||||
|
|
|
@ -229,7 +229,7 @@ double SafeReader::readD() {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
String SafeReader::readString(size_t stlen) {
|
String SafeReader::readStringWithEncoding(DivStringEncoding encoding, size_t stlen) {
|
||||||
String ret;
|
String ret;
|
||||||
#ifdef READ_DEBUG
|
#ifdef READ_DEBUG
|
||||||
logD("SR: reading string len %d at %x",stlen,curSeek);
|
logD("SR: reading string len %d at %x",stlen,curSeek);
|
||||||
|
@ -243,23 +243,67 @@ String SafeReader::readString(size_t stlen) {
|
||||||
if (c==0) {
|
if (c==0) {
|
||||||
zero=true;
|
zero=true;
|
||||||
}
|
}
|
||||||
if (!zero) ret.push_back(c);
|
if (!zero) {
|
||||||
|
if (encoding==DIV_ENCODING_LATIN1) {
|
||||||
|
if (c>=0x20) {
|
||||||
|
if (c&0x80) {
|
||||||
|
if (c>=0xa0) {
|
||||||
|
ret.push_back(0xc0|(c>>6));
|
||||||
|
ret.push_back(0x80|(c&63));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ret.push_back(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ret.push_back(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
curPos++;
|
curPos++;
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
String SafeReader::readString() {
|
String SafeReader::readStringWithEncoding(DivStringEncoding encoding) {
|
||||||
String ret;
|
String ret;
|
||||||
unsigned char c;
|
unsigned char c;
|
||||||
if (isEOF()) throw EndOfFileException(this, len);
|
if (isEOF()) throw EndOfFileException(this, len);
|
||||||
|
|
||||||
while (!isEOF() && (c=readC())!=0) {
|
while (!isEOF() && (c=readC())!=0) {
|
||||||
ret.push_back(c);
|
if (encoding==DIV_ENCODING_LATIN1) {
|
||||||
|
if (c>=0x20) {
|
||||||
|
if (c&0x80) {
|
||||||
|
if (c>=0xa0) {
|
||||||
|
ret.push_back(0xc0|(c>>6));
|
||||||
|
ret.push_back(0x80|(c&63));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ret.push_back(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ret.push_back(c);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String SafeReader::readString() {
|
||||||
|
return readStringWithEncoding(DIV_ENCODING_NONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
String SafeReader::readString(size_t stlen) {
|
||||||
|
return readStringWithEncoding(DIV_ENCODING_NONE,stlen);
|
||||||
|
}
|
||||||
|
|
||||||
|
String SafeReader::readStringLatin1() {
|
||||||
|
return readStringWithEncoding(DIV_ENCODING_LATIN1);
|
||||||
|
}
|
||||||
|
|
||||||
|
String SafeReader::readStringLatin1(size_t stlen) {
|
||||||
|
return readStringWithEncoding(DIV_ENCODING_LATIN1,stlen);
|
||||||
|
}
|
||||||
|
|
||||||
String SafeReader::readStringLine() {
|
String SafeReader::readStringLine() {
|
||||||
String ret;
|
String ret;
|
||||||
unsigned char c;
|
unsigned char c;
|
||||||
|
|
|
@ -29,6 +29,13 @@ enum Endianness {
|
||||||
BigEndian
|
BigEndian
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum DivStringEncoding {
|
||||||
|
DIV_ENCODING_NONE=0,
|
||||||
|
DIV_ENCODING_UTF8,
|
||||||
|
DIV_ENCODING_LATIN1,
|
||||||
|
DIV_ENCODING_SHIFT_JIS
|
||||||
|
};
|
||||||
|
|
||||||
class SafeReader;
|
class SafeReader;
|
||||||
|
|
||||||
struct EndOfFileException {
|
struct EndOfFileException {
|
||||||
|
@ -64,8 +71,12 @@ class SafeReader {
|
||||||
float readF_BE();
|
float readF_BE();
|
||||||
double readD();
|
double readD();
|
||||||
double readD_BE();
|
double readD_BE();
|
||||||
|
String readStringWithEncoding(DivStringEncoding encoding);
|
||||||
|
String readStringWithEncoding(DivStringEncoding encoding, size_t len);
|
||||||
String readString();
|
String readString();
|
||||||
String readString(size_t len);
|
String readString(size_t len);
|
||||||
|
String readStringLatin1();
|
||||||
|
String readStringLatin1(size_t len);
|
||||||
String readStringLine();
|
String readStringLine();
|
||||||
String readStringToken(unsigned char delim, bool stripContiguous);
|
String readStringToken(unsigned char delim, bool stripContiguous);
|
||||||
String readStringToken();
|
String readStringToken();
|
||||||
|
|
Loading…
Reference in a new issue