summaryrefslogtreecommitdiff
path: root/tools/msgbox_data.py
blob: 06eec2b3ebd17bb030ecbe00a9544b2fa496cd41 (plain)
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
messages = [
		# Message 0
		(0x100, 'A Test Message',
			'This is a test message.\nWith some lines.\nAnd more lines.\nAnd a really long line to see if nw4r::lyt can handle wrapping or not...\nFinal line.'
			),
		]

import struct, sys, os.path, codecs

if len(sys.argv) > 1:
	target = sys.argv[1]
elif os.path.exists('/home/me/Games/Newer'):
	target = '/home/me/Games/Newer/ISO/files/NewerRes/Messages.bin'
else:
	target = 'Messages.bin'

messageCount = len(messages)

stringOffset = (messageCount * 0xC) + 4
infoStruct = struct.Struct('>III')

headerData = bytearray(struct.pack('>I', messageCount))
stringData = bytearray()

for msgID, title, msg in messages:
	titleOffset = stringOffset + len(stringData)
	stringData += codecs.utf_16_be_encode(title)[0] + '\0\0'
	msgOffset = stringOffset + len(stringData)
	stringData += codecs.utf_16_be_encode(msg)[0] + '\0\0'

	headerData += infoStruct.pack(msgID, titleOffset, msgOffset)

with open(target, 'wb') as out:
	out.write(headerData)
	out.write(stringData)