Skip to content

Commit 6654e61

Browse files
committed
Option to not output any source
1 parent 3e4c0e8 commit 6654e61

9 files changed

Lines changed: 46 additions & 18 deletions

File tree

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
asm_version=9.4
22
fernflower_version=27416e1ed8b6955a64c78bfc21351db5b2412edc
3-
rdi_version=919bf2e
3+
rdi_version=669ba3a
44
jansi_version=2.4.0
55
json_version=20220924
66
diffpatch_version=c639936cdbed7e28c7833316161dcb7fae80d0b6

src/main/java/org/mcphackers/mcp/gui/TextAreaOutputStream.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.io.PrintStream;
55

66
import javax.swing.JTextPane;
7+
import javax.swing.text.BadLocationException;
78

89
public class TextAreaOutputStream extends PrintStream {
910
private JTextPane textPane;
@@ -38,8 +39,10 @@ public void println(String s) {
3839
}
3940

4041
private void printString(String msg) {
41-
int len = textPane.getDocument().getLength();
42-
textPane.setCaretPosition(len);
43-
textPane.replaceSelection(msg);
42+
try {
43+
textPane.getStyledDocument().insertString(textPane.getStyledDocument().getLength(), msg, null);
44+
} catch (BadLocationException ex) {
45+
ex.printStackTrace();
46+
}
4447
}
4548
}

