Skip to content
This repository has been archived by the owner on Mar 29, 2024. It is now read-only.

Commit

Permalink
Added support for Forge 1.17 - 1.18.2
Browse files Browse the repository at this point in the history
  • Loading branch information
RaphiMC committed Feb 23, 2022
1 parent 1225d4b commit 2611545
Show file tree
Hide file tree
Showing 21 changed files with 299 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ minecraft {
}
}

// Include resources generated by data generators.
sourceSets.main.resources { srcDir 'src/generated/resources' }

dependencies {
// Specify the version of Minecraft to use. If this is any group other than 'net.minecraft', it is assumed
// that the dep is a ForgeGradle 'patcher' dependency, and its patches will be applied.
Expand Down
2 changes: 2 additions & 0 deletions Forge-1.14-1.16.5/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Project Properties
archives_base_name = OpenAuthMod-Forge [1.14-1.16.5]
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ side = "CLIENT"
[[dependencies.oam]]
modId = "minecraft"
mandatory = true
versionRange = "[1.14,1.18.2]"
versionRange = "[1.14,1.16.5]"
ordering = "NONE"
side = "CLIENT"
6 changes: 6 additions & 0 deletions Forge-1.14-1.16.5/src/main/resources/pack.mcmeta
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"pack": {
"description": "Open Auth Mod resources",
"pack_format": 6
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function initializeCoreMod() {
'methodName': 'func_209521_a',
'methodDesc': '(Lnet/minecraft/network/login/server/SCustomPayloadLoginPacket;)V'
},
'transformer': function(method) {
'transformer': function (method) {
var insns = new InsnList();
var jumpAfterLabel = new LabelNode();
insns.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "com/github/oam/OpenAuthMod", "getInstance", "()Lcom/github/oam/OpenAuthMod;"));
Expand Down Expand Up @@ -45,7 +45,7 @@ function initializeCoreMod() {
'methodName': 'func_147240_a',
'methodDesc': '(Lnet/minecraft/network/play/server/SCustomPayloadPlayPacket;)V'
},
'transformer': function(method) {
'transformer': function (method) {
var insns = new InsnList();
var jumpAfterLabel = new LabelNode();
insns.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "com/github/oam/OpenAuthMod", "getInstance", "()Lcom/github/oam/OpenAuthMod;"));
Expand Down
2 changes: 0 additions & 2 deletions Forge-1.14-1.18.2/gradle.properties

This file was deleted.

7 changes: 0 additions & 7 deletions Forge-1.14-1.18.2/src/main/resources/pack.mcmeta

This file was deleted.

82 changes: 82 additions & 0 deletions Forge-1.17-1.18.2/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
buildscript {
repositories {
maven {
name = 'Forge'
url = 'https://maven.minecraftforge.net/'
}
}
dependencies {
classpath 'net.minecraftforge.gradle:ForgeGradle:5.1.+'
}
}

apply plugin: 'net.minecraftforge.gradle'
apply plugin: 'eclipse'
apply plugin: 'idea'

java.toolchain.languageVersion = JavaLanguageVersion.of(16)

minecraft {
// The mappings can be changed at any time and must be in the following format.
// Channel: Version:
// snapshot YYYYMMDD Snapshot are built nightly.
// stable # Stables are built at the discretion of the MCP team.
// official MCVersion Official field/method names from Mojang mapping files
//
// You must be aware of the Mojang license when using the 'official' mappings.
// See more information here: https://github.com/MinecraftForge/MCPConfig/blob/master/Mojang.md
mappings channel: 'official', version: '1.17.1'

// accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg') // Breaks build process?

runs {
client {
workingDirectory project.file('run')

// Recommended logging data for a userdev environment
// The markers can be added/remove as needed separated by commas.
// "SCAN": For mods scan.
// "REGISTRIES": For firing of registry events.
// "REGISTRYDUMP": For getting the contents of all registries.
property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP'

// Recommended logging level for the console
// You can set various levels here.
// Please read: https://stackoverflow.com/questions/2031163/when-to-use-the-different-log-levels
property 'forge.logging.console.level', 'debug'

// Load core mod
property "fml.coreMods.load", "com.github.oam.injection.Injector"
}
}
}

// Include resources generated by data generators.
sourceSets.main.resources { srcDir 'src/generated/resources' }

dependencies {
// Specify the version of Minecraft to use. If this is any group other than 'net.minecraft', it is assumed
// that the dep is a ForgeGradle 'patcher' dependency, and its patches will be applied.
// The userdev artifact is a special name and will get all sorts of transformations applied to it.
minecraft 'net.minecraftforge:forge:1.17.1-37.1.1'

// Real mod deobf dependency examples - these get remapped to your current mappings
// compileOnly fg.deobf("mezz.jei:jei-${mc_version}:${jei_version}:api") // Adds JEI API as a compile dependency
// runtimeOnly fg.deobf("mezz.jei:jei-${mc_version}:${jei_version}") // Adds the full JEI mod as a runtime dependency
// implementation fg.deobf("com.tterrag.registrate:Registrate:MC${mc_version}-${registrate_version}") // Adds registrate as a dependency

// For more info...
// http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html
// http://www.gradle.org/docs/current/userguide/dependency_management.html
libs project(":Shared-1.13-1.18.2")
}

processResources {
inputs.property "version", project.version

filesMatching("META-INF/mods.toml") {
expand "version": project.version
}
}

jar.finalizedBy('reobfJar')
2 changes: 2 additions & 0 deletions Forge-1.17-1.18.2/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Project Properties
archives_base_name = OpenAuthMod-Forge [1.17-1.18.2]
91 changes: 91 additions & 0 deletions Forge-1.17-1.18.2/src/main/java/com/github/oam/OpenAuthMod.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package com.github.oam;

import io.netty.buffer.ByteBufUtil;
import io.netty.buffer.Unpooled;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screens.ConfirmScreen;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.Connection;
import net.minecraft.network.ConnectionProtocol;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.network.protocol.game.ServerboundCustomPayloadPacket;
import net.minecraft.network.protocol.login.ServerboundCustomQueryPacket;
import net.minecraft.resources.ResourceLocation;
import net.minecraftforge.fml.common.Mod;

import java.io.IOException;
import java.util.concurrent.Callable;

@Mod("oam")
public class OpenAuthMod extends OpenAuthModPlatform {

private static OpenAuthMod INSTANCE;

public static OpenAuthMod getInstance() {
return INSTANCE;
}


private final Minecraft mc = Minecraft.getInstance();
private Connection connection;

public OpenAuthMod() {
INSTANCE = this;
}

public boolean handlePlayCustomPayload(final Connection connection, final ResourceLocation channel, final FriendlyByteBuf data) throws IOException {
this.connection = connection;

return this.handleCustomPayloadPacket(channel.toString(), ByteBufUtil.getBytes(data));
}

public boolean handleQueryRequest(final Connection connection, final ResourceLocation channel, final int queryId, final FriendlyByteBuf data) throws IOException {
this.connection = connection;

return this.handleQueryRequestPacket(channel.toString(), queryId, ByteBufUtil.getBytes(data));
}

@Override
protected void sendCustomPayloadPacket(String channel, byte[] data) {
this.connection.send(new ServerboundCustomPayloadPacket(new ResourceLocation(channel), new FriendlyByteBuf(Unpooled.wrappedBuffer(data))));
}

@Override
protected void sendQueryResponsePacket(int queryId, byte[] data) {
this.connection.send(new ServerboundCustomQueryPacket(queryId, data != null ? new FriendlyByteBuf(Unpooled.wrappedBuffer(data)) : null));
}

@Override
protected void openConfirmScreen(String title, String subTitle, Callable<Void> yesCallback, Callable<Void> noCallback) {
this.mc.execute(() -> {
final Screen parentScreen = this.mc.screen;
this.mc.setScreen(new ConfirmScreen(success -> {
try {
if (success) yesCallback.call();
else noCallback.call();
} catch (Throwable e) {
e.printStackTrace();
this.connection.channel().close();
}
this.mc.setScreen(parentScreen);
}, new TextComponent(title), new TextComponent(subTitle)));
});
}

@Override
protected boolean joinServer(String serverHash) {
try {
this.mc.getMinecraftSessionService().joinServer(this.mc.getUser().getGameProfile(), this.mc.getUser().getAccessToken(), serverHash);
return true;
} catch (Throwable e) {
return false;
}
}

@Override
protected boolean isInPlayState() {
return ConnectionProtocol.PLAY.equals(this.connection.channel().attr(Connection.ATTRIBUTE_PROTOCOL).get());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
public net.minecraft.network.protocol.login.ClientboundCustomQueryPacket *
public net.minecraft.network.protocol.game.ClientboundCustomPayloadPacket *
3 changes: 3 additions & 0 deletions Forge-1.17-1.18.2/src/main/resources/META-INF/coremods.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"OpenAuthMod Transformer": "transformer/oam-transformer.js"
}
27 changes: 27 additions & 0 deletions Forge-1.17-1.18.2/src/main/resources/META-INF/mods.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
modLoader = "javafml"
loaderVersion = "[24,)"
license = "MIT"
issueTrackerURL = "https://github.com/RaphiMC/OpenAuthMod/issues"

[[mods]]
modId = "oam"
version = "${version}"
displayName = "Open Auth Mod"
displayURL = "https://github.com/RaphiMC/OpenAuthMod"
logoFile = "logo.png"
authors = "RK_01, Lenni0451"
description = "Authenticate with proxies during login or play state to allow online mode server switching."

[[dependencies.oam]]
modId = "forge"
mandatory = true
versionRange = "[24,)"
ordering = "NONE"
side = "CLIENT"

[[dependencies.oam]]
modId = "minecraft"
mandatory = true
versionRange = "[1.17,1.18.2]"
ordering = "NONE"
side = "CLIENT"
6 changes: 6 additions & 0 deletions Forge-1.17-1.18.2/src/main/resources/pack.mcmeta
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"pack": {
"description": "Open Auth Mod resources",
"pack_format": 7
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
function initializeCoreMod() {
var ASMAPI = Java.type("net.minecraftforge.coremod.api.ASMAPI");
var Opcodes = Java.type('org.objectweb.asm.Opcodes');
var InsnList = Java.type("org.objectweb.asm.tree.InsnList");
var InsnNode = Java.type("org.objectweb.asm.tree.InsnNode");
var FieldInsnNode = Java.type("org.objectweb.asm.tree.FieldInsnNode");
var MethodInsnNode = Java.type("org.objectweb.asm.tree.MethodInsnNode");
var VarInsnNode = Java.type("org.objectweb.asm.tree.VarInsnNode");
var LabelNode = Java.type("org.objectweb.asm.tree.LabelNode");
var JumpInsnNode = Java.type("org.objectweb.asm.tree.JumpInsnNode");

return {
'ClientLoginNetHandler Transformer': {
'target': {
'type': 'METHOD',
'class': 'net.minecraft.client.multiplayer.ClientHandshakePacketListenerImpl',
'methodName': 'm_7254_',
'methodDesc': '(Lnet/minecraft/network/protocol/login/ClientboundCustomQueryPacket;)V'
},
'transformer': function (method) {
var insns = new InsnList();
var jumpAfterLabel = new LabelNode();
insns.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "com/github/oam/OpenAuthMod", "getInstance", "()Lcom/github/oam/OpenAuthMod;"));
insns.add(new VarInsnNode(Opcodes.ALOAD, 0));
insns.add(new FieldInsnNode(Opcodes.GETFIELD, "net/minecraft/client/multiplayer/ClientHandshakePacketListenerImpl", ASMAPI.mapField("f_104522_"), "Lnet/minecraft/network/Connection;"));
insns.add(new VarInsnNode(Opcodes.ALOAD, 1));
insns.add(new FieldInsnNode(Opcodes.GETFIELD, "net/minecraft/network/protocol/login/ClientboundCustomQueryPacket", ASMAPI.mapField("f_134746_"), "Lnet/minecraft/resources/ResourceLocation;"));
insns.add(new VarInsnNode(Opcodes.ALOAD, 1));
insns.add(new FieldInsnNode(Opcodes.GETFIELD, "net/minecraft/network/protocol/login/ClientboundCustomQueryPacket", ASMAPI.mapField("f_134745_"), "I"));
insns.add(new VarInsnNode(Opcodes.ALOAD, 1));
insns.add(new FieldInsnNode(Opcodes.GETFIELD, "net/minecraft/network/protocol/login/ClientboundCustomQueryPacket", ASMAPI.mapField("f_134747_"), "Lnet/minecraft/network/FriendlyByteBuf;"));
insns.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "com/github/oam/OpenAuthMod", "handleQueryRequest", "(Lnet/minecraft/network/Connection;Lnet/minecraft/resources/ResourceLocation;ILnet/minecraft/network/FriendlyByteBuf;)Z"));
insns.add(new JumpInsnNode(Opcodes.IFEQ, jumpAfterLabel));
insns.add(new InsnNode(Opcodes.RETURN));
insns.add(jumpAfterLabel);

ASMAPI.insertInsnList(method, ASMAPI.MethodType.INTERFACE, "java/util/function/Consumer", "accept", "(Ljava/lang/Object;)V", insns, ASMAPI.InsertMode.INSERT_AFTER);
return method;
}
},
'ClientPlayNetHandler Transformer': {
'target': {
'type': 'METHOD',
'class': 'net.minecraft.client.multiplayer.ClientPacketListener',
'methodName': 'm_7413_',
'methodDesc': '(Lnet/minecraft/network/protocol/game/ClientboundCustomPayloadPacket;)V'
},
'transformer': function (method) {
var insns = new InsnList();
var jumpAfterLabel = new LabelNode();
insns.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "com/github/oam/OpenAuthMod", "getInstance", "()Lcom/github/oam/OpenAuthMod;"));
insns.add(new VarInsnNode(Opcodes.ALOAD, 0));
insns.add(new FieldInsnNode(Opcodes.GETFIELD, "net/minecraft/client/multiplayer/ClientPacketListener", ASMAPI.mapField("f_104885_"), "Lnet/minecraft/network/Connection;"));
insns.add(new VarInsnNode(Opcodes.ALOAD, 1));
insns.add(new FieldInsnNode(Opcodes.GETFIELD, "net/minecraft/network/protocol/game/ClientboundCustomPayloadPacket", ASMAPI.mapField("f_132029_"), "Lnet/minecraft/resources/ResourceLocation;"));
insns.add(new VarInsnNode(Opcodes.ALOAD, 1));
insns.add(new FieldInsnNode(Opcodes.GETFIELD, "net/minecraft/network/protocol/game/ClientboundCustomPayloadPacket", ASMAPI.mapField("f_132030_"), "Lnet/minecraft/network/FriendlyByteBuf;"));
insns.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "com/github/oam/OpenAuthMod", "handlePlayCustomPayload", "(Lnet/minecraft/network/Connection;Lnet/minecraft/resources/ResourceLocation;Lnet/minecraft/network/FriendlyByteBuf;)Z"));
insns.add(new JumpInsnNode(Opcodes.IFEQ, jumpAfterLabel));
insns.add(new InsnNode(Opcodes.RETURN));
insns.add(jumpAfterLabel);

