| 442 | } |
| 443 | |
| 444 | bool CGhostLoader::ReadData(int Type, void *pData, size_t Size) |
| 445 | { |
| 446 | dbg_assert((bool)m_File, "File not open"); |
| 447 | dbg_assert(Type >= 0 && Type <= (int)std::numeric_limits<unsigned char>::max(), "Type invalid"); |
| 448 | dbg_assert(Size > 0 && Size <= MAX_ITEM_SIZE && Size % sizeof(uint32_t) == 0, "Size invalid"); |
| 449 | |
| 450 | if((size_t)(m_pBufferEnd - m_pBufferPos) < Size) |
| 451 | { |
| 452 | log_error_color(LOG_COLOR_GHOST, "ghost_loader", "Failed to read ghost file '%s': not enough data (type='%d', got='%" PRIzu "', wanted='%" PRIzu "')", m_aFilename, Type, (size_t)(m_pBufferEnd - m_pBufferPos), Size); |
| 453 | return false; |
| 454 | } |
| 455 | |
| 456 | CGhostItem Data(Type); |
| 457 | if(m_LastItem.m_Type == Data.m_Type) |
| 458 | { |
| 459 | UndiffItem((const uint32_t *)m_LastItem.m_aData, (const uint32_t *)m_pBufferPos, (uint32_t *)Data.m_aData, Size / sizeof(uint32_t)); |
| 460 | } |
| 461 | else |
| 462 | { |
| 463 | mem_copy(Data.m_aData, m_pBufferPos, Size); |
| 464 | } |
| 465 | |
| 466 | mem_copy(pData, Data.m_aData, Size); |
| 467 | |
| 468 | m_LastItem = Data; |
| 469 | m_pBufferPos += Size; |
| 470 | m_BufferCurItem++; |
| 471 | return true; |
| 472 | } |
| 473 | |
| 474 | void CGhostLoader::Close() |
| 475 | { |
no test coverage detected