Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(legacy): chatcontrol module #4836

Draft
wants to merge 7 commits into
base: legacy
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ object ModuleManager : Listenable, Collection<Module> by MODULE_REGISTRY {
CameraClip,
CameraView,
Chams,
ChatControl,
ChestAura,
ChestStealer,
CivBreak,
Expand All @@ -106,7 +107,6 @@ object ModuleManager : Listenable, Collection<Module> by MODULE_REGISTRY {
FastUse,
FlagCheck,
Fly,
ForceUnicodeChat,
FreeCam,
Freeze,
Fucker,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* LiquidBounce Hacked Client
* A free open source mixin-based injection hacked client for Minecraft using Minecraft Forge.
* https://github.com/CCBlueX/LiquidBounce/
*/
package net.ccbluex.liquidbounce.features.module.modules.misc

import net.ccbluex.liquidbounce.features.module.Category
import net.ccbluex.liquidbounce.features.module.Module

object ChatControl : Module("ChatControl", Category.MISC, gameDetecting = false) {

val noChatClear by boolean("NoChatClear", true)
// TODO: Add StackMessage Counter (Done)
// TODO: Combined duplicated messages (On-Progress)
val stackMessage by boolean("StackMessage", true)
val noLengthLimit by boolean("NoLengthLimit", true)
val forceUnicodeChat by boolean("ForceUnicodeChat", false)

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,32 @@
*/
package net.ccbluex.liquidbounce.injection.forge.mixins.gui;

import net.ccbluex.liquidbounce.features.module.modules.misc.ChatControl;
import net.ccbluex.liquidbounce.features.module.modules.render.HUD;
import net.ccbluex.liquidbounce.ui.font.Fonts;
import net.minecraft.client.gui.ChatLine;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.GuiNewChat;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.IChatComponent;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static net.ccbluex.liquidbounce.utils.client.MinecraftInstance.mc;

@Mixin(GuiNewChat.class)
public abstract class MixinGuiNewChat {

private final Map<String, Integer> messageCounts = new HashMap<>();

@Redirect(method = {"getChatComponent", "drawChat"}, at = @At(value = "FIELD", target = "Lnet/minecraft/client/gui/FontRenderer;FONT_HEIGHT:I"))
private int injectFontChat(FontRenderer instance) {
return HUD.INSTANCE.shouldModifyChatFont() ? Fonts.font40.getHeight() : instance.FONT_HEIGHT;
Expand All @@ -30,4 +45,48 @@ private int injectFontChatB(FontRenderer instance, String text, float x, float y
private int injectFontChatC(FontRenderer instance, String text) {
return HUD.INSTANCE.shouldModifyChatFont() ? Fonts.font40.getStringWidth(text) : instance.getStringWidth(text);
}

@Inject(method = "printChatMessage", at = @At("HEAD"), cancellable = true)
public void onPrintChatMessage(IChatComponent chatComponent, CallbackInfo ci) {
String rawMessage = chatComponent.getFormattedText(); //.getUnformattedText().trim();
String messageId = String.valueOf(rawMessage.hashCode());

if (ChatControl.INSTANCE.handleEvents() && ChatControl.INSTANCE.getStackMessage()) {
int count = messageCounts.getOrDefault(messageId, 0) + 1;
messageCounts.put(messageId, count);

if (count > 1) {
String modifiedMessage = rawMessage + " " + EnumChatFormatting.GRAY + "[" + count + "x]";
ChatComponentText stackedComponent = new ChatComponentText(modifiedMessage);

ci.cancel();
mc.ingameGUI.getChatGUI().printChatMessage(stackedComponent);
}

if (messageCounts.size() > 100) {
String firstKey = messageCounts.keySet().iterator().next();
messageCounts.remove(firstKey);
}
}
}

@Redirect(method = "setChatLine", at = @At(value = "INVOKE", target = "Ljava/util/List;size()I", ordinal = 0))
private int hookNoLengthLimit(List<ChatLine> list) {
final ChatControl chatControl = ChatControl.INSTANCE;

if (chatControl.handleEvents() && chatControl.getNoLengthLimit()) {
return -1;
}

return list.size();
}

@Inject(method = "clearChatMessages", at = @At("HEAD"), cancellable = true)
private void hookChatClear(CallbackInfo ci) {
final ChatControl chatControl = ChatControl.INSTANCE;

if (chatControl.handleEvents() && chatControl.getNoChatClear()) {
ci.cancel();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* LiquidBounce Hacked Client
* A free open source mixin-based injection hacked client for Minecraft using Minecraft Forge.
* https://github.com/CCBlueX/LiquidBounce/
*/
package net.ccbluex.liquidbounce.injection.forge.mixins.packets;

import net.ccbluex.liquidbounce.features.module.modules.misc.ChatControl;
import net.minecraft.network.play.client.C01PacketChatMessage;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(C01PacketChatMessage.class)
public class MixinC01PacketChatMessage {

@Shadow
public String message;

@Inject(method = "<init>(Ljava/lang/String;)V", at = @At("RETURN"), cancellable = true)
public void injectForceUnicodeChat(String p_i45240_1_, CallbackInfo ci) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Searge be like:
❌ map the parameter names
✔️ leave it there, happens 99.99% of the time.

if (ChatControl.INSTANCE.handleEvents() && ChatControl.INSTANCE.getForceUnicodeChat()) {
if (p_i45240_1_.startsWith("/")) {
return;
}

StringBuilder stringBuilder = new StringBuilder();

for (char c : p_i45240_1_.toCharArray()) {
if (c >= 33 && c <= 128) {
stringBuilder.append(Character.toChars(c + 65248));
} else {
stringBuilder.append(c);
}
}

this.message = stringBuilder.toString();
}

ci.cancel();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,6 @@

"module.fly.description": "Позволява ви да летите в режим на оцеляване.",

"module.forceUnicodeChat.description": "Позволява ви да изпращате съобщения на Unicode в чата.",

"module.freeCam.description": "Позволява ви да се преместите от тялото си.",

"module.freeLook.description": "UNTRANSLATED: Allows you to see around in third person view.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@
"module.cameraView.description": "Allows you to modify your camera-Y position.",

"module.chams.description": "Allows you to see targets through blocks.",

"module.chatControl.description": "Allows you to control chat messages.",

"module.chestAura.description": "Automatically opens chests around you.",

Expand Down Expand Up @@ -200,8 +202,6 @@

"module.fly.description": "Allows you to fly in survival mode.",

"module.forceUnicodeChat.description": "Allows you to send unicode messages in chat.",

"module.freeCam.description": "Allows you to move out of your body.",

"module.freeLook.description": "Allows you to see around in third person view.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,6 @@

"module.fly.description": "Permite que você voe no modo de sobrevivência.",

"module.forceUnicodeChat.description": "Permite que você envie mensagens unicode no chat.",

"module.freeCam.description": "Permite que você saia do seu corpo.",

"module.freeLook.description": "UNTRANSLATED: Allows you to see around in third person view.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,6 @@

"module.fly.description": "UNTRANSLATED: Allows you to fly in survival mode.",

"module.forceUnicodeChat.description": "UNTRANSLATED: Allows you to send unicode messages in chat.",

"module.freeCam.description": "Permite que tu mexas enquanto fora do teu corpo.",

"module.freeLook.description": "UNTRANSLATED: Allows you to see around in third person view.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,6 @@

"module.fly.description": "Позволяет летать.",

"module.forceUnicodeChat.description": "Позволяет отправлять в чат сообщения в юникоде.",

"module.freeCam.description": "Свободная летающая камера.",

"module.freeLook.description": "UNTRANSLATED: Allows you to see around in third person view.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,6 @@
"module.flagCheck.description": "检测您是否被反作弊标记。",

"module.fly.description": "允许你在生存模式下飞行。",

"module.forceUnicodeChat.description": "允许你在聊天栏中发送unicode消息。",

"module.freeCam.description": "允许你离开身体。(灵魂出窍)",

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,6 @@
"module.flagCheck.description": "偵測您是否被反作弊標記。",

"module.fly.description": "允許你在生存模式下飛行。",

"module.forceUnicodeChat.description": "允許你在聊天欄中發送unicode訊息。",

"module.freeCam.description": "允許你離開身體。(靈魂出竅)",

Expand Down
1 change: 1 addition & 0 deletions src/main/resources/liquidbounce.forge.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
"gui.MixinGuiAchievement",
"gui.MixinGuiContainer",
"gui.MixinGuiTextField",
"packets.MixinC01PacketChatMessage",
"render.MixinItemRenderer",
"render.MixinRenderGlobal",
"tweaks.MixinEntityFX"
Expand Down
Loading