-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Forge: Implements REP protection #63
- Loading branch information
Showing
9 changed files
with
138 additions
and
27 deletions.
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
84 changes: 84 additions & 0 deletions
84
.../br/com/gamemods/minecity/forge/base/core/transformer/mod/wrcbe/EntityREPTransformer.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,84 @@ | ||
package br.com.gamemods.minecity.forge.base.core.transformer.mod.wrcbe; | ||
|
||
import br.com.gamemods.minecity.api.CollectionUtil; | ||
import br.com.gamemods.minecity.forge.base.core.MethodPatcher; | ||
import br.com.gamemods.minecity.forge.base.core.ModEnv; | ||
import br.com.gamemods.minecity.forge.base.core.Referenced; | ||
import br.com.gamemods.minecity.forge.base.core.transformer.InsertSetterGetterTransformer; | ||
import org.objectweb.asm.ClassReader; | ||
import org.objectweb.asm.ClassWriter; | ||
import org.objectweb.asm.tree.*; | ||
|
||
import java.util.Comparator; | ||
|
||
import static org.objectweb.asm.Opcodes.*; | ||
|
||
@Referenced("br.com.gamemods.minecity.forge.mc_1_7_10.core.MineCitySevenCoreMod") | ||
@Referenced("br.com.gamemods.minecity.forge.mc_1_10_2.core.MineCityFrostCoreMod") | ||
@MethodPatcher | ||
public class EntityREPTransformer extends InsertSetterGetterTransformer | ||
{ | ||
public EntityREPTransformer() | ||
{ | ||
super("codechicken.wirelessredstone.addons.EntityREP", | ||
"br.com.gamemods.minecity.forge.base.accessors.entity.projectile.ProjectileShooter", | ||
"mineCityShooter", | ||
"br/com/gamemods/minecity/forge/base/protection/wrcbe/IEntityREP", | ||
"setMineCityShooter", "getMineCityShooter" | ||
); | ||
} | ||
|
||
@Override | ||
public byte[] transform(String name, String transformedName, byte[] basicClass) | ||
{ | ||
if(!"codechicken.wirelessredstone.addons.EntityREP".equals(transformedName)) | ||
return basicClass; | ||
|
||
basicClass = super.transform(name, transformedName, basicClass); | ||
|
||
ClassNode node = new ClassNode(); | ||
ClassReader reader = new ClassReader(basicClass); | ||
reader.accept(node, 0); | ||
|
||
String bolt = "br/com/gamemods/minecity/forge/base/protection/wrcbe/IWirelessBolt"; | ||
|
||
for(MethodNode method : node.methods) | ||
{ | ||
if(method.name.equals("detonate")) | ||
{ | ||
CollectionUtil.stream(method.instructions.iterator()) | ||
.filter(ins-> ins.getOpcode() == INVOKESPECIAL).map(MethodInsnNode.class::cast) | ||
.filter(ins-> ins.name.equals("<init>")) | ||
.filter(ins-> ins.owner.equals("codechicken/wirelessredstone/core/WirelessBolt")) | ||
.map(ins-> method.instructions.indexOf(ins)) | ||
.sorted(Comparator.reverseOrder()).mapToInt(Integer::intValue) | ||
.forEachOrdered(index -> { | ||
InsnList list = new InsnList(); | ||
list = new InsnList(); | ||
list.add(new VarInsnNode(ALOAD, 0)); | ||
list.add(new MethodInsnNode(INVOKEINTERFACE, | ||
bolt, "createdFromProjectile", "(Lbr/com/gamemods/minecity/forge/base/accessors/entity/projectile/EntityProjectile;)L"+bolt+";", | ||
true | ||
)); | ||
list.add(new TypeInsnNode(CHECKCAST, "codechicken/wirelessredstone/core/WirelessBolt")); | ||
method.instructions.insert(method.instructions.get(index), list); | ||
}); | ||
break; | ||
} | ||
} | ||
|
||
MethodNode method = new MethodNode(ACC_PUBLIC, "getShooterEntity", "()Lbr/com/gamemods/minecity/forge/base/accessors/entity/base/IEntityLivingBase;", null, null); | ||
method.visitCode(); | ||
method.visitVarInsn(ALOAD, 0); | ||
method.visitFieldInsn(GETFIELD, transformedName.replace('.','/'), "shootingEntity", "Lnet/minecraft/entity/EntityLivingBase;"); | ||
method.visitInsn(ARETURN); | ||
method.visitEnd(); | ||
node.methods.add(method); | ||
|
||
|
||
ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS); | ||
node.accept(writer); | ||
basicClass = ModEnv.saveClass(transformedName, writer.toByteArray()); | ||
return basicClass; | ||
} | ||
} |
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
25 changes: 25 additions & 0 deletions
25
...e/Base/src/main/java/br/com/gamemods/minecity/forge/base/protection/wrcbe/IEntityREP.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,25 @@ | ||
package br.com.gamemods.minecity.forge.base.protection.wrcbe; | ||
|
||
import br.com.gamemods.minecity.forge.base.MineCityForge; | ||
import br.com.gamemods.minecity.forge.base.accessors.entity.base.IEntityLivingBase; | ||
import br.com.gamemods.minecity.forge.base.accessors.entity.projectile.EntityProjectile; | ||
import br.com.gamemods.minecity.forge.base.accessors.entity.projectile.ProjectileShooter; | ||
import br.com.gamemods.minecity.forge.base.core.Referenced; | ||
import br.com.gamemods.minecity.forge.base.core.transformer.mod.wrcbe.EntityREPTransformer; | ||
|
||
@Referenced(at = EntityREPTransformer.class) | ||
public interface IEntityREP extends EntityProjectile | ||
{ | ||
@Referenced(at = EntityREPTransformer.class) | ||
IEntityLivingBase getShooterEntity(); | ||
|
||
@Override | ||
default void detectShooter(MineCityForge mod) | ||
{ | ||
IEntityLivingBase entity = getShooterEntity(); | ||
if(entity != null) | ||
setShooter(new ProjectileShooter(getEntityPos(mod), entity)); | ||
else | ||
setShooter(new ProjectileShooter(getEntityPos(mod))); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
.../Base/src/main/java/br/com/gamemods/minecity/forge/base/protection/wrcbe/IJammerPart.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
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