lillero/README.md

69 lines
4.2 KiB
Markdown
Raw Permalink Normal View History

2023-02-07 18:48:29 +01:00
# Lillero
2023-03-04 14:57:53 +01:00
Lillero is a lightweight and simple Java ASM patching framework built on top of [ObjectWeb's ASM library](https://asm.ow2.io/).
2023-02-07 12:47:10 +01:00
## How
2024-06-04 13:54:50 +02:00
This library provides the core interface, `IInjector`, as well as a small set of utils to make your life easier. Your patches should implement `IInjector`.
2023-02-07 18:48:29 +01:00
2023-02-24 17:21:20 +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`).
2023-03-04 12:31:58 +01:00
* `methodName()`: returns the name of the method to patch.
2023-02-07 18:48:29 +01:00
* `methodDesc()`: returns descriptor (arguments and return type) of method to patch.
2023-03-04 12:31:58 +01:00
* `inject(ClassNode, MethodNode)`: will be invoked providing you the ClassNode and MethodNode you requested. This is where the actual patching will happen.
2023-02-07 18:48:29 +01:00
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`).
2024-06-04 13:54:50 +02:00
Add this library into your build system of choice (Gradle is shown, but anything supporting Maven repositories will do):
2023-02-07 18:48:29 +01:00
```groovy
repositories {
maven { url = 'https://maven.fantabos.co' }
}
dependencies {
2023-03-04 12:31:58 +01:00
implementation 'ftbsc:lll:<whatever the latest version is>'
2023-02-07 18:48:29 +01:00
}
```
2023-02-07 12:47:10 +01:00
2023-03-04 12:31:58 +01:00
You are going to need an appropriate loader to use Lillero patches: **this is just a library and does nothing by itself**. You need to make it work by loading services implementing the `IInjector` interface, and by calling their `inject(ClassNode, MethodNode)` methods with the appropriate parameters.
2023-02-07 12:47:10 +01:00
2024-06-04 13:54:50 +02:00
It should also be noted that this library will be required at runtime for your patches to function. You will either have to bundle it using [Shadow](https://github.com/johnrengelman/shadow) or similar, or get this into your runtime classpath by some other means (our [loader](https://github.com/zaaarf/lillero-loader/), for instance, takes care of this for you).
Finally, know that you can spare yourself some trouble, by using this [annotation processor](https://github.com/zaaarf/lillero-processor/) to reduce boilerplate code to a minimum.
2023-03-28 00:22:39 +02:00
2023-03-04 12:31:58 +01:00
#### Tips specific to Minecraft patching
2024-06-04 13:54:50 +02:00
* In "raw" environments, you want to be using Notch (fully obfuscated) names whenever you are told to reference a class or method by name, since those are the ones that exist at runtime.
- Use deobfuscated names if you are running from ForgeGradle's or loom's runClient task.
- If you are using our loader (see below), use intermediary (unreadable but unique) names in every place you are told to use a name - ModLauncher will do the rest.
2024-08-30 14:26:25 +02:00
- If you are loading this through [Fabric-ASM](https://github.com/Chocohead/Fabric-ASM), use intermediary representation.
2024-06-04 13:54:50 +02:00
* Use our [loader](https://github.com/zaaarf/lillero-loader/) that hooks into Forge's ModLauncher if you're writing a modern Forge mod.
2023-03-04 12:31:58 +01:00
* Make sure to dunk on all the naysayers who tried to force you to use Mixin!
#### Example Minecraft patch
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"; }
2023-03-28 00:22:39 +02:00
public String methodName() { return "func_71407_l"; } //Searge name for tick()
public String methodDesc() { return "()V"; } //void, no args
2023-02-07 12:52:05 +01:00
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
```
2023-03-04 14:57:53 +01:00
When loaded into Minecraft, this 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-03-04 15:32:16 +01:00
Happy patching!