@ -1,6 +1,8 @@
@@ -1,6 +1,8 @@
#PAC Extractor
#coded by James
#! python2
#import
import sys , os
from struct import *
@ -25,8 +27,8 @@ def getType(str):
@@ -25,8 +27,8 @@ def getType(str):
try :
if str [ : 4 ] . encode ( " hex " ) . upper ( ) == " 4D4F4420 " or str [ : 3 ] == " MOD " :
suf = " mod "
elif str [ : 4 ] == " TIM2 " :
suf = " tm2 "
elif str [ : 4 ] . encode ( " hex " ) . upper ( ) == " 44445320 " or str [ : 3 ] == " DDS " :
suf = " dds "
elif str [ : 4 ] . encode ( " hex " ) . upper ( ) == " 53485720 " or str [ : 3 ] == " SHW " :
suf = " shw "
elif str [ : 3 ] == " MOT " or str [ : 4 ] . encode ( " hex " ) . upper ( ) == " 50000000 " :
@ -59,7 +61,7 @@ def getType(str):
@@ -59,7 +61,7 @@ def getType(str):
suf = " tsb "
elif str [ : 2 ] == " # " :
suf = " txt "
# elif str[:4] == "ff&A":
# elif str[:4] == "ff&A":
# suf = "ff"
elif str [ : 1 ] == " ; " :
suf = " txt "
@ -80,11 +82,15 @@ def PTX(str, ptx_name, pac_name):
@@ -80,11 +82,15 @@ def PTX(str, ptx_name, pac_name):
num_files = unpack ( " <I " , str [ : 4 ] ) [ 0 ] #number of files
offsets = [ ]
last = 0
trail_str = str [ 2056 : 2160 ]
trail_open = open ( " %s \\ %s .trail " % ( pac_name , ptx_name ) , " wb " )
trail_open . write ( trail_str )
trail_open . close ( )
#too lazy to properly write it, just searched
for i in range ( num_files ) :
offsets . append ( str . find ( " TIM2 " , last ) )
last = str . find ( " TIM2 " , last ) + 4
offsets . append ( str . find ( " DDS " , last ) )
last = str . find ( " DDS " , last ) + 4
#make another sub directory
try :
@ -99,14 +105,14 @@ def PTX(str, ptx_name, pac_name):
@@ -99,14 +105,14 @@ def PTX(str, ptx_name, pac_name):
except IndexError :
file_str = str [ offsets [ i ] : ]
#index files, and writing contents
index_file . write ( " %s _ %.3d .tm2 \n " % ( ptx_name , i ) )
print " \t Writing: %s _ %.3d .tm2 " % ( ptx_name , i )
index_file . write ( " %s _ %.3d .dds \n " % ( ptx_name , i ) )
print " \t Writing: %s _ %.3d .dds " % ( ptx_name , i )
try :
file_open = open ( " %s \\ %s \\ %s _ %.3d .tm2 " % ( pac_name , ptx_name , ptx_name , i ) , " wb " )
file_open = open ( " %s \\ %s \\ %s _ %.3d .dds " % ( pac_name , ptx_name , ptx_name , i ) , " wb " )
file_open . write ( file_str )
file_open . close ( )
except :
print " \t Error Writing %s _ %.3d .tm2 " % ( ptx_name , i )
print " \t Error Writing %s _ %.3d .dds " % ( ptx_name , i )
return 0
def main ( ) :
@ -159,7 +165,7 @@ def main():
@@ -159,7 +165,7 @@ def main():
except IndexError :
file_str = pac_str [ offsets [ i ] : ]
if " TIM2 " in file_str [ 4 : ] and " PAC " not in file_str and " PNST " not in file_str :
if " DDS " in file_str [ 4 : ] and " PAC " not in file_str and " PNST " not in file_str :
print " %X " % offsets [ i ]
PTX ( file_str , " %s _ %.3d " % ( pac_name , i ) , pac_name )
index_file . write ( " %s folder \n " % ( " %s _ %.3d " % ( pac_name , i ) ) )