In handmade hero you can watch the episodes about the asset file format it start at week 30 (episode 147).
Casey tackle almost the same problem but with assets instead of strings .
As @ratchetfreak said, you create a array of (size, pointer) where
pointer gives the file offset of the string and
size gives how many character to read.
The Idea is something like:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 | offset type
--------------------------------
0: file format signature
4: StringsCount
8: {CharCount, StringOffset} // string 0 entry
16: {CharCount, StringOffset} // string 1 entry
24: {CharCount, StringOffset} // string 2 entry
. .
. .
. .
??: {CharCount, StringOffset} // string StringCount-1 entry
//End of the array
//Start of the strings data
StringOffset0: String0
StringOffset1: String1
. .
. .
. .
. .
StringOffset(Count-1): String(Count-1)
End Of File
|
You can index the array which start at offset 8 in this case, as 8 bytes structures.
Then you can get the string by reading at
offset,
size characters long string as specified in the entry.
Then strings data comes after the array.
Even though the strings data comes after the array, when creating the file, the strings data will be structured in memory before the array to know what index every string will be at.
The string offsets can be from the beginning of the strings data instead of the beginning of the file which might be easier for you to do.