make the injector more reliable
This commit is contained in:
@@ -28,12 +28,21 @@ dependencies {
|
||||
implementation(group = "org.ow2.asm", name = "asm-util", version = "8.0.1")
|
||||
implementation(group = "org.jetbrains", name = "annotations", version = "19.0.0")
|
||||
implementation(group = "com.google.guava", name = "guava", version = "23.2-jre")
|
||||
implementation(group = "net.sf.jopt-simple", name = "jopt-simple", version = "5.0.1")
|
||||
}
|
||||
|
||||
tasks.register<JavaExec>("inject") {
|
||||
dependsOn(":runelite-mixins:build")
|
||||
dependsOn(":runescape-api:build")
|
||||
dependsOn(":runescape-client:build")
|
||||
|
||||
enableAssertions = true
|
||||
|
||||
main = "com.openosrs.injector.Injector"
|
||||
val out = "${project.extra["rootPath"]}/runelite-client/build/injected/injected-client.oprs"
|
||||
outputs.file(out)
|
||||
classpath = sourceSets["main"].runtimeClasspath
|
||||
args(vanillaDep.singleFile, openosrsVersion)
|
||||
args("--outmode", "jar", "--vanilla", vanillaDep.singleFile, "--version", openosrsVersion, "--output", out)
|
||||
outputs.upToDateWhen {
|
||||
false
|
||||
}
|
||||
|
||||
@@ -25,10 +25,20 @@ import com.openosrs.injector.rsapi.RSApi;
|
||||
import com.openosrs.injector.transformers.InjectTransformer;
|
||||
import com.openosrs.injector.transformers.Java8Ifier;
|
||||
import com.openosrs.injector.transformers.SourceChanger;
|
||||
import static net.runelite.deob.util.JarUtil.load;
|
||||
import static net.runelite.deob.util.JarUtil.save;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Comparator;
|
||||
import java.util.Objects;
|
||||
import joptsimple.ArgumentAcceptingOptionSpec;
|
||||
import joptsimple.OptionParser;
|
||||
import joptsimple.OptionSet;
|
||||
import joptsimple.util.EnumConverter;
|
||||
import net.runelite.asm.ClassFile;
|
||||
import net.runelite.asm.ClassGroup;
|
||||
import net.runelite.deob.util.JarUtil;
|
||||
import static net.runelite.deob.util.JarUtil.load;
|
||||
import org.gradle.api.logging.Logger;
|
||||
import org.gradle.api.logging.Logging;
|
||||
|
||||
@@ -36,22 +46,56 @@ public class Injector extends InjectData implements InjectTaskHandler
|
||||
{
|
||||
static final Logger log = Logging.getLogger(Injector.class);
|
||||
static Injector injector = new Injector();
|
||||
static File injectedClient =
|
||||
new File("../runelite-client/src/main/resources/net/runelite/client/injected-client.oprs");
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
injector.vanilla = load(new File(args[0]));
|
||||
OptionParser parser = new OptionParser();
|
||||
|
||||
ArgumentAcceptingOptionSpec<File> vanillaFileOption =
|
||||
parser.accepts("vanilla", "Vanilla OSRS gamepack file")
|
||||
.withRequiredArg().ofType(File.class);
|
||||
|
||||
ArgumentAcceptingOptionSpec<String> oprsVerOption =
|
||||
parser.accepts("version", "OpenOSRS version")
|
||||
.withRequiredArg().ofType(String.class);
|
||||
|
||||
ArgumentAcceptingOptionSpec<File> outFileOption =
|
||||
parser.accepts("output", "Output file, jar if outmode is jar, folder if outmode is files")
|
||||
.withRequiredArg().ofType(File.class);
|
||||
|
||||
ArgumentAcceptingOptionSpec<OutputMode> outModeOption =
|
||||
parser.accepts("outmode")
|
||||
.withRequiredArg().ofType(OutputMode.class)
|
||||
.withValuesConvertedBy(new EnumConverter<>(OutputMode.class)
|
||||
{
|
||||
@Override
|
||||
public OutputMode convert(String value)
|
||||
{
|
||||
return super.convert(value.toUpperCase());
|
||||
}
|
||||
});
|
||||
|
||||
OptionSet options = parser.parse(args);
|
||||
String oprsVer = options.valueOf(oprsVerOption);
|
||||
|
||||
injector.vanilla = load(options.valueOf(vanillaFileOption));
|
||||
injector.deobfuscated = load(
|
||||
new File("../runescape-client/build/libs/runescape-client-" + args[1] + ".jar"));
|
||||
new File("../runescape-client/build/libs/runescape-client-" + oprsVer + ".jar"));
|
||||
injector.rsApi = new RSApi(Objects.requireNonNull(
|
||||
new File("../runescape-api/build/classes/java/main/net/runelite/rs/api/")
|
||||
.listFiles()));
|
||||
injector.mixins = load(
|
||||
new File("../runelite-mixins/build/libs/runelite-mixins-" + args[1] + ".jar"));
|
||||
new File("../runelite-mixins/build/libs/runelite-mixins-" + oprsVer + ".jar"));
|
||||
|
||||
File oldInjected = new File("../runelite-client/src/main/resources/net/runelite/client/injected-client.oprs");
|
||||
if (oldInjected.exists())
|
||||
{
|
||||
oldInjected.delete();
|
||||
}
|
||||
|
||||
injector.initToVanilla();
|
||||
injector.injectVanilla();
|
||||
save(injector.getVanilla(), injectedClient);
|
||||
save(injector.getVanilla(), options.valueOf(outFileOption), options.valueOf(outModeOption));
|
||||
}
|
||||
|
||||
public void injectVanilla()
|
||||
@@ -100,7 +144,7 @@ public class Injector extends InjectData implements InjectTaskHandler
|
||||
{
|
||||
final String name = injector.getName();
|
||||
|
||||
log.info("[INFO] Starting {}", name);
|
||||
log.lifecycle("[INFO] Starting {}", name);
|
||||
|
||||
injector.start();
|
||||
|
||||
@@ -135,6 +179,52 @@ public class Injector extends InjectData implements InjectTaskHandler
|
||||
log.lifecycle("{} {}", name, transformer.getCompletionMsg());
|
||||
}
|
||||
|
||||
private static void save(ClassGroup group, File output, OutputMode mode)
|
||||
{
|
||||
if (output.exists())
|
||||
{
|
||||
try
|
||||
{
|
||||
Files.walk(output.toPath()).sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(File::delete);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
log.info("Failed to delete output directory contents.");
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
switch (mode)
|
||||
{
|
||||
case FILES:
|
||||
saveFiles(group, output);
|
||||
break;
|
||||
case JAR:
|
||||
output.getParentFile().mkdirs();
|
||||
JarUtil.save(group, output);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private static void saveFiles(ClassGroup group, File outDir)
|
||||
{
|
||||
try
|
||||
{
|
||||
outDir.mkdirs();
|
||||
|
||||
for (ClassFile cf : group.getClasses())
|
||||
{
|
||||
File f = new File(outDir, cf.getName() + ".class");
|
||||
byte[] data = JarUtil.writeClass(group, cf);
|
||||
Files.write(f.toPath(), data);
|
||||
}
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void runChildInjector(com.openosrs.injector.injectors.Injector injector)
|
||||
{
|
||||
inject(injector);
|
||||
|
||||
31
injector/src/main/java/com/openosrs/injector/OutputMode.java
Normal file
31
injector/src/main/java/com/openosrs/injector/OutputMode.java
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright (c) 2021, ThatGamerBlue <thatgamerblue@gmail.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package com.openosrs.injector;
|
||||
|
||||
public enum OutputMode
|
||||
{
|
||||
FILES,
|
||||
JAR
|
||||
}
|
||||
Reference in New Issue
Block a user