Rework build structure to prevent gradle plugins

Drop 1.14/1.15 as Forge doesn't seem to like Mixins on those versions
Fixed 1.17+ GUI rendering crashing for OpenGL exceptions
This commit is contained in:
FlorianMichael 2023-12-06 22:05:18 +01:00
parent c9efed6697
commit 2bd493a166
No known key found for this signature in database
GPG Key ID: C2FB87E71C425126
66 changed files with 266 additions and 2378 deletions

View File

@ -1,8 +1,178 @@
plugins { buildscript {
id "java" // Counterpart of settings.gradle file, sadly conventions can't use those defined repositories for some reason...
id "viaforge.base-conventions" repositories {
gradlePluginPortal()
maven { url = "https://repo.spongepowered.org/repository/maven-public/" }
maven { url = "https://jitpack.io/" }
maven { url = "https://files.minecraftforge.net/maven" }
}
// Counterpart of settings.gradle file, sadly conventions can't use those defined plugins for some reason...
dependencies {
classpath "com.github.johnrengelman:shadow:7.1.2"
classpath "net.minecraftforge.gradle:ForgeGradle:5.+"
classpath "org.spongepowered:mixingradle:0.7-SNAPSHOT"
}
} }
dependencies { allprojects {
apply plugin: "java-library"
apply plugin: "com.github.johnrengelman.shadow"
// We define the configuration here so we can use it across all conventions and platforms
// To define which projects/source files should be included in the jar
configurations {
library
implementation.extendsFrom(library)
}
// Repositories for the ViaVersion dependencies defined below
repositories {
maven {
url = "https://repo.spongepowered.org/repository/maven-public"
}
maven {
url = "https://repo.viaversion.com"
}
}
// Replace the version in the mcmod.info and mods.toml files with the project version
// Since this depends on the platform version, we can't define it in the global scope :(
processResources {
inputs.property "version", project.version
for (final def file in ["mcmod.info", "META-INF/mods.toml"]) {
filesMatching(file) {
expand "version": project.version
}
}
}
// Including all required libraries for ViaVersion {for version numbers see gradle.properties}
dependencies {
compileOnly "io.netty:netty-all:4.0.20.Final" compileOnly "io.netty:netty-all:4.0.20.Final"
library "com.viaversion:viaversion:${project.viaversion_version}"
library "com.viaversion:viabackwards:${project.viabackwards_version}"
library "com.viaversion:viarewind-universal:${project.viarewind_version}"
library ("net.raphimc:ViaLegacy:${project.vialegacy_version}") {
exclude group: "com.google.code.gson", module: "gson"
}
library "net.raphimc:ViaAprilFools:${project.viaaprilfools_version}"
library ("net.raphimc:ViaLoader:${project.vialoader_version}") {
exclude group: "com.google.guava"
exclude group: "org.slf4j"
}
library "org.yaml:snakeyaml:${project.snake_yml_version}"
}
}
subprojects {
apply plugin: "net.minecraftforge.gradle"
apply plugin: "org.spongepowered.mixin"
// Define the jar output attributes for all platforms
archivesBaseName = project.maven_name
version = maven_version + "-" + project.mc_version
group = maven_group
compileJava.options.encoding = "UTF-8"
minecraft {
runs {
client {
workingDirectory project.file("run")
property "forge.logging.markers", "REGISTRIES"
property "forge.logging.console.level", "debug"
// mixin
property "mixin.debug.export", "true"
property "mixin.hotSwap", "true"
property "fml.coreMods.load", "de.florianmichael.viaforge.mixin.MixinLoader" // Only required for MC 1.12, but modern Forges skips this anyway
args "-mixin.config=" + "mixins." + project.getProperty('maven_name') + ".json"
// source set
mods {
"${project.maven_name}" {
source sourceSets.main
}
}
}
}
}
sourceSets.main.resources {
srcDir "src/generated/resources"
}
dependencies {
if ((project.property("sub_module_increment") as Integer) >= 2) {
compileOnly "org.slf4j:slf4j-api:${slf4j_version}"
} else {
library "org.slf4j:slf4j-api:${slf4j_version}"
}
library "org.spongepowered:mixin:${mixin_version}"
annotationProcessor "org.spongepowered:mixin:${mixin_version}:processor"
library project(":") // Include the base project, to get Common-ViaForge
}
mixin {
add sourceSets.main, "mixins.${project.maven_name}.refmap.json"
}
jar {
manifest.attributes(
"Specification-Title": "viaforge",
"Specification-Vendor": "viaforge",
"Specification-Version": "1",
"Implementation-Title": project.name,
"Implementation-Version": "${archiveVersion}",
"Implementation-Vendor" :"viaforge",
"Implementation-Timestamp": new Date().format("yyyy-MM-dd"-"HH:mm:ssZ"),
"TweakClass": "org.spongepowered.asm.launch.MixinTweaker",
"TweakOrder": "0",
"FMLCorePluginContainsFMLMod": "true", // Only required for MC 1.12, but modern Forges skips this anyway
"FMLCorePlugin": "de.florianmichael.viaforge.mixin.MixinLoader", // Counterpart to the above
"MixinConfigs": "mixins.${project.maven_name}.json",
"ForceLoadAsMod": "true"
)
enabled = false
}
java {
if ((project.property("sub_module_increment") as Integer) >= 2) {
// Minecraft 1.17+ required Java 16/17 to compile
toolchain.languageVersion = JavaLanguageVersion.of(17)
}
}
shadowJar {
archiveFileName = jar.archiveFileName
configurations = [project.configurations.library] // Include the dependencies from the include configuration
duplicatesStrategy DuplicatesStrategy.EXCLUDE
// Prevent conflicts with Forge's weird service loading
exclude("META-INF/maven/**")
exclude("META-INF/versions/**")
if ((project.property("sub_module_increment") as Integer) >= 1) {
// Get rid of the services folder, since Forge 1.16+ would conflict with some of the ForgeDev Environment's services
// And since we don't need them for Mixins anyway, we can just exclude them from the shadowJar
exclude("META-INF/services/**")
// We don't need to package mixins into Forge 1.13+ jars, since Forge already has it
exclude("org/spongepowered/**")
}
}
reobf {
shadowJar {}
}
jar.dependsOn("shadowJar")
} }

View File

@ -1,19 +0,0 @@
plugins {
id "groovy-gradle-plugin"
}
// Counterpart of settings.gradle file, sadly conventions can't use those defined repositories for some reason...
repositories {
gradlePluginPortal()
maven { url = "https://repo.spongepowered.org/repository/maven-public/" }
maven { url = "https://jitpack.io/" }
maven { url = "https://files.minecraftforge.net/maven" }
}
// Counterpart of settings.gradle file, sadly conventions can't use those defined plugins for some reason...
dependencies {
implementation "com.github.johnrengelman:shadow:7.1.2"
implementation "net.minecraftforge.gradle:ForgeGradle:5.+"
implementation "org.spongepowered:mixingradle:0.7-SNAPSHOT"
}

View File

@ -1,34 +0,0 @@
plugins {
id "java-library"
}
// We define the configuration here so we can use it across all conventions and platforms
// To define which projects/source files should be included in the jar
configurations {
include
implementation.extendsFrom(include)
}
// Repositories for the ViaVersion dependencies defined below
repositories {
maven {
url = "https://repo.spongepowered.org/repository/maven-public"
}
maven {
url = "https://repo.viaversion.com"
}
}
// Including all required libraries for ViaVersion {for version numbers see gradle.properties}
dependencies {
include "com.viaversion:viaversion:${project.viaversion_version}"
include "com.viaversion:viabackwards:${project.viabackwards_version}"
include "com.viaversion:viarewind-universal:${project.viarewind_version}"
include ("net.raphimc:ViaLegacy:${project.vialegacy_version}") {
exclude group: "com.google.code.gson", module: "gson"
}
include "net.raphimc:ViaAprilFools:${project.viaaprilfools_version}"
include "net.raphimc:ViaLoader:${project.vialoader_version}"
include "org.yaml:snakeyaml:${project.snake_yml_version}"
}

View File

@ -1,9 +0,0 @@
plugins {
id "viaforge.shadow-conventions"
}
// Get rid of the services folder, since Forge 1.16+ would conflict with some of the ForgeDev Environment's services
// And since we don't need them for Mixins anyway, we can just exclude them from the shadowJar
shadowJar {
exclude "META-INF/services/**"
}

View File

@ -1,82 +0,0 @@
plugins {
id "net.minecraftforge.gradle"
id "org.spongepowered.mixin"
id "viaforge.shadow-conventions"
}
minecraft {
runs {
client {
workingDirectory project.file("run")
property "forge.logging.markers", "REGISTRIES"
property "forge.logging.console.level", "debug"
// mixin
property "mixin.debug.export", "true"
property "mixin.hotSwap", "true"
property "fml.coreMods.load", "de.florianmichael.viaforge.mixin.MixinLoader" // Only required for MC 1.12, but modern Forges skips this anyway
args "-mixin.config=" + "mixins." + project.getProperty('maven_name') + ".json"
// source set
mods {
"${maven_name}" {
source sourceSets.main
}
}
}
}
}
sourceSets.main.resources {
srcDir "src/generated/resources"
}
dependencies {
include "org.spongepowered:mixin:${mixin_version}"
include "org.slf4j:slf4j-api:${slf4j_version}"
annotationProcessor "org.spongepowered:mixin:${mixin_version}:processor"
include project(":") // Include the base project, to get Common-ViaForge
}
mixin {
add sourceSets.main, "mixins.${maven_name}.refmap.json"
}
jar {
manifest.attributes(
"Specification-Title": "viaforge",
"Specification-Vendor": "viaforge",
"Specification-Version": "1",
"Implementation-Title": project.name,
"Implementation-Version": "${archiveVersion}",
"Implementation-Vendor" :"viaforge",
"Implementation-Timestamp": new Date().format("yyyy-MM-dd"-"HH:mm:ssZ"),
"TweakClass": "org.spongepowered.asm.launch.MixinTweaker",
"TweakOrder": "0",
"FMLCorePluginContainsFMLMod": "true", // Only required for MC 1.12, but modern Forges skips this anyway
"FMLCorePlugin": "de.florianmichael.viaforge.mixin.MixinLoader", // Counterpart to the above
"MixinConfigs": "mixins.${maven_name}.json",
"ForceLoadAsMod": "true"
)
enabled = false
}
shadowJar {
archiveFileName = jar.archiveFileName
configurations = [project.configurations.include] // Include the dependencies from the include configuration
duplicatesStrategy DuplicatesStrategy.EXCLUDE
// Prevent conflicts with Forge's weird service loading
exclude("META-INF/maven/**")
exclude("META-INF/versions/**")
}
reobf {
shadowJar {}
}
jar.dependsOn("shadowJar")

View File

