Skip to content

Commit ab18b45

Browse files
committed
fix error spam when loading more modern libraries
1 parent e56cc05 commit ab18b45

File tree

2 files changed

+61
-2
lines changed

2 files changed

+61
-2
lines changed

src/main/java/com/falsepattern/lib/internal/asm/FPTransformer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
import org.apache.logging.log4j.LogManager;
3131
import org.apache.logging.log4j.Logger;
3232

33-
import java.util.Collections;
33+
import java.util.Arrays;
3434
import java.util.List;
3535

3636
@Accessors(fluent = true)
@@ -45,6 +45,6 @@ public class FPTransformer implements SmartTransformer {
4545
private final Logger logger = LOG;
4646

4747
public FPTransformer() {
48-
transformers = Collections.singletonList(new IMixinPluginTransformer());
48+
transformers = Arrays.asList(new IMixinPluginTransformer(), new ITypeDiscovererTransformer());
4949
}
5050
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright (C) 2022 FalsePattern
3+
* All Rights Reserved
4+
*
5+
* The above copyright notice, this permission notice and the word "SNEED"
6+
* shall be included in all copies or substantial portions of the Software.
7+
*
8+
* This program is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU Lesser General Public License as published by
10+
* the Free Software Foundation, either version 3 of the License, or
11+
* (at your option) any later version.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU Lesser General Public License
19+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
20+
*/
21+
22+
package com.falsepattern.lib.internal.asm;
23+
24+
import com.falsepattern.lib.asm.IClassNodeTransformer;
25+
import lombok.val;
26+
import org.objectweb.asm.tree.ClassNode;
27+
import org.objectweb.asm.tree.LdcInsnNode;
28+
29+
public class ITypeDiscovererTransformer implements IClassNodeTransformer {
30+
@Override
31+
public String getName() {
32+
return "ITypeDiscovererTransformer";
33+
}
34+
35+
@Override
36+
public boolean shouldTransform(ClassNode cn, String transformedName, boolean obfuscated) {
37+
return "cpw.mods.fml.common.discovery.ITypeDiscoverer".equals(transformedName);
38+
}
39+
40+
@Override
41+
public void transform(ClassNode cn, String transformedName, boolean obfuscated) {
42+
for (val method: cn.methods) {
43+
if (!method.name.equals("<clinit>")) {
44+
continue;
45+
}
46+
val instructions = method.instructions;
47+
for (int i = 0; i < instructions.size(); i++) {
48+
val insn = instructions.get(i);
49+
if (insn instanceof LdcInsnNode) {
50+
val ldc = (LdcInsnNode) insn;
51+
if (ldc.cst.equals("[^\\s\\$]+(\\$[^\\s]+)?\\.class$")) {
52+
ldc.cst = "(?!module-info)[^\\s\\$]+(\\$[^\\s]+)?\\.class$";
53+
return;
54+
}
55+
}
56+
}
57+
}
58+
}
59+
}

0 commit comments

Comments
 (0)