generated from kappa-maintainer/1.12.2-FG6-Template
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add patch for open disks and open security
- Loading branch information
1 parent
f9e620f
commit 960d94e
Showing
5 changed files
with
166 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
src/main/java/com/cleanroommc/transformer/OpenDisksUnpackTransformer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package com.cleanroommc.transformer; | ||
|
||
import com.cleanroommc.FugueLoadingPlugin; | ||
import net.minecraft.launchwrapper.IClassTransformer; | ||
import net.minecraft.launchwrapper.Launch; | ||
import org.objectweb.asm.ClassReader; | ||
import org.objectweb.asm.ClassWriter; | ||
import org.objectweb.asm.Opcodes; | ||
import org.objectweb.asm.tree.*; | ||
|
||
public class OpenDisksUnpackTransformer implements IClassTransformer { | ||
public OpenDisksUnpackTransformer() { | ||
FugueLoadingPlugin.registerToKnownTransformer("openlights", this); | ||
} | ||
@Override | ||
public byte[] transform(String s, String s1, byte[] bytes) { | ||
if (bytes == null) | ||
{ | ||
return null; | ||
} | ||
|
||
if (!s1.equals("pcl.opendisks.OpenDisksUnpack")) | ||
{ | ||
return bytes; | ||
} | ||
|
||
|
||
ClassNode classNode = new ClassNode(); | ||
ClassReader classReader = new ClassReader(bytes); | ||
classReader.accept(classNode, 0); | ||
boolean modified = false; | ||
AbstractInsnNode prevLine = null; | ||
if (classNode.methods != null) | ||
{ | ||
for (MethodNode methodNode : classNode.methods) | ||
{ | ||
if (methodNode.name.equals("load")) { | ||
InsnList instructions = methodNode.instructions; | ||
if (instructions != null) | ||
{ | ||
for (AbstractInsnNode insnNode : instructions) | ||
{ | ||
if (insnNode.getOpcode() == Opcodes.INVOKEVIRTUAL && insnNode instanceof MethodInsnNode methodInsnNode) | ||
{ | ||
if (methodInsnNode.name.equals("getPath") && methodInsnNode.owner.equals("java/net/URI")) | ||
{ | ||
instructions.insert(methodInsnNode, new MethodInsnNode(Opcodes.INVOKESTATIC, "com/cleanroommc/helper/HookHelper", "byGetResource", "()Ljava/lang/String;", false)); | ||
instructions.insert(methodInsnNode, new InsnNode(Opcodes.POP)); | ||
modified = true; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
if (modified) | ||
{ | ||
Launch.classLoader.unRegisterSuperTransformer(this); | ||
ClassWriter classWriter = new ClassWriter(0); | ||
|
||
classNode.accept(classWriter); | ||
return classWriter.toByteArray(); | ||
} | ||
return bytes; | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
src/main/java/com/cleanroommc/transformer/SoundUnpackTransformer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package com.cleanroommc.transformer; | ||
|
||
import com.cleanroommc.FugueLoadingPlugin; | ||
import net.minecraft.launchwrapper.IClassTransformer; | ||
import net.minecraft.launchwrapper.Launch; | ||
import org.objectweb.asm.ClassReader; | ||
import org.objectweb.asm.ClassWriter; | ||
import org.objectweb.asm.Opcodes; | ||
import org.objectweb.asm.tree.*; | ||
|
||
public class SoundUnpackTransformer implements IClassTransformer { | ||
public SoundUnpackTransformer() { | ||
FugueLoadingPlugin.registerToKnownTransformer("opensecurity", this); | ||
} | ||
@Override | ||
public byte[] transform(String s, String s1, byte[] bytes) { | ||
if (bytes == null) | ||
{ | ||
return null; | ||
} | ||
|
||
if (!s1.equals("pcl.opensecurity.util.SoundUnpack")) | ||
{ | ||
return bytes; | ||
} | ||
|
||
|
||
ClassNode classNode = new ClassNode(); | ||
ClassReader classReader = new ClassReader(bytes); | ||
classReader.accept(classNode, 0); | ||
boolean modified = false; | ||
AbstractInsnNode prevLine = null; | ||
if (classNode.methods != null) | ||
{ | ||
for (MethodNode methodNode : classNode.methods) | ||
{ | ||
if (methodNode.name.equals("load")) { | ||
InsnList instructions = methodNode.instructions; | ||
if (instructions != null) | ||
{ | ||
for (AbstractInsnNode insnNode : instructions) | ||
{ | ||
if (insnNode.getOpcode() == Opcodes.INVOKEVIRTUAL && insnNode instanceof MethodInsnNode methodInsnNode) | ||
{ | ||
if (methodInsnNode.name.equals("getPath") && methodInsnNode.owner.equals("java/net/URI")) | ||
{ | ||
instructions.insert(methodInsnNode, new MethodInsnNode(Opcodes.INVOKESTATIC, "com/cleanroommc/helper/HookHelper", "byGetResource", "()Ljava/lang/String;", false)); | ||
instructions.insert(methodInsnNode, new InsnNode(Opcodes.POP)); | ||
modified = true; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
if (modified) | ||
{ | ||
Launch.classLoader.unRegisterSuperTransformer(this); | ||
ClassWriter classWriter = new ClassWriter(0); | ||
|
||
classNode.accept(classWriter); | ||
return classWriter.toByteArray(); | ||
} | ||
return bytes; | ||
} | ||
} |