Skip to content
Open
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
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,9 @@ nb-configuration.xml
##############################
## OS X
##############################
.DS_Store
.DS_Store

##############################
## Dev
##############################
release/
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ subprojects {
apply plugin: 'maven-publish'

group = 'net.foxmcloud.clientresetpacket'
version = '0.3.1'
version = '0.4.1'

java.toolchain.languageVersion = JavaLanguageVersion.of(17)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ public static void handleReset(HandshakeHandler handler, S2CReset msg, Supplier<
}

logger.info(RESETMARKER, "Received reset packet from server.");
VoiceChatReset.disconnect();

if (!handleClear(context)) {
return;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package gg.chaldea.client.reset.packet;

import java.lang.reflect.Method;
import java.util.concurrent.atomic.AtomicBoolean;

final class VoiceChatReset {
private static final String CLIENT_MANAGER = "de.maxhenkel.voicechat.voice.client.ClientManager";
private static final String CLIENT_VOICECHAT = "de.maxhenkel.voicechat.voice.client.ClientVoicechat";
private static final AtomicBoolean RESETTING = new AtomicBoolean();

private VoiceChatReset() {
}

static void disconnect() {
if (!RESETTING.compareAndSet(false, true)) {
return;
}
try {
Class<?> managerType = Class.forName(CLIENT_MANAGER);
Object manager = managerType.getMethod("instance").invoke(null);
Method onDisconnect = managerType.getDeclaredMethod("onDisconnect");
onDisconnect.setAccessible(true);
onDisconnect.invoke(manager);
} catch (ClassNotFoundException ignored) {
// Simple Voice Chat is optional.
} catch (ReflectiveOperationException | RuntimeException exception) {
// Older SVC builds may not expose ClientManager.onDisconnect().
closeLegacyClient();
} catch (LinkageError error) {
// A different/incompatible SVC build must never crash the client reset.
ClientReset.logger.debug(ClientReset.RESETMARKER, "Simple Voice Chat client reset is incompatible", error);
} finally {
// The SVC client has been fully detached. The next Minecraft PLAY
// connection will create a fresh client through its normal join hook.
RESETTING.set(false);
}
}

private static void closeLegacyClient() {
try {
Class<?> type = Class.forName(CLIENT_VOICECHAT);
Method getClient = type.getMethod("getInstance");
Object instance = getClient.invoke(null);
if (instance != null) {
type.getMethod("disconnect").invoke(instance);
}
} catch (ClassNotFoundException ignored) {
// Simple Voice Chat is optional.
} catch (ReflectiveOperationException | RuntimeException exception) {
ClientReset.logger.debug(ClientReset.RESETMARKER, "Simple Voice Chat client reset was not available", exception);
} catch (LinkageError error) {
ClientReset.logger.debug(ClientReset.RESETMARKER, "Simple Voice Chat client reset is incompatible", error);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
@Mixin(VanillaPacketFilter.class)
public interface VanillaPacketFilterAccessor {

@Invoker("isNecessary")
@Invoker(value = "isNecessary", remap = false)
boolean invokeIsNecessary(Connection manager);
}
2 changes: 1 addition & 1 deletion forge/src/main/resources/META-INF/mods.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ issueTrackerURL="https://github.com/Just-Chaldea/Forge-Client-Reset-Packet/issue

[[mods]]
modId="clientresetpacket"
version="0.0.6"
version="0.4.1"
displayName="Client Reset Packet"
displayURL="https://github.com/Just-Chaldea/Forge-Client-Reset-Packet"
credits="https://github.com/Just-Chaldea/Forge-Client-Reset-Packet"
Expand Down