Jump to content

Recommended Posts

Posted

Hello!

I try to modify 2 functions: getSkinUrl and getCapeUrl with ASM in order to create my own skin system. In this way i can do event in my server. Tank's to this code I have managed to delete the content of function and i have add a invocation to a static method. But I want return the result and I don't know how do this!

 

package pickandcraftSkin;

 

import static org.objectweb.asm.Opcodes.ALOAD;

import static org.objectweb.asm.Opcodes.INVOKESTATIC;

 

import java.util.Iterator;

 

import org.objectweb.asm.ClassReader;

import org.objectweb.asm.ClassWriter;

import org.objectweb.asm.tree.AbstractInsnNode;

import org.objectweb.asm.tree.ClassNode;

import org.objectweb.asm.tree.InsnList;

import org.objectweb.asm.tree.MethodInsnNode;

import org.objectweb.asm.tree.MethodNode;

import org.objectweb.asm.tree.VarInsnNode;

 

 

 

 

public class EDClassTransformer implements net.minecraft.launchwrapper.IClassTransformer {

 

@Override

public byte[] transform(String arg0, String arg1, byte[] arg2) {

 

if (arg0.equals("beu")) {

System.out.println("********* INSIDE OBFUSCATED AbstractClientPlayer TRANSFORMER ABOUT TO PATCH: " + arg0);

return patchClassASM(arg0, arg2, true);

        }

 

if (arg0.equals("net.minecraft.client.entity.AbstractClientPlayer")) {

System.out.println("********* INSIDE AbstractClientPlayer TRANSFORMER ABOUT TO PATCH: " + arg0);

return patchClassASM(arg0, arg2, false);

        }

        return arg2;

}

 

public byte[] patchClassASM(String name, byte[] bytes, boolean obfuscated) {

 

String targetMethodName = "";

       

        if(obfuscated == true)

        targetMethodName ="d";

        else

        targetMethodName ="getSkinUrl";

       

 

      //set up ASM class manipulation stuff. Consult the ASM docs for details

    ClassNode classNode = new ClassNode();

        ClassReader classReader = new ClassReader(bytes);

        classReader.accept(classNode, 0);

       

       

     

      //Now we loop over all of the methods declared inside the Explosion class until we get to the targetMethodName "doExplosionB"

 

        // find method to inject into

        @SuppressWarnings("unchecked")

        Iterator<MethodNode> methods = classNode.methods.iterator();

        while(methods.hasNext())

        {

            MethodNode m = methods.next();

            System.out.println("********* Method Name: "+m.name + " Desc:" + m.desc);

 

       

          //Check if this is doExplosionB and it's method signature is (Z)V which means that it accepts a boolean (Z) and returns a void (V)

            if ((m.name.equals(targetMethodName) && m.desc.equals("(Ljava/lang/String;)Ljava/lang/String;")))

            {

                System.out.println("********* Inside target method!");

                //on supprime tous les noeuds

                AbstractInsnNode targetNode = null;

               

                @SuppressWarnings("unchecked")

                Iterator<AbstractInsnNode> iter = m.instructions.iterator();

                int index = -1;

               

                while (iter.hasNext()) {

                    index++;

                    targetNode = iter.next();

                    m.instructions.remove(targetNode);

                }

           

                InsnList toInject = new InsnList();

             

toInject.add(new VarInsnNode(ALOAD, 0));

                    toInject.add(new MethodInsnNode(INVOKESTATIC, "pickandcraftSkin/PlayerCustom", "getURLSkincustom", "(Ljava/lang/String;)Ljava/lang/String;"));

               

                // inject new instruction list into method instruction list

                m.instructions.insert(toInject);

               

                System.out.println("Patching Complete!");

                break;

            }

        }

       

      //ASM specific for cleaning up and returning the final bytes for JVM processing.

        ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);

        classNode.accept(writer);

        return writer.toByteArray();

      }

}

Posted

But where add the return instruction? Before or after  toInject.add(new MethodInsnNode(INVOKESTATIC, "pickandcraftSkin/PlayerCustom", "getURLSkincustom", "(Ljava/lang/String;)Ljava/lang/String;")) ?

And how add the return instruction? I can't do this: toInject.add("ARETURN")!

 

 

Sorry for my english: I'm french and I don't speak very well english :)

Posted

It should be safe to completely replace the instruction list of the method. It would be more efficient, and cleaner.

 

