Inital work on getting the prebaker to work, still very broken but things have worked
This commit is contained in:
		
							parent
							
								
									d8609346dd
								
							
						
					
					
						commit
						527000ed24
					
				
					 7 changed files with 122 additions and 25 deletions
				
			
		|  | @ -13,7 +13,7 @@ targetCompatibility = 1.8 | |||
| 
 | ||||
| group = 'com.openmodloader' | ||||
| archivesBaseName = project.name | ||||
| version = '0.0.8-SNAPSHOT' | ||||
| version = '0.0.9-SNAPSHOT' | ||||
| 
 | ||||
| repositories { | ||||
|     mavenCentral() | ||||
|  | @ -56,6 +56,10 @@ dependencies { | |||
| 	shade 'org.ow2.asm:asm-debug-all:5.2' | ||||
| 	shade 'cuchaz:enigma:0.11.0.33:lib' | ||||
| 	shade 'net.fabricmc:tiny-remapper:+' | ||||
| 	shade 'net.sf.jopt-simple:jopt-simple:5.0.4' | ||||
| 	shade 'org.apache.logging.log4j:log4j-api:2.11.0' | ||||
| 	shade 'org.apache.logging.log4j:log4j-core:2.11.0' | ||||
| 
 | ||||
| 
 | ||||
| 	shade ('net.minecraft:launchwrapper:1.12') { | ||||
| 		transitive = false | ||||
|  |  | |||
|  | @ -210,6 +210,11 @@ public class AbstractPlugin implements Plugin<Project> { | |||
| 				mavenArtifactRepository.setUrl("http://maven.fabricmc.net/"); | ||||
| 			}); | ||||
| 
 | ||||
| 			project1.getRepositories().maven(mavenArtifactRepository -> { | ||||
| 				mavenArtifactRepository.setName("modmuss50"); | ||||
| 				mavenArtifactRepository.setUrl("https://maven.modmuss50.me"); | ||||
| 			}); | ||||
| 
 | ||||
| 			project1.getRepositories().maven(mavenArtifactRepository -> { | ||||
| 				mavenArtifactRepository.setName("SpongePowered"); | ||||
| 				mavenArtifactRepository.setUrl("http://repo.spongepowered.org/maven"); | ||||
|  | @ -241,11 +246,10 @@ public class AbstractPlugin implements Plugin<Project> { | |||
| 			} | ||||
| 			project1.getDependencies().add(Constants.CONFIG_MC_DEPENDENCIES, "net.minecraft:" + Constants.MINECRAFT_FINAL_JAR.get(extension).getName().replace(".jar", "")); | ||||
| 
 | ||||
| 			if (extension.fabricVersion != null && !extension.fabricVersion.isEmpty()) { | ||||
| 			if (extension.omlVersion != null && !extension.omlVersion.isEmpty()) { | ||||
| 				//only add this when not in a fabric dev env | ||||
| 				project1.getDependencies().add(Constants.CONFIG_MC_DEPENDENCIES, "net.fabricmc:fabric-base:" + extension.version + "-" + extension.fabricVersion + ":deobf"); | ||||
| 				project1.getDependencies().add(Constants.COMPILE_MODS, "OpenModLoader:OpenModLoader:" + extension.version + "-" + extension.omlVersion); | ||||
| 			} | ||||
| 			project1.getDependencies().add(Constants.PROCESS_MODS_DEPENDENCIES, "net.fabricmc:fabric-base:16w38a-0.0.4-SNAPSHOT"); | ||||
| 		}); | ||||
| 
 | ||||
| 		project.getTasks().getByName("build").doLast(task -> { | ||||
|  |  | |||
|  | @ -31,7 +31,7 @@ import java.io.File; | |||
| public class LoomGradleExtension { | ||||
| 	public String version; | ||||
| 	public String runDir = "run"; | ||||
| 	public String fabricVersion; | ||||
| 	public String omlVersion; | ||||
| 	public String pomfVersion; | ||||
| 	public String refmapName; | ||||
| 	public boolean localMappings = false; | ||||
|  | @ -41,13 +41,13 @@ public class LoomGradleExtension { | |||
| 
 | ||||
| 	public String getVersionString() { | ||||
| 		if (isModWorkspace()) { | ||||
| 			return version + "-" + fabricVersion; | ||||
| 			return version + "-" + omlVersion; | ||||
| 		} | ||||
| 		return version; | ||||
| 	} | ||||
| 
 | ||||
| 	public boolean isModWorkspace() { | ||||
| 		return fabricVersion != null && !fabricVersion.isEmpty(); | ||||
| 		return omlVersion != null && !omlVersion.isEmpty(); | ||||
| 	} | ||||
| 
 | ||||
| 	public File getUserCache() { | ||||
|  |  | |||
|  | @ -0,0 +1,63 @@ | |||
| package net.fabricmc.loom.mixin; | ||||
| 
 | ||||
| import com.google.common.io.ByteStreams; | ||||
| import org.spongepowered.asm.service.IClassBytecodeProvider; | ||||
| import org.spongepowered.asm.service.mojang.MixinServiceLaunchWrapper; | ||||
| 
 | ||||
| import java.io.File; | ||||
| import java.io.IOException; | ||||
| import java.io.InputStream; | ||||
| import java.util.ArrayList; | ||||
| import java.util.List; | ||||
| import java.util.Set; | ||||
| import java.util.jar.JarFile; | ||||
| import java.util.zip.ZipEntry; | ||||
| 
 | ||||
| public class MixinServiceGradle extends MixinServiceLaunchWrapper implements IClassBytecodeProvider { | ||||
| 
 | ||||
| 	private static List<JarFile> jars = new ArrayList<>(); | ||||
| 
 | ||||
| 	@Override | ||||
| 	public String getName() { | ||||
| 		return "OpenModLoaderGradle"; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public InputStream getResourceAsStream(String name) { | ||||
| 		for(JarFile file : jars){ | ||||
| 			ZipEntry entry = file.getEntry(name); | ||||
| 			if(entry != null){ | ||||
| 				try { | ||||
| 					InputStream stream = file.getInputStream(entry); | ||||
| 					return stream; | ||||
| 				} catch (IOException e) { | ||||
| 					throw new RuntimeException("Failed to read mod file", e); | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
| 		return super.getResourceAsStream(name); | ||||
| 	} | ||||
| 
 | ||||
| 	public static void setupModFiles(Set<File> mods, File minecraft) throws IOException { | ||||
| 		jars.clear(); | ||||
| 		for(File mod : mods){ | ||||
| 			JarFile jarFile = new JarFile(mod); | ||||
| 			jars.add(jarFile); | ||||
| 		} | ||||
| 		jars.add(new JarFile(minecraft)); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public IClassBytecodeProvider getBytecodeProvider() { | ||||
| 		return this; | ||||
| 	} | ||||
| 
 | ||||
| 	public byte[] getClassBytes(String name, String transformedName) throws IOException { | ||||
| 		InputStream inputStream = getResourceAsStream(name.replace(".", "/") + ".class"); | ||||
| 		byte[] classBytes = ByteStreams.toByteArray(inputStream); | ||||
| 		if(classBytes == null){ | ||||
| 			return super.getClassBytes(name, transformedName); | ||||
| 		} | ||||
| 		return classBytes; | ||||
| 	} | ||||
| } | ||||
|  | @ -16,15 +16,20 @@ | |||
| package net.fabricmc.loom.util.proccessing; | ||||
| 
 | ||||
| import com.google.common.base.Charsets; | ||||
| import com.google.common.base.Predicate; | ||||
| import com.google.common.io.ByteStreams; | ||||
| import com.google.gson.Gson; | ||||
| import com.google.gson.JsonArray; | ||||
| import com.google.gson.JsonObject; | ||||
| import net.fabricmc.loom.mixin.MixinServiceGradle; | ||||
| import net.minecraft.launchwrapper.Launch; | ||||
| import net.minecraft.launchwrapper.LaunchClassLoader; | ||||
| import org.objectweb.asm.*; | ||||
| import org.spongepowered.asm.launch.GlobalProperties; | ||||
| import org.spongepowered.asm.launch.MixinBootstrap; | ||||
| import org.spongepowered.asm.mixin.EnvironmentStateTweaker; | ||||
| import org.spongepowered.asm.mixin.MixinEnvironment; | ||||
| import org.spongepowered.asm.mixin.Mixins; | ||||
| import org.spongepowered.asm.mixin.transformer.MixinTransformer; | ||||
| import org.spongepowered.asm.service.mojang.MixinServiceLaunchWrapper; | ||||
| 
 | ||||
|  | @ -116,8 +121,9 @@ public class MixinPrebaker { | |||
| 
 | ||||
| 	public static final String APPLIED_MIXIN_CONFIGS_FILENAME = ".oml-applied-mixin-configs"; | ||||
| 	public static final String MAPPINGS_FILENAME = ".oml-dev-mappings.tiny"; | ||||
| 	public static MixinTransformer mixinTransformer; | ||||
| 
 | ||||
| 	public static void main(String[] args) { | ||||
| 	public static void main(String[] args) throws IOException { | ||||
| 		boolean hasMappingsFile = false; | ||||
| 
 | ||||
| 		if (args.length < 3) { | ||||
|  | @ -148,17 +154,8 @@ public class MixinPrebaker { | |||
| 		Launch.blackboard = new HashMap<>(); | ||||
| 		Launch.blackboard.put(MixinServiceLaunchWrapper.BLACKBOARD_KEY_TWEAKS, Collections.emptyList()); | ||||
| 
 | ||||
| 		List<JsonObject> modInfo = findModInfo(modFiles); | ||||
| 		List<JsonObject> mods = new ArrayList<>(); | ||||
| 		for(JsonObject modInfoJson : modInfo){ | ||||
| 			if(!modInfoJson.isJsonArray()){ | ||||
| 				continue; | ||||
| 			} | ||||
| 			JsonArray jsonArray = modInfoJson.getAsJsonArray(); | ||||
| 			for (int i = 0; i < jsonArray.size(); i++) { | ||||
| 				mods.add(jsonArray.get(i).getAsJsonObject()); | ||||
| 			} | ||||
| 		} | ||||
| 		List<JsonObject> mods = findModInfo(modFiles); | ||||
| 		System.out.println("Found " + mods.size() + " mods"); | ||||
| 		List<String> mixins = new ArrayList<>(); | ||||
| 		for(JsonObject modObject : mods){ | ||||
| 			mixins.addAll(findMixins(modObject.getAsJsonArray("mixins"))); | ||||
|  | @ -167,11 +164,30 @@ public class MixinPrebaker { | |||
| 		} | ||||
| 		System.out.println("Found " + mixins.size() + " mixins to pre bake"); | ||||
| 
 | ||||
| 		List<String> tweakers = new ArrayList<>(); | ||||
| 		tweakers.add("com.openmodloader.loader.launch.OpenTweaker"); | ||||
| 		GlobalProperties.put("TweakClasses", tweakers); | ||||
| 
 | ||||
| 		MixinBootstrap.init(); | ||||
| 		mixins.forEach(Mixins::addConfiguration); | ||||
| 
 | ||||
| 		MixinServiceGradle.setupModFiles(modFiles, new File(args[argOffset + 0])); | ||||
| 
 | ||||
| 		EnvironmentStateTweaker tweaker = new EnvironmentStateTweaker(); | ||||
| 		tweaker.getLaunchArguments(); | ||||
| 		tweaker.injectIntoClassLoader(Launch.classLoader); | ||||
| 
 | ||||
| 		MixinTransformer mixinTransformer = GlobalProperties.get(GlobalProperties.Keys.TRANSFORMER); | ||||
| 		if(mixinTransformer == null){ | ||||
| 			mixinTransformer = GlobalProperties.get(GlobalProperties.Keys.TRANSFORMER); | ||||
| 		} | ||||
| 		//Check to ensure its not null | ||||
| 		if(mixinTransformer == null){ | ||||
| 			throw new RuntimeException("Failed to get MixinTransformer!"); | ||||
| 		} | ||||
| 
 | ||||
| 		MixinEnvironment mixinEnvironment = MixinEnvironment.getDefaultEnvironment(); | ||||
| 		mixinEnvironment.setSide(MixinEnvironment.Side.CLIENT); //TODO have an all side? | ||||
| 		mixinTransformer.audit(mixinEnvironment); | ||||
| 
 | ||||
| 		try { | ||||
| 			JarInputStream input = new JarInputStream(new FileInputStream(new File(args[argOffset + 0]))); | ||||
|  | @ -233,21 +249,29 @@ public class MixinPrebaker { | |||
| 	} | ||||
| 
 | ||||
| 	private static List<JsonObject> findModInfo(Set<File> mods){ | ||||
| 		return mods.stream().map(file -> { | ||||
| 		List<JsonArray> modFiles = mods.stream().map(file -> { | ||||
| 			try { | ||||
| 				JarFile jar = new JarFile(file); | ||||
| 				return readModInfoFromJar(jar); | ||||
| 			} catch (IOException e) { | ||||
| 				throw new RuntimeException("Failed to mod " + file.getName(), e); | ||||
| 			} | ||||
| 		}).collect(Collectors.toList()); | ||||
| 		}).filter((Predicate<JsonArray>) Objects::nonNull).collect(Collectors.toList()); | ||||
| 
 | ||||
| 		List<JsonObject> containedMods = new ArrayList<>(); | ||||
| 		for(JsonArray modFile : modFiles){ | ||||
| 			for (int i = 0; i < modFile.size(); i++) { | ||||
| 				containedMods.add(modFile.get(i).getAsJsonObject()); | ||||
| 			} | ||||
| 		} | ||||
| 		return containedMods; | ||||
| 	} | ||||
| 
 | ||||
| 	private static JsonObject readModInfoFromJar(@Nonnull JarFile file) throws IOException { | ||||
| 	private static JsonArray readModInfoFromJar(@Nonnull JarFile file) throws IOException { | ||||
| 		Gson gson = new Gson(); | ||||
| 		ZipEntry entry = file.getEntry("mod.json"); | ||||
| 		if (entry == null) | ||||
| 			return null; | ||||
| 		return gson.fromJson(new InputStreamReader(file.getInputStream(entry)), JsonObject.class); | ||||
| 		return gson.fromJson(new InputStreamReader(file.getInputStream(entry)), JsonArray.class); | ||||
| 	} | ||||
| } | ||||
|  | @ -30,11 +30,12 @@ import net.fabricmc.loom.util.Constants; | |||
| import org.gradle.api.Project; | ||||
| 
 | ||||
| import java.io.File; | ||||
| import java.io.IOException; | ||||
| import java.util.List; | ||||
| 
 | ||||
| public class PreBakeMixins { | ||||
| 
 | ||||
| 	public void proccess(Project project, LoomGradleExtension extension, List<File> mods) { | ||||
| 	public void proccess(Project project, LoomGradleExtension extension, List<File> mods) throws IOException { | ||||
| 		project.getLogger().lifecycle(":Found " + mods.size() + " mods to prebake"); | ||||
| 		String[] args = new String[mods.size() + 4]; | ||||
| 		args[0] = "-m"; | ||||
|  |  | |||
|  | @ -0,0 +1 @@ | |||
| net.fabricmc.loom.mixin.MixinServiceGradle | ||||
		Loading…
	
		Reference in a new issue