-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild-client.py
144 lines (108 loc) · 4.03 KB
/
build-client.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
import os
import shutil
import glob
import zipfile
MCP_ZIP = 'http://bitbucket.org/Brunner/mcp/get/default.zip'
FERNFLOWER = 'https://github.com/Zidonuke/Bukkit-MinecraftServer/blob/master/tools/fernflower.jar?raw=true'
LWJGL_VERSION = '2.8.5'
lwjgl_jars = set(['jar/lwjgl.jar', 'jar/lwjgl_util.jar', 'jar/jinput.jar'])
def get_mcp(mcpzip=MCP_ZIP):
import zipfile
import urllib
print('+ Deleting mcp directory')
shutil.rmtree('mcp', True)
print('+ Downloading newest mcp build')
urllib.urlretrieve(mcpzip, 'mcp.zip')
print('+ Extracting mcp')
os.makedirs('mcp')
with zipfile.ZipFile('mcp.zip', 'r') as z:
z.extractall('mcp')
os.unlink('mcp.zip')
def get_client_version():
import re
import urllib
import ConfigParser
with open('net/minecraft/client/Minecraft.java', 'r') as mcf:
find = re.search('Minecraft (\d+(\.\d+)*)', mcf.read())
if find is not None: v = find.group(1)
mcv = urllib.urlopen('https://raw.github.com/MinecraftForge/FML/master/mc_versions.cfg')
config = ConfigParser.SafeConfigParser()
config.readfp(mcv)
return v, config.get(v, 'client_url'), config.get(v, 'mcp_url')
def get_minecraft_jar(version=None, jarpath=None):
import urllib
print('+ Getting minecraft.jar for ' + version)
jardir = os.path.join('jars', 'bin')
try: os.makedirs(jardir)
except OSError: pass
urllib.urlretrieve(jarpath, 'jars/bin/minecraft.jar')
print('+ Downloading fernflower.jar')
urllib.urlretrieve(FERNFLOWER, 'runtime/bin/fernflower.jar')
LWJGL = ('http://downloads.sourceforge.net/project/java-game-lib/Official Releases' +
'/LWJGL ' + LWJGL_VERSION + '/lwjgl-' + LWJGL_VERSION + '.zip')
print('+ Getting LWJGL ' + LWJGL_VERSION)
urllib.urlretrieve(LWJGL, 'lwjgl.zip')
print('+ Unzipping required LWJGL files')
with open('lwjgl.zip', 'rb') as lwjgl_zip:
z = zipfile.ZipFile(lwjgl_zip)
for item in z.namelist():
if any([item.endswith(k) for k in lwjgl_jars]):
source = z.open(item)
target = file(os.path.join(jardir, os.path.basename(item)), 'wb')
with source, target: shutil.copyfileobj(source, target)
try: os.makedirs(os.path.join(jardir, 'natives'))
except OSError: pass
def decompile():
print('+ Decompiling')
import mcp.runtime.decompile
mcp.runtime.decompile.main()
def recompile():
import mcp.runtime.mcp as mcplib
import mcp.runtime.commands as commands
cmd = commands.Commands(None, verify=True)
print('+ Recompiling')
mcplib.recompile_side(cmd, commands.CLIENT)
print('+ Reobfuscating')
cmd.creatergcfg(reobf=True, keep_lvt=True, keep_generics=False, srg_names=False)
mcplib.reobfuscate_side(cmd, commands.CLIENT, reobf_all=False, srg_names=False)
def package(root, zfile):
print('+ Packaging client mod')
resroot = os.path.join('..', 'resources')
for src_path, dirs, files in os.walk(resroot):
dst_path = src_path.replace(resroot, root)
for file_ in files:
src = os.path.join(src_path, file_)
dst = os.path.join(dst_path, file_)
try: os.makedirs(os.path.dirname(dst))
except OSError: pass
shutil.copy(src, dst)
shutil.make_archive(zfile, 'zip', root)
src_dirs = set(['argo', 'net', 'org'])
def add_changes(src, dst):
import codecs
for src_dir, dirs, files in os.walk(src):
dst_dir = src_dir.replace(src, dst)
if not os.path.exists(dst_dir):
os.mkdir(dst_dir)
for file_ in files:
src_file = os.path.join(src_dir, file_)
dst_file = os.path.join(dst_dir, file_)
print('# Copying: ' + src_file)
if os.path.exists(dst_file):
os.remove(dst_file)
shutil.copy(src_file, dst_dir)
if __name__ == '__main__':
os.chdir(os.path.dirname(os.path.realpath(__file__)))
VERSION, CLIENT_JAR, MCP_ZIP = get_client_version()
get_mcp(mcpzip=MCP_ZIP)
os.chdir('mcp')
# create a dummy init to treat mcp as a python module
with open('__init__.py', 'w') as f: pass
get_minecraft_jar(version=VERSION, jarpath=CLIENT_JAR)
decompile()
for d in src_dirs:
target = os.path.join('src', 'minecraft', d)
add_changes(src=os.path.join('..', d), dst=target)
recompile()
package(os.path.join('reobf', 'minecraft'),
os.path.join('..', 'AutoReferee-client-' + VERSION))