aboutsummaryrefslogtreecommitdiffstats
path: root/Fabric/src/main/java
diff options
context:
space:
mode:
authorAizistral2026-09-30 11:40:44 +0200
committerGitHub2026-09-30 11:40:44 +0200
commit27a00a5c3b277ed658bac62a1485566d6ba42841 (patch)
tree4429eccd1bf8de633ad1f352ce4410cb0a8c61f3 /Fabric/src/main/java
parent0ce2600cc9523997605d069aff1ebc32948b027a (diff)
parent1b40c469fd7f32ea76bb150383708ebfc045c931 (diff)
Merge pull request #27 from Sw3ys/fix/user-properties-26.2
Fix account switcher compatibility on Forge and NeoForge
Diffstat (limited to 'Fabric/src/main/java')
-rw-r--r--Fabric/src/main/java/com/aizistral/nochatrestrictions/mixins/MixinMinecraft.java14
-rw-r--r--Fabric/src/main/java/com/aizistral/nochatrestrictions/mixins/MixinYggdrasilUserApiService.java63
2 files changed, 14 insertions, 63 deletions
diff --git a/Fabric/src/main/java/com/aizistral/nochatrestrictions/mixins/MixinMinecraft.java b/Fabric/src/main/java/com/aizistral/nochatrestrictions/mixins/MixinMinecraft.java
index c0fa4d0..21700fd 100644
--- a/Fabric/src/main/java/com/aizistral/nochatrestrictions/mixins/MixinMinecraft.java
+++ b/Fabric/src/main/java/com/aizistral/nochatrestrictions/mixins/MixinMinecraft.java
@@ -7,7 +7,9 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import com.aizistral.nochatrestrictions.core.NCRCore;
import com.aizistral.nochatrestrictions.core.WrappedUserApiService;
+import com.aizistral.nochatrestrictions.core.WrappedUserProperties;
import com.mojang.authlib.minecraft.UserApiService;
+import com.mojang.authlib.minecraft.UserApiService.UserProperties;
import com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService;
import net.minecraft.client.Minecraft;
@@ -26,6 +28,18 @@ public class MixinMinecraft {
NCRCore.LOGGER.info("Successfully supplanted UserApiService with a wrapped version.");
}
+ // Account switchers fetch the properties themselves and put the result straight into
+ // userPropertiesFuture, so wrapping the service on its own doesn't always stick.
+ // Everything that gates chat/multiplayer/realms reads them back through here.
+ @Inject(method = "userProperties", at = @At("RETURN"), cancellable = true)
+ private void onGetUserProperties(CallbackInfoReturnable<UserProperties> info) {
+ UserProperties properties = info.getReturnValue();
+
+ if (properties != null) {
+ info.setReturnValue(WrappedUserProperties.of(properties));
+ }
+ }
+
@Inject(method = "isNameBanned", at = @At("HEAD"), cancellable = true)
private void onCheckNameBan(CallbackInfoReturnable<Boolean> info) {
info.setReturnValue(Boolean.FALSE);
diff --git a/Fabric/src/main/java/com/aizistral/nochatrestrictions/mixins/MixinYggdrasilUserApiService.java b/Fabric/src/main/java/com/aizistral/nochatrestrictions/mixins/MixinYggdrasilUserApiService.java
deleted file mode 100644
index 4ff648d..0000000
--- a/Fabric/src/main/java/com/aizistral/nochatrestrictions/mixins/MixinYggdrasilUserApiService.java
+++ /dev/null
@@ -1,63 +0,0 @@
-package com.aizistral.nochatrestrictions.mixins;
-
-import java.util.Map;
-import java.util.concurrent.Executor;
-
-import org.jetbrains.annotations.Nullable;
-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.Inject;
-import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
-
-import com.aizistral.nochatrestrictions.config.NCRConfig;
-import com.aizistral.nochatrestrictions.core.NCRCore;
-import com.aizistral.nochatrestrictions.core.WrappedUserProperties;
-import com.google.common.collect.ImmutableSet;
-import com.mojang.authlib.minecraft.TelemetrySession;
-import com.mojang.authlib.minecraft.UserApiService.UserFlag;
-import com.mojang.authlib.minecraft.UserApiService.UserProperties;
-import com.mojang.authlib.yggdrasil.YggdrasilUserApiService;
-
-/**
- * Applies the chat/multiplayer restriction removal directly on the concrete
- * service class instead of just wrapping it once at {@code Minecraft#createUserApiService}.
- *
- * In-game account switchers (e.g. IAS) build a brand new {@link YggdrasilUserApiService}
- * and swap it onto the Minecraft instance without going through the original wrapping
- * path, which is why restrictions used to come back after switching accounts. By hooking
- * the service class itself, every instance the game ever uses returns permissive
- * properties, regardless of who created it or when.
- */
-@Mixin(value = YggdrasilUserApiService.class, remap = false)
-public class MixinYggdrasilUserApiService {
-
- static {
- NCRCore.LOGGER.info("MixinYggdrasilUserApiService initialized succesfully.");
- }
-
- private @Unique @Nullable UserProperties wrappedProperties;
-
- @Inject(method = "fetchProperties", at = @At("RETURN"), cancellable = true)
- private void onFetchProperties(CallbackInfoReturnable<UserProperties> info) {
- UserProperties original = info.getReturnValue();
-
- if (original == null)
- return;
- else if (this.wrappedProperties != null) {
- info.setReturnValue(this.wrappedProperties);
- return;
- } else {
- info.setReturnValue(this.wrappedProperties = WrappedUserProperties.of(original));
- return;
- }
- }
-
- @Inject(method = "newTelemetrySession", at = @At("HEAD"), cancellable = true)
- private void onNewTelemetrySession(Executor executor, CallbackInfoReturnable<TelemetrySession> info) {
- if (!NCRConfig.getInstance().allowTelemetry()) {
- info.setReturnValue(TelemetrySession.DISABLED);
- }
- }
-
-}