Skip to content

Commit b9799cc

Browse files
committed
- fix palette-related crashes for D1
1 parent d9632a2 commit b9799cc

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed

DriverLevelTool/driver_routines/regions_d1.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,20 +53,20 @@ void CDriver1LevelRegion::LoadRegionData(IVirtualStream* pFile, Spool* spool)
5353
int cellObjectsOffset = cellDataOffset + spool->cell_data_size[0];
5454
int pvsDataOffset = cellObjectsOffset + spool->cell_data_size[2]; // FIXME: is it even there in Driver 1?
5555

56-
char* packed_cell_pointers = new char[spool->cell_data_size[1] * SPOOL_CD_BLOCK_SIZE * 2];
57-
m_cellPointers = new ushort[m_owner->m_mapInfo.region_size * m_owner->m_mapInfo.region_size * 2];
58-
59-
memset(m_cellPointers, 0xFF, sizeof(ushort) * m_owner->m_mapInfo.region_size * m_owner->m_mapInfo.region_size * 2);
56+
char* packed_cell_pointers = new char[spool->cell_data_size[1] * SPOOL_CD_BLOCK_SIZE];
57+
58+
m_cellPointers = new ushort[m_owner->m_cell_objects_add[2]];
59+
memset(m_cellPointers, 0xFF, sizeof(ushort) * m_owner->m_cell_objects_add[2]);
6060

6161
// read packed cell pointers
6262
pFile->Seek(g_levInfo.spooldata_offset + cellPointersOffset * SPOOL_CD_BLOCK_SIZE, VS_SEEK_SET);
63-
pFile->Read(packed_cell_pointers, spool->cell_data_size[1] * SPOOL_CD_BLOCK_SIZE * 2, sizeof(char));
63+
pFile->Read(packed_cell_pointers, spool->cell_data_size[1] * SPOOL_CD_BLOCK_SIZE, sizeof(char));
6464

6565
// unpack cell pointers so we can use them
6666
if (UnpackCellPointers(m_cellPointers, packed_cell_pointers, 0, 0) != -1)
6767
{
6868
// read cell data
69-
m_cells = (CELL_DATA_D1*)malloc(spool->cell_data_size[0] * SPOOL_CD_BLOCK_SIZE * 2);
69+
m_cells = (CELL_DATA_D1*)malloc(spool->cell_data_size[0] * SPOOL_CD_BLOCK_SIZE);
7070
pFile->Seek(g_levInfo.spooldata_offset + cellDataOffset * SPOOL_CD_BLOCK_SIZE, VS_SEEK_SET);
7171
pFile->Read(m_cells, spool->cell_data_size[0] * SPOOL_CD_BLOCK_SIZE, sizeof(char));
7272

DriverLevelTool/driver_routines/regions_d2.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ void CDriver2LevelRegion::LoadRegionData(IVirtualStream* pFile, Spool* spool)
6969
}
7070

7171
char* packed_cell_pointers = new char[spool->cell_data_size[1] * SPOOL_CD_BLOCK_SIZE];
72-
m_cellPointers = new ushort[m_owner->m_mapInfo.region_size * m_owner->m_mapInfo.region_size];
7372

74-
memset(m_cellPointers, 0xFF, sizeof(ushort) * m_owner->m_mapInfo.region_size * m_owner->m_mapInfo.region_size);
73+
m_cellPointers = new ushort[m_owner->m_cell_objects_add[2]];
74+
memset(m_cellPointers, 0xFF, sizeof(ushort) * m_owner->m_cell_objects_add[2]);
7575

7676
// read packed cell pointers
7777
pFile->Seek(g_levInfo.spooldata_offset + cellPointersOffset * SPOOL_CD_BLOCK_SIZE, VS_SEEK_SET);

DriverLevelTool/driver_routines/textures.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -511,9 +511,12 @@ void CDriverLevelTextures::ProcessPalletLump(IVirtualStream* pFile)
511511
pFile->Read(clutTablePtr, 16, sizeof(ushort));
512512

513513
// reference
514-
TexDetailInfo_t& detail = m_texPages[data.tpage].m_details[info.texnum];
515-
detail.extraCLUTs[data.palette] = &data.clut;
516-
514+
if(info.texnum < m_texPages[data.tpage].GetDetailCount())
515+
{
516+
TexDetailInfo_t& detail = m_texPages[data.tpage].m_details[info.texnum];
517+
detail.extraCLUTs[data.palette] = &data.clut;
518+
}
519+
517520
added_cluts++;
518521

519522
// only in D1 we need to check count
@@ -531,8 +534,11 @@ void CDriverLevelTextures::ProcessPalletLump(IVirtualStream* pFile)
531534
data.texnum[data.texcnt++] = info.texnum;
532535

533536
// reference
534-
TexDetailInfo_t& detail = m_texPages[data.tpage].m_details[info.texnum];
535-
detail.extraCLUTs[data.palette] = &data.clut;
537+
if (info.texnum < m_texPages[data.tpage].GetDetailCount())
538+
{
539+
TexDetailInfo_t& detail = m_texPages[data.tpage].m_details[info.texnum];
540+
detail.extraCLUTs[data.palette] = &data.clut;
541+
}
536542
}
537543
}
538544

0 commit comments

Comments
 (0)