Skip to content

Commit

Permalink
Recoded and improved everything (1/2):tm:
Browse files Browse the repository at this point in the history
  • Loading branch information
RaphiMC committed Nov 24, 2023
1 parent 0220b7d commit 10851b4
Show file tree
Hide file tree
Showing 106 changed files with 1,398 additions and 2,125 deletions.
46 changes: 18 additions & 28 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,7 @@ base {
}

configurations {
// Jar in sources
api.extendsFrom jis

// Jar in jar
include.extendsFrom jij
implementation.extendsFrom jij
jij
}

repositories {
Expand Down Expand Up @@ -54,43 +49,49 @@ dependencies {
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_api_version}"

// ViaVersion Libraries
jis "com.viaversion:viaversion-common:${project.viaversion_version}"
jis ("com.viaversion:viabackwards-common:${project.viabackwards_version}") {
jij "com.viaversion:viaversion-common:${project.viaversion_version}"
jij ("com.viaversion:viabackwards-common:${project.viabackwards_version}") {
exclude group: "com.viaversion", module: "viaversion"
exclude group: "io.netty", module: "netty-all"
exclude group: "com.google.guava", module: "guava"
}
jis ("net.raphimc:ViaLegacy:${project.vialegacy_version}") {
jij ("net.raphimc:ViaLegacy:${project.vialegacy_version}") {
exclude group: "com.google.code.gson", module: "gson"
}
jis "net.raphimc:ViaAprilFools:${project.viaaprilfools_version}"
jis ("net.raphimc:ViaBedrock:${project.viabedrock_version}") {
jij "net.raphimc:ViaAprilFools:${project.viaaprilfools_version}"
jij ("net.raphimc:ViaBedrock:${project.viabedrock_version}") {
exclude group: "io.netty"
exclude group: "io.jsonwebtoken"
exclude group: "net.lenni0451.mcstructs", module: "text"
exclude group: "com.mojang", module: "brigadier"
}
jis ("net.raphimc:ViaLoader:${project.vialoader_version}") {
jij ("net.raphimc:ViaLoader:${project.vialoader_version}") {
exclude group: "com.google.guava", module: "guava"
exclude group: "org.slf4j", module: "slf4j-api"
}

// RaphiMC Libraries
jis ("net.raphimc:MinecraftAuth:${project.minecraftauth_version}") {
jij ("net.raphimc:MinecraftAuth:${project.minecraftauth_version}") {
exclude group: "com.google.code.gson", module: "gson"
exclude group: "org.slf4j", module: "slf4j-api"
}
jis("org.cloudburstmc.netty:netty-transport-raknet:${project.raknet_transport_version}") {
jij("org.cloudburstmc.netty:netty-transport-raknet:${project.raknet_transport_version}") {
exclude group: "io.netty"
}

// Lenni0451 Libraries
jij "net.lenni0451:Reflect:${project.reflect_version}"

// Misc Libraries
modApi "com.terraformersmc:modmenu:${project.mod_menu_version}"
include implementation(annotationProcessor("com.github.llamalad7.mixinextras:mixinextras-fabric:${project.mixin_extras_version}"))
jis "de.florianmichael:Classic4J:${project.classic4j_version}"
modCompileOnly "com.terraformersmc:modmenu:${project.mod_menu_version}"
jij(annotationProcessor("com.github.llamalad7.mixinextras:mixinextras-fabric:${project.mixin_extras_version}"))
jij "de.florianmichael:Classic4J:${project.classic4j_version}"

afterEvaluate {
configurations.jij.incoming.resolutionResult.allDependencies {
dependencies.include(dependencies.implementation(requested.toString()))
}
}
}

processResources {
Expand All @@ -109,17 +110,6 @@ java {
}

jar {
// Add all dependencies which are included using "jis" to the jar file and exclude the META-INF folder
dependsOn configurations.jis
from {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
configurations.jis.collect {
zipTree(it)
}
} {
exclude "META-INF/*.RSA", "META-INF/*.SF", "META-INF/*.DSA"
}

// Rename the project's license file to LICENSE_<project_name> to avoid conflicts
from("LICENSE") {
rename {
Expand Down
24 changes: 17 additions & 7 deletions src/main/java/de/florianmichael/viafabricplus/ViaFabricPlus.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,20 @@

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import de.florianmichael.viafabricplus.protocolhack.util.ViaJarReplacer;
import de.florianmichael.viafabricplus.event.FinishMinecraftLoadCallback;
import de.florianmichael.viafabricplus.event.PreLoadCallback;
import de.florianmichael.viafabricplus.settings.SettingsSystem;
import de.florianmichael.viafabricplus.definition.ClientsideFixes;
import de.florianmichael.viafabricplus.definition.account.BedrockAccountHandler;
import de.florianmichael.viafabricplus.definition.account.ClassiCubeAccountHandler;
import de.florianmichael.viafabricplus.definition.classic.CustomClassicProtocolExtensions;
import de.florianmichael.viafabricplus.definition.classic.screen.ClassicItemSelectionScreen;
import de.florianmichael.viafabricplus.event.FinishMinecraftLoadCallback;
import de.florianmichael.viafabricplus.event.PreLoadCallback;
import de.florianmichael.viafabricplus.information.InformationSystem;
import de.florianmichael.viafabricplus.mappings.CharacterMappings;
import de.florianmichael.viafabricplus.mappings.ItemReleaseVersionMappings;
import de.florianmichael.viafabricplus.mappings.PackFormatsMappings;
import de.florianmichael.viafabricplus.protocolhack.ProtocolHack;
import de.florianmichael.viafabricplus.definition.classic.screen.ClassicItemSelectionScreen;
import net.raphimc.vialoader.util.VersionEnum;
import de.florianmichael.viafabricplus.protocolhack.util.ViaJarReplacer;
import de.florianmichael.viafabricplus.settings.SettingsSystem;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

Expand All @@ -57,9 +56,19 @@
* - X/Z Face based jump movement in <= 1.13.2 is broken (https://github.com/ViaVersion/ViaFabricPlus/issues/189)
* - Collision hit boxes has been changed (https://github.com/ViaVersion/ViaFabricPlus/issues/195)
* - Blit-jump is not supported in <= 1.8.9 (https://github.com/ViaVersion/ViaFabricPlus/issues/225)
*
* TODO | Migration v3
* - Fix classic login input field (MixinSharedConstants)
* - Make recipe fixes dynamic instead of a data dump in java classes
* - Make mixin injection methods private
* - Make mixins abstract
* - Rename all methods
* - Use ViaProxy config patch for some clientside fixes options (Remove ViaFabricPlusVLViaConfig)
* - Is de.florianmichael.viafabricplus.injection.mixin.jsonwebtoken.* still needed?
* - Apply MixinAutoRefillHandler_ItemSlotMonitor only when mod is actually installed
* - Make block shapes static
*/
public class ViaFabricPlus {
public final static VersionEnum NATIVE_VERSION = VersionEnum.r1_20_2;

public final static Gson GSON = new GsonBuilder().setPrettyPrinting().create();
public final static Logger LOGGER = LogManager.getLogger("ViaFabricPlus");
Expand Down Expand Up @@ -93,6 +102,7 @@ public void init() {
CharacterMappings.load();

// Protocol Translator
ProtocolHack.initCommands();
ProtocolHack.init();

// Stuff which requires Minecraft to be initialized
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@
*/
package de.florianmichael.viafabricplus.definition;

import com.mojang.blaze3d.systems.RenderSystem;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.ArmorType;
import de.florianmichael.viafabricplus.event.ChangeProtocolVersionCallback;
import de.florianmichael.viafabricplus.event.FinishMinecraftLoadCallback;
import de.florianmichael.viafabricplus.event.LoadClassicProtocolExtensionCallback;
import de.florianmichael.viafabricplus.injection.MixinPlugin;
import de.florianmichael.viafabricplus.injection.access.IFontStorage;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.font.FontStorage;
Expand Down Expand Up @@ -103,30 +102,35 @@ public static void init() {
});

// Reloads some clientside stuff when the protocol version changes
ChangeProtocolVersionCallback.EVENT.register(protocolVersion -> {
ChangeProtocolVersionCallback.EVENT.register(protocolVersion -> MinecraftClient.getInstance().execute(() -> {
if (MinecraftClient.getInstance() == null) return;

// Reloads all bounding boxes
if (MinecraftClient.getInstance() != null && MinecraftClient.getInstance().player != null) { // Make sure that the game is loaded when reloading the cache
for (Block block : RELOADABLE_BLOCKS) {
block.getDefaultState().initShapeCache();
for (Block block : RELOADABLE_BLOCKS) {
for (BlockState state : block.getStateManager().getStates()) {
state.initShapeCache();
}
}

// Calculates the current chat limit, since it changes depending on the protocol version
currentChatLimit = 256;
if (protocolVersion.isOlderThanOrEqualTo(VersionEnum.r1_10)) {
if (protocolVersion.isOlderThanOrEqualTo(VersionEnum.c0_28toc0_30)) {
currentChatLimit = 64 - (MinecraftClient.getInstance().getSession().getUsername().length() + 2);
} else if (protocolVersion.equals(VersionEnum.bedrockLatest)) {
currentChatLimit = 512;
} else if (protocolVersion.isOlderThanOrEqualTo(VersionEnum.r1_9_3tor1_9_4)) {
currentChatLimit = 100;
if (protocolVersion.isOlderThanOrEqualTo(VersionEnum.c0_28toc0_30)) {
currentChatLimit = 64 - MinecraftClient.getInstance().getSession().getUsername().length() - 2;
}
} else {
currentChatLimit = 256;
}

if (!MixinPlugin.DASH_LOADER_PRESENT) {
// Reloads all font storages to fix the font renderer
for (FontStorage storage : MinecraftClient.getInstance().fontManager.fontStorages.values()) {
RenderSystem.recordRenderCall(() -> ((IFontStorage) storage).viafabricplus_clearCaches());
storage.glyphRendererCache.clear();
storage.glyphCache.clear();
}
}
});
}));

// Calculates the current chat limit, since it changes depending on the protocol version
LoadClassicProtocolExtensionCallback.EVENT.register(classicProtocolExtension -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,10 @@
import com.viaversion.viaversion.libs.opennbt.tag.builtin.IntTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag;
import de.florianmichael.viafabricplus.protocolhack.ProtocolHack;
import net.raphimc.vialoader.util.VersionEnum;
import net.raphimc.vialegacy.protocols.classic.protocola1_0_15toc0_28_30.model.ClassicLevel;
import net.raphimc.vialegacy.protocols.classic.protocola1_0_15toc0_28_30.providers.ClassicWorldHeightProvider;
import net.raphimc.vialegacy.protocols.classic.protocola1_0_15toc0_28_30.storage.ClassicLevelStorage;
import net.raphimc.vialoader.util.VersionEnum;

import java.util.ArrayList;
import java.util.BitSet;
Expand All @@ -46,7 +45,7 @@ public static PacketHandler handleJoinGame(final PacketHandler parentHandler) {
parentHandler.handle(wrapper);
if (wrapper.isCancelled()) return;

if (ProtocolHack.getTargetVersion(wrapper.user().getChannel()).isOlderThanOrEqualTo(VersionEnum.c0_28toc0_30)) {
if (VersionEnum.fromUserConnection(wrapper.user()).isOlderThanOrEqualTo(VersionEnum.c0_28toc0_30)) {
for (Tag dimension : wrapper.get(Type.NAMED_COMPOUND_TAG, 0).<CompoundTag>get("minecraft:dimension_type").<ListTag>get("value")) {
changeDimensionTagHeight(wrapper.user(), ((CompoundTag) dimension).get("element"));
}
Expand All @@ -60,7 +59,7 @@ public static PacketHandler handleRespawn(final PacketHandler parentHandler) {
parentHandler.handle(wrapper);
if (wrapper.isCancelled()) return;

if (ProtocolHack.getTargetVersion(wrapper.user().getChannel()).isOlderThanOrEqualTo(VersionEnum.c0_28toc0_30)) {
if (VersionEnum.fromUserConnection(wrapper.user()).isOlderThanOrEqualTo(VersionEnum.c0_28toc0_30)) {
changeDimensionTagHeight(wrapper.user(), wrapper.get(Type.NAMED_COMPOUND_TAG, 0));
}
};
Expand All @@ -71,7 +70,7 @@ public static PacketHandler handleChunkData(final PacketHandler parentHandler) {
parentHandler.handle(wrapper);
if (wrapper.isCancelled()) return;

if (ProtocolHack.getTargetVersion(wrapper.user().getChannel()).isOlderThanOrEqualTo(VersionEnum.c0_28toc0_30)) {
if (VersionEnum.fromUserConnection(wrapper.user()).isOlderThanOrEqualTo(VersionEnum.c0_28toc0_30)) {
wrapper.resetReader();
final Chunk chunk = wrapper.read(new ChunkType1_17(16));
wrapper.write(new ChunkType1_17(chunk.getSections().length), chunk);
Expand Down Expand Up @@ -161,7 +160,7 @@ public void register() {
};

return wrapper -> {
if (ProtocolHack.getTargetVersion(wrapper.user().getChannel()).isOlderThanOrEqualTo(VersionEnum.c0_28toc0_30)) {
if (VersionEnum.fromUserConnection(wrapper.user()).isOlderThanOrEqualTo(VersionEnum.c0_28toc0_30)) {
classicLightHandler.handle(wrapper);
} else {
parentHandler.handle(wrapper);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
import de.florianmichael.viafabricplus.definition.classic.command.ClassicViaSubCommand;
import de.florianmichael.viafabricplus.injection.access.IExtensionProtocolMetadataStorage;
import net.minecraft.util.Formatting;
import net.raphimc.vialoader.util.VersionEnum;
import net.raphimc.vialegacy.protocols.classic.protocolc0_28_30toc0_28_30cpe.storage.ExtensionProtocolMetadataStorage;
import net.raphimc.vialoader.util.VersionEnum;

public class ListExtensionsCommand extends ClassicViaSubCommand {
@Override
Expand All @@ -43,7 +43,7 @@ public boolean execute(ViaCommandSender sender, String[] args) {
sendMessage(sender, Formatting.RED + "Only for " + VersionEnum.c0_30cpe.getName());
return true;
}
((IExtensionProtocolMetadataStorage) connection.get(ExtensionProtocolMetadataStorage.class)).getServerExtensions().forEach((extension, version) -> {
((IExtensionProtocolMetadataStorage) connection.get(ExtensionProtocolMetadataStorage.class)).viaFabricPlus$getServerExtensions().forEach((extension, version) -> {
sendMessage(sender, Formatting.GREEN + extension.getName() + Formatting.GOLD + " v" + version);
});
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public GeneralInformation() {
@Override
public void applyInformation(UserConnection userConnection, List<String> output) {
output.add("Pipeline count: " + userConnection.getProtocolInfo().getPipeline().pipes().size());
output.add("Selected version (in the GUI): " + ProtocolHack.targetVersion.getName() + " (" + ProtocolHack.targetVersion.getVersion() + ")");
output.add("Selected version (in the GUI): " + ProtocolHack.getTargetVersion().getName() + " (" + ProtocolHack.getTargetVersion().getVersion() + ")");
output.add("Connected version: " + ProtocolHack.getTargetVersion().getName() + " (" + ProtocolHack.getTargetVersion().getVersion() + ")");
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,17 @@
*/
package de.florianmichael.viafabricplus.injection.access;

import javax.crypto.NoSuchPaddingException;
import javax.crypto.SecretKey;
import java.net.InetSocketAddress;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import com.viaversion.viaversion.api.connection.UserConnection;
import net.raphimc.vialoader.util.VersionEnum;

public interface IClientConnection {

void viafabricplus_setupPreNettyDecryption();
void viaFabricPlus$setupPreNettyDecryption();

InetSocketAddress viafabricplus_capturedAddress();
void viafabricplus_captureAddress(final InetSocketAddress socketAddress);
VersionEnum viaFabricPlus$getServerVersion();
void viaFabricPlus$setServerVersion(final VersionEnum serverVersion);

UserConnection viaFabricPlus$getUserConnection();
void viaFabricPlus$setUserConnection(final UserConnection userConnection);

void viafabricplus_enableZLibCompression();
void viafabricplus_enableSnappyCompression();
void viafabricplus_enableAesGcmEncryption(final SecretKey secretKey) throws InvalidAlgorithmParameterException, NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException;
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@

public interface IExtensionProtocolMetadataStorage {

EnumMap<ClassicProtocolExtension, Integer> getServerExtensions();
EnumMap<ClassicProtocolExtension, Integer> viaFabricPlus$getServerExtensions();
}

This file was deleted.

Loading

0 comments on commit 10851b4

Please sign in to comment.