ASMAPI.insertInsnList(method, ASMAPI.MethodType.STATIC, "net/minecraft/network/protocol/PacketUtils", ASMAPI.mapMethod("m_131363_"), "(Lnet/minecraft/network/protocol/Packet;Lnet/minecraft/network/PacketListener;Lnet/minecraft/util/thread/BlockableEventLoop;)V", insns, ASMAPI.InsertMode.INSERT_AFTER);
return method;
}
}
}
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This mod provides an interface for proxies to authenticate to an online mode ser

## Compatibility
* Fabric 1.14 - 1.18.2
* Forge 1.14 - 1.16.5 (1.17 soon™)
* Forge 1.14 - 1.18.2
* Forge 1.8 - 1.12.2

## Projects where this mod can be used
Expand Down
3 changes: 1 addition & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ jar {
subprojects {
apply plugin: "java"

sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
java.toolchain.languageVersion = JavaLanguageVersion.of(8)

compileJava.options.encoding = "UTF-8"

Expand Down
3 changes: 2 additions & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ include(":Shared-1.13-1.18.2")
include(":Shared-1.8-1.12.2")

include(":Fabric-1.14-1.18.2")
include(":Forge-1.14-1.18.2")
include(":Forge-1.17-1.18.2")
include(":Forge-1.14-1.16.5")
include(":Forge-1.8-1.12.2")

0 comments on commit 2611545

Please sign in to comment.