@ -1,7 +0,0 @@
plugins {
id "viaforge.forge-conventions"
id "viaforge.conflicting-conventions"
}
// Minecraft 1.17+ required Java 16/17 to compile
java.toolchain.languageVersion = JavaLanguageVersion.of(17)

View File

@ -1,25 +0,0 @@
plugins {
id "viaforge.base-conventions" // Include the base conventions, to get the dependencies
id "com.github.johnrengelman.shadow"
}
// Define the jar output attributes for all platforms
archivesBaseName = project.maven_name
version = maven_version + "-" + project.mc_version
group = maven_group
compileJava.options.encoding = "UTF-8"
// Replace the version in the mcmod.info and mods.toml files with the project version
// Since this depends on the platform version, we can't define it in the global scope :(
processResources {
inputs.property "version", project.version
for (final def file in ["mcmod.info", "META-INF/mods.toml"]) {
filesMatching(file) {
expand "version": project.version
}
}
}

View File

@ -1,8 +1,6 @@
rootProject.name = "ViaForge" rootProject.name = "ViaForge"
include "viaforge-mc112" include "viaforge-mc112"
include "viaforge-mc114"
include "viaforge-mc115"
include "viaforge-mc116" include "viaforge-mc116"
include "viaforge-mc117" include "viaforge-mc117"
include "viaforge-mc118" include "viaforge-mc118"

View File

@ -1,7 +1,3 @@
plugins {
id "viaforge.forge-conventions"
}
minecraft { minecraft {
mappings channel: "stable", version: "39-1.12" mappings channel: "stable", version: "39-1.12"
} }

View File

@ -1,2 +1,3 @@
maven_name=viaforge-mc112 maven_name=viaforge-mc112
mc_version=1.12.2 mc_version=1.12.2
sub_module_increment=0

View File

@ -29,7 +29,7 @@ import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.providers.G
import java.io.File; import java.io.File;
import java.util.function.Supplier; import java.util.function.Supplier;
@Mod(modid = "viaforge") @Mod(modid = "viaforge", version = "3.5.0")
public class ViaForge112 implements VFPlatform { public class ViaForge112 implements VFPlatform {
public static final ViaForge112 PLATFORM = new ViaForge112(); public static final ViaForge112 PLATFORM = new ViaForge112();

View File

@ -1,11 +0,0 @@
plugins {
id "viaforge.forge-conventions"
}
minecraft {
mappings channel: "official", version: "1.14.4"
}
dependencies {
minecraft "net.minecraftforge:forge:1.14.4-28.2.26"
}

View File

@ -1,2 +0,0 @@
maven_name=viaforge-mc114
mc_version=1.14.4

View File

@ -1,64 +0,0 @@
/*
* This file is part of ViaForge - https://github.com/FlorianMichael/ViaForge
* Copyright (C) 2021-2023 FlorianMichael/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.viaforge;
import de.florianmichael.viaforge.common.platform.VFPlatform;
import de.florianmichael.viaforge.provider.ViaForgeGameProfileFetcher;
import net.minecraft.client.Minecraft;
import net.minecraft.util.Session;
import net.minecraft.util.SharedConstants;
import net.minecraftforge.fml.common.Mod;
import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.providers.GameProfileFetcher;
import java.io.File;
import java.util.function.Supplier;
@Mod("viaforge")
public class ViaForge114 implements VFPlatform {
public static final ViaForge114 PLATFORM = new ViaForge114();
@Override
public int getGameVersion() {
return SharedConstants.getCurrentVersion().getProtocolVersion();
}
@Override
public Supplier<Boolean> isSingleplayer() {
return () -> Minecraft.getInstance().hasSingleplayerServer();
}
@Override
public File getLeadingDirectory() {
return Minecraft.getInstance().gameDirectory;
}
@Override
public void joinServer(String serverId) throws Throwable {
final Session session = Minecraft.getInstance().getUser();
Minecraft.getInstance().getMinecraftSessionService().joinServer(session.getGameProfile(), session.getAccessToken(), serverId);
}
@Override
public GameProfileFetcher getGameProfileFetcher() {
return new ViaForgeGameProfileFetcher();
}
}

View File

@ -1,165 +0,0 @@
/*
* This file is part of ViaForge - https://github.com/FlorianMichael/ViaForge
* Copyright (C) 2021-2023 FlorianMichael/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.viaforge.gui;
import com.mojang.realmsclient.gui.ChatFormatting;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.util.DumpUtil;
import de.florianmichael.viaforge.common.ViaForgeCommon;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.button.Button;
import net.minecraft.client.gui.widget.list.AbstractList;
import net.minecraft.client.gui.widget.list.ExtendedList;
import net.minecraft.util.text.StringTextComponent;
import net.raphimc.vialoader.util.VersionEnum;
import org.lwjgl.glfw.GLFW;
import org.lwjgl.opengl.GL11;
import java.util.UUID;
import java.util.concurrent.ExecutionException;
public class GuiProtocolSelector extends Screen {
public final Screen parent;
public final boolean simple;
public final FinishedCallback finishedCallback;
private SlotList list;
private String status;
private long time;
public static void open(final Minecraft minecraft) { // Bypass for some weird bytecode instructions errors in Forge
minecraft.setScreen(new GuiProtocolSelector(minecraft.screen));
}
public GuiProtocolSelector(final Screen parent) {
this(parent, false, (version, unused) -> {
// Default action is to set the target version and go back to the parent screen.
ViaForgeCommon.getManager().setTargetVersion(version);
});
}
public GuiProtocolSelector(final Screen parent, final boolean simple, final FinishedCallback finishedCallback) {
super(new StringTextComponent("ViaForge Protocol Selector"));
this.parent = parent;
this.simple = simple;
this.finishedCallback = finishedCallback;
}
@Override
public void init() {
super.init();
addButton(new Button(5, height - 25, 20, 20, "<-", b -> minecraft.setScreen(parent)));
if (!this.simple) {
addButton(new Button(width - 105, 5, 100, 20, "Create dump", b -> {
try {
minecraft.keyboardHandler.setClipboard(DumpUtil.postDump(UUID.randomUUID()).get());
setStatus(ChatFormatting.GREEN + "Dump created and copied to clipboard");
} catch (InterruptedException | ExecutionException e) {
setStatus(ChatFormatting.RED + "Failed to create dump: " + e.getMessage());
}
}));
addButton(new Button(width - 105, height - 25, 100, 20, "Reload configs", b -> Via.getManager().getConfigurationProvider().reloadConfigs()));
}
list = new SlotList(minecraft, width, height, 3 + 3 /* start offset */ + (font.lineHeight + 2) * 3 /* title is 2 */, height - 30, font.lineHeight + 2);
}
public void setStatus(final String status) {
this.status = status;
this.time = System.currentTimeMillis();
}
@Override
public boolean keyPressed(int keyCode, int scanCode, int actions) {
if (keyCode == GLFW.GLFW_KEY_ESCAPE) {
minecraft.setScreen(parent);
}
return super.keyPressed(keyCode, scanCode, actions);
}
@Override
public void render(int p_230430_2_, int p_230430_3_, float p_230430_4_) {
if (System.currentTimeMillis() - this.time >= 10_000) {
this.status = null;
}
renderBackground();
this.list.render(p_230430_2_, p_230430_3_, p_230430_4_);
super.render(p_230430_2_, p_230430_3_, p_230430_4_);
GL11.glPushMatrix();
GL11.glScalef(2.0F, 2.0F, 2.0F);
drawCenteredString(font, ChatFormatting.GOLD + "ViaForge", width / 4, 3, 16777215);
GL11.glPopMatrix();
drawCenteredString(font, "https://github.com/ViaVersion/ViaForge", width / 2, (font.lineHeight + 2) * 2 + 3, -1);
drawString(font, status != null ? status : "Discord: florianmichael", 3, 3, -1);
}
class SlotList extends ExtendedList<SlotList.SlotEntry> {
public SlotList(Minecraft client, int width, int height, int top, int bottom, int slotHeight) {
super(client, width, height, top, bottom, slotHeight);
for (VersionEnum version : VersionEnum.SORTED_VERSIONS) {
addEntry(new SlotEntry(version));
}
}
public class SlotEntry extends AbstractList.AbstractListEntry<SlotEntry> {
private final VersionEnum versionEnum;
public SlotEntry(VersionEnum versionEnum) {
this.versionEnum = versionEnum;
}
@Override
public boolean mouseClicked(double mouseX, double mouseY, int button) {
GuiProtocolSelector.this.finishedCallback.finished(versionEnum, GuiProtocolSelector.this.parent);
return super.mouseClicked(mouseX, mouseY, button);
}
@Override
public void render(int p_230432_2_, int y, int p_230432_4_, int p_230432_5_, int p_230432_6_, int p_230432_7_, int p_230432_8_, boolean p_230432_9_, float p_230432_10_) {
final VersionEnum targetVersion = ViaForgeCommon.getManager().getTargetVersion();
String color;
if (targetVersion == versionEnum) {
color = GuiProtocolSelector.this.simple ? ChatFormatting.GOLD.toString() : ChatFormatting.GREEN.toString();
} else {
color = GuiProtocolSelector.this.simple ? ChatFormatting.WHITE.toString() : ChatFormatting.DARK_RED.toString();
}
drawCenteredString(Minecraft.getInstance().font, color + versionEnum.getName(), width / 2, y, -1);
}
}
}
public interface FinishedCallback {
void finished(final VersionEnum version, final Screen parent);
}
}

View File

