/* * xml_encoding.h — down-convert UTF-16 cheat XML to UTF-8 before parsing. * * SHN and MC4 trainer files are authored by Windows tools that sometimes save * UTF-16 (a real `ff fe` / `fe ff` BOM, ``). The * cheat parser scans bytes for ASCII tags such as " /* * If `in` is UTF-16 (LE or BE, with or without a BOM), return a freshly * malloc'd, NUL-terminated UTF-8 copy and set *out_len to its length (not * counting the terminator). The caller owns the buffer and must free() it. * * Returns NULL when the input is already 8-bit (UTF-8/ASCII) — no conversion * is needed, so the caller keeps parsing the original bytes — and also on * allocation failure, which degrades to the same "parse the original" path. * *out_len is set to 0 in both NULL cases. */ char *xml_to_utf8(const char *in, size_t in_len, size_t *out_len); /* * MC4 files decrypt to XML that was serialised as an escaped string: the real * plaintext of etaHEN's CUSA00002_01.00.mc4 begins * <?xml version=\"1.0\" encoding=\"utf-16\"?> * i.e. every '<' '>' '"' is an XML entity and every '"' also carries a * backslash. The tag scan never sees "