| 583 | } |
| 584 | |
| 585 | std::vector<uint8_t> WolfPro::removeProtectionFromDat(const tString& filePath, const BasicDataFiles& bdf, uint32_t& projectSeed) const |
| 586 | { |
| 587 | std::array<uint8_t, 3> seedIdx = { 0, 3, 9 }; |
| 588 | |
| 589 | if (bdf == BasicDataFiles::GAME_DAT) |
| 590 | seedIdx = { 0, 8, 6 }; |
| 591 | |
| 592 | std::vector<uint8_t> bytes = decrypt(filePath, seedIdx); |
| 593 | |
| 594 | if (bytes.empty()) |
| 595 | { |
| 596 | ERROR_LOG << LOCALIZE("decrypt_error_msg") << std::endl; |
| 597 | return std::vector<uint8_t>(); |
| 598 | } |
| 599 | |
| 600 | // Cast the value to an int8_t to preserve the sign and then write it to an uint32_t |
| 601 | // to get a 32 bit value with the correct sign propagated to the upper bits |
| 602 | projectSeed = static_cast<int8_t>(bytes[ProtKey::KEY_OFFSET]); |
| 603 | |
| 604 | const uint32_t keyLen = *reinterpret_cast<uint32_t*>(&bytes[ProtKey::KEY_LEN_OFFSET]); |
| 605 | |
| 606 | if (keyLen + ProtKey::KEY_OFFSET >= bytes.size()) |
| 607 | { |
| 608 | ERROR_LOG << TEXT("ERROR: Invalid key length") << std::endl; |
| 609 | return std::vector<uint8_t>(); |
| 610 | } |
| 611 | |
| 612 | const uint32_t oldSize = static_cast<uint32_t>(bytes.size()); |
| 613 | |
| 614 | // Remove the first bytes until after the key |
| 615 | bytes.erase(bytes.begin(), bytes.begin() + ProtKey::KEY_OFFSET + keyLen); |
| 616 | |
| 617 | // Insert the decrypted start bytes |
| 618 | bytes.insert(bytes.begin(), ProtKey::DEC_START.begin(), ProtKey::DEC_START.end()); |
| 619 | |
| 620 | if (bdf == BasicDataFiles::GAME_DAT) |
| 621 | { |
| 622 | // For Game.dat swap bytes 6 and 9 |
| 623 | std::swap(bytes[6], bytes[9]); |
| 624 | |
| 625 | gameDatUpdateSize(bytes, oldSize); |
| 626 | } |
| 627 | else if (bdf == BasicDataFiles::COM_EVENT) |
| 628 | { |
| 629 | // If the file is CommonEvents.dat, replace byte 8 with 0x43 |
| 630 | bytes[8] = 0x43; |
| 631 | } |
| 632 | |
| 633 | return bytes; |
| 634 | } |
| 635 | |
| 636 | void WolfPro::gameDatUpdateSize(std::vector<uint8_t>& bytes, const uint32_t& oldSize) const |
| 637 | { |