moved Via loading

implemented Bedrock authentication
added some new Bedrock related fixes
This commit is contained in:
FlorianMichael 2023-03-16 21:46:33 +01:00
parent da9f390f71
commit 7e422eb2c5
34 changed files with 499 additions and 44 deletions

View File

@ -69,7 +69,16 @@ dependencies {
libs "net.raphimc:ViaLegacy:${project.vialegacy_version}"
libs "net.raphimc:ViaAprilFools:${project.viaaprilfools_version}"
libs "net.raphimc:ViaBedrock:${project.viabedrock_version}"
libs ("net.raphimc:ViaBedrock:${project.viabedrock_version}") {
exclude group: "io.jsonwebtoken", module: "jjwt-api"
exclude group: "io.jsonwebtoken", module: "jjwt-impl"
exclude group: "io.jsonwebtoken", module: "jjwt-gson"
}
libs ("net.raphimc:MinecraftAuth:${project.minecraftauth_version}") {
exclude group: "com.google.code.gson", module: "gson"
exclude group: "org.slf4j", module: "slf4j-api"
}
libs "net.lenni0451.mcstructs:text:${project.mcstructs_text_version}"
libs "net.lenni0451:Reflect:${project.reflect_version}"

View File

@ -9,7 +9,7 @@ loader_version=0.14.17
fabric_api_version=0.76.0+1.19.4
# viafabricplus
mod_version=2.1.2-ALPHA
mod_version=2.1.3-ALPHA
maven_group=de.florianmichael
archives_base_name=viafabricplus
@ -26,10 +26,11 @@ snake_yml_version=2.0
vialegacy_version=2.2.9-SNAPSHOT
viaaprilfools_version=2.0.6
viabedrock_version=0.0.1-SNAPSHOT
minecraftauth_version=2.0.1
# lenni0451 libs
mcstructs_text_version=2.2.0
reflect_version=1.1.0
# other mods
mod_menu_version=5.0.0
mod_menu_version=6.1.0-rc.1

View File

@ -17,9 +17,12 @@
*/
package de.florianmichael.viafabricplus;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import de.florianmichael.viafabricplus.definition.ChatLengthDefinition;
import de.florianmichael.viafabricplus.definition.ItemReleaseVersionDefinition;
import de.florianmichael.viafabricplus.definition.PackFormatsDefinition;
import de.florianmichael.viafabricplus.definition.bedrock.BedrockAccountManager;
import de.florianmichael.viafabricplus.definition.c0_30.ClassicItemSelectionScreen;
import de.florianmichael.viafabricplus.definition.c0_30.CustomClassicProtocolExtensions;
import de.florianmichael.viafabricplus.definition.c0_30.command.ClassicProtocolCommands;
@ -29,18 +32,23 @@ import de.florianmichael.viafabricplus.event.PreLoadCallback;
import de.florianmichael.viafabricplus.information.InformationSystem;
import de.florianmichael.viafabricplus.protocolhack.ProtocolHack;
import de.florianmichael.viafabricplus.settings.SettingsSystem;
import net.fabricmc.api.ClientModInitializer;
import java.io.File;
public class ViaFabricPlus {
public class ViaFabricPlus implements ClientModInitializer {
public final static Gson GSON = new GsonBuilder().setPrettyPrinting().create();
public final static File RUN_DIRECTORY = new File("ViaFabricPlus");
public final static ViaFabricPlus INSTANCE = new ViaFabricPlus();
private final SettingsSystem settingsSystem = new SettingsSystem();
private final InformationSystem informationSystem = new InformationSystem();
public void init() {
@Override
public void onInitializeClient() {
FinishMinecraftLoadCallback.EVENT.register(() -> {
// General settings
settingsSystem.init();
informationSystem.init();
@ -53,6 +61,9 @@ public class ViaFabricPlus {
ChatLengthDefinition.create();
ClassicItemSelectionScreen.create();
ClassicProtocolCommands.create();
// Bedrock Stuff
BedrockAccountManager.INSTANCE.load();
});
PreLoadCallback.EVENT.invoker().onLoad();

View File

@ -0,0 +1,72 @@
/*
* This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus
* Copyright (C) 2021-2023 FlorianMichael/MrLookAtMe (EnZaXD) and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.florianmichael.viafabricplus.definition.bedrock;
import com.google.gson.JsonObject;
import de.florianmichael.viafabricplus.ViaFabricPlus;
import net.raphimc.mcauth.MinecraftAuth;
import net.raphimc.mcauth.step.bedrock.StepMCChain;
import java.io.*;
public class BedrockAccountManager {
public final static BedrockAccountManager INSTANCE = new BedrockAccountManager();
private final File ACCOUNT_FILE = new File(ViaFabricPlus.RUN_DIRECTORY, "bedrock.account");
private StepMCChain.MCChain account;
public void load() {
if (ACCOUNT_FILE.exists()) {
final JsonObject mcChain;
try {
mcChain = ViaFabricPlus.GSON.fromJson(new FileReader(ACCOUNT_FILE), JsonObject.class).getAsJsonObject();
account = MinecraftAuth.Bedrock.Title.MC_CHAIN.fromJson(mcChain);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
Runtime.getRuntime().addShutdownHook(new Thread(this::save));
}
public void save() {
if (account != null) {
ACCOUNT_FILE.delete();
try {
ACCOUNT_FILE.createNewFile();
} catch (IOException e) {
throw new RuntimeException(e);
}
try (final FileWriter fw = new FileWriter(ACCOUNT_FILE)) {
fw.write(ViaFabricPlus.GSON.toJson(account.toJson()));
fw.flush();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
public StepMCChain.MCChain getAccount() {
return account;
}
public void setAccount(StepMCChain.MCChain account) {
this.account = account;
}
}

View File

@ -0,0 +1,56 @@
/*
* This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus
* Copyright (C) 2021-2023 FlorianMichael/MrLookAtMe (EnZaXD) and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.florianmichael.viafabricplus.definition.bedrock;
import com.viaversion.viaversion.api.connection.StoredObject;
import com.viaversion.viaversion.api.connection.UserConnection;
public class JoinGameStorage extends StoredObject {
private long seed;
private String levelId;
private long enchantmentSeed;
public JoinGameStorage(UserConnection user) {
super(user);
}
public long getSeed() {
return seed;
}
public void setSeed(long seed) {
this.seed = seed;
}
public String getLevelId() {
return levelId;
}
public void setLevelId(String levelId) {
this.levelId = levelId;
}
public long getEnchantmentSeed() {
return enchantmentSeed;
}
public void setEnchantmentSeed(long enchantmentSeed) {
this.enchantmentSeed = enchantmentSeed;
}
}

View File

@ -0,0 +1,30 @@
/*
* This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus
* Copyright (C) 2021-2023 FlorianMichael/MrLookAtMe (EnZaXD) and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.florianmichael.viafabricplus.definition.bedrock;
import net.raphimc.viabedrock.protocol.data.enums.bedrock.MovementMode;
public class ModelFormats {
public static String formatMovementMode(final int movementMode) {
if (movementMode == MovementMode.CLIENT) return "Client";
if (movementMode == MovementMode.SERVER) return "Server";
return "Server with rewind";
}
}

View File

@ -18,6 +18,8 @@
package de.florianmichael.viafabricplus.information.impl;
import com.viaversion.viaversion.api.connection.UserConnection;
import de.florianmichael.viafabricplus.definition.bedrock.JoinGameStorage;
import de.florianmichael.viafabricplus.definition.bedrock.ModelFormats;
import de.florianmichael.viafabricplus.information.AbstractInformationGroup;
import de.florianmichael.viafabricplus.util.ScreenUtil;
import de.florianmichael.vialoadingbase.platform.ProtocolRange;
@ -28,6 +30,7 @@ import net.raphimc.viabedrock.api.chunk.BedrockChunk;
import net.raphimc.viabedrock.api.model.entity.Entity;
import net.raphimc.viabedrock.protocol.storage.BlobCache;
import net.raphimc.viabedrock.protocol.storage.ChunkTracker;
import net.raphimc.viabedrock.protocol.storage.GameSessionStorage;
import java.util.List;
import java.util.Map;
@ -80,5 +83,18 @@ public class BedrockInformation extends AbstractInformationGroup {
output.add("Entity Tracker: " + entities);
}
}
final JoinGameStorage joinGameStorage = userConnection.get(JoinGameStorage.class);
if (!joinGameStorage.getLevelId().isEmpty() || joinGameStorage.getSeed() != 0 || joinGameStorage.getEnchantmentSeed() != 0) {
if (!output.isEmpty()) output.add("");
output.add("Join Game:");
}
if (joinGameStorage.getSeed() != 0) output.add("World Seed: " + joinGameStorage.getSeed());
if (!joinGameStorage.getLevelId().isEmpty()) output.add("Level Id: " + joinGameStorage.getLevelId());
if (joinGameStorage.getEnchantmentSeed() != 0) output.add("Enchantment Seed: " + joinGameStorage.getEnchantmentSeed());
final GameSessionStorage gameSessionStorage = userConnection.get(GameSessionStorage.class);
if (gameSessionStorage != null) {
output.add("Movement mode: " + ModelFormats.formatMovementMode(gameSessionStorage.getMovementMode()));
}
}
}

View File

@ -29,6 +29,6 @@ public class MixinMain {
@Inject(method = "main", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/crash/CrashReport;initCrashReport()V"))
private static void preLoad(CallbackInfo ci) {
ViaFabricPlus.INSTANCE.init();
// ViaFabricPlus.INSTANCE.init();
}
}

View File

@ -0,0 +1,33 @@
/*
* This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus
* Copyright (C) 2021-2023 FlorianMichael/MrLookAtMe (EnZaXD) and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.florianmichael.viafabricplus.injection.mixin.fixes.jsonwebtoken;
import io.jsonwebtoken.lang.Classes;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(value = Classes.class, remap = false)
public class MixinClasses {
@Inject(method = "forName", at = @At("HEAD"), cancellable = true)
private static void fixServicesSupport(String fqcn, CallbackInfoReturnable<Class<Object>> cir) throws ClassNotFoundException {
cir.setReturnValue((Class<Object>) Class.forName(fqcn));
}
}

View File

@ -0,0 +1,37 @@
/*
* This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus
* Copyright (C) 2021-2023 FlorianMichael/MrLookAtMe (EnZaXD) and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.florianmichael.viafabricplus.injection.mixin.fixes.jsonwebtoken;
import io.jsonwebtoken.impl.compression.DefaultCompressionCodecResolver;
import io.jsonwebtoken.impl.compression.DeflateCompressionCodec;
import io.jsonwebtoken.impl.compression.GzipCompressionCodec;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
import java.util.Arrays;
import java.util.List;
@Mixin(value = DefaultCompressionCodecResolver.class, remap = false)
public class MixinDefaultCompressionCodecResolver {
@Redirect(method = "<init>", at = @At(value = "INVOKE", target = "Lio/jsonwebtoken/impl/lang/Services;loadAll(Ljava/lang/Class;)Ljava/util/List;"))
public List<Object> fixServicesSupport(Class<Object> implementations) {
return Arrays.asList(new GzipCompressionCodec(), new DeflateCompressionCodec());
}
}

View File

@ -0,0 +1,33 @@
/*
* This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus
* Copyright (C) 2021-2023 FlorianMichael/MrLookAtMe (EnZaXD) and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.florianmichael.viafabricplus.injection.mixin.fixes.jsonwebtoken;
import io.jsonwebtoken.gson.io.GsonDeserializer;
import io.jsonwebtoken.impl.DefaultJwtParserBuilder;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
@Mixin(value = DefaultJwtParserBuilder.class, remap = false)
public class MixinDefaultJwtParserBuilder {
@Redirect(method = "build", at = @At(value = "INVOKE", target = "Lio/jsonwebtoken/impl/lang/Services;loadFirst(Ljava/lang/Class;)Ljava/lang/Object;"))
public Object fixServicesSupport(Class<Object> result) {
return new GsonDeserializer<>();
}
}

View File

@ -51,7 +51,7 @@ public class MixinAnvilBlock {
@Inject(method = "getOutlineShape", at = @At("HEAD"), cancellable = true)
public void injectGetOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context, CallbackInfoReturnable<VoxelShape> cir) {
if (ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_12_2)) {
if (ViaLoadingBase.getClassWrapper() != null && ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_12_2)) {
cir.setReturnValue(state.get(FACING).getAxis() == Direction.Axis.X ? viafabricplus_x_axis_shape_v1_12_2 : viafabricplus_z_axis_shape_v1_12_2);
}
}

View File

@ -44,7 +44,7 @@ public class MixinBrewingStandBlock {
@Inject(method = "getOutlineShape", at = @At("HEAD"), cancellable = true)
public void injectGetOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context, CallbackInfoReturnable<VoxelShape> cir) {
if (ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_12_2)) {
if (ViaLoadingBase.getClassWrapper() != null && ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_12_2)) {
cir.setReturnValue(viafabricplus_base_shape_v1_12_2);
}
}

View File

@ -48,7 +48,7 @@ public abstract class MixinCauldronBlock extends AbstractCauldronBlock {
@Override
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
if (ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_12_2)) {
if (ViaLoadingBase.getClassWrapper() != null && ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_12_2)) {
return viafabricplus_cauldron_shape_v1_12_2;
}
return super.getOutlineShape(state, world, pos, context);

View File

@ -39,7 +39,7 @@ public abstract class MixinChestBlock extends AbstractChestBlock<ChestBlockEntit
@Override
public VoxelShape getCollisionShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
if (ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(LegacyProtocolVersion.r1_4_2)) {
if (ViaLoadingBase.getClassWrapper() != null && ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(LegacyProtocolVersion.r1_4_2)) {
return VoxelShapes.fullCube();
}
return super.getCollisionShape(state, world, pos, context);

View File

@ -44,7 +44,7 @@ public class MixinEndPortalFrameBlock {
@Redirect(method = "getOutlineShape", at = @At(value = "FIELD", target = "Lnet/minecraft/block/EndPortalFrameBlock;FRAME_WITH_EYE_SHAPE:Lnet/minecraft/util/shape/VoxelShape;"))
public VoxelShape redirectGetOutlineShape() {
if (ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_12_2)) {
if (ViaLoadingBase.getClassWrapper() != null && ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_12_2)) {
return VoxelShapes.union(FRAME_SHAPE, viafabricplus_eye_shape_v1_12_2);
}
return FRAME_WITH_EYE_SHAPE;

View File

@ -50,7 +50,7 @@ public class MixinFarmlandBlock extends Block {
@Inject(method = "getOutlineShape", at = @At("HEAD"), cancellable = true)
public void injectGetOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context, CallbackInfoReturnable<VoxelShape> cir) {
if (ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_9_3)) {
if (ViaLoadingBase.getClassWrapper() != null && ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_9_3)) {
cir.setReturnValue(viafabricplus_shape_v1_9_4);
}
}

View File

@ -51,7 +51,7 @@ public class MixinFenceBlock extends HorizontalConnectingBlock {
@Override
public VoxelShape getCollisionShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
if (ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(LegacyProtocolVersion.b1_8tob1_8_1)) {
if (ViaLoadingBase.getClassWrapper() != null && ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(LegacyProtocolVersion.b1_8tob1_8_1)) {
return viafabricplus_fence_shape_b1_8_1;
}
return super.getCollisionShape(state, world, pos, context);
@ -59,7 +59,7 @@ public class MixinFenceBlock extends HorizontalConnectingBlock {
@Override
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
if (ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(LegacyProtocolVersion.b1_8tob1_8_1)) {
if (ViaLoadingBase.getClassWrapper() != null && ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(LegacyProtocolVersion.b1_8tob1_8_1)) {
return VoxelShapes.fullCube();
}
return super.getOutlineShape(state, world, pos, context);

View File

@ -36,7 +36,7 @@ public class MixinFireBlock {
@Inject(method = "getOutlineShape", at = @At("HEAD"), cancellable = true)
public void injectGetOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context, CallbackInfoReturnable<VoxelShape> cir) {
if (ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_15_2)) {
if (ViaLoadingBase.getClassWrapper() != null && ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_15_2)) {
cir.setReturnValue(VoxelShapes.empty());
}
}

View File

@ -48,14 +48,14 @@ public class MixinHopperBlock {
@Inject(method = "getOutlineShape", at = @At("HEAD"), cancellable = true)
public void injectGetOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context, CallbackInfoReturnable<VoxelShape> cir) {
if (ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_12_2)) {
if (ViaLoadingBase.getClassWrapper() != null && ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_12_2)) {
cir.setReturnValue(viafabricplus_hopper_shape_v1_12_2);
}
}
@Inject(method = "getRaycastShape", at = @At("HEAD"), cancellable = true)
public void injectGetRaycastShape(BlockState state, BlockView world, BlockPos pos, CallbackInfoReturnable<VoxelShape> cir) {
if (ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_12_2)) {
if (ViaLoadingBase.getClassWrapper() != null && ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_12_2)) {
cir.setReturnValue(viafabricplus_inside_shape_v1_12_2);
}
}

View File

@ -49,7 +49,7 @@ public class MixinLadderBlock {
@Inject(method = "getOutlineShape", at = @At("HEAD"), cancellable = true)
private void injectGetOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context, CallbackInfoReturnable<VoxelShape> ci) {
if (ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_8)) {
if (ViaLoadingBase.getClassWrapper() != null && ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_8)) {
switch (state.get(LadderBlock.FACING)) {
case NORTH -> ci.setReturnValue(viafabricplus_north_shape_v1_8_x);
case SOUTH -> ci.setReturnValue(viafabricplus_south_shape_v1_8_x);

View File

@ -40,7 +40,7 @@ public class MixinLilyPadBlock {
@Inject(method = "getOutlineShape", at = @At("HEAD"), cancellable = true)
public void changeBoundingBox(BlockState state, BlockView world, BlockPos pos, ShapeContext context, CallbackInfoReturnable<VoxelShape> cir) {
if (ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_8)) {
if (ViaLoadingBase.getClassWrapper() != null && ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_8)) {
cir.setReturnValue(viafabricplus_shape_v1_8_x);
}
}

View File

@ -36,7 +36,7 @@ public class MixinPaneBlock extends HorizontalConnectingBlock {
@Override
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
if (ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_8)) {
if (ViaLoadingBase.getClassWrapper() != null && ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_8)) {
return viafabricplus_get1_8Shape(state);
}
return super.getOutlineShape(state, world, pos, context);
@ -44,7 +44,7 @@ public class MixinPaneBlock extends HorizontalConnectingBlock {
@Override
public VoxelShape getCollisionShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
if (ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_8)) {
if (ViaLoadingBase.getClassWrapper() != null && ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_8)) {
return viafabricplus_get1_8Shape(state);
}
return super.getCollisionShape(state, world, pos, context);

View File

@ -40,14 +40,16 @@ public class MixinPistonHeadBlock extends FacingBlock {
@Inject(method = "getOutlineShape", at = @At("HEAD"), cancellable = true)
public void injectGetOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context, CallbackInfoReturnable<VoxelShape> cir) {
if (ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_12_2))
if (ViaLoadingBase.getClassWrapper() != null && ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_12_2)) {
cir.setReturnValue(viafabricplus_getCoreShape_v1_8_x(state));
}
}
@Override
public VoxelShape getCollisionShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
if (ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_8))
if (ViaLoadingBase.getClassWrapper() != null && ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_8)) {
return VoxelShapes.union(viafabricplus_getHeadShape_v1_8_x(state), viafabricplus_getCoreShape_v1_8_x(state));
}
return super.getCollisionShape(state, world, pos, context);
}

View File

@ -56,7 +56,7 @@ public class MixinSnowBlock {
@Inject(method = "getCollisionShape", at = @At("HEAD"), cancellable = true)
public void injectGetOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context, CallbackInfoReturnable<VoxelShape> cir) {
if (ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_12_2)) {
if (ViaLoadingBase.getClassWrapper() != null && ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_12_2)) {
cir.setReturnValue(viafabricplus_layers_to_shape_v1_12_2[state.get(LAYERS) - 1]);
}
}

View File

@ -158,14 +158,14 @@ public class MixinWallBlock extends Block {
@Inject(method = "getCollisionShape", at = @At("HEAD"), cancellable = true)
public void injectGetCollisionShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context, CallbackInfoReturnable<VoxelShape> cir) {
if (ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_12_2)) {
if (ViaLoadingBase.getClassWrapper() != null && ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_12_2)) {
cir.setReturnValue(viafabricplus_cip_shape_by_index_v1_12_2[viafabricplus_getShapeIndex_v1_12_2(state)]);
}
}
@Inject(method = "getOutlineShape", at = @At("HEAD"), cancellable = true)
public void injectGetOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context, CallbackInfoReturnable<VoxelShape> cir) {
if (ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_12_2)) {
if (ViaLoadingBase.getClassWrapper() != null && ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_12_2)) {
cir.setReturnValue(viafabricplus_shape_by_index_v1_12_2[viafabricplus_getShapeIndex_v1_12_2(state)]);
}
}

View File

@ -30,6 +30,7 @@ import net.minecraft.entity.player.PlayerAbilities;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.sound.SoundEvent;
import net.minecraft.world.World;
import net.raphimc.viabedrock.api.BedrockProtocolVersion;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
@ -80,7 +81,7 @@ public abstract class MixinPlayerEntity extends LivingEntity {
if (pose == EntityPose.CROUCHING) {
if (ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_8)) {
ci.setReturnValue(PlayerEntity.STANDING_DIMENSIONS);
} else if (ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_13_2)) {
} else if (ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_13_2) || ViaLoadingBase.getClassWrapper().getTargetVersion().isEqualTo(BedrockProtocolVersion.bedrockLatest)) {
ci.setReturnValue(viafabricplus_SNEAKING_DIMENSIONS_1_13_2);
}
}

View File

@ -20,6 +20,7 @@ package de.florianmichael.viafabricplus.injection.mixin.fixes.minecraft.screen;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.ProfileKey;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import de.florianmichael.viafabricplus.definition.bedrock.BedrockAccountManager;
import de.florianmichael.viafabricplus.injection.access.IPublicKeyData;
import de.florianmichael.viafabricplus.definition.v1_19_0.storage.ChatSession1_19_0;
import de.florianmichael.viafabricplus.definition.v1_19_2.storage.ChatSession1_19_2;
@ -31,6 +32,9 @@ import net.minecraft.client.network.ServerAddress;
import net.minecraft.network.ClientConnection;
import net.minecraft.network.encryption.PlayerKeyPair;
import net.minecraft.network.encryption.PlayerPublicKey;
import net.raphimc.mcauth.step.bedrock.StepMCChain;
import net.raphimc.viabedrock.api.BedrockProtocolVersion;
import net.raphimc.viabedrock.protocol.storage.AuthChainData;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
@ -56,24 +60,22 @@ public class MixinConnectScreen_1 {
@Redirect(method = "run", at = @At(value = "INVOKE", target = "Ljava/net/InetSocketAddress;getHostName()Ljava/lang/String;", ordinal = 1))
public String replaceAddress(InetSocketAddress instance) {
if (ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_17)) return field_33737.getAddress();
if (ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_17) || ViaLoadingBase.getClassWrapper().getTargetVersion().isEqualTo(BedrockProtocolVersion.bedrockLatest))
return field_33737.getAddress();
return instance.getHostString();
}
@Redirect(method = "run", at = @At(value = "INVOKE", target = "Ljava/net/InetSocketAddress;getPort()I"))
public int replacePort(InetSocketAddress instance) {
if (ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_17)) return field_33737.getPort();
if (ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_17) || ViaLoadingBase.getClassWrapper().getTargetVersion().isEqualTo(BedrockProtocolVersion.bedrockLatest))
return field_33737.getPort();
return instance.getPort();
}
@Inject(method = "run", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/ClientConnection;send(Lnet/minecraft/network/packet/Packet;)V", ordinal = 1, shift = At.Shift.BEFORE))
public void setupConnectionSessions(CallbackInfo ci) {
if (ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThan(ProtocolVersion.v1_19)) {
return; // This disables the chat session emulation for all versions <= 1.18.2
}
final ClientConnection connection = field_2416.connection;
if (connection == null || connection.channel == null) return;
final UserConnection userConnection = connection.channel.attr(ProtocolHack.LOCAL_VIA_CONNECTION).get();
@ -82,7 +84,18 @@ public class MixinConnectScreen_1 {
ViaLoadingBase.LOGGER.log(Level.WARNING, "ViaVersion userConnection is null");
return;
}
if (ViaLoadingBase.getClassWrapper().getTargetVersion().isEqualTo(BedrockProtocolVersion.bedrockLatest)) {
final StepMCChain.MCChain account = BedrockAccountManager.INSTANCE.getAccount();
if (account != null) {
userConnection.put(new AuthChainData(userConnection, account.mojangJwt(), account.identityJwt(), account.publicKey(), account.privateKey()));
}
return;
}
if (ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThan(ProtocolVersion.v1_19)) {
return; // This disables the chat session emulation for all versions <= 1.18.2
}
if (ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_19_1)) {
try {
final PlayerKeyPair playerKeyPair = MinecraftClient.getInstance().getProfileKeys().fetchKeyPair().get().orElse(null);

View File

@ -0,0 +1,35 @@
/*
* This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus
* Copyright (C) 2021-2023 FlorianMichael/MrLookAtMe (EnZaXD) and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.florianmichael.viafabricplus.injection.mixin.fixes.viabedrock;
import com.viaversion.viaversion.api.connection.UserConnection;
import de.florianmichael.viafabricplus.definition.bedrock.JoinGameStorage;
import net.raphimc.viabedrock.protocol.BedrockProtocol;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(value = BedrockProtocol.class, remap = false)
public class MixinBedrockProtocol {
@Inject(method = "init", at = @At("RETURN"))
public void hookStorages(UserConnection user, CallbackInfo ci) {
user.put(new JoinGameStorage(user));
}
}

View File

@ -0,0 +1,54 @@
/*
* This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus
* Copyright (C) 2021-2023 FlorianMichael/MrLookAtMe (EnZaXD) and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.florianmichael.viafabricplus.injection.mixin.fixes.viabedrock;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.type.Type;
import de.florianmichael.viafabricplus.definition.bedrock.JoinGameStorage;
import net.raphimc.viabedrock.protocol.packets.JoinPackets;
import net.raphimc.viabedrock.protocol.types.primitive.LongLEType;
import net.raphimc.viabedrock.protocol.types.primitive.StringType;
import net.raphimc.viabedrock.protocol.types.primitive.VarIntType;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
@Mixin(value = JoinPackets.class, remap = false)
public class MixinJoinPackets {
@Redirect(method = "lambda$register$2", at = @At(value = "INVOKE", target = "Lcom/viaversion/viaversion/api/protocol/packet/PacketWrapper;read(Lcom/viaversion/viaversion/api/type/Type;)Ljava/lang/Object;", ordinal = 5))
private static Object trackWorldSeed(PacketWrapper instance, Type<LongLEType> tType) throws Exception {
final Object seed = instance.read(tType);
instance.user().get(JoinGameStorage.class).setSeed((long) seed);
return seed;
}
@Redirect(method = "lambda$register$2", at = @At(value = "INVOKE", target = "Lcom/viaversion/viaversion/api/protocol/packet/PacketWrapper;read(Lcom/viaversion/viaversion/api/type/Type;)Ljava/lang/Object;", ordinal = 54))
private static Object trackLevelId(PacketWrapper instance, Type<StringType> tType) throws Exception {
final Object levelId = instance.read(tType);
instance.user().get(JoinGameStorage.class).setLevelId((String) levelId);
return levelId;
}
@Redirect(method = "lambda$register$2", at = @At(value = "INVOKE", target = "Lcom/viaversion/viaversion/api/protocol/packet/PacketWrapper;read(Lcom/viaversion/viaversion/api/type/Type;)Ljava/lang/Object;", ordinal = 62))
private static Object trackEnchantmentSeed(PacketWrapper instance, Type<VarIntType> tType) throws Exception {
final Object enchantmentSeed = instance.read(tType);
instance.user().get(JoinGameStorage.class).setEnchantmentSeed((Integer) enchantmentSeed);
return enchantmentSeed;
}
}

View File

@ -17,22 +17,33 @@
*/
package de.florianmichael.viafabricplus.screen;
import com.mojang.blaze3d.systems.RenderSystem;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import de.florianmichael.viafabricplus.definition.bedrock.BedrockAccountManager;
import de.florianmichael.viafabricplus.screen.settings.SettingsScreen;
import de.florianmichael.viafabricplus.settings.groups.GeneralSettings;
import de.florianmichael.vialoadingbase.ViaLoadingBase;
import de.florianmichael.vialoadingbase.platform.InternalProtocolList;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.screen.NoticeScreen;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.TitleScreen;
import net.minecraft.client.gui.screen.multiplayer.MultiplayerScreen;
import net.minecraft.client.gui.widget.AlwaysSelectedEntryListWidget;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.sound.PositionedSoundInstance;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.sound.SoundEvents;
import net.minecraft.text.Text;
import net.minecraft.util.Util;
import net.raphimc.mcauth.MinecraftAuth;
import java.awt.*;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.concurrent.CompletableFuture;
@SuppressWarnings({"DataFlowIssue", "DuplicatedCode"})
public class ProtocolSelectionScreen extends Screen {
@ -45,9 +56,12 @@ public class ProtocolSelectionScreen extends Screen {
public static void open(final Screen current) {
INSTANCE.prevScreen = current;
MinecraftClient.getInstance().setScreen(INSTANCE);
RenderSystem.recordRenderCall(() -> MinecraftClient.getInstance().setScreen(INSTANCE));
}
private ButtonWidget bedrockAuthentication;
@Override
protected void init() {
super.init();
@ -56,6 +70,41 @@ public class ProtocolSelectionScreen extends Screen {
this.addDrawableChild(ButtonWidget.builder(Text.literal("<-"), button -> this.close()).position(0, height - 20).size(20, 20).build());
this.addDrawableChild(ButtonWidget.builder(Text.literal("Settings"), button -> client.setScreen(SettingsScreen.get(this))).position(0, 0).size(98, 20).build());
this.addDrawableChild(bedrockAuthentication = ButtonWidget.builder(getBedrockAuthenticationText(), button -> {
CompletableFuture.runAsync(() -> {
try {
BedrockAccountManager.INSTANCE.setAccount(MinecraftAuth.requestBedrockLogin(msaDeviceCode -> {
client.execute(() -> this.client.setScreen(new NoticeScreen(() -> {
ProtocolSelectionScreen.open(new MultiplayerScreen(new TitleScreen()));
Thread.currentThread().interrupt();
}, Text.literal("Microsoft Bedrock login"), Text.literal("Your webbrowser should've opened.\nPlease enter the following Code: " + msaDeviceCode.userCode() + "\nClosing this screen will cancel the process!"), Text.literal("Cancel"), false)));
try {
Util.getOperatingSystem().open(new URI(msaDeviceCode.verificationUri()));
} catch (URISyntaxException e) {
e.printStackTrace();
}
}));
ProtocolSelectionScreen.open(new MultiplayerScreen(new TitleScreen()));
} catch (Throwable e) {
e.printStackTrace();
}
});
}).position(width - 98, 0).size(98, 20).build());
}
public Text getBedrockAuthenticationText() {
if (BedrockAccountManager.INSTANCE.getAccount() != null) {
return Text.literal(BedrockAccountManager.INSTANCE.getAccount().displayName());
}
return Text.literal("Set Bedrock Account");
}
@Override
public void tick() {
super.tick();
if (bedrockAuthentication != null) {
bedrockAuthentication.setMessage(getBedrockAuthenticationText());
}
}
@Override

View File

@ -17,8 +17,6 @@
*/
package de.florianmichael.viafabricplus.settings;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
import de.florianmichael.viafabricplus.ViaFabricPlus;
import de.florianmichael.viafabricplus.event.InitializeSettingsCallback;
@ -34,7 +32,6 @@ import java.util.Collections;
import java.util.List;
public class SettingsSystem {
private final Gson GSON = new GsonBuilder().setPrettyPrinting().create();
private final File CONFIG_FILE = new File(ViaFabricPlus.RUN_DIRECTORY, "settings.json");
private final List<SettingGroup> groups = new ArrayList<>();
@ -62,7 +59,7 @@ public class SettingsSystem {
if (CONFIG_FILE.exists()) {
final JsonObject parentNode;
try {
parentNode = GSON.fromJson(new FileReader(CONFIG_FILE), JsonObject.class).getAsJsonObject();
parentNode = ViaFabricPlus.GSON.fromJson(new FileReader(CONFIG_FILE), JsonObject.class).getAsJsonObject();
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
}
@ -93,7 +90,7 @@ public class SettingsSystem {
setting.write(parentNode);
}
}
fw.write(GSON.toJson(parentNode));
fw.write(ViaFabricPlus.GSON.toJson(parentNode));
fw.flush();
} catch (IOException e) {
throw new RuntimeException(e);

View File

@ -18,6 +18,9 @@
"icon": "assets/viafabricplus/icon.png",
"environment": "*",
"entrypoints": {
"client": [
"de.florianmichael.viafabricplus.ViaFabricPlus"
],
"modmenu": [
"de.florianmichael.viafabricplus.integration.ModMenuImpl"
]

View File

@ -141,12 +141,15 @@
"fixes.viaversion.protocol1_9to1_8.MixinEntityTracker1_9",
"fixes.viaversion.protocol1_9to1_8.MixinMetadataRewriter1_9To1_8",
"fixes.viaversion.protocol1_9to1_8.MixinMovementTracker",
"fixes.viaversion.protocol1_9to1_8.MixinViaIdleThread"
"fixes.viaversion.protocol1_9to1_8.MixinViaIdleThread",
"fixes.jsonwebtoken.MixinClasses",
"fixes.jsonwebtoken.MixinDefaultCompressionCodecResolver",
"fixes.jsonwebtoken.MixinDefaultJwtParserBuilder",
"fixes.minecraft.item.MixinItemGroup_DisplayContext",
"fixes.viabedrock.MixinBedrockProtocol",
"fixes.viabedrock.MixinJoinPackets"
],
"injectors": {
"defaultRequire": 1
},
"mixins": [
"fixes.minecraft.item.MixinItemGroup_DisplayContext"
]
}
}