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

Stop sound packet (nested if statements) are incorrectly parsed #3

Open
Pokechu22 opened this issue Dec 15, 2017 · 1 comment
Open

Comments

@Pokechu22
Copy link
Owner

The stop sound packet (currently 0x4A) incorrectly looks like this:

if(b != null) {
  if(a != null) {
    writeByte(3);
    writeVarIntEnum(b);
    writeIdentifier(a);
  } else {
    writeByte(1);
    writeVarIntEnum(b);
  } else {
    if(a != null) {
      writeByte(2);
      writeIdentifier(a);
    } else {
      writeByte(0);
    }
  }
}

It should be this:

if(b != null) {
  if(a != null) {
    writeByte(3);
    writeVarIntEnum(b);
    writeIdentifier(a);
  } else {
    writeByte(1);
    writeVarIntEnum(b);
  }
} else {
  if(a != null) {
    writeByte(2);
    writeIdentifier(a);
  } else {
    writeByte(0);
  }
}

or this:

if(b != null) {
  if(a != null) {
    writeByte(3);
    writeVarIntEnum(b);
    writeIdentifier(a);
  } else {
    writeByte(1);
    writeVarIntEnum(b);
  }
} else if(a != null) {
  writeByte(2);
  writeIdentifier(a);
} else {
  writeByte(0);
}
@Pokechu22
Copy link
Owner Author

Pokechu22 commented Dec 15, 2017

Sample code:

class nested {
	public void foo(boolean a, boolean b) {
		if (a) {
			if (b) {
				writeByte(3);
			} else {
				writeByte(1);
			}
		} else {
			if (b) {
				writeByte(2);
			} else {
				writeByte(0);
			}
		}
	}
	// as with before, so burger does something
	public void writeByte(int n) {}
}

and the python thing from #2

Disassembly

  public void foo(boolean, boolean);
    Code:
       0: iload_1
       1: ifeq          26
       4: iload_2
       5: ifeq          17
       8: aload_0
       9: iconst_3
      10: invokevirtual #2                  // Method writeByte:(I)Ljava/lang/Object;
      13: pop
      14: goto          45
      17: aload_0
      18: iconst_1
      19: invokevirtual #2                  // Method writeByte:(I)Ljava/lang/Object;
      22: pop
      23: goto          45
      26: iload_2
      27: ifeq          39
      30: aload_0
      31: iconst_2
      32: invokevirtual #2                  // Method writeByte:(I)Ljava/lang/Object;
      35: pop
      36: goto          45
      39: aload_0
      40: iconst_0
      41: invokevirtual #2                  // Method writeByte:(I)Ljava/lang/Object;
      44: pop
      45: return

PIT.operations

[
    {
        "position": 1,
        "operation": "if",
        "condition": "a"
    },
    {
        "position": 26,
        "operation": "else"
    },
    {
        "position": 5,
        "operation": "if",
        "condition": "b"
    },
    {
        "position": 17,
        "operation": "else"
    },
    {
        "position": 10,
        "operation": "write",
        "type": "byte",
        "field": "3"
    },
    {
        "position": 45,
        "operation": "endif"
    },
    {
        "position": 19,
        "operation": "write",
        "type": "byte",
        "field": "1"
    },
    {
        "position": 45,
        "operation": "endif"
    },
    {
        "position": 27,
        "operation": "if",
        "condition": "b"
    },
    {
        "position": 39,
        "operation": "else"
    },
    {
        "position": 32,
        "operation": "write",
        "type": "byte",
        "field": "2"
    },
    {
        "position": 45,
        "operation": "endif"
    },
    {
        "position": 41,
        "operation": "write",
        "type": "byte",
        "field": "0"
    }
]

PIT.format

{
    "instructions": [
        {
            "operation": "if",
            "condition": "a",
            "instructions": [
                {
                    "operation": "if",
                    "condition": "b",
                    "instructions": [
                        {
                            "operation": "write",
                            "type": "byte",
                            "field": "3"
                        }
                    ]
                },
                {
                    "operation": "else",
                    "instructions": [
                        {
                            "operation": "write",
                            "type": "byte",
                            "field": "1"
                        }
                    ]
                },
                {
                    "operation": "else",
                    "instructions": [
                        {
                            "operation": "if",
                            "condition": "b",
                            "instructions": [
                                {
                                    "operation": "write",
                                    "type": "byte",
                                    "field": "2"
                                }
                            ]
                        },
                        {
                            "operation": "else",
                            "instructions": [
                                {
                                    "operation": "write",
                                    "type": "byte",
                                    "field": "0"
                                }
                            ]
                        }
                    ]
                }
            ]
        }
    ]
}

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

No branches or pull requests

1 participant