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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*!
CK3 save files can be encoded in 4 different formats:
- autosave (binary / text)
- standard
- ironman
Let's start with standard and ironman first. These two are similar in that there are three
sections:
- a save id line
- the header
- a zip with the compressed gamestate
For standard saves, the header and the compressed gamestate are plaintext. Ironman saves use the
standard PDS binary format (not explained here).
What is interesting is that the gamestate contains the same header info. So one can bypass the
header and skip right to the zip file and there won't be any loss of data.
Now for autosave format:
- a save id line
- uncompressed gamestate in the binary or text format
These 4 formats pose an interesting challenge. If we only looked for the zip file signature (to
split the file to ensure our parser doesn't start interpretting zip data), we may end up scanning
100MB worth of data before realizing it's an autosave. This would be bad for performance. The
solution is to take advantage that zips orient themselves at the end of the file, so we assume
a zip until further notice.
In short, to know what the save file format:
- Attempt to parse as zip
- if not a zip, we know it's an autosave
- else if the 3rd and 4th byte are `01 00` then we know it's ironman
- else it's a standard save
*/
/// Describes the format of the save before decoding