Giter Club home page Giter Club logo

minecraftinjectionapi's Introduction

MinecraftInjectionAPI

Build Github All Releases GitHub release Twitter Follow

A simple API using MCP deobfuscation mappings helping you to inject mods at runtime.

With this library you can inject code into Minecraft at runtime! You can write a program, that does so after Minecraft (Vanilla) was already started, but you could also use it to hook into minecraft methods from any other context (e.g. Labymod / 5zigMod addons, Forge, Liteloader). To deal with an obfuscated minecraft environment the library includes a reflection wrapper that automatically downloads MCP deobfuscation mapping and gives you reflective access to minecraft classes by using their corresponding MCP names.

Maven:

<repositories>
  <repository>
    <id>jitpack.io</id>
    <url>https://jitpack.io</url>
  </repository>
</repositories>
<dependency>
  <groupId>com.github.Zortax</groupId>
  <artifactId>MinecraftInjectionAPI</artifactId>
  <version>v1.0</version>
</dependency>

Gradle:

allprojects {
  repositories {
    ...
    maven { url 'https://jitpack.io' }
  }
}
dependencies {
    implementation 'com.github.Zortax:MinecraftInjectionAPI:v1.0'
}

Here is an example class that should explain what the MinecraftInjectionAPI is doing:

package de.zortax.injection.example.transformer;

import de.zortax.injection.injector.Flags;
import de.zortax.injection.injector.FunctionHook;
import de.zortax.injection.injector.McAgent;
import de.zortax.injection.injector.RuntimeInjector;

public class MinecraftTransformer {

    public static void main(String[] args) {
        // Turn on console output
        Flags.verbose = true;
        // Concatenate the arguments to pass them to the agent
        StringBuilder sb = new StringBuilder();
        for (String arg : args)
            sb.append(arg).append(";");
        // male the agemt execute out onAgentLoaded() method after it os done loading
        sb.append("--load-hook-class;de.zortax.injection.example.transformer.MinecraftTransformer;--load-hook-method;onAgentLoaded");
        // attach the agent to the minecraft VM
        RuntimeInjector.attachToVm(sb.toString());

    }

    // this method will be called automatically as we told the McAgent to do so via arguments
    public static void onAgentLoaded() {
        // add this class as a transformer to register our function hooks
        McAgent.addTransformer(MinecraftTransformer.class);
        // call restransform() to modify the bytecode of the minecraft classes to activate our hooks
        McAgent.retransform();
    }
    
    // this DOES work in an obfuscated environment
    @FunctionHook(targetClass = "net/minecraft/client/Minecraft", targetMethod = "runTick")
    public static void onTick() {
        // This method is getting called 20 times a second
        System.out.println("Ticked!");
    }

    @FunctionHook(targetClass = "net/minecraft/client/renderer/entity/RendererLivingEntity", targetMethod = "renderName")
    public static void onNameRender() {
        // Don't do this unless you want to shred your minecraft launcher's log output...
        System.out.println("Name rendered!");
    }

}

This class could be compiled into a fat-jar (that includes all dependencies). The already mentioned reflection wrapper is easy to use as well. This is how you can check if minecraft is running on a 64bit JVM by using a method in the Minecraft class:

boolean is64bit = (boolean) McpManager.getWrappedClass("net/minecraft/client/Minecraft")
                                      .callStaticGetter("getMinecraft")
                                      .callGetter("isJava64bit").getObject();

If you are working with forge or an deobfuscated environment, there is no need to use this wrapper. Instead you will need the classes you want to use directly as build dependency (you should not put them into jar as they are already available in the minecraft JVM).

minecraftinjectionapi's People

Contributors

zortax avatar thefeldi avatar belohnung avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.