Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #40, fixes #9
This fixes an else-if chain bug in the decompiler incorrectly removing brackets
{ }
from else-statements whose bodies contain more than one statement, other than a single if-statement.It is caused by a special case when writing a compilation unit, which omits
{ }
from else clauses if the first statement in the else body is another if-statement, which ensures pretty else-if chains in the output. However, it would incorrectly do this if the else-body had additional statements following the if-statement, leading to those statements being left out of the else body in the output.This would cause decompiled and recompiled scripts to have inconsistent logic, leading to strange behavior in the game and sometimes crashing. I have tested the situations where crashes happened in issue #9, before and after the fix, and can confirm that this fix resolves those crashes.
The fix was changing a single line in
CompilationUnitWriter.cs
, such that it only omits the brackets if the if-statement is the only statement in the else body. Otherwise the brackets will be left in.An example from P5R's FIELD.BF (located at CPK\EN.CPK\FIELD\ETC\FIELD.BF)
The correct logic for the
fld_r1_menu()
procedure is as follows:However, the decompiler would produce:
Leading to
Field_SHORTCUT()
being called in any case, which is not correct