Skip to content

Commit ff9587e

Browse files
committed
envio de todo o material usado no projeto
1 parent 8fc620b commit ff9587e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1181
-0
lines changed
Binary file not shown.
Binary file not shown.
1.42 MB
Binary file not shown.
222 KB
Binary file not shown.
Binary file not shown.
37.3 KB
Binary file not shown.
11.4 KB
Binary file not shown.
2.6 MB
Binary file not shown.

src/texture_patches/png.rar

43.7 KB
Binary file not shown.
Lines changed: 397 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,397 @@
1+
import struct
2+
import sys
3+
import os
4+
from optparse import OptionParser
5+
6+
def openOutput(f):
7+
try:
8+
return open(f, "wb")
9+
except IOError:
10+
print "Output file could not be opened!"
11+
exit()
12+
13+
def makedir(dirname):
14+
global quiet
15+
try:
16+
os.mkdir(dirname)
17+
except OSError, e:
18+
if quiet == False:
19+
print "WARNING: Directory", dirname, "already exists!"
20+
21+
class rarc_header_class:
22+
_structformat = ">I4xI16xI8xI4xI8x"
23+
filesize = 0
24+
#4 bytes unknown
25+
dataStartOffset = 0 #where does actual data start? add 0x20
26+
#16 bytes unknown
27+
numNodes = 0
28+
#8 bytes unknown
29+
fileEntriesOffset = 0
30+
#4 bytes unknown
31+
stringTableOffset = 0 # where is the string table stored? add 0x20
32+
#8 bytes unknown
33+
def __init__(self):
34+
self._s = struct.Struct(self._structformat)
35+
def unpack(self, buf):
36+
s = self
37+
s.filesize, s.dataStartOffset, s.numNodes, s.fileEntriesOffset, s.stringTableOffset = s._s.unpack_from(buf)
38+
def size(self):
39+
#print self._s.size, "ohai"
40+
return self._s.size
41+
42+
class rarc_node_class:
43+
_structformat = ">II2xHI"
44+
type = 0
45+
filenameOffset = 0 #directory name, offset into string table
46+
#2 bytes unknown
47+
numFileEntries = 0 #how manu files belong to this node?
48+
firstFileEntryOffset = 0
49+
def __init__(self):
50+
self._s = struct.Struct(self._structformat)
51+
def unpack(self, buf):
52+
s = self
53+
s.type, s.filenameOffset, s.numFileEntries, s.firstFileEntryOffset = s._s.unpack_from(buf)
54+
def size(self):
55+
#print self._s.size
56+
return self._s.size
57+
58+
class rarc_fileEntry_class:
59+
_structformat = ">H4xHII4x"
60+
id = 0 #file id. if 0xFFFF, this entry is a subdir link
61+
#4 bytes unknown
62+
filenameOffset = 0 #file/subdir name, offset into string table
63+
dataOffset = 0 #offset to file data (for subdirs: index of node representing subdir)
64+
dataSize = 0 #size of data
65+
def __init__(self):
66+
self._s = struct.Struct(self._structformat)
67+
def unpack(self, buf):
68+
s = self
69+
s.id, s.filenameOffset, s.dataOffset, s.dataSize = s._s.unpack_from(buf)
70+
def size(self):
71+
return self._s.size
72+
73+
class U8_archive_header:
74+
_structformat = ">III16x"
75+
rootnode_offset = 0 #offset to root_node, always 0x20
76+
header_size = 0 #size of header from root_node to end of string table
77+
data_offset = 0 #offset to data: rootnode_offset + header_size aligned to 0x40
78+
#16 bytes zeros
79+
def __init__(self):
80+
self._s = struct.Struct(self._structformat)
81+
def unpack(self, buf):
82+
s = self
83+
s.rootnode_offset, s.header_size, s.data_offset = s._s.unpack_from(buf)
84+
def size(self):
85+
return self._s.size
86+
87+
class U8_node:
88+
_structformat = ">HHII"
89+
type = 0 #really u8, normal files = 0x0000, directories = 0x0100
90+
name_offset = 0 #really 'u24'
91+
data_offset = 0
92+
fsize = 0 #files: filesize, dirs: last included file with rootnode as 1
93+
def __init__(self):
94+
self._s = struct.Struct(self._structformat)
95+
def unpack(self, buf):
96+
s = self
97+
s.type, s.name_offset, s.data_offset, s.fsize = s._s.unpack_from(buf)
98+
def size(self):
99+
return self._s.size
100+
101+
class U8_globals:
102+
pass
103+
104+
def unyaz(input, output):
105+
global quiet, list
106+
#shamelessly stolen^W borrowed from yagcd
107+
data_size, = struct.unpack_from(">I", input.read(4)) #uncompressed data size
108+
if list:
109+
print "Uncompressed size:", data_size, "bytes"
110+
return
111+
t = input.read(8) #dummy
112+
srcplace = 0
113+
dstplace = 0
114+
bitsleft = 0
115+
currbyte = 0
116+
if quiet == False:
117+
print "Reading input"
118+
src = input.read()
119+
dst = [" "]*data_size
120+
#print len(dst), len(src)
121+
percent = 0
122+
if quiet == False:
123+
sys.stdout.write("Decompressing 0%")
124+
sys.stdout.flush()
125+
while dstplace < data_size:
126+
if bitsleft == 0:
127+
currbyte = ord(src[srcplace])
128+
srcplace += 1
129+
bitsleft = 8
130+
if (currbyte & 0x80) != 0:
131+
dst[dstplace] = src[srcplace]
132+
dstplace += 1
133+
srcplace += 1
134+
else:
135+
byte1 = ord(src[srcplace])
136+
byte2 = ord(src[srcplace+1])
137+
srcplace += 2
138+
dist = ((byte1 & 0xF) << 8) | byte2
139+
copySource = dstplace - (dist + 1)
140+
numbytes = byte1 >> 4
141+
if numbytes == 0:
142+
numbytes = ord(src[srcplace]) + 0x12
143+
srcplace += 1
144+
else:
145+
numbytes += 2
146+
j = 0
147+
for i in range(0, numbytes):
148+
dst[dstplace] = dst[copySource]
149+
copySource += 1
150+
dstplace += 1
151+
j += 1
152+
currbyte = (currbyte << 1)
153+
bitsleft -= 1
154+
if quiet == False:
155+
calcpercent = ((dstplace*1.0)/data_size)*100
156+
if int(calcpercent) > percent:
157+
if int(calcpercent) > 9:
158+
sys.stdout.write("\b")
159+
sys.stdout.write("\b\b" + str(int(calcpercent)) + "%")
160+
sys.stdout.flush()
161+
percent = calcpercent
162+
if quiet == False:
163+
print "\nWriting output"
164+
output.write("".join(dst))
165+
166+
def getNode(index, f, h):
167+
retval = rarc_node_class()
168+
f.seek(h.size() + 4 + index*retval.size())
169+
s = f.read(retval.size())
170+
retval.unpack(s)
171+
return retval
172+
173+
def getString(pos, f):
174+
t = f.tell()
175+
f.seek(pos)
176+
retval = []
177+
char = 0
178+
while True:
179+
char = f.read(1)
180+
if char == "\0":
181+
break
182+
retval.append(char)
183+
f.seek(t)
184+
return "".join(retval)
185+
186+
def getFileEntry(index, h, f):
187+
retval = rarc_fileEntry_class()
188+
f.seek(h.fileEntriesOffset + index*retval.size() + 0x20)
189+
retval.unpack(f.read(retval.size()))
190+
return retval
191+
192+
def processNode(node, h, f):
193+
global quiet, depthnum, list
194+
nodename = getString(node.filenameOffset + h.stringTableOffset + 0x20, f)
195+
if list == False:
196+
if quiet == False:
197+
print "Processing node", nodename
198+
makedir(nodename)
199+
os.chdir(nodename)
200+
else:
201+
print (" "*depthnum) + nodename + "/"
202+
depthnum += 1
203+
for i in range(0, node.numFileEntries):
204+
currfile = getFileEntry(node.firstFileEntryOffset + i, h, f)
205+
currname = getString(currfile.filenameOffset + h.stringTableOffset + 0x20, f)
206+
if (currfile.id == 0xFFFF): #file is a subdir
207+
if currname != "." and currname != "..": # don't go to "." and ".."
208+
processNode(getNode(currfile.dataOffset, f, h), h, f)
209+
else:
210+
if list:
211+
print (" "*depthnum) + currname, "-", currfile.dataSize
212+
continue
213+
if quiet == False:
214+
print "Dumping", nodename + "/" + currname, " 0%",
215+
try:
216+
percent = 0
217+
dest = open(currname, "wb")
218+
f.seek(currfile.dataOffset + h.dataStartOffset + 0x20)
219+
size = currfile.dataSize
220+
while size > 0:
221+
if quiet == False:
222+
calcpercent = int(((currfile.dataSize-size)/(currfile.dataSize*1.0))*100)
223+
calcpercent = int(calcpercent)
224+
if calcpercent > percent:
225+
if calcpercent > 9:
226+
sys.stdout.write("\b")
227+
sys.stdout.write("\b\b" + str(calcpercent) + "%")
228+
sys.stdout.flush()
229+
percent = calcpercent
230+
dest.write(f.read(size))
231+
size -= 1024
232+
if quiet == False:
233+
if percent > 9:
234+
sys.stdout.write("\b")
235+
sys.stdout.write("\b\b100%")
236+
print ""
237+
dest.close()
238+
except IOError:
239+
print "OMG SOMETHING WENT WRONG!!!!1111!!!!!"
240+
exit()
241+
if list == False:
242+
os.chdir("..")
243+
else:
244+
depthnum -= 1
245+
246+
def unrarc(i, o):
247+
global list
248+
header = rarc_header_class()
249+
header.unpack(i.read(header.size()))
250+
if list == False:
251+
try:
252+
makedir(o)
253+
except:
254+
pass
255+
os.chdir(o)
256+
processNode(getNode(0, i, header), header, i)
257+
258+
def get_u8_name(i, g, node):
259+
retval = []
260+
i.seek(g.string_table + node.name_offset-1)
261+
while True:
262+
t = i.read(1)
263+
if t == "\0":
264+
break
265+
retval.append(t)
266+
return "".join(retval)
267+
268+
def get_u8_node(i, g, index):
269+
retval = U8_node()
270+
index -= 1
271+
i.seek(g.header.rootnode_offset + (index * retval.size()))
272+
retval.unpack(i.read(retval.size()))
273+
return retval
274+
275+
def unu8(i, o):
276+
global quiet, depthnum, list
277+
header = U8_archive_header()
278+
header.unpack(i.read(header.size()))
279+
if list == False:
280+
try:
281+
makedir(o)
282+
except:
283+
pass
284+
os.chdir(o)
285+
root = U8_node()
286+
root.unpack(i.read(header.size()))
287+
g = U8_globals()
288+
g.rootnode = root
289+
g.numnodes = root.fsize
290+
g.header = header
291+
g.string_table = ((root.fsize)*root.size()) + header.rootnode_offset + 1
292+
depth = [root.fsize]
293+
for index in range(2, root.fsize+1):
294+
node = get_u8_node(i, g, index)
295+
name = get_u8_name(i, g, node)
296+
if list:
297+
if node.type == 0:
298+
print (" "*depthnum) + name, "-", node.fsize, "bytes"
299+
elif node.type == 0x0100:
300+
print (" "*depthnum) + name + "/"
301+
depthnum += 1
302+
depth.append(node.fsize)
303+
elif node.type == 0:
304+
if quiet == False:
305+
print "Dumping file node", name, " 0%",
306+
i.seek(node.data_offset)
307+
try:
308+
dest = open(name, "wb")
309+
percent = 0
310+
size = node.fsize
311+
while size > 0:
312+
if quiet == False:
313+
calcpercent = int(((node.fsize-size)/(node.fsize*1.0))*100)
314+
if calcpercent > percent:
315+
if calcpercent > 9:
316+
sys.stdout.write("\b")
317+
sys.stdout.write("\b\b" + str(calcpercent) + "%")
318+
sys.stdout.flush()
319+
percent = calcpercent
320+
dest.write(f.read(size))
321+
size -= 1024
322+
if quiet == False:
323+
if percent > 9:
324+
sys.stdout.write("\b")
325+
sys.stdout.write("\b\b100%\n")
326+
dest.close()
327+
except IOError:
328+
print "OMG SOMETHING WENT WRONG!!!!!!!111111111!!!!!!!!"
329+
exit()
330+
elif node.type == 0x0100:
331+
if quiet == False:
332+
print "Processing node", name
333+
makedir(name)
334+
os.chdir(name)
335+
depth.append(node.fsize)
336+
if index == depth[-1]:
337+
if list == False:
338+
os.chdir("..")
339+
depthnum -= 1
340+
depth.pop()
341+
if list == False:
342+
os.chdir("..")
343+
344+
def main():
345+
global of, quiet, list, depthnum
346+
parser = OptionParser(usage="python %prog [-q] [-o <output>] <inputfile> [inputfile2] ... [inputfileN]", version="ARCTool 0.3b")
347+
parser.add_option("-o", "--output", action="store", type="string", dest="of", help="write output to FILE/DIR. If you are extracting multiple archives, all of them will be put in this dir.", metavar="FILE/DIR")
348+
parser.add_option("-q", "--quiet", action="store_true", dest="quiet", default=False, help="don't print anything (except errors)")
349+
parser.add_option("-l", "--list", action="store_true", dest="list", default=False, help="print a list of files contained in the specified archive (ignores -q)")
350+
351+
352+
(options, args) = parser.parse_args()
353+
354+
of = options.of
355+
quiet = options.quiet
356+
list = options.list
357+
358+
depthnum = 0
359+
360+
if len(args) < 1:
361+
parser.error("Input filename required")
362+
363+
if len(args) > 1:
364+
if options.of != None:
365+
makedir(of)
366+
os.chdir(of)
367+
368+
for file in args:
369+
if options.of == None or len(args) > 1:
370+
of = os.path.split(file)[1] + ".extracted"
371+
if len(args) > 1 and options.of != None:
372+
file = "../" + file
373+
try:
374+
f = open(file, "rb")
375+
except IOError:
376+
print "Input file could not be opened!"
377+
exit()
378+
type = f.read(4)
379+
if type == "Yaz0":
380+
if quiet == False:
381+
print "Yaz0 compressed archive"
382+
unyaz(f, openOutput(of))
383+
elif type == "RARC":
384+
if quiet == False:
385+
print "RARC archive"
386+
unrarc(f, of)
387+
elif type == "U\xAA8-":
388+
if quiet == False:
389+
print "U8 archive"
390+
unu8(f, of)
391+
else:
392+
print "Unknown archive type!"
393+
exit()
394+
f.close()
395+
396+
if __name__ == "__main__":
397+
main()

0 commit comments

Comments
 (0)