diff --git a/src/gameflow.h b/src/gameflow.h index cec2c95..767f1a4 100644 --- a/src/gameflow.h +++ b/src/gameflow.h @@ -671,26 +671,31 @@ namespace TR { const char* getGameScreen(Version version, LevelID id) { if (useEasyStart) { + #define CHECK_FILE(name) if (Stream::existsContent(name)) return name + switch (id) { case LVL_TR1_TITLE : - if (Stream::existsContent("TITLEH.png")) return "TITLEH.png"; - if (Stream::existsContent("DATA/TITLEH.PCX")) return "DATA/TITLEH.PCX"; - if (Stream::existsContent("DELDATA/AMERTIT.RAW")) return "DELDATA/AMERTIT.RAW"; + CHECK_FILE("TITLEH.png"); + CHECK_FILE("DATA/TITLEH.PCX"); + CHECK_FILE("DELDATA/AMERTIT.RAW"); break; case LVL_TR2_TITLE : - if (Stream::existsContent("TITLE.png")) return "TITLE.png"; - if (Stream::existsContent("data/TITLE.PCX")) return "data/TITLE.PCX"; - if (Stream::existsContent("pix/title.pcx")) return "pix/title.pcx"; + CHECK_FILE("TITLE.png"); + CHECK_FILE("data/TITLE.PCX"); + CHECK_FILE("pix/title.pcx"); + CHECK_FILE("PIXUS/TITLEUS.RAW"); // TODO: add other languages break; case LVL_TR3_TITLE : - if (Stream::existsContent("pix/TITLEUK.BMP")) return "pix/TITLEUK.BMP"; + CHECK_FILE("pix/TITLEUK.BMP"); // TODO: add other languages break; default : ; } + #undef CHECK_FILE + } else { switch (id) { case LVL_TR1_TITLE : return "level/1/TITLEH.PCX"; diff --git a/src/texture.h b/src/texture.h index bb8eda9..3a11d7e 100644 --- a/src/texture.h +++ b/src/texture.h @@ -511,15 +511,18 @@ struct Texture { } static Texture* LoadRNC(Stream &stream) { // https://github.com/lab313ru/rnc_propack_source - stream.seek(4); // skip MAGIC - uint32 size = swap32(stream.read(size)); - uint32 csize = swap32(stream.read(csize)); - stream.seek(4); // skip CRC - uint8 chunks, fkey; - stream.read(fkey); - stream.read(chunks); + uint32 magic, size, csize; + stream.read(magic); - uint16 key = fkey; + if (magic == FOURCC("RNC\002")) { + size = swap32(stream.read(size)); + csize = swap32(stream.read(csize)); + stream.seek(6); + } else { + stream.seek(-4); + size = 384 * 256 * 2; + csize = stream.size; + } uint8 *data = new uint8[size]; uint8 *cdata = new uint8[csize]; @@ -528,13 +531,12 @@ struct Texture { BitStream bs(cdata, csize); uint8 *dst = data; - uint8 *end = data + size; uint32 length = 0; uint16 offset = 0; bs.readBits(2); - while (dst < end) { + while (bs.data < bs.end || bs.index > 0) { if (!bs.readBit()) { *dst++ = bs.readByte(); } else { @@ -578,7 +580,7 @@ struct Texture { delete[] cdata; int width = 384; - int height = 256; + int height = size / width / 2; int dw = Core::support.texNPOT ? width : nextPow2(width); int dh = Core::support.texNPOT ? height : nextPow2(height); @@ -610,13 +612,16 @@ struct Texture { static Texture* Load(Stream &stream) { uint32 magic; stream.read(magic); - stream.seek(-int(sizeof(magic))); + stream.seek(-4); + #ifdef USE_INFLATE if (magic == 0x474E5089) return LoadPNG(stream); #endif - if (magic == FOURCC("RNC\002")) + + if (stream.name && strstr(stream.name, ".RAW")) return LoadRNC(stream); + if ((magic & 0xFFFF) == 0x4D42) return LoadBMP(stream); return LoadPCX(stream); diff --git a/src/utils.h b/src/utils.h index 386be55..95fe579 100644 --- a/src/utils.h +++ b/src/utils.h @@ -1055,6 +1055,9 @@ struct Stream { size = ftell(f); fseek(f, 0, SEEK_SET); + this->name = new char[strlen(name) + 1]; + strcpy(this->name, name); + if (callback) callback(this, userData); }