diff options
Diffstat (limited to 'NeoForge')
6 files changed, 82 insertions, 71 deletions
diff --git a/NeoForge/gradle.properties b/NeoForge/gradle.properties index c23b501..d0fea0d 100644 --- a/NeoForge/gradle.properties +++ b/NeoForge/gradle.properties @@ -6,5 +6,5 @@ org.gradle.configuration-cache=false ## Environment Properties minecraft_version=26.3 neo_version=26.3.0.36-beta -mod_version=NeoForge-MC26.3-v1.3.0 -manifest_version=26.3-v1.3.0 +mod_version=NeoForge-MC26.3-v1.4.0 +manifest_version=26.3-v1.4.0 diff --git a/NeoForge/src/main/java/com/aizistral/nochatrestrictions/config/NCRConfig.java b/NeoForge/src/main/java/com/aizistral/nochatrestrictions/config/NCRConfig.java index ee04b0b..5b21b53 100644 --- a/NeoForge/src/main/java/com/aizistral/nochatrestrictions/config/NCRConfig.java +++ b/NeoForge/src/main/java/com/aizistral/nochatrestrictions/config/NCRConfig.java @@ -4,6 +4,7 @@ import java.io.BufferedReader; import java.io.BufferedWriter; import java.nio.file.Files; import java.nio.file.Path; +import java.util.Map; import java.util.Optional; import org.jetbrains.annotations.Nullable; @@ -11,15 +12,18 @@ import org.jetbrains.annotations.Nullable; import com.aizistral.nochatrestrictions.core.NCRCore; import com.google.gson.Gson; import com.google.gson.GsonBuilder; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; -import net.minecraft.client.Minecraft; +import net.neoforged.fml.loading.FMLPaths; -public record NCRConfig(boolean allowTelemetry, boolean allowProfanityFilter) { +public record NCRConfig(boolean enableMod, boolean allowTelemetry, boolean allowProfanityFilter) { private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create(); private static @Nullable NCRConfig instance = null; private static NCRConfig getDefault() { - return new NCRConfig(false, false); + return new NCRConfig(true, false, false); } public static NCRConfig getInstance() { @@ -34,23 +38,34 @@ public record NCRConfig(boolean allowTelemetry, boolean allowProfanityFilter) { NCRCore.LOGGER.debug("Reading config file {}...", fileName); NCRConfig config = readFile(fileName).orElseGet(NCRConfig::getDefault); + NCRCore.LOGGER.info("Mod Enabled: {}", config.enableMod()); NCRCore.LOGGER.info("Telemetry Allowed: {}", config.allowTelemetry()); NCRCore.LOGGER.info("Profanity Filter Allowed: {}", config.allowProfanityFilter()); - NCRCore.LOGGER.debug("Writing config file {} back to disk..."); + NCRCore.LOGGER.debug("Writing config file {} back to disk...", fileName); writeFile(fileName, config); return config; } + private static Path getConfigFile(String fileName) { + return FMLPaths.CONFIGDIR.get().resolve(fileName); + } + private static Optional<NCRConfig> readFile(String fileName) { - Path file = Minecraft.getInstance().gameDirectory.toPath().resolve("config").resolve(fileName); + Path file = getConfigFile(fileName); if (!Files.isRegularFile(file)) return Optional.empty(); try (BufferedReader reader = Files.newBufferedReader(file)) { - return Optional.of(GSON.fromJson(reader, NCRConfig.class)); + JsonObject json = GSON.toJsonTree(getDefault()).getAsJsonObject(); + + for (Map.Entry<String, JsonElement> entry : JsonParser.parseReader(reader).getAsJsonObject().entrySet()) { + json.add(entry.getKey(), entry.getValue()); + } + + return Optional.of(GSON.fromJson(json, NCRConfig.class)); } catch (Exception ex) { NCRCore.LOGGER.fatal("Could not read config file: {}", file); NCRCore.LOGGER.fatal("This likely indicates the file is corrupted. " @@ -61,7 +76,7 @@ public record NCRConfig(boolean allowTelemetry, boolean allowProfanityFilter) { } private static void writeFile(String fileName, NCRConfig config) { - Path file = Minecraft.getInstance().gameDirectory.toPath().resolve("config").resolve(fileName); + Path file = getConfigFile(fileName); try { Files.createDirectories(file.getParent()); diff --git a/NeoForge/src/main/java/com/aizistral/nochatrestrictions/core/NCRMixinPlugin.java b/NeoForge/src/main/java/com/aizistral/nochatrestrictions/core/NCRMixinPlugin.java new file mode 100644 index 0000000..cac9d7f --- /dev/null +++ b/NeoForge/src/main/java/com/aizistral/nochatrestrictions/core/NCRMixinPlugin.java @@ -0,0 +1,45 @@ +package com.aizistral.nochatrestrictions.core; + +import java.util.List; +import java.util.Set; + +import org.objectweb.asm.tree.ClassNode; +import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin; +import org.spongepowered.asm.mixin.extensibility.IMixinInfo; + +import com.aizistral.nochatrestrictions.config.NCRConfig; + +public class NCRMixinPlugin implements IMixinConfigPlugin { + + @Override + public void onLoad(String mixinPackage) { + } + + @Override + public String getRefMapperConfig() { + return null; + } + + @Override + public boolean shouldApplyMixin(String targetClassName, String mixinClassName) { + return NCRConfig.getInstance().enableMod(); + } + + @Override + public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) { + } + + @Override + public List<String> getMixins() { + return null; + } + + @Override + public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { + } + + @Override + public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { + } + +} 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); - } - } - -} diff --git a/NeoForge/src/main/resources/nochatrestrictions.mixins.json b/NeoForge/src/main/resources/nochatrestrictions.mixins.json index d50b07b..5f90fba 100644 --- a/NeoForge/src/main/resources/nochatrestrictions.mixins.json +++ b/NeoForge/src/main/resources/nochatrestrictions.mixins.json @@ -1,11 +1,11 @@ { "required": true, "package": "com.aizistral.nochatrestrictions.mixins", + "plugin": "com.aizistral.nochatrestrictions.core.NCRMixinPlugin", "minVersion": "0.8", "mixins": [], "client": [ - "MixinMinecraft", - "MixinMinecraftServicesUserApiService" + "MixinMinecraft" ], "injectors": { "defaultRequire": 1 |
