summaryrefslogtreecommitdiff
path: root/src/wii/common.py
blob: 40c39541aed2d1a3a972820803d691137b2271ff (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
class WiiStringTableBuilder(object):
	def __init__(self):
		self.nextOffset = 0
		self.data = ''
		self.lookup = {}
	
	def add(self, string):
		if string in self.lookup:
			return self.lookup[string]

		offset = self.nextOffset
		self.lookup[string] = offset
		
		self.data = "%s%s\0" % (self.data, string.encode('Shift-JIS'))
		self.nextOffset = len(self.data)

		return offset


def alignUp(value, alignTo):
	return (value + alignTo - 1) & ~(alignTo - 1)

def alignDown(value, alignTo):
	return value & ~(alignTo - 1)