def installAndPatchMcp(mcp_dir): mcp_exists = True if not os.path.exists(mcp_dir + "/runtime/commands.py"): mcp_exists = False mcp_zip_file = os.path.join(base_dir, mcp_version + ".zip") print("Checking for mcp zip file: %s" % mcp_zip_file) if not os.path.exists(mcp_zip_file) and mcp_download_url: # Attempt download download_file(mcp_download_url, mcp_zip_file) if os.path.exists(mcp_zip_file): if not os.path.exists(mcp_dir): os.mkdir(mcp_dir) mcp_zip = zipfile.ZipFile(mcp_zip_file) mcp_zip.extractall(mcp_dir) import stat astyle = os.path.join(mcp_dir, "runtime", "bin", "astyle-osx") st = os.stat(astyle) os.chmod(astyle, st.st_mode | stat.S_IEXEC) mcp_exists = True if mcp_exists == False: print "No %s directory or zip file found. Please copy the %s.zip file into %s and re-run the command." % ( mcp_version, mcp_version, base_dir) exit(1) # Patch mcp.cfg for additional mem print("Patching mcp.cfg. Ignore \"FAILED\" hunks") mcp_cfg_patch_file = os.path.join("mcppatches", "mcp.cfg.patch") if os.path.exists(mcp_cfg_patch_file): apply_patch(mcp_dir, mcp_cfg_patch_file, os.path.join(mcp_dir, "conf")) # Patch mcp.cfg with minecraft jar md5 mcp_cfg_file = os.path.join(mcp_dir, "conf", "mcp.cfg") if os.path.exists(mcp_cfg_file): replacelineinfile(mcp_cfg_file, "MD5Client =", "MD5Client = %s\n" % mc_file_md5, True) # Multiple 'MD5Client' entries - hack to get first one currently #replacelineinfile( mcp_cfg_file, "MD5Server =", "MD5Server = %s\n" % mc_server_file_md5, True ); # patch joined.srg if necessary mcp_joined_srg = os.path.join(mcp_dir, "conf", "joined.srg") patch_joined_srg = os.path.join(base_dir, "mcppatches", "joined.srg") if os.path.exists(patch_joined_srg): print 'Updating joined.srg: copying %s to %s' % (patch_joined_srg, mcp_joined_srg) shutil.copy(patch_joined_srg, mcp_joined_srg) # Patch fffix.py fffix_patch_path = os.path.join(base_dir, "mcppatches", "fffix.py.patch") if os.path.exists(fffix_patch_path): print("Patching fffix.py. Ignore \"FAILED\" hunks") apply_patch(mcp_dir, os.path.join("mcppatches", "fffix.py.patch"), os.path.join(mcp_dir, "runtime", "pylibs")) # Use fixed fernflower.jar ff_jar_source_path = os.path.join(base_dir, "mcppatches", "fernflower-opt-fix.jar") ff_jar_dest_path = os.path.join(mcp_dir, "runtime", "bin", "fernflower.jar") if os.path.exists(ff_jar_source_path): print 'Updating fernflower.jar: copying %s to %s' % ( ff_jar_source_path, ff_jar_dest_path) shutil.copy(ff_jar_source_path, ff_jar_dest_path) # Patch Start.java with minecraft version start_java_file = os.path.join(base_dir, "mcppatches", "Start.java") if os.path.exists(start_java_file): target_start_java_file = os.path.join(mcp_dir, "conf", "patches", "Start.java") print 'Updating Start.java: copying %s to %s' % ( start_java_file, target_start_java_file) shutil.copy(start_java_file, target_start_java_file) replacelineinfile( target_start_java_file, "args = concat(new String[] {\"--version\", \"mcp\"", " args = concat(new String[] {\"--version\", \"mcp\", \"--accessToken\", \"0\", \"--assetsDir\", \"assets\", \"--assetIndex\", \"%s\", \"--userProperties\", \"{}\"}, args);\n" % mc_version) # Setup the appropriate mcp file versions mcp_version_cfg = os.path.join(mcp_dir, "conf", "version.cfg") replacelineinfile(mcp_version_cfg, "ClientVersion =", "ClientVersion = %s\n" % mc_version) replacelineinfile(mcp_version_cfg, "ServerVersion =", "ServerVersion = %s\n" % mc_version) # Patch in mcp mappings (if present) params_csv_source = os.path.join(base_dir, "mcppatches", "mappings", "params.csv") params_csv_dest = os.path.join(mcp_dir, "conf", "params.csv") if os.path.exists(params_csv_source): shutil.copy(params_csv_source, params_csv_dest) methods_csv_source = os.path.join(base_dir, "mcppatches", "mappings", "methods.csv") methods_csv_dest = os.path.join(mcp_dir, "conf", "methods.csv") if os.path.exists(methods_csv_source): shutil.copy(methods_csv_source, methods_csv_dest) fields_csv_source = os.path.join(base_dir, "mcppatches", "mappings", "fields.csv") fields_csv_dest = os.path.join(mcp_dir, "conf", "fields.csv") if os.path.exists(fields_csv_source): shutil.copy(fields_csv_source, fields_csv_dest)
def download_deps( mcp_dir ): if not os.path.exists(mcp_dir+"/runtime/commands.py "): download_file( "http://mcp.ocean-labs.de/files/archive/"+mcp_version+".zip", mcp_version+".zip" ) try: os.mkdir( mcp_dir ) mcp_zip = zipfile.ZipFile( mcp_version+".zip" ) mcp_zip.extractall( mcp_dir ) import stat astyle = os.path.join(mcp_dir,"runtime","bin","astyle-osx") st = os.stat( astyle ) os.chmod(astyle, st.st_mode | stat.S_IEXEC) except: pass print("Patching mcp.cfg. ignore \"FAILED\" hunks") apply_patch( mcp_dir, "mcp.cfg.patch", os.path.join(mcp_dir,"conf")) jars = os.path.join(mcp_dir,"jars") versions = os.path.join(jars,"versions",mc_version) mkdir_p( versions ) if sys.platform == 'darwin': native = "osx" elif sys.platform == "linux": native = "linux" elif sys.platform == "linux2": native = "linux" else: native = "windows" json_file = os.path.join(versions,mc_version+".json") shutil.copy( os.path.join("installer",mc_version+".json"),json_file) optifine_dir = os.path.join(jars,"libraries","optifine","OptiFine",of_version ) mkdir_p( optifine_dir ) download_file( "http://optifine.net/download.php?f=OptiFine_"+of_version+of_file_extension, os.path.join( optifine_dir, "OptiFine-"+of_version+".jar" )) json_obj = [] with open(json_file,"rb") as f: json_obj = json.load( f ) try: newlibs = [] for lib in json_obj['libraries']: skip = False if "rules" in lib: for rule in lib["rules"]: if "action" in rule and rule["action"] == "allow" and "os" in rule: skip = True if skip: continue group,artifact,version = lib["name"].split(":") if "url" in lib: repo = lib["url"] else: repo = "https://s3.amazonaws.com/Minecraft.Download/libraries/" if "natives" in lib: url = group.replace(".","/")+ "/"+artifact+"/"+version +"/"+artifact+"-"+version+"-"+lib["natives"][native]+".jar" else: url = group.replace(".","/")+ "/"+artifact+"/"+version +"/"+artifact+"-"+version+".jar" file = os.path.join(jars,"libraries",url.replace("/",os.sep)) mkdir_p(os.path.dirname(file)) download_file( repo + url, file ) if "natives" in lib: folder = os.path.join(jars,"versions",mc_version,mc_version+"-natives") mkdir_p(folder) zip = zipfile.ZipFile(file) 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() newlibs.append( lib ) json_obj['libraries'] = newlibs with open(json_file,"wb+") as f: json.dump( json_obj,f, indent=1 ) except: pass repo = "https://s3.amazonaws.com/Minecraft.Download/" jar_file = os.path.join(versions,mc_version+".jar") jar_url = repo + "versions/"+mc_version+"/"+mc_version+".jar" download_file( jar_url, jar_file )
def installAndPatchMcp( mcp_dir ): mcp_exists = True if not os.path.exists(mcp_dir+"/runtime/commands.py"): mcp_exists = False mcp_zip_file = os.path.join( base_dir,mcp_version+".zip" ) print( "Checking for mcp zip file: %s" % mcp_zip_file ) if not os.path.exists( mcp_zip_file ) and mcp_download_url: # Attempt download download_file( mcp_download_url, mcp_zip_file ) if os.path.exists( mcp_zip_file ): if not os.path.exists( mcp_dir ): os.mkdir( mcp_dir ) mcp_zip = zipfile.ZipFile( mcp_zip_file ) mcp_zip.extractall( mcp_dir ) import stat astyle = os.path.join(mcp_dir,"runtime","bin","astyle-osx") st = os.stat( astyle ) os.chmod(astyle, st.st_mode | stat.S_IEXEC) mcp_exists = True if mcp_exists == False: print "No %s directory or zip file found. Please copy the %s.zip file into %s and re-run the command." % (mcp_version, mcp_version, base_dir) exit(1) # Patch mcp.cfg for additional mem print("Patching mcp.cfg. Ignore \"FAILED\" hunks") mcp_cfg_patch_file = os.path.join("mcppatches", "mcp.cfg.patch") if os.path.exists(mcp_cfg_patch_file): apply_patch( mcp_dir, mcp_cfg_patch_file, os.path.join(mcp_dir,"conf")) # Patch mcp.cfg with minecraft jar md5 mcp_cfg_file = os.path.join(mcp_dir,"conf","mcp.cfg") if os.path.exists(mcp_cfg_file): replacelineinfile( mcp_cfg_file, "MD5Client =", "MD5Client = %s\n" % mc_file_md5, True ); # Multiple 'MD5Client' entries - hack to get first one currently #replacelineinfile( mcp_cfg_file, "MD5Server =", "MD5Server = %s\n" % mc_server_file_md5, True ); # patch joined.srg if necessary mcp_joined_srg = os.path.join(mcp_dir,"conf","joined.srg") patch_joined_srg = os.path.join(base_dir,"mcppatches","joined.srg") if os.path.exists(patch_joined_srg): print 'Updating joined.srg: copying %s to %s' % (patch_joined_srg, mcp_joined_srg) shutil.copy(patch_joined_srg,mcp_joined_srg) # Patch fffix.py fffix_patch_path = os.path.join(base_dir, "mcppatches", "fffix.py.patch") if os.path.exists(fffix_patch_path): print("Patching fffix.py. Ignore \"FAILED\" hunks") apply_patch( mcp_dir, os.path.join("mcppatches", "fffix.py.patch"), os.path.join(mcp_dir,"runtime","pylibs")) # Use fixed fernflower.jar ff_jar_source_path = os.path.join(base_dir, "mcppatches", "fernflower-opt-fix.jar") ff_jar_dest_path = os.path.join(mcp_dir,"runtime","bin","fernflower.jar") if os.path.exists(ff_jar_source_path): print 'Updating fernflower.jar: copying %s to %s' % (ff_jar_source_path, ff_jar_dest_path) shutil.copy(ff_jar_source_path,ff_jar_dest_path) # Patch Start.java with minecraft version start_java_file = os.path.join(base_dir,"mcppatches","Start.java") if os.path.exists(start_java_file): target_start_java_file = os.path.join(mcp_dir,"conf","patches","Start.java") print 'Updating Start.java: copying %s to %s' % (start_java_file, target_start_java_file) shutil.copy(start_java_file,target_start_java_file) replacelineinfile( target_start_java_file, "args = concat(new String[] {\"--version\", \"mcp\"", " args = concat(new String[] {\"--version\", \"mcp\", \"--accessToken\", \"0\", \"--assetsDir\", \"assets\", \"--assetIndex\", \"%s\", \"--userProperties\", \"{}\"}, args);\n" % mc_version ); # Setup the appropriate mcp file versions mcp_version_cfg = os.path.join(mcp_dir,"conf","version.cfg") replacelineinfile( mcp_version_cfg, "ClientVersion =", "ClientVersion = %s\n" % mc_version ); replacelineinfile( mcp_version_cfg, "ServerVersion =", "ServerVersion = %s\n" % mc_version ); # Patch in mcp mappings (if present) params_csv_source = os.path.join(base_dir,"mcppatches","mappings","params.csv") params_csv_dest = os.path.join(mcp_dir,"conf","params.csv") if os.path.exists(params_csv_source): shutil.copy(params_csv_source,params_csv_dest) methods_csv_source = os.path.join(base_dir,"mcppatches","mappings","methods.csv") methods_csv_dest = os.path.join(mcp_dir,"conf","methods.csv") if os.path.exists(methods_csv_source): shutil.copy(methods_csv_source,methods_csv_dest) fields_csv_source = os.path.join(base_dir,"mcppatches","mappings","fields.csv") fields_csv_dest = os.path.join(mcp_dir,"conf","fields.csv") if os.path.exists(fields_csv_source): shutil.copy(fields_csv_source,fields_csv_dest)
def download_deps(mcp_dir): if not os.path.exists(mcp_dir + "/runtime/commands.py "): download_file( "http://mcp.ocean-labs.de/files/archive/" + mcp_version + ".zip", mcp_version + ".zip") try: os.mkdir(mcp_dir) mcp_zip = zipfile.ZipFile(mcp_version + ".zip") mcp_zip.extractall(mcp_dir) import stat astyle = os.path.join(mcp_dir, "runtime", "bin", "astyle-osx") st = os.stat(astyle) os.chmod(astyle, st.st_mode | stat.S_IEXEC) except: pass print("Patching mcp.cfg. ignore \"FAILED\" hunks") apply_patch(mcp_dir, "mcp.cfg.patch", os.path.join(mcp_dir, "conf")) jars = os.path.join(mcp_dir, "jars") versions = os.path.join(jars, "versions", mc_version) mkdir_p(versions) if sys.platform == 'darwin': native = "osx" elif sys.platform == "linux": native = "linux" elif sys.platform == "linux2": native = "linux" else: native = "windows" json_file = os.path.join(versions, mc_version + ".json") shutil.copy(os.path.join("installer", mc_version + ".json"), json_file) optifine_dir = os.path.join(jars, "libraries", "optifine", "OptiFine", of_version) mkdir_p(optifine_dir) download_file( "http://optifine.net/download.php?f=OptiFine_" + of_version + of_file_extension, os.path.join(optifine_dir, "OptiFine-" + of_version + ".jar")) json_obj = [] with open(json_file, "rb") as f: json_obj = json.load(f) try: newlibs = [] for lib in json_obj['libraries']: skip = False if "rules" in lib: for rule in lib["rules"]: if "action" in rule and rule[ "action"] == "allow" and "os" in rule: skip = True if skip: continue group, artifact, version = lib["name"].split(":") if "url" in lib: repo = lib["url"] else: repo = "https://s3.amazonaws.com/Minecraft.Download/libraries/" if "natives" in lib: url = group.replace( ".", "/" ) + "/" + artifact + "/" + version + "/" + artifact + "-" + version + "-" + lib[ "natives"][native] + ".jar" else: url = group.replace( ".", "/" ) + "/" + artifact + "/" + version + "/" + artifact + "-" + version + ".jar" file = os.path.join(jars, "libraries", url.replace("/", os.sep)) mkdir_p(os.path.dirname(file)) download_file(repo + url, file) if "natives" in lib: folder = os.path.join(jars, "versions", mc_version, mc_version + "-natives") mkdir_p(folder) zip = zipfile.ZipFile(file) 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() newlibs.append(lib) json_obj['libraries'] = newlibs with open(json_file, "wb+") as f: json.dump(json_obj, f, indent=1) except: pass repo = "https://s3.amazonaws.com/Minecraft.Download/" jar_file = os.path.join(versions, mc_version + ".jar") jar_url = repo + "versions/" + mc_version + "/" + mc_version + ".jar" download_file(jar_url, jar_file)