mirror of
https://github.com/zaaarf/lillero-loader.git
synced 2024-11-22 04:54:47 +01:00
feat: improved logging, caught patching errors
This commit is contained in:
parent
4844b40249
commit
1e3b49d0ac
3 changed files with 29 additions and 23 deletions
16
README.md
16
README.md
|
@ -30,22 +30,22 @@ Edit your target instance and go into "Versions". Select "Forge", click "Customi
|
||||||
{
|
{
|
||||||
"downloads": {
|
"downloads": {
|
||||||
"artifact": {
|
"artifact": {
|
||||||
"sha1": "3f51da8dd7df6044190f1fe86500b9793d806d0d",
|
"sha1": "2af308a2026453c4bfe814b42bb71cb579c32a40",
|
||||||
"size": 865,
|
"size": 1502,
|
||||||
"url": "https://maven.fantabos.co/ftbsc/lll/0.0.4/lll-0.0.4.jar"
|
"url": "https://maven.fantabos.co/ftbsc/lll/0.0.5/lll-0.0.5.jar"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"name": "ftbsc:lll:0.0.4"
|
"name": "ftbsc:lll:0.0.5"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"downloads": {
|
"downloads": {
|
||||||
"artifact": {
|
"artifact": {
|
||||||
"sha1": "2d7b816468af42f81b1b82f8c0ea8f373396ae61",
|
"sha1": "91770ff7cd9c8adc03e24ab03056ecafbb9f6e71",
|
||||||
"size": 4193,
|
"size": 4468,
|
||||||
"url": "https://maven.fantabos.co/ftbsc/lll/loader/0.0.5/loader-0.0.5.jar"
|
"url": "https://maven.fantabos.co/ftbsc/lll/loader/0.0.6/loader-0.0.6.jar"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"name": "ftbsc.lll:loader:0.0.5"
|
"name": "ftbsc.lll:loader:0.0.6"
|
||||||
},
|
},
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ dependencies {
|
||||||
implementation 'org.apache.logging.log4j:log4j-core:2.15.0'
|
implementation 'org.apache.logging.log4j:log4j-core:2.15.0'
|
||||||
implementation 'org.ow2.asm:asm-commons:9.4'
|
implementation 'org.ow2.asm:asm-commons:9.4'
|
||||||
implementation 'cpw.mods:modlauncher:8.1.3'
|
implementation 'cpw.mods:modlauncher:8.1.3'
|
||||||
implementation 'ftbsc:lll:0.0.4'
|
implementation 'ftbsc:lll:0.0.5'
|
||||||
}
|
}
|
||||||
|
|
||||||
// jar {
|
// jar {
|
||||||
|
|
|
@ -3,10 +3,10 @@ package ftbsc.lll.loader;
|
||||||
import cpw.mods.modlauncher.serviceapi.ILaunchPluginService;
|
import cpw.mods.modlauncher.serviceapi.ILaunchPluginService;
|
||||||
|
|
||||||
import ftbsc.lll.IInjector;
|
import ftbsc.lll.IInjector;
|
||||||
|
import ftbsc.lll.exception.InjectionException;
|
||||||
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
import org.objectweb.asm.Type;
|
import org.objectweb.asm.Type;
|
||||||
import org.objectweb.asm.tree.ClassNode;
|
import org.objectweb.asm.tree.ClassNode;
|
||||||
import org.objectweb.asm.tree.MethodNode;
|
import org.objectweb.asm.tree.MethodNode;
|
||||||
|
@ -23,13 +23,13 @@ import java.util.ServiceLoader;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class LilleroLoader implements ILaunchPluginService {
|
public class LilleroLoader implements ILaunchPluginService {
|
||||||
public static final Logger LOGGER = LogManager.getLogger("LilleroLoader");
|
public static final Logger LOGGER = LogManager.getLogger(LilleroLoader.class.getCanonicalName());
|
||||||
public static final String NAME = "lillero-loader";
|
public static final String NAME = "lll-loader";
|
||||||
|
|
||||||
private List<IInjector> injectors = new ArrayList<>();
|
private List<IInjector> injectors = new ArrayList<>();
|
||||||
|
|
||||||
public LilleroLoader() {
|
public LilleroLoader() {
|
||||||
LOGGER.info("Lillero Patch Loader initialized");
|
LOGGER.info("INIT", "Patch Loader initialized");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -42,23 +42,23 @@ public class LilleroLoader implements ILaunchPluginService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void offerResource(Path resource, String name) {
|
public void offerResource(Path resource, String name) {
|
||||||
LOGGER.warn(String.format("Resource offered to us: %s @ '%s'", name, resource.toString()));
|
LOGGER.error("RESOURCE", String.format("Resource offered to us (%s@%s) but no action was taken", name, resource.toString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addResources(List<Map.Entry<String, Path>> resources) {
|
public void addResources(List<Map.Entry<String, Path>> resources) {
|
||||||
LOGGER.info("Resources being added:");
|
LOGGER.debug("RESOURCE", "Resources being added:");
|
||||||
for (Map.Entry<String, Path> row : resources) {
|
for (Map.Entry<String, Path> row : resources) {
|
||||||
LOGGER.info(String.format("> %s @ '%s'", row.getKey(), row.getValue().toString()));
|
LOGGER.debug("RESOURCE", String.format("> %s (%s)", row.getKey(), row.getValue().toString()));
|
||||||
try {
|
try {
|
||||||
URL jarUrl = new URL("file:" + row.getValue().toString());
|
URL jarUrl = new URL("file:" + row.getValue().toString());
|
||||||
URLClassLoader loader = new URLClassLoader(new URL[] { jarUrl });
|
URLClassLoader loader = new URLClassLoader(new URL[] { jarUrl });
|
||||||
for (IInjector inj : ServiceLoader.load(IInjector.class, loader)) {
|
for (IInjector inj : ServiceLoader.load(IInjector.class, loader)) {
|
||||||
LOGGER.info(String.format("Registering injector %s", inj.name()));
|
LOGGER.info("RESOURCE", String.format("Registering injector %s", inj.name()));
|
||||||
this.injectors.add(inj);
|
this.injectors.add(inj);
|
||||||
}
|
}
|
||||||
} catch (MalformedURLException e) {
|
} catch (MalformedURLException e) {
|
||||||
LOGGER.error(String.format("Malformed URL for resource %s - 'file:%s'", row.getKey(), row.getValue().toString()));
|
LOGGER.error("RESOURCE", String.format("Malformed URL for resource %s - 'file:%s'", row.getKey(), row.getValue().toString()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -79,8 +79,10 @@ public class LilleroLoader implements ILaunchPluginService {
|
||||||
if (isEmpty) return NAY;
|
if (isEmpty) return NAY;
|
||||||
// TODO can I make a set of target classes to make this faster
|
// TODO can I make a set of target classes to make this faster
|
||||||
for (IInjector inj : this.injectors) {
|
for (IInjector inj : this.injectors) {
|
||||||
if (inj.targetClass().equals(classType.getClassName()))
|
if (inj.targetClass().equals(classType.getClassName())) {
|
||||||
|
LOGGER.debug("HANDLER", String.format("Marked class %s as handled by us", classType.getClassName()));
|
||||||
return YAY;
|
return YAY;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return NAY;
|
return NAY;
|
||||||
}
|
}
|
||||||
|
@ -90,7 +92,7 @@ public class LilleroLoader implements ILaunchPluginService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int processClassWithFlags(Phase phase, ClassNode classNode, Type classType, String reason) {
|
public int processClassWithFlags(Phase phase, ClassNode classNode, Type classType, String reason) {
|
||||||
LOGGER.debug("Processing class {} in phase {} of {}", classType.getClassName(), phase.name(), reason);
|
LOGGER.debug("PATCHER", "Processing class {} in phase {} of {}", classType.getClassName(), phase.name(), reason);
|
||||||
List<IInjector> relevantInjectors = this.injectors.stream()
|
List<IInjector> relevantInjectors = this.injectors.stream()
|
||||||
.filter(i -> i.targetClass().equals(classType.getClassName()))
|
.filter(i -> i.targetClass().equals(classType.getClassName()))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
@ -101,9 +103,13 @@ public class LilleroLoader implements ILaunchPluginService {
|
||||||
inj.methodName().equals(method.name) &&
|
inj.methodName().equals(method.name) &&
|
||||||
inj.methodDesc().equals(method.desc)
|
inj.methodDesc().equals(method.desc)
|
||||||
) {
|
) {
|
||||||
LOGGER.info(String.format("Patching %s.%s with %s", classType.getClassName(), method.name, inj.name()));
|
LOGGER.info("PATCHER", String.format("Patching %s.%s with %s (%s)", classType.getClassName(), method.name, inj.name(), inj.reason()));
|
||||||
inj.inject(classNode, method); // TODO catch patching exceptions
|
try {
|
||||||
modified = true;
|
inj.inject(classNode, method);
|
||||||
|
modified = true;
|
||||||
|
} catch (InjectionException e) {
|
||||||
|
LOGGER.error("PATCHER", String.format("Error applying patch '%s' : %s", inj.name(), e.toString()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue