diff options
| author | Aizistral | 2026-11-18 20:21:14 +0100 |
|---|---|---|
| committer | Aizistral | 2026-11-18 20:21:14 +0100 |
| commit | c86ec56e0970e0defdbc723911e7fd8fff5a2ed0 (patch) | |
| tree | 1ac6e4c70907458331531020bd07edeb9a457a1a /NeoForge/src/main/java/com | |
| parent | c498f88d62407609cea7ab4b46bff6ac61b32972 (diff) | |
Wrap user properties on read
Diffstat (limited to 'NeoForge/src/main/java/com')
2 files changed, 11 insertions, 60 deletions
diff --git a/NeoForge/src/main/java/com/aizistral/nochatrestrictions/mixins/MixinMinecraft.java b/NeoForge/src/main/java/com/aizistral/nochatrestrictions/mixins/MixinMinecraft.java index 2a8f935..862d381 100644 --- a/NeoForge/src/main/java/com/aizistral/nochatrestrictions/mixins/MixinMinecraft.java +++ b/NeoForge/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.services.MinecraftServicesDiscoveryService; import net.minecraft.client.Minecraft; @@ -26,6 +28,15 @@ public class MixinMinecraft { NCRCore.LOGGER.info("Successfully supplanted UserApiService with a wrapped version."); } + @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/NeoForge/src/main/java/com/aizistral/nochatrestrictions/mixins/MixinMinecraftServicesUserApiService.java b/NeoForge/src/main/java/com/aizistral/nochatrestrictions/mixins/MixinMinecraftServicesUserApiService.java deleted file mode 100644 index f38140b..0000000 --- a/NeoForge/src/main/java/com/aizistral/nochatrestrictions/mixins/MixinMinecraftServicesUserApiService.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.aizistral.nochatrestrictions.mixins; - -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.mojang.authlib.minecraft.TelemetrySession; -import com.mojang.authlib.minecraft.UserApiService.UserProperties; -import com.mojang.authlib.services.MinecraftServicesUserApiService; - -/** - * 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 MinecraftServicesUserApiService} - * 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 = MinecraftServicesUserApiService.class, remap = false) -public class MixinMinecraftServicesUserApiService { - - static { - NCRCore.LOGGER.info("MixinMinecraftServicesUserApiService initialized successfully."); - } - - 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); - } - } - -} |