src/main/java/org/mcphackers/mcp/main/MainGUI.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public class MainGUI extends MCP {
6969
"options.running"
7070
};
7171
public static final TaskParameter[][] TAB_PARAMETERS = {
72-
{TaskParameter.PATCHES, TaskParameter.INDENTATION_STRING, TaskParameter.IGNORED_PACKAGES, TaskParameter.DECOMPILE_RESOURCES, TaskParameter.GUESS_GENERICS, TaskParameter.STRIP_GENERICS},
72+
{TaskParameter.PATCHES, TaskParameter.INDENTATION_STRING, TaskParameter.IGNORED_PACKAGES, TaskParameter.OUTPUT_SRC, TaskParameter.DECOMPILE_RESOURCES, TaskParameter.GUESS_GENERICS, TaskParameter.STRIP_GENERICS},
7373
{TaskParameter.SOURCE_VERSION, TaskParameter.TARGET_VERSION, TaskParameter.JAVA_HOME},
7474
{TaskParameter.OBFUSCATION},
7575
{TaskParameter.FULL_BUILD},

src/main/java/org/mcphackers/mcp/tasks/TaskDecompile.java

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
package org.mcphackers.mcp.tasks;
22

3-
import static org.mcphackers.mcp.MCPPaths.*;
3+
import static org.mcphackers.mcp.MCPPaths.EXC;
4+
import static org.mcphackers.mcp.MCPPaths.GAMEDIR;
5+
import static org.mcphackers.mcp.MCPPaths.JARS_DIR;
6+
import static org.mcphackers.mcp.MCPPaths.JAR_ORIGINAL;
7+
import static org.mcphackers.mcp.MCPPaths.MAPPINGS;
8+
import static org.mcphackers.mcp.MCPPaths.MD5_DIR;
9+
import static org.mcphackers.mcp.MCPPaths.PATCHES;
10+
import static org.mcphackers.mcp.MCPPaths.PROJECT;
11+
import static org.mcphackers.mcp.MCPPaths.REMAPPED;
12+
import static org.mcphackers.mcp.MCPPaths.SOURCE;
13+
import static org.mcphackers.mcp.MCPPaths.SOURCE_JAR;
14+
import static org.mcphackers.mcp.MCPPaths.SOURCE_UNPATCHED;
415

516
import java.io.BufferedWriter;
617
import java.io.ByteArrayOutputStream;
@@ -100,8 +111,11 @@ protected Stage[] setStages() {
100111
}
101112
}
102113
FileUtil.compress(ffOut, MCPPaths.get(mcp, SOURCE_JAR, side));
103-
FileUtil.deletePackages(ffOut, mcp.getOptions().getStringArrayParameter(TaskParameter.IGNORED_PACKAGES));
104-
FileUtil.copyDirectory(ffOut, srcPath);
114+
Files.createDirectories(srcPath);
115+
if(mcp.getOptions().getBooleanParameter(TaskParameter.OUTPUT_SRC)) {
116+
FileUtil.deletePackages(ffOut, mcp.getOptions().getStringArrayParameter(TaskParameter.IGNORED_PACKAGES));
117+
FileUtil.copyDirectory(ffOut, srcPath);
118+
}
105119
Files.createDirectories(MCPPaths.get(mcp, GAMEDIR, side));
106120
}),
107121
stage(getLocalizedStage("recompile"),
@@ -222,7 +236,6 @@ public static String getLaunchArgs(MCP mcp) {
222236

223237
public static void createProject(MCP mcp, Side side, int sourceVersion) throws IOException {
224238
Path proj = MCPPaths.get(mcp, PROJECT, side);
225-
String natives = MCPPaths.get(mcp, NATIVES).toAbsolutePath().toString();
226239
Version version = mcp.getCurrentVersion();
227240
String clientArgs = getLaunchArgs(mcp);
228241
Side[] launchSides = side == Side.MERGED ? new Side[]{Side.CLIENT, Side.SERVER} : new Side[]{side};
@@ -238,7 +251,7 @@ public static void createProject(MCP mcp, Side side, int sourceVersion) throws I
238251
writer.startAttribute("classpath");
239252
writer.startAttribute("classpathentry kind=\"src\" path=\"src\"");
240253
writer.startAttribute("attributes");
241-
writer.writeAttribute("attribute name=\"org.eclipse.jdt.launching.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY\" value=\"" + natives + "\"");
254+
writer.writeAttribute("attribute name=\"org.eclipse.jdt.launching.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY\" value=\"" + projectName + "/libraries/natives\"");
242255
writer.closeAttribute("attributes");
243256
writer.closeAttribute("classpathentry");
244257
for(DependDownload dependencyDownload : version.libraries) {
@@ -318,6 +331,7 @@ public static void createProject(MCP mcp, Side side, int sourceVersion) throws I
318331
writer.writeAttribute("listEntry value=\"4\"");
319332
writer.closeAttribute("listAttribute");
320333
writer.startAttribute("listAttribute key=\"org.eclipse.debug.ui.favoriteGroups\"");
334+
writer.writeAttribute("listEntry value=\"org.eclipse.debug.ui.launchGroup.run\"");
321335
writer.writeAttribute("listEntry value=\"org.eclipse.debug.ui.launchGroup.debug\"");
322336
writer.closeAttribute("listAttribute");
323337
writer.writeAttribute("booleanAttribute key=\"org.eclipse.jdt.launching.ATTR_ATTR_USE_ARGFILE\" value=\"false\"");

src/main/java/org/mcphackers/mcp/tasks/TaskRecompile.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ protected Stage[] setStages() {
5757
if (!Files.exists(srcPath)) {
5858
throw new IOException(side.getName() + " sources not found!");
5959
}
60+
if(Files.list(srcPath).collect(Collectors.toList()).isEmpty()) {
61+
return;
62+
}
6063

6164
final List<File> src = collectSource();
6265
final List<Path> classpath = collectClassPath(mcp, side);
@@ -112,7 +115,7 @@ public List<Path> collectResources() throws IOException {
112115
return FileUtil.walkDirectory(srcPath, path -> !Files.isDirectory(path) && !path.getFileName().toString().endsWith(".java") && !path.getFileName().toString().endsWith(".class"));
113116
}
114117

115-
public static List<Path> collectClassPath(MCP mcp, Side side) {
118+
public static List<Path> collectClassPath(MCP mcp, Side side) throws IOException {
116119
List<Path> classpath = new ArrayList<>();
117120
classpath.add(MCPPaths.get(mcp, REMAPPED, side));
118121
if(mcp.getCurrentVersion() != null) {

src/main/java/org/mcphackers/mcp/tasks/TaskReobfuscate.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,20 +87,25 @@ private void reobfuscate() throws IOException {
8787
}
8888
FileUtil.cleanDirectory(reobfDir);
8989
FileUtil.extract(reobfJar, reobfDir, entry -> {
90+
if(entry.isDirectory()) {
91+
return false;
92+
}
9093
String className = entry.getName().replace(".class", "");
94+
// Force inner classes to compare outer class hash
95+
int index;
96+
if((index = className.indexOf('$')) != -1) {
97+
className = className.substring(0, index);
98+
}
9199
String deobfName = reversedNames.get(className);
92100
if(deobfName == null) {
93101
deobfName = className;
94102
}
95103
String hash = originalHashes.get(deobfName);
96104
String hashModified = recompHashes.get(deobfName);
97-
if(!entry.isDirectory()) {
98-
if(hash == null) {
99-
return true;
100-
}
101-
else return !hash.equals(hashModified);
105+
if(hash == null) {
106+
return true;
102107
}
103-
return false;
108+
else return !hash.equals(hashModified);
104109
});
105110
}
106111
}

src/main/java/org/mcphackers/mcp/tasks/mode/TaskParameter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ public enum TaskParameter {
2626
DECOMPILE_OVERRIDE("override", Boolean.class, false),
2727
DECOMPILE_RESOURCES("resources", Boolean.class, false),
2828
GUESS_GENERICS("generics", Boolean.class, false),
29-
STRIP_GENERICS("stripgenerics", Boolean.class, false);
29+
STRIP_GENERICS("stripgenerics", Boolean.class, false),
30+
OUTPUT_SRC("outputsrc", Boolean.class, true);
3031

3132
public static final TaskParameter[] VALUES = TaskParameter.values();
3233

src/main/resources/lang/en_US.lang

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ task.param.override = Add @Override
114114
task.param.resources = Keep resources
115115
task.param.generics = Guess generics
116116
task.param.stripgenerics = Strip generics
117+
task.param.outputsrc = Output source
117118

118119
tasks.success = Finished successfully!
119120
tasks.warning = Finished with warnings!

src/main/resources/lang/ru_RU.lang

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ task.param.override = Декомпиляция с @Override
108108
task.param.resources = Оставлять ресурсы
109109
task.param.generics = Отгадывать дженерики
110110
task.param.stripgenerics = Удалить дженерики
111+
task.param.outputsrc = Выводить исходный код
111112

112113
tasks.success = Завершено успешно!
113114
tasks.warning = Завершено с предупреждениями!

0 commit comments

Comments
 (0)