Improved allowed keybindings implementation. Fixed an exploit where if a key was bound to two different actions it could bypass the detection of it; the method now checks for the key on every possible keybinding.

This commit is contained in:
2021-09-30 21:18:05 +01:00
parent 80eebcf308
commit 872c3475b3

View File

@ -19,48 +19,7 @@ public class OnKeyPressEventHandler {
ServerData server = instance.getCurrentServer(); ServerData server = instance.getCurrentServer();
if (server == null) { return; } if (server == null) { return; }
if (Minecraft.getInstance().screen != null) { return; } if (Minecraft.getInstance().screen != null) { return; }
if (checkKeyAllowed(instance, event.getKey())) { return; }
if (Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.PAUSE) && event.getKey() == GLFW.GLFW_KEY_ESCAPE) { return; }
if (Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.DEBUG) && event.getKey() == GLFW.GLFW_KEY_F3) { return; }
if (Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.FULLSCREEN) && event.getKey() == instance.options.keyFullscreen.getKey().getValue()) { return; }
if (Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.PERSPECTIVE) && event.getKey() == instance.options.keyTogglePerspective.getKey().getValue()) { return; }
if (Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.SMOOTH_CAMERA) && event.getKey() == instance.options.keySmoothCamera.getKey().getValue()) { return; }
if (Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.SCREENSHOT) && event.getKey() == instance.options.keyScreenshot.getKey().getValue()) { return; }
if (Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.SPECTATOR_OUTLINES) && event.getKey() == instance.options.keySpectatorOutlines.getKey().getValue()) { return; }
if (Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.ADVANCEMENTS) && event.getKey() == instance.options.keyAdvancements.getKey().getValue()) { return; }
if (Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.PLAYER_LIST) && event.getKey() == instance.options.keyPlayerList.getKey().getValue()) { return; }
if (Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.CHAT)) {
if (event.getKey() == instance.options.keyChat.getKey().getValue() ||
event.getKey() == instance.options.keyCommand.getKey().getValue() ||
event.getKey() == GLFW.GLFW_KEY_ENTER) {
return;
}
}
if (Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.SOCIAL_INTERACTIONS) && event.getKey() == instance.options.keySocialInteractions.getKey().getValue()) { return; }
if (Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.LOAD_HOTBAR_ACTIVATOR) && event.getKey() == instance.options.keyLoadHotbarActivator.getKey().getValue()) { return; }
if (Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.SAVE_HOTBAR_ACTIVATOR) && event.getKey() == instance.options.keySaveHotbarActivator.getKey().getValue()) { return; }
if (Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.SWAP_ITEM) && event.getKey() == instance.options.keySwapOffhand.getKey().getValue()) { return; }
if (Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.INVENTORY) && event.getKey() == instance.options.keyInventory.getKey().getValue()) { return; }
if (Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.HOTBAR)) {
for (int i = 0; i < instance.options.keyHotbarSlots.length; i++) {
if (event.getKey() == instance.options.keyHotbarSlots[i].getKey().getValue()) { return; }
}
}
if (Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.DROP_ITEM) && event.getKey() == instance.options.keyDrop.getKey().getValue()) { return; }
if (Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.USE_ITEM) && event.getKey() == instance.options.keyUse.getKey().getValue()) { return; }
if (Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.PICK_BLOCK) && event.getKey() == instance.options.keyPickItem.getKey().getValue()) { return; }
if (Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.ATTACK) && event.getKey() == instance.options.keyAttack.getKey().getValue()) { return; }
if (Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.MOVE)) {
if (event.getKey() == instance.options.keyUp.getKey().getValue() ||
event.getKey() == instance.options.keyRight.getKey().getValue() ||
event.getKey() == instance.options.keyDown.getKey().getValue() ||
event.getKey() == instance.options.keyLeft.getKey().getValue() ||
event.getKey() == instance.options.keySprint.getKey().getValue()) {
return;
}
}
if (Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.SNEAK) && event.getKey() == instance.options.keyShift.getKey().getValue()) { return; }
if (Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.JUMP) && event.getKey() == instance.options.keyJump.getKey().getValue()) { return; }
try { try {
LoginProtection.INSTANCE.sendToServer(new C2SKeyPress()); LoginProtection.INSTANCE.sendToServer(new C2SKeyPress());
@ -74,51 +33,54 @@ public class OnKeyPressEventHandler {
ServerData server = instance.getCurrentServer(); ServerData server = instance.getCurrentServer();
if (server == null) { return; } if (server == null) { return; }
if (Minecraft.getInstance().screen != null) { return; } if (Minecraft.getInstance().screen != null) { return; }
if (checkKeyAllowed(instance, event.getKeyBinding().getKey().getValue())) { return; }
if (Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.PAUSE) && event.getKeyBinding().getKey().getValue() == GLFW.GLFW_KEY_ESCAPE) { return; }
if (Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.DEBUG) && event.getKeyBinding().getKey().getValue() == GLFW.GLFW_KEY_F3) { return; }
if (Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.FULLSCREEN) && event.getKeyBinding().getKey().getValue() == instance.options.keyFullscreen.getKey().getValue()) { return; }
if (Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.PERSPECTIVE) && event.getKeyBinding().getKey().getValue() == instance.options.keyTogglePerspective.getKey().getValue()) { return; }
if (Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.SMOOTH_CAMERA) && event.getKeyBinding().getKey().getValue() == instance.options.keySmoothCamera.getKey().getValue()) { return; }
if (Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.SCREENSHOT) && event.getKeyBinding().getKey().getValue() == instance.options.keyScreenshot.getKey().getValue()) { return; }
if (Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.SPECTATOR_OUTLINES) && event.getKeyBinding().getKey().getValue() == instance.options.keySpectatorOutlines.getKey().getValue()) { return; }
if (Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.ADVANCEMENTS) && event.getKeyBinding().getKey().getValue() == instance.options.keyAdvancements.getKey().getValue()) { return; }
if (Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.PLAYER_LIST) && event.getKeyBinding().getKey().getValue() == instance.options.keyPlayerList.getKey().getValue()) { return; }
if (Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.CHAT)) {
if (event.getKeyBinding().getKey().getValue() == instance.options.keyChat.getKey().getValue() ||
event.getKeyBinding().getKey().getValue() == instance.options.keyCommand.getKey().getValue() ||
event.getKeyBinding().getKey().getValue() == GLFW.GLFW_KEY_ENTER) {
return;
}
}
if (Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.SOCIAL_INTERACTIONS) && event.getKeyBinding().getKey().getValue() == instance.options.keySocialInteractions.getKey().getValue()) { return; }
if (Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.LOAD_HOTBAR_ACTIVATOR) && event.getKeyBinding().getKey().getValue() == instance.options.keyLoadHotbarActivator.getKey().getValue()) { return; }
if (Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.SAVE_HOTBAR_ACTIVATOR) && event.getKeyBinding().getKey().getValue() == instance.options.keySaveHotbarActivator.getKey().getValue()) { return; }
if (Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.SWAP_ITEM) && event.getKeyBinding().getKey().getValue() == instance.options.keySwapOffhand.getKey().getValue()) { return; }
if (Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.INVENTORY) && event.getKeyBinding().getKey().getValue() == instance.options.keyInventory.getKey().getValue()) { return; }
if (Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.HOTBAR)) {
for (int i = 0; i < instance.options.keyHotbarSlots.length; i++) {
if (event.getKeyBinding().getKey().getValue() == instance.options.keyHotbarSlots[i].getKey().getValue()) { return; }
}
}
if (Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.DROP_ITEM) && event.getKeyBinding().getKey().getValue() == instance.options.keyDrop.getKey().getValue()) { return; }
if (Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.USE_ITEM) && event.getKeyBinding().getKey().getValue() == instance.options.keyUse.getKey().getValue()) { return; }
if (Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.PICK_BLOCK) && event.getKeyBinding().getKey().getValue() == instance.options.keyPickItem.getKey().getValue()) { return; }
if (Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.ATTACK) && event.getKeyBinding().getKey().getValue() == instance.options.keyAttack.getKey().getValue()) { return; }
if (Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.MOVE)) {
if (event.getKeyBinding().getKey().getValue() == instance.options.keyUp.getKey().getValue() ||
event.getKeyBinding().getKey().getValue() == instance.options.keyRight.getKey().getValue() ||
event.getKeyBinding().getKey().getValue() == instance.options.keyDown.getKey().getValue() ||
event.getKeyBinding().getKey().getValue() == instance.options.keyLeft.getKey().getValue() ||
event.getKeyBinding().getKey().getValue() == instance.options.keySprint.getKey().getValue()) {
return;
}
}
if (Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.SNEAK) && event.getKeyBinding().getKey().getValue() == instance.options.keyShift.getKey().getValue()) { return; }
if (Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.JUMP) && event.getKeyBinding().getKey().getValue() == instance.options.keyJump.getKey().getValue()) { return; }
try { try {
LoginProtection.INSTANCE.sendToServer(new C2SKeyPress()); LoginProtection.INSTANCE.sendToServer(new C2SKeyPress());
} catch (NullPointerException ignored) { } } catch (NullPointerException ignored) { }
} }
@OnlyIn(Dist.CLIENT)
private static boolean checkKeyAllowed(Minecraft instance, int key) {
boolean isAllowed = false;
if (key == GLFW.GLFW_KEY_ESCAPE) { isAllowed = Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.PAUSE); }
if (key == GLFW.GLFW_KEY_F3) { isAllowed = Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.DEBUG); }
if (key == instance.options.keyFullscreen.getKey().getValue()) { isAllowed = Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.FULLSCREEN); }
if (key == instance.options.keyTogglePerspective.getKey().getValue()) { isAllowed = Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.PERSPECTIVE); }
if (key == instance.options.keySmoothCamera.getKey().getValue()) { isAllowed = Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.SMOOTH_CAMERA); }
if (key == instance.options.keyScreenshot.getKey().getValue()) { isAllowed = Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.SCREENSHOT); }
if (key == instance.options.keySpectatorOutlines.getKey().getValue()) { isAllowed = Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.SPECTATOR_OUTLINES); }
if (key == instance.options.keyAdvancements.getKey().getValue()) { isAllowed = Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.ADVANCEMENTS); }
if (key == instance.options.keyPlayerList.getKey().getValue()) { isAllowed = Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.PLAYER_LIST); }
if (key == instance.options.keyChat.getKey().getValue() ||
key == instance.options.keyCommand.getKey().getValue() ||
key == GLFW.GLFW_KEY_ENTER) {
isAllowed = Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.CHAT);
}
if (key == instance.options.keySocialInteractions.getKey().getValue()) { isAllowed = Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.SOCIAL_INTERACTIONS); }
if (key == instance.options.keyLoadHotbarActivator.getKey().getValue()) { isAllowed = Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.LOAD_HOTBAR_ACTIVATOR); }
if (key == instance.options.keySaveHotbarActivator.getKey().getValue()) { isAllowed = Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.SAVE_HOTBAR_ACTIVATOR); }
if (key == instance.options.keySwapOffhand.getKey().getValue()) { isAllowed = Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.SWAP_ITEM); }
if (key == instance.options.keyInventory.getKey().getValue()) { isAllowed = Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.INVENTORY); }
for (int i = 0; i < instance.options.keyHotbarSlots.length; i++) {
if (key == instance.options.keyHotbarSlots[i].getKey().getValue()) { isAllowed = Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.HOTBAR); }
}
if (key == instance.options.keyDrop.getKey().getValue()) { isAllowed = Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.DROP_ITEM); }
if (key == instance.options.keyUse.getKey().getValue()) { isAllowed = Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.USE_ITEM); }
if (key == instance.options.keyPickItem.getKey().getValue()) { isAllowed = Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.PICK_BLOCK); }
if (key == instance.options.keyAttack.getKey().getValue()) { isAllowed = Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.ATTACK); }
if (key == instance.options.keyUp.getKey().getValue() ||
key == instance.options.keyRight.getKey().getValue() ||
key == instance.options.keyDown.getKey().getValue() ||
key == instance.options.keyLeft.getKey().getValue() ||
key == instance.options.keySprint.getKey().getValue()) {
isAllowed = Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.MOVE);
}
if (key == instance.options.keyShift.getKey().getValue()) { isAllowed = Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.SNEAK); }
if (key == instance.options.keyJump.getKey().getValue()) { isAllowed = Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.JUMP); }
return isAllowed;
}
} }