This repository has been archived by the owner on Mar 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for Forge 1.17 - 1.18.2
- Loading branch information
Showing
21 changed files
with
299 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"pack": { | ||
"description": "Open Auth Mod resources", | ||
"pack_format": 6 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
91
Forge-1.17-1.18.2/src/main/java/com/github/oam/OpenAuthMod.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
|
||
} |
2 changes: 2 additions & 0 deletions
2
Forge-1.17-1.18.2/src/main/resources/META-INF/accesstransformer.cfg
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"OpenAuthMod Transformer": "transformer/oam-transformer.js" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"pack": { | ||
"description": "Open Auth Mod resources", | ||
"pack_format": 7 | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
Forge-1.17-1.18.2/src/main/resources/transformer/oam-transformer.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters