Skip to content

Commit

Permalink
Embrace paranoia my friend and tape your camera
Browse files Browse the repository at this point in the history
  • Loading branch information
M100K300 committed Jan 29, 2022
1 parent 982ae8e commit 90ae5b4
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 219 deletions.
97 changes: 5 additions & 92 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,95 +1,8 @@
# Lambda Plugin Example
# Anti Chat Exploit plugin for Lambda

This project in an example to show how a proper plugin for [Lambda Client](https://github.com/lambda-client/lambda) is set up.
The advantage of plugins for a utility mod is that they allow the user to decide what features their personalized client will have. Plugins work in plug and play manner, and can be downloaded and activated inside the ingame menu without reloading the client as long as no mixins are used for the plugin.
If you are scared about the Kotlin in this project be aware that Kotlin is a wrapper language for Java. That means that plugins can also be natively written in Java.
Could be also called **paranoia reliever**

## Setup
A very simple plugin to remove all harmful text from the chat.
Saves from exploits such as log4j and its workarounds even if you are playing on do-do server with amin who doesn't care for players and doesn't protect the server.

To achieve coding building and publishing your own plugin most of the following steps are required.

### Fork
This is a template repository and can be used as a base to create a custom plugin. Press the `Use as template` button on GitHub to automatically create a linked fork to this repository.

### Clone Repository

Clone the repository to your local machine. Use the link of either your fork or the main repository.
```
git clone https://github.com/lambda-client/ExamplePlugin
```

### Setup IDE

In this guide we will use [IntelliJ IDEA](https://www.jetbrains.com/idea/) as IDE.
1. Open the project from `File > Open...`
2. Let the IDE collect dependencies and index the code.
3. Goto `File > Project Structure... > SDKs` and make sure an SDK for Java 8 is installed and selected, if not download
it [here](https://adoptopenjdk.net/index.html?variant=openjdk8&jvmVariant=hotspot).
4. Run the `genIntellijRuns` Gradle task, or run `./gradlew genIntellijRuns`.
5. Open with `STRG+left_click` on `PluginModule` in `ExampleModule` to open the decompiled lambda dependency. To see the original source code go in the top right corner you can add `Sources...` and select the `lambda-*-api-source.jar`.

### Configure Gradle

Test if the environment is set up correctly by building the plugin jar using the Gradle tab on the right side of the IDE.
1. Go to `ExamplePlugin > Tasks > build > jar` in the Gradle tab and run the script
2. IntelliJ will create a new directory called `build`. The final built jar will be in `build/libs`

### Config

Configure the metadata of your plugin in `plugin_info.json`.
The flag `main_class` must contain the target main class `Plugin` in this case it is `PluginExample.kt`

### Plugin

The plugin main class will act as a register for the functions a plugin can provide.
For example when a new module class is created you have to add this to the `onLoad()` function of the plugin class.
```
modules.add(ExampleModule)
```
Every service is required to be added to the main class in order to index the contents.

### PluginModule

A module represents a utility module inside the game.
The `PluginModule` class acts as a wrapper for `Module` class. For many examples on how a module can work check out the [native modules](https://github.com/lambda-client/lambda/tree/master/src/main/kotlin/com/lambda/client/module/modules) of lambda, or the given example in this project.
The difference from the native `Module` class is that each component of a plugin requires a reference to the main `Plugin` class.
```
pluginMain = ExamplePlugin
```
Every PluginModule class will need to be registered to the main plugin class

### ClientCommand

Plugins use the same class as the native client for registering commands. Feel free to check out the [commands of Lambda Client](https://github.com/lambda-client/lambda/tree/master/src/main/kotlin/com/lambda/client/command/commands) as a reference.

### PluginLabelHud

A LabelHud is used to display information in the player GUI.
The `PluginLabelHud` class acts as a wrapper for `LabelHud` class. For many examples on how a hud can work check out the [native hud elements](https://github.com/lambda-client/lambda/tree/master/src/main/kotlin/com/lambda/client/gui/hudgui/elements) of lambda, or the given example in this project.
The difference to the native `LabelHud` class is that a referral to the main plugin class is given in the object data.
```
pluginMain = ExamplePlugin
```
Every `PluginLabelHud` class will need to be registered to the main `Plugin` class.

### Background Jobs

If coroutines are needed background jobs can be registered using
```
bgJobs.add(BackgroundJob)
```

### Mixin
Example coming soon. Plugin won't be able to hot reload anymore because mixins need to be triggered on client start.

### Build

1. Go to `ExamplePlugin > Tasks > build > jar` in the Gradle tab and run the script
2. IntelliJ will create a new directory called `build` the final built jar will be in `build/libs`
3. Put the `ExamplePlugin-1.0.jar` into your `./minecraft/lambda/plugins` folder and run the game.

### Publish

Publish your repository in Discord, and we may fork you, or transfer your repository to official
plugin [organization of Lambda](https://github.com/lambda-plugins/). After review, your plugin may get added to the native
marketplace.
![alt text](dumb-meme.jpeg)
Binary file added dumb-meme.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1 +1 @@
rootProject.name = 'ExamplePlugin'
rootProject.name = 'AntiChatExploitPlugin'
59 changes: 59 additions & 0 deletions src/main/kotlin/org/lambda/AntiChatExploit.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package org.lambda

import com.lambda.client.module.Category
import com.lambda.client.plugin.api.PluginModule
import com.lambda.event.listener.listener
import net.minecraftforge.client.event.ClientChatReceivedEvent
import java.util.concurrent.ConcurrentHashMap
import java.util.regex.Pattern

object AntiChatExploit : PluginModule(
name = "AntiChatExploit",
category = Category.CHAT,
description = "Removes malicious patterns from the chat",
pluginMain = AntiChatExploitPlugin
) {

private val filterOwn by setting("Filter Own", false)


private val messageHistory = ConcurrentHashMap<String, Long>()

init {
onDisable {
messageHistory.clear()
}

listener<ClientChatReceivedEvent> { event ->
if (mc.player == null) return@listener

messageHistory.values.removeIf { System.currentTimeMillis() - it > 600000 }

val pattern = isHarmful(event.message.unformattedText)

pattern?.let { event.isCanceled = true }
}
}

private fun isHarmful(message: String): String? {
return if (!filterOwn && isOwn(message)) {
null
} else {
detectHarmfulMessages(message)
}
}

private fun detectHarmfulMessages(message: String): String? {
for (harmfulString in HarmfulFilters.harmfulStrings) {
if (message.contains(harmfulString)) {
return message
}
}
return null
}

private fun isOwn(message: String): Boolean {
val ownFilter = "^<" + mc.player.name + "> "
return Pattern.compile(ownFilter, Pattern.CASE_INSENSITIVE).matcher(message).find()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@ package org.lambda

import com.lambda.client.plugin.api.Plugin

internal object ExamplePlugin: Plugin() {
internal object AntiChatExploitPlugin: Plugin() {

override fun onLoad() {
// Load any modules, commands, or HUD elements here
modules.add(ExampleModule)
commands.add(ExampleCommand)
hudElements.add(ExampleLabelHud)
modules.add(AntiChatExploit)
}

override fun onUnload() {
Expand Down
29 changes: 0 additions & 29 deletions src/main/kotlin/org/lambda/ExampleCommand.kt

This file was deleted.

19 changes: 0 additions & 19 deletions src/main/kotlin/org/lambda/ExampleLabelHud.kt

This file was deleted.

72 changes: 0 additions & 72 deletions src/main/kotlin/org/lambda/ExampleModule.kt

This file was deleted.

6 changes: 6 additions & 0 deletions src/main/kotlin/org/lambda/HarmfulFilters.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.lambda;

object HarmfulFilters {
val harmfulStrings = arrayOf(
"\${")
}
4 changes: 2 additions & 2 deletions src/main/resources/plugin_info.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "ExamplePlugin",
"name": "AntiChatExploitPlugin",
"version": "1.0",
"authors": [
"me",
Expand All @@ -9,6 +9,6 @@
"url": "",
"min_api_version": "3.0",
"required_plugins": [],
"main_class": "ExamplePlugin",
"main_class": "org.lambda.AntiChatExploitPlugin",
"hot_reload": true
}

0 comments on commit 90ae5b4

Please sign in to comment.