Skip to content

Commit

Permalink
Merge pull request #43 from funkemunky/1_19
Browse files Browse the repository at this point in the history
1 19
  • Loading branch information
funkemunky authored Jun 21, 2022
2 parents e420bdf + 21796f9 commit e2518da
Show file tree
Hide file tree
Showing 25 changed files with 506 additions and 147 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ local.properties
.settings/
.loadpath
.recommenders
*.iml


# External tool builders
.externalToolBuilders/
Expand Down
18 changes: 3 additions & 15 deletions AtlasParent/Atlas/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<parent>
<groupId>cc.funkemunky.utils</groupId>
<version>1.11.7</version>
<version>1.12.0</version>
<artifactId>atlas-parent</artifactId>
<relativePath>../pom.xml</relativePath>
</parent>
Expand Down Expand Up @@ -217,13 +217,13 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<version>1.18-R0.1</version>
<version>1.19-R0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.18-R0.1</version>
<version>1.19-R0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand All @@ -245,18 +245,6 @@
<version>2.9.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<version>1.18.2-R0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.18.2-R0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>co.aikar</groupId>
<artifactId>acf-bukkit</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public static WrappedClass getCBClass(String name) {
public static WrappedClass getNMSClass(String name) {
try {
return getClass(netMinecraftServerString + name);
} catch(Exception e) {
} catch(Throwable e) {
Pattern toTest = Pattern.compile("\\." + name.replace("$", ".") + "$");
for (String className : classNames) {
if(!className.startsWith("net.minecraft")) continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ public class MinecraftReflection {
private static final WrappedClass propertyMap = Reflections.getUtilClass("com.mojang.authlib.properties.PropertyMap");
private static final WrappedClass forwardMultiMap = Reflections.getUtilClass("com.google.common.collect.ForwardingMultimap");
public static WrappedClass iChatBaseComponent = Reflections.getNMSClass("IChatBaseComponent"),
chatComponentText = Reflections.getNMSClass("ChatComponentText");
chatComponentText;
public static WrappedClass vec3D = Reflections.getNMSClass("Vec3D");

private static final WrappedMethod getProfile = CraftReflection.craftPlayer.getMethod("getProfile");
private static final WrappedMethod methodGetServerConnection = minecraftServer
.getMethodByType(serverConnection.getParent(), ProtocolVersion.getGameVersion()
.isBelow(ProtocolVersion.V1_13) ? 1 : 0);
private static final WrappedConstructor chatComponentTextConst = chatComponentText.getConstructor(String.class);
private static WrappedConstructor chatComponentTextConst;
private static final WrappedMethod getProperties = gameProfile.getMethod("getProperties");
private static final WrappedMethod removeAll = forwardMultiMap.getMethod("removeAll", Object.class);
private static final WrappedMethod putAll = propertyMap.getMethod("putAll", Object.class, Iterable.class);
Expand Down Expand Up @@ -540,6 +540,11 @@ public static <T> List<T> getVanillaChunks(World world) {
getCubesFromVoxelShape = voxelShape.getMethodByType(List.class, 0);
fluidMethod = world.getMethodByType(Reflections.getNMSClass("Fluid").getParent(), 0, blockPos.getParent());
getFlowMethod = Reflections.getNMSClass("Fluid").getMethodByType(vec3D.getParent(), 0);

if(ProtocolVersion.getGameVersion().isBelow(ProtocolVersion.v1_19)) {
chatComponentText = Reflections.getNMSClass("ChatComponentText");
chatComponentTextConst = chatComponentText.getConstructor(String.class);
}
}

if(ProtocolVersion.getGameVersion().isOrAbove(ProtocolVersion.v1_16)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,12 @@ public static class Type {
public static final String DATAWATCHEROBJECT = Reflection.NMS_PREFIX + ".DataWatcherObject";
public static final String CHATMESSAGE = Reflection.NMS_PREFIX + ".ChatMessage";
public static final String CRAFTITEMSTACK = Reflection.OBC_PREFIX + ".inventory.CraftItemStack";
public static final String GAMEPROFILE = (Reflection.VERSION.startsWith("v1_7") ? "net.minecraft.util." : "") + "com.mojang.authlib.GameProfile";
public static final String PROPERTYMAP = (Reflection.VERSION.startsWith("v1_7") ? "net.minecraft.util." : "") + "com.mojang.authlib.PropertyMap";
public static final String GAMEPROFILE = (Reflection.VERSION.startsWith("v1_7") ? "net.minecraft.util." : "")
+ "com.mojang.authlib.GameProfile";
public static final String PROPERTYMAP = (Reflection.VERSION.startsWith("v1_7") ? "net.minecraft.util." : "")
+ (ProtocolVersion.getGameVersion().isOrAbove(ProtocolVersion.v1_19)
? "com.mojang.authlib.properties.PropertyMap"
: "com.mojang.authlib.PropertyMap");
public static final String VEC3D = Reflection.NMS_PREFIX + ".Vec3D";
public static final String PLAYERINFODATA = Reflection.NMS_PREFIX + Server.PLAYER_INFO + ".PlayerInfoData";
}
Expand Down Expand Up @@ -308,6 +312,7 @@ public static class Server {
public static class Login {
public static final String HANDSHAKE = "PacketHandshakingInSetProtocol";
public static final String PING = "PacketStatusInPing";
public static final String START = "PacketStatusInStart";
public static final String STATUS_START = "PacketStatusInStart";
public static final String LOGIN_START = "PacketLoginInStart";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,8 @@ public static class Server {
public static class Login {
public static final String HANDSHAKE = "PacketHandshakingInSetProtocol";
public static final String PING = "PacketStatusInPing";
public static final String START = "PacketStatusInStart";
public static final String STATUS_START = "PacketStatusInStart";
public static final String LOGIN_START = "PacketLoginInStart";
}

public static final Set<String> incomingPackets = new HashSet<>(), outgoingPackets = new HashSet<>(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public enum ProtocolVersion {
v1_17_1(756, "v1_17_R1"),
v1_18(757, "v1_18_R1"),
v1_18_2(758, "v1_18_R2"),
v1_19(759, "v1_19_R1"),

UNKNOWN(-1, "UNKNOWN");

Expand All @@ -79,6 +80,10 @@ private static ProtocolVersion fetchGameVersion() {
String version = mv.getFieldByType(String.class, 1).get(mvObject);

switch(version) {
case "1.19": {
toReturn = v1_19;
break;
}
case "1.18.2": {
toReturn = v1_18_2;
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,16 @@
import cc.funkemunky.api.reflections.impl.CraftReflection;
import cc.funkemunky.api.reflections.impl.MinecraftReflection;
import cc.funkemunky.api.reflections.types.WrappedClass;
import cc.funkemunky.api.reflections.types.WrappedField;
import cc.funkemunky.api.reflections.types.WrappedMethod;
import cc.funkemunky.api.tinyprotocol.api.ProtocolVersion;
import cc.funkemunky.api.tinyprotocol.api.Packet;
import cc.funkemunky.api.tinyprotocol.api.packets.AbstractTinyProtocol;
import cc.funkemunky.api.tinyprotocol.packet.login.WrappedHandshakingInSetProtocol;
import cc.funkemunky.api.tinyprotocol.packet.login.WrappedPacketLoginInStart;
import cc.funkemunky.api.tinyprotocol.packet.types.enums.WrappedEnumProtocol;
import cc.funkemunky.api.tinyprotocol.reflection.Reflection;
import cc.funkemunky.api.utils.RunUtils;
import com.google.common.collect.Lists;
import com.google.common.collect.MapMaker;
import com.mojang.authlib.GameProfile;
import io.netty.channel.*;
import lombok.val;
import org.bukkit.Bukkit;
Expand Down Expand Up @@ -58,13 +57,6 @@ public abstract class TinyProtocol1_8 implements AbstractTinyProtocol {
private static final WrappedMethod methodSendPacket = playerConnection.getMethodByType(void.class,
0, packetClass.getParent());

// Packets we have to intercept
private static final WrappedClass PACKET_SET_PROTOCOL = Reflections.getNMSClass("PacketHandshakingInSetProtocol");
private static final WrappedClass PACKET_LOGIN_IN_START = Reflections.getNMSClass("PacketLoginInStart");
private static final WrappedField getGameProfile = PACKET_LOGIN_IN_START.getFieldByType(GameProfile.class, 0),
protocolId = PACKET_SET_PROTOCOL.getFieldByType(int.class, 0),
protocolType = PACKET_SET_PROTOCOL.getFieldByType(Enum.class, 0);

private List<ChannelFuture> gList;

// Speedup channel lookup
Expand Down Expand Up @@ -536,10 +528,15 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) {
// Intercept channel
final Channel channel = ctx.channel();

if (PACKET_LOGIN_IN_START.getParent().isInstance(msg)) {
GameProfile profile = getGameProfile.get(msg);
channelLookup.put(profile.getName(), channel);
} else if (PACKET_SET_PROTOCOL.getParent().isInstance(msg)) {
String name = msg.getClass().getName();
int index = name.lastIndexOf(".");
String packetName = name.substring(index + 1);

if (packetName.equals(Packet.Login.LOGIN_START)) {
WrappedPacketLoginInStart protocol = new WrappedPacketLoginInStart(msg);

channelLookup.put(protocol.getGameProfile().getName(), channel);
} else if (packetName.equals(Packet.Login.HANDSHAKE)) {
WrappedHandshakingInSetProtocol protocol = new WrappedHandshakingInSetProtocol(msg);
if (protocol.enumProtocol == WrappedEnumProtocol.LOGIN) {
protocolLookup.put(channel, protocol.a);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package cc.funkemunky.api.tinyprotocol.packet.login;

import cc.funkemunky.api.reflections.Reflections;
import cc.funkemunky.api.reflections.types.WrappedClass;
import cc.funkemunky.api.reflections.types.WrappedField;
import cc.funkemunky.api.tinyprotocol.api.NMSObject;
import cc.funkemunky.api.tinyprotocol.api.ProtocolVersion;
import cc.funkemunky.api.tinyprotocol.packet.types.WrappedGameProfile;
import lombok.Getter;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;

import java.util.UUID;

@Getter
public class WrappedPacketLoginInStart extends NMSObject {

private static final WrappedClass packet = Reflections.getNMSClass(Login.LOGIN_START);
private static final WrappedField gameProfileField = packet.getFields().get(0);

private WrappedGameProfile gameProfile;

public WrappedPacketLoginInStart(Object object) {
super(object);
}

@Override
public void process(Player player, ProtocolVersion version) {
if(ProtocolVersion.getGameVersion().isBelow(ProtocolVersion.v1_19)) {
gameProfile = new WrappedGameProfile((Object)fetch(gameProfileField));
return;
}

String username = fetch(gameProfileField);
UUID uuid = Bukkit.getOfflinePlayer(username).getUniqueId();

this.gameProfile = new WrappedGameProfile(uuid, username);
}

@Override
public void updateObject() {
if(ProtocolVersion.getGameVersion().isBelow(ProtocolVersion.v1_19)) {
set(gameProfileField, gameProfile.getObject());
return;
}

set(gameProfileField, gameProfile.getName());
}
}
Original file line number Diff line number Diff line change
@@ -1,52 +1,59 @@
package cc.funkemunky.api.tinyprotocol.packet.out;

import cc.funkemunky.api.reflections.Reflections;
import cc.funkemunky.api.reflections.impl.MinecraftReflection;
import cc.funkemunky.api.reflections.types.WrappedClass;
import cc.funkemunky.api.reflections.types.WrappedField;
import cc.funkemunky.api.reflections.types.WrappedMethod;
import cc.funkemunky.api.tinyprotocol.api.NMSObject;
import cc.funkemunky.api.tinyprotocol.api.ProtocolVersion;
import cc.funkemunky.api.tinyprotocol.packet.types.WrappedChatComponent;
import cc.funkemunky.api.tinyprotocol.packet.types.WrappedChatMessage;
import cc.funkemunky.api.tinyprotocol.reflection.FieldAccessor;
import lombok.Getter;
import org.bukkit.entity.Player;

@Getter
public class WrappedOutOpenWindow extends NMSObject {

private static String packet = Server.OPEN_WINDOW;
private static WrappedClass packet = Reflections.getNMSClass(Server.OPEN_WINDOW);

public WrappedOutOpenWindow(Object object, Player player) {
super(object, player);
}

public WrappedOutOpenWindow(int id, String name, WrappedChatMessage msg, int size) {
setPacket(packet, id, name, msg.getObject(), size);
}

private static FieldAccessor<Integer> idField = fetchField(packet, int.class, 0);
private static FieldAccessor<String> nameField;
private static FieldAccessor<Object> chatCompField;
private static FieldAccessor<Integer> inventorySize = fetchField(packet, int.class, 1);
private static WrappedField idField = fetchField(packet, int.class, 0);
private static WrappedField nameField;
private static WrappedField chatCompField;
private static WrappedField inventorySize;

private int id;
private String name; //Not a thing in 1.14 and above.
private WrappedChatComponent chatComponent;
private int size;

@Override
public void process(Player player, ProtocolVersion version) {
id = fetch(idField);
size = fetch(inventorySize);

if(ProtocolVersion.getGameVersion().isOrBelow(ProtocolVersion.V1_13_2)) {
name = fetch(nameField);
}
if(ProtocolVersion.getGameVersion().isOrAbove(ProtocolVersion.v1_19)) {
size = getId(fetch(inventorySize));
} else size = fetch(inventorySize);
}

@Override
public void updateObject() {

}

private static WrappedClass iReg;
private static WrappedField rkeyContainers;
private static Object resourceKeyContainers;
private static WrappedMethod getId;

private static int getId(Object container) {
return getId.invoke(resourceKeyContainers, container);
}

static {
if(ProtocolVersion.getGameVersion().isOrAbove(ProtocolVersion.V1_8)) {
chatCompField = fetchField(packet,
Expand All @@ -55,5 +62,14 @@ public void updateObject() {
if(ProtocolVersion.getGameVersion().isOrBelow(ProtocolVersion.V1_13_2)) {
nameField = fetchField(packet, String.class, 0);
}
if(ProtocolVersion.getGameVersion().isOrAbove(ProtocolVersion.v1_19)) {
iReg = Reflections.getNMSClass("IRegistry");
rkeyContainers = iReg.getFieldByName("ah");
resourceKeyContainers = rkeyContainers.get(null);
getId = iReg.getMethod("a", Object.class);
inventorySize = fetchField(packet, Reflections.getClass("net.minecraft.world.inventory.Containers").getParent(), 0);
} else {
inventorySize = fetchField(packet, int.class, 1);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@ public void setPitch(float pitch) {
static {
List<WrappedField> fields = packetClass.getFields(true);

int addIndex = ProtocolVersion.getGameVersion().isOrAbove(ProtocolVersion.v1_17) ? 1 : 0;
int addIndex = ProtocolVersion.getGameVersion().isOrAbove(ProtocolVersion.v1_17)
&& ProtocolVersion.getGameVersion().isBelow(ProtocolVersion.v1_19) ? 1 : 0;

fieldId = fields.get(0 + addIndex);
fieldX = fields.get(1 + addIndex);
Expand Down
Loading

0 comments on commit e2518da

Please sign in to comment.