new U8 API, needs adding to other shit in archive.py

This commit is contained in:
Xuzz 2009-07-12 13:07:53 -07:00
parent 085c1a96fd
commit c3a4330a94
2 changed files with 11 additions and 8 deletions

View File

@ -89,6 +89,7 @@ class U8(WiiArchive):
def _dumpDir(self, dir): def _dumpDir(self, dir):
if(not os.path.isdir(dir)): if(not os.path.isdir(dir)):
os.mkdir(dir) os.mkdir(dir)
old = os.getcwd()
os.chdir(dir) os.chdir(dir)
for item, data in self.files: for item, data in self.files:
if(data == None): if(data == None):
@ -96,12 +97,13 @@ class U8(WiiArchive):
os.mkdir(item) os.mkdir(item)
else: else:
open(item, "wb").write(data) open(item, "wb").write(data)
os.chdir("..") os.chdir(old)
def _loadDir(self, dir): def _loadDir(self, dir):
try: try:
self._tmpPath += '' self._tmpPath += ''
except: except:
self._tmpPath = '' self._tmpPath = ''
old = os.getcwd()
os.chdir(dir) os.chdir(dir)
entries = os.listdir(".") entries = os.listdir(".")
for entry in entries: for entry in entries:
@ -112,7 +114,7 @@ class U8(WiiArchive):
elif(os.path.isfile(entry)): elif(os.path.isfile(entry)):
data = open(entry, "rb").read() data = open(entry, "rb").read()
self.files.append((self._tmpPath + entry, data)) self.files.append((self._tmpPath + entry, data))
os.chdir("..") os.chdir(old)
self._tmpPath = self._tmpPath[:self._tmpPath.find('/') + 1] self._tmpPath = self._tmpPath[:self._tmpPath.find('/') + 1]
def _load(self, data): def _load(self, data):
offset = 0 offset = 0
@ -148,7 +150,7 @@ class U8(WiiArchive):
if(node.type == 0x0100): # folder if(node.type == 0x0100): # folder
recursion.append(node.size) recursion.append(node.size)
recursiondir.append(name) 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)) self.files.append(('/'.join(recursiondir), None))
elif(node.type == 0): # file elif(node.type == 0): # file
self.files.append(('/'.join(recursiondir) + '/' + name, data[node.data_offset:node.data_offset + node.size])) self.files.append(('/'.join(recursiondir) + '/' + name, data[node.data_offset:node.data_offset + node.size]))
@ -179,10 +181,11 @@ class U8(WiiArchive):
return val return val
raise KeyError raise KeyError
def __setitem__(self, key, val): def __setitem__(self, key, val):
for i in self.files: for i in range(len(self.files)):
if(self.files[i][0] == key): if(self.files[i][0] == key):
self.files[i][1] = val self.files[i] = (self.files[i][0], val)
raise KeyError return
self.files.append((key, val))
class WAD: class WAD:

View File

@ -541,11 +541,11 @@ class TPL():
if k == 0: if k == 0:
a = (texel >> 8) & 0xff a = (texel >> 8) & 0xff
r = (texel >> 0) & 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: else:
g = (texel >> 8) & 0xff g = (texel >> 8) & 0xff
b = (texel >> 0) & 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) return ''.join(Struct.uint32(p) for p in out)
def RGB5A3(self, (w, h), jar): def RGB5A3(self, (w, h), jar):
out = [0 for i in range(w * h)] out = [0 for i in range(w * h)]