diff options
| author | 2025-08-21 21:29:52 +0100 | |
|---|---|---|
| committer | 2025-09-13 09:14:23 +0100 | |
| commit | 3f428c23dafb09cc5efe4f30d4d67b5a881d91bd (patch) | |
| tree | a1d17cc72bcfd98fab569f730ba7084962b3cc44 | |
| parent | Add ProjectService to listen for the project lifecycle (diff) | |
| download | enigma-fork-3f428c23dafb09cc5efe4f30d4d67b5a881d91bd.tar.gz enigma-fork-3f428c23dafb09cc5efe4f30d4d67b5a881d91bd.tar.xz enigma-fork-3f428c23dafb09cc5efe4f30d4d67b5a881d91bd.zip | |
Add more utility methods
5 files changed, 32 insertions, 2 deletions
diff --git a/enigma-swing/src/main/java/cuchaz/enigma/gui/GuiController.java b/enigma-swing/src/main/java/cuchaz/enigma/gui/GuiController.java index 9faa0d0..1c4549d 100644 --- a/enigma-swing/src/main/java/cuchaz/enigma/gui/GuiController.java +++ b/enigma-swing/src/main/java/cuchaz/enigma/gui/GuiController.java | |||
| @@ -27,6 +27,7 @@ import java.util.concurrent.ExecutionException; | |||
| 27 | import java.util.stream.Collectors; | 27 | import java.util.stream.Collectors; |
| 28 | import java.util.stream.Stream; | 28 | import java.util.stream.Stream; |
| 29 | 29 | ||
| 30 | import javax.swing.JFrame; | ||
| 30 | import javax.swing.JOptionPane; | 31 | import javax.swing.JOptionPane; |
| 31 | import javax.swing.SwingUtilities; | 32 | import javax.swing.SwingUtilities; |
| 32 | 33 | ||
| @@ -126,6 +127,11 @@ public class GuiController implements ClientPacketHandler, GuiView, DataInvalida | |||
| 126 | return project; | 127 | return project; |
| 127 | } | 128 | } |
| 128 | 129 | ||
| 130 | @Override | ||
| 131 | public JFrame getFrame() { | ||
| 132 | return gui.getFrame(); | ||
| 133 | } | ||
| 134 | |||
| 129 | public boolean isDirty() { | 135 | public boolean isDirty() { |
| 130 | return project != null && project.getMapper().isDirty(); | 136 | return project != null && project.getMapper().isDirty(); |
| 131 | } | 137 | } |
diff --git a/enigma/src/main/java/cuchaz/enigma/Enigma.java b/enigma/src/main/java/cuchaz/enigma/Enigma.java index 13640bc..4483ab7 100644 --- a/enigma/src/main/java/cuchaz/enigma/Enigma.java +++ b/enigma/src/main/java/cuchaz/enigma/Enigma.java | |||
| @@ -84,7 +84,7 @@ public class Enigma { | |||
| 84 | ClassProvider classProviderWithFrames = index.indexJar(scope, classProvider, progress); | 84 | ClassProvider classProviderWithFrames = index.indexJar(scope, classProvider, progress); |
| 85 | services.get(JarIndexerService.TYPE).forEach(indexer -> indexer.acceptJar(scope, classProviderWithFrames, index)); | 85 | services.get(JarIndexerService.TYPE).forEach(indexer -> indexer.acceptJar(scope, classProviderWithFrames, index)); |
| 86 | 86 | ||
| 87 | EnigmaProject project = new EnigmaProject(this, paths, classProvider, index, Utils.zipSha1(paths.toArray(new Path[0]))); | 87 | EnigmaProject project = new EnigmaProject(this, paths, classProvider, scope, index, Utils.zipSha1(paths.toArray(new Path[0]))); |
| 88 | 88 | ||
| 89 | if (callServices) { | 89 | if (callServices) { |
| 90 | for (ProjectService projectService : services.get(ProjectService.TYPE)) { | 90 | for (ProjectService projectService : services.get(ProjectService.TYPE)) { |
diff --git a/enigma/src/main/java/cuchaz/enigma/EnigmaProject.java b/enigma/src/main/java/cuchaz/enigma/EnigmaProject.java index 1e4afa2..3f4a067 100644 --- a/enigma/src/main/java/cuchaz/enigma/EnigmaProject.java +++ b/enigma/src/main/java/cuchaz/enigma/EnigmaProject.java | |||
| @@ -11,6 +11,7 @@ import java.util.Collection; | |||
| 11 | import java.util.List; | 11 | import java.util.List; |
| 12 | import java.util.Map; | 12 | import java.util.Map; |
| 13 | import java.util.Objects; | 13 | import java.util.Objects; |
| 14 | import java.util.Set; | ||
| 14 | import java.util.concurrent.atomic.AtomicInteger; | 15 | import java.util.concurrent.atomic.AtomicInteger; |
| 15 | import java.util.function.Function; | 16 | import java.util.function.Function; |
| 16 | import java.util.jar.JarEntry; | 17 | import java.util.jar.JarEntry; |
| @@ -58,12 +59,13 @@ public class EnigmaProject implements ProjectView { | |||
| 58 | private final ClassProvider classProvider; | 59 | private final ClassProvider classProvider; |
| 59 | private final JarIndex jarIndex; | 60 | private final JarIndex jarIndex; |
| 60 | private final byte[] jarChecksum; | 61 | private final byte[] jarChecksum; |
| 62 | private final Set<String> projectClasses; | ||
| 61 | 63 | ||
| 62 | private EntryRemapper mapper; | 64 | private EntryRemapper mapper; |
| 63 | 65 | ||
| 64 | private final List<DataInvalidationListener> dataInvalidationListeners = new ArrayList<>(); | 66 | private final List<DataInvalidationListener> dataInvalidationListeners = new ArrayList<>(); |
| 65 | 67 | ||
| 66 | public EnigmaProject(Enigma enigma, List<Path> jarPaths, ClassProvider classProvider, JarIndex jarIndex, byte[] jarChecksum) { | 68 | public EnigmaProject(Enigma enigma, List<Path> jarPaths, ClassProvider classProvider, Set<String> projectClasses, JarIndex jarIndex, byte[] jarChecksum) { |
| 67 | if (jarChecksum.length != 20) { | 69 | if (jarChecksum.length != 20) { |
| 68 | throw new IllegalArgumentException(); | 70 | throw new IllegalArgumentException(); |
| 69 | } | 71 | } |
| @@ -73,6 +75,7 @@ public class EnigmaProject implements ProjectView { | |||
| 73 | this.classProvider = classProvider; | 75 | this.classProvider = classProvider; |
| 74 | this.jarIndex = jarIndex; | 76 | this.jarIndex = jarIndex; |
| 75 | this.jarChecksum = jarChecksum; | 77 | this.jarChecksum = jarChecksum; |
| 78 | this.projectClasses = projectClasses; | ||
| 76 | 79 | ||
| 77 | this.mapper = EntryRemapper.empty(jarIndex); | 80 | this.mapper = EntryRemapper.empty(jarIndex); |
| 78 | } | 81 | } |
| @@ -341,6 +344,17 @@ public class EnigmaProject implements ProjectView { | |||
| 341 | } | 344 | } |
| 342 | 345 | ||
| 343 | @Override | 346 | @Override |
| 347 | public Collection<String> getProjectClasses() { | ||
| 348 | return projectClasses; | ||
| 349 | } | ||
| 350 | |||
| 351 | @Override | ||
| 352 | @Nullable | ||
| 353 | public ClassNode getBytecode(String className) { | ||
| 354 | return classProvider.get(className); | ||
| 355 | } | ||
| 356 | |||
| 357 | @Override | ||
| 344 | public void addDataInvalidationListener(DataInvalidationListener listener) { | 358 | public void addDataInvalidationListener(DataInvalidationListener listener) { |
| 345 | dataInvalidationListeners.add(listener); | 359 | dataInvalidationListeners.add(listener); |
| 346 | } | 360 | } |
diff --git a/enigma/src/main/java/cuchaz/enigma/api/view/GuiView.java b/enigma/src/main/java/cuchaz/enigma/api/view/GuiView.java index 15c2dc6..519a8ce 100644 --- a/enigma/src/main/java/cuchaz/enigma/api/view/GuiView.java +++ b/enigma/src/main/java/cuchaz/enigma/api/view/GuiView.java | |||
| @@ -1,5 +1,7 @@ | |||
| 1 | package cuchaz.enigma.api.view; | 1 | package cuchaz.enigma.api.view; |
| 2 | 2 | ||
| 3 | import javax.swing.JFrame; | ||
| 4 | |||
| 3 | import org.jetbrains.annotations.Nullable; | 5 | import org.jetbrains.annotations.Nullable; |
| 4 | 6 | ||
| 5 | import cuchaz.enigma.api.view.entry.EntryReferenceView; | 7 | import cuchaz.enigma.api.view.entry.EntryReferenceView; |
| @@ -10,4 +12,6 @@ public interface GuiView { | |||
| 10 | 12 | ||
| 11 | @Nullable | 13 | @Nullable |
| 12 | EntryReferenceView getCursorReference(); | 14 | EntryReferenceView getCursorReference(); |
| 15 | |||
| 16 | JFrame getFrame(); | ||
| 13 | } | 17 | } |
diff --git a/enigma/src/main/java/cuchaz/enigma/api/view/ProjectView.java b/enigma/src/main/java/cuchaz/enigma/api/view/ProjectView.java index eae776b..b8760e2 100644 --- a/enigma/src/main/java/cuchaz/enigma/api/view/ProjectView.java +++ b/enigma/src/main/java/cuchaz/enigma/api/view/ProjectView.java | |||
| @@ -4,6 +4,7 @@ import java.util.Collection; | |||
| 4 | import java.util.List; | 4 | import java.util.List; |
| 5 | 5 | ||
| 6 | import org.jetbrains.annotations.Nullable; | 6 | import org.jetbrains.annotations.Nullable; |
| 7 | import org.objectweb.asm.tree.ClassNode; | ||
| 7 | 8 | ||
| 8 | import cuchaz.enigma.api.DataInvalidationEvent; | 9 | import cuchaz.enigma.api.DataInvalidationEvent; |
| 9 | import cuchaz.enigma.api.DataInvalidationListener; | 10 | import cuchaz.enigma.api.DataInvalidationListener; |
| @@ -12,6 +13,11 @@ import cuchaz.enigma.api.view.entry.EntryView; | |||
| 12 | public interface ProjectView { | 13 | public interface ProjectView { |
| 13 | <T extends EntryView> T deobfuscate(T entry); | 14 | <T extends EntryView> T deobfuscate(T entry); |
| 14 | 15 | ||
| 16 | Collection<String> getProjectClasses(); | ||
| 17 | |||
| 18 | @Nullable | ||
| 19 | ClassNode getBytecode(String className); | ||
| 20 | |||
| 15 | void addDataInvalidationListener(DataInvalidationListener listener); | 21 | void addDataInvalidationListener(DataInvalidationListener listener); |
| 16 | 22 | ||
| 17 | default void invalidateData(DataInvalidationEvent.InvalidationType type) { | 23 | default void invalidateData(DataInvalidationEvent.InvalidationType type) { |