MCPcopy Create free account
hub / github.com/Kenix3/libultraship / LoadExtTable

Function LoadExtTable

extern/StormLib/src/SBaseFileTable.cpp:1120–1187  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1118// General EXT table functions
1119
1120TMPQExtHeader * LoadExtTable(
1121 TMPQArchive * ha,
1122 ULONGLONG ByteOffset,
1123 size_t Size,
1124 DWORD dwSignature,
1125 DWORD dwKey)
1126{
1127 TMPQExtHeader * pCompressed = NULL; // Compressed table
1128 TMPQExtHeader * pExtTable = NULL; // Uncompressed table
1129
1130 // Do nothing if the size is zero
1131 if(ByteOffset != 0 && Size != 0)
1132 {
1133 // Allocate size for the compressed table
1134 pExtTable = (TMPQExtHeader *)STORM_ALLOC(BYTE, Size);
1135 if(pExtTable != NULL)
1136 {
1137 // Load the table from the MPQ
1138 ByteOffset += ha->MpqPos;
1139 if(!FileStream_Read(ha->pStream, &ByteOffset, pExtTable, (DWORD)Size))
1140 {
1141 STORM_FREE(pExtTable);
1142 return NULL;
1143 }
1144
1145 // Swap the ext table header
1146 BSWAP_ARRAY32_UNSIGNED(pExtTable, sizeof(TMPQExtHeader));
1147 if(pExtTable->dwSignature != dwSignature)
1148 {
1149 STORM_FREE(pExtTable);
1150 return NULL;
1151 }
1152
1153 // Decrypt the block
1154 BSWAP_ARRAY32_UNSIGNED(pExtTable + 1, pExtTable->dwDataSize);
1155 DecryptMpqBlock(pExtTable + 1, (DWORD)(Size - sizeof(TMPQExtHeader)), dwKey);
1156 BSWAP_ARRAY32_UNSIGNED(pExtTable + 1, pExtTable->dwDataSize);
1157
1158 // If the table is compressed, decompress it
1159 if((pExtTable->dwDataSize + sizeof(TMPQExtHeader)) > Size)
1160 {
1161 pCompressed = pExtTable;
1162 pExtTable = (TMPQExtHeader *)STORM_ALLOC(BYTE, sizeof(TMPQExtHeader) + pCompressed->dwDataSize);
1163 if(pExtTable != NULL)
1164 {
1165 int cbOutBuffer = (int)pCompressed->dwDataSize;
1166 int cbInBuffer = (int)Size;
1167
1168 // Decompress the extended table
1169 pExtTable->dwSignature = pCompressed->dwSignature;
1170 pExtTable->dwVersion = pCompressed->dwVersion;
1171 pExtTable->dwDataSize = pCompressed->dwDataSize;
1172 if(!SCompDecompress2(pExtTable + 1, &cbOutBuffer, pCompressed + 1, cbInBuffer))
1173 {
1174 STORM_FREE(pExtTable);
1175 pExtTable = NULL;
1176 }
1177 }

Callers 3

LoadHetTableFunction · 0.85
LoadBetTableFunction · 0.85
SFileGetFileInfoFunction · 0.85

Calls 3

FileStream_ReadFunction · 0.85
DecryptMpqBlockFunction · 0.85
SCompDecompress2Function · 0.85

Tested by

no test coverage detected