-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 956534b
Showing
9 changed files
with
406 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="src" path="Alice Fixes"/> | ||
<classpathentry kind="src" path="src"/> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/> | ||
<classpathentry kind="lib" path="jars/bin/jinput.jar"> | ||
<attributes> | ||
<attribute name="org.eclipse.jdt.launching.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY" value="Minecraft/jars/bin/natives"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="lib" path="jars/bin/lwjgl_util.jar"> | ||
<attributes> | ||
<attribute name="org.eclipse.jdt.launching.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY" value="Minecraft/jars/bin/natives"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="lib" path="jars/bin/lwjgl.jar"> | ||
<attributes> | ||
<attribute name="org.eclipse.jdt.launching.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY" value="Minecraft/jars/bin/natives"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="lib" path="jars/bin/minecraft.jar"/> | ||
<classpathentry kind="lib" path="lib/argo-2.25.jar"/> | ||
<classpathentry kind="lib" path="lib/bcprov-jdk15on-147.jar"/> | ||
<classpathentry kind="lib" path="lib/mcpc-api-1.4.7.jar"/> | ||
<classpathentry exported="true" kind="lib" path="lib/asm-all-4.0.jar" sourcepath="lib/asm-all-4.0-source.jar"/> | ||
<classpathentry exported="true" kind="lib" path="lib/guava-12.0.1.jar" sourcepath="lib/guava-12.0.1-sources.jar"/> | ||
<classpathentry kind="output" path="bin"/> | ||
</classpath> |
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,5 @@ | ||
/build | ||
/*.bat | ||
/forge | ||
/bin | ||
/download |
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,56 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>Minecraft</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
</natures> | ||
<linkedResources> | ||
<link> | ||
<name>Alice Fixes</name> | ||
<type>2</type> | ||
<locationURI>PROJECT_LOC/alicefixes/src</locationURI> | ||
</link> | ||
<link> | ||
<name>jars</name> | ||
<type>2</type> | ||
<locationURI>MCP_LOC/jars</locationURI> | ||
</link> | ||
<link> | ||
<name>lib</name> | ||
<type>2</type> | ||
<locationURI>MCP_LOC/lib</locationURI> | ||
</link> | ||
<link> | ||
<name>src</name> | ||
<type>2</type> | ||
<locationURI>MCP_LOC/src/minecraft</locationURI> | ||
</link> | ||
</linkedResources> | ||
<filteredResources> | ||
<filter> | ||
<id>1307293455427</id> | ||
<name>jars</name> | ||
<type>13</type> | ||
<matcher> | ||
<id>org.eclipse.ui.ide.multiFilter</id> | ||
<arguments>1.0-name-matches-false-false-bin</arguments> | ||
</matcher> | ||
</filter> | ||
</filteredResources> | ||
<variableList> | ||
<variable> | ||
<name>MCP_LOC</name> | ||
<value>$%7BPROJECT_LOC%7D/forge/mcp</value> | ||
</variable> | ||
</variableList> | ||
</projectDescription> |
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,2 @@ | ||
To compile: | ||
Install Ant (http://ant.apache.org/) and run "ant". All dependencies will be downloaded for you. |
48 changes: 48 additions & 0 deletions
48
alicefixes/src/com/skcraft/alicefixes/AliceTransformer.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,48 @@ | ||
package com.skcraft.alicefixes; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.logging.Level; | ||
|
||
import cpw.mods.fml.common.FMLLog; | ||
import cpw.mods.fml.relauncher.IClassTransformer; | ||
|
||
public class AliceTransformer implements IClassTransformer { | ||
|
||
private final List<IClassTransformer> transformers; | ||
|
||
public AliceTransformer() { | ||
String[] names = LoadingPlugin.getTransformers(); | ||
transformers = new ArrayList(names.length); | ||
for(String transformer : names) { | ||
try { | ||
transformers.add((IClassTransformer)Class.forName(transformer).newInstance()); | ||
} | ||
catch(Throwable t) { | ||
t.printStackTrace(); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public byte[] transform(String name, byte[] bytes) { | ||
|
||
if(bytes == null) { | ||
return bytes; | ||
} | ||
|
||
for(IClassTransformer transformer : transformers) { | ||
try { | ||
bytes = transformer.transform(name, bytes); | ||
if(bytes == null) | ||
FMLLog.log(Level.SEVERE, "Transformer " + transformer + " has corrupted class " + name); | ||
} | ||
catch(Throwable t) { | ||
t.printStackTrace(); | ||
} | ||
} | ||
|
||
return bytes; | ||
} | ||
|
||
} |
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,45 @@ | ||
package com.skcraft.alicefixes; | ||
|
||
import java.util.Map; | ||
|
||
import cpw.mods.fml.relauncher.IFMLLoadingPlugin; | ||
import cpw.mods.fml.relauncher.IFMLLoadingPlugin.TransformerExclusions; | ||
|
||
@TransformerExclusions("com.skcraft.alicefixes") | ||
public class LoadingPlugin implements IFMLLoadingPlugin { | ||
|
||
@Override | ||
public String[] getLibraryRequestClass() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public String[] getASMTransformerClass() { | ||
System.out.println("getASMTransformerClass()"); | ||
return new String[] { "com.skcraft.alicefixes.AliceTransformer" }; | ||
} | ||
|
||
@Override | ||
public String getModContainerClass() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public String getSetupClass() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public void injectData(Map<String, Object> data) {} | ||
|
||
public static String[] getTransformers() { | ||
return new String[] { "com.skcraft.alicefixes.TransformMiningLaser", | ||
/*"com.skcraft.alicefixes.TransformIC2Explosions", | ||
"com.skcraft.alicefixes.TransformTCExcWand", | ||
"com.skcraft.alicefixes.TransformTCEquWand", | ||
"com.skcraft.alicefixes.TransformTCFrostWand", | ||
"com.skcraft.alicefixes.TransformTCAxe", | ||
"com.skcraft.alicefixes.TransformTCShovel"*/}; | ||
} | ||
|
||
} |
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,8 @@ | ||
package com.skcraft.alicefixes; | ||
|
||
public class ObfNames { | ||
|
||
public static final String ENTITY_LIVING = "md"; | ||
public static final String ENTITY = "lq"; | ||
|
||
} |
117 changes: 117 additions & 0 deletions
117
alicefixes/src/com/skcraft/alicefixes/TransformMiningLaser.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,117 @@ | ||
package com.skcraft.alicefixes; | ||
|
||
import static org.objectweb.asm.Opcodes.*; | ||
|
||
import java.lang.reflect.Method; | ||
import java.util.Iterator; | ||
|
||
import org.bukkit.Bukkit; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.event.block.BlockBreakEvent; | ||
import org.objectweb.asm.ClassReader; | ||
import org.objectweb.asm.ClassWriter; | ||
import org.objectweb.asm.tree.ClassNode; | ||
import org.objectweb.asm.tree.FieldInsnNode; | ||
import org.objectweb.asm.tree.InsnList; | ||
import org.objectweb.asm.tree.InsnNode; | ||
import org.objectweb.asm.tree.JumpInsnNode; | ||
import org.objectweb.asm.tree.LabelNode; | ||
import org.objectweb.asm.tree.MethodInsnNode; | ||
import org.objectweb.asm.tree.MethodNode; | ||
import org.objectweb.asm.tree.VarInsnNode; | ||
|
||
import net.minecraft.entity.Entity; | ||
import net.minecraft.entity.EntityLiving; | ||
import net.minecraft.util.MovingObjectPosition; | ||
import net.minecraft.util.Vec3; | ||
import cpw.mods.fml.relauncher.IClassTransformer; | ||
|
||
public class TransformMiningLaser implements IClassTransformer{ | ||
|
||
private final String LASER_CLASS_NAME = "ic2.core.item.tool.EntityMiningLaser"; | ||
private final String MINE_METHOD_NAME = "canMine"; | ||
|
||
@Override | ||
public byte[] transform(String name, byte[] bytes) { | ||
if(name.equals(LASER_CLASS_NAME)) { | ||
return handleLaserTransform(bytes); | ||
} | ||
return bytes; | ||
} | ||
|
||
private byte[] handleLaserTransform(byte[] bytes) { | ||
|
||
ClassNode classNode = new ClassNode(); | ||
ClassReader classReader = new ClassReader(bytes); | ||
classReader.accept(classNode, 0); | ||
|
||
Iterator<MethodNode> methods = classNode.methods.iterator(); | ||
while(methods.hasNext()) { | ||
MethodNode method = methods.next(); | ||
if(method.name.equals(MINE_METHOD_NAME)) { | ||
LabelNode l0 = new LabelNode(); | ||
LabelNode l1 = new LabelNode(); | ||
LabelNode l2 = new LabelNode(); | ||
InsnList toInject = new InsnList(); | ||
toInject.add(l0); | ||
toInject.add(new VarInsnNode(ALOAD, 0)); //"this" | ||
toInject.add(new VarInsnNode(ALOAD, 0)); //"this" | ||
toInject.add(new FieldInsnNode(GETFIELD, "ic2/core/item/tool/EntityMiningLaser", "owner", | ||
"L" + ObfNames.ENTITY_LIVING + ";")); //owner of laser | ||
//invokes canMine() in this class | ||
toInject.add(new MethodInsnNode(INVOKESTATIC, | ||
"com/skcraft/alicefixes/TransformMiningLaser", | ||
"canMine", | ||
"(L" + ObfNames.ENTITY + ";L" + ObfNames.ENTITY_LIVING + ";)Z")); | ||
toInject.add(new JumpInsnNode(IFEQ, l1)); //if statement | ||
toInject.add(l2); | ||
toInject.add(new InsnNode(ICONST_0)); //false | ||
toInject.add(new InsnNode(IRETURN)); //return | ||
toInject.add(l1); | ||
//Insert these instructions at the start of the method's | ||
method.instructions.insertBefore(method.instructions.getFirst(), toInject); | ||
|
||
System.out.println("Mining laser successfully patched!"); | ||
break; | ||
} | ||
} | ||
|
||
ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES); | ||
classNode.accept(writer); | ||
return writer.toByteArray(); | ||
} | ||
|
||
public static boolean canMine(Entity laser, EntityLiving owner) { | ||
Vec3 currentPos = Vec3.createVectorHelper(laser.posX, laser.posY, laser.posZ); | ||
Vec3 heading = Vec3.createVectorHelper(laser.posX + laser.motionX, laser.posY + laser.motionY, laser.posZ + laser.motionZ); | ||
MovingObjectPosition pos = laser.worldObj.rayTraceBlocks_do_do(currentPos, heading, false, true); | ||
|
||
if(pos != null) { | ||
int xPos = pos.blockX; | ||
int yPos = pos.blockY; | ||
int zPos = pos.blockZ; | ||
|
||
try { | ||
Method m = owner.getClass().getDeclaredMethod("getBukkitEntity", new Class[] {}); | ||
org.bukkit.entity.Entity ent = (org.bukkit.entity.Entity)m.invoke(owner); | ||
if ((ent instanceof Player)) { | ||
Player player = (Player)ent; | ||
org.bukkit.World bukkitWorld = player.getWorld(); | ||
BlockBreakEvent breakEv = new BlockBreakEvent(bukkitWorld.getBlockAt(xPos, yPos, zPos), player); | ||
Bukkit.getPluginManager().callEvent(breakEv); | ||
if (breakEv.isCancelled()) { | ||
laser.setDead(); | ||
return false; | ||
} | ||
|
||
breakEv.setCancelled(true); | ||
} | ||
} | ||
catch(Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
} |
Oops, something went wrong.