@ -1,66 +0,0 @@
/*
* This file is part of ViaForge - https://github.com/FlorianMichael/ViaForge
* Copyright (C) 2021-2023 FlorianMichael/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.viaforge.mixin;
import com.viaversion.viaversion.util.Pair;
import de.florianmichael.viaforge.common.ViaForgeCommon;
import de.florianmichael.viaforge.common.gui.ExtendedServerData;
import de.florianmichael.viaforge.common.platform.ViaForgeConfig;
import de.florianmichael.viaforge.gui.GuiProtocolSelector;
import net.minecraft.client.gui.screen.AddServerScreen;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.button.Button;
import net.minecraft.client.multiplayer.ServerData;
import net.minecraft.util.text.ITextComponent;
import net.raphimc.vialoader.util.VersionEnum;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(AddServerScreen.class)
public class MixinAddServerScreen extends Screen {
@Shadow @Final private ServerData serverData;
public MixinAddServerScreen(ITextComponent title) {
super(title);
}
@Inject(method = "init", at = @At("RETURN"))
public void initGui(CallbackInfo ci) {
final ViaForgeConfig config = ViaForgeCommon.getManager().getConfig();
if (config.isShowAddServerButton()) {
final Pair<Integer, Integer> pos = config.getAddServerScreenButtonPosition().getPosition(this.width, this.height);
final VersionEnum target = ((ExtendedServerData) serverData).viaForge$getVersion();
addButton(new Button(pos.key(), pos.value(), 100, 20, target != null ? target.getName() : "Set Version", b -> {
minecraft.setScreen(new GuiProtocolSelector(this, true, (version, parent) -> {
// Set version and go back to the parent screen.
((ExtendedServerData) serverData).viaForge$setVersion(version);
minecraft.setScreen(parent);
}));
}));
}
}
}

View File

@ -1,56 +0,0 @@
/*
* This file is part of ViaForge - https://github.com/FlorianMichael/ViaForge
* Copyright (C) 2021-2023 FlorianMichael/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.viaforge.mixin;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.exceptions.AuthenticationException;
import com.mojang.authlib.minecraft.MinecraftSessionService;
import com.viaversion.viaversion.api.connection.UserConnection;
import de.florianmichael.viaforge.common.ViaForgeCommon;
import net.minecraft.client.network.login.ClientLoginNetHandler;
import net.minecraft.network.NetworkManager;
import net.raphimc.vialegacy.protocols.release.protocol1_7_2_5to1_6_4.storage.ProtocolMetadataStorage;
import net.raphimc.vialoader.util.VersionEnum;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
@SuppressWarnings("DataFlowIssue")
@Mixin(ClientLoginNetHandler.class)
public class MixinClientLoginNetHandler {
@Shadow @Final private NetworkManager connection;
@Redirect(method = "authenticateServer", at = @At(value = "INVOKE", target = "Lcom/mojang/authlib/minecraft/MinecraftSessionService;joinServer(Lcom/mojang/authlib/GameProfile;Ljava/lang/String;Ljava/lang/String;)V"))
public void onlyJoinServerIfPremium(MinecraftSessionService instance, GameProfile profile, String authenticationToken, String serverId) throws AuthenticationException {
if (ViaForgeCommon.getManager().getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_6_4)) {
final UserConnection user = connection.channel().attr(ViaForgeCommon.LOCAL_VIA_USER).get();
if (user != null && user.has(ProtocolMetadataStorage.class) && !user.get(ProtocolMetadataStorage.class).authenticate) {
// We are in the 1.7 -> 1.6 protocol, so we need to skip the joinServer call
// if the server is in offline mode, due the packet changes <-> networking changes
// Minecraft's networking code is bad for us.
return;
}
}
instance.joinServer(profile, authenticationToken, serverId);
}
}

View File

@ -1,54 +0,0 @@
/*
* This file is part of ViaForge - https://github.com/FlorianMichael/ViaForge
* Copyright (C) 2021-2023 FlorianMichael/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.viaforge.mixin;
import de.florianmichael.viaforge.common.ViaForgeCommon;
import de.florianmichael.viaforge.common.gui.ExtendedServerData;
import net.minecraft.client.Minecraft;
import net.minecraft.network.NetworkManager;
import net.raphimc.vialoader.util.VersionEnum;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
import java.net.InetAddress;
@Mixin(targets = "net.minecraft.client.gui.screen.ConnectingScreen$1")
public class MixinConnectingScreen_1 {
@Redirect(method = "run", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/NetworkManager;connectToServer(Ljava/net/InetAddress;IZ)Lnet/minecraft/network/NetworkManager;"))
public NetworkManager trackVersion(InetAddress address, int i, boolean b) {
// We need to track the version of the server we are connecting to, so we can later
// use it to determine the protocol version to use.
// We hope that the current server data is not null
if (Minecraft.getInstance().getCurrentServer() instanceof ExtendedServerData) {
final VersionEnum version = ((ExtendedServerData) Minecraft.getInstance().getCurrentServer()).viaForge$getVersion();
if (version != null) {
ViaForgeCommon.getManager().setTargetVersionSilent(version);
} else {
// If the server data does not contain a version, we need to restore the version
// we had before, so we don't use the wrong version.
ViaForgeCommon.getManager().restoreVersion();
}
}
return NetworkManager.connectToServer(address, i, b);
}
}

View File

@ -1,54 +0,0 @@
/*
* This file is part of ViaForge - https://github.com/FlorianMichael/ViaForge
* Copyright (C) 2021-2023 FlorianMichael/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.viaforge.mixin;
import de.florianmichael.viaforge.common.ViaForgeCommon;
import net.minecraft.client.gui.overlay.DebugOverlayGui;
import net.raphimc.vialegacy.api.LegacyProtocolVersion;
import net.raphimc.vialoader.util.VersionEnum;
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;
import java.util.List;
@Mixin(DebugOverlayGui.class)
public class MixinDebugOverlayGui {
@Inject(method = "getSystemInformation", at = @At(value = "TAIL"))
public void addViaForgeVersion(CallbackInfoReturnable<List<String>> cir) {
final ViaForgeCommon common = ViaForgeCommon.getManager();
final VersionEnum version = ViaForgeCommon.getManager().getTargetVersion();
if (common.getConfig().isShowProtocolVersionInF3() && version != common.getNativeVersion() && !common.getPlatform().isSingleplayer().get()) {
cir.getReturnValue().add("");
int protocolVersion = version.getVersion();
if (version.isOlderThanOrEqualTo(VersionEnum.r1_6_4)) {
// Older versions (<= 1.6.4) are using fake ids in ViaLegacy to prevent version duplications / mismatches
// So we need to unmap the version to get the real protocol version id
protocolVersion = LegacyProtocolVersion.getRealProtocolVersion(protocolVersion);
}
cir.getReturnValue().add("ViaForge: " + version.getName() + " (" + protocolVersion + ")");
}
}
}

View File

@ -1,54 +0,0 @@
/*
* This file is part of ViaForge - https://github.com/FlorianMichael/ViaForge
* Copyright (C) 2021-2023 FlorianMichael/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.viaforge.mixin;
import com.viaversion.viaversion.util.Pair;
import de.florianmichael.viaforge.ViaForge114;
import de.florianmichael.viaforge.common.ViaForgeCommon;
import de.florianmichael.viaforge.common.platform.ViaForgeConfig;
import de.florianmichael.viaforge.gui.GuiProtocolSelector;
import net.minecraft.client.gui.screen.MainMenuScreen;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.button.Button;
import net.minecraft.util.text.ITextComponent;
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(MainMenuScreen.class)
public class MixinMainMenuScreen extends Screen {
public MixinMainMenuScreen(ITextComponent title) {
super(title);
}
@Inject(method = "init", at = @At("RETURN"))
public void hookViaForgeButton(CallbackInfo ci) {
ViaForgeCommon.init(ViaForge114.PLATFORM);
final ViaForgeConfig config = ViaForgeCommon.getManager().getConfig();
if (config.isShowMainMenuButton()) {
final Pair<Integer, Integer> pos = config.getViaForgeButtonPosition().getPosition(this.width, this.height);
addButton(new Button(pos.key(), pos.value(), 100, 20, "ViaForge", buttons -> GuiProtocolSelector.open(minecraft)));
}
}
}

View File

@ -1,51 +0,0 @@
/*
* This file is part of ViaForge - https://github.com/FlorianMichael/ViaForge
* Copyright (C) 2021-2023 FlorianMichael/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.viaforge.mixin;
import com.viaversion.viaversion.util.Pair;
import de.florianmichael.viaforge.common.ViaForgeCommon;
import de.florianmichael.viaforge.common.platform.ViaForgeConfig;
import de.florianmichael.viaforge.gui.GuiProtocolSelector;
import net.minecraft.client.gui.screen.MultiplayerScreen;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.button.Button;
import net.minecraft.util.text.ITextComponent;
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(MultiplayerScreen.class)
public class MixinMultiplayerScreen extends Screen {
public MixinMultiplayerScreen(ITextComponent title) {
super(title);
}
@Inject(method = "init", at = @At("RETURN"))
public void hookViaForgeButton(CallbackInfo ci) {
final ViaForgeConfig config = ViaForgeCommon.getManager().getConfig();
if (config.isShowMainMenuButton()) {
final Pair<Integer, Integer> pos = config.getViaForgeButtonPosition().getPosition(this.width, this.height);
addButton(new Button(pos.key(), pos.value(), 100, 20, "ViaForge", buttons -> GuiProtocolSelector.open(minecraft)));
}
}
}

View File

@ -1,108 +0,0 @@
/*
* This file is part of ViaForge - https://github.com/FlorianMichael/ViaForge
* Copyright (C) 2021-2023 FlorianMichael/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.viaforge.mixin;
import de.florianmichael.viaforge.common.ViaForgeCommon;
import de.florianmichael.viaforge.common.protocolhack.netty.VFNetworkManager;
import io.netty.channel.Channel;
import net.minecraft.network.NettyEncryptingDecoder;
import net.minecraft.network.NettyEncryptingEncoder;
import net.minecraft.network.NetworkManager;
import net.minecraft.util.CryptManager;
import net.minecraft.util.LazyLoadBase;
import net.minecraft.util.text.ITextComponent;
import net.raphimc.vialoader.netty.VLLegacyPipeline;
import net.raphimc.vialoader.util.VersionEnum;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
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.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import java.net.InetAddress;
@Mixin(NetworkManager.class)
public class MixinNetworkManager implements VFNetworkManager {
@Shadow private Channel channel;
@Unique
private Cipher viaForge$decryptionCipher;
@Unique
private VersionEnum viaForge$targetVersion;
@Inject(method = "connectToServer", at = @At(value = "INVOKE", target = "Lio/netty/bootstrap/Bootstrap;group(Lio/netty/channel/EventLoopGroup;)Lio/netty/bootstrap/AbstractBootstrap;"), locals = LocalCapture.CAPTURE_FAILHARD)
private static void trackSelfTarget(InetAddress address, int serverPort, boolean useNativeTransport, CallbackInfoReturnable<NetworkManager> cir, NetworkManager networkmanager, Class oclass, LazyLoadBase lazyloadbase) {
// The connecting screen and server pinger are setting the main target version when a specific version for a server is set,
// This works for joining perfect since we can simply restore the version when the server doesn't have a specific one set,
// but for the server pinger we need to store the target version and force the pinging to use the target version.
// Due to the fact that the server pinger is being called multiple times.
((VFNetworkManager) networkmanager).viaForge$setTrackedVersion(ViaForgeCommon.getManager().getTargetVersion());
}
@Inject(method = "setEncryptionKey", at = @At("HEAD"), cancellable = true)
private void storeEncryptionCiphers(SecretKey key, CallbackInfo ci) {
if (ViaForgeCommon.getManager().getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_6_4)) {
// Minecraft's encryption code is bad for us, we need to reorder the pipeline
ci.cancel();
// Minecraft 1.6.4 supports tile encryption which means the server can only disable one side of the encryption
// So we only enable the encryption side and later enable the decryption side if the 1.7 -> 1.6 protocol
// tells us to do, therefore we need to store the cipher instance.
this.viaForge$decryptionCipher = CryptManager.getCipher(2, key);
// Enabling the encryption side
this.channel.pipeline().addBefore(VLLegacyPipeline.VIALEGACY_PRE_NETTY_LENGTH_REMOVER_NAME, "encrypt", new NettyEncryptingEncoder(CryptManager.getCipher(1, key)));
}
}
@Inject(method = "disconnect", at = @At("HEAD"))
public void restoreTargetVersion(ITextComponent p_150718_1_, CallbackInfo ci) {
// If the previous server forced a version, we need to restore the version to the default one.
ViaForgeCommon.getManager().restoreVersion();
}
@Inject(method = "setupCompression", at = @At("RETURN"))
public void reorderPipeline(int p_setCompressionTreshold_1_, CallbackInfo ci) {
ViaForgeCommon.getManager().reorderCompression(channel);
}
@Override
public void viaForge$setupPreNettyDecryption() {
// Enabling the decryption side for 1.6.4 if the 1.7 -> 1.6 protocol tells us to do
this.channel.pipeline().addBefore(VLLegacyPipeline.VIALEGACY_PRE_NETTY_LENGTH_REMOVER_NAME, "decrypt", new NettyEncryptingDecoder(this.viaForge$decryptionCipher));
}
@Override
public VersionEnum viaForge$getTrackedVersion() {
return viaForge$targetVersion;
}
@Override
public void viaForge$setTrackedVersion(VersionEnum version) {
viaForge$targetVersion = version;
}
}

View File

@ -1,44 +0,0 @@
/*
* This file is part of ViaForge - https://github.com/FlorianMichael/ViaForge
* Copyright (C) 2021-2023 FlorianMichael/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.viaforge.mixin;
import de.florianmichael.viaforge.common.ViaForgeCommon;
import de.florianmichael.viaforge.common.protocolhack.netty.VFNetworkManager;
import io.netty.channel.Channel;
import net.minecraft.network.NetworkManager;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Mutable;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(targets = "net.minecraft.network.NetworkManager$1")
public class MixinNetworkManager_1 {
@Final
@Mutable
NetworkManager val$networkmanager;
@Inject(method = "initChannel", at = @At(value = "TAIL"), remap = false)
private void onInitChannel(Channel channel, CallbackInfo ci) {
ViaForgeCommon.getManager().inject(channel, (VFNetworkManager) val$networkmanager);
}
}

View File

@ -1,70 +0,0 @@
/*
* This file is part of ViaForge - https://github.com/FlorianMichael/ViaForge
* Copyright (C) 2021-2023 FlorianMichael/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.viaforge.mixin;
import de.florianmichael.viaforge.common.gui.ExtendedServerData;
import net.minecraft.client.multiplayer.ServerData;
import net.minecraft.nbt.CompoundNBT;
import net.raphimc.vialoader.util.VersionEnum;
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.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
@Mixin(ServerData.class)
public class MixinServerData implements ExtendedServerData {
@Unique
private VersionEnum viaForge$version;
@Inject(method = "write", at = @At(value = "INVOKE", target = "Lnet/minecraft/nbt/CompoundNBT;putString(Ljava/lang/String;Ljava/lang/String;)V", ordinal = 0), locals = LocalCapture.CAPTURE_FAILHARD)
public void saveVersion(CallbackInfoReturnable<CompoundNBT> cir, CompoundNBT compoundnbt) {
if (viaForge$version != null) {
compoundnbt.putInt("viaForge$version", viaForge$version.getVersion());
}
}
@Inject(method = "read", at = @At(value = "TAIL"))
private static void getVersion(CompoundNBT compoundnbt, CallbackInfoReturnable<ServerData> cir) {
if (compoundnbt.contains("viaForge$version")) {
((ExtendedServerData) cir.getReturnValue()).viaForge$setVersion(VersionEnum.fromProtocolId(compoundnbt.getInt("viaForge$version")));
}
}
@Inject(method = "copyFrom", at = @At("HEAD"))
public void track(ServerData serverDataIn, CallbackInfo ci) {
if (serverDataIn instanceof ExtendedServerData) {
viaForge$version = ((ExtendedServerData) serverDataIn).viaForge$getVersion();
}
}
@Override
public VersionEnum viaForge$getVersion() {
return viaForge$version;
}
@Override
public void viaForge$setVersion(VersionEnum version) {
viaForge$version = version;
}
}

View File

@ -1,51 +0,0 @@
/*
* This file is part of ViaForge - https://github.com/FlorianMichael/ViaForge
* Copyright (C) 2021-2023 FlorianMichael/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.viaforge.mixin;
import com.viaversion.viaversion.util.Pair;
import de.florianmichael.viaforge.common.ViaForgeCommon;
import de.florianmichael.viaforge.common.platform.ViaForgeConfig;
import de.florianmichael.viaforge.gui.GuiProtocolSelector;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.ServerListScreen;
import net.minecraft.client.gui.widget.button.Button;
import net.minecraft.util.text.ITextComponent;
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(ServerListScreen.class)
public class MixinServerListScreen extends Screen {
public MixinServerListScreen(ITextComponent title) {
super(title);
}
@Inject(method = "init", at = @At("RETURN"))
public void hookViaForgeButton(CallbackInfo ci) {
final ViaForgeConfig config = ViaForgeCommon.getManager().getConfig();
if (config.isShowDirectConnectButton()) {
final Pair<Integer, Integer> pos = config.getViaForgeButtonPosition().getPosition(this.width, this.height);
addButton(new Button(pos.key(), pos.value(), 100, 20, "ViaForge", b -> GuiProtocolSelector.open(minecraft)));
}
}
}

View File

@ -1,69 +0,0 @@
/*
* This file is part of ViaForge - https://github.com/FlorianMichael/ViaForge
* Copyright (C) 2021-2023 FlorianMichael/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.viaforge.mixin;
import de.florianmichael.viaforge.common.ViaForgeCommon;
import de.florianmichael.viaforge.common.gui.ExtendedServerData;
import net.minecraft.client.multiplayer.ServerData;
import net.minecraft.client.network.ServerPinger;
import net.minecraft.network.NetworkManager;
import net.raphimc.vialoader.util.VersionEnum;
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.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import java.net.InetAddress;
@Mixin(ServerPinger.class)
public class MixinServerPinger {
@Unique
private ServerData viaForge$serverData;
@Inject(method = "pingServer", at = @At("HEAD"))
public void trackServerData(ServerData server, CallbackInfo ci) {
viaForge$serverData = server;
}
@Redirect(method = "pingServer", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/NetworkManager;connectToServer(Ljava/net/InetAddress;IZ)Lnet/minecraft/network/NetworkManager;"))
public NetworkManager trackVersion(InetAddress address, int i, boolean b) {
// We need to track the version of the server we are connecting to, so we can later
// use it to determine the protocol version to use.
// We hope that the current server data is not null
if (viaForge$serverData instanceof ExtendedServerData) {
final VersionEnum version = ((ExtendedServerData) viaForge$serverData).viaForge$getVersion();
if (version != null) {
ViaForgeCommon.getManager().setTargetVersionSilent(version);
} else {
// If the server data does not contain a version, we need to restore the version
// we had before, so we don't use the wrong version.
ViaForgeCommon.getManager().restoreVersion();
}
viaForge$serverData = null;
}
return NetworkManager.connectToServer(address, i, b);
}
}

View File

@ -1,56 +0,0 @@
/*
* This file is part of ViaForge - https://github.com/FlorianMichael/ViaForge
* Copyright (C) 2021-2023 FlorianMichael/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.viaforge.mixin.fixes;
import com.mojang.authlib.GameProfile;
import de.florianmichael.viaforge.common.ViaForgeCommon;
import net.minecraft.client.entity.player.AbstractClientPlayerEntity;
import net.minecraft.client.entity.player.ClientPlayerEntity;
import net.minecraft.client.world.ClientWorld;
import net.raphimc.vialoader.util.VersionEnum;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
@Mixin(ClientPlayerEntity.class)
public class MixinClientPlayerEntity extends AbstractClientPlayerEntity {
@Shadow private boolean lastOnGround;
public MixinClientPlayerEntity(ClientWorld world, GameProfile profile) {
super(world, profile);
}
@Redirect(method = "sendPosition", at = @At(value = "FIELD", target = "Lnet/minecraft/client/entity/player/ClientPlayerEntity;lastOnGround:Z", ordinal = 0))
public boolean emulateIdlePacket(ClientPlayerEntity instance) {
if (ViaForgeCommon.getManager().getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_8)) {
// <= 1.8 spams the idle packet instead of only sending it when the ground state changes
// So we invert the original logic:
// if (prevOnGround != onGround) sendPacket
// To be like:
// if (!onGround != onGround) sendPacket
// Which is the same as:
// if (true) sendPacket
return !onGround;
}
return lastOnGround;
}
}

View File

@ -1,77 +0,0 @@
/*
* This file is part of ViaForge - https://github.com/FlorianMichael/ViaForge
* Copyright (C) 2021-2023 FlorianMichael/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.viaforge.provider;
import com.mojang.authlib.Agent;
import com.mojang.authlib.GameProfileRepository;
import com.mojang.authlib.HttpAuthenticationService;
import com.mojang.authlib.ProfileLookupCallback;
import com.mojang.authlib.minecraft.MinecraftSessionService;
import com.mojang.authlib.properties.Property;
import com.mojang.authlib.yggdrasil.ProfileNotFoundException;
import com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService;
import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.model.GameProfile;
import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.providers.GameProfileFetcher;
import java.net.Proxy;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
public class ViaForgeGameProfileFetcher extends GameProfileFetcher {
public static final HttpAuthenticationService AUTHENTICATION_SERVICE = new YggdrasilAuthenticationService(Proxy.NO_PROXY, "");
public static final MinecraftSessionService SESSION_SERVICE = AUTHENTICATION_SERVICE.createMinecraftSessionService();
public static final GameProfileRepository GAME_PROFILE_REPOSITORY = AUTHENTICATION_SERVICE.createProfileRepository();
@Override
public UUID loadMojangUUID(String playerName) throws Exception {
final CompletableFuture<com.mojang.authlib.GameProfile> future = new CompletableFuture<>();
GAME_PROFILE_REPOSITORY.findProfilesByNames(new String[]{playerName}, Agent.MINECRAFT, new ProfileLookupCallback() {
@Override
public void onProfileLookupSucceeded(com.mojang.authlib.GameProfile profile) {
future.complete(profile);
}
@Override
public void onProfileLookupFailed(com.mojang.authlib.GameProfile profile, Exception exception) {
future.completeExceptionally(exception);
}
});
if (!future.isDone()) {
future.completeExceptionally(new ProfileNotFoundException());
}
return future.get().getId();
}
@Override
public GameProfile loadGameProfile(UUID uuid) throws Exception {
final com.mojang.authlib.GameProfile inProfile = new com.mojang.authlib.GameProfile(uuid, null);
final com.mojang.authlib.GameProfile mojangProfile = SESSION_SERVICE.fillProfileProperties(inProfile, true);
if (mojangProfile.equals(inProfile)) throw new ProfileNotFoundException();
final GameProfile gameProfile = new GameProfile(mojangProfile.getName(), mojangProfile.getId());
for (final java.util.Map.Entry<String, Property> entry : mojangProfile.getProperties().entries()) {
final Property prop = entry.getValue();
gameProfile.addProperty(new GameProfile.Property(prop.getName(), prop.getValue(), prop.getSignature()));
}
return gameProfile;
}
}

View File

@ -1,27 +0,0 @@
{
"required": true,
"minVersion": "0.7.5",
"compatibilityLevel": "JAVA_8",
"package": "de.florianmichael.viaforge.mixin",
"client": [
"MixinAddServerScreen",
"MixinClientLoginNetHandler",
"MixinConnectingScreen_1",
"MixinDebugOverlayGui",
"MixinMainMenuScreen",
"MixinMultiplayerScreen",
"MixinNetworkManager",
"MixinNetworkManager_1",
"MixinServerData",
"MixinServerListScreen",
"MixinServerPinger",
"fixes.MixinClientPlayerEntity"
],
"injectors": {
"defaultRequire": 1
},
"refmap": "mixins.viaforge-mc114.refmap.json",
"mixins": [
"MixinNetworkManager_1"
]
}

View File

@ -1,11 +0,0 @@
plugins {
id "viaforge.forge-conventions"
}
minecraft {
mappings channel: "official", version: "1.15.2"
}
dependencies {
minecraft "net.minecraftforge:forge:1.15.2-31.2.57"
}

View File

@ -1,2 +0,0 @@
maven_name=viaforge-mc115
mc_version=1.15.2

View File

@ -1,64 +0,0 @@
/*
* This file is part of ViaForge - https://github.com/FlorianMichael/ViaForge
* Copyright (C) 2021-2023 FlorianMichael/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.viaforge;
import de.florianmichael.viaforge.common.platform.VFPlatform;
import de.florianmichael.viaforge.provider.ViaForgeGameProfileFetcher;
import net.minecraft.client.Minecraft;
import net.minecraft.util.Session;
import net.minecraft.util.SharedConstants;
import net.minecraftforge.fml.common.Mod;
import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.providers.GameProfileFetcher;
import java.io.File;
import java.util.function.Supplier;
@Mod("viaforge")
public class ViaForge115 implements VFPlatform {
public static final ViaForge115 PLATFORM = new ViaForge115();
@Override
public int getGameVersion() {
return SharedConstants.getCurrentVersion().getProtocolVersion();
}
@Override
public Supplier<Boolean> isSingleplayer() {
return () -> Minecraft.getInstance().hasSingleplayerServer();
}
@Override
public File getLeadingDirectory() {
return Minecraft.getInstance().gameDirectory;
}
@Override
public void joinServer(String serverId) throws Throwable {
final Session session = Minecraft.getInstance().getUser();
Minecraft.getInstance().getMinecraftSessionService().joinServer(session.getGameProfile(), session.getAccessToken(), serverId);
}
@Override
public GameProfileFetcher getGameProfileFetcher() {
return new ViaForgeGameProfileFetcher();
}
}

View File

@ -1,165 +0,0 @@
/*
* This file is part of ViaForge - https://github.com/FlorianMichael/ViaForge
* Copyright (C) 2021-2023 FlorianMichael/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.viaforge.gui;
import com.mojang.realmsclient.gui.ChatFormatting;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.util.DumpUtil;
import de.florianmichael.viaforge.common.ViaForgeCommon;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.button.Button;
import net.minecraft.client.gui.widget.list.AbstractList;
import net.minecraft.client.gui.widget.list.ExtendedList;
import net.minecraft.util.text.StringTextComponent;
import net.raphimc.vialoader.util.VersionEnum;
import org.lwjgl.glfw.GLFW;
import org.lwjgl.opengl.GL11;
import java.util.UUID;
import java.util.concurrent.ExecutionException;
public class GuiProtocolSelector extends Screen {
public final Screen parent;
public final boolean simple;
public final FinishedCallback finishedCallback;
private SlotList list;
private String status;
private long time;
public static void open(final Minecraft minecraft) { // Bypass for some weird bytecode instructions errors in Forge
minecraft.setScreen(new GuiProtocolSelector(minecraft.screen));
}
public GuiProtocolSelector(final Screen parent) {
this(parent, false, (version, unused) -> {
// Default action is to set the target version and go back to the parent screen.
ViaForgeCommon.getManager().setTargetVersion(version);
});
}
public GuiProtocolSelector(final Screen parent, final boolean simple, final FinishedCallback finishedCallback) {
super(new StringTextComponent("ViaForge Protocol Selector"));
this.parent = parent;
this.simple = simple;
this.finishedCallback = finishedCallback;
}
@Override
public void init() {
super.init();
addButton(new Button(5, height - 25, 20, 20, "<-", b -> minecraft.setScreen(parent)));
if (!this.simple) {
addButton(new Button(width - 105, 5, 100, 20, "Create dump", b -> {
try {
minecraft.keyboardHandler.setClipboard(DumpUtil.postDump(UUID.randomUUID()).get());
setStatus(ChatFormatting.GREEN + "Dump created and copied to clipboard");
} catch (InterruptedException | ExecutionException e) {
setStatus(ChatFormatting.RED + "Failed to create dump: " + e.getMessage());
}
}));
addButton(new Button(width - 105, height - 25, 100, 20, "Reload configs", b -> Via.getManager().getConfigurationProvider().reloadConfigs()));
}
list = new SlotList(minecraft, width, height, 3 + 3 /* start offset */ + (font.lineHeight + 2) * 3 /* title is 2 */, height - 30, font.lineHeight + 2);
}
public void setStatus(final String status) {
this.status = status;
this.time = System.currentTimeMillis();
}
@Override
public boolean keyPressed(int keyCode, int scanCode, int actions) {
if (keyCode == GLFW.GLFW_KEY_ESCAPE) {
minecraft.setScreen(parent);
}
return super.keyPressed(keyCode, scanCode, actions);
}
@Override
public void render(int p_230430_2_, int p_230430_3_, float p_230430_4_) {
if (System.currentTimeMillis() - this.time >= 10_000) {
this.status = null;
}
renderBackground();
this.list.render(p_230430_2_, p_230430_3_, p_230430_4_);
super.render(p_230430_2_, p_230430_3_, p_230430_4_);
GL11.glPushMatrix();
GL11.glScalef(2.0F, 2.0F, 2.0F);
drawCenteredString(font, ChatFormatting.GOLD + "ViaForge", width / 4, 3, 16777215);
GL11.glPopMatrix();
drawCenteredString(font, "https://github.com/ViaVersion/ViaForge", width / 2, (font.lineHeight + 2) * 2 + 3, -1);
drawString(font, status != null ? status : "Discord: florianmichael", 3, 3, -1);
}
class SlotList extends ExtendedList<SlotList.SlotEntry> {
public SlotList(Minecraft client, int width, int height, int top, int bottom, int slotHeight) {
super(client, width, height, top, bottom, slotHeight);
for (VersionEnum version : VersionEnum.SORTED_VERSIONS) {
addEntry(new SlotEntry(version));
}
}
public class SlotEntry extends AbstractList.AbstractListEntry<SlotEntry> {
private final VersionEnum versionEnum;
public SlotEntry(VersionEnum versionEnum) {
this.versionEnum = versionEnum;
}
@Override
public boolean mouseClicked(double mouseX, double mouseY, int button) {
GuiProtocolSelector.this.finishedCallback.finished(versionEnum, GuiProtocolSelector.this.parent);
return super.mouseClicked(mouseX, mouseY, button);
}
@Override
public void render(int p_230432_2_, int y, int p_230432_4_, int p_230432_5_, int p_230432_6_, int p_230432_7_, int p_230432_8_, boolean p_230432_9_, float p_230432_10_) {
final VersionEnum targetVersion = ViaForgeCommon.getManager().getTargetVersion();
String color;
if (targetVersion == versionEnum) {
color = GuiProtocolSelector.this.simple ? ChatFormatting.GOLD.toString() : ChatFormatting.GREEN.toString();
} else {
color = GuiProtocolSelector.this.simple ? ChatFormatting.WHITE.toString() : ChatFormatting.DARK_RED.toString();
}
drawCenteredString(Minecraft.getInstance().font, color + versionEnum.getName(), width / 2, y, -1);
}
}
}
public interface FinishedCallback {
void finished(final VersionEnum version, final Screen parent);
}
}

