lillero/README.md

62 lines
3 KiB
Markdown
Raw Normal View History

2023-02-07 18:48:29 +01:00
# Lillero
2023-02-07 12:47:10 +01:00
2023-02-07 18:48:29 +01:00
Lillero is a lightweight and simple ASM patching framework, empowering you to easily modify block game (byte)code, dunking on all the naysayers who said you absolutely had to use Mixin
2023-02-07 12:47:10 +01:00
## How
2023-02-07 18:48:29 +01:00
This library provides the core interface, `IInjector`, as well as a small set of utils to make your life easier. All patches should implement `IInjector` and be declared as [services](https://docs.oracle.com/javase/8/docs/api/java/util/ServiceLoader.html).
The following `IInjector` methods *must* be implemented
2023-02-07 12:47:10 +01:00
Some methods must be implemented, specifying which class and method will be patched:
2023-02-07 18:48:29 +01:00
* `targetClass()`: returns the *fully qualified name* of the class to patch (example: `net.minecraft.client.Minecraft`).
* `methodName()`: returns the "Searge name" of the method to patch.
* `methodDesc()`: returns descriptor (arguments and return type) of method to patch.
* `inject(ClassNode clazz, MethodNode method)`: will be invoked providing you the ClassNode and MethodNode you requested. This is where the actual patching will happen.
There's some more optional methods you *don't have to* implement, but really should because they will make your life considerably easier when it's time to debug:
2023-02-07 12:47:10 +01:00
* `name()` : returns patch name
* `reason()` : returns patch description
2023-02-07 18:48:29 +01:00
Finally, you should mark your classes as service providers, by creating a text file called `ftbsc.lll.IInjector` in `src/main/resources/META-INF/services` on your project. Inside, put the fully qualified names of your patches (example: `ftbsc.bscv.asm.patches.TestPatch$TickPatch`).
If you use Gradle (you do) don't forget to add this library as a dependency in your `build.gradle`:
```groovy
repositories {
maven { url = 'https://maven.fantabos.co' }
}
dependencies {
2023-02-24 16:35:16 +01:00
implementation 'ftbsc:lll:0.2.0'
2023-02-07 18:48:29 +01:00
}
```
2023-02-07 12:47:10 +01:00
2023-02-07 18:54:31 +01:00
**You are going to need a loader to use patches created with this library**. You can use our [loader](https://git.fantabos.co/lillero-loader/) or write your own: as long as it uses `IInjector` as patch interface, it won't break compatibility.
2023-02-07 12:47:10 +01:00
### Example
2023-02-07 18:48:29 +01:00
The following is an example patch, located at `src/main/java/example/patches/SamplePatch.java`:
2023-02-07 12:47:10 +01:00
```java
2023-02-07 12:52:05 +01:00
package example.patches;
import ftbsc.lll.IInjector;
public class SamplePatch implements IInjector {
public String name() { return "SamplePatch"; }
public String targetClass() { return "net.minecraft.client.Minecraft"; }
public String methodName() { return "func_71407_l"; } // tick()
public String methodDesc() { return "()V"; }
public void inject(ClassNode clazz, MethodNode main) {
InsnList insnList = new InsnList();
insnList.add(new InsnNode(POP));
main.instructions.insert(insnList);
}
}
2023-02-07 18:48:29 +01:00
```
The patch will crash the game with a NegativeArraySizeException as soon as it's done loading - so you know it's working.
2023-02-07 12:47:10 +01:00
2023-02-07 18:48:29 +01:00
The following is the service registration file, located at `src/main/resources/META-INF/services/ftbsc.lll.IInjector`:
```
2023-02-07 12:52:05 +01:00
example.patches.SamplePatch
2023-02-07 12:47:10 +01:00
```
2023-02-07 18:48:29 +01:00
2023-02-07 18:51:12 +01:00
Happy patching! And remember...
### "Don't do coremods!"