Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix instructions for some packets #42

Merged
merged 2 commits into from
Oct 29, 2022
Merged

Fix instructions for some packets #42

merged 2 commits into from
Oct 29, 2022

Conversation

mat-1
Copy link

@mat-1 mat-1 commented Oct 27, 2022

This PR fixes instruction extraction erroring for several packets. I'm not sure how many of these were broken specifically by 22w42a but I fixed them all regardless.

Changes:

  • Add the BitSet type (which required adding a length field to it, and I also added that length field to String because I might as well)
  • Add the EnumSet type
  • Add the Either type (I don't really like the .isLeft()/.left()/.right() thing but I don't know what the best way to do it would be)
  • Handle the putfield instruction (Advancement.Builder's writer set a field when writing a packet for some reason)

(Note: I haven't looked into the new snapshot that released today yet so I'm hoping they didn't add more weird types)

Comment on lines +840 to +851
operations.append(Operation(instruction.pos, "if",
condition=field.value + ".isLeft()"))
operations += _PIT._lambda_operations(
classloader, classes, instruction.pos, verbose,
left_consumer, [instance, field.value + ".left()"]
)
operations.append(Operation(instruction.pos + 1 - SUB_INS_EPSILON, "else"))
operations += _PIT._lambda_operations(
classloader, classes, instruction.pos + 1, verbose,
right_consumer, [instance, field.value + ".right()"]
)
operations.append(Operation(instruction.pos + 2 - SUB_INS_EPSILON, "endif"))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not 100% sure this will work correctly. There's a different implementation for java/util/Map (which I'm also not sure is correct, but it does guarantee that instruction.pos <= pos and pos < instruction.pos + 1). Though, I also don't 100% remember what pos corresponds to - if it's a byte offset, this might be better as call instructions are multiple bytes.

Copy link
Author

@mat-1 mat-1 Oct 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I didn't add to the instruction pos the else was empty and the instructions were getting mixed with the if instructions, so I think the implementation for Map might actually be wrong. I also just checked by doing print(instruction.pos) at the beginning of a loop where a method is disassembled, and it does look like they're byte offsets since the positions usually increase by more than 1 at a time.

Ok also you don't need to answer this, but why do operations even need to store their position? Can't that just be figured out from the order in the operations list?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case, it's probably fine.

Ok also you don't need to answer this, but why do operations even need to store their position? Can't that just be figured out from the order in the operations list?

I'm pretty sure that specific part of the code predates me. I do know that they aren't initially sorted (which is what ordered_operations does). I assume that it's related to endif, which I think gets put into the list as soon as a jump is seen. Not that the if handling is great; see #2 and #3. I think it also relates to converting from a list of instructions into a nested tree structure (see format).

@Pokechu22
Copy link
Owner

I haven't reviewed this in detail, but it seems to work fine (including on 1.18 and on 22w43a), both of which had broken packets, so I'll merge it. Thanks!

@Pokechu22 Pokechu22 merged commit 1633f75 into Pokechu22:1.19-dev Oct 29, 2022
Pokechu22 added a commit that referenced this pull request Oct 29, 2022
Pokechu22 added a commit to Pokechu22/BurgerVitrine that referenced this pull request Oct 29, 2022
Pokechu22 added a commit to Pokechu22/BurgerWebViewer that referenced this pull request Oct 29, 2022
@mat-1 mat-1 deleted the packet-instruction-fixes branch October 29, 2022 17:21
Pokechu22 added a commit that referenced this pull request Nov 16, 2022
I forgot to update burger on my pi, so it was building with the old version.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants