Skip to content

Commit

Permalink
Fix classic login input field
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianMichael committed Nov 25, 2023
1 parent f3a86c5 commit 1d45d1a
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
* - Blit-jump is not supported in <= 1.8.9 (https://github.com/ViaVersion/ViaFabricPlus/issues/225)
*
* TODO | Migration v3
* - Fix classic login input field (MixinSharedConstants)
* - Make recipe fixes dynamic instead of a data dump in java classes
* - Make mixin injection methods private
* - Make mixins abstract
Expand All @@ -67,6 +66,7 @@
* - Is de.florianmichael.viafabricplus.injection.mixin.jsonwebtoken.* still needed?
* - Apply MixinAutoRefillHandler_ItemSlotMonitor only when mod is actually installed
* - Make block shapes static
* - Remove information package / system
*/
public class ViaFabricPlus {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus
* Copyright (C) 2021-2023 FlorianMichael/EnZaXD and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.florianmichael.viafabricplus.injection.access;

public interface ITextFieldWidget {

void viaFabricPlus$unlockForbiddenCharacters();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus
* Copyright (C) 2021-2023 FlorianMichael/EnZaXD and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.florianmichael.viafabricplus.injection.mixin.base;

import de.florianmichael.viafabricplus.injection.access.ITextFieldWidget;
import net.minecraft.SharedConstants;
import net.minecraft.client.gui.widget.TextFieldWidget;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

@Mixin(TextFieldWidget.class)
public class MixinTextFieldWidget implements ITextFieldWidget {

@Unique
private boolean viaFabricPlus$forbiddenCharactersUnlocked = false;

@Redirect(method = "charTyped", at = @At(value = "INVOKE", target = "Lnet/minecraft/SharedConstants;isValidChar(C)Z"))
public boolean allowForbiddenCharacters(char c) {
if (this.viaFabricPlus$forbiddenCharactersUnlocked) {
return true;
}
return SharedConstants.isValidChar(c);
}

@Redirect(method = "write", at = @At(value = "INVOKE", target = "Lnet/minecraft/SharedConstants;stripInvalidChars(Ljava/lang/String;)Ljava/lang/String;"))
public String allowForbiddenCharacters(String string) {
if (this.viaFabricPlus$forbiddenCharactersUnlocked) {
return string;
}
return SharedConstants.stripInvalidChars(string);
}

@Override
public void viaFabricPlus$unlockForbiddenCharacters() {
this.viaFabricPlus$forbiddenCharactersUnlocked = true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import de.florianmichael.classic4j.ClassiCubeHandler;
import de.florianmichael.classic4j.api.LoginProcessHandler;
import de.florianmichael.classic4j.model.classicube.account.CCAccount;
import de.florianmichael.viafabricplus.injection.access.ITextFieldWidget;
import de.florianmichael.viafabricplus.screen.VFPScreen;
import de.florianmichael.viafabricplus.definition.account.ClassiCubeAccountHandler;
import de.florianmichael.viafabricplus.screen.common.ProtocolSelectionScreen;
Expand Down Expand Up @@ -66,6 +67,9 @@ protected void init() {
nameField.setMaxLength(Integer.MAX_VALUE);
passwordField.setMaxLength(Integer.MAX_VALUE);

((ITextFieldWidget) nameField).viaFabricPlus$unlockForbiddenCharacters();
((ITextFieldWidget) passwordField).viaFabricPlus$unlockForbiddenCharacters();

nameField.setText(ClassiCubeAccountHandler.INSTANCE.getUsername());
passwordField.setText(ClassiCubeAccountHandler.INSTANCE.getPassword());

Expand Down
1 change: 1 addition & 0 deletions src/main/resources/viafabricplus.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"base.MixinMultiplayerServerListWidget_ServerEntry",
"base.MixinOptionsScreen",
"base.MixinServerInfo",
"base.MixinTextFieldWidget",
"classic4j.MixinCCAuthenticationResponse",
"compat.ipnext.MixinAutoRefillHandler_ItemSlotMonitor",
"fixes.authlib.MixinKeyPairResponse",
Expand Down

0 comments on commit 1d45d1a

Please sign in to comment.