MCPcopy Create free account
hub / github.com/OneLoneCoder/olcPixelGameEngine / LoadPack

Method LoadPack

olcPixelGameEngine.h:2323–2367  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2321 }
2322
2323 bool ResourcePack::LoadPack(const std::string& sFile, const std::string& sKey)
2324 {
2325 // Open the resource file
2326 baseFile.open(sFile, std::ifstream::binary);
2327 if (!baseFile.is_open()) return false;
2328
2329 // 1) Read Scrambled index
2330 uint32_t nIndexSize = 0;
2331 baseFile.read((char*)&nIndexSize, sizeof(uint32_t));
2332
2333 std::vector<char> buffer(nIndexSize);
2334 for (uint32_t j = 0; j < nIndexSize; j++)
2335 buffer[j] = baseFile.get();
2336
2337 std::vector<char> decoded = scramble(buffer, sKey);
2338 size_t pos = 0;
2339 auto read = [&decoded, &pos](char* dst, size_t size) {
2340 memcpy((void*)dst, (const void*)(decoded.data() + pos), size);
2341 pos += size;
2342 };
2343
2344 auto get = [&read]() -> int { char c; read(&c, 1); return c; };
2345
2346 // 2) Read Map
2347 uint32_t nMapEntries = 0;
2348 read((char*)&nMapEntries, sizeof(uint32_t));
2349 for (uint32_t i = 0; i < nMapEntries; i++)
2350 {
2351 uint32_t nFilePathSize = 0;
2352 read((char*)&nFilePathSize, sizeof(uint32_t));
2353
2354 std::string sFileName(nFilePathSize, ' ');
2355 for (uint32_t j = 0; j < nFilePathSize; j++)
2356 sFileName[j] = get();
2357
2358 sResourceFile e;
2359 read((char*)&e.nSize, sizeof(uint32_t));
2360 read((char*)&e.nOffset, sizeof(uint32_t));
2361 mapFiles[sFileName] = e;
2362 }
2363
2364 // Don't close base file! we will provide a stream
2365 // pointer when the file is requested
2366 return true;
2367 }
2368
2369 bool ResourcePack::SavePack(const std::string& sFile, const std::string& sKey)
2370 {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected