Skip to content

Commit

Permalink
Fix featureAutoReconnect not working properly (MC 1.19+)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hendrix-Shen committed Dec 22, 2022
1 parent c591f60 commit 37cf486
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 46 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
plugins {
id("maven-publish")
id("fabric-loom").version("0.12-SNAPSHOT").apply(false)
id("fabric-loom").version("1.0-SNAPSHOT").apply(false)
// https://github.com/Juuxel/LoomQuiltflower
id("io.github.juuxel.loom-quiltflower").version("1.7.4").apply(false)
// id("io.github.juuxel.loom-quiltflower").version("1.8.0").apply(false)
// https://github.com/ReplayMod/preprocessor
// https://github.com/Fallen-Breath/preprocessor
id("com.replaymod.preprocess").version("b7207cffa9")
Expand Down
7 changes: 6 additions & 1 deletion common.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
apply(plugin: "maven-publish")
apply(plugin: "fabric-loom")
apply(plugin: "io.github.juuxel.loom-quiltflower")
// apply(plugin: "io.github.juuxel.loom-quiltflower")
apply(plugin: "com.replaymod.preprocess")

int mcVersion = 1
Expand Down Expand Up @@ -31,6 +31,11 @@ dependencies {
minecraft("com.mojang:minecraft:${project.minecraft_version}")
mappings(loom.officialMojangMappings())

modCompileOnly("org.projectlombok:lombok:${project.lombok_version}")
annotationProcessor("org.projectlombok:lombok:${project.lombok_version}")
testCompileOnly("org.projectlombok:lombok:${project.lombok_version}")
testAnnotationProcessor("org.projectlombok:lombok:${project.lombok_version}")

def ENV = System.getenv()
modImplementation("top.hendrixshen:magiclib-${project.minecraft_version.replace(".", "_")}:${project.magiclib_version}") {
if (ENV.BUILD_NUMBER) {
Expand Down
7 changes: 5 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ maven_group=top.hendrixshen
archives_base_name=TweakMyClient

# Development Environment
loader_version=0.14.11
loader_version=0.14.12

# Annotation processor
lombok_version=1.18.24

# Required Libraries
# MagicLib - 0.6.194
magiclib_dependency=0.6.194+3df5798-beta
magiclib_version=0.6.194+3df5798-beta
magiclib_version=0.6.195+22fabd0-beta
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class TweakMyClientReference {
public static boolean isHwylaLoaded = FabricUtil.isModLoaded("waila");
public static boolean isInGameAccountSwitcherLoaded = FabricUtil.isModLoaded("ias");
public static boolean isJadeLoaded = FabricUtil.isModLoaded("jade");
public static boolean isOauthLoaded = FabricUtil.isModLoaded("oauth-fabric");
public static boolean isOAuthLoaded = FabricUtil.isModLoaded("oauth-fabric");
public static boolean isReAuthLoaded = FabricUtil.isModLoaded("reauth");
public static boolean isWthitLoaded = FabricUtil.isModLoaded("wthit");

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package top.hendrixshen.tweakmyclient.util;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.*;
Expand All @@ -15,13 +16,14 @@
import net.minecraft.resources.ResourceLocation;
import top.hendrixshen.magiclib.compat.minecraft.blaze3d.vertex.VertexFormatCompatApi;
import top.hendrixshen.magiclib.compat.minecraft.network.chat.ComponentCompatApi;
import top.hendrixshen.magiclib.util.ReflectUtil;
import top.hendrixshen.tweakmyclient.TweakMyClient;
import top.hendrixshen.tweakmyclient.TweakMyClientReference;
import top.hendrixshen.tweakmyclient.config.Configs;
import top.hendrixshen.tweakmyclient.fakeInterface.IScreen;

import java.lang.reflect.InvocationTargetException;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

public class AutoReconnectUtil {
Expand All @@ -31,14 +33,20 @@ public class AutoReconnectUtil {
private static boolean initialized = false;
private static ServerData lastServer;
private static Button autoReconnectButton;
//#if MC >= 11903
private static final List<Component> reAuthMessages = Lists.newArrayList(
ComponentCompatApi.translatable("disconnect.loginFailedInfo", ComponentCompatApi.translatable("disconnect.loginFailedInfo.insufficientPrivileges")).plainCopy(),
ComponentCompatApi.translatable("disconnect.loginFailedInfo", ComponentCompatApi.translatable("disconnect.loginFailedInfo.invalidSession")).plainCopy(),
ComponentCompatApi.translatable("disconnect.loginFailedInfo", ComponentCompatApi.translatable("disconnect.loginFailedInfo.serversUnavailable")).plainCopy(),
ComponentCompatApi.translatable("disconnect.loginFailedInfo", ComponentCompatApi.translatable("disconnect.loginFailedInfo.userBanned")).plainCopy());
//#endif

private final static AutoReconnectUtil INSTANCE = new AutoReconnectUtil();

public static AutoReconnectUtil getInstance() {
return AutoReconnectUtil.INSTANCE;
}

private static int compatReAuthenticateMods = 0;

private static final LinkedHashMap<String, Screen> modHashMap = Maps.newLinkedHashMap();

//#if MC < 11700
Expand Down Expand Up @@ -68,83 +76,72 @@ private void init(Screen parent) {
Screen screen = null;

try {
// AuthMe 2.2.0
screen = (Screen) Class.forName("me.axieum.mcmod.authme.impl.gui.AuthMethodScreen").getDeclaredConstructor(Screen.class).newInstance(parent);
} catch (InstantiationException | IllegalAccessException | InvocationTargetException |
NoSuchMethodException | ClassNotFoundException e) {
screen = (Screen) ReflectUtil.newInstance("me.axieum.mcmod.authme.impl.gui.AuthMethodScreen", new Class[]{Screen.class}, parent);
} catch (RuntimeException e) {
try {
// AuthMe 2.1.0
screen = (Screen) Class.forName("me.axieum.mcmod.authme.impl.AuthMe").getDeclaredConstructor().newInstance(); // 2.1.0
} catch (InstantiationException | IllegalAccessException | InvocationTargetException |
NoSuchMethodException | ClassNotFoundException ex) {
screen = (Screen) ReflectUtil.newInstance("me.axieum.mcmod.authme.impl.AuthMe", 0, (Object) null);
} catch (RuntimeException ex) {
try {
// AuthMe for mc 114
screen = (Screen) Class.forName("me.axieum.mcmod.authme.gui.AuthScreen").getDeclaredConstructor(Screen.class).newInstance(parent);
} catch (InstantiationException | IllegalAccessException | InvocationTargetException |
NoSuchMethodException | ClassNotFoundException exc) {
TweakMyClient.getLogger().error("Can't invoke Authme Screen");
screen = (Screen) ReflectUtil.newInstance("me.axieum.mcmod.authme.gui.AuthScreen", new Class[]{Screen.class}, parent);
} catch (RuntimeException exc) {
TweakMyClient.getLogger().error("Can't invoke AuthMe Screen");
}
}
}

if (screen != null) {
AutoReconnectUtil.modHashMap.put("authme", screen);
AutoReconnectUtil.compatReAuthenticateMods++;
}
}

if (TweakMyClientReference.isInGameAccountSwitcherLoaded) {
Screen screen = null;

try {
screen = (Screen) Class.forName("the_fireplace.ias.gui.GuiAccountSelector").getDeclaredConstructor(Screen.class).newInstance(parent);
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | NoSuchMethodException |
InvocationTargetException e) {
TweakMyClient.getLogger().error("Can't invoke In-Game Account Switcher Screen");
screen = (Screen) ReflectUtil.newInstance("the_fireplace.ias.gui.GuiAccountSelector", new Class[]{Screen.class}, parent);
} catch (RuntimeException e) {
try {
screen = (Screen) ReflectUtil.newInstance("the_fireplace.ias.gui.AccountListScreen", new Class[]{Screen.class}, parent);
} catch (RuntimeException ex) {
TweakMyClient.getLogger().error("Can't invoke In-Game Account Switcher Screen");
}
}

if (screen != null) {
AutoReconnectUtil.modHashMap.put("ias", screen);
AutoReconnectUtil.compatReAuthenticateMods++;
}
}

if (TweakMyClientReference.isOauthLoaded) {
if (TweakMyClientReference.isOAuthLoaded) {
Screen screen = null;

try {
// For MC 1.17
screen = (Screen) Class.forName("com.sintinium.oauthfabric.gui.profile.ProfileSelectionScreen").getDeclaredConstructor().newInstance();
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | NoSuchMethodException |
InvocationTargetException e) {
screen = (Screen) ReflectUtil.newInstance("com.sintinium.oauthfabric.gui.profile.ProfileSelectionScreen", 0, (Object) null);
} catch (RuntimeException e) {
try {
// For MC 1.16 & 1.18
screen = (Screen) Class.forName("com.sintinium.oauth.oauthfabric.gui.LoginTypeScreen").getDeclaredConstructor(Screen.class).newInstance(parent);
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException |
NoSuchMethodException | InvocationTargetException ex) {
screen = (Screen) ReflectUtil.newInstance("com.sintinium.oauth.oauthfabric.gui.LoginTypeScreen", new Class[]{Screen.class}, parent);
} catch (RuntimeException ex) {
TweakMyClient.getLogger().error("Can't invoke OAuth Screen");
}
}

if (screen != null) {
AutoReconnectUtil.modHashMap.put("oauth", screen);
AutoReconnectUtil.compatReAuthenticateMods++;
}
}

if (TweakMyClientReference.isReAuthLoaded) {
Screen screen = null;

try {
screen = (Screen) Class.forName("technicianlp.reauth.gui.AuthScreen").getDeclaredConstructor(Screen.class).newInstance(parent);
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | NoSuchMethodException |
InvocationTargetException e) {
screen = (Screen) ReflectUtil.newInstance("technicianlp.reauth.gui.AuthScreen", new Class[]{Screen.class}, parent);
} catch (RuntimeException e) {
TweakMyClient.getLogger().error("Can't invoke Reauth Screen");
}

if (screen != null) {
AutoReconnectUtil.modHashMap.put("reauth", screen);
AutoReconnectUtil.compatReAuthenticateMods++;
}
}

Expand Down Expand Up @@ -187,9 +184,14 @@ public void initDisconnectedScreen(Screen current, Screen parent, int width, int
int backButtonY = Math.min(height / 2 + textHeight / 2 + 9, height - 30);

//#if MC >= 11903
AutoReconnectUtil.autoReconnectButton = ((IScreen) current).tmc$addButton(
((IScreen) current).tmc$addButton(
Button.builder(ComponentCompatApi.literal(StringUtil.tr("message.autoReconnect.static")),
button -> AutoReconnectUtil.reconnect(parent)).pos(backButtonX, backButtonY + 24).size(98, 20).build());
button -> AutoReconnectUtil.reconnect(parent)).pos(backButtonX, backButtonY + 24).size(98, 20).build());

AutoReconnectUtil.autoReconnectButton = ((IScreen) current).tmc$addButton(
Button.builder(ComponentCompatApi.literal(StringUtil.tr("message.autoReconnect.toggle")),
AutoReconnectUtil::onPressAutoReconnect).pos(backButtonX + 102, backButtonY + 24).size(98, 20).build());

//#elseif MC >= 11600
//$$ ((IScreen) current).tmc$addButton(new Button(backButtonX, backButtonY + 24, 98, 20,
//$$ ComponentCompatApi.literal(StringUtil.tr("message.autoReconnect.static")), button -> AutoReconnectUtil.reconnect(parent)));
Expand All @@ -204,12 +206,21 @@ public void initDisconnectedScreen(Screen current, Screen parent, int width, int

AutoReconnectUtil.reAuthenticateButtonOffsetY = 0;

if (reason == null || AutoReconnectUtil.getTranslationKey(reason).startsWith("disconnect.loginFailed") && AutoReconnectUtil.compatReAuthenticateMods > 0) {

//#if MC >= 11903
if (reason == null || AutoReconnectUtil.reAuthMessages.stream().anyMatch(component -> component.getString().equals(reason.getString()))) {
//#else
//$$ if (reason == null || AutoReconnectUtil.getTranslationKey(reason).startsWith("disconnect.loginFailed")) {
//#endif
// Auto disable autoReconnect
TweakMyClientReference.getConfigHandler().configManager.setValue("featureAutoReconnect", false);

if (AutoReconnectUtil.modHashMap.size() < 1) {
return;
}

AtomicInteger offsetX = new AtomicInteger();
int buttonWidth = (200 - 4 * (AutoReconnectUtil.compatReAuthenticateMods - 1)) / AutoReconnectUtil.compatReAuthenticateMods;
int buttonWidth = (200 - 4 * (AutoReconnectUtil.modHashMap.size() - 1)) / AutoReconnectUtil.modHashMap.size();

AutoReconnectUtil.modHashMap.forEach(
(modId, screen) -> {
Expand Down

0 comments on commit 37cf486

Please sign in to comment.