move VMS structure into SaveFileFormats

This commit is contained in:
Martin Michelsen
2023-09-24 09:48:04 -07:00
parent 7f7aaf920b
commit 6b5e672ebb
3 changed files with 40 additions and 39 deletions
-39
View File
@@ -184,45 +184,6 @@ string find_seed_and_decrypt_download_quest_data_section(
}
}
struct PSOVMSFileHeader {
ptext<char, 0x10> short_desc; // "PSO/DOWNLOAD " or "PSOV2/DOWNLOAD "
ptext<char, 0x20> long_desc; // Usually quest name
ptext<char, 0x10> creator_id;
le_uint16_t num_icons;
le_uint16_t animation_speed;
le_uint16_t eyecatch_type;
le_uint16_t crc;
le_uint32_t data_size; // Not including header and icons
parray<uint8_t, 0x14> unused;
parray<le_uint16_t, 0x10> icon_palette;
// Variable-length field follows here:
// parray<parray<uint8_t, 0x200>, num_icons> icon;
bool checksum_correct() const {
auto add_data = +[](const void* data, size_t size, uint16_t crc) -> uint16_t {
const uint8_t* bytes = reinterpret_cast<const uint8_t*>(data);
for (size_t z = 0; z < size; z++) {
crc ^= (static_cast<uint16_t>(bytes[z]) << 8);
for (uint8_t bit = 0; bit < 8; bit++) {
if (crc & 0x8000) {
crc = (crc << 1) ^ 0x1021;
} else {
crc = (crc << 1);
}
}
}
return crc;
};
uint16_t crc = add_data(this, offsetof(PSOVMSFileHeader, crc), 0);
crc = add_data("\0\0", 2, crc);
crc = add_data(&this->data_size,
sizeof(PSOVMSFileHeader) - offsetof(PSOVMSFileHeader, data_size) + this->num_icons * 0x200 + this->data_size, crc);
return (crc == this->crc);
}
} __attribute__((packed));
struct PSODownloadQuestHeader {
le_uint32_t size;
le_uint32_t encryption_seed;
+23
View File
@@ -46,6 +46,29 @@ void ShuffleTables::shuffle(void* vdest, const void* vsrc, size_t size, bool rev
memcpy(&dest[size & 0xFFFFFF00], &src[size & 0xFFFFFF00], size & 0xFF);
}
bool PSOVMSFileHeader::checksum_correct() const {
auto add_data = +[](const void* data, size_t size, uint16_t crc) -> uint16_t {
const uint8_t* bytes = reinterpret_cast<const uint8_t*>(data);
for (size_t z = 0; z < size; z++) {
crc ^= (static_cast<uint16_t>(bytes[z]) << 8);
for (uint8_t bit = 0; bit < 8; bit++) {
if (crc & 0x8000) {
crc = (crc << 1) ^ 0x1021;
} else {
crc = (crc << 1);
}
}
}
return crc;
};
uint16_t crc = add_data(this, offsetof(PSOVMSFileHeader, crc), 0);
crc = add_data("\0\0", 2, crc);
crc = add_data(&this->data_size,
sizeof(PSOVMSFileHeader) - offsetof(PSOVMSFileHeader, data_size) + this->num_icons * 0x200 + this->data_size, crc);
return (crc == this->crc);
}
bool PSOGCIFileHeader::checksum_correct() const {
uint32_t cs = crc32(&this->game_name, this->game_name.bytes());
cs = crc32(&this->embedded_seed, sizeof(this->embedded_seed), cs);
+17
View File
@@ -25,6 +25,23 @@ struct ShuffleTables {
void shuffle(void* vdest, const void* vsrc, size_t size, bool reverse) const;
};
struct PSOVMSFileHeader {
/* 0000 */ ptext<char, 0x10> short_desc;
/* 0010 */ ptext<char, 0x20> long_desc;
/* 0030 */ ptext<char, 0x10> creator_id;
/* 0040 */ le_uint16_t num_icons;
/* 0042 */ le_uint16_t animation_speed;
/* 0044 */ le_uint16_t eyecatch_type;
/* 0046 */ le_uint16_t crc;
/* 0048 */ le_uint32_t data_size; // Not including header and icons
/* 004C */ parray<uint8_t, 0x14> unused;
/* 0060 */ parray<le_uint16_t, 0x10> icon_palette;
// Variable-length field:
/* 0080 */ // parray<uint8_t, num_icons> icon;
bool checksum_correct() const;
} __attribute__((packed));
struct PSOGCIFileHeader {
// Every PSOGC save file begins with a PSOGCIFileHeader. The first 0x40 bytes
// of this structure are the .gci file header; the remaining bytes after that