~redstrate/libxiv

libxiv/src/exhparser.cpp -rw-r--r-- 916 bytes
f3feece1Joshua Goins Add deprecation notice 7 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include "exhparser.h"
#include "utility.h"

#include <cstdio>
#include <stdexcept>
#include <vector>
#include <algorithm>
#include <string>

EXH readEXH(MemorySpan data) {
    EXH exh;

    data.read(&exh.header);

    data.seek(0x20, Seek::Set);

    endianSwap(&exh.header.dataOffset);
    endianSwap(&exh.header.columnCount);
    endianSwap(&exh.header.pageCount);
    endianSwap(&exh.header.languageCount);
    endianSwap(&exh.header.rowCount);

    data.read_structures(&exh.columnDefinitions, exh.header.columnCount);
    data.read_structures(&exh.pages, exh.header.pageCount);
    data.read_structures(&exh.language, exh.header.languageCount);

    for(auto& columnDef : exh.columnDefinitions) {
        endianSwap(&columnDef.offset);
        endianSwap(&columnDef.type);
    }

    for(auto& page : exh.pages) {
        endianSwap(&page.rowCount);
        endianSwap(&page.startId);
    }

    return exh;
}