Skip to content

Commit

Permalink
patch window click crash
Browse files Browse the repository at this point in the history
  • Loading branch information
xGinko committed Nov 7, 2023
1 parent 53ee1c9 commit a311721
Show file tree
Hide file tree
Showing 11 changed files with 225 additions and 28 deletions.
4 changes: 2 additions & 2 deletions AnarchyExploitFixesFolia/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>me.moomoo.anarchyexploitfixes</groupId>
<artifactId>AnarchyExploitFixes</artifactId>
<version>2.5.0</version>
<version>2.5.1</version>
</parent>

<artifactId>Folia</artifactId>
Expand All @@ -32,7 +32,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.5.0</version>
<version>3.5.1</version>
<executions>
<execution>
<phase>package</phase>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import me.moomoo.anarchyexploitfixes.modules.preventions.portals.*;
import me.moomoo.anarchyexploitfixes.modules.preventions.withers.*;
import me.moomoo.anarchyexploitfixes.modules.protocollib.boatfly.AntiBoatFlyModule;
import me.moomoo.anarchyexploitfixes.modules.protocollib.windowclick.AntiWindowClickCrash;

import java.util.HashSet;

Expand Down Expand Up @@ -225,6 +226,7 @@ static void reloadModules() {
boolean protocolLibIsInstalled = unregisterPacketListeners(AnarchyExploitFixes.getInstance());

modules.add(new AntiBoatFlyModule());
modules.add(new AntiWindowClickCrash());

if (!AnarchyExploitFixes.getConfiguration().protocolLib_IsDisabled && !protocolLibIsInstalled) {
AnarchyExploitFixes.getLog().severe("Could not find ProtocolLib. Some packet exploits cannot be patched without it.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@

public class AntiBoatFlyModule implements AnarchyExploitFixesModule {

private final Config config;
private final int maxEntityPacketsPer10s;
private final boolean logIsEnabled, shouldKickPlayer;

public AntiBoatFlyModule() {
this.config = AnarchyExploitFixes.getConfiguration();
Config config = AnarchyExploitFixes.getConfiguration();
config.addComment("patches.boatfly-patch.enable", "Patches Futureclient / Rusherhack boat fly exploit.");
this.logIsEnabled = config.getBoolean("patches.boatfly-patch.log", true);
this.maxEntityPacketsPer10s = config.getInt("patches.boatfly-patch.max-entity-packets-per-10s", 15);
Expand Down Expand Up @@ -43,6 +42,7 @@ public void disable() {

@Override
public boolean shouldEnable() {
Config config = AnarchyExploitFixes.getConfiguration();
if (config.getBoolean("patches.boatfly-patch.enable", true)) {
if (config.protocolLib_IsDisabled) {
LogUtils.moduleLog(Level.WARNING, name(), "Not patching exploit because you disabled ProtocolLib in config!");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package me.moomoo.anarchyexploitfixes.modules.protocollib.boatfly;

import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLib;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.ListenerPriority;
import com.comphenix.protocol.events.PacketAdapter;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package me.moomoo.anarchyexploitfixes.modules.protocollib.windowclick;

import me.moomoo.anarchyexploitfixes.AnarchyExploitFixes;
import me.moomoo.anarchyexploitfixes.config.Config;
import me.moomoo.anarchyexploitfixes.modules.AnarchyExploitFixesModule;
import me.moomoo.anarchyexploitfixes.utils.LogUtils;

import java.util.logging.Level;

public class AntiWindowClickCrash implements AnarchyExploitFixesModule {


public AntiWindowClickCrash() {
Config config = AnarchyExploitFixes.getConfiguration();
config.addComment("patches.window-click-crash-patch.enable", "Patches Container click / Window click crash exploit.");
}

@Override
public String name() {
return "window-click-crash-patch";
}

@Override
public String category() {
return "patches";
}

@Override
public void enable() {
new WindowClickListener().register();
}

@Override
public boolean shouldEnable() {
Config config = AnarchyExploitFixes.getConfiguration();
if (config.getBoolean("patches.window-click-crash-patch.enable", true)) {
if (config.protocolLib_IsDisabled) {
LogUtils.moduleLog(Level.WARNING, name(), "Not patching exploit because you disabled ProtocolLib in config!");
return false;
}
if (!AnarchyExploitFixes.isProtocolLibInstalled()) {
LogUtils.moduleLog(Level.SEVERE, name(), "Unable to patch exploit because ProtocolLib is not installed!");
return false;
}
return true;
}
return false;
}

@Override
public void disable() {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package me.moomoo.anarchyexploitfixes.modules.protocollib.windowclick;

import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.ListenerPriority;
import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.reflect.StructureModifier;
import me.moomoo.anarchyexploitfixes.AnarchyExploitFixes;

public class WindowClickListener extends PacketAdapter {

public WindowClickListener() {
super(AnarchyExploitFixes.getInstance(), ListenerPriority.HIGHEST, PacketType.Play.Client.WINDOW_CLICK);
}

protected void register() {
ProtocolLibrary.getProtocolManager().addPacketListener(this);
}

@Override
public void onPacketReceiving(PacketEvent event) {
final StructureModifier<Integer> integers = event.getPacket().getIntegers();
if (getButton(integers) < 0 || getSlot(integers) < 0) {
event.setCancelled(true);
}
}

private int getSyncId(StructureModifier<Integer> packet) {
return packet.read(0);
}

private int getRevision(StructureModifier<Integer> packet) {
return packet.read(1);
}

private int getSlot(StructureModifier<Integer> packet) {
return packet.read(2);
}

private int getButton(StructureModifier<Integer> packet) {
return packet.read(3);
}
}
4 changes: 2 additions & 2 deletions AnarchyExploitFixesLegacy/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>me.moomoo.anarchyexploitfixes</groupId>
<artifactId>AnarchyExploitFixes</artifactId>
<version>2.5.0</version>
<version>2.5.1</version>
</parent>

<artifactId>Legacy</artifactId>
Expand All @@ -32,7 +32,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.5.0</version>
<version>3.5.1</version>
<executions>
<execution>
<phase>package</phase>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import me.moomoo.anarchyexploitfixes.modules.protocollib.craftrecipe.CraftRecipeCooldownModule;
import me.moomoo.anarchyexploitfixes.modules.protocollib.nocom.NoComModule;
import me.moomoo.anarchyexploitfixes.modules.protocollib.packetfly.AntiPacketFlyModule;
import me.moomoo.anarchyexploitfixes.modules.protocollib.windowclick.AntiWindowClickCrash;
import org.bukkit.event.HandlerList;

import java.util.HashSet;
Expand Down Expand Up @@ -245,6 +246,7 @@ static void reloadModules() {
modules.add(new AntiBoatFlyModule());
modules.add(new AntiPacketFlyModule());
modules.add(new CraftRecipeCooldownModule());
modules.add(new AntiWindowClickCrash());

if (!AnarchyExploitFixes.getConfiguration().protocolLib_IsDisabled && !protocolLibIsInstalled) {
AnarchyExploitFixes.getLog().severe("Could not find ProtocolLib. Many gamebreaking exploits cannot be patched without it.");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package me.moomoo.anarchyexploitfixes.modules.protocollib.windowclick;

import me.moomoo.anarchyexploitfixes.AnarchyExploitFixes;
import me.moomoo.anarchyexploitfixes.config.Config;
import me.moomoo.anarchyexploitfixes.modules.AnarchyExploitFixesModule;
import me.moomoo.anarchyexploitfixes.utils.LogUtils;

import java.util.logging.Level;

public class AntiWindowClickCrash implements AnarchyExploitFixesModule {


public AntiWindowClickCrash() {
Config config = AnarchyExploitFixes.getConfiguration();
config.addComment("patches.window-click-crash-patch.enable", "Patches Container click / Window click crash exploit.");
}

@Override
public String name() {
return "window-click-crash-patch";
}

@Override
public String category() {
return "patches";
}

@Override
public void enable() {
new WindowClickListener().register();
}

@Override
public boolean shouldEnable() {
Config config = AnarchyExploitFixes.getConfiguration();
if (config.getBoolean("patches.window-click-crash-patch.enable", true)) {
if (config.protocolLib_IsDisabled) {
LogUtils.moduleLog(Level.WARNING, name(), "Not patching exploit because you disabled ProtocolLib in config!");
return false;
}
if (!AnarchyExploitFixes.isProtocolLibInstalled()) {
LogUtils.moduleLog(Level.SEVERE, name(), "Unable to patch exploit because ProtocolLib is not installed!");
return false;
}
return true;
}
return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package me.moomoo.anarchyexploitfixes.modules.protocollib.windowclick;

import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.ListenerPriority;
import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.reflect.StructureModifier;
import me.moomoo.anarchyexploitfixes.AnarchyExploitFixes;

public class WindowClickListener extends PacketAdapter {

public WindowClickListener() {
super(AnarchyExploitFixes.getInstance(), ListenerPriority.HIGHEST, PacketType.Play.Client.WINDOW_CLICK);
}

protected void register() {
ProtocolLibrary.getProtocolManager().addPacketListener(this);
}

@Override
public void onPacketReceiving(PacketEvent event) {
final StructureModifier<Integer> integers = event.getPacket().getIntegers();
if (getButton(integers) < 0 || getSlot(integers) < 0) {
event.setCancelled(true);
}
}

private int getSyncId(StructureModifier<Integer> packet) {
return packet.read(0);
}

private int getRevision(StructureModifier<Integer> packet) {
return packet.read(1);
}

private int getSlot(StructureModifier<Integer> packet) {
return packet.read(2);
}

private int getButton(StructureModifier<Integer> packet) {
return packet.read(3);
}
}
47 changes: 25 additions & 22 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>me.moomoo.anarchyexploitfixes</groupId>
<artifactId>AnarchyExploitFixes</artifactId>
<version>2.5.0</version>
<version>2.5.1</version>
<modules>
<module>AnarchyExploitFixesFolia</module>
<module>AnarchyExploitFixesLegacy</module>
Expand Down Expand Up @@ -35,7 +35,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.5.0</version>
<version>3.5.1</version>
<executions>
<execution>
<phase>package</phase>
Expand Down Expand Up @@ -107,29 +107,24 @@
</repositories>

<dependencies>
<!-- ConfigurationMaster for enhanced config management -->
<dependency>
<groupId>com.github.thatsmusic99</groupId>
<artifactId>ConfigurationMaster-API</artifactId>
<version>v2.0.0-rc.1</version>
<scope>compile</scope>
</dependency>
<!-- Command Framework -->
<dependency>
<groupId>cloud.commandframework</groupId>
<artifactId>cloud-paper</artifactId>
<version>1.8.4</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>cloud.commandframework</groupId>
<artifactId>cloud-annotations</artifactId>
<version>1.8.4</version>
</dependency>
<!-- Bukkit bStats -->
<dependency>
<groupId>org.bstats</groupId>
<artifactId>bstats-bukkit</artifactId>
<version>3.0.2</version>
<scope>compile</scope>
</dependency>
<!-- Useful Paper related tools -->
<dependency>
<groupId>io.papermc</groupId>
<artifactId>paperlib</artifactId>
<version>1.0.8</version>
<scope>compile</scope>
</dependency>
<!-- ProtocolLib to patch packet based exploits -->
Expand All @@ -143,13 +138,21 @@
<dependency>
<groupId>de.tr7zw</groupId>
<artifactId>item-nbt-api</artifactId>
<version>2.12.0</version>
<version>2.12.1</version>
<scope>compile</scope>
</dependency>
<!-- ConfigurationMaster for enhanced config.yml management -->
<!-- Useful Paper related tools -->
<dependency>
<groupId>com.github.thatsmusic99</groupId>
<artifactId>ConfigurationMaster-API</artifactId>
<version>v2.0.0-rc.1</version>
<groupId>io.papermc</groupId>
<artifactId>paperlib</artifactId>
<version>1.0.8</version>
<scope>compile</scope>
</dependency>
<!-- Bukkit bStats -->
<dependency>
<groupId>org.bstats</groupId>
<artifactId>bstats-bukkit</artifactId>
<version>3.0.2</version>
<scope>compile</scope>
</dependency>
<!-- FastMath -->
Expand All @@ -163,14 +166,14 @@
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>1.10.0</version>
<version>1.11.0</version>
<scope>compile</scope>
</dependency>
<!-- Rule based number format used in first join messages to format to ordinal based on locale -->
<dependency>
<groupId>com.ibm.icu</groupId>
<artifactId>icu4j</artifactId>
<version>73.2</version>
<version>74.1</version>
<scope>compile</scope>
</dependency>
</dependencies>
Expand Down

0 comments on commit a311721

Please sign in to comment.