View File

@ -1,66 +0,0 @@
/*
* This file is part of ViaForge - https://github.com/FlorianMichael/ViaForge
* Copyright (C) 2021-2023 FlorianMichael/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.viaforge.mixin;
import com.viaversion.viaversion.util.Pair;
import de.florianmichael.viaforge.common.ViaForgeCommon;
import de.florianmichael.viaforge.common.gui.ExtendedServerData;
import de.florianmichael.viaforge.common.platform.ViaForgeConfig;
import de.florianmichael.viaforge.gui.GuiProtocolSelector;
import net.minecraft.client.gui.screen.AddServerScreen;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.button.Button;
import net.minecraft.client.multiplayer.ServerData;
import net.minecraft.util.text.ITextComponent;
import net.raphimc.vialoader.util.VersionEnum;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(AddServerScreen.class)
public class MixinAddServerScreen extends Screen {
@Shadow @Final private ServerData serverData;
public MixinAddServerScreen(ITextComponent title) {
super(title);
}
@Inject(method = "init", at = @At("RETURN"))
public void initGui(CallbackInfo ci) {
final ViaForgeConfig config = ViaForgeCommon.getManager().getConfig();
if (config.isShowAddServerButton()) {
final Pair<Integer, Integer> pos = config.getAddServerScreenButtonPosition().getPosition(this.width, this.height);
final VersionEnum target = ((ExtendedServerData) serverData).viaForge$getVersion();
addButton(new Button(pos.key(), pos.value(), 100, 20, target != null ? target.getName() : "Set Version", b -> {
minecraft.setScreen(new GuiProtocolSelector(this, true, (version, parent) -> {
// Set version and go back to the parent screen.
((ExtendedServerData) serverData).viaForge$setVersion(version);
minecraft.setScreen(parent);
}));
}));
}
}
}

View File

@ -1,56 +0,0 @@
/*
* This file is part of ViaForge - https://github.com/FlorianMichael/ViaForge
* Copyright (C) 2021-2023 FlorianMichael/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.viaforge.mixin;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.exceptions.AuthenticationException;
import com.mojang.authlib.minecraft.MinecraftSessionService;
import com.viaversion.viaversion.api.connection.UserConnection;
import de.florianmichael.viaforge.common.ViaForgeCommon;
import net.minecraft.client.network.login.ClientLoginNetHandler;
import net.minecraft.network.NetworkManager;
import net.raphimc.vialegacy.protocols.release.protocol1_7_2_5to1_6_4.storage.ProtocolMetadataStorage;
import net.raphimc.vialoader.util.VersionEnum;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
@SuppressWarnings("DataFlowIssue")
@Mixin(ClientLoginNetHandler.class)
public class MixinClientLoginNetHandler {
@Shadow @Final private NetworkManager connection;
@Redirect(method = "authenticateServer", at = @At(value = "INVOKE", target = "Lcom/mojang/authlib/minecraft/MinecraftSessionService;joinServer(Lcom/mojang/authlib/GameProfile;Ljava/lang/String;Ljava/lang/String;)V"))
public void onlyJoinServerIfPremium(MinecraftSessionService instance, GameProfile profile, String authenticationToken, String serverId) throws AuthenticationException {
if (ViaForgeCommon.getManager().getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_6_4)) {
final UserConnection user = connection.channel().attr(ViaForgeCommon.LOCAL_VIA_USER).get();
if (user != null && user.has(ProtocolMetadataStorage.class) && !user.get(ProtocolMetadataStorage.class).authenticate) {
// We are in the 1.7 -> 1.6 protocol, so we need to skip the joinServer call
// if the server is in offline mode, due the packet changes <-> networking changes
// Minecraft's networking code is bad for us.
return;
}
}
instance.joinServer(profile, authenticationToken, serverId);
}
}

View File

@ -1,54 +0,0 @@
/*
* This file is part of ViaForge - https://github.com/FlorianMichael/ViaForge
* Copyright (C) 2021-2023 FlorianMichael/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.viaforge.mixin;
import de.florianmichael.viaforge.common.ViaForgeCommon;
import de.florianmichael.viaforge.common.gui.ExtendedServerData;
import net.minecraft.client.Minecraft;
import net.minecraft.network.NetworkManager;
import net.raphimc.vialoader.util.VersionEnum;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
import java.net.InetAddress;
@Mixin(targets = "net.minecraft.client.gui.screen.ConnectingScreen$1")
public class MixinConnectingScreen_1 {
@Redirect(method = "run", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/NetworkManager;connectToServer(Ljava/net/InetAddress;IZ)Lnet/minecraft/network/NetworkManager;"))
public NetworkManager trackVersion(InetAddress address, int i, boolean b) {
// We need to track the version of the server we are connecting to, so we can later
// use it to determine the protocol version to use.
// We hope that the current server data is not null
if (Minecraft.getInstance().getCurrentServer() instanceof ExtendedServerData) {
final VersionEnum version = ((ExtendedServerData) Minecraft.getInstance().getCurrentServer()).viaForge$getVersion();
if (version != null) {
ViaForgeCommon.getManager().setTargetVersionSilent(version);
} else {
// If the server data does not contain a version, we need to restore the version
// we had before, so we don't use the wrong version.
ViaForgeCommon.getManager().restoreVersion();
}
}
return NetworkManager.connectToServer(address, i, b);
}
}

View File

@ -1,54 +0,0 @@
/*
* This file is part of ViaForge - https://github.com/FlorianMichael/ViaForge
* Copyright (C) 2021-2023 FlorianMichael/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.viaforge.mixin;
import de.florianmichael.viaforge.common.ViaForgeCommon;
import net.minecraft.client.gui.overlay.DebugOverlayGui;
import net.raphimc.vialegacy.api.LegacyProtocolVersion;
import net.raphimc.vialoader.util.VersionEnum;
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;
import java.util.List;
@Mixin(DebugOverlayGui.class)
public class MixinDebugOverlayGui {
@Inject(method = "getSystemInformation", at = @At(value = "TAIL"))
public void addViaForgeVersion(CallbackInfoReturnable<List<String>> cir) {
final ViaForgeCommon common = ViaForgeCommon.getManager();
final VersionEnum version = ViaForgeCommon.getManager().getTargetVersion();
if (common.getConfig().isShowProtocolVersionInF3() && version != common.getNativeVersion() && !common.getPlatform().isSingleplayer().get()) {
cir.getReturnValue().add("");
int protocolVersion = version.getVersion();
if (version.isOlderThanOrEqualTo(VersionEnum.r1_6_4)) {
// Older versions (<= 1.6.4) are using fake ids in ViaLegacy to prevent version duplications / mismatches
// So we need to unmap the version to get the real protocol version id
protocolVersion = LegacyProtocolVersion.getRealProtocolVersion(protocolVersion);
}
cir.getReturnValue().add("ViaForge: " + version.getName() + " (" + protocolVersion + ")");
}
}
}

View File

@ -1,54 +0,0 @@
/*
* This file is part of ViaForge - https://github.com/FlorianMichael/ViaForge
* Copyright (C) 2021-2023 FlorianMichael/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.viaforge.mixin;
import com.viaversion.viaversion.util.Pair;
import de.florianmichael.viaforge.ViaForge115;
import de.florianmichael.viaforge.common.ViaForgeCommon;
import de.florianmichael.viaforge.common.platform.ViaForgeConfig;
import de.florianmichael.viaforge.gui.GuiProtocolSelector;
import net.minecraft.client.gui.screen.MainMenuScreen;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.button.Button;
import net.minecraft.util.text.ITextComponent;
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(MainMenuScreen.class)
public class MixinMainMenuScreen extends Screen {
public MixinMainMenuScreen(ITextComponent title) {
super(title);
}
@Inject(method = "init", at = @At("RETURN"))
public void hookViaForgeButton(CallbackInfo ci) {
ViaForgeCommon.init(ViaForge115.PLATFORM);
final ViaForgeConfig config = ViaForgeCommon.getManager().getConfig();
if (config.isShowMainMenuButton()) {
final Pair<Integer, Integer> pos = config.getViaForgeButtonPosition().getPosition(this.width, this.height);
addButton(new Button(pos.key(), pos.value(), 100, 20, "ViaForge", buttons -> GuiProtocolSelector.open(minecraft)));
}
}
}

View File

@ -1,51 +0,0 @@
/*
* This file is part of ViaForge - https://github.com/FlorianMichael/ViaForge
* Copyright (C) 2021-2023 FlorianMichael/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.viaforge.mixin;
import com.viaversion.viaversion.util.Pair;
import de.florianmichael.viaforge.common.ViaForgeCommon;
import de.florianmichael.viaforge.common.platform.ViaForgeConfig;
import de.florianmichael.viaforge.gui.GuiProtocolSelector;
import net.minecraft.client.gui.screen.MultiplayerScreen;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.button.Button;
import net.minecraft.util.text.ITextComponent;
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(MultiplayerScreen.class)
public class MixinMultiplayerScreen extends Screen {
public MixinMultiplayerScreen(ITextComponent title) {
super(title);
}
@Inject(method = "init", at = @At("RETURN"))
public void hookViaForgeButton(CallbackInfo ci) {
final ViaForgeConfig config = ViaForgeCommon.getManager().getConfig();
if (config.isShowMainMenuButton()) {
final Pair<Integer, Integer> pos = config.getViaForgeButtonPosition().getPosition(this.width, this.height);
addButton(new Button(pos.key(), pos.value(), 100, 20, "ViaForge", buttons -> GuiProtocolSelector.open(minecraft)));
}
}
}

View File

@ -1,108 +0,0 @@
/*
* This file is part of ViaForge - https://github.com/FlorianMichael/ViaForge
* Copyright (C) 2021-2023 FlorianMichael/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.viaforge.mixin;
import de.florianmichael.viaforge.common.ViaForgeCommon;
import de.florianmichael.viaforge.common.protocolhack.netty.VFNetworkManager;
import io.netty.channel.Channel;
import net.minecraft.network.NettyEncryptingDecoder;
import net.minecraft.network.NettyEncryptingEncoder;
import net.minecraft.network.NetworkManager;
import net.minecraft.util.CryptManager;
import net.minecraft.util.LazyValue;
import net.minecraft.util.text.ITextComponent;
import net.raphimc.vialoader.netty.VLLegacyPipeline;
import net.raphimc.vialoader.util.VersionEnum;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
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.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import java.net.InetAddress;
@Mixin(NetworkManager.class)
public class MixinNetworkManager implements VFNetworkManager {
@Shadow private Channel channel;
@Unique
private Cipher viaForge$decryptionCipher;
@Unique
private VersionEnum viaForge$targetVersion;
@Inject(method = "connectToServer", at = @At(value = "INVOKE", target = "Lio/netty/bootstrap/Bootstrap;group(Lio/netty/channel/EventLoopGroup;)Lio/netty/bootstrap/AbstractBootstrap;"), locals = LocalCapture.CAPTURE_FAILHARD)
private static void trackSelfTarget(InetAddress p_181124_0_, int p_181124_1_, boolean p_181124_2_, CallbackInfoReturnable<NetworkManager> cir, NetworkManager networkmanager, Class oclass, LazyValue lazyvalue) {
// The connecting screen and server pinger are setting the main target version when a specific version for a server is set,
// This works for joining perfect since we can simply restore the version when the server doesn't have a specific one set,
// but for the server pinger we need to store the target version and force the pinging to use the target version.
// Due to the fact that the server pinger is being called multiple times.
((VFNetworkManager) networkmanager).viaForge$setTrackedVersion(ViaForgeCommon.getManager().getTargetVersion());
}
@Inject(method = "setEncryptionKey", at = @At("HEAD"), cancellable = true)
private void storeEncryptionCiphers(SecretKey key, CallbackInfo ci) {
if (ViaForgeCommon.getManager().getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_6_4)) {
// Minecraft's encryption code is bad for us, we need to reorder the pipeline
ci.cancel();
// Minecraft 1.6.4 supports tile encryption which means the server can only disable one side of the encryption
// So we only enable the encryption side and later enable the decryption side if the 1.7 -> 1.6 protocol
// tells us to do, therefore we need to store the cipher instance.
this.viaForge$decryptionCipher = CryptManager.getCipher(2, key);
// Enabling the encryption side
this.channel.pipeline().addBefore(VLLegacyPipeline.VIALEGACY_PRE_NETTY_LENGTH_REMOVER_NAME, "encrypt", new NettyEncryptingEncoder(CryptManager.getCipher(1, key)));
}
}
@Inject(method = "disconnect", at = @At("HEAD"))
public void restoreTargetVersion(ITextComponent p_150718_1_, CallbackInfo ci) {
// If the previous server forced a version, we need to restore the version to the default one.
ViaForgeCommon.getManager().restoreVersion();
}
@Inject(method = "setupCompression", at = @At("RETURN"))
public void reorderPipeline(int p_setCompressionTreshold_1_, CallbackInfo ci) {
ViaForgeCommon.getManager().reorderCompression(channel);
}
@Override
public void viaForge$setupPreNettyDecryption() {
// Enabling the decryption side for 1.6.4 if the 1.7 -> 1.6 protocol tells us to do
this.channel.pipeline().addBefore(VLLegacyPipeline.VIALEGACY_PRE_NETTY_LENGTH_REMOVER_NAME, "decrypt", new NettyEncryptingDecoder(this.viaForge$decryptionCipher));
}
@Override
public VersionEnum viaForge$getTrackedVersion() {
return viaForge$targetVersion;
}
@Override
public void viaForge$setTrackedVersion(VersionEnum version) {
viaForge$targetVersion = version;
}
}

View File

@ -1,44 +0,0 @@
/*
* This file is part of ViaForge - https://github.com/FlorianMichael/ViaForge
* Copyright (C) 2021-2023 FlorianMichael/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.viaforge.mixin;
import de.florianmichael.viaforge.common.ViaForgeCommon;
import de.florianmichael.viaforge.common.protocolhack.netty.VFNetworkManager;
import io.netty.channel.Channel;
import net.minecraft.network.NetworkManager;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Mutable;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(targets = "net.minecraft.network.NetworkManager$1")
public class MixinNetworkManager_1 {
@Final
@Mutable
NetworkManager val$networkmanager;
@Inject(method = "initChannel", at = @At(value = "TAIL"), remap = false)
private void onInitChannel(Channel channel, CallbackInfo ci) {
ViaForgeCommon.getManager().inject(channel, (VFNetworkManager) val$networkmanager);
}
}

View File

@ -1,70 +0,0 @@
/*
* This file is part of ViaForge - https://github.com/FlorianMichael/ViaForge
* Copyright (C) 2021-2023 FlorianMichael/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.viaforge.mixin;
import de.florianmichael.viaforge.common.gui.ExtendedServerData;
import net.minecraft.client.multiplayer.ServerData;
import net.minecraft.nbt.CompoundNBT;
import net.raphimc.vialoader.util.VersionEnum;
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.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
@Mixin(ServerData.class)
public class MixinServerData implements ExtendedServerData {
@Unique
private VersionEnum viaForge$version;
@Inject(method = "write", at = @At(value = "INVOKE", target = "Lnet/minecraft/nbt/CompoundNBT;putString(Ljava/lang/String;Ljava/lang/String;)V", ordinal = 0), locals = LocalCapture.CAPTURE_FAILHARD)
public void saveVersion(CallbackInfoReturnable<CompoundNBT> cir, CompoundNBT compoundnbt) {
if (viaForge$version != null) {
compoundnbt.putInt("viaForge$version", viaForge$version.getVersion());
}
}
@Inject(method = "read", at = @At(value = "TAIL"))
private static void getVersion(CompoundNBT compoundnbt, CallbackInfoReturnable<ServerData> cir) {
if (compoundnbt.contains("viaForge$version")) {
((ExtendedServerData) cir.getReturnValue()).viaForge$setVersion(VersionEnum.fromProtocolId(compoundnbt.getInt("viaForge$version")));
}
}
@Inject(method = "copyFrom", at = @At("HEAD"))
public void track(ServerData serverDataIn, CallbackInfo ci) {
if (serverDataIn instanceof ExtendedServerData) {
viaForge$version = ((ExtendedServerData) serverDataIn).viaForge$getVersion();
}
}
@Override
public VersionEnum viaForge$getVersion() {
return viaForge$version;
}
@Override
public void viaForge$setVersion(VersionEnum version) {
viaForge$version = version;
}
}

View File

@ -1,51 +0,0 @@
/*
* This file is part of ViaForge - https://github.com/FlorianMichael/ViaForge
* Copyright (C) 2021-2023 FlorianMichael/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.viaforge.mixin;
import com.viaversion.viaversion.util.Pair;
import de.florianmichael.viaforge.common.ViaForgeCommon;
import de.florianmichael.viaforge.common.platform.ViaForgeConfig;
import de.florianmichael.viaforge.gui.GuiProtocolSelector;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.ServerListScreen;
import net.minecraft.client.gui.widget.button.Button;
import net.minecraft.util.text.ITextComponent;
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(ServerListScreen.class)
public class MixinServerListScreen extends Screen {
public MixinServerListScreen(ITextComponent title) {
super(title);
}
@Inject(method = "init", at = @At("RETURN"))
public void hookViaForgeButton(CallbackInfo ci) {
final ViaForgeConfig config = ViaForgeCommon.getManager().getConfig();
if (config.isShowDirectConnectButton()) {
final Pair<Integer, Integer> pos = config.getViaForgeButtonPosition().getPosition(this.width, this.height);
addButton(new Button(pos.key(), pos.value(), 100, 20, "ViaForge", b -> GuiProtocolSelector.open(minecraft)));
}
}
}

View File

@ -1,69 +0,0 @@
/*
* This file is part of ViaForge - https://github.com/FlorianMichael/ViaForge
* Copyright (C) 2021-2023 FlorianMichael/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.viaforge.mixin;
import de.florianmichael.viaforge.common.ViaForgeCommon;
import de.florianmichael.viaforge.common.gui.ExtendedServerData;
import net.minecraft.client.multiplayer.ServerData;
import net.minecraft.client.network.ServerPinger;
import net.minecraft.network.NetworkManager;
import net.raphimc.vialoader.util.VersionEnum;
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.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import java.net.InetAddress;
@Mixin(ServerPinger.class)
public class MixinServerPinger {
@Unique
private ServerData viaForge$serverData;
@Inject(method = "pingServer", at = @At("HEAD"))
public void trackServerData(ServerData server, CallbackInfo ci) {
viaForge$serverData = server;
}
@Redirect(method = "pingServer", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/NetworkManager;connectToServer(Ljava/net/InetAddress;IZ)Lnet/minecraft/network/NetworkManager;"))
public NetworkManager trackVersion(InetAddress address, int i, boolean b) {
// We need to track the version of the server we are connecting to, so we can later
// use it to determine the protocol version to use.
// We hope that the current server data is not null
if (viaForge$serverData instanceof ExtendedServerData) {
final VersionEnum version = ((ExtendedServerData) viaForge$serverData).viaForge$getVersion();
if (version != null) {
ViaForgeCommon.getManager().setTargetVersionSilent(version);
} else {
// If the server data does not contain a version, we need to restore the version
// we had before, so we don't use the wrong version.
ViaForgeCommon.getManager().restoreVersion();
}
viaForge$serverData = null;
}
return NetworkManager.connectToServer(address, i, b);
}
}

View File

@ -1,56 +0,0 @@
/*
* This file is part of ViaForge - https://github.com/FlorianMichael/ViaForge
* Copyright (C) 2021-2023 FlorianMichael/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.viaforge.mixin.fixes;
import com.mojang.authlib.GameProfile;
import de.florianmichael.viaforge.common.ViaForgeCommon;
import net.minecraft.client.entity.player.AbstractClientPlayerEntity;
import net.minecraft.client.entity.player.ClientPlayerEntity;
import net.minecraft.client.world.ClientWorld;
import net.raphimc.vialoader.util.VersionEnum;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
@Mixin(ClientPlayerEntity.class)
public class MixinClientPlayerEntity extends AbstractClientPlayerEntity {
@Shadow private boolean lastOnGround;
public MixinClientPlayerEntity(ClientWorld world, GameProfile profile) {
super(world, profile);
}
@Redirect(method = "sendPosition", at = @At(value = "FIELD", target = "Lnet/minecraft/client/entity/player/ClientPlayerEntity;lastOnGround:Z", ordinal = 0))
public boolean emulateIdlePacket(ClientPlayerEntity instance) {
if (ViaForgeCommon.getManager().getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_8)) {
// <= 1.8 spams the idle packet instead of only sending it when the ground state changes
// So we invert the original logic:
// if (prevOnGround != onGround) sendPacket
// To be like:
// if (!onGround != onGround) sendPacket
// Which is the same as:
// if (true) sendPacket
return !onGround;
}
return lastOnGround;
}
}

View File

@ -1,77 +0,0 @@
/*
* This file is part of ViaForge - https://github.com/FlorianMichael/ViaForge
* Copyright (C) 2021-2023 FlorianMichael/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.viaforge.provider;
import com.mojang.authlib.Agent;
import com.mojang.authlib.GameProfileRepository;
import com.mojang.authlib.HttpAuthenticationService;
import com.mojang.authlib.ProfileLookupCallback;
import com.mojang.authlib.minecraft.MinecraftSessionService;
import com.mojang.authlib.properties.Property;
import com.mojang.authlib.yggdrasil.ProfileNotFoundException;
import com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService;
import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.model.GameProfile;
import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.providers.GameProfileFetcher;
import java.net.Proxy;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
public class ViaForgeGameProfileFetcher extends GameProfileFetcher {
public static final HttpAuthenticationService AUTHENTICATION_SERVICE = new YggdrasilAuthenticationService(Proxy.NO_PROXY, "");
public static final MinecraftSessionService SESSION_SERVICE = AUTHENTICATION_SERVICE.createMinecraftSessionService();
public static final GameProfileRepository GAME_PROFILE_REPOSITORY = AUTHENTICATION_SERVICE.createProfileRepository();
@Override
public UUID loadMojangUUID(String playerName) throws Exception {
final CompletableFuture<com.mojang.authlib.GameProfile> future = new CompletableFuture<>();
GAME_PROFILE_REPOSITORY.findProfilesByNames(new String[]{playerName}, Agent.MINECRAFT, new ProfileLookupCallback() {
@Override
public void onProfileLookupSucceeded(com.mojang.authlib.GameProfile profile) {
future.complete(profile);
}
@Override
public void onProfileLookupFailed(com.mojang.authlib.GameProfile profile, Exception exception) {
future.completeExceptionally(exception);
}
});
if (!future.isDone()) {
future.completeExceptionally(new ProfileNotFoundException());
}
return future.get().getId();
}
@Override
public GameProfile loadGameProfile(UUID uuid) throws Exception {
final com.mojang.authlib.GameProfile inProfile = new com.mojang.authlib.GameProfile(uuid, null);
final com.mojang.authlib.GameProfile mojangProfile = SESSION_SERVICE.fillProfileProperties(inProfile, true);
if (mojangProfile.equals(inProfile)) throw new ProfileNotFoundException();
final GameProfile gameProfile = new GameProfile(mojangProfile.getName(), mojangProfile.getId());
for (final java.util.Map.Entry<String, Property> entry : mojangProfile.getProperties().entries()) {
final Property prop = entry.getValue();
gameProfile.addProperty(new GameProfile.Property(prop.getName(), prop.getValue(), prop.getSignature()));
}
return gameProfile;
}
}

View File

@ -1,24 +0,0 @@
{
"required": true,
"minVersion": "0.7.5",
"compatibilityLevel": "JAVA_8",
"package": "de.florianmichael.viaforge.mixin",
"client": [
"MixinAddServerScreen",
"MixinClientLoginNetHandler",
"MixinConnectingScreen_1",
"MixinDebugOverlayGui",
"MixinMainMenuScreen",
"MixinMultiplayerScreen",
"MixinNetworkManager",
"MixinNetworkManager_1",
"MixinServerData",
"MixinServerListScreen",
"MixinServerPinger",
"fixes.MixinClientPlayerEntity"
],
"injectors": {
"defaultRequire": 1
},
"refmap": "mixins.viaforge-mc115.refmap.json"
}

View File

@ -1,8 +1,3 @@
plugins {
id "viaforge.forge-conventions"
id "viaforge.conflicting-conventions"
}
minecraft { minecraft {
mappings channel: "official", version: "1.16.5" mappings channel: "official", version: "1.16.5"
} }

View File

@ -1,2 +1,3 @@
maven_name=viaforge-mc116 maven_name=viaforge-mc116
mc_version=1.16.5 mc_version=1.16.5
sub_module_increment=1

View File

@ -1,5 +1,5 @@
modLoader="javafml" modLoader="javafml"
loaderVersion="[1,)" loaderVersion="[36,)"
license="GPL-3.0 license" license="GPL-3.0 license"
issueTrackerURL="https://github.com/ViaVersion/ViaForge/issues" issueTrackerURL="https://github.com/ViaVersion/ViaForge/issues"
@ -7,7 +7,7 @@ showAsResourcePack=false
[[mods]] [[mods]]
modId="viaforge" modId="viaforge"
version="${version}" version="3.5.0"
displayName="ViaForge" displayName="ViaForge"
displayURL="https://github.com/FlorianMichael" displayURL="https://github.com/FlorianMichael"
credits="FlorianMichael/EnZaXD and all ViaVersion/ViaForge contributors" credits="FlorianMichael/EnZaXD and all ViaVersion/ViaForge contributors"

View File

@ -1,7 +1,3 @@
plugins {
id "viaforge.modern-conventions"
}
minecraft { minecraft {
mappings channel: "official", version: "1.17.1" mappings channel: "official", version: "1.17.1"
} }

View File

@ -1,2 +1,3 @@
maven_name=viaforge-mc117 maven_name=viaforge-mc117
mc_version=1.17.1 mc_version=1.17.1
sub_module_increment=2

View File

@ -108,10 +108,10 @@ public class GuiProtocolSelector extends Screen {
super.render(matrices, p_230430_2_, p_230430_3_, p_230430_4_); super.render(matrices, p_230430_2_, p_230430_3_, p_230430_4_);
GL11.glPushMatrix(); matrices.pushPose();
GL11.glScalef(2.0F, 2.0F, 2.0F); matrices.scale(2.0F, 2.0F, 2.0F);
drawCenteredString(matrices, font, TextFormatting.GOLD + "ViaForge", width / 4, 3, 16777215); drawCenteredString(matrices, font, TextFormatting.GOLD + "ViaForge", width / 4, 3, 16777215);
GL11.glPopMatrix(); matrices.popPose();
drawCenteredString(matrices, font, "https://github.com/ViaVersion/ViaForge", width / 2, (font.lineHeight + 2) * 2 + 3, -1); drawCenteredString(matrices, font, "https://github.com/ViaVersion/ViaForge", width / 2, (font.lineHeight + 2) * 2 + 3, -1);
drawString(matrices, font, status != null ? status : "Discord: florianmichael", 3, 3, -1); drawString(matrices, font, status != null ? status : "Discord: florianmichael", 3, 3, -1);

View File

@ -0,0 +1,17 @@
modLoader="javafml"
loaderVersion="[37,)"
license="GPL-3.0 license"
issueTrackerURL="https://github.com/ViaVersion/ViaForge/issues"
showAsResourcePack=false
[[mods]]
modId="viaforge"
version="3.5.0"
displayName="ViaForge"
displayURL="https://github.com/FlorianMichael"
credits="FlorianMichael/EnZaXD and all ViaVersion/ViaForge contributors"
authors="FlorianMichael/EnZaXD"
description='''
Client-side Implementation of the Via* projects for Minecraft Forge
'''

View File

@ -1,7 +1,3 @@
plugins {
id "viaforge.modern-conventions"
}
minecraft { minecraft {
mappings channel: "official", version: "1.18.2" mappings channel: "official", version: "1.18.2"
} }

View File

@ -1,2 +1,3 @@
maven_name=viaforge-mc118 maven_name=viaforge-mc118
mc_version=1.18.2 mc_version=1.18.2
sub_module_increment=3

View File

@ -108,10 +108,10 @@ public class GuiProtocolSelector extends Screen {
super.render(matrices, p_230430_2_, p_230430_3_, p_230430_4_); super.render(matrices, p_230430_2_, p_230430_3_, p_230430_4_);
GL11.glPushMatrix(); matrices.pushPose();
GL11.glScalef(2.0F, 2.0F, 2.0F); matrices.scale(2.0F, 2.0F, 2.0F);
drawCenteredString(matrices, font, TextFormatting.GOLD + "ViaForge", width / 4, 3, 16777215); drawCenteredString(matrices, font, TextFormatting.GOLD + "ViaForge", width / 4, 3, 16777215);
GL11.glPopMatrix(); matrices.popPose();
drawCenteredString(matrices, font, "https://github.com/ViaVersion/ViaForge", width / 2, (font.lineHeight + 2) * 2 + 3, -1); drawCenteredString(matrices, font, "https://github.com/ViaVersion/ViaForge", width / 2, (font.lineHeight + 2) * 2 + 3, -1);
drawString(matrices, font, status != null ? status : "Discord: florianmichael", 3, 3, -1); drawString(matrices, font, status != null ? status : "Discord: florianmichael", 3, 3, -1);

View File

@ -0,0 +1,17 @@
modLoader="javafml"
loaderVersion="[40,)"
license="GPL-3.0 license"
issueTrackerURL="https://github.com/ViaVersion/ViaForge/issues"
showAsResourcePack=false
[[mods]]
modId="viaforge"
version="3.5.0"
displayName="ViaForge"
displayURL="https://github.com/FlorianMichael"
credits="FlorianMichael/EnZaXD and all ViaVersion/ViaForge contributors"
authors="FlorianMichael/EnZaXD"
description='''
Client-side Implementation of the Via* projects for Minecraft Forge
'''

View File

@ -1,7 +1,3 @@
plugins {
id "viaforge.modern-conventions"
}
minecraft { minecraft {
mappings channel: "official", version: "1.19.4" mappings channel: "official", version: "1.19.4"
} }

View File

@ -1,2 +1,3 @@
maven_name=viaforge-mc119 maven_name=viaforge-mc119
mc_version=1.19.4 mc_version=1.19.4
sub_module_increment=4

View File

@ -107,10 +107,10 @@ public class GuiProtocolSelector extends Screen {
super.render(matrices, p_230430_2_, p_230430_3_, p_230430_4_); super.render(matrices, p_230430_2_, p_230430_3_, p_230430_4_);
GL11.glPushMatrix(); matrices.pushPose();
GL11.glScalef(2.0F, 2.0F, 2.0F); matrices.scale(2.0F, 2.0F, 2.0F);
drawCenteredString(matrices, font, TextFormatting.GOLD + "ViaForge", width / 4, 3, 16777215); drawCenteredString(matrices, font, TextFormatting.GOLD + "ViaForge", width / 4, 3, 16777215);
GL11.glPopMatrix(); matrices.popPose();
drawCenteredString(matrices, font, "https://github.com/ViaVersion/ViaForge", width / 2, (font.lineHeight + 2) * 2 + 3, -1); drawCenteredString(matrices, font, "https://github.com/ViaVersion/ViaForge", width / 2, (font.lineHeight + 2) * 2 + 3, -1);
drawString(matrices, font, status != null ? status : "Discord: florianmichael", 3, 3, -1); drawString(matrices, font, status != null ? status : "Discord: florianmichael", 3, 3, -1);

View File

@ -0,0 +1,17 @@
modLoader="javafml"
loaderVersion="[45,)"
license="GPL-3.0 license"
issueTrackerURL="https://github.com/ViaVersion/ViaForge/issues"
showAsResourcePack=false
[[mods]]
modId="viaforge"
version="3.5.0"
displayName="ViaForge"
displayURL="https://github.com/FlorianMichael"
credits="FlorianMichael/EnZaXD and all ViaVersion/ViaForge contributors"
authors="FlorianMichael/EnZaXD"
description='''
Client-side Implementation of the Via* projects for Minecraft Forge
'''

View File

@ -1,7 +1,3 @@
plugins {
id "viaforge.modern-conventions"
}
minecraft { minecraft {
mappings channel: "official", version: "1.20.2" mappings channel: "official", version: "1.20.2"
} }

View File

@ -1,2 +1,3 @@
maven_name=viaforge-mc120 maven_name=viaforge-mc120
mc_version=1.20.2 mc_version=1.20.2
sub_module_increment=5

View File

@ -106,10 +106,12 @@ public class GuiProtocolSelector extends Screen {
this.list.render(graphics, p_230430_2_, p_230430_3_, p_230430_4_); this.list.render(graphics, p_230430_2_, p_230430_3_, p_230430_4_);
super.render(graphics, p_230430_2_, p_230430_3_, p_230430_4_); super.render(graphics, p_230430_2_, p_230430_3_, p_230430_4_);
GL11.glPushMatrix(); final var pose = graphics.pose();
GL11.glScalef(2.0F, 2.0F, 2.0F);
pose.pushPose();
pose.scale(2.0F, 2.0F, 2.0F);
graphics.drawCenteredString(font, TextFormatting.GOLD + "ViaForge", width / 4, 3, 16777215); graphics.drawCenteredString(font, TextFormatting.GOLD + "ViaForge", width / 4, 3, 16777215);
GL11.glPopMatrix(); pose.popPose();
graphics.drawCenteredString(font, "https://github.com/ViaVersion/ViaForge", width / 2, (font.lineHeight + 2) * 2 + 3, -1); graphics.drawCenteredString(font, "https://github.com/ViaVersion/ViaForge", width / 2, (font.lineHeight + 2) * 2 + 3, -1);
graphics.drawString(font, status != null ? status : "Discord: florianmichael", 3, 3, -1); graphics.drawString(font, status != null ? status : "Discord: florianmichael", 3, 3, -1);

View File

@ -0,0 +1,17 @@
modLoader="javafml"
loaderVersion="[48,)"
license="GPL-3.0 license"
issueTrackerURL="https://github.com/ViaVersion/ViaForge/issues"
showAsResourcePack=false
[[mods]]
modId="viaforge"
version="3.5.0"
displayName="ViaForge"
displayURL="https://github.com/FlorianMichael"
credits="FlorianMichael/EnZaXD and all ViaVersion/ViaForge contributors"
authors="FlorianMichael/EnZaXD"
description='''
Client-side Implementation of the Via* projects for Minecraft Forge
'''