#include "game_types.h"

/* Script_ReadData @ 0x0801308C (real 46B) -- script data dispatch with shared-epilogue exits. Mirrors src/matched/Script_ReadData.c. */
/* Advances past a zero byte into the shared Script_Advance epilogue at
   0x0801303E; otherwise bumps field 3, runs the fetch helper, and either
   re-enters the shared epilogue or resets field 3 and skips 5. Both early
   exits branch out of the function (modeled as tail calls). */
extern int Script_FetchHelper_08013030(void);
extern void Script_AdvanceTail(void); /* shared epilogue at 0x0801303E */

void Script_ReadData(char *st)
{
    unsigned char **cursor = (unsigned char **)(st + 64);
    unsigned char *p = *cursor;
    int gen;
    if (*p == 0) {
        *cursor = p + 1;
        Script_AdvanceTail();
        return;
    }
    gen = (unsigned char)(st[3] + 1);
    st[3] = (char)gen;
    if (gen >= Script_FetchHelper_08013030()) {
        Script_AdvanceTail();
        return;
    }
    st[3] = 0;
    *cursor = p + 5;
}
