summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author ftbsc <dev@fantabos.co>2023-02-08 00:08:13 +0100
committer ftbsc <dev@fantabos.co>2023-02-08 00:08:13 +0100
commit4f7baa6f87e6dff127fa18ab67bde49990c57acf (patch)
tree75a87458f33ad52e270b0ca642401d8d0266bcf0
parent22fa139b742fcdccabbee88aaa91e3386c90bf3d (diff)
fix: patch only once, bump dependancy
-rw-r--r--build.gradle2
-rw-r--r--src/main/java/ftbsc/lll/loader/LilleroLoader.java10
2 files changed, 9 insertions, 3 deletions
diff --git a/build.gradle b/build.gradle
index ea5792f..2f4a891 100644
--- a/build.gradle
+++ b/build.gradle
@@ -16,7 +16,7 @@ dependencies {
implementation 'org.apache.logging.log4j:log4j-core:2.15.0'
implementation 'org.ow2.asm:asm-commons:9.4'
implementation 'cpw.mods:modlauncher:8.1.3'
- implementation 'ftbsc:lll:0.0.5'
+ implementation 'ftbsc:lll:0.1.1'
}
// jar {
diff --git a/src/main/java/ftbsc/lll/loader/LilleroLoader.java b/src/main/java/ftbsc/lll/loader/LilleroLoader.java
index 7f14cd8..1db8544 100644
--- a/src/main/java/ftbsc/lll/loader/LilleroLoader.java
+++ b/src/main/java/ftbsc/lll/loader/LilleroLoader.java
@@ -19,9 +19,11 @@ import java.net.URLClassLoader;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.EnumSet;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.ServiceLoader;
+import java.util.Set;
import java.util.stream.Collectors;
public class LilleroLoader implements ILaunchPluginService {
@@ -34,6 +36,7 @@ public class LilleroLoader implements ILaunchPluginService {
public static final String NAME = "lll-loader";
private List<IInjector> injectors = new ArrayList<>();
+ private Set<IInjector> applied = new HashSet<>();
public LilleroLoader() {
LOGGER.info(INIT, "Patch Loader initialized");
@@ -85,9 +88,10 @@ public class LilleroLoader implements ILaunchPluginService {
public EnumSet<Phase> handlesClass(Type classType, final boolean isEmpty, final String reason) {
if (isEmpty) return NAY;
// TODO can I make a set of target classes to make this faster
+ LOGGER.debug(HANDLER, "Inspecting class {}", classType.getClassName());
for (IInjector inj : this.injectors) {
- if (inj.targetClass().equals(classType.getClassName())) {
- LOGGER.debug(HANDLER, "Marked class {} as handled by {}", classType.getClassName(), LilleroLoader.NAME);
+ if (!this.applied.contains(inj) && inj.targetClass().equals(classType.getClassName())) {
+ LOGGER.info(HANDLER, "Marked class {} as handled by {}", classType.getClassName(), LilleroLoader.NAME);
return YAY;
}
}
@@ -101,6 +105,7 @@ public class LilleroLoader implements ILaunchPluginService {
public int processClassWithFlags(Phase phase, ClassNode classNode, Type classType, String reason) {
LOGGER.debug(PATCHER, "Processing class {} in phase {} of {}", classType.getClassName(), phase.name(), reason);
List<IInjector> relevantInjectors = this.injectors.stream()
+ .filter(i -> !this.applied.contains(i))
.filter(i -> i.targetClass().equals(classType.getClassName()))
.collect(Collectors.toList());
boolean modified = false;
@@ -113,6 +118,7 @@ public class LilleroLoader implements ILaunchPluginService {
LOGGER.info(PATCHER, "Patching {}.{} with {} ({})", classType.getClassName(), method.name, inj.name(), inj.reason());
try {
inj.inject(classNode, method);
+ this.applied.add(inj);
modified = true;
} catch (InjectionException e) {
LOGGER.error(PATCHER, "Error applying patch '{}' : {}", inj.name(), e.toString());