| 453 | } |
| 454 | |
| 455 | int CGhost::Load(const char *pFilename) |
| 456 | { |
| 457 | int Slot = GetSlot(); |
| 458 | if(Slot == -1) |
| 459 | return -1; |
| 460 | |
| 461 | if(!GhostLoader()->Load(pFilename, GameClient()->Map()->BaseName(), GameClient()->Map()->Sha256(), GameClient()->Map()->Crc())) |
| 462 | return -1; |
| 463 | |
| 464 | const CGhostInfo *pInfo = GhostLoader()->GetInfo(); |
| 465 | |
| 466 | // select ghost |
| 467 | CGhostItem *pGhost = &m_aActiveGhosts[Slot]; |
| 468 | pGhost->Reset(); |
| 469 | pGhost->m_Path.SetSize(pInfo->m_NumTicks); |
| 470 | |
| 471 | str_copy(pGhost->m_aPlayer, pInfo->m_aOwner); |
| 472 | |
| 473 | int Index = 0; |
| 474 | bool FoundSkin = false; |
| 475 | bool NoTick = false; |
| 476 | bool Error = false; |
| 477 | |
| 478 | int Type; |
| 479 | while(!Error && GhostLoader()->ReadNextType(&Type)) |
| 480 | { |
| 481 | if(Index == pInfo->m_NumTicks && (Type == GHOSTDATA_TYPE_CHARACTER || Type == GHOSTDATA_TYPE_CHARACTER_NO_TICK)) |
| 482 | { |
| 483 | Error = true; |
| 484 | break; |
| 485 | } |
| 486 | |
| 487 | if(Type == GHOSTDATA_TYPE_SKIN && !FoundSkin) |
| 488 | { |
| 489 | FoundSkin = true; |
| 490 | if(!GhostLoader()->ReadData(Type, &pGhost->m_Skin, sizeof(CGhostSkin))) |
| 491 | Error = true; |
| 492 | } |
| 493 | else if(Type == GHOSTDATA_TYPE_CHARACTER_NO_TICK) |
| 494 | { |
| 495 | NoTick = true; |
| 496 | if(!GhostLoader()->ReadData(Type, pGhost->m_Path.Get(Index++), sizeof(CGhostCharacter_NoTick))) |
| 497 | Error = true; |
| 498 | } |
| 499 | else if(Type == GHOSTDATA_TYPE_CHARACTER) |
| 500 | { |
| 501 | if(!GhostLoader()->ReadData(Type, pGhost->m_Path.Get(Index++), sizeof(CGhostCharacter))) |
| 502 | Error = true; |
| 503 | } |
| 504 | else if(Type == GHOSTDATA_TYPE_START_TICK) |
| 505 | { |
| 506 | if(!GhostLoader()->ReadData(Type, &pGhost->m_StartTick, sizeof(int))) |
| 507 | Error = true; |
| 508 | } |
| 509 | } |
| 510 | |
| 511 | GhostLoader()->Close(); |
| 512 |
no test coverage detected