mirror of
https://github.com/mon/kbinxml.git
synced 2026-09-08 16:55:10 -05:00
Merge df48dc23a4 into d21602e149
This commit is contained in:
18
bin_xml.py
18
bin_xml.py
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user