forked from HIllya51/Cartagra_FHD_CHS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpak.py
116 lines (106 loc) · 4.76 KB
/
pak.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#__type=3
for __type in [1,2,3,5]:
if __type==1:
path=r'C:\InnocentGrey\カルタグラ FHD\files\SCRIPT.PAK'
packPAKpath=r'C:\Users\wcy\Documents\GitHub\Cartagra_FHD_CHS\SCRIPT_FHD/SCRIPT_FHD_transed'
newPAKpath=r'C:\InnocentGrey\カルタグラ FHD\CHSPAK\SCRIPT.PAK'
elif __type==2:
path=r'C:\InnocentGrey\カルタグラ FHD\files\FONT.PAK'
packPAKpath=r'C:\InnocentGrey\カルタグラ FHD\files\FONT_NEW'
newPAKpath=r'C:\InnocentGrey\カルタグラ FHD\CHSPAK\FONT.PAK'
elif __type==4:
path=r'C:\InnocentGrey\カルタグラ FHD\files\FONT_V.PAK'
packPAKpath=r'C:\InnocentGrey\カルタグラ FHD\files\FONT_V_NEW'
newPAKpath=r'C:\InnocentGrey\カルタグラ FHD\CHSPAK\FONT_V.PAK'
elif __type==3:
path=r'C:\InnocentGrey\カルタグラ FHD\files\SYSFONT.PAK'
packPAKpath=r'C:\InnocentGrey\カルタグラ FHD\files\SYSFONT_NEW'
newPAKpath=r'C:\InnocentGrey\カルタグラ FHD\CHSPAK\SYSFONT.PAK'
elif __type==5:
continue
path=r'C:\InnocentGrey\カルタグラ FHD\files\PARAM.PAK'
packPAKpath=r'C:\InnocentGrey\カルタグラ FHD\files\PARAM_NEW'
newPAKpath=r'C:\InnocentGrey\カルタグラ FHD\CHSPAK\PARAM.PAK'
with open(path,'rb') as ff:
bs=ff.read()
from ctypes import c_uint,c_byte
count=(c_uint.from_buffer_copy(bs[4:4+4]).value)
#print(count)
data_offset =(c_uint.from_buffer_copy(bs[0:0+4]).value)
#print(data_offset)
block_size =(c_uint.from_buffer_copy(bs[0xC:0xC+4]).value)
print(block_size)
first_offset = data_offset // block_size;
#print(first_offset)
flags = (c_byte.from_buffer_copy(bs[0x21:0x21+1]).value)
#print(flags)
index_offset = 0x24
while (index_offset < data_offset):
if c_uint.from_buffer_copy(bs[index_offset:index_offset+4]).value == first_offset:
break;
index_offset += 4;
#print(index_offset)
names=[]
if flags&2!=0:
names_offset = c_uint.from_buffer_copy(bs[index_offset - 4:index_offset]).value;
for i in range(count):
b=bs[names_offset:names_offset+50].split(b'\x00')[0]
#print(hex(i),hex(names_offset),b.hex())
names_offset+=len(b)+1
names.append(b.decode('utf8'))
bslist=list(bs)[:first_offset*block_size]
for i in range(count):
Offset=c_uint.from_buffer_copy(bs[index_offset:index_offset+4]).value* block_size;
Size=c_uint.from_buffer_copy(bs[index_offset+4:index_offset+8]).value
print(i,names[i],hex(Offset),hex(Size),hex(Offset+Size),Offset%block_size, Size%block_size )
#size%4不为0时,填充0
# with open('unpack/'+names[i],'wb') as ff:
# ff.write(bs[Offset:Offset+Size])
with open(packPAKpath+'/'+names[i],'rb') as ff:
fbs=ff.read()
save_size=_size=len(fbs)
if (_size%block_size)!=0:
_add=block_size-_size%block_size
_size+=_add
fbs+=_add*b'\x00'
#bs[index_offset+4:index_offset+8]=
#print(hex(index_offset))
for j in range(4):
bslist[index_offset+4+j]=save_size.to_bytes(4,'little')[j]
for j in range(4):
bslist[index_offset+0+j]=first_offset.to_bytes(4,'little')[j]
first_offset+=_size//block_size
bslist+=list(fbs)
index_offset+=8
with open(newPAKpath,'wb') as ff:
ff.write(bytes(bslist))
if 0:#check
with open(newPAKpath,'rb') as ff:
bs=ff.read()
from ctypes import c_uint,c_byte
count=(c_uint.from_buffer_copy(bs[4:4+4]).value)
data_offset =(c_uint.from_buffer_copy(bs[0:0+4]).value)
block_size =(c_uint.from_buffer_copy(bs[0xC:0xC+4]).value)
first_offset = data_offset // block_size;
flags = (c_byte.from_buffer_copy(bs[0x21:0x21+1]).value)
index_offset = 0x24
while (index_offset < data_offset):
if c_uint.from_buffer_copy(bs[index_offset:index_offset+4]).value == first_offset:
break;
index_offset += 4;
print(index_offset)
names=[]
if flags&2!=0:
names_offset = c_uint.from_buffer_copy(bs[index_offset - 4:index_offset]).value;
for i in range(count):
b=bs[names_offset:names_offset+50].split(b'\x00')[0]
names_offset+=len(b)+1
#print(hex(i),hex(names_offset),b.hex())
names.append(b.decode())
bslist=list(bs)
newOffset=None
for i in range(count):
Offset=c_uint.from_buffer_copy(bs[index_offset:index_offset+4]).value* block_size;
Size=c_uint.from_buffer_copy(bs[index_offset+4:index_offset+8]).value
index_offset+=8
print(i,names[i],hex(Offset),hex(Offset+Size),Offset%block_size, Size%block_size)