This repository has been archived by the owner on Jan 26, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Compiler.py
79 lines (68 loc) · 3.75 KB
/
Compiler.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
import base64
import os
import shutil
import struct
import sys
import time
import zlib
class Compiler:
@staticmethod
def str_to_l(st):
return struct.unpack('q', st)[0]
def z_unpack(self, src, dst):
with open(src, 'rb') as f_src:
try:
os.makedirs(dst.replace(src.split("/")[-1:][0], ""))
except:
pass
with open(dst[:-2], 'wb') as f_dst:
f_src.read(8)
size1 = self.str_to_l(f_src.read(8))
f_src.read(8)
size2 = self.str_to_l(f_src.read(8))
if (size1 == -1641380927):
size1 = 131072L
runs = (size2 + size1 - 1L) / size1
array = []
for i in range(runs):
array.append(f_src.read(8))
f_src.read(8)
for i in range(runs):
to_read = array[i]
compressed = f_src.read(self.str_to_l(to_read))
decompressed = zlib.decompress(compressed)
f_dst.write(decompressed)
def __init__(self, src_file, des_file):
self.z_unpack(src_file, des_file)
class Main:
def __init__(self, src_dir, des_dir, mod_id):
if self.make(src_dir, des_dir):
if self.mod_file(src_dir, des_dir, mod_id):
os.rename(des_dir + "/.mod", des_dir + "/../" + mod_id + ".mod")
print "UPDATE Successfully " + mod_id
@staticmethod
def make(src_dir, des_dir):
files = os.popen("find " + src_dir + "/WindowsNoEditor/" + " -name *.z").read().split("\n")
for File in files:
if len(File) > 1:
Compiler(File, File.replace("/WindowsNoEditor", "").replace(src_dir, des_dir))
try:
shutil.copy(src_dir + "/WindowsNoEditor/modmeta.info", des_dir + "/modmeta.info")
shutil.copy(src_dir + "/WindowsNoEditor/mod.info", des_dir + "/mod.info")
except:
pass
return True
@staticmethod
def mod_file(src_dir, des_dir, mod_id):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DAwXHgwMDFceDAwJyA+PiIkbW9kZGVzdGRpci8ubW9kIgoJICBlY2hvIGNhdCAiJG1vZGRlc3RkaXIvLm1vZCIKICAgIGZpCiAgICBlY2hvICIkbW9kYnJhbmNoIiA+IiRtb2RkZXN0ZGlyLy5tb2RicmFuY2giCg==").replace(
"4512545412125", des_dir).replace("50514154545", mod_id)
open(src_dir + "/Mod.sh", "w").write(shell_file)
print "Make {0} mod".format(mod_id)
os.popen("bash " + src_dir + "/Mod.sh")
time.sleep(0.5)
os.remove(des_dir + "/.modbranch")
os.remove(src_dir + "/Mod.sh")
return True
if __name__ == '__main__':
Main(sys.argv[1], sys.argv[2], sys.argv[3])