2424#include " filesystem.h"
2525#include " client_factorylist.h" // FactoryList_Retrieve
2626#include " eiface.h" // IVEngineServer
27+ #include < lzmaDecoder.h>
2728
2829static IVEngineServer *g_pEngineServer = NULL ;
2930
@@ -176,7 +177,15 @@ void CWorldLights::LevelInitPreEntity()
176177
177178 // If we can't divide the lump data into a whole number of worldlights,
178179 // then the BSP format changed and we're unaware
179- if (lightLump.filelen % sizeof (dworldlight_t ))
180+ int lumpsize = lightLump.filelen ;
181+
182+ // account for compressed BSPs
183+ if ( lightLump.uncompressedSize > 0 )
184+ {
185+ lumpsize = lightLump.uncompressedSize ;
186+ }
187+
188+ if ( lumpsize % sizeof (dworldlight_t ) )
180189 {
181190 Warning (" CWorldLights: unknown world light lump\n " );
182191
@@ -188,12 +197,24 @@ void CWorldLights::LevelInitPreEntity()
188197 g_pFullFileSystem->Seek (hFile, lightLump.fileofs , FILESYSTEM_SEEK_HEAD );
189198
190199 // Allocate memory for the worldlights
191- m_nWorldLights = lightLump. filelen / sizeof (dworldlight_t );
200+ m_nWorldLights = lumpsize / sizeof (dworldlight_t );
192201 m_pWorldLights = new dworldlight_t [m_nWorldLights];
193202
194203 // Read worldlights then close
195- g_pFullFileSystem->Read (m_pWorldLights, lightLump.filelen , hFile);
196- g_pFullFileSystem->Close (hFile);
204+ if ( lightLump.uncompressedSize > 0 )
205+ {
206+ // account for compressed BSPs
207+ uint8_t *worldlights = new uint8_t [lightLump.filelen ];
208+ g_pFullFileSystem->Read ( worldlights, lightLump.filelen , hFile );
209+ CLZMA::Uncompress ( (unsigned char *)worldlights, (unsigned char *)m_pWorldLights );
210+ delete[] worldlights;
211+ }
212+ else
213+ {
214+ g_pFullFileSystem->Read ( m_pWorldLights, lightLump.filelen , hFile );
215+ }
216+
217+ g_pFullFileSystem->Close ( hFile );
197218
198219 DevMsg (" CWorldLights: load successful (%d lights at 0x%p)\n " , m_nWorldLights, m_pWorldLights);
199220
0 commit comments