ProtocolLib

3M Downloads

FieldAccessException

Astralchroma opened this issue · 4 comments

commented

Make sure you're doing the following

  • You're using the latest build for your server version
  • This isn't an issue caused by another plugin
  • You've checked for duplicate issues
  • You didn't use /reload

Describe the question
Attempting to use ProtocolLib to fake the render distance sent to the client on login results in a FieldAccessException.

[10:32:48 ERROR]: [ion] Unhandled exception occured in onPacketSending(PacketEvent) for ion
com.comphenix.protocol.reflect.FieldAccessException: Cannot read field due to a security limitation.
        at com.comphenix.protocol.reflect.StructureModifier.writeInternal(StructureModifier.java:377) ~[ProtocolLib.jar:?]
        at com.comphenix.protocol.reflect.StructureModifier.write(StructureModifier.java:345) ~[ProtocolLib.jar:?]
        at net.horizonsend.ion.server.PacketTweaks.onPacketSending(PacketTweaks.kt:13) ~[IonServer.jar:?]
        at com.comphenix.protocol.injector.SortedPacketListenerList.invokeSendingListener(SortedPacketListenerList.java:195) ~[ProtocolLib.jar:?]
        at com.comphenix.protocol.injector.SortedPacketListenerList.invokePacketSending(SortedPacketListenerList.java:149) ~[ProtocolLib.jar:?]
        at com.comphenix.protocol.injector.PacketFilterManager.handlePacket(PacketFilterManager.java:535) ~[ProtocolLib.jar:?]
        at com.comphenix.protocol.injector.PacketFilterManager.invokePacketSending(PacketFilterManager.java:516) ~[ProtocolLib.jar:?]
        at com.comphenix.protocol.injector.netty.ProtocolInjector.packetQueued(ProtocolInjector.java:346) ~[ProtocolLib.jar:?]
        at com.comphenix.protocol.injector.netty.ProtocolInjector.onPacketSending(ProtocolInjector.java:308) ~[ProtocolLib.jar:?]
        at com.comphenix.protocol.injector.netty.ChannelInjector.processSending(ChannelInjector.java:433) ~[ProtocolLib.jar:?]
        at com.comphenix.protocol.injector.netty.ChannelInjector.access$800(ChannelInjector.java:70) ~[ProtocolLib.jar:?]
        at com.comphenix.protocol.injector.netty.ChannelInjector$3.handleScheduled(ChannelInjector.java:373) ~[ProtocolLib.jar:?]
        at com.comphenix.protocol.injector.netty.ChannelInjector$3.onMessageScheduled(ChannelInjector.java:343) ~[ProtocolLib.jar:?]
        at com.comphenix.protocol.injector.netty.ChannelProxy$2.schedulingRunnable(ChannelProxy.java:127) ~[ProtocolLib.jar:?]
        at com.comphenix.protocol.injector.netty.EventLoopProxy.execute(EventLoopProxy.java:95) ~[ProtocolLib.jar:?]
        at net.minecraft.network.Connection.writePacket(Connection.java:401) ~[?:?]
        at net.minecraft.network.Connection.send(Connection.java:348) ~[?:?]
        at net.minecraft.server.network.ServerGamePacketListenerImpl.send(ServerGamePacketListenerImpl.java:2006) ~[?:?]
        at net.minecraft.server.network.ServerGamePacketListenerImpl.send(ServerGamePacketListenerImpl.java:1992) ~[?:?]
        at net.minecraft.server.players.PlayerList.placeNewPlayer(PlayerList.java:270) ~[paper-1.18.1.jar:git-Paper-110]
        at net.minecraft.server.network.ServerLoginPacketListenerImpl.placeNewPlayer(ServerLoginPacketListenerImpl.java:218) ~[?:?]
        at net.minecraft.server.network.ServerLoginPacketListenerImpl.handleAcceptedLogin(ServerLoginPacketListenerImpl.java:199) ~[?:?]
        at net.minecraft.server.network.ServerLoginPacketListenerImpl.tick(ServerLoginPacketListenerImpl.java:87) ~[?:?]
        at net.minecraft.network.Connection.tick(Connection.java:517) ~[?:?]
        at net.minecraft.server.network.ServerConnectionListener.tick(ServerConnectionListener.java:201) ~[?:?]
        at net.minecraft.server.MinecraftServer.tickChildren(MinecraftServer.java:1636) ~[paper-1.18.1.jar:git-Paper-110]
        at net.minecraft.server.dedicated.DedicatedServer.tickChildren(DedicatedServer.java:480) ~[paper-1.18.1.jar:git-Paper-110]
        at net.minecraft.server.MinecraftServer.tickServer(MinecraftServer.java:1470) ~[paper-1.18.1.jar:git-Paper-110]
        at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:1264) ~[paper-1.18.1.jar:git-Paper-110]
        at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:317) ~[paper-1.18.1.jar:git-Paper-110]
        at java.lang.Thread.run(Thread.java:833) ~[?:?]
Caused by: java.lang.IllegalAccessException: Can not set final int field net.minecraft.network.protocol.game.PacketPlayOutLogin.a to java.lang.Integer
        at jdk.internal.reflect.UnsafeFieldAccessorImpl.throwFinalFieldIllegalAccessException(UnsafeFieldAccessorImpl.java:76) ~[?:?]
        at jdk.internal.reflect.UnsafeFieldAccessorImpl.throwFinalFieldIllegalAccessException(UnsafeFieldAccessorImpl.java:80) ~[?:?]
        at jdk.internal.reflect.UnsafeQualifiedIntegerFieldAccessorImpl.set(UnsafeQualifiedIntegerFieldAccessorImpl.java:79) ~[?:?]
        at java.lang.reflect.Field.set(Field.java:799) ~[?:?]
        at com.comphenix.protocol.reflect.FieldUtils.writeField(FieldUtils.java:450) ~[ProtocolLib.jar:?]
        at com.comphenix.protocol.reflect.StructureModifier.writeInternal(StructureModifier.java:375) ~[ProtocolLib.jar:?]
        ... 30 more
[10:32:48 ERROR]: Parameters: 
  net.minecraft.network.protocol.game.PacketPlayOutLogin@664cbae1[
    a=42
    b=false
    c=CREATIVE
    d=SURVIVAL
    e=[ResourceKey[minecraft:dimension / minecraft:overworld], ResourceKey[minecraft:dimension / minecraft:the_nether], ResourceKey[minecraft:dimension / minecraft:the_end]]
    f=net.minecraft.core.IRegistryCustom$Dimension@35ec5c3e
    g=net.minecraft.world.level.dimension.DimensionManager@141adc36
    h=ResourceKey[minecraft:dimension / minecraft:overworld]
    i=-5878948435060608077
    j=20
    k=10
    l=10
    m=false
    n=true
    o=false
    p=false
  ]

API method(s) used
Altering of sent packets

Expected behavior
A render distance of 32 is sent to the client.

Code
PacketTweaks.kt

object PacketTweaks: PacketAdapter(ionInstance, ListenerPriority.HIGHEST, PacketType.Play.Server.LOGIN) {
	override fun onPacketSending(event: PacketEvent) {
		if (event.packetType == PacketType.Play.Server.LOGIN) {
			// Set the render distance to 32
			event.packet.integers.write(2, 32)
		}
	}
}

Additional context
Minecraft 1.18.1 (Paper)

commented

4.8.0 should resolve the issue 🤔 , but I cannot see the version you are using...

commented

4.7.0

commented

Please use 4.8.0 for 1.18. See the readme for the link to the development builds.

commented

Did not notice that? Maybe put it under releases as a pre-release build or something?