diff --git a/src/s_sound.cpp b/src/s_sound.cpp index e34edf117..bacd5aa94 100644 --- a/src/s_sound.cpp +++ b/src/s_sound.cpp @@ -2458,7 +2458,11 @@ bool S_ChangeMusic (const char *musicname, int order, bool looping, bool force) { return false; } - reader = Wads.ReopenLumpNum(lumpnum); + reader = Wads.ReopenLumpNumNewFile(lumpnum); + if (reader == NULL) + { + return false; + } } } else diff --git a/src/w_wad.cpp b/src/w_wad.cpp index 2b3413460..efeb38571 100644 --- a/src/w_wad.cpp +++ b/src/w_wad.cpp @@ -1228,6 +1228,17 @@ FWadLump *FWadCollection::ReopenLumpNum (int lump) return new FWadLump(LumpInfo[lump].lump, true); } +FWadLump *FWadCollection::ReopenLumpNumNewFile (int lump) +{ + if ((unsigned)lump >= (unsigned)LumpInfo.Size()) + { + return NULL; + } + + return new FWadLump(lump, LumpInfo[lump].lump); +} + + //========================================================================== // // GetFileReader @@ -1417,6 +1428,34 @@ FWadLump::FWadLump(FResourceLump *lump, bool alwayscache) } } +FWadLump::FWadLump(int lumpnum, FResourceLump *lump) +: FileReader() +{ + FileReader *f = lump->GetReader(); + + if (f != NULL && f->GetFile() != NULL) + { + // Uncompressed lump in a file. For this we will have to open a new FILE, since we need it for streaming + int fileno = Wads.GetLumpFile(lumpnum); + const char *filename = Wads.GetWadFullName(fileno); + File = fopen(filename, "rb"); + if (File != NULL) + { + Length = lump->LumpSize; + StartPos = FilePos = lump->GetFileOffset(); + Lump = NULL; + CloseOnDestruct = true; + Seek(0, SEEK_SET); + return; + } + } + File = NULL; + Length = lump->LumpSize; + StartPos = FilePos = 0; + Lump = lump; + Lump->CacheLump(); +} + FWadLump::~FWadLump() { if (Lump != NULL) diff --git a/src/w_wad.h b/src/w_wad.h index 63912373e..323f12df2 100644 --- a/src/w_wad.h +++ b/src/w_wad.h @@ -112,6 +112,7 @@ public: private: FWadLump (FResourceLump *Lump, bool alwayscache = false); + FWadLump(int lumpnum, FResourceLump *lump); FResourceLump *Lump; @@ -185,6 +186,7 @@ public: FWadLump OpenLumpNum (int lump); FWadLump OpenLumpName (const char *name) { return OpenLumpNum (GetNumForName (name)); } FWadLump *ReopenLumpNum (int lump); // Opens a new, independent FILE + FWadLump *ReopenLumpNumNewFile (int lump); // Opens a new, independent FILE FileReader * GetFileReader(int wadnum); // Gets a FileReader object to the entire WAD