diff --git a/.gitignore b/.gitignore
index 7e93314700..cd3a8964e9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -13,3 +13,4 @@ fmlbranding.properties
/eclipse
/deobfuscation_data*.zip
/binpatch
+/mcp_data/
diff --git a/build.xml b/build.xml
index f589a72ff8..91ffe0ee54 100644
--- a/build.xml
+++ b/build.xml
@@ -79,8 +79,11 @@
+
+
+
@@ -268,7 +271,9 @@
+
+
@@ -276,9 +281,10 @@
+
+
-
diff --git a/commands.patch b/commands.patch
index f919e80d44..4271696d40 100644
--- a/commands.patch
+++ b/commands.patch
@@ -1,125 +1,15 @@
--- commands.py
+++ commands.py
-@@ -58,6 +58,8 @@
-
-
- def reallyrmtree(path):
-+ if os.path.isfile(os.path.join(path, 'asm-4.1.tar.gz')): #Check if asm exists, indicating the libs folder, if so, don't delete it
-+ return
- if not sys.platform.startswith('win'):
- if os.path.exists(path):
- shutil.rmtree(path)
-@@ -139,6 +141,8 @@
+@@ -142,6 +142,8 @@
fieldnames = csvreader.fieldnames
return set(fieldnames)
+def commands_sanity_check():
-+ print 'Commands patch applied successfully'
++ print ' Commands patch applied successfully'
class Commands(object):
"""Contains the commands and initialisation for a full mcp run"""
-@@ -194,6 +198,7 @@
- sys.exit(1)
-
- self.checkjava()
-+ self.checkscala()
- self.readcommands(verify, no_patch=no_patch)
-
- def checkcommand(self, name, command, java=False, single_line=False, check_return=True, error=True):
-@@ -230,6 +235,9 @@
- self.checkcommand('java', '%s -version' % self.cmdjava)
- self.checkcommand('javac', '%s -version' % self.cmdjavac)
- self.checkcommand('javac runtime', '%s -J-version' % self.cmdjavac)
-+ if self.cmdscalac:
-+ self.checkcommand('scalac', '%s -version' % self.cmdscalac)
-+ self.checkcommand('scalac runtime', '%s -J-version' % self.cmdscalac)
- self.checkcommand('retroguard', '%s --version' % self.retroguard, java=True)
-
- self.exceptor = os.path.normpath(self.config.get('COMMANDS', 'Exceptor'))
-@@ -268,6 +276,24 @@
- self.astyle = os.path.normpath(self.config.get('COMMANDS', 'AStyle_%s' % self.osname))
- if verify:
- self.has_astyle = self.checkcommand('astyle', '%s --version' % self.astyle, error=False)
-+
-+ if verify:
-+ output = self.runcmd('%s --version' % self.astyle).rstrip().split(' ')
-+ try:
-+ version = output[len(output) - 1].split('.')
-+ if int(version[0]) >= 2 and int(version[1]) >= 0:
-+ self.has_astyle = True
-+ else:
-+ self.logger.error('!! Astyle version out of date, 2.0+ required found: \"%s\"' % output[len(output) - 1])
-+ self.as_astyle = False
-+ except:
-+ self.logger.error('!! Could not extract astyle version information !!')
-+ self.logger.error(sys.exc_info()[0])
-+ self.has_astyle = False
-+
-+ if not self.has_astyle:
-+ self.logger.error('!! astyle is needed for FML, can not continue !!')
-+ sys.exit(1)
-
- # only check jad and jadretro if we can use it
- if self.jad:
-@@ -324,6 +350,8 @@
- reqs.append('astyle')
- if self.has_astyle_cfg:
- reqs.append('astyle config')
-+ if self.cmdscalac:
-+ reqs.append('scalac')
- self.logger.info('# found %s', ', '.join(reqs))
- if not self.has_jad_patch and not no_patch:
- self.has_jad = False
-@@ -350,6 +378,13 @@
- self.cmdfernflower = self.config.get('COMMANDS', 'CmdFernflower', raw=1) % (self.cmdjava, self.fernflower)
- self.cmdexceptor = self.config.get('COMMANDS', 'CmdExceptor', raw=1) % (self.cmdjava, self.exceptor)
- self.cmdrecomp = self.config.get('COMMANDS', 'CmdRecomp', raw=1) % self.cmdjavac
-+ try:
-+ if self.cmdscalac:
-+ self.cmdrecompscalac = self.config.get('COMMANDS', 'CmdRecompScalac', raw=1) % self.cmdscalac
-+ else:
-+ self.cmdrecompscalac = None
-+ except ConfigParser.NoOptionError:
-+ pass
- self.cmdstartsrv = self.config.get('COMMANDS', 'CmdStartSrv', raw=1) % self.cmdjava
- self.cmdstartclt = self.config.get('COMMANDS', 'CmdStartClt', raw=1) % self.cmdjava
-
-@@ -753,6 +788,34 @@
- self.cmdjavac = '"%s"' % os.path.join(results[0], 'javac')
- self.cmdjava = '"%s"' % os.path.join(results[0], 'java')
-
-+ def checkscala(self):
-+ cmd = None
-+ try:
-+ # TODO: Verify at least version 2.10
-+ self.runcmd('scalac -version', quiet=True)
-+ cmd = 'scalac'
-+ except (CalledProcessError, OSError):
-+ pass
-+ if cmd is None: # Stupid windows...
-+ try:
-+ # TODO: Verify at least version 2.10
-+ self.runcmd('scalac.bat -version', quiet=True)
-+ cmd = 'scalac.bat'
-+ except (CalledProcessError, OSError):
-+ pass
-+
-+ if cmd is None:
-+ self.logger.warning('"scalac" is not found on the PATH. Scala files will not be recompiled')
-+ self.cmdscalac = None
-+ else:
-+ self.cmdscalac = '"%s"' % cmd
-+
-+ try:
-+ self.runcmd('%s -target:jvm-1.6 -version' % self.cmdscalac, quiet=True)
-+ except (CalledProcessError, OSError):
-+ self.logger.info('%s does not support jvm-1.6 target, it is out of date. Ignoring' % self.cmdscalac)
-+ self.cmdscalac = None
-+
- def checkjars(self, side):
- jarlk = {CLIENT: self.jarclient, SERVER: self.jarserver}
- md5jarlk = {CLIENT: self.md5jarclt, SERVER: self.md5jarsrv}
-@@ -798,6 +861,8 @@
+@@ -980,6 +982,8 @@
binlk = {CLIENT: self.binclient, SERVER: self.binserver}
testlk = {CLIENT: self.testclient, SERVER: self.testserver}
@@ -128,7 +18,7 @@
if not os.path.exists(os.path.join(binlk[side], os.path.normpath(testlk[side] + '.class'))):
return False
return True
-@@ -1038,6 +1103,9 @@
+@@ -1311,6 +1315,9 @@
pathbinlk = {CLIENT: self.binclient, SERVER: self.binserver}
pathsrclk = {CLIENT: self.srcclient, SERVER: self.srcserver}
pathlog = {CLIENT: self.clientrecomplog, SERVER: self.serverrecomplog}
@@ -138,46 +28,7 @@
if not os.path.exists(pathbinlk[side]):
os.makedirs(pathbinlk[side])
-@@ -1051,6 +1119,29 @@
- all_files = True
- append_pattern = False
- pkglist = filterdirs(pathsrclk[side], '*.java', append_pattern=append_pattern, all_files=all_files)
-+ if self.cmdrecompscalac: # Compile scala before java as scala scans java files, but not vice-versa
-+ pkglistscala = pkglist[:]
-+ pkglistscala.extend(filterdirs(pathsrclk[side], '*.scala', append_pattern=append_pattern, all_files=all_files))
-+ dirs = ' '.join(pkglistscala)
-+ classpath = os.pathsep.join(cplk[side])
-+ forkcmd = self.cmdrecompscalac.format(classpath=classpath, sourcepath=pathsrclk[side], outpath=pathbinlk[side], pkgs=dirs)
-+ try:
-+ self.runcmd(forkcmd, log_file=pathlog[side])
-+ except CalledProcessError as ex:
-+ self.logger.error('')
-+ self.logger.error('== ERRORS FOUND in SCALA CODE ==')
-+ self.logger.error('')
-+ for line in ex.output.splitlines():
-+ if line.strip():
-+ if line.find("jvm-1.6") != -1:
-+ self.logger.error(' === Your scala version is out of date, update to at least 2.10.0 ===')
-+ if line[0] != '[' and line[0:4] != 'Note':
-+ self.logger.error(line)
-+ if '^' in line:
-+ self.logger.error('')
-+ self.logger.error('================================')
-+ self.logger.error('')
-+ raise
- dirs = ' '.join(pkglist)
- classpath = os.pathsep.join(cplk[side])
- forkcmd = self.cmdrecomp.format(classpath=classpath, sourcepath=pathsrclk[side], outpath=pathbinlk[side],
-@@ -1059,7 +1150,7 @@
- self.runcmd(forkcmd, log_file=pathlog[side])
- except CalledProcessError as ex:
- self.logger.error('')
-- self.logger.error('== ERRORS FOUND ==')
-+ self.logger.error('== ERRORS FOUND in JAVA CODE ==')
- self.logger.error('')
- for line in ex.output.splitlines():
- if line.strip():
-@@ -1072,7 +1163,7 @@
+@@ -1368,7 +1375,7 @@
raise
def startserver(self):
@@ -186,7 +37,7 @@
classpath = [os.path.join('..', p) for p in classpath]
classpath = os.pathsep.join(classpath)
os.chdir(self.dirjars)
-@@ -1080,7 +1171,7 @@
+@@ -1376,7 +1383,7 @@
self.runmc(forkcmd)
def startclient(self):
@@ -195,47 +46,7 @@
classpath = [os.path.join('..', p) for p in classpath]
classpath = os.pathsep.join(classpath)
natives = os.path.join('..', self.dirnatives)
-@@ -1207,20 +1298,20 @@
- with open(self.csvmethods, 'rb') as fh:
- methodsreader = csv.DictReader(fh)
- for row in methodsreader:
-- if int(row['side']) == side:
-+ if int(row['side']) == side or int(row['side']) == 2:
- if row['name'] != row['searge']:
- names['methods'][row['searge']] = row['name']
- with open(self.csvfields, 'rb') as fh:
- fieldsreader = csv.DictReader(fh)
- for row in fieldsreader:
-- if int(row['side']) == side:
-+ if int(row['side']) == side or int(row['side']) == 2:
- if row['name'] != row['searge']:
- names['fields'][row['searge']] = row['name']
- if self.has_param_csv:
- with open(self.csvparams, 'rb') as fh:
- paramsreader = csv.DictReader(fh)
- for row in paramsreader:
-- if int(row['side']) == side:
-+ if int(row['side']) == side or int(row['side']) == 2:
- names['params'][row['param']] = row['name']
-
- regexps = {
-@@ -1354,13 +1445,13 @@
- methods = {}
- for row in methodsreader:
- #HINT: Only include methods that have a non-empty description
-- if int(row['side']) == side and row['desc']:
-+ if (int(row['side']) == side or int(row['side']) == 2) and row['desc']:
- methods[row['searge']] = row['desc'].replace('*/', '* /')
-
- fields = {}
- for row in fieldsreader:
- #HINT: Only include fields that have a non-empty description
-- if int(row['side']) == side and row['desc']:
-+ if (int(row['side']) == side or int(row['side']) == 2) and row['desc']:
- fields[row['searge']] = row['desc'].replace('*/', '* /')
-
- regexps = {
-@@ -1437,7 +1528,7 @@
+@@ -1733,7 +1740,7 @@
self.runcmd(forkcmd)
return True
@@ -244,7 +55,7 @@
if not reobf:
md5lk = {CLIENT: self.md5client, SERVER: self.md5server}
else:
-@@ -1452,6 +1543,9 @@
+@@ -1748,6 +1755,9 @@
class_path = ''
else:
class_path += '/'
@@ -254,40 +65,7 @@
for class_file in fnmatch.filter(filelist, '*.class'):
class_name = class_path + os.path.splitext(class_file)[0]
bin_file = os.path.normpath(os.path.join(path, class_file))
-@@ -1548,6 +1642,8 @@
- if not os.path.exists(outpathlk[side]):
- os.makedirs(outpathlk[side])
-
-+ reserved = ['CON', 'PRN', 'AUX', 'NUL', 'COM1', 'COM2', 'COM3', 'COM4', 'COM5', 'COM6', 'COM7', 'COM8', 'COM9', 'LPT1', 'LPT2', 'LPT3', 'LPT4', 'LPT5', 'LPT6', 'LPT7', 'LPT8', 'LPT9']
-+
- # HINT: We extract the modified class files
- with closing(zipfile.ZipFile(jarlk[side])) as zipjar:
- for in_class in trgclasses:
-@@ -1561,6 +1657,23 @@
- out_class = out_class.replace(self.nullpkg, '')
- if out_class[0] == '/':
- out_class = out_class[1:]
-+
-+ rename = False
-+ for res in reserved:
-+ if out_class.upper().startswith(res):
-+ rename = True
-+ break
-+
-+ if rename:
-+ try:
-+ f = open(os.path.join(outpathlk[side], '_' + out_class), 'wb')
-+ f.write(zipjar.read(out_class))
-+ f.close()
-+ self.logger.info('> Outputted %s to %s as %s', in_class.ljust(35), outpathlk[side], '_' + out_class)
-+ except IOError:
-+ self.logger.error('* File %s failed extracting for %s', out_class, in_class)
-+ continue
-+
- try:
- zipjar.extract(out_class, outpathlk[side])
- self.logger.info('> Outputted %s to %s as %s', in_class.ljust(35), outpathlk[side], out_class)
-@@ -1607,6 +1720,9 @@
+@@ -1920,6 +1930,9 @@
sys.exit(1)
for entry in newfiles:
@@ -297,7 +75,7 @@
if entry[3] == 'U':
self.logger.info('Retrieving file from server : %s', entry[0])
cur_file = os.path.normpath(entry[0])
-@@ -1627,6 +1743,9 @@
+@@ -1940,6 +1953,9 @@
md5reoblk = {CLIENT: self.md5reobfclient, SERVER: self.md5reobfserver}
outpathlk = {CLIENT: self.srcmodclient, SERVER: self.srcmodserver}
src = {CLIENT: self.srcclient, SERVER: self.srcserver}
diff --git a/common/cpw/mods/fml/common/asm/transformers/MCPMerger.java b/common/cpw/mods/fml/common/asm/transformers/MCPMerger.java
index 1a745134ac..540151a8bf 100644
--- a/common/cpw/mods/fml/common/asm/transformers/MCPMerger.java
+++ b/common/cpw/mods/fml/common/asm/transformers/MCPMerger.java
@@ -72,9 +72,8 @@ public class MCPMerger
File map_file = new File(args[0]);
File client_jar = new File(args[1]);
File server_jar = new File(args[2]);
- File client_jar_tmp = new File(args[1] + ".MergeBack");
- File server_jar_tmp = new File(args[2] + ".MergeBack");
-
+ File client_jar_tmp = new File(args[1] + ".backup_merge");
+ File server_jar_tmp = new File(args[2] + ".backup_merge");
if (client_jar_tmp.exists() && !client_jar_tmp.delete())
{
diff --git a/conf/mcp.cfg b/conf/mcp.cfg
index 0b6fbd8704..fa55203f31 100644
--- a/conf/mcp.cfg
+++ b/conf/mcp.cfg
@@ -34,12 +34,12 @@ ReobfClientSrg = %(DirTemp)s/client_ro_srg.srg
ReobfServerSrg = %(DirTemp)s/server_ro_srg.srg
[JAR]
-DirNatives = %(DirJars)s/bin/natives
-Client = %(DirJars)s/bin/minecraft.jar
-Server = %(DirJars)s/minecraft_server.jar
-LWJGL = %(DirJars)s/bin/jinput.jar,%(DirJars)s/bin/lwjgl.jar,%(DirJars)s/bin/lwjgl_util.jar
-MD5Client = 6897c3287fb971c9f362eb3ab20f5ddd
-MD5Server = c4e1bf89e834bd3670c7bf8f13874bc6
+DirNatives = %(DirJars)s/versions/1.6/natives
+Json = %(DirJars)s/versions/1.6/1.6.json
+Client = %(DirJars)s/versions/1.6/1.6.jar
+Server = %(DirJars)s/minecraft_server.1.6.jar
+MD5Client = 6a64a2136e3a3fe4d29b0a0df30b25fc
+MD5Server = 7c03305c8bf97a8e8f3cdb147fc90607
[RETROGUARD]
Location = %(DirRuntime)s/bin/retroguard.jar
@@ -71,6 +71,8 @@ ClsServerTemp = %(DirTempCls)s/minecraft_server
SrcClientTemp = %(DirTempSrc)s/minecraft
SrcServerTemp = %(DirTempSrc)s/minecraft_server
FFSource = net
+FFClientIn = %(DirTemp)s/minecraft_ff_in.jar
+FFServerIn = %(DirTemp)s/minecraft_server_ff_in.jar
[OUTPUT]
BinClientTemp = %(DirTempBin)s/minecraft
@@ -94,11 +96,11 @@ BinClient = %(DirBin)s/minecraft
BinServer = %(DirBin)s/minecraft_server
LogClient = %(DirLogs)s/client_compile.log
LogServer = %(DirLogs)s/server_compile.log
-ClassPathClient = %(DirLib)s/,%(DirLib)s/*,%(DirJars)s/bin/minecraft.jar,%(DirJars)s/bin/jinput.jar,%(DirJars)s/bin/lwjgl.jar,%(DirJars)s/bin/lwjgl_util.jar
-ClassPathServer = %(DirLib)s/,%(DirLib)s/*,%(DirJars)s/minecraft_server.jar
+ClassPathClient = %(DirLib)s/,%(DirLib)s/*,%(DirJars)s/versions/1.6/1.6.jar
+ClassPathServer = %(DirLib)s/,%(DirLib)s/*,%(DirJars)s/minecraft_server.1.6.jar
ClientFixes = %(DirConf)s/patches
FixStart = Start
-IgnorePkg = paulscode,com/jcraft,isom,ibxm,de/matthiasmann/twl,org/xmlpull,javax/xml,com/fasterxml,javax/ws,org/bouncycastle,argo
+IgnorePkg = paulscode,com,isom,ibxm,de/matthiasmann/twl,org,javax/xml,javax/ws,argo
[REOBF]
MD5Client = %(DirTemp)s/client.md5
@@ -125,8 +127,8 @@ LogFile = %(DirLogs)s/mcp.log
LogFileErr = %(DirLogs)s/mcperr.log
UpdateUrl =
IgnoreUpdate = %(DirBin)s,%(DirLib)s,%(DirLogs)s,%(DirModSrc)s,%(DirReobf)s,%(DirSrc)s,%(DirTemp)s,%(DirEclipse)s/Client/bin,%(DirEclipse)s/Server/bin,%(DirJars)s/world,%(DirJars)s/saves,%(DirJars)s/resources
-RGIndex = 104000
-ParamIndex = 23000
+RGIndex = 130000
+ParamIndex = 30000
[ASTYLE]
AstyleConfig = %(DirConf)s/astyle.cfg
@@ -144,15 +146,18 @@ AStyle_osx = %(DirRuntime)s/bin/astyle-osx
JadRetro = %(DirRuntime)s/bin/jadretro.jar
Fernflower = %(DirRuntime)s/bin/fernflower.jar
Exceptor = %(DirRuntime)s/bin/mcinjector.jar
+SpecialSource = %(DirRuntime)s/bin/specialsource.jar
CmdPatch = %s -p1 -u -i {patchfile} -d {srcdir}
CmdJad = %s -b -d {outdir} -dead -o -r -s .java -stat -ff {classes}
CmdAStyle = %s --suffix=none --quiet --options={conffile} {classes}
CmdRG = %s -cp "{classpath}" RetroGuard -searge {conffile}
CmdRGReobf = %s -cp "{classpath}" RetroGuard -notch {conffile}
+CmdSS = %s -cp "{classpath}" -jar %s -i {injar} -o {outjar} -m {mapfile} --kill-source
+CmdSSReobf = %s -cp "{classpath}" -jar %s -i {injar} -o {outjar} -r -m {mapfile} -d {identifier} -e %s
CmdJadretro = %s -jar %s {targetdir}
CmdFernflower = %s -Xmx512M -jar %s -din=0 -rbr=0 -dgs=1 -asc=1 -log=WARN {indir} {outdir}
CmdExceptor = %s -jar %s {input} {output} {conf} {log}
CmdRecomp = %s -encoding UTF-8 -Xlint:-options -deprecation -g -source 1.6 -target 1.6 -classpath "{classpath}" -sourcepath {sourcepath} -d {outpath} {pkgs}
-CmdRecompScalac = %s -encoding UTF-8 -deprecation -target:jvm-1.6 -classpath "{classpath}" -sourcepath {sourcepath} -d {outpath} {pkgs}
+CmdRecompScala = %s -encoding UTF-8 -deprecation -target:jvm-1.6 -classpath "{classpath}" -sourcepath {sourcepath} -d {outpath} {pkgs}
CmdStartSrv = %s -Xincgc -Xms1024M -Xmx1024M -cp "{classpath}" net.minecraft.server.MinecraftServer
CmdStartClt = %s -Xincgc -Xms1024M -Xmx1024M -cp "{classpath}" -Djava.library.path={natives} Start
diff --git a/decompile.py b/decompile.py
index fe6b4c4dcd..33d93d61d2 100644
--- a/decompile.py
+++ b/decompile.py
@@ -2,19 +2,23 @@ import urllib
import zipfile
import sys
import os
+from optparse import OptionParser
if __name__ == '__main__':
- if not len(sys.argv) >= 3:
- print 'Invalid arguments, must supply mcp folder and fml folder: decompile.py '
+ parser = OptionParser()
+ parser.add_option('-g', '--gen-conf', action="store_true", dest='gen_conf', help='Generate merged MCP conf folder', default=False)
+ parser.add_option('-m', '--mcp-dir', action='store', dest='mcp_dir', help='Path to download/extract MCP to', default=None )
+ parser.add_option('-f', '--fml-dir', action='store', dest='fml_dir', help='Path to FML install folder', default=None )
+ options, _ = parser.parse_args()
+
+ if options.fml_dir is None or options.mcp_dir is None:
+ print 'Invalid arguments, must supply mcp folder and fml folder: decompile.py --mcp-dir --fml-dir '
else:
- mcp_dir = os.path.abspath(sys.argv[1])
- fml_dir = os.path.abspath(sys.argv[2])
- dont_gen_conf = '-no_gen_conf' in sys.argv
+ sys.path.append(os.path.join(options.fml_dir, 'install'))
- sys.path.append(os.path.join(fml_dir, 'install'))
+ from fml import decompile_minecraft, setup_mcp, download_mcp
- from fml import setup_fml, setup_mcp
-
- setup_mcp(fml_dir, mcp_dir, dont_gen_conf)
- setup_fml(fml_dir, mcp_dir)
+ download_mcp(fml_dir=options.fml_dir, mcp_dir=options.mcp_dir)
+ setup_mcp(options.fml_dir, options.mcp_dir, gen_conf=options.gen_conf)
+ decompile_minecraft(options.fml_dir, options.mcp_dir)
diff --git a/install/fml.py b/install/fml.py
index 6e12580e0c..aece73f2bc 100644
--- a/install/fml.py
+++ b/install/fml.py
@@ -7,29 +7,11 @@ from hashlib import md5 # pylint: disable-msg=E0611
from pprint import pprint
from zipfile import ZipFile
from pprint import pprint
+from contextlib import closing
-mcp_version = '7.42'
-uses_new_assets = False
-
-def download_deps(mcp_path):
- ret = True
- for lib in ['argo-3.2-src.jar','guava-14.0-rc3.jar','asm-4.1.tar.gz','asm-debug-all-4.1.jar','bcprov-debug-jdk15on-148.jar','bcprov-jdk15on-148-src.zip','guava-14.0-rc3-sources.jar', 'scala-library.jar']:
- libF = os.path.join(mcp_path, 'lib')
- if not os.path.isdir(libF):
- os.makedirs(libF)
-
- target = os.path.normpath(os.path.join(libF, lib))
-
- if not os.path.isfile(target):
- try:
- urllib.urlretrieve('http://files.minecraftforge.net/fmllibs/' + lib, target)
- print 'Downloaded %s' % lib
- except:
- print 'Download %s failed, download manually from http://files.minecraftforge.net/fmllibs/%s or http://files.minecraftforge.net/fmllibs/fml_libs_dev15.zip and place in mcp/lib' % (lib, lib)
- ret = False
-
- return ret
-
+#==========================================================================
+# Utility Functions
+#==========================================================================
def config_get_section(config, section):
dict = {}
options = config.options(section)
@@ -40,6 +22,113 @@ def config_get_section(config, section):
dict[option] = None
return dict
+def read_mc_versions(fml_dir, version=None, work_dir=None):
+ ###########################################################################################################
+ #Read mc_versions.cfg from the fml folder for the specified version, or the default
+ #version if none is specified.
+ #
+ #Should return a dictionary with the following keys:
+ # 'new_laucher' True if the version uses the new launcher structure for assets/libraries
+ # 'client_url' URL path to the minecraft client jar
+ # 'client_md5' MD5 checksum of the client jar
+ # 'server_url' URL path to the minecraft server jar
+ # 'server_md5' MD5 checksum of the server jar
+ # 'json_url' URL path to the json file for this version, or 'None' if new_launcher is false
+ # 'mcp_ver' Human readable version for MCP to use for this version of Minecraft
+ # 'mcp_url' URL path for MCP to download, or 'None' if there isn't one avalible
+ # 'mcp_md5' MD5 checksum of the MCP archive
+ # 'mcp_file' File path to the MCP archive
+ #
+ # If work_dir is specified the following keys also contain values:
+ # 'natives_dir' File path to native libraries used by Minecraft
+ # 'library_dir' File path to 'libraries' folder
+ # if 'new_launcher' is false this points to work_dir/bin/ and will not be used as maven style folder structure
+ # if 'new_launcher' is true this points to work_dir/libraraies/ and will use the maven style folder structure
+ # 'client_file' File path for the client minecraft.jar
+ # 'server_file' File path to the server minecraft jar
+ # 'json_file'
+ # if 'new_launcher' is false, this is 'None'
+ # if 'new_launcher' is true, this is the path to the version json file on disc.
+ # 'asset_dir' Folder containering all assets/resources used by minecraft
+ #
+ # Note: Because a file is give a path it does NOT mean that it exists! So alway check before using
+ ############################################################################################################################
+
+ versions_file = os.path.join(fml_dir, 'mc_versions.cfg')
+ if not os.path.isfile(versions_file):
+ print 'Could not find mc_versions.cfg in FML directory.'
+ sys.exit(1)
+
+ config = ConfigParser.ConfigParser()
+ config.read(versions_file)
+
+ default = config_get_section(config, 'default')
+ if version is None:
+ version = default['current_ver']
+
+ if not config.has_section(version):
+ print 'Error: Invalid minecraft version, could not find \'%s\' in mc_versions.cfg' % version
+ sys.exit(1)
+
+ mc_info = config_get_section(config, version)
+ mc_info['downloads'] = []
+ mc_info['version'] = version
+ if not 'client_url' in mc_info.keys():
+ mc_info['new_launcher'] = True
+ base_url = 'https://s3.amazonaws.com/Minecraft.Download/versions/%s' % version
+ mc_info['client_url'] = '%s/%s.jar' % (base_url, version)
+ mc_info['json_url'] = '%s/%s.json' % (base_url, version)
+ mc_info['server_url'] = '%s/minecraft_server.%s.jar' % (base_url, version)
+ if not work_dir is None:
+ version_dir = os.path.join(work_dir, 'versions', version)
+ mc_info['natives_dir'] = os.path.join(work_dir, 'libraries', 'natives')
+ mc_info['library_dir'] = os.path.join(work_dir, 'libraries')
+ mc_info['client_file'] = os.path.join(version_dir, '%s.jar' % version)
+ mc_info['json_file'] = os.path.join(version_dir, '%s.json' % version)
+ mc_info['server_file'] = os.path.join(work_dir, 'minecraft_server.%s.jar' % version)
+ mc_info['asset_dir'] = os.path.join(work_dir, 'assets')
+ else:
+ mc_info['new_launcher'] = False
+ mc_info['json_url'] = None
+ if not work_dir is None:
+ mc_info['natives_dir'] = os.path.join(work_dir, 'bin', 'natives')
+ mc_info['library_dir'] = os.path.join(work_dir, 'bin')
+ mc_info['client_file'] = os.path.join(work_dir, 'bin', 'minecraft.jar')
+ mc_info['json_file'] = None
+ mc_info['server_file'] = os.path.join(work_dir, 'minecraft_server.jar')
+ mc_info['asset_dir'] = os.path.join(work_dir, 'resources')
+ for lib in default['libraries'].split(' '):
+ mc_info['libraries'].append({
+ 'url' : default['base_url'] + lib,
+ 'file' : os.path.join(work_dir, 'bin', lib),
+ 'extract' : None,
+ 'md5' : None
+ })
+ for native in default['natives'].split(' '):
+ mc_info['libraries'].append({
+ 'url_ex' : default['base_url'] + lib,
+ 'file' : os.path.join(work_dir, 'bin', lib),
+ 'extract' : { 'exclude' : ['META-INF/'] },
+ 'md5' : None
+ })
+
+ if not mc_info['mcp_url'].startswith('http'):
+ mc_info['mcp_url'] = None
+ mc_info['mcp_file'] = os.path.join(fml_dir, 'mcp%s.zip' % mc_info['mcp_ver'])
+
+ if not work_dir is None:
+ for x in ['natives_dir', 'library_dir', 'asset_dir']:
+ if not os.path.isdir(mc_info[x]):
+ os.makedirs(mc_info[x])
+ for x in ['client_file', 'server_file', 'json_file', 'mcp_file']:
+ if mc_info[x] is None:
+ continue
+ dir = os.path.dirname(mc_info[x])
+ if not os.path.isdir(dir):
+ os.makedirs(dir)
+
+ return mc_info
+
def download_file(url, target, md5=None, root=None, prefix=''):
name = os.path.basename(target)
@@ -74,202 +163,10 @@ def download_file(url, target, md5=None, root=None, prefix=''):
return False
return True
-def download_native(url, folder, name):
- if not os.path.exists(folder):
- os.makedirs(folder)
-
- target = os.path.join(folder, name)
- if not download_file(url + name, target):
- return False
-
- zip = ZipFile(target)
- for name in zip.namelist():
- if not name.startswith('META-INF') and not name.endswith('/'):
- out_file = os.path.join(folder, name)
- if not os.path.isfile(out_file):
- print ' Extracting %s' % name
- out = open(out_file, 'wb')
- out.write(zip.read(name))
- out.flush()
- out.close()
- zip.close()
- return True
-
-def download_minecraft(mcp_dir, fml_dir, version=None):
- versions_file = os.path.join(fml_dir, 'mc_versions.cfg')
- if not os.path.isfile(versions_file):
- print 'Could not find mc_versions.cfg in FML directory.'
- sys.exit(1)
-
- config = ConfigParser.ConfigParser()
- config.read(versions_file)
-
- default = config_get_section(config, 'default')
- if version is None:
- version = default['current_ver']
-
- bin_folder = os.path.join(mcp_dir, 'jars', 'bin')
- if not os.path.exists(bin_folder):
- os.makedirs(bin_folder)
-
- failed = False
-
- if not config.has_section(version):
- print 'Error: Invalid minecraft version, could not find \'%s\' in mc_versions.cfg' % version
- sys.exit(1)
-
- mc_info = config_get_section(config, version)
-
- client_jar = os.path.join(bin_folder, 'minecraft.jar')
- server_jar = os.path.join(mcp_dir, 'jars', 'minecraft_server.jar')
-
- if not 'client_url' in mc_info.keys():
- global uses_new_assets
- uses_new_assets = True
- base_url = 'https://s3.amazonaws.com/Minecraft.Download/versions/%s' % version
- mc_info['client_url'] = '%s/%s.jar' % (base_url, version)
- mc_info['json_url'] = '%s/%s.json' % (base_url, version)
- mc_info['server_url'] = '%s/minecraft_server.%s.jar' % (base_url, version)
-
- version_dir = os.path.join(mcp_dir, 'jars', 'versions', version)
- if not os.path.isdir(version_dir):
- os.makedirs(version_dir)
-
- client_jar = os.path.join(version_dir, '%s.jar' % version)
- json_file = os.path.join(version_dir, '%s.json' % version)
- server_jar = os.path.join(mcp_dir, 'jars', 'minecraft_server.%s.jar' % version)
-
- headers = get_headers(mc_info['json_url'])
- if not headers is None:
- mc_info['json_md5'] = headers['ETag']
- else:
- mc_info['json_md5'] = None
-
- if not download_file(mc_info['json_url'], json_file, mc_info['json_md5']):
- print 'Failed to download version json'
- sys.exit(1)
-
- version_json = None
- try:
- version_json = json.load(open(json_file))
- except Exception as e:
- os.remove(json_file)
- print 'Failed to download version json'
- sys.exit(1)
-
- failed = download_libraries(mcp_dir, version_json['libraries']) or failed
-
- else:
- for lib in default['libraries'].split(' '):
- failed = not download_file(default['base_url'] + lib, os.path.join(bin_folder, lib)) or failed
- for native in default['natives'].split(' '):
- failed = not download_native(default['base_url'], os.path.join(bin_folder, 'natives'), native) or failed
-
- # Remove any invalid files
- file_backup(client_jar, mc_info['client_md5'])
- file_backup(server_jar, mc_info['server_md5'])
-
- failed = not download_file(mc_info['client_url'], client_jar, mc_info['client_md5']) or failed
- failed = not download_file(mc_info['server_url'], server_jar, mc_info['server_md5']) or failed
-
- # Backup clean jars, or delete if corrupted
- file_backup(client_jar, mc_info['client_md5'])
- file_backup(server_jar, mc_info['server_md5'])
-
- if failed:
- print 'Something failed verifying minecraft files, see log for details.'
- sys.exit(1)
-
-def download_libraries(mcp_dir, libraries):
- lib_dir = os.path.join(mcp_dir, 'jars', 'libraries')
- base_url = 'https://s3.amazonaws.com/Minecraft.Download/libraries'
-
- downloads = []
- failed = False
-
- for lib in libraries:
- name = lib['name'].split(':')
- domain = name[0].split('.')
- root = name[1]
- version = name[2]
- path = domain + [root, version]
- extract = None
- if 'extract' in lib.keys():
- extract = lib['extract']
-
- file_names = ['%s-%s.jar' % (root, version)]
-
- if 'natives' in lib.keys():
- file_names = []
- for k,v in lib['natives'].items():
- file_names.append('%s-%s-%s.jar' % (root, version, v))
-
- for file_name in file_names:
- url = '%s/%s/%s' % (base_url, '/'.join(path), file_name)
- file_path = os.path.join(lib_dir, os.sep.join(path), file_name)
- headers = get_headers(url)
- if headers is None:
- print 'Could not retreive headers for library: %s ( %s )' % (lib['name'], url)
- failed = True
- else:
- downloads.append({
- 'url' : url,
- 'file' : file_path,
- 'md5' : headers['ETag'],
- 'size' : headers['Content-Length'],
- 'extract' : extract
- })
-
- natives_dir = os.path.join(lib_dir, 'natives')
- if not os.path.isdir(natives_dir):
- os.makedirs(natives_dir)
-
- missing = []
- for dl in downloads:
- if os.path.isfile(dl['file']):
- if dl['md5'] is None or not get_md5(dl['file']) == dl['md5']:
- missing.append(dl)
-
- if len(missing) == 0:
- return failed
-
- print 'Downloading %s libraries' % len(missing)
- for dl in missing:
- if download_file(dl['url'], dl['file'], dl['md5'], prefix=' '):
- if not dl['extract'] is None:
- excludes = []
- if 'exclude' in dl['extract'].keys():
- excludes = dl['extract']['exclude']
-
- def is_filtered(name, excludes):
- for ex in excludes:
- if name.startswith(ex):
- return True
- return name.endswith('/')
-
- zip = ZipFile(dl['file'])
- for name in zip.namelist():
- if is_filtered(name, excludes):
- continue
- out_file = os.path.join(natives_dir, os.sep.join(name.split('/')))
-
- if not os.path.isfile(out_file):
- dir = os.path.dirname(out_file)
- if not os.path.isdir(dir):
- os.makedirs(dir)
-
- print ' Extracting %s' % name
- out = open(out_file, 'wb')
- out.write(zip.read(name))
- out.flush()
- out.close()
- zip.close()
- else:
- failed = True
-
- return failed
-
def get_headers(url):
+ #Connects to the given URL and requests just the headers, No data
+ #Used when talking to Minecraft's asset/library server to gather server side MD5's
+ #Returns a dictionary of all headers
class HeadRequest(urllib2.Request):
def get_method(self):
return 'HEAD'
@@ -279,417 +176,29 @@ def get_headers(url):
for line in array:
pts = line.split(':', 1)
pts[1] = pts[1].strip()
+ #Strip the first and last "s if the stirng is surrounded with them
if pts[1][0] == '"' and pts[1][-1] == '"':
pts[1] = pts[1][1:-1]
dict[pts[0]] = pts[1]
- return dict
+ return dict
def get_md5(file):
+ #Returns the MD5 digest of the specified file, or None if the file doesnt exist
if not os.path.isfile(file):
- return ""
- with open(file, 'rb') as fh:
- return md5(fh.read()).hexdigest()
-
-def pre_decompile(mcp_dir, fml_dir, disable_assets = False):
- download_minecraft(mcp_dir, fml_dir)
-
- if not disable_assets:
- download_assets(mcp_dir)
-
-def download_assets(mcp_dir):
- if not uses_new_assets:
- return
- from xml.dom.minidom import parse
- asset_dir = os.path.join(mcp_dir, 'jars', 'assets')
- base_url = 'https://s3.amazonaws.com/Minecraft.Resources'
-
- print 'Gathering assets list from %s' % base_url
-
- files = []
- failed = False
-
- try:
- url = urllib.urlopen(base_url)
- xml = parse(url)
-
- def get(xml, key):
- return xml.getElementsByTagName(key)[0].firstChild.nodeValue
-
- for asset in xml.getElementsByTagName('Contents'):
- path = get(asset, 'Key')
- if path.endswith('/'):
- continue
-
- file = os.path.join(asset_dir, os.sep.join(path.split('/')))
- md5 = get(asset, 'ETag').replace('"', '')
-
- if os.path.isfile(file):
- if get_md5(file) == md5:
- continue
-
- files.append({
- 'file' : file,
- 'url' : '%s/%s' % (base_url, path),
- 'size' : get(asset, 'Size'),
- 'md5' : md5
- })
- except Exception as e:
- print 'Error gathering asset list:'
- pprint(e)
- sys.exit(1)
-
- if len(files) == 0:
- print 'No new assets need to download'
- return
-
- print 'Downloading %s assets' % len(files)
- for file in files:
- failed = not download_file(file['url'], file['file'], file['md5'], root=asset_dir, prefix=' ') or failed
-
- if failed:
- print 'Downloading assets failed, please review log for more details'
- sys.exit(1)
-
-def file_backup(file, md5):
- base = os.path.dirname(file)
- name = os.path.basename(file)
- bck_jar = os.path.join(base, name + '.backup')
- src_jar = os.path.join(base, name)
-
- if not os.path.isfile(src_jar) and not os.path.isfile(bck_jar):
- return
-
- if os.path.isfile(bck_jar):
- if get_md5(bck_jar) == md5:
- if os.path.isfile(src_jar):
- os.remove(src_jar)
- shutil.move(bck_jar, src_jar)
- else:
- os.remove(bck_jar)
-
- if os.path.isfile(src_jar):
- if not get_md5(src_jar) == md5:
- print 'Modified %s detected, removing' % os.path.basename(src_jar)
- os.remove(src_jar)
- else:
- shutil.copy(src_jar, bck_jar)
-
-def post_decompile(mcp_dir, fml_dir, client_jar):
- dir = os.path.dirname(client_jar)
- name = os.path.basename(client_jar)
- back_jar = os.path.join(dir, '%s.backup' % name)
- src_jar = client_jar
-
- if not os.path.isfile(src_jar):
- return
-
- print 'Stripping META-INF from minecraft.jar'
-
- zip_in = zipfile.ZipFile(back_jar, mode='a')
- zip_out = zipfile.ZipFile(src_jar, 'w', zipfile.ZIP_DEFLATED)
- for i in zip_in.filelist:
- if not i.filename.startswith('META-INF'):
- c = zip_in.read(i.filename)
- zip_out.writestr(i.filename, c)
- else:
- print 'Skipping: %s' % i.filename
- zip_out.close()
-
-def reset_logger():
- log = logging.getLogger()
- while len(log.handlers) > 0:
- log.removeHandler(log.handlers[0])
-
-count = 0
-def cleanup_source(path):
- from rename_vars import rename_class
- path = os.path.normpath(path)
- regex_cases_before = re.compile(r'((case|default).+\r?\n)\r?\n', re.MULTILINE) #Fixes newline after case before case body
- regex_cases_after = re.compile(r'\r?\n(\r?\n[ \t]+(case|default))', re.MULTILINE) #Fixes newline after case body before new case
-
- def updatefile(src_file):
- global count
- tmp_file = src_file + '.tmp'
- count = 0
- with open(src_file, 'r') as fh:
- buf = fh.read()
-
- def fix_cases(match):
- global count
- count += 1
- return match.group(1)
-
- buf = regex_cases_before.sub(fix_cases, buf)
- buf = regex_cases_after.sub(fix_cases, buf)
- old = buf.replace('\r', '')
- buf = rename_class(old, MCP=True)
-
- if count > 0 or buf != old:
- with open(tmp_file, 'w') as fh:
- fh.write(buf)
- shutil.move(tmp_file, src_file)
-
- for path, _, filelist in os.walk(path, followlinks=True):
- sub_dir = os.path.relpath(path, path)
- for cur_file in fnmatch.filter(filelist, '*.java'):
- src_file = os.path.normpath(os.path.join(path, cur_file))
- updatefile(src_file)
-
-compile_tools = True
-def setup_fml(fml_dir, mcp_dir, disable_at=False, disable_merge=False, enable_server=False, disable_client=False, disable_assets=False):
- global compile_tools
- global client_jar
- sys.path.append(mcp_dir)
- from runtime.decompile import decompile
- from runtime.cleanup import cleanup
- from runtime.commands import Commands, CLIENT, SERVER
-
- src_dir = os.path.join(mcp_dir, 'src')
-
- if os.path.isdir(src_dir):
- os.chdir(mcp_dir)
- cleanup(None, False)
- reset_logger()
- os.chdir(fml_dir)
-
- if os.path.isdir(src_dir):
- print 'Please make sure to backup your modified files, and say yes when it asks you to do cleanup.'
- sys.exit(1)
-
- #download fernflower/argo/asm/guava
- if not download_deps(mcp_dir):
- sys.exit(1)
-
- compile_tools = True
- client_jar = None
-
- def applyrg_shunt(self, side, reobf=False, applyrg_real = Commands.applyrg):
- global compile_tools
- global client_jar
- if not self.has_wine and not self.has_astyle:
- self.logger.error('!! Please install either wine or astyle for source cleanup !!')
- self.logger.error('!! This is REQUIRED by FML/Forge Cannot proceed !!')
- sys.exit(1)
- jars = {CLIENT: self.jarclient, SERVER: self.jarserver}
- client_jar = os.path.abspath(self.jarclient)
-
- dir_bin = os.path.join(fml_dir, 'bin')
- if not os.path.isdir(dir_bin):
- os.makedirs(dir_bin)
-
- class_path = os.pathsep.join(['.', os.path.join(mcp_dir, 'lib', '*'), dir_bin])
- dir_common = os.path.join(fml_dir, 'common')
- dir_trans = os.path.join(dir_common, 'cpw', 'mods', 'fml', 'common', 'asm', 'transformers')
- java = self.cmdjava.translate(None, '"')
- javac = self.cmdjavac.translate(None, '"')
- cmd_compile = '"%s" -Xlint:-options -deprecation -g -source 1.6 -target 1.6 -classpath "{classpath}" -sourcepath "{sourcepath}" -d "{outpath}" "{target}"' % javac
- cmd_compile = cmd_compile.format(classpath=class_path, sourcepath=dir_common, outpath=dir_bin, target="{target}")
-
- if compile_tools:
- self.logger.info('> Compiling AccessTransformer')
- if not runcmd(self, cmd_compile.format(target=os.path.join(dir_trans, 'AccessTransformer.java')), echo=False):
- sys.exit(1)
-
- self.logger.info('> Compiling MCPMerger')
- if not runcmd(self, cmd_compile.format(target=os.path.join(dir_trans, 'MCPMerger.java')), echo=False):
- sys.exit(1)
-
- compile_tools = False
-
- if side == CLIENT:
- if not disable_merge:
- self.logger.info('> Running MCPMerger')
- forkcmd = ('"%s" -classpath "{classpath}" cpw.mods.fml.common.asm.transformers.MCPMerger "{mergecfg}" "{client}" "{server}"' % java).format(
- classpath=class_path, mergecfg=os.path.join(fml_dir, 'mcp_merge.cfg'), client=jars[CLIENT], server=jars[SERVER])
-
- if not runcmd(self, forkcmd):
- sys.exit(1)
- else:
- self.logger.info('> MCPMerge disabled')
-
- if not disable_at:
- self.logger.info('> Running AccessTransformer')
- forkcmd = ('"%s" -classpath "{classpath}" cpw.mods.fml.common.asm.transformers.AccessTransformer "{jar}" "{fmlconfig}"' % java).format(
- classpath=class_path, jar=jars[side], fmlconfig=os.path.join(fml_dir, 'common', 'fml_at.cfg'))
-
- forge_cfg = os.path.join(fml_dir, '..', 'common', 'forge_at.cfg')
- if os.path.isfile(forge_cfg):
- self.logger.info(' Forge config detected')
- forkcmd += ' "%s"' % forge_cfg
-
- for dirname, dirnames, filenames in os.walk(os.path.join(fml_dir, '..', 'accesstransformers')):
- for filename in filenames:
- accesstransformer = os.path.join(dirname, filename)
- if os.path.isfile(accesstransformer):
- self.logger.info(' Access Transformer "%s" detected' % filename)
- forkcmd += ' "%s"' % accesstransformer
-
- if not runcmd(self, forkcmd):
- sys.exit(1)
- else:
- self.logger.info('> Access Transformer disabled')
-
- self.logger.info('> Really Applying Retroguard')
- applyrg_real(self, side, reobf)
-
- #Check the original jars not the transformed jars
- def checkjars_shunt(self, side, checkjars_real = Commands.checkjars):
- self.jarclient = self.jarclient + '.backup'
- self.jarserver = self.jarserver + '.backup'
- #print 'Jar Check %s %s %s' % (side, self.jarclient, self.jarserver)
- ret = checkjars_real(self, side)
- self.jarclient = self.jarclient[:-7]
- self.jarserver = self.jarserver[:-7]
- #print 'Jar Check out %s %s %s' % (side, self.jarclient, self.jarserver)
- return ret
-
- try:
- pre_decompile(mcp_dir, fml_dir, disable_assets=disable_assets)
-
- os.chdir(mcp_dir)
- Commands.applyrg = applyrg_shunt
- Commands.checkjars = checkjars_shunt
- #decompile -d -n -r
- # Conf JAD CSV -r -d -a -n -p -o -l -g -c -s
- decompile(None, False, False, True, True, False, True, False, False, False, False, not disable_client, enable_server)
- reset_logger()
- os.chdir(fml_dir)
- post_decompile(mcp_dir, fml_dir, client_jar)
-
- except SystemExit, e:
- print 'Decompile Exception: %d ' % e.code
- raise e
-
- if not os.path.isdir(src_dir):
- print 'Something went wrong, src folder not found at: %s' % src_dir
- sys.exit(1)
-
- #cleanup_source
- cleanup_source(src_dir)
-
- os.chdir(mcp_dir)
- commands = Commands(verify=True)
-
- if not disable_client:
- updatemd5_side(mcp_dir, commands, CLIENT)
- reset_logger()
-
- if enable_server:
- updatemd5_side(mcp_dir, commands, CLIENT)
- reset_logger()
-
- os.chdir(fml_dir)
-
-def updatemd5_side(mcp_dir, commands, side):
- sys.path.append(mcp_dir)
- from runtime.mcp import recompile_side, updatemd5_side
- from runtime.commands import SIDE_NAME
-
- recomp = recompile_side(commands, side)
- if recomp:
- commands.logger.info('> Generating %s md5s', SIDE_NAME[side])
- commands.gathermd5s(side, skip_fml=True)
-
-def cmdsplit(args):
- if os.sep == '\\':
- args = args.replace('\\', '\\\\')
- return shlex.split(args)
-
-def runcmd(commands, command, echo=True):
- forklist = cmdsplit(command)
- process = subprocess.Popen(forklist, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, bufsize=-1)
- output, _ = process.communicate()
-
- if echo:
- for line in output.splitlines():
- commands.logger.info(line)
-
- if process.returncode:
- if not echo:
- for line in output.splitlines():
- commands.logger.info(line)
- return False
- return True
-
-def get_joined_srg(mcp_dir):
- joined = os.path.join(mcp_dir, 'conf', 'joined.srg')
- values = {'PK:': {}, 'CL:': {}, 'FD:': {}, 'MD:': {}}
-
- if not os.path.isfile(joined):
- print 'Could not read joined.srg, file not found'
- sys.exit(1)
- else:
- with open(joined, 'r') as fh:
- for line in fh:
- pts = line.rstrip('\r\n').split(' ')
- if pts[0] == 'MD:':
- values[pts[0]][pts[1] + ' ' + pts[2]] = pts[3] + ' ' + pts[4]
- else:
- values[pts[0]][pts[1]] = pts[2]
-
- return values
-
-def apply_fml_patches(fml_dir, mcp_dir, src_dir, copy_files=True):
- #Delete /minecraft/cpw to get rid of the Side/SideOnly classes used in decompilation
- cpw_mc_dir = os.path.join(src_dir, 'minecraft', 'cpw')
- if os.path.isdir(cpw_mc_dir):
- shutil.rmtree(cpw_mc_dir)
-
- #patch files
- print 'Applying Forge ModLoader patches'
- sys.stdout.flush()
-
- if os.path.isdir(os.path.join(fml_dir, 'patches', 'minecraft')):
- apply_patches(mcp_dir, os.path.join(fml_dir, 'patches', 'minecraft'), src_dir)
- if copy_files and os.path.isdir(os.path.join(fml_dir, 'client')):
- copytree(os.path.join(fml_dir, 'client'), os.path.join(src_dir, 'minecraft'))
- if copy_files and os.path.isdir(os.path.join(fml_dir, 'common')):
- copytree(os.path.join(fml_dir, 'common'), os.path.join(src_dir, 'minecraft'))
-
- #delete argo
- if os.path.isdir(os.path.join(src_dir, 'minecraft', 'argo')):
- shutil.rmtree(os.path.join(src_dir, 'minecraft', 'argo'))
-
-def finish_setup_fml(fml_dir, mcp_dir, enable_server=False, disable_client=False, disable_rename=False):
- sys.path.append(mcp_dir)
- from runtime.updatenames import updatenames
- from runtime.updatemd5 import updatemd5
- from runtime.updatemcp import updatemcp
-
- os.chdir(mcp_dir)
- if not disable_rename:
- updatenames(None, True, not disable_client, enable_server)
- reset_logger()
- updatemd5(None, True, not disable_client, enable_server)
- reset_logger()
- os.chdir(fml_dir)
-
-def apply_patches(mcp_dir, patch_dir, target_dir, find=None, rep=None):
- sys.path.append(mcp_dir)
- from runtime.commands import cmdsplit
-
- temp = os.path.abspath('temp.patch')
- cmd = cmdsplit('patch -p2 -i "%s" ' % temp)
-
- if os.name == 'nt':
- applydiff = os.path.abspath(os.path.join(mcp_dir, 'runtime', 'bin', 'applydiff.exe'))
- cmd = cmdsplit('"%s" -uf -p2 -i "%s"' % (applydiff, temp))
-
- for path, _, filelist in os.walk(patch_dir, followlinks=True):
- for cur_file in fnmatch.filter(filelist, '*.patch'):
- patch_file = os.path.normpath(os.path.join(patch_dir, path[len(patch_dir)+1:], cur_file))
- target_file = os.path.join(target_dir, fix_patch(patch_file, temp, find, rep))
- process = subprocess.Popen(cmd, cwd=target_dir, bufsize=-1)
- process.communicate()
-
- if os.path.isfile(temp):
- os.remove(temp)
+ return None
+ with closing(open(file, 'rb')) as fh:
+ return md5(fh.read()).hexdigest()
def fix_patch(in_file, out_file, find=None, rep=None):
+ #Fixes the following issues in the patch file if they exist:
+ # Normalizes the path seperators for the current OS
+ # Normalizes the line endings
+ # Returns the path that the file wants to apply to
+
in_file = os.path.normpath(in_file)
if out_file is None:
- tmp_filename = in_file + '.tmp'
+ tmp_file = in_file + '.tmp'
else:
out_file = os.path.normpath(out_file)
tmp_file = out_file
@@ -697,6 +206,7 @@ def fix_patch(in_file, out_file, find=None, rep=None):
if dir_name:
if not os.path.exists(dir_name):
os.makedirs(dir_name)
+
file = 'not found'
with open(in_file, 'rb') as inpatch:
with open(tmp_file, 'wb') as outpatch:
@@ -717,6 +227,215 @@ def fix_patch(in_file, out_file, find=None, rep=None):
shutil.move(tmp_file, in_file)
return file
+def apply_patch(patch, target, mcp_dir):
+ temp = os.path.abspath('temp.patch')
+ cmd = 'patch -i "%s" ' % temp
+
+ if os.name == 'nt':
+ applydiff = os.path.abspath(os.path.join(mcp_dir, 'runtime', 'bin', 'applydiff.exe'))
+ cmd = '"%s" -uf -i "%s"' % (applydiff, temp)
+
+ if os.sep == '\\':
+ cmd = cmd.replace('\\', '\\\\')
+ cmd = shlex.split(cmd)
+
+ fix_patch(patch, temp)
+
+ process = subprocess.Popen(cmd, cwd=os.path.join(mcp_dir, 'runtime'), bufsize=-1)
+ process.communicate()
+
+ if os.path.isfile(temp):
+ os.remove(temp)
+
+def file_backup(file, md5=None):
+ #Takes a backup of the passed in file
+ #Verifying the md5 sum if it's specified
+ #At the end of this things should be in one of two states:
+ # 1) file and file.backup exist, both are valid and match the md5 provided
+ # 2) neither file or file.backup exist, as they both failed the md5 check
+
+ base = os.path.dirname(file)
+ name = os.path.basename(file)
+ bck = os.path.join(base, name + '.backup')
+ src = os.path.join(base, name)
+
+ if not os.path.isfile(src) and not os.path.isfile(bck):
+ return
+
+ if os.path.isfile(bck):
+ if get_md5(bck) == md5 or md5 is None:
+ if os.path.isfile(src):
+ os.remove(src)
+ shutil.move(bck, src)
+ else:
+ os.remove(bck)
+
+ if os.path.isfile(src):
+ if not get_md5(src) == md5 and not md5 is None:
+ print 'Modified %s detected, removing' % os.path.basename(src_jar)
+ os.remove(src)
+ else:
+ shutil.copy(src, bck)
+
+def normaliselines(file):
+ #Normalises the lines of the specified file to linux \n line endings
+ file = os.path.normpath(file)
+ tmp = file + '.tmp'
+
+ with open(file, 'rb') as in_file:
+ with open(tmp, 'wb') as out_file:
+ out_file.write(in_file.read().replace('\r\n', '\n'))
+
+ shutil.move(tmp, file)
+
+def load_srg(srg_file, reverse=False):
+ #Loads a Retroguard .srg file into a dictonary
+ #If reverse if true, the mappings are reversed
+ with open(srg_file, 'r') as fh:
+ lines = fh.readlines()
+ srg = {'CL:': {}, 'MD:': {}, 'FD:': {}, 'PK:': {}}
+
+ for line in lines:
+ line = line.strip()
+ if len(line) == 0: continue
+ if line[0] == '#': continue
+ args = line.split(' ')
+ type = args[0]
+
+ if type == 'PK:' or type == 'CL:' or type == 'FD:':
+ srg[type][args[1]] = args[2]
+ elif type == 'MD:':
+ srg[type][args[1] + ' ' + args[2]] = args[3] + ' ' + args[4]
+ else:
+ assert 'Unknown type %s' % line
+
+ if reverse:
+ for type,map in srg.items():
+ srg[type] = dict([[v,k] for k,v in map.items()])
+ return srg
+
+def extract_zip(src, dst, prefix=None, filter=[]):
+ # Extract a zip rchive to the specified folder,
+ # Filtering out anything that matches the supplied filters
+
+ def is_filtered(name, excludes):
+ for ex in excludes:
+ if name.startswith(ex):
+ return True
+ return name.endswith('/')
+
+ zip = ZipFile(src)
+ for name in zip.namelist():
+ if is_filtered(name, filter):
+ continue
+ out_file = os.path.join(dst, os.sep.join(name.split('/')))
+
+ if not os.path.isfile(out_file):
+ dir = os.path.dirname(out_file)
+ if not os.path.isdir(dir):
+ os.makedirs(dir)
+
+ if not prefix is None:
+ print '%sExtracting %s' % (prefix, name)
+ out = open(out_file, 'wb')
+ out.write(zip.read(name))
+ out.flush()
+ out.close()
+ zip.close()
+
+def merge_tree(root_src_dir, root_dst_dir, prefix=None):
+ #Merges the source directory into the dest directory,
+ #will overwrite anything the currently exists
+ for src_dir, dirs, files in os.walk(root_src_dir):
+ dst_dir = src_dir.replace(root_src_dir, root_dst_dir)
+ clean_dir = src_dir.replace(root_src_dir, '')[1:]
+ 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_)
+ if os.path.exists(dst_file):
+ os.remove(dst_file)
+ shutil.copy(src_file, dst_dir)
+ if not prefix is None:
+ print('%s%s%s'% (prefix, clean_dir, file_))
+
+def read_file(file):
+ if not os.path.exists(file):
+ return None
+ buf = None
+ with closing(open(file, 'r')) as fh:
+ buf = fh.read()
+ return buf
+
+def runcmd(cmd, echo=True, commands=None):
+ forklist = cmdsplit(cmd)
+ process = subprocess.Popen(forklist, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, bufsize=-1)
+ output, _ = process.communicate()
+
+ if echo and not commands is None:
+ for line in output.splitlines():
+ commands.logger.info(line)
+
+ if process.returncode:
+ if not echo and not commands is None:
+ for line in output.splitlines():
+ commands.logger.info(line)
+ return False
+ return True
+
+def cmdsplit(args):
+ if os.sep == '\\':
+ args = args.replace('\\', '\\\\')
+ return shlex.split(args)
+
+def kill_signatures(jar_file):
+ # Removes everything in a jar file's META-INF folder, typically used to remove signature data
+ dir = os.path.dirname(jar_file)
+ name = os.path.basename(jar_file)
+ tmp_jar = os.path.join(dir, '%s.temp' % name)
+
+ if not os.path.isfile(jar_file):
+ return
+
+ if os.path.isfile(tmp_jar):
+ os.remove(tmp_jar)
+
+ shutil.move(jar_file, tmp_jar)
+
+ print('Stripping META-INF from %s' % jar_file)
+
+ with closing(zipfile.ZipFile(tmp_jar, mode='a')) as zip_in:
+ with closing(zipfile.ZipFile(jar_file, 'w', zipfile.ZIP_DEFLATED)) as zip_out:
+ for i in zip_in.filelist:
+ if not i.filename.startswith('META-INF'):
+ c = zip_in.read(i.filename)
+ zip_out.writestr(i.filename, c)
+ else:
+ print(' Skipping: %s' % i.filename)
+ os.remove(tmp_jar)
+
+def apply_patches(mcp_dir, patch_dir, target_dir, find=None, rep=None):
+ # Attempts to apply a directory full of patch files onto a target directory.
+ sys.path.append(mcp_dir)
+
+ temp = os.path.abspath('temp.patch')
+ cmd = cmdsplit('patch -p2 -i "%s" ' % temp)
+
+ if os.name == 'nt':
+ applydiff = os.path.abspath(os.path.join(mcp_dir, 'runtime', 'bin', 'applydiff.exe'))
+ cmd = cmdsplit('"%s" -uf -p2 -i "%s"' % (applydiff, temp))
+
+ for path, _, filelist in os.walk(patch_dir, followlinks=True):
+ for cur_file in fnmatch.filter(filelist, '*.patch'):
+ patch_file = os.path.normpath(os.path.join(patch_dir, path[len(patch_dir)+1:], cur_file))
+ target_file = os.path.join(target_dir, fix_patch(patch_file, temp, find, rep))
+ process = subprocess.Popen(cmd, cwd=target_dir, bufsize=-1)
+ process.communicate()
+
+ if os.path.isfile(temp):
+ os.remove(temp)
+
#Taken from: http://stackoverflow.com/questions/7545299/distutil-shutil-copytree
def _mkdir(newdir):
"""works the way a good mkdir should :)
@@ -736,7 +455,6 @@ def _mkdir(newdir):
#print "_mkdir %s" % repr(newdir)
if tail:
os.mkdir(newdir)
-
#Taken from: http://stackoverflow.com/questions/7545299/distutil-shutil-copytree
def copytree(src, dst, verbose=0, symlinks=False):
"""Recursively copy a directory tree using copy2().
@@ -785,33 +503,9 @@ def copytree(src, dst, verbose=0, symlinks=False):
# can't copy file access times on Windows
pass
-def cleanDirs(path):
- if not os.path.isdir(path):
- return
-
- files = os.listdir(path)
- if len(files):
- for f in files:
- fullpath = os.path.join(path, f)
- if os.path.isdir(fullpath):
- cleanDirs(fullpath)
-
- files = os.listdir(path)
- if len(files) == 0:
- os.rmdir(path)
-
-def merge_tree(root_src_dir, root_dst_dir):
- for src_dir, dirs, files in os.walk(root_src_dir):
- dst_dir = src_dir.replace(root_src_dir, root_dst_dir)
- 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_)
- if os.path.exists(dst_file):
- os.remove(dst_file)
- shutil.copy(src_file, dst_dir)
-
+#==========================================================================
+# MCP Related Functions
+#==========================================================================
def download_mcp(mcp_dir, fml_dir, version=None):
if os.path.isfile(os.path.join(mcp_dir, 'runtime', 'commands.py')):
print 'MCP Detected already, not downloading'
@@ -820,44 +514,19 @@ def download_mcp(mcp_dir, fml_dir, version=None):
if os.path.isdir(mcp_dir):
print 'Old MCP Directory exists, but MCP was not detected, please delete MCP directory at \'%s\'' % mcp_dir
sys.exit(1)
-
- versions_file = os.path.join(fml_dir, 'mc_versions.cfg')
- if not os.path.isfile(versions_file):
- print 'Could not find mc_versions.cfg in FML directory.'
- sys.exit(1)
-
- config = ConfigParser.ConfigParser()
- config.read(versions_file)
-
- default = config_get_section(config, 'default')
- if version is None:
- version = default['current_ver']
-
- if not config.has_section(version):
- print 'Error: Invalid minecraft version, could not find \'%s\' in mc_versions.cfg' % version
- sys.exit(1)
- mc_info = config_get_section(config, version)
- mcp_zip = os.path.join(fml_dir, 'mcp%s.zip' % mc_info['mcp_ver'])
+ mc_info = read_mc_versions(fml_dir, version=version)
- if not download_file(mc_info['mcp_url'], mcp_zip, mc_info['mcp_md5']):
+ if not download_file(mc_info['mcp_url'], mc_info['mcp_file'], mc_info['mcp_md5']):
sys.exit(1)
if not os.path.isdir(mcp_dir):
_mkdir(mcp_dir)
print 'Extracting MCP to \'%s\'' % mcp_dir
- zf = ZipFile(mcp_zip)
- #OS X's python 2.6.1 extractall has a bug in zipfile that makes it unzip directories as regular files.
- for path in zf.namelist():
- if not path.endswith('/'):
- zf.extract(path, mcp_dir)
- zf.close()
-
- eclipse_dir = os.path.join(mcp_dir, 'eclipse')
- if os.path.isdir(eclipse_dir):
- shutil.rmtree(eclipse_dir)
+ extract_zip(mc_info['mcp_file'], mcp_dir, filter=['eclipse']) #, prefix=' ')
+ #If we're not on windows, lets set the executable flag on all shell scripts and astyle-osx
if os.name != 'nt':
for path, _, filelist in os.walk(mcp_dir):
for cur_file in fnmatch.filter(filelist, '*.sh'):
@@ -867,72 +536,54 @@ def download_mcp(mcp_dir, fml_dir, version=None):
process = subprocess.Popen(cmdsplit('chmod +x "%s/runtime/bin/astyle-osx"' % mcp_dir), stdout=subprocess.PIPE, stderr=subprocess.STDOUT, bufsize=-1)
output, _ = process.communicate()
-
+
+ #As a helper to build servers, or people who don't wish to download all libraris and assets every time.
+ #Copy all data from 'mcp_data' to the mcp directory
+ data_dir = os.path.join(fml_dir, 'mcp_data')
+ if os.path.isdir(data_dir):
+ print 'Moving mcp_data to MCP'
+ merge_tree(data_dir, mcp_dir)##, prefix=' ')
+
return True
-def setup_mcp(fml_dir, mcp_dir, dont_gen_conf=True):
- global mcp_version
+def setup_mcp(fml_dir, mcp_dir, gen_conf=True):
+ #Modifies MCP to the state FML needs it in for recompile/reobf/etc to work as we intend it.
+ #Does not decompile minecraft in this stage!
- if not download_mcp(mcp_dir, fml_dir):
- sys.exit(1)
-
- backup = os.path.join(mcp_dir, 'runtime', 'commands.py.bck')
+ print('Setting up MCP')
runtime = os.path.join(mcp_dir, 'runtime', 'commands.py')
- patch = os.path.join(fml_dir, 'commands.patch')
+ file_backup(runtime)
- print 'Setting up MCP'
- if os.path.isfile(backup):
- print 'Restoring commands.py backup'
- if os.path.exists(runtime):
- os.remove(runtime)
- shutil.copy(backup, runtime)
- else:
- print 'Backing up commands.py'
- shutil.copy(runtime, backup)
+ patch = os.path.join(fml_dir, 'commands.patch')
if not os.path.isfile(patch):
raise Exception('Commands.py patch not found %s' % patch)
return
- temp = os.path.abspath('temp.patch')
- cmd = 'patch -i "%s" ' % temp
-
- if os.name == 'nt':
- applydiff = os.path.abspath(os.path.join(mcp_dir, 'runtime', 'bin', 'applydiff.exe'))
- cmd = '"%s" -uf -i "%s"' % (applydiff, temp)
-
- if os.sep == '\\':
- cmd = cmd.replace('\\', '\\\\')
- cmd = shlex.split(cmd)
-
- fix_patch(patch, temp)
- process = subprocess.Popen(cmd, cwd=os.path.join(mcp_dir, 'runtime'), bufsize=-1)
- process.communicate()
-
- if os.path.isfile(temp):
- os.remove(temp)
+ print('Patching commands.py')
+ apply_patch(patch, runtime, mcp_dir=mcp_dir)
try:
sys.path.append(mcp_dir)
from runtime.commands import commands_sanity_check
commands_sanity_check()
except ImportError as ex:
- print 'Could not verify commands.py patch integrity, this typically means that you are not in a clean MCP environment.'
- print 'Download a clean version of MCP %s and try again' % mcp_version
- print ex
+ print('Could not verify commands.py patch integrity, this typically means that you are not in a clean MCP environment.')
+ print('Download a clean version of MCP %s and try again' % mcp_version)
+ print(ex)
sys.exit(1)
mcp_conf = os.path.join(mcp_dir, 'conf')
mcp_conf_bak = os.path.join(mcp_dir, 'conf.bak')
fml_conf = os.path.join(fml_dir, 'conf')
- if not dont_gen_conf:
+ if gen_conf:
if os.path.isdir(mcp_conf_bak):
print 'Reverting old conf backup folder'
shutil.rmtree(mcp_conf)
os.rename(mcp_conf_bak, mcp_conf)
- get_conf_copy(mcp_dir, fml_dir)
+ create_merged_conf(mcp_dir, fml_dir)
print 'Backing up MCP Conf'
os.rename(mcp_conf, mcp_conf_bak)
@@ -942,7 +593,7 @@ def setup_mcp(fml_dir, mcp_dir, dont_gen_conf=True):
print 'Copying FML conf'
shutil.copytree(fml_conf, mcp_conf)
- gen_renamed_conf(mcp_dir, fml_dir)
+ create_renamed_conf(mcp_dir, fml_dir)
#update workspace
if not os.path.isfile(os.path.join(fml_dir, 'fmlbuild.properties-sample')):
@@ -953,65 +604,108 @@ def setup_mcp(fml_dir, mcp_dir, dont_gen_conf=True):
if not os.path.isdir(mcp_eclipse) and os.path.isdir(os.path.join(fml_dir, 'eclipse')):
print 'Fixing MCP Workspace'
- copytree(os.path.join(fml_dir, 'eclipse'), mcp_eclipse)
+ copytree(os.path.join(fml_dir, 'eclipse'), mcp_eclipse)
-def normaliselines(in_filename):
- in_filename = os.path.normpath(in_filename)
- tmp_filename = in_filename + '.tmp'
+def whereis(filename, rootdir):
+ # Snagged from MCP
+ if not os.path.exists(rootdir):
+ return []
+ #logging.info('> Searching for %s in %s', filename, rootdir)
+ results = []
+ for path, _, filelist in os.walk(rootdir):
+ if filename in filelist:
+ results.append(path)
+ return results
+
+def find_java():
+ # Snagged from MCP so we can gather this info without setting up it's Command object
+ results = []
+ if os.name == 'nt':
+ if not results:
+ import _winreg
+ for flag in [_winreg.KEY_WOW64_64KEY, _winreg.KEY_WOW64_32KEY]:
+ try:
+ k = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, r'Software\JavaSoft\Java Development Kit', 0, _winreg.KEY_READ | flag)
+ version, _ = _winreg.QueryValueEx(k, 'CurrentVersion')
+ k.Close()
+ k = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, r'Software\JavaSoft\Java Development Kit\%s' % version, 0, _winreg.KEY_READ | flag)
+ path, _ = _winreg.QueryValueEx(k, 'JavaHome')
+ k.Close()
+ path = os.path.join(str(path), 'bin')
+ if (runcmd('"%s" -version' % os.path.join(path, 'javac'))):
+ results.append(path)
+ except (OSError):
+ pass
+ if not results:
+ if (runcmd('javac -version')):
+ results.append('')
+ if not results and 'ProgramW6432' in os.environ:
+ results.extend(whereis('javac.exe', os.environ['ProgramW6432']))
+ if not results and 'ProgramFiles' in os.environ:
+ results.extend(whereis('javac.exe', os.environ['ProgramFiles']))
+ if not results and 'ProgramFiles(x86)' in os.environ:
+ results.extend(whereis('javac.exe', os.environ['ProgramFiles(x86)']))
+ else:
+ if not results:
+ if (runcmd('javac -version')):
+ results.append('')
+ if not results:
+ results.extend(whereis('javac', '/usr/bin'))
+ if not results:
+ results.extend(whereis('javac', '/usr/local/bin'))
+ if not results:
+ results.extend(whereis('javac', '/opt'))
+ if not results:
+ print('Java JDK is not installed ! Please install java JDK from http://java.oracle.com')
+ sys.exit(1)
+
+ return {
+ 'javac' : '"%s"' % os.path.join(results[0], 'javac'),
+ 'java' : '"%s"' % os.path.join(results[0], 'java')
+ }
- with open(in_filename, 'rb') as in_file:
- with open(tmp_filename, 'wb') as out_file:
- out_file.write(in_file.read().replace('\r\n', '\n'))
-
- shutil.move(tmp_filename, in_filename)
-
-def get_conf_copy(mcp_dir, fml_dir):
+#==================================================================================
+# MCP Conf Merger Code
+#==================================================================================
+def create_merged_conf(mcp_dir, fml_dir):
+ print('Creating merged conf')
+ #Creates the merged conf folder from MCP's conf folder to fml_dir/conf
+
#Lets grab the files we dont work on
- for file in ['version.cfg', 'newids.csv']:
- dst_file = os.path.normpath(os.path.join(fml_dir, 'conf', file))
- src_file = os.path.normpath(os.path.join(mcp_dir, 'conf', file))
+ for file in ['version.cfg', 'newids.csv', 'joined.exc']:
+ dst_file = os.path.join(fml_dir, 'conf', file)
+ src_file = os.path.join(mcp_dir, 'conf', file)
if not os.path.isdir(os.path.dirname(dst_file)):
os.makedirs(os.path.dirname(dst_file))
if os.path.exists(dst_file):
os.remove(dst_file)
shutil.copy(src_file, dst_file)
normaliselines(dst_file)
- print 'Grabbing: ' + src_file
+ print(' Copying %s' % os.path.normpath(src_file))
- common_srg = gen_merged_srg(mcp_dir, fml_dir)
- common_exc = gen_merged_exc(mcp_dir, fml_dir)
- common_map = gen_shared_searge_names(common_srg, common_exc)
+ print(' Generating merged Retroguard data')
+ common_srg = create_merged_srg(mcp_dir, fml_dir)
+ print(' Reading merged MCInjector config')
+ common_exc = load_merged_exc(mcp_dir, fml_dir)
+ print(' Gathering list of common searge names')
+ common_map = create_shared_searge_names(common_srg, common_exc)
- gen_merged_csv(common_map, os.path.join(mcp_dir, 'conf', 'fields.csv'), os.path.join(fml_dir, 'conf', 'fields.csv'))
- gen_merged_csv(common_map, os.path.join(mcp_dir, 'conf', 'methods.csv'), os.path.join(fml_dir, 'conf', 'methods.csv'))
- gen_merged_csv(common_map, os.path.join(mcp_dir, 'conf', 'params.csv'), os.path.join(fml_dir, 'conf', 'params.csv'), main_key='param')
+ for x in [['fields.csv', 'searge'], ['methods.csv', 'searge'], ['params.csv', 'param']]:
+ print(' Generating merged csv for %s' % x[0])
+ create_merged_csv(common_map, os.path.join(mcp_dir, 'conf', x[0]), os.path.join(fml_dir, 'conf', x[0]), main_key=x[1])
-def gen_merged_srg(mcp_dir, fml_dir):
- print 'Generating merged Retroguard data'
- srg_client = os.path.join(mcp_dir, 'conf', 'client.srg')
- srg_server = os.path.join(mcp_dir, 'conf', 'server.srg')
+def create_merged_srg(mcp_dir, fml_dir):
+ #Merges two .srg files together to create one master mapping.
+ # When issues are encountered, they are reported but the client srg is trusted over the server
+ client_file = os.path.join(mcp_dir, 'conf', 'client.srg')
+ server_file = os.path.join(mcp_dir, 'conf', 'server.srg')
- if not os.path.isfile(srg_client) or not os.path.isfile(srg_server):
- print 'Could not find client and server srg files in "%s"' % mcp_dir
+ if not os.path.isfile(client_file) or not os.path.isfile(server_file):
+ print(' Could not find client and server srg files in "%s"' % mcp_dir)
return False
- client = {'PK:': {}, 'CL:': {}, 'FD:': {}, 'MD:': {}}
- with open(srg_client, 'r') as fh:
- for line in fh:
- pts = line.rstrip('\r\n').split(' ')
- if pts[0] == 'MD:':
- client[pts[0]][pts[1] + ' ' + pts[2]] = pts[3] + ' ' + pts[4]
- else:
- client[pts[0]][pts[1]] = pts[2]
-
- server = {'PK:': {}, 'CL:': {}, 'FD:': {}, 'MD:': {}}
- with open(srg_server, 'r') as fh:
- for line in fh:
- pts = line.rstrip('\r\n').split(' ')
- if pts[0] == 'MD:':
- server[pts[0]][pts[1] + ' ' + pts[2]] = pts[3] + ' ' + pts[4]
- else:
- server[pts[0]][pts[1]] = pts[2]
+ client = load_srg(client_file)
+ server = load_srg(server_file)
common = {'PK:': {}, 'CL:': {}, 'FD:': {}, 'MD:': {}}
for type in common:
@@ -1024,48 +718,43 @@ def gen_merged_srg(mcp_dir, fml_dir):
for type in common:
for key, value in client[type].items():
- common[type][key] = value #+ ' #C'
+ common[type][key] = value + ' #C' # Tag the client only entries
for type in common:
for key, value in server[type].items():
- common[type][key] = value #+ ' #S'
+ common[type][key] = value + ' #S' # Tag the server only entries
- #Print joined retroguard files
- if fml_dir is None:
- return common
-
- with open(os.path.join(fml_dir, 'conf', 'joined.srg'), 'wb') as f:
- for type in ['PK:', 'CL:', 'FD:', 'MD:']:
- for key in sorted(common[type]):
- f.write('%s %s %s\n' % (type, key, common[type][key]))
+ if not fml_dir is None:
+ #Print joined retroguard files
+ with open(os.path.join(fml_dir, 'conf', 'joined.srg'), 'wb') as f:
+ for type in ['PK:', 'CL:', 'FD:', 'MD:']:
+ for key in sorted(common[type]):
+ f.write('%s %s %s\n' % (type, key, common[type][key]))
return common
-
-def gen_merged_exc(mcp_dir, fml_dir):
- print 'Reading merged MCInjector config'
- exc_joined = os.path.join(mcp_dir, 'conf', 'joined.exc')
+def load_merged_exc(mcp_dir, fml_dir):
+ #Reads the exc file into a dictionary
joined = {}
- with open(exc_joined, 'r') as fh:
+ with open(os.path.join(mcp_dir, 'conf', 'joined.exc'), 'r') as fh:
for line in fh:
if not line.startswith('#'):
pts = line.rstrip('\r\n').split('=')
joined[pts[0]] = pts[1]
- return joined
-
-def gen_shared_searge_names(common_srg, common_exc):
+ return joined
+
+def create_shared_searge_names(common_srg, common_exc):
+ #Creates an array of all srg names that are common on both the client and server
field = re.compile(r'field_[0-9]+_[a-zA-Z_]+$')
method = re.compile(r'func_[0-9]+_[a-zA-Z_]+')
param = re.compile(r'p_[\w]+_\d+_')
- print 'Gathering list of common searge names'
-
searge = []
for key, value in common_srg['FD:'].items():
m = field.search(value)
- if not m is None:
+ if not m is None and not '#' in value:
if not m.group(0) in searge:
searge.append(m.group(0))
@@ -1082,121 +771,80 @@ def gen_shared_searge_names(common_srg, common_exc):
if not p in searge:
searge.append(p)
- return searge
-
-def gen_merged_csv(common_map, in_file, out_file, main_key='searge'):
- reader = csv.DictReader(open(in_file, 'r'))
- print 'Generating merged csv for %s' % os.path.basename(in_file)
- common = []
+ return searge
+
+def create_merged_csv(common_map, in_file, out_file, main_key='searge'):
+ #Filter throw the csv and condense 'shared' mappings into one entry of side 2
+ fields = []
+ data = []
+ with closing(open(in_file, 'r')) as fh:
+ reader = csv.DictReader(fh)
+ fields = reader.fieldnames
+ data = [r for r in reader]
+
+ side = [
+ [r for r in data if r['side'] == '0' and not r[main_key] in common_map],
+ [r for r in data if r['side'] == '1' and not r[main_key] in common_map],
+ sorted([r for r in data if r[main_key] in common_map], key=lambda row: row['side'])
+ ]
+
added = []
- for row in reader:
+ common = []
+ for row in side[2]:
if not row[main_key] in added:
row['side'] = '2'
- common.append(row)
added.append(row[main_key])
- writer = csv.DictWriter(open(out_file, 'wb'), fieldnames=reader.fieldnames, lineterminator='\n')
- writer.writeheader()
- for row in sorted(common, key=lambda row: row[main_key]):
- writer.writerow(row)
+ common.append(row)
+
+ with closing(open(out_file, 'wb')) as fh:
+ writer = csv.DictWriter(fh, fieldnames=fields, lineterminator='\n')
+ writer.writeheader()
+ for row in sorted(side[0] + side[1] + common, key=lambda row: row[main_key]):
+ writer.writerow(row)
-def repackage_class(pkgs, cls):
- if cls.startswith('net/minecraft/src/'):
- tmp = cls[18:]
- if tmp in pkgs.keys():
- return '%s/%s' % (pkgs[tmp], tmp)
- return cls
-
-typere = re.compile('([\[ZBCSIJFDV]|L([\w\/]+);)')
-def repackage_signature(pkgs, sig):
- global typere
- sig1 = sig
- params = sig.rsplit(')', 1)[0][1:]
- ret = sig.rsplit(')', 1)[1]
-
- sig = '('
- for arg in typere.findall(params):
- if len(arg[1]) > 0:
- sig += 'L%s;' % repackage_class(pkgs, arg[1])
- else:
- sig += arg[0]
- sig += ')'
- for tmp in typere.findall(ret):
- if len(tmp[1]) > 0:
- sig += 'L%s;' % repackage_class(pkgs, tmp[1])
- else:
- sig += tmp[0]
- return sig
-
-def gen_renamed_conf(mcp_dir, fml_dir):
+def create_renamed_conf(mcp_dir, fml_dir):
+ # Creates copies of the joined srg and exec files with the new Packaged names
+ # Also updates the patches in the conf folder for the new packaged names
+ print('Creating Repackaged data')
pkg_file = os.path.join(fml_dir, 'conf', 'packages.csv')
- srg_in = os.path.join(mcp_dir, 'conf', 'joined.srg')
- srg_out = os.path.join(mcp_dir, 'conf', 'packaged.srg')
- exc_in = os.path.join(mcp_dir, 'conf', 'joined.exc')
- exc_out = os.path.join(mcp_dir, 'conf', 'packaged.exc')
pkgs = {}
if os.path.isfile(pkg_file):
- with open(pkg_file) as fh:
+ with closing(open(pkg_file)) as fh:
reader = csv.DictReader(fh)
for line in reader:
pkgs[line['class']] = line['package']
-
- print 'Creating re-packaged srg'
- with open(srg_in, 'r') as inf:
- with open(srg_out, 'wb') as outf:
- for line in inf:
- pts = line.rstrip('\r\n').split(' ')
- if pts[0] == 'PK:':
- outf.write(' '.join(pts) + '\n')
- elif pts[0] == 'CL:':
- pts[2] = repackage_class(pkgs, pts[2])
- outf.write('CL: %s %s\n' % (pts[1], pts[2]))
- elif pts[0] == 'FD:':
- tmp = pts[2].rsplit('/', 1)
- tmp[0] = repackage_class(pkgs, tmp[0])
- outf.write('FD: %s %s/%s\n' % (pts[1], tmp[0], tmp[1]))
- elif pts[0] == 'MD:':
- tmp = pts[3].rsplit('/', 1)
- pts[3] = '%s/%s' % (repackage_class(pkgs, tmp[0]), tmp[1])
- pts[4] = repackage_signature(pkgs, pts[4])
- outf.write('MD: %s %s %s %s\n' % (pts[1], pts[2], pts[3], pts[4]))
- else:
- print 'Line unknown in SRG: ' + line
- outf.write(line)
-
- excre = re.compile('([\[ZBCSIJFDV]|L([\w\/]+);)')
- print 'Creating re-packaged exc'
- with open(exc_in, 'r') as inf:
- with open(exc_out, 'wb') as outf:
- for line in inf:
- line = line.rstrip('\r\n')
- cls = line.split('.')[0]
- named = line.rsplit('=', 1)[1]
- line = line[len(cls)+1:-1*len(named)-1]
- func = line.split('(')[0]
- tmp = named.split('|', 1)
- if len(tmp[0]) > 0:
- excs = tmp[0].split(',')
- for x in range(len(excs)):
- excs[x] = repackage_class(pkgs, excs[x])
- named = '%s|%s' % (','.join(excs), tmp[1])
-
- sig = repackage_signature(pkgs, line[len(func):])
- cls = repackage_class(pkgs, cls)
- outf.write('%s.%s%s=%s\n' % (cls, func, sig, named))
+ def repackage_class(pkgs, cls):
+ if cls.startswith('net/minecraft/src/'):
+ tmp = cls[18:]
+ if tmp in pkgs.keys():
+ return '%s/%s' % (pkgs[tmp], tmp)
+ return cls
+
+ for ext in ['srg', 'exc']:
+ regnms = re.compile(r'net/minecraft/src/(\w+)')
+ print(' Creating re-packaged %s' % ext)
+
+ buf = read_file(os.path.join(mcp_dir, 'conf', 'joined.%s' % ext))
+ def mapname(match):
+ return repackage_class(pkgs, match.group(0))
+ buf = regnms.sub(mapname, buf)
+
+ with closing(open(os.path.join(mcp_dir, 'conf', 'packaged.%s' % ext), 'wb')) as outf:
+ outf.write(buf)
- print 'Creating re-packaged MCP patches'
+ print(' Creating re-packaged MCP patches')
def fix_patches(patch_in, patch_tmp):
regnms = re.compile(r'net\\minecraft\\src\\(\w+)')
- with open(patch_in, 'r') as fh:
+ with closing(open(patch_in, 'r')) as fh:
buf = fh.read()
def mapname(match):
return repackage_class(pkgs, match.group(0).replace('\\', '/')).replace('/', '\\')
buf = regnms.sub(mapname, buf)
- with open(patch_tmp, 'w') as fh:
+ with closing(open(patch_tmp, 'w')) as fh:
fh.write(buf)
shutil.move(patch_tmp, patch_in)
@@ -1204,3 +852,455 @@ def gen_renamed_conf(mcp_dir, fml_dir):
patch_dir = os.path.join(mcp_dir, 'conf', 'patches')
fix_patches(os.path.join(patch_dir, 'minecraft_ff.patch' ), os.path.join(patch_dir, 'tmp.patch'))
fix_patches(os.path.join(patch_dir, 'minecraft_server_ff.patch'), os.path.join(patch_dir, 'tmp.patch'))
+
+#==========================================================================
+# MCP Decompile Process
+#==========================================================================
+def reset_logger():
+ # Resets the logging handlers, if we don't do this, we get multi-prints from MCP
+ log = logging.getLogger()
+ while len(log.handlers) > 0:
+ log.removeHandler(log.handlers[0])
+
+count = 0
+def cleanup_source(path):
+ # We cleanup various things in MCP such as:
+ # astyle differences:
+ # newline after case before case body
+ # newline after case body before new case
+ # We also assign jad-style names to local variables in decompiled code.
+
+ from rename_vars import rename_class
+ path = os.path.normpath(path)
+ regex_cases_before = re.compile(r'((case|default).+\r?\n)\r?\n', re.MULTILINE) #Fixes newline after case before case body
+ regex_cases_after = re.compile(r'\r?\n(\r?\n[ \t]+(case|default))', re.MULTILINE) #Fixes newline after case body before new case
+
+ def updatefile(src_file):
+ global count
+ tmp_file = src_file + '.tmp'
+ count = 0
+ with open(src_file, 'r') as fh:
+ buf = fh.read()
+
+ def fix_cases(match):
+ global count
+ count += 1
+ return match.group(1)
+
+ buf = regex_cases_before.sub(fix_cases, buf)
+ buf = regex_cases_after.sub(fix_cases, buf)
+ old = buf.replace('\r', '')
+ buf = rename_class(old, MCP=True)
+
+ if count > 0 or buf != old:
+ with open(tmp_file, 'w') as fh:
+ fh.write(buf)
+ shutil.move(tmp_file, src_file)
+
+ for path, _, filelist in os.walk(path, followlinks=True):
+ sub_dir = os.path.relpath(path, path)
+ for cur_file in fnmatch.filter(filelist, '*.java'):
+ src_file = os.path.normpath(os.path.join(path, cur_file))
+ updatefile(src_file)
+
+compile_tools = True
+client_jar = None
+def decompile_minecraft(fml_dir, mcp_dir, disable_at=False, disable_merge=False, enable_server=False, disable_client=False, disable_assets=False):
+ # This is where the bulk of the decompile actually happens
+ # Its a bit of a pain as we need to hook into MCP's Commands class to inject our transformers at certian times.
+ global compile_tools
+ global client_jar
+
+ sys.path.append(mcp_dir)
+ from runtime.decompile import decompile
+ from runtime.cleanup import cleanup
+ from runtime.commands import Commands, CLIENT, SERVER
+
+ fml_dir = os.path.abspath(fml_dir)
+
+ # Make sure the src directroy is dead
+ src_dir = os.path.join(mcp_dir, 'src')
+ if os.path.isdir(src_dir):
+ os.chdir(mcp_dir)
+ cleanup(None, False)
+ reset_logger()
+ os.chdir(fml_dir)
+
+ if os.path.isdir(src_dir):
+ print 'Please make sure to backup your modified files, and say yes when it asks you to do cleanup.'
+ sys.exit(1)
+
+ compile_tools = True
+
+ # Inject ourselves before RetroGuard if it's used
+ def applyrg_shunt(self, side, reobf=False, applyrg_real=Commands.applyrg):
+ transformers_hook(self, side)
+ self.logger.info('> Really Applying Retroguard')
+ applyrg_real(self, side, reobf)
+ # Inject ourselves before SpecialSource if it's used
+ def applyss_shunt(self, side, reobf=False, srg_names=False, in_jar=None, out_jar=None, keep_lvt=False, keep_generics=False, applyss_real=Commands.applyss):
+ transformers_hook(self, side)
+ self.logger.info('> Really Applying SpecialSource')
+ applyss_real(self, side, reobf=reobf, srg_names=srg_names, in_jar=in_jar, out_jar=out_jar, keep_lvt=keep_lvt, keep_generics=keep_generics)
+
+ # This is our pre-everything hook.
+ # We do the following:
+ # Verify if astyle is installed/accessible, if not then exit
+ # We also compile and run our transformers:
+ # MCPMerge, This merges the runnable code from the server and client creating a single codebase that is complete.
+ # AccessTransformer:
+ # This changes access levels of classes fields and methods based on a configuration map.
+ # Allows up to keep out base edits down because we don't have to patch the access levels of everything.
+ def transformers_hook(self, side):
+ global compile_tools
+ if not self.has_wine and not self.has_astyle:
+ self.logger.error('!! Please install either wine or astyle for source cleanup !!')
+ self.logger.error('!! This is REQUIRED by FML/Forge Cannot proceed !!')
+ sys.exit(1)
+ jars = {CLIENT: self.jarclient, SERVER: self.jarserver}
+ kill_signatures(jars[side])
+
+ dir_bin = os.path.join(fml_dir, 'bin')
+ if not os.path.isdir(dir_bin):
+ os.makedirs(dir_bin)
+
+ class_path = os.pathsep.join([f for f in self.cpathclient + [dir_bin] if not f in jars.values()])
+ dir_common = os.path.join(fml_dir, 'common')
+ dir_trans = os.path.join(dir_common, 'cpw/mods/fml/common/asm/transformers'.replace('/', os.sep))
+ java = self.cmdjava.translate(None, '"')
+ javac = self.cmdjavac.translate(None, '"')
+ cmd_compile = '"%s" -Xlint:-options -deprecation -g -source 1.6 -target 1.6 -classpath "{classpath}" -sourcepath "{sourcepath}" -d "{outpath}" "{target}"' % javac
+ cmd_compile = cmd_compile.format(classpath=class_path, sourcepath=dir_common, outpath=dir_bin, target="{target}")
+
+ #Compile AccessTransformer and MCPMerger if we havent already
+ # Only needs to happen once, but we don't know if were gunna decompile both client and server so cant do it based off side
+ if compile_tools:
+ self.logger.info('> Compiling AccessTransformer')
+ if not runcmd(cmd_compile.format(target=os.path.join(dir_trans, 'AccessTransformer.java')), commands=self, echo=False):
+ sys.exit(1)
+
+ self.logger.info('> Compiling MCPMerger')
+ if not runcmd(cmd_compile.format(target=os.path.join(dir_trans, 'MCPMerger.java')), commands=self, echo=False):
+ sys.exit(1)
+
+ compile_tools = False
+
+ # Merge the client and server jar, only needs to be run once so only do it on the client
+ if side == CLIENT:
+ if not disable_merge:
+ self.logger.info('> Running MCPMerger')
+ forkcmd = ('"%s" -classpath "{classpath}" cpw.mods.fml.common.asm.transformers.MCPMerger "{mergecfg}" "{client}" "{server}"' % java).format(
+ classpath=class_path, mergecfg=os.path.join(fml_dir, 'mcp_merge.cfg'), client=jars[CLIENT], server=jars[SERVER])
+
+ if not runcmd(forkcmd, echo=False, commands=self):
+ sys.exit(1)
+ else:
+ self.logger.info('> MCPMerge disabled')
+
+ apply_ats(fml_dir, mcp_dir, class_path, jars[side], disable_at=disable_at, commands=self)
+
+ #Check the original jars not the transformed jars
+ def checkjars_shunt(self, side, checkjars_real = Commands.checkjars):
+ self.jarclient = self.jarclient + '.backup'
+ self.jarserver = self.jarserver + '.backup'
+ ret = checkjars_real(self, side)
+ self.jarclient = self.jarclient[:-7]
+ self.jarserver = self.jarserver[:-7]
+ return ret
+
+ try:
+ pre_decompile(mcp_dir, fml_dir, disable_assets=disable_assets)
+
+ os.chdir(mcp_dir)
+ Commands.applyrg = applyrg_shunt
+ Commands.applyss = applyss_shunt
+ Commands.checkjars = checkjars_shunt
+ #decompile -d -n -r
+ # Conf JAD CSV -r -d -a -n -p -o -l -g -c -s --rg
+ decompile(None, False, False, True, True, False, True, False, False, False, False, not disable_client, enable_server, False)
+ reset_logger()
+ os.chdir(fml_dir)
+ post_decompile(mcp_dir, fml_dir)
+
+ except SystemExit, e:
+ print 'Decompile Exception: %d ' % e.code
+ raise e
+
+ if not os.path.isdir(src_dir):
+ print 'Something went wrong, src folder not found at: %s' % src_dir
+ sys.exit(1)
+
+ #cleanup_source
+ cleanup_source(src_dir)
+
+ os.chdir(mcp_dir)
+ commands = Commands(verify=True)
+
+ if not disable_client:
+ updatemd5_side(mcp_dir, commands, CLIENT)
+ reset_logger()
+
+ if enable_server:
+ updatemd5_side(mcp_dir, commands, CLIENT)
+ reset_logger()
+
+ os.chdir(fml_dir)
+
+def updatemd5_side(mcp_dir, commands, side):
+ sys.path.append(mcp_dir)
+ from runtime.mcp import recompile_side, updatemd5_side
+ from runtime.commands import SIDE_NAME
+
+ recomp = recompile_side(commands, side)
+ if recomp:
+ commands.logger.info('> Generating %s md5s', SIDE_NAME[side])
+ commands.gathermd5s(side, skip_fml=True)
+
+def pre_decompile(mcp_dir, fml_dir, disable_assets=False):
+ download_minecraft(mcp_dir, fml_dir)
+
+ if not disable_assets:
+ download_assets(mcp_dir)
+
+def post_decompile(mcp_dir, fml_dir):
+ if False:
+ print('hi')
+
+def apply_fml_patches(fml_dir, mcp_dir, src_dir, copy_files=True):
+ #Delete /minecraft/cpw to get rid of the Side/SideOnly classes used in decompilation
+ cpw_mc_dir = os.path.join(src_dir, 'minecraft', 'cpw')
+ if os.path.isdir(cpw_mc_dir):
+ shutil.rmtree(cpw_mc_dir)
+
+ #patch files
+ print('Applying Forge ModLoader patches')
+ sys.stdout.flush()
+
+ if os.path.isdir(os.path.join(fml_dir, 'patches', 'minecraft')):
+ apply_patches(mcp_dir, os.path.join(fml_dir, 'patches', 'minecraft'), src_dir)
+ if copy_files and os.path.isdir(os.path.join(fml_dir, 'client')):
+ copytree(os.path.join(fml_dir, 'client'), os.path.join(src_dir, 'minecraft'))
+ if copy_files and os.path.isdir(os.path.join(fml_dir, 'common')):
+ copytree(os.path.join(fml_dir, 'common'), os.path.join(src_dir, 'minecraft'))
+
+ #delete argo
+ if os.path.isdir(os.path.join(src_dir, 'minecraft', 'argo')):
+ shutil.rmtree(os.path.join(src_dir, 'minecraft', 'argo'))
+
+def finish_setup_fml(fml_dir, mcp_dir, enable_server=False, disable_client=False, disable_rename=False):
+ sys.path.append(mcp_dir)
+ from runtime.updatenames import updatenames
+ from runtime.updatemd5 import updatemd5
+ from runtime.updatemcp import updatemcp
+
+ os.chdir(mcp_dir)
+ if not disable_rename:
+ updatenames(None, True, not disable_client, enable_server)
+ reset_logger()
+ updatemd5(None, True, not disable_client, enable_server)
+ reset_logger()
+ os.chdir(fml_dir)
+#==========================================================================
+# Download Functions!
+#==========================================================================
+def download_minecraft(mcp_dir, fml_dir, version=None):
+ mc_info = read_mc_versions(fml_dir, version=version, work_dir=os.path.join(mcp_dir, 'jars'))
+
+ failed = False
+
+ if mc_info['new_launcher']:
+ if os.path.isdir(os.path.join(fml_dir, 'jsons')):
+ json_file = os.path.join(fml_dir, 'jsons', '%s-dev.json' % mc_info['version'])
+ else:
+ json_file = os.path.join(fml_dir, 'fml.json')
+
+ version_json = None
+ try:
+ version_json = json.load(open(json_file))
+ except Exception as e:
+ print 'Failed to load version json: %s' % json_file
+ sys.exit(1)
+
+ failed = download_libraries(mcp_dir, version_json['libraries'], mc_info['natives_dir']) or failed
+ if os.path.isfile(mc_info['json_file']):
+ os.remove(mc_info['json_file'])
+ shutil.copy(json_file, mc_info['json_file'])
+ else:
+ failed = not download_list(mc_info['downloads']) or failed
+
+ # Remove any invalid files
+ for type in ['client', 'server']:
+ file_backup(mc_info['%s_file' % type], mc_info['%s_md5' % type])
+ failed = not download_file(mc_info['%s_url' % type], mc_info['%s_file' % type], mc_info['%s_md5' % type]) or failed
+ file_backup(mc_info['%s_file' % type], mc_info['%s_md5' % type])
+
+ if failed:
+ print 'Something failed verifying minecraft files, see log for details.'
+ sys.exit(1)
+
+def download_libraries(mcp_dir, libraries, natives_dir):
+ # Will attempt to download a list of maven style libraries from the default Minecraft website
+ # or a custom website if the library specifies it
+ # This list should be in the format of the new launcher's version.json file
+ # Under the entry 'libraries'
+ lib_dir = os.path.join(mcp_dir, 'jars', 'libraries')
+ default_url = 'https://s3.amazonaws.com/Minecraft.Download/libraries'
+
+ downloads = []
+ failed = False
+
+ for lib in libraries:
+ name = lib['name'].split(':')
+ domain = name[0].split('.')
+ root = name[1]
+ version = name[2]
+ path = domain + [root, version]
+ extract = None
+ root_url = default_url
+ if 'extract' in lib.keys():
+ extract = lib['extract']
+ if 'url' in lib.keys():
+ root_url = lib['url']
+
+ file_names = ['%s-%s.jar' % (root, version)]
+
+ if 'natives' in lib.keys():
+ file_names = []
+ for k,v in lib['natives'].items():
+ file_names.append('%s-%s-%s.jar' % (root, version, v))
+
+ for file_name in file_names:
+ url = '%s/%s/%s' % (root_url, '/'.join(path), file_name)
+ file_path = os.path.join(lib_dir, os.sep.join(path), file_name)
+ headers = get_headers(url)
+ if headers is None:
+ print 'Could not retreive headers for library: %s ( %s )' % (lib['name'], url)
+ failed = True
+ else:
+ downloads.append({
+ 'url' : url,
+ 'file' : file_path,
+ 'md5' : headers['ETag'],
+ 'size' : headers['Content-Length'],
+ 'extract' : extract
+ })
+
+ return download_list(downloads, natives_dir)
+
+def download_list(list, natives_dir):
+ #Downloads a list of files and urls. Verifying md5s if avalible.
+ #Skipping already existing and valid files.
+ #Also extracts files that are specified to be extracted to the natives folder
+ missing = []
+ for dl in list:
+ if os.path.isfile(dl['file']):
+ if dl['md5'] is None or not get_md5(dl['file']) == dl['md5']:
+ missing.append(dl)
+ else:
+ missing.append(dl)
+
+ if len(missing) == 0:
+ return False
+
+ print 'Downloading %s libraries' % len(missing)
+ failed = False
+ for dl in missing:
+ if download_file(dl['url'], dl['file'], dl['md5'], prefix=' '):
+ if not dl['extract'] is None:
+ excludes = []
+ if 'exclude' in dl['extract'].keys():
+ excludes = dl['extract']['exclude']
+ extract_zip(dl['file'], natives_dir, prefix=' ', filter=excludes)
+ else:
+ print(' Failed to download %s from %s' % (os.path.basename(dl['file']), dl['url']))
+ failed = True
+
+ return failed
+
+def download_assets(mcp_dir):
+ from xml.dom.minidom import parse
+ asset_dir = os.path.join(mcp_dir, 'jars', 'assets')
+ base_url = 'https://s3.amazonaws.com/Minecraft.Resources'
+
+ print('Gathering assets list from %s' % base_url)
+
+ files = []
+ failed = False
+
+ try:
+ url = urllib.urlopen(base_url)
+ xml = parse(url)
+
+ def get(xml, key):
+ return xml.getElementsByTagName(key)[0].firstChild.nodeValue
+
+ for asset in xml.getElementsByTagName('Contents'):
+ path = get(asset, 'Key')
+ if path.endswith('/'):
+ continue
+
+ file = os.path.join(asset_dir, os.sep.join(path.split('/')))
+ md5 = get(asset, 'ETag').replace('"', '')
+
+ if os.path.isfile(file):
+ if get_md5(file) == md5:
+ continue
+
+ files.append({
+ 'file' : file,
+ 'url' : '%s/%s' % (base_url, path),
+ 'size' : get(asset, 'Size'),
+ 'md5' : md5
+ })
+ except Exception as e:
+ print 'Error gathering asset list:'
+ pprint(e)
+ sys.exit(1)
+
+ if len(files) == 0:
+ print(' No new assets need to download')
+ return
+
+ print(' Downloading %s assets' % len(files))
+ for file in files:
+ failed = not download_file(file['url'], file['file'], file['md5'], root=asset_dir, prefix=' ') or failed
+
+ if failed:
+ print(' Downloading assets failed, please review log for more details')
+ sys.exit(1)
+#==========================================================================
+# Transformers
+#==========================================================================
+def apply_ats(fml_dir, mcp_dir, class_path, target, disable_at=False, commands=None):
+ def log(msg):
+ if commands is None:
+ print(msg)
+ else:
+ commands.logger.info(msg)
+
+ cmds = find_java()
+ if cmds is None:
+ log('>Could not run Access Transformer, Java not found!')
+ sys.exit(1)
+
+ if not disable_at:
+ log('> Running AccessTransformer')
+ forkcmd = ('"%s" -classpath "{classpath}" cpw.mods.fml.common.asm.transformers.AccessTransformer "{jar}" "{fmlconfig}"' % cmds['java']).format(
+ classpath=class_path, jar=target, fmlconfig=os.path.join(fml_dir, 'common', 'fml_at.cfg'))
+
+ forge_cfg = os.path.join(fml_dir, '..', 'common', 'forge_at.cfg')
+ if os.path.isfile(forge_cfg):
+ log(' Forge config detected')
+ forkcmd += ' "%s"' % forge_cfg
+
+ for dirname, dirnames, filenames in os.walk(os.path.join(fml_dir, '..', 'accesstransformers')):
+ for filename in filenames:
+ accesstransformer = os.path.join(dirname, filename)
+ if os.path.isfile(accesstransformer):
+ log(' Access Transformer "%s" detected' % filename)
+ forkcmd += ' "%s"' % accesstransformer
+
+ if not runcmd(forkcmd, echo=False, commands=commands):
+ sys.exit(1)
+ else:
+ log('> Access Transformer disabled')
diff --git a/install/install.py b/install/install.py
index 3edb7173fe..fb0ede495d 100644
--- a/install/install.py
+++ b/install/install.py
@@ -1,20 +1,24 @@
import os, os.path, sys
from optparse import OptionParser
-from fml import setup_fml, finish_setup_fml, apply_fml_patches, setup_mcp
+from fml import setup_fml, finish_setup_fml, apply_fml_patches, setup_mcp, download_mcp
-def fml_main(fml_dir, mcp_dir, dont_gen_conf=True, disable_patches=False, disable_at=False, disable_merge=False, enable_server=False,
- disable_client=False, disable_rename=False, disable_assets=False):
+def fml_main(fml_dir, mcp_dir, gen_conf=True, disable_patches=False, disable_at=False, disable_merge=False, enable_server=False,
+ disable_client=False, disable_rename=False, disable_assets=False, decompile=False):
print '================ Forge ModLoader Setup Start ==================='
- setup_mcp(fml_dir, mcp_dir, dont_gen_conf, download)
- setup_fml(fml_dir, mcp_dir, disable_at=disable_at, disable_merge=disable_merge,
+ download_mcp(fml_dir, mcp_dir)
+ setup_mcp(fml_dir, mcp_dir, gen_conf)
+ if decompile:
+ decompile_minecraft(fml_dir, mcp_dir, disable_at=disable_at, disable_merge=disable_merge,
enable_server=enable_server, disable_client=disable_client,
disable_assets=disable_assets)
- if disable_patches:
- print 'Patching disabled'
+ if disable_patches:
+ print 'Patching disabled'
+ else:
+ apply_fml_patches(fml_dir, mcp_dir, os.path.join(mcp_dir, 'src'))
+ finish_setup_fml(fml_dir, mcp_dir, enable_server=enable_server, disable_client=disable_client, disable_rename=disable_rename)
else:
- apply_fml_patches(fml_dir, mcp_dir, os.path.join(mcp_dir, 'src'))
- finish_setup_fml(fml_dir, mcp_dir, enable_server=enable_server, disable_client=disable_client, disable_rename=disable_rename)
+ print 'Decompile free install is on the to-do!'
print '================ Forge ModLoader Setup End ==================='
if __name__ == '__main__':
@@ -27,6 +31,7 @@ if __name__ == '__main__':
parser.add_option('-e', '--no-merge', action="store_true", dest='no_merge', help='Disable merging server code into client', default=False)
parser.add_option('-n', '--no-rename', action="store_true", dest='no_rename', help='Disable running updatenames', default=False)
parser.add_option('-a', '--no-assets', action="store_true", dest='no_assets', help='Disable downloading of assets folder', default=False)
+ parser.add_option('-d', '--decompile', action="store_true", dest='decompile', help='Decompile minecraft and apply patches', default=True)
options, _ = parser.parse_args()
fml_dir = os.path.dirname(os.path.abspath(__file__))
@@ -46,4 +51,5 @@ if __name__ == '__main__':
fml_main(fml_dir, mcp_dir, disable_patches=options.no_patch,
disable_at=options.no_access, disable_merge=options.no_merge,
enable_server=options.enable_server, disable_client=options.no_client,
- disable_rename=options.no_rename, disable_assets=options.assets)
\ No newline at end of file
+ disable_rename=options.no_rename, disable_assets=options.assets,
+ decompile=options.decompile, gen_conf=False)
\ No newline at end of file
diff --git a/jsons/1.6-dev.json b/jsons/1.6-dev.json
new file mode 100644
index 0000000000..f2e2fdb9ee
--- /dev/null
+++ b/jsons/1.6-dev.json
@@ -0,0 +1,94 @@
+{
+ "id": "FML{version}",
+ "time": "{timestamp}",
+ "releaseTime": "{timestamp}",
+ "type": "release",
+ "processArguments": "username_session_version",
+ "minecraftArguments": "--username ${auth_player_name} --session ${auth_session} --version ${version_name} --gameDir ${game_directory} --assetsDir ${game_assets} --tweakClass cpw.mods.fml.common.launcher.FMLTweaker",
+ "minimumLauncherVersion": 2,
+ "libraries": [
+ {
+ "name": "net.minecraft:launchwrapper:1.3",
+ "comment" : "Important for FML, we add this"
+ },
+ {
+ "name": "org.ow2.asm:asm-all:4.1",
+ "comment" : "Important for FML, we add this"
+ },
+ {
+ "name": "net.sf.jopt-simple:jopt-simple:4.5"
+ },
+ {
+ "name": "com.paulscode:codecjorbis:20101023"
+ },
+ {
+ "name": "com.paulscode:codecwav:20101023"
+ },
+ {
+ "name": "com.paulscode:libraryjavasound:20101123"
+ },
+ {
+ "name": "com.paulscode:librarylwjglopenal:20100824"
+ },
+ {
+ "name": "com.paulscode:soundsystem:20120107"
+ },
+ {
+ "name": "org.lwjgl.lwjgl:lwjgl:2.9.0"
+ },
+ {
+ "name": "org.lwjgl.lwjgl:lwjgl_util:2.9.0"
+ },
+ {
+ "name": "argo:argo:2.25_fixed"
+ },
+ {
+ "name": "org.bouncycastle:bcprov-jdk15on:1.47"
+ },
+ {
+ "name": "com.google.guava:guava:14.0"
+ },
+ {
+ "name": "org.apache.commons:commons-lang3:3.1"
+ },
+ {
+ "name": "commons-io:commons-io:2.4"
+ },
+ {
+ "name": "net.java.jinput:jinput:2.0.5"
+ },
+ {
+ "name": "net.java.jutils:jutils:1.0.0"
+ },
+ {
+ "name": "com.google.code.gson:gson:2.2.2"
+ },
+ {
+ "name": "org.lwjgl.lwjgl:lwjgl-platform:2.9.0",
+ "natives": {
+ "linux": "natives-linux",
+ "windows": "natives-windows",
+ "osx": "natives-osx"
+ },
+ "extract": {
+ "exclude": [
+ "META-INF/"
+ ]
+ }
+ },
+ {
+ "name": "net.java.jinput:jinput-platform:2.0.5",
+ "natives": {
+ "linux": "natives-linux",
+ "windows": "natives-windows",
+ "osx": "natives-osx"
+ },
+ "extract": {
+ "exclude": [
+ "META-INF/"
+ ]
+ }
+ }
+ ],
+ "mainClass": "net.minecraft.client.main.Main"
+}
\ No newline at end of file
diff --git a/jsons/1.6-rel.json b/jsons/1.6-rel.json
new file mode 100644
index 0000000000..7a0596ac3f
--- /dev/null
+++ b/jsons/1.6-rel.json
@@ -0,0 +1,93 @@
+{
+ "id": "FML{version}",
+ "time": "{timestamp}",
+ "releaseTime": "{timestamp}",
+ "type": "release",
+ "processArguments": "username_session_version",
+ "minecraftArguments": "--username ${auth_player_name} --session ${auth_session} --version ${version_name} --gameDir ${game_directory} --assetsDir ${game_assets} --tweakClass cpw.mods.fml.common.launcher.FMLTweaker",
+ "minimumLauncherVersion": 2,
+ "libraries": [
+ {
+ "name": "cpw.mods:fml:{version}",
+ "devdl" : "false"
+ },
+ {
+ "name": "net.minecraft:launchwrapper:1.3"
+ },
+ {
+ "name": "net.sf.jopt-simple:jopt-simple:4.5"
+ },
+ {
+ "name": "com.paulscode:codecjorbis:20101023"
+ },
+ {
+ "name": "com.paulscode:codecwav:20101023"
+ },
+ {
+ "name": "com.paulscode:libraryjavasound:20101123"
+ },
+ {
+ "name": "com.paulscode:librarylwjglopenal:20100824"
+ },
+ {
+ "name": "com.paulscode:soundsystem:20120107"
+ },
+ {
+ "name": "org.lwjgl.lwjgl:lwjgl:2.9.0"
+ },
+ {
+ "name": "org.lwjgl.lwjgl:lwjgl_util:2.9.0"
+ },
+ {
+ "name": "argo:argo:2.25_fixed"
+ },
+ {
+ "name": "org.bouncycastle:bcprov-jdk15on:1.47"
+ },
+ {
+ "name": "com.google.guava:guava:14.0"
+ },
+ {
+ "name": "org.apache.commons:commons-lang3:3.1"
+ },
+ {
+ "name": "commons-io:commons-io:2.4"
+ },
+ {
+ "name": "net.java.jinput:jinput:2.0.5"
+ },
+ {
+ "name": "net.java.jutils:jutils:1.0.0"
+ },
+ {
+ "name": "com.google.code.gson:gson:2.2.2"
+ },
+ {
+ "name": "org.lwjgl.lwjgl:lwjgl-platform:2.9.0",
+ "natives": {
+ "linux": "natives-linux",
+ "windows": "natives-windows",
+ "osx": "natives-osx"
+ },
+ "extract": {
+ "exclude": [
+ "META-INF/"
+ ]
+ }
+ },
+ {
+ "name": "net.java.jinput:jinput-platform:2.0.5",
+ "natives": {
+ "linux": "natives-linux",
+ "windows": "natives-windows",
+ "osx": "natives-osx"
+ },
+ "extract": {
+ "exclude": [
+ "META-INF/"
+ ]
+ }
+ }
+ ],
+ "mainClass": "net.minecraft.client.main.Main"
+}
\ No newline at end of file
diff --git a/mc_versions.cfg b/mc_versions.cfg
index 76ea7befe1..b9df0c229a 100644
--- a/mc_versions.cfg
+++ b/mc_versions.cfg
@@ -1,5 +1,5 @@
[default]
-current_ver = 1.5.2
+current_ver = 1.6
base_url = http://s3.amazonaws.com/MinecraftDownload/
libraries = lwjgl.jar lwjgl_util.jar jinput.jar
natives = windows_natives.jar macosx_natives.jar linux_natives.jar
@@ -94,9 +94,9 @@ mcp_ver = 7.51
mcp_url = http://mcp.ocean-labs.de/files/archive/mcp751.zip
mcp_md5 = a8c68db8736227c9e26cbcb0995e5b71
-[13w24a]
-client_md5 = 6164313863f51af4f0ea206fc351dacf
-server_md5 = 25ae7388545ae5a533508b1983cce796
+[1.6]
+client_md5 = 6a64a2136e3a3fe4d29b0a0df30b25fc
+server_md5 = 7c03305c8bf97a8e8f3cdb147fc90607
mcp_ver = 7.98
-mcp_url = NO_DOWNLOAD_YET
-mcp_md5 = a8c68db8736227c9e26cbcb0995e5b71
+mcp_url =
+mcp_md5 = e2ecc18dc6907dcb63bf5506f9d137d9
diff --git a/update_patches.py b/update_patches.py
index 55d325630a..59aac4665d 100644
--- a/update_patches.py
+++ b/update_patches.py
@@ -63,7 +63,7 @@ def main():
cleanDirs(patchd)
- backup = os.path.join(mcp, 'runtime', 'commands.py.bck')
+ backup = os.path.join(mcp, 'runtime', 'commands.py.backup')
runtime = os.path.join(mcp, 'runtime', 'commands.py')
patch_file = os.path.join(fml_dir, 'commands.patch')