This commit is contained in:
Will Xyen L
2017-06-21 08:23:13 +00:00
committed by GitHub

View File

@@ -83,6 +83,12 @@ class kbinxml():
raise ValueError('Node name can only contain alphanumeric + underscore')
return ''.join(map(chr, compress))
def align_dataBuf(self):
# padding
while len(self.dataBuf) % 4:
self.dataBuf.append_u8(0)
def data_grab_auto(self):
size = self.dataBuf.get_s32()
ret = [self.dataBuf.get_u8() for x in range(size)]
@@ -95,10 +101,7 @@ class kbinxml():
def data_append_auto(self, data):
self.dataBuf.append_s32(len(data))
self.dataBuf.append(data, 's', len(data))
# padding
while len(self.dataBuf) % 4:
self.dataBuf.append_u8(0)
self.align_dataBuf()
def data_append_string(self, string):
string = string.encode('shift_jisx0213') + '\0'
@@ -151,6 +154,7 @@ class kbinxml():
self.dataWordBuf.set(data, self.dataWordBuf.offset, type, count)
else:
self.dataBuf.append(data, type, count)
self.align_dataBuf()
def is_binary_xml(self, input):
nodeBuf = ByteBuffer(input)
@@ -188,8 +192,7 @@ class kbinxml():
self.dataBuf.append_u32(len(data) * calcsize(fmt['type']))
self.dataBuf.append(data, fmt['type'], len(data))
# padding
while len(self.dataBuf) % 4:
self.dataBuf.append_u8(0)
self.align_dataBuf()
else:
self.data_append_aligned(data, fmt['type'], fmt['count'])
@@ -217,7 +220,7 @@ class kbinxml():
header = ByteBuffer()
header.append_u16(SIGNATURE)
header.append_u8(4 << 5) # SHIFT-JIS TODO make encoding variable
header.append_u8(0x7F) # TODO what does this do as 7f or ff
header.append_u8(0x7F) # Binary negation of encoding variable
self.nodeBuf = ByteBuffer()
self.dataBuf = ByteBuffer()
self.dataByteBuf = ByteBuffer(self.dataBuf.data)
@@ -227,6 +230,7 @@ class kbinxml():
self._node_to_binary(child)
self.nodeBuf.append_u8(xml_types['endSection'] | 64)
# align nodeBuf
while len(self.nodeBuf) % 4 != 0:
self.nodeBuf.append_u8(0)
header.append_u32(len(self.nodeBuf))