As for what to put in the new instruction list, here's what you need to do:

               if ((m.name.equals(targetMethodName) && m.desc.equals("(Ljava/lang/String;)Ljava/lang/String;")))
               {
                   System.out.println("********* Inside target method!");
                   InsnList toInject = new InsnList();
                     
                   toInject.add(new VarInsnNode(ALOAD, 0));
                   toInject.add(new MethodInsnNode(INVOKESTATIC, "pickandcraftSkin/PlayerCustom", "getURLSkincustom", "(Ljava/lang/String;)Ljava/lang/String;"));
                   toInject.add(new InsnNode(ARETURN));
                
                   // inject new instruction list into method instruction list
                   m.instructions = toInject;
                   
                   System.out.println("Patching Complete!");
                   break;
               }

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Yes that’s the full log, I managed to get it working last night, the anvil fix mod is what was causing it to crash
    • Hey guys, i'm currently developping a mod with forge 1.12.2 2860 and i'm using optifine and gradle 4.9. The thing is i'm trying to figure out how to show the player's body in first person. So far everything's going well since i've try to use a shader. The player's body started to blink dark when using a shader. I've try a lot of shader like chocapic, zeus etc etc but still the same issue. So my question is : How should i apply the current shader to the body ? At the same time i'm also drawing a HUD so maybe it could be the problem?   Here is the issue :    And here is the code where i'm trying to display the body :    private static void renderFirstPersonBody(EntityPlayerSP player, float partialTicks) { Minecraft mc = Minecraft.getMinecraft(); GlStateManager.pushMatrix(); GlStateManager.pushAttrib(); try { // Préparation OpenGL GlStateManager.enableDepth(); GlStateManager.depthMask(true); GlStateManager.enableAlpha(); GlStateManager.alphaFunc(GL11.GL_GREATER, 0.1F); GlStateManager.enableBlend(); GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); // Éclairage correct pour shaders GlStateManager.enableLighting(); RenderHelper.enableStandardItemLighting(); GlStateManager.enableRescaleNormal(); // Active la lightmap pour les shaders mc.entityRenderer.enableLightmap(); // Position de rendu interpolée double px = player.lastTickPosX + (player.posX - player.lastTickPosX) * partialTicks; double py = player.lastTickPosY + (player.posY - player.lastTickPosY) * partialTicks; double pz = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * partialTicks; GlStateManager.translate( px - mc.getRenderManager().viewerPosX, py - mc.getRenderManager().viewerPosY, pz - mc.getRenderManager().viewerPosZ ); // Rendu du joueur sans la tête Render<?> render = mc.getRenderManager().getEntityRenderObject(player); if (render instanceof RenderPlayer) { RenderPlayer renderPlayer = (RenderPlayer) render; boolean oldHeadHidden = renderPlayer.getMainModel().bipedHead.isHidden; boolean oldHeadwearHidden = renderPlayer.getMainModel().bipedHeadwear.isHidden; renderPlayer.getMainModel().bipedHead.isHidden = true; renderPlayer.getMainModel().bipedHeadwear.isHidden = true; setArmorHeadVisibility(renderPlayer, false); renderPlayer.doRender(player, 0, 0, 0, player.rotationYaw, partialTicks); renderPlayer.getMainModel().bipedHead.isHidden = oldHeadHidden; renderPlayer.getMainModel().bipedHeadwear.isHidden = oldHeadwearHidden; setArmorHeadVisibility(renderPlayer, !oldHeadwearHidden); } // Nettoyage post rendu mc.entityRenderer.disableLightmap(); GlStateManager.disableRescaleNormal(); } catch (Exception e) { // silent fail } finally { GlStateManager.popAttrib(); GlStateManager.popMatrix(); } }   Ty for your help. 
    • Item successfully registered, but there was a problem with the texture of the item, it did not insert and has just the wrong texture.     
    • Keep on using the original Launcher Run Vanilla 1.12.2 once and close the game Download Optifine and run optifine as installer (click on the optifine jar) Start the launcher and make sure the Optifine profile is selected - then test it again  
    • Hi everyone, I’m hoping to revisit an old version of Minecraft — specifically around Beta 1.7.3 — for nostalgia’s sake. I’ve heard you can do this through the official Minecraft Launcher, but I’m unsure how to do it safely without affecting my current installation or save files. Are there any compatibility issues I should watch out for when switching between versions? Would really appreciate any tips or advice from anyone who’s done this before! – Adam
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.