Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Light and shadow Patches #75

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,9 @@ public static void registerTransformers() {
Config.registerConfigModifier(new DJ2PhaseFixer(), "mixins.dj2addons.json");
TransformerDelegate.registerExplicitTransformer(new DJ2AddonsCoreTransformer(), "org.btpos.dj2addons.core.DJ2AddonsCore");
}
if (FugueConfig.modPatchConfig.enableLightAndShadow) {
TransformerDelegate.registerExplicitTransformer(new com.cleanroommc.fugue.transformer.light_and_shadow.AsmTransformerTransformer(), "kpan.light_and_shadow.asm.core.AsmTransformer");
}

if (FugueConfig.getCodeSourcePatchTargets.length > 0) {
TransformerDelegate.registerExplicitTransformer(new ITweakerTransformer(), FugueConfig.getCodeSourcePatchTargets);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,6 @@ public class ModPatchConfig {
@Config.Comment("Only use with dj2addons 1.2.1.1 or lower")
@Config.Name("Enable Divine Journey 2 Addons Patch")
public boolean enableDivineJourney2Addons = true;
@Config.Name("Enable LightAndShadow Patch")
public boolean enableLightAndShadow = true;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.cleanroommc.fugue.transformer.light_and_shadow;

import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.MethodNode;
import top.outlands.foundation.IExplicitTransformer;

/**
* Targets :
* kpan.light_and_shadow.asm.core.AsmTransformer
*/
public class AsmTransformerTransformer implements IExplicitTransformer{

@Override
public byte[] transform(byte[] bytes) {
ClassReader classReader = new ClassReader(bytes);
ClassNode classNode = new ClassNode();
classReader.accept(classNode, 0);
/*
@SuppressWarnings("unused")
public static void rearrange() {}
public int getPriority(){return -1;}
*/
for (MethodNode methodNode : classNode.methods) {
if ("rearrange".equals(methodNode.name)) {
clearMethod(methodNode);
methodNode.visitInsn(Opcodes.RETURN);
methodNode.visitMaxs(0, 0);
}
}
MethodNode methodNode = new MethodNode(Opcodes.ACC_PUBLIC, "getPriority", "()I", "getPriority()I", null);
methodNode.visitInsn(Opcodes.ICONST_M1);
methodNode.visitInsn(Opcodes.IRETURN);
methodNode.visitMaxs(1, 1);
classNode.methods.add(methodNode);

var classWriter = new ClassWriter(0);
classNode.accept(classWriter);
return classWriter.toByteArray();
}

static void clearMethod(MethodNode method) {
if (method.instructions != null) method.instructions.clear();
if (method.tryCatchBlocks != null) method.tryCatchBlocks.clear();
if (method.localVariables != null) method.localVariables.clear();
if (method.visibleLocalVariableAnnotations != null) method.visibleLocalVariableAnnotations.clear();
if (method.invisibleLocalVariableAnnotations != null) method.invisibleLocalVariableAnnotations.clear();
}
}