astei / krypton

A Fabric mod that optimizes the Minecraft networking stack and entity tracker.
GNU Lesser General Public License v3.0
367 stars 34 forks source link

Fixed NoSuchElementException if threshold is negative #100

Closed FlorianMichael closed 1 year ago

FlorianMichael commented 1 year ago

This PullRequest fixes a NoSuchElementException if the server sends a negative threshold in the compression, you can test it yourself:

  1. start Krypton
  2. join "raphimc.net".

Without my fix you will be kicked for a NoSuchElementException.

Kichura commented 1 year ago

This seems to fail upon compile attempt as both PacketInflater and PacketDeflater are marked as symbols that cannot be found.

FlorianMichael commented 1 year ago

These are Minecraft classes, how can you not have them?

astei commented 1 year ago

That's presumably because he just pulled the logic from the decompiled code. Even if the correct imports were added, this would still be broken because it doesn't account for Krypton outright replacing the handlers.

FlorianMichael commented 1 year ago

Fixed @Kichura

FlorianMichael commented 1 year ago

@astei You could also check if the handlers are null

FlorianMichael commented 1 year ago

@astei Why didn't you merged my PR, it's simpler than the current code.

astei commented 1 year ago

Fixed in 80720b286b66b3b0506b8454d2c3264f7bdbea09, the null check isn't even necessary as it's implied in the instanceof checks.

what exactly is wrong about it? it simulates the vanilla-like behaviour and when you don't follow or at least try simulating the vanilla behaviour everything breaks down and everything gets detectable server-side

You don't seem to understand that Krypton is already detectable on the server side, and that this change does nothing but fix a variance from vanilla, and a painfully minor one too. The goal of this mod is wire compatibility, not to be 100% undetectable.

astei commented 1 year ago

@FlorianMichael I am the author of this mod and I decide what code goes in.

Your fix was only partially correct, since it did not account for the fact Krypton uses entirely different compression handlers.

FlorianMichael commented 1 year ago

Can you add compactibility for ViaFabricPlus for compression?

astei commented 1 year ago

I'll entertain adding a pipeline event for reordering that you can listen to, but not calling out to any mods. The approach I took for ViaFabric was a mistake I'm not going to repeat

FlorianMichael commented 1 year ago

I won't do it, but okay, thank you for your time

astei commented 1 year ago

5896b6064b8e5ed24da583a823c884f11d8f4b79 has the events you need

FlorianMichael commented 1 year ago

I don't see why I should implement this, Krypton overwrites the whole compression and not me, you could just add a second event handler or modify the Minecraft elements and not replace them.

astei commented 1 year ago

I don't think you understand that I did.

I added a generic event handler that any mod can listen to know when Krypton has rearranged the compression handlers. At some point I'm going to get rid of the ViaFabric-specific one as well.

FlorianMichael commented 1 year ago

Can't you just drag the ViaFabric stuff into its own class then I can inject in there, I don't want to add Krypton as a dependency because that's just not my job as a mod to fix that, Krypton ends up overwriting everything and not me.

astei commented 1 year ago

Why would you prefer that? Mind you, "moving it into its own class" still introduces a dependency on Krypton, and it's arguably a worse design choice than just emitting an event through the pipeline, since you have to introduce a mixin that only applies when Krypton is in use, which necessarily implies Krypton as an optional dependency (so that Krypton can be loaded and present before your mod loads, too). You already inject into ClientConnection, after all, you can go the extra step and inject into userEventTriggered().

Here, you can use some reflection to see if the Krypton event class exists and extract the compression enabled/disabled events.

I'm really not sure what the problem with this approach is. I've provided a solution that you should be able to work with. If I'm missing something, please go into detail.

FlorianMichael commented 1 year ago

I find a pseudo mixin like I did in Sodium just nicer than having random reflection code that has to check for something, especially because my mod is not the problem. But okay

FlorianMichael commented 1 year ago

When will the new changes be uploaded to modrinth?

astei commented 1 year ago

At some point in the future. I'm not in a rush to cut a new release given that 0.2.3 currently has very little of note.

FlorianMichael commented 1 year ago

Looks like the API will work without reflection, thanks, but I'm pretty sure that with isKryptonOrVanillaDecompressor and isKryptonOrVanillaCompressor the vanilla check is unnecessary.

astei commented 1 year ago

It can't hurt, though, in case there's a mod that tries to undo what Krypton does...