From 4cc254f8535d74d74cedaafc20b15eb3d425b0e5 Mon Sep 17 00:00:00 2001 From: ZXMushroom63 Date: Sun, 27 Oct 2024 16:36:59 +0800 Subject: [PATCH] better hooking doc --- docs/apidoc/hooks.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/docs/apidoc/hooks.md b/docs/apidoc/hooks.md index 8614a0c..abe02ea 100644 --- a/docs/apidoc/hooks.md +++ b/docs/apidoc/hooks.md @@ -4,6 +4,21 @@ It has quite a few propeties, but most of them are just foundations for more use ### Property: ModAPI.hooks.methods `ModAPI.hooks.methods` is a String-to-method dictionary/object of every java method. This allows you to do pretty much whatever you want in terms of modifying and hooking into code. +It's properties are defined by the package of the java class, as well as that methods name. For example, `net.minecraft.world.World`'s `spawnEntityInWorld` method will be named `ModAPI.hooks.methods.nmw_World_spawnEntityInWorld`, where `nmw` is `net.minecraft.world`. You can automate finding this by using `ModAPI.util.getMethodFromPackage("com.package.abc.MyClass", "myMethod")`, which is an alorithm that automatically finds the key in `ModAPI.hooks.methods`. + +Due to the injector's patches, all game code runs by calling these ModAPI.hooks.methods functions, which allows you to call, patch, replace and modify the game's source code in realtime. + +To call a method, use `ModAPI.hooks.methods[ModAPI.util.getMethodFromPackage("com.package.abc.MyClass", "myMethod")](argument1, argument2, etc);`. + +Complexities with calling methods: +Methods that are described in EaglercraftX's source code as `static` can be called by replacing boolean values `true`/`false` with `1` and `0`, respectively. Strings have to be converted by using `ModAPI.util.str("string")` or one of it's aliases. To pass data from a ModAPI proxy you have to use .getRef(), eg: `ModAPI.player.getRef(); //raw java player object`. + +Non static methods must be called with the object they are running on (the value of the `this` keyword in the java source). Do this by using the object as the first argument. For example, look at this code: + +```javascript +ModAPI.require("world"); +ModAPI.hooks.methods.nmw_World_spawnEntityInWorld(ModAPI.world.getRef(), *an entity object*); +``` - To replace a method with another, you can use: - `ModAPI.hooks.methods[ModAPI.util.getMethodFromPackage("com.package.abc.MyClass", "myMethod")] = function () {}` @@ -19,5 +34,7 @@ It has quite a few propeties, but most of them are just foundations for more use } ``` +Please note that if you are just calling methods, I recommend attempting to call the method directly on the object. `Eg: ModAPI.world.spawnEntityInWorld(*an entity object*)` or using `ModAPI.reflect.getClassByName("MyClass").methods.methodName.method()`; + ### Property: ModAPI.hooks._teavm `ModAPI.hooks._teavm` is usually only used for internal purposes, but it is basically a collection of every internal TeaVM method. Keep in mind that this only stores references (for performance reasons), so modifying and editing it's contents will not affect the way the game runs. \ No newline at end of file