-
Notifications
You must be signed in to change notification settings - Fork 1
/
acbdl.py
174 lines (165 loc) · 5.26 KB
/
acbdl.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#!py -3
def usage():
print("\tUsage:run.py [-v <VERSION>] [-g] [-s] [-m]")
return
import os,sys
import requests
import json
import sqlite3,hashlib
from lz4 import block
import time
def dlfilefrmurl(url,path,headers):
r=requests.get(url,headers=headers)
fp=open(path,'wb')
if verbose:
print("\tWriting into disk ...")
fp.write(r.content)
fp.close()
ldate=r.headers['Last-Modified']
timeStruct=time.strptime(ldate,"%a, %d %b %Y %H:%M:%S GMT")
timestamp=time.mktime(timeStruct)+8*60*60
os.utime(path,(os.stat(path).st_atime,timestamp))
r.close()
version=None
gennamelist=False
verbose=True
md5chk=False
args=iter(sys.argv[1:])
for i in args:
if i=='-v' or i=='--version' or i=='-V' or i=='--version':
try:
version=next(args)
except Exception as e:
print("\tError:Cannot parse args:"+i,sys.stderr)
usage()
sys.exit(1)
elif i=='-g' or i=='--generate-name-list':
gennamelist=True
elif i=='-s' or i=='S' or i=='--silent':
verbose=False
elif i=='-m' or i[:5]=='--md5' or i=='--check':
md5chk=True
else:
print("\tError:Cannot parse args:"+i,sys.stderr)
usage()
sys.exit(1)
if not version:
if verbose:
print("\tGetting game version ...")
url="https://starlight.kirara.ca/api/v1/info"
r=requests.get(url)
jsonData=json.loads(r.content)
version=jsonData['truth_version']
if verbose:
print("\tGame Version = "+version)
if not os.path.exists(".\\"+version):
os.mkdir(version)
dl_headers={'User-Agent': 'Dalvik/2.1.0 (Linux; U; Android 7.0; FRD-AL00 Build/HUAWEIFRD-AL00)','X-Unity-Version': '5.4.5p1','Accept-Encoding': 'gzip'}
if not os.path.exists(".\\manifests"):
os.mkdir(".\\manifests")
dbname=".\\manifests\\manifest_"+version+".db"
lz4name=".\\manifests\\manifest_"+version+".db.lz4"
if not os.path.exists(dbname):
if not os.path.exists(lz4name):
if verbose:
print("\tDownloading lz4-compressed database ...")
url="http://storage.game.starlight-stage.jp/dl/"+version+"/manifests/Android_AHigh_SHigh"
r=requests.get(url,headers=dl_headers)
with open(lz4name,'wb') as fp:
fp.write(r.content)
fp.close()
ldate=r.headers['Last-Modified']
timeStruct=time.strptime(ldate,"%a, %d %b %Y %H:%M:%S GMT")
timestamp=time.mktime(timeStruct)+8*60*60
os.utime(lz4name,(os.stat(lz4name).st_atime,timestamp))
dat=r.content[4:]
r.close()
else:
fp=open(lz4name,'rb')
dat=fp.read()[4:]
fp.close()
dat=dat[0:4]+dat[12:]
dec=block.decompress(dat)
fp=open(dbname,'wb')
fp.write(dec)
fp.close()
del(dec)
del(dat)
if verbose:
print("\tAnalysing sqlite3 database ...")
db=sqlite3.Connection(dbname)
if gennamelist:
if verbose:
print("\tGenerating namelist.csv ...")
namelist=open(version+"\\list_name_hash_sha1.csv",'w')
query=db.execute("select name,hash from manifests")
namelist.write("name,md5,sha1\n")
for i in query:
name,hash=i
namelist.write(name+','+hash+',')
if name[1]=='/':
name=name[2:]
namelist.write(hashlib.sha1(name.encode()).hexdigest()+'\n')
query.close()
namelist.close()
query=db.execute("select name,hash from manifests where name like 'b/%.acb'")
fp1=open(version+"\\b_ren1.bat",'w')
fp2=open(version+"\\b_ren2.bat",'w')
for name,hash in query:
fp1.write("ren "+hash+' '+name[2:]+'\n')
fp2.write("ren "+name[2:]+' '+hash+'\n')
if not os.path.exists(".\\b\\"+hash):
if verbose:
print("\tDownloading file "+hash+'('+name+')')
url="http://storage.game.starlight-stage.jp/dl/resources/High/Sound/Common/b/"+hash
dlfilefrmurl(url,".\\b\\"+hash,dl_headers)
else:
if md5chk:
with open(".\\b\\"+hash,'rb') as fp:
buf=fp.read()
fp.close()
md5res=hashlib.md5(buf).hexdigest()
del(buf)
if md5res!=hash:
if verbose:
print("\tFile "+hash+'('+name+')'+" didn't pass md5check, delete and re-downloading ...")
url="http://storage.game.starlight-stage.jp/dl/resources/High/Sound/Common/b/"+hash
dlfilefrmurl(url,".\\b\\"+hash,dl_headers)
elif verbose:
print("\tFile "+hash+'('+name+')'+" already exists")
elif verbose:
print("\tFile "+hash+'('+name+')'+" already exists")
fp1.close()
fp2.close()
query=db.execute("select name,hash from manifests where name like 'l/%.acb'")
fp1=open(version+"\\l_ren1.bat",'w')
fp2=open(version+"\\l_ren2.bat",'w')
for name,hash in query:
fp1.write("ren "+hash+' '+name[2:]+'\n')
fp2.write("ren "+name[2:]+' '+hash+'\n')
if not os.path.exists(".\\l\\"+hash):
if verbose:
print("\tDownloading file "+hash+'('+name+')')
url="http://storage.game.starlight-stage.jp/dl/resources/High/Sound/Common/l/"+hash
dlfilefrmurl(url,".\\l\\"+hash,dl_headers)
else:
if md5chk:
with open(".\\l\\"+hash,'rb') as fp:
buf=fp.read()
fp.close()
md5res=hashlib.md5(buf).hexdigest()
del(buf)
if md5res!=hash:
if verbose:
print("\tFile "+hash+'('+name+')'+" didn't pass md5check, delete and re-downloading ...")
url="http://storage.game.starlight-stage.jp/dl/resources/High/Sound/Common/l/"+hash
dlfilefrmurl(url,".\\l\\"+hash,dl_headers)
elif verbose:
print("\tFile "+hash+'('+name+')'+" already exists")
elif verbose:
print("\tFile "+hash+'('+name+')'+" already exists")
fp1.close()
fp2.close()
db.close()
if verbose:
print("\tFinished analysing database ...")