From c3a4330a946163e7a13717ea9965ed69d22be883 Mon Sep 17 00:00:00 2001 From: Xuzz Date: Sun, 12 Jul 2009 13:07:53 -0700 Subject: [PATCH] new U8 API, needs adding to other shit in archive.py --- archive.py | 15 +++++++++------ image.py | 4 ++-- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/archive.py b/archive.py index 233e044..ed654f4 100644 --- a/archive.py +++ b/archive.py @@ -89,6 +89,7 @@ class U8(WiiArchive): def _dumpDir(self, dir): if(not os.path.isdir(dir)): os.mkdir(dir) + old = os.getcwd() os.chdir(dir) for item, data in self.files: if(data == None): @@ -96,12 +97,13 @@ class U8(WiiArchive): os.mkdir(item) else: open(item, "wb").write(data) - os.chdir("..") + os.chdir(old) def _loadDir(self, dir): try: self._tmpPath += '' except: self._tmpPath = '' + old = os.getcwd() os.chdir(dir) entries = os.listdir(".") for entry in entries: @@ -112,7 +114,7 @@ class U8(WiiArchive): elif(os.path.isfile(entry)): data = open(entry, "rb").read() self.files.append((self._tmpPath + entry, data)) - os.chdir("..") + os.chdir(old) self._tmpPath = self._tmpPath[:self._tmpPath.find('/') + 1] def _load(self, data): offset = 0 @@ -148,7 +150,7 @@ class U8(WiiArchive): if(node.type == 0x0100): # folder recursion.append(node.size) recursiondir.append(name) - assert len(recursion) == node.data_offset + 2 #bad idea? + assert len(recursion) == node.data_offset + 2 # haxx self.files.append(('/'.join(recursiondir), None)) elif(node.type == 0): # file self.files.append(('/'.join(recursiondir) + '/' + name, data[node.data_offset:node.data_offset + node.size])) @@ -179,10 +181,11 @@ class U8(WiiArchive): return val raise KeyError def __setitem__(self, key, val): - for i in self.files: + for i in range(len(self.files)): if(self.files[i][0] == key): - self.files[i][1] = val - raise KeyError + self.files[i] = (self.files[i][0], val) + return + self.files.append((key, val)) class WAD: diff --git a/image.py b/image.py index db1d9a9..a2ecf68 100644 --- a/image.py +++ b/image.py @@ -541,11 +541,11 @@ class TPL(): if k == 0: a = (texel >> 8) & 0xff r = (texel >> 0) & 0xff - out[m + (l * x)] = out[m + (l * x)] | ((r<<0) | (a<<24)) + out[m + (l * x)] |= ((r << 0) | (a << 24)) else: g = (texel >> 8) & 0xff b = (texel >> 0) & 0xff - out[m + (l * x)] = out[m + (l * x)] | ((g<<8) | (b<<16)) + out[m + (l * x)] |= ((g << 8) | (b << 16)) return ''.join(Struct.uint32(p) for p in out) def RGB5A3(self, (w, h), jar): out = [0 for i in range(w * h)]