Skip to content

thecl: restore pre-th10 jump displacement regression - #142

Open
ACA4DFA4 wants to merge 1 commit into
thpatch:masterfrom
ACA4DFA4:fix/old-ecl-jump-displacement
Open

thecl: restore pre-th10 jump displacement regression#142
ACA4DFA4 wants to merge 1 commit into
thpatch:masterfrom
ACA4DFA4:fix/old-ecl-jump-displacement

Conversation

@ACA4DFA4

Copy link
Copy Markdown

Pre-th9 ECL jump targets ('o' params) are displacements relative to the emitting instruction — matching ZUN's originals and thtk's own dumper (sub_name + instr->offset + value). The serializer currently writes label_offset() verbatim (an absolute offset), corrupting every compiled jump/loop in th06–th08 subs; timelines have no 'o' params and were unaffected.

f0190b2 wrote the correct - instr->offset term; the serializer rewrite in 5ad773c dropped it. This PR restores that single term.

Minimal repro

A single backward conditional loop compiles to displacement +16 (the label's absolute offset) instead of -24:

sub SubT()
{
    ins_95(0);
SubT_A:
    ins_117(20, 4, #ffffffff);
+4:
    ins_3(0, SubT_A, [10012]);
    ins_42();
}

Round-trip audit

dump → recompile → CFG comparison over all shipped stage scripts:

corpus files findings before after
th07 ecldata1–8 8 1462 (148 subs damaged) 0
th08 ecldata* (incl. sp/boss scripts) 24 3085 0

In-game symptom of the bug: any old-engine script containing loops or jumps breaks when recompiled with thecl -c.

Pre-th9 ECL jump targets ('o' params) are displacements relative to the
emitting instruction, matching ZUN's originals and thtk's own dumper
(sub_name + instr->offset + value).

f0190b2 originally wrote the correct term, but the serializer rewrite in
5ad773c dropped the '- instr->offset', so every jump/loop compiled for
th06-th08 landed at an absolute sub offset instead; timelines (no 'o'
params) were unaffected. Restore the lost term.

Round-trip audit over all shipped stage scripts: th07 8/8 and th08
24/24 files corrupted before (1462 / 3085 findings); 0 after.
@ACA4DFA4
ACA4DFA4 marked this pull request as ready for review August 25, 2026 21:02
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.

1 participant